Search in sources :

Example 36 with TargetOpponent

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

the class DemonstrateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Spell spell = (Spell) getValue("spellCast");
    if (spell == null) {
        return false;
    }
    spell.createCopyOnStack(game, source, source.getControllerId(), true);
    TargetOpponent target = new TargetOpponent(true);
    controller.choose(outcome, target, source.getSourceId(), game);
    if (game.getPlayer(target.getFirstTarget()) != null) {
        spell.createCopyOnStack(game, source, target.getFirstTarget(), true);
    }
    return true;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Spell(mage.game.stack.Spell)

Example 37 with TargetOpponent

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

the class EpiphanyAtTheDrownyardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX() + 1));
    controller.revealCards(sourceObject.getIdName(), cards, game);
    Player opponent;
    Set<UUID> opponents = game.getOpponents(controller.getId());
    if (opponents.size() == 1) {
        opponent = game.getPlayer(opponents.iterator().next());
    } else {
        Target target = new TargetOpponent(true);
        controller.chooseTarget(Outcome.Detriment, target, source, game);
        opponent = game.getPlayer(target.getFirstTarget());
    }
    if (opponent != null) {
        TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
        List<Card> pile1 = new ArrayList<>();
        Cards pile1CardsIds = new CardsImpl();
        target.setRequired(false);
        if (controller.choose(Outcome.Neutral, cards, target, game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
                Card card = game.getCard(targetId);
                if (card != null) {
                    pile1.add(card);
                    pile1CardsIds.add(card.getId());
                }
            }
        }
        List<Card> pile2 = new ArrayList<>();
        Cards pile2CardsIds = new CardsImpl();
        for (UUID cardId : cards) {
            Card card = game.getCard(cardId);
            if (card != null && !pile1.contains(card)) {
                pile2.add(card);
                pile2CardsIds.add(card.getId());
            }
        }
        boolean choice = opponent.choosePile(Outcome.Detriment, "Choose a pile to put into " + controller.getName() + "'s hand.", pile1, pile2, game);
        Zone pile1Zone = Zone.GRAVEYARD;
        Zone pile2Zone = Zone.HAND;
        if (choice) {
            pile1Zone = Zone.HAND;
            pile2Zone = Zone.GRAVEYARD;
        }
        StringBuilder sb = new StringBuilder(sourceObject.getLogName() + ": Pile 1, going to ").append(pile1Zone == Zone.HAND ? "Hand" : "Graveyard").append(": ");
        int i = 0;
        for (UUID cardUuid : pile1CardsIds) {
            i++;
            Card card = game.getCard(cardUuid);
            if (card != null) {
                sb.append(GameLog.getColoredObjectName(card));
                if (i < pile1CardsIds.size()) {
                    sb.append(", ");
                }
            }
        }
        controller.moveCards(new CardsImpl(pile1CardsIds), pile1Zone, source, game);
        game.informPlayers(sb.toString());
        sb = new StringBuilder(sourceObject.getLogName() + ": Pile 2, going to ").append(pile2Zone == Zone.HAND ? "Hand" : "Graveyard").append(':');
        i = 0;
        for (UUID cardUuid : pile2CardsIds) {
            Card card = game.getCard(cardUuid);
            if (card != null) {
                i++;
                sb.append(' ').append(GameLog.getColoredObjectName(card));
                if (i < pile2CardsIds.size()) {
                    sb.append(", ");
                }
            }
        }
        controller.moveCards(new CardsImpl(pile2CardsIds), pile2Zone, source, game);
        game.informPlayers(sb.toString());
    }
    return true;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Zone(mage.constants.Zone) MageObject(mage.MageObject) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) UUID(java.util.UUID)

Example 38 with TargetOpponent

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

the class GuidedPassageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller == null || sourceObject == null) {
        return false;
    }
    int libSize = controller.getLibrary().size();
    if (libSize == 0) {
        controller.shuffleLibrary(source, game);
        return true;
    }
    CardsImpl cards = new CardsImpl();
    cards.addAll(controller.getLibrary().getTopCards(game, libSize));
    controller.revealCards(sourceObject.getIdName(), cards, game);
    Player opponent;
    Set<UUID> opponents = game.getOpponents(controller.getId());
    if (opponents.size() == 1) {
        opponent = game.getPlayer(opponents.iterator().next());
    } else {
        Target target = new TargetOpponent(true);
        controller.chooseTarget(Outcome.Detriment, target, source, game);
        opponent = game.getPlayer(target.getFirstTarget());
    }
    TargetCard target1 = new TargetCard(1, Zone.LIBRARY, StaticFilters.FILTER_CARD_CREATURE);
    TargetCard target2 = new TargetCard(1, Zone.LIBRARY, StaticFilters.FILTER_CARD_LAND);
    TargetCard target3 = new TargetCard(1, Zone.LIBRARY, new FilterCard(filter));
    opponent.chooseTarget(Outcome.Detriment, cards, target1, source, game);
    opponent.chooseTarget(Outcome.Detriment, cards, target2, source, game);
    opponent.chooseTarget(Outcome.Detriment, cards, target3, source, game);
    Cards cardsToHand = new CardsImpl();
    Card cardToHand;
    cardToHand = game.getCard(target1.getFirstTarget());
    if (cardToHand != null) {
        cardsToHand.add(cardToHand);
    }
    cardToHand = game.getCard(target2.getFirstTarget());
    if (cardToHand != null) {
        cardsToHand.add(cardToHand);
    }
    cardToHand = game.getCard(target3.getFirstTarget());
    if (cardToHand != null) {
        cardsToHand.add(cardToHand);
    }
    controller.moveCards(cardsToHand, Zone.HAND, source, game);
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Cards(mage.cards.Cards) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 39 with TargetOpponent

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

the class IntellectualOfferingUntapEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Target target = new TargetOpponent(true);
        target.choose(Outcome.Untap, source.getControllerId(), source.getSourceId(), game);
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterNonlandPermanent(), player.getId(), game)) {
            permanent.untap(game);
        }
        Player opponent = game.getPlayer(target.getFirstTarget());
        if (opponent != null) {
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterNonlandPermanent(), opponent.getId(), game)) {
                permanent.untap(game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 40 with TargetOpponent

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

the class LyndeCheerfulTormentorAttachCurseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        TargetPermanent targetPermanent = new TargetPermanent(filter);
        targetPermanent.setNotTarget(true);
        if (controller.chooseTarget(outcome, targetPermanent, source, game)) {
            Permanent curse = game.getPermanent(targetPermanent.getFirstTarget());
            if (curse != null) {
                TargetOpponent targetOpponent = new TargetOpponent(true);
                if (controller.chooseTarget(Outcome.Detriment, targetOpponent, source, game)) {
                    Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
                    if (opponent != null) {
                        controller.removeAttachment(curse, source, game);
                        opponent.addAttachment(curse.getId(), source, game);
                        controller.drawCards(2, source, game);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) TargetOpponent(mage.target.common.TargetOpponent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Aggregations

Player (mage.players.Player)67 TargetOpponent (mage.target.common.TargetOpponent)67 Target (mage.target.Target)35 UUID (java.util.UUID)25 MageObject (mage.MageObject)22 TargetCard (mage.target.TargetCard)22 FilterCard (mage.filter.FilterCard)21 Permanent (mage.game.permanent.Permanent)20 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)12 ArrayList (java.util.ArrayList)8 CardsImpl (mage.cards.CardsImpl)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 Cards (mage.cards.Cards)7 Zone (mage.constants.Zone)6 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)6 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)5 Effect (mage.abilities.effects.Effect)4 OneShotEffect (mage.abilities.effects.OneShotEffect)4 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)4