]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix auto-emote bug (#14883)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Mon, 27 Mar 2023 00:47:46 +0000 (13:47 +1300)
committerGitHub <noreply@github.com>
Mon, 27 Mar 2023 00:47:46 +0000 (17:47 -0700)
Content.Server/Chat/Systems/AutoEmoteSystem.cs
Content.Server/Chat/Systems/EmoteOnDamageSystem.cs

index 7dd4a98a435183b35f3df5162943ddf32f28e2a0..f139c9d63ca49e0155220405f30109e983b29e36 100644 (file)
@@ -83,6 +83,8 @@ public sealed class AutoEmoteSystem : EntitySystem
         if (!Resolve(uid, ref autoEmote, logMissing: false))
             return false;
 
+        DebugTools.Assert(autoEmote.LifeStage <= ComponentLifeStage.Running);
+
         if (autoEmote.Emotes.Contains(autoEmotePrototypeId))
             return false;
 
@@ -93,9 +95,9 @@ public sealed class AutoEmoteSystem : EntitySystem
     }
 
     /// <summary>
-    /// Stop preforming an emote.
+    /// Stop preforming an emote. Note that by default this will queue empty components for removal.
     /// </summary>
-    public bool RemoveEmote(EntityUid uid, string autoEmotePrototypeId, AutoEmoteComponent? autoEmote = null)
+    public bool RemoveEmote(EntityUid uid, string autoEmotePrototypeId, AutoEmoteComponent? autoEmote = null, bool removeEmpty = true)
     {
         if (!Resolve(uid, ref autoEmote, logMissing: false))
             return false;
@@ -105,7 +107,13 @@ public sealed class AutoEmoteSystem : EntitySystem
         if (!autoEmote.EmoteTimers.Remove(autoEmotePrototypeId))
             return false;
 
-        autoEmote.NextEmoteTime = autoEmote.EmoteTimers.Values.Min();
+        if (autoEmote.EmoteTimers.Count > 0)
+            autoEmote.NextEmoteTime = autoEmote.EmoteTimers.Values.Min();
+        else if (removeEmpty)
+            RemCompDeferred(uid, autoEmote);
+        else
+            autoEmote.NextEmoteTime = TimeSpan.MaxValue;
+
         return true;
     }
 
index ae14399c250194035766c9124c56acc6344703a9..956a7eb8254de5584dbf47365aab4e0b2f061112 100644 (file)
@@ -62,21 +62,28 @@ public sealed class EmoteOnDamageSystem : EntitySystem
         if (!Resolve(uid, ref emoteOnDamage, logMissing: false))
             return false;
 
+        DebugTools.Assert(emoteOnDamage.LifeStage <= ComponentLifeStage.Running);
         DebugTools.Assert(_prototypeManager.HasIndex<EmotePrototype>(emotePrototypeId), "Prototype not found. Did you make a typo?");
 
         return emoteOnDamage.Emotes.Add(emotePrototypeId);
     }
 
     /// <summary>
-    /// Stop preforming an emote.
+    /// Stop preforming an emote. Note that by default this will queue empty components for removal.
     /// </summary>
-    public bool RemoveEmote(EntityUid uid, string emotePrototypeId, EmoteOnDamageComponent? emoteOnDamage = null)
+    public bool RemoveEmote(EntityUid uid, string emotePrototypeId, EmoteOnDamageComponent? emoteOnDamage = null, bool removeEmpty = true)
     {
         if (!Resolve(uid, ref emoteOnDamage, logMissing: false))
             return false;
 
         DebugTools.Assert(_prototypeManager.HasIndex<EmotePrototype>(emotePrototypeId), "Prototype not found. Did you make a typo?");
 
-        return emoteOnDamage.Emotes.Remove(emotePrototypeId);
+        if (!emoteOnDamage.Emotes.Remove(emotePrototypeId))
+            return false;
+
+        if (removeEmpty && emoteOnDamage.Emotes.Count == 0)
+            RemCompDeferred(uid, emoteOnDamage);
+
+        return true;
     }
 }