Fix high pressure protection (#14968)
This commit is contained in:
@@ -61,21 +61,27 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
args.Multiplier = 10000;
|
args.Multiplier = 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetFeltLowPressure(BarotraumaComponent baro, float environmentPressure)
|
public float GetFeltLowPressure(EntityUid uid, BarotraumaComponent baro, float environmentPressure)
|
||||||
{
|
{
|
||||||
var modifier = float.MaxValue;
|
var modifier = float.MaxValue;
|
||||||
var multiplier = float.MaxValue;
|
var multiplier = float.MaxValue;
|
||||||
|
|
||||||
TryComp(baro.Owner, out InventoryComponent? inv);
|
TryComp(uid, out InventoryComponent? inv);
|
||||||
TryComp(baro.Owner, out ContainerManagerComponent? contMan);
|
TryComp(uid, out ContainerManagerComponent? contMan);
|
||||||
|
|
||||||
// TODO: cache this & update when equipment changes?
|
// TODO: cache this & update when equipment changes?
|
||||||
// This continuously raises events for every player in space.
|
// This continuously raises events for every player in space.
|
||||||
|
|
||||||
|
if (baro.ProtectionSlots.Count == 0)
|
||||||
|
{
|
||||||
|
modifier = 0;
|
||||||
|
multiplier = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// First, check if for protective equipment
|
// First, check if for protective equipment
|
||||||
foreach (var slot in baro.ProtectionSlots)
|
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))
|
|| ! TryComp(equipment, out PressureProtectionComponent? protection))
|
||||||
{
|
{
|
||||||
// Missing protection, skin is exposed.
|
// Missing protection, skin is exposed.
|
||||||
@@ -90,26 +96,33 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
|
|
||||||
// Then apply any generic, non-clothing related modifiers.
|
// Then apply any generic, non-clothing related modifiers.
|
||||||
var lowPressureEvent = new LowPressureEvent(environmentPressure);
|
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 modifier = float.MinValue;
|
||||||
var multiplier = float.MinValue;
|
var multiplier = float.MinValue;
|
||||||
|
|
||||||
TryComp(baro.Owner, out InventoryComponent? inv);
|
TryComp(uid, out InventoryComponent? inv);
|
||||||
TryComp(baro.Owner, out ContainerManagerComponent? contMan);
|
TryComp(uid, out ContainerManagerComponent? contMan);
|
||||||
|
|
||||||
// TODO: cache this & update when equipment changes?
|
// TODO: cache this & update when equipment changes?
|
||||||
// Not as import and as low-pressure, but probably still useful.
|
// 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
|
// First, check if for protective equipment
|
||||||
foreach (var slot in baro.ProtectionSlots)
|
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))
|
|| !TryComp(equipment, out PressureProtectionComponent? protection))
|
||||||
{
|
{
|
||||||
// Missing protection, skin is exposed.
|
// Missing protection, skin is exposed.
|
||||||
@@ -118,15 +131,16 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
modifier = Math.Max(protection.LowPressureModifier, modifier);
|
modifier = Math.Max(protection.HighPressureModifier, modifier);
|
||||||
multiplier = Math.Max(protection.LowPressureMultiplier, multiplier);
|
multiplier = Math.Max(protection.HighPressureMultiplier, multiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then apply any generic, non-clothing related modifiers.
|
// Then apply any generic, non-clothing related modifiers.
|
||||||
var highPressureEvent = new HighPressureEvent(environmentPressure);
|
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)
|
public override void Update(float frameTime)
|
||||||
@@ -138,9 +152,9 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
|
|
||||||
_timer -= UpdateTimer;
|
_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;
|
var totalDamage = FixedPoint2.Zero;
|
||||||
foreach (var (barotraumaDamageType, _) in barotrauma.Damage.DamageDict)
|
foreach (var (barotraumaDamageType, _) in barotrauma.Damage.DamageDict)
|
||||||
{
|
{
|
||||||
@@ -162,32 +176,32 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
{
|
{
|
||||||
// Low pressure.
|
// Low pressure.
|
||||||
case <= Atmospherics.WarningLowPressure:
|
case <= Atmospherics.WarningLowPressure:
|
||||||
pressure = GetFeltLowPressure(barotrauma, pressure);
|
pressure = GetFeltLowPressure(uid, barotrauma, pressure);
|
||||||
|
|
||||||
if (pressure > Atmospherics.WarningLowPressure)
|
if (pressure > Atmospherics.WarningLowPressure)
|
||||||
goto default;
|
goto default;
|
||||||
|
|
||||||
// Deal damage and ignore resistances. Resistance to pressure damage should be done via pressure protection gear.
|
// 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)
|
if (!barotrauma.TakingDamage)
|
||||||
{
|
{
|
||||||
barotrauma.TakingDamage = true;
|
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)
|
if (pressure <= Atmospherics.HazardLowPressure)
|
||||||
{
|
{
|
||||||
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.LowPressure, 2);
|
_alertsSystem.ShowAlert(uid, AlertType.LowPressure, 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.LowPressure, 1);
|
_alertsSystem.ShowAlert(uid, AlertType.LowPressure, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// High pressure.
|
// High pressure.
|
||||||
case >= Atmospherics.WarningHighPressure:
|
case >= Atmospherics.WarningHighPressure:
|
||||||
pressure = GetFeltHighPressure(barotrauma, pressure);
|
pressure = GetFeltHighPressure(uid, barotrauma, pressure);
|
||||||
|
|
||||||
if(pressure < Atmospherics.WarningHighPressure)
|
if(pressure < Atmospherics.WarningHighPressure)
|
||||||
goto default;
|
goto default;
|
||||||
@@ -195,21 +209,21 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
var damageScale = MathF.Min((pressure / Atmospherics.HazardHighPressure) * Atmospherics.PressureDamageCoefficient, Atmospherics.MaxHighPressureDamage);
|
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.
|
// 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)
|
if (!barotrauma.TakingDamage)
|
||||||
{
|
{
|
||||||
barotrauma.TakingDamage = true;
|
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)
|
if (pressure >= Atmospherics.HazardHighPressure)
|
||||||
{
|
{
|
||||||
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.HighPressure, 2);
|
_alertsSystem.ShowAlert(uid, AlertType.HighPressure, 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_alertsSystem.ShowAlert(barotrauma.Owner, AlertType.HighPressure, 1);
|
_alertsSystem.ShowAlert(uid, AlertType.HighPressure, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Normal pressure.
|
// Normal pressure.
|
||||||
@@ -217,9 +231,9 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
if (barotrauma.TakingDamage)
|
if (barotrauma.TakingDamage)
|
||||||
{
|
{
|
||||||
barotrauma.TakingDamage = false;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user