MobStateSystem.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Content.Shared.ActionBlocker;
  2. using Content.Shared.Administration.Logs;
  3. using Content.Shared.Mobs.Components;
  4. using Content.Shared.Standing;
  5. using Robust.Shared.Physics.Systems;
  6. using Robust.Shared.Timing;
  7. namespace Content.Shared.Mobs.Systems;
  8. [Virtual]
  9. public partial class MobStateSystem : EntitySystem
  10. {
  11. [Dependency] private readonly ActionBlockerSystem _blocker = default!;
  12. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  13. [Dependency] private readonly StandingStateSystem _standing = default!;
  14. [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
  15. [Dependency] private readonly ILogManager _logManager = default!;
  16. [Dependency] private readonly IGameTiming _timing = default!;
  17. private ISawmill _sawmill = default!;
  18. private EntityQuery<MobStateComponent> _mobStateQuery;
  19. public override void Initialize()
  20. {
  21. _sawmill = _logManager.GetSawmill("MobState");
  22. _mobStateQuery = GetEntityQuery<MobStateComponent>();
  23. base.Initialize();
  24. SubscribeEvents();
  25. }
  26. #region Public API
  27. /// <summary>
  28. /// Check if a Mob is Alive
  29. /// </summary>
  30. /// <param name="target">Target Entity</param>
  31. /// <param name="component">The MobState component owned by the target</param>
  32. /// <returns>If the entity is alive</returns>
  33. public bool IsAlive(EntityUid target, MobStateComponent? component = null)
  34. {
  35. if (!_mobStateQuery.Resolve(target, ref component, false))
  36. return false;
  37. return component.CurrentState == MobState.Alive;
  38. }
  39. /// <summary>
  40. /// Check if a Mob is Critical
  41. /// </summary>
  42. /// <param name="target">Target Entity</param>
  43. /// <param name="component">The MobState component owned by the target</param>
  44. /// <returns>If the entity is Critical</returns>
  45. public bool IsCritical(EntityUid target, MobStateComponent? component = null)
  46. {
  47. if (!_mobStateQuery.Resolve(target, ref component, false))
  48. return false;
  49. return component.CurrentState == MobState.Critical;
  50. }
  51. /// <summary>
  52. /// Check if a Mob is Dead
  53. /// </summary>
  54. /// <param name="target">Target Entity</param>
  55. /// <param name="component">The MobState component owned by the target</param>
  56. /// <returns>If the entity is Dead</returns>
  57. public bool IsDead(EntityUid target, MobStateComponent? component = null)
  58. {
  59. if (!_mobStateQuery.Resolve(target, ref component, false))
  60. return false;
  61. return component.CurrentState == MobState.Dead;
  62. }
  63. /// <summary>
  64. /// Check if a Mob is Critical or Dead
  65. /// </summary>
  66. /// <param name="target">Target Entity</param>
  67. /// <param name="component">The MobState component owned by the target</param>
  68. /// <returns>If the entity is Critical or Dead</returns>
  69. public bool IsIncapacitated(EntityUid target, MobStateComponent? component = null)
  70. {
  71. if (!_mobStateQuery.Resolve(target, ref component, false))
  72. return false;
  73. return component.CurrentState is MobState.Critical or MobState.Dead;
  74. }
  75. /// <summary>
  76. /// Check if a Mob is in an Invalid state
  77. /// </summary>
  78. /// <param name="target">Target Entity</param>
  79. /// <param name="component">The MobState component owned by the target</param>
  80. /// <returns>If the entity is in an Invalid State</returns>
  81. public bool IsInvalidState(EntityUid target, MobStateComponent? component = null)
  82. {
  83. if (!_mobStateQuery.Resolve(target, ref component, false))
  84. return false;
  85. return component.CurrentState is MobState.Invalid;
  86. }
  87. #endregion
  88. }