FuncEnchant.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 net.sf.l2j.gameserver.skills.funcs;
  16. import net.sf.l2j.Config;
  17. import net.sf.l2j.gameserver.model.L2ItemInstance;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  19. import net.sf.l2j.gameserver.skills.Env;
  20. import net.sf.l2j.gameserver.skills.Stats;
  21. import net.sf.l2j.gameserver.templates.item.L2Item;
  22. import net.sf.l2j.gameserver.templates.item.L2WeaponType;
  23. public class FuncEnchant extends Func
  24. {
  25. public FuncEnchant(Stats pStat, int pOrder, Object owner, Lambda lambda)
  26. {
  27. super(pStat, pOrder, owner);
  28. }
  29. @Override
  30. public void calc(Env env)
  31. {
  32. if (cond != null && !cond.test(env))
  33. return;
  34. L2ItemInstance item = (L2ItemInstance) funcOwner;
  35. int enchant = item.getEnchantLevel();
  36. if (enchant <= 0)
  37. return;
  38. int overenchant = 0;
  39. if (enchant > 3)
  40. {
  41. overenchant = enchant - 3;
  42. enchant = 3;
  43. }
  44. if (env.player != null && env.player instanceof L2PcInstance)
  45. {
  46. L2PcInstance player = (L2PcInstance)env.player;
  47. if (player.isInOlympiadMode() && Config.ALT_OLY_ENCHANT_LIMIT >= 0 &&
  48. (enchant + overenchant) > Config.ALT_OLY_ENCHANT_LIMIT)
  49. {
  50. if (Config.ALT_OLY_ENCHANT_LIMIT > 3)
  51. {
  52. overenchant = Config.ALT_OLY_ENCHANT_LIMIT - 3;
  53. }
  54. else
  55. {
  56. overenchant = 0;
  57. enchant = Config.ALT_OLY_ENCHANT_LIMIT;
  58. }
  59. }
  60. }
  61. if (stat == Stats.MAGIC_DEFENCE || stat == Stats.POWER_DEFENCE)
  62. {
  63. env.value += enchant + 3 * overenchant;
  64. return;
  65. }
  66. if (stat == Stats.MAGIC_ATTACK)
  67. {
  68. switch (item.getItem().getCrystalType())
  69. {
  70. case L2Item.CRYSTAL_S:
  71. case L2Item.CRYSTAL_S80:
  72. env.value += 4 * enchant + 8 * overenchant;
  73. break;
  74. case L2Item.CRYSTAL_A:
  75. env.value += 3 * enchant + 6 * overenchant;
  76. break;
  77. case L2Item.CRYSTAL_B:
  78. env.value += 3 * enchant + 6 * overenchant;
  79. break;
  80. case L2Item.CRYSTAL_C:
  81. env.value += 3 * enchant + 6 * overenchant;
  82. break;
  83. case L2Item.CRYSTAL_D:
  84. env.value += 2 * enchant + 4 * overenchant;
  85. break;
  86. }
  87. return;
  88. }
  89. if (item.isWeapon())
  90. {
  91. L2WeaponType type = (L2WeaponType) item.getItemType();
  92. switch (item.getItem().getCrystalType())
  93. {
  94. case L2Item.CRYSTAL_S:
  95. case L2Item.CRYSTAL_S80:
  96. switch(type)
  97. {
  98. case BOW:
  99. case CROSSBOW:
  100. env.value += 10 * enchant + 20 * overenchant;
  101. break;
  102. default:
  103. env.value += 5 * enchant + 10 * overenchant;
  104. break;
  105. }
  106. break;
  107. case L2Item.CRYSTAL_A:
  108. switch(type)
  109. {
  110. case BOW:
  111. case CROSSBOW:
  112. env.value += 8 * enchant + 16 * overenchant;
  113. break;
  114. default:
  115. env.value += 4 * enchant + 8 * overenchant;
  116. break;
  117. }
  118. break;
  119. case L2Item.CRYSTAL_B:
  120. switch(type)
  121. {
  122. case BOW:
  123. case CROSSBOW:
  124. env.value += 6 * enchant + 12 * overenchant;
  125. break;
  126. default:
  127. env.value += 3 * enchant + 6 * overenchant;
  128. break;
  129. }
  130. break;
  131. case L2Item.CRYSTAL_C:
  132. switch(type)
  133. {
  134. case BOW:
  135. case CROSSBOW:
  136. env.value += 6 * enchant + 12 * overenchant;
  137. break;
  138. default:
  139. env.value += 3 * enchant + 6 * overenchant;
  140. break;
  141. }
  142. break;
  143. case L2Item.CRYSTAL_D:
  144. case L2Item.CRYSTAL_NONE:
  145. switch(type)
  146. {
  147. case BOW:
  148. case CROSSBOW:
  149. {
  150. env.value += 4 * enchant + 8 * overenchant;
  151. break;
  152. }
  153. default:
  154. env.value += 2 * enchant + 4 * overenchant;
  155. break;
  156. }
  157. break;
  158. }
  159. }
  160. return;
  161. }
  162. }