Make hacking energy swords predicted (#34877)

* Make hacking energy swords predicted

* Fix up component, add dirty call

* access

* Dirty Entity<T>

* false
This commit is contained in:
Plykiya 2025-02-05 11:48:28 -08:00 committed by deltanedas
parent 02f7614578
commit 7eb15610b3
3 changed files with 59 additions and 41 deletions

View File

@ -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;
}

View File

@ -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;
}

View 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);
}
}