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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations