Guest User

:)

a guest
Aug 2nd, 2012
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.26 KB | None | 0 0
  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.  
  16. package com.l2jserver.gameserver.handler.voicedcommandhandlers;
  17.  
  18. import l2ft.commons.util.Rnd;
  19.  
  20. import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  21. import com.l2jserver.gameserver.model.Elementals;
  22. import com.l2jserver.gameserver.model.L2ItemInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  25. import com.l2jserver.gameserver.network.serverpackets.CharInfo;
  26. import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
  27. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  28. import com.l2jserver.gameserver.network.serverpackets.UserInfo;
  29.  
  30. /**
  31.  * @author Vampir
  32.  * @version 2
  33.  *
  34.  */
  35. public class Beta implements IVoicedCommandHandler
  36. {
  37.     private static final String[] VOICED_COMMANDS =
  38.     {
  39.             "dark", "earth", "fire", "holy", "water", "wind", "beta"
  40.     };
  41.  
  42.     private static final int[] _onlyEnchantedParts = {Inventory.PAPERDOLL_CLOAK, Inventory.PAPERDOLL_RHAND,
  43.         Inventory.PAPERDOLL_LHAND, Inventory.PAPERDOLL_LEAR, Inventory.PAPERDOLL_REAR, Inventory.PAPERDOLL_LFINGER,
  44.         Inventory.PAPERDOLL_RFINGER, Inventory.PAPERDOLL_NECK, Inventory.PAPERDOLL_UNDER, Inventory.PAPERDOLL_BELT};
  45.    
  46.     private static final int[] _enchantedAndAttributed = {Inventory.PAPERDOLL_HEAD, Inventory.PAPERDOLL_CHEST,
  47.         Inventory.PAPERDOLL_GLOVES, Inventory.PAPERDOLL_FEET};
  48.     private static final String[] _possibilities = {"dark", "earth", "fire", "holy", "water", "wind"};
  49.    
  50.     @Override
  51.     public boolean useVoicedCommand(String command, L2PcInstance activeChar, String name)
  52.     {
  53.         if (command.startsWith("beta"))
  54.         {
  55.             for(int part : _onlyEnchantedParts)
  56.                 if(activeChar.getInventory().getPaperdollItem(part) != null)
  57.                     handleOnlyEnchanted(activeChar, part);
  58.            
  59.             for(int part : _enchantedAndAttributed)
  60.                 if(activeChar.getInventory().getPaperdollItem(part) != null)
  61.                     handleEnchantAndAttribute(activeChar, part);
  62.            
  63.             activeChar.sendPacket(iu);
  64.             activeChar.broadcastPacket(new CharInfo(activeChar));
  65.             activeChar.sendPacket(new UserInfo(activeChar));
  66.             activeChar.broadcastPacket(new ExBrExtraUserInfo(activeChar));
  67.            
  68.         }
  69.         else
  70.             handleWeapon(activeChar, command);
  71.         return false;
  72.     }
  73.    
  74.     private static void handleWeapon(L2PcInstance activeChar, String type)
  75.     {
  76.         L2ItemInstance item = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  77.         activeChar.getInventory().unEquipItem(item);
  78.         item.clearElementAttr((byte) -1);
  79.         item.setElementAttr(Elementals.getElementId(type), 450);
  80.         activeChar.getInventory().equipItem(item);
  81.     }
  82.    
  83.     private static void handleEnchantAndAttribute(L2PcInstance activeChar, int bodySlot)
  84.     {
  85.         InventoryUpdate iu = new InventoryUpdate();
  86.         L2ItemInstance item = activeChar.getInventory().getPaperdollItem(bodySlot);
  87.         activeChar.getInventory().unEquipItem(item);
  88.         item.setEnchantLevel(30);
  89.         item.clearElementAttr((byte) -1);
  90.         for(int i = 0;i<3;i++)
  91.             item.setElementAttr(Elementals.getElementId(Rnd.get(_possibilities)), 450);
  92.         activeChar.getInventory().equipItem(item);
  93.         iu.addModifiedItem(item);
  94.     }
  95.    
  96.     private void handleOnlyEnchanted(L2PcInstance activeChar, int bodySlot)
  97.     {
  98.         InventoryUpdate iu = new InventoryUpdate();
  99.         L2ItemInstance itemInstance = activeChar.getInventory().getPaperdollItem(bodySlot);
  100.         itemInstance = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_CLOAK);
  101.         itemInstance.setEnchantLevel(30);
  102.         itemInstance.clearElementAttr((byte) -1);
  103.         // send packets
  104.         iu.addModifiedItem(itemInstance);
  105.     }
  106.    
  107.     @Override
  108.     public String[] getVoicedCommandList()
  109.     {
  110.         return VOICED_COMMANDS;
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment