AdminPolymorph.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import com.l2jserver.gameserver.data.xml.impl.TransformData;
  21. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  27. import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
  28. import com.l2jserver.gameserver.util.Util;
  29. /**
  30. * Polymorph admin command implementation.
  31. * @author Zoey76
  32. */
  33. public class AdminPolymorph implements IAdminCommandHandler
  34. {
  35. private static final String[] ADMIN_COMMANDS =
  36. {
  37. "admin_polymorph",
  38. "admin_unpolymorph",
  39. "admin_transform",
  40. "admin_untransform",
  41. "admin_transform_menu",
  42. };
  43. @Override
  44. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  45. {
  46. if (command.equals("admin_transform_menu"))
  47. {
  48. AdminHtml.showAdminHtml(activeChar, "transform.htm");
  49. return true;
  50. }
  51. else if (command.startsWith("admin_untransform"))
  52. {
  53. L2Object obj = activeChar.getTarget();
  54. if (obj instanceof L2Character)
  55. {
  56. ((L2Character) obj).stopTransformation(true);
  57. }
  58. else
  59. {
  60. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  61. }
  62. }
  63. else if (command.startsWith("admin_transform"))
  64. {
  65. final L2Object obj = activeChar.getTarget();
  66. if ((obj == null) || !obj.isPlayer())
  67. {
  68. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  69. return false;
  70. }
  71. final L2PcInstance player = obj.getActingPlayer();
  72. if (activeChar.isSitting())
  73. {
  74. activeChar.sendPacket(SystemMessageId.CANNOT_TRANSFORM_WHILE_SITTING);
  75. return false;
  76. }
  77. if (player.isTransformed() || player.isInStance())
  78. {
  79. if (!command.contains(" "))
  80. {
  81. player.untransform();
  82. return true;
  83. }
  84. activeChar.sendPacket(SystemMessageId.YOU_ALREADY_POLYMORPHED_AND_CANNOT_POLYMORPH_AGAIN);
  85. return false;
  86. }
  87. if (player.isInWater())
  88. {
  89. activeChar.sendPacket(SystemMessageId.YOU_CANNOT_POLYMORPH_INTO_THE_DESIRED_FORM_IN_WATER);
  90. return false;
  91. }
  92. if (player.isFlyingMounted() || player.isMounted())
  93. {
  94. activeChar.sendPacket(SystemMessageId.YOU_CANNOT_POLYMORPH_WHILE_RIDING_A_PET);
  95. return false;
  96. }
  97. final String[] parts = command.split(" ");
  98. if ((parts.length != 2) || !Util.isDigit(parts[1]))
  99. {
  100. activeChar.sendMessage("Usage: //transform <id>");
  101. return false;
  102. }
  103. final int id = Integer.parseInt(parts[1]);
  104. if (!TransformData.getInstance().transformPlayer(id, player))
  105. {
  106. player.sendMessage("Unknown transformation ID: " + id);
  107. return false;
  108. }
  109. }
  110. if (command.startsWith("admin_polymorph"))
  111. {
  112. final String[] parts = command.split(" ");
  113. if ((parts.length < 2) || !Util.isDigit(parts[1]))
  114. {
  115. activeChar.sendMessage("Usage: //polymorph [type] <id>");
  116. return false;
  117. }
  118. if (parts.length > 2)
  119. {
  120. doPolymorph(activeChar, activeChar.getTarget(), parts[2], parts[1]);
  121. }
  122. else
  123. {
  124. doPolymorph(activeChar, activeChar.getTarget(), parts[1], "npc");
  125. }
  126. }
  127. else if (command.equals("admin_unpolymorph"))
  128. {
  129. doUnPolymorph(activeChar, activeChar.getTarget());
  130. }
  131. return true;
  132. }
  133. @Override
  134. public String[] getAdminCommandList()
  135. {
  136. return ADMIN_COMMANDS;
  137. }
  138. /**
  139. * Polymorph a creature.
  140. * @param activeChar the active Game Master
  141. * @param obj the target
  142. * @param id the polymorph ID
  143. * @param type the polymorph type
  144. */
  145. private static void doPolymorph(L2PcInstance activeChar, L2Object obj, String id, String type)
  146. {
  147. if (obj != null)
  148. {
  149. obj.getPoly().setPolyInfo(type, id);
  150. // animation
  151. if (obj instanceof L2Character)
  152. {
  153. L2Character Char = (L2Character) obj;
  154. MagicSkillUse msk = new MagicSkillUse(Char, 1008, 1, 4000, 0);
  155. Char.broadcastPacket(msk);
  156. SetupGauge sg = new SetupGauge(0, 4000);
  157. Char.sendPacket(sg);
  158. }
  159. // end of animation
  160. obj.decayMe();
  161. obj.spawnMe(obj.getX(), obj.getY(), obj.getZ());
  162. activeChar.sendMessage("Polymorph succeed");
  163. }
  164. else
  165. {
  166. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  167. }
  168. }
  169. /**
  170. * Unpolymorh a creature.
  171. * @param activeChar the active Game Master
  172. * @param target the target
  173. */
  174. private static void doUnPolymorph(L2PcInstance activeChar, L2Object target)
  175. {
  176. if (target != null)
  177. {
  178. target.getPoly().setPolyInfo(null, "1");
  179. target.decayMe();
  180. target.spawnMe(target.getX(), target.getY(), target.getZ());
  181. activeChar.sendMessage("Unpolymorph succeed");
  182. }
  183. else
  184. {
  185. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  186. }
  187. }
  188. }