Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Senior ID cards get a custom job name: Attempt 2 #1418

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,9 @@ public void RefreshJobs()

foreach (var job in jobs)
{
if (job.EditorHidden)
continue;

var jobContainer = new BoxContainer()
{
Orientation = LayoutOrientation.Horizontal,
Expand Down
6 changes: 0 additions & 6 deletions Content.Server/Access/Components/PresetIdCardComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,4 @@ public sealed partial class PresetIdCardComponent : Component

[DataField("name")]
public string? IdName;

/// <summary>
/// DeltaV: Allow changing the job title, even if it'd be otherwise set by the JobPrototype
/// </summary>
[DataField("customJob")]
public string? CustomJobName;
}
25 changes: 0 additions & 25 deletions Content.Server/Access/Systems/PresetIdCardSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
using Content.Server.GameTicking;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Server.StationRecords.Systems;
using Content.Shared.Access.Systems;
using Content.Shared.Roles;
using Content.Shared.StationRecords;
using Content.Shared.StatusIcon;
using Robust.Shared.Prototypes;

Expand All @@ -17,8 +15,6 @@ public sealed class PresetIdCardSystem : EntitySystem
[Dependency] private readonly IdCardSystem _cardSystem = default!;
[Dependency] private readonly SharedAccessSystem _accessSystem = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly StationRecordsSystem _record = default!; // DeltaV - Allow changing the job title within the prototype

public override void Initialize()
{
SubscribeLocalEvent<PresetIdCardComponent, MapInitEvent>(OnMapInit);
Expand All @@ -41,7 +37,6 @@ private void PlayerJobsAssigned(RulePlayerJobsAssignedEvent ev)

SetupIdAccess(uid, card, true);
SetupIdName(uid, card);
SetupIdJob(uid, card); // DeltaV - Allow changing the job title within the prototype
}
}

Expand All @@ -61,7 +56,6 @@ private void OnMapInit(EntityUid uid, PresetIdCardComponent id, MapInitEvent arg

SetupIdAccess(uid, id, extended);
SetupIdName(uid, id);
SetupIdJob(uid, id); // DeltaV - Allow changing the job title within the prototype
}

private void SetupIdName(EntityUid uid, PresetIdCardComponent id)
Expand All @@ -71,25 +65,6 @@ private void SetupIdName(EntityUid uid, PresetIdCardComponent id)
_cardSystem.TryChangeFullName(uid, id.IdName);
}

// DeltaV - Allow changing the job title within the prototype
private void SetupIdJob(EntityUid uid, PresetIdCardComponent id)
{
if (id.CustomJobName == null)
return;
_cardSystem.TryChangeJobTitle(uid, id.CustomJobName);

// The following code is taken from IdCardConsoleSystem
if (!TryComp<StationRecordKeyStorageComponent>(uid, out var keyStorage)
|| keyStorage.Key is not { } key
|| !_record.TryGetRecord<GeneralStationRecord>(key, out var record))
{
return;
}
record.JobTitle = id.CustomJobName;
_record.Synchronize(key);
}
// End of DeltaV code

private void SetupIdAccess(EntityUid uid, PresetIdCardComponent id, bool extended)
{
if (id.JobName == null)
Expand Down
99 changes: 95 additions & 4 deletions Content.Server/GameTicking/GameTicker.Spawning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
using Content.Shared.Mind;
using Content.Shared.Players;
using Content.Shared.Preferences;
using Content.Shared.Preferences.Loadouts;
using Content.Shared.Roles;
using Content.Shared.Roles.Jobs;
using Content.Shared.Clothing;
using Content.Shared.Access.Components;
using JetBrains.Annotations;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
Expand All @@ -21,13 +24,19 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using Microsoft.CodeAnalysis;
using Content.Shared.PDA;
using FastAccessors;
using Content.Server.Access.Components;
using Content.Shared.Destructible;

namespace Content.Server.GameTicking
{
public sealed partial class GameTicker
{
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly SharedJobSystem _jobs = default!;
[Dependency] private readonly IComponentFactory _componentFactory = default!;

[ValidatePrototypeId<EntityPrototype>]
public const string ObserverPrototypeName = "MobObserver";
Expand Down Expand Up @@ -224,7 +233,32 @@ private void SpawnPlayer(ICommonSession player,

var jobPrototype = _prototypeManager.Index<JobPrototype>(jobId);
var job = new JobComponent {Prototype = jobId};
// DeltaV - Senior ID cards
do
{
var jobLoadout = LoadoutSystem.GetJobPrototype(jobPrototype.ID);

if (!_prototypeManager.TryIndex(jobLoadout, out RoleLoadoutPrototype? roleProto))
break;

RoleLoadout? loadout = null;
character.Loadouts.TryGetValue(jobLoadout, out loadout);

// Set to default if not present
if (loadout == null)
{
loadout = new RoleLoadout(jobLoadout);
loadout.SetDefault(_prototypeManager);
}

if (GetVirtualJobFromRoleLoadout(loadout, roleProto, character, out var virtualJobId) && _prototypeManager.TryIndex<JobPrototype>(virtualJobId, out var virtualJobProto))
{
job.VirtualJob = new JobComponent {Prototype = virtualJobProto};
}
}
while (false);
_roles.MindAddRole(newMind, job, silent: silent);
// End of DeltaV code
var jobName = _jobs.MindTryGetJobName(newMind);

_playTimeTrackings.PlayerRolesChanged(player);
Expand Down Expand Up @@ -302,14 +336,71 @@ private void SpawnPlayer(ICommonSession player,
PlayersJoinedRoundNormally++;
var aev = new PlayerSpawnCompleteEvent(mob,
player,
jobId,
job,
lateJoin,
PlayersJoinedRoundNormally,
station,
character);
RaiseLocalEvent(mob, aev, true);
}

// DeltaV - Senior ID cards
private bool GetVirtualJobFromRoleLoadout(RoleLoadout loadout, RoleLoadoutPrototype roleProto, HumanoidCharacterProfile character, out ProtoId<JobPrototype>? virtualJob)
{
virtualJob = null;

// Use to read job loadout and find an ID card
foreach (var group in loadout.SelectedLoadouts.OrderBy(x => roleProto.Groups.FindIndex(e => e == x.Key)))
{
foreach (var items in group.Value)
{
if (!_prototypeManager.TryIndex(items.Prototype, out var loadoutProto))
{
Log.Warning($"Unable to find loadout prototype for {items.Prototype}");
continue;
}
if (!_prototypeManager.TryIndex(loadoutProto.Equipment, out var startingGear))
{
Log.Warning($"Unable to find starting gear {loadoutProto.Equipment} for loadout {loadoutProto}");
continue;
}
var entProtoId = startingGear.GetGear("id");
if (!_prototypeManager.TryIndex<EntityPrototype>(entProtoId, out var idProto))
{
Log.Warning($"Unable to find prototype for {startingGear} for starting gear {loadoutProto.Equipment} for loadout {loadoutProto}");
continue;
}
if (idProto.TryGetComponent<PdaComponent>(out var pdaComponent, _componentFactory) && pdaComponent.IdCard != null)
{
ProtoId<EntityPrototype> idProtoId = pdaComponent.IdCard;
if (!_prototypeManager.TryIndex<EntityPrototype>(idProtoId, out idProto))
{
Log.Warning($"Unable to find an idCard in {idProto}");
return false;
}
}

if (!idProto.TryGetComponent<PresetIdCardComponent>(out var idComponent, _componentFactory))
{
Log.Warning($"Unable to find presetIdCard for {idProto}");
continue;
}

ProtoId<JobPrototype> jobProtoId = idComponent.JobName ?? string.Empty;
if (jobProtoId == string.Empty)
{
Log.Warning($"Empty jobProtoId!");
return false;
}
virtualJob = jobProtoId;
Log.Debug($"Successfully outputted {virtualJob} from {idProto}");
return true;
}
}
Log.Warning($"All other options exhausted");
return false;
}

public void Respawn(ICommonSession player)
{
_mind.WipeMind(player);
Expand Down Expand Up @@ -500,7 +591,7 @@ public sealed class PlayerSpawnCompleteEvent : EntityEventArgs
{
public EntityUid Mob { get; }
public ICommonSession Player { get; }
public string? JobId { get; }
public JobComponent? Job { get; }
public bool LateJoin { get; }
public EntityUid Station { get; }
public HumanoidCharacterProfile Profile { get; }
Expand All @@ -510,15 +601,15 @@ public sealed class PlayerSpawnCompleteEvent : EntityEventArgs

public PlayerSpawnCompleteEvent(EntityUid mob,
ICommonSession player,
string? jobId,
JobComponent? job,
bool lateJoin,
int joinOrder,
EntityUid station,
HumanoidCharacterProfile profile)
{
Mob = mob;
Player = player;
JobId = jobId;
Job = job;
LateJoin = lateJoin;
Station = station;
Profile = profile;
Expand Down
5 changes: 3 additions & 2 deletions Content.Server/Station/Systems/StationSpawningSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public EntityUid SpawnPlayerMob(
EntityUid? entity = null)
{
_prototypeManager.TryIndex(job?.Prototype ?? string.Empty, out var prototype);
_prototypeManager.TryIndex(job?.VirtualJob?.Prototype ?? string.Empty, out var virtualJobPrototype); // DeltaV - Senior ID cards

// If we're not spawning a humanoid, we're gonna exit early without doing all the humanoid stuff.
if (prototype?.JobEntity != null)
Expand Down Expand Up @@ -212,7 +213,7 @@ public EntityUid SpawnPlayerMob(
if (profile != null)
{
if (prototype != null)
SetPdaAndIdCardData(entity.Value, profile.Name, prototype, station);
SetPdaAndIdCardData(entity.Value, profile.Name, virtualJobPrototype ?? prototype, station); //DeltaV - Senior ID cards

_humanoidSystem.LoadProfile(entity.Value, profile);
_metaSystem.SetEntityName(entity.Value, profile.Name);
Expand Down Expand Up @@ -258,7 +259,7 @@ public void SetPdaAndIdCardData(EntityUid entity, string characterName, JobProto
return;

_cardSystem.TryChangeFullName(cardId, characterName, card);
_cardSystem.TryChangeJobTitle(cardId, jobPrototype.LocalizedName, card);
_cardSystem.TryChangeJobTitle(cardId, jobPrototype.LocalizedName, card); // Delta V - Senior ID card, job names and icon should already be set via prototype

if (_prototypeManager.TryIndex(jobPrototype.Icon, out var jobIcon))
_cardSystem.TryChangeJobIcon(cardId, jobIcon, card);
Expand Down
13 changes: 11 additions & 2 deletions Content.Server/StationRecords/Systems/StationRecordsSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Content.Server.Forensics;
using Content.Server.GameTicking;
using Content.Shared.Inventory;
using Content.Shared.PDA;
using Content.Shared.Preferences;
using Content.Shared.Roles;
using Content.Shared.Roles.Jobs;
using Content.Shared.StationRecords;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
Expand Down Expand Up @@ -48,12 +50,18 @@ private void OnPlayerSpawn(PlayerSpawnCompleteEvent args)
if (!TryComp<StationRecordsComponent>(args.Station, out var stationRecords))
return;

CreateGeneralRecord(args.Station, args.Mob, args.Profile, args.JobId, stationRecords);
CreateGeneralRecord(args.Station, args.Mob, args.Profile, args.Job, stationRecords);
}

private void CreateGeneralRecord(EntityUid station, EntityUid player, HumanoidCharacterProfile profile,
string? jobId, StationRecordsComponent records)
JobComponent? job, StationRecordsComponent records)
{
_prototypeManager.TryIndex<JobPrototype>(job?.VirtualJob?.Prototype, out var a);
if (!_prototypeManager.TryIndex<JobPrototype>(job?.Prototype, out var b))
return;

ProtoId<JobPrototype> jobId = a?.ID ?? b.ID;
Log.Debug(jobId);
// TODO make PlayerSpawnCompleteEvent.JobId a ProtoId
if (string.IsNullOrEmpty(jobId)
|| !_prototypeManager.HasIndex<JobPrototype>(jobId))
Expand Down Expand Up @@ -133,6 +141,7 @@ public void CreateGeneralRecord(
Fingerprint = mobFingerprint,
DNA = dna
};
Log.Debug($"Record: {record.JobTitle}, {record.JobIcon}, {record.JobPrototype}");

var key = AddRecordEntry(station, record);
if (!key.IsValid())
Expand Down
3 changes: 3 additions & 0 deletions Content.Shared/Roles/JobPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public sealed partial class JobPrototype : IPrototype

[DataField]
public bool Whitelisted;

[DataField]
public bool EditorHidden;
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Content.Shared/Roles/Jobs/JobComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public sealed partial class JobComponent : Component
{
[DataField(required: true), AutoNetworkedField]
public ProtoId<JobPrototype>? Prototype;
[DataField]
public JobComponent? VirtualJob;
}
30 changes: 25 additions & 5 deletions Content.Shared/Roles/Jobs/SharedJobSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ private void SetupTrackerLookup()
// This breaks if you have N trackers to 1 JobId but future concern.
foreach (var job in _protoManager.EnumeratePrototypes<JobPrototype>())
{
if (_inverseTrackerLookup.ContainsKey(job.PlayTimeTracker)) continue; // DeltaV - we have N trackers to 1 JobId... (senior job names)

_inverseTrackerLookup.Add(job.PlayTimeTracker, job.ID);
}
}
Expand Down Expand Up @@ -118,6 +120,19 @@ public bool MindTryGetJob(
_prototypes.TryIndex(comp.Prototype, out prototype);
}

public bool MindTryGetVirtualJob( // DeltaV - Senior ID cards
[NotNullWhen(true)] EntityUid? mindId,
[NotNullWhen(true)] out JobComponent? comp,
[NotNullWhen(true)] out JobPrototype? virtualJob)
{
comp = null;
virtualJob = null;

return TryComp(mindId, out comp) &&
comp.VirtualJob != null &&
_prototypes.TryIndex(comp.VirtualJob.Prototype, out virtualJob);
}

public bool MindTryGetJobId([NotNullWhen(true)] EntityUid? mindId, out ProtoId<JobPrototype>? job)
{
if (!TryComp(mindId, out JobComponent? comp))
Expand All @@ -136,14 +151,19 @@ public bool MindTryGetJobId([NotNullWhen(true)] EntityUid? mindId, out ProtoId<J
/// </summary>
public bool MindTryGetJobName([NotNullWhen(true)] EntityUid? mindId, out string name)
{
if (MindTryGetJob(mindId, out _, out var prototype))
MindTryGetVirtualJob(mindId, out _, out var virtualJob);
if (!MindTryGetJob(mindId, out _, out var prototype))
{
name = prototype.LocalizedName;
return true;
name = Loc.GetString("generic-unknown-title");
return false;
}

name = Loc.GetString("generic-unknown-title");
return false;
name = virtualJob?.LocalizedName ?? string.Empty;
if (string.IsNullOrEmpty(name))
name = prototype.LocalizedName;

Log.Debug(name);
return true;
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions Resources/Locale/en-US/job/job-names.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ job-name-ertjanitor = ERT Janitor
job-name-boxer = Boxer
job-name-zookeeper = Zookeeper
job-name-visitor = Visitor
# DeltaV - Define senior job names for use in separate prototypes
job-name-seniorengineer = Senior Engineer
job-name-seniorphysician = Senior Physician
job-name-seniorresearcher = Senior Researcher
job-name-seniorofficer = Senior Officer

# Role timers - Make these alphabetical or I cut you
JobAtmosphericTechnician = Atmospheric Technician
Expand Down
Loading