use of mage.cards.Cards in project mage by magefree.
the class MoldgrafMonstrosityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards possibleCards = new CardsImpl(controller.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game));
// Set<Card> cards = controller.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game);
Cards toBattlefield = new CardsImpl();
for (int i = 0; i < 2; i++) {
Card card = possibleCards.getRandom(game);
if (card != null) {
toBattlefield.add(card);
possibleCards.remove(card);
}
}
controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game);
return true;
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class NecromentiaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
Player controller = game.getPlayer(source.getControllerId());
if (cardName != null && controller != null) {
FilterCard filter = new FilterCard("card named " + cardName);
filter.add(new NamePredicate(cardName));
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
// cards in Graveyard
int cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getGraveyard().count(filter, game));
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the graveyard of " + targetPlayer.getName());
TargetCard target = new TargetCard(0, cardsCount, Zone.GRAVEYARD, filter);
if (controller.choose(Outcome.Exile, targetPlayer.getGraveyard(), target, game)) {
controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
}
// cards in Hand
int numberOfCardsExiledFromHand = 0;
cardsCount = (cardName.isEmpty() ? 0 : targetPlayer.getHand().count(filter, game));
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the hand of " + targetPlayer.getName());
TargetCard target = new TargetCard(0, cardsCount, Zone.HAND, filter);
if (controller.choose(Outcome.Exile, targetPlayer.getHand(), target, game)) {
numberOfCardsExiledFromHand = target.getTargets().size();
controller.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
}
} else {
targetPlayer.revealCards(targetPlayer.getName() + "'s Hand", targetPlayer.getHand(), game);
}
// cards in Library
Cards cardsInLibrary = new CardsImpl();
cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));
cardsCount = (cardName.isEmpty() ? 0 : cardsInLibrary.count(filter, game));
if (cardsCount > 0) {
filter.setMessage("card named " + cardName + " in the library of " + targetPlayer.getLogName());
TargetCardInLibrary targetLib = new TargetCardInLibrary(0, cardsCount, filter);
if (controller.choose(Outcome.Exile, cardsInLibrary, targetLib, game)) {
controller.moveCards(new CardsImpl(targetLib.getTargets()), Zone.EXILED, source, game);
}
} else {
targetPlayer.revealCards(targetPlayer.getName() + "'s Library", new CardsImpl(new HashSet<>(targetPlayer.getLibrary().getCards(game))), game);
}
targetPlayer.shuffleLibrary(source, game);
if (numberOfCardsExiledFromHand > 0) {
game.getState().applyEffects(game);
Token zombieToken = new ZombieToken();
zombieToken.putOntoBattlefield(numberOfCardsExiledFromHand, game, source, targetPlayer.getId());
}
return true;
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class NaturalSelectionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer == null || controller == null) {
return false;
}
Cards cards = new CardsImpl(targetPlayer.getLibrary().getTopCards(game, 3));
controller.lookAtCards(source, null, cards, game);
controller.putCardsOnTopOfLibrary(cards, game, source, true);
if (controller.chooseUse(Outcome.Neutral, "You may have that player shuffle", source, game)) {
targetPlayer.shuffleLibrary(source, game);
}
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class RansackEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
FilterCard filter = new FilterCard("cards to put on the bottom of your library");
if (player != null) {
int number = min(player.getLibrary().size(), 5);
Set<Card> cards = player.getLibrary().getTopCards(game, number);
Cards cardsRemaining = new CardsImpl();
cardsRemaining.addAll(cards);
TargetCard target = new TargetCard(0, number, Zone.LIBRARY, filter);
if (player.choose(Outcome.DrawCard, cardsRemaining, target, game)) {
Cards pickedCards = new CardsImpl(target.getTargets());
cardsRemaining.removeAll(pickedCards);
player.putCardsOnBottomOfLibrary(pickedCards, game, source, true);
player.putCardsOnTopOfLibrary(cardsRemaining, game, source, true);
return true;
}
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class SkyclavePlunderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int xValue = 3 + PartyCount.instance.calculate(game, source, this);
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
int toTake = Math.min(cards.size(), 3);
TargetCard target = new TargetCardInLibrary(toTake, toTake, StaticFilters.FILTER_CARD);
player.choose(outcome, cards, target, game);
Cards toHand = new CardsImpl(target.getTargets());
cards.removeIf(target.getTargets()::contains);
player.moveCards(toHand, Zone.HAND, source, game);
player.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
Aggregations