GibOnRoundEndSystem.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Content.Shared.GameTicking;
  2. using Content.Shared.Gibbing.Components;
  3. using Content.Shared.Mind;
  4. using Content.Shared.Objectives.Systems;
  5. using Content.Server.Body.Systems;
  6. namespace Content.Server.Gibbing.Systems;
  7. public sealed class GibOnRoundEndSystem : EntitySystem
  8. {
  9. [Dependency] private readonly BodySystem _body = default!;
  10. [Dependency] private readonly SharedMindSystem _mind = default!;
  11. [Dependency] private readonly SharedObjectivesSystem _objectives = default!;
  12. public override void Initialize()
  13. {
  14. base.Initialize();
  15. // this is raised after RoundEndTextAppendEvent, so they can successfully greentext before we gib them
  16. SubscribeLocalEvent<RoundEndMessageEvent>(OnRoundEnd);
  17. }
  18. private void OnRoundEnd(RoundEndMessageEvent args)
  19. {
  20. var gibQuery = EntityQueryEnumerator<GibOnRoundEndComponent>();
  21. // gib everyone with the component
  22. while (gibQuery.MoveNext(out var uid, out var gibComp))
  23. {
  24. var gib = false;
  25. // if they fulfill all objectives given in the component they are not gibbed
  26. if (_mind.TryGetMind(uid, out var mindId, out var mindComp))
  27. {
  28. foreach (var objectiveId in gibComp.PreventGibbingObjectives)
  29. {
  30. if (!_mind.TryFindObjective((mindId, mindComp), objectiveId, out var objective)
  31. || !_objectives.IsCompleted(objective.Value, (mindId, mindComp)))
  32. {
  33. gib = true;
  34. break;
  35. }
  36. }
  37. }
  38. else
  39. gib = true;
  40. if (!gib)
  41. continue;
  42. if (gibComp.SpawnProto != null)
  43. SpawnAtPosition(gibComp.SpawnProto, Transform(uid).Coordinates);
  44. _body.GibBody(uid, splatModifier: 5f);
  45. }
  46. }
  47. }