From 0d9f9e96159bee861c1214f4d3c0e6bbfb3fef9e Mon Sep 17 00:00:00 2001 From: Plykiya <58439124+Plykiya@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:48:28 -0800 Subject: [PATCH] Make hacking energy swords predicted (#34877) * Make hacking energy swords predicted * Fix up component, add dirty call * access * Dirty Entity * false --- .../Melee/EnergySword/EnergySwordComponent.cs | 28 ------------- .../Melee/EnergySword/EnergySwordComponent.cs | 40 +++++++++++++++++++ .../Melee/EnergySword/EnergySwordSystem.cs | 32 +++++++++------ 3 files changed, 59 insertions(+), 41 deletions(-) delete mode 100644 Content.Server/Weapons/Melee/EnergySword/EnergySwordComponent.cs create mode 100644 Content.Shared/Weapons/Melee/EnergySword/EnergySwordComponent.cs rename {Content.Server => Content.Shared}/Weapons/Melee/EnergySword/EnergySwordSystem.cs (53%) diff --git a/Content.Server/Weapons/Melee/EnergySword/EnergySwordComponent.cs b/Content.Server/Weapons/Melee/EnergySword/EnergySwordComponent.cs deleted file mode 100644 index 458c88af3e..0000000000 --- a/Content.Server/Weapons/Melee/EnergySword/EnergySwordComponent.cs +++ /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; - - /// - /// A color option list for the random color picker. - /// - [DataField("colorOptions")] - public List ColorOptions = new() - { - Color.Tomato, - Color.DodgerBlue, - Color.Aqua, - Color.MediumSpringGreen, - Color.MediumOrchid - }; - - public bool Hacked = false; - /// - /// RGB cycle rate for hacked e-swords. - /// - [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 index 0000000000..ba84acb617 --- /dev/null +++ b/Content.Shared/Weapons/Melee/EnergySword/EnergySwordComponent.cs @@ -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 +{ + /// + /// What color the blade will be when activated. + /// + [DataField, AutoNetworkedField] + public Color ActivatedColor = Color.DodgerBlue; + + /// + /// A color option list for the random color picker. + /// + [DataField] + public List ColorOptions = new() + { + Color.Tomato, + Color.DodgerBlue, + Color.Aqua, + Color.MediumSpringGreen, + Color.MediumOrchid + }; + + /// + /// Whether the energy sword has been pulsed by a multitool, + /// causing the blade to cycle RGB colors. + /// + [DataField, AutoNetworkedField] + public bool Hacked; + + /// + /// RGB cycle rate for hacked e-swords. + /// + [DataField] + public float CycleRate = 1f; +} diff --git a/Content.Server/Weapons/Melee/EnergySword/EnergySwordSystem.cs b/Content.Shared/Weapons/Melee/EnergySword/EnergySwordSystem.cs similarity index 53% rename from Content.Server/Weapons/Melee/EnergySword/EnergySwordSystem.cs rename to Content.Shared/Weapons/Melee/EnergySword/EnergySwordSystem.cs index c9be87c623..7ca3de9cc5 100644 --- a/Content.Server/Weapons/Melee/EnergySword/EnergySwordSystem.cs +++ b/Content.Shared/Weapons/Melee/EnergySword/EnergySwordSystem.cs @@ -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(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 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 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(uid); - _rgbSystem.SetCycleRate(uid, comp.CycleRate, rgb); + var rgb = EnsureComp(entity); + _rgbSystem.SetCycleRate(entity, entity.Comp.CycleRate, rgb); } else - RemComp(uid); + RemComp(entity); + + Dirty(entity); } } -- 2.51.2