DispelBySlotProbability.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.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.effects.EffectTemplate;
  25. import com.l2jserver.gameserver.model.effects.L2Effect;
  26. import com.l2jserver.gameserver.model.effects.L2EffectType;
  27. import com.l2jserver.gameserver.model.skills.AbnormalType;
  28. import com.l2jserver.gameserver.model.stats.Env;
  29. import com.l2jserver.util.Rnd;
  30. /**
  31. * Dispel By Slot Probability effect implementation.
  32. * @author Adry_85
  33. */
  34. public class DispelBySlotProbability extends L2Effect
  35. {
  36. private final String _dispel;
  37. private final Map<AbnormalType, Byte> _dispelAbnormals;
  38. private final int _rate;
  39. public DispelBySlotProbability(Env env, EffectTemplate template)
  40. {
  41. super(env, template);
  42. _dispel = template.getParameters().getString("dispel", null);
  43. _rate = template.getParameters().getInt("rate", 0);
  44. if ((_dispel != null) && !_dispel.isEmpty())
  45. {
  46. _dispelAbnormals = new EnumMap<>(AbnormalType.class);
  47. for (String ngtStack : _dispel.split(";"))
  48. {
  49. String[] ngt = ngtStack.split(",");
  50. final AbnormalType type = AbnormalType.getAbnormalType(ngt[0]);
  51. _dispelAbnormals.put(type, Byte.MAX_VALUE);
  52. }
  53. }
  54. else
  55. {
  56. _dispelAbnormals = Collections.<AbnormalType, Byte> emptyMap();
  57. }
  58. }
  59. @Override
  60. public L2EffectType getEffectType()
  61. {
  62. return L2EffectType.DISPEL;
  63. }
  64. @Override
  65. public boolean isInstant()
  66. {
  67. return true;
  68. }
  69. @Override
  70. public boolean onStart()
  71. {
  72. if (_dispelAbnormals.isEmpty())
  73. {
  74. return false;
  75. }
  76. for (L2Effect effect : getEffected().getAllEffects())
  77. {
  78. if (effect == null)
  79. {
  80. continue;
  81. }
  82. for (Entry<AbnormalType, Byte> negate : _dispelAbnormals.entrySet())
  83. {
  84. if ((effect.getSkill().getAbnormalType() == negate.getKey()) && (Rnd.get(100) < _rate))
  85. {
  86. effect.exit();
  87. }
  88. }
  89. }
  90. return true;
  91. }
  92. }