ECSatize AlertsSystem (#5559)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Alert;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Atmos;
|
||||
@@ -16,11 +15,11 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
{
|
||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
|
||||
[Dependency] private readonly AdminLogSystem _logSystem = default!;
|
||||
|
||||
private const float UpdateTimer = 1f;
|
||||
|
||||
private float _timer = 0f;
|
||||
private float _timer;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -72,7 +71,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
_timer -= UpdateTimer;
|
||||
|
||||
foreach (var (barotrauma, damageable, transform) in EntityManager.EntityQuery<BarotraumaComponent, DamageableComponent, TransformComponent>(false))
|
||||
foreach (var (barotrauma, damageable, transform) in EntityManager.EntityQuery<BarotraumaComponent, DamageableComponent, TransformComponent>())
|
||||
{
|
||||
var totalDamage = FixedPoint2.Zero;
|
||||
foreach (var (barotraumaDamageType, _) in barotrauma.Damage.DamageDict)
|
||||
@@ -84,28 +83,24 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
if (totalDamage >= barotrauma.MaxDamage)
|
||||
continue;
|
||||
|
||||
var uid = barotrauma.Owner;
|
||||
|
||||
var status = EntityManager.GetComponentOrNull<ServerAlertsComponent>(barotrauma.Owner);
|
||||
|
||||
var pressure = 1f;
|
||||
|
||||
if (_atmosphereSystem.GetTileMixture(transform.Coordinates) is { } mixture)
|
||||
{
|
||||
pressure = MathF.Max(mixture.Pressure, 1f);;
|
||||
pressure = MathF.Max(mixture.Pressure, 1f);
|
||||
}
|
||||
|
||||
switch (pressure)
|
||||
{
|
||||
// Low pressure.
|
||||
case <= Atmospherics.WarningLowPressure:
|
||||
pressure = GetFeltLowPressure(uid, pressure);
|
||||
pressure = GetFeltLowPressure(barotrauma.Owner, pressure);
|
||||
|
||||
if (pressure > Atmospherics.WarningLowPressure)
|
||||
goto default;
|
||||
|
||||
// Deal damage and ignore resistances. Resistance to pressure damage should be done via pressure protection gear.
|
||||
_damageableSystem.TryChangeDamage(uid, barotrauma.Damage * Atmospherics.LowPressureDamage, true, false);
|
||||
_damageableSystem.TryChangeDamage(barotrauma.Owner, barotrauma.Damage * Atmospherics.LowPressureDamage, true, false);
|
||||
|
||||
if (!barotrauma.TakingDamage)
|
||||
{
|
||||
@@ -113,20 +108,18 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
_logSystem.Add(LogType.Barotrauma, $"{ToPrettyString(barotrauma.Owner):entity} started taking low pressure damage");
|
||||
}
|
||||
|
||||
if (status == null) break;
|
||||
|
||||
if (pressure <= Atmospherics.HazardLowPressure)
|
||||
{
|
||||
status.ShowAlert(AlertType.LowPressure, 2);
|
||||
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.LowPressure, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
status.ShowAlert(AlertType.LowPressure, 1);
|
||||
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.LowPressure, 1);
|
||||
break;
|
||||
|
||||
// High pressure.
|
||||
case >= Atmospherics.WarningHighPressure:
|
||||
pressure = GetFeltHighPressure(uid, pressure);
|
||||
pressure = GetFeltHighPressure(barotrauma.Owner, pressure);
|
||||
|
||||
if(pressure < Atmospherics.WarningHighPressure)
|
||||
goto default;
|
||||
@@ -134,7 +127,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
var damageScale = MathF.Min((pressure / Atmospherics.HazardHighPressure) * Atmospherics.PressureDamageCoefficient, Atmospherics.MaxHighPressureDamage);
|
||||
|
||||
// Deal damage and ignore resistances. Resistance to pressure damage should be done via pressure protection gear.
|
||||
_damageableSystem.TryChangeDamage(uid, barotrauma.Damage * damageScale, true, false);
|
||||
_damageableSystem.TryChangeDamage(barotrauma.Owner, barotrauma.Damage * damageScale, true, false);
|
||||
|
||||
if (!barotrauma.TakingDamage)
|
||||
{
|
||||
@@ -142,15 +135,13 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
_logSystem.Add(LogType.Barotrauma, $"{ToPrettyString(barotrauma.Owner):entity} started taking high pressure damage");
|
||||
}
|
||||
|
||||
if (status == null) break;
|
||||
|
||||
if (pressure >= Atmospherics.HazardHighPressure)
|
||||
{
|
||||
status.ShowAlert(AlertType.HighPressure, 2);
|
||||
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.HighPressure, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
status.ShowAlert(AlertType.HighPressure, 1);
|
||||
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.HighPressure, 1);
|
||||
break;
|
||||
|
||||
// Normal pressure.
|
||||
@@ -160,7 +151,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
barotrauma.TakingDamage = false;
|
||||
_logSystem.Add(LogType.Barotrauma, $"{ToPrettyString(barotrauma.Owner):entity} stopped taking pressure damage");
|
||||
}
|
||||
status?.ClearAlertCategory(AlertCategory.Pressure);
|
||||
_alertsSystem.ClearAlertCategory(barotrauma.Owner, AlertCategory.Pressure);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Alert;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Server.Stunnable;
|
||||
using Content.Server.Temperature.Systems;
|
||||
@@ -28,6 +27,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
[Dependency] private readonly StunSystem _stunSystem = default!;
|
||||
[Dependency] private readonly TemperatureSystem _temperatureSystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
|
||||
[Dependency] private readonly AdminLogSystem _logSystem = default!;
|
||||
|
||||
private const float MinimumFireStacks = -10f;
|
||||
@@ -167,10 +167,9 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
}
|
||||
|
||||
public void Resist(EntityUid uid,
|
||||
FlammableComponent? flammable = null,
|
||||
ServerAlertsComponent? alerts = null)
|
||||
FlammableComponent? flammable = null)
|
||||
{
|
||||
if (!Resolve(uid, ref flammable, ref alerts))
|
||||
if (!Resolve(uid, ref flammable))
|
||||
return;
|
||||
|
||||
if (!flammable.OnFire || !_actionBlockerSystem.CanInteract(flammable.Owner) || flammable.Resisting)
|
||||
@@ -179,7 +178,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
flammable.Resisting = true;
|
||||
|
||||
flammable.Owner.PopupMessage(Loc.GetString("flammable-component-resist-message"));
|
||||
_stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f), true, alerts: alerts);
|
||||
_stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f), true);
|
||||
|
||||
// TODO FLAMMABLE: Make this not use TimerComponent...
|
||||
flammable.Owner.SpawnTimer(2000, () =>
|
||||
@@ -224,15 +223,13 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
flammable.FireStacks = MathF.Min(0, flammable.FireStacks + 1);
|
||||
}
|
||||
|
||||
EntityManager.TryGetComponent(flammable.Owner, out ServerAlertsComponent? status);
|
||||
|
||||
if (!flammable.OnFire)
|
||||
{
|
||||
status?.ClearAlert(AlertType.Fire);
|
||||
_alertsSystem.ClearAlert(uid, AlertType.Fire);
|
||||
continue;
|
||||
}
|
||||
|
||||
status?.ShowAlert(AlertType.Fire);
|
||||
_alertsSystem.ShowAlert(uid, AlertType.Fire, null, null);
|
||||
|
||||
if (flammable.FireStacks > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user