]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Make hacking energy swords predicted (#34877)
authorPlykiya <58439124+Plykiya@users.noreply.github.com>
Wed, 5 Feb 2025 19:48:28 +0000 (11:48 -0800)
committerGitHub <noreply@github.com>
Wed, 5 Feb 2025 19:48:28 +0000 (20:48 +0100)
* Make hacking energy swords predicted

* Fix up component, add dirty call

* access

* Dirty Entity<T>

* false

Content.Server/Weapons/Melee/EnergySword/EnergySwordComponent.cs [deleted file]
Content.Shared/Weapons/Melee/EnergySword/EnergySwordComponent.cs [new file with mode: 0644]
Content.Shared/Weapons/Melee/EnergySword/EnergySwordSystem.cs [moved from Content.Server/Weapons/Melee/EnergySword/EnergySwordSystem.cs with 53% similarity]

diff --git a/Content.Server/Weapons/Melee/EnergySword/EnergySwordComponent.cs b/Content.Server/Weapons/Melee/EnergySword/EnergySwordComponent.cs
deleted file mode 100644 (file)
index 458c88a..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-namespace Content.Server.Weapons.Melee.EnergySword;
-
-[RegisterComponent]
-internal sealed partial class EnergySwordComponent : Component
-{
-    [ViewVariables(VVAccess.ReadWrite), DataField("activatedColor"), AutoNetworkedField]
-    public Color ActivatedColor = Color.DodgerBlue;
-
-    /// <summary>
-    ///     A color option list for the random color picker.
-    /// </summary>
-    [DataField("colorOptions")]
-    public List<Color> ColorOptions = new()
-    {
-        Color.Tomato,
-        Color.DodgerBlue,
-        Color.Aqua,
-        Color.MediumSpringGreen,
-        Color.MediumOrchid
-    };
-
-    public bool Hacked = false;
-    /// <summary>
-    ///     RGB cycle rate for hacked e-swords.
-    /// </summary>
-    [DataField("cycleRate")]
-    public float CycleRate = 1f;
-}
diff --git a/Content.Shared/Weapons/Melee/EnergySword/EnergySwordComponent.cs b/Content.Shared/Weapons/Melee/EnergySword/EnergySwordComponent.cs
new file mode 100644 (file)
index 0000000..ba84acb
--- /dev/null
@@ -0,0 +1,40 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Weapons.Melee.EnergySword;
+
+[RegisterComponent, NetworkedComponent, Access(typeof(EnergySwordSystem))]
+[AutoGenerateComponentState]
+public sealed partial class EnergySwordComponent : Component
+{
+    /// <summary>
+    /// What color the blade will be when activated.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public Color ActivatedColor = Color.DodgerBlue;
+
+    /// <summary>
+    ///     A color option list for the random color picker.
+    /// </summary>
+    [DataField]
+    public List<Color> ColorOptions = new()
+    {
+        Color.Tomato,
+        Color.DodgerBlue,
+        Color.Aqua,
+        Color.MediumSpringGreen,
+        Color.MediumOrchid
+    };
+
+    /// <summary>
+    /// Whether the energy sword has been pulsed by a multitool,
+    /// causing the blade to cycle RGB colors.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool Hacked;
+
+    /// <summary>
+    ///     RGB cycle rate for hacked e-swords.
+    /// </summary>
+    [DataField]
+    public float CycleRate = 1f;
+}
similarity index 53%
rename from Content.Server/Weapons/Melee/EnergySword/EnergySwordSystem.cs
rename to Content.Shared/Weapons/Melee/EnergySword/EnergySwordSystem.cs
index c9be87c623188be9d3460fb3b619cd3f5c4caf8b..7ca3de9cc5c972b39ae54b654f5eda7127e2b665 100644 (file)
@@ -5,7 +5,7 @@ using Content.Shared.Toggleable;
 using Content.Shared.Tools.Systems;
 using Robust.Shared.Random;
 
-namespace Content.Server.Weapons.Melee.EnergySword;
+namespace Content.Shared.Weapons.Melee.EnergySword;
 
 public sealed class EnergySwordSystem : EntitySystem
 {
@@ -22,18 +22,22 @@ public sealed class EnergySwordSystem : EntitySystem
         SubscribeLocalEvent<EnergySwordComponent, InteractUsingEvent>(OnInteractUsing);
     }
     // Used to pick a random color for the blade on map init.
-    private void OnMapInit(EntityUid uid, EnergySwordComponent comp, MapInitEvent args)
+    private void OnMapInit(Entity<EnergySwordComponent> entity, ref MapInitEvent args)
     {
-        if (comp.ColorOptions.Count != 0)
-            comp.ActivatedColor = _random.Pick(comp.ColorOptions);
+        if (entity.Comp.ColorOptions.Count != 0)
+        {
+            entity.Comp.ActivatedColor = _random.Pick(entity.Comp.ColorOptions);
+            Dirty(entity);
+        }
 
-        if (!TryComp(uid, out AppearanceComponent? appearanceComponent))
+        if (!TryComp(entity, out AppearanceComponent? appearanceComponent))
             return;
-        _appearance.SetData(uid, ToggleableLightVisuals.Color, comp.ActivatedColor, appearanceComponent);
+
+        _appearance.SetData(entity, ToggleableLightVisuals.Color, entity.Comp.ActivatedColor, appearanceComponent);
     }
 
-    // Used to make the make the blade multicolored when using a multitool on it.
-    private void OnInteractUsing(EntityUid uid, EnergySwordComponent comp, InteractUsingEvent args)
+    // Used to make the blade multicolored when using a multitool on it.
+    private void OnInteractUsing(Entity<EnergySwordComponent> entity, ref InteractUsingEvent args)
     {
         if (args.Handled)
             return;
@@ -42,14 +46,16 @@ public sealed class EnergySwordSystem : EntitySystem
             return;
 
         args.Handled = true;
-        comp.Hacked = !comp.Hacked;
+        entity.Comp.Hacked = !entity.Comp.Hacked;
 
-        if (comp.Hacked)
+        if (entity.Comp.Hacked)
         {
-            var rgb = EnsureComp<RgbLightControllerComponent>(uid);
-            _rgbSystem.SetCycleRate(uid, comp.CycleRate, rgb);
+            var rgb = EnsureComp<RgbLightControllerComponent>(entity);
+            _rgbSystem.SetCycleRate(entity, entity.Comp.CycleRate, rgb);
         }
         else
-            RemComp<RgbLightControllerComponent>(uid);
+            RemComp<RgbLightControllerComponent>(entity);
+
+        Dirty(entity);
     }
 }