use of mage.target.common.TargetOpponent in project mage by magefree.
the class DeathOrGloryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cards = new CardsImpl(controller.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game));
if (!cards.isEmpty()) {
TargetCard targetCards = new TargetCard(0, cards.size(), Zone.EXILED, new FilterCard("cards to put in the first pile"));
List<Card> pile1 = new ArrayList<>();
if (controller.choose(Outcome.Neutral, cards, targetCards, game)) {
List<UUID> targets = targetCards.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));
StringBuilder sb = new StringBuilder("First pile of ").append(controller.getLogName()).append(": ");
sb.append(pile1.stream().map(Card::getLogName).collect(Collectors.joining(", ")));
game.informPlayers(sb.toString());
sb = new StringBuilder("Second pile of ").append(controller.getLogName()).append(": ");
sb.append(pile2.stream().map(Card::getLogName).collect(Collectors.joining(", ")));
game.informPlayers(sb.toString());
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 choose their pile");
}
}
if (opponent != null) {
boolean choice = opponent.choosePile(outcome, "Choose a pile to put onto the battlefield.", pile1, pile2, game);
Zone pile1Zone = Zone.EXILED;
Zone pile2Zone = Zone.BATTLEFIELD;
if (choice) {
pile1Zone = Zone.BATTLEFIELD;
pile2Zone = Zone.EXILED;
}
Set<Card> pile1Set = new HashSet<>();
Set<Card> pile2Set = new HashSet<>();
pile1Set.addAll(pile1);
pile2Set.addAll(pile2);
controller.moveCards(pile1Set, pile1Zone, source, game, false, false, false, null);
controller.moveCards(pile2Set, pile2Zone, source, game, false, false, false, null);
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class BrilliantUltimatumEffect 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 pile2 = new CardsImpl();
pile2.addAll(controller.getLibrary().getTopCards(game, 5));
controller.moveCardsToExile(pile2.getCards(game), source, game, true, source.getSourceId(), sourceObject.getIdName());
TargetOpponent targetOpponent = new TargetOpponent(true);
targetOpponent.choose(outcome, source.getControllerId(), source.getSourceId(), game);
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent != null) {
TargetCard target = new TargetCard(0, pile2.size(), Zone.EXILED, new FilterCard("cards to put in the first pile"));
target.setRequired(false);
Cards pile1 = new CardsImpl();
List<Card> pileOne = new ArrayList<>();
List<Card> pileTwo = new ArrayList<>();
if (opponent.choose(Outcome.Neutral, pile2, target, game)) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = pile2.get(targetId, game);
if (card != null) {
pile1.add(card);
pile2.remove(card);
}
}
}
pileOne.addAll(pile1.getCards(game));
pileTwo.addAll(pile2.getCards(game));
controller.revealCards("Pile 1 - " + sourceObject.getIdName(), pile1, game);
controller.revealCards("Pile 2 - " + sourceObject.getIdName(), pile2, game);
boolean choice = controller.choosePile(Outcome.PlayForFree, "Which pile (play for free)?", pileOne, pileTwo, game);
String selectedPileName;
List<Card> selectedPileCards;
Cards selectedPile;
if (choice) {
selectedPileName = "pile 1";
selectedPileCards = pileOne;
selectedPile = pile1;
} else {
selectedPileName = "pile 2";
selectedPileCards = pileTwo;
selectedPile = pile2;
}
game.informPlayers(controller.getLogName() + " chose " + selectedPileName + '.');
while (!selectedPileCards.isEmpty() && controller.chooseUse(Outcome.PlayForFree, "Play a card for free from " + selectedPileName + '?', source, game)) {
TargetCard targetExiledCard = new TargetCard(Zone.EXILED, new FilterCard());
if (controller.chooseTarget(Outcome.PlayForFree, selectedPile, targetExiledCard, source, game)) {
Card card = selectedPile.get(targetExiledCard.getFirstTarget(), game);
if (controller.playCard(card, game, true, new ApprovingObject(source, game))) {
selectedPileCards.remove(card);
selectedPile.remove(card);
}
}
}
return true;
}
return false;
}
Aggregations