Search in sources :

Example 81 with TargetControlledPermanent

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

the class DivineReckoningEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Card> chosen = new ArrayList<>();
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                Target target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
                if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                    while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
                        player.chooseTarget(Outcome.Benefit, target, source, game);
                    }
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        chosen.add(permanent);
                    }
                }
            }
        }
        for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), source.getSourceId(), game)) {
            if (!chosen.contains(permanent)) {
                permanent.destroy(source, game, false);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) Card(mage.cards.Card)

Example 82 with TargetControlledPermanent

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

the class DragonsFireEffect method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    this.targets.clear();
    dragonZone = DragonZone.NONE;
    selectedCardId = null;
    Player controller = game.getPlayer(controllerId);
    if (controller != null) {
        boolean dragonInHand = false;
        boolean dragonOnBattlefield = false;
        DragonZone chosenZone = DragonZone.NONE;
        for (UUID cardId : controller.getHand()) {
            Card card = game.getCard(cardId);
            if (card != null && card.hasSubtype(SubType.DRAGON, game)) {
                dragonInHand = true;
                break;
            }
        }
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controllerId)) {
            if (permanent != null && permanent.hasSubtype(SubType.DRAGON, game)) {
                dragonOnBattlefield = true;
                break;
            }
        }
        if (dragonInHand && dragonOnBattlefield) {
            if (controller.chooseUse(Outcome.Benefit, "Reveal a Dragon card from your hand or choose a Dragon you control?", source, game)) {
                if (controller.chooseUse(Outcome.Benefit, "Choose Dragon from hand or Dragon on battlefield", null, "Hand", "Battlefield", source, game)) {
                    chosenZone = DragonZone.HAND;
                } else {
                    chosenZone = DragonZone.BATTLEFIELD;
                }
            }
        } else if (dragonInHand) {
            if (controller.chooseUse(Outcome.Benefit, "Reveal a Dragon card from your hand?", source, game)) {
                chosenZone = DragonZone.HAND;
            }
        } else if (dragonOnBattlefield) {
            if (controller.chooseUse(Outcome.Benefit, "Choose a dragon on the battlefield?", source, game)) {
                chosenZone = DragonZone.BATTLEFIELD;
            }
        }
        switch(chosenZone) {
            case HAND:
                targets.add(new TargetCardInHand(handFilter));
                if (targets.choose(Outcome.Benefit, controllerId, source.getSourceId(), game)) {
                    Card card = game.getCard(targets.getFirstTarget());
                    if (card != null) {
                        dragonZone = DragonZone.HAND;
                        selectedCardId = targets.getFirstTarget();
                        controller.revealCards(source, new CardsImpl(card), game);
                    }
                }
                break;
            case BATTLEFIELD:
                targets.add(new TargetControlledPermanent(battlefieldFilter));
                if (targets.choose(Outcome.Benefit, controllerId, source.getSourceId(), game)) {
                    Permanent permanent = game.getPermanent(targets.getFirstTarget());
                    if (permanent != null) {
                        dragonZone = DragonZone.BATTLEFIELD;
                        selectedCardId = targets.getFirstTarget();
                        game.informPlayers(controller.getLogName() + " chooses " + permanent.getLogName());
                    }
                }
                break;
        }
    }
    return paid = true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 83 with TargetControlledPermanent

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

the class MartyrsBondEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> perms = new ArrayList<>();
    if (source != null) {
        Permanent saccedPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null && saccedPermanent != null) {
            FilterControlledPermanent filter = new FilterControlledPermanent();
            String message = "permanent with type (";
            boolean firstType = true;
            List<CardType.CardTypePredicate> cardTypes = new ArrayList<>();
            for (CardType type : saccedPermanent.getCardType(game)) {
                cardTypes.add(type.getPredicate());
                if (firstType) {
                    message += type;
                    firstType = false;
                } else {
                    message += " or " + type;
                }
            }
            message += ") to sacrifice";
            filter.add(Predicates.or(cardTypes));
            filter.setMessage(message);
            for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
                Player player = game.getPlayer(playerId);
                if (player != null && !playerId.equals(controller.getId())) {
                    TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
                    if (target.canChoose(source.getSourceId(), playerId, game)) {
                        player.chooseTarget(Outcome.Sacrifice, target, source, game);
                        perms.add(target.getFirstTarget());
                    }
                }
            }
            boolean saccedPermaents = false;
            for (UUID permID : perms) {
                Permanent permanent = game.getPermanent(permID);
                if (permanent != null) {
                    permanent.sacrifice(source, game);
                    saccedPermaents = true;
                }
            }
            return saccedPermaents;
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) CardType(mage.constants.CardType) ArrayList(java.util.ArrayList) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 84 with TargetControlledPermanent

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

the class OathOfLimDulEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean sacrificeDone = false;
    int numberSacrificed = 0;
    int numberToDiscard = 0;
    int numberOfControlledPermanents = 0;
    Player controller = game.getPlayer(source.getControllerId());
    int amountDamage = (int) game.getState().getValue(source.getSourceId().toString() + "oathOfLimDul");
    if (amountDamage > 0 && controller != null) {
        TargetControlledPermanent target = new TargetControlledPermanent(0, numberOfControlledPermanents, filter, true);
        target.setNotTarget(true);
        if (controller.choose(Outcome.Detriment, target, source.getSourceId(), game)) {
            for (UUID targetPermanentId : target.getTargets()) {
                Permanent permanent = game.getPermanent(targetPermanentId);
                if (permanent != null && permanent.sacrifice(source, game)) {
                    numberSacrificed += 1;
                    sacrificeDone = true;
                }
            }
        }
        numberToDiscard = amountDamage - numberSacrificed;
        Cost cost = new DiscardTargetCost(new TargetCardInHand(numberToDiscard, new FilterCard("card(s) in your hand to discard")));
        if (numberToDiscard > 0 && cost.canPay(source, source, controller.getId(), game)) {
            // discard cost paid simultaneously
            return cost.pay(source, game, source, controller.getId(), true);
        }
    }
    return sacrificeDone;
}
Also used : FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) UUID(java.util.UUID) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) Cost(mage.abilities.costs.Cost)

Example 85 with TargetControlledPermanent

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

the class SelfInflictedWoundEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetOpponent = game.getPlayer(source.getTargets().getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (targetOpponent == null || controller == null) {
        return false;
    }
    FilterControlledPermanent filter = new FilterControlledPermanent("a green or white creature");
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(TargetController.YOU.getControllerPredicate());
    filter.add(Predicates.or(new ColorPredicate(ObjectColor.GREEN), new ColorPredicate(ObjectColor.WHITE)));
    TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
    if (target.canChoose(source.getSourceId(), targetOpponent.getId(), game)) {
        targetOpponent.chooseTarget(Outcome.Sacrifice, target, source, game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            if (permanent.sacrifice(source, game)) {
                targetOpponent.loseLife(2, game, source, false);
            }
        }
    }
    return true;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

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