Refactor Barotrauma to be ECS. (#4674)

- Refactor IPressureProtection to be two different ECS events.
This commit is contained in:
Vera Aguilera Puerto
2021-09-22 13:02:25 +02:00
committed by GitHub
parent 6891c32eb5
commit 246fda53c5
8 changed files with 217 additions and 144 deletions

View File

@@ -7,7 +7,6 @@ using Content.Server.Clothing.Components;
using Content.Server.Hands.Components;
using Content.Server.Interaction;
using Content.Server.Items;
using Content.Server.Pressure;
using Content.Server.Storage.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Acts;
@@ -38,7 +37,7 @@ namespace Content.Server.Inventory.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedInventoryComponent))]
public class InventoryComponent : SharedInventoryComponent, IExAct, IPressureProtection, IEffectBlocker
public class InventoryComponent : SharedInventoryComponent, IExAct, IEffectBlocker
{
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
@@ -63,52 +62,6 @@ namespace Content.Server.Inventory.Components
}
}
// 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;
}
}
public override float WalkSpeedModifier
{
get

View File

@@ -1,3 +1,4 @@
using Content.Server.Atmos;
using Content.Server.Inventory.Components;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
@@ -12,6 +13,8 @@ namespace Content.Server.Inventory
SubscribeLocalEvent<HumanInventoryControllerComponent, EntRemovedFromContainerMessage>(HandleRemovedFromContainer);
SubscribeLocalEvent<InventoryComponent, EntRemovedFromContainerMessage>(HandleInvRemovedFromContainer);
SubscribeLocalEvent<InventoryComponent, HighPressureEvent>(OnHighPressureEvent);
SubscribeLocalEvent<InventoryComponent, LowPressureEvent>(OnLowPressureEvent);
}
private static void HandleInvRemovedFromContainer(EntityUid uid, InventoryComponent component, EntRemovedFromContainerMessage args)
@@ -23,5 +26,23 @@ namespace Content.Server.Inventory
{
component.CheckUniformExists();
}
private void OnHighPressureEvent(EntityUid uid, InventoryComponent component, HighPressureEvent args)
{
RelayPressureEvent(component, args);
}
private void OnLowPressureEvent(EntityUid uid, InventoryComponent component, LowPressureEvent args)
{
RelayPressureEvent(component, args);
}
private void RelayPressureEvent<T>(InventoryComponent component, T args) where T : PressureEvent
{
foreach (var equipped in component.GetAllHeldItems())
{
RaiseLocalEvent(equipped.Uid, args, false);
}
}
}
}