SnackS

Soulbound item

Dec 29th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 41.95 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.model.actor.instance;
  22.  
  23. import java.sql.Connection;
  24. import java.sql.PreparedStatement;
  25. import java.sql.ResultSet;
  26. import java.sql.SQLException;
  27. import java.util.concurrent.ScheduledFuture;
  28. import java.util.logging.Level;
  29. import java.util.logging.LogRecord;
  30.  
  31. import org.apache.log4j.Logger;
  32.  
  33. import com.l2jfrozen.Config;
  34. import com.l2jfrozen.gameserver.ai.CtrlIntention;
  35. import com.l2jfrozen.gameserver.datatables.sql.ItemTable;
  36. import com.l2jfrozen.gameserver.geo.GeoData;
  37. import com.l2jfrozen.gameserver.managers.ItemsOnGroundManager;
  38. import com.l2jfrozen.gameserver.model.DropProtection;
  39. import com.l2jfrozen.gameserver.model.L2Augmentation;
  40. import com.l2jfrozen.gameserver.model.L2Character;
  41. import com.l2jfrozen.gameserver.model.L2Object;
  42. import com.l2jfrozen.gameserver.model.L2World;
  43. import com.l2jfrozen.gameserver.model.Location;
  44. import com.l2jfrozen.gameserver.model.actor.knownlist.NullKnownList;
  45. import com.l2jfrozen.gameserver.model.extender.BaseExtender.EventType;
  46. import com.l2jfrozen.gameserver.network.SystemMessageId;
  47. import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
  48. import com.l2jfrozen.gameserver.network.serverpackets.InventoryUpdate;
  49. import com.l2jfrozen.gameserver.network.serverpackets.StatusUpdate;
  50. import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
  51. import com.l2jfrozen.gameserver.skills.funcs.Func;
  52. import com.l2jfrozen.gameserver.templates.L2Armor;
  53. import com.l2jfrozen.gameserver.templates.L2EtcItem;
  54. import com.l2jfrozen.gameserver.templates.L2Item;
  55. import com.l2jfrozen.gameserver.templates.L2Weapon;
  56. import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
  57. import com.l2jfrozen.gameserver.util.IllegalPlayerAction;
  58. import com.l2jfrozen.gameserver.util.Util;
  59. import com.l2jfrozen.util.CloseUtil;
  60. import com.l2jfrozen.util.database.DatabaseUtils;
  61. import com.l2jfrozen.util.database.L2DatabaseFactory;
  62. import com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException;
  63.  
  64. /**
  65.  * This class manages items.
  66.  * @version $Revision: 1.4.2.1.2.11 $ $Date: 2005/03/31 16:07:50 $
  67.  */
  68. public final class L2ItemInstance extends L2Object
  69. {
  70.    
  71.     /** The Constant LOGGER. */
  72.     private static final Logger LOGGER = Logger.getLogger(L2ItemInstance.class);
  73.    
  74.     /** The Constant _logItems. */
  75.     private static final java.util.logging.Logger _logItems = java.util.logging.Logger.getLogger("item");
  76.    
  77.     /** The _drop protection. */
  78.     private final DropProtection _dropProtection = new DropProtection();
  79.    
  80.     /**
  81.      * Enumeration of locations for item.
  82.      */
  83.     public static enum ItemLocation
  84.     {
  85.        
  86.         /** The VOID. */
  87.         VOID,
  88.        
  89.         /** The INVENTORY. */
  90.         INVENTORY,
  91.        
  92.         /** The PAPERDOLL. */
  93.         PAPERDOLL,
  94.        
  95.         /** The WAREHOUSE. */
  96.         WAREHOUSE,
  97.        
  98.         /** The CLANWH. */
  99.         CLANWH,
  100.        
  101.         /** The PET. */
  102.         PET,
  103.        
  104.         /** The PE t_ equip. */
  105.         PET_EQUIP,
  106.        
  107.         /** The LEASE. */
  108.         LEASE,
  109.        
  110.         /** The FREIGHT. */
  111.         FREIGHT
  112.     }
  113.    
  114.     /** ID of the owner. */
  115.     private int _ownerId;
  116.    
  117.     /** Quantity of the item. */
  118.     private int _count;
  119.    
  120.     /** Initial Quantity of the item. */
  121.     private int _initCount;
  122.    
  123.     /** Time after restore Item count (in Hours). */
  124.     private int _time;
  125.    
  126.     /** Quantity of the item can decrease. */
  127.     private boolean _decrease = false;
  128.    
  129.     /** ID of the item. */
  130.     private final int _itemId;
  131.    
  132.     /** Object L2Item associated to the item. */
  133.     private final L2Item _item;
  134.    
  135.     /** Location of the item : Inventory, PaperDoll, WareHouse. */
  136.     private ItemLocation _loc;
  137.    
  138.     /** Slot where item is stored. */
  139.     private int _locData;
  140.    
  141.     /** Level of enchantment of the item. */
  142.     private int _enchantLevel;
  143.    
  144.     /** Price of the item for selling. */
  145.     private int _priceSell;
  146.    
  147.     /** Price of the item for buying. */
  148.     private int _priceBuy;
  149.    
  150.     /** Wear Item. */
  151.     private boolean _wear;
  152.    
  153.     /** Augmented Item. */
  154.     private L2Augmentation _augmentation = null;
  155.    
  156.     /** Shadow item. */
  157.     private int _mana = -1;
  158.    
  159.     /** The _consuming mana. */
  160.     private boolean _consumingMana = false;
  161.    
  162.     /** The Constant MANA_CONSUMPTION_RATE. */
  163.     private static final int MANA_CONSUMPTION_RATE = 60000;
  164.    
  165.     /** Custom item types (used loto, race tickets). */
  166.     private int _type1;
  167.    
  168.     /** The _type2. */
  169.     private int _type2;
  170.    
  171.     /** The _drop time. */
  172.     private long _dropTime;
  173.    
  174.     /** The Constant CHARGED_NONE. */
  175.     public static final int CHARGED_NONE = 0;
  176.    
  177.     /** The Constant CHARGED_SOULSHOT. */
  178.     public static final int CHARGED_SOULSHOT = 1;
  179.    
  180.     /** The Constant CHARGED_SPIRITSHOT. */
  181.     public static final int CHARGED_SPIRITSHOT = 1;
  182.    
  183.     /** The Constant CHARGED_BLESSED_SOULSHOT. */
  184.     public static final int CHARGED_BLESSED_SOULSHOT = 2; // It's a realy exists? ;-)
  185.    
  186.     /** The Constant CHARGED_BLESSED_SPIRITSHOT. */
  187.     public static final int CHARGED_BLESSED_SPIRITSHOT = 2;
  188.    
  189.     /** Item charged with SoulShot (type of SoulShot). */
  190.     private int _chargedSoulshot = CHARGED_NONE;
  191.    
  192.     /** Item charged with SpiritShot (type of SpiritShot). */
  193.     private int _chargedSpiritshot = CHARGED_NONE;
  194.    
  195.     /** The _charged fishtshot. */
  196.     private boolean _chargedFishtshot = false;
  197.    
  198.     /** The _protected. */
  199.     private boolean _protected;
  200.    
  201.     /** The Constant UNCHANGED. */
  202.     public static final int UNCHANGED = 0;
  203.    
  204.     /** The Constant ADDED. */
  205.     public static final int ADDED = 1;
  206.    
  207.     /** The Constant REMOVED. */
  208.     public static final int REMOVED = 3;
  209.    
  210.     /** The Constant MODIFIED. */
  211.     public static final int MODIFIED = 2;
  212.    
  213.     /** The _last change. */
  214.     private int _lastChange = 2; // 1 ??, 2 modified, 3 removed
  215.    
  216.     /** The _exists in db. */
  217.     private boolean _existsInDb; // if a record exists in DB.
  218.    
  219.     /** The _stored in db. */
  220.     private boolean _storedInDb; // if DB data is up-to-date.
  221.    
  222.     /** The item loot shedule. */
  223.     private ScheduledFuture<?> itemLootShedule = null;
  224.    
  225.     /**
  226.      * Constructor of the L2ItemInstance from the objectId and the itemId.
  227.      * @param objectId : int designating the ID of the object in the world
  228.      * @param itemId : int designating the ID of the item
  229.      * @throws IllegalArgumentException the illegal argument exception
  230.      */
  231.     public L2ItemInstance(final int objectId, final int itemId) throws IllegalArgumentException
  232.     {
  233.         this(objectId, ItemTable.getInstance().getTemplate(itemId));
  234.     }
  235.    
  236.     /**
  237.      * Constructor of the L2ItemInstance from the objetId and the description of the item given by the L2Item.
  238.      * @param objectId : int designating the ID of the object in the world
  239.      * @param item : L2Item containing informations of the item
  240.      * @throws IllegalArgumentException the illegal argument exception
  241.      */
  242.     public L2ItemInstance(final int objectId, final L2Item item) throws IllegalArgumentException
  243.     {
  244.         super(objectId);
  245.        
  246.         if (item == null)
  247.             throw new IllegalArgumentException();
  248.        
  249.         super.setKnownList(new NullKnownList(this));
  250.        
  251.         _itemId = item.getItemId();
  252.         _item = item;
  253.         _count = 1;
  254.         _loc = ItemLocation.VOID;
  255.         _mana = _item.getDuration();
  256.     }
  257.    
  258.     /**
  259.      * Sets the ownerID of the item.
  260.      * @param process : String Identifier of process triggering this action
  261.      * @param owner_id : int designating the ID of the owner
  262.      * @param creator : L2PcInstance Player requesting the item creation
  263.      * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  264.      */
  265.     public void setOwnerId(final String process, final int owner_id, final L2PcInstance creator, final L2Object reference)
  266.     {
  267.         final int oldOwner = _ownerId;
  268.         setOwnerId(owner_id);
  269.        
  270.         /*
  271.          * if(Config.LOG_ITEMS) { LogRecord record = new LogRecord(Level.INFO, "CHANGE:" + process); record.setLoggerName("item"); record.setParameters(new Object[] { this, creator, reference }); _logItems.LOGGER(record); record = null; }
  272.          */
  273.         fireEvent(EventType.SETOWNER.name, new Object[]
  274.         {
  275.             process,
  276.             oldOwner
  277.         });
  278.     }
  279.    
  280.     /**
  281.      * Sets the ownerID of the item.
  282.      * @param owner_id : int designating the ID of the owner
  283.      */
  284.     public void setOwnerId(final int owner_id)
  285.     {
  286.         if (owner_id == _ownerId)
  287.             return;
  288.        
  289.         _ownerId = owner_id;
  290.         _storedInDb = false;
  291.     }
  292.    
  293.     /**
  294.      * Returns the ownerID of the item.
  295.      * @return int : ownerID of the item
  296.      */
  297.     public int getOwnerId()
  298.     {
  299.         return _ownerId;
  300.     }
  301.    
  302.     /**
  303.      * Sets the location of the item.
  304.      * @param loc : ItemLocation (enumeration)
  305.      */
  306.     public void setLocation(final ItemLocation loc)
  307.     {
  308.         setLocation(loc, 0);
  309.     }
  310.    
  311.     /**
  312.      * Sets the location of the item.<BR>
  313.      * <BR>
  314.      * <U><I>Remark :</I></U> If loc and loc_data different from database, say datas not up-to-date
  315.      * @param loc : ItemLocation (enumeration)
  316.      * @param loc_data : int designating the slot where the item is stored or the village for freights
  317.      */
  318.     public void setLocation(final ItemLocation loc, final int loc_data)
  319.     {
  320.         if (loc == _loc && loc_data == _locData)
  321.             return;
  322.         _loc = loc;
  323.         _locData = loc_data;
  324.         _storedInDb = false;
  325.     }
  326.    
  327.     /**
  328.      * Gets the location.
  329.      * @return the location
  330.      */
  331.     public ItemLocation getLocation()
  332.     {
  333.         return _loc;
  334.     }
  335.    
  336.     public boolean isPotion()
  337.     {
  338.         return _item.isPotion();
  339.     }
  340.    
  341.     /**
  342.      * Returns the quantity of item.
  343.      * @return int
  344.      */
  345.     public int getCount()
  346.     {
  347.         return _count;
  348.     }
  349.    
  350.     /**
  351.      * Sets the quantity of the item.<BR>
  352.      * <BR>
  353.      * <U><I>Remark :</I></U> If loc and loc_data different from database, say datas not up-to-date
  354.      * @param process : String Identifier of process triggering this action
  355.      * @param count : int
  356.      * @param creator : L2PcInstance Player requesting the item creation
  357.      * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  358.      */
  359.     public void changeCount(final String process, final int count, final L2PcInstance creator, final L2Object reference)
  360.     {
  361.         if (count == 0)
  362.             return;
  363.        
  364.         if (count > 0 && _count > Integer.MAX_VALUE - count)
  365.             _count = Integer.MAX_VALUE;
  366.         else
  367.             _count += count;
  368.        
  369.         if (_count < 0)
  370.             _count = 0;
  371.        
  372.         _storedInDb = false;
  373.        
  374.         if (Config.LOG_ITEMS)
  375.         {
  376.             LogRecord record = new LogRecord(Level.INFO, "CHANGE:" + process);
  377.             record.setLoggerName("item");
  378.             record.setParameters(new Object[]
  379.             {
  380.                 this,
  381.                 creator,
  382.                 reference
  383.             });
  384.             _logItems.log(record);
  385.             record = null;
  386.         }
  387.     }
  388.    
  389.     // No logging (function designed for shots only)
  390.     /**
  391.      * Change count without trace.
  392.      * @param process the process
  393.      * @param count the count
  394.      * @param creator the creator
  395.      * @param reference the reference
  396.      */
  397.     public void changeCountWithoutTrace(final String process, final int count, final L2PcInstance creator, final L2Object reference)
  398.     {
  399.         if (count == 0)
  400.             return;
  401.         if (count > 0 && _count > Integer.MAX_VALUE - count)
  402.             _count = Integer.MAX_VALUE;
  403.         else
  404.             _count += count;
  405.         if (_count < 0)
  406.             _count = 0;
  407.        
  408.         _storedInDb = false;
  409.     }
  410.    
  411.     /**
  412.      * Sets the quantity of the item.<BR>
  413.      * <BR>
  414.      * <U><I>Remark :</I></U> If loc and loc_data different from database, say datas not up-to-date
  415.      * @param count : int
  416.      */
  417.     public void setCount(final int count)
  418.     {
  419.         if (_count == count)
  420.             return;
  421.        
  422.         _count = count >= -1 ? count : 0;
  423.         _storedInDb = false;
  424.     }
  425.    
  426.     /**
  427.      * Returns if item is equipable.
  428.      * @return boolean
  429.      */
  430.     public boolean isEquipable()
  431.     {
  432.         return !(_item.getBodyPart() == 0 || _item instanceof L2EtcItem);
  433.     }
  434.    
  435.     /**
  436.      * Returns if item is equipped.
  437.      * @return boolean
  438.      */
  439.     public boolean isEquipped()
  440.     {
  441.         return _loc == ItemLocation.PAPERDOLL || _loc == ItemLocation.PET_EQUIP;
  442.     }
  443.    
  444.     /**
  445.      * Returns the slot where the item is stored.
  446.      * @return int
  447.      */
  448.     public int getEquipSlot()
  449.     {
  450.         if (Config.ASSERT)
  451.             assert _loc == ItemLocation.PAPERDOLL || _loc == ItemLocation.PET_EQUIP || _loc == ItemLocation.FREIGHT;
  452.        
  453.         return _locData;
  454.     }
  455.    
  456.     /**
  457.      * Returns the characteristics of the item.
  458.      * @return L2Item
  459.      */
  460.     public L2Item getItem()
  461.     {
  462.         return _item;
  463.     }
  464.    
  465.     /**
  466.      * Gets the custom type1.
  467.      * @return the custom type1
  468.      */
  469.     public int getCustomType1()
  470.     {
  471.         return _type1;
  472.     }
  473.    
  474.     /**
  475.      * Gets the custom type2.
  476.      * @return the custom type2
  477.      */
  478.     public int getCustomType2()
  479.     {
  480.         return _type2;
  481.     }
  482.    
  483.     /**
  484.      * Sets the custom type1.
  485.      * @param newtype the new custom type1
  486.      */
  487.     public void setCustomType1(final int newtype)
  488.     {
  489.         _type1 = newtype;
  490.     }
  491.    
  492.     /**
  493.      * Sets the custom type2.
  494.      * @param newtype the new custom type2
  495.      */
  496.     public void setCustomType2(final int newtype)
  497.     {
  498.         _type2 = newtype;
  499.     }
  500.    
  501.     /**
  502.      * Sets the drop time.
  503.      * @param time the new drop time
  504.      */
  505.     public void setDropTime(final long time)
  506.     {
  507.         _dropTime = time;
  508.     }
  509.    
  510.     /**
  511.      * Gets the drop time.
  512.      * @return the drop time
  513.      */
  514.     public long getDropTime()
  515.     {
  516.         return _dropTime;
  517.     }
  518.    
  519.     // Cupid's bow
  520.     /**
  521.      * Checks if is cupid bow.
  522.      * @return true, if is cupid bow
  523.      */
  524.     public boolean isCupidBow()
  525.     {
  526.         if (getItemId() == 9140 || getItemId() == 9141)
  527.             return true;
  528.         return false;
  529.     }
  530.    
  531.     /**
  532.      * Checks if is wear.
  533.      * @return true, if is wear
  534.      */
  535.     public boolean isWear()
  536.     {
  537.         return _wear;
  538.     }
  539.    
  540.     /**
  541.      * Sets the wear.
  542.      * @param newwear the new wear
  543.      */
  544.     public void setWear(final boolean newwear)
  545.     {
  546.         _wear = newwear;
  547.     }
  548.    
  549.     /**
  550.      * Returns the type of item.
  551.      * @return Enum
  552.      */
  553.     public Enum<?> getItemType()
  554.     {
  555.         return _item.getItemType();
  556.     }
  557.    
  558.     /**
  559.      * Returns the ID of the item.
  560.      * @return int
  561.      */
  562.     public int getItemId()
  563.     {
  564.         return _itemId;
  565.     }
  566.    
  567.     /**
  568.      * Returns the quantity of crystals for crystallization.
  569.      * @return int
  570.      */
  571.     public final int getCrystalCount()
  572.     {
  573.         return _item.getCrystalCount(_enchantLevel);
  574.     }
  575.    
  576.     /**
  577.      * Returns the reference price of the item.
  578.      * @return int
  579.      */
  580.     public int getReferencePrice()
  581.     {
  582.         return _item.getReferencePrice();
  583.     }
  584.    
  585.     /**
  586.      * Returns the name of the item.
  587.      * @return String
  588.      */
  589.     public String getItemName()
  590.     {
  591.         return _item.getName();
  592.     }
  593.    
  594.     /**
  595.      * Returns the price of the item for selling.
  596.      * @return int
  597.      */
  598.     public int getPriceToSell()
  599.     {
  600.         return isConsumable() ? (int) (_priceSell * Config.RATE_CONSUMABLE_COST) : _priceSell;
  601.     }
  602.    
  603.     /**
  604.      * Sets the price of the item for selling <U><I>Remark :</I></U> If loc and loc_data different from database, say datas not up-to-date.
  605.      * @param price : int designating the price
  606.      */
  607.     public void setPriceToSell(final int price)
  608.     {
  609.         _priceSell = price;
  610.         _storedInDb = false;
  611.     }
  612.    
  613.     /**
  614.      * Returns the price of the item for buying.
  615.      * @return int
  616.      */
  617.     // public int getPriceToBuy()
  618.     // {
  619.     // return isConsumable() ? (int) (_priceBuy * Config.RATE_CONSUMABLE_COST) : _priceBuy;
  620.     // }
  621.    
  622.     /**
  623.      * Sets the price of the item for buying <U><I>Remark :</I></U> If loc and loc_data different from database, say datas not up-to-date.
  624.      * @param price : int
  625.      */
  626.     // public void setPriceToBuy(int price)
  627.     // {
  628.     // _priceBuy = price;
  629.     // _storedInDb = false;
  630.     // }
  631.    
  632.     /**
  633.      * Returns the last change of the item.
  634.      * @return int
  635.      */
  636.     public int getLastChange()
  637.     {
  638.         return _lastChange;
  639.     }
  640.    
  641.     /**
  642.      * Sets the last change of the item.
  643.      * @param lastChange : int
  644.      */
  645.     public void setLastChange(final int lastChange)
  646.     {
  647.         _lastChange = lastChange;
  648.     }
  649.    
  650.     /**
  651.      * Returns if item is stackable.
  652.      * @return boolean
  653.      */
  654.     public boolean isStackable()
  655.     {
  656.         return _item.isStackable();
  657.     }
  658.    
  659.     /**
  660.      * Returns if item is dropable.
  661.      * @return boolean
  662.      */
  663.     public boolean isDropable()
  664.     {
  665.         return isAugmented() ? false : _item.isDropable();
  666.     }
  667.    
  668.     /**
  669.      * Returns if item is destroyable.
  670.      * @return boolean
  671.      */
  672.     public boolean isDestroyable()
  673.     {
  674.         return _item.isDestroyable();
  675.     }
  676.    
  677.     /**
  678.      * Returns if item is tradeable.
  679.      * @return boolean
  680.      */
  681.     public boolean isTradeable()
  682.     {
  683.         if(isSoulbound() || isAugmented())
  684.         {
  685.             return false;
  686.         }
  687.         else
  688.         {
  689.             return _item.isTradeable();
  690.         }
  691.     }
  692.    
  693.     /**
  694.      * Returns if item is consumable.
  695.      * @return boolean
  696.      */
  697.     public boolean isConsumable()
  698.     {
  699.         return _item.isConsumable();
  700.     }
  701.    
  702.     /**
  703.      * Returns if item is available for manipulation.
  704.      * @param player the player
  705.      * @param allowAdena the allow adena
  706.      * @param allowEquipped
  707.      * @return boolean
  708.      */
  709.     public boolean isAvailable(final L2PcInstance player, final boolean allowAdena, final boolean allowEquipped)
  710.     {
  711.         return (!isEquipped() || allowEquipped) && getItem().getType2() != L2Item.TYPE2_QUEST && (getItem().getType2() != L2Item.TYPE2_MONEY || getItem().getType1() != L2Item.TYPE1_SHIELD_ARMOR) // TODO: what does this mean?
  712.             && (player.getPet() == null || getObjectId() != player.getPet().getControlItemId()) // Not Control item of currently summoned pet
  713.             && player.getActiveEnchantItem() != this && (allowAdena || getItemId() != 57) && (player.getCurrentSkill() == null || player.getCurrentSkill().getSkill().getItemConsumeId() != getItemId()) && isTradeable();
  714.     }
  715.    
  716.     /*
  717.      * (non-Javadoc)
  718.      * @see com.l2jfrozen.gameserver.model.L2Object#onAction(com.l2jfrozen.gameserver.model.L2PcInstance) also check constraints: only soloing castle owners may pick up mercenary tickets of their castle
  719.      */
  720.     @Override
  721.     public void onAction(final L2PcInstance player)
  722.     {
  723.         // this causes the validate position handler to do the pickup if the location is reached.
  724.         // mercenary tickets can only be picked up by the castle owner and GMs.
  725.         if ((!player.isGM()) && (_itemId >= 3960 && _itemId <= 4021 && player.isInParty() || _itemId >= 3960 && _itemId <= 3969 && !player.isCastleLord(1) || _itemId >= 3973 && _itemId <= 3982 && !player.isCastleLord(2) || _itemId >= 3986 && _itemId <= 3995 && !player.isCastleLord(3) || _itemId >= 3999 && _itemId <= 4008 && !player.isCastleLord(4) || _itemId >= 4012 && _itemId <= 4021 && !player.isCastleLord(5) || _itemId >= 5205 && _itemId <= 5214 && !player.isCastleLord(6) || _itemId >= 6779 && _itemId <= 6788 && !player.isCastleLord(7) || _itemId >= 7973 && _itemId <= 7982 && !player.isCastleLord(8) || _itemId >= 7918 && _itemId <= 7927 && !player.isCastleLord(9)))
  726.         {
  727.             if (player.isInParty())
  728.                 player.sendMessage("You cannot pickup mercenaries while in a party.");
  729.             else
  730.                 player.sendMessage("Only the castle lord can pickup mercenaries.");
  731.            
  732.             player.setTarget(this);
  733.             player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  734.             // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  735.             player.sendPacket(ActionFailed.STATIC_PACKET);
  736.         }
  737.         else
  738.         {
  739.             if (player.getFreight().getItemByObjectId(this.getObjectId()) != null)
  740.             {
  741.                 player.setTarget(this);
  742.                 player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  743.                 // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
  744.                 player.sendPacket(ActionFailed.STATIC_PACKET);
  745.                
  746.                 Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to pickup Freight Items", IllegalPlayerAction.PUNISH_KICK);
  747.             }
  748.             else
  749.             {
  750.                 player.getAI().setIntention(CtrlIntention.AI_INTENTION_PICK_UP, this);
  751.             }
  752.         }
  753.     }
  754.    
  755.     /**
  756.      * Returns the level of enchantment of the item.
  757.      * @return int
  758.      */
  759.     public int getEnchantLevel()
  760.     {
  761.         return _enchantLevel;
  762.     }
  763.    
  764.     /**
  765.      * Sets the level of enchantment of the item.
  766.      * @param enchantLevel the new enchant level
  767.      */
  768.     public void setEnchantLevel(final int enchantLevel)
  769.     {
  770.         if (_enchantLevel == enchantLevel)
  771.             return;
  772.         _enchantLevel = enchantLevel;
  773.         _storedInDb = false;
  774.     }
  775.    
  776.     /**
  777.      * Returns the physical defense of the item.
  778.      * @return int
  779.      */
  780.     public int getPDef()
  781.     {
  782.         if (_item instanceof L2Armor)
  783.             return ((L2Armor) _item).getPDef();
  784.         return 0;
  785.     }
  786.    
  787.     /**
  788.      * Returns whether this item is augmented or not.
  789.      * @return true if augmented
  790.      */
  791.     public boolean isAugmented()
  792.     {
  793.         return _augmentation == null ? false : true;
  794.     }
  795.    
  796.     /**
  797.      * Returns the augmentation object for this item.
  798.      * @return augmentation
  799.      */
  800.     public L2Augmentation getAugmentation()
  801.     {
  802.         return _augmentation;
  803.     }
  804.    
  805.     /**
  806.      * Sets a new augmentation.
  807.      * @param augmentation the augmentation
  808.      * @return return true if sucessfull
  809.      */
  810.     public boolean setAugmentation(final L2Augmentation augmentation)
  811.     {
  812.         // there shall be no previous augmentation..
  813.         if (_augmentation != null)
  814.             return false;
  815.         _augmentation = augmentation;
  816.         return true;
  817.     }
  818.    
  819.     /**
  820.      * Remove the augmentation.
  821.      */
  822.     public void removeAugmentation()
  823.     {
  824.         if (_augmentation == null)
  825.             return;
  826.         _augmentation.deleteAugmentationData();
  827.         _augmentation = null;
  828.     }
  829.    
  830.     /**
  831.      * Used to decrease mana (mana means life time for shadow items).
  832.      */
  833.     public class ScheduleConsumeManaTask implements Runnable
  834.     {
  835.        
  836.         /** The _shadow item. */
  837.         private final L2ItemInstance _shadowItem;
  838.        
  839.         /**
  840.          * Instantiates a new schedule consume mana task.
  841.          * @param item the item
  842.          */
  843.         public ScheduleConsumeManaTask(final L2ItemInstance item)
  844.         {
  845.             _shadowItem = item;
  846.         }
  847.        
  848.         /*
  849.          * (non-Javadoc)
  850.          * @see java.lang.Runnable#run()
  851.          */
  852.         @Override
  853.         public void run()
  854.         {
  855.             try
  856.             {
  857.                 // decrease mana
  858.                 if (_shadowItem != null)
  859.                 {
  860.                     _shadowItem.decreaseMana(true);
  861.                 }
  862.             }
  863.             catch (final Throwable t)
  864.             {
  865.                 if (Config.ENABLE_ALL_EXCEPTIONS)
  866.                     t.printStackTrace();
  867.             }
  868.         }
  869.     }
  870.    
  871.     /**
  872.      * Returns true if this item is a shadow item Shadow items have a limited life-time.
  873.      * @return true, if is shadow item
  874.      */
  875.     public boolean isShadowItem()
  876.     {
  877.         return _mana >= 0;
  878.     }
  879.    
  880.     /**
  881.      * Sets the mana for this shadow item <b>NOTE</b>: does not send an inventory update packet.
  882.      * @param mana the new mana
  883.      */
  884.     public void setMana(final int mana)
  885.     {
  886.         _mana = mana;
  887.     }
  888.    
  889.     /**
  890.      * Returns the remaining mana of this shadow item.
  891.      * @return lifeTime
  892.      */
  893.     public int getMana()
  894.     {
  895.         return _mana;
  896.     }
  897.    
  898.     /**
  899.      * Decreases the mana of this shadow item, sends a inventory update schedules a new consumption task if non is running optionally one could force a new task.
  900.      * @param resetConsumingMana the reset consuming mana
  901.      */
  902.     public void decreaseMana(final boolean resetConsumingMana)
  903.     {
  904.         if (!isShadowItem())
  905.             return;
  906.        
  907.         if (_mana > 0)
  908.             _mana--;
  909.        
  910.         if (_storedInDb)
  911.             _storedInDb = false;
  912.         if (resetConsumingMana)
  913.             _consumingMana = false;
  914.        
  915.         L2PcInstance player = (L2PcInstance) L2World.getInstance().findObject(getOwnerId());
  916.         if (player != null)
  917.         {
  918.             SystemMessage sm;
  919.             switch (_mana)
  920.             {
  921.                 case 10:
  922.                     sm = new SystemMessage(SystemMessageId.S1S_REMAINING_MANA_IS_NOW_10);
  923.                     sm.addString(getItemName());
  924.                     player.sendPacket(sm);
  925.                     break;
  926.                 case 5:
  927.                     sm = new SystemMessage(SystemMessageId.S1S_REMAINING_MANA_IS_NOW_5);
  928.                     sm.addString(getItemName());
  929.                     player.sendPacket(sm);
  930.                     break;
  931.                 case 1:
  932.                     sm = new SystemMessage(SystemMessageId.S1S_REMAINING_MANA_IS_NOW_1);
  933.                     sm.addString(getItemName());
  934.                     player.sendPacket(sm);
  935.                     break;
  936.             }
  937.            
  938.             if (_mana == 0) // The life time has expired
  939.             {
  940.                 sm = new SystemMessage(SystemMessageId.S1S_REMAINING_MANA_IS_NOW_0);
  941.                 sm.addString(getItemName());
  942.                 player.sendPacket(sm);
  943.                
  944.                 // unequip
  945.                 if (isEquipped())
  946.                 {
  947.                     L2ItemInstance[] unequiped = player.getInventory().unEquipItemInSlotAndRecord(getEquipSlot());
  948.                     InventoryUpdate iu = new InventoryUpdate();
  949.                    
  950.                     for (final L2ItemInstance element : unequiped)
  951.                     {
  952.                         player.checkSSMatch(null, element);
  953.                         iu.addModifiedItem(element);
  954.                     }
  955.                    
  956.                     player.sendPacket(iu);
  957.                    
  958.                     unequiped = null;
  959.                     iu = null;
  960.                 }
  961.                
  962.                 if (getLocation() != ItemLocation.WAREHOUSE)
  963.                 {
  964.                     // destroy
  965.                     player.getInventory().destroyItem("L2ItemInstance", this, player, null);
  966.                    
  967.                     // send update
  968.                     InventoryUpdate iu = new InventoryUpdate();
  969.                     iu.addRemovedItem(this);
  970.                     player.sendPacket(iu);
  971.                     iu = null;
  972.                    
  973.                     StatusUpdate su = new StatusUpdate(player.getObjectId());
  974.                     su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
  975.                     player.sendPacket(su);
  976.                     su = null;
  977.                 }
  978.                 else
  979.                 {
  980.                     player.getWarehouse().destroyItem("L2ItemInstance", this, player, null);
  981.                 }
  982.                
  983.                 // delete from world
  984.                 L2World.getInstance().removeObject(this);
  985.             }
  986.             else
  987.             {
  988.                 // Reschedule if still equipped
  989.                 if (!_consumingMana && isEquipped())
  990.                     scheduleConsumeManaTask();
  991.                
  992.                 if (getLocation() != ItemLocation.WAREHOUSE)
  993.                 {
  994.                     InventoryUpdate iu = new InventoryUpdate();
  995.                     iu.addModifiedItem(this);
  996.                     player.sendPacket(iu);
  997.                     iu = null;
  998.                 }
  999.             }
  1000.            
  1001.             sm = null;
  1002.         }
  1003.        
  1004.         player = null;
  1005.     }
  1006.    
  1007.     /**
  1008.      * Schedule consume mana task.
  1009.      */
  1010.     private void scheduleConsumeManaTask()
  1011.     {
  1012.         _consumingMana = true;
  1013.         ThreadPoolManager.getInstance().scheduleGeneral(new ScheduleConsumeManaTask(this), MANA_CONSUMPTION_RATE);
  1014.     }
  1015.    
  1016.     /**
  1017.      * Returns false cause item can't be attacked.
  1018.      * @param attacker the attacker
  1019.      * @return boolean false
  1020.      */
  1021.     @Override
  1022.     public boolean isAutoAttackable(final L2Character attacker)
  1023.     {
  1024.         return false;
  1025.     }
  1026.    
  1027.     /**
  1028.      * Returns the type of charge with SoulShot of the item.
  1029.      * @return int (CHARGED_NONE, CHARGED_SOULSHOT)
  1030.      */
  1031.     public int getChargedSoulshot()
  1032.     {
  1033.         return _chargedSoulshot;
  1034.     }
  1035.    
  1036.     /**
  1037.      * Returns the type of charge with SpiritShot of the item.
  1038.      * @return int (CHARGED_NONE, CHARGED_SPIRITSHOT, CHARGED_BLESSED_SPIRITSHOT)
  1039.      */
  1040.     public int getChargedSpiritshot()
  1041.     {
  1042.         return _chargedSpiritshot;
  1043.     }
  1044.    
  1045.     /**
  1046.      * Gets the charged fishshot.
  1047.      * @return the charged fishshot
  1048.      */
  1049.     public boolean getChargedFishshot()
  1050.     {
  1051.         return _chargedFishtshot;
  1052.     }
  1053.    
  1054.     /**
  1055.      * Sets the type of charge with SoulShot of the item.
  1056.      * @param type : int (CHARGED_NONE, CHARGED_SOULSHOT)
  1057.      */
  1058.     public void setChargedSoulshot(final int type)
  1059.     {
  1060.         _chargedSoulshot = type;
  1061.     }
  1062.    
  1063.     /**
  1064.      * Sets the type of charge with SpiritShot of the item.
  1065.      * @param type : int (CHARGED_NONE, CHARGED_SPIRITSHOT, CHARGED_BLESSED_SPIRITSHOT)
  1066.      */
  1067.     public void setChargedSpiritshot(final int type)
  1068.     {
  1069.         _chargedSpiritshot = type;
  1070.     }
  1071.    
  1072.     /**
  1073.      * Sets the charged fishshot.
  1074.      * @param type the new charged fishshot
  1075.      */
  1076.     public void setChargedFishshot(final boolean type)
  1077.     {
  1078.         _chargedFishtshot = type;
  1079.     }
  1080.    
  1081.     /**
  1082.      * This function basically returns a set of functions from L2Item/L2Armor/L2Weapon, but may add additional functions, if this particular item instance is enhanched for a particular player.
  1083.      * @param player : L2Character designating the player
  1084.      * @return Func[]
  1085.      */
  1086.     public Func[] getStatFuncs(final L2Character player)
  1087.     {
  1088.         return getItem().getStatFuncs(this, player);
  1089.     }
  1090.    
  1091.     /**
  1092.      * Updates database.<BR>
  1093.      * <BR>
  1094.      * <U><I>Concept : </I></U><BR>
  1095.      * <B>IF</B> the item exists in database :
  1096.      * <UL>
  1097.      * <LI><B>IF</B> the item has no owner, or has no location, or has a null quantity : remove item from database</LI>
  1098.      * <LI><B>ELSE</B> : update item in database</LI>
  1099.      * </UL>
  1100.      * <B> Otherwise</B> :
  1101.      * <UL>
  1102.      * <LI><B>IF</B> the item hasn't a null quantity, and has a correct location, and has a correct owner : insert item in database</LI>
  1103.      * </UL>
  1104.      */
  1105.     public void updateDatabase()
  1106.     {
  1107.         // LOGGER.info("Item: "+getItemId()+" Loc: "+_loc.name()+" ExistInDb: "+_existsInDb+" owner: "+_ownerId);
  1108.        
  1109.         if (isWear())
  1110.             return;
  1111.        
  1112.         if (_existsInDb)
  1113.         {
  1114.             if (_ownerId == 0 || _loc == ItemLocation.VOID || _count == 0 && _loc != ItemLocation.LEASE)
  1115.                 removeFromDb();
  1116.             else
  1117.                 updateInDb();
  1118.         }
  1119.         else
  1120.         {
  1121.             if (_count == 0 && _loc != ItemLocation.LEASE)
  1122.                 return;
  1123.            
  1124.             if (_loc == ItemLocation.VOID || _ownerId == 0)
  1125.                 return;
  1126.            
  1127.             insertIntoDb();
  1128.         }
  1129.     }
  1130.    
  1131.     /**
  1132.      * Returns a L2ItemInstance stored in database from its objectID.
  1133.      * @param objectId : int designating the objectID of the item
  1134.      * @return L2ItemInstance
  1135.      */
  1136.     public static L2ItemInstance restoreFromDb(final int objectId)
  1137.     {
  1138.         L2ItemInstance inst = null;
  1139.         Connection con = null;
  1140.        
  1141.         try
  1142.         {
  1143.             con = L2DatabaseFactory.getInstance().getConnection(false);
  1144.             PreparedStatement statement = con.prepareStatement("SELECT owner_id, object_id, item_id, count, enchant_level, loc, loc_data, price_sell, price_buy, custom_type1, custom_type2, mana_left, soulbound FROM items WHERE object_id = ?");
  1145.             statement.setInt(1, objectId);
  1146.             ResultSet rs = statement.executeQuery();
  1147.            
  1148.             if (rs.next())
  1149.             {
  1150.                 final int owner_id = rs.getInt("owner_id");
  1151.                 final int item_id = rs.getInt("item_id");
  1152.                 final int count = rs.getInt("count");
  1153.                
  1154.                 ItemLocation loc = ItemLocation.valueOf(rs.getString("loc"));
  1155.                
  1156.                 final int loc_data = rs.getInt("loc_data");
  1157.                 final int enchant_level = rs.getInt("enchant_level");
  1158.                 final int custom_type1 = rs.getInt("custom_type1");
  1159.                 final int custom_type2 = rs.getInt("custom_type2");
  1160.                 final int price_sell = rs.getInt("price_sell");
  1161.                 final int price_buy = rs.getInt("price_buy");
  1162.                 final int manaLeft = rs.getInt("mana_left");
  1163.                 final int soulbound = rs.getBoolean("soulbound");
  1164.                
  1165.                 L2Item item = ItemTable.getInstance().getTemplate(item_id);
  1166.                
  1167.                 if (item == null)
  1168.                 {
  1169.                     LOGGER.warn("Item item_id=" + item_id + " not known, object_id=" + objectId);
  1170.                     rs.close();
  1171.                     DatabaseUtils.close(statement);
  1172.                     CloseUtil.close(con);
  1173.                     return null;
  1174.                 }
  1175.                
  1176.                 inst = new L2ItemInstance(objectId, item);
  1177.                 inst._existsInDb = true;
  1178.                 inst._storedInDb = true;
  1179.                 inst._ownerId = owner_id;
  1180.                 inst._count = count;
  1181.                 inst._enchantLevel = enchant_level;
  1182.                 inst._type1 = custom_type1;
  1183.                 inst._type2 = custom_type2;
  1184.                 inst._loc = loc;
  1185.                 inst._locData = loc_data;
  1186.                 inst._priceSell = price_sell;
  1187.                 inst._priceBuy = price_buy;
  1188.                 inst.soulbound = soulbound;
  1189.                
  1190.                 // Setup life time for shadow weapons
  1191.                 inst._mana = manaLeft;
  1192.                
  1193.                 // consume 1 mana
  1194.                 if (inst._mana > 0 && inst.getLocation() == ItemLocation.PAPERDOLL)
  1195.                     inst.decreaseMana(false);
  1196.                
  1197.                 // if mana left is 0 delete this item
  1198.                 if (inst._mana == 0)
  1199.                 {
  1200.                     inst.removeFromDb();
  1201.                    
  1202.                     rs.close();
  1203.                     DatabaseUtils.close(statement);
  1204.                     CloseUtil.close(con);
  1205.                    
  1206.                     return null;
  1207.                 }
  1208.                 else if (inst._mana > 0 && inst.getLocation() == ItemLocation.PAPERDOLL)
  1209.                 {
  1210.                     inst.scheduleConsumeManaTask();
  1211.                 }
  1212.                
  1213.                 loc = null;
  1214.                 item = null;
  1215.             }
  1216.             else
  1217.             {
  1218.                 LOGGER.warn("Item object_id=" + objectId + " not found");
  1219.                
  1220.                 rs.close();
  1221.                 DatabaseUtils.close(statement);
  1222.                 CloseUtil.close(con);
  1223.                
  1224.                 return null;
  1225.             }
  1226.            
  1227.             rs.close();
  1228.             DatabaseUtils.close(statement);
  1229.            
  1230.             // load augmentation
  1231.             statement = con.prepareStatement("SELECT attributes,skill,level FROM augmentations WHERE item_id=?");
  1232.             statement.setInt(1, objectId);
  1233.             rs = statement.executeQuery();
  1234.            
  1235.             if (rs.next())
  1236.                 inst._augmentation = new L2Augmentation(inst, rs.getInt("attributes"), rs.getInt("skill"), rs.getInt("level"), false);
  1237.            
  1238.             rs.close();
  1239.             DatabaseUtils.close(statement);
  1240.             rs = null;
  1241.             statement = null;
  1242.         }
  1243.         catch (final Exception e)
  1244.         {
  1245.             LOGGER.error("Could not restore item " + objectId + " from DB", e);
  1246.         }
  1247.         finally
  1248.         {
  1249.             CloseUtil.close(con);
  1250.            
  1251.         }
  1252.        
  1253.         if (inst != null)
  1254.             inst.fireEvent(EventType.LOAD.name, new Object[] {
  1255.             // con
  1256.             });
  1257.        
  1258.         return inst;
  1259.     }
  1260.    
  1261.     /**
  1262.      * Init a dropped L2ItemInstance and add it in the world as a visible object.<BR>
  1263.      * <BR>
  1264.      * <B><U> Actions</U> :</B><BR>
  1265.      * <BR>
  1266.      * <li>Set the x,y,z position of the L2ItemInstance dropped and update its _worldregion</li> <li>Add the L2ItemInstance dropped to _visibleObjects of its L2WorldRegion</li> <li>Add the L2ItemInstance dropped in the world as a <B>visible</B> object</li><BR>
  1267.      * <BR>
  1268.      * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T ADD the object to _allObjects of L2World </B></FONT><BR>
  1269.      * <BR>
  1270.      * <B><U> Assert </U> :</B><BR>
  1271.      * <BR>
  1272.      * <li>_worldRegion == null <I>(L2Object is invisible at the beginning)</I></li><BR>
  1273.      * <BR>
  1274.      * <B><U> Example of use </U> :</B><BR>
  1275.      * <BR>
  1276.      * <li>Drop item</li> <li>Call Pet</li><BR>
  1277.      * @param dropper the dropper
  1278.      * @param x the x
  1279.      * @param y the y
  1280.      * @param z the z
  1281.      */
  1282.     public final void dropMe(final L2Character dropper, int x, int y, int z)
  1283.     {
  1284.         if (Config.ASSERT)
  1285.             assert getPosition().getWorldRegion() == null;
  1286.        
  1287.         if (Config.GEODATA > 0 && dropper != null)
  1288.         {
  1289.             Location dropDest = GeoData.getInstance().moveCheck(dropper.getX(), dropper.getY(), dropper.getZ(), x, y, z);
  1290.            
  1291.             if (dropDest != null && dropDest.getX() != 0 && dropDest.getY() != 0)
  1292.             {
  1293.                
  1294.                 x = dropDest.getX();
  1295.                 y = dropDest.getY();
  1296.                 z = dropDest.getZ();
  1297.                
  1298.             }
  1299.            
  1300.             dropDest = null;
  1301.         }
  1302.        
  1303.         synchronized (this)
  1304.         {
  1305.             // Set the x,y,z position of the L2ItemInstance dropped and update its _worldregion
  1306.             setIsVisible(true);
  1307.             getPosition().setWorldPosition(x, y, z);
  1308.             getPosition().setWorldRegion(L2World.getInstance().getRegion(getPosition().getWorldPosition()));
  1309.            
  1310.             // Add the L2ItemInstance dropped to _visibleObjects of its L2WorldRegion
  1311.             getPosition().getWorldRegion().addVisibleObject(this);
  1312.         }
  1313.        
  1314.         setDropTime(System.currentTimeMillis());
  1315.        
  1316.         // this can synchronize on others instancies, so it's out of
  1317.         // synchronized, to avoid deadlocks
  1318.         // Add the L2ItemInstance dropped in the world as a visible object
  1319.         L2World.getInstance().addVisibleObject(this, getPosition().getWorldRegion(), dropper);
  1320.        
  1321.         if (Config.SAVE_DROPPED_ITEM)
  1322.             ItemsOnGroundManager.getInstance().save(this);
  1323.     }
  1324.    
  1325.     /**
  1326.      * Update the database with values of the item.
  1327.      */
  1328.     private void updateInDb()
  1329.     {
  1330.         if (Config.ASSERT)
  1331.             assert _existsInDb;
  1332.        
  1333.         if (_wear)
  1334.             return;
  1335.        
  1336.         if (_storedInDb)
  1337.             return;
  1338.        
  1339.         Connection con = null;
  1340.         try
  1341.         {
  1342.             con = L2DatabaseFactory.getInstance().getConnection(false);
  1343.             PreparedStatement statement = con.prepareStatement("UPDATE items SET owner_id=?,count=?,loc=?,loc_data=?,enchant_level=?,price_sell=?,price_buy=?,custom_type1=?,custom_type2=?,mana_left=?,soulbound=? " + "WHERE object_id = ?");
  1344.             statement.setInt(1, _ownerId);
  1345.             statement.setInt(2, getCount());
  1346.             statement.setString(3, _loc.name());
  1347.             statement.setInt(4, _locData);
  1348.             statement.setInt(5, getEnchantLevel());
  1349.             statement.setInt(6, _priceSell);
  1350.             statement.setInt(7, _priceBuy);
  1351.             statement.setInt(8, getCustomType1());
  1352.             statement.setInt(9, getCustomType2());
  1353.             statement.setInt(10, getMana());
  1354.             statement.setBoolean(11, isSoulbound());
  1355.             statement.setInt(12, getObjectId());
  1356.             statement.executeUpdate();
  1357.             _existsInDb = true;
  1358.             _storedInDb = true;
  1359.             DatabaseUtils.close(statement);
  1360.             statement = null;
  1361.            
  1362.         }
  1363.         catch (final Exception e)
  1364.         {
  1365.             if (Config.ENABLE_ALL_EXCEPTIONS)
  1366.                 e.printStackTrace();
  1367.            
  1368.             LOGGER.error("Could not update item " + getObjectId() + " in DB: Reason: ");
  1369.             e.printStackTrace();
  1370.         }
  1371.         finally
  1372.         {
  1373.             CloseUtil.close(con);
  1374.             con = null;
  1375.            
  1376.         }
  1377.        
  1378.         if (_existsInDb)
  1379.             fireEvent(EventType.STORE.name, (Object[]) null);
  1380.     }
  1381.    
  1382.     /**
  1383.      * Insert the item in database.
  1384.      */
  1385.     private void insertIntoDb()
  1386.     {
  1387.         if (_wear)
  1388.             return;
  1389.        
  1390.         if (Config.ASSERT)
  1391.             assert !_existsInDb && getObjectId() != 0;
  1392.        
  1393.         Connection con = null;
  1394.         try
  1395.         {
  1396.             con = L2DatabaseFactory.getInstance().getConnection(false);
  1397.             PreparedStatement statement = con.prepareStatement("INSERT INTO items (owner_id,item_id,count,loc,loc_data,enchant_level,price_sell,price_buy,object_id,custom_type1,custom_type2,mana_left,soulbound) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
  1398.             statement.setInt(1, _ownerId);
  1399.             statement.setInt(2, _itemId);
  1400.             statement.setInt(3, getCount());
  1401.             statement.setString(4, _loc.name());
  1402.             statement.setInt(5, _locData);
  1403.             statement.setInt(6, getEnchantLevel());
  1404.             statement.setInt(7, _priceSell);
  1405.             statement.setInt(8, _priceBuy);
  1406.             statement.setInt(9, getObjectId());
  1407.             statement.setInt(10, _type1);
  1408.             statement.setInt(11, _type2);
  1409.             statement.setInt(12, getMana());
  1410.             statement.setInt(13, isSoulbound());
  1411.            
  1412.             statement.executeUpdate();
  1413.             _existsInDb = true;
  1414.             _storedInDb = true;
  1415.             DatabaseUtils.close(statement);
  1416.             statement = null;
  1417.            
  1418.         }
  1419.         catch (final MySQLIntegrityConstraintViolationException e)
  1420.         {
  1421.             // if(Config.ENABLE_ALL_EXCEPTIONS)
  1422.             // e.printStackTrace();
  1423.            
  1424.             if (Config.DEBUG)
  1425.                 LOGGER.error("ATTENTION: Update Item instead of Insert one, check player with id " + this.getOwnerId() + " actions on item " + this.getObjectId());
  1426.             updateInDb();
  1427.            
  1428.         }
  1429.         catch (final SQLException e)
  1430.         {
  1431.             e.printStackTrace();
  1432.         }
  1433.         finally
  1434.         {
  1435.             CloseUtil.close(con);
  1436.         }
  1437.     }
  1438.    
  1439.     /**
  1440.      * Delete item from database.
  1441.      */
  1442.     private void removeFromDb()
  1443.     {
  1444.         if (_wear)
  1445.             return;
  1446.        
  1447.         if (Config.ASSERT)
  1448.             assert _existsInDb;
  1449.        
  1450.         // delete augmentation data
  1451.         if (isAugmented())
  1452.             _augmentation.deleteAugmentationData();
  1453.        
  1454.         Connection con = null;
  1455.         try
  1456.         {
  1457.             con = L2DatabaseFactory.getInstance().getConnection(false);
  1458.             PreparedStatement statement = con.prepareStatement("DELETE FROM items WHERE object_id=?");
  1459.             statement.setInt(1, getObjectId());
  1460.             statement.executeUpdate();
  1461.             _existsInDb = false;
  1462.             _storedInDb = false;
  1463.             DatabaseUtils.close(statement);
  1464.             statement = null;
  1465.            
  1466.         }
  1467.         catch (final Exception e)
  1468.         {
  1469.             LOGGER.error("Could not delete item " + getObjectId() + " in DB:", e);
  1470.             e.printStackTrace();
  1471.         }
  1472.         finally
  1473.         {
  1474.             CloseUtil.close(con);
  1475.         }
  1476.        
  1477.         if (!_existsInDb)
  1478.             fireEvent(EventType.DELETE.name, (Object[]) null);
  1479.     }
  1480.    
  1481.     /**
  1482.      * Returns the item in String format.
  1483.      * @return String
  1484.      */
  1485.     @Override
  1486.     public String toString()
  1487.     {
  1488.         return "" + _item;
  1489.     }
  1490.    
  1491.     /**
  1492.      * Reset owner timer.
  1493.      */
  1494.     public void resetOwnerTimer()
  1495.     {
  1496.         if (itemLootShedule != null)
  1497.         {
  1498.             itemLootShedule.cancel(true);
  1499.         }
  1500.         itemLootShedule = null;
  1501.     }
  1502.    
  1503.     /**
  1504.      * Sets the item loot shedule.
  1505.      * @param sf the new item loot shedule
  1506.      */
  1507.     public void setItemLootShedule(final ScheduledFuture<?> sf)
  1508.     {
  1509.         itemLootShedule = sf;
  1510.     }
  1511.    
  1512.     /**
  1513.      * Gets the item loot shedule.
  1514.      * @return the item loot shedule
  1515.      */
  1516.     public ScheduledFuture<?> getItemLootShedule()
  1517.     {
  1518.         return itemLootShedule;
  1519.     }
  1520.    
  1521.     /**
  1522.      * Sets the protected.
  1523.      * @param is_protected the new protected
  1524.      */
  1525.     public void setProtected(final boolean is_protected)
  1526.     {
  1527.         _protected = is_protected;
  1528.     }
  1529.    
  1530.     /**
  1531.      * Checks if is protected.
  1532.      * @return true, if is protected
  1533.      */
  1534.     public boolean isProtected()
  1535.     {
  1536.         return _protected;
  1537.     }
  1538.    
  1539.     /**
  1540.      * Checks if is night lure.
  1541.      * @return true, if is night lure
  1542.      */
  1543.     public boolean isNightLure()
  1544.     {
  1545.         return _itemId >= 8505 && _itemId <= 8513 || _itemId == 8485;
  1546.     }
  1547.    
  1548.     /**
  1549.      * Sets the count decrease.
  1550.      * @param decrease the new count decrease
  1551.      */
  1552.     public void setCountDecrease(final boolean decrease)
  1553.     {
  1554.         _decrease = decrease;
  1555.     }
  1556.    
  1557.     /**
  1558.      * Gets the count decrease.
  1559.      * @return the count decrease
  1560.      */
  1561.     public boolean getCountDecrease()
  1562.     {
  1563.         return _decrease;
  1564.     }
  1565.    
  1566.     /**
  1567.      * Sets the inits the count.
  1568.      * @param InitCount the new inits the count
  1569.      */
  1570.     public void setInitCount(final int InitCount)
  1571.     {
  1572.         _initCount = InitCount;
  1573.     }
  1574.    
  1575.     /**
  1576.      * Gets the inits the count.
  1577.      * @return the inits the count
  1578.      */
  1579.     public int getInitCount()
  1580.     {
  1581.         return _initCount;
  1582.     }
  1583.    
  1584.     /**
  1585.      * Restore init count.
  1586.      */
  1587.     public void restoreInitCount()
  1588.     {
  1589.         if (_decrease)
  1590.             _count = _initCount;
  1591.     }
  1592.    
  1593.     /**
  1594.      * Sets the time.
  1595.      * @param time the new time
  1596.      */
  1597.     public void setTime(final int time)
  1598.     {
  1599.         if (time > 0)
  1600.             _time = time;
  1601.         else
  1602.             _time = 0;
  1603.     }
  1604.    
  1605.     /**
  1606.      * Gets the time.
  1607.      * @return the time
  1608.      */
  1609.     public int getTime()
  1610.     {
  1611.         return _time;
  1612.     }
  1613.    
  1614.     /**
  1615.      * Returns the slot where the item is stored.
  1616.      * @return int
  1617.      */
  1618.     public int getLocationSlot()
  1619.     {
  1620.         if (Config.ASSERT)
  1621.             assert _loc == ItemLocation.PAPERDOLL || _loc == ItemLocation.PET_EQUIP || _loc == ItemLocation.FREIGHT || _loc == ItemLocation.INVENTORY;
  1622.        
  1623.         return _locData;
  1624.     }
  1625.    
  1626.     /**
  1627.      * Gets the drop protection.
  1628.      * @return the drop protection
  1629.      */
  1630.     public final DropProtection getDropProtection()
  1631.     {
  1632.         return _dropProtection;
  1633.     }
  1634.    
  1635.     /**
  1636.      * Checks if is varka ketra ally quest item.
  1637.      * @return true, if is varka ketra ally quest item
  1638.      */
  1639.     public boolean isVarkaKetraAllyQuestItem()
  1640.     {
  1641.        
  1642.         if ((this.getItemId() >= 7211 && this.getItemId() <= 7215) || (this.getItemId() >= 7221 && this.getItemId() <= 7225))
  1643.         {
  1644.            
  1645.             return true;
  1646.            
  1647.         }
  1648.        
  1649.         return false;
  1650.        
  1651.     }
  1652.    
  1653.     public boolean isOlyRestrictedItem()
  1654.     {
  1655.         return (Config.LIST_OLY_RESTRICTED_ITEMS.contains(_itemId));
  1656.     }
  1657.    
  1658.     public boolean isHeroItem()
  1659.     {
  1660.         return ((_itemId >= 6611 && _itemId <= 6621) || (_itemId >= 9388 && _itemId <= 9390) || _itemId == 6842);
  1661.     }
  1662.    
  1663.     public boolean checkOlympCondition()
  1664.     {
  1665.         if (isHeroItem() || isOlyRestrictedItem() || isWear() || (!Config.ALT_OLY_AUGMENT_ALLOW && isAugmented()))
  1666.             return false;
  1667.         return true;
  1668.     }
  1669.    
  1670.     /**
  1671.      * Returns true if item is a Weapon/Shield
  1672.      * @return boolean
  1673.      */
  1674.     public boolean isWeapon()
  1675.     {
  1676.         return (_item instanceof L2Weapon);
  1677.     }
  1678.    
  1679.     private boolean soulbound = false;
  1680.    
  1681.     public boolean isSoulbound()
  1682.     {
  1683.         return soulbound;
  1684.     }
  1685.    
  1686.     public void setSoulbound(boolean val)
  1687.     {
  1688.         soulbound = val;
  1689.     }
  1690.    
  1691. }
Advertisement
Add Comment
Please, Sign In to add comment