Skip to content

Commit

Permalink
SetStationAiName for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyyapril committed Jan 4, 2025
1 parent b8e2844 commit c9e0e5d
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 9 deletions.
57 changes: 57 additions & 0 deletions Content.Server/Administration/Commands/SetStationAiName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Content.Server.Station.Systems;
using Content.Shared.Administration;
using Content.Shared.Roles;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;


namespace Content.Server.Administration.Commands;


[AdminCommand(AdminFlags.Admin)]
public sealed class GetStationAiNameCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly StationSpawningSystem _spawning = default!;

private ProtoId<JobPrototype> _stationAIJob = "StationAi";

public string Command => "setstationainame";
public string Description => Loc.GetString("set-station-ai-name-command-description");
public string Help => Loc.GetString("set-station-ai-name-command-help-text", ("command", Command));

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
return;
}

if (!int.TryParse(args[0], out var entInt))
{
shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number"));
return;
}

var netEntity = new NetEntity(entInt);

if (!_entManager.TryGetEntity(netEntity, out var target))
{
shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
return;
}

var hasStationAi = _prototypeManager.TryIndex(_stationAIJob, out var job);

if (!hasStationAi)
{
shell.WriteLine(Loc.GetString("set-station-ai-name-command-no-station-ai"));
return;
}

_spawning.EquipJobName(target.Value, job!);
shell.WriteLine(Loc.GetString("shell-command-success"));
}
}
10 changes: 7 additions & 3 deletions Content.Server/Clothing/Systems/LoadoutSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Content.Server.GameTicking;
using Content.Server.Paint;
using Content.Server.Players.PlayTimeTracking;
using Content.Server.Station.Systems;
using Content.Shared.CCVar;
using Content.Shared.Clothing.Loadouts.Prototypes;
using Content.Shared.Clothing.Loadouts.Systems;
Expand Down Expand Up @@ -33,6 +34,7 @@ public sealed class LoadoutSystem : EntitySystem
[Dependency] private readonly ISerializationManager _serialization = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;
[Dependency] private readonly StationSpawningSystem _stationSpawning = default!;


public override void Initialize()
Expand All @@ -43,10 +45,13 @@ public override void Initialize()

private void OnPlayerSpawnComplete(PlayerSpawnCompleteEvent ev)
{
if (ev.JobId == null ||
!_configurationManager.GetCVar(CCVars.GameLoadoutsEnabled))
if (ev.JobId == null
|| !_protoMan.TryIndex<JobPrototype>(ev.JobId, out var job)
|| !_configurationManager.GetCVar(CCVars.GameLoadoutsEnabled))
return;

_stationSpawning.EquipJobName(ev.Mob, job);

ApplyCharacterLoadout(
ev.Mob,
ev.JobId,
Expand Down Expand Up @@ -108,7 +113,6 @@ public void ApplyCharacterLoadout(
function.OnPlayerSpawn(uid, loadout.Item1, _componentFactory, EntityManager, _serialization);
}


// Pick the heirloom
if (heirlooms.Any())
{
Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Roles/JobPrototype.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Shared.Access;
using Content.Shared.Customization.Systems;
using Content.Shared.Dataset;
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Roles;
using Content.Shared.StatusIcon;
Expand Down Expand Up @@ -98,6 +99,13 @@ public sealed partial class JobPrototype : IPrototype
[DataField("startingGear", customTypeSerializer: typeof(PrototypeIdSerializer<StartingGearPrototype>))]
public string? StartingGear { get; private set; }

/// <summary>
/// If this has a value, it will randomly set the entity name of the
/// entity upon spawn based on the dataset.
/// </summary>
[DataField]
public ProtoId<LocalizedDatasetPrototype>? NameDataset;

/// <summary>
/// Use this to spawn in as a non-humanoid (borg, test subject, etc.)
/// Starting gear will be ignored.
Expand Down
14 changes: 9 additions & 5 deletions Content.Shared/Station/SharedStationSpawningSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Content.Shared.Dataset;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Inventory;
Expand All @@ -18,9 +19,10 @@ public abstract class SharedStationSpawningSystem : EntitySystem
[Dependency] protected readonly IPrototypeManager PrototypeManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] protected readonly InventorySystem InventorySystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedStorageSystem _storage = default!;
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedStorageSystem _storage = default!;
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
[Dependency] private readonly MetaDataSystem _metadata = default!;

private EntityQuery<HandsComponent> _handsQuery;
private EntityQuery<InventoryComponent> _inventoryQuery;
Expand All @@ -39,11 +41,13 @@ public override void Initialize()
/// <summary>
/// Applies the role's name as applicable to the entity.
/// </summary>
public void EquipRoleName(EntityUid entity, RoleLoadout loadout, RoleLoadoutPrototype roleProto)
public void EquipJobName(EntityUid entity, JobPrototype job)
{
string? name = null;

if (string.IsNullOrEmpty(name) && PrototypeManager.TryIndex(roleProto.NameDataset, out var nameData))
if (string.IsNullOrEmpty(name)
&& job.NameDataset.HasValue
&& PrototypeManager.TryIndex(job.NameDataset.Value, out var nameData))
{
name = Loc.GetString(_random.Pick(nameData.Values));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set-station-ai-name-command-description = Sets a specific uid to be given a Station AI name at random.
set-station-ai-name-command-help-text = Usage: {$command} <entityUid>
set-station-ai-name-command-no-station-ai = No station AI job prototype found.
3 changes: 2 additions & 1 deletion Resources/Prototypes/Roles/Jobs/Science/borg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
icon: JobIconStationAi
supervisors: job-supervisors-rd
jobEntity: StationAiBrain
nameDataset: NamesAI

- type: job
id: Borg
Expand All @@ -24,4 +25,4 @@
canBeAntag: false
icon: JobIconBorg
supervisors: job-supervisors-rd
jobEntity: PlayerBorgGeneric
jobEntity: PlayerBorgGeneric

0 comments on commit c9e0e5d

Please sign in to comment.