Disablers.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 com.l2jserver.gameserver.ai.CtrlEvent;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.ai.L2AttackableAI;
  23. import com.l2jserver.gameserver.handler.ISkillHandler;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.ShotType;
  26. import com.l2jserver.gameserver.model.actor.L2Attackable;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.effects.L2Effect;
  29. import com.l2jserver.gameserver.model.skills.L2Skill;
  30. import com.l2jserver.gameserver.model.skills.L2SkillType;
  31. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  32. import com.l2jserver.gameserver.model.stats.Env;
  33. import com.l2jserver.gameserver.model.stats.Formulas;
  34. import com.l2jserver.gameserver.model.stats.Stats;
  35. import com.l2jserver.gameserver.network.SystemMessageId;
  36. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  37. /**
  38. * This Handles Disabler skills
  39. * @author _drunk_
  40. */
  41. public class Disablers implements ISkillHandler
  42. {
  43. private static final L2SkillType[] SKILL_IDS =
  44. {
  45. L2SkillType.AGGDAMAGE,
  46. L2SkillType.AGGREDUCE,
  47. L2SkillType.AGGREDUCE_CHAR,
  48. L2SkillType.AGGREMOVE,
  49. L2SkillType.CONFUSE_MOB_ONLY,
  50. };
  51. @Override
  52. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  53. {
  54. L2SkillType type = skill.getSkillType();
  55. byte shld = 0;
  56. boolean ss = skill.useSoulShot() && activeChar.isChargedShot(ShotType.SOULSHOTS);
  57. boolean sps = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.SPIRITSHOTS);
  58. boolean bss = skill.useSpiritShot() && activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS);
  59. for (L2Object obj : targets)
  60. {
  61. if (!(obj instanceof L2Character))
  62. {
  63. continue;
  64. }
  65. L2Character target = (L2Character) obj;
  66. if (target.isDead() || (target.isInvul() && !target.isParalyzed()))
  67. {
  68. continue;
  69. }
  70. shld = Formulas.calcShldUse(activeChar, target, skill);
  71. switch (type)
  72. {
  73. case CONFUSE_MOB_ONLY:
  74. {
  75. // do nothing if not on mob
  76. if (target.isL2Attackable())
  77. {
  78. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  79. {
  80. for (L2Effect e : target.getAllEffects())
  81. {
  82. if (e.getSkill().getSkillType() == type)
  83. {
  84. e.exit();
  85. }
  86. }
  87. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  88. }
  89. else
  90. {
  91. if (activeChar.isPlayer())
  92. {
  93. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  94. sm.addCharName(target);
  95. sm.addSkillName(skill);
  96. activeChar.sendPacket(sm);
  97. }
  98. }
  99. }
  100. else
  101. {
  102. activeChar.sendPacket(SystemMessageId.TARGET_IS_INCORRECT);
  103. }
  104. break;
  105. }
  106. case AGGDAMAGE:
  107. {
  108. if (target.isL2Attackable())
  109. {
  110. target.getAI().notifyEvent(CtrlEvent.EVT_AGGRESSION, activeChar, (int) ((150 * skill.getPower()) / (target.getLevel() + 7)));
  111. }
  112. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  113. break;
  114. }
  115. case AGGREDUCE:
  116. {
  117. // these skills needs to be rechecked
  118. if (target.isL2Attackable())
  119. {
  120. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  121. double aggdiff = ((L2Attackable) target).getHating(activeChar) - target.calcStat(Stats.AGGRESSION, ((L2Attackable) target).getHating(activeChar), target, skill);
  122. if (skill.getPower() > 0)
  123. {
  124. ((L2Attackable) target).reduceHate(null, (int) skill.getPower());
  125. }
  126. else if (aggdiff > 0)
  127. {
  128. ((L2Attackable) target).reduceHate(null, (int) aggdiff);
  129. }
  130. }
  131. // when fail, target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  132. break;
  133. }
  134. case AGGREDUCE_CHAR:
  135. {
  136. // these skills needs to be rechecked
  137. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  138. {
  139. if (target.isL2Attackable())
  140. {
  141. L2Attackable targ = (L2Attackable) target;
  142. targ.stopHating(activeChar);
  143. if ((targ.getMostHated() == null) && targ.hasAI() && (targ.getAI() instanceof L2AttackableAI))
  144. {
  145. ((L2AttackableAI) targ.getAI()).setGlobalAggro(-25);
  146. targ.clearAggroList();
  147. targ.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  148. targ.setWalking();
  149. }
  150. }
  151. skill.getEffects(activeChar, target, new Env(shld, ss, sps, bss));
  152. }
  153. else
  154. {
  155. if (activeChar.isPlayer())
  156. {
  157. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  158. sm.addCharName(target);
  159. sm.addSkillName(skill);
  160. activeChar.sendPacket(sm);
  161. }
  162. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  163. }
  164. break;
  165. }
  166. case AGGREMOVE:
  167. {
  168. // these skills needs to be rechecked
  169. if (target.isL2Attackable() && !target.isRaid())
  170. {
  171. if (Formulas.calcSkillSuccess(activeChar, target, skill, shld, ss, sps, bss))
  172. {
  173. if (skill.getTargetType() == L2TargetType.UNDEAD)
  174. {
  175. if (target.isUndead())
  176. {
  177. ((L2Attackable) target).reduceHate(null, ((L2Attackable) target).getHating(((L2Attackable) target).getMostHated()));
  178. }
  179. }
  180. else
  181. {
  182. ((L2Attackable) target).reduceHate(null, ((L2Attackable) target).getHating(((L2Attackable) target).getMostHated()));
  183. }
  184. }
  185. else
  186. {
  187. if (activeChar.isPlayer())
  188. {
  189. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_RESISTED_YOUR_S2);
  190. sm.addCharName(target);
  191. sm.addSkillName(skill);
  192. activeChar.sendPacket(sm);
  193. }
  194. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  195. }
  196. }
  197. else
  198. {
  199. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  200. }
  201. break;
  202. }
  203. }
  204. }
  205. // self Effect :]
  206. if (skill.hasSelfEffects())
  207. {
  208. final L2Effect effect = activeChar.getFirstEffect(skill.getId());
  209. if ((effect != null) && effect.isSelfEffect())
  210. {
  211. // Replace old effect with new one.
  212. effect.exit();
  213. }
  214. skill.getEffectsSelf(activeChar);
  215. }
  216. activeChar.setChargedShot(bss ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  217. }
  218. @Override
  219. public L2SkillType[] getSkillIds()
  220. {
  221. return SKILL_IDS;
  222. }
  223. }