PcFreight.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* This program is free software; you can redistribute it and/or modify
  2. * it under the terms of the GNU General Public License as published by
  3. * the Free Software Foundation; either version 2, or (at your option)
  4. * any later version.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  14. * 02111-1307, USA.
  15. *
  16. * http://www.gnu.org/copyleft/gpl.html
  17. */
  18. package com.l2jserver.gameserver.model.itemcontainer;
  19. import java.util.List;
  20. import javolution.util.FastList;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.model.L2ItemInstance;
  23. import com.l2jserver.gameserver.model.L2ItemInstance.ItemLocation;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.skills.Stats;
  26. public class PcFreight extends ItemContainer
  27. {
  28. private final L2PcInstance _owner;
  29. private int _ownerId = 0;
  30. public PcFreight(int object_id)
  31. {
  32. _owner = null;
  33. _ownerId = object_id;
  34. restore();
  35. }
  36. public PcFreight(L2PcInstance owner)
  37. {
  38. _owner = owner;
  39. _ownerId = owner.getObjectId();
  40. }
  41. @Override
  42. public L2PcInstance getOwner()
  43. {
  44. return _owner;
  45. }
  46. @Override
  47. public ItemLocation getBaseLocation()
  48. {
  49. return ItemLocation.FREIGHT;
  50. }
  51. /**
  52. * Returns the quantity of items in the inventory
  53. * @return int
  54. */
  55. @Override
  56. public int getSize()
  57. {
  58. int size = 0;
  59. for (L2ItemInstance item : _items)
  60. {
  61. if (item.getLocation() == getBaseLocation())
  62. size++;
  63. }
  64. return size;
  65. }
  66. /**
  67. * Returns the list of items in inventory
  68. * @return L2ItemInstance : items in inventory
  69. */
  70. @Override
  71. public L2ItemInstance[] getItems()
  72. {
  73. List<L2ItemInstance> list = new FastList<L2ItemInstance>();
  74. for (L2ItemInstance item : _items)
  75. {
  76. if (item.isFreightable())
  77. list.add(item);
  78. }
  79. return list.toArray(new L2ItemInstance[list.size()]);
  80. }
  81. /**
  82. * Returns the item from inventory by using its <B>itemId</B>
  83. * @param itemId : int designating the ID of the item
  84. * @return L2ItemInstance designating the item or null if not found in inventory
  85. */
  86. @Override
  87. public L2ItemInstance getItemByItemId(int itemId)
  88. {
  89. for (L2ItemInstance item : _items)
  90. if ((item.getItemId() == itemId) && (item.getLocation() == ItemLocation.INVENTORY))
  91. return item;
  92. return null;
  93. }
  94. @Override
  95. public int getOwnerId()
  96. {
  97. return _ownerId;
  98. }
  99. @Override
  100. public boolean validateCapacity(int slots)
  101. {
  102. int curSlots = _owner == null ? Config.ALT_FREIGHT_SLOTS : Config.ALT_FREIGHT_SLOTS + (int)_owner.getStat().calcStat(Stats.FREIGHT_LIM, 0, null, null);
  103. return (getSize() + slots <= curSlots);
  104. }
  105. }