Browse Source

add level requirements for rooms and update tests

pull/65/head
andy 4 years ago
parent
commit
dacbf1eea3
  1. 68
      src/ship/packet/handler/room.rs
  2. 5
      src/ship/room.rs
  3. 2
      src/ship/ship.rs
  4. 6
      tests/test_shops.rs

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

@ -7,20 +7,47 @@ 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 => {
if level < 1 {
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("You must be at least level 1 \nto create Normal rooms.".into())))].into_iter()))
}
},
// i can't believe you've done this
_ => {unreachable!()},
};
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 +90,40 @@ 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_else(|| ShipError::InvalidRoom(pkt.item))?.as_ref()
.ok_or_else(|| ShipError::InvalidRoom(pkt.item))?;
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()))
}
},
room::Difficulty::Normal => {
if level < 1 {
return Ok(Box::new(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("You must be at least level 1 \nto join Normal 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))?;
// let room = rooms.get(pkt.item as usize)
// .ok_or_else(|| ShipError::InvalidRoom(pkt.item))?.as_ref()
// .ok_or_else(|| 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()))
}

5
src/ship/room.rs

@ -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)]

2
src/ship/ship.rs

@ -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)?;

6
tests/test_shops.rs

@ -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,

Loading…
Cancel
Save