Unsummon.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2004-2014 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.effecthandlers;
  20. import com.l2jserver.gameserver.model.StatsSet;
  21. import com.l2jserver.gameserver.model.actor.L2Summon;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.conditions.Condition;
  24. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  25. import com.l2jserver.gameserver.model.effects.L2EffectType;
  26. import com.l2jserver.gameserver.model.skills.BuffInfo;
  27. import com.l2jserver.gameserver.model.stats.Formulas;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. import com.l2jserver.util.Rnd;
  30. /**
  31. * Unsummon effect implementation.
  32. * @author Adry_85
  33. */
  34. public final class Unsummon extends AbstractEffect
  35. {
  36. private final int _chance;
  37. public Unsummon(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  38. {
  39. super(attachCond, applyCond, set, params);
  40. _chance = hasParameters() ? getParameters().getInt("chance", 100) : 100;
  41. }
  42. @Override
  43. public boolean calcSuccess(BuffInfo info)
  44. {
  45. int magicLevel = info.getSkill().getMagicLevel();
  46. if ((magicLevel <= 0) || ((info.getEffected().getLevel() - 9) <= magicLevel))
  47. {
  48. double chance = _chance * Formulas.calcAttributeBonus(info.getEffector(), info.getEffected(), info.getSkill()) * Formulas.calcGeneralTraitBonus(info.getEffector(), info.getEffected(), info.getSkill().getTraitType(), false);
  49. if (chance > (Rnd.nextDouble() * 100))
  50. {
  51. return true;
  52. }
  53. }
  54. return false;
  55. }
  56. @Override
  57. public boolean canStart(BuffInfo info)
  58. {
  59. return info.getEffected().isSummon();
  60. }
  61. @Override
  62. public boolean isInstant()
  63. {
  64. return true;
  65. }
  66. @Override
  67. public void onStart(BuffInfo info)
  68. {
  69. final L2Summon summon = info.getEffected().getSummon();
  70. if (summon.isPhoenixBlessed() || summon.isNoblesseBlessed())
  71. {
  72. summon.stopEffects(L2EffectType.NOBLESSE_BLESSING);
  73. }
  74. else
  75. {
  76. summon.stopAllEffectsExceptThoseThatLastThroughDeath();
  77. }
  78. summon.abortAttack();
  79. summon.abortCast();
  80. final L2PcInstance summonOwner = info.getEffected().getActingPlayer();
  81. summon.unSummon(summonOwner);
  82. summonOwner.sendPacket(SystemMessageId.YOUR_SERVITOR_HAS_VANISHED);
  83. }
  84. }