use of mage.target.TargetCard in project mage by magefree.
the class CultivatorColossusEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
while (player.getHand().count(StaticFilters.FILTER_CARD_LAND, game) > 0) {
TargetCard target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_LAND);
player.choose(outcome, target, source.getSourceId(), game);
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
break;
}
player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
if (game.getPermanent(card.getId()) == null) {
break;
}
player.drawCards(1, source, game);
}
return true;
}
use of mage.target.TargetCard in project mage by magefree.
the class CultivateEffect 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(target.getTargets());
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);
if (card != null) {
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();
if (card != null) {
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();
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
}
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.target.TargetCard in project mage by magefree.
the class FinalPartingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// Unlike Jarad's Orders, which this mostly copies, you can't fail to find
TargetCardInLibrary target = new TargetCardInLibrary(2, 2, new FilterCard());
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards searched = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().getCard(cardId, game);
searched.add(card);
}
if (target.getTargets().size() == 2) {
TargetCard target2 = new TargetCard(Zone.LIBRARY, filter);
controller.choose(Outcome.Benefit, searched, target2, game);
Card card = searched.get(target2.getFirstTarget(), game);
controller.moveCards(card, Zone.HAND, source, game);
searched.remove(card);
Set<Card> cards = searched.getCards(game);
card = cards.isEmpty() ? null : cards.iterator().next();
controller.moveCards(card, Zone.GRAVEYARD, source, game);
} else if (target.getTargets().size() == 1) {
Set<Card> cards = searched.getCards(game);
Card card = cards.isEmpty() ? null : cards.iterator().next();
controller.moveCards(card, Zone.HAND, source, game);
}
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
}
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class HowlpackPiperEffect 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_CREATURE, game) < 1) {
return false;
}
TargetCard target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_CREATURE);
player.choose(outcome, player.getHand(), target, game);
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
player.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent permanent = game.getPermanent(card.getId());
Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
if (permanent == null || sourcePermanent == null) {
return true;
}
if (permanent.hasSubtype(SubType.WOLF, game) || permanent.hasSubtype(SubType.WEREWOLF, game)) {
sourcePermanent.untap(game);
}
return true;
}
use of mage.target.TargetCard in project mage by magefree.
the class MasterOfPredicamentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (!controller.getHand().isEmpty()) {
Card cardFromHand = null;
if (controller.getHand().size() > 1) {
TargetCard target = new TargetCardInHand(new FilterCard());
if (controller.choose(Outcome.PlayForFree, controller.getHand(), target, game)) {
cardFromHand = game.getCard(target.getFirstTarget());
}
} else {
cardFromHand = controller.getHand().getRandom(game);
}
if (cardFromHand == null) {
return false;
}
Player attackedPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (attackedPlayer == null) {
return false;
}
boolean guessWrong;
if (attackedPlayer.chooseUse(Outcome.Detriment, "Is the chosen card's " + "mana value greater than 4?", source, game)) {
game.informPlayers(attackedPlayer.getLogName() + " guessed that the chosen " + "card's mana value is greater than 4");
guessWrong = cardFromHand.getManaValue() <= 4;
} else {
game.informPlayers(attackedPlayer.getLogName() + " guessed that the chosen " + "card's mana value is not greater than 4");
guessWrong = cardFromHand.getManaValue() > 4;
}
game.informPlayers(attackedPlayer.getLogName() + " guessed " + (guessWrong ? "wrong" : "right"));
if (guessWrong) {
if (cardFromHand.isLand(game)) {
// If the revealed card is a land, you can't cast it. So nothing happens
} else {
if (controller.chooseUse(outcome, "Cast " + cardFromHand.getName() + " without paying its mana cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardFromHand.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardFromHand, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardFromHand.getId(), null);
}
}
}
}
return true;
}
return false;
}
Aggregations