L2SkillElemental.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.l2skills;
  16. import com.l2jserver.gameserver.model.L2Effect;
  17. import com.l2jserver.gameserver.model.L2ItemInstance;
  18. import com.l2jserver.gameserver.model.L2Object;
  19. import com.l2jserver.gameserver.model.L2Skill;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Summon;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.skills.Env;
  24. import com.l2jserver.gameserver.skills.Formulas;
  25. import com.l2jserver.gameserver.templates.StatsSet;
  26. public class L2SkillElemental extends L2Skill {
  27. private final int[] _seeds;
  28. private final boolean _seedAny;
  29. public L2SkillElemental(StatsSet set) {
  30. super(set);
  31. _seeds = new int[3];
  32. _seeds[0] = set.getInteger("seed1",0);
  33. _seeds[1] = set.getInteger("seed2",0);
  34. _seeds[2] = set.getInteger("seed3",0);
  35. if (set.getInteger("seed_any",0)==1)
  36. _seedAny = true;
  37. else
  38. _seedAny = false;
  39. }
  40. @Override
  41. public void useSkill(L2Character activeChar, L2Object[] targets) {
  42. if (activeChar.isAlikeDead())
  43. return;
  44. boolean ss = false;
  45. boolean bss = false;
  46. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  47. if (activeChar instanceof L2PcInstance)
  48. {
  49. if (weaponInst == null)
  50. {
  51. activeChar.sendMessage("You must equip your weapon before casting a spell.");
  52. return;
  53. }
  54. }
  55. if (weaponInst != null)
  56. {
  57. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  58. {
  59. bss = true;
  60. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  61. }
  62. else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  63. {
  64. ss = true;
  65. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  66. }
  67. }
  68. // If there is no weapon equipped, check for an active summon.
  69. else if (activeChar instanceof L2Summon)
  70. {
  71. L2Summon activeSummon = (L2Summon)activeChar;
  72. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  73. {
  74. bss = true;
  75. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  76. }
  77. else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  78. {
  79. ss = true;
  80. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  81. }
  82. }
  83. for (L2Character target: (L2Character[]) targets)
  84. {
  85. if (target.isAlikeDead())
  86. continue;
  87. boolean charged = true;
  88. if (!_seedAny){
  89. for (int i=0;i<_seeds.length;i++){
  90. if (_seeds[i]!=0){
  91. L2Effect e = target.getFirstEffect(_seeds[i]);
  92. if (e==null || !e.getInUse()){
  93. charged = false;
  94. break;
  95. }
  96. }
  97. }
  98. }
  99. else {
  100. charged = false;
  101. for (int i=0;i<_seeds.length;i++){
  102. if (_seeds[i]!=0){
  103. L2Effect e = target.getFirstEffect(_seeds[i]);
  104. if (e!=null && e.getInUse()){
  105. charged = true;
  106. break;
  107. }
  108. }
  109. }
  110. }
  111. if (!charged)
  112. {
  113. activeChar.sendMessage("Target is not charged by elements.");
  114. continue;
  115. }
  116. boolean mcrit = Formulas.calcMCrit(activeChar.getMCriticalHit(target, this));
  117. byte shld = Formulas.calcShldUse(activeChar, target, this);
  118. int damage = (int)Formulas.calcMagicDam(
  119. activeChar, target, this, shld, ss, bss, mcrit);
  120. if (damage > 0)
  121. {
  122. target.reduceCurrentHp(damage, activeChar, this);
  123. // Manage attack or cast break of the target (calculating rate, sending message...)
  124. if (!target.isRaid() && Formulas.calcAtkBreak(target, damage))
  125. {
  126. target.breakAttack();
  127. target.breakCast();
  128. }
  129. activeChar.sendDamageMessage(target, damage, false, false, false);
  130. }
  131. // activate attacked effects, if any
  132. target.stopSkillEffects(getId());
  133. getEffects(activeChar, target, new Env(shld, ss, false, bss));
  134. }
  135. }
  136. }