PcFreight.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.util.List;
  17. import javolution.util.FastList;
  18. import com.l2jserver.Config;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.item.instance.L2ItemInstance;
  21. import com.l2jserver.gameserver.model.item.instance.L2ItemInstance.ItemLocation;
  22. import com.l2jserver.gameserver.skills.Stats;
  23. public class PcFreight extends ItemContainer
  24. {
  25. private final L2PcInstance _owner;
  26. private int _ownerId = 0;
  27. public PcFreight(int object_id)
  28. {
  29. _owner = null;
  30. _ownerId = object_id;
  31. restore();
  32. }
  33. public PcFreight(L2PcInstance owner)
  34. {
  35. _owner = owner;
  36. _ownerId = owner.getObjectId();
  37. }
  38. @Override
  39. public L2PcInstance getOwner()
  40. {
  41. return _owner;
  42. }
  43. @Override
  44. public ItemLocation getBaseLocation()
  45. {
  46. return ItemLocation.FREIGHT;
  47. }
  48. /**
  49. * Returns the quantity of items in the inventory
  50. * @return int
  51. */
  52. @Override
  53. public int getSize()
  54. {
  55. int size = 0;
  56. for (L2ItemInstance item : _items)
  57. {
  58. if (item.getLocation() == getBaseLocation())
  59. size++;
  60. }
  61. return size;
  62. }
  63. /**
  64. * Returns the list of items in inventory
  65. * @return L2ItemInstance : items in inventory
  66. */
  67. @Override
  68. public L2ItemInstance[] getItems()
  69. {
  70. List<L2ItemInstance> list = new FastList<L2ItemInstance>();
  71. for (L2ItemInstance item : _items)
  72. {
  73. if (item.isFreightable())
  74. list.add(item);
  75. }
  76. return list.toArray(new L2ItemInstance[list.size()]);
  77. }
  78. /**
  79. * Returns the item from inventory by using its <B>itemId</B>
  80. * @param itemId : int designating the ID of the item
  81. * @return L2ItemInstance designating the item or null if not found in inventory
  82. */
  83. @Override
  84. public L2ItemInstance getItemByItemId(int itemId)
  85. {
  86. for (L2ItemInstance item : _items)
  87. if ((item.getItemId() == itemId) && (item.getLocation() == ItemLocation.INVENTORY))
  88. return item;
  89. return null;
  90. }
  91. @Override
  92. public int getOwnerId()
  93. {
  94. return _ownerId;
  95. }
  96. @Override
  97. public boolean validateCapacity(int slots)
  98. {
  99. int curSlots = _owner == null ? Config.ALT_FREIGHT_SLOTS : Config.ALT_FREIGHT_SLOTS + (int)_owner.getStat().calcStat(Stats.FREIGHT_LIM, 0, null, null);
  100. return (getSize() + slots <= curSlots);
  101. }
  102. }