Rejig pressure protection (#7560)

This commit is contained in:
Leon Friedrich
2022-04-16 10:41:47 +12:00
committed by GitHub
parent 52ec5036d5
commit 6dc51589f4
9 changed files with 149 additions and 88 deletions

View File

@@ -1,8 +1,5 @@
using Content.Shared.Damage;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Atmos.Components
{
@@ -24,5 +21,11 @@ namespace Content.Server.Atmos.Components
/// Used to keep track of when damage starts/stops. Useful for logs.
/// </summary>
public bool TakingDamage = false;
/// <summary>
/// These are the inventory slots that are checked for pressure protection. If a slot is missing protection, no protection is applied.
/// </summary>
[DataField("protectionSlots")]
public List<string> ProtectionSlots = new() { "head", "outerClothing" };
}
}

View File

@@ -1,4 +1,3 @@
using System;
using Content.Server.Administration.Logs;
using Content.Server.Atmos.Components;
using Content.Shared.Alert;
@@ -6,8 +5,8 @@ using Content.Shared.Atmos;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Content.Shared.Inventory;
using Robust.Shared.Containers;
namespace Content.Server.Atmos.EntitySystems
{
@@ -17,6 +16,7 @@ namespace Content.Server.Atmos.EntitySystems
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly AdminLogSystem _logSystem = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;
private const float UpdateTimer = 1f;
private float _timer;
@@ -39,27 +39,72 @@ namespace Content.Server.Atmos.EntitySystems
args.Multiplier *= component.LowPressureMultiplier;
}
private float CalculateFeltPressure(float environmentPressure, PressureEvent pressureEvent)
public float GetFeltLowPressure(BarotraumaComponent baro, float environmentPressure)
{
environmentPressure += pressureEvent.Modifier;
environmentPressure *= pressureEvent.Multiplier;
return environmentPressure;
}
var modifier = float.MaxValue;
var multiplier = float.MaxValue;
public float GetFeltLowPressure(EntityUid uid, float environmentPressure)
{
TryComp(baro.Owner, out InventoryComponent? inv);
TryComp(baro.Owner, out ContainerManagerComponent? contMan);
// TODO: cache this & update when equipment changes?
// This continuously raises events for every player in space.
// First, check if for protective equipment
foreach (var slot in baro.ProtectionSlots)
{
if (!_inventorySystem.TryGetSlotEntity(baro.Owner, slot, out var equipment, inv, contMan)
|| ! TryComp(equipment, out PressureProtectionComponent? protection))
{
// Missing protection, skin is exposed.
modifier = 0;
multiplier = 1;
break;
}
modifier = Math.Min(protection.LowPressureModifier, modifier);
multiplier = Math.Min(protection.LowPressureMultiplier, multiplier);
}
// Then apply any generic, non-clothing related modifiers.
var lowPressureEvent = new LowPressureEvent(environmentPressure);
RaiseLocalEvent(uid, lowPressureEvent, false);
RaiseLocalEvent(baro.Owner, lowPressureEvent, false);
return CalculateFeltPressure(environmentPressure, lowPressureEvent);
return (environmentPressure + modifier + lowPressureEvent.Modifier) * (multiplier * lowPressureEvent.Multiplier);
}
public float GetFeltHighPressure(EntityUid uid, float environmentPressure)
public float GetFeltHighPressure(BarotraumaComponent baro, float environmentPressure)
{
var highPressureEvent = new HighPressureEvent(environmentPressure);
RaiseLocalEvent(uid, highPressureEvent, false);
var modifier = float.MinValue;
var multiplier = float.MinValue;
return CalculateFeltPressure(environmentPressure, highPressureEvent);
TryComp(baro.Owner, out InventoryComponent? inv);
TryComp(baro.Owner, out ContainerManagerComponent? contMan);
// TODO: cache this & update when equipment changes?
// Not as import and as low-pressure, but probably still useful.
// First, check if for protective equipment
foreach (var slot in baro.ProtectionSlots)
{
if (!_inventorySystem.TryGetSlotEntity(baro.Owner, slot, out var equipment, inv, contMan)
|| !TryComp(equipment, out PressureProtectionComponent? protection))
{
// Missing protection, skin is exposed.
modifier = 0;
multiplier = 1;
break;
}
modifier = Math.Max(protection.LowPressureModifier, modifier);
multiplier = Math.Max(protection.LowPressureMultiplier, multiplier);
}
// Then apply any generic, non-clothing related modifiers.
var highPressureEvent = new HighPressureEvent(environmentPressure);
RaiseLocalEvent(baro.Owner, highPressureEvent, false);
return (environmentPressure + modifier + highPressureEvent.Modifier) * (multiplier * highPressureEvent.Multiplier);
}
public override void Update(float frameTime)
@@ -94,7 +139,7 @@ namespace Content.Server.Atmos.EntitySystems
{
// Low pressure.
case <= Atmospherics.WarningLowPressure:
pressure = GetFeltLowPressure(barotrauma.Owner, pressure);
pressure = GetFeltLowPressure(barotrauma, pressure);
if (pressure > Atmospherics.WarningLowPressure)
goto default;
@@ -119,7 +164,7 @@ namespace Content.Server.Atmos.EntitySystems
// High pressure.
case >= Atmospherics.WarningHighPressure:
pressure = GetFeltHighPressure(barotrauma.Owner, pressure);
pressure = GetFeltHighPressure(barotrauma, pressure);
if(pressure < Atmospherics.WarningHighPressure)
goto default;

View File

@@ -1,9 +1,6 @@
using Content.Shared.Inventory;
using Robust.Shared.GameObjects;
namespace Content.Server.Atmos
{
public abstract class PressureEvent : EntityEventArgs, IInventoryRelayEvent
public abstract class PressureEvent : EntityEventArgs
{
/// <summary>
/// The environment pressure.
@@ -29,11 +26,6 @@ namespace Content.Server.Atmos
/// </remarks>
public float Multiplier { get; set; } = 1f;
/// <summary>
/// The inventory slots that should be checked for pressure protecting equipment.
/// </summary>
public SlotFlags TargetSlots { get; } = ~SlotFlags.POCKET;
protected PressureEvent(float pressure)
{
Pressure = pressure;