CatStation/Content.Server/CharacterInfo/CharacterInfoSystem.cs
Oleksandr 1c680180a9
Fix highlights don't work for other languages (#41062)
* Update base system

* Update highlights.ftl

* Update highlights.ftl

* Fix some mistakes

* Fix lawyer and libriab hightlight... Arghhg

* Change string jobId to JobPrototype. Remove JobName from CharacterData

* Fix to use ProtoId<JobPrototype>

* Fixes for qrwas!

* fix using

* fix integration tests

* Update ChatHighlightTest.cs

---------

Co-authored-by: SlamBamActionman <slambamactionman@gmail.com>
2026-07-30 14:57:59 +00:00

69 lines
2.5 KiB
C#

using Content.Server.Mind;
using Content.Server.Roles;
using Content.Server.Roles.Jobs;
using Content.Shared.CharacterInfo;
using Content.Shared.Objectives;
using Content.Shared.Objectives.Components;
using Content.Shared.Objectives.Systems;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;
namespace Content.Server.CharacterInfo;
public sealed partial class CharacterInfoSystem : EntitySystem
{
[Dependency] private JobSystem _jobs = default!;
[Dependency] private MindSystem _minds = default!;
[Dependency] private RoleSystem _roles = default!;
[Dependency] private SharedObjectivesSystem _objectives = default!;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<RequestCharacterInfoEvent>(OnRequestCharacterInfoEvent);
}
private void OnRequestCharacterInfoEvent(RequestCharacterInfoEvent msg, EntitySessionEventArgs args)
{
if (!args.SenderSession.AttachedEntity.HasValue
|| args.SenderSession.AttachedEntity != GetEntity(msg.NetEntity))
return;
var entity = args.SenderSession.AttachedEntity.Value;
var objectives = new Dictionary<string, List<ObjectiveInfo>>();
string? briefing = null;
ProtoId<JobPrototype>? job = null;
if (_minds.TryGetMind(entity, out var mindId, out var mind))
{
// Get objectives
foreach (var objective in mind.Objectives)
{
var info = _objectives.GetInfo(objective, mindId, mind);
if (info == null)
continue;
if (!ProtoMan.TryIndex(Comp<ObjectiveComponent>(objective).Issuer, out var issuerProto))
{
Log.Error($"Found incorrect objective issuer {issuerProto} when generating character info for objective {MetaData(objective).EntityPrototype}.");
continue;
}
// group objectives by their issuer
var issuer = issuerProto.LocalizedName;
if (!objectives.ContainsKey(issuer))
objectives[issuer] = new List<ObjectiveInfo>();
objectives[issuer].Add(info.Value);
}
if (_jobs.MindTryGetJob(mindId, out var j))
job = j;
// Get briefing
briefing = _roles.MindGetBriefing(mindId);
}
RaiseNetworkEvent(new CharacterInfoEvent(GetNetEntity(entity), objectives, briefing, job), args.SenderSession);
}
}