Search in sources :

Example 41 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class ManaUtil method getColorIdentity.

/**
 * Find full card's color identity (from mana cost and rules)
 *
 * @param cardColor       color indicator
 * @param cardManaSymbols mana cost
 * @param cardRules       rules list
 * @param secondSideCard  second side of double faces card
 * @return
 */
public static FilterMana getColorIdentity(ObjectColor cardColor, String cardManaSymbols, List<String> cardRules, Card secondSideCard) {
    // 20210121
    // 903.4
    // The Commander variant uses color identity to determine what cards can be in a deck with a certain
    // commander. The color identity of a card is the color or colors of any mana symbols in that card’s mana
    // cost or rules text, plus any colors defined by its characteristic-defining abilities (see rule 604.3)
    // or color indicator (see rule 204).
    // 903.4d
    // The back face of a double-faced card (see rule 711) is included when determining a card’s color identity.
    // This is an exception to rule 711.4a.
    FilterMana res = new FilterMana();
    // from object (color indicator)
    ObjectColor color = (cardColor != null ? new ObjectColor(cardColor) : new ObjectColor());
    // from mana
    res.setWhite(color.isWhite() || containsManaSymbol(cardManaSymbols, "W"));
    res.setBlue(color.isBlue() || containsManaSymbol(cardManaSymbols, "U"));
    res.setBlack(color.isBlack() || containsManaSymbol(cardManaSymbols, "B"));
    res.setRed(color.isRed() || containsManaSymbol(cardManaSymbols, "R"));
    res.setGreen(color.isGreen() || containsManaSymbol(cardManaSymbols, "G"));
    // from rules
    for (String rule : cardRules) {
        // Ignoring reminder text in italic
        rule = rule.replaceAll("(?i)<i.*?</i>", "");
        if (!res.isWhite() && (rule.matches(regexWhite))) {
            res.setWhite(true);
        }
        if (!res.isBlue() && (rule.matches(regexBlue))) {
            res.setBlue(true);
        }
        if (!res.isBlack() && rule.matches(regexBlack)) {
            res.setBlack(true);
        }
        if (!res.isRed() && (rule.matches(regexRed))) {
            res.setRed(true);
        }
        if (!res.isGreen() && (rule.matches(regexGreen))) {
            res.setGreen(true);
        }
    }
    // SECOND SIDE CARD
    if (secondSideCard != null) {
        // from object (color indicator)
        ObjectColor secondColor = secondSideCard.getColor(null);
        res.setBlack(res.isBlack() || secondColor.isBlack());
        res.setGreen(res.isGreen() || secondColor.isGreen());
        res.setRed(res.isRed() || secondColor.isRed());
        res.setBlue(res.isBlue() || secondColor.isBlue());
        res.setWhite(res.isWhite() || secondColor.isWhite());
        // from mana
        List<String> secondManaSymbols = secondSideCard.getManaCostSymbols();
        res.setWhite(res.isWhite() || containsManaSymbol(secondManaSymbols, "W"));
        res.setBlue(res.isBlue() || containsManaSymbol(secondManaSymbols, "U"));
        res.setBlack(res.isBlack() || containsManaSymbol(secondManaSymbols, "B"));
        res.setRed(res.isRed() || containsManaSymbol(secondManaSymbols, "R"));
        res.setGreen(res.isGreen() || containsManaSymbol(secondManaSymbols, "G"));
        // from rules
        for (String rule : secondSideCard.getRules()) {
            // Ignoring reminder text in italic
            rule = rule.replaceAll("(?i)<i.*?</i>", "");
            if (!res.isWhite() && rule.matches(regexWhite)) {
                res.setWhite(true);
            }
            if (!res.isBlue() && rule.matches(regexBlue)) {
                res.setBlue(true);
            }
            if (!res.isBlack() && rule.matches(regexBlack)) {
                res.setBlack(true);
            }
            if (!res.isRed() && rule.matches(regexRed)) {
                res.setRed(true);
            }
            if (!res.isGreen() && rule.matches(regexGreen)) {
                res.setGreen(true);
            }
        }
    }
    return res;
}
Also used : FilterMana(mage.filter.FilterMana) ObjectColor(mage.ObjectColor)

Example 42 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class CreatureToken method withColor.

public CreatureToken withColor(String extraColors) {
    ObjectColor extraColorsList = new ObjectColor(extraColors);
    this.getColor(null).addColor(extraColorsList);
    return this;
}
Also used : ObjectColor(mage.ObjectColor)

Example 43 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class EarnestFellowshipEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
        if (permanent.getColor(game).hasColor()) {
            List<ColorPredicate> colorPredicates = new ArrayList<>();
            for (ObjectColor color : permanent.getColor(game).getColors()) {
                colorPredicates.add(new ColorPredicate(color));
            }
            FilterCard filterColors = new FilterCard("its colors");
            filterColors.add(Predicates.or(colorPredicates));
            Ability ability = new ProtectionAbility(filterColors);
            permanent.addAbility(ability, source.getSourceId(), game);
        }
    }
    return true;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) FilterCard(mage.filter.FilterCard) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) ProtectionAbility(mage.abilities.keyword.ProtectionAbility) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ArrayList(java.util.ArrayList) ObjectColor(mage.ObjectColor) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 44 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class HarshJudgmentEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (event.getTargetId().equals(source.getControllerId())) {
        Spell spell = null;
        StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
        if (stackObject == null) {
            stackObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
        }
        if (stackObject instanceof Spell) {
            spell = (Spell) stackObject;
        }
        // Checks if damage is from a sorcery or instants and spell is of chosen color
        Permanent permanent = game.getPermanent(source.getSourceId());
        ObjectColor color = (ObjectColor) game.getState().getValue(permanent.getId() + "_color");
        if (spell != null && instantOrSorceryFilter.match(spell.getCard(), game) && spell.getColor(game).contains(color)) {
            TargetPlayer target = new TargetPlayer();
            target.add(spell.getControllerId(), game);
            redirectTarget = target;
            return true;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) StackObject(mage.game.stack.StackObject) ObjectColor(mage.ObjectColor) Spell(mage.game.stack.Spell) TargetPlayer(mage.target.TargetPlayer)

Example 45 with ObjectColor

use of mage.ObjectColor in project mage by magefree.

the class InciteHysteriaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (target != null) {
            ObjectColor color = target.getColor(game);
            for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
                if (permanent.getColor(game).shares(color)) {
                    ContinuousEffect effect = new GainAbilityTargetEffect(new CantBlockAbility(), Duration.EndOfTurn);
                    effect.setTargetPointer(new FixedTarget(permanent, game));
                    game.addEffect(effect, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ObjectColor(mage.ObjectColor) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) CantBlockAbility(mage.abilities.common.CantBlockAbility)

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