Files
OldThink/Content.Shared/_White/Cult/Systems/CultistWordGeneratorManager.cs
Cinka f02cc9cb87
Some checks failed
Build & Test Map Renderer / build (ubuntu-latest) (push) Has been cancelled
Build & Test Debug / build (ubuntu-latest) (push) Has been cancelled
Check Merge Conflicts / Label (push) Has been cancelled
Test Packaging / Test Packaging (push) Has been cancelled
RGA schema validator / YAML RGA schema validator (push) Has been cancelled
Map file schema validator / YAML map schema validator (push) Has been cancelled
YAML Linter / YAML Linter (push) Has been cancelled
Build & Test Map Renderer / Build & Test Debug (push) Has been cancelled
Build & Test Debug / Build & Test Debug (push) Has been cancelled
Benchmarks / Run Benchmarks (push) Has been cancelled
Update Contrib and Patreons in credits / get_credits (push) Has been cancelled
Build & Publish Docfx / docfx (push) Has been cancelled
- fix: engine update fix
2026-02-01 14:47:44 +03:00

58 lines
1.4 KiB
C#

using System.Linq;
using System.Text;
using Robust.Shared.Random;
namespace Content.Shared._White.Cult.Systems;
/// <summary>
/// Words generator for whisper
/// </summary>
public sealed class CultistWordGeneratorManager
{
private const string Vowels = "aeiou";
private const string Consonants = "bcdfghjklmnpqrstvwxyz";
[Dependency] private readonly IRobustRandom _random = default!;
public string GenerateText(string text)
{
var content = text.Split(' ').Where(x => x.Length > 0).ToArray();
var wordsAmount = content.Length;
if (wordsAmount <= 0)
return "";
for (var i = 0; i < wordsAmount; i++)
{
content[i] = GenerateWord(content[i].Length);
}
return string.Join(" ", content);
}
private string GenerateWord(int length)
{
if (length <= 0)
throw new ArgumentException("Word length must be greater than zero.");
var word = new StringBuilder();
for (var i = 0; i < length; i++)
{
var isVowel = (i % 2 == 0); // Alternate between vowels and consonants
var randomChar = GetRandomChar(isVowel ? Vowels : Consonants);
word.Append(randomChar);
}
return word.ToString();
}
private char GetRandomChar(string characters)
{
var index = _random.Next(characters.Length);
return characters[index];
}
}