AdminPolymorph.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.admincommandhandlers;
  16. import java.util.StringTokenizer;
  17. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  18. import com.l2jserver.gameserver.instancemanager.TransformationManager;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  24. import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. /**
  27. * This class handles following admin commands: polymorph
  28. *
  29. * @version $Revision: 1.2.2.1.2.4 $ $Date: 2007/07/31 10:05:56 $
  30. */
  31. public class AdminPolymorph implements IAdminCommandHandler
  32. {
  33. private static final String[] ADMIN_COMMANDS =
  34. {
  35. "admin_polymorph",
  36. "admin_unpolymorph",
  37. "admin_polymorph_menu",
  38. "admin_unpolymorph_menu",
  39. "admin_transform",
  40. "admin_untransform",
  41. "admin_transform_menu",
  42. "admin_untransform_menu",
  43. };
  44. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  45. {
  46. if (activeChar.isMounted())
  47. {
  48. activeChar.sendMessage("You can't transform while mounted, please dismount and try again.");
  49. return false;
  50. }
  51. 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(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  61. }
  62. }
  63. else if (command.startsWith("admin_transform"))
  64. {
  65. L2Object obj = activeChar.getTarget();
  66. if (obj instanceof L2PcInstance)
  67. {
  68. L2PcInstance cha = (L2PcInstance) obj;
  69. String[] parts = command.split(" ");
  70. if (parts.length >= 2)
  71. {
  72. try
  73. {
  74. int id = Integer.parseInt(parts[1]);
  75. if (!TransformationManager.getInstance().transformPlayer(id, cha))
  76. {
  77. cha.sendMessage("Unknow transformation id: " + id);
  78. }
  79. }
  80. catch (NumberFormatException e)
  81. {
  82. activeChar.sendMessage("Usage: //transform <id>");
  83. }
  84. }
  85. else if (parts.length == 1)
  86. cha.untransform();
  87. else
  88. {
  89. activeChar.sendMessage("Usage: //transform <id>");
  90. }
  91. }
  92. else
  93. {
  94. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  95. }
  96. }
  97. if (command.startsWith("admin_polymorph"))
  98. {
  99. StringTokenizer st = new StringTokenizer(command);
  100. L2Object target = activeChar.getTarget();
  101. try
  102. {
  103. st.nextToken();
  104. String p1 = st.nextToken();
  105. if (st.hasMoreTokens())
  106. {
  107. String p2 = st.nextToken();
  108. doPolymorph(activeChar, target, p2, p1);
  109. }
  110. else
  111. doPolymorph(activeChar, target, p1, "npc");
  112. }
  113. catch (Exception e)
  114. {
  115. activeChar.sendMessage("Usage: //polymorph [type] <id>");
  116. }
  117. }
  118. else if (command.equals("admin_unpolymorph"))
  119. {
  120. doUnpoly(activeChar, activeChar.getTarget());
  121. }
  122. if (command.contains("_menu"))
  123. {
  124. showMainPage(activeChar, command);
  125. }
  126. return true;
  127. }
  128. public String[] getAdminCommandList()
  129. {
  130. return ADMIN_COMMANDS;
  131. }
  132. /**
  133. * @param activeChar
  134. * @param target
  135. * @param id
  136. * @param type
  137. */
  138. private void doPolymorph(L2PcInstance activeChar, L2Object obj, String id, String type)
  139. {
  140. if (obj != null)
  141. {
  142. obj.getPoly().setPolyInfo(type, id);
  143. //animation
  144. if (obj instanceof L2Character)
  145. {
  146. L2Character Char = (L2Character) obj;
  147. MagicSkillUse msk = new MagicSkillUse(Char, 1008, 1, 4000, 0);
  148. Char.broadcastPacket(msk);
  149. SetupGauge sg = new SetupGauge(0, 4000);
  150. Char.sendPacket(sg);
  151. }
  152. //end of animation
  153. obj.decayMe();
  154. obj.spawnMe(obj.getX(), obj.getY(), obj.getZ());
  155. activeChar.sendMessage("Polymorph succeed");
  156. }
  157. else
  158. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  159. }
  160. /**
  161. * @param activeChar
  162. * @param target
  163. */
  164. private void doUnpoly(L2PcInstance activeChar, L2Object target)
  165. {
  166. if (target != null)
  167. {
  168. target.getPoly().setPolyInfo(null, "1");
  169. target.decayMe();
  170. target.spawnMe(target.getX(), target.getY(), target.getZ());
  171. activeChar.sendMessage("Unpolymorph succeed");
  172. }
  173. else
  174. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  175. }
  176. private void showMainPage(L2PcInstance activeChar, String command)
  177. {
  178. if (command.contains("transform"))
  179. AdminHelpPage.showHelpPage(activeChar, "transform.htm");
  180. else if (command.contains("abnormal"))
  181. AdminHelpPage.showHelpPage(activeChar, "abnormal.htm");
  182. else
  183. AdminHelpPage.showHelpPage(activeChar, "effects_menu.htm");
  184. }
  185. }