Skip to content

Commit

Permalink
Allow non-humanoid roles (#9604)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rane authored Jul 11, 2022
1 parent e57294b commit cfe3912
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Content.Server/Roles/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public sealed class Job : Role
[ViewVariables]
public string? StartingGear => Prototype.StartingGear;

[ViewVariables]
public string? JobEntity => Prototype.JobEntity;

[ViewVariables]
public bool CanBeAntag;

Expand Down
21 changes: 18 additions & 3 deletions Content.Server/Station/Systems/StationSpawningSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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;
Expand All @@ -20,6 +20,7 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;


namespace Content.Server.Station.Systems;

/// <summary>
Expand Down Expand Up @@ -92,6 +93,15 @@ public EntityUid SpawnPlayerMob(
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<SpeciesPrototype>(profile?.Species ?? SpeciesManager.DefaultSpecies).Prototype,
coordinates);
Expand All @@ -114,12 +124,17 @@ public EntityUid SpawnPlayerMob(
}
}

DoJobSpecials(job, entity);

return entity;
}

private void DoJobSpecials(Job? job, EntityUid entity)
{
foreach (var jobSpecial in job?.Prototype.Special ?? Array.Empty<JobSpecial>())
{
jobSpecial.AfterEquip(entity);
}

return entity;
}

/// <summary>
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Roles/JobPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public sealed class JobPrototype : IPrototype
[DataField("startingGear", customTypeSerializer: typeof(PrototypeIdSerializer<StartingGearPrototype>))]
public string? StartingGear { get; private set; }

/// <summary>
/// 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.
/// </summary>
[DataField("jobEntity", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
public string? JobEntity = null;

[DataField("icon")] public string Icon { get; } = string.Empty;

[DataField("special", serverOnly:true)]
Expand Down

0 comments on commit cfe3912

Please sign in to comment.