Fix auto-emote bug (#14883)

This commit is contained in:
Leon Friedrich
2023-03-27 13:47:46 +13:00
committed by GitHub
parent ef29436347
commit 87185d019c
2 changed files with 21 additions and 6 deletions

View File

@@ -83,6 +83,8 @@ public sealed class AutoEmoteSystem : EntitySystem
if (!Resolve(uid, ref autoEmote, logMissing: false)) if (!Resolve(uid, ref autoEmote, logMissing: false))
return false; return false;
DebugTools.Assert(autoEmote.LifeStage <= ComponentLifeStage.Running);
if (autoEmote.Emotes.Contains(autoEmotePrototypeId)) if (autoEmote.Emotes.Contains(autoEmotePrototypeId))
return false; return false;
@@ -93,9 +95,9 @@ public sealed class AutoEmoteSystem : EntitySystem
} }
/// <summary> /// <summary>
/// Stop preforming an emote. /// Stop preforming an emote. Note that by default this will queue empty components for removal.
/// </summary> /// </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)) if (!Resolve(uid, ref autoEmote, logMissing: false))
return false; return false;
@@ -105,7 +107,13 @@ public sealed class AutoEmoteSystem : EntitySystem
if (!autoEmote.EmoteTimers.Remove(autoEmotePrototypeId)) if (!autoEmote.EmoteTimers.Remove(autoEmotePrototypeId))
return false; return false;
if (autoEmote.EmoteTimers.Count > 0)
autoEmote.NextEmoteTime = autoEmote.EmoteTimers.Values.Min(); autoEmote.NextEmoteTime = autoEmote.EmoteTimers.Values.Min();
else if (removeEmpty)
RemCompDeferred(uid, autoEmote);
else
autoEmote.NextEmoteTime = TimeSpan.MaxValue;
return true; return true;
} }

View File

@@ -62,21 +62,28 @@ public sealed class EmoteOnDamageSystem : EntitySystem
if (!Resolve(uid, ref emoteOnDamage, logMissing: false)) if (!Resolve(uid, ref emoteOnDamage, logMissing: false))
return false; return false;
DebugTools.Assert(emoteOnDamage.LifeStage <= ComponentLifeStage.Running);
DebugTools.Assert(_prototypeManager.HasIndex<EmotePrototype>(emotePrototypeId), "Prototype not found. Did you make a typo?"); DebugTools.Assert(_prototypeManager.HasIndex<EmotePrototype>(emotePrototypeId), "Prototype not found. Did you make a typo?");
return emoteOnDamage.Emotes.Add(emotePrototypeId); return emoteOnDamage.Emotes.Add(emotePrototypeId);
} }
/// <summary> /// <summary>
/// Stop preforming an emote. /// Stop preforming an emote. Note that by default this will queue empty components for removal.
/// </summary> /// </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)) if (!Resolve(uid, ref emoteOnDamage, logMissing: false))
return false; return false;
DebugTools.Assert(_prototypeManager.HasIndex<EmotePrototype>(emotePrototypeId), "Prototype not found. Did you make a typo?"); 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;
} }
} }