use of mage.ObjectColor 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.ObjectColor in project mage by magefree.
the class BrightflameEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent target = game.getPermanent(targetPointer.getFirst(game, source));
int damageDealt = 0;
if (target != null) {
ObjectColor color = target.getColor(game);
damageDealt += target.damage(amount.calculate(game, source, this), source.getSourceId(), source, game);
for (Permanent p : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
if (!target.getId().equals(p.getId()) && p.getColor(game).shares(color)) {
damageDealt += p.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, true);
}
}
Player you = game.getPlayer(source.getControllerId());
if (you != null && damageDealt > 0) {
you.gainLife(damageDealt, game, source);
}
return true;
}
return false;
}
Aggregations