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 GitHub
parent 89d1100337
commit 737bd3e22c
5 changed files with 48 additions and 70 deletions

View File

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

View File

@@ -1,54 +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;
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))
continue;
var damage = bedComponent.Damage;
if (_sleepingQuery.HasComp(healedEntity))
damage *= bedComponent.SleepMultiplier;
_damageableSystem.TryChangeDamage(healedEntity, damage, true, origin: uid);
}
}
}
}
}

View File

@@ -4,7 +4,9 @@ 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 +14,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 +41,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 +54,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);
@@ -62,7 +70,7 @@ public abstract class SharedBedSystem : EntitySystem
_actionsSystem.RemoveAction(args.Buckle.Owner, bed.Comp.SleepAction);
_sleepingSystem.TryWaking(args.Buckle.Owner);
}
RemComp<HealOnBuckleHealingComponent>(bed);
}
@@ -112,7 +120,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 +130,36 @@ 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))
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>