PolyOthersArtifactSystem.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Content.Server.Polymorph.Systems;
  2. using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
  3. using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
  4. using Content.Shared.Humanoid;
  5. using Content.Shared.Mobs.Systems;
  6. using Robust.Shared.Audio.Systems;
  7. namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
  8. public sealed class PolyOthersArtifactSystem : EntitySystem
  9. {
  10. [Dependency] private readonly EntityLookupSystem _lookup = default!;
  11. [Dependency] private readonly MobStateSystem _mob = default!;
  12. [Dependency] private readonly PolymorphSystem _poly = default!;
  13. [Dependency] private readonly SharedAudioSystem _audio = default!;
  14. /// <summary>
  15. /// On effect trigger polymorphs targets in range.
  16. /// </summary>
  17. public override void Initialize()
  18. {
  19. SubscribeLocalEvent<PolyOthersArtifactComponent, ArtifactActivatedEvent>(OnActivate);
  20. }
  21. /// <summary>
  22. /// Provided target is alive and is not a zombie, polymorphs the target.
  23. /// </summary>
  24. private void OnActivate(Entity<PolyOthersArtifactComponent> ent, ref ArtifactActivatedEvent args)
  25. {
  26. var xform = Transform(ent);
  27. var humanoids = new HashSet<Entity<HumanoidAppearanceComponent>>();
  28. _lookup.GetEntitiesInRange(xform.Coordinates, ent.Comp.Range, humanoids);
  29. foreach (var comp in humanoids)
  30. {
  31. var target = comp.Owner;
  32. if (_mob.IsAlive(target))
  33. {
  34. _poly.PolymorphEntity(target, ent.Comp.PolymorphPrototypeName);
  35. _audio.PlayPvs(ent.Comp.PolySound, ent);
  36. }
  37. }
  38. }
  39. }