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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations