L2SkillElemental.java 5.2 KB

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