use of mage.watchers.common.CommanderInfoWatcher in project mage by magefree.
the class CastBRGCommanderTest method testCommanderRestoredToBattlefieldAfterKarnUltimate.
/**
* If the commander is exiled by Karn (and not returned to the command
* zone), it needs to restart the game in play and not the command zone.
*/
@Test
public void testCommanderRestoredToBattlefieldAfterKarnUltimate() {
// +4: Target player exiles a card from their hand.
// -3: Exile target permanent.
// -14: Restart the game, leaving in exile all non-Aura permanent cards exiled with Karn Liberated. Then put those cards onto the battlefield under your control.
// Planeswalker (6)
addCard(Zone.BATTLEFIELD, playerA, "Karn Liberated", 1);
addCard(Zone.HAND, playerA, "Silvercoat Lion", 3);
addCard(Zone.BATTLEFIELD, playerB, "Plains", 2);
addCard(Zone.BATTLEFIELD, playerB, "Island", 1);
// exile from hand 1
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+4: Target player", playerA);
addTarget(playerA, "Silvercoat Lion");
// prepare commander
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Daxos of Meletis");
// exile from hand 2
activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "+4: Target player", playerA);
addTarget(playerA, "Silvercoat Lion");
// attack and get commander damage
attack(4, playerB, "Daxos of Meletis");
// exile commander
activateAbility(5, PhaseStep.PRECOMBAT_MAIN, playerA, "-3: Exile target permanent", "Daxos of Meletis");
// Move commander NOT to command zone
setChoice(playerB, false);
// exile from hand 3
activateAbility(7, PhaseStep.PRECOMBAT_MAIN, playerA, "+4: Target player", playerA);
addTarget(playerA, "Silvercoat Lion");
// restart game and return to battlefield 1x commander and 3x lions
activateAbility(9, PhaseStep.PRECOMBAT_MAIN, playerA, "-14: Restart");
// warning:
// - karn restart code can clear some game data
// - current version ignores a card's ZCC
// - so ZCC are same after game restart and SBA can't react on commander new move
// - logic can be changed in the future, so game can ask commander move again here
// setChoice(playerB, false); // Move commander NOT to command zone
setStopAt(9, PhaseStep.BEGIN_COMBAT);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
assertGraveyardCount(playerA, "Karn Liberated", 0);
assertPermanentCount(playerA, "Silvercoat Lion", 3);
assertCommandZoneCount(playerA, "Prossh, Skyraider of Kher", 1);
assertCommandZoneCount(playerB, "Daxos of Meletis", 0);
// Karn brings back the cards under the control of Karn's controller
assertPermanentCount(playerA, "Daxos of Meletis", 1);
CommanderInfoWatcher watcher = currentGame.getState().getWatcher(CommanderInfoWatcher.class, playerB.getCommandersIds().iterator().next());
Assert.assertEquals("Watcher is reset to 0 commander damage", 0, watcher.getDamageToPlayer().size());
}
use of mage.watchers.common.CommanderInfoWatcher in project mage by magefree.
the class DefaultCommander method init.
@Override
protected void init(UUID choosingPlayerId) {
// move tiny leader to command zone
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
Player player = getPlayer(playerId);
if (player != null) {
String commanderName = player.getMatchPlayer().getDeck().getName();
Card commander = findCommander(this, player, commanderName);
if (commander != null) {
// already exists - just move to zone (example: game restart by Karn Liberated)
commander.moveToZone(Zone.COMMAND, null, this, true);
} else {
// create new commander
commander = getCommanderCard(commanderName, player.getId());
if (commander != null) {
Set<Card> cards = new HashSet<>();
cards.add(commander);
this.loadCards(cards, playerId);
player.addCommanderId(commander.getId());
commander.moveToZone(Zone.COMMAND, null, this, true);
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Commander effects"));
ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary, false, "Commander"));
ability.addEffect(new CommanderCostModification(commander));
// Commander rule #4 was removed Jan. 18, 2016
// ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander)));
CommanderInfoWatcher watcher = new CommanderInfoWatcher("Commander", commander.getId(), false);
getState().addWatcher(watcher);
watcher.addCardInfoToCommander(this);
this.getState().addAbility(ability, null);
} else {
// Test use case: create tiny game with random generated deck - game freezes with empty battlefield
throw new IllegalStateException("Commander card could not be created. Name: [" + player.getMatchPlayer().getDeck().getName() + ']');
}
}
}
}
super.init(choosingPlayerId);
if (startingPlayerSkipsDraw) {
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
}
}
use of mage.watchers.common.CommanderInfoWatcher in project mage by magefree.
the class GameCommanderImpl method initCommander.
public void initCommander(Card commander, Player player) {
if (!Zone.EXILED.equals(getState().getZone(commander.getId()))) {
// Exile check needed for Karn Liberated restart
commander.moveToZone(Zone.COMMAND, null, this, true);
}
commander.getAbilities().setControllerId(player.getId());
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Commander effects"));
initCommanderEffects(commander, player, ability);
CommanderInfoWatcher watcher = initCommanderWatcher(commander, checkCommanderDamage);
getState().addWatcher(watcher);
watcher.addCardInfoToCommander(this);
this.getState().addAbility(ability, null);
}
Aggregations