|
|
@ -9,7 +9,7 @@ use crate::common::serverstate::ClientId; |
|
|
|
use crate::common::leveltable::LEVEL_TABLE;
|
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
|
use crate::entity::character::SectionID;
|
|
|
|
use crate::entity::room::{RoomEntity, RoomEntityId, NewRoomEntity, RoomEntityMode};
|
|
|
|
use crate::entity::room::{RoomEntity, RoomEntityId, NewRoomEntity, RoomEntityMode, RoomNote};
|
|
|
|
use crate::ship::drops::DropTable;
|
|
|
|
use crate::ship::ship::{SendShipPacket, Clients, ShipEvent};
|
|
|
|
use crate::ship::room::{Rooms, Episode, Difficulty, RoomState, RoomMode};
|
|
|
@ -57,7 +57,6 @@ where |
|
|
|
let room_id = client_location.create_new_room(id).await?;
|
|
|
|
let new_area_client = client_location.get_local_client(id).await?;
|
|
|
|
|
|
|
|
|
|
|
|
let name = String::from_utf16_lossy(&create_room.name).trim_matches(char::from(0)).to_string();
|
|
|
|
let mode = match (create_room.battle, create_room.challenge, create_room.single_player) {
|
|
|
|
(1, 0, 0) => RoomEntityMode::Battle,
|
|
|
@ -81,6 +80,10 @@ where |
|
|
|
difficulty,
|
|
|
|
}).await?;
|
|
|
|
|
|
|
|
entity_gateway.add_room_note(room_entity.id, RoomNote::Create {
|
|
|
|
character_id: client.character.id,
|
|
|
|
}).await?;
|
|
|
|
|
|
|
|
let mut room = RoomState::new(room_entity.id, mode, episode, difficulty,
|
|
|
|
client.character.section_id, name, create_room.password, event,
|
|
|
|
map_builder, drop_table_builder)?;
|
|
|
@ -121,14 +124,18 @@ pub async fn room_name_request(id: ClientId, |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn join_room(id: ClientId,
|
|
|
|
pkt: MenuSelect,
|
|
|
|
client_location: &mut ClientLocation,
|
|
|
|
clients: &Clients,
|
|
|
|
item_state: &mut ItemState,
|
|
|
|
rooms: &Rooms,
|
|
|
|
event: ShipEvent)
|
|
|
|
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> {
|
|
|
|
pub async fn join_room<EG>(id: ClientId,
|
|
|
|
pkt: MenuSelect,
|
|
|
|
entity_gateway: &mut EG,
|
|
|
|
client_location: &mut ClientLocation,
|
|
|
|
clients: &Clients,
|
|
|
|
item_state: &mut ItemState,
|
|
|
|
rooms: &Rooms,
|
|
|
|
event: ShipEvent)
|
|
|
|
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
|
|
|
|
where
|
|
|
|
EG: EntityGateway + Clone + 'static,
|
|
|
|
{
|
|
|
|
let room_id = RoomId(pkt.item as usize);
|
|
|
|
if !rooms.exists(room_id).await {
|
|
|
|
return Ok(vec![(id, SendShipPacket::SmallDialog(SmallDialog::new("This room no longer exists!".into())))])
|
|
|
@ -136,8 +143,8 @@ pub async fn join_room(id: ClientId, |
|
|
|
let level = clients.with(id, |client| Box::pin(async move {
|
|
|
|
LEVEL_TABLE.get_level_from_exp(client.character.char_class, client.character.exp)
|
|
|
|
})).await?;
|
|
|
|
let (difficulty, bursting) = rooms.with(room_id, |room| Box::pin(async move {
|
|
|
|
(room.mode.difficulty(), room.bursting)
|
|
|
|
let (difficulty, bursting, room_entity_id) = rooms.with(room_id, |room| Box::pin(async move {
|
|
|
|
(room.mode.difficulty(), room.bursting, room.room_id)
|
|
|
|
})).await?;
|
|
|
|
|
|
|
|
match difficulty {
|
|
|
@ -166,9 +173,14 @@ pub async fn join_room(id: ClientId, |
|
|
|
|
|
|
|
clients.with(id, |client| {
|
|
|
|
let mut item_state = item_state.clone();
|
|
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
|
|
Box::pin(async move {
|
|
|
|
entity_gateway.add_room_note(room_entity_id, RoomNote::PlayerJoin {
|
|
|
|
character_id: client.character.id,
|
|
|
|
}).await?;
|
|
|
|
item_state.add_character_to_room(room_id, &client.character, area_client).await;
|
|
|
|
})}).await?;
|
|
|
|
Ok::<_, anyhow::Error>(())
|
|
|
|
})}).await??;
|
|
|
|
|
|
|
|
let join_room = rooms.with(room_id, |room| {
|
|
|
|
let clients = clients.clone();
|
|
|
|