Search in sources :

Example 6 with CommanderPlaysCountWatcher

use of mage.watchers.common.CommanderPlaysCountWatcher in project mage by magefree.

the class Card method commanderCost.

/**
 * Commander tax calculation. Tax logic can be changed (example: from {2} to life cost, see Liesa, Shroud of Dusk)
 *
 * @param game
 * @param source
 * @param abilityToModify
 * @return
 */
default 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.getManaCostsToPay().add(ManaUtil.createManaCost(2 * castCount, false));
    }
    return true;
}
Also used : CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher)

Example 7 with CommanderPlaysCountWatcher

use of mage.watchers.common.CommanderPlaysCountWatcher in project mage by magefree.

the class MythUnboundCostReductionEffect method apply.

@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
    Ability spellAbility = abilityToModify;
    if (spellAbility != null) {
        CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
        int castCount = watcher.getPlaysCount(abilityToModify.getSourceId());
        CardUtil.reduceCost(spellAbility, castCount);
        return true;
    }
    return false;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ZoneChangeAllTriggeredAbility(mage.abilities.common.ZoneChangeAllTriggeredAbility) PlayLandAbility(mage.abilities.PlayLandAbility) SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher)

Example 8 with CommanderPlaysCountWatcher

use of mage.watchers.common.CommanderPlaysCountWatcher in project mage by magefree.

the class CommandersGameRestartTest method test_KarnLiberated_Manual.

@Test
public void test_KarnLiberated_Manual() {
    // 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);
    // 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, 20);
    // 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));
    });
    // game restart
    activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "-14: ");
    waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, playerA);
    setStopAt(1, PhaseStep.END_TURN);
    setStrictChooseMode(true);
    execute();
    assertAllCommandsUsed();
    // check watcher after restart
    UUID commanderId = currentGame.getCommandersIds(playerA, CommanderCardType.ANY, false).stream().findFirst().orElse(null);
    CommanderPlaysCountWatcher watcher = currentGame.getState().getWatcher(CommanderPlaysCountWatcher.class);
    Assert.assertEquals("commander tax must be x0", 0, watcher.getPlaysCount(commanderId));
    // no cards on battle after game restart
    assertPermanentCount(playerA, 0);
}
Also used : CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher) UUID(java.util.UUID) Test(org.junit.Test)

Example 9 with CommanderPlaysCountWatcher

use of mage.watchers.common.CommanderPlaysCountWatcher in project mage by magefree.

the class StudyHallTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!getSourceId().equals(event.getSourceId())) {
        return false;
    }
    Permanent sourcePermanent = getSourcePermanentOrLKI(game);
    if (sourcePermanent == null || sourcePermanent.getAbilities(game).stream().map(Ability::getOriginalId).map(UUID::toString).noneMatch(event.getData()::equals)) {
        return false;
    }
    Player player = game.getPlayer(getControllerId());
    Spell spell = game.getStack().getSpell(event.getTargetId());
    CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
    if (player == null || spell == null || watcher == null || !game.isCommanderObject(player, spell)) {
        return false;
    }
    getEffects().clear();
    addEffect(new ScryEffect(watcher.getPlaysCount(spell.getMainCard().getId())));
    return true;
}
Also used : Player(mage.players.Player) CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher) ScryEffect(mage.abilities.effects.keyword.ScryEffect) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) 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