]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
electrification hud
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Thu, 21 Nov 2024 23:43:02 +0000 (00:43 +0100)
committerslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Thu, 21 Nov 2024 23:43:02 +0000 (00:43 +0100)
14 files changed:
Content.Client/Electrocution/ElectrocutionOverlaySystem.cs [new file with mode: 0644]
Content.Server/Electrocution/ElectrocutionSystem.cs
Content.Server/Power/PowerWireAction.cs
Content.Shared/Electrocution/Components/ElectrocutionOverlayComponent.cs [new file with mode: 0644]
Content.Shared/Electrocution/SharedElectrocution.cs
Content.Shared/Electrocution/SharedElectrocutionSystem.cs
Resources/Prototypes/Entities/Mobs/Player/observer.yml
Resources/Prototypes/Entities/Mobs/Player/silicon.yml
Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml
Resources/Prototypes/Entities/Structures/Walls/fence_metal.yml
Resources/Prototypes/Entities/Structures/Walls/grille.yml
Resources/Textures/Interface/Misc/ai_hud.rsi/apc_hacked.png [new file with mode: 0644]
Resources/Textures/Interface/Misc/ai_hud.rsi/electrified.png [new file with mode: 0644]
Resources/Textures/Interface/Misc/ai_hud.rsi/meta.json [new file with mode: 0644]

diff --git a/Content.Client/Electrocution/ElectrocutionOverlaySystem.cs b/Content.Client/Electrocution/ElectrocutionOverlaySystem.cs
new file mode 100644 (file)
index 0000000..2751c49
--- /dev/null
@@ -0,0 +1,101 @@
+using Content.Shared.Electrocution;
+using Robust.Client.GameObjects;
+using Robust.Client.Player;
+using Robust.Shared.Player;
+
+namespace Content.Client.Electrocution;
+
+/// <summary>
+/// Shows the ElectrocutionOverlay to entities with the ElectrocutionOverlayComponent.
+/// </summary>
+public sealed class ElectrocutionOverlaySystem : EntitySystem
+{
+
+    [Dependency] private readonly AppearanceSystem _appearance = default!;
+    [Dependency] private readonly IPlayerManager _playerMan = default!;
+
+    /// <inheritdoc/>
+    public override void Initialize()
+    {
+        SubscribeLocalEvent<ElectrocutionOverlayComponent, ComponentInit>(OnInit);
+        SubscribeLocalEvent<ElectrocutionOverlayComponent, ComponentShutdown>(OnShutdown);
+        SubscribeLocalEvent<ElectrocutionOverlayComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
+        SubscribeLocalEvent<ElectrocutionOverlayComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
+
+        SubscribeLocalEvent<ElectrifiedComponent, AppearanceChangeEvent>(OnAppearanceChange);
+    }
+
+    private void OnPlayerAttached(Entity<ElectrocutionOverlayComponent> ent, ref LocalPlayerAttachedEvent args)
+    {
+        ShowOverlay();
+    }
+
+    private void OnPlayerDetached(Entity<ElectrocutionOverlayComponent> ent, ref LocalPlayerDetachedEvent args)
+    {
+        RemoveOverlay();
+    }
+
+    private void OnInit(Entity<ElectrocutionOverlayComponent> ent, ref ComponentInit args)
+    {
+        if (_playerMan.LocalEntity == ent)
+        {
+            ShowOverlay();
+        }
+    }
+
+    private void OnShutdown(Entity<ElectrocutionOverlayComponent> ent, ref ComponentShutdown args)
+    {
+        if (_playerMan.LocalEntity == ent)
+        {
+            RemoveOverlay();
+        }
+    }
+
+    private void ShowOverlay()
+    {
+        var electrifiedQuery = AllEntityQuery<ElectrifiedComponent, AppearanceComponent, SpriteComponent>();
+        while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp))
+        {
+            if (!_appearance.TryGetData<bool>(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<ElectrifiedComponent, AppearanceComponent, SpriteComponent>();
+        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<ElectrifiedComponent> ent, ref AppearanceChangeEvent args)
+    {
+        if (args.Sprite == null)
+            return;
+
+        if (!_appearance.TryGetData<bool>(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<ElectrocutionOverlayComponent>(player))
+            args.Sprite.LayerSetVisible(layer, true);
+        else
+            args.Sprite.LayerSetVisible(layer, false);
+    }
+}
index 88404c4aa96052d2f5d28736b6ddc78202f94244..eb10f8d28092d954fcb8c71a3ca3217520251176 100644 (file)
@@ -121,7 +121,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
             activated.TimeLeft -= frameTime;
             if (activated.TimeLeft <= 0 || !IsPowered(uid, electrified, transform))
             {
-                _appearance.SetData(uid, ElectrifiedVisuals.IsPowered, false);
+                _appearance.SetData(uid, ElectrifiedVisuals.ShowSparks, false);
                 RemComp<ActivatedElectrifiedComponent>(uid);
             }
         }
@@ -217,7 +217,7 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
             return false;
 
         EnsureComp<ActivatedElectrifiedComponent>(uid);
-        _appearance.SetData(uid, ElectrifiedVisuals.IsPowered, true);
+        _appearance.SetData(uid, ElectrifiedVisuals.ShowSparks, true);
 
         siemens *= electrified.SiemensCoefficient;
         if (!DoCommonElectrocutionAttempt(targetUid, uid, ref siemens) || siemens <= 0)
@@ -488,15 +488,4 @@ public sealed class ElectrocutionSystem : SharedElectrocutionSystem
         }
         _audio.PlayPvs(electrified.ShockNoises, targetUid, AudioParams.Default.WithVolume(electrified.ShockVolume));
     }
-
-    public void SetElectrifiedWireCut(Entity<ElectrifiedComponent> ent, bool value)
-    {
-        if (ent.Comp.IsWireCut == value)
-        {
-            return;
-        }
-
-        ent.Comp.IsWireCut = value;
-        Dirty(ent);
-    }
 }
index cebb7de8ec868568969e76a4df6161c31d5cc458..9e4e6a6086d190d37e5897a47770789832654273 100644 (file)
@@ -17,7 +17,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;
 
@@ -105,8 +105,8 @@ public sealed partial class PowerWireAction : BaseWireAction
             && !EntityManager.TryGetComponent(used, out electrified))
             return;
 
-        _electrocutionSystem.SetElectrifiedWireCut((used, electrified), setting);
-        electrified.Enabled = setting;
+        _electrocution.SetElectrifiedWireCut((used, electrified), setting);
+        _electrocution.SetElectrified((used, electrified), setting);
     }
 
     /// <returns>false if failed, true otherwise, or if the entity cannot be electrified</returns>
@@ -120,7 +120,7 @@ public sealed partial class PowerWireAction : BaseWireAction
         // 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;
@@ -161,7 +161,7 @@ public sealed partial class PowerWireAction : BaseWireAction
     {
         base.Initialize();
 
-        _electrocutionSystem = EntityManager.System<ElectrocutionSystem>();
+        _electrocution = EntityManager.System<ElectrocutionSystem>();
     }
 
     // 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 (file)
index 0000000..e03e8cb
--- /dev/null
@@ -0,0 +1,9 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Electrocution;
+
+/// <summary>
+/// Allow an entity to see the ElectrocutionOverlay showing electrocuted doors.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class ElectrocutionOverlayComponent : Component;
index 4060856d4d61dc3456fe6825dc3ce3bd7559bcbf..b00fb1afdb7f1922c342a9e0ba808efe64ccf707 100644 (file)
@@ -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
 }
index e36e4a804b7ee1d5a5a20a77819aa27db56c7cc8..5da344e023a8235d5348a0585547934f926caab7 100644 (file)
@@ -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 @@ namespace Content.Shared.Electrocution
 
             ent.Comp.Enabled = value;
             Dirty(ent, ent.Comp);
+
+            _appearance.SetData(ent.Owner, ElectrifiedVisuals.IsElectrified, value);
+        }
+
+        public void SetElectrifiedWireCut(Entity<ElectrifiedComponent> ent, bool value)
+        {
+            if (ent.Comp.IsWireCut == value)
+            {
+                return;
+            }
+
+            ent.Comp.IsWireCut = value;
+            Dirty(ent);
         }
 
         /// <param name="uid">Entity being electrocuted.</param>
index d7c5dfe97bbd0583f299c141f90315b772942246..dc89e635bf0019b83f1817bc2302a1e132878d0e 100644 (file)
@@ -55,6 +55,7 @@
     skipChecks: true
   - type: Ghost
   - type: GhostHearing
+  - type: ElectrocutionOverlay
   - type: IntrinsicRadioReceiver
   - type: ActiveRadio
     receiveAllChannels: true
index bcac46ed842ab8f240b6defb9402ce4f163ce8d6..3b2b65e67908976b0717531e079dd3f9794431d8 100644 (file)
@@ -30,6 +30,7 @@
   - type: IgnoreUIRange
   - type: StationAiHeld
   - type: StationAiOverlay
+  - type: ElectrocutionOverlay
   - type: ActionGrant
     actions:
     - ActionJumpToCore
index fe725b068410e93aa4a5bf93d651848efac1055f..27f4973d050f1b06a263657eb24439072b5d7623 100644 (file)
       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
index 2d0c55af5a7beaa9bdb5c12e93eadb1ea4d6aad3..b5fa7d91902515b3f0cd4cba9f144b42ff0778a5 100644 (file)
@@ -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
@@ -91,7 +91,7 @@
     - state: straight_broken
     - state: electrified
       sprite: Effects/electricity.rsi
-      map: ["enum.ElectrifiedLayers.Powered"]
+      map: ["enum.ElectrifiedLayers.Sparks"]
       shader: unshaded
       visible: false
   - type: Physics
     - state: straight
     - state: electrified
       sprite: Effects/electricity.rsi
-      map: ["enum.ElectrifiedLayers.Powered"]
+      map: ["enum.ElectrifiedLayers.Sparks"]
       shader: unshaded
       visible: false
   - type: Fixtures
     - state: corner
     - state: electrified
       sprite: Effects/electricity.rsi
-      map: ["enum.ElectrifiedLayers.Powered"]
+      map: ["enum.ElectrifiedLayers.Sparks"]
       shader: unshaded
       visible: false
   - type: Fixtures
     - state: end
     - state: electrified
       sprite: Effects/electricity.rsi
-      map: ["enum.ElectrifiedLayers.Powered"]
+      map: ["enum.ElectrifiedLayers.Sparks"]
       shader: unshaded
       visible: false
   - type: Fixtures
       map: ["enum.DoorVisualLayers.Base"]
     - state: electrified
       sprite: Effects/electricity.rsi
-      map: [ "enum.ElectrifiedLayers.Powered" ]
+      map: [ "enum.ElectrifiedLayers.Sparks" ]
       shader: unshaded
       visible: false
   - type: Fixtures
index 2b65528d225064761869390d76c38692399c65f7..3433ffc366ba26170ac4436bc7ed0d024607b440 100644 (file)
@@ -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
         - state: grille_diagonal
         - state: electrified_diagonal
           sprite: Effects/electricity.rsi
-          map: ["enum.ElectrifiedLayers.Powered"]
+          map: ["enum.ElectrifiedLayers.Sparks"]
           shader: unshaded
           visible: false
     - type: Icon
         - 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 (file)
index 0000000..72e111e
Binary files /dev/null and b/Resources/Textures/Interface/Misc/ai_hud.rsi/apc_hacked.png differ
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 (file)
index 0000000..046a307
Binary files /dev/null and b/Resources/Textures/Interface/Misc/ai_hud.rsi/electrified.png differ
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 (file)
index 0000000..7f1e67a
--- /dev/null
@@ -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