1
0

PolymorphCommand.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Linq;
  2. using Content.Server.Administration;
  3. using Content.Server.Polymorph.Systems;
  4. using Content.Shared.Administration;
  5. using Content.Shared.Polymorph;
  6. using Robust.Shared.Prototypes;
  7. using Robust.Shared.Toolshed;
  8. namespace Content.Server.Polymorph.Toolshed;
  9. /// <summary>
  10. /// Polymorphs the given entity(s) into the target morph.
  11. /// </summary>
  12. [ToolshedCommand, AdminCommand(AdminFlags.Fun)]
  13. public sealed class PolymorphCommand : ToolshedCommand
  14. {
  15. private PolymorphSystem? _system;
  16. [Dependency] private IPrototypeManager _proto = default!;
  17. [CommandImplementation]
  18. public EntityUid? Polymorph(
  19. [PipedArgument] EntityUid input,
  20. ProtoId<PolymorphPrototype> protoId
  21. )
  22. {
  23. _system ??= GetSys<PolymorphSystem>();
  24. if (!_proto.TryIndex(protoId, out var prototype))
  25. return null;
  26. return _system.PolymorphEntity(input, prototype.Configuration);
  27. }
  28. [CommandImplementation]
  29. public IEnumerable<EntityUid> Polymorph(
  30. [PipedArgument] IEnumerable<EntityUid> input,
  31. ProtoId<PolymorphPrototype> protoId
  32. )
  33. => input.Select(x => Polymorph(x, protoId)).Where(x => x is not null).Select(x => (EntityUid)x!);
  34. }