AdminEnchant.java 6.7 KB

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