Stasis bed cleanup and bugfixes. (#38762)

* Stasis bed sent to shed

* Code Review

* Code Review 2
This commit is contained in:
Nemanja
2025-07-05 20:59:31 -04:00
committed by GitHub
parent 7aaccb5b98
commit ab201b6e82
21 changed files with 243 additions and 222 deletions

View File

@@ -1,7 +1,12 @@
using Content.Shared.Actions;
using Content.Shared.Bed.Components;
using Content.Shared.Bed.Sleep;
using Content.Shared.Body.Events;
using Content.Shared.Body.Systems;
using Content.Shared.Buckle.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Power;
using Content.Shared.Power.EntitySystems;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -12,6 +17,9 @@ public abstract class SharedBedSystem : EntitySystem
[Dependency] protected readonly IGameTiming Timing = default!;
[Dependency] private readonly ActionContainerSystem _actConts = default!;
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly EmagSystem _emag = default!;
[Dependency] private readonly SharedMetabolizerSystem _metabolizer = default!;
[Dependency] private readonly SharedPowerReceiverSystem _powerReceiver = default!;
[Dependency] private readonly SleepingSystem _sleepingSystem = default!;
public override void Initialize()
@@ -21,6 +29,12 @@ public abstract class SharedBedSystem : EntitySystem
SubscribeLocalEvent<HealOnBuckleComponent, MapInitEvent>(OnHealMapInit);
SubscribeLocalEvent<HealOnBuckleComponent, StrappedEvent>(OnStrapped);
SubscribeLocalEvent<HealOnBuckleComponent, UnstrappedEvent>(OnUnstrapped);
SubscribeLocalEvent<StasisBedComponent, StrappedEvent>(OnStasisStrapped);
SubscribeLocalEvent<StasisBedComponent, UnstrappedEvent>(OnStasisUnstrapped);
SubscribeLocalEvent<StasisBedComponent, GotEmaggedEvent>(OnStasisEmagged);
SubscribeLocalEvent<StasisBedComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<StasisBedBuckledComponent, GetMetabolicMultiplierEvent>(OnStasisGetMetabolicMultiplier);
}
private void OnHealMapInit(Entity<HealOnBuckleComponent> ent, ref MapInitEvent args)
@@ -46,4 +60,61 @@ public abstract class SharedBedSystem : EntitySystem
_sleepingSystem.TryWaking(args.Buckle.Owner);
RemComp<HealOnBuckleHealingComponent>(bed);
}
private void OnStasisStrapped(Entity<StasisBedComponent> ent, ref StrappedEvent args)
{
EnsureComp<StasisBedBuckledComponent>(args.Buckle);
_metabolizer.UpdateMetabolicMultiplier(args.Buckle);
}
private void OnStasisUnstrapped(Entity<StasisBedComponent> ent, ref UnstrappedEvent args)
{
RemComp<StasisBedBuckledComponent>(ent);
_metabolizer.UpdateMetabolicMultiplier(args.Buckle);
}
private void OnStasisEmagged(Entity<StasisBedComponent> ent, ref GotEmaggedEvent args)
{
if (!_emag.CompareFlag(args.Type, EmagType.Interaction))
return;
if (_emag.CheckFlag(ent, EmagType.Interaction))
return;
ent.Comp.Multiplier = 1f / ent.Comp.Multiplier;
UpdateMetabolisms(ent.Owner);
Dirty(ent);
args.Handled = true;
}
private void OnPowerChanged(Entity<StasisBedComponent> ent, ref PowerChangedEvent args)
{
UpdateMetabolisms(ent.Owner);
}
private void OnStasisGetMetabolicMultiplier(Entity<StasisBedBuckledComponent> ent, ref GetMetabolicMultiplierEvent args)
{
if (!TryComp<BuckleComponent>(ent, out var buckle) || buckle.BuckledTo is not { } buckledTo)
return;
if (!TryComp<StasisBedComponent>(buckledTo, out var stasis))
return;
if (!_powerReceiver.IsPowered(buckledTo))
return;
args.Multiplier *= stasis.Multiplier;
}
protected void UpdateMetabolisms(Entity<StrapComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp, false))
return;
foreach (var buckledEntity in ent.Comp.BuckledEntities)
{
_metabolizer.UpdateMetabolicMultiplier(buckledEntity);
}
}
}