L2EtcItem.java 4.6 KB

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