AdminElement.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2, or (at your option)
  5. * any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. * 02111-1307, USA.
  16. *
  17. * http://www.gnu.org/copyleft/gpl.html
  18. */
  19. package handlers.admincommandhandlers;
  20. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  21. import com.l2jserver.gameserver.model.Elementals;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  25. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  28. /**
  29. * This class handles following admin commands: - delete = deletes target
  30. *
  31. * @version $Revision: 1.2.2.1.2.4 $ $Date: 2005/04/11 10:05:56 $
  32. */
  33. public class AdminElement implements IAdminCommandHandler
  34. {
  35. private static final String[] ADMIN_COMMANDS =
  36. {
  37. "admin_setlh",
  38. "admin_setlc",
  39. "admin_setll",
  40. "admin_setlg",
  41. "admin_setlb",
  42. "admin_setlw",
  43. "admin_setls"
  44. };
  45. @Override
  46. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  47. {
  48. int armorType = -1;
  49. if (command.startsWith("admin_setlh"))
  50. armorType = Inventory.PAPERDOLL_HEAD;
  51. else if (command.startsWith("admin_setlc"))
  52. armorType = Inventory.PAPERDOLL_CHEST;
  53. else if (command.startsWith("admin_setlg"))
  54. armorType = Inventory.PAPERDOLL_GLOVES;
  55. else if (command.startsWith("admin_setlb"))
  56. armorType = Inventory.PAPERDOLL_FEET;
  57. else if (command.startsWith("admin_setll"))
  58. armorType = Inventory.PAPERDOLL_LEGS;
  59. else if (command.startsWith("admin_setlw"))
  60. armorType = Inventory.PAPERDOLL_RHAND;
  61. else if (command.startsWith("admin_setls"))
  62. armorType = Inventory.PAPERDOLL_LHAND;
  63. if (armorType != -1)
  64. {
  65. try
  66. {
  67. String[] args = command.split(" ");
  68. byte element = Elementals.getElementId(args[1]);
  69. int value = Integer.parseInt(args[2]);
  70. if (element < -1 || element > 5 || value < 0 || value > 450)
  71. {
  72. activeChar.sendMessage("Usage: //setlh/setlc/setlg/setlb/setll/setlw/setls <element> <value>[0-450]");
  73. return false;
  74. }
  75. setElement(activeChar, element, value, armorType);
  76. }
  77. catch (Exception e)
  78. {
  79. activeChar.sendMessage("Usage: //setlh/setlc/setlg/setlb/setll/setlw/setls <element>[0-5] <value>[0-450]");
  80. return false;
  81. }
  82. }
  83. return true;
  84. }
  85. @Override
  86. public String[] getAdminCommandList()
  87. {
  88. return ADMIN_COMMANDS;
  89. }
  90. private void setElement(L2PcInstance activeChar, byte type, int value, int armorType)
  91. {
  92. // get the target
  93. L2Object target = activeChar.getTarget();
  94. if (target == null)
  95. target = activeChar;
  96. L2PcInstance player = null;
  97. if (target instanceof L2PcInstance)
  98. {
  99. player = (L2PcInstance) target;
  100. }
  101. else
  102. {
  103. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  104. return;
  105. }
  106. L2ItemInstance itemInstance = null;
  107. // only attempt to enchant if there is a weapon equipped
  108. L2ItemInstance parmorInstance = player.getInventory().getPaperdollItem(armorType);
  109. if (parmorInstance != null && parmorInstance.getLocationSlot() == armorType)
  110. {
  111. itemInstance = parmorInstance;
  112. }
  113. if (itemInstance != null)
  114. {
  115. String old, current;
  116. Elementals element = itemInstance.getElemental(type);
  117. if (element == null)
  118. old = "None";
  119. else
  120. {
  121. old = element.toString();
  122. }
  123. // set enchant value
  124. player.getInventory().unEquipItemInSlot(armorType);
  125. if (type == -1)
  126. itemInstance.clearElementAttr(type);
  127. else
  128. itemInstance.setElementAttr(type, value);
  129. player.getInventory().equipItem(itemInstance);
  130. if (itemInstance.getElementals() == null)
  131. current = "None";
  132. else
  133. current = itemInstance.getElemental(type).toString();
  134. // send packets
  135. InventoryUpdate iu = new InventoryUpdate();
  136. iu.addModifiedItem(itemInstance);
  137. player.sendPacket(iu);
  138. // informations
  139. activeChar.sendMessage("Changed elemental power of " + player.getName() + "'s "
  140. + itemInstance.getItem().getName() + " from " + old + " to " + current + ".");
  141. if (player != activeChar)
  142. {
  143. player.sendMessage(activeChar.getName()+" has changed the elemental power of your "
  144. + itemInstance.getItem().getName() + " from " + old + " to " + current + ".");
  145. }
  146. }
  147. }
  148. }