* Moved ghost boo to ecs * Fixed small light exception * No need to inject EM * Moved cooldown and time to fields Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
using System;
|
|
using Content.Server.Ghost;
|
|
using Content.Server.Light.Components;
|
|
using Content.Shared.Light;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Timing;
|
|
using Content.Server.Light.Components;
|
|
using Content.Server.MachineLinking.Events;
|
|
using Robust.Shared.GameObjects;
|
|
|
|
namespace Content.Server.Light.EntitySystems
|
|
{
|
|
public class PoweredLightSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<PoweredLightComponent, GhostBooEvent>(OnGhostBoo);
|
|
SubscribeLocalEvent<PoweredLightComponent, SignalReceivedEvent>(OnSignalReceived);
|
|
}
|
|
|
|
private void OnGhostBoo(EntityUid uid, PoweredLightComponent light, GhostBooEvent args)
|
|
{
|
|
if (light.IgnoreGhostsBoo)
|
|
return;
|
|
|
|
// check cooldown first to prevent abuse
|
|
var time = _gameTiming.CurTime;
|
|
if (light.LastGhostBlink != null)
|
|
{
|
|
if (time <= light.LastGhostBlink + light.GhostBlinkingCooldown)
|
|
return;
|
|
}
|
|
|
|
light.LastGhostBlink = time;
|
|
|
|
ToggleBlinkingLight(light, true);
|
|
light.Owner.SpawnTimer(light.GhostBlinkingTime, () =>
|
|
{
|
|
ToggleBlinkingLight(light, false);
|
|
});
|
|
|
|
args.Handled = true;
|
|
}
|
|
|
|
public void ToggleBlinkingLight(PoweredLightComponent light, bool isNowBlinking)
|
|
{
|
|
if (light.IsBlinking == isNowBlinking)
|
|
return;
|
|
|
|
light.IsBlinking = isNowBlinking;
|
|
|
|
if (!light.Owner.TryGetComponent(out AppearanceComponent? appearance))
|
|
return;
|
|
appearance.SetData(PoweredLightVisuals.Blinking, isNowBlinking);
|
|
}
|
|
|
|
private void OnSignalReceived(EntityUid uid, PoweredLightComponent component, SignalReceivedEvent args)
|
|
{
|
|
switch (args.Port)
|
|
{
|
|
case "toggle":
|
|
component.ToggleLight();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|