Emergency light goodies (#9352)
Co-authored-by: Jacob Tong <10494922+ShadowCommander@users.noreply.github.com>
This commit is contained in:
@@ -1,23 +1,33 @@
|
||||
using System.Drawing;
|
||||
using Content.Server.AlertLevel;
|
||||
using Content.Server.Audio;
|
||||
using Content.Server.Light.Components;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Light;
|
||||
using Content.Shared.Light.Component;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Color = Robust.Shared.Maths.Color;
|
||||
|
||||
namespace Content.Server.Light.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class EmergencyLightSystem : SharedEmergencyLightSystem
|
||||
{
|
||||
[Dependency] private readonly AmbientSoundSystem _ambient = default!;
|
||||
[Dependency] private readonly StationSystem _station = default!;
|
||||
|
||||
private readonly HashSet<EmergencyLightComponent> _activeLights = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<EmergencyLightEvent>(HandleEmergencyLightMessage);
|
||||
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertLevelChanged);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, ComponentGetState>(GetCompState);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, PointLightToggleEvent>(HandleLightToggle);
|
||||
SubscribeLocalEvent<EmergencyLightComponent, ExaminedEvent>(OnEmergencyExamine);
|
||||
@@ -35,6 +45,24 @@ namespace Content.Server.Light.EntitySystems
|
||||
Loc.GetString("emergency-light-component-on-examine",
|
||||
("batteryStateText",
|
||||
Loc.GetString(component.BatteryStateText[component.State]))));
|
||||
|
||||
// Show alert level on the light itself.
|
||||
if (!TryComp<AlertLevelComponent>(_station.GetOwningStation(uid), out var alerts))
|
||||
return;
|
||||
|
||||
if (alerts.AlertLevels == null)
|
||||
return;
|
||||
|
||||
var name = alerts.CurrentLevel;
|
||||
|
||||
var color = Color.White;
|
||||
if (alerts.AlertLevels.Levels.TryGetValue(alerts.CurrentLevel, out var details))
|
||||
color = details.Color;
|
||||
|
||||
args.PushMarkup(
|
||||
Loc.GetString("emergency-light-component-on-examine-alert",
|
||||
("color", color.ToHex()),
|
||||
("level", name)));
|
||||
}
|
||||
|
||||
private void HandleLightToggle(EntityUid uid, EmergencyLightComponent component, PointLightToggleEvent args)
|
||||
@@ -66,6 +94,36 @@ namespace Content.Server.Light.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAlertLevelChanged(AlertLevelChangedEvent ev)
|
||||
{
|
||||
if (!TryComp<AlertLevelComponent>(ev.Station, out var alert))
|
||||
return;
|
||||
|
||||
if (alert.AlertLevels == null || !alert.AlertLevels.Levels.TryGetValue(ev.AlertLevel, out var details))
|
||||
return;
|
||||
|
||||
foreach (var (light, pointLight, appearance, xform) in EntityQuery<EmergencyLightComponent, PointLightComponent, AppearanceComponent, TransformComponent>())
|
||||
{
|
||||
if (CompOrNull<StationMemberComponent>(xform.GridUid)?.Station != ev.Station)
|
||||
continue;
|
||||
|
||||
pointLight.Color = details.EmergencyLightColor;
|
||||
appearance.SetData(EmergencyLightVisuals.Color, details.EmergencyLightColor);
|
||||
|
||||
if (details.ForceEnableEmergencyLights && !light.ForciblyEnabled)
|
||||
{
|
||||
light.ForciblyEnabled = true;
|
||||
TurnOn(light);
|
||||
}
|
||||
else if (!details.ForceEnableEmergencyLights && light.ForciblyEnabled)
|
||||
{
|
||||
// Previously forcibly enabled, and we went down an alert level.
|
||||
light.ForciblyEnabled = false;
|
||||
UpdateState(light);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(EmergencyLightComponent component, EmergencyLightState state)
|
||||
{
|
||||
if (component.State == state) return;
|
||||
@@ -122,7 +180,7 @@ namespace Content.Server.Light.EntitySystems
|
||||
return;
|
||||
}
|
||||
|
||||
if (receiver.Powered)
|
||||
if (receiver.Powered && !component.ForciblyEnabled)
|
||||
{
|
||||
receiver.Load = (int) Math.Abs(component.Wattage);
|
||||
TurnOff(component);
|
||||
@@ -144,6 +202,8 @@ namespace Content.Server.Light.EntitySystems
|
||||
|
||||
if (TryComp(component.Owner, out AppearanceComponent? appearance))
|
||||
appearance.SetData(EmergencyLightVisuals.On, false);
|
||||
|
||||
_ambient.SetAmbience(component.Owner, false);
|
||||
}
|
||||
|
||||
private void TurnOn(EmergencyLightComponent component)
|
||||
@@ -154,7 +214,12 @@ namespace Content.Server.Light.EntitySystems
|
||||
}
|
||||
|
||||
if (TryComp(component.Owner, out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(EmergencyLightVisuals.On, true);
|
||||
}
|
||||
|
||||
_ambient.SetAmbience(component.Owner, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user