Search in sources :

Example 1 with TargetOpponent

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

the class BoneyardParleyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Cards cards = new CardsImpl();
        for (Target target : source.getTargets()) {
            for (UUID cardId : target.getTargets()) {
                cards.add(cardId);
            }
        }
        if (!cards.isEmpty() && player.moveCards(cards, Zone.EXILED, source, game)) {
            TargetOpponent targetOpponent = new TargetOpponent(true);
            if (player.choose(Outcome.Neutral, targetOpponent, source.getSourceId(), game)) {
                Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
                if (opponent != null) {
                    TargetCard targetCards = new TargetCard(0, cards.size(), Zone.EXILED, new FilterCard("cards to put in the first pile"));
                    List<Card> pile1 = new ArrayList<>();
                    if (opponent.choose(Outcome.Neutral, cards, targetCards, game)) {
                        List<UUID> targets = targetCards.getTargets();
                        for (UUID targetId : targets) {
                            Card card = cards.get(targetId, game);
                            if (card != null) {
                                pile1.add(card);
                                cards.remove(card);
                            }
                        }
                    }
                    List<Card> pile2 = new ArrayList<>();
                    pile2.addAll(cards.getCards(game));
                    boolean choice = player.choosePile(outcome, "Choose a pile to put onto the battlefield.", pile1, pile2, game);
                    Zone pile1Zone = Zone.GRAVEYARD;
                    Zone pile2Zone = Zone.BATTLEFIELD;
                    if (choice) {
                        pile1Zone = Zone.BATTLEFIELD;
                        pile2Zone = Zone.GRAVEYARD;
                    }
                    Set<Card> pile1Set = new HashSet<>();
                    Set<Card> pile2Set = new HashSet<>();
                    pile1Set.addAll(pile1);
                    pile2Set.addAll(pile2);
                    // Cards toBattlefield = new CardsImpl();
                    // Cards toGraveyard = new CardsImpl();
                    // 
                    // if (pile1Zone == Zone.BATTLEFIELD) {
                    // toBattlefield.addAll(pile1);
                    // toGraveyard.addAll(pile2);
                    // } else {
                    // toBattlefield.addAll(pile2);
                    // toGraveyard.addAll(pile1);
                    // }
                    player.moveCards(pile1Set, pile1Zone, source, game, false, false, false, null);
                    player.moveCards(pile2Set, pile2Zone, source, game, false, false, false, null);
                // StringBuilder sb = new StringBuilder("Pile 1, going to ").append(pile1Zone == Zone.BATTLEFIELD ? "Battlefield" : "Graveyard").append(": ");
                // game.informPlayers(sb.toString());
                // sb = new StringBuilder("Pile 2, going to ").append(pile2Zone == Zone.BATTLEFIELD ? "Battlefield" : "Graveyard").append(':');
                // game.informPlayers(sb.toString());
                }
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Zone(mage.constants.Zone) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) HashSet(java.util.HashSet)

Example 2 with TargetOpponent

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

the class DeliverUntoEvilEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards cards = new CardsImpl(source.getTargets().get(0).getTargets());
    if (cards.isEmpty()) {
        return false;
    }
    if (!game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game).isEmpty()) {
        return player.moveCards(cards, Zone.HAND, source, game);
    }
    TargetOpponent targetOpponent = new TargetOpponent();
    targetOpponent.setNotTarget(true);
    if (!player.choose(outcome, targetOpponent, source.getSourceId(), game)) {
        return false;
    }
    Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
    if (opponent == null) {
        return false;
    }
    TargetCard targetCard = new TargetCardInGraveyard(Math.min(2, cards.size()), filter2);
    if (!opponent.choose(outcome, cards, targetCard, game)) {
        return false;
    }
    cards.removeAll(targetCard.getTargets());
    return player.moveCards(cards, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 3 with TargetOpponent

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

the class MurmursFromBeyondEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
        if (!cards.isEmpty()) {
            controller.revealCards(staticText, cards, game);
            Card cardToGraveyard;
            if (cards.size() == 1) {
                cardToGraveyard = cards.getRandom(game);
            } else {
                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 target = new TargetCard(1, Zone.LIBRARY, new FilterCard());
                opponent.chooseTarget(outcome, cards, target, source, game);
                cardToGraveyard = game.getCard(target.getFirstTarget());
            }
            if (cardToGraveyard != null) {
                controller.moveCards(cardToGraveyard, Zone.GRAVEYARD, source, game);
                cards.remove(cardToGraveyard);
            }
            controller.moveCards(cards, Zone.HAND, source, game);
        }
        return true;
    }
    return false;
}
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) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 4 with TargetOpponent

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

the class NullChamberReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    TargetOpponent chosenOpponent = new TargetOpponent(true);
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getPermanentEntering(source.getSourceId());
    if (sourceObject == null) {
        sourceObject = source.getSourceObject(game);
    }
    if (controller == null || sourceObject == null) {
        return false;
    }
    controller.choose(Outcome.Neutral, chosenOpponent, source.getSourceId(), game);
    Player opponent = game.getPlayer(chosenOpponent.getFirstTarget());
    String cardName = ChooseACardNameEffect.TypeOfName.NOT_BASIC_LAND_NAME.getChoice(controller, game, source, false);
    if (cardName != null) {
        game.getState().setValue(source.getSourceId().toString() + INFO_KEY_CONTROLLER, cardName);
        if (sourceObject instanceof Permanent) {
            ((Permanent) sourceObject).addInfo(INFO_KEY_CONTROLLER, CardUtil.addToolTipMarkTags("Named card (Controller): " + cardName), game);
        }
    }
    if (opponent == null) {
        return true;
    }
    cardName = ChooseACardNameEffect.TypeOfName.NOT_BASIC_LAND_NAME.getChoice(opponent, game, source, false);
    if (cardName == null) {
        return true;
    }
    game.getState().setValue(source.getSourceId().toString() + INFO_KEY_OPPONENT, cardName);
    if (sourceObject instanceof Permanent) {
        ((Permanent) sourceObject).addInfo(INFO_KEY_OPPONENT, CardUtil.addToolTipMarkTags("Named card (Opponent): " + cardName), game);
    }
    return true;
}
Also used : TargetOpponent(mage.target.common.TargetOpponent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject)

Example 5 with TargetOpponent

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

the class OpponentGainControlEffect method init.

@Override
public void init(Ability source, Game game) {
    super.init(source, game);
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (controller != null && permanent != null) {
        if (game.getOpponents(controller.getId()).size() == 1) {
            opponentId = game.getOpponents(controller.getId()).iterator().next();
        } else {
            Target target = new TargetOpponent(true);
            controller.chooseTarget(outcome, target, source, game);
            opponentId = target.getFirstTarget();
        }
    }
    Player targetOpponent = game.getPlayer(opponentId);
    if (targetOpponent != null && permanent != null) {
        game.informPlayers(permanent.getLogName() + " is now controlled by " + targetOpponent.getLogName());
    } else {
        discard();
    }
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent)

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