Use EntityQuery for mob state system resolves (#29021)
This commit is contained in:
@@ -16,7 +16,8 @@ public partial class MobStateSystem
|
|||||||
/// <returns>If the entity can be set to that MobState</returns>
|
/// <returns>If the entity can be set to that MobState</returns>
|
||||||
public bool HasState(EntityUid entity, MobState mobState, MobStateComponent? component = null)
|
public bool HasState(EntityUid entity, MobState mobState, MobStateComponent? component = null)
|
||||||
{
|
{
|
||||||
return Resolve(entity, ref component, false) && component.AllowedStates.Contains(mobState);
|
return _mobStateQuery.Resolve(entity, ref component, false) &&
|
||||||
|
component.AllowedStates.Contains(mobState);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -27,7 +28,7 @@ public partial class MobStateSystem
|
|||||||
/// <param name="origin">Entity that caused the state update (if applicable)</param>
|
/// <param name="origin">Entity that caused the state update (if applicable)</param>
|
||||||
public void UpdateMobState(EntityUid entity, MobStateComponent? component = null, EntityUid? origin = null)
|
public void UpdateMobState(EntityUid entity, MobStateComponent? component = null, EntityUid? origin = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(entity, ref component))
|
if (!_mobStateQuery.Resolve(entity, ref component))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var ev = new UpdateMobStateEvent {Target = entity, Component = component, Origin = origin};
|
var ev = new UpdateMobStateEvent {Target = entity, Component = component, Origin = origin};
|
||||||
@@ -46,7 +47,7 @@ public partial class MobStateSystem
|
|||||||
public void ChangeMobState(EntityUid entity, MobState mobState, MobStateComponent? component = null,
|
public void ChangeMobState(EntityUid entity, MobState mobState, MobStateComponent? component = null,
|
||||||
EntityUid? origin = null)
|
EntityUid? origin = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(entity, ref component))
|
if (!_mobStateQuery.Resolve(entity, ref component))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ChangeState(entity, component, mobState, origin: origin);
|
ChangeState(entity, component, mobState, origin: origin);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ using Content.Shared.ActionBlocker;
|
|||||||
using Content.Shared.Administration.Logs;
|
using Content.Shared.Administration.Logs;
|
||||||
using Content.Shared.Mobs.Components;
|
using Content.Shared.Mobs.Components;
|
||||||
using Content.Shared.Standing;
|
using Content.Shared.Standing;
|
||||||
using Robust.Shared.GameStates;
|
|
||||||
using Robust.Shared.Physics.Systems;
|
using Robust.Shared.Physics.Systems;
|
||||||
using Robust.Shared.Timing;
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
@@ -20,9 +19,12 @@ public partial class MobStateSystem : EntitySystem
|
|||||||
[Dependency] private readonly IGameTiming _timing = default!;
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
private ISawmill _sawmill = default!;
|
private ISawmill _sawmill = default!;
|
||||||
|
|
||||||
|
private EntityQuery<MobStateComponent> _mobStateQuery;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
_sawmill = _logManager.GetSawmill("MobState");
|
_sawmill = _logManager.GetSawmill("MobState");
|
||||||
|
_mobStateQuery = GetEntityQuery<MobStateComponent>();
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeEvents();
|
SubscribeEvents();
|
||||||
}
|
}
|
||||||
@@ -37,7 +39,7 @@ public partial class MobStateSystem : EntitySystem
|
|||||||
/// <returns>If the entity is alive</returns>
|
/// <returns>If the entity is alive</returns>
|
||||||
public bool IsAlive(EntityUid target, MobStateComponent? component = null)
|
public bool IsAlive(EntityUid target, MobStateComponent? component = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(target, ref component, false))
|
if (!_mobStateQuery.Resolve(target, ref component, false))
|
||||||
return false;
|
return false;
|
||||||
return component.CurrentState == MobState.Alive;
|
return component.CurrentState == MobState.Alive;
|
||||||
}
|
}
|
||||||
@@ -50,7 +52,7 @@ public partial class MobStateSystem : EntitySystem
|
|||||||
/// <returns>If the entity is Critical</returns>
|
/// <returns>If the entity is Critical</returns>
|
||||||
public bool IsCritical(EntityUid target, MobStateComponent? component = null)
|
public bool IsCritical(EntityUid target, MobStateComponent? component = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(target, ref component, false))
|
if (!_mobStateQuery.Resolve(target, ref component, false))
|
||||||
return false;
|
return false;
|
||||||
return component.CurrentState == MobState.Critical;
|
return component.CurrentState == MobState.Critical;
|
||||||
}
|
}
|
||||||
@@ -63,7 +65,7 @@ public partial class MobStateSystem : EntitySystem
|
|||||||
/// <returns>If the entity is Dead</returns>
|
/// <returns>If the entity is Dead</returns>
|
||||||
public bool IsDead(EntityUid target, MobStateComponent? component = null)
|
public bool IsDead(EntityUid target, MobStateComponent? component = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(target, ref component, false))
|
if (!_mobStateQuery.Resolve(target, ref component, false))
|
||||||
return false;
|
return false;
|
||||||
return component.CurrentState == MobState.Dead;
|
return component.CurrentState == MobState.Dead;
|
||||||
}
|
}
|
||||||
@@ -76,7 +78,7 @@ public partial class MobStateSystem : EntitySystem
|
|||||||
/// <returns>If the entity is Critical or Dead</returns>
|
/// <returns>If the entity is Critical or Dead</returns>
|
||||||
public bool IsIncapacitated(EntityUid target, MobStateComponent? component = null)
|
public bool IsIncapacitated(EntityUid target, MobStateComponent? component = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(target, ref component, false))
|
if (!_mobStateQuery.Resolve(target, ref component, false))
|
||||||
return false;
|
return false;
|
||||||
return component.CurrentState is MobState.Critical or MobState.Dead;
|
return component.CurrentState is MobState.Critical or MobState.Dead;
|
||||||
}
|
}
|
||||||
@@ -89,14 +91,10 @@ public partial class MobStateSystem : EntitySystem
|
|||||||
/// <returns>If the entity is in an Invalid State</returns>
|
/// <returns>If the entity is in an Invalid State</returns>
|
||||||
public bool IsInvalidState(EntityUid target, MobStateComponent? component = null)
|
public bool IsInvalidState(EntityUid target, MobStateComponent? component = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(target, ref component, false))
|
if (!_mobStateQuery.Resolve(target, ref component, false))
|
||||||
return false;
|
return false;
|
||||||
return component.CurrentState is MobState.Invalid;
|
return component.CurrentState is MobState.Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Implementation
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user