diff --git a/Content.Client/Damage/GodmodeSystem.cs b/Content.Client/Damage/GodmodeSystem.cs new file mode 100644 index 0000000000..8038aee3f8 --- /dev/null +++ b/Content.Client/Damage/GodmodeSystem.cs @@ -0,0 +1,8 @@ +using Content.Shared.Damage.Systems; + +namespace Content.Client.Damage; + +public sealed class GodmodeSystem : SharedGodmodeSystem +{ + +} diff --git a/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs b/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs index e83a42a2fb..31dd1d8434 100644 --- a/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs +++ b/Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs @@ -50,6 +50,7 @@ using Robust.Shared.Random; using Robust.Shared.Utility; using Timer = Robust.Shared.Timing.Timer; using Content.Shared.Cluwne; +using Content.Shared.Damage.Systems; namespace Content.Server.Administration.Systems; @@ -65,7 +66,7 @@ public sealed partial class AdminVerbSystem [Dependency] private readonly FixtureSystem _fixtures = default!; [Dependency] private readonly FlammableSystem _flammableSystem = default!; [Dependency] private readonly GhostKickManager _ghostKickManager = default!; - [Dependency] private readonly GodmodeSystem _godmodeSystem = default!; + [Dependency] private readonly SharedGodmodeSystem _sharedGodmodeSystem = default!; [Dependency] private readonly InventorySystem _inventorySystem = default!; [Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!; [Dependency] private readonly PolymorphSystem _polymorphSystem = default!; @@ -119,7 +120,7 @@ public sealed partial class AdminVerbSystem Icon = new SpriteSpecifier.Rsi(new ("/Textures/Objects/Fun/Tabletop/chessboard.rsi"), "chessboard"), Act = () => { - _godmodeSystem.EnableGodmode(args.Target); // So they don't suffocate. + _sharedGodmodeSystem.EnableGodmode(args.Target); // So they don't suffocate. EnsureComp(args.Target); RemComp(args.Target); // So they can be dragged around. var xform = Transform(args.Target); diff --git a/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs b/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs index 77cdee3a9e..e1266b14bb 100644 --- a/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs +++ b/Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs @@ -21,6 +21,7 @@ using Content.Shared.Administration; using Content.Shared.Atmos; using Content.Shared.Construction.Components; using Content.Shared.Damage; +using Content.Shared.Damage.Components; using Content.Shared.Database; using Content.Shared.Doors.Components; using Content.Shared.Hands.Components; @@ -135,7 +136,7 @@ public sealed partial class AdminVerbSystem Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/plus.svg.192dpi.png")), Act = () => { - _godmodeSystem.EnableGodmode(args.Target); + _sharedGodmodeSystem.EnableGodmode(args.Target); }, Impact = LogImpact.Extreme, Message = Loc.GetString("admin-trick-make-indestructible-description"), @@ -152,7 +153,7 @@ public sealed partial class AdminVerbSystem Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/plus.svg.192dpi.png")), Act = () => { - _godmodeSystem.DisableGodmode(args.Target); + _sharedGodmodeSystem.DisableGodmode(args.Target); }, Impact = LogImpact.Extreme, Message = Loc.GetString("admin-trick-make-vulnerable-description"), diff --git a/Content.Server/Damage/Commands/GodModeCommand.cs b/Content.Server/Damage/Commands/GodModeCommand.cs index 79aef877d8..d5d3d32b59 100644 --- a/Content.Server/Damage/Commands/GodModeCommand.cs +++ b/Content.Server/Damage/Commands/GodModeCommand.cs @@ -1,6 +1,7 @@ using Content.Server.Administration; using Content.Server.Damage.Systems; using Content.Shared.Administration; +using Content.Shared.Damage.Systems; using Robust.Server.Player; using Robust.Shared.Console; @@ -57,7 +58,7 @@ namespace Content.Server.Damage.Commands return; } - var godmodeSystem = EntitySystem.Get(); + var godmodeSystem = EntitySystem.Get(); var enabled = godmodeSystem.ToggleGodmode(entity); var name = entityManager.GetComponent(entity).EntityName; diff --git a/Content.Server/Damage/Components/GodmodeComponent.cs b/Content.Server/Damage/Components/GodmodeComponent.cs deleted file mode 100644 index 65ebec2e3d..0000000000 --- a/Content.Server/Damage/Components/GodmodeComponent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Content.Server.Damage.Systems; -using Content.Shared.Damage; - -namespace Content.Server.Damage.Components; - -/// -/// -/// -[RegisterComponent, Access(typeof(GodmodeSystem))] -public sealed class GodmodeComponent : Component -{ - public bool WasMovedByPressure; - public DamageSpecifier? OldDamage = null; -} diff --git a/Content.Server/Damage/Systems/GodmodeSystem.cs b/Content.Server/Damage/Systems/GodmodeSystem.cs index 87209afef2..404cc63905 100644 --- a/Content.Server/Damage/Systems/GodmodeSystem.cs +++ b/Content.Server/Damage/Systems/GodmodeSystem.cs @@ -1,98 +1,37 @@ using Content.Server.Atmos.Components; -using Content.Server.Damage.Components; -using Content.Shared.Damage; +using Content.Shared.Damage.Components; using Content.Shared.Damage.Systems; -using Content.Shared.FixedPoint; -using Content.Shared.Rejuvenate; -using Content.Shared.StatusEffect; -using JetBrains.Annotations; -namespace Content.Server.Damage.Systems +namespace Content.Server.Damage.Systems; + +public sealed class GodmodeSystem : SharedGodmodeSystem { - [UsedImplicitly] - public sealed class GodmodeSystem : EntitySystem + public override void EnableGodmode(EntityUid uid, GodmodeComponent? godmode = null) { - [Dependency] private readonly DamageableSystem _damageable = default!; + godmode ??= EnsureComp(uid); - public override void Initialize() + base.EnableGodmode(uid, godmode); + + if (TryComp(uid, out var moved)) { - base.Initialize(); - - SubscribeLocalEvent(OnBeforeDamageChanged); - SubscribeLocalEvent(OnBeforeStatusEffect); - SubscribeLocalEvent(OnBeforeStaminaDamage); + godmode.WasMovedByPressure = moved.Enabled; + moved.Enabled = false; } + } - private void OnBeforeDamageChanged(EntityUid uid, GodmodeComponent component, ref BeforeDamageChangedEvent args) + public override void DisableGodmode(EntityUid uid, GodmodeComponent? godmode = null) + { + if (!Resolve(uid, ref godmode, false)) + return; + + base.DisableGodmode(uid, godmode); + + if (godmode.Deleted) + return; + + if (TryComp(uid, out var moved)) { - args.Cancelled = true; - } - - private void OnBeforeStatusEffect(EntityUid uid, GodmodeComponent component, ref BeforeStatusEffectAddedEvent args) - { - args.Cancelled = true; - } - - private void OnBeforeStaminaDamage(EntityUid uid, GodmodeComponent component, ref BeforeStaminaDamageEvent args) - { - args.Cancelled = true; - } - - public void EnableGodmode(EntityUid uid) - { - var godmode = EnsureComp(uid); - - if (TryComp(uid, out var moved)) - { - godmode.WasMovedByPressure = moved.Enabled; - moved.Enabled = false; - } - - if (TryComp(uid, out var damageable)) - { - godmode.OldDamage = new(damageable.Damage); - } - - // Rejuv to cover other stuff - RaiseLocalEvent(uid, new RejuvenateEvent()); - } - - public void DisableGodmode(EntityUid uid) - { - if (!TryComp(uid, out var godmode)) - return; - - if (TryComp(uid, out var moved)) - { - moved.Enabled = godmode.WasMovedByPressure; - } - - if (!TryComp(uid, out var damageable)) - return; - - if (godmode.OldDamage != null) - { - _damageable.SetDamage(uid, damageable, godmode.OldDamage); - } - - RemComp(uid); - } - - /// - /// Toggles godmode for a given entity. - /// - /// The entity to toggle godmode for. - /// true if enabled, false if disabled. - public bool ToggleGodmode(EntityUid uid) - { - if (HasComp(uid)) - { - DisableGodmode(uid); - return false; - } - - EnableGodmode(uid); - return true; + moved.Enabled = godmode.WasMovedByPressure; } } } diff --git a/Content.Shared/Damage/Components/GodmodeComponent.cs b/Content.Shared/Damage/Components/GodmodeComponent.cs new file mode 100644 index 0000000000..f85479bb65 --- /dev/null +++ b/Content.Shared/Damage/Components/GodmodeComponent.cs @@ -0,0 +1,14 @@ +using Content.Shared.Damage.Systems; +using Robust.Shared.GameStates; + +namespace Content.Shared.Damage.Components; + +[RegisterComponent, NetworkedComponent, Access(typeof(SharedGodmodeSystem))] +public sealed class GodmodeComponent : Component +{ + [DataField("wasMovedByPressure")] + public bool WasMovedByPressure; + + [DataField("oldDamage")] + public DamageSpecifier? OldDamage = null; +} diff --git a/Content.Shared/Damage/Systems/SharedGodmodeSystem.cs b/Content.Shared/Damage/Systems/SharedGodmodeSystem.cs new file mode 100644 index 0000000000..d904c211ee --- /dev/null +++ b/Content.Shared/Damage/Systems/SharedGodmodeSystem.cs @@ -0,0 +1,84 @@ +using Content.Shared.Damage.Components; +using Content.Shared.Rejuvenate; +using Content.Shared.Slippery; +using Content.Shared.StatusEffect; + +namespace Content.Shared.Damage.Systems; + +public abstract class SharedGodmodeSystem : EntitySystem +{ + [Dependency] private readonly DamageableSystem _damageable = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnBeforeDamageChanged); + SubscribeLocalEvent(OnBeforeStatusEffect); + SubscribeLocalEvent(OnBeforeStaminaDamage); + SubscribeLocalEvent(OnSlipAttempt); + } + + private void OnSlipAttempt(EntityUid uid, GodmodeComponent component, SlipAttemptEvent args) + { + args.Cancel(); + } + + private void OnBeforeDamageChanged(EntityUid uid, GodmodeComponent component, ref BeforeDamageChangedEvent args) + { + args.Cancelled = true; + } + + private void OnBeforeStatusEffect(EntityUid uid, GodmodeComponent component, ref BeforeStatusEffectAddedEvent args) + { + args.Cancelled = true; + } + + private void OnBeforeStaminaDamage(EntityUid uid, GodmodeComponent component, ref BeforeStaminaDamageEvent args) + { + args.Cancelled = true; + } + + public virtual void EnableGodmode(EntityUid uid, GodmodeComponent? godmode = null) + { + godmode ??= EnsureComp(uid); + + if (TryComp(uid, out var damageable)) + { + godmode.OldDamage = new DamageSpecifier(damageable.Damage); + } + + // Rejuv to cover other stuff + RaiseLocalEvent(uid, new RejuvenateEvent()); + } + + public virtual void DisableGodmode(EntityUid uid, GodmodeComponent? godmode = null) + { + if (!Resolve(uid, ref godmode, false)) + return; + + if (TryComp(uid, out var damageable) && godmode.OldDamage != null) + { + _damageable.SetDamage(uid, damageable, godmode.OldDamage); + } + + RemComp(uid); + } + + /// + /// Toggles godmode for a given entity. + /// + /// The entity to toggle godmode for. + /// true if enabled, false if disabled. + public bool ToggleGodmode(EntityUid uid) + { + if (TryComp(uid, out var godmode)) + { + DisableGodmode(uid, godmode); + return false; + } + + EnableGodmode(uid, godmode); + return true; + } +}