2022-10-15 17:45:47 -04:00
using Content.Shared.Humanoid.Prototypes ;
using Content.Shared.Dataset ;
using Robust.Shared.Random ;
using Robust.Shared.Prototypes ;
using Robust.Shared.Enums ;
namespace Content.Shared.Humanoid
{
/// <summary>
/// Figure out how to name a humanoid with these extensions.
/// </summary>
public sealed class NamingSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default ! ;
[Dependency] private readonly IPrototypeManager _prototypeManager = default ! ;
public string GetName ( string species , Gender ? gender = null )
{
// 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" ) ;
2023-06-27 23:56:52 +10:00
Log . Warning ( $"Unable to find species {species} for name, falling back to Human" ) ;
2022-10-15 17:45:47 -04:00
}
switch ( speciesProto . Naming )
{
2024-02-14 04:08:45 +01:00
case SpeciesNaming . First :
return Loc . GetString ( "namepreset-first" ,
( "first" , GetFirstName ( speciesProto , gender ) ) ) ;
2022-11-08 15:26:59 -05:00
case SpeciesNaming . TheFirstofLast :
return Loc . GetString ( "namepreset-thefirstoflast" ,
( "first" , GetFirstName ( speciesProto , gender ) ) , ( "last" , GetLastName ( speciesProto ) ) ) ;
2022-10-15 17:45:47 -04:00
case SpeciesNaming . FirstDashFirst :
2022-11-08 15:26:59 -05:00
return Loc . GetString ( "namepreset-firstdashfirst" ,
( "first1" , GetFirstName ( speciesProto , gender ) ) , ( "first2" , GetFirstName ( speciesProto , gender ) ) ) ;
2022-10-15 17:45:47 -04:00
case SpeciesNaming . FirstLast :
default :
2022-11-08 15:26:59 -05:00
return Loc . GetString ( "namepreset-firstlast" ,
( "first" , GetFirstName ( speciesProto , gender ) ) , ( "last" , GetLastName ( speciesProto ) ) ) ;
2022-10-15 17:45:47 -04:00
}
}
public string GetFirstName ( SpeciesPrototype speciesProto , Gender ? gender = null )
{
switch ( gender )
{
case Gender . Male :
2024-06-03 23:50:05 +03:00
return Loc . GetString ( _random . Pick ( _prototypeManager . Index < LocalizedDatasetPrototype > ( speciesProto . MaleFirstNames ) . Values ) ) ; //CrystallPunk name localization
2022-10-15 17:45:47 -04:00
case Gender . Female :
2024-06-03 23:50:05 +03:00
return Loc . GetString ( _random . Pick ( _prototypeManager . Index < LocalizedDatasetPrototype > ( speciesProto . FemaleFirstNames ) . Values ) ) ; //CrystallPunk name localization
2022-10-15 17:45:47 -04:00
default :
if ( _random . Prob ( 0.5f ) )
2024-06-03 23:50:05 +03:00
return Loc . GetString ( _random . Pick ( _prototypeManager . Index < LocalizedDatasetPrototype > ( speciesProto . MaleFirstNames ) . Values ) ) ; //CrystallPunk name localization
2022-10-15 17:45:47 -04:00
else
2024-06-03 23:50:05 +03:00
return Loc . GetString ( _random . Pick ( _prototypeManager . Index < LocalizedDatasetPrototype > ( speciesProto . FemaleFirstNames ) . Values ) ) ; //CrystallPunk name localization
2022-10-15 17:45:47 -04:00
}
}
public string GetLastName ( SpeciesPrototype speciesProto )
{
2024-06-03 23:50:05 +03:00
return Loc . GetString ( _random . Pick ( _prototypeManager . Index < LocalizedDatasetPrototype > ( speciesProto . LastNames ) . Values ) ) ; //CrystallPunk name localization
2022-10-15 17:45:47 -04:00
}
}
}