L2EtcItem.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. _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 ((getId() == PcInventory.ADENA_ID) || (getId() == PcInventory.ANCIENT_ADENA_ID))
  63. {
  64. _type2 = L2Item.TYPE2_MONEY;
  65. }
  66. _handler = set.getString("handler", null); // ! null !
  67. _isBlessed = set.getBoolean("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 the ID of the Etc item after applying the mask.
  121. */
  122. @Override
  123. public int getItemMask()
  124. {
  125. return getItemType().mask();
  126. }
  127. /**
  128. * @return the handler name, null if no handler for item.
  129. */
  130. public String getHandlerName()
  131. {
  132. return _handler;
  133. }
  134. /**
  135. * @return {@code true} if the item is blessed, {@code false} otherwise.
  136. */
  137. public final boolean isBlessed()
  138. {
  139. return _isBlessed;
  140. }
  141. /**
  142. * @return the extractable items list.
  143. */
  144. public List<L2ExtractableProduct> getExtractableItems()
  145. {
  146. return _extractableItems;
  147. }
  148. }