From: ScarKy0 <106310278+ScarKy0@users.noreply.github.com> Date: Wed, 7 Jan 2026 15:58:28 +0000 (+0100) Subject: Predict Rotting Examine (#42254) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=a8469ca509d5409282083b96aa886dcaa0dd4bef;p=space-station-14.git Predict Rotting Examine (#42254) * init * review * test * Apply suggestions from code review --------- Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com> --- diff --git a/Content.Server/Atmos/Rotting/RottingSystem.cs b/Content.Server/Atmos/Rotting/RottingSystem.cs index 5feb95e3c4..e83d80748b 100644 --- a/Content.Server/Atmos/Rotting/RottingSystem.cs +++ b/Content.Server/Atmos/Rotting/RottingSystem.cs @@ -72,19 +72,21 @@ public sealed class RottingSystem : SharedRottingSystem { if (_timing.CurTime < perishable.RotNextUpdate) continue; + perishable.RotNextUpdate += perishable.PerishUpdateRate; var stage = PerishStage((uid, perishable), MaxStages); if (stage != perishable.Stage) { perishable.Stage = stage; - Dirty(uid, perishable); + DirtyField(uid, perishable, nameof(PerishableComponent.Stage)); } if (IsRotten(uid) || !IsRotProgressing(uid, perishable)) continue; perishable.RotAccumulator += perishable.PerishUpdateRate * GetRotRate(uid); + DirtyField(uid, perishable, nameof(PerishableComponent.RotAccumulator)); if (perishable.RotAccumulator >= perishable.RotAfter) { var rot = AddComp(uid); diff --git a/Content.Shared/Atmos/Rotting/PerishableComponent.cs b/Content.Shared/Atmos/Rotting/PerishableComponent.cs index 99b30fc906..3acda1c3ff 100644 --- a/Content.Shared/Atmos/Rotting/PerishableComponent.cs +++ b/Content.Shared/Atmos/Rotting/PerishableComponent.cs @@ -7,7 +7,7 @@ namespace Content.Shared.Atmos.Rotting; /// This makes mobs eventually start rotting when they die. /// It may be expanded to food at some point, but it's just for mobs right now. /// -[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause] +[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(fieldDeltas: true), AutoGenerateComponentPause] [Access(typeof(SharedRottingSystem))] public sealed partial class PerishableComponent : Component { @@ -20,7 +20,7 @@ public sealed partial class PerishableComponent : Component /// /// How much rotting has occured /// - [DataField] + [DataField, AutoNetworkedField] public TimeSpan RotAccumulator = TimeSpan.Zero; /// diff --git a/Content.Shared/Atmos/Rotting/SharedRottingSystem.cs b/Content.Shared/Atmos/Rotting/SharedRottingSystem.cs index 60c89c012a..5fd9aaf3e2 100644 --- a/Content.Shared/Atmos/Rotting/SharedRottingSystem.cs +++ b/Content.Shared/Atmos/Rotting/SharedRottingSystem.cs @@ -31,21 +31,22 @@ public abstract class SharedRottingSystem : EntitySystem SubscribeLocalEvent(OnExamined); } - private void OnPerishableMapInit(EntityUid uid, PerishableComponent component, MapInitEvent args) + private void OnPerishableMapInit(Entity ent, ref MapInitEvent args) { - component.RotNextUpdate = _timing.CurTime + component.PerishUpdateRate; + ent.Comp.RotNextUpdate = _timing.CurTime + ent.Comp.PerishUpdateRate; } - private void OnMobStateChanged(EntityUid uid, PerishableComponent component, MobStateChangedEvent args) + private void OnMobStateChanged(Entity ent, ref MobStateChangedEvent args) { if (args.NewMobState != MobState.Dead && args.OldMobState != MobState.Dead) return; - if (HasComp(uid)) + if (HasComp(ent)) return; - component.RotAccumulator = TimeSpan.Zero; - component.RotNextUpdate = _timing.CurTime + component.PerishUpdateRate; + ent.Comp.RotAccumulator = TimeSpan.Zero; + ent.Comp.RotNextUpdate = _timing.CurTime + ent.Comp.PerishUpdateRate; + DirtyField(ent.Owner, ent.Comp, nameof(PerishableComponent.RotAccumulator)); } private void OnPerishableExamined(Entity perishable, ref ExaminedEvent args) @@ -62,9 +63,9 @@ public abstract class SharedRottingSystem : EntitySystem args.PushMarkup(Loc.GetString(description, ("target", Identity.Entity(perishable, EntityManager)))); } - private void OnShutdown(EntityUid uid, RottingComponent component, ComponentShutdown args) + private void OnShutdown(Entity ent, ref ComponentShutdown args) { - if (TryComp(uid, out var perishable)) + if (TryComp(ent, out var perishable)) { perishable.RotNextUpdate = TimeSpan.Zero; } @@ -74,6 +75,7 @@ public abstract class SharedRottingSystem : EntitySystem { if (args.NewMobState == MobState.Dead) return; + RemCompDeferred(uid, component); } @@ -148,6 +150,7 @@ public abstract class SharedRottingSystem : EntitySystem if (!TryComp(uid, out var rotting)) { perishable.RotAccumulator -= time; + DirtyField(uid, perishable, nameof(PerishableComponent.RotAccumulator)); return; } var total = (rotting.TotalRotTime + perishable.RotAccumulator) - time; @@ -156,8 +159,8 @@ public abstract class SharedRottingSystem : EntitySystem { RemCompDeferred(uid, rotting); perishable.RotAccumulator = total; + DirtyField(uid, perishable, nameof(PerishableComponent.RotAccumulator)); } - else rotting.TotalRotTime = total - perishable.RotAfter; }