FuncEnchant.java 6.3 KB

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