]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predict Rotting Examine (#42254)
authorScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Wed, 7 Jan 2026 15:58:28 +0000 (16:58 +0100)
committerGitHub <noreply@github.com>
Wed, 7 Jan 2026 15:58:28 +0000 (15:58 +0000)
* init

* review

* test

* Apply suggestions from code review

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
Content.Server/Atmos/Rotting/RottingSystem.cs
Content.Shared/Atmos/Rotting/PerishableComponent.cs
Content.Shared/Atmos/Rotting/SharedRottingSystem.cs

index 5feb95e3c495d63ed18c7ace60e0bd8bd6b57d41..e83d80748b60a0e5b1f23bc07b2dd33925f70a26 100644 (file)
@@ -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<RottingComponent>(uid);
index 99b30fc9069ae067b3e3f86e7c01a075f00a424b..3acda1c3ffbfe239c1e1a4a6e234fa4b21187adb 100644 (file)
@@ -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.
 /// </summary>
-[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
     /// <summary>
     /// How much rotting has occured
     /// </summary>
-    [DataField]
+    [DataField, AutoNetworkedField]
     public TimeSpan RotAccumulator = TimeSpan.Zero;
 
     /// <summary>
index 60c89c012a0f49b928c7a7eeaef57c14f0a50c03..5fd9aaf3e275382a8b80cdcbea50bd9bb27e1843 100644 (file)
@@ -31,21 +31,22 @@ public abstract class SharedRottingSystem : EntitySystem
         SubscribeLocalEvent<RottingComponent, ExaminedEvent>(OnExamined);
     }
 
-    private void OnPerishableMapInit(EntityUid uid, PerishableComponent component, MapInitEvent args)
+    private void OnPerishableMapInit(Entity<PerishableComponent> 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<PerishableComponent> ent, ref MobStateChangedEvent args)
     {
         if (args.NewMobState != MobState.Dead && args.OldMobState != MobState.Dead)
             return;
 
-        if (HasComp<RottingComponent>(uid))
+        if (HasComp<RottingComponent>(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<PerishableComponent> 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<RottingComponent> ent, ref ComponentShutdown args)
     {
-        if (TryComp<PerishableComponent>(uid, out var perishable))
+        if (TryComp<PerishableComponent>(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<RottingComponent>(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;
     }