Continuous.java 6.3 KB

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