SpeechComponent.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Content.Shared.Chat.Prototypes;
  2. using Robust.Shared.Audio;
  3. using Robust.Shared.GameStates;
  4. using Robust.Shared.Prototypes;
  5. namespace Content.Shared.Speech
  6. {
  7. /// <summary>
  8. /// Component required for entities to be able to speak. (TODO: Entities can speak fine without this, this only forbids them speak if they have it and enabled is false.)
  9. /// Contains the option to let entities make noise when speaking, change speech verbs, datafields for the sounds in question, and relevant AudioParams.
  10. /// </summary>
  11. [RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
  12. public sealed partial class SpeechComponent : Component
  13. {
  14. [DataField, AutoNetworkedField]
  15. [Access(typeof(SpeechSystem), Friend = AccessPermissions.ReadWrite, Other = AccessPermissions.Read)]
  16. public bool Enabled = true;
  17. [ViewVariables(VVAccess.ReadWrite)]
  18. [DataField]
  19. public ProtoId<SpeechSoundsPrototype>? SpeechSounds;
  20. /// <summary>
  21. /// What speech verb prototype should be used by default for displaying this entity's messages?
  22. /// </summary>
  23. [ViewVariables(VVAccess.ReadWrite)]
  24. [DataField]
  25. public ProtoId<SpeechVerbPrototype> SpeechVerb = "Default";
  26. /// <summary>
  27. /// What emotes allowed to use event if emote <see cref="EmotePrototype.Available"/> is false
  28. /// </summary>
  29. [ViewVariables(VVAccess.ReadWrite)]
  30. [DataField]
  31. public List<ProtoId<EmotePrototype>> AllowedEmotes = new();
  32. /// <summary>
  33. /// A mapping from chat suffixes loc strings to speech verb prototypes that should be conditionally used.
  34. /// For things like '?' changing to 'asks' or '!!' making text bold and changing to 'yells'. Can be overridden if necessary.
  35. /// </summary>
  36. [DataField]
  37. public Dictionary<string, ProtoId<SpeechVerbPrototype>> SuffixSpeechVerbs = new()
  38. {
  39. { "chat-speech-verb-suffix-exclamation-strong", "DefaultExclamationStrong" },
  40. { "chat-speech-verb-suffix-exclamation", "DefaultExclamation" },
  41. { "chat-speech-verb-suffix-question", "DefaultQuestion" },
  42. { "chat-speech-verb-suffix-stutter", "DefaultStutter" },
  43. { "chat-speech-verb-suffix-mumble", "DefaultMumble" },
  44. };
  45. [DataField]
  46. public AudioParams AudioParams = AudioParams.Default.WithVolume(-2f).WithRolloffFactor(4.5f);
  47. [ViewVariables(VVAccess.ReadWrite)]
  48. [DataField]
  49. public float SoundCooldownTime { get; set; } = 0.5f;
  50. public TimeSpan LastTimeSoundPlayed = TimeSpan.Zero;
  51. /// <summary>
  52. /// Additional vertical offset for speech bubbles generated by this entity
  53. /// </summary>
  54. [DataField]
  55. public float SpeechBubbleOffset = 0f;
  56. }
  57. }