Add events for TemperatureProtection and PressureProtection (#25165)
This commit is contained in:
@@ -1,18 +1,33 @@
|
||||
namespace Content.Server.Atmos.Components
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
|
||||
namespace Content.Server.Atmos.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
[Access(typeof(BarotraumaSystem))]
|
||||
public sealed partial class PressureProtectionComponent : Component
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed partial class PressureProtectionComponent : Component
|
||||
{
|
||||
[DataField("highPressureMultiplier")]
|
||||
public float HighPressureMultiplier { get; private set; } = 1f;
|
||||
[DataField]
|
||||
public float HighPressureMultiplier = 1f;
|
||||
|
||||
[DataField("highPressureModifier")]
|
||||
public float HighPressureModifier { get; private set; } = 0f;
|
||||
[DataField]
|
||||
public float HighPressureModifier;
|
||||
|
||||
[DataField("lowPressureMultiplier")]
|
||||
public float LowPressureMultiplier { get; private set; } = 1f;
|
||||
[DataField]
|
||||
public float LowPressureMultiplier = 1f;
|
||||
|
||||
[DataField("lowPressureModifier")]
|
||||
public float LowPressureModifier { get; private set; } = 0f;
|
||||
}
|
||||
[DataField]
|
||||
public float LowPressureModifier;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event raised on an entity with <see cref="PressureProtectionComponent"/> in order to adjust its default values.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct GetPressureProtectionValuesEvent
|
||||
{
|
||||
public float HighPressureMultiplier;
|
||||
public float HighPressureModifier;
|
||||
public float LowPressureMultiplier;
|
||||
public float LowPressureModifier;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
namespace Content.Server.Atmos.Components;
|
||||
using Content.Server.Temperature.Systems;
|
||||
|
||||
namespace Content.Server.Atmos.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
[Access(typeof(TemperatureSystem))]
|
||||
public sealed partial class TemperatureProtectionComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// How much to multiply temperature deltas by.
|
||||
/// </summary>
|
||||
[DataField("coefficient")]
|
||||
[DataField]
|
||||
public float Coefficient = 1.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event raised on an entity with <see cref="TemperatureProtectionComponent"/> to determine the actual value of the coefficient.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct GetTemperatureProtectionEvent(float Coefficient);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Atmos.Components;
|
||||
using Content.Shared.Alert;
|
||||
@@ -97,7 +98,11 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
foreach (var slot in barotrauma.ProtectionSlots)
|
||||
{
|
||||
if (!_inventorySystem.TryGetSlotEntity(uid, slot, out var equipment, inv, contMan)
|
||||
|| !TryComp(equipment, out PressureProtectionComponent? protection))
|
||||
|| !TryGetPressureProtectionValues(equipment.Value,
|
||||
out var itemHighMultiplier,
|
||||
out var itemHighModifier,
|
||||
out var itemLowMultiplier,
|
||||
out var itemLowModifier))
|
||||
{
|
||||
// Missing protection, skin is exposed.
|
||||
hPModifier = 0f;
|
||||
@@ -108,10 +113,10 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
}
|
||||
|
||||
// The entity is as protected as its weakest part protection
|
||||
hPModifier = Math.Max(hPModifier, protection.HighPressureModifier);
|
||||
hPMultiplier = Math.Max(hPMultiplier, protection.HighPressureMultiplier);
|
||||
lPModifier = Math.Min(lPModifier, protection.LowPressureModifier);
|
||||
lPMultiplier = Math.Min(lPMultiplier, protection.LowPressureMultiplier);
|
||||
hPModifier = Math.Max(hPModifier, itemHighModifier.Value);
|
||||
hPMultiplier = Math.Max(hPMultiplier, itemHighMultiplier.Value);
|
||||
lPModifier = Math.Min(lPModifier, itemLowModifier.Value);
|
||||
lPMultiplier = Math.Min(lPMultiplier, itemLowMultiplier.Value);
|
||||
}
|
||||
|
||||
barotrauma.HighPressureModifier = hPModifier;
|
||||
@@ -121,12 +126,16 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
}
|
||||
|
||||
// any innate pressure resistance ?
|
||||
if (TryComp<PressureProtectionComponent>(uid, out var innatePressureProtection))
|
||||
if (TryGetPressureProtectionValues(uid,
|
||||
out var highMultiplier,
|
||||
out var highModifier,
|
||||
out var lowMultiplier,
|
||||
out var lowModifier))
|
||||
{
|
||||
barotrauma.HighPressureModifier += innatePressureProtection.HighPressureModifier;
|
||||
barotrauma.HighPressureMultiplier *= innatePressureProtection.HighPressureMultiplier;
|
||||
barotrauma.LowPressureModifier += innatePressureProtection.LowPressureModifier;
|
||||
barotrauma.LowPressureMultiplier *= innatePressureProtection.LowPressureMultiplier;
|
||||
barotrauma.HighPressureModifier += highModifier.Value;
|
||||
barotrauma.HighPressureMultiplier *= highMultiplier.Value;
|
||||
barotrauma.LowPressureModifier += lowModifier.Value;
|
||||
barotrauma.LowPressureMultiplier *= lowMultiplier.Value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +165,36 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
return (environmentPressure + barotrauma.HighPressureModifier) * (barotrauma.HighPressureMultiplier);
|
||||
}
|
||||
|
||||
public bool TryGetPressureProtectionValues(
|
||||
Entity<PressureProtectionComponent?> ent,
|
||||
[NotNullWhen(true)] out float? highMultiplier,
|
||||
[NotNullWhen(true)] out float? highModifier,
|
||||
[NotNullWhen(true)] out float? lowMultiplier,
|
||||
[NotNullWhen(true)] out float? lowModifier)
|
||||
{
|
||||
highMultiplier = null;
|
||||
highModifier = null;
|
||||
lowMultiplier = null;
|
||||
lowModifier = null;
|
||||
if (!Resolve(ent, ref ent.Comp, false))
|
||||
return false;
|
||||
|
||||
var comp = ent.Comp;
|
||||
var ev = new GetPressureProtectionValuesEvent
|
||||
{
|
||||
HighPressureMultiplier = comp.HighPressureMultiplier,
|
||||
HighPressureModifier = comp.HighPressureModifier,
|
||||
LowPressureMultiplier = comp.LowPressureMultiplier,
|
||||
LowPressureModifier = comp.LowPressureModifier
|
||||
};
|
||||
RaiseLocalEvent(ent, ref ev);
|
||||
highMultiplier = ev.HighPressureMultiplier;
|
||||
highModifier = ev.HighPressureModifier;
|
||||
lowMultiplier = ev.LowPressureMultiplier;
|
||||
lowModifier = ev.LowPressureModifier;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
_timer += frameTime;
|
||||
|
||||
@@ -293,7 +293,10 @@ public sealed class TemperatureSystem : EntitySystem
|
||||
private void OnTemperatureChangeAttempt(EntityUid uid, TemperatureProtectionComponent component,
|
||||
InventoryRelayedEvent<ModifyChangedTemperatureEvent> args)
|
||||
{
|
||||
args.Args.TemperatureDelta *= component.Coefficient;
|
||||
var ev = new GetTemperatureProtectionEvent(component.Coefficient);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
|
||||
args.Args.TemperatureDelta *= ev.Coefficient;
|
||||
}
|
||||
|
||||
private void OnParentChange(EntityUid uid, TemperatureComponent component,
|
||||
|
||||
Reference in New Issue
Block a user