]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Makes unpowered flashlights emmagables. (#16143)
authorAJCM-git <60196617+AJCM-git@users.noreply.github.com>
Sun, 7 May 2023 06:08:03 +0000 (02:08 -0400)
committerGitHub <noreply@github.com>
Sun, 7 May 2023 06:08:03 +0000 (16:08 +1000)
Content.Server/Light/EntitySystems/UnpoweredFlashlightSystem.cs
Content.Shared/Light/Component/UnpoweredFlashlightComponent.cs
Resources/Prototypes/Palettes/emagged.yml [new file with mode: 0644]

index 558ed39a2cdff8d47c571d6f4e049aaa9b355e0c..bd6c0d5dba549bbda4fedaa308cc9d1acaf6f9db 100644 (file)
@@ -1,22 +1,26 @@
-using Content.Server.Light.Components;
 using Content.Server.Light.Events;
 using Content.Server.Mind.Components;
 using Content.Shared.Actions;
+using Content.Shared.Decals;
+using Content.Shared.Emag.Systems;
 using Content.Shared.Light;
 using Content.Shared.Light.Component;
 using Content.Shared.Toggleable;
 using Content.Shared.Verbs;
 using Robust.Server.GameObjects;
-using Robust.Shared.Audio;
-using Robust.Shared.Player;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Random;
 using Robust.Shared.Utility;
 
 namespace Content.Server.Light.EntitySystems
 {
     public sealed class UnpoweredFlashlightSystem : EntitySystem
     {
+        [Dependency] private readonly IRobustRandom _random = default!;
         [Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
         [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
+        [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+        [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
 
         public override void Initialize()
         {
@@ -26,6 +30,7 @@ namespace Content.Server.Light.EntitySystems
             SubscribeLocalEvent<UnpoweredFlashlightComponent, GetItemActionsEvent>(OnGetActions);
             SubscribeLocalEvent<UnpoweredFlashlightComponent, ToggleActionEvent>(OnToggleAction);
             SubscribeLocalEvent<UnpoweredFlashlightComponent, MindAddedMessage>(OnMindAdded);
+            SubscribeLocalEvent<UnpoweredFlashlightComponent, GotEmaggedEvent>(OnGotEmagged);
         }
 
         private void OnToggleAction(EntityUid uid, UnpoweredFlashlightComponent component, ToggleActionEvent args)
@@ -48,11 +53,13 @@ namespace Content.Server.Light.EntitySystems
             if (!args.CanAccess || !args.CanInteract)
                 return;
 
-            ActivationVerb verb = new();
-            verb.Text = Loc.GetString("toggle-flashlight-verb-get-data-text");
-            verb.Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/light.svg.192dpi.png"));
-            verb.Act = () => ToggleLight(uid, component);
-            verb.Priority = -1; // For things like PDA's, Open-UI and other verbs that should be higher priority.
+            ActivationVerb verb = new()
+            {
+                Text = Loc.GetString("toggle-flashlight-verb-get-data-text"),
+                Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/light.svg.192dpi.png")),
+                Act = () => ToggleLight(uid, component),
+                Priority = -1 // For things like PDA's, Open-UI and other verbs that should be higher priority.
+            };
 
             args.Verbs.Add(verb);
         }
@@ -61,20 +68,35 @@ namespace Content.Server.Light.EntitySystems
         {
             _actionsSystem.AddAction(uid, component.ToggleAction, null);
         }
+
+        private void OnGotEmagged(EntityUid uid, UnpoweredFlashlightComponent component, ref GotEmaggedEvent args)
+        {
+            if (!TryComp<PointLightComponent>(uid, out var light))
+                return;
+
+            if (_prototypeManager.TryIndex<ColorPalettePrototype>(component.EmaggedColorsPrototype, out var possibleColors))
+            {
+                var pick = _random.Pick(possibleColors.Colors.Values);
+                light.Color = pick;
+            }
+
+            args.Repeatable = true;
+            args.Handled = true;
+        }
+
         public void ToggleLight(EntityUid uid, UnpoweredFlashlightComponent flashlight)
         {
-            if (!EntityManager.TryGetComponent(flashlight.Owner, out PointLightComponent? light))
+            if (!TryComp<PointLightComponent>(uid, out var light))
                 return;
 
             flashlight.LightOn = !flashlight.LightOn;
             light.Enabled = flashlight.LightOn;
 
-            if (EntityManager.TryGetComponent(flashlight.Owner, out AppearanceComponent? appearance))
-                _appearance.SetData(uid, UnpoweredFlashlightVisuals.LightOn, flashlight.LightOn, appearance);
+            _appearance.SetData(uid, UnpoweredFlashlightVisuals.LightOn, flashlight.LightOn);
 
-            SoundSystem.Play(flashlight.ToggleSound.GetSound(), Filter.Pvs(light.Owner), flashlight.Owner);
+            _audioSystem.PlayPvs(flashlight.ToggleSound, uid);
 
-            RaiseLocalEvent(flashlight.Owner, new LightToggleEvent(flashlight.LightOn), true);
+            RaiseLocalEvent(uid, new LightToggleEvent(flashlight.LightOn), true);
             _actionsSystem.SetToggled(flashlight.ToggleAction, flashlight.LightOn);
         }
     }
index f9d572e69d394424ed719ce3b8c133cf4ab7422b..108c252b6141e820d0ee6e4c3f23af312316e7ec 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Shared.Actions.ActionTypes;
+using Content.Shared.Decals;
 using Robust.Shared.Audio;
 
 namespace Content.Shared.Light.Component;
@@ -17,4 +18,12 @@ public sealed class UnpoweredFlashlightComponent : Robust.Shared.GameObjects.Com
 
     [DataField("toggleAction", required: true)]
     public InstantAction ToggleAction = new();
+
+    /// <summary>
+    ///  <see cref="ColorPalettePrototype"/> ID that determines the list
+    /// of colors to select from when we get emagged
+    /// </summary>
+    [DataField("emaggedColorsPrototype")]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public string EmaggedColorsPrototype = "Emagged";
 }
diff --git a/Resources/Prototypes/Palettes/emagged.yml b/Resources/Prototypes/Palettes/emagged.yml
new file mode 100644 (file)
index 0000000..37b4e4e
--- /dev/null
@@ -0,0 +1,11 @@
+- type: palette
+  id: Emagged
+  name: Emagged
+  colors:
+    red: "#FF0000"
+    orange: "#FFA500"
+    yellow: "#FFFF00"
+    lime: "#32CD32"
+    bright_blue: "#0096FF"
+    cyan: "#00FFFF"
+    purple: "#A020F0"