Continuous.java 6.5 KB

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