use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class SelfInflictedWoundEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetOpponent = game.getPlayer(source.getTargets().getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (targetOpponent == null || controller == null) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent("a green or white creature");
filter.add(CardType.CREATURE.getPredicate());
filter.add(TargetController.YOU.getControllerPredicate());
filter.add(Predicates.or(new ColorPredicate(ObjectColor.GREEN), new ColorPredicate(ObjectColor.WHITE)));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), targetOpponent.getId(), game)) {
targetOpponent.chooseTarget(Outcome.Sacrifice, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
if (permanent.sacrifice(source, game)) {
targetOpponent.loseLife(2, game, source, false);
}
}
}
return true;
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class GainProtectionFromColorSourceEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ChoiceColor colorChoice = new ChoiceColor(true);
colorChoice.setMessage("Choose color for protection ability");
if (controller.choose(outcome, colorChoice, game)) {
game.informPlayers("Choosen color: " + colorChoice.getColor());
protectionFilter.add(new ColorPredicate(colorChoice.getColor()));
protectionFilter.setMessage(colorChoice.getChoice());
((ProtectionAbility) ability).setFilter(protectionFilter);
return;
}
}
discard();
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class ProtectionAbility method from.
public static ProtectionAbility from(ObjectColor color) {
FilterObject filter = new FilterObject(getFilterText(color));
filter.add(new ColorPredicate(color));
ProtectionAbility ability = new ProtectionAbility(filter);
ability.getFromColor().addColor(color);
return ability;
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class TargetControlledCreatureEachColor method makeFilter.
private static final FilterControlledPermanent makeFilter(String colors) {
List<ObjectColor> objectColors = Arrays.stream(colors.split("")).map(ObjectColor::new).collect(Collectors.toList());
FilterControlledPermanent filter = new FilterControlledCreaturePermanent(CardUtil.concatWithAnd(objectColors.stream().map(ObjectColor::getDescription).map(s -> CardUtil.addArticle(s) + " creature").collect(Collectors.toList())));
filter.add(Predicates.or(objectColors.stream().map(ColorPredicate::new).collect(Collectors.toList())));
return filter;
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class AddleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
ChoiceColor choice = new ChoiceColor();
if (controller != null && controller.choose(outcome, choice, game)) {
ObjectColor color = choice.getColor();
game.informPlayers(controller.getLogName() + " chooses " + color + '.');
FilterCard filter = new FilterCard();
filter.add(new ColorPredicate(color));
Effect effect = new DiscardCardYouChooseTargetEffect(filter);
return effect.apply(game, source);
}
return false;
}
Aggregations