From 3015b4a29dd12c5ffb79ae5302d60354b1eef1b0 Mon Sep 17 00:00:00 2001 From: StereoJunkie Date: Fri, 27 May 2022 16:57:53 +0000 Subject: [PATCH] Non-humanoid picking up consumables when hungry --- CHANGELOG.md | 1 + server/src/sys/agent.rs | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 319daaddc9..0aecb6f084 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Stealth is now shown as a percentage in Stats Diary UI - Stealth effects from sneaking and armor are evaluated independently. Armor now has effects even when not sneaking - Zoom-in effect when aiming bow is now optional +- Non-Humanoid NPCs now pick up consumables when less than full health and use them to heal up. ### Removed diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 09e7bcad3b..094cffe8d8 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -37,6 +37,7 @@ use common::{ tool::{AbilitySpec, ToolKind}, ConsumableKind, Item, ItemDesc, ItemKind, }, + item_drop, projectile::ProjectileConstructor, Agent, Alignment, BehaviorState, Body, CharacterState, ControlAction, ControlEvent, Controller, Health, HealthChange, InputKind, InventoryAction, InventoryEvent, Pos, Scale, @@ -1601,7 +1602,24 @@ impl<'a> AgentData<'a> { } }; let is_valid_target = |entity: EcsEntity| match read_data.bodies.get(entity) { - Some(Body::ItemDrop(_)) => Some((entity, false)), + Some(Body::ItemDrop(item)) => { + //If statement that checks either if the self (agent) is a humanoid, + //or if the self is not a humanoid, it checks whether or not you are 'hungry' - + // meaning less than full health - and additionally checks if + // the target entity is a consumable item. If it qualifies for + // either being a humanoid or a hungry non-humanoid that likes consumables, + // it will choose the item as its target. + if matches!(self.body, Some(Body::Humanoid(_))) + || (self + .health + .map_or(false, |health| health.current() < health.maximum()) + && matches!(item, item_drop::Body::Consumable)) + { + Some((entity, false)) + } else { + None + } + }, _ => { if read_data.healths.get(entity).map_or(false, |health| { !health.is_dead && !is_invulnerable(entity, read_data)