50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using Content.Shared.Actions;
|
|
using Content.Shared.Bed.Components;
|
|
using Content.Shared.Bed.Sleep;
|
|
using Content.Shared.Buckle.Components;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Shared.Bed;
|
|
|
|
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 SleepingSystem _sleepingSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<HealOnBuckleComponent, MapInitEvent>(OnHealMapInit);
|
|
SubscribeLocalEvent<HealOnBuckleComponent, StrappedEvent>(OnStrapped);
|
|
SubscribeLocalEvent<HealOnBuckleComponent, UnstrappedEvent>(OnUnstrapped);
|
|
}
|
|
|
|
private void OnHealMapInit(Entity<HealOnBuckleComponent> ent, ref MapInitEvent args)
|
|
{
|
|
_actConts.EnsureAction(ent.Owner, ref ent.Comp.SleepAction, SleepingSystem.SleepActionId);
|
|
Dirty(ent);
|
|
}
|
|
|
|
private void OnStrapped(Entity<HealOnBuckleComponent> bed, ref StrappedEvent args)
|
|
{
|
|
EnsureComp<HealOnBuckleHealingComponent>(bed);
|
|
bed.Comp.NextHealTime = Timing.CurTime + TimeSpan.FromSeconds(bed.Comp.HealTime);
|
|
_actionsSystem.AddAction(args.Buckle, ref bed.Comp.SleepAction, SleepingSystem.SleepActionId, bed);
|
|
Dirty(bed);
|
|
|
|
// Single action entity, cannot strap multiple entities to the same bed.
|
|
DebugTools.AssertEqual(args.Strap.Comp.BuckledEntities.Count, 1);
|
|
}
|
|
|
|
private void OnUnstrapped(Entity<HealOnBuckleComponent> bed, ref UnstrappedEvent args)
|
|
{
|
|
_actionsSystem.RemoveAction(args.Buckle.Owner, bed.Comp.SleepAction);
|
|
_sleepingSystem.TryWaking(args.Buckle.Owner);
|
|
RemComp<HealOnBuckleHealingComponent>(bed);
|
|
}
|
|
}
|