Files
tbd-station-14/Content.Server/Light/EntitySystems/PoweredLightSystem.cs
metalgearsloth fd52f698c7 Predict PoweredLights (#36541)
* Move PoweredLight to shared

* Predict the rest of the owl

* reacher

* compinit & anim

* Fix names

* Revert this?

* Fix these

* chicken drummies

* deita

* Fix

* review

* fix

* fixes

* fix PVS weirdness

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2025-08-11 23:06:28 +02:00

65 lines
1.9 KiB
C#

using Content.Server.Emp;
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);
SubscribeLocalEvent<PoweredLightComponent, EmpPulseEvent>(OnEmpPulse);
}
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);
}
private void OnEmpPulse(EntityUid uid, PoweredLightComponent component, ref EmpPulseEvent args)
{
if (TryDestroyBulb(uid, component))
args.Affected = true;
}
}