use of mage.filter.common.FilterCreatureCard in project mage by magefree.
the class InstrumentOfTheBardsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller == null || permanent == null) {
return false;
}
int counters = permanent.getCounters(game).getCount(CounterType.HARMONY);
FilterCreatureCard filter = new FilterCreatureCard("creature card with mana value " + counters);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, counters));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.revealCards(permanent.getIdName(), new CardsImpl(card), game);
controller.moveCards(card, Zone.HAND, source, game);
if (card.isLegendary()) {
new TreasureToken().putOntoBattlefield(1, game, source, source.getControllerId());
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.filter.common.FilterCreatureCard in project mage by magefree.
the class KindredSummonsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
if (subType == null) {
return false;
}
FilterControlledCreaturePermanent filterPermanent = new FilterControlledCreaturePermanent("creature you control of the chosen type");
filterPermanent.add(subType.getPredicate());
int numberOfCards = game.getBattlefield().countAll(filterPermanent, source.getControllerId(), game);
Cards revealed = new CardsImpl();
Set<Card> chosenSubtypeCreatureCards = new LinkedHashSet<>();
Cards otherCards = new CardsImpl();
FilterCreatureCard filterCard = new FilterCreatureCard("creature card of the chosen type");
filterCard.add(subType.getPredicate());
if (numberOfCards == 0) {
// no matches so nothing is revealed
game.informPlayers("There are 0 creature cards of the chosen type in " + controller.getName() + "'s library.");
return true;
}
for (Card card : controller.getLibrary().getCards(game)) {
revealed.add(card);
if (card != null && filterCard.match(card, game)) {
chosenSubtypeCreatureCards.add(card);
if (chosenSubtypeCreatureCards.size() == numberOfCards) {
break;
}
} else {
otherCards.add(card);
}
}
controller.revealCards(source, revealed, game);
controller.moveCards(chosenSubtypeCreatureCards, Zone.BATTLEFIELD, source, game);
if (!otherCards.isEmpty()) {
controller.putCardsOnTopOfLibrary(otherCards, game, source, false);
controller.shuffleLibrary(source, game);
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreatureCard in project mage by magefree.
the class MarchOfBurgeoningLifeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (player == null || permanent == null) {
return false;
}
FilterCard filter = new FilterCreatureCard("creature card with the same name as " + permanent.getName());
filter.add(new MarchOfBurgeoningLifePredicate(permanent));
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
player.searchLibrary(target, source, game);
Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
}
player.shuffleLibrary(source, game);
return true;
}
use of mage.filter.common.FilterCreatureCard in project mage by magefree.
the class BodyDoubleCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Target target = new TargetCardInGraveyard(new FilterCreatureCard("creature card in a graveyard"));
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
player.choose(outcome, target, source.getSourceId(), game);
Card copyFromCard = game.getCard(target.getFirstTarget());
if (copyFromCard != null) {
CopyEffect copyEffect = new CopyEffect(Duration.Custom, copyFromCard, source.getSourceId());
game.addEffect(copyEffect, source);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreatureCard 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