L2ArmorSet.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. private int _con;
  37. private int _dex;
  38. private int _str;
  39. private int _men;
  40. private int _wit;
  41. private int _int;
  42. public L2ArmorSet()
  43. {
  44. _legs = new ArrayList<>();
  45. _head = new ArrayList<>();
  46. _gloves = new ArrayList<>();
  47. _feet = new ArrayList<>();
  48. _shield = new ArrayList<>();
  49. _skills = new ArrayList<>();
  50. _shieldSkills = new ArrayList<>();
  51. _enchant6Skill = new ArrayList<>();
  52. }
  53. public void addChest(int id)
  54. {
  55. _chestId = id;
  56. }
  57. public void addLegs(int id)
  58. {
  59. _legs.add(id);
  60. }
  61. public void addHead(int id)
  62. {
  63. _head.add(id);
  64. }
  65. public void addGloves(int id)
  66. {
  67. _gloves.add(id);
  68. }
  69. public void addFeet(int id)
  70. {
  71. _feet.add(id);
  72. }
  73. public void addShield(int id)
  74. {
  75. _shield.add(id);
  76. }
  77. public void addSkill(SkillHolder holder)
  78. {
  79. _skills.add(holder);
  80. }
  81. public void addShieldSkill(SkillHolder holder)
  82. {
  83. _shieldSkills.add(holder);
  84. }
  85. public void addEnchant6Skill(SkillHolder holder)
  86. {
  87. _enchant6Skill.add(holder);
  88. }
  89. public void addCon(int val)
  90. {
  91. _con = val;
  92. }
  93. public void addDex(int val)
  94. {
  95. _dex = val;
  96. }
  97. public void addStr(int val)
  98. {
  99. _str = val;
  100. }
  101. public void addMen(int val)
  102. {
  103. _men = val;
  104. }
  105. public void addWit(int val)
  106. {
  107. _wit = val;
  108. }
  109. public void addInt(int val)
  110. {
  111. _int = val;
  112. }
  113. /**
  114. * Checks if player have equipped all items from set (not checking shield)
  115. *
  116. * @param player
  117. * whose inventory is being checked
  118. * @return True if player equips whole set
  119. */
  120. public boolean containAll(L2PcInstance player)
  121. {
  122. Inventory inv = player.getInventory();
  123. L2ItemInstance legsItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  124. L2ItemInstance headItem = inv.getPaperdollItem(Inventory.PAPERDOLL_HEAD);
  125. L2ItemInstance glovesItem = inv.getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  126. L2ItemInstance feetItem = inv.getPaperdollItem(Inventory.PAPERDOLL_FEET);
  127. int legs = 0;
  128. int head = 0;
  129. int gloves = 0;
  130. int feet = 0;
  131. if (legsItem != null)
  132. legs = legsItem.getItemId();
  133. if (headItem != null)
  134. head = headItem.getItemId();
  135. if (glovesItem != null)
  136. gloves = glovesItem.getItemId();
  137. if (feetItem != null)
  138. feet = feetItem.getItemId();
  139. return containAll(_chestId, legs, head, gloves, feet);
  140. }
  141. public boolean containAll(int chest, int legs, int head, int gloves, int feet)
  142. {
  143. if (_chestId != 0 &&_chestId != chest)
  144. return false;
  145. if (!_legs.isEmpty() && !_legs.contains(legs))
  146. return false;
  147. if (!_head.isEmpty() && !_head.contains(head))
  148. return false;
  149. if (!_gloves.isEmpty() && !_gloves.contains(gloves))
  150. return false;
  151. if (!_feet.isEmpty() && !_feet.contains(feet))
  152. return false;
  153. return true;
  154. }
  155. public boolean containItem(int slot, int itemId)
  156. {
  157. switch (slot)
  158. {
  159. case Inventory.PAPERDOLL_CHEST:
  160. return _chestId == itemId;
  161. case Inventory.PAPERDOLL_LEGS:
  162. return _legs.contains(itemId);
  163. case Inventory.PAPERDOLL_HEAD:
  164. return _head.contains(itemId);
  165. case Inventory.PAPERDOLL_GLOVES:
  166. return _gloves.contains(itemId);
  167. case Inventory.PAPERDOLL_FEET:
  168. return _feet.contains(itemId);
  169. default:
  170. return false;
  171. }
  172. }
  173. public int getChestId()
  174. {
  175. return _chestId;
  176. }
  177. public List<SkillHolder> getSkills()
  178. {
  179. return _skills;
  180. }
  181. public boolean containShield(L2PcInstance player)
  182. {
  183. Inventory inv = player.getInventory();
  184. L2ItemInstance shieldItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  185. return (shieldItem != null && _shield.contains(Integer.valueOf(shieldItem.getItemId())));
  186. }
  187. public boolean containShield(int shield_id)
  188. {
  189. if (_shield.isEmpty())
  190. return false;
  191. return _shield.contains(Integer.valueOf(shield_id));
  192. }
  193. public List<SkillHolder> getShieldSkillId()
  194. {
  195. return _shieldSkills;
  196. }
  197. public List<SkillHolder> getEnchant6skillId()
  198. {
  199. return _enchant6Skill;
  200. }
  201. /**
  202. * @param player
  203. * @return true if all parts of set are enchanted to +6 or more
  204. */
  205. public boolean isEnchanted6(L2PcInstance player)
  206. {
  207. // Player don't have full set
  208. if (!containAll(player))
  209. return false;
  210. Inventory inv = player.getInventory();
  211. L2ItemInstance chestItem = inv.getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  212. L2ItemInstance legsItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  213. L2ItemInstance headItem = inv.getPaperdollItem(Inventory.PAPERDOLL_HEAD);
  214. L2ItemInstance glovesItem = inv.getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  215. L2ItemInstance feetItem = inv.getPaperdollItem(Inventory.PAPERDOLL_FEET);
  216. if (chestItem == null || chestItem.getEnchantLevel() < 6)
  217. return false;
  218. if (!_legs.isEmpty() && (legsItem == null || legsItem.getEnchantLevel() < 6))
  219. return false;
  220. if (!_gloves.isEmpty() && (glovesItem == null || glovesItem.getEnchantLevel() < 6))
  221. return false;
  222. if (!_head.isEmpty() && (headItem == null || headItem.getEnchantLevel() < 6))
  223. return false;
  224. if (!_feet.isEmpty() && (feetItem == null || feetItem.getEnchantLevel() < 6))
  225. return false;
  226. return true;
  227. }
  228. public int getCON()
  229. {
  230. return _con;
  231. }
  232. public int getDEX()
  233. {
  234. return _dex;
  235. }
  236. public int getSTR()
  237. {
  238. return _str;
  239. }
  240. public int getMEN()
  241. {
  242. return _men;
  243. }
  244. public int getWIT()
  245. {
  246. return _wit;
  247. }
  248. public int getINT()
  249. {
  250. return _int;
  251. }
  252. }