Adds barotrauma (pressure damage) (#1605)
* Adds barotrauma, disables it for now * At least show status effect, but don't damage the mobs * Fix switch misuse
This commit is contained in:
committed by
GitHub
parent
079937a9fe
commit
ffc9a24ea0
@@ -0,0 +1,98 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using CannyFastMath;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Atmos
|
||||
{
|
||||
/// <summary>
|
||||
/// Barotrauma: injury because of changes in air pressure.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class BarotraumaComponent : Component
|
||||
{
|
||||
public override string Name => "Barotrauma";
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Update(float frameTime)
|
||||
{
|
||||
if (!Owner.TryGetComponent(out DamageableComponent damageable)) return;
|
||||
Owner.TryGetComponent(out ServerStatusEffectsComponent status);
|
||||
|
||||
var coordinates = Owner.Transform.GridPosition;
|
||||
var gridAtmos = EntitySystem.Get<AtmosphereSystem>().GetGridAtmosphere(coordinates.GridID);
|
||||
var tile = gridAtmos?.GetTile(coordinates);
|
||||
|
||||
var pressure = 1f;
|
||||
var highPressureMultiplier = 1f;
|
||||
var lowPressureMultiplier = 1f;
|
||||
|
||||
foreach (var protection in Owner.GetAllComponents<IPressureProtection>())
|
||||
{
|
||||
highPressureMultiplier *= protection.HighPressureMultiplier;
|
||||
lowPressureMultiplier *= protection.LowPressureMultiplier;
|
||||
}
|
||||
|
||||
if (tile?.Air != null)
|
||||
pressure = MathF.Max(tile.Air.Pressure, 1f);
|
||||
|
||||
switch (pressure)
|
||||
{
|
||||
// Low pressure.
|
||||
case var p when p <= Atmospherics.WarningLowPressure:
|
||||
pressure *= lowPressureMultiplier;
|
||||
|
||||
if(pressure > Atmospherics.WarningLowPressure)
|
||||
goto default;
|
||||
|
||||
// TODO ATMOS Uncomment this when saltern is pressurized
|
||||
//damageable.TakeDamage(DamageType.Brute, Atmospherics.LowPressureDamage, Owner, null);
|
||||
|
||||
if (status == null) break;
|
||||
|
||||
if (pressure <= Atmospherics.HazardLowPressure)
|
||||
{
|
||||
status.ChangeStatusEffect(StatusEffect.Pressure, "/Textures/Interface/StatusEffects/Pressure/lowpressure2.png", null);
|
||||
break;
|
||||
}
|
||||
|
||||
status.ChangeStatusEffect(StatusEffect.Pressure, "/Textures/Interface/StatusEffects/Pressure/lowpressure1.png", null);
|
||||
break;
|
||||
|
||||
// High pressure.
|
||||
case var p when p >= Atmospherics.WarningHighPressure:
|
||||
pressure *= highPressureMultiplier;
|
||||
|
||||
if(pressure < Atmospherics.WarningHighPressure)
|
||||
goto default;
|
||||
|
||||
var damage = (int) MathF.Min((pressure / Atmospherics.HazardHighPressure) * Atmospherics.PressureDamageCoefficient, Atmospherics.MaxHighPressureDamage);
|
||||
|
||||
// TODO ATMOS Uncomment this when saltern is pressurized
|
||||
//damageable.TakeDamage(DamageType.Brute, damage, Owner, null);
|
||||
|
||||
if (status == null) break;
|
||||
|
||||
if (pressure >= Atmospherics.HazardHighPressure)
|
||||
{
|
||||
status.ChangeStatusEffect(StatusEffect.Pressure, "/Textures/Interface/StatusEffects/Pressure/highpressure2.png", null);
|
||||
break;
|
||||
}
|
||||
|
||||
status.ChangeStatusEffect(StatusEffect.Pressure, "/Textures/Interface/StatusEffects/Pressure/highpressure1.png", null);
|
||||
break;
|
||||
|
||||
// Normal pressure.
|
||||
default:
|
||||
status?.RemoveStatusEffect(StatusEffect.Pressure);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Atmos
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class PressureProtectionComponent : Component, IPressureProtection
|
||||
{
|
||||
public override string Name => "PressureProtection";
|
||||
|
||||
[ViewVariables]
|
||||
public float HighPressureMultiplier { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
public float LowPressureMultiplier { get; private set; }
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(this, x => HighPressureMultiplier, "highPressureMultiplier", 1f);
|
||||
serializer.DataField(this, x => LowPressureMultiplier, "lowPressureMultiplier", 1f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.EntitySystems.Click;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Interaction;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
@@ -26,7 +27,7 @@ using static Content.Shared.GameObjects.SharedInventoryComponent.ClientInventory
|
||||
namespace Content.Server.GameObjects
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class InventoryComponent : SharedInventoryComponent, IExAct, IEffectBlocker
|
||||
public class InventoryComponent : SharedInventoryComponent, IExAct, IEffectBlocker, IPressureProtection
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||
@@ -51,6 +52,52 @@ namespace Content.Server.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
// Optimization: Cache this
|
||||
[ViewVariables]
|
||||
public float HighPressureMultiplier
|
||||
{
|
||||
get
|
||||
{
|
||||
var multiplier = 1f;
|
||||
|
||||
foreach (var (slot, containerSlot) in SlotContainers)
|
||||
{
|
||||
foreach (var entity in containerSlot.ContainedEntities)
|
||||
{
|
||||
foreach (var protection in entity.GetAllComponents<IPressureProtection>())
|
||||
{
|
||||
multiplier *= protection.HighPressureMultiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
// Optimization: Cache this
|
||||
[ViewVariables]
|
||||
public float LowPressureMultiplier
|
||||
{
|
||||
get
|
||||
{
|
||||
var multiplier = 1f;
|
||||
|
||||
foreach (var (slot, containerSlot) in SlotContainers)
|
||||
{
|
||||
foreach (var entity in containerSlot.ContainedEntities)
|
||||
{
|
||||
foreach (var protection in entity.GetAllComponents<IPressureProtection>())
|
||||
{
|
||||
multiplier *= protection.LowPressureMultiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
bool IEffectBlocker.CanSlip()
|
||||
{
|
||||
if(Owner.TryGetComponent(out InventoryComponent inventoryComponent) &&
|
||||
|
||||
29
Content.Server/GameObjects/EntitySystems/BarotraumaSystem.cs
Normal file
29
Content.Server/GameObjects/EntitySystems/BarotraumaSystem.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Content.Server.GameObjects.Components.Atmos;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class BarotraumaSystem : EntitySystem
|
||||
{
|
||||
private const float TimePerUpdate = 0.5f;
|
||||
|
||||
private float _timer = 0f;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
_timer += frameTime;
|
||||
|
||||
if (_timer < TimePerUpdate) return;
|
||||
|
||||
_timer = 0f;
|
||||
|
||||
foreach (var barotraumaComp in ComponentManager.EntityQuery<BarotraumaComponent>())
|
||||
{
|
||||
barotraumaComp.Update(frameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user