2023-10-19 12:34:31 -07:00
|
|
|
using Content.Server.Emp;
|
2021-08-31 11:33:55 +03:00
|
|
|
using Content.Server.Ghost;
|
2023-09-04 06:31:10 +01:00
|
|
|
using Content.Shared.Light.Components;
|
2025-08-12 07:06:28 +10:00
|
|
|
using Content.Shared.Light.EntitySystems;
|
2021-08-27 17:46:02 +02:00
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
namespace Content.Server.Light.EntitySystems;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// System for the PoweredLightComponents
|
|
|
|
|
/// </summary>
|
|
|
|
|
public sealed class PoweredLightSystem : SharedPoweredLightSystem
|
2021-08-27 17:46:02 +02:00
|
|
|
{
|
2025-08-12 07:06:28 +10:00
|
|
|
public override void Initialize()
|
2021-08-27 17:46:02 +02:00
|
|
|
{
|
2025-08-12 07:06:28 +10:00
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<PoweredLightComponent, MapInitEvent>(OnMapInit);
|
2021-10-27 04:24:22 +03:00
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
SubscribeLocalEvent<PoweredLightComponent, GhostBooEvent>(OnGhostBoo);
|
2021-10-27 04:24:22 +03:00
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
SubscribeLocalEvent<PoweredLightComponent, EmpPulseEvent>(OnEmpPulse);
|
|
|
|
|
}
|
2021-10-24 01:23:19 +02:00
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
private void OnGhostBoo(EntityUid uid, PoweredLightComponent light, GhostBooEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (light.IgnoreGhostsBoo)
|
|
|
|
|
return;
|
2021-10-24 01:23:19 +02:00
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
// check cooldown first to prevent abuse
|
|
|
|
|
var time = GameTiming.CurTime;
|
|
|
|
|
if (light.LastGhostBlink != null)
|
2021-10-01 13:59:06 -07:00
|
|
|
{
|
2025-08-12 07:06:28 +10:00
|
|
|
if (time <= light.LastGhostBlink + light.GhostBlinkingCooldown)
|
2021-10-27 04:24:22 +03:00
|
|
|
return;
|
2021-10-01 13:59:06 -07:00
|
|
|
}
|
|
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
light.LastGhostBlink = time;
|
2021-10-27 04:24:22 +03:00
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
ToggleBlinkingLight(uid, light, true);
|
|
|
|
|
uid.SpawnTimer(light.GhostBlinkingTime, () =>
|
2021-10-27 04:24:22 +03:00
|
|
|
{
|
2025-08-12 07:06:28 +10:00
|
|
|
ToggleBlinkingLight(uid, light, false);
|
|
|
|
|
});
|
2021-10-27 04:24:22 +03:00
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
2022-06-21 20:55:06 -04:00
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
private void OnMapInit(EntityUid uid, PoweredLightComponent light, MapInitEvent args)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Use ContainerFill dog
|
|
|
|
|
if (light.HasLampOnSpawn != null)
|
2022-06-21 20:55:06 -04:00
|
|
|
{
|
2025-08-12 07:06:28 +10:00
|
|
|
var entity = EntityManager.SpawnEntity(light.HasLampOnSpawn, EntityManager.GetComponent<TransformComponent>(uid).Coordinates);
|
|
|
|
|
ContainerSystem.Insert(entity, light.LightBulbContainer);
|
2022-06-21 20:55:06 -04:00
|
|
|
}
|
2025-08-12 07:06:28 +10:00
|
|
|
// need this to update visualizers
|
|
|
|
|
UpdateLight(uid, light);
|
|
|
|
|
}
|
2023-03-06 22:05:12 +03:00
|
|
|
|
2025-08-12 07:06:28 +10:00
|
|
|
private void OnEmpPulse(EntityUid uid, PoweredLightComponent component, ref EmpPulseEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (TryDestroyBulb(uid, component))
|
|
|
|
|
args.Affected = true;
|
2021-08-27 17:46:02 +02:00
|
|
|
}
|
|
|
|
|
}
|