Fixed mice behavior of eating everything (#23322)

* Added precondition for EatTask

* Added Thirsty precondition for htn drink task

* Added start state for hungry and thirsty components

* Update nutrition.yml

* Fixed pascalcase's
This commit is contained in:
778b
2024-01-02 21:49:20 +03:00
committed by GitHub
parent 5e6633ea50
commit 439d6ff44e
4 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
using Content.Shared.Hands.Components;
using Content.Shared.Nutrition.Components;
using Robust.Shared.Prototypes;
namespace Content.Server.NPC.HTN.Preconditions;
/// <summary>
/// Returns true if the active hand entity has the specified components.
/// </summary>
public sealed partial class HungryPrecondition : HTNPrecondition
{
[Dependency] private readonly IEntityManager _entManager = default!;
[DataField(required: true)]
public HungerThreshold MinHungerState = HungerThreshold.Starving;
public override bool IsMet(NPCBlackboard blackboard)
{
if (!blackboard.TryGetValue<EntityUid>(NPCBlackboard.Owner, out var owner, _entManager))
{
return false;
}
return _entManager.TryGetComponent<HungerComponent>(owner, out var hunger) ? hunger.CurrentThreshold <= MinHungerState : false;
}
}