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;
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!;
[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)
return jobEntity;
}
- if (!_prototypeManager.TryIndex(profile?.Species ?? HumanoidAppearanceSystem.DefaultSpecies, out SpeciesPrototype? species))
+ string speciesId;
+ if (_randomizeCharacters)
+ {
+ var weightId = _configurationManager.GetCVar(CCVars.ICRandomSpeciesWeights);
+ var weights = _prototypeManager.Index<WeightedRandomPrototype>(weightId);
+ speciesId = weights.Pick(_random);
+ }
+ else if (profile != null)
+ {
+ speciesId = profile.Species;
+ }
+ else
{
- species = _prototypeManager.Index<SpeciesPrototype>(HumanoidAppearanceSystem.DefaultSpecies);
+ 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)
{
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;
}
}
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
*/