Non-humanoid picking up consumables when hungry

This commit is contained in:
StereoJunkie 2022-05-27 16:57:53 +00:00 committed by Samuel Keiffer
parent ca1a27bd11
commit 3015b4a29d
2 changed files with 20 additions and 1 deletions

View File

@ -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 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 - 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 - 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 ### Removed

View File

@ -37,6 +37,7 @@ use common::{
tool::{AbilitySpec, ToolKind}, tool::{AbilitySpec, ToolKind},
ConsumableKind, Item, ItemDesc, ItemKind, ConsumableKind, Item, ItemDesc, ItemKind,
}, },
item_drop,
projectile::ProjectileConstructor, projectile::ProjectileConstructor,
Agent, Alignment, BehaviorState, Body, CharacterState, ControlAction, ControlEvent, Agent, Alignment, BehaviorState, Body, CharacterState, ControlAction, ControlEvent,
Controller, Health, HealthChange, InputKind, InventoryAction, InventoryEvent, Pos, Scale, 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) { 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| { if read_data.healths.get(entity).map_or(false, |health| {
!health.is_dead && !is_invulnerable(entity, read_data) !health.is_dead && !is_invulnerable(entity, read_data)