]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Clean up new HTNs tasks (#28469)
authorTornado Tech <54727692+Tornado-Technology@users.noreply.github.com>
Sat, 1 Jun 2024 17:46:35 +0000 (03:46 +1000)
committerGitHub <noreply@github.com>
Sat, 1 Jun 2024 17:46:35 +0000 (13:46 -0400)
* Clean up new HTNs tasks

* Added docs to math operations

12 files changed:
Content.Server/NPC/HTN/Preconditions/KeyExistsPrecondition.cs
Content.Server/NPC/HTN/Preconditions/KeyNotExistsPrecondition.cs
Content.Server/NPC/HTN/Preconditions/Math/KeyBoolEqualsPrecondition.cs
Content.Server/NPC/HTN/Preconditions/Math/KeyFloatEqualsPrecondition.cs
Content.Server/NPC/HTN/Preconditions/Math/KeyFloatGreaterPrecondition.cs
Content.Server/NPC/HTN/Preconditions/Math/KeyFloatLessPrecondition.cs
Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/AddFloatOperator.cs
Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetBoolOperator.cs
Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetFloatOperator.cs
Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetRandomFloatOperator.cs
Content.Server/NPC/HTN/PrimitiveTasks/Operators/SayKeyOperator.cs
Content.Server/NPC/HTN/PrimitiveTasks/Operators/SpeakOperator.cs

index 72c4e6367fef0a150f035aa735d26ce30e03cf77..69e265f2763df5de5b9f9cbdd5196a3af8b60df4 100644 (file)
@@ -1,8 +1,13 @@
 namespace Content.Server.NPC.HTN.Preconditions;
 
+/// <summary>
+/// Checks for the presence of the value by the specified <see cref="KeyExistsPrecondition.Key"/> in the <see cref="NPCBlackboard"/>.
+/// Returns true if there is a value.
+/// </summary>
 public sealed partial class KeyExistsPrecondition : HTNPrecondition
 {
-    [DataField("key", required: true)] public string Key = string.Empty;
+    [DataField(required: true), ViewVariables]
+    public string Key = string.Empty;
 
     public override bool IsMet(NPCBlackboard blackboard)
     {
index c12663901c74d06631bc069d84de808b4ff93d12..8dc38e442ab3a8ecf60e05062805824f78c72b56 100644 (file)
@@ -1,8 +1,12 @@
 namespace Content.Server.NPC.HTN.Preconditions;
 
+/// <summary>
+/// Checks if there is no value at the specified  <see cref="KeyNotExistsPrecondition.Key"/> in the <see cref="NPCBlackboard"/>.
+/// Returns true if there is no value.
+/// </summary>
 public sealed partial class KeyNotExistsPrecondition : HTNPrecondition
 {
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables]
     public string Key = string.Empty;
 
     public override bool IsMet(NPCBlackboard blackboard)
index 8c7920e8be5c4258ae8b26081df80c90fb69b53d..2abb351272ff57c51db37da807ab57f6154cb278 100644 (file)
@@ -1,16 +1,17 @@
 namespace Content.Server.NPC.HTN.Preconditions.Math;
 
 /// <summary>
-/// Checks for the presence of data in the blackboard and makes a comparison with the specified boolean
+/// Checks if there is a bool value for the specified <see cref="KeyBoolEqualsPrecondition.Key"/>
+/// in the <see cref="NPCBlackboard"/> and the specified value is equal to the <see cref="KeyBoolEqualsPrecondition.Value"/>.
 /// </summary>
 public sealed partial class KeyBoolEqualsPrecondition : HTNPrecondition
 {
     [Dependency] private readonly IEntityManager _entManager = default!;
 
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables]
     public string Key = string.Empty;
 
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
     public bool Value;
 
     public override bool IsMet(NPCBlackboard blackboard)
index 802fdaf2b9c30550d4fbb56b43f42ee2efaaf003..0f7e2cca2af0602fa438bde9ad21710441a658c7 100644 (file)
@@ -1,13 +1,17 @@
 namespace Content.Server.NPC.HTN.Preconditions.Math;
 
+/// <summary>
+/// Checks if there is a float value for the specified <see cref="KeyFloatEqualsPrecondition.Key"/>
+/// in the <see cref="NPCBlackboard"/> and the specified value is equal to the <see cref="KeyFloatEqualsPrecondition.Value"/>.
+/// </summary>
 public sealed partial class KeyFloatEqualsPrecondition : HTNPrecondition
 {
     [Dependency] private readonly IEntityManager _entManager = default!;
 
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables]
     public string Key = string.Empty;
 
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
     public float Value;
 
     public override bool IsMet(NPCBlackboard blackboard)
index 3a9ac366980a0417a1fcac9f7f97ef2337010af2..b3a27a7d5debeb90d1e6d389cb364cfe2db14a1c 100644 (file)
@@ -1,13 +1,17 @@
 namespace Content.Server.NPC.HTN.Preconditions.Math;
 
+/// <summary>
+/// Checks if there is a float value for the specified <see cref="KeyFloatGreaterPrecondition.Key"/>
+/// in the <see cref="NPCBlackboard"/> and the specified value is greater then <see cref="KeyFloatGreaterPrecondition.Value"/>.
+/// </summary>
 public sealed partial class KeyFloatGreaterPrecondition : HTNPrecondition
 {
     [Dependency] private readonly IEntityManager _entManager = default!;
 
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables]
     public string Key = string.Empty;
 
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
     public float Value;
 
     public override bool IsMet(NPCBlackboard blackboard)
index 5cd51d7a7c573ebd8151c071c2f40b1d58b3bc90..c5eb35eebc430e9187182122c0b670a64785f92c 100644 (file)
@@ -1,13 +1,17 @@
 namespace Content.Server.NPC.HTN.Preconditions.Math;
 
+/// <summary>
+/// Checks if there is a float value for the specified <see cref="KeyFloatGreaterPrecondition.Key"/>
+/// in the <see cref="NPCBlackboard"/> and the specified value is less then <see cref="KeyFloatGreaterPrecondition.Value"/>.
+/// </summary>
 public sealed partial class KeyFloatLessPrecondition : HTNPrecondition
 {
     [Dependency] private readonly IEntityManager _entManager = default!;
 
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables]
     public string Key = string.Empty;
 
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables(VVAccess.ReadWrite)]
     public float Value;
 
     public override bool IsMet(NPCBlackboard blackboard)
index 00404517c9e0ad160adc24914780ff6e0ac1d9c4..f8ed20544ecc3bee579520c1e228604774a288d2 100644 (file)
@@ -4,13 +4,14 @@ using System.Threading.Tasks;
 namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
 
 /// <summary>
-/// Gets the key, and adds the value to that float
+/// Added <see cref="AddFloatOperator.Amount"/> to float value for the
+/// specified <see cref="AddFloatOperator.TargetKey"/> in the <see cref="NPCBlackboard"/>.
 /// </summary>
 public sealed partial class AddFloatOperator : HTNOperator
 {
     [Dependency] private readonly IEntityManager _entManager = default!;
 
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables]
     public string TargetKey = string.Empty;
 
     [DataField, ViewVariables(VVAccess.ReadWrite)]
index a40b96798d4aae26f963341077e5928523692413..f168326af7b0f0280efacb698777f74bdc779c60 100644 (file)
@@ -4,11 +4,12 @@ using System.Threading.Tasks;
 namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
 
 /// <summary>
-/// Just sets a blackboard key to a bool
+/// Set <see cref="SetBoolOperator.Value"/> to bool value for the
+/// specified <see cref="SetFloatOperator.TargetKey"/> in the <see cref="NPCBlackboard"/>.
 /// </summary>
 public sealed partial class SetBoolOperator : HTNOperator
 {
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables]
     public string TargetKey = string.Empty;
 
     [DataField, ViewVariables(VVAccess.ReadWrite)]
index 76842b431f70181d8ff358bdc34a009588e9386f..f9b5e54fe3eed9ce8f37f6ec0510ed32a8c2ce25 100644 (file)
@@ -4,11 +4,12 @@ using System.Threading.Tasks;
 namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
 
 /// <summary>
-/// Just sets a blackboard key to a float
+/// Set <see cref="SetFloatOperator.Amount"/> to float value for the
+/// specified <see cref="SetFloatOperator.TargetKey"/> in the <see cref="NPCBlackboard"/>.
 /// </summary>
 public sealed partial class SetFloatOperator : HTNOperator
 {
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables]
     public string TargetKey = string.Empty;
 
     [DataField, ViewVariables(VVAccess.ReadWrite)]
index 999756f1f74cb51de30684f8396027b70a9bc99a..edcab6baff5725de1fd9d69c50c6802bc6f95d8a 100644 (file)
@@ -5,20 +5,22 @@ using Robust.Shared.Random;
 namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
 
 /// <summary>
-/// Sets a random float from MinAmount to MaxAmount to blackboard
+/// Set random float value between <see cref="SetRandomFloatOperator.MinAmount"/> and
+/// <see cref="SetRandomFloatOperator.MaxAmount"/> specified <see cref="SetRandomFloatOperator.TargetKey"/>
+/// in the <see cref="NPCBlackboard"/>.
 /// </summary>
 public sealed partial class SetRandomFloatOperator : HTNOperator
 {
     [Dependency] private readonly IRobustRandom _random = default!;
 
-    [DataField(required: true)]
+    [DataField(required: true), ViewVariables]
     public string TargetKey = string.Empty;
 
     [DataField, ViewVariables(VVAccess.ReadWrite)]
     public float MaxAmount = 1f;
 
     [DataField, ViewVariables(VVAccess.ReadWrite)]
-    public float MinAmount = 0f;
+    public float MinAmount;
 
     public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard,
         CancellationToken cancelToken)
index d1c7d619150291fd0e5b1185f59a3fed70e5fe0e..558b1fc04dc62b2558b242d10b52a7392067b718 100644 (file)
@@ -20,7 +20,8 @@ public sealed partial class SayKeyOperator : HTNOperator
     public override void Initialize(IEntitySystemManager sysManager)
     {
         base.Initialize(sysManager);
-        _chat = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>();
+
+        _chat = sysManager.GetEntitySystem<ChatSystem>();
     }
 
     public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
@@ -28,8 +29,12 @@ public sealed partial class SayKeyOperator : HTNOperator
         if (!blackboard.TryGetValue<object>(Key, out var value, _entManager))
             return HTNOperatorStatus.Failed;
 
+        var @string = value.ToString();
+        if (@string is not { })
+            return HTNOperatorStatus.Failed;
+
         var speaker = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
-        _chat.TrySendInGameICMessage(speaker, value.ToString() ?? "Oh no...", InGameICChatType.Speak, hideChat: Hidden, hideLog: Hidden);
+        _chat.TrySendInGameICMessage(speaker, @string, InGameICChatType.Speak, hideChat: Hidden, hideLog: Hidden);
 
         return base.Update(blackboard, frameTime);
     }
index cf07831959bda1bb4cb94c036335615a3d18c91f..8a4c655a39b5d18f2d631445275b43249763c2a2 100644 (file)
@@ -6,7 +6,7 @@ public sealed partial class SpeakOperator : HTNOperator
 {
     private ChatSystem _chat = default!;
 
-    [DataField("speech", required: true)]
+    [DataField(required: true)]
     public string Speech = string.Empty;
 
     /// <summary>
@@ -18,14 +18,15 @@ public sealed partial class SpeakOperator : HTNOperator
     public override void Initialize(IEntitySystemManager sysManager)
     {
         base.Initialize(sysManager);
-        _chat = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ChatSystem>();
+
+        _chat = sysManager.GetEntitySystem<ChatSystem>();
     }
 
     public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
     {
         var speaker = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
-
         _chat.TrySendInGameICMessage(speaker, Loc.GetString(Speech), InGameICChatType.Speak, hideChat: Hidden, hideLog: Hidden);
+
         return base.Update(blackboard, frameTime);
     }
 }