Continuous.java 8.8 KB

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