Speech verbs & conditional markup modification (#18980)

This commit is contained in:
Kara
2023-08-15 13:03:05 -07:00
committed by GitHub
parent 5742c4ee11
commit 7db8c781e7
27 changed files with 252 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
using Content.Shared.Popups;
using Content.Shared.Radio;
using Content.Shared.Speech;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
@@ -26,6 +27,9 @@ public abstract class SharedChatSystem : EntitySystem
public static string DefaultChannelPrefix = $"{RadioChannelPrefix}{DefaultChannelKey}";
[ValidatePrototypeId<SpeechVerbPrototype>]
public const string DefaultSpeechVerb = "Default";
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
@@ -63,6 +67,30 @@ public abstract class SharedChatSystem : EntitySystem
_prototypeManager.PrototypesReloaded -= OnPrototypeReload;
}
/// <summary>
/// Attempts to find an applicable <see cref="SpeechVerbPrototype"/> for a speaking entity's message.
/// If one is not found, returns <see cref="DefaultSpeechVerb"/>.
/// </summary>
public SpeechVerbPrototype GetSpeechVerb(EntityUid source, string message, SpeechComponent? speech = null)
{
if (!Resolve(source, ref speech, false))
return _prototypeManager.Index<SpeechVerbPrototype>(DefaultSpeechVerb);
// check for a suffix-applicable speech verb
SpeechVerbPrototype? current = null;
foreach (var (str, id) in speech.SuffixSpeechVerbs)
{
var proto = _prototypeManager.Index<SpeechVerbPrototype>(id);
if (message.EndsWith(Loc.GetString(str)) && proto.Priority >= (current?.Priority ?? 0))
{
current = proto;
}
}
// if no applicable suffix verb return the normal one used by the entity
return current ?? _prototypeManager.Index<SpeechVerbPrototype>(speech.SpeechVerb);
}
/// <summary>
/// Attempts to resolve radio prefixes in chat messages (e.g., remove a leading ":e" and resolve the requested
/// channel. Returns true if a radio message was attempted, even if the channel is invalid.