use of mage.cards.Cards in project mage by magefree.
the class PutOnLibraryTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<Card> cards = new ArrayList<>();
List<Permanent> permanents = new ArrayList<>();
for (UUID targetId : targetPointer.getTargets(game, source)) {
switch(game.getState().getZone(targetId)) {
case BATTLEFIELD:
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
permanents.add(permanent);
}
break;
case GRAVEYARD:
Card graveyardCard = game.getCard(targetId);
if (graveyardCard != null) {
cards.add(graveyardCard);
}
break;
case STACK:
Card stackSpellCard = game.getSpell(targetId).getCard();
if (stackSpellCard != null) {
cards.add(stackSpellCard);
}
break;
}
}
// 10/4/2004 The owner decides the order the two lands are stacked there.
while (!cards.isEmpty()) {
Card card = cards.iterator().next();
if (card != null) {
Player owner = game.getPlayer(card.getOwnerId());
Cards cardsPlayer = new CardsImpl();
for (Iterator<Card> iterator = cards.iterator(); iterator.hasNext(); ) {
Card next = iterator.next();
if (next.isOwnedBy(owner.getId())) {
cardsPlayer.add(next);
iterator.remove();
}
}
if (onTop) {
owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
} else {
owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true);
}
}
}
while (!permanents.isEmpty()) {
Permanent permanent = permanents.iterator().next();
if (permanent != null) {
Player owner = game.getPlayer(permanent.getOwnerId());
Cards cardsPlayer = new CardsImpl();
for (Iterator<Permanent> iterator = permanents.iterator(); iterator.hasNext(); ) {
Permanent next = iterator.next();
if (next.isOwnedBy(owner.getId())) {
cardsPlayer.add(next);
iterator.remove();
}
}
if (onTop) {
owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
} else {
owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true);
}
}
}
return true;
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class LookLibraryControllerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// take cards from library and look at them
boolean topCardRevealed = controller.isTopCardRevealed();
controller.setTopCardRevealed(false);
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, this.numberOfCards.calculate(game, source, this)));
controller.lookAtCards(source, null, cards, game);
this.actionWithSelectedCards(cards, game, source);
this.putCardsBack(source, controller, cards, game);
controller.setTopCardRevealed(topCardRevealed);
this.mayShuffle(controller, source, game);
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class HideawayLookAtFaceDownCardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
// LKI is required for this ruling
/*
If Watcher for Tomorrow leaves the battlefield before its
triggered ability from hideaway resolves, its leaves-the-battlefield
ability resolves and does nothing. Then its enters-the-battlefield
ability resolves and you exile a card with no way to return it to your hand.
*/
Permanent hideawaySource = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (hideawaySource == null || controller == null) {
return false;
}
Cards cards = new CardsImpl();
cards.addAll(controller.getLibrary().getTopCards(game, 4));
if (!cards.isEmpty()) {
TargetCard target1 = new TargetCard(Zone.LIBRARY, filter1);
target1.setNotTarget(true);
if (controller.choose(Outcome.Detriment, cards, target1, game)) {
Card card = cards.get(target1.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
controller.moveCardToExileWithInfo(card, exileId, "Hideaway (" + hideawaySource.getIdName() + ')', source, game, Zone.LIBRARY, false);
card.setFaceDown(true, game);
}
}
controller.putCardsOnBottomOfLibrary(cards, game, source, true);
}
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class AlrundGodOfTheCosmosEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
String chosenCardType = (String) game.getState().getValue(source.getSourceId() + "_type");
Cards cardsToHand = new CardsImpl();
Cards cardsToBottomOfLibrary = new CardsImpl();
if (controller != null) {
Set<Card> twoCardsFromTop = controller.getLibrary().getTopCards(game, 2);
Cards cards = new CardsImpl();
cards.addAll(twoCardsFromTop);
controller.revealCards(source, cards, game);
for (Card card : cards.getCards(game)) {
if (card.getCardType(game).toString().contains(chosenCardType)) {
cardsToHand.add(card);
} else {
cardsToBottomOfLibrary.add(card);
}
}
controller.moveCards(cardsToHand, Zone.HAND, source, game);
controller.putCardsOnBottomOfLibrary(cardsToBottomOfLibrary, game, source, true);
return true;
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class AminatousAuguryCastFromExileEffect 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) {
// move cards from library to exile
controller.moveCardsToExile(controller.getLibrary().getTopCards(game, 8), source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
ExileZone auguryExileZone = game.getExile().getExileZone(source.getSourceId());
if (auguryExileZone == null) {
return true;
}
Cards cardsToCast = new CardsImpl();
cardsToCast.addAll(auguryExileZone.getCards(game));
// put a land card from among them onto the battlefield
TargetCard target = new TargetCard(Zone.EXILED, StaticFilters.FILTER_CARD_LAND_A);
if (cardsToCast.count(StaticFilters.FILTER_CARD_LAND, game) > 0) {
if (controller.chooseUse(Outcome.PutLandInPlay, "Put a land from among the exiled cards into play?", source, game)) {
if (controller.choose(Outcome.PutLandInPlay, cardsToCast, target, game)) {
Card card = cardsToCast.get(target.getFirstTarget(), game);
if (card != null) {
cardsToCast.remove(card);
controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
}
}
}
}
for (Card card : cardsToCast.getCards(StaticFilters.FILTER_CARD_NON_LAND, game)) {
AminatousAuguryCastFromExileEffect effect = new AminatousAuguryCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
}
}
return false;
}
Aggregations