+++ /dev/null
-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;
-}
--- /dev/null
+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;
+}
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
{
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;
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);
}
}