Search in sources :

Example 81 with ObjectColor

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;
}
Also used : SimpleActivatedAbility(mage.abilities.common.SimpleActivatedAbility) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) FilterCard(mage.filter.FilterCard) ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) ObjectColor(mage.ObjectColor)

Example 82 with ObjectColor

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;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ObjectColor(mage.ObjectColor)

Aggregations

ObjectColor (mage.ObjectColor)82 Permanent (mage.game.permanent.Permanent)50 Player (mage.players.Player)27 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)19 UUID (java.util.UUID)14 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)14 Card (mage.cards.Card)13 FilterPermanent (mage.filter.FilterPermanent)13 Spell (mage.game.stack.Spell)12 Ability (mage.abilities.Ability)10 FixedTarget (mage.target.targetpointer.FixedTarget)10 ChoiceColor (mage.choices.ChoiceColor)9 Mana (mage.Mana)8 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)8 ArrayList (java.util.ArrayList)7 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 ProtectionAbility (mage.abilities.keyword.ProtectionAbility)7 FilterCard (mage.filter.FilterCard)7 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)6 MageObject (mage.MageObject)5