DispelBySlot.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /**
  30. * Dispel By Slot effect implementation.
  31. * @author Gnacik, Zoey76, Adry_85
  32. */
  33. public class DispelBySlot extends L2Effect
  34. {
  35. private final String _dispel;
  36. private final Map<AbnormalType, Byte> _dispelAbnormals;
  37. public DispelBySlot(Env env, EffectTemplate template)
  38. {
  39. super(env, template);
  40. _dispel = template.getParameters().getString("dispel", null);
  41. if ((_dispel != null) && !_dispel.isEmpty())
  42. {
  43. _dispelAbnormals = new EnumMap<>(AbnormalType.class);
  44. for (String ngtStack : _dispel.split(";"))
  45. {
  46. String[] ngt = ngtStack.split(",");
  47. final AbnormalType type = AbnormalType.getAbnormalType(ngt[0]);
  48. _dispelAbnormals.put(type, Byte.parseByte(ngt[1]));
  49. }
  50. }
  51. else
  52. {
  53. _dispelAbnormals = Collections.<AbnormalType, Byte> emptyMap();
  54. }
  55. }
  56. @Override
  57. public L2EffectType getEffectType()
  58. {
  59. return L2EffectType.DISPEL;
  60. }
  61. @Override
  62. public boolean isInstant()
  63. {
  64. return true;
  65. }
  66. @Override
  67. public boolean onStart()
  68. {
  69. if (_dispelAbnormals.isEmpty())
  70. {
  71. return false;
  72. }
  73. for (L2Effect effect : getEffected().getAllEffects())
  74. {
  75. if (effect == null)
  76. {
  77. continue;
  78. }
  79. for (Entry<AbnormalType, Byte> dispel : _dispelAbnormals.entrySet())
  80. {
  81. if ((effect.getSkill().getAbnormalType() == AbnormalType.TRANSFORM) && ((dispel.getValue() == getEffected().getActingPlayer().getTransformationId()) || (dispel.getValue() < 0)))
  82. {
  83. getEffected().stopTransformation(true);
  84. continue;
  85. }
  86. else if ((effect.getSkill().getAbnormalType() == dispel.getKey()) && (dispel.getValue() >= effect.getSkill().getAbnormalLvl()))
  87. {
  88. effect.exit();
  89. }
  90. }
  91. }
  92. // Stop transformed by GM.
  93. for (Entry<AbnormalType, Byte> dispel : _dispelAbnormals.entrySet())
  94. {
  95. if ((dispel.getKey() == AbnormalType.TRANSFORM) && getEffected().isTransformed())
  96. {
  97. getEffected().stopTransformation(false);
  98. }
  99. }
  100. return true;
  101. }
  102. }