EnchantScroll.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 java.util.Map;
  18. import com.l2jserver.Config;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.model.items.L2Item;
  21. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  22. /**
  23. * @author UnAfraid
  24. */
  25. public class EnchantScroll extends EnchantItem
  26. {
  27. private final boolean _isBlessed;
  28. private final boolean _isSafe;
  29. private final Map<Integer, Double> _enchantSteps;
  30. /**
  31. * @param set
  32. * @param items
  33. * @param enchantSteps
  34. */
  35. public EnchantScroll(StatsSet set, List<Integer> items, Map<Integer, Double> enchantSteps)
  36. {
  37. super(set, items);
  38. _isBlessed = set.getBool("isBlessed", false);
  39. _isSafe = set.getBool("isSafe", false);
  40. _enchantSteps = enchantSteps;
  41. }
  42. /**
  43. * @return true for blessed scrolls
  44. */
  45. public final boolean isBlessed()
  46. {
  47. return _isBlessed;
  48. }
  49. /**
  50. * @return true for safe-enchant scrolls (enchant level will remain on failure)
  51. */
  52. public final boolean isSafe()
  53. {
  54. return _isSafe;
  55. }
  56. /**
  57. * @param enchantItem
  58. * @param supportItem
  59. * @return
  60. */
  61. public final boolean isValid(L2ItemInstance enchantItem, EnchantItem supportItem)
  62. {
  63. // blessed scrolls can't use support items
  64. if ((supportItem != null) && (!supportItem.isValid(enchantItem) || isBlessed()))
  65. {
  66. return false;
  67. }
  68. return super.isValid(enchantItem);
  69. }
  70. /**
  71. * @param enchantItem
  72. * @param supportItem
  73. * @return
  74. */
  75. public final double getChance(L2ItemInstance enchantItem, EnchantItem supportItem)
  76. {
  77. if (!isValid(enchantItem, supportItem))
  78. {
  79. return -1;
  80. }
  81. boolean fullBody = enchantItem.getItem().getBodyPart() == L2Item.SLOT_FULL_ARMOR;
  82. if ((enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX) || (fullBody && (enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX_FULL)))
  83. {
  84. return 100;
  85. }
  86. L2PcInstance activeChar = L2World.getInstance().getPlayer(enchantItem.getOwnerId());
  87. int level = enchantItem.getEnchantLevel() + 1;
  88. double chance = _chanceAdd;
  89. if (_enchantSteps.containsKey(level))
  90. {
  91. chance = _enchantSteps.get(level);
  92. }
  93. if (activeChar.isDebug())
  94. {
  95. activeChar.sendDebugMessage("Enchant Level: " + level + " Chance: " + chance + " " + (supportItem != null ? "Support item: " + supportItem.getChanceAdd() : ""));
  96. }
  97. if ((supportItem != null) && !_isBlessed)
  98. {
  99. chance *= supportItem.getChanceAdd();
  100. }
  101. return chance;
  102. }
  103. }