EnchantScroll.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.model.items.L2Item;
  19. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  20. /**
  21. * @author UnAfraid
  22. */
  23. public class EnchantScroll extends EnchantItem
  24. {
  25. private final boolean _isBlessed;
  26. private final boolean _isSafe;
  27. /**
  28. * @param set
  29. * @param items
  30. */
  31. public EnchantScroll(StatsSet set, List<Integer> items)
  32. {
  33. super(set, items);
  34. _isBlessed = set.getBool("isBlessed", false);
  35. _isSafe = set.getBool("isSafe", false);
  36. }
  37. /**
  38. * @return true for blessed scrolls
  39. */
  40. public final boolean isBlessed()
  41. {
  42. return _isBlessed;
  43. }
  44. /**
  45. * @return true for safe-enchant scrolls (enchant level will remain on failure)
  46. */
  47. public final boolean isSafe()
  48. {
  49. return _isSafe;
  50. }
  51. /**
  52. * @param enchantItem
  53. * @param supportItem
  54. * @return
  55. */
  56. public final boolean isValid(L2ItemInstance enchantItem, EnchantItem supportItem)
  57. {
  58. // blessed scrolls can't use support items
  59. if (supportItem != null && (!supportItem.isValid(enchantItem) || isBlessed()))
  60. return false;
  61. return super.isValid(enchantItem);
  62. }
  63. /**
  64. * @param enchantItem
  65. * @param supportItem
  66. * @return
  67. */
  68. public final double getChance(L2ItemInstance enchantItem, EnchantItem supportItem)
  69. {
  70. if (!isValid(enchantItem, supportItem))
  71. return -1;
  72. boolean fullBody = enchantItem.getItem().getBodyPart() == L2Item.SLOT_FULL_ARMOR;
  73. if (enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX || (fullBody && enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX_FULL))
  74. return 100;
  75. double chance = _chanceAdd;
  76. if (supportItem != null && !_isBlessed)
  77. chance *= supportItem.getChanceAdd();
  78. return chance;
  79. }
  80. }