# Conflicts: # .github/CODEOWNERS # .github/ISSUE_TEMPLATE/config.yml # .github/ISSUE_TEMPLATE/issue_report.md # Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs # Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml # Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml # Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml.cs # Content.Client/Weapons/Ranged/Systems/GunSystem.cs # Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs # Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs # Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs # Content.Server/Arcade/SpaceVillainGame/SpaceVillainArcadeComponent.cs # Content.Server/Atmos/EntitySystems/FlammableSystem.cs # Content.Server/Chat/Systems/ChatSystem.cs # Content.Server/Destructible/Thresholds/DamageThreshold.cs # Content.Server/Entry/EntryPoint.cs # Content.Server/Fluids/EntitySystems/PuddleSystem.cs # Content.Server/GuideGenerator/ReagentEntry.cs # Content.Server/IoC/ServerContentIoC.cs # Content.Server/Medical/HealthAnalyzerSystem.cs # Content.Server/Medical/VomitSystem.cs # Content.Server/Radio/EntitySystems/HeadsetSystem.cs # Content.Server/Revenant/EntitySystems/RevenantSystem.cs # Content.Server/Weapons/Ranged/Systems/GunSystem.cs # Content.Shared/Armor/SharedArmorSystem.cs # Content.Shared/Bed/Sleep/SleepingSystem.cs # Content.Shared/Cabinet/ItemCabinetSystem.cs # Content.Shared/Chat/SharedChatSystem.Emote.cs # Content.Shared/Chat/SharedChatSystem.cs # Content.Shared/Clothing/EntitySystems/MaskSystem.cs # Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs # Content.Shared/Damage/Systems/DamageableSystem.cs # Content.Shared/EntityEffects/Effects/StatusEffects/GenericStatusEffect.cs # Content.Shared/EntityEffects/Effects/Transform/ExplosionEntityEffect.cs # Content.Shared/Humanoid/HumanoidCharacterAppearance.cs # Content.Shared/IoC/SharedContentIoC.cs # Content.Shared/Lock/LockSystem.cs # Content.Shared/Ninja/Components/NinjaSuitComponent.cs # Content.Shared/Preferences/HumanoidCharacterProfile.cs # Content.Shared/Revenant/Components/RevenantComponent.cs # Content.Shared/Silicons/StationAi/SharedStationAiSystem.Airlock.cs # Content.Shared/Trigger/Systems/TriggerSystem.Condition.cs # Content.Shared/VendingMachines/SharedVendingMachineSystem.cs # Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs # Content.Shared/Weapons/Ranged/HitscanPrototype.cs # Content.Shared/Xenoarchaeology/Artifact/XAT/BaseQueryUpdateXATSystem.cs # README.md # Resources/Audio/Weapons/attributions.yml # Resources/Locale/en-US/_strings/ghost/make-ghost-gui.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/conditions.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/effects.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/healthchange.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/statuseffects.ftl # Resources/Locale/en-US/_strings/job/job-description.ftl # Resources/Locale/en-US/_strings/medical/components/crew-monitoring-component.ftl # Resources/Locale/en-US/_strings/npc/hugbot.ftl # Resources/Locale/en-US/_strings/npc/npc-debug.ftl # Resources/Locale/en-US/_strings/speech/speech-triggers.ftl # Resources/Locale/en-US/_strings/ui/stat-values.ftl # Resources/Locale/en-US/guidebook/chemistry/conditions.ftl # Resources/Locale/en-US/guidebook/chemistry/effects.ftl # Resources/Locale/en-US/guidebook/chemistry/healthchange.ftl # Resources/Locale/en-US/guidebook/entity-effects/conditions.ftl # Resources/Locale/en-US/guidebook/entity-effects/effects.ftl # Resources/Locale/en-US/guidebook/entity-effects/healthchange.ftl # Resources/Maps/Shuttles/cargo_relic.yml # Resources/Maps/_Sunrise/Station/bagel.yml # Resources/Maps/_Sunrise/Station/barratry.yml # Resources/Maps/_Sunrise/Station/fland.yml # Resources/Maps/_Sunrise/Station/marathon.yml # Resources/Maps/_Sunrise/Station/oasis.yml # Resources/Maps/_Sunrise/Station/packed.yml # Resources/Maps/_Sunrise/Station/plasma.yml # Resources/Maps/_Sunrise/Station/relic.yml # Resources/Maps/_Sunrise/event/clon_mine.yml # Resources/Maps/_Sunrise/event/void.yml # Resources/Prototypes/Body/Prototypes/vox.yml # Resources/Prototypes/Catalog/Fills/Boxes/emergency.yml # Resources/Prototypes/Catalog/Fills/Crates/fun.yml # Resources/Prototypes/Catalog/Fills/Lockers/heads.yml # Resources/Prototypes/Catalog/Fills/Lockers/security.yml # Resources/Prototypes/Entities/Clothing/Belt/belts.yml # Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml # Resources/Prototypes/Entities/Mobs/NPCs/silicon.yml # Resources/Prototypes/Entities/Mobs/Species/skeleton.yml # Resources/Prototypes/Entities/Objects/Devices/Electronics/base_electronics.yml # Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/pistol.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/pistol.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/hitscan.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/access.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/airlocks.yml # Resources/Prototypes/Entities/Structures/Doors/MaterialDoors/material_doors.yml # Resources/Prototypes/Entities/Structures/Machines/lathe.yml # Resources/Prototypes/Entities/Structures/Specific/Atmospherics/sensor.yml # Resources/Prototypes/Loadouts/Jobs/Engineering/station_engineer.yml # Resources/Prototypes/Loadouts/Jobs/Science/scientist.yml # Resources/Prototypes/Loadouts/Jobs/Security/security_officer.yml # Resources/Prototypes/Loadouts/Miscellaneous/glasses.yml # Resources/Prototypes/Loadouts/loadout_groups.yml # Resources/Prototypes/Objectives/objectiveGroups.yml # Resources/Prototypes/Reagents/Consumable/Drink/alcohol.yml # Resources/Prototypes/Reagents/medicine.yml # Resources/Prototypes/Reagents/narcotics.yml # Resources/Prototypes/Reagents/toxins.yml # Resources/Prototypes/Recipes/Lathes/Packs/biogen.yml # Resources/Prototypes/Recipes/Lathes/Packs/security.yml # Resources/Prototypes/Recipes/Lathes/biogen.yml # Resources/Prototypes/Roles/Antags/nukeops.yml # Resources/Prototypes/Roles/Antags/revolutionary.yml # Resources/Prototypes/Roles/Antags/thief.yml # Resources/Prototypes/Roles/Antags/traitor.yml # Resources/Prototypes/Roles/Antags/wizard.yml # Resources/Prototypes/Roles/Antags/zombie.yml # Resources/Prototypes/Roles/Jobs/Cargo/salvage_specialist.yml # Resources/Prototypes/Roles/Jobs/Civilian/bartender.yml # Resources/Prototypes/Roles/Jobs/Civilian/chef.yml # Resources/Prototypes/Roles/Jobs/Civilian/mime.yml # Resources/Prototypes/Roles/Jobs/Engineering/atmospheric_technician.yml # Resources/Prototypes/Roles/Jobs/Engineering/station_engineer.yml # Resources/Prototypes/Roles/Jobs/Engineering/technical_assistant.yml # Resources/Prototypes/Roles/Jobs/Medical/chemist.yml # Resources/Prototypes/Roles/Jobs/Medical/medical_doctor.yml # Resources/Prototypes/Roles/Jobs/Medical/medical_intern.yml # Resources/Prototypes/Roles/Jobs/Medical/paramedic.yml # Resources/Prototypes/Roles/Jobs/Science/borg.yml # Resources/Prototypes/Roles/Jobs/Science/research_assistant.yml # Resources/Prototypes/Roles/Jobs/Science/scientist.yml # Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml # Resources/Prototypes/Roles/Jobs/Security/security_officer.yml # Resources/Prototypes/Roles/Jobs/Security/warden.yml # Resources/Prototypes/Stacks/Materials/crystals.yml # Resources/Prototypes/Stacks/floor_tile_stacks.yml # Resources/Prototypes/tags.yml # Resources/ServerInfo/Guidebook/Science/ArtifactReports.xml # Resources/ServerInfo/Guidebook/Science/Xenoarchaeology.xml # Resources/Textures/Clothing/Hands/Gloves/Color/black.rsi/equipped-HAND.png # Resources/Textures/Clothing/Hands/Gloves/Color/black.rsi/meta.json # Resources/Textures/Clothing/Head/Hardsuits/mime.rsi/meta.json # Resources/Textures/Effects/speech.rsi/moth3.png # Resources/Textures/Interface/Misc/job_icons.rsi/meta.json # Resources/Textures/Structures/Machines/microwave.rsi/meta.json # Resources/Textures/Structures/Machines/microwave.rsi/mw.png # Resources/Textures/Structures/Machines/microwave.rsi/mw0.png # Resources/Textures/Structures/Machines/microwave.rsi/mw_running_unlit.png # Resources/Textures/Structures/Machines/microwave.rsi/mw_unlit.png # Resources/Textures/Structures/Machines/microwave.rsi/mwb.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloody.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloody0.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloody1.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloodyo.png # Resources/Textures/Structures/Machines/microwave.rsi/mwo.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/meta.json # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw0.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw_running_unlit.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw_unlit.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mwb.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mwo.png # Resources/migration.yml # RobustToolbox
851 lines
30 KiB
C#
851 lines
30 KiB
C#
using System.Linq;
|
||
using System.Text.RegularExpressions;
|
||
using Content.Shared._Sunrise.SunriseCCVars;
|
||
using Content.Shared.CCVar;
|
||
using Content.Shared._Sunrise.TTS;
|
||
using Content.Shared.GameTicking;
|
||
using Content.Shared.Humanoid;
|
||
using Content.Shared.Humanoid.Prototypes;
|
||
using Content.Shared.Preferences.Loadouts;
|
||
using Content.Shared.Roles;
|
||
using Content.Shared.Traits;
|
||
using Content.Sunrise.Interfaces.Shared;
|
||
using Robust.Shared.Collections;
|
||
using Robust.Shared.Configuration;
|
||
using Robust.Shared.Enums;
|
||
using Robust.Shared.Player;
|
||
using Robust.Shared.Prototypes;
|
||
using Robust.Shared.Random;
|
||
using Robust.Shared.Serialization;
|
||
using Robust.Shared.Utility;
|
||
|
||
namespace Content.Shared.Preferences
|
||
{
|
||
/// <summary>
|
||
/// Character profile. Looks immutable, but uses non-immutable semantics internally for serialization/code sanity purposes.
|
||
/// </summary>
|
||
[DataDefinition]
|
||
[Serializable, NetSerializable]
|
||
public sealed partial class HumanoidCharacterProfile : ICharacterProfile
|
||
{
|
||
private static readonly Regex RestrictedNameRegex = new("[^А-Яа-яA-Za-zёЁ0-9, ,\\-,'.]"); // Sunrise-edit
|
||
private static readonly Regex ICNameCaseRegex = new(@"^(?<word>\w)|\b(?<word>\w)(?=\w*$)");
|
||
|
||
/// <summary>
|
||
/// Job preferences for initial spawn.
|
||
/// </summary>
|
||
[DataField]
|
||
private Dictionary<ProtoId<JobPrototype>, JobPriority> _jobPriorities = new()
|
||
{
|
||
{
|
||
SharedGameTicker.FallbackOverflowJob, JobPriority.High
|
||
}
|
||
};
|
||
|
||
/// <summary>
|
||
/// Antags we have opted in to.
|
||
/// </summary>
|
||
[DataField]
|
||
private HashSet<ProtoId<AntagPrototype>> _antagPreferences = new();
|
||
|
||
/// <summary>
|
||
/// Enabled traits.
|
||
/// </summary>
|
||
[DataField]
|
||
private HashSet<ProtoId<TraitPrototype>> _traitPreferences = new();
|
||
|
||
/// <summary>
|
||
/// <see cref="_loadouts"/>
|
||
/// </summary>
|
||
public IReadOnlyDictionary<string, RoleLoadout> Loadouts => _loadouts;
|
||
|
||
[DataField]
|
||
private Dictionary<string, RoleLoadout> _loadouts = new();
|
||
|
||
[DataField]
|
||
public string Name { get; set; } = "John Doe";
|
||
|
||
/// <summary>
|
||
/// Detailed text that can appear for the character if <see cref="CCVars.FlavorText"/> is enabled.
|
||
/// </summary>
|
||
[DataField]
|
||
public string FlavorText { get; set; } = string.Empty;
|
||
|
||
/// <summary>
|
||
/// Associated <see cref="SpeciesPrototype"/> for this profile.
|
||
/// </summary>
|
||
[DataField]
|
||
public ProtoId<SpeciesPrototype> Species { get; set; } = SharedHumanoidAppearanceSystem.DefaultSpecies;
|
||
|
||
[DataField]
|
||
public string Voice { get; set; } = SharedHumanoidAppearanceSystem.DefaultVoice;
|
||
|
||
[DataField]
|
||
public int Age { get; set; } = 18;
|
||
|
||
[DataField]
|
||
public Sex Sex { get; private set; } = Sex.Male;
|
||
|
||
[DataField]
|
||
public Gender Gender { get; private set; } = Gender.Male;
|
||
|
||
[DataField]
|
||
public string BodyType { get; set; } = SharedHumanoidAppearanceSystem.DefaultBodyType;
|
||
|
||
/// <summary>
|
||
/// <see cref="Appearance"/>
|
||
/// </summary>
|
||
public ICharacterAppearance CharacterAppearance => Appearance;
|
||
|
||
/// <summary>
|
||
/// Stores markings, eye colors, etc for the profile.
|
||
/// </summary>
|
||
[DataField]
|
||
public HumanoidCharacterAppearance Appearance { get; set; } = new();
|
||
|
||
/// <summary>
|
||
/// When spawning into a round what's the preferred spot to spawn.
|
||
/// </summary>
|
||
[DataField]
|
||
public SpawnPriorityPreference SpawnPriority { get; private set; } = SpawnPriorityPreference.None;
|
||
|
||
/// <summary>
|
||
/// <see cref="_jobPriorities"/>
|
||
/// </summary>
|
||
public IReadOnlyDictionary<ProtoId<JobPrototype>, JobPriority> JobPriorities => _jobPriorities;
|
||
|
||
/// <summary>
|
||
/// <see cref="_antagPreferences"/>
|
||
/// </summary>
|
||
public IReadOnlySet<ProtoId<AntagPrototype>> AntagPreferences => _antagPreferences;
|
||
|
||
/// <summary>
|
||
/// <see cref="_traitPreferences"/>
|
||
/// </summary>
|
||
public IReadOnlySet<ProtoId<TraitPrototype>> TraitPreferences => _traitPreferences;
|
||
|
||
/// <summary>
|
||
/// If we're unable to get one of our preferred jobs do we spawn as a fallback job or do we stay in lobby.
|
||
/// </summary>
|
||
[DataField]
|
||
public PreferenceUnavailableMode PreferenceUnavailable { get; private set; } =
|
||
PreferenceUnavailableMode.SpawnAsOverflow;
|
||
|
||
public HumanoidCharacterProfile(
|
||
string name,
|
||
string flavortext,
|
||
string species,
|
||
string voice, // Sunrise-TTS
|
||
string bodyType,
|
||
int age,
|
||
Sex sex,
|
||
Gender gender,
|
||
HumanoidCharacterAppearance appearance,
|
||
SpawnPriorityPreference spawnPriority,
|
||
Dictionary<ProtoId<JobPrototype>, JobPriority> jobPriorities,
|
||
PreferenceUnavailableMode preferenceUnavailable,
|
||
HashSet<ProtoId<AntagPrototype>> antagPreferences,
|
||
HashSet<ProtoId<TraitPrototype>> traitPreferences,
|
||
Dictionary<string, RoleLoadout> loadouts)
|
||
{
|
||
Name = name;
|
||
FlavorText = flavortext;
|
||
Species = species;
|
||
Voice = voice; // Sunrise-TTS
|
||
BodyType = bodyType;
|
||
Age = age;
|
||
Sex = sex;
|
||
Gender = gender;
|
||
Appearance = appearance;
|
||
SpawnPriority = spawnPriority;
|
||
_jobPriorities = jobPriorities;
|
||
PreferenceUnavailable = preferenceUnavailable;
|
||
_antagPreferences = antagPreferences;
|
||
_traitPreferences = traitPreferences;
|
||
_loadouts = loadouts;
|
||
|
||
var hasHighPrority = false;
|
||
foreach (var (key, value) in _jobPriorities)
|
||
{
|
||
if (value == JobPriority.Never)
|
||
_jobPriorities.Remove(key);
|
||
else if (value != JobPriority.High)
|
||
continue;
|
||
|
||
if (hasHighPrority)
|
||
_jobPriorities[key] = JobPriority.Medium;
|
||
|
||
hasHighPrority = true;
|
||
}
|
||
}
|
||
|
||
/// <summary>Copy constructor</summary>
|
||
public HumanoidCharacterProfile(HumanoidCharacterProfile other)
|
||
: this(other.Name,
|
||
other.FlavorText,
|
||
other.Species,
|
||
other.Voice,
|
||
other.BodyType,
|
||
other.Age,
|
||
other.Sex,
|
||
other.Gender,
|
||
other.Appearance.Clone(),
|
||
other.SpawnPriority,
|
||
new Dictionary<ProtoId<JobPrototype>, JobPriority>(other.JobPriorities),
|
||
other.PreferenceUnavailable,
|
||
new HashSet<ProtoId<AntagPrototype>>(other.AntagPreferences),
|
||
new HashSet<ProtoId<TraitPrototype>>(other.TraitPreferences),
|
||
new Dictionary<string, RoleLoadout>(other.Loadouts))
|
||
{
|
||
}
|
||
|
||
/// <summary>
|
||
/// Get the default humanoid character profile, using internal constant values.
|
||
/// Defaults to <see cref="SharedHumanoidAppearanceSystem.DefaultSpecies"/> for the species.
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public HumanoidCharacterProfile()
|
||
{
|
||
}
|
||
|
||
/// <summary>
|
||
/// Return a default character profile, based on species.
|
||
/// </summary>
|
||
/// <param name="species">The species to use in this default profile. The default species is <see cref="SharedHumanoidAppearanceSystem.DefaultSpecies"/>.</param>
|
||
/// <returns>Humanoid character profile with default settings.</returns>
|
||
public static HumanoidCharacterProfile DefaultWithSpecies(string? species = null)
|
||
{
|
||
species ??= SharedHumanoidAppearanceSystem.DefaultSpecies;
|
||
|
||
return new()
|
||
{
|
||
Species = species,
|
||
Appearance = HumanoidCharacterAppearance.DefaultWithSpecies(species),
|
||
};
|
||
}
|
||
|
||
// TODO: This should eventually not be a visual change only.
|
||
public static HumanoidCharacterProfile Random(HashSet<string>? ignoredSpecies = null)
|
||
{
|
||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||
var random = IoCManager.Resolve<IRobustRandom>();
|
||
|
||
var species = random.Pick(prototypeManager
|
||
.EnumeratePrototypes<SpeciesPrototype>()
|
||
.Where(x => (ignoredSpecies == null ? x.RoundStart : x.RoundStart && !ignoredSpecies.Contains(x.ID))
|
||
&& !x.SponsorOnly)
|
||
.ToArray()
|
||
).ID;
|
||
|
||
return RandomWithSpecies(species);
|
||
}
|
||
|
||
public static HumanoidCharacterProfile RandomWithSpecies(string? species = null)
|
||
{
|
||
species ??= SharedHumanoidAppearanceSystem.DefaultSpecies;
|
||
|
||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||
var random = IoCManager.Resolve<IRobustRandom>();
|
||
|
||
var sex = Sex.Unsexed;
|
||
var age = 18;
|
||
var bodyType = SharedHumanoidAppearanceSystem.DefaultBodyType;
|
||
if (prototypeManager.TryIndex<SpeciesPrototype>(species, out var speciesPrototype))
|
||
{
|
||
sex = random.Pick(speciesPrototype.Sexes);
|
||
age = random.Next(speciesPrototype.MinAge, speciesPrototype.OldAge); // people don't look and keep making 119 year old characters with zero rp, cap it at middle aged
|
||
bodyType = speciesPrototype.BodyTypes.First();
|
||
}
|
||
|
||
// Sunrise-TTS-Start
|
||
var voiceId = random.Pick(prototypeManager
|
||
.EnumeratePrototypes<TTSVoicePrototype>()
|
||
.Where(o => CanHaveVoice(o, sex) && !o.SponsorOnly)
|
||
.ToArray()
|
||
).ID;
|
||
// Sunrise-TTS-End
|
||
|
||
var gender = Gender.Epicene;
|
||
|
||
switch (sex)
|
||
{
|
||
case Sex.Male:
|
||
gender = Gender.Male;
|
||
break;
|
||
case Sex.Female:
|
||
gender = Gender.Female;
|
||
break;
|
||
}
|
||
|
||
var name = GetName(species, gender);
|
||
|
||
return new HumanoidCharacterProfile()
|
||
{
|
||
Name = name,
|
||
Sex = sex,
|
||
Age = age,
|
||
Gender = gender,
|
||
Species = species,
|
||
Voice = voiceId, // Sunrise-TTS
|
||
BodyType = bodyType,
|
||
Appearance = HumanoidCharacterAppearance.Random(species, sex),
|
||
};
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithName(string name)
|
||
{
|
||
return new(this) { Name = name };
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithFlavorText(string flavorText)
|
||
{
|
||
return new(this) { FlavorText = flavorText };
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithAge(int age)
|
||
{
|
||
return new(this) { Age = age };
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithSex(Sex sex)
|
||
{
|
||
return new(this) { Sex = sex };
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithGender(Gender gender)
|
||
{
|
||
return new(this) { Gender = gender };
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithSpecies(string species)
|
||
{
|
||
return new(this) { Species = species };
|
||
}
|
||
|
||
// Sunrise-TTS-Start
|
||
public HumanoidCharacterProfile WithVoice(string voice)
|
||
{
|
||
return new(this) { Voice = voice };
|
||
}
|
||
// Sunrise-TTS-End
|
||
|
||
public HumanoidCharacterProfile WithBodyType(string bodyType)
|
||
{
|
||
return new HumanoidCharacterProfile(this) { BodyType = bodyType };
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithCharacterAppearance(HumanoidCharacterAppearance appearance)
|
||
{
|
||
return new(this) { Appearance = appearance };
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithSpawnPriorityPreference(SpawnPriorityPreference spawnPriority)
|
||
{
|
||
return new(this) { SpawnPriority = spawnPriority };
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithJobPriorities(IEnumerable<KeyValuePair<ProtoId<JobPrototype>, JobPriority>> jobPriorities)
|
||
{
|
||
var dictionary = new Dictionary<ProtoId<JobPrototype>, JobPriority>(jobPriorities);
|
||
var hasHighPrority = false;
|
||
|
||
foreach (var (key, value) in dictionary)
|
||
{
|
||
if (value == JobPriority.Never)
|
||
dictionary.Remove(key);
|
||
else if (value != JobPriority.High)
|
||
continue;
|
||
|
||
if (hasHighPrority)
|
||
dictionary[key] = JobPriority.Medium;
|
||
|
||
hasHighPrority = true;
|
||
}
|
||
|
||
return new(this)
|
||
{
|
||
_jobPriorities = dictionary
|
||
};
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithJobPriority(ProtoId<JobPrototype> jobId, JobPriority priority)
|
||
{
|
||
var dictionary = new Dictionary<ProtoId<JobPrototype>, JobPriority>(_jobPriorities);
|
||
if (priority == JobPriority.Never)
|
||
{
|
||
dictionary.Remove(jobId);
|
||
}
|
||
else if (priority == JobPriority.High)
|
||
{
|
||
// There can only ever be one high priority job.
|
||
foreach (var (job, value) in dictionary)
|
||
{
|
||
if (value == JobPriority.High)
|
||
dictionary[job] = JobPriority.Medium;
|
||
}
|
||
|
||
dictionary[jobId] = priority;
|
||
}
|
||
else
|
||
{
|
||
dictionary[jobId] = priority;
|
||
}
|
||
|
||
return new(this)
|
||
{
|
||
_jobPriorities = dictionary,
|
||
};
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithPreferenceUnavailable(PreferenceUnavailableMode mode)
|
||
{
|
||
return new(this) { PreferenceUnavailable = mode };
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithAntagPreferences(IEnumerable<ProtoId<AntagPrototype>> antagPreferences)
|
||
{
|
||
return new(this)
|
||
{
|
||
_antagPreferences = new (antagPreferences),
|
||
};
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithAntagPreference(ProtoId<AntagPrototype> antagId, bool pref)
|
||
{
|
||
var list = new HashSet<ProtoId<AntagPrototype>>(_antagPreferences);
|
||
if (pref)
|
||
{
|
||
list.Add(antagId);
|
||
}
|
||
else
|
||
{
|
||
list.Remove(antagId);
|
||
}
|
||
|
||
return new(this)
|
||
{
|
||
_antagPreferences = list,
|
||
};
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithTraitPreference(ProtoId<TraitPrototype> traitId, IPrototypeManager protoManager)
|
||
{
|
||
// null category is assumed to be default.
|
||
if (!protoManager.TryIndex(traitId, out var traitProto))
|
||
return new(this);
|
||
|
||
var category = traitProto.Category;
|
||
|
||
// Category not found so dump it.
|
||
TraitCategoryPrototype? traitCategory = null;
|
||
|
||
if (category != null && !protoManager.Resolve(category, out traitCategory))
|
||
return new(this);
|
||
|
||
var list = new HashSet<ProtoId<TraitPrototype>>(_traitPreferences) { traitId };
|
||
|
||
if (traitCategory == null || traitCategory.MaxTraitPoints < 0)
|
||
{
|
||
return new(this)
|
||
{
|
||
_traitPreferences = list,
|
||
};
|
||
}
|
||
|
||
var count = 0;
|
||
foreach (var trait in list)
|
||
{
|
||
// If trait not found or another category don't count its points.
|
||
if (!protoManager.TryIndex<TraitPrototype>(trait, out var otherProto) ||
|
||
otherProto.Category != traitCategory)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
count += otherProto.Cost;
|
||
}
|
||
|
||
if (count > traitCategory.MaxTraitPoints && traitProto.Cost != 0)
|
||
{
|
||
return new(this);
|
||
}
|
||
|
||
return new(this)
|
||
{
|
||
_traitPreferences = list,
|
||
};
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithoutTraitPreference(ProtoId<TraitPrototype> traitId, IPrototypeManager protoManager)
|
||
{
|
||
var list = new HashSet<ProtoId<TraitPrototype>>(_traitPreferences);
|
||
list.Remove(traitId);
|
||
|
||
return new(this)
|
||
{
|
||
_traitPreferences = list,
|
||
};
|
||
}
|
||
|
||
public string Summary =>
|
||
Loc.GetString(
|
||
"humanoid-character-profile-summary",
|
||
("name", Name),
|
||
("gender", Gender.ToString().ToLowerInvariant()),
|
||
("age", Age)
|
||
);
|
||
|
||
public bool MemberwiseEquals(ICharacterProfile maybeOther)
|
||
{
|
||
if (maybeOther is not HumanoidCharacterProfile other) return false;
|
||
if (Name != other.Name) return false;
|
||
if (Age != other.Age) return false;
|
||
if (Sex != other.Sex) return false;
|
||
if (Gender != other.Gender) return false;
|
||
if (Species != other.Species) return false;
|
||
if (BodyType != other.BodyType) return false;
|
||
if (PreferenceUnavailable != other.PreferenceUnavailable) return false;
|
||
if (SpawnPriority != other.SpawnPriority) return false;
|
||
if (!_jobPriorities.SequenceEqual(other._jobPriorities)) return false;
|
||
if (!_antagPreferences.SequenceEqual(other._antagPreferences)) return false;
|
||
if (!_traitPreferences.SequenceEqual(other._traitPreferences)) return false;
|
||
if (!Loadouts.SequenceEqual(other.Loadouts)) return false;
|
||
if (FlavorText != other.FlavorText) return false;
|
||
return Appearance.MemberwiseEquals(other.Appearance);
|
||
}
|
||
|
||
public void EnsureValid(ICommonSession session, IDependencyCollection collection, string[] sponsorPrototypes)
|
||
{
|
||
var configManager = collection.Resolve<IConfigurationManager>();
|
||
var prototypeManager = collection.Resolve<IPrototypeManager>();
|
||
|
||
if (!prototypeManager.TryIndex(Species, out var speciesPrototype) || speciesPrototype.RoundStart == false)
|
||
{
|
||
Species = SharedHumanoidAppearanceSystem.DefaultSpecies;
|
||
speciesPrototype = prototypeManager.Index(Species);
|
||
}
|
||
|
||
// Sunrise-Sponsors-Start: Reset to human if player not sponsor
|
||
if (speciesPrototype.SponsorOnly && !sponsorPrototypes.Contains(Species.Id))
|
||
{
|
||
Species = SharedHumanoidAppearanceSystem.DefaultSpecies;
|
||
speciesPrototype = prototypeManager.Index<SpeciesPrototype>(Species);
|
||
}
|
||
// Sunrise-Sponsors-End
|
||
|
||
var sex = Sex switch
|
||
{
|
||
Sex.Male => Sex.Male,
|
||
Sex.Female => Sex.Female,
|
||
Sex.Unsexed => Sex.Unsexed,
|
||
_ => Sex.Male // Invalid enum values.
|
||
};
|
||
|
||
// ensure the species can be that sex and their age fits the founds
|
||
if (!speciesPrototype.Sexes.Contains(sex))
|
||
sex = speciesPrototype.Sexes[0];
|
||
|
||
var age = Math.Clamp(Age, speciesPrototype.MinAge, speciesPrototype.MaxAge);
|
||
|
||
var gender = Gender switch
|
||
{
|
||
Gender.Epicene => Gender.Epicene,
|
||
Gender.Female => Gender.Female,
|
||
Gender.Male => Gender.Male,
|
||
Gender.Neuter => Gender.Neuter,
|
||
_ => Gender.Epicene // Invalid enum values.
|
||
};
|
||
|
||
var bodyType = speciesPrototype.BodyTypes.Contains(BodyType) ? BodyType : speciesPrototype.BodyTypes.First();
|
||
|
||
string name;
|
||
var maxNameLength = configManager.GetCVar(CCVars.MaxNameLength);
|
||
if (string.IsNullOrEmpty(Name))
|
||
{
|
||
name = GetName(Species, gender);
|
||
}
|
||
else if (Name.Length > maxNameLength)
|
||
{
|
||
name = Name[..maxNameLength];
|
||
}
|
||
else
|
||
{
|
||
name = Name;
|
||
}
|
||
|
||
name = name.Trim();
|
||
|
||
if (configManager.GetCVar(CCVars.RestrictedNames))
|
||
{
|
||
name = RestrictedNameRegex.Replace(name, string.Empty);
|
||
}
|
||
|
||
if (configManager.GetCVar(CCVars.ICNameCase))
|
||
{
|
||
// This regex replaces the first character of the first and last words of the name with their uppercase version
|
||
name = ICNameCaseRegex.Replace(name, m => m.Groups["word"].Value.ToUpper());
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(name))
|
||
{
|
||
name = GetName(Species, gender);
|
||
}
|
||
|
||
// Sunrise-Start
|
||
IoCManager.Instance!.TryResolveType<ISharedSponsorsManager>(out var sponsors);
|
||
var maxDescLength = configManager.GetCVar(SunriseCCVars.FlavorTextBaseLength);
|
||
if (sponsors != null)
|
||
{
|
||
if (sponsors.IsSponsor(session.UserId))
|
||
maxDescLength = sponsors.GetSizeFlavor(session.UserId);
|
||
if (!sponsors.IsAllowedFlavor(session.UserId) && configManager.GetCVar(SunriseCCVars.FlavorTextSponsorOnly))
|
||
{
|
||
FlavorText = string.Empty;
|
||
}
|
||
}
|
||
// Sunrise-End
|
||
|
||
string flavortext;
|
||
if (FlavorText.Length > maxDescLength) // Sunrise-Edit
|
||
{
|
||
flavortext = FormattedMessage.RemoveMarkupOrThrow(FlavorText)[..maxDescLength]; // Sunrise-Edit
|
||
}
|
||
else
|
||
{
|
||
flavortext = FormattedMessage.RemoveMarkupOrThrow(FlavorText);
|
||
}
|
||
|
||
var appearance = HumanoidCharacterAppearance.EnsureValid(Appearance, Species, Sex, sponsorPrototypes);
|
||
|
||
var prefsUnavailableMode = PreferenceUnavailable switch
|
||
{
|
||
PreferenceUnavailableMode.StayInLobby => PreferenceUnavailableMode.StayInLobby,
|
||
PreferenceUnavailableMode.SpawnAsOverflow => PreferenceUnavailableMode.SpawnAsOverflow,
|
||
_ => PreferenceUnavailableMode.StayInLobby // Invalid enum values.
|
||
};
|
||
|
||
var spawnPriority = SpawnPriority switch
|
||
{
|
||
SpawnPriorityPreference.None => SpawnPriorityPreference.None,
|
||
SpawnPriorityPreference.Arrivals => SpawnPriorityPreference.Arrivals,
|
||
SpawnPriorityPreference.Cryosleep => SpawnPriorityPreference.Cryosleep,
|
||
_ => SpawnPriorityPreference.None // Invalid enum values.
|
||
};
|
||
|
||
var priorities = new Dictionary<ProtoId<JobPrototype>, JobPriority>(JobPriorities
|
||
.Where(p => prototypeManager.TryIndex<JobPrototype>(p.Key, out var job) && job.SetPreference && p.Value switch
|
||
{
|
||
JobPriority.Never => false, // Drop never since that's assumed default.
|
||
JobPriority.Low => true,
|
||
JobPriority.Medium => true,
|
||
JobPriority.High => true,
|
||
_ => false
|
||
}));
|
||
|
||
var hasHighPrio = false;
|
||
foreach (var (key, value) in priorities)
|
||
{
|
||
if (value != JobPriority.High)
|
||
continue;
|
||
|
||
if (hasHighPrio)
|
||
priorities[key] = JobPriority.Medium;
|
||
hasHighPrio = true;
|
||
}
|
||
|
||
var antags = AntagPreferences
|
||
.Where(id => prototypeManager.TryIndex(id, out var antag) && antag.SetPreference)
|
||
.ToList();
|
||
|
||
var traits = TraitPreferences
|
||
.Where(prototypeManager.HasIndex)
|
||
.ToList();
|
||
|
||
Name = name;
|
||
FlavorText = flavortext;
|
||
Age = age;
|
||
Sex = sex;
|
||
Gender = gender;
|
||
BodyType = bodyType;
|
||
Appearance = appearance;
|
||
SpawnPriority = spawnPriority;
|
||
|
||
_jobPriorities.Clear();
|
||
|
||
foreach (var (job, priority) in priorities)
|
||
{
|
||
_jobPriorities.Add(job, priority);
|
||
}
|
||
|
||
PreferenceUnavailable = prefsUnavailableMode;
|
||
|
||
_antagPreferences.Clear();
|
||
_antagPreferences.UnionWith(antags);
|
||
|
||
_traitPreferences.Clear();
|
||
_traitPreferences.UnionWith(GetValidTraits(traits, prototypeManager));
|
||
|
||
// Sunrise-TTS-Start
|
||
prototypeManager.TryIndex<TTSVoicePrototype>(Voice, out var voice);
|
||
if (voice is null || !CanHaveVoice(voice, Sex))
|
||
Voice = SharedHumanoidAppearanceSystem.DefaultSexVoice[sex];
|
||
// Sunrise-TTS-End
|
||
|
||
// Checks prototypes exist for all loadouts and dump / set to default if not.
|
||
var toRemove = new ValueList<string>();
|
||
|
||
foreach (var (roleName, loadouts) in _loadouts)
|
||
{
|
||
if (!prototypeManager.HasIndex<RoleLoadoutPrototype>(roleName))
|
||
{
|
||
toRemove.Add(roleName);
|
||
continue;
|
||
}
|
||
|
||
// This happens after we verify the prototype exists
|
||
// These values are set equal in the database and we need to make sure they're equal here too!
|
||
loadouts.Role = roleName;
|
||
loadouts.EnsureValid(this, session, collection, sponsorPrototypes); // Sunrise-Sponsors
|
||
}
|
||
|
||
foreach (var value in toRemove)
|
||
{
|
||
_loadouts.Remove(value);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Takes in an IEnumerable of traits and returns a List of the valid traits.
|
||
/// </summary>
|
||
public List<ProtoId<TraitPrototype>> GetValidTraits(IEnumerable<ProtoId<TraitPrototype>> traits, IPrototypeManager protoManager)
|
||
{
|
||
// Track points count for each group.
|
||
var groups = new Dictionary<string, int>();
|
||
var result = new List<ProtoId<TraitPrototype>>();
|
||
|
||
foreach (var trait in traits)
|
||
{
|
||
if (!protoManager.TryIndex(trait, out var traitProto))
|
||
continue;
|
||
|
||
// Always valid.
|
||
if (traitProto.Category == null)
|
||
{
|
||
result.Add(trait);
|
||
continue;
|
||
}
|
||
|
||
// No category so dump it.
|
||
if (!protoManager.Resolve(traitProto.Category, out var category))
|
||
continue;
|
||
|
||
var existing = groups.GetOrNew(category.ID);
|
||
existing += traitProto.Cost;
|
||
|
||
// Too expensive.
|
||
if (existing > category.MaxTraitPoints)
|
||
continue;
|
||
|
||
groups[category.ID] = existing;
|
||
result.Add(trait);
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
// Sunrise-TTS-Start
|
||
public static bool CanHaveVoice(TTSVoicePrototype voice, Sex sex)
|
||
{
|
||
return voice.RoundStart && sex == Sex.Unsexed || (voice.Sex == sex || voice.Sex == Sex.Unsexed);
|
||
}
|
||
// Sunrise-TTS-End
|
||
|
||
public ICharacterProfile Validated(ICommonSession session, IDependencyCollection collection, string[] sponsorPrototypes)
|
||
{
|
||
var profile = new HumanoidCharacterProfile(this);
|
||
profile.EnsureValid(session, collection, sponsorPrototypes);
|
||
return profile;
|
||
}
|
||
|
||
// sorry this is kind of weird and duplicated,
|
||
/// working inside these non entity systems is a bit wack
|
||
public static string GetName(string species, Gender gender)
|
||
{
|
||
var namingSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<NamingSystem>();
|
||
return namingSystem.GetName(species, gender);
|
||
}
|
||
public bool Equals(HumanoidCharacterProfile? other)
|
||
{
|
||
if (other is null)
|
||
return false;
|
||
|
||
return ReferenceEquals(this, other) || MemberwiseEquals(other);
|
||
}
|
||
|
||
public override bool Equals(object? obj)
|
||
{
|
||
return obj is HumanoidCharacterProfile other && Equals(other);
|
||
}
|
||
|
||
public override int GetHashCode()
|
||
{
|
||
var hashCode = new HashCode();
|
||
hashCode.Add(_jobPriorities);
|
||
hashCode.Add(_antagPreferences);
|
||
hashCode.Add(_traitPreferences);
|
||
hashCode.Add(_loadouts);
|
||
hashCode.Add(Name);
|
||
hashCode.Add(FlavorText);
|
||
hashCode.Add(Species);
|
||
hashCode.Add(Age);
|
||
hashCode.Add(BodyType);
|
||
hashCode.Add((int)Sex);
|
||
hashCode.Add((int)Gender);
|
||
hashCode.Add(Appearance);
|
||
hashCode.Add((int)SpawnPriority);
|
||
hashCode.Add((int)PreferenceUnavailable);
|
||
return hashCode.ToHashCode();
|
||
}
|
||
|
||
public void SetLoadout(RoleLoadout loadout)
|
||
{
|
||
_loadouts[loadout.Role.Id] = loadout;
|
||
}
|
||
|
||
public HumanoidCharacterProfile WithLoadout(RoleLoadout loadout)
|
||
{
|
||
// Deep copies so we don't modify the DB profile.
|
||
var copied = new Dictionary<string, RoleLoadout>();
|
||
|
||
foreach (var proto in _loadouts)
|
||
{
|
||
if (proto.Key == loadout.Role)
|
||
continue;
|
||
|
||
copied[proto.Key] = proto.Value.Clone();
|
||
}
|
||
|
||
copied[loadout.Role] = loadout.Clone();
|
||
var profile = Clone();
|
||
profile._loadouts = copied;
|
||
return profile;
|
||
}
|
||
|
||
public RoleLoadout GetLoadoutOrDefault(string id, ICommonSession? session, ProtoId<SpeciesPrototype>? species, IEntityManager entManager, IPrototypeManager protoManager, string [] sponsorPrototypes)
|
||
{
|
||
if (!_loadouts.TryGetValue(id, out var loadout))
|
||
{
|
||
loadout = new RoleLoadout(id);
|
||
loadout.SetDefault(this, session, protoManager, sponsorPrototypes, force: true);
|
||
}
|
||
|
||
loadout.SetDefault(this, session, protoManager, sponsorPrototypes);
|
||
return loadout;
|
||
}
|
||
|
||
public HumanoidCharacterProfile Clone()
|
||
{
|
||
return new HumanoidCharacterProfile(this);
|
||
}
|
||
}
|
||
}
|