Search in sources :

Example 56 with TargetOpponent

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

the class SorcerousSpyglassActivationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        TargetOpponent target = new TargetOpponent(true);
        if (player.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
            Player opponent = game.getPlayer(target.getFirstTarget());
            if (opponent != null) {
                MageObject sourceObject = game.getObject(source.getSourceId());
                player.lookAtCards(sourceObject != null ? sourceObject.getIdName() : null, opponent.getHand(), game);
                player.chooseUse(Outcome.Benefit, "Press Ok to name a card", "You won't be able to resize the window showing opponents hand once you do", "Ok", "", source, game);
            }
        }
    }
    return super.apply(game, source);
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) MageObject(mage.MageObject)

Example 57 with TargetOpponent

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

the class TasigurTheGoldenFangEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID opponentId = null;
        if (game.getOpponents(controller.getId()).size() > 1) {
            Target target = new TargetOpponent(true);
            if (controller.chooseTarget(outcome, target, source, game)) {
                opponentId = target.getFirstTarget();
            }
        } else {
            opponentId = game.getOpponents(controller.getId()).iterator().next();
        }
        if (opponentId != null) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                FilterNonlandCard filter = new FilterNonlandCard("nonland card from " + controller.getLogName() + " graveyard");
                filter.add(new OwnerIdPredicate(controller.getId()));
                Target target = new TargetCardInGraveyard(filter);
                target.setNotTarget(true);
                opponent.chooseTarget(outcome, target, source, game);
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) UUID(java.util.UUID) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 58 with TargetOpponent

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

the class ChooseOpponentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getPermanentEntering(source.getSourceId());
    if (mageObject == null) {
        mageObject = game.getObject(source.getSourceId());
    }
    if (controller != null && mageObject != null) {
        TargetOpponent target = new TargetOpponent(true);
        if (controller.choose(this.outcome, target, source.getSourceId(), game)) {
            Player chosenPlayer = game.getPlayer(target.getFirstTarget());
            if (chosenPlayer != null) {
                game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + chosenPlayer.getLogName());
                game.getState().setValue(mageObject.getId() + VALUE_KEY, target.getFirstTarget());
                if (mageObject instanceof Permanent) {
                    ((Permanent) mageObject).addInfo("chosen opponent", CardUtil.addToolTipMarkTags("Chosen player: " + chosenPlayer.getLogName()), game);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject)

Example 59 with TargetOpponent

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

the class ClashEffect 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 || game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CLASH, controller.getId(), source, controller.getId()))) {
        return false;
    }
    // choose opponent
    Target target = new TargetOpponent(true);
    target.setTargetName("an opponent to clash with");
    target.setNotTarget(true);
    if (!controller.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
        return false;
    }
    Player opponent = game.getPlayer(target.getFirstTarget());
    if (opponent == null) {
        return false;
    }
    int cmcController = Integer.MIN_VALUE;
    Card cardController = null;
    boolean topController = true;
    int cmcOpponent = Integer.MIN_VALUE;
    Card cardOpponent = null;
    boolean topOpponent = true;
    // Reveal top cards of involved players
    StringBuilder message = new StringBuilder("Clash: ");
    message.append(controller.getLogName());
    if (controller.getLibrary().hasCards()) {
        Cards cards = new CardsImpl();
        cardController = controller.getLibrary().getFromTop(game);
        cards.add(cardController);
        controller.revealCards(sourceObject.getIdName() + ": Clash card of " + controller.getName(), cards, game);
        cmcController = cardController.getManaValue();
        message.append(" (").append(cmcController).append(')');
    } else {
        message.append(" no card");
    }
    message.append(" vs. ").append(opponent.getLogName());
    if (opponent.getLibrary().hasCards()) {
        Cards cards = new CardsImpl();
        cardOpponent = opponent.getLibrary().getFromTop(game);
        cards.add(cardOpponent);
        opponent.revealCards(sourceObject.getIdName() + ": Clash card of " + opponent.getName(), cards, game);
        cmcOpponent = cardOpponent.getManaValue();
        message.append(" (").append(cmcOpponent).append(')');
    } else {
        message.append(" no card");
    }
    message.append(" - ");
    if (!game.isSimulation()) {
        if (cmcController > cmcOpponent) {
            message.append(controller.getLogName()).append(" won the clash");
            game.informPlayer(controller, "You won the clash!");
        } else if (cmcController < cmcOpponent) {
            message.append(opponent.getLogName()).append(" won the clash");
            game.informPlayer(controller, opponent.getLogName() + " won the clash!");
        } else {
            message.append(" no winner ");
        }
        game.informPlayers(message.toString());
    }
    // decide to put the cards on top or on the buttom of library in turn order beginning with the active player in turn order
    PlayerList playerList = game.getPlayerList().copy();
    playerList.setCurrent(game.getActivePlayerId());
    Player nextPlayer;
    do {
        Player current = playerList.getCurrent(game);
        if (cardController != null && current.getId().equals(controller.getId())) {
            topController = current.chooseUse(Outcome.Detriment, "Put " + cardController.getLogName() + " back on top of your library? (otherwise it goes to bottom)", source, game);
        }
        if (cardOpponent != null && current.getId().equals(opponent.getId())) {
            topOpponent = current.chooseUse(Outcome.Detriment, "Put " + cardOpponent.getLogName() + " back on top of your library? (otherwise it goes to bottom)", source, game);
        }
        nextPlayer = playerList.getNext(game, false);
    } while (nextPlayer != null && !nextPlayer.getId().equals(game.getActivePlayerId()));
    // put the cards back to library
    if (cardController != null) {
        controller.moveCardToLibraryWithInfo(cardController, source, game, Zone.LIBRARY, topController, true);
    }
    if (cardOpponent != null) {
        opponent.moveCardToLibraryWithInfo(cardOpponent, source, game, Zone.LIBRARY, topOpponent, true);
    }
    // fire CLASHED event with info about who won
    game.fireEvent(new GameEvent(GameEvent.EventType.CLASHED, controller.getId(), source, opponent.getId(), 0, cmcController > cmcOpponent));
    game.fireEvent(new GameEvent(GameEvent.EventType.CLASHED, opponent.getId(), source, controller.getId(), 0, cmcOpponent > cmcController));
    // set opponent to DoIfClashWonEffect
    for (Effect effect : source.getEffects()) {
        if (effect instanceof DoIfClashWonEffect) {
            effect.setValue("clashOpponent", opponent);
        }
    }
    return cmcController > cmcOpponent;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) PlayerList(mage.players.PlayerList) MageObject(mage.MageObject) Card(mage.cards.Card) Target(mage.target.Target) GameEvent(mage.game.events.GameEvent) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 60 with TargetOpponent

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

the class CallousOppressorChooseCreatureTypeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getPermanentEntering(source.getSourceId());
    if (mageObject == null) {
        mageObject = game.getObject(source.getSourceId());
    }
    if (controller != null) {
        TargetOpponent target = new TargetOpponent(true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
                controller.chooseTarget(outcome, target, source, game);
            }
        } else {
            return false;
        }
        Player opponent = game.getPlayer(target.getFirstTarget());
        if (opponent != null && mageObject != null) {
            Choice typeChoice = new ChoiceCreatureType(mageObject);
            typeChoice.setMessage("Choose creature type");
            if (!opponent.choose(outcome, typeChoice, game)) {
                return false;
            }
            if (typeChoice.getChoice() == null) {
                return false;
            }
            if (!game.isSimulation()) {
                game.informPlayers(mageObject.getName() + ": " + opponent.getLogName() + " has chosen " + typeChoice.getChoice());
            }
            game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
            if (mageObject instanceof Permanent) {
                ((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Choice(mage.choices.Choice) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) MageObject(mage.MageObject) ChoiceCreatureType(mage.choices.ChoiceCreatureType)

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