From a29b6a6894f8197be392bfd1c90085b8ea80f86c Mon Sep 17 00:00:00 2001
From: Tornado Tech <54727692+Tornado-Technology@users.noreply.github.com>
Date: Sun, 2 Jun 2024 03:46:35 +1000
Subject: [PATCH] Clean up new HTNs tasks (#28469)
* Clean up new HTNs tasks
* Added docs to math operations
---
.../NPC/HTN/Preconditions/KeyExistsPrecondition.cs | 7 ++++++-
.../NPC/HTN/Preconditions/KeyNotExistsPrecondition.cs | 6 +++++-
.../HTN/Preconditions/Math/KeyBoolEqualsPrecondition.cs | 7 ++++---
.../HTN/Preconditions/Math/KeyFloatEqualsPrecondition.cs | 8 ++++++--
.../Preconditions/Math/KeyFloatGreaterPrecondition.cs | 8 ++++++--
.../HTN/Preconditions/Math/KeyFloatLessPrecondition.cs | 8 ++++++--
.../PrimitiveTasks/Operators/Math/AddFloatOperator.cs | 5 +++--
.../HTN/PrimitiveTasks/Operators/Math/SetBoolOperator.cs | 5 +++--
.../PrimitiveTasks/Operators/Math/SetFloatOperator.cs | 5 +++--
.../Operators/Math/SetRandomFloatOperator.cs | 8 +++++---
.../NPC/HTN/PrimitiveTasks/Operators/SayKeyOperator.cs | 9 +++++++--
.../NPC/HTN/PrimitiveTasks/Operators/SpeakOperator.cs | 7 ++++---
12 files changed, 58 insertions(+), 25 deletions(-)
diff --git a/Content.Server/NPC/HTN/Preconditions/KeyExistsPrecondition.cs b/Content.Server/NPC/HTN/Preconditions/KeyExistsPrecondition.cs
index 72c4e6367f..69e265f276 100644
--- a/Content.Server/NPC/HTN/Preconditions/KeyExistsPrecondition.cs
+++ b/Content.Server/NPC/HTN/Preconditions/KeyExistsPrecondition.cs
@@ -1,8 +1,13 @@
namespace Content.Server.NPC.HTN.Preconditions;
+///
+/// Checks for the presence of the value by the specified in the .
+/// Returns true if there is a value.
+///
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)
{
diff --git a/Content.Server/NPC/HTN/Preconditions/KeyNotExistsPrecondition.cs b/Content.Server/NPC/HTN/Preconditions/KeyNotExistsPrecondition.cs
index c12663901c..8dc38e442a 100644
--- a/Content.Server/NPC/HTN/Preconditions/KeyNotExistsPrecondition.cs
+++ b/Content.Server/NPC/HTN/Preconditions/KeyNotExistsPrecondition.cs
@@ -1,8 +1,12 @@
namespace Content.Server.NPC.HTN.Preconditions;
+///
+/// Checks if there is no value at the specified in the .
+/// Returns true if there is no value.
+///
public sealed partial class KeyNotExistsPrecondition : HTNPrecondition
{
- [DataField(required: true)]
+ [DataField(required: true), ViewVariables]
public string Key = string.Empty;
public override bool IsMet(NPCBlackboard blackboard)
diff --git a/Content.Server/NPC/HTN/Preconditions/Math/KeyBoolEqualsPrecondition.cs b/Content.Server/NPC/HTN/Preconditions/Math/KeyBoolEqualsPrecondition.cs
index 8c7920e8be..2abb351272 100644
--- a/Content.Server/NPC/HTN/Preconditions/Math/KeyBoolEqualsPrecondition.cs
+++ b/Content.Server/NPC/HTN/Preconditions/Math/KeyBoolEqualsPrecondition.cs
@@ -1,16 +1,17 @@
namespace Content.Server.NPC.HTN.Preconditions.Math;
///
-/// 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
+/// in the and the specified value is equal to the .
///
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)
diff --git a/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatEqualsPrecondition.cs b/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatEqualsPrecondition.cs
index 802fdaf2b9..0f7e2cca2a 100644
--- a/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatEqualsPrecondition.cs
+++ b/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatEqualsPrecondition.cs
@@ -1,13 +1,17 @@
namespace Content.Server.NPC.HTN.Preconditions.Math;
+///
+/// Checks if there is a float value for the specified
+/// in the and the specified value is equal to the .
+///
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)
diff --git a/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatGreaterPrecondition.cs b/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatGreaterPrecondition.cs
index 3a9ac36698..b3a27a7d5d 100644
--- a/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatGreaterPrecondition.cs
+++ b/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatGreaterPrecondition.cs
@@ -1,13 +1,17 @@
namespace Content.Server.NPC.HTN.Preconditions.Math;
+///
+/// Checks if there is a float value for the specified
+/// in the and the specified value is greater then .
+///
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)
diff --git a/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatLessPrecondition.cs b/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatLessPrecondition.cs
index 5cd51d7a7c..c5eb35eebc 100644
--- a/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatLessPrecondition.cs
+++ b/Content.Server/NPC/HTN/Preconditions/Math/KeyFloatLessPrecondition.cs
@@ -1,13 +1,17 @@
namespace Content.Server.NPC.HTN.Preconditions.Math;
+///
+/// Checks if there is a float value for the specified
+/// in the and the specified value is less then .
+///
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)
diff --git a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/AddFloatOperator.cs b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/AddFloatOperator.cs
index 00404517c9..f8ed20544e 100644
--- a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/AddFloatOperator.cs
+++ b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/AddFloatOperator.cs
@@ -4,13 +4,14 @@ using System.Threading.Tasks;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
///
-/// Gets the key, and adds the value to that float
+/// Added to float value for the
+/// specified in the .
///
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)]
diff --git a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetBoolOperator.cs b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetBoolOperator.cs
index a40b96798d..f168326af7 100644
--- a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetBoolOperator.cs
+++ b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetBoolOperator.cs
@@ -4,11 +4,12 @@ using System.Threading.Tasks;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
///
-/// Just sets a blackboard key to a bool
+/// Set to bool value for the
+/// specified in the .
///
public sealed partial class SetBoolOperator : HTNOperator
{
- [DataField(required: true)]
+ [DataField(required: true), ViewVariables]
public string TargetKey = string.Empty;
[DataField, ViewVariables(VVAccess.ReadWrite)]
diff --git a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetFloatOperator.cs b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetFloatOperator.cs
index 76842b431f..f9b5e54fe3 100644
--- a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetFloatOperator.cs
+++ b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetFloatOperator.cs
@@ -4,11 +4,12 @@ using System.Threading.Tasks;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
///
-/// Just sets a blackboard key to a float
+/// Set to float value for the
+/// specified in the .
///
public sealed partial class SetFloatOperator : HTNOperator
{
- [DataField(required: true)]
+ [DataField(required: true), ViewVariables]
public string TargetKey = string.Empty;
[DataField, ViewVariables(VVAccess.ReadWrite)]
diff --git a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetRandomFloatOperator.cs b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetRandomFloatOperator.cs
index 999756f1f7..edcab6baff 100644
--- a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetRandomFloatOperator.cs
+++ b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/Math/SetRandomFloatOperator.cs
@@ -5,20 +5,22 @@ using Robust.Shared.Random;
namespace Content.Server.NPC.HTN.PrimitiveTasks.Operators.Math;
///
-/// Sets a random float from MinAmount to MaxAmount to blackboard
+/// Set random float value between and
+/// specified
+/// in the .
///
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? Effects)> Plan(NPCBlackboard blackboard,
CancellationToken cancelToken)
diff --git a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/SayKeyOperator.cs b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/SayKeyOperator.cs
index d1c7d61915..558b1fc04d 100644
--- a/Content.Server/NPC/HTN/PrimitiveTasks/Operators/SayKeyOperator.cs
+++ b/Content.Server/NPC/HTN/PrimitiveTasks/Operators/SayKeyOperator.cs
@@ -20,7 +20,8 @@ public sealed partial class SayKeyOperator : HTNOperator
public override void Initialize(IEntitySystemManager sysManager)
{
base.Initialize(sysManager);
- _chat = IoCManager.Resolve().GetEntitySystem();
+
+ _chat = sysManager.GetEntitySystem();
}
public override HTNOperatorStatus Update(NPCBlackboard blackboard, float frameTime)
@@ -28,8 +29,12 @@ public sealed partial class SayKeyOperator : HTNOperator
if (!blackboard.TryGetValue