EnchantScroll.java 2.8 KB

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