Remove all but 1 IsIncapacitated (#10661)

This commit is contained in:
metalgearsloth
2022-08-25 23:56:56 +10:00
committed by GitHub
parent 1e9e93a33c
commit 9b84c1a9fd
7 changed files with 69 additions and 50 deletions

View File

@@ -1,5 +1,5 @@
using Content.Client.Pointing.Components; using Content.Client.Pointing.Components;
using Content.Shared.MobState.Components; using Content.Shared.MobState.EntitySystems;
using Content.Shared.Pointing; using Content.Shared.Pointing;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
@@ -7,8 +7,10 @@ using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Client.Pointing; namespace Content.Client.Pointing;
internal sealed class PointingSystem : EntitySystem public sealed class PointingSystem : EntitySystem
{ {
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -33,7 +35,7 @@ internal sealed class PointingSystem : EntitySystem
// Can the user point? Checking mob state directly instead of some action blocker, as many action blockers are blocked for // Can the user point? Checking mob state directly instead of some action blocker, as many action blockers are blocked for
// ghosts and there is no obvious choice for pointing (unless ghosts CanEmote?). // ghosts and there is no obvious choice for pointing (unless ghosts CanEmote?).
if (TryComp(args.User, out MobStateComponent? mob) && mob.IsIncapacitated()) if (_mobState.IsIncapacitated(args.User))
return; return;
// We won't check in range or visibility, as this verb is currently only executable via the context menu, // We won't check in range or visibility, as this verb is currently only executable via the context menu,

View File

@@ -9,6 +9,7 @@ using Content.Shared.Body.Components;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.MobState.Components; using Content.Shared.MobState.Components;
using Content.Shared.MobState.EntitySystems;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -18,14 +19,15 @@ namespace Content.Server.Body.Systems
[UsedImplicitly] [UsedImplicitly]
public sealed class RespiratorSystem : EntitySystem public sealed class RespiratorSystem : EntitySystem
{ {
[Dependency] private readonly DamageableSystem _damageableSys = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly LungSystem _lungSystem = default!;
[Dependency] private readonly AtmosphereSystem _atmosSys = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly AtmosphereSystem _atmosSys = default!;
[Dependency] private readonly BodySystem _bodySystem = default!;
[Dependency] private readonly DamageableSystem _damageableSys = default!;
[Dependency] private readonly LungSystem _lungSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -44,8 +46,8 @@ namespace Content.Server.Body.Systems
EntityManager.EntityQuery<RespiratorComponent, SharedBodyComponent>()) EntityManager.EntityQuery<RespiratorComponent, SharedBodyComponent>())
{ {
var uid = respirator.Owner; var uid = respirator.Owner;
if (!EntityManager.TryGetComponent<MobStateComponent>(uid, out var state) ||
state.IsDead()) if (_mobState.IsDead(uid))
{ {
continue; continue;
} }
@@ -57,7 +59,7 @@ namespace Content.Server.Body.Systems
respirator.AccumulatedFrametime -= respirator.CycleDelay; respirator.AccumulatedFrametime -= respirator.CycleDelay;
UpdateSaturation(respirator.Owner, -respirator.CycleDelay, respirator); UpdateSaturation(respirator.Owner, -respirator.CycleDelay, respirator);
if (!state.IsIncapacitated()) // cannot breathe in crit. if (!_mobState.IsIncapacitated(uid)) // cannot breathe in crit.
{ {
switch (respirator.Status) switch (respirator.Status)
{ {
@@ -100,10 +102,11 @@ namespace Content.Server.Body.Systems
var ev = new InhaleLocationEvent(); var ev = new InhaleLocationEvent();
RaiseLocalEvent(uid, ev, false); RaiseLocalEvent(uid, ev, false);
ev.Gas ??= _atmosSys.GetContainingMixture(uid, false, true);
if (ev.Gas == null) if (ev.Gas == null)
{ {
ev.Gas = _atmosSys.GetContainingMixture(uid, false, true); return;
if (ev.Gas == null) return;
} }
var ratio = (Atmospherics.BreathVolume / ev.Gas.Volume); var ratio = (Atmospherics.BreathVolume / ev.Gas.Volume);

View File

@@ -69,13 +69,14 @@ public sealed partial class ChemistrySystem
} }
else if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Draw) else if (component.ToggleState == SharedInjectorComponent.InjectorToggleMode.Draw)
{ {
/// Draw from a bloodstream, if the target has that // Draw from a bloodstream, if the target has that
if (TryComp<BloodstreamComponent>(target, out var stream)) if (TryComp<BloodstreamComponent>(target, out var stream))
{ {
TryDraw(component, target, stream.BloodSolution, user, stream); TryDraw(component, target, stream.BloodSolution, user, stream);
return; return;
} }
/// Draw from an object (food, beaker, etc)
// Draw from an object (food, beaker, etc)
if (_solutions.TryGetDrawableSolution(target, out var drawableSolution)) if (_solutions.TryGetDrawableSolution(target, out var drawableSolution))
{ {
TryDraw(component, target, drawableSolution, user); TryDraw(component, target, drawableSolution, user);
@@ -111,7 +112,8 @@ public sealed partial class ChemistrySystem
private void OnInjectorAfterInteract(EntityUid uid, InjectorComponent component, AfterInteractEvent args) private void OnInjectorAfterInteract(EntityUid uid, InjectorComponent component, AfterInteractEvent args)
{ {
if (args.Handled || !args.CanReach) return; if (args.Handled || !args.CanReach)
return;
if (component.CancelToken != null) if (component.CancelToken != null)
{ {
@@ -146,7 +148,8 @@ public sealed partial class ChemistrySystem
private void OnInjectorUse(EntityUid uid, InjectorComponent component, UseInHandEvent args) private void OnInjectorUse(EntityUid uid, InjectorComponent component, UseInHandEvent args)
{ {
if (args.Handled) return; if (args.Handled)
return;
Toggle(component, args.User); Toggle(component, args.User);
args.Handled = true; args.Handled = true;
@@ -200,11 +203,11 @@ public sealed partial class ChemistrySystem
("user", userName)), user, Filter.Entities(target)); ("user", userName)), user, Filter.Entities(target));
// Check if the target is incapacitated or in combat mode and modify time accordingly. // Check if the target is incapacitated or in combat mode and modify time accordingly.
if (TryComp<MobStateComponent>(target, out var mobState) && mobState.IsIncapacitated()) if (_mobState.IsIncapacitated(target))
{ {
actualDelay /= 2; actualDelay /= 2;
} }
else if (TryComp<CombatModeComponent>(target, out var combat) && combat.IsInCombatMode) else if (_combat.IsInCombatMode(target))
{ {
// Slightly increase the delay when the target is in combat mode. Helps prevents cheese injections in // Slightly increase the delay when the target is in combat mode. Helps prevents cheese injections in
// combat with fast syringes & lag. // combat with fast syringes & lag.

View File

@@ -2,6 +2,8 @@ using Content.Server.Administration.Logs;
using Content.Server.Body.Systems; using Content.Server.Body.Systems;
using Content.Server.DoAfter; using Content.Server.DoAfter;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Shared.CombatMode;
using Content.Shared.MobState.EntitySystems;
namespace Content.Server.Chemistry.EntitySystems; namespace Content.Server.Chemistry.EntitySystems;
@@ -11,6 +13,8 @@ public sealed partial class ChemistrySystem : EntitySystem
[Dependency] private readonly BloodstreamSystem _blood = default!; [Dependency] private readonly BloodstreamSystem _blood = default!;
[Dependency] private readonly DoAfterSystem _doAfter = default!; [Dependency] private readonly DoAfterSystem _doAfter = default!;
[Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
[Dependency] private readonly SharedCombatModeSystem _combat = default!;
[Dependency] private readonly SolutionContainerSystem _solutions = default!; [Dependency] private readonly SolutionContainerSystem _solutions = default!;
public override void Initialize() public override void Initialize()

View File

@@ -3,21 +3,22 @@ using Content.Server.Hands.Components;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Cuffs; using Content.Shared.Cuffs;
using Content.Shared.Hands; using Content.Shared.Hands;
using Content.Shared.MobState.Components;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Player; using Robust.Shared.Player;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Robust.Shared.Audio; using Content.Shared.MobState.EntitySystems;
namespace Content.Server.Cuffs namespace Content.Server.Cuffs
{ {
[UsedImplicitly] [UsedImplicitly]
public sealed class CuffableSystem : SharedCuffableSystem public sealed class CuffableSystem : SharedCuffableSystem
{ {
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -41,9 +42,11 @@ namespace Content.Server.Cuffs
if (args.User != args.Target && !args.CanInteract) if (args.User != args.Target && !args.CanInteract)
return; return;
Verb verb = new(); Verb verb = new()
verb.Act = () => component.TryUncuff(args.User); {
verb.Text = Loc.GetString("uncuff-verb-get-data-text"); Act = () => component.TryUncuff(args.User),
Text = Loc.GetString("uncuff-verb-get-data-text")
};
//TODO VERB ICON add uncuffing symbol? may re-use the alert symbol showing that you are currently cuffed? //TODO VERB ICON add uncuffing symbol? may re-use the alert symbol showing that you are currently cuffed?
args.Verbs.Add(verb); args.Verbs.Add(verb);
} }
@@ -61,39 +64,39 @@ namespace Content.Server.Cuffs
if (component.Broken) if (component.Broken)
{ {
args.User.PopupMessage(Loc.GetString("handcuff-component-cuffs-broken-error")); _popup.PopupEntity(Loc.GetString("handcuff-component-cuffs-broken-error"), args.User, Filter.Entities(args.User));
return; return;
} }
if (!EntityManager.TryGetComponent<HandsComponent?>(target, out var hands)) if (!EntityManager.TryGetComponent<HandsComponent?>(target, out var hands))
{ {
args.User.PopupMessage(Loc.GetString("handcuff-component-target-has-no-hands-error",("targetName", args.Target))); _popup.PopupEntity(Loc.GetString("handcuff-component-target-has-no-hands-error",("targetName", args.Target)), args.User, Filter.Entities(args.User));
return; return;
} }
if (cuffed.CuffedHandCount >= hands.Count) if (cuffed.CuffedHandCount >= hands.Count)
{ {
args.User.PopupMessage(Loc.GetString("handcuff-component-target-has-no-free-hands-error",("targetName", args.Target))); _popup.PopupEntity(Loc.GetString("handcuff-component-target-has-no-free-hands-error",("targetName", args.Target)), args.User, Filter.Entities(args.User));
return; return;
} }
if (!args.CanReach) if (!args.CanReach)
{ {
args.User.PopupMessage(Loc.GetString("handcuff-component-too-far-away-error")); _popup.PopupEntity(Loc.GetString("handcuff-component-too-far-away-error"), args.User, Filter.Entities(args.User));
return; return;
} }
if (args.Target == args.User) if (args.Target == args.User)
{ {
args.User.PopupMessage(Loc.GetString("handcuff-component-target-self")); _popup.PopupEntity(Loc.GetString("handcuff-component-target-self"), args.User, Filter.Entities(args.User));
} }
else else
{ {
args.User.PopupMessage(Loc.GetString("handcuff-component-start-cuffing-target-message",("targetName", args.Target))); _popup.PopupEntity(Loc.GetString("handcuff-component-start-cuffing-target-message",("targetName", args.Target)), args.User, Filter.Entities(args.User));
args.User.PopupMessage(target, Loc.GetString("handcuff-component-start-cuffing-by-other-message",("otherName", args.User))); _popup.PopupEntity(Loc.GetString("handcuff-component-start-cuffing-by-other-message",("otherName", args.User)), target, Filter.Entities(args.User));
} }
SoundSystem.Play(component.StartCuffSound.GetSound(), Filter.Pvs(uid), uid); _audio.PlayPvs(component.StartCuffSound, uid);
component.TryUpdateCuff(args.User, target, cuffed); component.TryUpdateCuff(args.User, target, cuffed);
args.Handled = true; args.Handled = true;
@@ -116,13 +119,9 @@ namespace Content.Server.Cuffs
if (args.User == args.Target) if (args.User == args.Target)
{ {
// This UncuffAttemptEvent check should probably be In MobStateSystem, not here? // This UncuffAttemptEvent check should probably be In MobStateSystem, not here?
if (EntityManager.TryGetComponent<MobStateComponent?>(args.User, out var state)) if (_mobState.IsIncapacitated(args.User))
{ {
// Manually check this. args.Cancel();
if (state.IsIncapacitated())
{
args.Cancel();
}
} }
else else
{ {
@@ -139,7 +138,7 @@ namespace Content.Server.Cuffs
} }
if (args.Cancelled) if (args.Cancelled)
{ {
_popupSystem.PopupEntity(Loc.GetString("cuffable-component-cannot-interact-message"), args.Target, Filter.Entities(args.User)); _popup.PopupEntity(Loc.GetString("cuffable-component-cannot-interact-message"), args.Target, Filter.Entities(args.User));
} }
} }
@@ -151,7 +150,10 @@ namespace Content.Server.Cuffs
var owner = message.Sender; var owner = message.Sender;
if (!EntityManager.TryGetComponent(owner, out CuffableComponent? cuffable) || if (!EntityManager.TryGetComponent(owner, out CuffableComponent? cuffable) ||
!cuffable.Initialized) return; !cuffable.Initialized)
{
return;
}
var dirty = false; var dirty = false;
var handCount = EntityManager.GetComponentOrNull<HandsComponent>(owner)?.Count ?? 0; var handCount = EntityManager.GetComponentOrNull<HandsComponent>(owner)?.Count ?? 0;

View File

@@ -8,7 +8,7 @@ using Content.Shared.IdentityManagement;
using Content.Shared.Input; using Content.Shared.Input;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers; using Content.Shared.Interaction.Helpers;
using Content.Shared.MobState.Components; using Content.Shared.MobState.EntitySystems;
using Content.Shared.Pointing; using Content.Shared.Pointing;
using Content.Shared.Popups; using Content.Shared.Popups;
using JetBrains.Annotations; using JetBrains.Annotations;
@@ -31,6 +31,8 @@ namespace Content.Server.Pointing.EntitySystems
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!; [Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!;
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly VisibilitySystem _visibilitySystem = default!; [Dependency] private readonly VisibilitySystem _visibilitySystem = default!;
private static readonly TimeSpan PointDelay = TimeSpan.FromSeconds(0.5f); private static readonly TimeSpan PointDelay = TimeSpan.FromSeconds(0.5f);
@@ -70,7 +72,7 @@ namespace Content.Server.Pointing.EntitySystems
? viewerPointedAtMessage ? viewerPointedAtMessage
: viewerMessage; : viewerMessage;
source.PopupMessage(viewerEntity, message); _popup.PopupEntity(message, source, Filter.Entities(viewerEntity));
} }
} }
@@ -108,7 +110,7 @@ namespace Content.Server.Pointing.EntitySystems
// Checking mob state directly instead of some action blocker, as many action blockers are blocked for // Checking mob state directly instead of some action blocker, as many action blockers are blocked for
// ghosts and there is no obvious choice for pointing. // ghosts and there is no obvious choice for pointing.
if (TryComp(player, out MobStateComponent? mob) && mob.IsIncapacitated()) if (_mobState.IsIncapacitated(player))
{ {
return false; return false;
} }
@@ -120,7 +122,7 @@ namespace Content.Server.Pointing.EntitySystems
if (!InRange(player, coords)) if (!InRange(player, coords))
{ {
player.PopupMessage(Loc.GetString("pointing-system-try-point-cannot-reach")); _popup.PopupEntity(Loc.GetString("pointing-system-try-point-cannot-reach"), player, Filter.Entities(player));
return false; return false;
} }

View File

@@ -3,6 +3,7 @@ using Content.Shared.Buckle.Components;
using Content.Shared.Rotatable; using Content.Shared.Rotatable;
using JetBrains.Annotations; using JetBrains.Annotations;
using Content.Shared.MobState.Components; using Content.Shared.MobState.Components;
using Content.Shared.MobState.EntitySystems;
namespace Content.Shared.Interaction namespace Content.Shared.Interaction
{ {
@@ -16,6 +17,8 @@ namespace Content.Shared.Interaction
public sealed class RotateToFaceSystem : EntitySystem public sealed class RotateToFaceSystem : EntitySystem
{ {
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly SharedMobStateSystem _mobState = default!;
public bool TryFaceCoordinates(EntityUid user, Vector2 coordinates) public bool TryFaceCoordinates(EntityUid user, Vector2 coordinates)
{ {
var diff = coordinates - EntityManager.GetComponent<TransformComponent>(user).MapPosition.Position; var diff = coordinates - EntityManager.GetComponent<TransformComponent>(user).MapPosition.Position;
@@ -27,9 +30,9 @@ namespace Content.Shared.Interaction
public bool TryFaceAngle(EntityUid user, Angle diffAngle) public bool TryFaceAngle(EntityUid user, Angle diffAngle)
{ {
if (_actionBlockerSystem.CanChangeDirection(user) && TryComp(user, out MobStateComponent? mob) && !mob.IsIncapacitated()) if (_actionBlockerSystem.CanChangeDirection(user) && !_mobState.IsIncapacitated(user))
{ {
EntityManager.GetComponent<TransformComponent>(user).WorldRotation = diffAngle; Transform(user).WorldRotation = diffAngle;
return true; return true;
} }
else else
@@ -40,13 +43,13 @@ namespace Content.Shared.Interaction
if (suid != null) if (suid != null)
{ {
// We're buckled to another object. Is that object rotatable? // We're buckled to another object. Is that object rotatable?
if (EntityManager.TryGetComponent<RotatableComponent>(suid.Value!, out var rotatable) && rotatable.RotateWhileAnchored) if (EntityManager.TryGetComponent<RotatableComponent>(suid.Value, out var rotatable) && rotatable.RotateWhileAnchored)
{ {
// Note the assumption that even if unanchored, user can only do spinnychair with an "independent wheel". // Note the assumption that even if unanchored, user can only do spinnychair with an "independent wheel".
// (Since the user being buckled to it holds it down with their weight.) // (Since the user being buckled to it holds it down with their weight.)
// This is logically equivalent to RotateWhileAnchored. // This is logically equivalent to RotateWhileAnchored.
// Barstools and office chairs have independent wheels, while regular chairs don't. // Barstools and office chairs have independent wheels, while regular chairs don't.
EntityManager.GetComponent<TransformComponent>(rotatable.Owner).WorldRotation = diffAngle; Transform(rotatable.Owner).WorldRotation = diffAngle;
return true; return true;
} }
} }