L2Armor.java 4.4 KB

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