| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using Content.Shared.Interaction;
- using Content.Shared.Light;
- using Content.Shared.Light.Components;
- using Content.Shared.Toggleable;
- using Content.Shared.Tools.Systems;
- using Robust.Shared.Random;
- namespace Content.Shared.Weapons.Melee.EnergySword;
- public sealed class EnergySwordSystem : EntitySystem
- {
- [Dependency] private readonly SharedRgbLightControllerSystem _rgbSystem = default!;
- [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
- [Dependency] private readonly IRobustRandom _random = default!;
- [Dependency] private readonly SharedToolSystem _toolSystem = default!;
- public override void Initialize()
- {
- base.Initialize();
- SubscribeLocalEvent<EnergySwordComponent, MapInitEvent>(OnMapInit);
- SubscribeLocalEvent<EnergySwordComponent, InteractUsingEvent>(OnInteractUsing);
- }
- // Used to pick a random color for the blade on map init.
- private void OnMapInit(Entity<EnergySwordComponent> entity, ref MapInitEvent args)
- {
- if (entity.Comp.ColorOptions.Count != 0)
- {
- entity.Comp.ActivatedColor = _random.Pick(entity.Comp.ColorOptions);
- Dirty(entity);
- }
- if (!TryComp(entity, out AppearanceComponent? appearanceComponent))
- return;
- _appearance.SetData(entity, ToggleableLightVisuals.Color, entity.Comp.ActivatedColor, appearanceComponent);
- }
- // 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;
- if (!_toolSystem.HasQuality(args.Used, SharedToolSystem.PulseQuality))
- return;
- args.Handled = true;
- entity.Comp.Hacked = !entity.Comp.Hacked;
- if (entity.Comp.Hacked)
- {
- var rgb = EnsureComp<RgbLightControllerComponent>(entity);
- _rgbSystem.SetCycleRate(entity, entity.Comp.CycleRate, rgb);
- }
- else
- RemComp<RgbLightControllerComponent>(entity);
- Dirty(entity);
- }
- }
|