PcInventory.java 23 KB

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