L2EtcItem.java 4.5 KB

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