From cfe39123a77dc3abb6be3ced74e9722ee484a26d Mon Sep 17 00:00:00 2001 From: Rane <60792108+Elijahrane@users.noreply.github.com> Date: Sun, 10 Jul 2022 21:10:03 -0400 Subject: [PATCH] Allow non-humanoid roles (#9604) --- Content.Server/Roles/Job.cs | 3 +++ .../Station/Systems/StationSpawningSystem.cs | 21 ++++++++++++++++--- Content.Shared/Roles/JobPrototype.cs | 8 +++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Content.Server/Roles/Job.cs b/Content.Server/Roles/Job.cs index 3ecc9afb74..cb37da26cc 100644 --- a/Content.Server/Roles/Job.cs +++ b/Content.Server/Roles/Job.cs @@ -17,6 +17,9 @@ namespace Content.Server.Roles [ViewVariables] public string? StartingGear => Prototype.StartingGear; + [ViewVariables] + public string? JobEntity => Prototype.JobEntity; + [ViewVariables] public bool CanBeAntag; diff --git a/Content.Server/Station/Systems/StationSpawningSystem.cs b/Content.Server/Station/Systems/StationSpawningSystem.cs index 95ea6eb480..c116630ba1 100644 --- a/Content.Server/Station/Systems/StationSpawningSystem.cs +++ b/Content.Server/Station/Systems/StationSpawningSystem.cs @@ -6,7 +6,7 @@ using Content.Server.Hands.Systems; using Content.Server.PDA; using Content.Server.Roles; using Content.Server.Station.Components; -using Content.Shared.Access.Components; +using Content.Server.Mind.Commands; using Content.Shared.Access.Systems; using Content.Shared.CCVar; using Content.Shared.Inventory; @@ -20,6 +20,7 @@ using Robust.Shared.Map; using Robust.Shared.Prototypes; using Robust.Shared.Utility; + namespace Content.Server.Station.Systems; /// @@ -92,6 +93,15 @@ public sealed class StationSpawningSystem : EntitySystem HumanoidCharacterProfile? profile, EntityUid? station) { + // If we're not spawning a humanoid, we're gonna exit early without doing all the humanoid stuff. + if (job?.JobEntity != null) + { + var jobEntity = EntityManager.SpawnEntity(job.JobEntity, coordinates); + MakeSentientCommand.MakeSentient(jobEntity, EntityManager); + DoJobSpecials(job, jobEntity); + return jobEntity; + } + var entity = EntityManager.SpawnEntity( _prototypeManager.Index(profile?.Species ?? SpeciesManager.DefaultSpecies).Prototype, coordinates); @@ -114,12 +124,17 @@ public sealed class StationSpawningSystem : EntitySystem } } + DoJobSpecials(job, entity); + + return entity; + } + + private void DoJobSpecials(Job? job, EntityUid entity) + { foreach (var jobSpecial in job?.Prototype.Special ?? Array.Empty()) { jobSpecial.AfterEquip(entity); } - - return entity; } /// diff --git a/Content.Shared/Roles/JobPrototype.cs b/Content.Shared/Roles/JobPrototype.cs index 92915c6af1..b435dcf812 100644 --- a/Content.Shared/Roles/JobPrototype.cs +++ b/Content.Shared/Roles/JobPrototype.cs @@ -51,6 +51,14 @@ namespace Content.Shared.Roles [DataField("startingGear", customTypeSerializer: typeof(PrototypeIdSerializer))] public string? StartingGear { get; private set; } + /// + /// Use this to spawn in as a non-humanoid (borg, test subject, etc.) + /// Starting gear will be ignored. + /// If you want to just add special attributes to a humanoid, use AddComponentSpecial instead. + /// + [DataField("jobEntity", customTypeSerializer: typeof(PrototypeIdSerializer))] + public string? JobEntity = null; + [DataField("icon")] public string Icon { get; } = string.Empty; [DataField("special", serverOnly:true)]