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(OnHealMapInit); SubscribeLocalEvent(OnStrapped); SubscribeLocalEvent(OnUnstrapped); } private void OnHealMapInit(Entity ent, ref MapInitEvent args) { _actConts.EnsureAction(ent.Owner, ref ent.Comp.SleepAction, SleepingSystem.SleepActionId); Dirty(ent); } private void OnStrapped(Entity bed, ref StrappedEvent args) { EnsureComp(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 bed, ref UnstrappedEvent args) { _actionsSystem.RemoveAction(args.Buckle.Owner, bed.Comp.SleepAction); _sleepingSystem.TryWaking(args.Buckle.Owner); RemComp(bed); } }