HTNComponent.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Threading;
  2. using Content.Server.NPC.Components;
  3. namespace Content.Server.NPC.HTN;
  4. [RegisterComponent]
  5. public sealed partial class HTNComponent : NPCComponent
  6. {
  7. /// <summary>
  8. /// The base task to use for planning
  9. /// </summary>
  10. [ViewVariables(VVAccess.ReadWrite),
  11. DataField("rootTask", required: true)]
  12. public HTNCompoundTask RootTask = default!;
  13. /// <summary>
  14. /// Check any active services for our current plan. This is used to find new targets for example without changing our plan.
  15. /// </summary>
  16. [DataField("checkServices")]
  17. public bool CheckServices = true;
  18. /// <summary>
  19. /// The NPC's current plan.
  20. /// </summary>
  21. [ViewVariables]
  22. public HTNPlan? Plan;
  23. /// <summary>
  24. /// How long to wait after having planned to try planning again.
  25. /// </summary>
  26. [ViewVariables(VVAccess.ReadWrite), DataField("planCooldown")]
  27. public float PlanCooldown = 0.45f;
  28. /// <summary>
  29. /// How much longer until we can try re-planning. This will happen even during update in case something changed.
  30. /// </summary>
  31. [ViewVariables(VVAccess.ReadWrite)]
  32. public float PlanAccumulator = 0f;
  33. [ViewVariables]
  34. public HTNPlanJob? PlanningJob = null;
  35. [ViewVariables]
  36. public CancellationTokenSource? PlanningToken = null;
  37. /// <summary>
  38. /// Is this NPC currently planning?
  39. /// </summary>
  40. [ViewVariables] public bool Planning => PlanningJob != null;
  41. /// <summary>
  42. /// Determines whether plans should be made / updated for this entity
  43. /// </summary>
  44. [DataField]
  45. public bool Enabled = true;
  46. }