2
0

EffectCancelDebuff.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 com.l2jserver.gameserver.skills.effects;
  16. import com.l2jserver.gameserver.model.L2Effect;
  17. import com.l2jserver.gameserver.model.L2Skill;
  18. import com.l2jserver.gameserver.model.actor.L2Character;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.skills.Env;
  21. import com.l2jserver.gameserver.templates.effects.EffectTemplate;
  22. import com.l2jserver.gameserver.templates.skills.L2EffectType;
  23. import com.l2jserver.util.Rnd;
  24. /**
  25. *
  26. * @author UnAfraid
  27. *
  28. */
  29. public class EffectCancelDebuff extends L2Effect
  30. {
  31. public EffectCancelDebuff(Env env, EffectTemplate template)
  32. {
  33. super(env, template);
  34. }
  35. /**
  36. *
  37. * @see com.l2jserver.gameserver.model.L2Effect#getEffectType()
  38. */
  39. @Override
  40. public L2EffectType getEffectType()
  41. {
  42. return L2EffectType.CANCEL_DEBUFF;
  43. }
  44. /**
  45. *
  46. * @see com.l2jserver.gameserver.model.L2Effect#onStart()
  47. */
  48. @Override
  49. public boolean onStart()
  50. {
  51. return cancel(getEffector(), getEffected(), getSkill(), getEffectPower());
  52. }
  53. /**
  54. *
  55. * @see com.l2jserver.gameserver.model.L2Effect#onActionTime()
  56. */
  57. @Override
  58. public boolean onActionTime()
  59. {
  60. return false;
  61. }
  62. private static boolean cancel(L2Character caster, L2Character target, L2Skill skill, double baseRate)
  63. {
  64. if (!(target instanceof L2PcInstance)|| target.isDead())
  65. return false;
  66. final int cancelLvl = skill.getMagicLevel();
  67. int count = skill.getMaxNegatedEffects();
  68. L2Effect effect;
  69. int lastCanceledSkillId = 0;
  70. final L2Effect[] effects = target.getAllEffects();
  71. for (int i = effects.length; --i >= 0;)
  72. {
  73. effect = effects[i];
  74. if (effect == null)
  75. continue;
  76. if (!effect.getSkill().isDebuff() || !effect.getSkill().canBeDispeled())
  77. {
  78. effects[i] = null;
  79. continue;
  80. }
  81. if (effect.getSkill().getId() == lastCanceledSkillId)
  82. {
  83. effect.exit(); // this skill already canceled
  84. continue;
  85. }
  86. if (!calcCancelSuccess(effect, cancelLvl, (int)baseRate))
  87. continue;
  88. lastCanceledSkillId = effect.getSkill().getId();
  89. effect.exit();
  90. count--;
  91. if (count == 0)
  92. break;
  93. }
  94. if (count != 0)
  95. {
  96. lastCanceledSkillId = 0;
  97. for (int i = effects.length; --i >= 0;)
  98. {
  99. effect = effects[i];
  100. if (effect == null)
  101. continue;
  102. if (!effect.getSkill().isDebuff() || !effect.getSkill().canBeDispeled())
  103. {
  104. effects[i] = null;
  105. continue;
  106. }
  107. if (effect.getSkill().getId() == lastCanceledSkillId)
  108. {
  109. effect.exit(); // this skill already canceled
  110. continue;
  111. }
  112. if (!calcCancelSuccess(effect, cancelLvl, (int)baseRate))
  113. continue;
  114. lastCanceledSkillId = effect.getSkill().getId();
  115. effect.exit();
  116. count--;
  117. if (count == 0)
  118. break;
  119. }
  120. }
  121. return true;
  122. }
  123. private static boolean calcCancelSuccess(L2Effect effect, int cancelLvl, int baseRate)
  124. {
  125. int rate = 2 * (cancelLvl - effect.getSkill().getMagicLevel());
  126. rate += (effect.getAbnormalTime() - effect.getTime()) / 1200;
  127. rate += baseRate;
  128. if (rate < 25)
  129. rate = 25;
  130. else if (rate > 75)
  131. rate = 75;
  132. return Rnd.get(100) < rate;
  133. }
  134. }