AdminEnchant.java 6.4 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.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.item.instance.L2ItemInstance;
  22. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. import com.l2jserver.gameserver.network.serverpackets.CharInfo;
  25. import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
  26. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. import com.l2jserver.gameserver.network.serverpackets.UserInfo;
  29. /**
  30. * This class handles following admin commands:
  31. * - enchant_armor
  32. *
  33. * @version $Revision: 1.3.2.1.2.10 $ $Date: 2005/08/24 21:06:06 $
  34. */
  35. public class AdminEnchant implements IAdminCommandHandler
  36. {
  37. private static Logger _log = Logger.getLogger(AdminEnchant.class.getName());
  38. private static final String[] ADMIN_COMMANDS =
  39. {
  40. "admin_seteh",//6
  41. "admin_setec",//10
  42. "admin_seteg",//9
  43. "admin_setel",//11
  44. "admin_seteb",//12
  45. "admin_setew",//7
  46. "admin_setes",//8
  47. "admin_setle",//1
  48. "admin_setre",//2
  49. "admin_setlf",//4
  50. "admin_setrf",//5
  51. "admin_seten",//3
  52. "admin_setun",//0
  53. "admin_setba",//13
  54. "admin_setbe",
  55. "admin_enchant"
  56. };
  57. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  58. {
  59. if (command.equals("admin_enchant"))
  60. {
  61. showMainPage(activeChar);
  62. }
  63. else
  64. {
  65. int armorType = -1;
  66. if (command.startsWith("admin_seteh"))
  67. armorType = Inventory.PAPERDOLL_HEAD;
  68. else if (command.startsWith("admin_setec"))
  69. armorType = Inventory.PAPERDOLL_CHEST;
  70. else if (command.startsWith("admin_seteg"))
  71. armorType = Inventory.PAPERDOLL_GLOVES;
  72. else if (command.startsWith("admin_seteb"))
  73. armorType = Inventory.PAPERDOLL_FEET;
  74. else if (command.startsWith("admin_setel"))
  75. armorType = Inventory.PAPERDOLL_LEGS;
  76. else if (command.startsWith("admin_setew"))
  77. armorType = Inventory.PAPERDOLL_RHAND;
  78. else if (command.startsWith("admin_setes"))
  79. armorType = Inventory.PAPERDOLL_LHAND;
  80. else if (command.startsWith("admin_setle"))
  81. armorType = Inventory.PAPERDOLL_LEAR;
  82. else if (command.startsWith("admin_setre"))
  83. armorType = Inventory.PAPERDOLL_REAR;
  84. else if (command.startsWith("admin_setlf"))
  85. armorType = Inventory.PAPERDOLL_LFINGER;
  86. else if (command.startsWith("admin_setrf"))
  87. armorType = Inventory.PAPERDOLL_RFINGER;
  88. else if (command.startsWith("admin_seten"))
  89. armorType = Inventory.PAPERDOLL_NECK;
  90. else if (command.startsWith("admin_setun"))
  91. armorType = Inventory.PAPERDOLL_UNDER;
  92. else if (command.startsWith("admin_setba"))
  93. armorType = Inventory.PAPERDOLL_CLOAK;
  94. else if (command.startsWith("admin_setbe"))
  95. armorType = Inventory.PAPERDOLL_BELT;
  96. if (armorType != -1)
  97. {
  98. try
  99. {
  100. int ench = Integer.parseInt(command.substring(12));
  101. // check value
  102. if (ench < 0 || ench > 65535)
  103. activeChar.sendMessage("You must set the enchant level to be between 0-65535.");
  104. else
  105. setEnchant(activeChar, ench, armorType);
  106. }
  107. catch (StringIndexOutOfBoundsException e)
  108. {
  109. if (Config.DEVELOPER)
  110. _log.warning("Set enchant error: " + e);
  111. activeChar.sendMessage("Please specify a new enchant value.");
  112. }
  113. catch (NumberFormatException e)
  114. {
  115. if (Config.DEVELOPER)
  116. _log.warning("Set enchant error: " + e);
  117. activeChar.sendMessage("Please specify a valid new enchant value.");
  118. }
  119. }
  120. // show the enchant menu after an action
  121. showMainPage(activeChar);
  122. }
  123. return true;
  124. }
  125. private void setEnchant(L2PcInstance activeChar, int ench, int armorType)
  126. {
  127. // get the target
  128. L2Object target = activeChar.getTarget();
  129. if (target == null)
  130. target = activeChar;
  131. L2PcInstance player = null;
  132. if (target instanceof L2PcInstance)
  133. {
  134. player = (L2PcInstance) target;
  135. }
  136. else
  137. {
  138. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  139. return;
  140. }
  141. // now we need to find the equipped weapon of the targeted character...
  142. int curEnchant = 0; // display purposes only
  143. L2ItemInstance itemInstance = null;
  144. // only attempt to enchant if there is a weapon equipped
  145. L2ItemInstance parmorInstance = player.getInventory().getPaperdollItem(armorType);
  146. if (parmorInstance != null && parmorInstance.getLocationSlot() == armorType)
  147. {
  148. itemInstance = parmorInstance;
  149. }
  150. if (itemInstance != null)
  151. {
  152. curEnchant = itemInstance.getEnchantLevel();
  153. // set enchant value
  154. player.getInventory().unEquipItemInSlot(armorType);
  155. itemInstance.setEnchantLevel(ench);
  156. player.getInventory().equipItem(itemInstance);
  157. // send packets
  158. InventoryUpdate iu = new InventoryUpdate();
  159. iu.addModifiedItem(itemInstance);
  160. player.sendPacket(iu);
  161. player.broadcastPacket(new CharInfo(player));
  162. player.sendPacket(new UserInfo(player));
  163. player.broadcastPacket(new ExBrExtraUserInfo(player));
  164. // informations
  165. activeChar.sendMessage("Changed enchantment of " + player.getName() + "'s " + itemInstance.getItem().getName() + " from " + curEnchant + " to " + ench + ".");
  166. player.sendMessage("Admin has changed the enchantment of your " + itemInstance.getItem().getName() + " from " + curEnchant + " to " + ench + ".");
  167. }
  168. }
  169. private void showMainPage(L2PcInstance activeChar)
  170. {
  171. AdminHelpPage.showHelpPage(activeChar, "enchant.htm");
  172. }
  173. public String[] getAdminCommandList()
  174. {
  175. return ADMIN_COMMANDS;
  176. }
  177. }