Compare commits
7 Commits
2dc34f9f28
...
27a6c9a136
Author | SHA1 | Date | |
---|---|---|---|
27a6c9a136 | |||
7c85199e4c | |||
fef3b94732 | |||
cd8ebc23a0 | |||
f29b59507a | |||
bb5d157439 | |||
dacbf1eea3 |
@ -370,7 +370,6 @@ where
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: stop giving away wares for free
|
||||
if client.character.meseta < (item.price() * buy_item.amount as usize) as u32 {
|
||||
return Err(ShipError::ShopError.into())
|
||||
}
|
||||
|
@ -7,20 +7,41 @@ use crate::ship::location::{ClientLocation, RoomId, RoomLobby, ClientLocationErr
|
||||
use crate::ship::packet::builder;
|
||||
use crate::ship::room;
|
||||
use crate::ship::items::ItemManager;
|
||||
use std::convert::{TryFrom};
|
||||
|
||||
pub fn create_room(id: ClientId,
|
||||
create_room: &CreateRoom,
|
||||
client_location: &mut ClientLocation,
|
||||
clients: &mut Clients,
|
||||
item_manager: &mut ItemManager,
|
||||
level_table: &CharacterLevelTable,
|
||||
rooms: &mut Rooms)
|
||||
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
||||
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, anyhow::Error> {
|
||||
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
||||
let level = level_table.get_level_from_exp(client.character.char_class, client.character.exp);
|
||||
match room::Difficulty::try_from(create_room.difficulty)? {
|
||||
room::Difficulty::Ultimate => {
|
||||
if level < 80 {
|
||||
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("You must be at least level 80 \nto create Ultimate rooms.".into())))].into_iter()))
|
||||
}
|
||||
},
|
||||
room::Difficulty::VeryHard => {
|
||||
if level < 40 {
|
||||
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("You must be at least level 40 \nto create Very Hard rooms.".into())))].into_iter()))
|
||||
}
|
||||
},
|
||||
room::Difficulty::Hard => {
|
||||
if level < 20 {
|
||||
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("You must be at least level 20 \nto create Hard rooms.".into())))].into_iter()))
|
||||
}
|
||||
},
|
||||
room::Difficulty::Normal => {},
|
||||
};
|
||||
|
||||
let area = client_location.get_area(id).unwrap();
|
||||
let area_client = client_location.get_local_client(id).unwrap();
|
||||
let lobby_neighbors = client_location.get_client_neighbors(id).unwrap();
|
||||
let room_id = client_location.create_new_room(id).unwrap();
|
||||
|
||||
let client = clients.get_mut(&id).unwrap();//.ok_or(ShipError::ClientNotFound(id)).unwrap();
|
||||
let mut room = room::RoomState::from_create_room(create_room, client.character.section_id).unwrap();
|
||||
room.bursting = true;
|
||||
|
||||
@ -63,11 +84,31 @@ pub fn join_room(id: ClientId,
|
||||
level_table: &CharacterLevelTable,
|
||||
rooms: &mut Rooms)
|
||||
-> Result<Box<dyn Iterator<Item=(ClientId, SendShipPacket)> + Send>, ShipError> {
|
||||
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
||||
let level = level_table.get_level_from_exp(client.character.char_class, client.character.exp);
|
||||
let room = rooms.get(pkt.item as usize).ok_or(ShipError::InvalidRoom(pkt.item))?.as_ref().unwrap(); // clippy look what you made me do
|
||||
|
||||
match room.mode.difficulty() {
|
||||
room::Difficulty::Ultimate => {
|
||||
if level < 80 {
|
||||
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("You must be at least level 80 \nto join Ultimate rooms.".into())))].into_iter()))
|
||||
}
|
||||
},
|
||||
room::Difficulty::VeryHard => {
|
||||
if level < 40 {
|
||||
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("You must be at least level 40 \nto join Very Hard rooms.".into())))].into_iter()))
|
||||
}
|
||||
},
|
||||
room::Difficulty::Hard => {
|
||||
if level < 20 {
|
||||
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("You must be at least level 20 \nto join Hard rooms.".into())))].into_iter()))
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
};
|
||||
|
||||
let original_area = client_location.get_area(id).unwrap();
|
||||
let original_neighbors = client_location.get_client_neighbors(id).unwrap();
|
||||
let room = rooms.get(pkt.item as usize)
|
||||
.ok_or(ShipError::InvalidRoom(pkt.item))?.as_ref()
|
||||
.ok_or(ShipError::InvalidRoom(pkt.item))?;
|
||||
if room.bursting {
|
||||
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("player is bursting\nplease wait".into())))].into_iter()))
|
||||
}
|
||||
|
@ -7,14 +7,15 @@ use crate::ship::drops::DropTable;
|
||||
use crate::entity::character::SectionID;
|
||||
use crate::ship::monster::{load_monster_stats_table, MonsterType, MonsterStats};
|
||||
use crate::ship::map::area::MapAreaLookup;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Error)]
|
||||
#[error("")]
|
||||
pub enum RoomCreationError {
|
||||
InvalidMode,
|
||||
InvalidEpisode(u8),
|
||||
InvalidDifficulty(u8),
|
||||
CouldNotLoadMonsterStats(RoomMode),
|
||||
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, derive_more::Display)]
|
||||
|
@ -635,7 +635,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
|
||||
},
|
||||
RecvShipPacket::CreateRoom(create_room) => {
|
||||
let block = self.blocks.with_client(id, &self.clients)?;
|
||||
handler::room::create_room(id, create_room, &mut block.client_location, &mut self.clients, &mut self.item_manager, &mut block.rooms)?
|
||||
handler::room::create_room(id, create_room, &mut block.client_location, &mut self.clients, &mut self.item_manager, &self.level_table, &mut block.rooms)?
|
||||
},
|
||||
RecvShipPacket::RoomNameRequest(_req) => {
|
||||
let block = self.blocks.with_client(id, &self.clients)?;
|
||||
|
@ -292,7 +292,7 @@ async fn test_player_sells_3_attr_weapon_to_shop() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -323,7 +323,7 @@ async fn test_other_clients_see_purchase() {
|
||||
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
join_lobby(&mut ship, ClientId(2)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
|
||||
join_room(&mut ship, ClientId(2), 0).await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
||||
@ -377,7 +377,7 @@ async fn test_other_clients_see_stacked_purchase() {
|
||||
log_in_char(&mut ship, ClientId(2), "a2", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
join_lobby(&mut ship, ClientId(2)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
|
||||
join_room(&mut ship, ClientId(2), 0).await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
||||
@ -414,7 +414,7 @@ async fn test_buying_item_without_enough_mseseta() {
|
||||
.build());
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Normal).await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
|
||||
client: 255,
|
||||
@ -662,7 +662,7 @@ async fn test_player_sells_untekked_weapon() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -710,7 +710,7 @@ async fn test_player_sells_rare_item() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -757,7 +757,7 @@ async fn test_player_sells_partial_photon_drop_stack() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -802,7 +802,7 @@ async fn test_player_sells_basic_frame() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -847,7 +847,7 @@ async fn test_player_sells_max_frame() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -891,7 +891,7 @@ async fn test_player_sells_basic_barrier() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -935,7 +935,7 @@ async fn test_player_sells_max_barrier() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -978,7 +978,7 @@ async fn test_player_sells_1_star_minusminus_unit() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -1021,7 +1021,7 @@ async fn test_player_sells_5_star_plusplus_unit() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -1066,7 +1066,7 @@ async fn test_player_sells_rare_frame() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -1110,7 +1110,7 @@ async fn test_player_sells_rare_barrier() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
@ -1153,7 +1153,7 @@ async fn test_player_sells_rare_unit() {
|
||||
|
||||
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
|
||||
join_lobby(&mut ship, ClientId(1)).await;
|
||||
create_room_with_difficulty(&mut ship, ClientId(1), "room", "", Difficulty::Ultimate).await;
|
||||
create_room(&mut ship, ClientId(1), "room", "").await;
|
||||
|
||||
ship.handle(ClientId(1), &RecvShipPacket::Message(Message::new(GameMessage::PlayerSoldItem(PlayerSoldItem {
|
||||
client: 0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user