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;
}
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;
}
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);
}
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;
}
Aggregations