* Fixed a bug that could cause endless loop of applying replacement/prevention effects (e.g. prevent effect of Hedron-Field Purists) locking the UI.

This commit is contained in:
LevelX2 2015-03-07 16:42:11 +01:00
parent a1208f1a73
commit b4894f5564
3 changed files with 12 additions and 4 deletions

View file

@ -52,6 +52,7 @@ import mage.cards.CardsImpl;
import mage.constants.AsThoughEffectType;
import mage.constants.CostModificationType;
import mage.constants.Duration;
import mage.constants.EffectType;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SpellAbilityType;
@ -717,7 +718,12 @@ public class ContinuousEffects implements Serializable {
boolean onlyOne = false;
if (rEffects.size() == 1) {
ReplacementEffect effect = rEffects.keySet().iterator().next();
HashSet<Ability> abilities = replacementEffects.getAbility(effect.getId());
HashSet<Ability> abilities;
if (effect.getEffectType().equals(EffectType.REPLACEMENT)) {
abilities = replacementEffects.getAbility(effect.getId());
} else {
abilities = preventionEffects.getAbility(effect.getId());
}
if (abilities == null || abilities.size() == 1) {
onlyOne = true;
}
@ -788,6 +794,7 @@ public class ContinuousEffects implements Serializable {
}
}
// Must be called here for some effects to be able to work correctly
// TODO: add info which effects that need
game.applyEffects();
} while (true);
return caught;

View file

@ -119,7 +119,7 @@ public class GainAbilitySourceEffect extends ContinuousEffectImpl implements Sou
permanent = game.getPermanent(source.getSourceId());
}
if (permanent != null) {
permanent.addAbility(ability, source.getSourceId(), game);
permanent.addAbility(ability, source.getSourceId(), game, false);
return true;
}
}

View file

@ -424,10 +424,11 @@ public class GameState implements Serializable, Copyable<GameState> {
}
public void addEffect(ContinuousEffect effect, UUID sourceId, Ability source) {
if (sourceId == null)
if (sourceId == null) {
effects.addEffect(effect, source);
else
} else {
effects.addEffect(effect, sourceId, source);
}
}
// public void addMessage(String message) {