SnackS

Soulbound item

Dec 29th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.91 KB | None | 0 0
  1. /*
  2.  * L2jFrozen Project - www.l2jfrozen.com
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2, or (at your option)
  7.  * any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  17.  * 02111-1307, USA.
  18.  *
  19.  * http://www.gnu.org/copyleft/gpl.html
  20.  */
  21. package com.l2jfrozen.gameserver.network.clientpackets;
  22.  
  23. import java.util.Arrays;
  24.  
  25. import org.apache.log4j.Logger;
  26.  
  27. import com.l2jfrozen.Config;
  28. import com.l2jfrozen.gameserver.ai.CtrlIntention;
  29. import com.l2jfrozen.gameserver.datatables.SkillTable;
  30. import com.l2jfrozen.gameserver.handler.IItemHandler;
  31. import com.l2jfrozen.gameserver.handler.ItemHandler;
  32. import com.l2jfrozen.gameserver.managers.CastleManager;
  33. import com.l2jfrozen.gameserver.managers.ClanHallManager;
  34. import com.l2jfrozen.gameserver.model.Inventory;
  35. import com.l2jfrozen.gameserver.model.L2Clan;
  36. import com.l2jfrozen.gameserver.model.L2Object;
  37. import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
  38. import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
  39. import com.l2jfrozen.gameserver.network.SystemMessageId;
  40. import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
  41. import com.l2jfrozen.gameserver.network.serverpackets.EtcStatusUpdate;
  42. import com.l2jfrozen.gameserver.network.serverpackets.InventoryUpdate;
  43. import com.l2jfrozen.gameserver.network.serverpackets.ItemList;
  44. import com.l2jfrozen.gameserver.network.serverpackets.ShowCalculator;
  45. import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
  46. import com.l2jfrozen.gameserver.network.serverpackets.UserInfo;
  47. import com.l2jfrozen.gameserver.templates.L2Item;
  48. import com.l2jfrozen.gameserver.templates.L2Weapon;
  49. import com.l2jfrozen.gameserver.templates.L2WeaponType;
  50. import com.l2jfrozen.gameserver.util.Util;
  51.  
  52. public final class UseItem extends L2GameClientPacket
  53. {
  54.     private static Logger LOGGER = Logger.getLogger(UseItem.class);
  55.     private int _objectId;
  56.    
  57.     @Override
  58.     protected void readImpl()
  59.     {
  60.         _objectId = readD();
  61.     }
  62.    
  63.     @Override
  64.     protected void runImpl()
  65.     {
  66.         final L2PcInstance activeChar = getClient().getActiveChar();
  67.         if (activeChar == null)
  68.             return;
  69.        
  70.         final L2ItemInstance item = activeChar.getInventory().getItemByObjectId(_objectId);
  71.        
  72.         if (item == null)
  73.             return;
  74.        
  75.         // Like L2OFF you can't use soulshots while sitting
  76.         final int[] shots_ids =
  77.         {
  78.             5789,
  79.             1835,
  80.             1463,
  81.             1464,
  82.             1465,
  83.             1466,
  84.             1467,
  85.             5790,
  86.             2509,
  87.             2510,
  88.             2511,
  89.             2512,
  90.             2513,
  91.             2514,
  92.             3947,
  93.             3948,
  94.             3949,
  95.             3950,
  96.             3951,
  97.             3952
  98.         };
  99.         if (activeChar.isSitting() && Arrays.toString(shots_ids).contains(String.valueOf(item.getItemId())))
  100.         {
  101.             final SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_AUTO_USE_LACK_OF_S1);
  102.             sm.addItemName(item.getItemId());
  103.             activeChar.sendPacket(sm);
  104.             return;
  105.         }
  106.        
  107.         // Flood protect UseItem
  108.         if (item.isPotion())
  109.         {
  110.             if (!getClient().getFloodProtectors().getUsePotion().tryPerformAction("use potion"))
  111.                 return;
  112.         }
  113.         else
  114.         {
  115.             if (!getClient().getFloodProtectors().getUseItem().tryPerformAction("use item"))
  116.                 return;
  117.         }
  118.         if (activeChar.isStunned() || activeChar.isConfused() || activeChar.isAway() || activeChar.isParalyzed() || activeChar.isSleeping())
  119.         {
  120.             activeChar.sendMessage("You Cannot Use Items Right Now.");
  121.             return;
  122.         }
  123.        
  124.         if (activeChar.getPrivateStoreType() != 0)
  125.         {
  126.             activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_TRADE_DISCARD_DROP_ITEM_WHILE_IN_SHOPMODE));
  127.             activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  128.             return;
  129.         }
  130.        
  131.         if (activeChar.getActiveTradeList() != null)
  132.         {
  133.             activeChar.cancelActiveTrade();
  134.         }
  135.        
  136.         // NOTE: disabled due to deadlocks
  137.         // synchronized (activeChar.getInventory())
  138.         // {
  139.        
  140.         if (item.isWear())
  141.             // No unequipping wear-items
  142.             return;
  143.        
  144.         if (item.getItem().getType2() == L2Item.TYPE2_QUEST)
  145.         {
  146.             SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_USE_QUEST_ITEMS);
  147.             activeChar.sendPacket(sm);
  148.             sm = null;
  149.             return;
  150.         }
  151.        
  152.         final int itemId = item.getItemId();
  153.         /*
  154.          * Alt game - Karma punishment // SOE 736 Scroll of Escape 1538 Blessed Scroll of Escape 1829 Scroll of Escape: Clan Hall 1830 Scroll of Escape: Castle 3958 L2Day - Blessed Scroll of Escape 5858 Blessed Scroll of Escape: Clan Hall 5859 Blessed Scroll of Escape: Castle 6663 Scroll of Escape:
  155.          * Orc Village 6664 Scroll of Escape: Silenos Village 7117 Scroll of Escape to Talking Island 7118 Scroll of Escape to Elven Village 7119 Scroll of Escape to Dark Elf Village 7120 Scroll of Escape to Orc Village 7121 Scroll of Escape to Dwarven Village 7122 Scroll of Escape to Gludin Village
  156.          * 7123 Scroll of Escape to the Town of Gludio 7124 Scroll of Escape to the Town of Dion 7125 Scroll of Escape to Floran 7126 Scroll of Escape to Giran Castle Town 7127 Scroll of Escape to Hardin's Private Academy 7128 Scroll of Escape to Heine 7129 Scroll of Escape to the Town of Oren 7130
  157.          * Scroll of Escape to Ivory Tower 7131 Scroll of Escape to Hunters Village 7132 Scroll of Escape to Aden Castle Town 7133 Scroll of Escape to the Town of Goddard 7134 Scroll of Escape to the Rune Township 7135 Scroll of Escape to the Town of Schuttgart. 7554 Scroll of Escape to Talking
  158.          * Island 7555 Scroll of Escape to Elven Village 7556 Scroll of Escape to Dark Elf Village 7557 Scroll of Escape to Orc Village 7558 Scroll of Escape to Dwarven Village 7559 Scroll of Escape to Giran Castle Town 7618 Scroll of Escape - Ketra Orc Village 7619 Scroll of Escape - Varka Silenos
  159.          * Village 10129 Scroll of Escape : Fortress 10130 Blessed Scroll of Escape : Fortress
  160.          */
  161.         if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TELEPORT && activeChar.getKarma() > 0 && (itemId == 736 || itemId == 1538 || itemId == 1829 || itemId == 1830 || itemId == 3958 || itemId == 5858 || itemId == 5859 || itemId == 6663 || itemId == 6664 || itemId >= 7117 && itemId <= 7135 || itemId >= 7554 && itemId <= 7559 || itemId == 7618 || itemId == 7619 || itemId == 10129 || itemId == 10130))
  162.             return;
  163.        
  164.         // Items that cannot be used
  165.         if (itemId == 57)
  166.             return;
  167.        
  168.         if ((itemId == 5858) && (ClanHallManager.getInstance().getClanHallByOwner(activeChar.getClan()) == null))
  169.         {
  170.             activeChar.sendMessage("Blessed Scroll of Escape: Clan Hall cannot be used due to unsuitable terms.");
  171.             return;
  172.         }
  173.         else if ((itemId == 5859) && (CastleManager.getInstance().getCastleByOwner(activeChar.getClan()) == null))
  174.         {
  175.             activeChar.sendMessage("Blessed Scroll of Escape: Castle cannot be used due to unsuitable terms.");
  176.             return;
  177.         }
  178.        
  179.         if (activeChar.isFishing() && (itemId < 6535 || itemId > 6540))
  180.         {
  181.             // You cannot do anything else while fishing
  182.             SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_DO_WHILE_FISHING_3);
  183.             getClient().getActiveChar().sendPacket(sm);
  184.             sm = null;
  185.             return;
  186.         }
  187.        
  188.         if (activeChar.getPkKills() > 0 && (itemId >= 7816 && itemId <= 7831))
  189.         {
  190.             // Retail messages... same L2OFF
  191.             activeChar.sendMessage("You do not meet the required condition to equip that item.");
  192.             activeChar.sendMessage("You are unable to equip this item when your PK count is greater than or equal to one.");
  193.             return;
  194.         }
  195.        
  196.         final L2Clan cl = activeChar.getClan();
  197.         // A shield that can only be used by the members of a clan that owns a castle.
  198.         if ((cl == null || cl.getHasCastle() == 0) && itemId == 7015 && Config.CASTLE_SHIELD && !activeChar.isGM())
  199.         {
  200.             activeChar.sendMessage("You can't equip that");
  201.             return;
  202.         }
  203.        
  204.         // A shield that can only be used by the members of a clan that owns a clan hall.
  205.         if ((cl == null || cl.getHasHideout() == 0) && itemId == 6902 && Config.CLANHALL_SHIELD && !activeChar.isGM())
  206.         {
  207.             activeChar.sendMessage("You can't equip that");
  208.             return;
  209.         }
  210.        
  211.         // Apella armor used by clan members may be worn by a Baron or a higher level Aristocrat.
  212.         if (itemId >= 7860 && itemId <= 7879 && Config.APELLA_ARMORS && (cl == null || activeChar.getPledgeClass() < 5) && !activeChar.isGM())
  213.         {
  214.             activeChar.sendMessage("You can't equip that");
  215.             return;
  216.         }
  217.        
  218.         // Clan Oath armor used by all clan members
  219.         if (itemId >= 7850 && itemId <= 7859 && Config.OATH_ARMORS && cl == null && !activeChar.isGM())
  220.         {
  221.             activeChar.sendMessage("You can't equip that");
  222.             return;
  223.         }
  224.        
  225.         // The Lord's Crown used by castle lords only
  226.         if (itemId == 6841 && Config.CASTLE_CROWN && (cl == null || cl.getHasCastle() == 0 || !activeChar.isClanLeader()) && !activeChar.isGM())
  227.         {
  228.             activeChar.sendMessage("You can't equip that");
  229.             return;
  230.         }
  231.        
  232.         // Scroll of resurrection like L2OFF if you are casting you can't use them
  233.         if ((itemId == 737 || itemId == 3936 || itemId == 3959 || itemId == 6387) && activeChar.isCastingNow())
  234.             return;
  235.        
  236.         // Castle circlets used by the members of a clan that owns a castle, academy members are excluded.
  237.         if (Config.CASTLE_CIRCLETS && (itemId >= 6834 && itemId <= 6840 || itemId == 8182 || itemId == 8183))
  238.         {
  239.             if (cl == null)
  240.             {
  241.                 activeChar.sendMessage("You can't equip that");
  242.                 return;
  243.             }
  244.            
  245.             final int circletId = CastleManager.getInstance().getCircletByCastleId(cl.getHasCastle());
  246.             if (activeChar.getPledgeType() == -1 || circletId != itemId)
  247.             {
  248.                 activeChar.sendMessage("You can't equip that");
  249.                 return;
  250.             }
  251.         }
  252.        
  253.         /*
  254.          * //You can't equip Shield if you have specific weapon equiped, not retail L2Weapon curwep = activeChar.getActiveWeaponItem(); if(curwep != null) { if(curwep.getItemType() == L2WeaponType.DUAL && item.getItemType() == L2WeaponType.NONE) {
  255.          * activeChar.sendMessage("You are not allowed to do this."); return; } else if(curwep.getItemType() == L2WeaponType.BOW && item.getItemType() == L2WeaponType.NONE) { activeChar.sendMessage("You are not allowed to do this."); return; } else if(curwep.getItemType() == L2WeaponType.BIGBLUNT &&
  256.          * item.getItemType() == L2WeaponType.NONE) { activeChar.sendMessage("You are not allowed to do this."); return; } else if(curwep.getItemType() == L2WeaponType.BIGSWORD && item.getItemType() == L2WeaponType.NONE) { activeChar.sendMessage("You are not allowed to do this."); return; } else
  257.          * if(curwep.getItemType() == L2WeaponType.POLE && item.getItemType() == L2WeaponType.NONE) { activeChar.sendMessage("You are not allowed to do this."); return; } else if(curwep.getItemType() == L2WeaponType.DUALFIST && item.getItemType() == L2WeaponType.NONE) {
  258.          * activeChar.sendMessage("You are not allowed to do this."); return; } }
  259.          */
  260.        
  261.         // Char cannot use item when dead
  262.         if (activeChar.isDead())
  263.         {
  264.             SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
  265.             sm.addItemName(itemId);
  266.             getClient().getActiveChar().sendPacket(sm);
  267.             sm = null;
  268.             return;
  269.         }
  270.        
  271.         // Char cannot use pet items
  272.         if (item.getItem().isForWolf() || item.getItem().isForHatchling() || item.getItem().isForStrider() || item.getItem().isForBabyPet())
  273.         {
  274.             SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_EQUIP_PET_ITEM); // You cannot equip a pet item.
  275.             sm.addItemName(itemId);
  276.             getClient().getActiveChar().sendPacket(sm);
  277.             sm = null;
  278.             return;
  279.         }
  280.        
  281.         if (Config.DEBUG)
  282.         {
  283.             LOGGER.debug(activeChar.getObjectId() + ": use item " + _objectId);
  284.         }
  285.        
  286.         if (item.isEquipable())
  287.         {
  288.             // No unequipping/equipping while the player is in special conditions
  289.             if (activeChar.isFishing() || activeChar.isStunned() || activeChar.isSleeping() || activeChar.isParalyzed() || activeChar.isAlikeDead())
  290.             {
  291.                 activeChar.sendMessage("Your status does not allow you to do that.");
  292.                 return;
  293.             }
  294.            
  295.             // SECURE FIX - Anti Overenchant Cheat!!
  296.             if (Config.MAX_ITEM_ENCHANT_KICK > 0 && !activeChar.isGM() && item.getEnchantLevel() > Config.MAX_ITEM_ENCHANT_KICK)
  297.             {
  298.                 activeChar.sendMessage("You have been kicked for using an item overenchanted!");
  299.                 Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " has item Overenchanted! Kicked ", Config.DEFAULT_PUNISH);
  300.                 // activeChar.closeNetConnection();
  301.                 return;
  302.             }
  303.            
  304.             int bodyPart = item.getItem().getBodyPart();
  305.            
  306.             // Like L2OFF you can't use equips while you are casting
  307.             if ((activeChar.isCastingNow() || activeChar.isCastingPotionNow() || activeChar.isMounted() || (activeChar._inEventCTF && activeChar._haveFlagCTF)))
  308.             {
  309.                 if (activeChar._inEventCTF && activeChar._haveFlagCTF)
  310.                 {
  311.                     activeChar.sendMessage("This item can not be equipped when you have the flag.");
  312.                 }
  313.                 else
  314.                 {
  315.                     final SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_USE_ITEM_WHILE_USING_MAGIC);
  316.                     activeChar.sendPacket(sm);
  317.                 }
  318.                 return;
  319.             }
  320.            
  321.             // Like L2OFF, since c5 you can equip weapon
  322.             // Don't allow weapon/shield equipment if wearing formal wear
  323.             /*
  324.              * if (activeChar.isWearingFormalWear() && (bodyPart == L2Item.SLOT_LR_HAND || bodyPart == L2Item.SLOT_L_HAND || bodyPart == L2Item.SLOT_R_HAND)) { SystemMessage sm = new SystemMessage(SystemMessageId.CANNOT_USE_ITEMS_SKILLS_WITH_FORMALWEAR); activeChar.sendPacket(sm); return; }
  325.              */
  326.            
  327.             // Over enchant protection
  328.             if (Config.PROTECTED_ENCHANT)
  329.             {
  330.                 switch (bodyPart)
  331.                 {
  332.                     case L2Item.SLOT_LR_HAND:
  333.                     case L2Item.SLOT_L_HAND:
  334.                     case L2Item.SLOT_R_HAND:
  335.                     {
  336.                         if ((item.getEnchantLevel() > Config.NORMAL_WEAPON_ENCHANT_LEVEL.size() || item.getEnchantLevel() > Config.BLESS_WEAPON_ENCHANT_LEVEL.size() || item.getEnchantLevel() > Config.CRYSTAL_WEAPON_ENCHANT_LEVEL.size()) && !activeChar.isGM())
  337.                         {
  338.                             // activeChar.setAccountAccesslevel(-1); //ban
  339.                             activeChar.sendMessage("You have been banned for using an item wich is over enchanted!"); // message
  340.                             Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " has item Overenchanted! ", Config.DEFAULT_PUNISH);
  341.                             // activeChar.closeNetConnection(); //kick
  342.                             return;
  343.                         }
  344.                         break;
  345.                     }
  346.                     case L2Item.SLOT_CHEST:
  347.                     case L2Item.SLOT_BACK:
  348.                     case L2Item.SLOT_GLOVES:
  349.                     case L2Item.SLOT_FEET:
  350.                     case L2Item.SLOT_HEAD:
  351.                     case L2Item.SLOT_FULL_ARMOR:
  352.                     case L2Item.SLOT_LEGS:
  353.                     {
  354.                         if ((item.getEnchantLevel() > Config.NORMAL_ARMOR_ENCHANT_LEVEL.size() || item.getEnchantLevel() > Config.BLESS_ARMOR_ENCHANT_LEVEL.size() || item.getEnchantLevel() > Config.CRYSTAL_ARMOR_ENCHANT_LEVEL.size()) && !activeChar.isGM())
  355.                         {
  356.                             // activeChar.setAccountAccesslevel(-1); //ban
  357.                             activeChar.sendMessage("You have been banned for using an item wich is over enchanted!"); // message
  358.                             Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " has item Overenchanted! ", Config.DEFAULT_PUNISH);
  359.                             // activeChar.closeNetConnection(); //kick
  360.                             return;
  361.                         }
  362.                         break;
  363.                     }
  364.                     case L2Item.SLOT_R_EAR:
  365.                     case L2Item.SLOT_L_EAR:
  366.                     case L2Item.SLOT_NECK:
  367.                     case L2Item.SLOT_R_FINGER:
  368.                     case L2Item.SLOT_L_FINGER:
  369.                     {
  370.                         if ((item.getEnchantLevel() > Config.NORMAL_JEWELRY_ENCHANT_LEVEL.size() || item.getEnchantLevel() > Config.BLESS_JEWELRY_ENCHANT_LEVEL.size() || item.getEnchantLevel() > Config.CRYSTAL_JEWELRY_ENCHANT_LEVEL.size()) && !activeChar.isGM())
  371.                         {
  372.                             // activeChar.setAccountAccesslevel(-1); //ban
  373.                             activeChar.sendMessage("You have been banned for using an item wich is over enchanted!"); // message
  374.                             Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " has item Overenchanted! ", Config.DEFAULT_PUNISH);
  375.                             // activeChar.closeNetConnection(); //kick
  376.                             return;
  377.                         }
  378.                         break;
  379.                     }
  380.                 }
  381.             }
  382.            
  383.             // Don't allow weapon/shield equipment if a cursed weapon is equiped
  384.             if (activeChar.isCursedWeaponEquiped() && (bodyPart == L2Item.SLOT_LR_HAND || bodyPart == L2Item.SLOT_L_HAND || bodyPart == L2Item.SLOT_R_HAND))
  385.                 return;
  386.            
  387.             // Don't allow weapon/shield hero equipment during Olimpia
  388.             if (activeChar.isInOlympiadMode() && ((bodyPart == L2Item.SLOT_LR_HAND || bodyPart == L2Item.SLOT_L_HAND || bodyPart == L2Item.SLOT_R_HAND) && (item.getItemId() >= 6611 && item.getItemId() <= 6621 || item.getItemId() == 6842) || Config.LIST_OLY_RESTRICTED_ITEMS.contains(item.getItemId())))
  389.                 return;
  390.            
  391.             // Don't allow Hero items equipment if not a hero
  392.             if (!activeChar.isHero() && (item.getItemId() >= 6611 && item.getItemId() <= 6621 || item.getItemId() == 6842) && !activeChar.isGM())
  393.                 return;
  394.            
  395.             if (activeChar.isMoving() && activeChar.isAttackingNow() && (bodyPart == L2Item.SLOT_LR_HAND || bodyPart == L2Item.SLOT_L_HAND || bodyPart == L2Item.SLOT_R_HAND))
  396.             {
  397.                 final L2Object target = activeChar.getTarget();
  398.                 activeChar.setTarget(null);
  399.                 activeChar.stopMove(null);
  400.                 activeChar.setTarget(target);
  401.                 activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK);
  402.             }
  403.            
  404.             // Don't allow to put formal wear
  405.             if (activeChar.isCursedWeaponEquipped() && itemId == 6408)
  406.                 return;
  407.            
  408.             // Elrokian Trap like L2OFF, add skills
  409.             if (itemId == 8763)
  410.             {
  411.                 if (!item.isEquipped())
  412.                 {
  413.                     activeChar.addSkill(SkillTable.getInstance().getInfo(3626, 1));
  414.                     activeChar.addSkill(SkillTable.getInstance().getInfo(3627, 1));
  415.                     activeChar.addSkill(SkillTable.getInstance().getInfo(3628, 1));
  416.                     activeChar.sendSkillList();
  417.                 }
  418.             }
  419.            
  420.             // Equip or unEquip
  421.             L2ItemInstance[] items = null;
  422.             final boolean isEquiped = item.isEquipped();
  423.             SystemMessage sm = null;
  424.            
  425.             if (item.getItem().getType2() == L2Item.TYPE2_WEAPON)
  426.             { // if used item is a weapon
  427.            
  428.                 L2ItemInstance wep = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_LRHAND);
  429.                 if (wep == null)
  430.                 {
  431.                     wep = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
  432.                 }
  433.                
  434.                 activeChar.checkSSMatch(item, wep);
  435.                
  436.             }
  437.            
  438.             // Remove the item if it's equiped
  439.             if (isEquiped)
  440.             {
  441.                 // Elrokian Trap like L2OFF, remove skills
  442.                 if (itemId == 8763)
  443.                 {
  444.                     activeChar.removeSkill(3626, true);
  445.                     activeChar.removeSkill(3627, true);
  446.                     activeChar.removeSkill(3628, true);
  447.                     activeChar.sendSkillList();
  448.                 }
  449.                
  450.                 if (item.getEnchantLevel() > 0)
  451.                 {
  452.                     sm = new SystemMessage(SystemMessageId.EQUIPMENT_S1_S2_REMOVED);
  453.                     sm.addNumber(item.getEnchantLevel());
  454.                     sm.addItemName(itemId);
  455.                 }
  456.                 else
  457.                 {
  458.                     sm = new SystemMessage(SystemMessageId.S1_DISARMED);
  459.                     sm.addItemName(itemId);
  460.                 }
  461.                
  462.                 activeChar.sendPacket(sm);
  463.                
  464.                 // Remove augementation bonus on unequipment
  465.                 if (item.isAugmented())
  466.                 {
  467.                     item.getAugmentation().removeBoni(activeChar);
  468.                 }
  469.                
  470.                 switch (item.getEquipSlot())
  471.                 {
  472.                     case 1:
  473.                         bodyPart = L2Item.SLOT_L_EAR;
  474.                         break;
  475.                     case 2:
  476.                         bodyPart = L2Item.SLOT_R_EAR;
  477.                         break;
  478.                     case 4:
  479.                         bodyPart = L2Item.SLOT_L_FINGER;
  480.                         break;
  481.                     case 5:
  482.                         bodyPart = L2Item.SLOT_R_FINGER;
  483.                         break;
  484.                     default:
  485.                         break;
  486.                 }
  487.                
  488.                 // remove cupid's bow skills on unequip
  489.                 if (item.isCupidBow())
  490.                 {
  491.                     if (item.getItemId() == 9140)
  492.                         activeChar.removeSkill(SkillTable.getInstance().getInfo(3261, 1));
  493.                     else
  494.                     {
  495.                         activeChar.removeSkill(SkillTable.getInstance().getInfo(3260, 0));
  496.                         activeChar.removeSkill(SkillTable.getInstance().getInfo(3262, 0));
  497.                     }
  498.                 }
  499.                
  500.                 items = activeChar.getInventory().unEquipItemInBodySlotAndRecord(bodyPart);
  501.             }
  502.             else
  503.             {
  504.                 // Restrict bow weapon for class except Cupid bow.
  505.                 if (item.getItem() instanceof L2Weapon && ((L2Weapon) item.getItem()).getItemType() == L2WeaponType.BOW && !item.isCupidBow())
  506.                 {
  507.                     // Restriction not valid on Olympiad matches
  508.                     if (Config.DISABLE_BOW_CLASSES.contains(activeChar.getClassId().getId()) && !activeChar.isInOlympiadMode())
  509.                     {
  510.                         activeChar.sendMessage("This item can not be equipped by your class!");
  511.                         activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  512.                         return;
  513.                     }
  514.                 }
  515.                
  516.                 final int tempBodyPart = item.getItem().getBodyPart();
  517.                 L2ItemInstance tempItem = activeChar.getInventory().getPaperdollItemByL2ItemId(tempBodyPart);
  518.                
  519.                 // remove augmentation stats for replaced items
  520.                 // currently weapons only..
  521.                 if (tempItem != null && tempItem.isAugmented())
  522.                 {
  523.                     tempItem.getAugmentation().removeBoni(activeChar);
  524.                 }
  525.                
  526.                 // check if the item replaces a wear-item
  527.                 if (tempItem != null && tempItem.isWear())
  528.                     // dont allow an item to replace a wear-item
  529.                     return;
  530.                 else if (tempBodyPart == 0x4000) // left+right hand equipment
  531.                 {
  532.                     // this may not remove left OR right hand equipment
  533.                     tempItem = activeChar.getInventory().getPaperdollItem(7);
  534.                     if (tempItem != null && tempItem.isWear())
  535.                         return;
  536.                    
  537.                     tempItem = activeChar.getInventory().getPaperdollItem(8);
  538.                     if (tempItem != null && tempItem.isWear())
  539.                         return;
  540.                 }
  541.                 else if (tempBodyPart == 0x8000) // fullbody armor
  542.                 {
  543.                     // this may not remove chest or leggins
  544.                     tempItem = activeChar.getInventory().getPaperdollItem(10);
  545.                     if (tempItem != null && tempItem.isWear())
  546.                         return;
  547.                    
  548.                     tempItem = activeChar.getInventory().getPaperdollItem(11);
  549.                     if (tempItem != null && tempItem.isWear())
  550.                         return;
  551.                 }
  552.                
  553.                 // Left hand
  554.                 tempItem = activeChar.getInventory().getPaperdollItem(7);
  555.                 // Elrokian Trap like L2OFF, remove skills
  556.                 if (tempItem != null && tempItem.getItemId() == 8763)
  557.                 {
  558.                     activeChar.removeSkill(3626, true);
  559.                     activeChar.removeSkill(3627, true);
  560.                     activeChar.removeSkill(3628, true);
  561.                     activeChar.sendSkillList();
  562.                 }
  563.                
  564.                 if (item.getEnchantLevel() > 0)
  565.                 {
  566.                     sm = new SystemMessage(SystemMessageId.S1_S2_EQUIPPED);
  567.                     sm.addNumber(item.getEnchantLevel());
  568.                     sm.addItemName(itemId);
  569.                 }
  570.                 else
  571.                 {
  572.                     sm = new SystemMessage(SystemMessageId.S1_EQUIPPED);
  573.                     sm.addItemName(itemId);
  574.                 }
  575.                 activeChar.sendPacket(sm);
  576.                
  577.                 // Apply augementation boni on equip
  578.                 if (item.isAugmented())
  579.                 {
  580.                     item.getAugmentation().applyBoni(activeChar);
  581.                 }
  582.                
  583.                 // Apply cupid's bow skills on equip
  584.                 if (item.isCupidBow())
  585.                 {
  586.                     if (item.getItemId() == 9140)
  587.                         activeChar.addSkill(SkillTable.getInstance().getInfo(3261, 1));
  588.                     else
  589.                         activeChar.addSkill(SkillTable.getInstance().getInfo(3260, 0));
  590.                    
  591.                     activeChar.addSkill(SkillTable.getInstance().getInfo(3262, 0));
  592.                 }
  593.                
  594.                 item.setSoulbound(true);
  595.                
  596.                 items = activeChar.getInventory().equipItemAndRecord(item);
  597.                
  598.                 if (item.getItem() instanceof L2Weapon)
  599.                 {
  600.                    
  601.                     // charge Soulshot/Spiritshot like L2OFF
  602.                     activeChar.rechargeAutoSoulShot(true, true, false, 0);
  603.                     item.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  604.                     item.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  605.                 }
  606.                 // Consume mana - will start a task if required; returns if item is not a shadow item
  607.                 item.decreaseMana(false);
  608.             }
  609.            
  610.             sm = null;
  611.            
  612.             /*
  613.              * if(item.getItem().getType2() == L2Item.TYPE2_WEAPON) { activeChar.checkIfWeaponIsAllowed(); }
  614.              */
  615.            
  616.             activeChar.abortAttack();
  617.            
  618.             activeChar.sendPacket(new EtcStatusUpdate(activeChar));
  619.             // if an "invisible" item has changed (Jewels, helmet),
  620.             // we dont need to send broadcast packet to all other users
  621.             if (!((item.getItem().getBodyPart() & L2Item.SLOT_HEAD) > 0 || (item.getItem().getBodyPart() & L2Item.SLOT_NECK) > 0 || (item.getItem().getBodyPart() & L2Item.SLOT_L_EAR) > 0 || (item.getItem().getBodyPart() & L2Item.SLOT_R_EAR) > 0 || (item.getItem().getBodyPart() & L2Item.SLOT_L_FINGER) > 0 || (item.getItem().getBodyPart() & L2Item.SLOT_R_FINGER) > 0))
  622.             {
  623.                 activeChar.broadcastUserInfo();
  624.                 final InventoryUpdate iu = new InventoryUpdate();
  625.                 iu.addItems(Arrays.asList(items));
  626.                 activeChar.sendPacket(iu);
  627.             }
  628.             else if ((item.getItem().getBodyPart() & L2Item.SLOT_HEAD) > 0)
  629.             {
  630.                 final InventoryUpdate iu = new InventoryUpdate();
  631.                 iu.addItems(Arrays.asList(items));
  632.                 activeChar.sendPacket(iu);
  633.                 activeChar.sendPacket(new UserInfo(activeChar));
  634.             }
  635.             else
  636.             {
  637.                 // because of complicated jewels problem i'm forced to resend the item list :(
  638.                 activeChar.sendPacket(new ItemList(activeChar, true));
  639.                 activeChar.sendPacket(new UserInfo(activeChar));
  640.             }
  641.         }
  642.         else
  643.         {
  644.             final L2Weapon weaponItem = activeChar.getActiveWeaponItem();
  645.             final int itemid = item.getItemId();
  646.             // LOGGER.warn( "item not equipable id:"+ item.getItemId());
  647.             if (itemid == 4393)
  648.             {
  649.                 activeChar.sendPacket(new ShowCalculator(4393));
  650.             }
  651.             else if (weaponItem != null && weaponItem.getItemType() == L2WeaponType.ROD && (itemid >= 6519 && itemid <= 6527 || itemid >= 7610 && itemid <= 7613 || itemid >= 7807 && itemid <= 7809 || itemid >= 8484 && itemid <= 8486 || itemid >= 8505 && itemid <= 8513))
  652.             {
  653.                 activeChar.getInventory().setPaperdollItem(Inventory.PAPERDOLL_LHAND, item);
  654.                 activeChar.broadcastUserInfo();
  655.                 // Send a Server->Client packet ItemList to this L2PcINstance to update left hand equipement
  656.                 final ItemList il = new ItemList(activeChar, false);
  657.                 sendPacket(il);
  658.                 return;
  659.             }
  660.             else
  661.             {
  662.                 final IItemHandler handler = ItemHandler.getInstance().getItemHandler(itemId);
  663.                 if (handler == null)
  664.                 {
  665.                     if (Config.DEBUG)
  666.                         LOGGER.warn("No item handler registered for item ID " + itemId + ".");
  667.                 }
  668.                 else
  669.                 {
  670.                     handler.useItem(activeChar, item);
  671.                 }
  672.             }
  673.         }
  674.         // }
  675.     }
  676.    
  677.     @Override
  678.     public String getType()
  679.     {
  680.         return "[C] 14 UseItem";
  681.     }
  682.    
  683. }
Advertisement
Add Comment
Please, Sign In to add comment