DispelBySlot.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /**
  33. * Dispel By Slot effect implementation.
  34. * @author Gnacik, Zoey76, Adry_85
  35. */
  36. public final class DispelBySlot extends AbstractEffect
  37. {
  38. private final String _dispel;
  39. private final Map<AbnormalType, Short> _dispelAbnormals;
  40. public DispelBySlot(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
  41. {
  42. super(attachCond, applyCond, set, params);
  43. _dispel = params.getString("dispel", null);
  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. _dispelAbnormals.put(AbnormalType.getAbnormalType(ngt[0]), Short.parseShort(ngt[1]));
  51. }
  52. }
  53. else
  54. {
  55. _dispelAbnormals = Collections.<AbnormalType, Short> emptyMap();
  56. }
  57. }
  58. @Override
  59. public L2EffectType getEffectType()
  60. {
  61. return L2EffectType.DISPEL_BY_SLOT;
  62. }
  63. @Override
  64. public boolean isInstant()
  65. {
  66. return true;
  67. }
  68. @Override
  69. public void onStart(BuffInfo info)
  70. {
  71. if (_dispelAbnormals.isEmpty())
  72. {
  73. return;
  74. }
  75. final L2Character effected = info.getEffected();
  76. final CharEffectList effectList = effected.getEffectList();
  77. // There is no need to iterate over all buffs,
  78. // Just iterate once over all slots to dispel and get the buff with that abnormal if exists,
  79. // Operation of O(n) for the amount of slots to dispel (which is usually small) and O(1) to get the buff.
  80. for (Entry<AbnormalType, Short> entry : _dispelAbnormals.entrySet())
  81. {
  82. // Dispel transformations (buff and by GM)
  83. if ((entry.getKey() == AbnormalType.TRANSFORM))
  84. {
  85. if (effected.isTransformed() || (effected.isPlayer() || (entry.getValue() == effected.getActingPlayer().getTransformationId()) || (entry.getValue() < 0)))
  86. {
  87. info.getEffected().stopTransformation(true);
  88. continue;
  89. }
  90. }
  91. final BuffInfo toDispel = effectList.getBuffInfoByAbnormalType(entry.getKey());
  92. if (toDispel == null)
  93. {
  94. continue;
  95. }
  96. if ((entry.getKey() == toDispel.getSkill().getAbnormalType()) && ((entry.getValue() < 0) || (entry.getValue() >= toDispel.getSkill().getAbnormalLvl())))
  97. {
  98. effectList.stopSkillEffects(true, entry.getKey());
  99. }
  100. }
  101. }
  102. }