56 lines
1.6 KiB
C#
56 lines
1.6 KiB
C#
using Content.Server.Ghost;
|
|
using Content.Shared.Light.Components;
|
|
using Content.Shared.Light.EntitySystems;
|
|
|
|
namespace Content.Server.Light.EntitySystems;
|
|
|
|
/// <summary>
|
|
/// System for the PoweredLightComponents
|
|
/// </summary>
|
|
public sealed class PoweredLightSystem : SharedPoweredLightSystem
|
|
{
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<PoweredLightComponent, MapInitEvent>(OnMapInit);
|
|
|
|
SubscribeLocalEvent<PoweredLightComponent, GhostBooEvent>(OnGhostBoo);
|
|
}
|
|
|
|
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(uid, light, true);
|
|
uid.SpawnTimer(light.GhostBlinkingTime, () =>
|
|
{
|
|
ToggleBlinkingLight(uid, light, false);
|
|
});
|
|
|
|
args.Handled = true;
|
|
}
|
|
|
|
private void OnMapInit(EntityUid uid, PoweredLightComponent light, MapInitEvent args)
|
|
{
|
|
// TODO: Use ContainerFill dog
|
|
if (light.HasLampOnSpawn != null)
|
|
{
|
|
var entity = EntityManager.SpawnEntity(light.HasLampOnSpawn, EntityManager.GetComponent<TransformComponent>(uid).Coordinates);
|
|
ContainerSystem.Insert(entity, light.LightBulbContainer);
|
|
}
|
|
// need this to update visualizers
|
|
UpdateLight(uid, light);
|
|
}
|
|
}
|