EnchantItem.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.List;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.datatables.ItemTable;
  19. import com.l2jserver.gameserver.model.items.L2Item;
  20. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  21. /**
  22. * @author UnAfraid
  23. */
  24. public class EnchantItem
  25. {
  26. protected final int _id;
  27. protected final boolean _isWeapon;
  28. protected final int _grade;
  29. protected final int _maxEnchantLevel;
  30. protected final double _chanceAdd;
  31. protected final List<Integer> _itemIds;
  32. /**
  33. * @param set
  34. * @param items
  35. */
  36. public EnchantItem(StatsSet set, List<Integer> items)
  37. {
  38. _id = set.getInteger("id");
  39. _isWeapon = set.getBool("isWeapon", true);
  40. _grade = ItemTable._crystalTypes.get(set.getString("targetGrade", "none"));
  41. _maxEnchantLevel = set.getInteger("maxEnchant", Config.MAX_ENCHANT_LEVEL);
  42. _chanceAdd = set.getDouble("successBonus", Config.ENCHANT_CHANCE);
  43. _itemIds = items;
  44. }
  45. /**
  46. * @param enchantItem
  47. * @return true if support item can be used for this item
  48. */
  49. public final boolean isValid(L2ItemInstance enchantItem)
  50. {
  51. if (enchantItem == null)
  52. return false;
  53. else if (enchantItem.isEnchantable() == 0)
  54. return false;
  55. else if (!isValidItemType(enchantItem.getItem().getType2()))
  56. return false;
  57. else if (_maxEnchantLevel != 0 && enchantItem.getEnchantLevel() >= _maxEnchantLevel)
  58. return false;
  59. else if (_grade != enchantItem.getItem().getItemGradeSPlus())
  60. return false;
  61. else if ((enchantItem.isEnchantable() > 1 && (_itemIds.isEmpty() || !_itemIds.contains(enchantItem.getItemId())))
  62. || !_itemIds.isEmpty() && !_itemIds.contains(enchantItem.getItemId()))
  63. return false;
  64. return true;
  65. }
  66. private boolean isValidItemType(int type2)
  67. {
  68. if (type2 == L2Item.TYPE2_WEAPON)
  69. {
  70. return _isWeapon;
  71. }
  72. else if (type2 == L2Item.TYPE2_SHIELD_ARMOR || type2 == L2Item.TYPE2_ACCESSORY)
  73. {
  74. return !_isWeapon;
  75. }
  76. return false;
  77. }
  78. /**
  79. * @return chance increase
  80. */
  81. public final double getChanceAdd()
  82. {
  83. return _chanceAdd;
  84. }
  85. public int getScrollId()
  86. {
  87. return _id;
  88. }
  89. }