Search in sources :

Example 51 with TargetOpponent

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

the class InfernalOfferingReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetOpponent(true);
        target.choose(Outcome.PutCreatureInPlay, source.getControllerId(), source.getSourceId(), game);
        Player opponent = game.getPlayer(target.getFirstTarget());
        target = new TargetCardInYourGraveyard(new FilterCreatureCard("creature card in your graveyard"));
        if (target.choose(Outcome.PutCreatureInPlay, controller.getId(), source.getSourceId(), game)) {
            Card card = controller.getGraveyard().get(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            }
        }
        if (opponent != null) {
            target = new TargetCardInYourGraveyard(new FilterCreatureCard("creature card in your graveyard"));
            if (target.choose(Outcome.PutCreatureInPlay, opponent.getId(), source.getSourceId(), game)) {
                Card card = opponent.getGraveyard().get(target.getFirstTarget(), game);
                if (card != null) {
                    opponent.moveCards(card, Zone.BATTLEFIELD, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 52 with TargetOpponent

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

the class IngeniousMasteryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    if (!AlternativeCostSourceAbility.getActivatedStatus(game, source, this.alternativeCostOriginalID, false)) {
        return player.drawCards(source.getManaCostsToPay().getX(), source, game) > 0;
    }
    player.drawCards(3, source, game);
    TargetOpponent targetOpponent = new TargetOpponent(true);
    if (!player.chooseTarget(Outcome.DrawCard, targetOpponent, source, game)) {
        return false;
    }
    Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
    if (opponent == null) {
        return false;
    }
    new TreasureToken().putOntoBattlefield(2, game, source, opponent.getId());
    opponent.scry(2, source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TreasureToken(mage.game.permanent.token.TreasureToken)

Example 53 with TargetOpponent

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

the class ExplosionOfRichesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        if (!playerId.equals(source.getControllerId()) && !player.chooseUse(outcome, "Draw a card?", source, game)) {
            continue;
        }
        if (player.drawCards(1, source, game) >= 1) {
            continue;
        }
        ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(5), false, "{this} deals damage to target opponent chosen at random");
        Target target = new TargetOpponent();
        target.setRandom(true);
        ability.addTarget(target);
        game.fireReflexiveTriggeredAbility(ability, source);
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) UUID(java.util.UUID) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect)

Example 54 with TargetOpponent

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

the class JaceArchitectOfThoughtEffect3 method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Cards allCards = new CardsImpl(player.getLibrary().getTopCards(game, 3));
    player.revealCards(source, allCards, game);
    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    if (!opponents.isEmpty()) {
        Player opponent = null;
        if (opponents.size() > 1) {
            TargetOpponent targetOpponent = new TargetOpponent();
            if (player.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
                opponent = game.getPlayer(targetOpponent.getFirstTarget());
            }
        }
        if (opponent == null) {
            opponent = game.getPlayer(opponents.iterator().next());
        }
        TargetCard target = new TargetCard(0, allCards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
        target.setNotTarget(true);
        opponent.choose(Outcome.Neutral, allCards, target, game);
        Cards pile1 = new CardsImpl(target.getTargets());
        Cards pile2 = new CardsImpl(allCards);
        pile2.removeAll(pile1);
        player.revealCards(source, "Pile 1", pile1, game);
        player.revealCards(source, "Pile 2", pile2, game);
        postPileToLog("Pile 1", pile1.getCards(game), game);
        postPileToLog("Pile 2", pile2.getCards(game), game);
        boolean pileChoice = player.choosePile(Outcome.Neutral, "Choose a pile to to put into your hand.", new ArrayList<>(pile1.getCards(game)), new ArrayList<>(pile2.getCards(game)), game);
        game.informPlayers(player.getLogName() + " chose pile" + (pileChoice ? "1" : "2"));
        player.moveCards(pileChoice ? pile1 : pile2, Zone.HAND, source, game);
        player.putCardsOnBottomOfLibrary(pileChoice ? pile2 : pile1, game, source, true);
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) FilterPlayer(mage.filter.FilterPlayer) TargetOpponent(mage.target.common.TargetOpponent) TargetCard(mage.target.TargetCard)

Example 55 with TargetOpponent

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

the class KarnMinus1Effect 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) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 2));
    if (cards.isEmpty()) {
        return true;
    }
    controller.revealCards(staticText, cards, game);
    Card cardToHand;
    if (cards.size() == 1) {
        cardToHand = 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);
        cardToHand = game.getCard(target.getFirstTarget());
    }
    if (cardToHand != null) {
        controller.moveCards(cardToHand, Zone.HAND, source, game);
        cards.remove(cardToHand);
    }
    if (!cards.isEmpty()) {
        controller.moveCards(cards, Zone.EXILED, source, game);
        for (Card c : cards.getCards(game)) {
            c.addCounters(CounterType.SILVER.createInstance(1), source.getControllerId(), 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) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

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