Files
crystall-punk-14/Content.Server/CharacterInfo/CharacterInfoSystem.cs

57 lines
2.0 KiB
C#
Raw Normal View History

using Content.Server.Mind;
2021-12-11 15:12:55 -08:00
using Content.Server.Roles;
using Content.Server.Roles.Jobs;
2021-12-11 15:12:55 -08:00
using Content.Shared.CharacterInfo;
using Content.Shared.Objectives;
namespace Content.Server.CharacterInfo;
public sealed class CharacterInfoSystem : EntitySystem
2021-12-11 15:12:55 -08:00
{
[Dependency] private readonly JobSystem _jobs = default!;
[Dependency] private readonly MindSystem _minds = default!;
[Dependency] private readonly RoleSystem _roles = default!;
2021-12-11 15:12:55 -08:00
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<RequestCharacterInfoEvent>(OnRequestCharacterInfoEvent);
}
private void OnRequestCharacterInfoEvent(RequestCharacterInfoEvent msg, EntitySessionEventArgs args)
{
if (!args.SenderSession.AttachedEntity.HasValue
|| args.SenderSession.AttachedEntity != msg.EntityUid)
return;
var entity = args.SenderSession.AttachedEntity.Value;
var conditions = new Dictionary<string, List<ConditionInfo>>();
var jobTitle = "No Profession";
string? briefing = null;
if (_minds.TryGetMind(entity, out var mindId, out var mind))
2021-12-11 15:12:55 -08:00
{
// Get objectives
foreach (var objective in mind.AllObjectives)
{
if (!conditions.ContainsKey(objective.Prototype.Issuer))
conditions[objective.Prototype.Issuer] = new List<ConditionInfo>();
foreach (var condition in objective.Conditions)
{
conditions[objective.Prototype.Issuer].Add(new ConditionInfo(condition.Title,
condition.Description, condition.Icon, condition.Progress));
}
}
if (_jobs.MindTryGetJobName(mindId, out var jobName))
jobTitle = jobName;
// Get briefing
briefing = _roles.MindGetBriefing(mindId);
2021-12-11 15:12:55 -08:00
}
RaiseNetworkEvent(new CharacterInfoEvent(entity, jobTitle, conditions, briefing), args.SenderSession);
2021-12-11 15:12:55 -08:00
}
}