From d71f2ff68211dd27716afca80655c1dde4899321 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Tue, 31 May 2022 15:57:58 +0100 Subject: [PATCH] Fixed animals picking up non-owned non-consumable loot --- server/src/sys/agent.rs | 43 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index f1701a41c0..1eb20321bd 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1604,29 +1604,30 @@ impl<'a> AgentData<'a> { }; let is_valid_target = |entity: EcsEntity| match read_data.bodies.get(entity) { Some(Body::ItemDrop(item)) => { - // If there is no LootOwner then the ItemDrop is a valid target, otherwise check - // if the loot can be picked up - read_data - .loot_owners - .get(entity) - .map_or(Some((entity, false)), |loot_owner| { - // Agents want to pick up items if they are humanoid, or are hungry and the - // item is consumable - let hungry = self - .health - .map_or(false, |health| health.current() < health.maximum()); - let wants_pickup = matches!(self.body, Some(Body::Humanoid(_))) - || (hungry && matches!(item, item_drop::Body::Consumable)); + // Agents want to pick up items if they are humanoid, or are hungry and the + // item is consumable + let hungry = || { + self.health + .map_or(false, |health| health.current() < health.maximum()) + }; + let wants_pickup = matches!(self.body, Some(Body::Humanoid(_))) + || (hungry() && matches!(item, item_drop::Body::Consumable)); - let can_pickup = - loot_owner.can_pickup(*self.uid, self.alignment, self.body, None); + // The agent will attempt to pickup the item if it wants to pick it up and is + // allowed to + let attempt_pickup = wants_pickup + && read_data + .loot_owners + .get(entity) + .map_or(true, |loot_owner| { + loot_owner.can_pickup(*self.uid, self.alignment, self.body, None) + }); - if wants_pickup && can_pickup { - Some((entity, false)) - } else { - None - } - }) + if attempt_pickup { + Some((entity, false)) + } else { + None + } }, _ => { if read_data.healths.get(entity).map_or(false, |health| {