Merge branch 'xvar/fix-agent-loot-pickup' into 'master'

Fixed animals picking up non-owned non-consumable loot

See merge request veloren/veloren!3417
This commit is contained in:
Ben Wallis
2022-05-31 15:30:57 +00:00

View File

@ -1604,29 +1604,30 @@ impl<'a> AgentData<'a> {
}; };
let is_valid_target = |entity: EcsEntity| match read_data.bodies.get(entity) { let is_valid_target = |entity: EcsEntity| match read_data.bodies.get(entity) {
Some(Body::ItemDrop(item)) => { Some(Body::ItemDrop(item)) => {
// If there is no LootOwner then the ItemDrop is a valid target, otherwise check // Agents want to pick up items if they are humanoid, or are hungry and the
// if the loot can be picked up // item is consumable
read_data let hungry = || {
.loot_owners self.health
.get(entity) .map_or(false, |health| health.current() < health.maximum())
.map_or(Some((entity, false)), |loot_owner| { };
// Agents want to pick up items if they are humanoid, or are hungry and the let wants_pickup = matches!(self.body, Some(Body::Humanoid(_)))
// item is consumable || (hungry() && matches!(item, item_drop::Body::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 = // The agent will attempt to pickup the item if it wants to pick it up and is
loot_owner.can_pickup(*self.uid, self.alignment, self.body, None); // 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 { if attempt_pickup {
Some((entity, false)) Some((entity, false))
} else { } else {
None None
} }
})
}, },
_ => { _ => {
if read_data.healths.get(entity).map_or(false, |health| { if read_data.healths.get(entity).map_or(false, |health| {