Merge pull request 'keep track of player's position' (#177) from player_position into master
This commit is contained in:
commit
b50d37cbb7
@ -160,3 +160,35 @@ where
|
||||
})))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_player_position(id: ClientId,
|
||||
message: &GameMessage,
|
||||
clients: &mut Clients,
|
||||
client_location: &ClientLocation,
|
||||
rooms: &Rooms)
|
||||
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + 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()))
|
||||
}
|
@ -219,6 +219,10 @@ pub struct ClientState {
|
||||
pub item_drop_location: Option<ItemDropLocation>,
|
||||
pub done_loading_quest: bool,
|
||||
//pub loading_quest: Option<LoadingQuest>,
|
||||
pub area: Option<MapArea>,
|
||||
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<EG: EntityGateway> ShipServerState<EG> {
|
||||
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, &msg.msg, &mut self.clients, &mut self.client_location, &self.rooms)
|
||||
},
|
||||
_ => {
|
||||
let cmsg = msg.clone();
|
||||
Ok(Box::new(self.client_location.get_client_neighbors(id).unwrap().into_iter()
|
||||
|
Loading…
x
Reference in New Issue
Block a user