Make energy swords use RgbLightController (#7344)

This commit is contained in:
Leon Friedrich
2022-04-16 17:11:48 +12:00
committed by GitHub
parent 1dcaa2d44b
commit a231429cb4
35 changed files with 240 additions and 583 deletions

View File

@@ -1,12 +1,11 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Item;
using Content.Shared.Light;
using Content.Shared.Light.Component;
using Content.Shared.Toggleable;
using Content.Shared.Tools.Components;
using Content.Shared.Weapons.Melee;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Player;
using Robust.Shared.Random;
@@ -15,6 +14,7 @@ namespace Content.Server.Weapon.Melee.EnergySword
public sealed class EnergySwordSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedRgbLightControllerSystem _rgbSystem = default!;
public override void Initialize()
{
@@ -55,6 +55,8 @@ namespace Content.Server.Weapon.Melee.EnergySword
{
TurnOn(comp);
}
UpdateAppearance(comp);
}
private void TurnOff(EnergySwordComponent comp)
@@ -67,10 +69,9 @@ namespace Content.Server.Weapon.Melee.EnergySword
item.Size = 5;
}
SoundSystem.Play(Filter.Pvs(comp.Owner), comp.DeActivateSound.GetSound(), comp.Owner);
SoundSystem.Play(Filter.Pvs(comp.Owner, entityManager: EntityManager), comp.DeActivateSound.GetSound(), comp.Owner);
comp.Activated = false;
UpdateAppearance(comp, item);
}
private void TurnOn(EnergySwordComponent comp)
@@ -83,43 +84,36 @@ namespace Content.Server.Weapon.Melee.EnergySword
item.Size = 9999;
}
SoundSystem.Play(Filter.Pvs(comp.Owner), comp.ActivateSound.GetSound(), comp.Owner);
SoundSystem.Play(Filter.Pvs(comp.Owner, entityManager: EntityManager), comp.ActivateSound.GetSound(), comp.Owner);
comp.Activated = true;
UpdateAppearance(comp, item);
}
private void UpdateAppearance(EnergySwordComponent component, SharedItemComponent? itemComponent = null)
private void UpdateAppearance(EnergySwordComponent component)
{
if (!EntityManager.TryGetComponent(component.Owner, out AppearanceComponent? appearanceComponent)) return;
if (!TryComp(component.Owner, out AppearanceComponent? appearanceComponent))
return;
appearanceComponent.SetData(EnergySwordVisuals.Color, component.BladeColor);
var status = component.Activated ? EnergySwordStatus.On : EnergySwordStatus.Off;
if (component.Hacked)
status |= EnergySwordStatus.Hacked;
appearanceComponent.SetData(EnergySwordVisuals.State, status);
// wew itemcomp
if (Resolve(component.Owner, ref itemComponent, false))
{
itemComponent.EquippedPrefix = component.Activated ? "on" : "off";
itemComponent.Color = component.BladeColor;
}
appearanceComponent.SetData(ToggleableLightVisuals.Enabled, component.Activated);
appearanceComponent.SetData(ToggleableLightVisuals.Color, component.BladeColor);
}
private void OnInteractUsing(EntityUid uid, EnergySwordComponent comp, InteractUsingEvent args)
{
if (args.Handled) return;
if (comp.Hacked)
return;
if (!TryComp(args.Used, out ToolComponent? tool) || !tool.Qualities.ContainsAny("Pulsing")) return;
args.Handled = true;
comp.Hacked = true;
UpdateAppearance(comp);
comp.Hacked = !comp.Hacked;
if (comp.Hacked)
{
var rgb = EnsureComp<RgbLightControllerComponent>(uid);
_rgbSystem.SetCycleRate(uid, comp.CycleRate, rgb);
}
else
RemComp<RgbLightControllerComponent>(uid);
}
}
}