use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class HelmOfObedienceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetOpponent = game.getPlayer(source.getFirstTarget());
int max = ManacostVariableValue.REGULAR.calculate(game, source, this);
if (targetOpponent == null || controller == null || max < 1) {
return false;
}
Cards cards = new CardsImpl();
while (targetOpponent.getLibrary().hasCards()) {
cards.addAll(targetOpponent.millCards(1, source, game));
cards.retainZone(Zone.GRAVEYARD, game);
if (cards.size() >= max || cards.count(StaticFilters.FILTER_CARD_CREATURE, game) > 0) {
break;
}
}
Card card;
switch(cards.count(StaticFilters.FILTER_CARD_CREATURE, game)) {
case 0:
return true;
case 1:
card = cards.getCards(StaticFilters.FILTER_CARD_CREATURE, game).stream().findFirst().orElse(null);
break;
default:
TargetCardInGraveyard target = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_CREATURE);
target.setNotTarget(true);
controller.choose(Outcome.PutCreatureInPlay, cards, target, game);
card = game.getCard(target.getFirstTarget());
}
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent != null) {
permanent.sacrifice(source, game);
}
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
return true;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class OKagachiMadeManifestEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller == null || player == null) {
return false;
}
Card card;
switch(controller.getGraveyard().count(StaticFilters.FILTER_CARD_A_NON_LAND, game)) {
case 0:
return false;
case 1:
card = controller.getGraveyard().getCards(StaticFilters.FILTER_CARD_A_NON_LAND, game).stream().findFirst().orElse(null);
break;
default:
TargetCard target = new TargetCardInGraveyard(StaticFilters.FILTER_CARD_A_NON_LAND);
target.setNotTarget(true);
player.choose(Outcome.ReturnToHand, controller.getGraveyard(), target, game);
card = game.getCard(target.getFirstTarget());
}
if (card == null) {
return false;
}
int manaValue = card.getManaValue();
player.moveCards(card, Zone.HAND, source, game);
if (manaValue > 0) {
game.addEffect(new BoostSourceEffect(manaValue, 0, Duration.EndOfTurn), source);
}
return true;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class OathOfGhoulsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player firstPlayer = game.getPlayer(game.getActivePlayerId());
if (sourceObject == null || firstPlayer == null) {
return false;
}
FilterCard filter = new FilterCreatureCard("creature card");
filter.add(new OwnerIdPredicate(firstPlayer.getId()));
Target target = new TargetCardInGraveyard(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), firstPlayer.getId(), game) && firstPlayer.chooseUse(outcome, "Return a creature card from your graveyard to your hand?", source, game) && firstPlayer.chooseTarget(Outcome.ReturnToHand, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
firstPlayer.moveCards(card, Zone.HAND, source, game);
}
}
return true;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class ShroudedLoreEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
if (you != null && opponent != null) {
FilterCard filter = new FilterCard();
filter.add(new OwnerIdPredicate(you.getId()));
Cost cost = new ManaCostsImpl("{B}");
TargetCardInGraveyard chosenCard;
Card card = null;
boolean done = false;
do {
chosenCard = new TargetCardInGraveyard(filter);
chosenCard.setNotTarget(true);
if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
card = game.getCard(chosenCard.getFirstTarget());
if (card != null) {
filter.add(Predicates.not(new CardIdPredicate(card.getId())));
game.informPlayers("Shrouded Lore: " + opponent.getLogName() + " has chosen " + card.getLogName());
}
} else {
done = true;
}
if (!done) {
done = true;
if (cost.canPay(source, source, you.getId(), game) && you.chooseUse(Outcome.Benefit, "Pay {B} to choose a different card ?", source, game)) {
cost.clearPaid();
if (cost.pay(source, game, source, you.getId(), false, null)) {
done = false;
}
}
}
} while (!done);
if (card != null) {
Cards cardsToHand = new CardsImpl();
cardsToHand.add(card);
you.moveCards(cardsToHand, Zone.HAND, source, game);
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInGraveyard in project mage by magefree.
the class CryptChampionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Set<Card> toBattlefield = new HashSet<>();
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
FilterCard filter = new FilterCreatureCard("creature card with mana value 3 or less from your graveyard");
filter.add(new OwnerIdPredicate(playerId));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 4));
Target target = new TargetCardInGraveyard(filter);
if (target.canChoose(source.getSourceId(), playerId, game) && player.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
toBattlefield.add(card);
}
}
}
}
// must happen simultaneously Rule 101.4
controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, false, true, null);
return true;
}
return false;
}
Aggregations