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]
|
[RegisterComponent]
|
||||||
|
[Access(typeof(BarotraumaSystem))]
|
||||||
public sealed partial class PressureProtectionComponent : Component
|
public sealed partial class PressureProtectionComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("highPressureMultiplier")]
|
[DataField]
|
||||||
public float HighPressureMultiplier { get; private set; } = 1f;
|
public float HighPressureMultiplier = 1f;
|
||||||
|
|
||||||
[DataField("highPressureModifier")]
|
[DataField]
|
||||||
public float HighPressureModifier { get; private set; } = 0f;
|
public float HighPressureModifier;
|
||||||
|
|
||||||
[DataField("lowPressureMultiplier")]
|
[DataField]
|
||||||
public float LowPressureMultiplier { get; private set; } = 1f;
|
public float LowPressureMultiplier = 1f;
|
||||||
|
|
||||||
[DataField("lowPressureModifier")]
|
[DataField]
|
||||||
public float LowPressureModifier { get; private set; } = 0f;
|
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]
|
[RegisterComponent]
|
||||||
|
[Access(typeof(TemperatureSystem))]
|
||||||
public sealed partial class TemperatureProtectionComponent : Component
|
public sealed partial class TemperatureProtectionComponent : Component
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How much to multiply temperature deltas by.
|
/// How much to multiply temperature deltas by.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("coefficient")]
|
[DataField]
|
||||||
public float Coefficient = 1.0f;
|
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.Administration.Logs;
|
||||||
using Content.Server.Atmos.Components;
|
using Content.Server.Atmos.Components;
|
||||||
using Content.Shared.Alert;
|
using Content.Shared.Alert;
|
||||||
@@ -97,7 +98,11 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
foreach (var slot in barotrauma.ProtectionSlots)
|
foreach (var slot in barotrauma.ProtectionSlots)
|
||||||
{
|
{
|
||||||
if (!_inventorySystem.TryGetSlotEntity(uid, slot, out var equipment, inv, contMan)
|
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.
|
// Missing protection, skin is exposed.
|
||||||
hPModifier = 0f;
|
hPModifier = 0f;
|
||||||
@@ -108,10 +113,10 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The entity is as protected as its weakest part protection
|
// The entity is as protected as its weakest part protection
|
||||||
hPModifier = Math.Max(hPModifier, protection.HighPressureModifier);
|
hPModifier = Math.Max(hPModifier, itemHighModifier.Value);
|
||||||
hPMultiplier = Math.Max(hPMultiplier, protection.HighPressureMultiplier);
|
hPMultiplier = Math.Max(hPMultiplier, itemHighMultiplier.Value);
|
||||||
lPModifier = Math.Min(lPModifier, protection.LowPressureModifier);
|
lPModifier = Math.Min(lPModifier, itemLowModifier.Value);
|
||||||
lPMultiplier = Math.Min(lPMultiplier, protection.LowPressureMultiplier);
|
lPMultiplier = Math.Min(lPMultiplier, itemLowMultiplier.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
barotrauma.HighPressureModifier = hPModifier;
|
barotrauma.HighPressureModifier = hPModifier;
|
||||||
@@ -121,12 +126,16 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
}
|
}
|
||||||
|
|
||||||
// any innate pressure resistance ?
|
// 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.HighPressureModifier += highModifier.Value;
|
||||||
barotrauma.HighPressureMultiplier *= innatePressureProtection.HighPressureMultiplier;
|
barotrauma.HighPressureMultiplier *= highMultiplier.Value;
|
||||||
barotrauma.LowPressureModifier += innatePressureProtection.LowPressureModifier;
|
barotrauma.LowPressureModifier += lowModifier.Value;
|
||||||
barotrauma.LowPressureMultiplier *= innatePressureProtection.LowPressureMultiplier;
|
barotrauma.LowPressureMultiplier *= lowMultiplier.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,6 +165,36 @@ namespace Content.Server.Atmos.EntitySystems
|
|||||||
return (environmentPressure + barotrauma.HighPressureModifier) * (barotrauma.HighPressureMultiplier);
|
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)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
_timer += frameTime;
|
_timer += frameTime;
|
||||||
|
|||||||
@@ -293,7 +293,10 @@ public sealed class TemperatureSystem : EntitySystem
|
|||||||
private void OnTemperatureChangeAttempt(EntityUid uid, TemperatureProtectionComponent component,
|
private void OnTemperatureChangeAttempt(EntityUid uid, TemperatureProtectionComponent component,
|
||||||
InventoryRelayedEvent<ModifyChangedTemperatureEvent> args)
|
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,
|
private void OnParentChange(EntityUid uid, TemperatureComponent component,
|
||||||
|
|||||||
Reference in New Issue
Block a user