use of mage.filter.FilterCard in project mage by magefree.
the class IncandescentSoulstokeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
FilterCard filter = new FilterCreatureCard();
filter.add(SubType.ELEMENTAL.getPredicate());
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("sacrifice " + card.getName(), source.getControllerId());
sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
}
}
}
}
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class KotoseTheSilentSpiderWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (controller == null || card == null) {
return false;
}
Player opponent = game.getPlayer(card.getOwnerId());
if (opponent == null) {
return false;
}
UUID exileId = CardUtil.getExileZoneId(game, source);
String exileName = CardUtil.getSourceName(game, source);
controller.moveCardsToExile(card, source, game, true, exileId, exileName);
Cards cards = new CardsImpl();
FilterCard filter = new FilterCard("cards named " + card.getName() + " from " + opponent.getName() + "'s graveyard");
filter.add(new NamePredicate(card.getName()));
TargetCardInGraveyard targetCardInGraveyard = new TargetCardInGraveyard(0, Integer.MAX_VALUE, filter);
controller.choose(outcome, opponent.getGraveyard(), targetCardInGraveyard, game);
cards.addAll(targetCardInGraveyard.getTargets());
filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s hand");
TargetCardInHand targetCardInHand = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
controller.choose(outcome, opponent.getHand(), targetCardInHand, game);
cards.addAll(targetCardInHand.getTargets());
filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s library");
TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
controller.searchLibrary(target, source, game, opponent.getId());
target.getTargets().stream().map(cardId -> opponent.getLibrary().getCard(cardId, game)).forEach(cards::add);
Set<Card> cardSet = cards.getCards(game);
controller.moveCardsToExile(cardSet, source, game, true, exileId, exileName);
opponent.shuffleLibrary(source, game);
cardSet.add(card);
if (cardSet.isEmpty() || source.getSourcePermanentIfItStillExists(game) == null) {
return true;
}
KotoseTheSilentSpiderWatcher.addCards(source, cardSet, game);
for (Card exiledCard : cardSet) {
CardUtil.makeCardPlayable(game, source, exiledCard, Duration.WhileControlled, true, null, new KotoseTheSilentSpiderCondition(exiledCard, game));
}
return true;
}
use of mage.filter.FilterCard in project mage by magefree.
the class KozilekDiscardCost method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Spell targetSpell = game.getStack().getSpell(ability.getFirstTarget());
if (targetSpell == null) {
return false;
}
Player player = game.getPlayer(controllerId);
if (player == null) {
return false;
}
FilterCard filter = new FilterCard("card with mana value of " + targetSpell.getManaValue());
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, targetSpell.getManaValue()));
TargetCardInHand target = new TargetCardInHand(filter);
this.getTargets().clear();
this.getTargets().add(target);
if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), game)) {
for (UUID targetId : targets.get(0).getTargets()) {
Card card = player.getHand().get(targetId, game);
if (card == null) {
return false;
}
player.discard(card, true, source, game);
paid = true;
}
}
return paid;
}
use of mage.filter.FilterCard in project mage by magefree.
the class LostHoursEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (targetPlayer != null && controller != null) {
targetPlayer.revealCards(source, targetPlayer.getHand(), game);
if (targetPlayer.getHand().size() > 0) {
TargetCard target = new TargetCard(Zone.HAND, new FilterCard(StaticFilters.FILTER_CARD_A_NON_LAND));
if (controller.choose(Outcome.Discard, targetPlayer.getHand(), target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
targetPlayer.putCardOnTopXOfLibrary(card, game, source, 3, true);
}
}
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class MausoleumSecretsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int critterCount = player.getGraveyard().count(StaticFilters.FILTER_CARD_CREATURE, game);
FilterCard filter = new FilterCard("a black card with mana value less than or equal to " + critterCount);
filter.add(new ColorPredicate(ObjectColor.BLACK));
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, critterCount + 1));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true).apply(game, source);
}
Aggregations