use of mage.cards.Cards in project mage by magefree.
the class SearchLibraryPutOnLibraryEffect 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) {
return false;
}
if (controller.searchLibrary(target, source, game)) {
Cards foundCards = new CardsImpl(target.getTargets());
if (reveal && !foundCards.isEmpty()) {
controller.revealCards(sourceObject.getIdName(), foundCards, game);
}
if (forceShuffle) {
controller.shuffleLibrary(source, game);
}
controller.putCardsOnTopOfLibrary(foundCards, game, source, reveal);
return true;
}
// shuffle
if (forceShuffle) {
controller.shuffleLibrary(source, game);
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class SearchLibraryPutInHandOrOnBattlefieldEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
target.clearChosen();
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards cards = new CardsImpl();
boolean askToPutOntoBf = false;
Card cardToPutOnBf = null;
for (UUID cardId : target.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
if (card.getName().equals(nameToPutOnBattlefield)) {
askToPutOntoBf = true;
cardToPutOnBf = card;
}
cards.add(card);
}
}
if (askToPutOntoBf && controller.chooseUse(Outcome.PutCardInPlay, "Put " + cardToPutOnBf.getLogName() + " onto the battlefield instead?", source, game)) {
controller.moveCards(cards, Zone.BATTLEFIELD, source, game);
} else {
controller.moveCards(cards, Zone.HAND, source, game);
}
if (revealCards) {
String name = "Reveal";
Card sourceCard = game.getCard(source.getSourceId());
if (sourceCard != null) {
name = sourceCard.getIdName();
}
controller.revealCards(name, cards, game);
}
}
controller.shuffleLibrary(source, game);
return true;
}
if (forceShuffle) {
controller.shuffleLibrary(source, game);
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class DiscardEachPlayerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
// Store for each player the cards to discard, that's important because all discard shall happen at the same time
Map<UUID, Cards> cardsToDiscard = new HashMap<>();
if (controller == null) {
return true;
}
int toDiscard = amount.calculate(game, source, this);
// choose cards to discard
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
switch(targetController) {
case NOT_YOU:
if (playerId.equals(source.getControllerId())) {
continue;
}
break;
case OPPONENT:
if (!game.getOpponents(source.getControllerId()).contains(playerId)) {
continue;
}
break;
}
if (randomDiscard) {
player.discard(toDiscard, true, false, source, game);
continue;
}
int numberOfCardsToDiscard = Math.min(toDiscard, player.getHand().size());
Cards cards = new CardsImpl();
if (numberOfCardsToDiscard > 0) {
Target target = new TargetDiscard(numberOfCardsToDiscard, numberOfCardsToDiscard, StaticFilters.FILTER_CARD, playerId);
player.chooseTarget(outcome, target, source, game);
cards.addAll(target.getTargets());
}
cardsToDiscard.put(playerId, cards);
}
if (randomDiscard) {
return true;
}
// discard all choosen cards
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
player.discard(cardsToDiscard.get(playerId), false, source, game);
}
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class AtrisOracleOfHalfTruthsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || targetOpponent == null || sourceObject == null) {
return false;
}
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
TargetCard target = new TargetCard(0, Integer.MAX_VALUE, Zone.LIBRARY, filter);
targetOpponent.choose(outcome, cards, target, game);
Cards faceDownPile = new CardsImpl(target.getTargets());
cards.removeAll(target.getTargets());
controller.revealCards(sourceObject.getIdName() + " - cards in face-up pile", cards, game);
game.informPlayers(targetOpponent.getLogName() + " puts " + faceDownPile.size() + " card(s) into the face-down pile");
if (controller.chooseUse(outcome, "Choose a pile to put in your hand.", null, "Face-down", "Face-up", source, game)) {
controller.moveCards(faceDownPile, Zone.HAND, source, game);
controller.moveCards(cards, Zone.GRAVEYARD, source, game);
} else {
controller.moveCards(faceDownPile, Zone.GRAVEYARD, source, game);
controller.moveCards(cards, Zone.HAND, source, game);
}
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class AshnodsCylixEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player == null) {
return false;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 3));
player.lookAtCards(source, null, cards, game);
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put on top of your library"));
if (player.choose(Outcome.Benefit, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
game.informPlayers(source.getSourceObject(game).getIdName() + ": " + player.getLogName() + " puts a card back on top of their library");
}
}
player.moveCards(cards, Zone.EXILED, source, game);
return true;
}
Aggregations