Continuous.java 9.5 KB

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