FuncEnchant.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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.skills.funcs;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.model.L2ItemInstance;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.skills.Env;
  20. import com.l2jserver.gameserver.skills.Stats;
  21. import com.l2jserver.gameserver.templates.item.L2Item;
  22. import com.l2jserver.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().getItemGradeSPlus())
  69. {
  70. case L2Item.CRYSTAL_S:
  71. env.value += 4 * enchant + 8 * overenchant;
  72. break;
  73. case L2Item.CRYSTAL_A:
  74. env.value += 3 * enchant + 6 * overenchant;
  75. break;
  76. case L2Item.CRYSTAL_B:
  77. env.value += 3 * enchant + 6 * overenchant;
  78. break;
  79. case L2Item.CRYSTAL_C:
  80. env.value += 3 * enchant + 6 * overenchant;
  81. break;
  82. case L2Item.CRYSTAL_D:
  83. env.value += 2 * enchant + 4 * overenchant;
  84. break;
  85. }
  86. return;
  87. }
  88. if (item.isWeapon())
  89. {
  90. L2WeaponType type = (L2WeaponType) item.getItemType();
  91. switch (item.getItem().getItemGradeSPlus())
  92. {
  93. case L2Item.CRYSTAL_S:
  94. switch(type)
  95. {
  96. case BOW:
  97. case CROSSBOW:
  98. env.value += 10 * enchant + 20 * overenchant;
  99. break;
  100. default:
  101. env.value += 5 * enchant + 10 * overenchant;
  102. break;
  103. }
  104. break;
  105. case L2Item.CRYSTAL_A:
  106. switch(type)
  107. {
  108. case BOW:
  109. case CROSSBOW:
  110. env.value += 8 * enchant + 16 * overenchant;
  111. break;
  112. default:
  113. env.value += 4 * enchant + 8 * overenchant;
  114. break;
  115. }
  116. break;
  117. case L2Item.CRYSTAL_B:
  118. switch(type)
  119. {
  120. case BOW:
  121. case CROSSBOW:
  122. env.value += 6 * enchant + 12 * overenchant;
  123. break;
  124. default:
  125. env.value += 3 * enchant + 6 * overenchant;
  126. break;
  127. }
  128. break;
  129. case L2Item.CRYSTAL_C:
  130. switch(type)
  131. {
  132. case BOW:
  133. case CROSSBOW:
  134. env.value += 6 * enchant + 12 * overenchant;
  135. break;
  136. default:
  137. env.value += 3 * enchant + 6 * overenchant;
  138. break;
  139. }
  140. break;
  141. case L2Item.CRYSTAL_D:
  142. case L2Item.CRYSTAL_NONE:
  143. switch(type)
  144. {
  145. case BOW:
  146. case CROSSBOW:
  147. {
  148. env.value += 4 * enchant + 8 * overenchant;
  149. break;
  150. }
  151. default:
  152. env.value += 2 * enchant + 4 * overenchant;
  153. break;
  154. }
  155. break;
  156. }
  157. }
  158. }
  159. }