diff --git a/src/ship/packet/handler/message.rs b/src/ship/packet/handler/message.rs index 1e21884..e0230fe 100644 --- a/src/ship/packet/handler/message.rs +++ b/src/ship/packet/handler/message.rs @@ -160,3 +160,35 @@ where }))) } } + +pub fn update_player_position(id: ClientId, + clients: &mut Clients, + client_location: &ClientLocation, + rooms: &Rooms, + message: &GameMessage,) + -> Result + Send>, ShipError> { + let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; + if let Ok(room_id) = client_location.get_room(id).map_err(|err| -> ClientLocationError { err.into() }) { + let room = rooms.get(room_id.0) + .ok_or_else(|| ShipError::InvalidRoom(room_id.0 as u32))? + .as_ref() + .ok_or_else(|| ShipError::InvalidRoom(room_id.0 as u32))?; + + match message { + GameMessage::PlayerChangedMap(p) => {client.x = p.x; client.y = p.y; client.z = p.z;}, + GameMessage::PlayerChangedMap2(p) => {client.area = MapArea::from_value(&room.mode.episode(), p.map_area).ok();}, + GameMessage::TellOtherPlayerMyLocation(p) => {client.x = p.x; client.y = p.y; client.z = p.z; client.area = MapArea::from_value(&room.mode.episode(), p.map_area).ok();}, + GameMessage::PlayerWarpingToFloor(p) => {client.area = MapArea::from_value(&room.mode.episode(), p.area as u32).ok();}, + GameMessage::PlayerTeleported(p) => {client.x = p.x; client.y = p.y; client.z = p.z;}, + GameMessage::PlayerStopped(p) => {client.x = p.x; client.y = p.y; client.z = p.z;}, + GameMessage::PlayerLoadedIn(p) => {client.x = p.x; client.y = p.y; client.z = p.z;}, + GameMessage::PlayerWalking(p) => {client.x = p.x; client.z = p.z;}, + GameMessage::PlayerRunning(p) => {client.x = p.x; client.z = p.z;}, + GameMessage::PlayerWarped(p) => {client.x = p.x; client.y = p.y;}, + GameMessage::PlayerChangedFloor(p) => {client.area = MapArea::from_value(&room.mode.episode(), p.map).ok();}, + GameMessage::InitializeSpeechNpc(p) => {client.x = p.x; client.z = p.z;} + _ => {}, + } + } else {} + Ok(Box::new(None.into_iter())) +} \ No newline at end of file diff --git a/src/ship/ship.rs b/src/ship/ship.rs index ba97417..086a8e8 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -219,6 +219,10 @@ pub struct ClientState { pub item_drop_location: Option, pub done_loading_quest: bool, //pub loading_quest: Option, + pub area: Option, + pub x: f32, + pub y: f32, + pub z: f32, } impl ClientState { @@ -231,6 +235,10 @@ impl ClientState { block: 1, item_drop_location: None, done_loading_quest: false, + area: None, + x: 0.0, + y: 0.0, + z: 0.0, } } } @@ -275,6 +283,12 @@ impl ShipServerState { GameMessage::PlayerSplitItemStack(split_item_stack) => { handler::message::split_item_stack(id, split_item_stack, &mut self.entity_gateway, &mut self.client_location, &mut self.clients, &mut self.item_manager).await }, + GameMessage::PlayerChangedMap(_) | GameMessage::PlayerChangedMap2(_) | GameMessage::TellOtherPlayerMyLocation(_) | + GameMessage::PlayerWarpingToFloor(_) | GameMessage::PlayerTeleported(_) | GameMessage::PlayerStopped(_) | + GameMessage::PlayerLoadedIn(_) | GameMessage::PlayerWalking(_) | GameMessage::PlayerRunning(_) | + GameMessage::PlayerWarped(_) | GameMessage::PlayerChangedFloor(_) | GameMessage::InitializeSpeechNpc(_) => { + handler::message::update_player_position(id, &mut self.clients, &mut self.client_location, &self.rooms, &msg.msg) + }, _ => { let cmsg = msg.clone(); Ok(Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter()