PcInventory.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model.itemcontainer;
  16. import java.sql.Connection;
  17. import java.sql.PreparedStatement;
  18. import java.sql.ResultSet;
  19. import java.util.List;
  20. import java.util.logging.Level;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.L2DatabaseFactory;
  23. import com.l2jserver.gameserver.model.L2ItemInstance;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.TradeList;
  26. import com.l2jserver.gameserver.model.L2ItemInstance.ItemLocation;
  27. import com.l2jserver.gameserver.model.TradeList.TradeItem;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
  30. import com.l2jserver.gameserver.network.serverpackets.ItemList;
  31. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  32. import com.l2jserver.gameserver.templates.item.L2EtcItemType;
  33. import javolution.util.FastList;
  34. public class PcInventory extends Inventory
  35. {
  36. public static final int ADENA_ID = 57;
  37. public static final int ANCIENT_ADENA_ID = 5575;
  38. public static final long MAX_ADENA = 99900000000L;
  39. private final L2PcInstance _owner;
  40. private L2ItemInstance _adena;
  41. private L2ItemInstance _ancientAdena;
  42. public PcInventory(L2PcInstance owner)
  43. {
  44. _owner = owner;
  45. }
  46. @Override
  47. public L2PcInstance getOwner() { return _owner; }
  48. @Override
  49. protected ItemLocation getBaseLocation() { return ItemLocation.INVENTORY; }
  50. @Override
  51. protected ItemLocation getEquipLocation() { return ItemLocation.PAPERDOLL; }
  52. public L2ItemInstance getAdenaInstance() {return _adena;}
  53. @Override
  54. public long getAdena() {return _adena != null ? _adena.getCount() : 0;}
  55. public L2ItemInstance getAncientAdenaInstance()
  56. {
  57. return _ancientAdena;
  58. }
  59. public long getAncientAdena()
  60. {
  61. return (_ancientAdena != null) ? _ancientAdena.getCount() : 0;
  62. }
  63. /**
  64. * Returns the list of items in inventory available for transaction
  65. * @return L2ItemInstance : items in inventory
  66. */
  67. public L2ItemInstance[] getUniqueItems(boolean allowAdena, boolean allowAncientAdena)
  68. {
  69. return getUniqueItems(allowAdena, allowAncientAdena, true);
  70. }
  71. public L2ItemInstance[] getUniqueItems(boolean allowAdena, boolean allowAncientAdena, boolean onlyAvailable)
  72. {
  73. List<L2ItemInstance> list = new FastList<L2ItemInstance>();
  74. for (L2ItemInstance item : _items)
  75. {
  76. if ((!allowAdena && item.getItemId() == 57))
  77. continue;
  78. if ((!allowAncientAdena && item.getItemId() == 5575))
  79. continue;
  80. boolean isDuplicate = false;
  81. for (L2ItemInstance litem : list)
  82. {
  83. if (litem.getItemId() == item.getItemId())
  84. {
  85. isDuplicate = true;
  86. break;
  87. }
  88. }
  89. if (!isDuplicate && (!onlyAvailable || (item.isSellable() && item.isAvailable(getOwner(), false, false)))) list.add(item);
  90. }
  91. return list.toArray(new L2ItemInstance[list.size()]);
  92. }
  93. /**
  94. * Returns the list of items in inventory available for transaction
  95. * Allows an item to appear twice if and only if there is a difference in enchantment level.
  96. * @return L2ItemInstance : items in inventory
  97. */
  98. public L2ItemInstance[] getUniqueItemsByEnchantLevel(boolean allowAdena, boolean allowAncientAdena)
  99. {
  100. return getUniqueItemsByEnchantLevel(allowAdena, allowAncientAdena, true);
  101. }
  102. public L2ItemInstance[] getUniqueItemsByEnchantLevel(boolean allowAdena, boolean allowAncientAdena, boolean onlyAvailable)
  103. {
  104. List<L2ItemInstance> list = new FastList<L2ItemInstance>();
  105. for (L2ItemInstance item : _items)
  106. {
  107. if ((!allowAdena && item.getItemId() == 57))
  108. continue;
  109. if ((!allowAncientAdena && item.getItemId() == 5575))
  110. continue;
  111. boolean isDuplicate = false;
  112. for (L2ItemInstance litem : list)
  113. if( (litem.getItemId() == item.getItemId()) && (litem.getEnchantLevel() == item.getEnchantLevel()))
  114. {
  115. isDuplicate = true;
  116. break;
  117. }
  118. if (!isDuplicate && (!onlyAvailable || (item.isSellable() && item.isAvailable(getOwner(), false, false)))) list.add(item);
  119. }
  120. return list.toArray(new L2ItemInstance[list.size()]);
  121. }
  122. /**
  123. * @see net.sf.l2j.gameserver.model.itemcontainer.PcInventory#getAllItemsByItemId(int, boolean)
  124. */
  125. public L2ItemInstance[] getAllItemsByItemId(int itemId)
  126. {
  127. return getAllItemsByItemId(itemId, true);
  128. }
  129. /**
  130. * Returns the list of all items in inventory that have a given item id.
  131. * @param itemId : ID of item
  132. * @param includeEquipped : include equipped items
  133. * @return L2ItemInstance[] : matching items from inventory
  134. */
  135. public L2ItemInstance[] getAllItemsByItemId(int itemId, boolean includeEquipped)
  136. {
  137. List<L2ItemInstance> list = new FastList<L2ItemInstance>();
  138. for (L2ItemInstance item : _items)
  139. {
  140. if (item.getItemId() == itemId && (includeEquipped || !item.isEquipped()))
  141. list.add(item);
  142. }
  143. return list.toArray(new L2ItemInstance[list.size()]);
  144. }
  145. /**
  146. * @see net.sf.l2j.gameserver.model.itemcontainer.PcInventory#getAllItemsByItemId(int, int, boolean)
  147. */
  148. public L2ItemInstance[] getAllItemsByItemId(int itemId, int enchantment)
  149. {
  150. return getAllItemsByItemId(itemId, enchantment, true);
  151. }
  152. /**
  153. * Returns the list of all items in inventory that have a given item id AND a given enchantment level.
  154. * @param itemId : ID of item
  155. * @param enchantment : enchant level of item
  156. * @param includeEquipped : include equipped items
  157. * @return L2ItemInstance[] : matching items from inventory
  158. */
  159. public L2ItemInstance[] getAllItemsByItemId(int itemId, int enchantment, boolean includeEquipped)
  160. {
  161. List<L2ItemInstance> list = new FastList<L2ItemInstance>();
  162. for (L2ItemInstance item : _items)
  163. {
  164. if ((item.getItemId() == itemId) && (item.getEnchantLevel() == enchantment) && (includeEquipped || !item.isEquipped()))
  165. list.add(item);
  166. }
  167. return list.toArray(new L2ItemInstance[list.size()]);
  168. }
  169. /**
  170. * Returns the list of items in inventory available for transaction
  171. * @return L2ItemInstance : items in inventory
  172. */
  173. public L2ItemInstance[] getAvailableItems(boolean allowAdena, boolean allowNonTradeable)
  174. {
  175. List<L2ItemInstance> list = new FastList<L2ItemInstance>();
  176. for (L2ItemInstance item : _items)
  177. if (item != null && item.isAvailable(getOwner(), allowAdena, allowNonTradeable)) list.add(item);
  178. return list.toArray(new L2ItemInstance[list.size()]);
  179. }
  180. /**
  181. * Get all augmented items
  182. * @return
  183. */
  184. public L2ItemInstance[] getAugmentedItems()
  185. {
  186. List<L2ItemInstance> list = new FastList<L2ItemInstance>();
  187. for (L2ItemInstance item : _items)
  188. if (item != null && item.isAugmented()) list.add(item);
  189. return list.toArray(new L2ItemInstance[list.size()]);
  190. }
  191. /**
  192. * Get all element items
  193. * @return
  194. */
  195. public L2ItemInstance[] getElementItems()
  196. {
  197. List<L2ItemInstance> list = new FastList<L2ItemInstance>();
  198. for (L2ItemInstance item : _items)
  199. {
  200. if (item != null && item.getElementals() != null)
  201. list.add(item);
  202. }
  203. return list.toArray(new L2ItemInstance[list.size()]);
  204. }
  205. /**
  206. * Returns the list of items in inventory available for transaction adjusted by tradeList
  207. * @return L2ItemInstance : items in inventory
  208. */
  209. public TradeList.TradeItem[] getAvailableItems(TradeList tradeList)
  210. {
  211. List<TradeList.TradeItem> list = new FastList<TradeList.TradeItem>();
  212. for (L2ItemInstance item : _items)
  213. if (item.isAvailable(getOwner(), false, false))
  214. {
  215. TradeList.TradeItem adjItem = tradeList.adjustAvailableItem(item);
  216. if (adjItem != null) list.add(adjItem);
  217. }
  218. return list.toArray(new TradeList.TradeItem[list.size()]);
  219. }
  220. /**
  221. * Adjust TradeItem according his status in inventory
  222. * @param item : L2ItemInstance to be adjusten
  223. * @return TradeItem representing adjusted item
  224. */
  225. public void adjustAvailableItem(TradeItem item)
  226. {
  227. boolean notAllEquipped = false;
  228. for(L2ItemInstance adjItem: getItemsByItemId(item.getItem().getItemId()))
  229. {
  230. if(adjItem.isEquipable())
  231. {
  232. if(!adjItem.isEquipped())
  233. notAllEquipped |= true;
  234. }else{
  235. notAllEquipped |= true;
  236. break;
  237. }
  238. }
  239. if(notAllEquipped)
  240. {
  241. L2ItemInstance adjItem = getItemByItemId(item.getItem().getItemId());
  242. item.setObjectId(adjItem.getObjectId());
  243. item.setEnchant(adjItem.getEnchantLevel());
  244. if (adjItem.getCount() < item.getCount())
  245. item.setCount(adjItem.getCount());
  246. return;
  247. }
  248. item.setCount(0);
  249. }
  250. /**
  251. * Adds adena to PCInventory
  252. * @param process : String Identifier of process triggering this action
  253. * @param count : int Quantity of adena to be added
  254. * @param actor : L2PcInstance Player requesting the item add
  255. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  256. */
  257. public void addAdena(String process, long count, L2PcInstance actor, L2Object reference)
  258. {
  259. if (count > 0)
  260. addItem(process, ADENA_ID, count, actor, reference);
  261. }
  262. /**
  263. * Removes adena to PCInventory
  264. * @param process : String Identifier of process triggering this action
  265. * @param count : int Quantity of adena to be removed
  266. * @param actor : L2PcInstance Player requesting the item add
  267. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  268. */
  269. public void reduceAdena(String process, long count, L2PcInstance actor, L2Object reference)
  270. {
  271. if (count > 0)
  272. destroyItemByItemId(process, ADENA_ID, count, actor, reference);
  273. }
  274. /**
  275. * Adds specified amount of ancient adena to player inventory.
  276. * @param process : String Identifier of process triggering this action
  277. * @param count : int Quantity of adena to be added
  278. * @param actor : L2PcInstance Player requesting the item add
  279. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  280. */
  281. public void addAncientAdena(String process, long count, L2PcInstance actor, L2Object reference)
  282. {
  283. if (count > 0)
  284. addItem(process, ANCIENT_ADENA_ID, count, actor, reference);
  285. }
  286. /**
  287. * Removes specified amount of ancient adena from player inventory.
  288. * @param process : String Identifier of process triggering this action
  289. * @param count : int Quantity of adena to be removed
  290. * @param actor : L2PcInstance Player requesting the item add
  291. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  292. */
  293. public void reduceAncientAdena(String process, long count, L2PcInstance actor, L2Object reference)
  294. {
  295. if (count > 0)
  296. destroyItemByItemId(process, ANCIENT_ADENA_ID, count, actor, reference);
  297. }
  298. /**
  299. * Adds item in inventory and checks _adena and _ancientAdena
  300. * @param process : String Identifier of process triggering this action
  301. * @param item : L2ItemInstance to be added
  302. * @param actor : L2PcInstance Player requesting the item add
  303. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  304. * @return L2ItemInstance corresponding to the new item or the updated item in inventory
  305. */
  306. @Override
  307. public L2ItemInstance addItem(String process, L2ItemInstance item, L2PcInstance actor, L2Object reference)
  308. {
  309. item = super.addItem(process, item, actor, reference);
  310. if (item != null && item.getItemId() == ADENA_ID && !item.equals(_adena))
  311. _adena = item;
  312. if (item != null && item.getItemId() == ANCIENT_ADENA_ID && !item.equals(_ancientAdena))
  313. _ancientAdena = item;
  314. return item;
  315. }
  316. /**
  317. * Adds item in inventory and checks _adena and _ancientAdena
  318. * @param process : String Identifier of process triggering this action
  319. * @param itemId : int Item Identifier of the item to be added
  320. * @param count : int Quantity of items to be added
  321. * @param actor : L2PcInstance Player requesting the item creation
  322. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  323. * @return L2ItemInstance corresponding to the new item or the updated item in inventory
  324. */
  325. @Override
  326. public L2ItemInstance addItem(String process, int itemId, long count, L2PcInstance actor, L2Object reference)
  327. {
  328. L2ItemInstance item = super.addItem(process, itemId, count, actor, reference);
  329. if (item != null && item.getItemId() == ADENA_ID && !item.equals(_adena))
  330. _adena = item;
  331. if (item != null && item.getItemId() == ANCIENT_ADENA_ID && !item.equals(_ancientAdena))
  332. _ancientAdena = item;
  333. if (item != null && actor != null)
  334. {
  335. // Send inventory update packet
  336. if (!Config.FORCE_INVENTORY_UPDATE)
  337. {
  338. InventoryUpdate playerIU = new InventoryUpdate();
  339. playerIU.addItem(item);
  340. actor.sendPacket(playerIU);
  341. }
  342. else
  343. actor.sendPacket(new ItemList(actor, false));
  344. // Update current load as well
  345. StatusUpdate su = new StatusUpdate(actor.getObjectId());
  346. su.addAttribute(StatusUpdate.CUR_LOAD, actor.getCurrentLoad());
  347. actor.sendPacket(su);
  348. }
  349. return item;
  350. }
  351. /**
  352. * Transfers item to another inventory and checks _adena and _ancientAdena
  353. * @param process : String Identifier of process triggering this action
  354. * @param itemId : int Item Identifier of the item to be transfered
  355. * @param count : int Quantity of items to be transfered
  356. * @param actor : L2PcInstance Player requesting the item transfer
  357. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  358. * @return L2ItemInstance corresponding to the new item or the updated item in inventory
  359. */
  360. @Override
  361. public L2ItemInstance transferItem(String process, int objectId, long count, ItemContainer target, L2PcInstance actor, L2Object reference)
  362. {
  363. L2ItemInstance item = super.transferItem(process, objectId, count, target, actor, reference);
  364. if (_adena != null && (_adena.getCount() <= 0 || _adena.getOwnerId() != getOwnerId()))
  365. _adena = null;
  366. if (_ancientAdena != null && (_ancientAdena.getCount() <= 0 || _ancientAdena.getOwnerId() != getOwnerId()))
  367. _ancientAdena = null;
  368. return item;
  369. }
  370. /**
  371. * Destroy item from inventory and checks _adena and _ancientAdena
  372. * @param process : String Identifier of process triggering this action
  373. * @param item : L2ItemInstance to be destroyed
  374. * @param actor : L2PcInstance Player requesting the item destroy
  375. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  376. * @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
  377. */
  378. @Override
  379. public L2ItemInstance destroyItem(String process, L2ItemInstance item, L2PcInstance actor, L2Object reference)
  380. {
  381. return this.destroyItem(process, item, item.getCount(), actor, reference);
  382. }
  383. /**
  384. * Destroy item from inventory and checks _adena and _ancientAdena
  385. * @param process : String Identifier of process triggering this action
  386. * @param item : L2ItemInstance to be destroyed
  387. * @param actor : L2PcInstance Player requesting the item destroy
  388. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  389. * @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
  390. */
  391. @Override
  392. public L2ItemInstance destroyItem(String process, L2ItemInstance item, long count, L2PcInstance actor, L2Object reference)
  393. {
  394. item = super.destroyItem(process, item, count, actor, reference);
  395. if (_adena != null && _adena.getCount() <= 0)
  396. _adena = null;
  397. if (_ancientAdena != null && _ancientAdena.getCount() <= 0)
  398. _ancientAdena = null;
  399. return item;
  400. }
  401. /**
  402. * Destroys item from inventory and checks _adena and _ancientAdena
  403. * @param process : String Identifier of process triggering this action
  404. * @param objectId : int Item Instance identifier of the item to be destroyed
  405. * @param count : int Quantity of items to be destroyed
  406. * @param actor : L2PcInstance Player requesting the item destroy
  407. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  408. * @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
  409. */
  410. @Override
  411. public L2ItemInstance destroyItem(String process, int objectId, long count, L2PcInstance actor, L2Object reference)
  412. {
  413. L2ItemInstance item = getItemByObjectId(objectId);
  414. if (item == null)
  415. {
  416. return null;
  417. }
  418. return this.destroyItem(process, item, count, actor, reference);
  419. }
  420. /**
  421. * Destroy item from inventory by using its <B>itemId</B> and checks _adena and _ancientAdena
  422. * @param process : String Identifier of process triggering this action
  423. * @param itemId : int Item identifier of the item to be destroyed
  424. * @param count : int Quantity of items to be destroyed
  425. * @param actor : L2PcInstance Player requesting the item destroy
  426. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  427. * @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
  428. */
  429. @Override
  430. public L2ItemInstance destroyItemByItemId(String process, int itemId, long count, L2PcInstance actor, L2Object reference)
  431. {
  432. L2ItemInstance item = getItemByItemId(itemId);
  433. if (item == null)
  434. {
  435. return null;
  436. }
  437. return this.destroyItem(process, item, count, actor, reference);
  438. }
  439. /**
  440. * Drop item from inventory and checks _adena and _ancientAdena
  441. * @param process : String Identifier of process triggering this action
  442. * @param item : L2ItemInstance to be dropped
  443. * @param actor : L2PcInstance Player requesting the item drop
  444. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  445. * @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
  446. */
  447. @Override
  448. public L2ItemInstance dropItem(String process, L2ItemInstance item, L2PcInstance actor, L2Object reference)
  449. {
  450. item = super.dropItem(process, item, actor, reference);
  451. if (_adena != null && (_adena.getCount() <= 0 || _adena.getOwnerId() != getOwnerId()))
  452. _adena = null;
  453. if (_ancientAdena != null && (_ancientAdena.getCount() <= 0 || _ancientAdena.getOwnerId() != getOwnerId()))
  454. _ancientAdena = null;
  455. return item;
  456. }
  457. /**
  458. * Drop item from inventory by using its <B>objectID</B> and checks _adena and _ancientAdena
  459. * @param process : String Identifier of process triggering this action
  460. * @param objectId : int Item Instance identifier of the item to be dropped
  461. * @param count : int Quantity of items to be dropped
  462. * @param actor : L2PcInstance Player requesting the item drop
  463. * @param reference : L2Object Object referencing current action like NPC selling item or previous item in transformation
  464. * @return L2ItemInstance corresponding to the destroyed item or the updated item in inventory
  465. */
  466. @Override
  467. public L2ItemInstance dropItem(String process, int objectId, long count, L2PcInstance actor, L2Object reference)
  468. {
  469. L2ItemInstance item = super.dropItem(process, objectId, count, actor, reference);
  470. if (_adena != null && (_adena.getCount() <= 0 || _adena.getOwnerId() != getOwnerId()))
  471. _adena = null;
  472. if (_ancientAdena != null && (_ancientAdena.getCount() <= 0 || _ancientAdena.getOwnerId() != getOwnerId()))
  473. _ancientAdena = null;
  474. return item;
  475. }
  476. /**
  477. * <b>Overloaded</b>, when removes item from inventory, remove also owner shortcuts.
  478. * @param item : L2ItemInstance to be removed from inventory
  479. */
  480. @Override
  481. protected boolean removeItem(L2ItemInstance item)
  482. {
  483. // Removes any reference to the item from Shortcut bar
  484. getOwner().removeItemFromShortCut(item.getObjectId());
  485. // Removes active Enchant Scroll
  486. if(item.equals(getOwner().getActiveEnchantItem()))
  487. getOwner().setActiveEnchantItem(null);
  488. if (item.getItemId() == ADENA_ID)
  489. _adena = null;
  490. else if (item.getItemId() == ANCIENT_ADENA_ID)
  491. _ancientAdena = null;
  492. return super.removeItem(item);
  493. }
  494. /**
  495. * Refresh the weight of equipment loaded
  496. */
  497. @Override
  498. public void refreshWeight()
  499. {
  500. super.refreshWeight();
  501. getOwner().refreshOverloaded();
  502. }
  503. /**
  504. * Get back items in inventory from database
  505. */
  506. @Override
  507. public void restore()
  508. {
  509. super.restore();
  510. _adena = getItemByItemId(ADENA_ID);
  511. _ancientAdena = getItemByItemId(ANCIENT_ADENA_ID);
  512. }
  513. public static int[][] restoreVisibleInventory(int objectId)
  514. {
  515. int[][] paperdoll = new int[31][3];
  516. Connection con = null;
  517. try
  518. {
  519. con = L2DatabaseFactory.getInstance().getConnection();
  520. PreparedStatement statement2 = con.prepareStatement(
  521. "SELECT object_id,item_id,loc_data,enchant_level FROM items WHERE owner_id=? AND loc='PAPERDOLL'");
  522. statement2.setInt(1, objectId);
  523. ResultSet invdata = statement2.executeQuery();
  524. while (invdata.next())
  525. {
  526. int slot = invdata.getInt("loc_data");
  527. paperdoll[slot][0] = invdata.getInt("object_id");
  528. paperdoll[slot][1] = invdata.getInt("item_id");
  529. paperdoll[slot][2] = invdata.getInt("enchant_level");
  530. if (slot == Inventory.PAPERDOLL_LRHAND)
  531. {
  532. paperdoll[Inventory.PAPERDOLL_RHAND][0] = invdata.getInt("object_id");
  533. paperdoll[Inventory.PAPERDOLL_RHAND][1] = invdata.getInt("item_id");
  534. paperdoll[Inventory.PAPERDOLL_RHAND][2] = invdata.getInt("enchant_level");
  535. }
  536. }
  537. invdata.close();
  538. statement2.close();
  539. }
  540. catch (Exception e) {
  541. _log.log(Level.WARNING, "could not restore inventory:", e);
  542. }
  543. finally {
  544. try { con.close(); } catch (Exception e) { _log.warning(""); }
  545. }
  546. return paperdoll;
  547. }
  548. public boolean validateCapacity(L2ItemInstance item)
  549. {
  550. int slots = 0;
  551. if (!(item.isStackable() && getItemByItemId(item.getItemId()) != null) && item.getItemType() != L2EtcItemType.HERB)
  552. slots++;
  553. return validateCapacity(slots);
  554. }
  555. public boolean validateCapacity(List<L2ItemInstance> items)
  556. {
  557. int slots = 0;
  558. for (L2ItemInstance item : items)
  559. if (!(item.isStackable() && getItemByItemId(item.getItemId()) != null))
  560. slots++;
  561. return validateCapacity(slots);
  562. }
  563. public boolean validateCapacityByItemId(int ItemId)
  564. {
  565. int slots = 0;
  566. L2ItemInstance invItem = getItemByItemId(ItemId);
  567. if (!(invItem != null && invItem.isStackable()))
  568. slots++;
  569. return validateCapacity(slots);
  570. }
  571. @Override
  572. public boolean validateCapacity(int slots)
  573. {
  574. return (_items.size() + slots <= _owner.getInventoryLimit());
  575. }
  576. @Override
  577. public boolean validateWeight(int weight)
  578. {
  579. return (_totalWeight + weight <= _owner.getMaxLoad());
  580. }
  581. }