Continuous.java 5.6 KB

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