Search in sources :

Example 1 with CommanderPlaysCountWatcher

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();
}
Also used : CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with CommanderPlaysCountWatcher

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;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher) Hint(mage.abilities.hint.Hint)

Example 3 with CommanderPlaysCountWatcher

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;
}
Also used : CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher) PayLifeCost(mage.abilities.costs.common.PayLifeCost)

Example 4 with CommanderPlaysCountWatcher

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;
}
Also used : CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher) Permanent(mage.game.permanent.Permanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent)

Example 5 with CommanderPlaysCountWatcher

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;
}
Also used : Player(mage.players.Player) CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher) MageObjectReference(mage.MageObjectReference) Spell(mage.game.stack.Spell)

Aggregations

CommanderPlaysCountWatcher (mage.watchers.common.CommanderPlaysCountWatcher)9 UUID (java.util.UUID)3 Player (mage.players.Player)3 Permanent (mage.game.permanent.Permanent)2 Spell (mage.game.stack.Spell)2 Test (org.junit.Test)2 MageObjectReference (mage.MageObjectReference)1 Ability (mage.abilities.Ability)1 PlayLandAbility (mage.abilities.PlayLandAbility)1 SpellAbility (mage.abilities.SpellAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 ZoneChangeAllTriggeredAbility (mage.abilities.common.ZoneChangeAllTriggeredAbility)1 PayLifeCost (mage.abilities.costs.common.PayLifeCost)1 ScryEffect (mage.abilities.effects.keyword.ScryEffect)1 Hint (mage.abilities.hint.Hint)1 EntersTheBattlefieldEvent (mage.game.events.EntersTheBattlefieldEvent)1 TargetPlayer (mage.target.TargetPlayer)1