Search in sources :

Example 41 with FilterControlledPermanent

use of mage.filter.common.FilterControlledPermanent 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)

Example 42 with FilterControlledPermanent

use of mage.filter.common.FilterControlledPermanent in project mage by magefree.

the class TargetControlledCreatureEachColor method makeFilter.

private static final FilterControlledPermanent makeFilter(String colors) {
    List<ObjectColor> objectColors = Arrays.stream(colors.split("")).map(ObjectColor::new).collect(Collectors.toList());
    FilterControlledPermanent filter = new FilterControlledCreaturePermanent(CardUtil.concatWithAnd(objectColors.stream().map(ObjectColor::getDescription).map(s -> CardUtil.addArticle(s) + " creature").collect(Collectors.toList())));
    filter.add(Predicates.or(objectColors.stream().map(ColorPredicate::new).collect(Collectors.toList())));
    return filter;
}
Also used : Arrays(java.util.Arrays) Cards(mage.cards.Cards) Predicates(mage.filter.predicate.Predicates) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Collectors(java.util.stream.Collectors) ColorAssignment(mage.abilities.dynamicvalue.common.ColorAssignment) Game(mage.game.Game) List(java.util.List) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) ObjectColor(mage.ObjectColor) Ability(mage.abilities.Ability) ObjectColor(mage.ObjectColor) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 43 with FilterControlledPermanent

use of mage.filter.common.FilterControlledPermanent in project mage by magefree.

the class ReturnToHandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (targetPlayer == null) {
        return false;
    }
    Target target = new TargetControlledPermanent(1, 1, new FilterControlledPermanent(), true);
    if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
        targetPlayer.chooseTarget(Outcome.ReturnToHand, target, source, game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            targetPlayer.moveCards(permanent, Zone.HAND, source, game);
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 44 with FilterControlledPermanent

use of mage.filter.common.FilterControlledPermanent in project mage by magefree.

the class DescentIntoMadnessEffect method selectCards.

private void selectCards(Player player, List<UUID> selectedObjects, int count, Ability source, Game game) {
    int amount = Math.min(count, player.getHand().size() + game.getBattlefield().getAllActivePermanents(player.getId()).size());
    int cardsFromHand = 0;
    while (player.canRespond() && amount > 0) {
        Target target;
        do {
            FilterControlledPermanent filter = new FilterControlledPermanent();
            filter.setMessage("permanent you control (" + amount + " left in total)");
            List<PermanentIdPredicate> uuidPredicates = new ArrayList<>();
            for (UUID uuid : selectedObjects) {
                uuidPredicates.add(new PermanentIdPredicate(uuid));
            }
            filter.add(Predicates.not(Predicates.or(uuidPredicates)));
            target = new TargetControlledPermanent(0, 1, filter, true);
            if (target.canChoose(source.getSourceId(), player.getId(), game) && player.choose(Outcome.Exile, target, source.getSourceId(), game)) {
                for (UUID targetId : target.getTargets()) {
                    if (!selectedObjects.contains(targetId)) {
                        Permanent chosen = game.getPermanent(targetId);
                        if (chosen != null) {
                            amount--;
                            game.informPlayers(player.getLogName() + " selects " + chosen.getLogName() + " from battlefield");
                            selectedObjects.add(targetId);
                        }
                    }
                }
            }
        } while (amount > 0 && !target.getTargets().isEmpty() && player.canRespond());
        if (amount > 0) {
            TargetCard targetInHand;
            do {
                FilterCard filterInHand = new FilterCard();
                filterInHand.setMessage("card from your hand (" + amount + " left in total)");
                targetInHand = new TargetCard(0, 1, Zone.HAND, filterInHand);
                List<CardIdPredicate> uuidPredicates = new ArrayList<>();
                for (UUID uuid : selectedObjects) {
                    uuidPredicates.add(new CardIdPredicate(uuid));
                }
                filterInHand.add(Predicates.not(Predicates.or(uuidPredicates)));
                if (targetInHand.canChoose(source.getSourceId(), player.getId(), game) && player.choose(Outcome.Exile, player.getHand(), targetInHand, game)) {
                    Card card = player.getHand().get(targetInHand.getFirstTarget(), game);
                    if (card != null) {
                        selectedObjects.add(targetInHand.getFirstTarget());
                        amount--;
                        cardsFromHand++;
                    }
                }
            } while (amount > 0 && !targetInHand.getTargets().isEmpty() && player.canRespond());
        }
    }
    if (cardsFromHand > 0) {
        game.informPlayers(player.getLogName() + " selects " + cardsFromHand + (cardsFromHand == 1 ? " card" : " cards") + " from their hand");
    }
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Target(mage.target.Target) UUID(java.util.UUID) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 45 with FilterControlledPermanent

use of mage.filter.common.FilterControlledPermanent in project mage by magefree.

the class CoordinatedBarrageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Choice choice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
        if (controller.choose(Outcome.Damage, choice, game)) {
            String chosenType = choice.getChoice();
            FilterControlledPermanent filter = new FilterControlledPermanent();
            filter.add(SubType.byDescription(chosenType).getPredicate());
            int damageDealt = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
            Permanent permanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
            if (permanent != null) {
                permanent.damage(damageDealt, source.getSourceId(), source, game, false, true);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) ChoiceCreatureType(mage.choices.ChoiceCreatureType) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Aggregations

FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)47 Player (mage.players.Player)41 Permanent (mage.game.permanent.Permanent)34 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)28 UUID (java.util.UUID)17 Target (mage.target.Target)16 FilterPermanent (mage.filter.FilterPermanent)9 TargetPermanent (mage.target.TargetPermanent)9 Card (mage.cards.Card)6 OneShotEffect (mage.abilities.effects.OneShotEffect)5 FixedTarget (mage.target.targetpointer.FixedTarget)5 ArrayList (java.util.ArrayList)4 Effect (mage.abilities.effects.Effect)4 Choice (mage.choices.Choice)4 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)4 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)4 TargetPlayer (mage.target.TargetPlayer)4 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)3 Cards (mage.cards.Cards)3 FilterCard (mage.filter.FilterCard)3