use of mage.watchers.common.CommanderPlaysCountWatcher in project mage by magefree.
the class CommandersGameRestartTest method test_KarnLiberated_AI.
@Test
public void test_KarnLiberated_AI() {
// Player order: A -> D -> C -> B
// {1}{G}, 2/2, commander
addCard(Zone.COMMAND, playerA, "Balduvian Bears", 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
//
// -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.
addCard(Zone.BATTLEFIELD, playerA, "Karn Liberated", 1);
//
addCard(Zone.HAND, playerB, "Balduvian Bears", 5);
addCard(Zone.HAND, playerC, "Balduvian Bears", 5);
addCard(Zone.HAND, playerD, "Balduvian Bears", 5);
// prepare commander
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Balduvian Bears");
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, playerA);
checkPermanentCount("prepare", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Balduvian Bears", 1);
// prepare karn
addCounters(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Karn Liberated", CounterType.LOYALTY, 50);
// check watcher before restart
runCode("before restart", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
UUID commanderId = game.getCommandersIds(player, CommanderCardType.ANY, false).stream().findFirst().orElse(null);
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
Assert.assertEquals("commander tax must be x1", 1, watcher.getPlaysCount(commanderId));
});
// possible bug: ai can use restart in one of the simulations, so it can freeze the game (if bugged)
aiPlayStep(1, PhaseStep.PRECOMBAT_MAIN, playerA);
aiPlayStep(1, PhaseStep.PRECOMBAT_MAIN, playerB);
aiPlayStep(1, PhaseStep.PRECOMBAT_MAIN, playerC);
aiPlayStep(1, PhaseStep.PRECOMBAT_MAIN, playerD);
setStopAt(1, PhaseStep.END_TURN);
setStrictChooseMode(true);
execute();
assertAllCommandsUsed();
}
use of mage.watchers.common.CommanderPlaysCountWatcher in project mage by magefree.
the class CommandersInsightEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
if (player == null || watcher == null) {
return false;
}
int toDraw = watcher.getPlayerCount(player.getId()) + source.getManaCostsToPay().getX();
return player.drawCards(toDraw, source, game) > 0;
}
use of mage.watchers.common.CommanderPlaysCountWatcher in project mage by magefree.
the class LiesaShroudOfDusk method commanderCost.
@Override
public boolean commanderCost(Game game, Ability source, Ability abilityToModify) {
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
int castCount = watcher.getPlaysCount(getMainCard().getId());
if (castCount > 0) {
abilityToModify.addCost(new PayLifeCost(2 * castCount));
}
return true;
}
use of mage.watchers.common.CommanderPlaysCountWatcher in project mage by magefree.
the class OpalPalaceEntersBattlefieldEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent permanent = ((EntersTheBattlefieldEvent) event).getTarget();
if (permanent != null) {
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
int castCount = watcher.getPlaysCount(permanent.getId());
if (castCount > 0) {
permanent.addCounters(CounterType.P1P1.createInstance(castCount), source.getControllerId(), source, game);
}
}
return false;
}
use of mage.watchers.common.CommanderPlaysCountWatcher in project mage by magefree.
the class CommanderStormEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObjectReference spellRef = (MageObjectReference) this.getValue("StormSpellRef");
if (spellRef == null) {
return false;
}
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
if (watcher == null) {
return false;
}
int stormCount = game.getCommandersIds(player, CommanderCardType.COMMANDER_OR_OATHBREAKER, false).stream().mapToInt(watcher::getPlaysCount).sum();
if (stormCount == 0) {
return true;
}
Spell spell = (Spell) this.getValue("StormSpell");
if (spell == null) {
return false;
}
game.informPlayers(spell.getLogName() + " will be copied " + stormCount + " time" + (stormCount > 1 ? "s" : ""));
spell.createCopyOnStack(game, source, source.getControllerId(), true, stormCount);
return true;
}
Aggregations