use of mage.target.TargetCard in project mage by magefree.
the class MonomaniaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
if (player == null || player.getHand().isEmpty()) {
return false;
}
TargetCard target = new TargetDiscard(player.getId());
player.choose(Outcome.Benefit, player.getHand(), target, game);
Cards cards = player.getHand().copy();
cards.removeIf(target.getTargets()::contains);
return !player.discard(cards, false, source, game).isEmpty();
}
use of mage.target.TargetCard 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.target.TargetCard 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.target.TargetCard in project mage by magefree.
the class RootsOfWisdomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
player.millCards(3, source, game);
TargetCard targetCard = new TargetCardInYourGraveyard(filter);
targetCard.setNotTarget(true);
if (targetCard.canChoose(source.getSourceId(), source.getControllerId(), game) && player.choose(outcome, targetCard, source.getSourceId(), game)) {
Card card = player.getGraveyard().get(targetCard.getFirstTarget(), game);
if (card != null && player.moveCards(card, Zone.HAND, source, game)) {
return true;
}
}
player.drawCards(1, source, game);
return true;
}
use of mage.target.TargetCard 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