Fixed a bug in handling ContinuousEffects introduced with 463cec8754.

This commit is contained in:
LevelX2 2014-01-09 15:15:05 +01:00
parent c0323c168c
commit e3d543fa76
2 changed files with 18 additions and 13 deletions

View file

@ -63,14 +63,20 @@ public class MasterOfThePearlTridentTest extends CardTestPlayerBase {
public void testTurnToFrog() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 2);
addCard(Zone.HAND, playerA, "Master of the Pearl Trident");
// Creature Merfolk 2/2, UU
// Other Merfolk creatures you control get +1/+1 and have islandwalk. (They can't be blocked as long as defending player controls an Island.)
addCard(Zone.BATTLEFIELD, playerA, "Merfolk of the Pearl Trident");
addCard(Zone.BATTLEFIELD, playerB, "Island", 2);
addCard(Zone.BATTLEFIELD, playerB, "Llanowar Elves");
// Creature Elf Druid 1/1, G
// {T}: Add {G} to your mana pool.
addCard(Zone.HAND, playerB, "Turn to Frog");
// Target creature loses all abilities and becomes a 1/1 blue Frog until end of turn.
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Master of the Pearl Trident");
castSpell(3, PhaseStep.DECLARE_ATTACKERS, playerB, "Turn to Frog", "Master of the Pearl Trident");
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerB, "Turn to Frog", "Master of the Pearl Trident");
attack(3, playerA, "Merfolk of the Pearl Trident");
block(3, playerB, "Llanowar Elves", "Merfolk of the Pearl Trident");

View file

@ -727,34 +727,31 @@ public class ContinuousEffects implements Serializable {
effect.apply(Layer.ColorChangingEffects_5, SubLayer.NA, ability, game);
}
}
Map<ContinuousEffect, List<Ability>> appliedEffects = new HashMap<ContinuousEffect, List<Ability>>();
boolean allApplied = false;
while (!allApplied) { // loop needed if a added effect adds again an effect (e.g. Level 5- of Joraga Treespeaker)
boolean effectApplied = false;
boolean done = false;
while (!done) { // loop needed if a added effect adds again an effect (e.g. Level 5- of Joraga Treespeaker)
done = true;
layer = filterLayeredEffects(layerEffects, Layer.AbilityAddingRemovingEffects_6);
for (ContinuousEffect effect: layer) {
if (layerEffects.contains(effect)) {
List<Ability> appliedAbilities = appliedEffects.get(effect);
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {
for (Ability ability : abilities) {
if (appliedAbilities == null || !appliedAbilities.contains(ability)) {
if (appliedAbilities == null) {
appliedAbilities = new ArrayList<Ability>();
appliedEffects.put(effect, appliedAbilities);
}
appliedAbilities.add(ability);
appliedAbilities.add(ability);
effect.apply(Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, ability, game);
effectApplied = true;
done = false;
// list must be updated after each applied effect (eg. if "Turn to Frog" removes abilities)
layerEffects = getLayeredEffects(game);
}
}
}
}
// if effect were applied, new effects of this layer could be added, so all yet not applied effects of this layer must still be applied
allApplied = !effectApplied;
if (effectApplied) {
layerEffects = getLayeredEffects(game);
}
}
layer = filterLayeredEffects(layerEffects, Layer.PTChangingEffects_7);
@ -770,7 +767,9 @@ public class ContinuousEffects implements Serializable {
effect.apply(Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, ability, game);
}
}
applyCounters.apply(Layer.PTChangingEffects_7, SubLayer.Counters_7d, null, game);
for (ContinuousEffect effect: layer) {
HashSet<Ability> abilities = layeredEffects.getAbility(effect.getId());
for (Ability ability : abilities) {