use of mage.target.TargetCard in project mage by magefree.
the class DimensionalBreachReturnEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(game.getActivePlayerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(morSet.stream().map(mor -> mor.getCard(game)).filter(Objects::nonNull).filter(c -> c.isOwnedBy(game.getActivePlayerId())).collect(Collectors.toSet()));
if (cards.isEmpty()) {
return false;
}
if (cards.size() > 1) {
TargetCard target = new TargetCardInExile(StaticFilters.FILTER_CARD);
target.setNotTarget(true);
player.choose(outcome, cards, target, game);
cards.clear();
cards.add(target.getFirstTarget());
}
return player.moveCards(cards, Zone.BATTLEFIELD, source, game);
}
use of mage.target.TargetCard in project mage by magefree.
the class DiscordantDirgeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent discordantDirge = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (discordantDirge == null) {
return false;
}
int verseCounters = discordantDirge.getCounters(game).getCount(CounterType.VERSE);
Player targetOpponent = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (targetOpponent == null || controller == null) {
return false;
}
controller.lookAtCards(targetOpponent.getName() + " hand", targetOpponent.getHand(), game);
TargetCard target = new TargetCard(0, verseCounters, Zone.HAND, new FilterCard());
target.setNotTarget(true);
if (!controller.choose(Outcome.Benefit, targetOpponent.getHand(), target, game)) {
return false;
}
targetOpponent.discard(new CardsImpl(target.getTargets()), false, source, game);
return true;
}
use of mage.target.TargetCard in project mage by magefree.
the class HatcherySpiderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int xValue = new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this);
FilterCard filter = new FilterPermanentCard("green permanent card with mana value " + xValue + " or less");
filter.add(new ColorPredicate(ObjectColor.GREEN));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCard target = new TargetCardInLibrary(filter);
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
if (player.chooseUse(outcome, "Put a card onto the battlefield?", source, game) && player.choose(outcome, cards, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
cards.remove(card);
}
}
while (!cards.isEmpty()) {
Card card = cards.getRandom(game);
player.getLibrary().putOnBottom(card, game);
cards.remove(card);
}
return true;
}
use of mage.target.TargetCard in project mage by magefree.
the class HauntedFengrafEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null || player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game) < 1) {
return false;
}
TargetCard target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE);
target.setNotTarget(true);
target.setRandom(true);
target.chooseTarget(outcome, player.getId(), source, game);
return player.moveCards(game.getCard(target.getFirstTarget()), Zone.HAND, source, game);
}
use of mage.target.TargetCard in project mage by magefree.
the class HazoretsUndyingFuryEffect 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) {
controller.shuffleLibrary(source, game);
// move cards from library to exile
controller.moveCardsToExile(controller.getLibrary().getTopCards(game, 4), source, game, true, source.getSourceId(), sourceObject.getIdName());
// cast the possible cards without paying the mana
ExileZone hazoretsUndyingFuryExileZone = game.getExile().getExileZone(source.getSourceId());
Cards cardsToCast = new CardsImpl();
if (hazoretsUndyingFuryExileZone == null) {
return true;
}
cardsToCast.addAll(hazoretsUndyingFuryExileZone.getCards(filter, source.getSourceId(), source.getControllerId(), game));
while (controller.canRespond() && !cardsToCast.isEmpty()) {
if (!controller.chooseUse(Outcome.PlayForFree, "Cast (another) a card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
break;
}
TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("nonland card to cast for free"));
if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
cardsToCast.remove(card);
if (!cardWasCast) {
game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
}
}
}
return true;
}
return false;
}
Aggregations