1
0

CharacterInfoSystem.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Content.Server.Mind;
  2. using Content.Server.Roles;
  3. using Content.Server.Roles.Jobs;
  4. using Content.Shared.CharacterInfo;
  5. using Content.Shared.Objectives;
  6. using Content.Shared.Objectives.Components;
  7. using Content.Shared.Objectives.Systems;
  8. namespace Content.Server.CharacterInfo;
  9. public sealed class CharacterInfoSystem : EntitySystem
  10. {
  11. [Dependency] private readonly JobSystem _jobs = default!;
  12. [Dependency] private readonly MindSystem _minds = default!;
  13. [Dependency] private readonly RoleSystem _roles = default!;
  14. [Dependency] private readonly SharedObjectivesSystem _objectives = default!;
  15. public override void Initialize()
  16. {
  17. base.Initialize();
  18. SubscribeNetworkEvent<RequestCharacterInfoEvent>(OnRequestCharacterInfoEvent);
  19. }
  20. private void OnRequestCharacterInfoEvent(RequestCharacterInfoEvent msg, EntitySessionEventArgs args)
  21. {
  22. if (!args.SenderSession.AttachedEntity.HasValue
  23. || args.SenderSession.AttachedEntity != GetEntity(msg.NetEntity))
  24. return;
  25. var entity = args.SenderSession.AttachedEntity.Value;
  26. var objectives = new Dictionary<string, List<ObjectiveInfo>>();
  27. var jobTitle = Loc.GetString("character-info-no-profession");
  28. string? briefing = null;
  29. if (_minds.TryGetMind(entity, out var mindId, out var mind))
  30. {
  31. // Get objectives
  32. foreach (var objective in mind.Objectives)
  33. {
  34. var info = _objectives.GetInfo(objective, mindId, mind);
  35. if (info == null)
  36. continue;
  37. // group objectives by their issuer
  38. var issuer = Comp<ObjectiveComponent>(objective).LocIssuer;
  39. if (!objectives.ContainsKey(issuer))
  40. objectives[issuer] = new List<ObjectiveInfo>();
  41. objectives[issuer].Add(info.Value);
  42. }
  43. if (_jobs.MindTryGetJobName(mindId, out var jobName))
  44. jobTitle = jobName;
  45. // Get briefing
  46. briefing = _roles.MindGetBriefing(mindId);
  47. }
  48. RaiseNetworkEvent(new CharacterInfoEvent(GetNetEntity(entity), jobTitle, objectives, briefing), args.SenderSession);
  49. }
  50. }