1
0

SurvivorRuleSystem.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using Content.Server.Antag;
  2. using Content.Server.GameTicking.Rules.Components;
  3. using Content.Server.Mind;
  4. using Content.Server.Roles;
  5. using Content.Server.Shuttles.Systems;
  6. using Content.Shared.GameTicking.Components;
  7. using Content.Shared.Mind;
  8. using Content.Shared.Mobs.Systems;
  9. using Content.Shared.Survivor.Components;
  10. using Content.Shared.Tag;
  11. using Robust.Server.GameObjects;
  12. namespace Content.Server.GameTicking.Rules;
  13. public sealed class SurvivorRuleSystem : GameRuleSystem<SurvivorRuleComponent>
  14. {
  15. [Dependency] private readonly RoleSystem _role = default!;
  16. [Dependency] private readonly MindSystem _mind = default!;
  17. [Dependency] private readonly AntagSelectionSystem _antag = default!;
  18. [Dependency] private readonly TransformSystem _xform = default!;
  19. [Dependency] private readonly EmergencyShuttleSystem _eShuttle = default!;
  20. [Dependency] private readonly TagSystem _tag = default!;
  21. [Dependency] private readonly MobStateSystem _mobState = default!;
  22. public override void Initialize()
  23. {
  24. base.Initialize();
  25. SubscribeLocalEvent<SurvivorRoleComponent, GetBriefingEvent>(OnGetBriefing);
  26. }
  27. // TODO: Planned rework post wizard release when RandomGlobalSpawnSpell becomes a gamerule
  28. protected override void Started(EntityUid uid, SurvivorRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
  29. {
  30. base.Started(uid, component, gameRule, args);
  31. var allAliveHumanMinds = _mind.GetAliveHumans();
  32. foreach (var humanMind in allAliveHumanMinds)
  33. {
  34. if (!humanMind.Comp.OwnedEntity.HasValue)
  35. continue;
  36. var mind = humanMind.Owner;
  37. var ent = humanMind.Comp.OwnedEntity.Value;
  38. if (HasComp<SurvivorComponent>(mind) || _tag.HasTag(mind, "InvalidForSurvivorAntag"))
  39. continue;
  40. EnsureComp<SurvivorComponent>(mind);
  41. _role.MindAddRole(mind, "MindRoleSurvivor");
  42. _antag.SendBriefing(ent, Loc.GetString("survivor-role-greeting"), Color.Olive, null);
  43. }
  44. }
  45. private void OnGetBriefing(Entity<SurvivorRoleComponent> ent, ref GetBriefingEvent args)
  46. {
  47. args.Append(Loc.GetString("survivor-role-greeting"));
  48. }
  49. protected override void AppendRoundEndText(EntityUid uid,
  50. SurvivorRuleComponent component,
  51. GameRuleComponent gameRule,
  52. ref RoundEndTextAppendEvent args)
  53. {
  54. base.AppendRoundEndText(uid, component, gameRule, ref args);
  55. // Using this instead of alive antagonists to make checking for shuttle & if the ent is alive easier
  56. var existingSurvivors = AllEntityQuery<SurvivorComponent, MindComponent>();
  57. var deadSurvivors = 0;
  58. var aliveMarooned = 0;
  59. var aliveOnShuttle = 0;
  60. var eShuttle = _eShuttle.GetShuttle();
  61. while (existingSurvivors.MoveNext(out _, out _, out var mindComp))
  62. {
  63. // If their brain is gone or they respawned/became a ghost role
  64. if (mindComp.CurrentEntity is null)
  65. {
  66. deadSurvivors++;
  67. continue;
  68. }
  69. var survivor = mindComp.CurrentEntity.Value;
  70. if (!_mobState.IsAlive(survivor))
  71. {
  72. deadSurvivors++;
  73. continue;
  74. }
  75. if (eShuttle != null && eShuttle.Value.IsValid() && (Transform(eShuttle.Value).MapID == _xform.GetMapCoordinates(survivor).MapId))
  76. {
  77. aliveOnShuttle++;
  78. continue;
  79. }
  80. aliveMarooned++;
  81. }
  82. args.AddLine(Loc.GetString("survivor-round-end-dead-count", ("deadCount", deadSurvivors)));
  83. args.AddLine(Loc.GetString("survivor-round-end-alive-count", ("aliveCount", aliveMarooned)));
  84. args.AddLine(Loc.GetString("survivor-round-end-alive-on-shuttle-count", ("aliveCount", aliveOnShuttle)));
  85. // Player manifest at EOR shows who's a survivor so no need for extra info here.
  86. }
  87. }