use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class ApostlesBlessingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
ChoiceColorOrArtifact choice = new ChoiceColorOrArtifact();
if (controller.choose(outcome, choice, game)) {
FilterCard protectionFilter = new FilterCard();
if (choice.isArtifactSelected()) {
protectionFilter.add(CardType.ARTIFACT.getPredicate());
} else {
protectionFilter.add(new ColorPredicate(choice.getColor()));
}
protectionFilter.setMessage(choice.getChoice());
ProtectionAbility protectionAbility = new ProtectionAbility(protectionFilter);
ContinuousEffect effect = new GainAbilityTargetEffect(protectionAbility, Duration.EndOfTurn);
effect.setTargetPointer(getTargetPointer());
game.addEffect(effect, source);
return true;
}
}
return false;
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class CephalidSnitchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetCreature = game.getPermanent(targetPointer.getFirst(game, source));
if (targetCreature != null) {
List<Ability> toRemove = new ArrayList<>();
// Go through protection abilities and sort out any containing black
for (ProtectionAbility a : targetCreature.getAbilities().getProtectionAbilities()) {
ObjectColor colors = a.getFromColor();
if (colors.isBlack()) {
List<ObjectColor> nonBlackColors = colors.intersection(NONBLACK).getColors();
if (!nonBlackColors.isEmpty()) {
// If the ability is protection from multiple colors, construct a new filter excluding black
FilterCard filter = new FilterCard(filterNameAssembler(nonBlackColors));
if (nonBlackColors.size() == 1)
filter.add(new ColorPredicate(nonBlackColors.get(0)));
else if (nonBlackColors.size() == 2)
filter.add(Predicates.or(new ColorPredicate(nonBlackColors.get(0)), new ColorPredicate(nonBlackColors.get(1))));
else if (nonBlackColors.size() == 3)
filter.add(Predicates.or(new ColorPredicate(nonBlackColors.get(0)), new ColorPredicate(nonBlackColors.get(1)), new ColorPredicate(nonBlackColors.get(2))));
else if (nonBlackColors.size() == 4)
filter.add(Predicates.or(new ColorPredicate(nonBlackColors.get(0)), new ColorPredicate(nonBlackColors.get(1)), new ColorPredicate(nonBlackColors.get(2)), new ColorPredicate(nonBlackColors.get(3))));
a.setFilter(filter);
} else {
// if the ability is just protection from black, remove it from the creature
toRemove.add(a);
}
}
}
targetCreature.removeAbilities(toRemove, source.getSourceId(), game);
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class DarigaazTheIgniterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
ChoiceColor choice = new ChoiceColor(true);
if (controller != null && controller.choose(outcome, choice, game)) {
game.informPlayers(controller.getLogName() + " chooses " + choice.getColor());
Player damagedPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (damagedPlayer != null) {
damagedPlayer.revealCards("hand of " + damagedPlayer.getName(), damagedPlayer.getHand(), game);
FilterCard filter = new FilterCard();
filter.add(new ColorPredicate(choice.getColor()));
int damage = damagedPlayer.getHand().count(filter, source.getSourceId(), source.getControllerId(), game);
if (damage > 0) {
damagedPlayer.damage(damage, source.getSourceId(), source, game);
}
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.ColorPredicate in project mage by magefree.
the class DarkTemperEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
if (permanent == null) {
return false;
}
FilterPermanent filter = new FilterPermanent("black permanent");
filter.add(new ColorPredicate(ObjectColor.BLACK));
if (game.getBattlefield().countAll(filter, source.getControllerId(), game) == 0) {
permanent.damage(2, source.getSourceId(), source, game, false, true);
} else {
permanent.destroy(source, game, false);
}
return true;
}
Aggregations