L2ArmorSet.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under the terms of the
  3. * GNU General Public License as published by the Free Software Foundation, either version 3 of the
  4. * License, or (at your option) any later version.
  5. *
  6. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  7. * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  8. * General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with this program. If
  11. * not, see <http://www.gnu.org/licenses/>.
  12. */
  13. package com.l2jserver.gameserver.model;
  14. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  15. import com.l2jserver.gameserver.model.item.instance.L2ItemInstance;
  16. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  17. /**
  18. *
  19. * @author Luno
  20. */
  21. public final class L2ArmorSet
  22. {
  23. private final int _chest;
  24. private final int _legs;
  25. private final int _head;
  26. private final int _gloves;
  27. private final int _feet;
  28. private final int _mw_legs;
  29. private final int _mw_head;
  30. private final int _mw_gloves;
  31. private final int _mw_feet;
  32. private final String[] _skills;
  33. private final int _shield;
  34. private final int _mw_shield;
  35. private final int _shieldSkillId;
  36. private final int _enchant6Skill;
  37. public L2ArmorSet(int chest, int legs, int head, int gloves, int feet, String[] skills, int shield, int shield_skill_id, int enchant6skill, int mw_legs, int mw_head, int mw_gloves, int mw_feet, int mw_shield)
  38. {
  39. _chest = chest;
  40. _legs = legs;
  41. _head = head;
  42. _gloves = gloves;
  43. _feet = feet;
  44. _mw_legs = mw_legs;
  45. _mw_head = mw_head;
  46. _mw_gloves = mw_gloves;
  47. _mw_feet = mw_feet;
  48. _mw_shield = mw_shield;
  49. _skills = skills;
  50. _shield = shield;
  51. _shieldSkillId = shield_skill_id;
  52. _enchant6Skill = enchant6skill;
  53. }
  54. /**
  55. * Checks if player have equiped all items from set (not checking shield)
  56. *
  57. * @param player
  58. * whose inventory is being checked
  59. * @return True if player equips whole set
  60. */
  61. public boolean containAll(L2PcInstance player)
  62. {
  63. Inventory inv = player.getInventory();
  64. L2ItemInstance legsItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  65. L2ItemInstance headItem = inv.getPaperdollItem(Inventory.PAPERDOLL_HEAD);
  66. L2ItemInstance glovesItem = inv.getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  67. L2ItemInstance feetItem = inv.getPaperdollItem(Inventory.PAPERDOLL_FEET);
  68. int legs = 0;
  69. int head = 0;
  70. int gloves = 0;
  71. int feet = 0;
  72. if (legsItem != null)
  73. legs = legsItem.getItemId();
  74. if (headItem != null)
  75. head = headItem.getItemId();
  76. if (glovesItem != null)
  77. gloves = glovesItem.getItemId();
  78. if (feetItem != null)
  79. feet = feetItem.getItemId();
  80. return containAll(_chest, legs, head, gloves, feet);
  81. }
  82. public boolean containAll(int chest, int legs, int head, int gloves, int feet)
  83. {
  84. if (_chest != 0 && _chest != chest)
  85. return false;
  86. if (_legs != 0 && _legs != legs && (_mw_legs == 0 || _mw_legs != legs))
  87. return false;
  88. if (_head != 0 && _head != head && (_mw_head == 0 || _mw_head != head))
  89. return false;
  90. if (_gloves != 0 && _gloves != gloves && (_mw_gloves == 0 || _mw_gloves != gloves))
  91. return false;
  92. if (_feet != 0 && _feet != feet && (_mw_feet == 0 || _mw_feet != feet))
  93. return false;
  94. return true;
  95. }
  96. public boolean containItem(int slot, int itemId)
  97. {
  98. switch (slot)
  99. {
  100. case Inventory.PAPERDOLL_CHEST:
  101. return _chest == itemId;
  102. case Inventory.PAPERDOLL_LEGS:
  103. return (_legs == itemId || _mw_legs == itemId);
  104. case Inventory.PAPERDOLL_HEAD:
  105. return (_head == itemId || _mw_head == itemId);
  106. case Inventory.PAPERDOLL_GLOVES:
  107. return (_gloves == itemId || _mw_gloves == itemId);
  108. case Inventory.PAPERDOLL_FEET:
  109. return (_feet == itemId || _mw_feet == itemId);
  110. default:
  111. return false;
  112. }
  113. }
  114. public String[] getSkills()
  115. {
  116. return _skills;
  117. }
  118. public boolean containShield(L2PcInstance player)
  119. {
  120. Inventory inv = player.getInventory();
  121. L2ItemInstance shieldItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  122. if (shieldItem != null && (shieldItem.getItemId() == _shield || shieldItem.getItemId() == _mw_shield))
  123. return true;
  124. return false;
  125. }
  126. public boolean containShield(int shield_id)
  127. {
  128. if (_shield == 0)
  129. return false;
  130. return (_shield == shield_id || _mw_shield == shield_id);
  131. }
  132. public int getShieldSkillId()
  133. {
  134. return _shieldSkillId;
  135. }
  136. public int getEnchant6skillId()
  137. {
  138. return _enchant6Skill;
  139. }
  140. /**
  141. * @param player
  142. * @return true if all parts of set are enchanted to +6 or more
  143. */
  144. public boolean isEnchanted6(L2PcInstance player)
  145. {
  146. // Player don't have full set
  147. if (!containAll(player))
  148. return false;
  149. Inventory inv = player.getInventory();
  150. L2ItemInstance chestItem = inv.getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  151. L2ItemInstance legsItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  152. L2ItemInstance headItem = inv.getPaperdollItem(Inventory.PAPERDOLL_HEAD);
  153. L2ItemInstance glovesItem = inv.getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  154. L2ItemInstance feetItem = inv.getPaperdollItem(Inventory.PAPERDOLL_FEET);
  155. if (chestItem == null || chestItem.getEnchantLevel() < 6)
  156. return false;
  157. if (_legs != 0 && (legsItem == null || legsItem.getEnchantLevel() < 6))
  158. return false;
  159. if (_gloves != 0 && (glovesItem == null || glovesItem.getEnchantLevel() < 6))
  160. return false;
  161. if (_head != 0 && (headItem == null || headItem.getEnchantLevel() < 6))
  162. return false;
  163. if (_feet != 0 && (feetItem == null || feetItem.getEnchantLevel() < 6))
  164. return false;
  165. return true;
  166. }
  167. }