Search in sources :

Example 31 with TargetOpponent

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

the class ZaffaiThunderConductorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.scry(1, source, game);
    Spell spell = (Spell) getValue(MagecraftAbility.SPELL_KEY);
    if (spell == null || spell.getManaValue() < 5) {
        return true;
    }
    new Elemental44Token().putOntoBattlefield(1, game, source, source.getControllerId());
    if (spell.getManaValue() < 10) {
        return true;
    }
    TargetOpponent target = new TargetOpponent(true);
    target.setRandom(true);
    target.chooseTarget(Outcome.Damage, player.getId(), source, game);
    Player opponent = game.getPlayer(target.getFirstTarget());
    if (opponent != null) {
        opponent.damage(10, source.getSourceId(), source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Elemental44Token(mage.game.permanent.token.Elemental44Token) Spell(mage.game.stack.Spell)

Example 32 with TargetOpponent

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

the class FactOrFictionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
    controller.revealCards(sourceObject.getName(), cards, game);
    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    if (!opponents.isEmpty()) {
        Player opponent = game.getPlayer(opponents.iterator().next());
        if (opponents.size() > 1) {
            Target targetOpponent = new TargetOpponent(true);
            if (controller.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
                opponent = game.getPlayer(targetOpponent.getFirstTarget());
                game.informPlayers(controller.getLogName() + " chose " + opponent.getLogName() + " to separate the revealed cards");
            }
        }
        TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
        List<Card> pile1 = new ArrayList<>();
        if (opponent.choose(Outcome.Neutral, cards, target, game)) {
            List<UUID> targets = target.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 = controller.choosePile(outcome, "Choose a pile to put into your hand.", pile1, pile2, game);
        Zone pile1Zone = Zone.GRAVEYARD;
        Zone pile2Zone = Zone.HAND;
        if (choice) {
            pile1Zone = Zone.HAND;
            pile2Zone = Zone.GRAVEYARD;
        }
        StringBuilder sb = new StringBuilder("Pile 1, going to ").append(pile1Zone == Zone.HAND ? "Hand" : "Graveyard").append(": ");
        int i = 0;
        for (Card card : pile1) {
            i++;
            sb.append(card.getName());
            if (i < pile1.size()) {
                sb.append(", ");
            }
        }
        cards.clear();
        cards.addAll(pile1);
        controller.moveCards(cards, pile1Zone, source, game);
        game.informPlayers(sb.toString());
        sb = new StringBuilder("Pile 2, going to ").append(pile2Zone == Zone.HAND ? "Hand" : "Graveyard").append(':');
        i = 0;
        for (Card card : pile2) {
            i++;
            sb.append(' ').append(card.getName());
            if (i < pile2.size()) {
                sb.append(", ");
            }
        }
        cards.clear();
        cards.addAll(pile2);
        controller.moveCards(cards, 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 33 with TargetOpponent

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

the class StandOrFallEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // 802.2. As the combat phase starts, the attacking player doesn’t choose an opponent to become the defending player.
    // Instead, all the attacking player’s opponents are defending players during the combat phase.
    // 
    // 802.2a Any rule, object, or effect that refers to a “defending player” refers to one specific defending player, not to all of the defending players.
    // If an ability of an attacking creature refers to a defending player, or a spell or ability refers to both an attacking creature and a defending player,
    // then unless otherwise specified, the defending player it’s referring to is the player that creature was attacking at the time it became an attacking
    // creature that combat, or the controller of the planeswalker that creature was attacking at the time it became an attacking creature that combat. If a spell or ability
    // could apply to multiple attacking creatures, the appropriate defending player is individually determined for each of those attacking creatures.
    // If there are multiple defending players that could be chosen, the controller of the spell or ability chooses one.
    // 
    // https://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/756140-stand-or-fall-mechanics
    Player player = game.getPlayer(source.getControllerId());
    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    if (!opponents.isEmpty()) {
        Player targetPlayer = game.getPlayer(opponents.iterator().next());
        if (opponents.size() > 1) {
            TargetOpponent targetOpponent = new TargetOpponent(true);
            if (player != null && player.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
                targetPlayer = game.getPlayer(targetOpponent.getFirstTarget());
                game.informPlayers(player.getLogName() + " chose " + targetPlayer.getLogName() + " as the defending player");
            }
        }
        if (player != null && targetPlayer != null) {
            int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
            TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
            List<Permanent> pile1 = new ArrayList<>();
            creatures.setRequired(false);
            if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
                List<UUID> targets = creatures.getTargets();
                for (UUID targetId : targets) {
                    Permanent p = game.getPermanent(targetId);
                    if (p != null) {
                        pile1.add(p);
                    }
                }
            }
            List<Permanent> pile2 = new ArrayList<>();
            for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
                if (!pile1.contains(p)) {
                    pile2.add(p);
                }
            }
            boolean choice = targetPlayer.choosePile(outcome, "Choose which pile can block this turn.", pile1, pile2, game);
            List<Permanent> chosenPile = choice ? pile2 : pile1;
            List<Permanent> otherPile = choice ? pile1 : pile2;
            for (Permanent permanent : chosenPile) {
                if (permanent != null) {
                    RestrictionEffect effect = new CantBlockTargetEffect(Duration.EndOfTurn);
                    effect.setText("");
                    effect.setTargetPointer(new FixedTarget(permanent, game));
                    game.addEffect(effect, source);
                }
            }
            game.informPlayers("Creatures that can block this turn: " + otherPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CantBlockTargetEffect(mage.abilities.effects.common.combat.CantBlockTargetEffect) ArrayList(java.util.ArrayList) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) UUID(java.util.UUID) RestrictionEffect(mage.abilities.effects.RestrictionEffect)

Example 34 with TargetOpponent

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

the class ThranTomeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // validate source and controller exist
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject == null || controller == null) {
        return false;
    }
    // target an opponent, if able
    Player opponent;
    Set<UUID> opponents = game.getOpponents(controller.getId());
    opponents.removeIf(opp -> !game.getPlayer(opp).canBeTargetedBy(sourceObject, source.getControllerId(), game));
    if (opponents.isEmpty()) {
        return false;
    } else {
        if (opponents.size() == 1) {
            opponent = game.getPlayer(opponents.iterator().next());
        } else {
            Target target = new TargetOpponent();
            controller.chooseTarget(Outcome.Detriment, target, source, game);
            opponent = game.getPlayer(target.getFirstTarget());
        }
    }
    // reveal the cards and choose one. put it in the graveyard
    Card cardToGraveyard;
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
    controller.revealCards(sourceObject.getIdName(), cards, game);
    if (cards.size() == 1) {
        cardToGraveyard = cards.getRandom(game);
    } else {
        TargetCardInLibrary target = new TargetCardInLibrary(1, new FilterCard());
        opponent.chooseTarget(outcome, cards, target, source, game);
        cardToGraveyard = game.getCard(target.getFirstTarget());
    }
    // put the chosen card in the graveyard
    if (cardToGraveyard != null) {
        controller.moveCards(cardToGraveyard, Zone.GRAVEYARD, source, game);
        cards.remove(cardToGraveyard);
    }
    // draw 2
    controller.drawCards(2, 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) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard)

Example 35 with TargetOpponent

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

the class OpponentCreateSurvivorTokenCost method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Player controller = game.getPlayer(controllerId);
    if (controller != null) {
        TargetOpponent target = new TargetOpponent();
        if (controller.chooseTarget(Outcome.Neutral, target, ability, game)) {
            Player opponent = game.getPlayer(target.getFirstTarget());
            if (opponent != null) {
                Effect effect = new CreateTokenTargetEffect(new SurvivorToken());
                effect.setTargetPointer(new FixedTarget(opponent.getId(), game));
                paid = effect.apply(game, ability);
            }
        }
    }
    return paid;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) CreateTokenTargetEffect(mage.abilities.effects.common.CreateTokenTargetEffect) CreateTokenTargetEffect(mage.abilities.effects.common.CreateTokenTargetEffect) Effect(mage.abilities.effects.Effect) SurvivorToken(mage.game.permanent.token.SurvivorToken)

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