Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make hacking energy swords predicted #34877

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Robust.Shared.GameStates;

namespace Content.Shared.Weapons.Melee.EnergySword;

[RegisterComponent, NetworkedComponent, Access(typeof(EnergySwordSystem))]
[AutoGenerateComponentState]
Plykiya marked this conversation as resolved.
Show resolved Hide resolved
public sealed partial class EnergySwordComponent : Component
{
/// <summary>
/// What color the blade will be when activated.
/// </summary>
[DataField, AutoNetworkedField]
public Color ActivatedColor = Color.DodgerBlue;

/// <summary>
Plykiya marked this conversation as resolved.
Show resolved Hide resolved
/// 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
{
Expand All @@ -22,18 +22,22 @@ public override void Initialize()
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);
Plykiya marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand All @@ -42,14 +46,16 @@ private void OnInteractUsing(EntityUid uid, EnergySwordComponent comp, InteractU
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);
}
}
Loading