EnchantItem.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.Arrays;
  17. import com.l2jserver.gameserver.model.items.L2Item;
  18. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  19. /**
  20. * @author UnAfraid
  21. */
  22. public class EnchantItem
  23. {
  24. protected final boolean _isWeapon;
  25. protected final int _grade;
  26. protected final int _maxEnchantLevel;
  27. protected final double _chanceAdd;
  28. protected final int[] _itemIds;
  29. /**
  30. * @param wep
  31. * @param type
  32. * @param level
  33. * @param chance
  34. * @param items
  35. */
  36. public EnchantItem(boolean wep, int type, int level, double chance, int[] items)
  37. {
  38. _isWeapon = wep;
  39. _grade = type;
  40. _maxEnchantLevel = level;
  41. _chanceAdd = chance;
  42. _itemIds = items;
  43. }
  44. /**
  45. * @param enchantItem
  46. * @return true if support item can be used for this item
  47. */
  48. public final boolean isValid(L2ItemInstance enchantItem)
  49. {
  50. if (enchantItem == null)
  51. return false;
  52. else if (enchantItem.isEnchantable() == 0)
  53. return false;
  54. else if (!isValidItemType(enchantItem.getItem().getType2()))
  55. return false;
  56. else if (_maxEnchantLevel != 0 && enchantItem.getEnchantLevel() >= _maxEnchantLevel)
  57. return false;
  58. else if (_grade != enchantItem.getItem().getItemGradeSPlus())
  59. return false;
  60. else if ((enchantItem.isEnchantable() > 1 && (_itemIds == null || Arrays.binarySearch(_itemIds, enchantItem.getItemId()) < 0)) || _itemIds != null && Arrays.binarySearch(_itemIds, enchantItem.getItemId()) < 0)
  61. return false;
  62. return true;
  63. }
  64. private boolean isValidItemType(int type2)
  65. {
  66. if (type2 == L2Item.TYPE2_WEAPON)
  67. {
  68. return _isWeapon;
  69. }
  70. else if (type2 == L2Item.TYPE2_SHIELD_ARMOR || type2 == L2Item.TYPE2_ACCESSORY)
  71. {
  72. return !_isWeapon;
  73. }
  74. return false;
  75. }
  76. /**
  77. * @return chance increase
  78. */
  79. public final double getChanceAdd()
  80. {
  81. return _chanceAdd;
  82. }
  83. }