L2ArmorSet.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  17. import com.l2jserver.gameserver.model.itemcontainer.Inventory;
  18. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  19. /**
  20. * @author Luno
  21. */
  22. public final class L2ArmorSet
  23. {
  24. private final int _chest;
  25. private final int _legs;
  26. private final int _head;
  27. private final int _gloves;
  28. private final int _feet;
  29. private final int _mw_legs;
  30. private final int _mw_head;
  31. private final int _mw_gloves;
  32. private final int _mw_feet;
  33. private final String[] _skills;
  34. private final int _shield;
  35. private final int _mw_shield;
  36. private final int _shieldSkillId;
  37. private final int _enchant6Skill;
  38. 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)
  39. {
  40. _chest = chest;
  41. _legs = legs;
  42. _head = head;
  43. _gloves = gloves;
  44. _feet = feet;
  45. _mw_legs = mw_legs;
  46. _mw_head = mw_head;
  47. _mw_gloves = mw_gloves;
  48. _mw_feet = mw_feet;
  49. _mw_shield = mw_shield;
  50. _skills = skills;
  51. _shield = shield;
  52. _shieldSkillId = shield_skill_id;
  53. _enchant6Skill = enchant6skill;
  54. }
  55. /**
  56. * Checks if player have equipped all items from set (not checking shield)
  57. *
  58. * @param player
  59. * whose inventory is being checked
  60. * @return True if player equips whole set
  61. */
  62. public boolean containAll(L2PcInstance player)
  63. {
  64. Inventory inv = player.getInventory();
  65. L2ItemInstance legsItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  66. L2ItemInstance headItem = inv.getPaperdollItem(Inventory.PAPERDOLL_HEAD);
  67. L2ItemInstance glovesItem = inv.getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  68. L2ItemInstance feetItem = inv.getPaperdollItem(Inventory.PAPERDOLL_FEET);
  69. int legs = 0;
  70. int head = 0;
  71. int gloves = 0;
  72. int feet = 0;
  73. if (legsItem != null)
  74. legs = legsItem.getItemId();
  75. if (headItem != null)
  76. head = headItem.getItemId();
  77. if (glovesItem != null)
  78. gloves = glovesItem.getItemId();
  79. if (feetItem != null)
  80. feet = feetItem.getItemId();
  81. return containAll(_chest, legs, head, gloves, feet);
  82. }
  83. public boolean containAll(int chest, int legs, int head, int gloves, int feet)
  84. {
  85. if (_chest != 0 && _chest != chest)
  86. return false;
  87. if (_legs != 0 && _legs != legs && (_mw_legs == 0 || _mw_legs != legs))
  88. return false;
  89. if (_head != 0 && _head != head && (_mw_head == 0 || _mw_head != head))
  90. return false;
  91. if (_gloves != 0 && _gloves != gloves && (_mw_gloves == 0 || _mw_gloves != gloves))
  92. return false;
  93. if (_feet != 0 && _feet != feet && (_mw_feet == 0 || _mw_feet != feet))
  94. return false;
  95. return true;
  96. }
  97. public boolean containItem(int slot, int itemId)
  98. {
  99. switch (slot)
  100. {
  101. case Inventory.PAPERDOLL_CHEST:
  102. return _chest == itemId;
  103. case Inventory.PAPERDOLL_LEGS:
  104. return (_legs == itemId || _mw_legs == itemId);
  105. case Inventory.PAPERDOLL_HEAD:
  106. return (_head == itemId || _mw_head == itemId);
  107. case Inventory.PAPERDOLL_GLOVES:
  108. return (_gloves == itemId || _mw_gloves == itemId);
  109. case Inventory.PAPERDOLL_FEET:
  110. return (_feet == itemId || _mw_feet == itemId);
  111. default:
  112. return false;
  113. }
  114. }
  115. public String[] getSkills()
  116. {
  117. return _skills;
  118. }
  119. public boolean containShield(L2PcInstance player)
  120. {
  121. Inventory inv = player.getInventory();
  122. L2ItemInstance shieldItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LHAND);
  123. if (shieldItem != null && (shieldItem.getItemId() == _shield || shieldItem.getItemId() == _mw_shield))
  124. return true;
  125. return false;
  126. }
  127. public boolean containShield(int shield_id)
  128. {
  129. if (_shield == 0)
  130. return false;
  131. return (_shield == shield_id || _mw_shield == shield_id);
  132. }
  133. public int getShieldSkillId()
  134. {
  135. return _shieldSkillId;
  136. }
  137. public int getEnchant6skillId()
  138. {
  139. return _enchant6Skill;
  140. }
  141. /**
  142. * @param player
  143. * @return true if all parts of set are enchanted to +6 or more
  144. */
  145. public boolean isEnchanted6(L2PcInstance player)
  146. {
  147. // Player don't have full set
  148. if (!containAll(player))
  149. return false;
  150. Inventory inv = player.getInventory();
  151. L2ItemInstance chestItem = inv.getPaperdollItem(Inventory.PAPERDOLL_CHEST);
  152. L2ItemInstance legsItem = inv.getPaperdollItem(Inventory.PAPERDOLL_LEGS);
  153. L2ItemInstance headItem = inv.getPaperdollItem(Inventory.PAPERDOLL_HEAD);
  154. L2ItemInstance glovesItem = inv.getPaperdollItem(Inventory.PAPERDOLL_GLOVES);
  155. L2ItemInstance feetItem = inv.getPaperdollItem(Inventory.PAPERDOLL_FEET);
  156. if (chestItem == null || chestItem.getEnchantLevel() < 6)
  157. return false;
  158. if (_legs != 0 && (legsItem == null || legsItem.getEnchantLevel() < 6))
  159. return false;
  160. if (_gloves != 0 && (glovesItem == null || glovesItem.getEnchantLevel() < 6))
  161. return false;
  162. if (_head != 0 && (headItem == null || headItem.getEnchantLevel() < 6))
  163. return false;
  164. if (_feet != 0 && (feetItem == null || feetItem.getEnchantLevel() < 6))
  165. return false;
  166. return true;
  167. }
  168. }