room_join_requirements #49

Merged
jake merged 6 commits from room_join_requirements into master 3 years ago
  1. 53
      src/ship/packet/handler/room.rs
  2. 5
      src/ship/room.rs
  3. 2
      src/ship/ship.rs
  4. 6
      tests/test_shops.rs

53
src/ship/packet/handler/room.rs

@ -7,20 +7,41 @@ use crate::ship::location::{ClientLocation, RoomId, RoomLobby, ClientLocationErr
use crate::ship::packet::builder; use crate::ship::packet::builder;
use crate::ship::room; use crate::ship::room;
use crate::ship::items::ItemManager; use crate::ship::items::ItemManager;
use std::convert::{TryFrom};
pub fn create_room(id: ClientId, pub fn create_room(id: ClientId,
create_room: &CreateRoom, create_room: &CreateRoom,
client_location: &mut ClientLocation, client_location: &mut ClientLocation,
clients: &mut Clients, clients: &mut Clients,
item_manager: &mut ItemManager, item_manager: &mut ItemManager,
level_table: &CharacterLevelTable,
rooms: &mut Rooms) 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_location.get_area(id).unwrap();
let area_client = client_location.get_local_client(id).unwrap(); let area_client = client_location.get_local_client(id).unwrap();
let lobby_neighbors = client_location.get_client_neighbors(id).unwrap(); let lobby_neighbors = client_location.get_client_neighbors(id).unwrap();
let room_id = client_location.create_new_room(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(); let mut room = room::RoomState::from_create_room(create_room, client.character.section_id).unwrap();
room.bursting = true; room.bursting = true;
@ -63,11 +84,31 @@ pub fn join_room(id: ClientId,
level_table: &CharacterLevelTable, level_table: &CharacterLevelTable,
rooms: &mut Rooms) rooms: &mut Rooms)
-> Result<Box<dyn Iterator<Item=(ClientId, SendShipPacket)> + Send>, ShipError> { -> 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_area = client_location.get_area(id).unwrap();
let original_neighbors = client_location.get_client_neighbors(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 { if room.bursting {
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("player is bursting\nplease wait".into())))].into_iter())) return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("player is bursting\nplease wait".into())))].into_iter()))
} }

5
src/ship/room.rs

@ -7,14 +7,15 @@ use crate::ship::drops::DropTable;
use crate::entity::character::SectionID; use crate::entity::character::SectionID;
use crate::ship::monster::{load_monster_stats_table, MonsterType, MonsterStats}; use crate::ship::monster::{load_monster_stats_table, MonsterType, MonsterStats};
use crate::ship::map::area::MapAreaLookup; use crate::ship::map::area::MapAreaLookup;
use thiserror::Error;
#[derive(Debug)]
#[derive(Debug, Error)]
#[error("")]
pub enum RoomCreationError { pub enum RoomCreationError {
InvalidMode, InvalidMode,
InvalidEpisode(u8), InvalidEpisode(u8),
InvalidDifficulty(u8), InvalidDifficulty(u8),
CouldNotLoadMonsterStats(RoomMode), CouldNotLoadMonsterStats(RoomMode),
} }
#[derive(Debug, Copy, Clone, derive_more::Display)] #[derive(Debug, Copy, Clone, derive_more::Display)]

2
src/ship/ship.rs

@ -632,7 +632,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
}, },
RecvShipPacket::CreateRoom(create_room) => { RecvShipPacket::CreateRoom(create_room) => {
let block = self.blocks.with_client(id, &self.clients)?; 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) => { RecvShipPacket::RoomNameRequest(_req) => {
let block = self.blocks.with_client(id, &self.clients)?; let block = self.blocks.with_client(id, &self.clients)?;

6
tests/test_shops.rs

@ -279,7 +279,7 @@ async fn test_other_clients_see_purchase() {
log_in_char(&mut ship, ClientId(2), "a2", "a").await; log_in_char(&mut ship, ClientId(2), "a2", "a").await;
join_lobby(&mut ship, ClientId(1)).await; join_lobby(&mut ship, ClientId(1)).await;
join_lobby(&mut ship, ClientId(2)).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; join_room(&mut ship, ClientId(2), 0).await;
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest { ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
@ -333,7 +333,7 @@ async fn test_other_clients_see_stacked_purchase() {
log_in_char(&mut ship, ClientId(2), "a2", "a").await; log_in_char(&mut ship, ClientId(2), "a2", "a").await;
join_lobby(&mut ship, ClientId(1)).await; join_lobby(&mut ship, ClientId(1)).await;
join_lobby(&mut ship, ClientId(2)).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; join_room(&mut ship, ClientId(2), 0).await;
ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest { ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
@ -370,7 +370,7 @@ async fn test_buying_item_without_enough_mseseta() {
.build()); .build());
log_in_char(&mut ship, ClientId(1), "a1", "a").await; log_in_char(&mut ship, ClientId(1), "a1", "a").await;
join_lobby(&mut ship, ClientId(1)).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 { ship.handle(ClientId(1), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::ShopRequest(ShopRequest {
client: 255, client: 255,

Loading…
Cancel
Save