Commander: improved lands compatibility with cost modification and restriction effects;

This commit is contained in:
Oleg Agafonov 2019-05-23 14:57:26 +04:00
parent 42ed14df52
commit 97c8622311
8 changed files with 81 additions and 83 deletions

View file

@ -0,0 +1,57 @@
package mage.abilities.effects.common.cost;
import mage.abilities.Ability;
import mage.abilities.common.CastCommanderAbility;
import mage.abilities.common.PlayLandAsCommanderAbility;
import mage.abilities.costs.mana.GenericManaCost;
import mage.constants.CostModificationType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.game.Game;
import mage.watchers.common.CommanderPlaysCountWatcher;
import java.util.UUID;
/**
* @author Plopman
*/
/*
903.8. A player may cast a commander they own from the command zone. A commander cast from the
command zone costs an additional {2} for each previous time the player casting it has cast it from
the command zone that game. This additional cost is informally known as the commander tax.
*/
public class CommanderCostModification extends CostModificationEffectImpl {
private final UUID commanderId;
public CommanderCostModification(UUID commanderId) {
super(Duration.Custom, Outcome.Neutral, CostModificationType.INCREASE_COST);
this.commanderId = commanderId;
}
public CommanderCostModification(final CommanderCostModification effect) {
super(effect);
this.commanderId = effect.commanderId;
}
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
int castCount = watcher.getPlaysCount(commanderId);
if (castCount > 0) {
abilityToModify.getManaCostsToPay().add(new GenericManaCost(2 * castCount));
}
return true;
}
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
return commanderId.equals(abilityToModify.getSourceId())
&& (abilityToModify instanceof CastCommanderAbility || abilityToModify instanceof PlayLandAsCommanderAbility);
}
@Override
public CommanderCostModification copy() {
return new CommanderCostModification(this);
}
}