From 920dafa6bda940cab065279e22d8e32e8e41b3df Mon Sep 17 00:00:00 2001 From: Ethan Moffat Date: Thu, 4 May 2023 15:08:43 -0700 Subject: [PATCH] Update algorithm for drunk text to be accurate to EO main --- EOLib/Domain/Chat/ChatProcessor.cs | 68 ++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/EOLib/Domain/Chat/ChatProcessor.cs b/EOLib/Domain/Chat/ChatProcessor.cs index e2f409788..c512c7e39 100644 --- a/EOLib/Domain/Chat/ChatProcessor.cs +++ b/EOLib/Domain/Chat/ChatProcessor.cs @@ -52,25 +52,69 @@ public string RemoveFirstCharacterIfNeeded(string chat, ChatType chatType, strin public string MakeDrunk(string input) { - // implementation from Phorophor::notepad (thanks Blo) - // https://discord.com/channels/723989119503696013/785190349026492437/791376941822246953 - - // todo: make this use the authentic algorithm here: https://discord.com/channels/723989119503696013/787685796055482368/945700924536553544 + // algorithm from: https://discord.com/channels/723989119503696013/787685796055482368/945700924536553544 var ret = new StringBuilder(); + //Pass 1: + //If E or A: 70 % chance to insert a j + //if U or O: 70 % chance to insert a w + //if i(lowercase only): 40 % chance to insert a u + //if not a space: 40 % chance to double the letter foreach (var c in input) { - var repeats = _random.Next(0, 8) < 6 ? 1 : 2; - ret.Append(c, repeats); + ret.Append(c); + + if (char.ToLower(c) == 'e' || char.ToLower(c) == 'a') + { + if (_random.Next(100) < 70) + ret.Append('j'); + } + else if (char.ToLower(c) == 'u' || char.ToLower(c) == 'o') + { + if (_random.Next(100) < 70) + ret.Append('w'); + } + else if (c == 'i') + { + if (_random.Next(100) < 40) + ret.Append('u'); + } - if ((c == 'a' || c == 'e') && _random.NextDouble() / 1.0 < 0.555) - ret.Append('j'); + if (c != ' ' && _random.Next(100) < 40) + { + ret.Append(c); + } + } - if ((c == 'u' || c == 'o') && _random.NextDouble() / 1.0 < 0.444) - ret.Append('w'); - if ((c == ' ') && _random.NextDouble() / 1.0 < 0.333) - ret.Append(" *hic*"); + //Pass 2: + //if vowel: 1 in 12 chance to replace with * + for (int i = 0; i < ret.Length; i++) + { + var c = char.ToLower(ret[i]); + + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') + { + if (_random.Next(12) == 6) + ret[i] = '*'; + } + } + + //Pass 3: + //if space, 30 % chance to insert "hic" + for (int i = 0; i < ret.Length; i++) + { + if (ret[i] == ' ' && _random.Next(100) < 30) + { + ret.Insert(i, "*hic*"); + } + } + + // If string length > 128: trim to 126 bytes and add ".." + if (ret.Length > 128) + { + ret = ret.Remove(126, ret.Length - 126); + ret.Append(".."); } return ret.ToString();