From f334f4a4b932f324e41889f3545a2c6f1da153f8 Mon Sep 17 00:00:00 2001 From: Pancake Date: Tue, 21 Dec 2021 12:31:20 -0800 Subject: [PATCH] Accents (#5720) Co-authored-by: metalgearsloth Co-authored-by: Paul --- Content.Client/Entry/EntryPoint.cs | 1 + Content.Client/Entry/IgnoredComponents.cs | 4 +- .../Components/MonkeyAccentComponent.cs | 7 ++ .../Components/ReplacementAccentComponent.cs | 30 +++++++++ .../EntitySystems/MonkeyAccentSystem.cs | 67 +++++++++++++++++++ .../EntitySystems/ReplacementAccentSystem.cs | 30 +++++++++ .../Prototypes/Entities/Mobs/NPCs/animals.yml | 1 + .../Prototypes/Entities/Mobs/NPCs/pets.yml | 4 ++ Resources/Prototypes/accents.yml | 17 +++++ 9 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 Content.Server/Speech/Components/MonkeyAccentComponent.cs create mode 100644 Content.Server/Speech/Components/ReplacementAccentComponent.cs create mode 100644 Content.Server/Speech/EntitySystems/MonkeyAccentSystem.cs create mode 100644 Content.Server/Speech/EntitySystems/ReplacementAccentSystem.cs create mode 100644 Resources/Prototypes/accents.yml diff --git a/Content.Client/Entry/EntryPoint.cs b/Content.Client/Entry/EntryPoint.cs index 0ff2077933..73c3187a6a 100644 --- a/Content.Client/Entry/EntryPoint.cs +++ b/Content.Client/Entry/EntryPoint.cs @@ -84,6 +84,7 @@ namespace Content.Client.Entry factory.RegisterClass(); factory.RegisterClass(); + prototypes.RegisterIgnore("accent"); prototypes.RegisterIgnore("material"); prototypes.RegisterIgnore("reaction"); //Chemical reactions only needed by server. Reactions checks are server-side. prototypes.RegisterIgnore("gasReaction"); diff --git a/Content.Client/Entry/IgnoredComponents.cs b/Content.Client/Entry/IgnoredComponents.cs index 81c845b3cd..d3e0e640c7 100644 --- a/Content.Client/Entry/IgnoredComponents.cs +++ b/Content.Client/Entry/IgnoredComponents.cs @@ -317,7 +317,9 @@ namespace Content.Client.Entry "Udder", "PneumaticCannon", "Spreader", - "GrowingKudzu" + "GrowingKudzu", + "MonkeyAccent", + "ReplacementAccent" }; } } diff --git a/Content.Server/Speech/Components/MonkeyAccentComponent.cs b/Content.Server/Speech/Components/MonkeyAccentComponent.cs new file mode 100644 index 0000000000..0e1e510396 --- /dev/null +++ b/Content.Server/Speech/Components/MonkeyAccentComponent.cs @@ -0,0 +1,7 @@ +using Robust.Shared.GameObjects; + +namespace Content.Server.Speech.Components; + +[RegisterComponent] +[ComponentProtoName("MonkeyAccent")] +public sealed class MonkeyAccentComponent : Component {} diff --git a/Content.Server/Speech/Components/ReplacementAccentComponent.cs b/Content.Server/Speech/Components/ReplacementAccentComponent.cs new file mode 100644 index 0000000000..ef63a558a7 --- /dev/null +++ b/Content.Server/Speech/Components/ReplacementAccentComponent.cs @@ -0,0 +1,30 @@ +using Robust.Shared.GameObjects; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; +using Robust.Shared.ViewVariables; + +namespace Content.Server.Speech.Components +{ + [Prototype("accent")] + public sealed class ReplacementAccentPrototype : IPrototype + { + [ViewVariables] + [DataField("id", required: true)] + public string ID { get; } = default!; + + [DataField("words")] + public string[] Words = default!; + } + + /// + /// Replaces any spoken sentences with a random word. + /// + [RegisterComponent] + [ComponentProtoName("ReplacementAccent")] + public class ReplacementAccentComponent : Component + { + [DataField("accent", customTypeSerializer: typeof(PrototypeIdSerializer), required: true)] + public string Accent = default!; + } +} diff --git a/Content.Server/Speech/EntitySystems/MonkeyAccentSystem.cs b/Content.Server/Speech/EntitySystems/MonkeyAccentSystem.cs new file mode 100644 index 0000000000..8bf8e7219b --- /dev/null +++ b/Content.Server/Speech/EntitySystems/MonkeyAccentSystem.cs @@ -0,0 +1,67 @@ +using System.Text; +using Content.Server.Speech.Components; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Random; + +namespace Content.Server.Speech.EntitySystems; + +public sealed class MonkeyAccentSystem : EntitySystem +{ + [Dependency] private readonly IRobustRandom _random = default!; + + public override void Initialize() + { + SubscribeLocalEvent(OnAccent); + } + + public string Accentuate(string message) + { + var words = message.Split(); + var accentedMessage = new StringBuilder(message.Length + 2); + + for (var i = 0; i < words.Length; i++) + { + var word = words[i]; + + if (_random.NextDouble() >= 0.5) + { + if (word.Length > 1) + { + foreach (var _ in word) + { + accentedMessage.Append('O'); + } + + if (_random.NextDouble() >= 0.3) + accentedMessage.Append('K'); + } + else + accentedMessage.Append('O'); + } + else + { + foreach (var _ in word) + { + if (_random.NextDouble() >= 0.8) + accentedMessage.Append('H'); + else + accentedMessage.Append('A'); + } + + } + + if (i < words.Length - 1) + accentedMessage.Append(' '); + } + + accentedMessage.Append('!'); + + return accentedMessage.ToString(); + } + + private void OnAccent(EntityUid uid, MonkeyAccentComponent component, AccentGetEvent args) + { + args.Message = Accentuate(args.Message); + } +} diff --git a/Content.Server/Speech/EntitySystems/ReplacementAccentSystem.cs b/Content.Server/Speech/EntitySystems/ReplacementAccentSystem.cs new file mode 100644 index 0000000000..94443cb0a8 --- /dev/null +++ b/Content.Server/Speech/EntitySystems/ReplacementAccentSystem.cs @@ -0,0 +1,30 @@ +using Content.Server.Speech.Components; +using Robust.Shared.GameObjects; +using Robust.Shared.IoC; +using Robust.Shared.Prototypes; +using Robust.Shared.Random; + +namespace Content.Server.Speech.EntitySystems +{ + // TODO: Code in-game languages and make this a language + /// + /// Replaces any spoken sentences with a random word. + /// + public class ReplacementAccentSystem : EntitySystem + { + [Dependency] private readonly IPrototypeManager _proto = default!; + [Dependency] private readonly IRobustRandom _random = default!; + + public override void Initialize() + { + SubscribeLocalEvent(OnAccent); + } + + private void OnAccent(EntityUid uid, ReplacementAccentComponent component, AccentGetEvent args) + { + var words = _proto.Index(component.Accent).Words; + + args.Message = words.Length != 0 ? _random.Pick(words) : ""; + } + } +} diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml b/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml index aa26fc8e79..606a04942c 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/animals.yml @@ -370,6 +370,7 @@ - type: FireVisualizer sprite: Mobs/Effects/onfire.rsi normalState: Monkey_burning + - type: MonkeyAccent - type: entity name: mouse diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/pets.yml b/Resources/Prototypes/Entities/Mobs/NPCs/pets.yml index 43d6d94ba2..38ea01d948 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/pets.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/pets.yml @@ -33,6 +33,8 @@ normal: corgi crit: corgi_dead dead: corgi_dead + - type: ReplacementAccent + accent: dog - type: entity name: Ian @@ -85,6 +87,8 @@ normal: cat crit: cat_dead dead: cat_dead + - type: ReplacementAccent + accent: cat - type: entity name: calico cat diff --git a/Resources/Prototypes/accents.yml b/Resources/Prototypes/accents.yml new file mode 100644 index 0000000000..517225897a --- /dev/null +++ b/Resources/Prototypes/accents.yml @@ -0,0 +1,17 @@ +- type: accent + id: cat + words: + - Meow! + - Mow. + - Mrrrow! + - Hhsss! + - Brrow + +- type: accent + id: dog + words: + - Bark! + - Bork! + - Woof! + - Arf. + - Grrr.