mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
* Militant Angel - fixed rollback error on usage (#7239);
This commit is contained in:
parent
3cccad2138
commit
1b830032ac
2 changed files with 87 additions and 6 deletions
|
@ -0,0 +1,73 @@
|
||||||
|
package org.mage.test.cards.single.gnt;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
|
import mage.abilities.dynamicvalue.common.AttackedThisTurnOpponentsCount;
|
||||||
|
import mage.abilities.effects.Effect;
|
||||||
|
import mage.constants.PhaseStep;
|
||||||
|
import mage.constants.Zone;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.players.Player;
|
||||||
|
import mage.watchers.common.PlayersAttackedThisTurnWatcher;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mage.test.serverside.base.CardTestCommander4Players;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author JayDi85
|
||||||
|
*/
|
||||||
|
public class MilitantAngelTest extends CardTestCommander4Players {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_AttackedThisTurnOpponentsCount() {
|
||||||
|
// Player order: A -> D -> C -> B
|
||||||
|
|
||||||
|
// it's testing counter only (no need to test card -- it's same)
|
||||||
|
// When Militant Angel enters the battlefield, create a number of 2/2 white Knight creature tokens
|
||||||
|
// with vigilance equal to the number of opponents you attacked this turn.
|
||||||
|
//addCard(Zone.BATTLEFIELD, playerA, "Militant Angel", 2);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Balduvian Bears", 1);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Kitesail Corsair", 1);
|
||||||
|
|
||||||
|
// turn 1: 2x attack -> 1 player = 1 value
|
||||||
|
mustHaveValue("2x->1 = 1", 1, PhaseStep.PRECOMBAT_MAIN, 0);
|
||||||
|
attack(1, playerA, "Balduvian Bears", playerB);
|
||||||
|
attack(1, playerA, "Kitesail Corsair", playerB);
|
||||||
|
mustHaveValue("2x->1 = 1", 1, PhaseStep.POSTCOMBAT_MAIN, 1);
|
||||||
|
|
||||||
|
// between attacks - no value
|
||||||
|
mustHaveValue("no attacks = 0", 2, PhaseStep.PRECOMBAT_MAIN, 0);
|
||||||
|
|
||||||
|
// turn 5: 2x attack -> 2 players = 2 value
|
||||||
|
mustHaveValue("2x->2 = 2", 5, PhaseStep.PRECOMBAT_MAIN, 0);
|
||||||
|
attack(5, playerA, "Balduvian Bears", playerB);
|
||||||
|
attack(5, playerA, "Kitesail Corsair", playerC);
|
||||||
|
mustHaveValue("2x->2 = 2", 5, PhaseStep.POSTCOMBAT_MAIN, 2);
|
||||||
|
runCode("watcher must be copyable", 5, PhaseStep.POSTCOMBAT_MAIN, playerA, (info, player, game) -> {
|
||||||
|
PlayersAttackedThisTurnWatcher watcher = game.getState().getWatcher(PlayersAttackedThisTurnWatcher.class);
|
||||||
|
PlayersAttackedThisTurnWatcher newWatcher = watcher.copy();
|
||||||
|
Assert.assertEquals("old watcher", 2, watcher.getAttackedOpponentsCount(player.getId()));
|
||||||
|
Assert.assertEquals("new watcher", 2, newWatcher.getAttackedOpponentsCount(player.getId()));
|
||||||
|
});
|
||||||
|
|
||||||
|
// between attacks - no value
|
||||||
|
mustHaveValue("no attacks = 0", 6, PhaseStep.PRECOMBAT_MAIN, 0);
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
setStopAt(6, PhaseStep.END_TURN);
|
||||||
|
execute();
|
||||||
|
assertAllCommandsUsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mustHaveValue(String needInfo, int turnNum, PhaseStep step, int needValue) {
|
||||||
|
runCode(needInfo, turnNum, step, playerA, (info, player, game) -> {
|
||||||
|
assertCounterValue(info, player, game, needValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertCounterValue(String checkName, Player player, Game game, int needValue) {
|
||||||
|
Ability fakeAbility = new SimpleStaticAbility((Effect) null); // dynamic value need ability's controllerId
|
||||||
|
fakeAbility.setControllerId(player.getId());
|
||||||
|
Assert.assertEquals(checkName, needValue, AttackedThisTurnOpponentsCount.instance.calculate(game, fakeAbility, null));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,12 +1,14 @@
|
||||||
package mage.watchers;
|
package mage.watchers;
|
||||||
|
|
||||||
|
import mage.constants.WatcherScope;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.game.events.GameEvent;
|
||||||
|
import mage.players.PlayerList;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import mage.constants.WatcherScope;
|
|
||||||
import mage.game.Game;
|
|
||||||
import mage.game.events.GameEvent;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* watches for certain game events to occur and flags condition
|
* watches for certain game events to occur and flags condition
|
||||||
|
@ -123,6 +125,14 @@ public abstract class Watcher implements Serializable {
|
||||||
set.addAll(e.getValue());
|
set.addAll(e.getValue());
|
||||||
target.put(e.getKey(), set);
|
target.put(e.getKey(), set);
|
||||||
}
|
}
|
||||||
|
} else if (valueType.getTypeName().contains("PlayerList")) {
|
||||||
|
Map<Object, PlayerList> source = (Map<Object, PlayerList>) field.get(this);
|
||||||
|
Map<Object, PlayerList> target = (Map<Object, PlayerList>) field.get(watcher);
|
||||||
|
target.clear();
|
||||||
|
for (Map.Entry<Object, PlayerList> e : source.entrySet()) {
|
||||||
|
PlayerList list = e.getValue().copy();
|
||||||
|
target.put(e.getKey(), list);
|
||||||
|
}
|
||||||
} else if (valueType.getTypeName().contains("List")) {
|
} else if (valueType.getTypeName().contains("List")) {
|
||||||
Map<Object, List<Object>> source = (Map<Object, List<Object>>) field.get(this);
|
Map<Object, List<Object>> source = (Map<Object, List<Object>>) field.get(this);
|
||||||
Map<Object, List<Object>> target = (Map<Object, List<Object>>) field.get(watcher);
|
Map<Object, List<Object>> target = (Map<Object, List<Object>>) field.get(watcher);
|
||||||
|
@ -141,14 +151,12 @@ public abstract class Watcher implements Serializable {
|
||||||
map.putAll(e.getValue());
|
map.putAll(e.getValue());
|
||||||
target.put(e.getKey(), map);
|
target.put(e.getKey(), map);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
((Map) field.get(watcher)).putAll((Map) field.get(this));
|
((Map) field.get(watcher)).putAll((Map) field.get(this));
|
||||||
}
|
}
|
||||||
} else if (field.getType() == List.class) {
|
} else if (field.getType() == List.class) {
|
||||||
((List) field.get(watcher)).clear();
|
((List) field.get(watcher)).clear();
|
||||||
((List) field.get(watcher)).addAll((List) field.get(this));
|
((List) field.get(watcher)).addAll((List) field.get(this));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
field.set(watcher, field.get(this));
|
field.set(watcher, field.get(this));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue