Continuous.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.skillhandlers;
  20. import java.util.List;
  21. import com.l2jserver.gameserver.enums.ShotType;
  22. import com.l2jserver.gameserver.handler.ISkillHandler;
  23. import com.l2jserver.gameserver.instancemanager.DuelManager;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.actor.L2Summon;
  27. import com.l2jserver.gameserver.model.actor.instance.L2ClanHallManagerInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.effects.L2Effect;
  30. import com.l2jserver.gameserver.model.skills.L2Skill;
  31. import com.l2jserver.gameserver.model.skills.L2SkillType;
  32. import com.l2jserver.gameserver.model.stats.Env;
  33. import com.l2jserver.gameserver.model.stats.Formulas;
  34. import com.l2jserver.gameserver.network.SystemMessageId;
  35. public class Continuous implements ISkillHandler
  36. {
  37. private static final L2SkillType[] SKILL_IDS =
  38. {
  39. L2SkillType.BUFF,
  40. L2SkillType.DEBUFF,
  41. };
  42. @Override
  43. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  44. {
  45. boolean acted = true;
  46. L2PcInstance player = null;
  47. if (activeChar.isPlayer())
  48. {
  49. player = activeChar.getActingPlayer();
  50. }
  51. boolean ss = skill.useSoulShot() && activeChar.isChargedShot(ShotType.SOULSHOTS);
  52. boolean sps = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  53. boolean bss = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  54. for (L2Character target : (L2Character[]) targets)
  55. {
  56. byte shld = 0;
  57. if (Formulas.calcBuffDebuffReflection(target, skill))
  58. {
  59. target = activeChar;
  60. }
  61. // Player holding a cursed weapon can't be buffed and can't buff
  62. if ((skill.getSkillType() == L2SkillType.BUFF) && !(activeChar instanceof L2ClanHallManagerInstance))
  63. {
  64. if (target != activeChar)
  65. {
  66. if (target.isPlayer())
  67. {
  68. L2PcInstance trg = target.getActingPlayer();
  69. if (trg.isCursedWeaponEquipped())
  70. {
  71. continue;
  72. }
  73. else if (trg.getBlockCheckerArena() != -1)
  74. {
  75. continue;
  76. }
  77. }
  78. else if ((player != null) && player.isCursedWeaponEquipped())
  79. {
  80. continue;
  81. }
  82. }
  83. }
  84. if (skill.isBad())
  85. {
  86. shld = Formulas.calcShldUse(activeChar, target, skill);
  87. acted = Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss);
  88. }
  89. if (acted)
  90. {
  91. if (skill.isToggle())
  92. {
  93. List<L2Effect> effects = target.getAllEffects();
  94. if (effects != null)
  95. {
  96. for (L2Effect e : effects)
  97. {
  98. if (e != null)
  99. {
  100. if (e.getSkill().getId() == skill.getId())
  101. {
  102. e.exit();
  103. return;
  104. }
  105. }
  106. }
  107. }
  108. }
  109. // if this is a debuff let the duel manager know about it
  110. // so the debuff can be removed after the duel
  111. // (player & target must be in the same duel)
  112. if (target.isPlayer() && target.getActingPlayer().isInDuel() && (player != null) && (player.getDuelId() == target.getActingPlayer().getDuelId()))
  113. {
  114. DuelManager dm = DuelManager.getInstance();
  115. for (L2Effect buff : skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss)))
  116. {
  117. if (buff != null)
  118. {
  119. dm.onBuff(target.getActingPlayer(), buff);
  120. }
  121. }
  122. }
  123. else
  124. {
  125. List<L2Effect> effects = skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  126. L2Summon summon = target.getSummon();
  127. if ((summon != null) && (summon != activeChar) && summon.isServitor() && !effects.isEmpty())
  128. {
  129. if (effects.get(0).canBeStolen() || skill.isHeroSkill() || skill.isStatic())
  130. {
  131. skill.getEffects(activeChar, target.getSummon(), new Env(shld, ss, sps, bss));
  132. }
  133. }
  134. }
  135. }
  136. else
  137. {
  138. activeChar.sendPacket(SystemMessageId.ATTACK_FAILED);
  139. }
  140. }
  141. // self Effect :]
  142. if (skill.hasSelfEffects())
  143. {
  144. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  145. if ((effect != null) && effect.isSelfEffect())
  146. {
  147. // Replace old effect with new one.
  148. effect.exit();
  149. }
  150. skill.getEffectsSelf(activeChar);
  151. }
  152. activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  153. }
  154. @Override
  155. public L2SkillType[] getSkillIds()
  156. {
  157. return SKILL_IDS;
  158. }
  159. }