From 9b84c1a9fd2902c205b8210d21fbc9360c1c3338 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Thu, 25 Aug 2022 23:56:56 +1000 Subject: [PATCH] Remove all but 1 IsIncapacitated (#10661) --- Content.Client/Pointing/PointingSystem.cs | 8 ++-- .../Body/Systems/RespiratorSystem.cs | 25 +++++----- .../EntitySystems/ChemistrySystem.Injector.cs | 15 +++--- .../EntitySystems/ChemistrySystem.cs | 4 ++ Content.Server/Cuffs/CuffableSystem.cs | 46 ++++++++++--------- .../Pointing/EntitySystems/PointingSystem.cs | 10 ++-- .../Interaction/RotateToFaceSystem.cs | 11 +++-- 7 files changed, 69 insertions(+), 50 deletions(-) diff --git a/Content.Client/Pointing/PointingSystem.cs b/Content.Client/Pointing/PointingSystem.cs index 8bef309335..2cc4a2b5bc 100644 --- a/Content.Client/Pointing/PointingSystem.cs +++ b/Content.Client/Pointing/PointingSystem.cs @@ -1,5 +1,5 @@ using Content.Client.Pointing.Components; -using Content.Shared.MobState.Components; +using Content.Shared.MobState.EntitySystems; using Content.Shared.Pointing; using Content.Shared.Verbs; using Robust.Client.GameObjects; @@ -7,8 +7,10 @@ using DrawDepth = Content.Shared.DrawDepth.DrawDepth; namespace Content.Client.Pointing; -internal sealed class PointingSystem : EntitySystem +public sealed class PointingSystem : EntitySystem { + [Dependency] private readonly SharedMobStateSystem _mobState = default!; + public override void 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 // 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; // We won't check in range or visibility, as this verb is currently only executable via the context menu, diff --git a/Content.Server/Body/Systems/RespiratorSystem.cs b/Content.Server/Body/Systems/RespiratorSystem.cs index 448341659e..c647abf743 100644 --- a/Content.Server/Body/Systems/RespiratorSystem.cs +++ b/Content.Server/Body/Systems/RespiratorSystem.cs @@ -9,6 +9,7 @@ using Content.Shared.Body.Components; using Content.Shared.Damage; using Content.Shared.Database; using Content.Shared.MobState.Components; +using Content.Shared.MobState.EntitySystems; using JetBrains.Annotations; using Robust.Shared.Player; using Robust.Shared.Timing; @@ -18,14 +19,15 @@ namespace Content.Server.Body.Systems [UsedImplicitly] public sealed class RespiratorSystem : EntitySystem { - [Dependency] private readonly DamageableSystem _damageableSys = 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 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() { @@ -44,8 +46,8 @@ namespace Content.Server.Body.Systems EntityManager.EntityQuery()) { var uid = respirator.Owner; - if (!EntityManager.TryGetComponent(uid, out var state) || - state.IsDead()) + + if (_mobState.IsDead(uid)) { continue; } @@ -57,7 +59,7 @@ namespace Content.Server.Body.Systems respirator.AccumulatedFrametime -= respirator.CycleDelay; UpdateSaturation(respirator.Owner, -respirator.CycleDelay, respirator); - if (!state.IsIncapacitated()) // cannot breathe in crit. + if (!_mobState.IsIncapacitated(uid)) // cannot breathe in crit. { switch (respirator.Status) { @@ -100,10 +102,11 @@ namespace Content.Server.Body.Systems var ev = new InhaleLocationEvent(); RaiseLocalEvent(uid, ev, false); + ev.Gas ??= _atmosSys.GetContainingMixture(uid, false, true); + if (ev.Gas == null) { - ev.Gas = _atmosSys.GetContainingMixture(uid, false, true); - if (ev.Gas == null) return; + return; } var ratio = (Atmospherics.BreathVolume / ev.Gas.Volume); diff --git a/Content.Server/Chemistry/EntitySystems/ChemistrySystem.Injector.cs b/Content.Server/Chemistry/EntitySystems/ChemistrySystem.Injector.cs index fa16d6d734..01e47ae176 100644 --- a/Content.Server/Chemistry/EntitySystems/ChemistrySystem.Injector.cs +++ b/Content.Server/Chemistry/EntitySystems/ChemistrySystem.Injector.cs @@ -69,13 +69,14 @@ public sealed partial class ChemistrySystem } 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(target, out var stream)) { TryDraw(component, target, stream.BloodSolution, user, stream); return; } - /// Draw from an object (food, beaker, etc) + + // Draw from an object (food, beaker, etc) if (_solutions.TryGetDrawableSolution(target, out var drawableSolution)) { TryDraw(component, target, drawableSolution, user); @@ -111,7 +112,8 @@ public sealed partial class ChemistrySystem 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) { @@ -146,7 +148,8 @@ public sealed partial class ChemistrySystem private void OnInjectorUse(EntityUid uid, InjectorComponent component, UseInHandEvent args) { - if (args.Handled) return; + if (args.Handled) + return; Toggle(component, args.User); args.Handled = true; @@ -200,11 +203,11 @@ public sealed partial class ChemistrySystem ("user", userName)), user, Filter.Entities(target)); // Check if the target is incapacitated or in combat mode and modify time accordingly. - if (TryComp(target, out var mobState) && mobState.IsIncapacitated()) + if (_mobState.IsIncapacitated(target)) { actualDelay /= 2; } - else if (TryComp(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 // combat with fast syringes & lag. diff --git a/Content.Server/Chemistry/EntitySystems/ChemistrySystem.cs b/Content.Server/Chemistry/EntitySystems/ChemistrySystem.cs index 352d45fb63..0299eaa4a2 100644 --- a/Content.Server/Chemistry/EntitySystems/ChemistrySystem.cs +++ b/Content.Server/Chemistry/EntitySystems/ChemistrySystem.cs @@ -2,6 +2,8 @@ using Content.Server.Administration.Logs; using Content.Server.Body.Systems; using Content.Server.DoAfter; using Content.Server.Popups; +using Content.Shared.CombatMode; +using Content.Shared.MobState.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 DoAfterSystem _doAfter = 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!; public override void Initialize() diff --git a/Content.Server/Cuffs/CuffableSystem.cs b/Content.Server/Cuffs/CuffableSystem.cs index c3cd205fbb..1cfb07b524 100644 --- a/Content.Server/Cuffs/CuffableSystem.cs +++ b/Content.Server/Cuffs/CuffableSystem.cs @@ -3,21 +3,22 @@ using Content.Server.Hands.Components; using Content.Shared.ActionBlocker; using Content.Shared.Cuffs; using Content.Shared.Hands; -using Content.Shared.MobState.Components; using Content.Shared.Popups; using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Shared.Player; using Content.Shared.Interaction; -using Robust.Shared.Audio; +using Content.Shared.MobState.EntitySystems; namespace Content.Server.Cuffs { [UsedImplicitly] public sealed class CuffableSystem : SharedCuffableSystem { - [Dependency] private readonly SharedPopupSystem _popupSystem = 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() { @@ -41,9 +42,11 @@ namespace Content.Server.Cuffs if (args.User != args.Target && !args.CanInteract) return; - Verb verb = new(); - verb.Act = () => component.TryUncuff(args.User); - verb.Text = Loc.GetString("uncuff-verb-get-data-text"); + Verb verb = new() + { + 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? args.Verbs.Add(verb); } @@ -61,39 +64,39 @@ namespace Content.Server.Cuffs 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; } if (!EntityManager.TryGetComponent(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; } 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; } 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; } 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 { - args.User.PopupMessage(Loc.GetString("handcuff-component-start-cuffing-target-message",("targetName", args.Target))); - args.User.PopupMessage(target, Loc.GetString("handcuff-component-start-cuffing-by-other-message",("otherName", args.User))); + _popup.PopupEntity(Loc.GetString("handcuff-component-start-cuffing-target-message",("targetName", args.Target)), args.User, Filter.Entities(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); args.Handled = true; @@ -116,13 +119,9 @@ namespace Content.Server.Cuffs if (args.User == args.Target) { // This UncuffAttemptEvent check should probably be In MobStateSystem, not here? - if (EntityManager.TryGetComponent(args.User, out var state)) + if (_mobState.IsIncapacitated(args.User)) { - // Manually check this. - if (state.IsIncapacitated()) - { - args.Cancel(); - } + args.Cancel(); } else { @@ -139,7 +138,7 @@ namespace Content.Server.Cuffs } 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; if (!EntityManager.TryGetComponent(owner, out CuffableComponent? cuffable) || - !cuffable.Initialized) return; + !cuffable.Initialized) + { + return; + } var dirty = false; var handCount = EntityManager.GetComponentOrNull(owner)?.Count ?? 0; diff --git a/Content.Server/Pointing/EntitySystems/PointingSystem.cs b/Content.Server/Pointing/EntitySystems/PointingSystem.cs index 5f8f6b7f88..c7d09fe9a5 100644 --- a/Content.Server/Pointing/EntitySystems/PointingSystem.cs +++ b/Content.Server/Pointing/EntitySystems/PointingSystem.cs @@ -8,7 +8,7 @@ using Content.Shared.IdentityManagement; using Content.Shared.Input; using Content.Shared.Interaction; using Content.Shared.Interaction.Helpers; -using Content.Shared.MobState.Components; +using Content.Shared.MobState.EntitySystems; using Content.Shared.Pointing; using Content.Shared.Popups; using JetBrains.Annotations; @@ -31,6 +31,8 @@ namespace Content.Server.Pointing.EntitySystems [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly IGameTiming _gameTiming = 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!; private static readonly TimeSpan PointDelay = TimeSpan.FromSeconds(0.5f); @@ -70,7 +72,7 @@ namespace Content.Server.Pointing.EntitySystems ? viewerPointedAtMessage : 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 // ghosts and there is no obvious choice for pointing. - if (TryComp(player, out MobStateComponent? mob) && mob.IsIncapacitated()) + if (_mobState.IsIncapacitated(player)) { return false; } @@ -120,7 +122,7 @@ namespace Content.Server.Pointing.EntitySystems 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; } diff --git a/Content.Shared/Interaction/RotateToFaceSystem.cs b/Content.Shared/Interaction/RotateToFaceSystem.cs index 65d47eeca8..0ebdcf6418 100644 --- a/Content.Shared/Interaction/RotateToFaceSystem.cs +++ b/Content.Shared/Interaction/RotateToFaceSystem.cs @@ -3,6 +3,7 @@ using Content.Shared.Buckle.Components; using Content.Shared.Rotatable; using JetBrains.Annotations; using Content.Shared.MobState.Components; +using Content.Shared.MobState.EntitySystems; namespace Content.Shared.Interaction { @@ -16,6 +17,8 @@ namespace Content.Shared.Interaction public sealed class RotateToFaceSystem : EntitySystem { [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; + [Dependency] private readonly SharedMobStateSystem _mobState = default!; + public bool TryFaceCoordinates(EntityUid user, Vector2 coordinates) { var diff = coordinates - EntityManager.GetComponent(user).MapPosition.Position; @@ -27,9 +30,9 @@ namespace Content.Shared.Interaction 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(user).WorldRotation = diffAngle; + Transform(user).WorldRotation = diffAngle; return true; } else @@ -40,13 +43,13 @@ namespace Content.Shared.Interaction if (suid != null) { // We're buckled to another object. Is that object rotatable? - if (EntityManager.TryGetComponent(suid.Value!, out var rotatable) && rotatable.RotateWhileAnchored) + if (EntityManager.TryGetComponent(suid.Value, out var rotatable) && rotatable.RotateWhileAnchored) { // 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.) // This is logically equivalent to RotateWhileAnchored. // Barstools and office chairs have independent wheels, while regular chairs don't. - EntityManager.GetComponent(rotatable.Owner).WorldRotation = diffAngle; + Transform(rotatable.Owner).WorldRotation = diffAngle; return true; } }