use of mage.filter.FilterCard in project mage by magefree.
the class SufferThePastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterCard filter = new FilterCard("card in target player's graveyard");
int numberExiled = 0;
Player you = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (targetPlayer != null) {
int numberToTarget = Math.min(targetPlayer.getGraveyard().size(), source.getManaCostsToPay().getX());
TargetCardInOpponentsGraveyard target = new TargetCardInOpponentsGraveyard(numberToTarget, numberToTarget, filter);
if (you != null) {
if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
if (!target.getTargets().isEmpty()) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = game.getCard(targetId);
if (card != null) {
card.moveToExile(id, "Suffer the Past", source, game);
numberExiled++;
}
}
you.gainLife(numberExiled, game, source);
targetPlayer.loseLife(numberExiled, game, source, false);
}
}
return true;
}
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class CardCanBeCastPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.getLibrary().hasCards()) {
/**
* 10/1/2005 Any card you find must be legally cast-able (for
* example, you have to be able to choose a legal target for
* it). If you can't find a cast-able card (or choose not to),
* nothing happens and you shuffle your library.
*/
FilterCard filter = new FilterCard("red or white instant card with mana value 4 or less");
TargetCardInLibrary target = new TargetCardInLibrary(filter);
filter.add(Predicates.or(new ColorPredicate(ObjectColor.RED), new ColorPredicate(ObjectColor.WHITE)));
filter.add(CardType.INSTANT.getPredicate());
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, 5));
filter.add(new CardCanBeCastPredicate(source.getControllerId()));
if (controller.searchLibrary(target, source, game, controller.getId())) {
UUID targetId = target.getFirstTarget();
Card card = game.getCard(targetId);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.filter.FilterCard 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.FilterCard in project mage by magefree.
the class ReplaceOpponentCardsInHandWithSelectedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null && targetOpponent != null) {
int originalHandSize = targetOpponent.getHand().size();
if (originalHandSize > 0) {
targetOpponent.putCardsOnTopOfLibrary(targetOpponent.getHand(), game, source, false);
int librarySize = targetOpponent.getLibrary().size();
int searchLibraryForNum = min(originalHandSize, librarySize);
TargetCardInLibrary target = new TargetCardInLibrary(searchLibraryForNum, searchLibraryForNum, new FilterCard());
controller.searchLibrary(target, source, game, targetOpponent.getId());
for (UUID cardId : target.getTargets()) {
Card targetCard = game.getCard(cardId);
targetOpponent.moveCards(targetCard, Zone.HAND, source, game);
}
targetOpponent.shuffleLibrary(source, game);
}
return true;
}
return false;
}
use of mage.filter.FilterCard in project mage by magefree.
the class CardSelector method buildFilter.
private FilterCard buildFilter() {
FilterCard filter = new FilterCard();
String name = jTextFieldSearch.getText().trim();
filter.add(new CardTextPredicate(name, chkNames.isSelected(), chkTypes.isSelected(), chkRules.isSelected(), chkUnique.isSelected()));
if (limited) {
List<Predicate<MageObject>> predicates = new ArrayList<>();
if (this.tbGreen.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.GREEN));
}
if (this.tbRed.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.RED));
}
if (this.tbBlack.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.BLACK));
}
if (this.tbBlue.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.BLUE));
}
if (this.tbWhite.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.WHITE));
}
if (this.tbColorless.isSelected()) {
predicates.add(ColorlessPredicate.instance);
}
filter.add(Predicates.or(predicates));
predicates.clear();
if (this.tbLand.isSelected()) {
predicates.add(CardType.LAND.getPredicate());
}
if (this.tbArifiacts.isSelected()) {
predicates.add(CardType.ARTIFACT.getPredicate());
}
if (this.tbCreatures.isSelected()) {
predicates.add(CardType.CREATURE.getPredicate());
}
if (this.tbEnchantments.isSelected()) {
predicates.add(CardType.ENCHANTMENT.getPredicate());
}
if (this.tbInstants.isSelected()) {
predicates.add(CardType.INSTANT.getPredicate());
}
if (this.tbSorceries.isSelected()) {
predicates.add(CardType.SORCERY.getPredicate());
}
if (this.tbPlaneswalkers.isSelected()) {
predicates.add(CardType.PLANESWALKER.getPredicate());
}
filter.add(Predicates.or(predicates));
List<String> filteredSets = getFilteredSets();
if (!filteredSets.isEmpty()) {
List<Predicate<Card>> expansionPredicates = new ArrayList<>();
for (String setCode : filteredSets) {
expansionPredicates.add(new ExpansionSetPredicate(setCode));
}
filter.add(Predicates.or(expansionPredicates));
}
}
return filter;
}
Aggregations