L2ArmorSet.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 javolution.util.FastList;
  17. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.model.holders.SkillHolder;
  19. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  20. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  21. /**
  22. * @author Luno
  23. */
  24. public final class L2ArmorSet
  25. {
  26. private final FastList<Integer> _chest;
  27. private final FastList<Integer> _legs;
  28. private final FastList<Integer> _head;
  29. private final FastList<Integer> _gloves;
  30. private final FastList<Integer> _feet;
  31. private final FastList<Integer> _shield;
  32. private final FastList<SkillHolder> _skills;
  33. private final FastList<SkillHolder> _shieldSkills;
  34. private final FastList<SkillHolder> _enchant6Skill;
  35. public L2ArmorSet()
  36. {
  37. _chest = new FastList<>();
  38. _legs = new FastList<>();
  39. _head = new FastList<>();
  40. _gloves = new FastList<>();
  41. _feet = new FastList<>();
  42. _shield = new FastList<>();
  43. _skills = new FastList<>();
  44. _shieldSkills = new FastList<>();
  45. _enchant6Skill = new FastList<>();
  46. }
  47. public void addChest(int id)
  48. {
  49. _chest.add(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. if (!_chest.isEmpty())
  110. {
  111. for (Integer chest : _chest)
  112. {
  113. if (containAll(chest, legs, head, gloves, feet))
  114. return true;
  115. }
  116. }
  117. return containAll(0, legs, head, gloves, feet);
  118. }
  119. public boolean containAll(int chest, int legs, int head, int gloves, int feet)
  120. {
  121. if (!_chest.isEmpty() && !_chest.contains(Integer.valueOf(chest)))
  122. return false;
  123. if (!_legs.isEmpty() && !_legs.contains(Integer.valueOf(legs)))
  124. return false;
  125. if (!_head.isEmpty() && !_head.contains(Integer.valueOf(head)))
  126. return false;
  127. if (!_gloves.isEmpty() && !_gloves.contains(Integer.valueOf(gloves)))
  128. return false;
  129. if (!_feet.isEmpty() && !_feet.contains(Integer.valueOf(feet)))
  130. return false;
  131. return true;
  132. }
  133. public boolean containItem(int slot, Integer itemId)
  134. {
  135. switch (slot)
  136. {
  137. case Inventory.PAPERDOLL_CHEST:
  138. return _chest.contains(Integer.valueOf(itemId));
  139. case Inventory.PAPERDOLL_LEGS:
  140. return _legs.contains(Integer.valueOf(itemId));
  141. case Inventory.PAPERDOLL_HEAD:
  142. return _head.contains(Integer.valueOf(itemId));
  143. case Inventory.PAPERDOLL_GLOVES:
  144. return _gloves.contains(Integer.valueOf(itemId));
  145. case Inventory.PAPERDOLL_FEET:
  146. return _feet.contains(Integer.valueOf(itemId));
  147. default:
  148. return false;
  149. }
  150. }
  151. public FastList<SkillHolder> getSkills()
  152. {
  153. return _skills;
  154. }
  155. public boolean containShield(L2PcInstance player)
  156. {
  157. Inventory inv = player.getInventory();
  158. L2ItemInstance shieldItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  159. return (shieldItem != null && _shield.contains(Integer.valueOf(shieldItem.getItemId())));
  160. }
  161. public boolean containShield(int shield_id)
  162. {
  163. if (_shield.isEmpty())
  164. return false;
  165. return _shield.contains(Integer.valueOf(shield_id));
  166. }
  167. public FastList<SkillHolder> getShieldSkillId()
  168. {
  169. return _shieldSkills;
  170. }
  171. public FastList<SkillHolder> getEnchant6skillId()
  172. {
  173. return _enchant6Skill;
  174. }
  175. /**
  176. * @param player
  177. * @return true if all parts of set are enchanted to +6 or more
  178. */
  179. public boolean isEnchanted6(L2PcInstance player)
  180. {
  181. // Player don't have full set
  182. if (!containAll(player))
  183. return false;
  184. Inventory inv = player.getInventory();
  185. L2ItemInstance chestItem = inv.getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  186. L2ItemInstance legsItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  187. L2ItemInstance headItem = inv.getPaperdollItem(Inventory.PAPERDOLL_HEAD);
  188. L2ItemInstance glovesItem = inv.getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  189. L2ItemInstance feetItem = inv.getPaperdollItem(Inventory.PAPERDOLL_FEET);
  190. if (chestItem == null || chestItem.getEnchantLevel() < 6)
  191. return false;
  192. if (!_legs.isEmpty() && (legsItem == null || legsItem.getEnchantLevel() < 6))
  193. return false;
  194. if (!_gloves.isEmpty() && (glovesItem == null || glovesItem.getEnchantLevel() < 6))
  195. return false;
  196. if (!_head.isEmpty() && (headItem == null || headItem.getEnchantLevel() < 6))
  197. return false;
  198. if (!_feet.isEmpty() && (feetItem == null || feetItem.getEnchantLevel() < 6))
  199. return false;
  200. return true;
  201. }
  202. public boolean containsChest(int chestId)
  203. {
  204. return _chest.contains(Integer.valueOf(chestId));
  205. }
  206. }