1
0

RandomWalkComponent.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Numerics;
  2. using Content.Server.Physics.Controllers;
  3. namespace Content.Server.Physics.Components;
  4. /// <summary>
  5. /// A component which makes its entity move around at random.
  6. /// </summary>
  7. [RegisterComponent]
  8. public sealed partial class RandomWalkComponent : Component
  9. {
  10. /// <summary>
  11. /// The minimum speed at which this entity will move.
  12. /// </summary>
  13. [DataField("minSpeed")]
  14. [ViewVariables(VVAccess.ReadWrite)]
  15. public float MinSpeed = 7.5f;
  16. /// <summary>
  17. /// The maximum speed at which this entity will move.
  18. /// </summary>
  19. [DataField("maxSpeed")]
  20. [ViewVariables(VVAccess.ReadWrite)]
  21. public float MaxSpeed = 10f;
  22. /// <summary>
  23. /// The amount of speed carried over when the speed updates.
  24. /// </summary>
  25. [DataField("accumulatorRatio")]
  26. [ViewVariables(VVAccess.ReadWrite)]
  27. public float AccumulatorRatio = 0.0f;
  28. /// <summary>
  29. /// The vector by which the random walk direction is biased.
  30. /// </summary>
  31. [DataField, ViewVariables(VVAccess.ReadWrite)]
  32. public Vector2 BiasVector = new Vector2(0f, 0f);
  33. /// <summary>
  34. /// Whether to set BiasVector to (0, 0) every random walk update.
  35. /// </summary>
  36. [DataField, ViewVariables(VVAccess.ReadWrite)]
  37. public bool ResetBiasOnWalk = true;
  38. /// <summary>
  39. /// Whether this random walker should take a step immediately when it starts up.
  40. /// </summary>
  41. [DataField("stepOnStartup")]
  42. [ViewVariables(VVAccess.ReadOnly)]
  43. public bool StepOnStartup = false;
  44. #region Update Timing
  45. /// <summary>
  46. /// The minimum amount of time between speed updates.
  47. /// </summary>
  48. [DataField("minStepCooldown")]
  49. [ViewVariables(VVAccess.ReadWrite)]
  50. public TimeSpan MinStepCooldown { get; internal set; } = TimeSpan.FromSeconds(2.0);
  51. /// <summary>
  52. /// The maximum amount of time between speed updates.
  53. /// </summary>
  54. [DataField("maxStepCooldown")]
  55. [ViewVariables(VVAccess.ReadWrite)]
  56. public TimeSpan MaxStepCooldown { get; internal set; } = TimeSpan.FromSeconds(5.0);
  57. /// <summary>
  58. /// The next time this should update its speed.
  59. /// </summary>
  60. [ViewVariables(VVAccess.ReadWrite)]
  61. [Access(typeof(RandomWalkController))]
  62. public TimeSpan NextStepTime { get; internal set; } = default!;
  63. #endregion Update Timing
  64. }