]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fixed mice behavior of eating everything (#23322)
author778b <33431126+778b@users.noreply.github.com>
Tue, 2 Jan 2024 18:49:20 +0000 (21:49 +0300)
committerGitHub <noreply@github.com>
Tue, 2 Jan 2024 18:49:20 +0000 (13:49 -0500)
* 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

Content.Server/NPC/HTN/Preconditions/HungryPrecondition.cs [new file with mode: 0644]
Content.Server/NPC/HTN/Preconditions/ThirstyPrecondition.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Mobs/NPCs/animals.yml
Resources/Prototypes/NPCs/nutrition.yml

diff --git a/Content.Server/NPC/HTN/Preconditions/HungryPrecondition.cs b/Content.Server/NPC/HTN/Preconditions/HungryPrecondition.cs
new file mode 100644 (file)
index 0000000..9f0a46b
--- /dev/null
@@ -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;
+    }
+}
diff --git a/Content.Server/NPC/HTN/Preconditions/ThirstyPrecondition.cs b/Content.Server/NPC/HTN/Preconditions/ThirstyPrecondition.cs
new file mode 100644 (file)
index 0000000..97206dc
--- /dev/null
@@ -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 ThirstyPrecondition : HTNPrecondition
+{
+    [Dependency] private readonly IEntityManager _entManager = default!;
+
+    [DataField(required: true)]
+    public ThirstThreshold MinThirstState = ThirstThreshold.Parched;
+
+    public override bool IsMet(NPCBlackboard blackboard)
+    {
+        if (!blackboard.TryGetValue<EntityUid>(NPCBlackboard.Owner, out var owner, _entManager))
+        {
+            return false;
+        }
+
+        return _entManager.TryGetComponent<ThirstComponent>(owner, out var thirst) ? thirst.CurrentThirstThreshold <= MinThirstState : false;
+    }
+}
index 8f8cb59d5efba66e57b24199adb8b913ddba7931..74cf35322d77e0e141b77113f24dbc01cf9f06ec 100644 (file)
       Dead:
         Base: splat-0
   - type: Food
+  - type: Thirst
+    startingThirst: 25  # spawn with Okay thirst state
+    thresholds:
+      OverHydrated: 35
+      Okay: 25
+      Thirsty: 15
+      Parched: 10
+      Dead: 0
+    baseDecayRate: 0.04
   - type: Hunger
+    currentHunger: 25   # spawn with Okay hunger state
     thresholds:
       Overfed: 35
       Okay: 25
index da64989c330aa1213803241678c3764e671ef5a2..dea065c34ffcaf49be852c3cc50ad1496c28b4ad 100644 (file)
@@ -4,6 +4,9 @@
     # Picks a nearby food, moves into range, then eats it and waits the idle time.
     - tasks:
         - !type:HTNPrimitiveTask
+          preconditions:
+            - !type:HungryPrecondition
+              minHungerState: Starving  # See HungerThreshold enum
           operator: !type:UtilityOperator
             proto: NearbyFood
 
@@ -31,6 +34,9 @@
     # Picks nearby drink then consumes it and waits idle time
     - tasks:
         - !type:HTNPrimitiveTask
+          preconditions:
+            - !type:ThirstyPrecondition
+              minThirstState: Parched  # See ThirstThreshold enum
           operator: !type:UtilityOperator
             proto: NearbyDrink