From 76fe63ed9a8d7c5911eee1e4b2845eea383bc422 Mon Sep 17 00:00:00 2001 From: DixiE Date: Tue, 6 Jul 2021 22:35:35 +0100 Subject: [PATCH] Fix players having inventory and lantern control while dead --- server/src/events/interaction.rs | 6 +++++- server/src/events/inventory_manip.rs | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/server/src/events/interaction.rs b/server/src/events/interaction.rs index bf5047154b..a0663ff4d6 100644 --- a/server/src/events/interaction.rs +++ b/server/src/events/interaction.rs @@ -49,7 +49,11 @@ pub fn handle_lantern(server: &mut Server, entity: EcsEntity, enable: bool) { .ecs() .write_storage::() .remove(entity); - } else { + } else if ecs // Only enable lantern if entity is alive + .read_storage::() + .get(entity) + .map_or(true, |h| !h.is_dead) + { let inventory_storage = ecs.read_storage::(); let lantern_opt = inventory_storage .get(entity) diff --git a/server/src/events/inventory_manip.rs b/server/src/events/inventory_manip.rs index 7a29c7caae..e860677d44 100644 --- a/server/src/events/inventory_manip.rs +++ b/server/src/events/inventory_manip.rs @@ -91,6 +91,17 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv return; }; + // Disallow inventory manipulation while dead + if state + .ecs() + .read_storage::() + .get(entity) + .map_or(false, |h| h.is_dead) + { + debug!("Can't manipulate inventory; entity is dead"); + return; + } + match manip { comp::InventoryManip::Pickup(uid) => { let item_entity = if let Some(item_entity) = state.ecs().entity_from_uid(uid.into()) { @@ -113,16 +124,6 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv return; } - // Grab the health from the entity and check if the entity is dead. - let healths = state.ecs().read_storage::(); - if let Some(entity_health) = healths.get(entity) { - if entity_health.is_dead { - debug!("Failed to pick up item as the entity is dead"); - return; // If dead, don't continue - } - } - drop(healths); - // First, we remove the item, assuming picking it up will succeed (we do this to // avoid cloning the item, as we should not call Item::clone and it // may be removed!).