Search in sources :

Example 61 with TargetOpponent

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

the class DemonicHordesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent demonicHordes = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && demonicHordes != null) {
        StringBuilder sb = new StringBuilder(cost.getText()).append('?');
        if (!sb.toString().toLowerCase(Locale.ENGLISH).startsWith("exile ") && !sb.toString().toLowerCase(Locale.ENGLISH).startsWith("return ")) {
            sb.insert(0, "Pay ");
        }
        if (controller.chooseUse(Outcome.Benefit, sb.toString(), source, game)) {
            cost.clearPaid();
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                return true;
            }
        }
        demonicHordes.tap(source, game);
        Target choiceOpponent = new TargetOpponent();
        choiceOpponent.setNotTarget(true);
        FilterLandPermanent filterLand = new FilterLandPermanent();
        filterLand.add(new ControllerIdPredicate(source.getControllerId()));
        if (controller.choose(Outcome.Neutral, choiceOpponent, source.getSourceId(), game)) {
            Player opponent = game.getPlayer(choiceOpponent.getFirstTarget());
            if (opponent != null) {
                Target chosenLand = new TargetLandPermanent(filterLand);
                chosenLand.setNotTarget(true);
                if (opponent.chooseTarget(Outcome.Sacrifice, chosenLand, source, game)) {
                    Permanent land = game.getPermanent(chosenLand.getFirstTarget());
                    if (land != null) {
                        land.sacrifice(source, game);
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetLandPermanent(mage.target.common.TargetLandPermanent)

Example 62 with TargetOpponent

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

the class AllureOfTheUnknownEffect 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(player.getLibrary().getTopCards(game, 6));
    player.revealCards(source, cards, game);
    if (cards.count(StaticFilters.FILTER_CARD_NON_LAND, game) == 0) {
        return player.moveCards(cards, Zone.HAND, source, game);
    }
    TargetOpponent targetOpponent = new TargetOpponent(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 TargetCardInLibrary(StaticFilters.FILTER_CARD_A_NON_LAND);
    opponent.choose(Outcome.Exile, cards, targetCard, game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (player.moveCards(card, Zone.EXILED, source, game) && card != null && game.getState().getZone(card.getId()) == Zone.EXILED) {
        cards.remove(card);
    }
    player.moveCards(cards, Zone.HAND, source, game);
    if (opponent.chooseUse(outcome, "Cast the exiled card without paying its mana cost?", source, game)) {
        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
        opponent.cast(opponent.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
    }
    return true;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) ApprovingObject(mage.ApprovingObject) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) TargetCard(mage.target.TargetCard)

Example 63 with TargetOpponent

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

the class BenevolentOfferingEffect2 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.Sacrifice, source.getControllerId(), source.getSourceId(), game);
        Player opponent = game.getPlayer(target.getFirstTarget());
        if (opponent != null) {
            int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game) * 2;
            controller.gainLife(count, game, source);
            count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game) * 2;
            opponent.gainLife(count, game, source);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) TargetOpponent(mage.target.common.TargetOpponent)

Example 64 with TargetOpponent

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

the class AnimalMagnetismEffect 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, 5));
        if (!cards.isEmpty()) {
            controller.revealCards(staticText, cards, game);
            Card cardToBattlefield;
            if (cards.size() == 1) {
                cardToBattlefield = 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, StaticFilters.FILTER_CARD_CREATURE);
                opponent.chooseTarget(outcome, cards, target, source, game);
                cardToBattlefield = game.getCard(target.getFirstTarget());
            }
            if (cardToBattlefield != null) {
                controller.moveCards(cardToBattlefield, Zone.BATTLEFIELD, source, game);
                cards.remove(cardToBattlefield);
            }
            controller.moveCards(cards, Zone.GRAVEYARD, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCard(mage.target.TargetCard)

Example 65 with TargetOpponent

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

the class BurningRuneDemonTarget method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        TargetCardInLibrary targetCardInLibrary = new BurningRuneDemonTarget();
        if (controller.searchLibrary(targetCardInLibrary, source, game)) {
            Cards cards = new CardsImpl(targetCardInLibrary.getTargets());
            if (!cards.isEmpty()) {
                Player opponent;
                Set<UUID> opponents = game.getOpponents(controller.getId());
                if (opponents.size() == 1) {
                    opponent = game.getPlayer(opponents.iterator().next());
                } else {
                    TargetOpponent targetOpponent = new TargetOpponent(true);
                    controller.chooseTarget(Outcome.Detriment, targetOpponent, source, game);
                    opponent = game.getPlayer(targetOpponent.getFirstTarget());
                }
                if (opponent != null) {
                    TargetCard targetCard = new TargetCard(Zone.LIBRARY, StaticFilters.FILTER_CARD);
                    targetCard.withChooseHint("Card to go to opponent's hand (other goes to graveyard)");
                    opponent.chooseTarget(outcome, cards, targetCard, source, game);
                    Card cardToHand = game.getCard(targetCard.getFirstTarget());
                    if (cardToHand != null) {
                        controller.moveCards(cardToHand, Zone.HAND, source, game);
                        cards.remove(cardToHand);
                    }
                    if (!cards.isEmpty()) {
                        controller.moveCards(cards, Zone.GRAVEYARD, source, game);
                    }
                }
            }
            controller.shuffleLibrary(source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) 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