use of mage.target.TargetCard in project mage by magefree.
the class MuzzioVisionaryArchitectEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int highCMC = 0;
List<Permanent> controlledArtifacts = game.getBattlefield().getAllActivePermanents(new FilterArtifactPermanent(), controller.getId(), game);
for (Permanent permanent : controlledArtifacts) {
if (permanent.getSpellAbility() != null) {
int cmc = permanent.getSpellAbility().getManaCosts().manaValue();
if (cmc > highCMC) {
highCMC = cmc;
}
}
}
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, highCMC));
controller.lookAtCards(source, null, cards, game);
if (!cards.isEmpty()) {
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterArtifactCard("artifact card to put onto the battlefield"));
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(Outcome.Benefit, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
controller.revealCards(source, new CardsImpl(card), game);
cards.remove(card);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
controller.putCardsOnBottomOfLibrary(cards, game, source, true);
return true;
}
use of mage.target.TargetCard in project mage by magefree.
the class NissasEncouragementTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card sourceCard = game.getCard(source.getSourceId());
if (player == null || sourceCard == null) {
return false;
}
NissasEncouragementTarget target = new NissasEncouragementTarget(filter);
if (player.searchLibrary(target, source, game)) {
boolean searchGY = false;
if (target.getTargets().size() < 3) {
searchGY = true;
}
Map<String, Integer> foundCards = new HashMap<>();
foundCards.put("Forest", 0);
foundCards.put("Brambleweft Behemoth", 0);
foundCards.put("Nissa, Genesis Mage", 0);
Cards cards = new CardsImpl();
if (!target.getTargets().isEmpty()) {
for (UUID cardId : target.getTargets()) {
Card card = player.getLibrary().remove(cardId, game);
if (card != null) {
cards.add(card);
foundCards.put(card.getName(), 1);
}
}
}
if (searchGY) {
for (String name : foundCards.keySet()) {
if (foundCards.get(name) == 1) {
continue;
}
// Look in graveyard for any with this name
// never change static objects so copy the object here before
FilterCard namedFilterGY = filterGY.copy();
namedFilterGY.add(new NamePredicate(name));
if (player.getGraveyard().count(namedFilterGY, game) > 0) {
TargetCard targetGY = new TargetCard(0, 1, Zone.GRAVEYARD, namedFilterGY);
if (player.choose(Outcome.ReturnToHand, player.getGraveyard(), targetGY, game)) {
for (UUID cardIdGY : targetGY.getTargets()) {
Card cardGY = player.getGraveyard().get(cardIdGY, game);
cards.add(cardGY);
}
}
}
}
}
if (!cards.isEmpty()) {
player.revealCards(sourceCard.getIdName(), cards, game);
player.moveCards(cards, Zone.HAND, source, game);
player.shuffleLibrary(source, game);
return true;
}
}
player.shuffleLibrary(source, game);
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class PeregrinationEffect 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) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary(0, 2, StaticFilters.FILTER_CARD_BASIC_LAND);
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards revealed = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().getCard(cardId, game);
revealed.add(card);
}
controller.revealCards(sourceObject.getIdName(), revealed, game);
if (target.getTargets().size() == 2) {
TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
controller.choose(Outcome.Benefit, revealed, target2, game);
Card card = revealed.get(target2.getFirstTarget(), game);
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
revealed.remove(card);
Set<Card> cards = revealed.getCards(game);
card = cards.isEmpty() ? null : cards.iterator().next();
controller.moveCards(card, Zone.HAND, source, game);
} else if (target.getTargets().size() == 1) {
Set<Card> cards = revealed.getCards(game);
Card card = cards.isEmpty() ? null : cards.iterator().next();
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
}
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class PsychicIntrusionSpendAnyManaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId());
if (opponent != null && sourceObject != null) {
opponent.revealCards(sourceObject.getName(), opponent.getHand(), game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int cardsGraveyard = opponent.getGraveyard().count(filter, game);
int cardsHand = opponent.getHand().count(filter, game);
boolean fromHand = false;
if (cardsGraveyard > 0 && cardsHand > 0) {
if (controller.chooseUse(Outcome.Detriment, "Exile card from opponents Hand?", source, game)) {
fromHand = true;
}
} else {
if (cardsHand > 0) {
fromHand = true;
}
}
Card card = null;
if (cardsHand > 0 && fromHand) {
TargetCard target = new TargetCard(Zone.HAND, filter);
if (controller.choose(Outcome.Benefit, opponent.getHand(), target, game)) {
card = opponent.getHand().get(target.getFirstTarget(), game);
}
}
if (cardsGraveyard > 0 && !fromHand) {
TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
if (controller.choose(Outcome.Benefit, opponent.getGraveyard(), target, game)) {
card = opponent.getGraveyard().get(target.getFirstTarget(), game);
}
}
if (card != null) {
// move card to exile
UUID exileId = CardUtil.getCardExileZoneId(game, source);
controller.moveCardToExileWithInfo(card, exileId, sourceObject.getIdName(), source, game, fromHand ? Zone.HAND : Zone.GRAVEYARD, true);
// allow to cast the card
ContinuousEffect effect = new PsychicIntrusionCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
// and you may spend mana as though it were mana of any color to cast it
effect = new PsychicIntrusionSpendAnyManaEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
}
return true;
}
}
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class PsychicTheftWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
if (opponent == null) {
return false;
}
opponent.revealCards(CardUtil.getSourceName(game, source), opponent.getHand(), game);
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int cardsHand = opponent.getHand().count(filter, game);
Card chosenCard = null;
if (cardsHand > 0) {
TargetCard target = new TargetCard(Zone.HAND, filter);
if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) {
chosenCard = opponent.getHand().get(target.getFirstTarget(), game);
}
}
if (chosenCard == null) {
return false;
}
controller.moveCardToExileWithInfo(chosenCard, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source), source, game, Zone.HAND, true);
CardUtil.makeCardPlayable(game, source, chosenCard, Duration.Custom, false);
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ConditionalOneShotEffect(new ReturnFromExileEffect(Zone.HAND), new PsychicTheftCondition(chosenCard, game), "if you haven't cast it, return it to its owner's hand.")), source);
return true;
}
Aggregations