L2Armor.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 SkillHolder[] _skillHolder;
  37. private L2ArmorType _type;
  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. * <LI>enchant4Skill</LI>
  45. * @param type : L2ArmorType designating the type of armor
  46. * @param set : StatsSet designating the set of couples (key,value) caracterizing the armor
  47. * @see L2Item constructor
  48. */
  49. public L2Armor(StatsSet set)
  50. {
  51. super(set);
  52. _type = L2ArmorType.valueOf(set.getString("armor_type", "none").toUpperCase());
  53. int _bodyPart = getBodyPart();
  54. if (_bodyPart == L2Item.SLOT_NECK || _bodyPart == L2Item.SLOT_HAIR || _bodyPart == L2Item.SLOT_HAIR2
  55. || _bodyPart == L2Item.SLOT_HAIRALL || (_bodyPart & L2Item.SLOT_L_EAR) != 0 || (_bodyPart & L2Item.SLOT_L_FINGER) != 0
  56. || (_bodyPart & L2Item.SLOT_R_BRACELET) != 0 || (_bodyPart & L2Item.SLOT_L_BRACELET) != 0
  57. || (_bodyPart & L2Item.SLOT_BACK) != 0 )
  58. {
  59. _type1 = L2Item.TYPE1_WEAPON_RING_EARRING_NECKLACE;
  60. _type2 = L2Item.TYPE2_ACCESSORY;
  61. }
  62. else
  63. {
  64. if (_type == L2ArmorType.NONE && getBodyPart() == L2Item.SLOT_L_HAND) // retail define shield as NONE
  65. _type = L2ArmorType.SHIELD;
  66. _type1 = L2Item.TYPE1_SHIELD_ARMOR;
  67. _type2 = L2Item.TYPE2_SHIELD_ARMOR;
  68. }
  69. _avoidModifier = set.getInteger("avoid_modify", 0);
  70. String skill = set.getString("enchant4_skill", null);
  71. if (skill != null)
  72. {
  73. String[] info = skill.split("-");
  74. if (info != null && info.length == 2)
  75. {
  76. int id = 0;
  77. int level = 0;
  78. try
  79. {
  80. id = Integer.parseInt(info[0]);
  81. level = Integer.parseInt(info[1]);
  82. }
  83. catch (Exception nfe)
  84. {
  85. // Incorrect syntax, dont add new skill
  86. _log.info(StringUtil.concat("> Couldnt parse ", skill, " in armor enchant skills! item ",this.toString()));
  87. }
  88. if (id > 0 && level > 0)
  89. _enchant4Skill = new SkillHolder(id, level);
  90. }
  91. }
  92. skill = set.getString("item_skill", null);
  93. if (skill != null)
  94. {
  95. String[] skills = skill.split(";");
  96. _skillHolder = new SkillHolder[skills.length];
  97. byte iterator = 0;
  98. for (String st : skills)
  99. {
  100. String[] info = st.split("-");
  101. if (info == null || info.length != 2)
  102. continue;
  103. int id = 0;
  104. int level = 0;
  105. try
  106. {
  107. id = Integer.parseInt(info[0]);
  108. level = Integer.parseInt(info[1]);
  109. }
  110. catch (Exception nfe)
  111. {
  112. // Incorrect syntax, dont add new skill
  113. _log.info(StringUtil.concat("> Couldnt parse ", st, " in armor skills! item ",this.toString()));
  114. continue;
  115. }
  116. // If skill can exist, add it
  117. if (id > 0 && level > 0)
  118. {
  119. _skillHolder[iterator] = new SkillHolder(id, level);
  120. iterator++;
  121. }
  122. }
  123. }
  124. }
  125. /**
  126. * Returns the type of the armor.
  127. * @return L2ArmorType
  128. */
  129. @Override
  130. public L2ArmorType getItemType()
  131. {
  132. return _type;
  133. }
  134. /**
  135. * Returns the ID of the item after applying the mask.
  136. * @return int : ID of the item
  137. */
  138. @Override
  139. public final int getItemMask()
  140. {
  141. return getItemType().mask();
  142. }
  143. /**
  144. * Returns avoid modifier given by the armor
  145. * @return int : avoid modifier
  146. */
  147. public final int getAvoidModifier()
  148. {
  149. return _avoidModifier;
  150. }
  151. /**
  152. * Returns skill that player get when has equiped armor +4 or more
  153. * @return
  154. */
  155. public L2Skill getEnchant4Skill()
  156. {
  157. if (_enchant4Skill == null)
  158. return null;
  159. return _enchant4Skill.getSkill();
  160. }
  161. /**
  162. * Returns passive skill linked to that armor
  163. * @return
  164. */
  165. @Override
  166. public SkillHolder[] getSkills()
  167. {
  168. return _skillHolder;
  169. }
  170. /**
  171. * Returns array of Func objects containing the list of functions used by the armor
  172. * @param instance : L2ItemInstance pointing out the armor
  173. * @param player : L2Character pointing out the player
  174. * @return Func[] : array of functions
  175. */
  176. @Override
  177. public Func[] getStatFuncs(L2ItemInstance instance, L2Character player)
  178. {
  179. if (_funcTemplates == null || _funcTemplates.length == 0)
  180. return _emptyFunctionSet;
  181. ArrayList<Func> funcs = new ArrayList<Func>(_funcTemplates.length);
  182. Env env = new Env();
  183. env.player = player;
  184. env.item = instance;
  185. Func f;
  186. for (FuncTemplate t : _funcTemplates) {
  187. f = t.getFunc(env, instance);
  188. if (f != null)
  189. funcs.add(f);
  190. }
  191. return funcs.toArray(new Func[funcs.size()]);
  192. }
  193. }