Predict BedSystem (#41686)

* BedSystem-move-to-shared

* dependency

* dirty!!!
This commit is contained in:
Pok 2025-12-03 21:44:17 +02:00 committed by BarryNorfolk
parent 1052426b3e
commit e21a29ddf8
5 changed files with 50 additions and 73 deletions

View File

@ -1,8 +0,0 @@
using Content.Shared.Bed;
namespace Content.Client.Bed;
public sealed class BedSystem : SharedBedSystem
{
}

View File

@ -1,57 +0,0 @@
using Content.Shared.Bed;
using Content.Shared.Bed.Components;
using Content.Shared.Bed.Sleep;
using Content.Shared.Buckle.Components;
using Content.Shared.Damage.Systems;
using Content.Shared.Mobs.Systems;
using Content.Shared.Power;
using Content.Shared._EE.Silicon.Components; // Goobstation
namespace Content.Server.Bed
{
public sealed class BedSystem : SharedBedSystem
{
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
private EntityQuery<SleepingComponent> _sleepingQuery;
public override void Initialize()
{
base.Initialize();
_sleepingQuery = GetEntityQuery<SleepingComponent>();
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<HealOnBuckleHealingComponent, HealOnBuckleComponent, StrapComponent>();
while (query.MoveNext(out var uid, out _, out var bedComponent, out var strapComponent))
{
if (Timing.CurTime < bedComponent.NextHealTime)
continue;
bedComponent.NextHealTime += TimeSpan.FromSeconds(bedComponent.HealTime);
if (strapComponent.BuckledEntities.Count == 0)
continue;
foreach (var healedEntity in strapComponent.BuckledEntities)
{
if (_mobStateSystem.IsDead(healedEntity)
|| HasComp<SiliconComponent>(healedEntity)) // Goobstation
continue;
var damage = bedComponent.Damage;
if (_sleepingQuery.HasComp(healedEntity))
damage *= bedComponent.SleepMultiplier;
_damageableSystem.TryChangeDamage(healedEntity, damage, true, origin: uid);
}
}
}
}
}

View File

@ -1,10 +1,13 @@
using Content.Shared._EE.Silicon.Components; // Goobstation
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.Damage.Systems;
using Content.Shared.Emag.Systems;
using Content.Shared.Mobs.Systems;
using Content.Shared.Power;
using Content.Shared.Power.EntitySystems;
using Robust.Shared.Timing;
@ -12,16 +15,20 @@ using Robust.Shared.Utility;
namespace Content.Shared.Bed;
public abstract class SharedBedSystem : EntitySystem
public sealed class BedSystem : EntitySystem
{
[Dependency] protected readonly IGameTiming Timing = default!;
[Dependency] private readonly ActionContainerSystem _actConts = default!;
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly EmagSystem _emag = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
[Dependency] private readonly SharedMetabolizerSystem _metabolizer = default!;
[Dependency] private readonly SharedPowerReceiverSystem _powerReceiver = default!;
[Dependency] private readonly SleepingSystem _sleepingSystem = default!;
private EntityQuery<SleepingComponent> _sleepingQuery;
public override void Initialize()
{
base.Initialize();
@ -35,6 +42,8 @@ public abstract class SharedBedSystem : EntitySystem
SubscribeLocalEvent<StasisBedComponent, GotEmaggedEvent>(OnStasisEmagged);
SubscribeLocalEvent<StasisBedComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<StasisBedBuckledComponent, GetMetabolicMultiplierEvent>(OnStasisGetMetabolicMultiplier);
_sleepingQuery = GetEntityQuery<SleepingComponent>();
}
private void OnHealMapInit(Entity<HealOnBuckleComponent> ent, ref MapInitEvent args)
@ -46,7 +55,7 @@ public abstract class SharedBedSystem : EntitySystem
private void OnStrapped(Entity<HealOnBuckleComponent> bed, ref StrappedEvent args)
{
EnsureComp<HealOnBuckleHealingComponent>(bed);
bed.Comp.NextHealTime = Timing.CurTime + TimeSpan.FromSeconds(bed.Comp.HealTime);
bed.Comp.NextHealTime = _timing.CurTime + TimeSpan.FromSeconds(bed.Comp.HealTime);
_actionsSystem.AddAction(args.Buckle, ref bed.Comp.SleepAction, SleepingSystem.SleepActionId, bed);
Dirty(bed);
@ -112,7 +121,7 @@ public abstract class SharedBedSystem : EntitySystem
args.Multiplier *= stasis.Multiplier;
}
protected void UpdateMetabolisms(Entity<StrapComponent?> ent)
private void UpdateMetabolisms(Entity<StrapComponent?> ent)
{
if (!Resolve(ent, ref ent.Comp, false))
return;
@ -122,4 +131,37 @@ public abstract class SharedBedSystem : EntitySystem
_metabolizer.UpdateMetabolicMultiplier(buckledEntity);
}
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<HealOnBuckleHealingComponent, HealOnBuckleComponent, StrapComponent>();
while (query.MoveNext(out var uid, out _, out var bedComponent, out var strapComponent))
{
if (_timing.CurTime < bedComponent.NextHealTime)
continue;
bedComponent.NextHealTime += TimeSpan.FromSeconds(bedComponent.HealTime);
Dirty(uid, bedComponent);
if (strapComponent.BuckledEntities.Count == 0)
continue;
foreach (var healedEntity in strapComponent.BuckledEntities)
{
if (_mobStateSystem.IsDead(healedEntity)
|| HasComp<SiliconComponent>(healedEntity)) // Goobstation)
continue;
var damage = bedComponent.Damage;
if (_sleepingQuery.HasComp(healedEntity))
damage *= bedComponent.SleepMultiplier;
_damageableSystem.TryChangeDamage(healedEntity, damage, true, origin: uid);
}
}
}
}

View File

@ -6,5 +6,5 @@ namespace Content.Shared.Bed.Components;
/// Tracking component added to entities buckled to stasis beds.
/// </summary>
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedBedSystem))]
[Access(typeof(BedSystem))]
public sealed partial class StasisBedBuckledComponent : Component;

View File

@ -7,7 +7,7 @@ namespace Content.Shared.Bed.Components;
/// A <see cref="StrapComponent"/> that modifies a strapped entity's metabolic rate by the given multiplier
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
[Access(typeof(SharedBedSystem))]
[Access(typeof(BedSystem))]
public sealed partial class StasisBedComponent : Component
{
/// <summary>