use of mage.filter.predicate.Predicate in project mage by magefree.
the class CounterlashEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (stackObject != null && controller != null) {
game.getStack().counter(source.getFirstTarget(), source, game);
if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
FilterCard filter = new FilterCard();
List<Predicate<MageObject>> types = new ArrayList<>();
for (CardType type : stackObject.getCardType(game)) {
if (type != CardType.LAND) {
types.add(type.getPredicate());
}
}
filter.add(Predicates.or(types));
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card card = controller.getHand().get(target.getFirstTarget(), game);
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);
}
}
}
return true;
}
return false;
}
use of mage.filter.predicate.Predicate in project mage by magefree.
the class ElementalAppealEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
CreateTokenEffect effect = new CreateTokenEffect(new RedElementalWithTrampleAndHaste());
if (effect.apply(game, source)) {
effect.exileTokensCreatedAtNextEndStep(game, source);
if (KickedCondition.instance.apply(game, source)) {
List<Predicate<MageObject>> predList = new ArrayList<>();
for (UUID tokenId : effect.getLastAddedTokenIds()) {
predList.add(new CardIdPredicate(tokenId));
}
if (!predList.isEmpty()) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.or(predList));
game.addEffect(new BoostAllEffect(7, 0, Duration.EndOfTurn, filter, false), source);
}
}
return true;
}
return false;
}
use of mage.filter.predicate.Predicate 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;
}
use of mage.filter.predicate.Predicate in project mage by magefree.
the class CrypticGatewayPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
if (source.getCosts() == null) {
return false;
}
FilterCard filter = new FilterCreatureCard("creature card from your hand that shares a creature type with each creature tapped this way");
for (Cost cost : source.getCosts()) {
if (cost instanceof CrypticGatewayCost) {
Predicate predicate = ((CrypticGatewayCost) cost).getPredicate();
filter.add(predicate);
return new PutCardFromHandOntoBattlefieldEffect(filter).apply(game, source);
}
}
return false;
}
use of mage.filter.predicate.Predicate in project mage by magefree.
the class NecromanticSelectionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Cards cards = new CardsImpl();
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), source.getSourceId(), game)) {
permanent.destroy(source, game, false);
// Meren of the Clan Nel Toth bug #8515
game.checkStateAndTriggered();
if (game.getState().getZone(permanent.getId()) == Zone.GRAVEYARD) {
cards.add(permanent);
}
}
FilterCard filter = new FilterCreatureCard("creature card put into a graveyard with " + sourceObject.getLogName());
List<Predicate<MageObject>> cardIdPredicates = new ArrayList<>();
for (UUID cardId : cards) {
cardIdPredicates.add(new CardIdPredicate(cardId));
}
filter.add(Predicates.or(cardIdPredicates));
Target target = new TargetCardInGraveyard(filter);
target.setNotTarget(true);
if (controller.chooseTarget(Outcome.Benefit, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
ContinuousEffect effect = new BecomesBlackZombieAdditionEffect();
effect.setText("It's a black Zombie in addition to its other colors and types");
effect.setTargetPointer(new FixedTarget(card.getId(), game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
Aggregations