Files
tbd-station-14/Content.Shared/Mobs/Systems/MobStateSystem.cs
Hannah Giovanna Dawson cdbe92d37d Update DamageableSystem to modern standards (#39417)
* Update DamageableSystem to modern standards

* DamageContainerId -> DamageContainerID with lint flag

* Replace strings with protoids

* Make CVar subscription declarations all consistently whitespaced

* ChangeDamage -> TryChangeDamage, cope with C# jank

* Revert event signature changes

* Restore a comment

* Re-add two queries

* Init the queries

* Use appearanceQuery in DamageChanged

* Use damageableQuery in TryChangeDamage

* Use damageableQuery in SetDamageModifierSetId

* Final cleanup, fix sandboxing

* Rectify ExplosionSystem:::ProcessEntity's call to TryChangeDamage

* Re-organize DamageableSystem

* first big fuck you breaking change.

* THATS A LOT OF DAMAGE!!!

* Fix test fails

* test fixes 2

* push it

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2025-10-27 19:53:04 +00:00

101 lines
3.7 KiB
C#

using Content.Shared.ActionBlocker;
using Content.Shared.Administration.Logs;
using Content.Shared.Damage.Systems;
using Content.Shared.Mobs.Components;
using Content.Shared.Standing;
using Robust.Shared.Timing;
namespace Content.Shared.Mobs.Systems;
[Virtual]
public partial class MobStateSystem : EntitySystem
{
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly StandingStateSystem _standing = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
private ISawmill _sawmill = default!;
private EntityQuery<MobStateComponent> _mobStateQuery;
public override void Initialize()
{
_sawmill = _logManager.GetSawmill("MobState");
_mobStateQuery = GetEntityQuery<MobStateComponent>();
base.Initialize();
SubscribeEvents();
}
#region Public API
/// <summary>
/// Check if a Mob is Alive
/// </summary>
/// <param name="target">Target Entity</param>
/// <param name="component">The MobState component owned by the target</param>
/// <returns>If the entity is alive</returns>
public bool IsAlive(EntityUid target, MobStateComponent? component = null)
{
if (!_mobStateQuery.Resolve(target, ref component, false))
return false;
return component.CurrentState == MobState.Alive;
}
/// <summary>
/// Check if a Mob is Critical
/// </summary>
/// <param name="target">Target Entity</param>
/// <param name="component">The MobState component owned by the target</param>
/// <returns>If the entity is Critical</returns>
public bool IsCritical(EntityUid target, MobStateComponent? component = null)
{
if (!_mobStateQuery.Resolve(target, ref component, false))
return false;
return component.CurrentState == MobState.Critical;
}
/// <summary>
/// Check if a Mob is Dead
/// </summary>
/// <param name="target">Target Entity</param>
/// <param name="component">The MobState component owned by the target</param>
/// <returns>If the entity is Dead</returns>
public bool IsDead(EntityUid target, MobStateComponent? component = null)
{
if (!_mobStateQuery.Resolve(target, ref component, false))
return false;
return component.CurrentState == MobState.Dead;
}
/// <summary>
/// Check if a Mob is Critical or Dead
/// </summary>
/// <param name="target">Target Entity</param>
/// <param name="component">The MobState component owned by the target</param>
/// <returns>If the entity is Critical or Dead</returns>
public bool IsIncapacitated(EntityUid target, MobStateComponent? component = null)
{
if (!_mobStateQuery.Resolve(target, ref component, false))
return false;
return component.CurrentState is MobState.Critical or MobState.Dead;
}
/// <summary>
/// Check if a Mob is in an Invalid state
/// </summary>
/// <param name="target">Target Entity</param>
/// <param name="component">The MobState component owned by the target</param>
/// <returns>If the entity is in an Invalid State</returns>
public bool IsInvalidState(EntityUid target, MobStateComponent? component = null)
{
if (!_mobStateQuery.Resolve(target, ref component, false))
return false;
return component.CurrentState is MobState.Invalid;
}
#endregion
}