L2Armor.java 4.9 KB

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