L2Armor.java 4.1 KB

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