2022-10-23 00:46:28 +02:00
|
|
|
using Content.Server.Actions;
|
2022-04-15 18:53:52 -04:00
|
|
|
using Content.Server.Bed.Components;
|
2022-10-23 00:46:28 +02:00
|
|
|
using Content.Server.Body.Systems;
|
2022-04-15 18:53:52 -04:00
|
|
|
using Content.Server.Power.Components;
|
2022-05-27 10:36:12 +10:00
|
|
|
using Content.Server.Power.EntitySystems;
|
2022-10-23 00:46:28 +02:00
|
|
|
using Content.Shared.Bed;
|
|
|
|
|
using Content.Shared.Bed.Sleep;
|
|
|
|
|
using Content.Shared.Body.Components;
|
|
|
|
|
using Content.Shared.Buckle.Components;
|
|
|
|
|
using Content.Shared.Damage;
|
2022-04-15 18:53:52 -04:00
|
|
|
using Content.Shared.Emag.Systems;
|
2023-01-13 16:57:10 -08:00
|
|
|
using Content.Shared.Mobs.Systems;
|
2024-08-25 22:18:42 +10:00
|
|
|
using Content.Shared.Power;
|
2022-11-08 20:59:34 +01:00
|
|
|
using Robust.Shared.Timing;
|
2024-06-20 03:14:18 +12:00
|
|
|
using Robust.Shared.Utility;
|
2022-04-15 18:53:52 -04:00
|
|
|
|
|
|
|
|
namespace Content.Server.Bed
|
|
|
|
|
{
|
|
|
|
|
public sealed class BedSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
2022-07-27 00:46:24 -04:00
|
|
|
[Dependency] private readonly ActionsSystem _actionsSystem = default!;
|
|
|
|
|
[Dependency] private readonly SleepingSystem _sleepingSystem = default!;
|
2022-10-15 17:39:30 -04:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2022-07-27 00:46:24 -04:00
|
|
|
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
2022-11-08 20:59:34 +01:00
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
2022-10-23 00:46:28 +02:00
|
|
|
|
2022-04-15 18:53:52 -04:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2024-06-20 03:14:18 +12:00
|
|
|
SubscribeLocalEvent<HealOnBuckleComponent, StrappedEvent>(OnStrapped);
|
|
|
|
|
SubscribeLocalEvent<HealOnBuckleComponent, UnstrappedEvent>(OnUnstrapped);
|
|
|
|
|
SubscribeLocalEvent<StasisBedComponent, StrappedEvent>(OnStasisStrapped);
|
|
|
|
|
SubscribeLocalEvent<StasisBedComponent, UnstrappedEvent>(OnStasisUnstrapped);
|
2022-04-15 18:53:52 -04:00
|
|
|
SubscribeLocalEvent<StasisBedComponent, PowerChangedEvent>(OnPowerChanged);
|
|
|
|
|
SubscribeLocalEvent<StasisBedComponent, GotEmaggedEvent>(OnEmagged);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-20 03:14:18 +12:00
|
|
|
private void OnStrapped(Entity<HealOnBuckleComponent> bed, ref StrappedEvent args)
|
2022-04-15 18:53:52 -04:00
|
|
|
{
|
2024-06-20 03:14:18 +12:00
|
|
|
EnsureComp<HealOnBuckleHealingComponent>(bed);
|
|
|
|
|
bed.Comp.NextHealTime = _timing.CurTime + TimeSpan.FromSeconds(bed.Comp.HealTime);
|
|
|
|
|
_actionsSystem.AddAction(args.Buckle, ref bed.Comp.SleepAction, SleepingSystem.SleepActionId, bed);
|
2022-04-15 18:53:52 -04:00
|
|
|
|
2024-06-20 03:14:18 +12:00
|
|
|
// 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, bed.Comp.SleepAction);
|
|
|
|
|
_sleepingSystem.TryWaking(args.Buckle.Owner);
|
|
|
|
|
RemComp<HealOnBuckleHealingComponent>(bed);
|
2022-04-15 18:53:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
var query = EntityQueryEnumerator<HealOnBuckleHealingComponent, HealOnBuckleComponent, StrapComponent>();
|
|
|
|
|
while (query.MoveNext(out var uid, out _, out var bedComponent, out var strapComponent))
|
2022-04-15 18:53:52 -04:00
|
|
|
{
|
2022-11-08 20:59:34 +01:00
|
|
|
if (_timing.CurTime < bedComponent.NextHealTime)
|
2022-04-15 18:53:52 -04:00
|
|
|
continue;
|
2022-05-24 22:31:15 -04:00
|
|
|
|
2022-11-08 20:59:34 +01:00
|
|
|
bedComponent.NextHealTime += TimeSpan.FromSeconds(bedComponent.HealTime);
|
2022-05-24 22:31:15 -04:00
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
if (strapComponent.BuckledEntities.Count == 0)
|
|
|
|
|
continue;
|
2022-05-24 22:31:15 -04:00
|
|
|
|
|
|
|
|
foreach (var healedEntity in strapComponent.BuckledEntities)
|
2022-04-15 18:53:52 -04:00
|
|
|
{
|
2022-07-27 00:46:24 -04:00
|
|
|
if (_mobStateSystem.IsDead(healedEntity))
|
2022-05-24 22:31:15 -04:00
|
|
|
continue;
|
|
|
|
|
|
2022-07-27 00:46:24 -04:00
|
|
|
var damage = bedComponent.Damage;
|
|
|
|
|
|
|
|
|
|
if (HasComp<SleepingComponent>(healedEntity))
|
|
|
|
|
damage *= bedComponent.SleepMultiplier;
|
|
|
|
|
|
2023-10-19 12:34:31 -07:00
|
|
|
_damageableSystem.TryChangeDamage(healedEntity, damage, true, origin: uid);
|
2022-04-15 18:53:52 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateAppearance(EntityUid uid, bool isOn)
|
|
|
|
|
{
|
2022-10-15 17:39:30 -04:00
|
|
|
_appearance.SetData(uid, StasisBedVisuals.IsOn, isOn);
|
2022-04-15 18:53:52 -04:00
|
|
|
}
|
|
|
|
|
|
2024-06-20 03:14:18 +12:00
|
|
|
private void OnStasisStrapped(Entity<StasisBedComponent> bed, ref StrappedEvent args)
|
2022-04-15 18:53:52 -04:00
|
|
|
{
|
2024-06-20 03:14:18 +12:00
|
|
|
if (!HasComp<BodyComponent>(args.Buckle) || !this.IsPowered(bed, EntityManager))
|
2022-04-15 18:53:52 -04:00
|
|
|
return;
|
|
|
|
|
|
2024-06-20 03:14:18 +12:00
|
|
|
var metabolicEvent = new ApplyMetabolicMultiplierEvent(args.Buckle, bed.Comp.Multiplier, true);
|
|
|
|
|
RaiseLocalEvent(args.Buckle, ref metabolicEvent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnStasisUnstrapped(Entity<StasisBedComponent> bed, ref UnstrappedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!HasComp<BodyComponent>(args.Buckle) || !this.IsPowered(bed, EntityManager))
|
2022-04-15 18:53:52 -04:00
|
|
|
return;
|
|
|
|
|
|
2024-06-20 03:14:18 +12:00
|
|
|
var metabolicEvent = new ApplyMetabolicMultiplierEvent(args.Buckle, bed.Comp.Multiplier, false);
|
|
|
|
|
RaiseLocalEvent(args.Buckle, ref metabolicEvent);
|
2022-04-15 18:53:52 -04:00
|
|
|
}
|
|
|
|
|
|
2022-10-15 15:08:15 +11:00
|
|
|
private void OnPowerChanged(EntityUid uid, StasisBedComponent component, ref PowerChangedEvent args)
|
2022-04-15 18:53:52 -04:00
|
|
|
{
|
|
|
|
|
UpdateAppearance(uid, args.Powered);
|
|
|
|
|
UpdateMetabolisms(uid, component, args.Powered);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-21 10:12:45 -05:00
|
|
|
private void OnEmagged(EntityUid uid, StasisBedComponent component, ref GotEmaggedEvent args)
|
2022-04-15 18:53:52 -04:00
|
|
|
{
|
2023-02-19 01:03:06 +00:00
|
|
|
args.Repeatable = true;
|
2022-05-24 22:31:15 -04:00
|
|
|
// Reset any metabolisms first so they receive the multiplier correctly
|
2022-04-15 18:53:52 -04:00
|
|
|
UpdateMetabolisms(uid, component, false);
|
|
|
|
|
component.Multiplier = 1 / component.Multiplier;
|
|
|
|
|
UpdateMetabolisms(uid, component, true);
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateMetabolisms(EntityUid uid, StasisBedComponent component, bool shouldApply)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp<StrapComponent>(uid, out var strap) || strap.BuckledEntities.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var buckledEntity in strap.BuckledEntities)
|
|
|
|
|
{
|
2024-03-28 01:48:37 +01:00
|
|
|
var metabolicEvent = new ApplyMetabolicMultiplierEvent(buckledEntity, component.Multiplier, shouldApply);
|
|
|
|
|
RaiseLocalEvent(buckledEntity, ref metabolicEvent);
|
2022-04-15 18:53:52 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|