use of mage.cards.Cards in project mage by magefree.
the class BoneyardParleyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Cards cards = new CardsImpl();
for (Target target : source.getTargets()) {
for (UUID cardId : target.getTargets()) {
cards.add(cardId);
}
}
if (!cards.isEmpty() && player.moveCards(cards, Zone.EXILED, source, game)) {
TargetOpponent targetOpponent = new TargetOpponent(true);
if (player.choose(Outcome.Neutral, targetOpponent, source.getSourceId(), game)) {
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent != null) {
TargetCard targetCards = new TargetCard(0, cards.size(), Zone.EXILED, new FilterCard("cards to put in the first pile"));
List<Card> pile1 = new ArrayList<>();
if (opponent.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));
boolean choice = player.choosePile(outcome, "Choose a pile to put onto the battlefield.", pile1, pile2, game);
Zone pile1Zone = Zone.GRAVEYARD;
Zone pile2Zone = Zone.BATTLEFIELD;
if (choice) {
pile1Zone = Zone.BATTLEFIELD;
pile2Zone = Zone.GRAVEYARD;
}
Set<Card> pile1Set = new HashSet<>();
Set<Card> pile2Set = new HashSet<>();
pile1Set.addAll(pile1);
pile2Set.addAll(pile2);
// Cards toBattlefield = new CardsImpl();
// Cards toGraveyard = new CardsImpl();
//
// if (pile1Zone == Zone.BATTLEFIELD) {
// toBattlefield.addAll(pile1);
// toGraveyard.addAll(pile2);
// } else {
// toBattlefield.addAll(pile2);
// toGraveyard.addAll(pile1);
// }
player.moveCards(pile1Set, pile1Zone, source, game, false, false, false, null);
player.moveCards(pile2Set, pile2Zone, source, game, false, false, false, null);
// StringBuilder sb = new StringBuilder("Pile 1, going to ").append(pile1Zone == Zone.BATTLEFIELD ? "Battlefield" : "Graveyard").append(": ");
// game.informPlayers(sb.toString());
// sb = new StringBuilder("Pile 2, going to ").append(pile2Zone == Zone.BATTLEFIELD ? "Battlefield" : "Graveyard").append(':');
// game.informPlayers(sb.toString());
}
return true;
}
}
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class CouncilsJudgmentVote method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
CouncilsJudgmentVote vote = new CouncilsJudgmentVote(player);
vote.doVotes(source, game);
Cards cards = new CardsImpl();
vote.getMostVoted().stream().forEach(cards::add);
return player.moveCards(cards, Zone.EXILED, source, game);
}
use of mage.cards.Cards in project mage by magefree.
the class CourtOfAmbitionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int discardCount = source.isControlledBy(game.getMonarchId()) ? 2 : 1;
String message = "Discard " + CardUtil.numberToText(discardCount, "a") + " card" + (discardCount > 1 ? 's' : "") + "? If not you lose " + (discardCount * 3) + " life";
Map<UUID, Cards> discardMap = new HashMap<>();
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
if (player.getHand().size() < discardCount || !player.chooseUse(Outcome.LoseLife, message, source, game)) {
player.loseLife(discardCount * 3, game, source, false);
continue;
}
TargetDiscard target = new TargetDiscard(discardCount, StaticFilters.FILTER_CARD, playerId);
player.choose(Outcome.Discard, target, source.getSourceId(), game);
discardMap.put(playerId, new CardsImpl(target.getTargets()));
}
for (Map.Entry<UUID, Cards> entry : discardMap.entrySet()) {
Player player = game.getPlayer(entry.getKey());
if (player != null) {
player.discard(entry.getValue(), false, source, game);
}
}
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class DeliverUntoEvilEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(source.getTargets().get(0).getTargets());
if (cards.isEmpty()) {
return false;
}
if (!game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game).isEmpty()) {
return player.moveCards(cards, Zone.HAND, source, game);
}
TargetOpponent targetOpponent = new TargetOpponent();
targetOpponent.setNotTarget(true);
if (!player.choose(outcome, targetOpponent, source.getSourceId(), game)) {
return false;
}
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent == null) {
return false;
}
TargetCard targetCard = new TargetCardInGraveyard(Math.min(2, cards.size()), filter2);
if (!opponent.choose(outcome, cards, targetCard, game)) {
return false;
}
cards.removeAll(targetCard.getTargets());
return player.moveCards(cards, Zone.HAND, source, game);
}
use of mage.cards.Cards in project mage by magefree.
the class DimensionalBreachReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(game.getActivePlayerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(morSet.stream().map(mor -> mor.getCard(game)).filter(Objects::nonNull).filter(c -> c.isOwnedBy(game.getActivePlayerId())).collect(Collectors.toSet()));
if (cards.isEmpty()) {
return false;
}
if (cards.size() > 1) {
TargetCard target = new TargetCardInExile(StaticFilters.FILTER_CARD);
target.setNotTarget(true);
player.choose(outcome, cards, target, game);
cards.clear();
cards.add(target.getFirstTarget());
}
return player.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
Aggregations