2
0

L2EtcItem.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 com.l2jserver.gameserver.skills.SkillHolder;
  17. import com.l2jserver.gameserver.templates.StatsSet;
  18. import com.l2jserver.util.StringUtil;
  19. /**
  20. * This class is dedicated to the management of EtcItem.
  21. *
  22. * @version $Revision: 1.2.2.1.2.3 $ $Date: 2005/03/27 15:30:10 $
  23. */
  24. public final class L2EtcItem extends L2Item
  25. {
  26. // private final String[] _skill;
  27. private final String _handler;
  28. private SkillHolder[] _skillHolder;
  29. private int _sharedReuseGroup;
  30. /**
  31. * Constructor for EtcItem.
  32. * @see L2Item constructor
  33. * @param type : L2EtcItemType designating the type of object Etc
  34. * @param set : StatsSet designating the set of couples (key,value) for description of the Etc
  35. */
  36. public L2EtcItem(L2EtcItemType type, StatsSet set)
  37. {
  38. super(type, set);
  39. String[] skills = set.getString("skill").split(";");
  40. _skillHolder = new SkillHolder[skills.length];
  41. byte iterator = 0;
  42. for(String st : skills)
  43. {
  44. String[] info = st.split("-");
  45. if(info == null || info.length != 2)
  46. continue;
  47. int id = 0;
  48. int level = 0;
  49. try
  50. {
  51. id = Integer.parseInt(info[0]);
  52. level = Integer.parseInt(info[1]);
  53. }
  54. catch(Exception nfe)
  55. {
  56. // Incorrect syntax, dont add new skill
  57. _log.info(StringUtil.concat("> Couldnt parse " , st, " in etcitem skills!"));
  58. continue;
  59. }
  60. // If skill can exist, add it
  61. if(id > 0 && level > 0)
  62. {
  63. _skillHolder[iterator] = new SkillHolder(id, level);
  64. iterator++;
  65. }
  66. }
  67. _handler = set.getString("handler");
  68. _sharedReuseGroup = set.getInteger("shared_reuse_group", -1);
  69. }
  70. /**
  71. * Returns the type of Etc Item
  72. * @return L2EtcItemType
  73. */
  74. @Override
  75. public L2EtcItemType getItemType()
  76. {
  77. return (L2EtcItemType)super._type;
  78. }
  79. /**
  80. * Returns if the item is consumable
  81. * @return boolean
  82. */
  83. @Override
  84. public final boolean isConsumable()
  85. {
  86. return ((getItemType() == L2EtcItemType.SHOT) || (getItemType() == L2EtcItemType.POTION)); // || (type == L2EtcItemType.SCROLL));
  87. }
  88. /**
  89. * Returns the ID of the Etc item after applying the mask.
  90. * @return int : ID of the EtcItem
  91. */
  92. @Override
  93. public int getItemMask()
  94. {
  95. return getItemType().mask();
  96. }
  97. /**
  98. * Returns skills linked to that EtcItem
  99. * @return
  100. */
  101. public SkillHolder[] getSkills()
  102. {
  103. return _skillHolder;
  104. }
  105. public String getHandlerName()
  106. {
  107. return _handler;
  108. }
  109. public int getSharedReuseGroup()
  110. {
  111. return _sharedReuseGroup;
  112. }
  113. }