NinjaGlovesSystem.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Content.Server.Ninja.Events;
  2. using Content.Shared.Mind;
  3. using Content.Shared.Objectives.Systems;
  4. using Content.Shared.Ninja.Components;
  5. using Content.Shared.Ninja.Systems;
  6. namespace Content.Server.Ninja.Systems;
  7. /// <summary>
  8. /// Handles the toggle gloves action.
  9. /// </summary>
  10. public sealed class NinjaGlovesSystem : SharedNinjaGlovesSystem
  11. {
  12. [Dependency] private readonly SharedMindSystem _mind = default!;
  13. [Dependency] private readonly SharedObjectivesSystem _objectives = default!;
  14. [Dependency] private readonly SpaceNinjaSystem _ninja = default!;
  15. protected override void EnableGloves(Entity<NinjaGlovesComponent> ent, Entity<SpaceNinjaComponent> user)
  16. {
  17. base.EnableGloves(ent, user);
  18. // can't use abilities if suit is not equipped, this is checked elsewhere but just making sure to satisfy nullability
  19. if (user.Comp.Suit is not {} suit)
  20. return;
  21. if (!_mind.TryGetMind(user, out var mindId, out var mind))
  22. return;
  23. foreach (var ability in ent.Comp.Abilities)
  24. {
  25. // non-objective abilities are added in shared already
  26. if (ability.Objective is not {} objId)
  27. continue;
  28. // prevent doing an objective multiple times by toggling gloves after doing them
  29. // if it's not tied to an objective always add them anyway
  30. if (!_mind.TryFindObjective((mindId, mind), objId, out var obj))
  31. {
  32. Log.Error($"Ninja glove ability of {ent} referenced missing objective {ability.Objective} of {_mind.MindOwnerLoggingString(mind)}");
  33. continue;
  34. }
  35. if (!_objectives.IsCompleted(obj.Value, (mindId, mind)))
  36. EntityManager.AddComponents(user, ability.Components);
  37. }
  38. // let abilities that use battery power work
  39. if (_ninja.GetNinjaBattery(user, out var battery, out var _))
  40. {
  41. var ev = new NinjaBatteryChangedEvent(battery.Value, suit);
  42. RaiseLocalEvent(user, ref ev);
  43. RaiseLocalEvent(suit, ref ev);
  44. }
  45. }
  46. }