L2ArmorSet.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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.model;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.model.holders.SkillHolder;
  20. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  21. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  22. /**
  23. * @author Luno
  24. */
  25. public final class L2ArmorSet
  26. {
  27. private int _chestId;
  28. private final List<Integer> _legs;
  29. private final List<Integer> _head;
  30. private final List<Integer> _gloves;
  31. private final List<Integer> _feet;
  32. private final List<Integer> _shield;
  33. private final List<SkillHolder> _skills;
  34. private final List<SkillHolder> _shieldSkills;
  35. private final List<SkillHolder> _enchant6Skill;
  36. public L2ArmorSet()
  37. {
  38. _legs = new ArrayList<>();
  39. _head = new ArrayList<>();
  40. _gloves = new ArrayList<>();
  41. _feet = new ArrayList<>();
  42. _shield = new ArrayList<>();
  43. _skills = new ArrayList<>();
  44. _shieldSkills = new ArrayList<>();
  45. _enchant6Skill = new ArrayList<>();
  46. }
  47. public void addChest(int id)
  48. {
  49. _chestId = id;
  50. }
  51. public void addLegs(int id)
  52. {
  53. _legs.add(id);
  54. }
  55. public void addHead(int id)
  56. {
  57. _head.add(id);
  58. }
  59. public void addGloves(int id)
  60. {
  61. _gloves.add(id);
  62. }
  63. public void addFeet(int id)
  64. {
  65. _feet.add(id);
  66. }
  67. public void addShield(int id)
  68. {
  69. _shield.add(id);
  70. }
  71. public void addSkill(SkillHolder holder)
  72. {
  73. _skills.add(holder);
  74. }
  75. public void addShieldSkill(SkillHolder holder)
  76. {
  77. _shieldSkills.add(holder);
  78. }
  79. public void addEnchant6Skill(SkillHolder holder)
  80. {
  81. _enchant6Skill.add(holder);
  82. }
  83. /**
  84. * Checks if player have equipped all items from set (not checking shield)
  85. *
  86. * @param player
  87. * whose inventory is being checked
  88. * @return True if player equips whole set
  89. */
  90. public boolean containAll(L2PcInstance player)
  91. {
  92. Inventory inv = player.getInventory();
  93. L2ItemInstance legsItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  94. L2ItemInstance headItem = inv.getPaperdollItem(Inventory.PAPERDOLL_HEAD);
  95. L2ItemInstance glovesItem = inv.getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  96. L2ItemInstance feetItem = inv.getPaperdollItem(Inventory.PAPERDOLL_FEET);
  97. int legs = 0;
  98. int head = 0;
  99. int gloves = 0;
  100. int feet = 0;
  101. if (legsItem != null)
  102. legs = legsItem.getItemId();
  103. if (headItem != null)
  104. head = headItem.getItemId();
  105. if (glovesItem != null)
  106. gloves = glovesItem.getItemId();
  107. if (feetItem != null)
  108. feet = feetItem.getItemId();
  109. return containAll(_chestId, legs, head, gloves, feet);
  110. }
  111. public boolean containAll(int chest, int legs, int head, int gloves, int feet)
  112. {
  113. if (_chestId != 0 &&_chestId != chest)
  114. return false;
  115. if (!_legs.isEmpty() && !_legs.contains(legs))
  116. return false;
  117. if (!_head.isEmpty() && !_head.contains(head))
  118. return false;
  119. if (!_gloves.isEmpty() && !_gloves.contains(gloves))
  120. return false;
  121. if (!_feet.isEmpty() && !_feet.contains(feet))
  122. return false;
  123. return true;
  124. }
  125. public boolean containItem(int slot, int itemId)
  126. {
  127. switch (slot)
  128. {
  129. case Inventory.PAPERDOLL_CHEST:
  130. return _chestId == itemId;
  131. case Inventory.PAPERDOLL_LEGS:
  132. return _legs.contains(itemId);
  133. case Inventory.PAPERDOLL_HEAD:
  134. return _head.contains(itemId);
  135. case Inventory.PAPERDOLL_GLOVES:
  136. return _gloves.contains(itemId);
  137. case Inventory.PAPERDOLL_FEET:
  138. return _feet.contains(itemId);
  139. default:
  140. return false;
  141. }
  142. }
  143. public int getChestId()
  144. {
  145. return _chestId;
  146. }
  147. public List<SkillHolder> getSkills()
  148. {
  149. return _skills;
  150. }
  151. public boolean containShield(L2PcInstance player)
  152. {
  153. Inventory inv = player.getInventory();
  154. L2ItemInstance shieldItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  155. return (shieldItem != null && _shield.contains(Integer.valueOf(shieldItem.getItemId())));
  156. }
  157. public boolean containShield(int shield_id)
  158. {
  159. if (_shield.isEmpty())
  160. return false;
  161. return _shield.contains(Integer.valueOf(shield_id));
  162. }
  163. public List<SkillHolder> getShieldSkillId()
  164. {
  165. return _shieldSkills;
  166. }
  167. public List<SkillHolder> getEnchant6skillId()
  168. {
  169. return _enchant6Skill;
  170. }
  171. /**
  172. * @param player
  173. * @return true if all parts of set are enchanted to +6 or more
  174. */
  175. public boolean isEnchanted6(L2PcInstance player)
  176. {
  177. // Player don't have full set
  178. if (!containAll(player))
  179. return false;
  180. Inventory inv = player.getInventory();
  181. L2ItemInstance chestItem = inv.getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  182. L2ItemInstance legsItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  183. L2ItemInstance headItem = inv.getPaperdollItem(Inventory.PAPERDOLL_HEAD);
  184. L2ItemInstance glovesItem = inv.getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  185. L2ItemInstance feetItem = inv.getPaperdollItem(Inventory.PAPERDOLL_FEET);
  186. if (chestItem == null || chestItem.getEnchantLevel() < 6)
  187. return false;
  188. if (!_legs.isEmpty() && (legsItem == null || legsItem.getEnchantLevel() < 6))
  189. return false;
  190. if (!_gloves.isEmpty() && (glovesItem == null || glovesItem.getEnchantLevel() < 6))
  191. return false;
  192. if (!_head.isEmpty() && (headItem == null || headItem.getEnchantLevel() < 6))
  193. return false;
  194. if (!_feet.isEmpty() && (feetItem == null || feetItem.getEnchantLevel() < 6))
  195. return false;
  196. return true;
  197. }
  198. }