DispelBySlotProbability.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2004-2015 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 java.util.Collections;
  21. import java.util.EnumMap;
  22. import java.util.Map;
  23. import java.util.Map.Entry;
  24. import com.l2jserver.gameserver.model.CharEffectList;
  25. import com.l2jserver.gameserver.model.StatsSet;
  26. import com.l2jserver.gameserver.model.actor.L2Character;
  27. import com.l2jserver.gameserver.model.conditions.Condition;
  28. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  29. import com.l2jserver.gameserver.model.effects.L2EffectType;
  30. import com.l2jserver.gameserver.model.skills.AbnormalType;
  31. import com.l2jserver.gameserver.model.skills.BuffInfo;
  32. import com.l2jserver.util.Rnd;
  33. /**
  34. * Dispel By Slot Probability effect implementation.
  35. * @author Adry_85, Zoey76
  36. */
  37. public final class DispelBySlotProbability extends AbstractEffect
  38. {
  39. private final String _dispel;
  40. private final Map<AbnormalType, Short> _dispelAbnormals;
  41. private final int _rate;
  42. public DispelBySlotProbability(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  43. {
  44. super(attachCond, applyCond, set, params);
  45. _dispel = params.getString("dispel", null);
  46. _rate = params.getInt("rate", 0);
  47. if ((_dispel != null) && !_dispel.isEmpty())
  48. {
  49. _dispelAbnormals = new EnumMap<>(AbnormalType.class);
  50. for (String ngtStack : _dispel.split(";"))
  51. {
  52. String[] ngt = ngtStack.split(",");
  53. _dispelAbnormals.put(AbnormalType.getAbnormalType(ngt[0]), Short.MAX_VALUE);
  54. }
  55. }
  56. else
  57. {
  58. _dispelAbnormals = Collections.<AbnormalType, Short> emptyMap();
  59. }
  60. }
  61. @Override
  62. public L2EffectType getEffectType()
  63. {
  64. return L2EffectType.DISPEL;
  65. }
  66. @Override
  67. public boolean isInstant()
  68. {
  69. return true;
  70. }
  71. @Override
  72. public void onStart(BuffInfo info)
  73. {
  74. if (_dispelAbnormals.isEmpty())
  75. {
  76. return;
  77. }
  78. final L2Character effected = info.getEffected();
  79. final CharEffectList effectList = effected.getEffectList();
  80. // There is no need to iterate over all buffs,
  81. // Just iterate once over all slots to dispel and get the buff with that abnormal if exists,
  82. // Operation of O(n) for the amount of slots to dispel (which is usually small) and O(1) to get the buff.
  83. for (Entry<AbnormalType, Short> entry : _dispelAbnormals.entrySet())
  84. {
  85. if ((Rnd.get(100) < _rate))
  86. {
  87. // Dispel transformations (buff and by GM)
  88. if ((entry.getKey() == AbnormalType.TRANSFORM))
  89. {
  90. if (effected.isTransformed() || (effected.isPlayer() || (entry.getValue() == effected.getActingPlayer().getTransformationId()) || (entry.getValue() < 0)))
  91. {
  92. info.getEffected().stopTransformation(true);
  93. }
  94. }
  95. final BuffInfo toDispel = effectList.getBuffInfoByAbnormalType(entry.getKey());
  96. if (toDispel == null)
  97. {
  98. continue;
  99. }
  100. if ((toDispel.getSkill().getAbnormalType() == entry.getKey()) && (entry.getValue() >= toDispel.getSkill().getAbnormalLvl()))
  101. {
  102. effectList.stopSkillEffects(true, entry.getKey());
  103. }
  104. }
  105. }
  106. }
  107. }