Files

62 lines
2.0 KiB
C#

using Yarn.Unity;
namespace NightclubArcadia.Dialogue
{
/// <summary>
/// Deterministically turns the player's real name into an unrelated club
/// alias. Same input name always yields the same alias (hash-seeded pick
/// from two word pools), but the alias carries no resemblance to the
/// input — it's a stage name, not a nickname derived from it.
///
/// Used from Yarn as a smart variable (see $player_alias in Common.yarn)
/// or directly: {alias_name($player_name)}
/// </summary>
public static class AliasNameGenerator
{
static readonly string[] FirstWords =
{
"Midnight", "Velvet", "Neon", "Crimson", "Static", "Amber",
"Obsidian", "Electric", "Hollow", "Silver", "Violet", "Iron",
"Phantom", "Copper", "Glass", "Ashen",
};
static readonly string[] SecondWords =
{
"Vex", "Wilde", "Sable", "Rook", "Marlowe", "Cross",
"Vane", "Thorn", "Rye", "Blaze", "Faye", "Quinn",
"Storm", "Reyes", "Lark", "Doyle",
};
[YarnFunction("alias_name")]
public static string AliasName(string realName)
{
if (string.IsNullOrEmpty(realName))
{
realName = "unknown";
}
var hash = Fnv1aHash(realName);
var first = FirstWords[hash % (uint)FirstWords.Length];
var second = SecondWords[(hash / (uint)FirstWords.Length) % (uint)SecondWords.Length];
return $"{first} {second}";
}
// FNV-1a: simple, stable across platforms and .NET versions (unlike
// string.GetHashCode, which is not guaranteed stable run-to-run).
static uint Fnv1aHash(string value)
{
const uint offsetBasis = 2166136261;
const uint prime = 16777619;
var hash = offsetBasis;
foreach (var c in value)
{
hash ^= c;
hash *= prime;
}
return hash;
}
}
}