package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.filter.common.FilterLandPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.common.TargetLandPermanent;
import java.util.UUID;
/**
* "Untap up to X lands" effect
*/
public class UntapLandsEffect extends OneShotEffect {
private int amount;
public UntapLandsEffect(int amount) {
super(Outcome.Untap);
this.amount = amount;
staticText = "Untap up to " + amount + " lands";
}
public UntapLandsEffect(final UntapLandsEffect effect) {
super(effect);
this.amount = effect.amount;
}
@Override
public boolean apply(Game game, Ability source) {
TargetLandPermanent target = new TargetLandPermanent(0, amount, new FilterLandPermanent(), true);
if (target.canChoose(source.getControllerId(), game)) {
if (target.choose(Outcome.Untap, source.getControllerId(), source.getSourceId(), game)) {
for (Object targetId : target.getTargets()) {
Permanent p = game.getPermanent((UUID) targetId);
if (p.isTapped())
p.untap(game);
}
}
}
return false;
}
@Override
public UntapLandsEffect copy() {
return new UntapLandsEffect(this);
}
}