use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class PyreOfHeroesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sacrificedPermanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
if (!sacrificeCost.getPermanents().isEmpty()) {
sacrificedPermanent = sacrificeCost.getPermanents().get(0);
}
break;
}
}
Player controller = game.getPlayer(source.getControllerId());
if (sacrificedPermanent == null || controller == null) {
return false;
}
int newConvertedCost = sacrificedPermanent.getManaValue() + 1;
FilterCard filter = new FilterCard("creature card with mana value " + newConvertedCost);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, newConvertedCost));
filter.add(CardType.CREATURE.getPredicate());
filter.add(new SharesCreatureTypePredicate(sacrificedPermanent));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class WuSpyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (controller != null && opponent != null) {
Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, 2));
if (!cards.isEmpty()) {
TargetCard target = new TargetCardInLibrary(new FilterCard("card to put into graveyard"));
controller.choose(Outcome.Benefit, cards, target, game);
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.GRAVEYARD, source, game);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class ArmoredSkyhunterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6));
TargetCardInLibrary targetCard = new TargetCardInLibrary(0, 1, filter);
player.choose(outcome, cards, targetCard, game);
Card card = game.getCard(targetCard.getFirstTarget());
if (card == null) {
return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
player.moveCards(card, Zone.BATTLEFIELD, source, game);
cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.LIBRARY);
Permanent equipment = game.getPermanent(card.getId());
if (equipment == null || !equipment.hasSubtype(SubType.EQUIPMENT, game)) {
return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
TargetPermanent targetPermanent = new TargetControlledCreaturePermanent(0, 1);
targetCard.setNotTarget(true);
player.choose(outcome, targetPermanent, source.getSourceId(), game);
Permanent permanent = game.getPermanent(targetPermanent.getFirstTarget());
if (permanent != null) {
permanent.addAttachment(equipment.getId(), source, game);
}
return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class BlossomPrancerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 5));
TargetCard target = new TargetCardInLibrary(0, 1, filter);
player.choose(outcome, cards, target, game);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
player.revealCards(source, new CardsImpl(card), game);
player.moveCards(card, Zone.HAND, source, game);
cards.remove(card);
player.putCardsOnBottomOfLibrary(card, game, source, false);
} else {
player.putCardsOnBottomOfLibrary(card, game, source, false);
player.gainLife(4, game, source);
}
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class CongregationAtDawnEffect 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) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 3, new FilterCreatureCard("creature cards"));
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards revealed = new CardsImpl();
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().remove(cardId, game);
revealed.add(card);
}
controller.revealCards(sourceObject.getName(), revealed, game);
controller.shuffleLibrary(source, game);
TargetCard targetToLib = new TargetCard(Zone.LIBRARY, new FilterCard(textTop));
while (revealed.size() > 1 && controller.canRespond()) {
controller.choose(Outcome.Neutral, revealed, targetToLib, game);
Card card = revealed.get(targetToLib.getFirstTarget(), game);
if (card != null) {
revealed.remove(card);
controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
}
targetToLib.clearChosen();
}
if (revealed.size() == 1) {
Card card = revealed.get(revealed.iterator().next(), game);
controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, true, false);
}
}
return true;
}
}
return false;
}
Aggregations