use of mage.filter.common.FilterPermanentCard in project mage by magefree.
the class HatcherySpiderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int xValue = new CardsInControllerGraveyardCount(StaticFilters.FILTER_CARD_CREATURE).calculate(game, source, this);
FilterCard filter = new FilterPermanentCard("green permanent card with mana value " + xValue + " or less");
filter.add(new ColorPredicate(ObjectColor.GREEN));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
TargetCard target = new TargetCardInLibrary(filter);
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
if (player.chooseUse(outcome, "Put a card onto the battlefield?", source, game) && player.choose(outcome, cards, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
cards.remove(card);
}
}
while (!cards.isEmpty()) {
Card card = cards.getRandom(game);
player.getLibrary().putOnBottom(card, game);
cards.remove(card);
}
return true;
}
use of mage.filter.common.FilterPermanentCard in project mage by magefree.
the class NissaStewardOfElementsToken method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int count = 1 + new CountersSourceCount(CounterType.LOYALTY).calculate(game, source, this);
FilterPermanentCard filter = new FilterPermanentCard();
filter.add(Predicates.or(CardType.CREATURE.getPredicate(), CardType.LAND.getPredicate()));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, count));
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
controller.lookAtCards(source, null, new CardsImpl(card), game);
if (filter.match(card, game)) {
if (controller.chooseUse(outcome, "Put " + card.getName() + " onto the battlefield?", source, game)) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
return true;
}
use of mage.filter.common.FilterPermanentCard in project mage by magefree.
the class ZarethSanTheTricksterTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Player opponent = game.getPlayer(event.getPlayerId());
if (opponent == null || !event.getSourceId().equals(this.sourceId) || !((DamagedEvent) event).isCombatDamage()) {
return false;
}
FilterCard filter = new FilterPermanentCard("permanent card in " + opponent.getLogName() + "'s graveyard");
filter.add(new OwnerIdPredicate(opponent.getId()));
this.getTargets().clear();
this.addTarget(new TargetCardInGraveyard(filter));
return true;
}
use of mage.filter.common.FilterPermanentCard in project mage by magefree.
the class BifurcateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
FilterCard filter = new FilterPermanentCard();
filter.add(new NamePredicate(permanent.getName()));
return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filter)).apply(game, source);
}
use of mage.filter.common.FilterPermanentCard in project mage by magefree.
the class EurekaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
PlayerList playerList = game.getState().getPlayerList().copy();
while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
playerList.getNext();
}
Player currentPlayer = game.getPlayer(playerList.get());
UUID firstInactivePlayer = null;
Target target = new TargetCardInHand(new FilterPermanentCard());
while (controller.canRespond()) {
if (firstInactivePlayer == null) {
firstInactivePlayer = currentPlayer.getId();
}
if (currentPlayer != null && currentPlayer.canRespond() && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
target.clearChosen();
if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game) && currentPlayer.chooseUse(outcome, "Put permanent from your hand to play?", source, game)) {
if (target.chooseTarget(outcome, currentPlayer.getId(), source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
currentPlayer.moveCards(card, Zone.BATTLEFIELD, source, game);
firstInactivePlayer = null;
}
}
}
}
// get next player
playerList.getNext();
currentPlayer = game.getPlayer(playerList.get());
// if all player since this player didn't put permanent in play finish the process
if (currentPlayer != null && currentPlayer.getId().equals(firstInactivePlayer)) {
break;
}
}
return true;
}
return false;
}
Aggregations