use of mage.target.common.TargetCardInHand in project mage by magefree.
the class GateToTheAfterlifeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
FilterCard filter = new FilterCard("card named " + cardName);
filter.add(new NamePredicate(cardName));
Card card = null;
// Graveyard check
if (controller.chooseUse(Outcome.Benefit, "Search your graveyard for " + cardName + "?", source, game)) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(1, 1, filter, true);
if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
card = game.getCard(target.getFirstTarget());
}
}
// Hand check
if (card == null && controller.chooseUse(Outcome.Benefit, "Search your hand for " + cardName + "?", source, game)) {
TargetCardInHand target = new TargetCardInHand(0, 1, filter);
if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
card = game.getCard(target.getFirstTarget());
}
}
// Library check
boolean librarySearched = false;
if (card == null && controller.chooseUse(Outcome.Benefit, "Search your library for " + cardName + "?", source, game)) {
librarySearched = true;
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
card = game.getCard(target.getFirstTarget());
}
controller.shuffleLibrary(source, game);
}
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
if (librarySearched) {
controller.shuffleLibrary(source, game);
}
return true;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class KamahlsSummonsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
Map<UUID, Integer> revealedCards = new HashMap<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.getHand().count(StaticFilters.FILTER_CARD_CREATURE, game) > 0) {
TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_CREATURE);
if (player.choose(outcome, target, source.getSourceId(), game)) {
Cards cards = new CardsImpl(target.getTargets());
controller.revealCards(sourceObject.getIdName(), cards, game);
revealedCards.put(playerId, target.getTargets().size());
}
}
}
}
Token token = new BearToken();
for (Map.Entry<UUID, Integer> revealedCardsByPlayer : revealedCards.entrySet()) {
int value = revealedCardsByPlayer.getValue();
if (value > 0) {
token.putOntoBattlefield(value, game, source, revealedCardsByPlayer.getKey());
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class KroxaTitanOfDeathsHungerDiscardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Cards cards = new CardsImpl();
game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).forEachOrdered(player -> {
if (player.getHand().size() == 0) {
return;
}
TargetCard target = new TargetCardInHand(1, StaticFilters.FILTER_CARD);
player.choose(Outcome.Discard, player.getHand(), target, game);
cards.add(target.getFirstTarget());
});
Set<UUID> playerSet = new HashSet();
cards.getCards(game).stream().forEachOrdered(card -> {
Player player = game.getPlayer(card.getOwnerId());
if (player == null || !player.discard(card, false, source, game) || card.isLand(game)) {
return;
}
playerSet.add(player.getId());
});
game.getOpponents(source.getControllerId()).stream().filter(uuid -> !playerSet.contains(uuid)).map(game::getPlayer).filter(Objects::nonNull).forEachOrdered(player -> player.loseLife(3, game, source, false));
return true;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class MindleechGhoulEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl();
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player opponent = game.getPlayer(playerId);
if (opponent == null || opponent.getHand().isEmpty()) {
continue;
}
TargetCard target = new TargetCardInHand();
opponent.choose(Outcome.Discard, opponent.getHand(), target, game);
cards.add(game.getCard(target.getFirstTarget()));
}
return controller.moveCards(cards, Zone.EXILED, source, game);
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class NantukoCultivatorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || player.getHand().count(StaticFilters.FILTER_CARD_LAND, game) < 1) {
return false;
}
TargetCardInHand toDiscard = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_LAND);
player.chooseTarget(Outcome.AIDontUseIt, toDiscard, source, game);
int count = player.discard(new CardsImpl(toDiscard.getTargets()), false, source, game).size();
if (count < 1) {
return false;
}
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
permanent.addCounters(CounterType.P1P1.createInstance(count), source.getControllerId(), source, game);
}
player.drawCards(count, source, game);
return true;
}
Aggregations