using Content.Server.Ghost;
using Content.Shared.Light.Components;
using Content.Shared.Light.EntitySystems;
namespace Content.Server.Light.EntitySystems;
///
/// System for the PoweredLightComponents
///
public sealed class PoweredLightSystem : SharedPoweredLightSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnMapInit);
SubscribeLocalEvent(OnGhostBoo);
}
private void OnGhostBoo(EntityUid uid, PoweredLightComponent light, GhostBooEvent args)
{
if (light.IgnoreGhostsBoo || HasComp(uid))
return; // The light is immune or already blinking.
// check cooldown first to prevent abuse
var curTime = GameTiming.CurTime;
if (light.LastGhostBlink != null && curTime <= light.LastGhostBlink + light.GhostBlinkingCooldown)
return;
light.LastGhostBlink = curTime;
var blinkingComp = EnsureComp(uid);
blinkingComp.StopBlinkingTime = curTime + light.GhostBlinkingTime;
Dirty(uid, blinkingComp);
args.Handled = true;
}
private void OnMapInit(EntityUid uid, PoweredLightComponent light, MapInitEvent args)
{
// TODO: Use ContainerFill dog
if (light.HasLampOnSpawn != null)
{
var entity = Spawn(light.HasLampOnSpawn, Comp(uid).Coordinates);
ContainerSystem.Insert(entity, light.LightBulbContainer);
}
// need this to update visualizers
UpdateLight(uid, light);
}
}