Actual randomized humanoids (#11574)

This commit is contained in:
Flipp Syder
2022-10-20 06:46:05 -07:00
committed by GitHub
parent e4c67e998f
commit 0fe9f38968
8 changed files with 418 additions and 175 deletions

View File

@@ -1,5 +1,6 @@
using Content.Server.GameTicking.Rules.Configurations;
using Content.Shared.Dataset;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Roles;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
@@ -25,8 +26,8 @@ public sealed class NukeopsRuleConfiguration : GameRuleConfiguration
[DataField("maxOps")]
public int MaxOperatives = 5;
[DataField("spawnEntityProto", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string SpawnEntityPrototype = "MobHumanNukeOp";
[DataField("randomHumanoidSettings", customTypeSerializer: typeof(PrototypeIdSerializer<RandomHumanoidSettingsPrototype>))]
public string RandomHumanoidSettingsPrototype = "NukeOp";
[DataField("spawnPointProto", customTypeSerializer: typeof(PrototypeIdSerializer<StartingGearPrototype>))]
public string SpawnPointPrototype = "SpawnPointNukies";

View File

@@ -35,6 +35,7 @@ using Robust.Shared.Audio;
using Robust.Shared.Configuration;
using Robust.Shared.Player;
using Content.Server.Administration.Commands;
using Content.Server.Humanoid.Systems;
using Content.Shared.Preferences;
using Content.Server.Preferences.Managers;
@@ -57,6 +58,7 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
[Dependency] private readonly RoundEndSystem _roundEndSystem = default!;
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly RandomHumanoidSystem _randomHumanoid = default!;
private enum WinType
@@ -732,7 +734,7 @@ public sealed class NukeopsRuleSystem : GameRuleSystem
if (sessions.TryGetValue(i, out var session))
{
var mob = EntityManager.SpawnEntity(_nukeopsRuleConfig.SpawnEntityPrototype, _random.Pick(spawns));
var mob = _randomHumanoid.SpawnRandomHumanoid(_nukeopsRuleConfig.RandomHumanoidSettingsPrototype, _random.Pick(spawns), string.Empty);
var profile = _prefs.GetPreferences(session.UserId).SelectedCharacter as HumanoidCharacterProfile;
SetupOperativeEntity(mob, spawnDetails.Name, spawnDetails.Gear, profile);

View File

@@ -0,0 +1,16 @@
using Content.Shared.Humanoid.Prototypes;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.Humanoid.Components;
/// <summary>
/// This is added to a marker entity in order to spawn a randomized
/// humanoid ingame.
/// </summary>
[RegisterComponent]
public sealed class RandomHumanoidSpawnerComponent : Component
{
[DataField("settings", customTypeSerializer: typeof(PrototypeIdSerializer<RandomHumanoidSettingsPrototype>))]
public string SettingsPrototypeId = default!;
}

View File

@@ -0,0 +1,66 @@
using Content.Server.Humanoid.Components;
using Content.Server.RandomMetadata;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Preferences;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager;
namespace Content.Server.Humanoid.Systems;
/// <summary>
/// This deals with spawning and setting up random humanoids.
/// </summary>
public sealed class RandomHumanoidSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IComponentFactory _compFactory = default!;
[Dependency] private readonly ISerializationManager _serialization = default!;
[Dependency] private readonly HumanoidSystem _humanoid = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<RandomHumanoidSpawnerComponent, MapInitEvent>(OnMapInit,
after: new []{ typeof(RandomMetadataSystem) });
}
private void OnMapInit(EntityUid uid, RandomHumanoidSpawnerComponent component, MapInitEvent args)
{
QueueDel(uid);
SpawnRandomHumanoid(component.SettingsPrototypeId, Transform(uid).Coordinates, MetaData(uid).EntityName);
}
public EntityUid SpawnRandomHumanoid(string prototypeId, EntityCoordinates coordinates, string name)
{
if (!_prototypeManager.TryIndex<RandomHumanoidSettingsPrototype>(prototypeId, out var prototype))
{
throw new ArgumentException("Could not get random humanoid settings");
}
var profile = HumanoidCharacterProfile.Random(prototype.SpeciesBlacklist);
var speciesProto = _prototypeManager.Index<SpeciesPrototype>(profile.Species);
var humanoid = Spawn(speciesProto.Prototype, coordinates);
MetaData(humanoid).EntityName = prototype.RandomizeName
? profile.Name
: name;
_humanoid.LoadProfile(humanoid, profile);
if (prototype.Components == null)
{
return humanoid;
}
foreach (var entry in prototype.Components.Values)
{
var comp = (Component) _serialization.Copy(entry.Component);
comp.Owner = humanoid;
EntityManager.AddComponent(humanoid, comp, true);
}
return humanoid;
}
}