L2Armor.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model.items;
  20. import com.l2jserver.gameserver.model.StatsSet;
  21. import com.l2jserver.gameserver.model.holders.SkillHolder;
  22. import com.l2jserver.gameserver.model.items.type.ArmorType;
  23. import com.l2jserver.gameserver.model.skills.Skill;
  24. import com.l2jserver.util.StringUtil;
  25. /**
  26. * This class is dedicated to the management of armors.
  27. */
  28. public final class L2Armor extends L2Item
  29. {
  30. /**
  31. * Skill that activates when armor is enchanted +4.
  32. */
  33. private SkillHolder _enchant4Skill = null;
  34. private ArmorType _type;
  35. /**
  36. * Constructor for Armor.
  37. * @param set the StatsSet designating the set of couples (key,value) characterizing the armor.
  38. */
  39. public L2Armor(StatsSet set)
  40. {
  41. super(set);
  42. _type = set.getEnum("armor_type", ArmorType.class, ArmorType.NONE);
  43. int _bodyPart = getBodyPart();
  44. if ((_bodyPart == L2Item.SLOT_NECK) || ((_bodyPart & L2Item.SLOT_L_EAR) != 0) || ((_bodyPart & L2Item.SLOT_L_FINGER) != 0) || ((_bodyPart & L2Item.SLOT_R_BRACELET) != 0) || ((_bodyPart & L2Item.SLOT_L_BRACELET) != 0))
  45. {
  46. _type1 = L2Item.TYPE1_WEAPON_RING_EARRING_NECKLACE;
  47. _type2 = L2Item.TYPE2_ACCESSORY;
  48. }
  49. else
  50. {
  51. if ((_type == ArmorType.NONE) && (getBodyPart() == L2Item.SLOT_L_HAND))
  52. {
  53. _type = ArmorType.SHIELD;
  54. }
  55. _type1 = L2Item.TYPE1_SHIELD_ARMOR;
  56. _type2 = L2Item.TYPE2_SHIELD_ARMOR;
  57. }
  58. String skill = set.getString("enchant4_skill", null);
  59. if (skill != null)
  60. {
  61. String[] info = skill.split("-");
  62. if ((info != null) && (info.length == 2))
  63. {
  64. int id = 0;
  65. int level = 0;
  66. try
  67. {
  68. id = Integer.parseInt(info[0]);
  69. level = Integer.parseInt(info[1]);
  70. }
  71. catch (Exception nfe)
  72. {
  73. // Incorrect syntax, don't add new skill
  74. _log.info(StringUtil.concat("> Couldnt parse ", skill, " in armor enchant skills! item ", toString()));
  75. }
  76. if ((id > 0) && (level > 0))
  77. {
  78. _enchant4Skill = new SkillHolder(id, level);
  79. }
  80. }
  81. }
  82. }
  83. /**
  84. * @return the type of the armor.
  85. */
  86. @Override
  87. public ArmorType getItemType()
  88. {
  89. return _type;
  90. }
  91. /**
  92. * @return the ID of the item after applying the mask.
  93. */
  94. @Override
  95. public final int getItemMask()
  96. {
  97. return getItemType().mask();
  98. }
  99. /**
  100. * @return skill that player get when has equipped armor +4 or more
  101. */
  102. @Override
  103. public Skill getEnchant4Skill()
  104. {
  105. if (_enchant4Skill == null)
  106. {
  107. return null;
  108. }
  109. return _enchant4Skill.getSkill();
  110. }
  111. }