]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Status Effect Alerts and Time Bugfixes (#39529)
authorPrincess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
Sun, 10 Aug 2025 20:55:13 +0000 (13:55 -0700)
committerGitHub <noreply@github.com>
Sun, 10 Aug 2025 20:55:13 +0000 (13:55 -0700)
* Bugefix

* Clean up

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
Content.Shared/StatusEffectNew/StatusEffectSystem.API.cs
Content.Shared/StatusEffectNew/StatusEffectsSystem.cs

index 2144b5a0c19c90cb2370b9a9d98fa412e27ca652..56636c9601ff138b53460ea9c2fa2b46197a255e 100644 (file)
@@ -69,7 +69,7 @@ public sealed partial class StatusEffectsSystem
         if (!TryGetStatusEffect(target, effectProto, out statusEffect))
             return TryAddStatusEffect(target, effectProto, out statusEffect, duration);
 
-        SetStatusEffectTime(statusEffect.Value, duration);
+        SetStatusEffectEndTime(statusEffect.Value, duration);
 
         return true;
     }
@@ -291,7 +291,7 @@ public sealed partial class StatusEffectsSystem
             var meta = MetaData(effect);
             if (meta.EntityPrototype is not null && meta.EntityPrototype == effectProto)
             {
-                SetStatusEffectTime(effect, time);
+                SetStatusEffectEndTime(effect, time);
                 return true;
             }
         }
index 1ffb74570a29e2e2a989e4bc089326f61214eebd..b385a12fb86e1d162c23421d2753332ba4ecb38c 100644 (file)
@@ -125,47 +125,6 @@ public sealed partial class StatusEffectsSystem : EntitySystem
         PredictedQueueDel(ent.Owner);
     }
 
-    private void SetStatusEffectTime(EntityUid effect, TimeSpan? duration)
-    {
-        if (!_effectQuery.TryComp(effect, out var effectComp))
-            return;
-
-        if (duration is null)
-        {
-            if(effectComp.EndEffectTime is null)
-                return;
-
-            effectComp.EndEffectTime = null;
-        }
-        else
-            effectComp.EndEffectTime = _timing.CurTime + duration;
-
-        Dirty(effect, effectComp);
-    }
-
-    private void UpdateStatusEffectTime(EntityUid effect, TimeSpan? duration)
-    {
-        if (!_effectQuery.TryComp(effect, out var effectComp))
-            return;
-
-        // It's already infinitely long
-        if (effectComp.EndEffectTime is null)
-            return;
-
-        if (duration is null)
-            effectComp.EndEffectTime = null;
-        else
-        {
-            var newEndTime = _timing.CurTime + duration;
-            if (effectComp.EndEffectTime >= newEndTime)
-                return;
-
-            effectComp.EndEffectTime = newEndTime;
-        }
-
-        Dirty(effect, effectComp);
-    }
-
     public bool CanAddStatusEffect(EntityUid uid, EntProtoId effectProto)
     {
         if (!_proto.TryIndex(effectProto, out var effectProtoData))
@@ -227,13 +186,39 @@ public sealed partial class StatusEffectsSystem : EntitySystem
         return true;
     }
 
-    private void AddStatusEffectTime(EntityUid effect, TimeSpan delta)
+    private void UpdateStatusEffectTime(Entity<StatusEffectComponent?> effect, TimeSpan? duration)
     {
-        if (!_effectQuery.TryComp(effect, out var effectComp))
+        if (!_effectQuery.Resolve(effect, ref effect.Comp))
+            return;
+
+        // It's already infinitely long
+        if (effect.Comp.EndEffectTime is null)
+            return;
+
+        TimeSpan? newEndTime = null;
+
+        if (duration is not null)
+        {
+            // Don't update time to a smaller timespan...
+            newEndTime = _timing.CurTime + duration;
+            if (effect.Comp.EndEffectTime >= newEndTime)
+                return;
+        }
+
+        SetStatusEffectEndTime(effect, newEndTime);
+    }
+
+    private void AddStatusEffectTime(Entity<StatusEffectComponent?> effect, TimeSpan delta)
+    {
+        if (!_effectQuery.Resolve(effect, ref effect.Comp))
+            return;
+
+        // It's already infinitely long can't add or subtract from infinity...
+        if (effect.Comp.EndEffectTime is null)
             return;
 
-        // If we don't have an end time set, we want to just make the status effect end in delta time from now.
-        SetStatusEffectEndTime((effect, effectComp), (effectComp.EndEffectTime ?? _timing.CurTime) + delta);
+        // Add to the current end effect time, if we're here we should have one set already, and if it's null it's probably infinite.
+        SetStatusEffectEndTime((effect, effect.Comp), effect.Comp.EndEffectTime.Value + delta);
     }
 
     private void SetStatusEffectEndTime(Entity<StatusEffectComponent?> ent, TimeSpan? endTime)