L2EtcItem.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.item;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import com.l2jserver.gameserver.model.L2ExtractableProduct;
  19. import com.l2jserver.gameserver.model.StatsSet;
  20. import com.l2jserver.gameserver.model.item.type.L2EtcItemType;
  21. import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
  22. import com.l2jserver.util.StringUtil;
  23. /**
  24. * This class is dedicated to the management of EtcItem.
  25. *
  26. * @version $Revision: 1.2.2.1.2.3 $ $Date: 2005/03/27 15:30:10 $
  27. */
  28. public final class L2EtcItem extends L2Item
  29. {
  30. // private final String[] _skill;
  31. private String _handler;
  32. private final int _sharedReuseGroup;
  33. private L2EtcItemType _type;
  34. private final boolean _isBlessed;
  35. private final List<L2ExtractableProduct> _extractableItems;
  36. /**
  37. * Constructor for EtcItem.
  38. * @see L2Item constructor
  39. * @param set : StatsSet designating the set of couples (key,value) for description of the Etc
  40. */
  41. public L2EtcItem(StatsSet set)
  42. {
  43. super(set);
  44. _type = L2EtcItemType.valueOf(set.getString("etcitem_type", "none").toUpperCase());
  45. // l2j custom - L2EtcItemType.SHOT
  46. switch (getDefaultAction())
  47. {
  48. case soulshot:
  49. case summon_soulshot:
  50. case summon_spiritshot:
  51. case spiritshot:
  52. {
  53. _type = L2EtcItemType.SHOT;
  54. break;
  55. }
  56. }
  57. if (is_ex_immediate_effect())
  58. _type = L2EtcItemType.HERB;
  59. _type1 = L2Item.TYPE1_ITEM_QUESTITEM_ADENA;
  60. _type2 = L2Item.TYPE2_OTHER; // default is other
  61. if (isQuestItem())
  62. _type2 = L2Item.TYPE2_QUEST;
  63. else if (getItemId() == PcInventory.ADENA_ID || getItemId() == PcInventory.ANCIENT_ADENA_ID)
  64. _type2 = L2Item.TYPE2_MONEY;
  65. _handler = set.getString("handler", null); // ! null !
  66. _sharedReuseGroup = set.getInteger("shared_reuse_group", -1);
  67. _isBlessed = set.getBool("blessed", false);
  68. //extractable
  69. String capsuled_items = set.getString("capsuled_items", null);
  70. if (capsuled_items != null)
  71. {
  72. String[] split = capsuled_items.split(";");
  73. _extractableItems = new ArrayList<L2ExtractableProduct>(split.length);
  74. for (String part : split)
  75. {
  76. if (part.trim().isEmpty())
  77. continue;
  78. String[] data = part.split(",");
  79. if (data.length != 4)
  80. {
  81. _log.info(StringUtil.concat("> Couldnt parse ", part, " in capsuled_items! item ", this.toString()));
  82. continue;
  83. }
  84. int itemId = Integer.parseInt(data[0]);
  85. int min = Integer.parseInt(data[1]);
  86. int max = Integer.parseInt(data[2]);
  87. double chance = Double.parseDouble(data[3]);
  88. if (max < min)
  89. {
  90. _log.info(StringUtil.concat("> Max amount < Min amount in ", part, ", item ",this.toString()));
  91. continue;
  92. }
  93. L2ExtractableProduct product = new L2ExtractableProduct(itemId, min, max, chance);
  94. _extractableItems.add(product);
  95. }
  96. ((ArrayList<?>) _extractableItems).trimToSize();
  97. //check for handler
  98. if (_handler == null)
  99. //_log.warning("Item "+this+ " define capsuled_items but missing handler.");
  100. _handler = "ExtractableItems";
  101. }
  102. else
  103. _extractableItems = null;
  104. }
  105. /**
  106. * Returns the type of Etc Item
  107. * @return L2EtcItemType
  108. */
  109. @Override
  110. public L2EtcItemType getItemType()
  111. {
  112. return _type;
  113. }
  114. /**
  115. * Returns if the item is consumable
  116. * @return boolean
  117. */
  118. @Override
  119. public final boolean isConsumable()
  120. {
  121. return ((getItemType() == L2EtcItemType.SHOT) || (getItemType() == L2EtcItemType.POTION)); // || (type == L2EtcItemType.SCROLL));
  122. }
  123. /**
  124. * Returns the ID of the Etc item after applying the mask.
  125. * @return int : ID of the EtcItem
  126. */
  127. @Override
  128. public int getItemMask()
  129. {
  130. return getItemType().mask();
  131. }
  132. /**
  133. * Return handler name. null if no handler for item
  134. * @return String
  135. */
  136. public String getHandlerName()
  137. {
  138. return _handler;
  139. }
  140. /**
  141. *
  142. * @return
  143. */
  144. public int getSharedReuseGroup()
  145. {
  146. return _sharedReuseGroup;
  147. }
  148. /**
  149. *
  150. * @return
  151. */
  152. public final boolean isBlessed()
  153. {
  154. return _isBlessed;
  155. }
  156. /**
  157. * @return the _extractable_items
  158. */
  159. public List<L2ExtractableProduct> getExtractableItems()
  160. {
  161. return _extractableItems;
  162. }
  163. }