Search in sources :

Example 11 with FilterControlledPermanent

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

the class LinessaZephyrMageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player targetPlayer = game.getPlayer(source.getFirstTarget());
        if (targetPlayer != null) {
            // Target player returns a creature they control to its owner's hand,
            Target target = new TargetControlledCreaturePermanent();
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            // then repeats this process for an artifact,
            FilterControlledPermanent filter = new FilterControlledPermanent("artifact you control");
            filter.add(CardType.ARTIFACT.getPredicate());
            target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            // an enchantment,
            filter = new FilterControlledPermanent("enchantment you control");
            filter.add(CardType.ENCHANTMENT.getPredicate());
            target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, source, game);
                }
            }
            // and a land.
            filter = new FilterControlledPermanent("land you control");
            filter.add(CardType.LAND.getPredicate());
            target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(target.getFirstTarget());
                if (permanent != null) {
                    targetPlayer.moveCards(permanent, Zone.HAND, 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) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 12 with FilterControlledPermanent

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

the class AnnihilatorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID defendingPlayerId = (UUID) getValue("defendingPlayerId");
    Player player = null;
    if (defendingPlayerId != null) {
        player = game.getPlayer(defendingPlayerId);
    }
    if (player != null) {
        int amount = Math.min(count, game.getBattlefield().countAll(new FilterControlledPermanent(), player.getId(), game));
        if (amount > 0) {
            Target target = new TargetControlledPermanent(amount, amount, new FilterControlledPermanent(), true);
            if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                while (player.canRespond() && target.canChoose(source.getSourceId(), player.getId(), game) && !target.isChosen()) {
                    player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
                }
                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) Target(mage.target.Target) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 13 with FilterControlledPermanent

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

the class ArmedAndArmoredEquipEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterControlledPermanent dwarfFilter = new FilterControlledPermanent(SubType.DWARF);
    List<Permanent> dwarves = game.getBattlefield().getAllActivePermanents(dwarfFilter, controller.getId(), game);
    FilterControlledPermanent equipmentFilter = new FilterControlledPermanent(SubType.EQUIPMENT);
    List<Permanent> equipment = game.getBattlefield().getAllActivePermanents(equipmentFilter, controller.getId(), game);
    if (!dwarves.isEmpty() && !equipment.isEmpty()) {
        TargetPermanent target = new TargetPermanent(0, 1, dwarfFilter, true);
        target.withChooseHint("dwarf to be equipped");
        controller.choose(outcome, target, source.getId(), game);
        Permanent dwarf = game.getPermanent(target.getFirstTarget());
        if (dwarf != null) {
            target = new TargetPermanent(0, Integer.MAX_VALUE, equipmentFilter, true);
            target.withChooseHint("equip to " + dwarf.getLogName());
            controller.choose(outcome, target, source.getId(), game);
            for (UUID targetId : target.getTargets()) {
                dwarf.addAttachment(targetId, source, game);
                game.informPlayers(game.getPermanent(targetId).getLogName() + " was attached to " + dwarf.getLogName());
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) UUID(java.util.UUID)

Example 14 with FilterControlledPermanent

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

the class PlaguecrafterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<UUID> perms = new ArrayList<>();
    List<UUID> cantSac = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        FilterControlledPermanent filter = new FilterControlledPermanent("creature or planeswalker");
        filter.add(Predicates.or(CardType.CREATURE.getPredicate(), CardType.PLANESWALKER.getPredicate()));
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
        if (target.canChoose(source.getSourceId(), player.getId(), game)) {
            while (!target.isChosen() && player.canRespond()) {
                player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
            }
            perms.addAll(target.getTargets());
        } else {
            cantSac.add(playerId);
        }
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            permanent.sacrifice(source, game);
        }
    }
    for (UUID playerId : cantSac) {
        Effect discardEffect = new DiscardTargetEffect(1);
        discardEffect.setTargetPointer(new FixedTarget(playerId, game));
        discardEffect.apply(game, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ArrayList(java.util.ArrayList) DiscardTargetEffect(mage.abilities.effects.common.discard.DiscardTargetEffect) DiscardTargetEffect(mage.abilities.effects.common.discard.DiscardTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 15 with FilterControlledPermanent

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

the class RiteOfRuinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Set<String> choices = new HashSet<>();
    choices.add("Artifacts");
    choices.add("Creatures");
    choices.add("Lands");
    LinkedList<CardType> order = new LinkedList<>();
    ChoiceImpl choice = new ChoiceImpl(true);
    choice.setMessage("Choose a card type");
    choice.setChoices(choices);
    while (choices.size() > 1) {
        if (!controller.choose(Outcome.Sacrifice, choice, game)) {
            return false;
        }
        order.add(getCardType(choice.getChoice()));
        choices.remove(choice.getChoice());
        choice.clearChoice();
    }
    order.add(getCardType(choices.iterator().next()));
    int count = 1;
    for (CardType cardType : order) {
        FilterControlledPermanent filter = new FilterControlledPermanent(cardType + " you control");
        filter.add(cardType.getPredicate());
        new SacrificeAllEffect(count, filter).apply(game, source);
        count++;
    }
    return true;
}
Also used : Player(mage.players.Player) CardType(mage.constants.CardType) SacrificeAllEffect(mage.abilities.effects.common.SacrificeAllEffect) ChoiceImpl(mage.choices.ChoiceImpl) 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