Ingredient.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model.multisell;
  20. import com.l2jserver.gameserver.datatables.ItemTable;
  21. import com.l2jserver.gameserver.model.StatsSet;
  22. import com.l2jserver.gameserver.model.items.L2Armor;
  23. import com.l2jserver.gameserver.model.items.L2Item;
  24. import com.l2jserver.gameserver.model.items.L2Weapon;
  25. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  26. /**
  27. * @author DS
  28. */
  29. public class Ingredient
  30. {
  31. private int _itemId;
  32. private long _itemCount;
  33. private boolean _isTaxIngredient;
  34. private boolean _maintainIngredient;
  35. private L2Item _template = null;
  36. private ItemInfo _itemInfo = null;
  37. public Ingredient(StatsSet set)
  38. {
  39. this(set.getInt("id"), set.getLong("count"), set.getBoolean("isTaxIngredient", false), set.getBoolean("maintainIngredient", false));
  40. }
  41. public Ingredient(int itemId, long itemCount, boolean isTaxIngredient, boolean maintainIngredient)
  42. {
  43. _itemId = itemId;
  44. _itemCount = itemCount;
  45. _isTaxIngredient = isTaxIngredient;
  46. _maintainIngredient = maintainIngredient;
  47. if (_itemId > 0)
  48. {
  49. _template = ItemTable.getInstance().getTemplate(_itemId);
  50. }
  51. }
  52. /**
  53. * @return a new Ingredient instance with the same values as this.
  54. */
  55. public Ingredient getCopy()
  56. {
  57. return new Ingredient(_itemId, _itemCount, _isTaxIngredient, _maintainIngredient);
  58. }
  59. public final L2Item getTemplate()
  60. {
  61. return _template;
  62. }
  63. public final void setItemInfo(L2ItemInstance item)
  64. {
  65. _itemInfo = new ItemInfo(item);
  66. }
  67. public final void setItemInfo(ItemInfo info)
  68. {
  69. _itemInfo = info;
  70. }
  71. public final ItemInfo getItemInfo()
  72. {
  73. return _itemInfo;
  74. }
  75. public final int getEnchantLevel()
  76. {
  77. return _itemInfo != null ? _itemInfo.getEnchantLevel() : 0;
  78. }
  79. public final void setItemId(int itemId)
  80. {
  81. _itemId = itemId;
  82. }
  83. public final int getItemId()
  84. {
  85. return _itemId;
  86. }
  87. public final void setItemCount(long itemCount)
  88. {
  89. _itemCount = itemCount;
  90. }
  91. public final long getItemCount()
  92. {
  93. return _itemCount;
  94. }
  95. public final void setIsTaxIngredient(boolean isTaxIngredient)
  96. {
  97. _isTaxIngredient = isTaxIngredient;
  98. }
  99. public final boolean isTaxIngredient()
  100. {
  101. return _isTaxIngredient;
  102. }
  103. public final void setMaintainIngredient(boolean maintainIngredient)
  104. {
  105. _maintainIngredient = maintainIngredient;
  106. }
  107. public final boolean getMaintainIngredient()
  108. {
  109. return _maintainIngredient;
  110. }
  111. public final boolean isStackable()
  112. {
  113. return _template == null ? true : _template.isStackable();
  114. }
  115. public final boolean isArmorOrWeapon()
  116. {
  117. return _template == null ? false : (_template instanceof L2Armor) || (_template instanceof L2Weapon);
  118. }
  119. public final int getWeight()
  120. {
  121. return _template == null ? 0 : _template.getWeight();
  122. }
  123. }