AdminElement.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.item.instance.L2ItemInstance;
  25. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  28. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  29. /**
  30. * This class handles following admin commands: - delete = deletes target
  31. *
  32. * @version $Revision: 1.2.2.1.2.4 $ $Date: 2005/04/11 10:05:56 $
  33. */
  34. public class AdminElement implements IAdminCommandHandler
  35. {
  36. private static final String[] ADMIN_COMMANDS =
  37. {
  38. "admin_setlh",
  39. "admin_setlc",
  40. "admin_setll",
  41. "admin_setlg",
  42. "admin_setlb",
  43. "admin_setlw",
  44. "admin_setls"
  45. };
  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. public String[] getAdminCommandList()
  86. {
  87. return ADMIN_COMMANDS;
  88. }
  89. private void setElement(L2PcInstance activeChar, byte type, int value, int armorType)
  90. {
  91. // get the target
  92. L2Object target = activeChar.getTarget();
  93. if (target == null)
  94. target = activeChar;
  95. L2PcInstance player = null;
  96. if (target instanceof L2PcInstance)
  97. {
  98. player = (L2PcInstance) target;
  99. }
  100. else
  101. {
  102. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  103. return;
  104. }
  105. L2ItemInstance itemInstance = null;
  106. // only attempt to enchant if there is a weapon equipped
  107. L2ItemInstance parmorInstance = player.getInventory().getPaperdollItem(armorType);
  108. if (parmorInstance != null && parmorInstance.getLocationSlot() == armorType)
  109. {
  110. itemInstance = parmorInstance;
  111. }
  112. if (itemInstance != null)
  113. {
  114. String old, current;
  115. Elementals element = itemInstance.getElemental(type);
  116. if (element == null)
  117. old = "None";
  118. else
  119. {
  120. old = element.toString();
  121. }
  122. // set enchant value
  123. player.getInventory().unEquipItemInSlot(armorType);
  124. if (type == -1)
  125. itemInstance.clearElementAttr(type);
  126. else
  127. itemInstance.setElementAttr(type, value);
  128. player.getInventory().equipItem(itemInstance);
  129. if (itemInstance.getElementals() == null)
  130. current = "None";
  131. else
  132. current = itemInstance.getElemental(type).toString();
  133. // send packets
  134. InventoryUpdate iu = new InventoryUpdate();
  135. iu.addModifiedItem(itemInstance);
  136. player.sendPacket(iu);
  137. // informations
  138. activeChar.sendMessage("Changed elemental power of " + player.getName() + "'s "
  139. + itemInstance.getItem().getName() + " from " + old + " to " + current + ".");
  140. if (player != activeChar)
  141. {
  142. player.sendMessage(activeChar.getName()+" has changed the elemental power of your "
  143. + itemInstance.getItem().getName() + " from " + old + " to " + current + ".");
  144. }
  145. }
  146. }
  147. }