1
0

JobSystem.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Globalization;
  2. using Content.Server.Chat.Managers;
  3. using Content.Server.Mind;
  4. using Content.Shared.Mind;
  5. using Content.Shared.Roles;
  6. using Content.Shared.Roles.Jobs;
  7. namespace Content.Server.Roles.Jobs;
  8. /// <summary>
  9. /// Handles the job data on mind entities.
  10. /// </summary>
  11. public sealed class JobSystem : SharedJobSystem
  12. {
  13. [Dependency] private readonly IChatManager _chat = default!;
  14. [Dependency] private readonly MindSystem _mind = default!;
  15. [Dependency] private readonly RoleSystem _roles = default!;
  16. public override void Initialize()
  17. {
  18. base.Initialize();
  19. SubscribeLocalEvent<RoleAddedEvent>(OnRoleAddedEvent);
  20. SubscribeLocalEvent<RoleRemovedEvent>(OnRoleRemovedEvent);
  21. }
  22. private void OnRoleAddedEvent(RoleAddedEvent args)
  23. {
  24. MindOnDoGreeting(args.MindId, args.Mind, args);
  25. if (args.RoleTypeUpdate)
  26. _roles.RoleUpdateMessage(args.Mind);
  27. }
  28. private void OnRoleRemovedEvent(RoleRemovedEvent args)
  29. {
  30. if (args.RoleTypeUpdate)
  31. _roles.RoleUpdateMessage(args.Mind);
  32. }
  33. private void MindOnDoGreeting(EntityUid mindId, MindComponent component, RoleAddedEvent args)
  34. {
  35. if (args.Silent)
  36. return;
  37. if (!_mind.TryGetSession(mindId, out var session))
  38. return;
  39. if (!MindTryGetJob(mindId, out var prototype))
  40. return;
  41. _chat.DispatchServerMessage(session, Loc.GetString("job-greet-introduce-job-name",
  42. ("jobName", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(prototype.LocalizedName))));
  43. if (prototype.RequireAdminNotify)
  44. _chat.DispatchServerMessage(session, Loc.GetString("job-greet-important-disconnect-admin-notify"));
  45. //_chat.DispatchServerMessage(session, Loc.GetString("job-greet-supervisors-warning", ("jobName", prototype.LocalizedName), ("supervisors", Loc.GetString(prototype.Supervisors))));
  46. }
  47. public void MindAddJob(EntityUid mindId, string jobPrototypeId)
  48. {
  49. if (MindHasJobWithId(mindId, jobPrototypeId))
  50. return;
  51. _roles.MindAddJobRole(mindId, null, false, jobPrototypeId);
  52. }
  53. }