EnchantScroll.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.model;
  20. import java.util.List;
  21. import java.util.Map;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.items.L2Item;
  25. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  26. /**
  27. * @author UnAfraid
  28. */
  29. public class EnchantScroll extends EnchantItem
  30. {
  31. private final boolean _isBlessed;
  32. private final boolean _isSafe;
  33. private final Map<Integer, Double> _enchantSteps;
  34. /**
  35. * @param set
  36. * @param items
  37. * @param enchantSteps
  38. */
  39. public EnchantScroll(StatsSet set, List<Integer> items, Map<Integer, Double> enchantSteps)
  40. {
  41. super(set, items);
  42. _isBlessed = set.getBool("isBlessed", false);
  43. _isSafe = set.getBool("isSafe", false);
  44. _enchantSteps = enchantSteps;
  45. }
  46. /**
  47. * @return true for blessed scrolls
  48. */
  49. public final boolean isBlessed()
  50. {
  51. return _isBlessed;
  52. }
  53. /**
  54. * @return true for safe-enchant scrolls (enchant level will remain on failure)
  55. */
  56. public final boolean isSafe()
  57. {
  58. return _isSafe;
  59. }
  60. /**
  61. * @param enchantItem
  62. * @param supportItem
  63. * @return
  64. */
  65. public final boolean isValid(L2ItemInstance enchantItem, EnchantItem supportItem)
  66. {
  67. // blessed scrolls can't use support items
  68. if ((supportItem != null) && (!supportItem.isValid(enchantItem) || isBlessed()))
  69. {
  70. return false;
  71. }
  72. return super.isValid(enchantItem);
  73. }
  74. /**
  75. * @param enchantItem
  76. * @param supportItem
  77. * @return
  78. */
  79. public final double getChance(L2ItemInstance enchantItem, EnchantItem supportItem)
  80. {
  81. if (!isValid(enchantItem, supportItem))
  82. {
  83. return -1;
  84. }
  85. boolean fullBody = enchantItem.getItem().getBodyPart() == L2Item.SLOT_FULL_ARMOR;
  86. if ((enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX) || (fullBody && (enchantItem.getEnchantLevel() < Config.ENCHANT_SAFE_MAX_FULL)))
  87. {
  88. return 100;
  89. }
  90. L2PcInstance activeChar = L2World.getInstance().getPlayer(enchantItem.getOwnerId());
  91. int level = enchantItem.getEnchantLevel() + 1;
  92. double chance = _chanceAdd;
  93. if (_enchantSteps.containsKey(level))
  94. {
  95. chance = _enchantSteps.get(level);
  96. }
  97. if (activeChar.isDebug())
  98. {
  99. activeChar.sendDebugMessage("Enchant Level: " + level + " Chance: " + chance + " " + (supportItem != null ? "Support item: " + supportItem.getChanceAdd() : ""));
  100. }
  101. if ((supportItem != null) && !_isBlessed)
  102. {
  103. chance *= supportItem.getChanceAdd();
  104. }
  105. return chance;
  106. }
  107. }