L2SkillElemental.java 4.9 KB

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