L2Armor.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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.model.L2ItemInstance;
  18. import com.l2jserver.gameserver.model.L2Skill;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.skills.Env;
  21. import com.l2jserver.gameserver.skills.SkillHolder;
  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 com.l2jserver.util.StringUtil;
  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 SkillHolder _enchant4Skill = null; // skill that activates when armor is enchanted +4
  35. // private final String[] _skill;
  36. private L2ArmorType _type;
  37. /**
  38. * Constructor for Armor.<BR><BR>
  39. * <U><I>Variables filled :</I></U><BR>
  40. * <LI>_avoidModifier</LI>
  41. * <LI>_pDef & _mDef</LI>
  42. * <LI>_mpBonus & _hpBonus</LI>
  43. * <LI>enchant4Skill</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(StatsSet set)
  49. {
  50. super(set);
  51. _type = L2ArmorType.valueOf(set.getString("armor_type", "none").toUpperCase());
  52. int _bodyPart = getBodyPart();
  53. if (_bodyPart == L2Item.SLOT_NECK || _bodyPart == L2Item.SLOT_HAIR || _bodyPart == L2Item.SLOT_HAIR2
  54. || _bodyPart == L2Item.SLOT_HAIRALL || (_bodyPart & L2Item.SLOT_L_EAR) != 0 || (_bodyPart & L2Item.SLOT_L_FINGER) != 0
  55. || (_bodyPart & L2Item.SLOT_R_BRACELET) != 0 || (_bodyPart & L2Item.SLOT_L_BRACELET) != 0
  56. || (_bodyPart & L2Item.SLOT_BACK) != 0 )
  57. {
  58. _type1 = L2Item.TYPE1_WEAPON_RING_EARRING_NECKLACE;
  59. _type2 = L2Item.TYPE2_ACCESSORY;
  60. }
  61. else
  62. {
  63. if (_type == L2ArmorType.NONE && getBodyPart() == L2Item.SLOT_L_HAND) // retail define shield as NONE
  64. _type = L2ArmorType.SHIELD;
  65. _type1 = L2Item.TYPE1_SHIELD_ARMOR;
  66. _type2 = L2Item.TYPE2_SHIELD_ARMOR;
  67. }
  68. _avoidModifier = set.getInteger("avoid_modify", 0);
  69. String skill = set.getString("enchant4_skill", null);
  70. if (skill != null)
  71. {
  72. String[] info = skill.split("-");
  73. if (info != null && info.length == 2)
  74. {
  75. int id = 0;
  76. int level = 0;
  77. try
  78. {
  79. id = Integer.parseInt(info[0]);
  80. level = Integer.parseInt(info[1]);
  81. }
  82. catch (Exception nfe)
  83. {
  84. // Incorrect syntax, dont add new skill
  85. _log.info(StringUtil.concat("> Couldnt parse ", skill, " in armor enchant skills! item ",this.toString()));
  86. }
  87. if (id > 0 && level > 0)
  88. _enchant4Skill = new SkillHolder(id, level);
  89. }
  90. }
  91. }
  92. /**
  93. * Returns the type of the armor.
  94. * @return L2ArmorType
  95. */
  96. @Override
  97. public L2ArmorType getItemType()
  98. {
  99. return _type;
  100. }
  101. /**
  102. * Returns the ID of the item after applying the mask.
  103. * @return int : ID of the item
  104. */
  105. @Override
  106. public final int getItemMask()
  107. {
  108. return getItemType().mask();
  109. }
  110. /**
  111. * Returns avoid modifier given by the armor
  112. * @return int : avoid modifier
  113. */
  114. public final int getAvoidModifier()
  115. {
  116. return _avoidModifier;
  117. }
  118. /**
  119. * Returns skill that player get when has equiped armor +4 or more
  120. * @return
  121. */
  122. public L2Skill getEnchant4Skill()
  123. {
  124. if (_enchant4Skill == null)
  125. return null;
  126. return _enchant4Skill.getSkill();
  127. }
  128. /**
  129. * Returns array of Func objects containing the list of functions used by the armor
  130. * @param instance : L2ItemInstance pointing out the armor
  131. * @param player : L2Character pointing out the player
  132. * @return Func[] : array of functions
  133. */
  134. @Override
  135. public Func[] getStatFuncs(L2ItemInstance instance, L2Character player)
  136. {
  137. if (_funcTemplates == null || _funcTemplates.length == 0)
  138. return _emptyFunctionSet;
  139. ArrayList<Func> funcs = new ArrayList<Func>(_funcTemplates.length);
  140. Env env = new Env();
  141. env.player = player;
  142. env.item = instance;
  143. Func f;
  144. for (FuncTemplate t : _funcTemplates) {
  145. f = t.getFunc(env, instance);
  146. if (f != null)
  147. funcs.add(f);
  148. }
  149. return funcs.toArray(new Func[funcs.size()]);
  150. }
  151. }