Search in sources :

Example 21 with TargetControlledPermanent

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

the class CataclysmEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Card> chosen = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        Target target1 = new TargetControlledPermanent(1, 1, new FilterControlledArtifactPermanent(), true);
        Target target2 = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
        Target target3 = new TargetControlledPermanent(1, 1, new FilterControlledEnchantmentPermanent(), true);
        Target target4 = new TargetControlledPermanent(1, 1, new FilterControlledLandPermanent(), true);
        if (target1.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target1.isChosen() && target1.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target1, source, game);
            }
            Permanent artifact = game.getPermanent(target1.getFirstTarget());
            if (artifact != null) {
                chosen.add(artifact);
            }
            target1.clearChosen();
        }
        if (target2.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target2.isChosen() && target2.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target2, source, game);
            }
            Permanent creature = game.getPermanent(target2.getFirstTarget());
            if (creature != null) {
                chosen.add(creature);
            }
            target2.clearChosen();
        }
        if (target3.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target3.isChosen() && target3.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target3, source, game);
            }
            Permanent enchantment = game.getPermanent(target3.getFirstTarget());
            if (enchantment != null) {
                chosen.add(enchantment);
            }
            target3.clearChosen();
        }
        if (target4.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target4.isChosen() && target4.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target4, source, game);
            }
            Permanent land = game.getPermanent(target4.getFirstTarget());
            if (land != null) {
                chosen.add(land);
            }
            target4.clearChosen();
        }
    }
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
        if (!chosen.contains(permanent)) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) FilterControlledEnchantmentPermanent(mage.filter.common.FilterControlledEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) FilterControlledEnchantmentPermanent(mage.filter.common.FilterControlledEnchantmentPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) Card(mage.cards.Card)

Example 22 with TargetControlledPermanent

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

the class CataclysmicGearhulkEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Card> chosen = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        Target target1 = new TargetControlledPermanent(1, 1, filterArtifact, true);
        Target target2 = new TargetControlledPermanent(1, 1, filterCreature, true);
        Target target3 = new TargetControlledPermanent(1, 1, filterEnchantment, true);
        Target target4 = new TargetControlledPermanent(1, 1, filterPlaneswalker, true);
        if (target1.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target1.isChosen() && target1.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target1, source, game);
            }
            Permanent artifact = game.getPermanent(target1.getFirstTarget());
            if (artifact != null) {
                chosen.add(artifact);
            }
            target1.clearChosen();
        }
        if (target2.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target2.isChosen() && target2.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target2, source, game);
            }
            Permanent creature = game.getPermanent(target2.getFirstTarget());
            if (creature != null) {
                chosen.add(creature);
            }
            target2.clearChosen();
        }
        if (target3.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target3.isChosen() && target3.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target3, source, game);
            }
            Permanent enchantment = game.getPermanent(target3.getFirstTarget());
            if (enchantment != null) {
                chosen.add(enchantment);
            }
            target3.clearChosen();
        }
        if (target4.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target4.isChosen() && target4.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target4, source, game);
            }
            Permanent planeswalker = game.getPermanent(target4.getFirstTarget());
            if (planeswalker != null) {
                chosen.add(planeswalker);
            }
            target4.clearChosen();
        }
    }
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
        if (!chosen.contains(permanent) && !permanent.isLand(game)) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) FilterControlledEnchantmentPermanent(mage.filter.common.FilterControlledEnchantmentPermanent) FilterControlledPlaneswalkerPermanent(mage.filter.common.FilterControlledPlaneswalkerPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Card(mage.cards.Card)

Example 23 with TargetControlledPermanent

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

the class CurseOfTheCabalTriggeredAbilityConditionalDelay method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null) {
        int amount = game.getBattlefield().countAll(StaticFilters.FILTER_CONTROLLED_PERMANENT, targetPlayer.getId(), game) / 2;
        if (amount < 1) {
            return true;
        }
        Target target = new TargetControlledPermanent(amount, amount, StaticFilters.FILTER_CONTROLLED_PERMANENT, true);
        if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
            while (!target.isChosen() && target.canChoose(source.getSourceId(), targetPlayer.getId(), game) && targetPlayer.canRespond()) {
                targetPlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
            }
            // sacrifice all chosen (non null) permanents
            target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(permanent -> permanent.sacrifice(source, game));
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) Target(mage.target.Target)

Example 24 with TargetControlledPermanent

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

the class ElderSpawnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
        SacrificeTargetCost cost = new SacrificeTargetCost(target);
        if (!controller.chooseUse(Outcome.AIDontUseIt, "Sacrifice an Island?", source, game) || !cost.canPay(source, source, source.getControllerId(), game) || !cost.pay(source, game, source, source.getControllerId(), true)) {
            sourcePermanent.sacrifice(source, game);
            controller.damage(6, sourcePermanent.getId(), source, game);
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent)

Example 25 with TargetControlledPermanent

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

the class FadeAwayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            int creaturesNumber = game.getBattlefield().getAllActivePermanents(FILTER_CREATURE, playerId, game).size();
            if (creaturesNumber > 0) {
                String message = "For how many creatures will you pay (up to " + creaturesNumber + ")?";
                int payAmount = 0;
                boolean paid = false;
                while (player.canRespond() && !paid) {
                    payAmount = player.getAmount(0, creaturesNumber, message, game);
                    ManaCostsImpl cost = new ManaCostsImpl();
                    cost.add(new GenericManaCost(payAmount));
                    cost.clearPaid();
                    if (cost.payOrRollback(source, game, source, playerId)) {
                        paid = true;
                    }
                }
                int sacrificeNumber = creaturesNumber - payAmount;
                game.informPlayers(player.getLogName() + " pays {" + payAmount + "} and sacrifices " + sacrificeNumber + " permanent" + (sacrificeNumber == 1 ? "" : "s"));
                if (sacrificeNumber > 0) {
                    int permanentsNumber = game.getBattlefield().getAllActivePermanents(playerId).size();
                    int targetsNumber = Math.min(sacrificeNumber, permanentsNumber);
                    TargetControlledPermanent target = new TargetControlledPermanent(targetsNumber);
                    player.chooseTarget(Outcome.Sacrifice, target, source, game);
                    for (UUID permanentId : target.getTargets()) {
                        Permanent permanent = game.getPermanent(permanentId);
                        if (permanent != null) {
                            permanent.sacrifice(source, game);
                        }
                    }
                }
            } else {
                game.informPlayers(player.getLogName() + " has no creatures");
            }
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Aggregations

TargetControlledPermanent (mage.target.common.TargetControlledPermanent)100 Player (mage.players.Player)94 Permanent (mage.game.permanent.Permanent)87 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)49 UUID (java.util.UUID)47 Target (mage.target.Target)45 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)23 Card (mage.cards.Card)17 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)16 ArrayList (java.util.ArrayList)13 TargetPermanent (mage.target.TargetPermanent)13 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)10 FilterCard (mage.filter.FilterCard)10 TargetPlayer (mage.target.TargetPlayer)10 FilterPermanent (mage.filter.FilterPermanent)8 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)8 Cost (mage.abilities.costs.Cost)7 FilterControlledArtifactPermanent (mage.filter.common.FilterControlledArtifactPermanent)7 TargetCardInHand (mage.target.common.TargetCardInHand)6 OneShotEffect (mage.abilities.effects.OneShotEffect)5