use of mage.cards.CardsImpl in project mage by magefree.
the class ReturnToBattlefieldUnderOwnerControlTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cardsToBattlefield = new CardsImpl();
if (returnFromExileZoneOnly) {
for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
if (game.getExile().containsId(targetId, game)) {
cardsToBattlefield.add(targetId);
} else {
Card card = game.getCard(targetId);
if (card instanceof MeldCard) {
MeldCard meldCard = (MeldCard) card;
Card topCard = meldCard.getTopHalfCard();
Card bottomCard = meldCard.getBottomHalfCard();
if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter() && game.getExile().containsId(topCard.getId(), game)) {
cardsToBattlefield.add(topCard);
}
if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter() && game.getExile().containsId(bottomCard.getId(), game)) {
cardsToBattlefield.add(bottomCard);
}
}
}
}
} else {
cardsToBattlefield.addAll(getTargetPointer().getTargets(game, source));
}
if (!cardsToBattlefield.isEmpty()) {
controller.moveCards(cardsToBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, tapped, false, true, null);
}
return true;
}
return false;
}
use of mage.cards.CardsImpl 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.CardsImpl 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.CardsImpl 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.CardsImpl 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;
}
Aggregations