L2Armor.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 com.l2jserver.gameserver.datatables.SkillTable;
  18. import com.l2jserver.gameserver.model.L2ItemInstance;
  19. import com.l2jserver.gameserver.model.L2Skill;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.skills.Env;
  22. import com.l2jserver.gameserver.skills.SkillHolder;
  23. import com.l2jserver.gameserver.skills.funcs.Func;
  24. import com.l2jserver.gameserver.skills.funcs.FuncTemplate;
  25. import com.l2jserver.gameserver.templates.StatsSet;
  26. import com.l2jserver.util.StringUtil;
  27. /**
  28. * This class is dedicated to the management of armors.
  29. *
  30. * @version $Revision: 1.2.2.1.2.6 $ $Date: 2005/03/27 15:30:10 $
  31. */
  32. public final class L2Armor extends L2Item
  33. {
  34. private final int _avoidModifier;
  35. private final int _pDef;
  36. private final int _mDef;
  37. private final int _mpBonus;
  38. private final int _hpBonus;
  39. private L2Skill _enchant4Skill = null; // skill that activates when armor is enchanted +4
  40. // private final String[] _skill;
  41. private SkillHolder[] _skillHolder;
  42. /**
  43. * Constructor for Armor.<BR><BR>
  44. * <U><I>Variables filled :</I></U><BR>
  45. * <LI>_avoidModifier</LI>
  46. * <LI>_pDef & _mDef</LI>
  47. * <LI>_mpBonus & _hpBonus</LI>
  48. * <LI>enchant4Skill</LI>
  49. * @param type : L2ArmorType designating the type of armor
  50. * @param set : StatsSet designating the set of couples (key,value) caracterizing the armor
  51. * @see L2Item constructor
  52. */
  53. public L2Armor(L2ArmorType type, StatsSet set)
  54. {
  55. super(type, set);
  56. _avoidModifier = set.getInteger("avoid_modify");
  57. _pDef = set.getInteger("p_def");
  58. _mDef = set.getInteger("m_def");
  59. _mpBonus = set.getInteger("mp_bonus", 0);
  60. _hpBonus = set.getInteger("hp_bonus", 0);
  61. String[] skill = set.getString("enchant4_skill").split("-");
  62. if (skill != null && skill.length == 2)
  63. {
  64. int skill_Id = Integer.parseInt(skill[0]);
  65. int skillLvl = Integer.parseInt(skill[1]);
  66. if (skill_Id > 0 && skillLvl > 0)
  67. _enchant4Skill = SkillTable.getInstance().getInfo(skill_Id, skillLvl);
  68. }
  69. String[] skills = set.getString("skill").split(";");
  70. _skillHolder = new SkillHolder[skills.length];
  71. byte iterator = 0;
  72. for(String st : skills)
  73. {
  74. String[] info = st.split("-");
  75. if(info == null || info.length != 2)
  76. continue;
  77. int id = 0;
  78. int level = 0;
  79. try
  80. {
  81. id = Integer.parseInt(info[0]);
  82. level = Integer.parseInt(info[1]);
  83. }
  84. catch(Exception nfe)
  85. {
  86. // Incorrect syntax, dont add new skill
  87. _log.info(StringUtil.concat("> Couldnt parse " , st, " in armor skills!"));
  88. continue;
  89. }
  90. // If skill can exist, add it
  91. if(id > 0 && level > 0)
  92. {
  93. _skillHolder[iterator] = new SkillHolder(id, level);
  94. iterator++;
  95. }
  96. }
  97. }
  98. /**
  99. * Returns the type of the armor.
  100. * @return L2ArmorType
  101. */
  102. @Override
  103. public L2ArmorType getItemType()
  104. {
  105. return (L2ArmorType)super._type;
  106. }
  107. /**
  108. * Returns the ID of the item after applying the mask.
  109. * @return int : ID of the item
  110. */
  111. @Override
  112. public final int getItemMask()
  113. {
  114. return getItemType().mask();
  115. }
  116. /**
  117. * Returns the magical defense of the armor
  118. * @return int : value of the magic defense
  119. */
  120. public final int getMDef()
  121. {
  122. return _mDef;
  123. }
  124. /**
  125. * Returns the physical defense of the armor
  126. * @return int : value of the physical defense
  127. */
  128. public final int getPDef()
  129. {
  130. return _pDef;
  131. }
  132. /**
  133. * Returns avoid modifier given by the armor
  134. * @return int : avoid modifier
  135. */
  136. public final int getAvoidModifier()
  137. {
  138. return _avoidModifier;
  139. }
  140. /**
  141. * Returns magical bonus given by the armor
  142. * @return int : value of the magical bonus
  143. */
  144. public final int getMpBonus()
  145. {
  146. return _mpBonus;
  147. }
  148. /**
  149. * Returns physical bonus given by the armor
  150. * @return int : value of the physical bonus
  151. */
  152. public final int getHpBonus()
  153. {
  154. return _hpBonus;
  155. }
  156. /**
  157. * Returns skill that player get when has equiped armor +4 or more
  158. * @return
  159. */
  160. public L2Skill getEnchant4Skill()
  161. {
  162. return _enchant4Skill;
  163. }
  164. /**
  165. * Returns passive skill linked to that armor
  166. * @return
  167. */
  168. public SkillHolder[] getSkills()
  169. {
  170. return _skillHolder;
  171. }
  172. /**
  173. * Returns array of Func objects containing the list of functions used by the armor
  174. * @param instance : L2ItemInstance pointing out the armor
  175. * @param player : L2Character pointing out the player
  176. * @return Func[] : array of functions
  177. */
  178. @Override
  179. public Func[] getStatFuncs(L2ItemInstance instance, L2Character player)
  180. {
  181. if (_funcTemplates == null || _funcTemplates.length == 0)
  182. return _emptyFunctionSet;
  183. ArrayList<Func> funcs = new ArrayList<Func>(_funcTemplates.length);
  184. Env env = new Env();
  185. env.player = player;
  186. env.item = instance;
  187. Func f;
  188. for (FuncTemplate t : _funcTemplates) {
  189. f = t.getFunc(env, instance);
  190. if (f != null)
  191. funcs.add(f);
  192. }
  193. return funcs.toArray(new Func[funcs.size()]);
  194. }
  195. }