Search in sources :

Example 11 with TargetLandPermanent

use of mage.target.common.TargetLandPermanent in project mage by magefree.

the class KudzuEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent kudzu = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (kudzu != null) {
        Permanent enchantedLand = game.getPermanentOrLKIBattlefield(kudzu.getAttachedTo());
        Player controller = game.getPlayer(source.getControllerId());
        if (enchantedLand != null && controller != null) {
            Player landsController = game.getPlayer(enchantedLand.getControllerId());
            if (game.getState().getZone(enchantedLand.getId()) == Zone.BATTLEFIELD) {
                // if 2 or more Kudzu's were on a land
                enchantedLand.destroy(source, game, false);
            }
            if (!game.getBattlefield().getAllActivePermanents(CardType.LAND, game).isEmpty()) {
                // lands are available on the battlefield
                Target target = new TargetLandPermanent();
                // not a target, it is chosen
                target.setNotTarget(true);
                Card kudzuCard = game.getCard(source.getSourceId());
                if (kudzuCard != null && landsController != null) {
                    if (landsController.choose(Outcome.Detriment, target, source.getId(), game)) {
                        if (target.getFirstTarget() != null) {
                            Permanent landChosen = game.getPermanent(target.getFirstTarget());
                            if (landChosen != null) {
                                for (Target targetTest : kudzuCard.getSpellAbility().getTargets()) {
                                    if (targetTest.getFilter().match(landChosen, game)) {
                                        landChosen.addAttachment(kudzu.getId(), source, game);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) Card(mage.cards.Card)

Example 12 with TargetLandPermanent

use of mage.target.common.TargetLandPermanent in project mage by magefree.

the class OrcishSettlersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int amount = source.getManaCostsToPay().getX();
    if (amount == 0) {
        return false;
    }
    TargetLandPermanent target = new TargetLandPermanent(amount);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(Outcome.DestroyPermanent, target, source.getSourceId(), game)) {
        List<UUID> targets = target.getTargets();
        targets.forEach((landId) -> {
            Permanent land = game.getPermanent(landId);
            if (land != null) {
                land.destroy(source, game, false);
            }
        });
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) UUID(java.util.UUID)

Example 13 with TargetLandPermanent

use of mage.target.common.TargetLandPermanent in project mage by magefree.

the class PlanarOverlayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Card> lands = new HashSet<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                for (SubType landName : SubType.getBasicLands()) {
                    FilterLandPermanent filter = new FilterLandPermanent(landName + " to return to hand");
                    filter.add(landName.getPredicate());
                    filter.add(TargetController.YOU.getControllerPredicate());
                    Target target = new TargetLandPermanent(1, 1, filter, true);
                    if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                        player.chooseTarget(outcome, target, source, game);
                        lands.add(game.getPermanent(target.getFirstTarget()));
                    }
                }
            }
        }
        controller.moveCards(lands, Zone.HAND, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) UUID(java.util.UUID) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 14 with TargetLandPermanent

use of mage.target.common.TargetLandPermanent in project mage by magefree.

the class CantPlayLandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    game.getState().getPlayersInRange(source.getControllerId(), game).forEach((playerId) -> {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            int lands = game.getBattlefield().countAll(new FilterControlledLandPermanent(), playerId, game);
            TargetLandPermanent target = new TargetLandPermanent(Integer.min(5, lands));
            target.setNotTarget(true);
            target.setRequired(true);
            player.chooseTarget(outcome.Benefit, target, source, game);
            game.getBattlefield().getAllActivePermanents(new FilterControlledLandPermanent(), playerId, game).stream().filter((land) -> (!target.getTargets().contains(land.getId()))).forEachOrdered((land) -> {
                land.sacrifice(source, game);
            });
        }
    });
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) Zone(mage.constants.Zone) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) Outcome(mage.constants.Outcome) PermanentsOnTheBattlefieldCondition(mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) TargetLandPermanent(mage.target.common.TargetLandPermanent) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Duration(mage.constants.Duration) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Game(mage.game.Game) GameEvent(mage.game.events.GameEvent) ComparisonType(mage.constants.ComparisonType) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) ConditionalContinuousRuleModifyingEffect(mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect) ContinuousRuleModifyingEffectImpl(mage.abilities.effects.ContinuousRuleModifyingEffectImpl) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 15 with TargetLandPermanent

use of mage.target.common.TargetLandPermanent in project mage by magefree.

the class DemonicHordesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent demonicHordes = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && demonicHordes != null) {
        StringBuilder sb = new StringBuilder(cost.getText()).append('?');
        if (!sb.toString().toLowerCase(Locale.ENGLISH).startsWith("exile ") && !sb.toString().toLowerCase(Locale.ENGLISH).startsWith("return ")) {
            sb.insert(0, "Pay ");
        }
        if (controller.chooseUse(Outcome.Benefit, sb.toString(), source, game)) {
            cost.clearPaid();
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                return true;
            }
        }
        demonicHordes.tap(source, game);
        Target choiceOpponent = new TargetOpponent();
        choiceOpponent.setNotTarget(true);
        FilterLandPermanent filterLand = new FilterLandPermanent();
        filterLand.add(new ControllerIdPredicate(source.getControllerId()));
        if (controller.choose(Outcome.Neutral, choiceOpponent, source.getSourceId(), game)) {
            Player opponent = game.getPlayer(choiceOpponent.getFirstTarget());
            if (opponent != null) {
                Target chosenLand = new TargetLandPermanent(filterLand);
                chosenLand.setNotTarget(true);
                if (opponent.chooseTarget(Outcome.Sacrifice, chosenLand, source, game)) {
                    Permanent land = game.getPermanent(chosenLand.getFirstTarget());
                    if (land != null) {
                        land.sacrifice(source, game);
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetLandPermanent(mage.target.common.TargetLandPermanent)

Aggregations

TargetLandPermanent (mage.target.common.TargetLandPermanent)15 Player (mage.players.Player)13 Permanent (mage.game.permanent.Permanent)12 FilterLandPermanent (mage.filter.common.FilterLandPermanent)11 Target (mage.target.Target)10 UUID (java.util.UUID)9 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)6 OneShotEffect (mage.abilities.effects.OneShotEffect)3 Card (mage.cards.Card)3 TargetPermanent (mage.target.TargetPermanent)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Ability (mage.abilities.Ability)2 Effect (mage.abilities.effects.Effect)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 MageObjectReference (mage.MageObjectReference)1 EntersBattlefieldTriggeredAbility (mage.abilities.common.EntersBattlefieldTriggeredAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)1 PermanentsOnTheBattlefieldCondition (mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition)1