Fix high pressure protection (#14968)

This commit is contained in:
Leon Friedrich
2023-03-30 12:45:56 +13:00
committed by GitHub
parent 27f0b1f0ed
commit 7f524f6751

View File

@@ -61,21 +61,27 @@ namespace Content.Server.Atmos.EntitySystems
args.Multiplier = 10000;
}
public float GetFeltLowPressure(BarotraumaComponent baro, float environmentPressure)
public float GetFeltLowPressure(EntityUid uid, BarotraumaComponent baro, float environmentPressure)
{
var modifier = float.MaxValue;
var multiplier = float.MaxValue;
TryComp(baro.Owner, out InventoryComponent? inv);
TryComp(baro.Owner, out ContainerManagerComponent? contMan);
TryComp(uid, out InventoryComponent? inv);
TryComp(uid, out ContainerManagerComponent? contMan);
// TODO: cache this & update when equipment changes?
// This continuously raises events for every player in space.
if (baro.ProtectionSlots.Count == 0)
{
modifier = 0;
multiplier = 1;
}
// First, check if for protective equipment
foreach (var slot in baro.ProtectionSlots)
{
if (!_inventorySystem.TryGetSlotEntity(baro.Owner, slot, out var equipment, inv, contMan)
if (!_inventorySystem.TryGetSlotEntity(uid, slot, out var equipment, inv, contMan)
|| ! TryComp(equipment, out PressureProtectionComponent? protection))
{
// Missing protection, skin is exposed.
@@ -90,26 +96,33 @@ namespace Content.Server.Atmos.EntitySystems
// Then apply any generic, non-clothing related modifiers.
var lowPressureEvent = new LowPressureEvent(environmentPressure);
RaiseLocalEvent(baro.Owner, lowPressureEvent, false);
RaiseLocalEvent(uid, lowPressureEvent);
return (environmentPressure + modifier + lowPressureEvent.Modifier) * (multiplier * lowPressureEvent.Multiplier);
return (environmentPressure + modifier + lowPressureEvent.Modifier)
* (multiplier * lowPressureEvent.Multiplier);
}
public float GetFeltHighPressure(BarotraumaComponent baro, float environmentPressure)
public float GetFeltHighPressure(EntityUid uid, BarotraumaComponent baro, float environmentPressure)
{
var modifier = float.MinValue;
var multiplier = float.MinValue;
TryComp(baro.Owner, out InventoryComponent? inv);
TryComp(baro.Owner, out ContainerManagerComponent? contMan);
TryComp(uid, out InventoryComponent? inv);
TryComp(uid, out ContainerManagerComponent? contMan);
// TODO: cache this & update when equipment changes?
// Not as import and as low-pressure, but probably still useful.
if (baro.ProtectionSlots.Count == 0)
{
modifier = 0;
multiplier = 1;
}
// First, check if for protective equipment
foreach (var slot in baro.ProtectionSlots)
{
if (!_inventorySystem.TryGetSlotEntity(baro.Owner, slot, out var equipment, inv, contMan)
if (!_inventorySystem.TryGetSlotEntity(uid, slot, out var equipment, inv, contMan)
|| !TryComp(equipment, out PressureProtectionComponent? protection))
{
// Missing protection, skin is exposed.
@@ -118,15 +131,16 @@ namespace Content.Server.Atmos.EntitySystems
break;
}
modifier = Math.Max(protection.LowPressureModifier, modifier);
multiplier = Math.Max(protection.LowPressureMultiplier, multiplier);
modifier = Math.Max(protection.HighPressureModifier, modifier);
multiplier = Math.Max(protection.HighPressureMultiplier, multiplier);
}
// Then apply any generic, non-clothing related modifiers.
var highPressureEvent = new HighPressureEvent(environmentPressure);
RaiseLocalEvent(baro.Owner, highPressureEvent, false);
RaiseLocalEvent(uid, highPressureEvent);
return (environmentPressure + modifier + highPressureEvent.Modifier) * (multiplier * highPressureEvent.Multiplier);
return (environmentPressure + modifier + highPressureEvent.Modifier)
* (multiplier * highPressureEvent.Multiplier);
}
public override void Update(float frameTime)
@@ -138,9 +152,9 @@ namespace Content.Server.Atmos.EntitySystems
_timer -= UpdateTimer;
foreach (var (barotrauma, damageable, transform) in EntityManager.EntityQuery<BarotraumaComponent, DamageableComponent, TransformComponent>())
var enumerator = EntityQueryEnumerator<BarotraumaComponent, DamageableComponent>();
while (enumerator.MoveNext(out var uid, out var barotrauma, out var damageable))
{
var uid = barotrauma.Owner;
var totalDamage = FixedPoint2.Zero;
foreach (var (barotraumaDamageType, _) in barotrauma.Damage.DamageDict)
{
@@ -162,32 +176,32 @@ namespace Content.Server.Atmos.EntitySystems
{
// Low pressure.
case <= Atmospherics.WarningLowPressure:
pressure = GetFeltLowPressure(barotrauma, pressure);
pressure = GetFeltLowPressure(uid, barotrauma, 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(barotrauma.Owner, barotrauma.Damage * Atmospherics.LowPressureDamage, true, false);
_damageableSystem.TryChangeDamage(uid, barotrauma.Damage * Atmospherics.LowPressureDamage, true, false);
if (!barotrauma.TakingDamage)
{
barotrauma.TakingDamage = true;
_adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(barotrauma.Owner):entity} started taking low pressure damage");
_adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} started taking low pressure damage");
}
if (pressure <= Atmospherics.HazardLowPressure)
{
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.LowPressure, 2);
_alertsSystem.ShowAlert(uid, AlertType.LowPressure, 2);
break;
}
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.LowPressure, 1);
_alertsSystem.ShowAlert(uid, AlertType.LowPressure, 1);
break;
// High pressure.
case >= Atmospherics.WarningHighPressure:
pressure = GetFeltHighPressure(barotrauma, pressure);
pressure = GetFeltHighPressure(uid, barotrauma, pressure);
if(pressure < Atmospherics.WarningHighPressure)
goto default;
@@ -195,21 +209,21 @@ 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(barotrauma.Owner, barotrauma.Damage * damageScale, true, false);
_damageableSystem.TryChangeDamage(uid, barotrauma.Damage * damageScale, true, false);
if (!barotrauma.TakingDamage)
{
barotrauma.TakingDamage = true;
_adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(barotrauma.Owner):entity} started taking high pressure damage");
_adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} started taking high pressure damage");
}
if (pressure >= Atmospherics.HazardHighPressure)
{
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.HighPressure, 2);
_alertsSystem.ShowAlert(uid, AlertType.HighPressure, 2);
break;
}
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.HighPressure, 1);
_alertsSystem.ShowAlert(uid, AlertType.HighPressure, 1);
break;
// Normal pressure.
@@ -217,9 +231,9 @@ namespace Content.Server.Atmos.EntitySystems
if (barotrauma.TakingDamage)
{
barotrauma.TakingDamage = false;
_adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(barotrauma.Owner):entity} stopped taking pressure damage");
_adminLogger.Add(LogType.Barotrauma, $"{ToPrettyString(uid):entity} stopped taking pressure damage");
}
_alertsSystem.ClearAlertCategory(barotrauma.Owner, AlertCategory.Pressure);
_alertsSystem.ClearAlertCategory(uid, AlertCategory.Pressure);
break;
}
}