mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fix players having inventory and lantern control while dead
This commit is contained in:
parent
0a57bf4367
commit
76fe63ed9a
@ -49,7 +49,11 @@ pub fn handle_lantern(server: &mut Server, entity: EcsEntity, enable: bool) {
|
|||||||
.ecs()
|
.ecs()
|
||||||
.write_storage::<comp::LightEmitter>()
|
.write_storage::<comp::LightEmitter>()
|
||||||
.remove(entity);
|
.remove(entity);
|
||||||
} else {
|
} else if ecs // Only enable lantern if entity is alive
|
||||||
|
.read_storage::<comp::Health>()
|
||||||
|
.get(entity)
|
||||||
|
.map_or(true, |h| !h.is_dead)
|
||||||
|
{
|
||||||
let inventory_storage = ecs.read_storage::<Inventory>();
|
let inventory_storage = ecs.read_storage::<Inventory>();
|
||||||
let lantern_opt = inventory_storage
|
let lantern_opt = inventory_storage
|
||||||
.get(entity)
|
.get(entity)
|
||||||
|
@ -91,6 +91,17 @@ pub fn handle_inventory(server: &mut Server, entity: EcsEntity, manip: comp::Inv
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Disallow inventory manipulation while dead
|
||||||
|
if state
|
||||||
|
.ecs()
|
||||||
|
.read_storage::<comp::Health>()
|
||||||
|
.get(entity)
|
||||||
|
.map_or(false, |h| h.is_dead)
|
||||||
|
{
|
||||||
|
debug!("Can't manipulate inventory; entity is dead");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
match manip {
|
match manip {
|
||||||
comp::InventoryManip::Pickup(uid) => {
|
comp::InventoryManip::Pickup(uid) => {
|
||||||
let item_entity = if let Some(item_entity) = state.ecs().entity_from_uid(uid.into()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab the health from the entity and check if the entity is dead.
|
|
||||||
let healths = state.ecs().read_storage::<comp::Health>();
|
|
||||||
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
|
// 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
|
// avoid cloning the item, as we should not call Item::clone and it
|
||||||
// may be removed!).
|
// may be removed!).
|
||||||
|
Loading…
Reference in New Issue
Block a user