use of mage.target.common.TargetOpponent in project mage by magefree.
the class DemonstrateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Spell spell = (Spell) getValue("spellCast");
if (spell == null) {
return false;
}
spell.createCopyOnStack(game, source, source.getControllerId(), true);
TargetOpponent target = new TargetOpponent(true);
controller.choose(outcome, target, source.getSourceId(), game);
if (game.getPlayer(target.getFirstTarget()) != null) {
spell.createCopyOnStack(game, source, target.getFirstTarget(), true);
}
return true;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class EpiphanyAtTheDrownyardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || sourceObject == null) {
return false;
}
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX() + 1));
controller.revealCards(sourceObject.getIdName(), cards, game);
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());
}
if (opponent != null) {
TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
List<Card> pile1 = new ArrayList<>();
Cards pile1CardsIds = new CardsImpl();
target.setRequired(false);
if (controller.choose(Outcome.Neutral, cards, target, game)) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = game.getCard(targetId);
if (card != null) {
pile1.add(card);
pile1CardsIds.add(card.getId());
}
}
}
List<Card> pile2 = new ArrayList<>();
Cards pile2CardsIds = new CardsImpl();
for (UUID cardId : cards) {
Card card = game.getCard(cardId);
if (card != null && !pile1.contains(card)) {
pile2.add(card);
pile2CardsIds.add(card.getId());
}
}
boolean choice = opponent.choosePile(Outcome.Detriment, "Choose a pile to put into " + controller.getName() + "'s hand.", pile1, pile2, game);
Zone pile1Zone = Zone.GRAVEYARD;
Zone pile2Zone = Zone.HAND;
if (choice) {
pile1Zone = Zone.HAND;
pile2Zone = Zone.GRAVEYARD;
}
StringBuilder sb = new StringBuilder(sourceObject.getLogName() + ": Pile 1, going to ").append(pile1Zone == Zone.HAND ? "Hand" : "Graveyard").append(": ");
int i = 0;
for (UUID cardUuid : pile1CardsIds) {
i++;
Card card = game.getCard(cardUuid);
if (card != null) {
sb.append(GameLog.getColoredObjectName(card));
if (i < pile1CardsIds.size()) {
sb.append(", ");
}
}
}
controller.moveCards(new CardsImpl(pile1CardsIds), pile1Zone, source, game);
game.informPlayers(sb.toString());
sb = new StringBuilder(sourceObject.getLogName() + ": Pile 2, going to ").append(pile2Zone == Zone.HAND ? "Hand" : "Graveyard").append(':');
i = 0;
for (UUID cardUuid : pile2CardsIds) {
Card card = game.getCard(cardUuid);
if (card != null) {
i++;
sb.append(' ').append(GameLog.getColoredObjectName(card));
if (i < pile2CardsIds.size()) {
sb.append(", ");
}
}
}
controller.moveCards(new CardsImpl(pile2CardsIds), pile2Zone, source, game);
game.informPlayers(sb.toString());
}
return true;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class GuidedPassageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || sourceObject == null) {
return false;
}
int libSize = controller.getLibrary().size();
if (libSize == 0) {
controller.shuffleLibrary(source, game);
return true;
}
CardsImpl cards = new CardsImpl();
cards.addAll(controller.getLibrary().getTopCards(game, libSize));
controller.revealCards(sourceObject.getIdName(), cards, game);
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 target1 = new TargetCard(1, Zone.LIBRARY, StaticFilters.FILTER_CARD_CREATURE);
TargetCard target2 = new TargetCard(1, Zone.LIBRARY, StaticFilters.FILTER_CARD_LAND);
TargetCard target3 = new TargetCard(1, Zone.LIBRARY, new FilterCard(filter));
opponent.chooseTarget(Outcome.Detriment, cards, target1, source, game);
opponent.chooseTarget(Outcome.Detriment, cards, target2, source, game);
opponent.chooseTarget(Outcome.Detriment, cards, target3, source, game);
Cards cardsToHand = new CardsImpl();
Card cardToHand;
cardToHand = game.getCard(target1.getFirstTarget());
if (cardToHand != null) {
cardsToHand.add(cardToHand);
}
cardToHand = game.getCard(target2.getFirstTarget());
if (cardToHand != null) {
cardsToHand.add(cardToHand);
}
cardToHand = game.getCard(target3.getFirstTarget());
if (cardToHand != null) {
cardsToHand.add(cardToHand);
}
controller.moveCards(cardsToHand, Zone.HAND, source, game);
controller.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class IntellectualOfferingUntapEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Target target = new TargetOpponent(true);
target.choose(Outcome.Untap, source.getControllerId(), source.getSourceId(), game);
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterNonlandPermanent(), player.getId(), game)) {
permanent.untap(game);
}
Player opponent = game.getPlayer(target.getFirstTarget());
if (opponent != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterNonlandPermanent(), opponent.getId(), game)) {
permanent.untap(game);
}
return true;
}
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class LyndeCheerfulTormentorAttachCurseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
TargetPermanent targetPermanent = new TargetPermanent(filter);
targetPermanent.setNotTarget(true);
if (controller.chooseTarget(outcome, targetPermanent, source, game)) {
Permanent curse = game.getPermanent(targetPermanent.getFirstTarget());
if (curse != null) {
TargetOpponent targetOpponent = new TargetOpponent(true);
if (controller.chooseTarget(Outcome.Detriment, targetOpponent, source, game)) {
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent != null) {
controller.removeAttachment(curse, source, game);
opponent.addAttachment(curse.getId(), source, game);
controller.drawCards(2, source, game);
return true;
}
}
}
}
}
return false;
}
Aggregations