L2EtcItem.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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.templates.item;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import com.l2jserver.gameserver.model.L2ExtractableProduct;
  19. import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
  20. import com.l2jserver.gameserver.skills.SkillHolder;
  21. import com.l2jserver.gameserver.templates.StatsSet;
  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 SkillHolder[] _skillHolder;
  33. private int _sharedReuseGroup;
  34. private L2EtcItemType _type;
  35. private final boolean _isBlessed;
  36. private final List<L2ExtractableProduct> _extractableItems;
  37. /**
  38. * Constructor for EtcItem.
  39. * @see L2Item constructor
  40. * @param type : L2EtcItemType designating the type of object Etc
  41. * @param set : StatsSet designating the set of couples (key,value) for description of the Etc
  42. */
  43. public L2EtcItem(StatsSet set)
  44. {
  45. super(set);
  46. _type = L2EtcItemType.valueOf(set.getString("etcitem_type", "none").toUpperCase());
  47. // l2j custom - L2EtcItemType.SHOT
  48. switch (getDefaultAction())
  49. {
  50. case soulshot:
  51. case summon_soulshot:
  52. case summon_spiritshot:
  53. case spiritshot:
  54. {
  55. _type = L2EtcItemType.SHOT;
  56. break;
  57. }
  58. }
  59. if (is_ex_immediate_effect())
  60. _type = L2EtcItemType.HERB;
  61. _type1 = L2Item.TYPE1_ITEM_QUESTITEM_ADENA;
  62. _type2 = L2Item.TYPE2_OTHER; // default is other
  63. if (isQuestItem())
  64. _type2 = L2Item.TYPE2_QUEST;
  65. else if (getItemId() == PcInventory.ADENA_ID || getItemId() == PcInventory.ANCIENT_ADENA_ID)
  66. _type2 = L2Item.TYPE2_MONEY;
  67. String skill = set.getString("item_skill", null);
  68. if (skill != null)
  69. {
  70. String[] skills = skill.split(";");
  71. _skillHolder = new SkillHolder[skills.length];
  72. byte iterator = 0;
  73. for (String st : skills)
  74. {
  75. String[] info = st.split("-");
  76. if (info == null || info.length != 2)
  77. continue;
  78. int id = 0;
  79. int level = 0;
  80. try
  81. {
  82. id = Integer.parseInt(info[0]);
  83. level = Integer.parseInt(info[1]);
  84. }
  85. catch (Exception nfe)
  86. {
  87. // Incorrect syntax, dont add new skill
  88. _log.info(StringUtil.concat("> Couldnt parse ", st, " in etcitem skills! item ", this.toString()));
  89. continue;
  90. }
  91. // If skill can exist, add it
  92. if (id > 0 && level > 0)
  93. {
  94. _skillHolder[iterator] = new SkillHolder(id, level);
  95. iterator++;
  96. }
  97. }
  98. }
  99. _handler = set.getString("handler", null); // ! null !
  100. _sharedReuseGroup = set.getInteger("shared_reuse_group", -1);
  101. _isBlessed = set.getBool("blessed", false);
  102. //extractable
  103. String capsuled_items = set.getString("capsuled_items", null);
  104. if (capsuled_items != null)
  105. {
  106. String[] split = capsuled_items.split(";");
  107. _extractableItems = new ArrayList<L2ExtractableProduct>(split.length);
  108. for (String part : split)
  109. {
  110. if (part.trim().isEmpty())
  111. continue;
  112. String[] data = part.split(",");
  113. if (data.length != 4)
  114. {
  115. _log.info(StringUtil.concat("> Couldnt parse ", part, " in capsuled_items! item ", this.toString()));
  116. continue;
  117. }
  118. int itemId = Integer.parseInt(data[0]);
  119. int min = Integer.parseInt(data[1]);
  120. int max = Integer.parseInt(data[2]);
  121. double chance = Double.parseDouble(data[3]);
  122. if (max < min)
  123. {
  124. _log.info(StringUtil.concat("> Max amount < Min amount in ", part, ", item ",this.toString()));
  125. continue;
  126. }
  127. L2ExtractableProduct product = new L2ExtractableProduct(itemId, min, max, chance);
  128. _extractableItems.add(product);
  129. }
  130. ((ArrayList<?>) _extractableItems).trimToSize();
  131. //check for handler
  132. if (_handler == null)
  133. //_log.warning("Item "+this+ " define capsuled_items but missing handler.");
  134. _handler = "ExtractableItems";
  135. }
  136. else
  137. _extractableItems = null;
  138. }
  139. /**
  140. * Returns the type of Etc Item
  141. * @return L2EtcItemType
  142. */
  143. @Override
  144. public L2EtcItemType getItemType()
  145. {
  146. return _type;
  147. }
  148. /**
  149. * Returns if the item is consumable
  150. * @return boolean
  151. */
  152. @Override
  153. public final boolean isConsumable()
  154. {
  155. return ((getItemType() == L2EtcItemType.SHOT) || (getItemType() == L2EtcItemType.POTION)); // || (type == L2EtcItemType.SCROLL));
  156. }
  157. /**
  158. * Returns the ID of the Etc item after applying the mask.
  159. * @return int : ID of the EtcItem
  160. */
  161. @Override
  162. public int getItemMask()
  163. {
  164. return getItemType().mask();
  165. }
  166. /**
  167. * Returns skills linked to that EtcItem
  168. * @return
  169. */
  170. @Override
  171. public SkillHolder[] getSkills()
  172. {
  173. return _skillHolder;
  174. }
  175. /**
  176. * Return handler name. null if no handler for item
  177. * @return String
  178. */
  179. public String getHandlerName()
  180. {
  181. return _handler;
  182. }
  183. /**
  184. *
  185. * @return
  186. */
  187. public int getSharedReuseGroup()
  188. {
  189. return _sharedReuseGroup;
  190. }
  191. /**
  192. *
  193. * @return
  194. */
  195. public final boolean isBlessed()
  196. {
  197. return _isBlessed;
  198. }
  199. /**
  200. * @return the _extractable_items
  201. */
  202. public List<L2ExtractableProduct> getExtractableItems()
  203. {
  204. return _extractableItems;
  205. }
  206. }