FuncEnchant.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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.actor.instance.L2PcInstance;
  18. import com.l2jserver.gameserver.model.item.L2Item;
  19. import com.l2jserver.gameserver.model.item.instance.L2ItemInstance;
  20. import com.l2jserver.gameserver.model.item.type.L2WeaponType;
  21. import com.l2jserver.gameserver.skills.Env;
  22. import com.l2jserver.gameserver.skills.Stats;
  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. // M. Atk. increases by 4 for all weapons.
  72. // Starting at +4, M. Atk. bonus double.
  73. env.value += 4 * enchant + 8 * overenchant;
  74. break;
  75. case L2Item.CRYSTAL_A:
  76. case L2Item.CRYSTAL_B:
  77. case L2Item.CRYSTAL_C:
  78. // M. Atk. increases by 3 for all weapons.
  79. // Starting at +4, M. Atk. bonus double.
  80. env.value += 3 * enchant + 6 * overenchant;
  81. break;
  82. case L2Item.CRYSTAL_D:
  83. case L2Item.CRYSTAL_NONE:
  84. // M. Atk. increases by 2 for all weapons. Starting at +4, M. Atk. bonus double.
  85. // Starting at +4, M. Atk. bonus double.
  86. env.value += 2 * enchant + 4 * overenchant;
  87. break;
  88. }
  89. return;
  90. }
  91. if (item.isWeapon())
  92. {
  93. L2WeaponType type = (L2WeaponType) item.getItemType();
  94. switch (item.getItem().getItemGradeSPlus())
  95. {
  96. case L2Item.CRYSTAL_S:
  97. switch(type)
  98. {
  99. case BOW:
  100. case CROSSBOW:
  101. // P. Atk. increases by 10 for bows.
  102. // Starting at +4, P. Atk. bonus double.
  103. env.value += 10 * enchant + 20 * overenchant;
  104. break;
  105. case BIGSWORD:
  106. case BIGBLUNT:
  107. case DUAL:
  108. case DUALFIST:
  109. case ANCIENTSWORD:
  110. case DUALDAGGER:
  111. // P. Atk. increases by 6 for two-handed swords, two-handed blunts, dualswords, and two-handed combat weapons.
  112. // Starting at +4, P. Atk. bonus double.
  113. env.value += 6 * enchant + 12 * overenchant;
  114. break;
  115. default:
  116. // P. Atk. increases by 5 for one-handed swords, one-handed blunts, daggers, spears, and other weapons.
  117. // Starting at +4, P. Atk. bonus double.
  118. env.value += 5 * enchant + 10 * overenchant;
  119. break;
  120. }
  121. break;
  122. case L2Item.CRYSTAL_A:
  123. switch(type)
  124. {
  125. case BOW:
  126. case CROSSBOW:
  127. // P. Atk. increases by 8 for bows.
  128. // Starting at +4, P. Atk. bonus double.
  129. env.value += 8 * enchant + 16 * overenchant;
  130. break;
  131. case BIGSWORD:
  132. case BIGBLUNT:
  133. case DUAL:
  134. case DUALFIST:
  135. case ANCIENTSWORD:
  136. case DUALDAGGER:
  137. // P. Atk. increases by 5 for two-handed swords, two-handed blunts, dualswords, and two-handed combat weapons.
  138. // Starting at +4, P. Atk. bonus double.
  139. env.value += 5 * enchant + 10 * overenchant;
  140. break;
  141. default:
  142. // P. Atk. increases by 4 for one-handed swords, one-handed blunts, daggers, spears, and other weapons.
  143. // Starting at +4, P. Atk. bonus double.
  144. env.value += 4 * enchant + 8 * overenchant;
  145. break;
  146. }
  147. break;
  148. case L2Item.CRYSTAL_B:
  149. case L2Item.CRYSTAL_C:
  150. switch(type)
  151. {
  152. case BOW:
  153. case CROSSBOW:
  154. // P. Atk. increases by 6 for bows.
  155. // Starting at +4, P. Atk. bonus double.
  156. env.value += 6 * enchant + 12 * overenchant;
  157. break;
  158. case BIGSWORD:
  159. case BIGBLUNT:
  160. case DUAL:
  161. case DUALFIST:
  162. case ANCIENTSWORD:
  163. case DUALDAGGER:
  164. // P. Atk. increases by 4 for two-handed swords, two-handed blunts, dualswords, and two-handed combat weapons.
  165. // Starting at +4, P. Atk. bonus double.
  166. env.value += 4 * enchant + 8 * overenchant;
  167. break;
  168. default:
  169. // P. Atk. increases by 3 for one-handed swords, one-handed blunts, daggers, spears, and other weapons.
  170. // Starting at +4, P. Atk. bonus double.
  171. env.value += 3 * enchant + 6 * overenchant;
  172. break;
  173. }
  174. break;
  175. case L2Item.CRYSTAL_D:
  176. case L2Item.CRYSTAL_NONE:
  177. switch(type)
  178. {
  179. case BOW:
  180. case CROSSBOW:
  181. {
  182. // Bows increase by 4.
  183. // Starting at +4, P. Atk. bonus double.
  184. env.value += 4 * enchant + 8 * overenchant;
  185. break;
  186. }
  187. default:
  188. // P. Atk. increases by 2 for all weapons with the exception of bows.
  189. // Starting at +4, P. Atk. bonus double.
  190. env.value += 2 * enchant + 4 * overenchant;
  191. break;
  192. }
  193. break;
  194. }
  195. }
  196. }
  197. }