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-07-27 00:46:24 -04:00
|
|
|
using Content.Server.Bed.Sleep;
|
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;
|
2022-11-08 20:59:34 +01:00
|
|
|
using Robust.Shared.Timing;
|
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();
|
|
|
|
|
SubscribeLocalEvent<HealOnBuckleComponent, BuckleChangeEvent>(ManageUpdateList);
|
|
|
|
|
SubscribeLocalEvent<StasisBedComponent, BuckleChangeEvent>(OnBuckleChange);
|
|
|
|
|
SubscribeLocalEvent<StasisBedComponent, PowerChangedEvent>(OnPowerChanged);
|
|
|
|
|
SubscribeLocalEvent<StasisBedComponent, GotEmaggedEvent>(OnEmagged);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-01 03:04:23 -04:00
|
|
|
private void ManageUpdateList(EntityUid uid, HealOnBuckleComponent component, ref BuckleChangeEvent args)
|
2022-04-15 18:53:52 -04:00
|
|
|
{
|
|
|
|
|
if (args.Buckling)
|
|
|
|
|
{
|
|
|
|
|
AddComp<HealOnBuckleHealingComponent>(uid);
|
2022-11-08 20:59:34 +01:00
|
|
|
component.NextHealTime = _timing.CurTime + TimeSpan.FromSeconds(component.HealTime);
|
2023-09-23 04:49:39 -04:00
|
|
|
_actionsSystem.AddAction(args.BuckledEntity, ref component.SleepAction, SleepingSystem.SleepActionId, uid);
|
2022-04-15 18:53:52 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-23 04:49:39 -04:00
|
|
|
_actionsSystem.RemoveAction(args.BuckledEntity, component.SleepAction);
|
2022-07-27 00:46:24 -04:00
|
|
|
_sleepingSystem.TryWaking(args.BuckledEntity);
|
2022-04-15 18:53:52 -04:00
|
|
|
RemComp<HealOnBuckleHealingComponent>(uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2023-05-01 03:04:23 -04:00
|
|
|
private void OnBuckleChange(EntityUid uid, StasisBedComponent component, ref BuckleChangeEvent args)
|
2022-04-15 18:53:52 -04:00
|
|
|
{
|
|
|
|
|
// In testing this also received an unbuckle event when the bed is destroyed
|
|
|
|
|
// So don't worry about that
|
2022-10-23 00:46:28 +02:00
|
|
|
if (!HasComp<BodyComponent>(args.BuckledEntity))
|
2022-04-15 18:53:52 -04:00
|
|
|
return;
|
|
|
|
|
|
2022-05-27 10:36:12 +10:00
|
|
|
if (!this.IsPowered(uid, EntityManager))
|
2022-04-15 18:53:52 -04:00
|
|
|
return;
|
|
|
|
|
|
2024-03-28 01:48:37 +01:00
|
|
|
var metabolicEvent = new ApplyMetabolicMultiplierEvent(args.BuckledEntity, component.Multiplier, args.Buckling);
|
|
|
|
|
RaiseLocalEvent(args.BuckledEntity, 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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|