Continuous.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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.actor.L2Attackable;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.L2Playable;
  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.actor.instance.L2ServitorInstance;
  30. import com.l2jserver.gameserver.model.effects.L2Effect;
  31. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  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.HOT,
  51. L2SkillType.CPHOT,
  52. L2SkillType.MPHOT,
  53. L2SkillType.FEAR,
  54. L2SkillType.CONT,
  55. L2SkillType.UNDEAD_DEFENSE,
  56. L2SkillType.AGGDEBUFF,
  57. L2SkillType.FUSION
  58. };
  59. @Override
  60. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  61. {
  62. boolean acted = true;
  63. L2PcInstance player = null;
  64. if (activeChar instanceof L2PcInstance)
  65. player = (L2PcInstance) activeChar;
  66. if (skill.getEffectId() != 0)
  67. {
  68. L2Skill sk = SkillTable.getInstance().getInfo(skill.getEffectId(), skill.getEffectLvl() == 0 ? 1 : skill.getEffectLvl());
  69. if (sk != null)
  70. skill = sk;
  71. }
  72. for (L2Character target: (L2Character[]) targets)
  73. {
  74. boolean ss = false;
  75. boolean sps = false;
  76. boolean bss = false;
  77. byte shld = 0;
  78. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  79. target = activeChar;
  80. // Player holding a cursed weapon can't be buffed and can't buff
  81. if (skill.getSkillType() == L2SkillType.BUFF && !(activeChar instanceof L2ClanHallManagerInstance))
  82. {
  83. if (target != activeChar)
  84. {
  85. if (target instanceof L2PcInstance)
  86. {
  87. L2PcInstance trg = (L2PcInstance)target;
  88. if(trg.isCursedWeaponEquipped())
  89. continue;
  90. // Avoiding block checker players get buffed from outside
  91. else if(trg.getBlockCheckerArena() != -1)
  92. continue;
  93. }
  94. else if (player != null && player.isCursedWeaponEquipped())
  95. continue;
  96. }
  97. }
  98. switch (skill.getSkillType())
  99. {
  100. case HOT:
  101. case CPHOT:
  102. case MPHOT:
  103. if (activeChar.isInvul())
  104. continue;
  105. break;
  106. }
  107. if (skill.isOffensive() || skill.isDebuff())
  108. {
  109. L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
  110. if (weaponInst != null)
  111. {
  112. if (skill.isMagic())
  113. {
  114. if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  115. {
  116. bss = true;
  117. if (skill.getId() != 1020) // vitalize
  118. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  119. }
  120. else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  121. {
  122. sps = true;
  123. if (skill.getId() != 1020) // vitalize
  124. weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
  125. }
  126. }
  127. else if (weaponInst.getChargedSoulshot() == L2ItemInstance.CHARGED_SOULSHOT)
  128. {
  129. ss = true;
  130. if (skill.getId() != 1020) // vitalize
  131. weaponInst.setChargedSoulshot(L2ItemInstance.CHARGED_NONE);
  132. }
  133. }
  134. else if (activeChar instanceof L2Summon)
  135. {
  136. L2Summon activeSummon = (L2Summon) activeChar;
  137. if (skill.isMagic())
  138. {
  139. if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
  140. {
  141. bss = true;
  142. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  143. }
  144. else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
  145. {
  146. sps = true;
  147. activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
  148. }
  149. }
  150. else if (activeSummon.getChargedSoulShot() == L2ItemInstance.CHARGED_SOULSHOT)
  151. {
  152. ss = true;
  153. activeSummon.setChargedSoulShot(L2ItemInstance.CHARGED_NONE);
  154. }
  155. }
  156. else if (activeChar instanceof L2Npc)
  157. {
  158. ss = ((L2Npc) activeChar)._soulshotcharged;
  159. ((L2Npc) activeChar)._soulshotcharged = false;
  160. bss = ((L2Npc) activeChar)._spiritshotcharged;
  161. ((L2Npc) activeChar)._spiritshotcharged = false;
  162. }
  163. shld = Formulas.calcShldUse(activeChar, target, skill);
  164. acted = Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss);
  165. }
  166. if (acted)
  167. {
  168. if (skill.isToggle())
  169. {
  170. L2Effect[] effects = target.getAllEffects();
  171. if (effects != null)
  172. {
  173. for (L2Effect e : effects)
  174. {
  175. if (e != null)
  176. {
  177. if (e.getSkill().getId() == skill.getId())
  178. {
  179. e.exit();
  180. return;
  181. }
  182. }
  183. }
  184. }
  185. }
  186. // if this is a debuff let the duel manager know about it
  187. // so the debuff can be removed after the duel
  188. // (player & target must be in the same duel)
  189. if (target instanceof L2PcInstance && ((L2PcInstance) target).isInDuel() && (skill.getSkillType() == L2SkillType.DEBUFF || skill.getSkillType() == L2SkillType.BUFF) && player != null
  190. && player.getDuelId() == ((L2PcInstance) target).getDuelId())
  191. {
  192. DuelManager dm = DuelManager.getInstance();
  193. for (L2Effect buff : skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss)))
  194. if (buff != null)
  195. dm.onBuff(((L2PcInstance) target), buff);
  196. }
  197. else
  198. {
  199. L2Effect[] effects = skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  200. L2Summon summon = target.getPet();
  201. if (summon != null && summon != activeChar && summon instanceof L2ServitorInstance && effects.length > 0)
  202. {
  203. skill.getEffects(activeChar, target.getPet(), new Env(shld, ss, sps, bss));
  204. }
  205. }
  206. if (skill.getSkillType() == L2SkillType.AGGDEBUFF)
  207. {
  208. if (target instanceof L2Attackable)
  209. target.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, activeChar, (int) skill.getPower());
  210. else if (target instanceof L2Playable)
  211. {
  212. if (target.getTarget() == activeChar)
  213. target.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, activeChar);
  214. else
  215. target.setTarget(activeChar);
  216. }
  217. }
  218. }
  219. else
  220. {
  221. activeChar.sendPacket(SystemMessageId.ATTACK_FAILED);
  222. }
  223. // Possibility of a lethal strike
  224. Formulas.calcLethalHit(activeChar, target, skill);
  225. }
  226. // self Effect :]
  227. if (skill.hasSelfEffects())
  228. {
  229. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  230. if (effect != null && effect.isSelfEffect())
  231. {
  232. //Replace old effect with new one.
  233. effect.exit();
  234. }
  235. skill.getEffectsSelf(activeChar);
  236. }
  237. }
  238. @Override
  239. public L2SkillType[] getSkillIds()
  240. {
  241. return SKILL_IDS;
  242. }
  243. }