L2EtcItem.java 4.6 KB

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