AntagObjectivesSystem.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Content.Server.Antag.Components;
  2. using Content.Server.Objectives;
  3. using Content.Shared.Mind;
  4. using Content.Shared.Objectives.Systems;
  5. namespace Content.Server.Antag;
  6. /// <summary>
  7. /// Adds fixed objectives to an antag made with <c>AntagObjectivesComponent</c>.
  8. /// </summary>
  9. public sealed class AntagObjectivesSystem : EntitySystem
  10. {
  11. [Dependency] private readonly SharedMindSystem _mind = default!;
  12. public override void Initialize()
  13. {
  14. base.Initialize();
  15. SubscribeLocalEvent<AntagObjectivesComponent, AfterAntagEntitySelectedEvent>(OnAntagSelected);
  16. }
  17. private void OnAntagSelected(Entity<AntagObjectivesComponent> ent, ref AfterAntagEntitySelectedEvent args)
  18. {
  19. if (!_mind.TryGetMind(args.Session, out var mindId, out var mind))
  20. {
  21. Log.Error($"Antag {ToPrettyString(args.EntityUid):player} was selected by {ToPrettyString(ent):rule} but had no mind attached!");
  22. return;
  23. }
  24. foreach (var id in ent.Comp.Objectives)
  25. {
  26. _mind.TryAddObjective(mindId, mind, id);
  27. }
  28. }
  29. }