Search in sources :

Example 76 with TargetControlledPermanent

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

the class LichDamageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetControlledPermanent(amount, amount, filter, true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            if (controller.choose(Outcome.Sacrifice, target, source.getSourceId(), game)) {
                for (UUID targetId : target.getTargets()) {
                    Permanent permanent = game.getPermanent(targetId);
                    if (permanent != null) {
                        permanent.sacrifice(source, game);
                    }
                }
                return true;
            }
        }
        controller.lost(game);
        return true;
    }
    return false;
}
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) UUID(java.util.UUID)

Example 77 with TargetControlledPermanent

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

the class NicolBolasDragonGodMinus8Effect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Boolean applied = false;
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.drawCards(1, source, game);
    Set<Card> cardsOnBattlefield = new LinkedHashSet<>();
    Set<Card> cards = new LinkedHashSet<>();
    for (UUID opponentId : game.getState().getPlayersInRange(player.getId(), game)) {
        if (!player.hasOpponent(opponentId, game)) {
            continue;
        }
        Player opponent = game.getPlayer(opponentId);
        if (opponent == null) {
            continue;
        }
        List<Target> possibleTargetTypes = new ArrayList<>();
        // hand
        TargetCardInHand targetHand = new TargetCardInHand();
        if (!opponent.getHand().isEmpty()) {
            possibleTargetTypes.add(targetHand);
        }
        // permanent
        TargetPermanent targetPermanent = new TargetControlledPermanent();
        targetPermanent.setNotTarget(true);
        targetPermanent.setTargetController(opponentId);
        if (!targetPermanent.possibleTargets(opponentId, game).isEmpty()) {
            possibleTargetTypes.add(targetPermanent);
        }
        // choose target type first, AI must use hand first (benefit)
        if (possibleTargetTypes.size() > 1 && !opponent.chooseUse(Outcome.Benefit, "Exile a card in your hand or a permanent you control?", null, "Card in hand", "Permanent", source, game)) {
            // change order (permanent goes first)
            Collections.reverse(possibleTargetTypes);
        }
        // choose target
        for (Target target : possibleTargetTypes) {
            // hand
            if (target.equals(targetHand)) {
                if (opponent.choose(Outcome.Exile, opponent.getHand(), targetHand, game) && game.getCard(targetHand.getFirstTarget()) != null) {
                    cards.add(game.getCard(targetHand.getFirstTarget()));
                    break;
                }
            }
            // permanent
            if (target.equals(targetPermanent)) {
                if (opponent.choose(Outcome.Exile, targetPermanent, source.getSourceId(), game)) {
                    MageObject mageObject = game.getObject(targetPermanent.getFirstTarget());
                    if (mageObject instanceof Permanent) {
                        cardsOnBattlefield.add((Card) mageObject);
                        break;
                    }
                }
            }
        }
    }
    cards.addAll(cardsOnBattlefield);
    for (Card card : cards) {
        if (card != null) {
            Player owner = game.getPlayer(card.getOwnerId());
            if (owner != null && owner.moveCards(card, Zone.EXILED, source, game)) {
                applied = true;
            }
        }
    }
    return applied;
}
Also used : Player(mage.players.Player) FilterCreatureOrPlaneswalkerPermanent(mage.filter.common.FilterCreatureOrPlaneswalkerPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterPlaneswalkerPermanent(mage.filter.common.FilterPlaneswalkerPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) MageObject(mage.MageObject) Card(mage.cards.Card) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Target(mage.target.Target) TargetPermanent(mage.target.TargetPermanent)

Example 78 with TargetControlledPermanent

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

the class RenounceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int amount = 0;
    TargetControlledPermanent toSacrifice = new TargetControlledPermanent(0, Integer.MAX_VALUE, new FilterControlledPermanent(), true);
    if (player.chooseTarget(Outcome.Sacrifice, toSacrifice, source, game)) {
        for (UUID uuid : toSacrifice.getTargets()) {
            Permanent permanent = game.getPermanent(uuid);
            if (permanent != null) {
                permanent.sacrifice(source, game);
                amount++;
            }
        }
        player.gainLife(amount * 2, game, source);
    }
    return 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) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) UUID(java.util.UUID)

Example 79 with TargetControlledPermanent

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

the class VirtussManeuverEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    ChooseFriendsAndFoes choice = new ChooseFriendsAndFoes();
    if (controller != null && !choice.chooseFriendOrFoe(controller, source, game)) {
        return false;
    }
    Map<UUID, Card> getBackMap = new HashMap<>();
    for (Player player : choice.getFriends()) {
        if (player == null) {
            continue;
        }
        FilterCard filter = new FilterCreatureCard("creature card in your graveyard");
        filter.add(new OwnerIdPredicate(player.getId()));
        TargetCardInGraveyard target = new TargetCardInGraveyard(filter);
        getBackMap.put(player.getId(), null);
        if (player.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
            getBackMap.put(player.getId(), game.getCard(target.getFirstTarget()));
        }
    }
    for (Player player : choice.getFriends()) {
        if (player == null) {
            continue;
        }
        Card card = getBackMap.getOrDefault(player.getId(), null);
        if (card == null) {
            continue;
        }
        player.moveCards(card, Zone.HAND, source, game);
    }
    List<UUID> perms = new ArrayList<>();
    for (Player player : choice.getFoes()) {
        if (player == null) {
            continue;
        }
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, StaticFilters.FILTER_CONTROLLED_A_CREATURE, true);
        player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        perms.addAll(target.getTargets());
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) ChooseFriendsAndFoes(mage.choices.ChooseFriendsAndFoes) UUID(java.util.UUID)

Example 80 with TargetControlledPermanent

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

the class WarrenWeirdingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (player == null) {
        return false;
    }
    FilterControlledPermanent filter = new FilterControlledPermanent("creature");
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(new ControllerIdPredicate(player.getId()));
    TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
    // had, if thats the case this ability should fizzle.
    if (target.canChoose(source.getSourceId(), player.getId(), game)) {
        player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            permanent.sacrifice(source, game);
            if (filterGoblin.match(permanent, game)) {
                for (int i = 0; i < 2; i++) {
                    Token token = new GoblinRogueToken();
                    Effect effect = new CreateTokenTargetEffect(token);
                    effect.setTargetPointer(new FixedTarget(player.getId()));
                    if (effect.apply(game, source)) {
                        Permanent tokenPermanent = game.getPermanent(token.getLastAddedToken());
                        if (tokenPermanent != null) {
                            ContinuousEffect hasteEffect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
                            hasteEffect.setTargetPointer(new FixedTarget(tokenPermanent.getId()));
                            game.addEffect(hasteEffect, source);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) CreateTokenTargetEffect(mage.abilities.effects.common.CreateTokenTargetEffect) GoblinRogueToken(mage.game.permanent.token.GoblinRogueToken) Token(mage.game.permanent.token.Token) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) GoblinRogueToken(mage.game.permanent.token.GoblinRogueToken) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) CreateTokenTargetEffect(mage.abilities.effects.common.CreateTokenTargetEffect) Effect(mage.abilities.effects.Effect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

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