Move random species selection earlier in player spawning logic (#37258)
* Select random species earlier in spawning logic * ternary operator * Move it even earlier to fix more bugs
This commit is contained in:
@@ -8,11 +8,16 @@ using Content.Server.Ghost;
|
||||
using Content.Server.Spawners.Components;
|
||||
using Content.Server.Speech.Components;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Humanoid.Prototypes;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Players;
|
||||
using Content.Shared.Preferences;
|
||||
using Content.Shared.Random;
|
||||
using Content.Shared.Random.Helpers;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Roles.Jobs;
|
||||
using Robust.Shared.Map;
|
||||
@@ -180,6 +185,36 @@ namespace Content.Server.GameTicking
|
||||
return;
|
||||
}
|
||||
|
||||
string speciesId;
|
||||
if (_randomizeCharacters)
|
||||
{
|
||||
var weightId = _cfg.GetCVar(CCVars.ICRandomSpeciesWeights);
|
||||
|
||||
// If blank, choose a round start species.
|
||||
if (string.IsNullOrEmpty(weightId))
|
||||
{
|
||||
var roundStart = new List<ProtoId<SpeciesPrototype>>();
|
||||
|
||||
var speciesPrototypes = _prototypeManager.EnumeratePrototypes<SpeciesPrototype>();
|
||||
foreach (var proto in speciesPrototypes)
|
||||
{
|
||||
if (proto.RoundStart)
|
||||
roundStart.Add(proto.ID);
|
||||
}
|
||||
|
||||
speciesId = roundStart.Count == 0
|
||||
? SharedHumanoidAppearanceSystem.DefaultSpecies
|
||||
: _robustRandom.Pick(roundStart);
|
||||
}
|
||||
else
|
||||
{
|
||||
var weights = _prototypeManager.Index<WeightedRandomSpeciesPrototype>(weightId);
|
||||
speciesId = weights.Pick(_robustRandom);
|
||||
}
|
||||
|
||||
character = HumanoidCharacterProfile.RandomWithSpecies(speciesId);
|
||||
}
|
||||
|
||||
// We raise this event to allow other systems to handle spawning this player themselves. (e.g. late-join wizard, etc)
|
||||
var bev = new PlayerBeforeSpawnEvent(player, character, jobId, lateJoin, station);
|
||||
RaiseLocalEvent(bev);
|
||||
|
||||
@@ -9,6 +9,7 @@ using Content.Server.Players.PlayTimeTracking;
|
||||
using Content.Server.Preferences.Managers;
|
||||
using Content.Server.ServerUpdates;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Mind;
|
||||
@@ -72,6 +73,8 @@ namespace Content.Server.GameTicking
|
||||
|
||||
private ISawmill _sawmill = default!;
|
||||
|
||||
private bool _randomizeCharacters;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -82,6 +85,8 @@ namespace Content.Server.GameTicking
|
||||
_sawmill = _logManager.GetSawmill("ticker");
|
||||
_sawmillReplays = _logManager.GetSawmill("ticker.replays");
|
||||
|
||||
Subs.CVar(_cfg, CCVars.ICRandomCharacters, e => _randomizeCharacters = e, true);
|
||||
|
||||
// Initialize the other parts of the game ticker.
|
||||
InitializeStatusShell();
|
||||
InitializeCVars();
|
||||
|
||||
@@ -14,8 +14,6 @@ using Content.Shared.Humanoid.Prototypes;
|
||||
using Content.Shared.PDA;
|
||||
using Content.Shared.Preferences;
|
||||
using Content.Shared.Preferences.Loadouts;
|
||||
using Content.Shared.Random;
|
||||
using Content.Shared.Random.Helpers;
|
||||
using Content.Shared.Roles;
|
||||
using Content.Shared.Station;
|
||||
using JetBrains.Annotations;
|
||||
@@ -23,7 +21,6 @@ using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Station.Systems;
|
||||
@@ -44,16 +41,6 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
|
||||
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
|
||||
[Dependency] private readonly PdaSystem _pdaSystem = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
private bool _randomizeCharacters;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
Subs.CVar(_configurationManager, CCVars.ICRandomCharacters, e => _randomizeCharacters = e, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to spawn a player character onto the given station.
|
||||
@@ -136,53 +123,13 @@ public sealed class StationSpawningSystem : SharedStationSpawningSystem
|
||||
return jobEntity;
|
||||
}
|
||||
|
||||
string speciesId;
|
||||
if (_randomizeCharacters)
|
||||
{
|
||||
var weightId = _configurationManager.GetCVar(CCVars.ICRandomSpeciesWeights);
|
||||
|
||||
// If blank, choose a round start species.
|
||||
if (string.IsNullOrEmpty(weightId))
|
||||
{
|
||||
var roundStart = new List<ProtoId<SpeciesPrototype>>();
|
||||
|
||||
var speciesPrototypes = _prototypeManager.EnumeratePrototypes<SpeciesPrototype>();
|
||||
foreach (var proto in speciesPrototypes)
|
||||
{
|
||||
if (proto.RoundStart)
|
||||
roundStart.Add(proto.ID);
|
||||
}
|
||||
|
||||
if (roundStart.Count == 0)
|
||||
speciesId = SharedHumanoidAppearanceSystem.DefaultSpecies;
|
||||
else
|
||||
speciesId = _random.Pick(roundStart);
|
||||
}
|
||||
else
|
||||
{
|
||||
var weights = _prototypeManager.Index<WeightedRandomSpeciesPrototype>(weightId);
|
||||
speciesId = weights.Pick(_random);
|
||||
}
|
||||
}
|
||||
else if (profile != null)
|
||||
{
|
||||
speciesId = profile.Species;
|
||||
}
|
||||
else
|
||||
{
|
||||
speciesId = SharedHumanoidAppearanceSystem.DefaultSpecies;
|
||||
}
|
||||
string speciesId = profile != null ? profile.Species : SharedHumanoidAppearanceSystem.DefaultSpecies;
|
||||
|
||||
if (!_prototypeManager.TryIndex<SpeciesPrototype>(speciesId, out var species))
|
||||
throw new ArgumentException($"Invalid species prototype was used: {speciesId}");
|
||||
|
||||
entity ??= Spawn(species.Prototype, coordinates);
|
||||
|
||||
if (_randomizeCharacters)
|
||||
{
|
||||
profile = HumanoidCharacterProfile.RandomWithSpecies(speciesId);
|
||||
}
|
||||
|
||||
if (profile != null)
|
||||
{
|
||||
_humanoidSystem.LoadProfile(entity.Value, profile);
|
||||
|
||||
Reference in New Issue
Block a user