2022-05-13 00:59:03 -07:00
|
|
|
|
using Content.Shared.Dataset;
|
2022-05-12 20:43:15 -03:00
|
|
|
|
using Content.Shared.Species;
|
2021-02-17 10:46:44 +01:00
|
|
|
|
using Robust.Shared.Prototypes;
|
2022-05-12 20:43:15 -03:00
|
|
|
|
using Robust.Shared.Random;
|
2021-02-17 10:46:44 +01:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Shared.CharacterAppearance
|
2019-12-22 13:47:34 +01:00
|
|
|
|
{
|
2022-05-12 20:43:15 -03:00
|
|
|
|
public enum Sex : byte
|
2019-12-22 13:47:34 +01:00
|
|
|
|
{
|
|
|
|
|
|
Male,
|
2020-12-24 13:42:40 +00:00
|
|
|
|
Female
|
2019-12-22 13:47:34 +01:00
|
|
|
|
}
|
2021-02-17 10:46:44 +01:00
|
|
|
|
|
|
|
|
|
|
public static class SexExtensions
|
|
|
|
|
|
{
|
2022-05-12 20:43:15 -03:00
|
|
|
|
public static string GetName(this Sex sex, string species, IPrototypeManager? prototypeManager = null, IRobustRandom? random = null)
|
2021-02-17 10:46:44 +01:00
|
|
|
|
{
|
2022-05-12 20:43:15 -03:00
|
|
|
|
IoCManager.Resolve(ref prototypeManager);
|
|
|
|
|
|
IoCManager.Resolve(ref random);
|
|
|
|
|
|
|
|
|
|
|
|
// if they have an old species or whatever just fall back to human I guess?
|
|
|
|
|
|
// Some downstream is probably gonna have this eventually but then they can deal with fallbacks.
|
|
|
|
|
|
if (!prototypeManager.TryIndex(species, out SpeciesPrototype? speciesProto))
|
|
|
|
|
|
{
|
|
|
|
|
|
speciesProto = prototypeManager.Index<SpeciesPrototype>("Human");
|
|
|
|
|
|
Logger.Warning($"Unable to find species {species} for name, falling back to Human");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch (speciesProto.Naming)
|
|
|
|
|
|
{
|
|
|
|
|
|
case SpeciesNaming.FirstDashFirst:
|
|
|
|
|
|
return $"{GetFirstName(sex, speciesProto, prototypeManager, random)}-{GetFirstName(sex, speciesProto, prototypeManager, random)}";
|
|
|
|
|
|
case SpeciesNaming.FirstLast:
|
|
|
|
|
|
default:
|
|
|
|
|
|
return $"{GetFirstName(sex, speciesProto, prototypeManager, random)} {GetLastName(sex, speciesProto, prototypeManager, random)}";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetFirstName(this Sex sex, SpeciesPrototype speciesProto, IPrototypeManager? protoManager = null, IRobustRandom? random = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
IoCManager.Resolve(ref protoManager);
|
|
|
|
|
|
IoCManager.Resolve(ref random);
|
2021-02-17 10:46:44 +01:00
|
|
|
|
|
|
|
|
|
|
switch (sex)
|
|
|
|
|
|
{
|
|
|
|
|
|
case Sex.Male:
|
2022-05-12 20:43:15 -03:00
|
|
|
|
return random.Pick(protoManager.Index<DatasetPrototype>(speciesProto.MaleFirstNames).Values);
|
2021-02-17 10:46:44 +01:00
|
|
|
|
case Sex.Female:
|
2022-05-12 20:43:15 -03:00
|
|
|
|
return random.Pick(protoManager.Index<DatasetPrototype>(speciesProto.FemaleFirstNames).Values);
|
2021-02-17 10:46:44 +01:00
|
|
|
|
default:
|
2022-05-12 20:43:15 -03:00
|
|
|
|
throw new ArgumentOutOfRangeException();
|
2021-02-17 10:46:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-12 20:43:15 -03:00
|
|
|
|
|
|
|
|
|
|
public static string GetLastName(this Sex sex, SpeciesPrototype speciesProto, IPrototypeManager? protoManager = null, IRobustRandom? random = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
IoCManager.Resolve(ref protoManager);
|
|
|
|
|
|
IoCManager.Resolve(ref random);
|
|
|
|
|
|
return random.Pick(protoManager.Index<DatasetPrototype>(speciesProto.LastNames).Values);
|
|
|
|
|
|
}
|
2021-02-17 10:46:44 +01:00
|
|
|
|
}
|
2019-12-22 13:47:34 +01:00
|
|
|
|
}
|