From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
Date: Wed, 29 Mar 2023 01:30:00 +0000 (-0400)
Subject: Add support for true randomized characters (#14918)
X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=66ff565e16c4da45cbaf0d47ceae6fdbdd083096;p=space-station-14.git
Add support for true randomized characters (#14918)
---
diff --git a/Content.Server/Station/Systems/StationSpawningSystem.cs b/Content.Server/Station/Systems/StationSpawningSystem.cs
index 65577ab05a..641c801d50 100644
--- a/Content.Server/Station/Systems/StationSpawningSystem.cs
+++ b/Content.Server/Station/Systems/StationSpawningSystem.cs
@@ -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;
+
///
public override void Initialize()
{
SubscribeLocalEvent(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)
+ {
+ var weightId = _configurationManager.GetCVar(CCVars.ICRandomSpeciesWeights);
+ var weights = _prototypeManager.Index(weightId);
+ speciesId = weights.Pick(_random);
+ }
+ else if (profile != null)
+ {
+ speciesId = profile.Species;
+ }
+ else
{
- species = _prototypeManager.Index(HumanoidAppearanceSystem.DefaultSpecies);
+ speciesId = SharedHumanoidAppearanceSystem.DefaultSpecies;
}
- var entity = EntityManager.SpawnEntity(species.Prototype, coordinates);
+ if (!_prototypeManager.TryIndex(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(entity).EntityName = profile.Name;
+ MetaData(entity).EntityName = profile.Name;
if (profile.FlavorText != "" && _configurationManager.GetCVar(CCVars.FlavorText))
{
- EntityManager.AddComponent(entity).Content = profile.FlavorText;
+ AddComp(entity).Content = profile.FlavorText;
}
}
diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs
index d50ad12461..8280d8d294 100644
--- a/Content.Shared/CCVar/CCVars.cs
+++ b/Content.Shared/CCVar/CCVars.cs
@@ -1300,6 +1300,18 @@ namespace Content.Shared.CCVar
public static readonly CVarDef ICNameCase =
CVarDef.Create("ic.name_case", true, CVar.SERVER | CVar.REPLICATED);
+ ///
+ /// Whether or not players' characters are randomly generated rather than using their selected characters in the creator.
+ ///
+ public static readonly CVarDef ICRandomCharacters =
+ CVarDef.Create("ic.random_characters", false, CVar.SERVER);
+
+ ///
+ /// A weighted random prototype used to determine the species selected for random characters.
+ ///
+ public static readonly CVarDef ICRandomSpeciesWeights =
+ CVarDef.Create("ic.random_species_weights", "SpeciesWeights", CVar.SERVER);
+
/*
* Salvage
*/
diff --git a/Resources/Prototypes/Species/species_weights.yml b/Resources/Prototypes/Species/species_weights.yml
new file mode 100644
index 0000000000..2e82a0b9db
--- /dev/null
+++ b/Resources/Prototypes/Species/species_weights.yml
@@ -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