Continuous.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 com.l2jserver.gameserver.ai.CtrlEvent;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.datatables.SkillTable;
  23. import com.l2jserver.gameserver.handler.ISkillHandler;
  24. import com.l2jserver.gameserver.instancemanager.DuelManager;
  25. import com.l2jserver.gameserver.model.L2Object;
  26. import com.l2jserver.gameserver.model.ShotType;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Summon;
  29. import com.l2jserver.gameserver.model.actor.instance.L2ClanHallManagerInstance;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.effects.L2Effect;
  32. import com.l2jserver.gameserver.model.skills.L2Skill;
  33. import com.l2jserver.gameserver.model.skills.L2SkillType;
  34. import com.l2jserver.gameserver.model.stats.Env;
  35. import com.l2jserver.gameserver.model.stats.Formulas;
  36. import com.l2jserver.gameserver.network.SystemMessageId;
  37. /**
  38. * @version $Revision: 1.1.2.2.2.9 $ $Date: 2005/04/03 15:55:04 $
  39. */
  40. public class Continuous implements ISkillHandler
  41. {
  42. private static final L2SkillType[] SKILL_IDS =
  43. {
  44. L2SkillType.BUFF,
  45. L2SkillType.DEBUFF,
  46. L2SkillType.DOT,
  47. L2SkillType.MDOT,
  48. L2SkillType.POISON,
  49. L2SkillType.BLEED,
  50. L2SkillType.FEAR,
  51. L2SkillType.CONT,
  52. L2SkillType.AGGDEBUFF,
  53. L2SkillType.FUSION
  54. };
  55. @Override
  56. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  57. {
  58. boolean acted = true;
  59. L2PcInstance player = null;
  60. if (activeChar.isPlayer())
  61. {
  62. player = activeChar.getActingPlayer();
  63. }
  64. if (skill.getEffectId() != 0)
  65. {
  66. L2Skill sk = SkillTable.getInstance().getInfo(skill.getEffectId(), skill.getEffectLvl() == 0 ? 1 : skill.getEffectLvl());
  67. if (sk != null)
  68. {
  69. skill = sk;
  70. }
  71. }
  72. boolean ss = skill.useSoulShot() && activeChar.isChargedShot(ShotType.SOULSHOTS);
  73. boolean sps = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  74. boolean bss = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  75. for (L2Character target : (L2Character[]) targets)
  76. {
  77. byte shld = 0;
  78. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  79. {
  80. target = activeChar;
  81. }
  82. // Player holding a cursed weapon can't be buffed and can't buff
  83. if ((skill.getSkillType() == L2SkillType.BUFF) && !(activeChar instanceof L2ClanHallManagerInstance))
  84. {
  85. if (target != activeChar)
  86. {
  87. if (target.isPlayer())
  88. {
  89. L2PcInstance trg = target.getActingPlayer();
  90. if (trg.isCursedWeaponEquipped())
  91. {
  92. continue;
  93. }
  94. else if (trg.getBlockCheckerArena() != -1)
  95. {
  96. continue;
  97. }
  98. }
  99. else if ((player != null) && player.isCursedWeaponEquipped())
  100. {
  101. continue;
  102. }
  103. }
  104. }
  105. if (skill.isOffensive() || skill.isDebuff())
  106. {
  107. shld = Formulas.calcShldUse(activeChar, target, skill);
  108. acted = Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss);
  109. }
  110. if (acted)
  111. {
  112. if (skill.isToggle())
  113. {
  114. L2Effect[] effects = target.getAllEffects();
  115. if (effects != null)
  116. {
  117. for (L2Effect e : effects)
  118. {
  119. if (e != null)
  120. {
  121. if (e.getSkill().getId() == skill.getId())
  122. {
  123. e.exit();
  124. return;
  125. }
  126. }
  127. }
  128. }
  129. }
  130. // if this is a debuff let the duel manager know about it
  131. // so the debuff can be removed after the duel
  132. // (player & target must be in the same duel)
  133. if (target.isPlayer() && target.getActingPlayer().isInDuel() && ((skill.getSkillType() == L2SkillType.DEBUFF) || (skill.getSkillType() == L2SkillType.BUFF)) && (player != null) && (player.getDuelId() == target.getActingPlayer().getDuelId()))
  134. {
  135. DuelManager dm = DuelManager.getInstance();
  136. for (L2Effect buff : skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss)))
  137. {
  138. if (buff != null)
  139. {
  140. dm.onBuff(target.getActingPlayer(), buff);
  141. }
  142. }
  143. }
  144. else
  145. {
  146. L2Effect[] effects = skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  147. L2Summon summon = target.getSummon();
  148. if ((summon != null) && (summon != activeChar) && summon.isServitor() && (effects.length > 0))
  149. {
  150. if (effects[0].canBeStolen() || skill.isHeroSkill() || skill.isStatic())
  151. {
  152. skill.getEffects(activeChar, target.getSummon(), new Env(shld, ss, sps, bss));
  153. }
  154. }
  155. }
  156. if (skill.getSkillType() == L2SkillType.AGGDEBUFF)
  157. {
  158. if (target.isL2Attackable())
  159. {
  160. target.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, activeChar, (int) skill.getPower());
  161. }
  162. else if (target.isPlayable())
  163. {
  164. if (target.getTarget() == activeChar)
  165. {
  166. target.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, activeChar);
  167. }
  168. else
  169. {
  170. target.setTarget(activeChar);
  171. }
  172. }
  173. }
  174. }
  175. else
  176. {
  177. activeChar.sendPacket(SystemMessageId.ATTACK_FAILED);
  178. }
  179. // Possibility of a lethal strike
  180. Formulas.calcLethalHit(activeChar, target, skill);
  181. }
  182. // self Effect :]
  183. if (skill.hasSelfEffects())
  184. {
  185. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  186. if ((effect != null) && effect.isSelfEffect())
  187. {
  188. // Replace old effect with new one.
  189. effect.exit();
  190. }
  191. skill.getEffectsSelf(activeChar);
  192. }
  193. activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  194. }
  195. @Override
  196. public L2SkillType[] getSkillIds()
  197. {
  198. return SKILL_IDS;
  199. }
  200. }