Add support for true randomized characters (#14918)

This commit is contained in:
Nemanja
2023-03-28 21:30:00 -04:00
committed by GitHub
parent 3c9a74e8a0
commit 66ff565e16
3 changed files with 52 additions and 6 deletions

View File

@@ -8,18 +8,21 @@ using Content.Server.PDA;
using Content.Server.Roles;
using Content.Server.Station.Components;
using Content.Server.Mind.Commands;
using Content.Server.Shuttles.Components;
using Content.Shared.Access.Systems;
using Content.Shared.CCVar;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Inventory;
using Content.Shared.PDA;
using Content.Shared.Preferences;
using Content.Shared.Random;
using Content.Shared.Random.Helpers;
using Content.Shared.Roles;
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
@@ -33,6 +36,7 @@ namespace Content.Server.Station.Systems;
public sealed class StationSpawningSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly HandsSystem _handsSystem = default!;
[Dependency] private readonly HumanoidAppearanceSystem _humanoidSystem = default!;
@@ -42,10 +46,13 @@ public sealed class StationSpawningSystem : EntitySystem
[Dependency] private readonly SharedAccessSystem _accessSystem = default!;
[Dependency] private readonly IdentitySystem _identity = default!;
private bool _randomizeCharacters;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<StationInitializedEvent>(OnStationInitialized);
_configurationManager.OnValueChanged(CCVars.ICRandomCharacters, e => _randomizeCharacters = e, true);
}
private void OnStationInitialized(StationInitializedEvent ev)
@@ -106,12 +113,31 @@ public sealed class StationSpawningSystem : EntitySystem
return jobEntity;
}
if (!_prototypeManager.TryIndex(profile?.Species ?? HumanoidAppearanceSystem.DefaultSpecies, out SpeciesPrototype? species))
string speciesId;
if (_randomizeCharacters)
{
species = _prototypeManager.Index<SpeciesPrototype>(HumanoidAppearanceSystem.DefaultSpecies);
var weightId = _configurationManager.GetCVar(CCVars.ICRandomSpeciesWeights);
var weights = _prototypeManager.Index<WeightedRandomPrototype>(weightId);
speciesId = weights.Pick(_random);
}
else if (profile != null)
{
speciesId = profile.Species;
}
else
{
speciesId = SharedHumanoidAppearanceSystem.DefaultSpecies;
}
var entity = EntityManager.SpawnEntity(species.Prototype, coordinates);
if (!_prototypeManager.TryIndex<SpeciesPrototype>(speciesId, out var species))
throw new ArgumentException($"Invalid species prototype was used: {speciesId}");
var entity = Spawn(species.Prototype, coordinates);
if (_randomizeCharacters)
{
profile = HumanoidCharacterProfile.RandomWithSpecies(speciesId);
}
if (job?.StartingGear != null)
{
@@ -124,10 +150,10 @@ public sealed class StationSpawningSystem : EntitySystem
if (profile != null)
{
_humanoidSystem.LoadProfile(entity, profile);
EntityManager.GetComponent<MetaDataComponent>(entity).EntityName = profile.Name;
MetaData(entity).EntityName = profile.Name;
if (profile.FlavorText != "" && _configurationManager.GetCVar(CCVars.FlavorText))
{
EntityManager.AddComponent<DetailExaminableComponent>(entity).Content = profile.FlavorText;
AddComp<DetailExaminableComponent>(entity).Content = profile.FlavorText;
}
}

View File

@@ -1300,6 +1300,18 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<bool> ICNameCase =
CVarDef.Create("ic.name_case", true, CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Whether or not players' characters are randomly generated rather than using their selected characters in the creator.
/// </summary>
public static readonly CVarDef<bool> ICRandomCharacters =
CVarDef.Create("ic.random_characters", false, CVar.SERVER);
/// <summary>
/// A weighted random prototype used to determine the species selected for random characters.
/// </summary>
public static readonly CVarDef<string> ICRandomSpeciesWeights =
CVarDef.Create("ic.random_species_weights", "SpeciesWeights", CVar.SERVER);
/*
* Salvage
*/

View File

@@ -0,0 +1,8 @@
#default species weights used for randomly selected species
- type: weightedRandom
id: SpeciesWeights
weights:
Human: 5
Reptilian: 4
SlimePerson: 4
Diona: 2