From eb4ce6cba49a580575d6ef6183b2233cce8a4e55 Mon Sep 17 00:00:00 2001 From: slarticodefast <161409025+slarticodefast@users.noreply.github.com> Date: Fri, 22 Nov 2024 00:43:02 +0100 Subject: [PATCH] electrification hud --- .../ElectrocutionOverlaySystem.cs | 101 ++++++++++++++++++ .../Electrocution/ElectrocutionSystem.cs | 15 +-- Content.Server/Power/PowerWireAction.cs | 10 +- .../ElectrocutionOverlayComponent.cs | 9 ++ .../Electrocution/SharedElectrocution.cs | 6 +- .../SharedElectrocutionSystem.cs | 15 +++ .../Entities/Mobs/Player/observer.yml | 1 + .../Entities/Mobs/Player/silicon.yml | 1 + .../Doors/Airlocks/base_structureairlocks.yml | 5 + .../Entities/Structures/Walls/fence_metal.yml | 14 +-- .../Entities/Structures/Walls/grille.yml | 10 +- .../Interface/Misc/ai_hud.rsi/apc_hacked.png | Bin 0 -> 561 bytes .../Interface/Misc/ai_hud.rsi/electrified.png | Bin 0 -> 812 bytes .../Interface/Misc/ai_hud.rsi/meta.json | 37 +++++++ 14 files changed, 192 insertions(+), 32 deletions(-) create mode 100644 Content.Client/Electrocution/ElectrocutionOverlaySystem.cs create mode 100644 Content.Shared/Electrocution/Components/ElectrocutionOverlayComponent.cs create mode 100644 Resources/Textures/Interface/Misc/ai_hud.rsi/apc_hacked.png create mode 100644 Resources/Textures/Interface/Misc/ai_hud.rsi/electrified.png create mode 100644 Resources/Textures/Interface/Misc/ai_hud.rsi/meta.json diff --git a/Content.Client/Electrocution/ElectrocutionOverlaySystem.cs b/Content.Client/Electrocution/ElectrocutionOverlaySystem.cs new file mode 100644 index 00000000000..2751c498de3 --- /dev/null +++ b/Content.Client/Electrocution/ElectrocutionOverlaySystem.cs @@ -0,0 +1,101 @@ +using Content.Shared.Electrocution; +using Robust.Client.GameObjects; +using Robust.Client.Player; +using Robust.Shared.Player; + +namespace Content.Client.Electrocution; + +/// +/// Shows the ElectrocutionOverlay to entities with the ElectrocutionOverlayComponent. +/// +public sealed class ElectrocutionOverlaySystem : EntitySystem +{ + + [Dependency] private readonly AppearanceSystem _appearance = default!; + [Dependency] private readonly IPlayerManager _playerMan = default!; + + /// + public override void Initialize() + { + SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(OnShutdown); + SubscribeLocalEvent(OnPlayerAttached); + SubscribeLocalEvent(OnPlayerDetached); + + SubscribeLocalEvent(OnAppearanceChange); + } + + private void OnPlayerAttached(Entity ent, ref LocalPlayerAttachedEvent args) + { + ShowOverlay(); + } + + private void OnPlayerDetached(Entity ent, ref LocalPlayerDetachedEvent args) + { + RemoveOverlay(); + } + + private void OnInit(Entity ent, ref ComponentInit args) + { + if (_playerMan.LocalEntity == ent) + { + ShowOverlay(); + } + } + + private void OnShutdown(Entity ent, ref ComponentShutdown args) + { + if (_playerMan.LocalEntity == ent) + { + RemoveOverlay(); + } + } + + private void ShowOverlay() + { + var electrifiedQuery = AllEntityQuery(); + while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp)) + { + if (!_appearance.TryGetData(uid, ElectrifiedVisuals.IsElectrified, out var electrified, appearanceComp)) + continue; + + if (!spriteComp.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer)) + continue; + + if (electrified) + spriteComp.LayerSetVisible(ElectrifiedLayers.Overlay, true); + else + spriteComp.LayerSetVisible(ElectrifiedLayers.Overlay, false); + } + } + + private void RemoveOverlay() + { + var electrifiedQuery = AllEntityQuery(); + while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp)) + { + if (!spriteComp.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer)) + continue; + + spriteComp.LayerSetVisible(layer, false); + } + } + + private void OnAppearanceChange(Entity ent, ref AppearanceChangeEvent args) + { + if (args.Sprite == null) + return; + + if (!_appearance.TryGetData(ent.Owner, ElectrifiedVisuals.IsElectrified, out var electrified, args.Component)) + return; + + if (!args.Sprite.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer)) + return; + + var player = _playerMan.LocalEntity; + if (electrified && HasComp(player)) + args.Sprite.LayerSetVisible(layer, true); + else + args.Sprite.LayerSetVisible(layer, false); + } +} diff --git a/Content.Server/Electrocution/ElectrocutionSystem.cs b/Content.Server/Electrocution/ElectrocutionSystem.cs index e8dc64e1854..978c7573f54 100644 --- a/Content.Server/Electrocution/ElectrocutionSystem.cs +++ b/Content.Server/Electrocution/ElectrocutionSystem.cs @@ -123,7 +123,7 @@ private void UpdateState(float frameTime) activated.TimeLeft -= frameTime; if (activated.TimeLeft <= 0 || !IsPowered(uid, electrified, transform)) { - _appearance.SetData(uid, ElectrifiedVisuals.IsPowered, false); + _appearance.SetData(uid, ElectrifiedVisuals.ShowSparks, false); RemComp(uid); } } @@ -219,7 +219,7 @@ public bool TryDoElectrifiedAct(EntityUid uid, EntityUid targetUid, return false; EnsureComp(uid); - _appearance.SetData(uid, ElectrifiedVisuals.IsPowered, true); + _appearance.SetData(uid, ElectrifiedVisuals.ShowSparks, true); siemens *= electrified.SiemensCoefficient; if (!DoCommonElectrocutionAttempt(targetUid, uid, ref siemens) || siemens <= 0) @@ -490,15 +490,4 @@ private void PlayElectrocutionSound(EntityUid targetUid, EntityUid sourceUid, El } _audio.PlayPvs(electrified.ShockNoises, targetUid, AudioParams.Default.WithVolume(electrified.ShockVolume)); } - - public void SetElectrifiedWireCut(Entity ent, bool value) - { - if (ent.Comp.IsWireCut == value) - { - return; - } - - ent.Comp.IsWireCut = value; - Dirty(ent); - } } diff --git a/Content.Server/Power/PowerWireAction.cs b/Content.Server/Power/PowerWireAction.cs index 43d1de6e4d3..52cbaeb41ea 100644 --- a/Content.Server/Power/PowerWireAction.cs +++ b/Content.Server/Power/PowerWireAction.cs @@ -18,7 +18,7 @@ public sealed partial class PowerWireAction : BaseWireAction [DataField("pulseTimeout")] private int _pulseTimeout = 30; - private ElectrocutionSystem _electrocutionSystem = default!; + private ElectrocutionSystem _electrocution = default!; public override object StatusKey { get; } = PowerWireActionKey.Status; @@ -109,8 +109,8 @@ private void SetElectrified(EntityUid used, bool setting, ElectrifiedComponent? && !EntityManager.TryGetComponent(used, out electrified)) return; - _electrocutionSystem.SetElectrifiedWireCut((used, electrified), setting); - electrified.Enabled = setting; + _electrocution.SetElectrifiedWireCut((used, electrified), setting); + _electrocution.SetElectrified((used, electrified), setting); } /// false if failed, true otherwise, or if the entity cannot be electrified @@ -124,7 +124,7 @@ private bool TrySetElectrocution(EntityUid user, Wire wire, bool timed = false) // always set this to true SetElectrified(wire.Owner, true, electrified); - var electrifiedAttempt = _electrocutionSystem.TryDoElectrifiedAct(wire.Owner, user); + var electrifiedAttempt = _electrocution.TryDoElectrifiedAct(wire.Owner, user); // if we were electrified, then return false return !electrifiedAttempt; @@ -165,7 +165,7 @@ public override void Initialize() { base.Initialize(); - _electrocutionSystem = EntitySystem.Get(); + _electrocution = EntityManager.System(); } // This should add a wire into the entity's state, whether it be diff --git a/Content.Shared/Electrocution/Components/ElectrocutionOverlayComponent.cs b/Content.Shared/Electrocution/Components/ElectrocutionOverlayComponent.cs new file mode 100644 index 00000000000..e03e8cb9344 --- /dev/null +++ b/Content.Shared/Electrocution/Components/ElectrocutionOverlayComponent.cs @@ -0,0 +1,9 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Electrocution; + +/// +/// Allow an entity to see the ElectrocutionOverlay showing electrocuted doors. +/// +[RegisterComponent, NetworkedComponent] +public sealed partial class ElectrocutionOverlayComponent : Component; diff --git a/Content.Shared/Electrocution/SharedElectrocution.cs b/Content.Shared/Electrocution/SharedElectrocution.cs index 4060856d4d6..b00fb1afdb7 100644 --- a/Content.Shared/Electrocution/SharedElectrocution.cs +++ b/Content.Shared/Electrocution/SharedElectrocution.cs @@ -5,11 +5,13 @@ namespace Content.Shared.Electrocution; [Serializable, NetSerializable] public enum ElectrifiedLayers : byte { - Powered + Sparks, + Overlay, } [Serializable, NetSerializable] public enum ElectrifiedVisuals : byte { - IsPowered + ShowSparks, // only shown when zapping someone, deactivated after a short time + IsElectrified, // if the entity is electrified or not, used for the AI HUD } diff --git a/Content.Shared/Electrocution/SharedElectrocutionSystem.cs b/Content.Shared/Electrocution/SharedElectrocutionSystem.cs index e36e4a804b7..5da344e023a 100644 --- a/Content.Shared/Electrocution/SharedElectrocutionSystem.cs +++ b/Content.Shared/Electrocution/SharedElectrocutionSystem.cs @@ -5,6 +5,8 @@ namespace Content.Shared.Electrocution { public abstract class SharedElectrocutionSystem : EntitySystem { + [Dependency] private readonly SharedAppearanceSystem _appearance = default!; + public override void Initialize() { base.Initialize(); @@ -35,6 +37,19 @@ public void SetElectrified(Entity ent, bool value) ent.Comp.Enabled = value; Dirty(ent, ent.Comp); + + _appearance.SetData(ent.Owner, ElectrifiedVisuals.IsElectrified, value); + } + + public void SetElectrifiedWireCut(Entity ent, bool value) + { + if (ent.Comp.IsWireCut == value) + { + return; + } + + ent.Comp.IsWireCut = value; + Dirty(ent); } /// Entity being electrocuted. diff --git a/Resources/Prototypes/Entities/Mobs/Player/observer.yml b/Resources/Prototypes/Entities/Mobs/Player/observer.yml index ed98f87ffb3..a44518ff3de 100644 --- a/Resources/Prototypes/Entities/Mobs/Player/observer.yml +++ b/Resources/Prototypes/Entities/Mobs/Player/observer.yml @@ -59,6 +59,7 @@ skipChecks: true - type: Ghost - type: GhostHearing + - type: ElectrocutionOverlay - type: IntrinsicRadioReceiver - type: ActiveRadio receiveAllChannels: true diff --git a/Resources/Prototypes/Entities/Mobs/Player/silicon.yml b/Resources/Prototypes/Entities/Mobs/Player/silicon.yml index b8cf7f0c269..d9a54b2c1cd 100644 --- a/Resources/Prototypes/Entities/Mobs/Player/silicon.yml +++ b/Resources/Prototypes/Entities/Mobs/Player/silicon.yml @@ -22,6 +22,7 @@ - type: IgnoreUIRange - type: StationAiHeld - type: StationAiOverlay + - type: ElectrocutionOverlay - type: ActionGrant actions: - ActionJumpToCore diff --git a/Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml b/Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml index 58a3f6ceca6..fd907a0ff26 100644 --- a/Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml +++ b/Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml @@ -30,6 +30,11 @@ shader: unshaded - state: panel_open map: ["enum.WiresVisualLayers.MaintenancePanel"] + - state: electrified + sprite: Interface/Misc/ai_hud.rsi + shader: unshaded + visible: false + map: ["enum.ElectrifiedLayers.Overlay"] - type: AnimationPlayer - type: Physics - type: Fixtures diff --git a/Resources/Prototypes/Entities/Structures/Walls/fence_metal.yml b/Resources/Prototypes/Entities/Structures/Walls/fence_metal.yml index 78e28d27a53..67efa9dd19b 100644 --- a/Resources/Prototypes/Entities/Structures/Walls/fence_metal.yml +++ b/Resources/Prototypes/Entities/Structures/Walls/fence_metal.yml @@ -70,8 +70,8 @@ - type: Appearance - type: GenericVisualizer visuals: - enum.ElectrifiedVisuals.IsPowered: - enum.ElectrifiedLayers.Powered: + enum.ElectrifiedVisuals.ShowSparks: + enum.ElectrifiedLayers.Sparks: True: { visible: True } False: { visible: False } - type: AnimationPlayer @@ -94,7 +94,7 @@ - state: straight_broken - state: electrified sprite: Effects/electricity.rsi - map: ["enum.ElectrifiedLayers.Powered"] + map: ["enum.ElectrifiedLayers.Sparks"] shader: unshaded visible: false - type: Physics @@ -149,7 +149,7 @@ - state: straight - state: electrified sprite: Effects/electricity.rsi - map: ["enum.ElectrifiedLayers.Powered"] + map: ["enum.ElectrifiedLayers.Sparks"] shader: unshaded visible: false - type: Fixtures @@ -202,7 +202,7 @@ - state: corner - state: electrified sprite: Effects/electricity.rsi - map: ["enum.ElectrifiedLayers.Powered"] + map: ["enum.ElectrifiedLayers.Sparks"] shader: unshaded visible: false - type: Fixtures @@ -244,7 +244,7 @@ - state: end - state: electrified sprite: Effects/electricity.rsi - map: ["enum.ElectrifiedLayers.Powered"] + map: ["enum.ElectrifiedLayers.Sparks"] shader: unshaded visible: false - type: Fixtures @@ -275,7 +275,7 @@ map: ["enum.DoorVisualLayers.Base"] - state: electrified sprite: Effects/electricity.rsi - map: [ "enum.ElectrifiedLayers.Powered" ] + map: [ "enum.ElectrifiedLayers.Sparks" ] shader: unshaded visible: false - type: Fixtures diff --git a/Resources/Prototypes/Entities/Structures/Walls/grille.yml b/Resources/Prototypes/Entities/Structures/Walls/grille.yml index 7be721b6f9a..8a61bbb37a1 100644 --- a/Resources/Prototypes/Entities/Structures/Walls/grille.yml +++ b/Resources/Prototypes/Entities/Structures/Walls/grille.yml @@ -21,7 +21,7 @@ - state: grille - state: electrified sprite: Effects/electricity.rsi - map: ["enum.ElectrifiedLayers.Powered"] + map: ["enum.ElectrifiedLayers.Sparks"] shader: unshaded visible: false - type: Icon @@ -82,8 +82,8 @@ - type: Appearance - type: GenericVisualizer visuals: - enum.ElectrifiedVisuals.IsPowered: - enum.ElectrifiedLayers.Powered: + enum.ElectrifiedVisuals.ShowSparks: + enum.ElectrifiedLayers.Sparks: True: { visible: True } False: { visible: False } - type: AnimationPlayer @@ -176,7 +176,7 @@ - state: grille_diagonal - state: electrified_diagonal sprite: Effects/electricity.rsi - map: ["enum.ElectrifiedLayers.Powered"] + map: ["enum.ElectrifiedLayers.Sparks"] shader: unshaded visible: false - type: Icon @@ -211,7 +211,7 @@ - state: ratvargrille_diagonal - state: electrified_diagonal sprite: Effects/electricity.rsi - map: ["enum.ElectrifiedLayers.Powered"] + map: ["enum.ElectrifiedLayers.Sparks"] shader: unshaded visible: false - type: Icon diff --git a/Resources/Textures/Interface/Misc/ai_hud.rsi/apc_hacked.png b/Resources/Textures/Interface/Misc/ai_hud.rsi/apc_hacked.png new file mode 100644 index 0000000000000000000000000000000000000000..72e111edac559c01afecad417d4e79eb6e953d80 GIT binary patch literal 561 zcmeAS@N?(olHy`uVBq!ia0vp^4nUm1!3HGP9xZtRq&N#aB8wRq_>O=u<5X=vX$A(y z$DS^ZAr*7p&JN5wY{27eso;L|Vc8Pdyz-k9_!vX3d!?vuEcTB)o5Vj03`d{1&yJo6>KO1N;cl0e$; z*HR2coD3&a85E{7G{i6=I9v4Bd_O(2`qTUK|9`((FaLk<#1@ZZ_K)8F)W3IxrzMy1 zbF|yGZA9*$1*K-tnKPdlko%Z@wqB{(z|Z{qCF1AIknRme1MKd)MiL zDacO~ycrzy7#ScQgm5zAPh5Mh{QV=)T_#~_ZW@Z4vP2FA=GJvf_D*jsxT0b>MJU?z zmiz@{`^)kP;xdgFUkiTlyXAGA!5V1c4l8*Hpydef-f(oS-FGYA`hc~;YPtpXGnkjxjOZghtrdu`eiQrDums|E=r~Q|Lgfb@B6&{ zzeOchp0ECYU;Zrfys!DsSK2EqP-hVR`ZKHkEyILvxdZY=GS8}w)^a8T(*T2~tDnm{ Hr-UW|fzIqt literal 0 HcmV?d00001 diff --git a/Resources/Textures/Interface/Misc/ai_hud.rsi/electrified.png b/Resources/Textures/Interface/Misc/ai_hud.rsi/electrified.png new file mode 100644 index 0000000000000000000000000000000000000000..046a307d09f964825068522b4fe5790b0eb5eb7c GIT binary patch literal 812 zcmV+{1JnG8P)t3m`bd7309&o=J$TLpk^JmiVDGT3 z$u5dNjX9AR(SBcRsd4w8{Ar9)NatF0uVFbV4ej~r@#i&EPx(7L46A# zmwgY_FogEp?+7;mxUHjveD4i!eSdrNABm;j3uu(@ml4*?NnbxMLbhK2M*!~<>(Ai~ zG@kq;cYl75wHu^M)`!|2PbL4V0JUu4aAyJ-f52WaDHR|^_0mK&4QepMx58BZfYe!F zmTqtge?V$0OqgK`Y=H9zcm_{^^#^zaPk{0VXrKEXAJJ#t%Jc_}=j;u1Yd1)jx zH<)Ju)G4sRGz*{yPf*_i$YtL{H4LFW_d9~vAD|&0x4xPFfUS+QdM_X$ABnU50llCl q{s8X(???0B^Czs`AYIPv5BLEgD;PVJ8F0k_0000>qx literal 0 HcmV?d00001 diff --git a/Resources/Textures/Interface/Misc/ai_hud.rsi/meta.json b/Resources/Textures/Interface/Misc/ai_hud.rsi/meta.json new file mode 100644 index 00000000000..7f1e67ac4d9 --- /dev/null +++ b/Resources/Textures/Interface/Misc/ai_hud.rsi/meta.json @@ -0,0 +1,37 @@ +{ + "version": 1, + "license": "CC-BY-SA-3.0", + "copyright": "taken from tgstation at commit https://github.com/tgstation/tgstation/commit/d170a410d40eec4fc19fe5eb8d561d58a0902082", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "electrified", + "delays": [ + [ + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2 + ] + ] + }, + { + "name": "apc_hacked", + "delays": [ + [ + 0.2, + 0.2, + 0.2, + 0.2, + 0.2, + 0.2 + ] + ] + } + ] +} \ No newline at end of file