mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
remove util function on converted manacost, make getColorIdentity default interface method
This commit is contained in:
parent
8a80976171
commit
2c34870bf0
8 changed files with 105 additions and 126 deletions
|
@ -150,7 +150,7 @@ public class Commander extends Constructed {
|
||||||
invalid.put("Commander", "Commander without Partner (" + commander.getName() + ')');
|
invalid.put("Commander", "Commander without Partner (" + commander.getName() + ')');
|
||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
FilterMana commanderColor = CardUtil.getColorIdentity(commander);
|
FilterMana commanderColor = commander.getColorIdentity();
|
||||||
if (commanderColor.isWhite()) {
|
if (commanderColor.isWhite()) {
|
||||||
colorIdentity.setWhite(true);
|
colorIdentity.setWhite(true);
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ public class Commander extends Constructed {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean cardHasValidColor(FilterMana commander, Card card) {
|
public boolean cardHasValidColor(FilterMana commander, Card card) {
|
||||||
FilterMana cardColor = CardUtil.getColorIdentity(card);
|
FilterMana cardColor = card.getColorIdentity();
|
||||||
return !(cardColor.isBlack() && !commander.isBlack()
|
return !(cardColor.isBlack() && !commander.isBlack()
|
||||||
|| cardColor.isBlue() && !commander.isBlue()
|
|| cardColor.isBlue() && !commander.isBlue()
|
||||||
|| cardColor.isGreen() && !commander.isGreen()
|
|| cardColor.isGreen() && !commander.isGreen()
|
||||||
|
@ -654,7 +654,7 @@ public class Commander extends Constructed {
|
||||||
color = color.union(commander.getColor(null));
|
color = color.union(commander.getColor(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterMana commanderColor = CardUtil.getColorIdentity(commander);
|
FilterMana commanderColor = commander.getColorIdentity();
|
||||||
if (commanderColor.isWhite()) {
|
if (commanderColor.isWhite()) {
|
||||||
color.setWhite(true);
|
color.setWhite(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ public class TinyLeaders extends Constructed {
|
||||||
if ((commander.isCreature() && commander.isLegendary())
|
if ((commander.isCreature() && commander.isLegendary())
|
||||||
|| (commander.isPlaneswalker() && commander.getAbilities().contains(CanBeYourCommanderAbility.getInstance()))) {
|
|| (commander.isPlaneswalker() && commander.getAbilities().contains(CanBeYourCommanderAbility.getInstance()))) {
|
||||||
if (!bannedCommander.contains(commander.getName())) {
|
if (!bannedCommander.contains(commander.getName())) {
|
||||||
FilterMana color = CardUtil.getColorIdentity(commander);
|
FilterMana color = commander.getColorIdentity();
|
||||||
for (Card card : deck.getCards()) {
|
for (Card card : deck.getCards()) {
|
||||||
if (!isCardFormatValid(card, commander, color)) {
|
if (!isCardFormatValid(card, commander, color)) {
|
||||||
valid = false;
|
valid = false;
|
||||||
|
@ -249,7 +249,7 @@ public class TinyLeaders extends Constructed {
|
||||||
* @return True if card has a valid color identity
|
* @return True if card has a valid color identity
|
||||||
*/
|
*/
|
||||||
public boolean cardHasValideColor(FilterMana commander, Card card) {
|
public boolean cardHasValideColor(FilterMana commander, Card card) {
|
||||||
FilterMana cardColor = CardUtil.getColorIdentity(card);
|
FilterMana cardColor = card.getColorIdentity();
|
||||||
return !(cardColor.isBlack() && !commander.isBlack()
|
return !(cardColor.isBlack() && !commander.isBlack()
|
||||||
|| cardColor.isBlue() && !commander.isBlue()
|
|| cardColor.isBlue() && !commander.isBlue()
|
||||||
|| cardColor.isGreen() && !commander.isGreen()
|
|| cardColor.isGreen() && !commander.isGreen()
|
||||||
|
|
|
@ -99,7 +99,7 @@ class CounterbalanceEffect extends OneShotEffect {
|
||||||
CardsImpl cards = new CardsImpl();
|
CardsImpl cards = new CardsImpl();
|
||||||
cards.add(topcard);
|
cards.add(topcard);
|
||||||
controller.revealCards(sourcePermanent.getName(), cards, game);
|
controller.revealCards(sourcePermanent.getName(), cards, game);
|
||||||
if (CardUtil.convertedManaCostsIsEqual(topcard, spell)) {
|
if (topcard.getConvertedManaCost() == spell.getConvertedManaCost()) {
|
||||||
return game.getStack().counter(spell.getId(), source.getSourceId(), game);
|
return game.getStack().counter(spell.getId(), source.getSourceId(), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,7 @@ class HisokaMinamoSenseiCounterEffect extends OneShotEffect {
|
||||||
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
|
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
|
||||||
if (spell != null) {
|
if (spell != null) {
|
||||||
HisokaMinamoSenseiDiscardTargetCost cost = (HisokaMinamoSenseiDiscardTargetCost) source.getCosts().get(0);
|
HisokaMinamoSenseiDiscardTargetCost cost = (HisokaMinamoSenseiDiscardTargetCost) source.getCosts().get(0);
|
||||||
if (cost != null && CardUtil.convertedManaCostsIsEqual(cost.getDiscardedCard(), spell)) {
|
if (cost != null && cost.getDiscardedCard().getConvertedManaCost() == spell.getConvertedManaCost()) {
|
||||||
return game.getStack().counter(targetPointer.getFirst(game, source), source.getSourceId(), game);
|
return game.getStack().counter(targetPointer.getFirst(game, source), source.getSourceId(), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class CommanderColorIdentityTest extends CardTestCommander3PlayersFFA {
|
||||||
throw new IllegalArgumentException("Couldn't find the card " + cardName + " in the DB.");
|
throw new IllegalArgumentException("Couldn't find the card " + cardName + " in the DB.");
|
||||||
}
|
}
|
||||||
Card card = cardInfo.getCard();
|
Card card = cardInfo.getCard();
|
||||||
FilterMana filterMana = CardUtil.getColorIdentity(card);
|
FilterMana filterMana = card.getColorIdentity();
|
||||||
return filterMana.toString();
|
return filterMana.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class CommanderColorIdentityManaAbility extends ActivatedManaAbilityImpl
|
||||||
for (UUID commanderId : controller.getCommandersIds()) {
|
for (UUID commanderId : controller.getCommandersIds()) {
|
||||||
Card commander = game.getCard(commanderId);
|
Card commander = game.getCard(commanderId);
|
||||||
if (commander != null) {
|
if (commander != null) {
|
||||||
FilterMana commanderMana = CardUtil.getColorIdentity(commander);
|
FilterMana commanderMana = commander.getColorIdentity();
|
||||||
if (commanderMana.isBlack()) {
|
if (commanderMana.isBlack()) {
|
||||||
netMana.add(new Mana(ColoredManaSymbol.B));
|
netMana.add(new Mana(ColoredManaSymbol.B));
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ class CommanderIdentityManaEffect extends ManaEffect {
|
||||||
for (UUID commanderId : controller.getCommandersIds()) {
|
for (UUID commanderId : controller.getCommandersIds()) {
|
||||||
Card commander = game.getCard(commanderId);
|
Card commander = game.getCard(commanderId);
|
||||||
if (commander != null) {
|
if (commander != null) {
|
||||||
FilterMana commanderMana = CardUtil.getColorIdentity(commander);
|
FilterMana commanderMana = commander.getColorIdentity();
|
||||||
if (commanderMana.isWhite()) {
|
if (commanderMana.isWhite()) {
|
||||||
choice.getChoices().add("White");
|
choice.getChoices().add("White");
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.Mana;
|
import mage.Mana;
|
||||||
|
import mage.ObjectColor;
|
||||||
import mage.abilities.Abilities;
|
import mage.abilities.Abilities;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.SpellAbility;
|
import mage.abilities.SpellAbility;
|
||||||
|
@ -40,12 +41,21 @@ import mage.constants.Rarity;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.counters.Counter;
|
import mage.counters.Counter;
|
||||||
import mage.counters.Counters;
|
import mage.counters.Counters;
|
||||||
|
import mage.filter.FilterMana;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.GameState;
|
import mage.game.GameState;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
|
||||||
public interface Card extends MageObject {
|
public interface Card extends MageObject {
|
||||||
|
|
||||||
|
|
||||||
|
final String regexBlack = ".*\\x7b.{0,2}B.{0,2}\\x7d.*";
|
||||||
|
final String regexBlue = ".*\\x7b.{0,2}U.{0,2}\\x7d.*";
|
||||||
|
final String regexRed = ".*\\x7b.{0,2}R.{0,2}\\x7d.*";
|
||||||
|
final String regexGreen = ".*\\x7b.{0,2}G.{0,2}\\x7d.*";
|
||||||
|
final String regexWhite = ".*\\x7b.{0,2}W.{0,2}\\x7d.*";
|
||||||
|
|
||||||
|
|
||||||
UUID getOwnerId();
|
UUID getOwnerId();
|
||||||
|
|
||||||
String getCardNumber();
|
String getCardNumber();
|
||||||
|
@ -176,6 +186,67 @@ public interface Card extends MageObject {
|
||||||
*/
|
*/
|
||||||
Card getMainCard();
|
Card getMainCard();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the colors that are in the casting cost but also in the rules text
|
||||||
|
* as far as not included in reminder text.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
default FilterMana getColorIdentity() {
|
||||||
|
FilterMana mana = new FilterMana();
|
||||||
|
mana.setBlack(getManaCost().getText().matches(regexBlack));
|
||||||
|
mana.setBlue(getManaCost().getText().matches(regexBlue));
|
||||||
|
mana.setGreen(getManaCost().getText().matches(regexGreen));
|
||||||
|
mana.setRed(getManaCost().getText().matches(regexRed));
|
||||||
|
mana.setWhite(getManaCost().getText().matches(regexWhite));
|
||||||
|
|
||||||
|
for (String rule : getRules()) {
|
||||||
|
rule = rule.replaceAll("(?i)<i.*?</i>", ""); // Ignoring reminder text in italic
|
||||||
|
if (!mana.isBlack() && rule.matches(regexBlack)) {
|
||||||
|
mana.setBlack(true);
|
||||||
|
}
|
||||||
|
if (!mana.isBlue() && rule.matches(regexBlue)) {
|
||||||
|
mana.setBlue(true);
|
||||||
|
}
|
||||||
|
if (!mana.isGreen() && rule.matches(regexGreen)) {
|
||||||
|
mana.setGreen(true);
|
||||||
|
}
|
||||||
|
if (!mana.isRed() && rule.matches(regexRed)) {
|
||||||
|
mana.setRed(true);
|
||||||
|
}
|
||||||
|
if (!mana.isWhite() && rule.matches(regexWhite)) {
|
||||||
|
mana.setWhite(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isTransformable()) {
|
||||||
|
Card secondCard = getSecondCardFace();
|
||||||
|
ObjectColor color = secondCard.getColor(null);
|
||||||
|
mana.setBlack(mana.isBlack() || color.isBlack());
|
||||||
|
mana.setGreen(mana.isGreen() || color.isGreen());
|
||||||
|
mana.setRed(mana.isRed() || color.isRed());
|
||||||
|
mana.setBlue(mana.isBlue() || color.isBlue());
|
||||||
|
mana.setWhite(mana.isWhite() || color.isWhite());
|
||||||
|
for (String rule : secondCard.getRules()) {
|
||||||
|
rule = rule.replaceAll("(?i)<i.*?</i>", ""); // Ignoring reminder text in italic
|
||||||
|
if (!mana.isBlack() && rule.matches(regexBlack)) {
|
||||||
|
mana.setBlack(true);
|
||||||
|
}
|
||||||
|
if (!mana.isBlue() && rule.matches(regexBlue)) {
|
||||||
|
mana.setBlue(true);
|
||||||
|
}
|
||||||
|
if (!mana.isGreen() && rule.matches(regexGreen)) {
|
||||||
|
mana.setGreen(true);
|
||||||
|
}
|
||||||
|
if (!mana.isRed() && rule.matches(regexRed)) {
|
||||||
|
mana.setRed(true);
|
||||||
|
}
|
||||||
|
if (!mana.isWhite() && rule.matches(regexWhite)) {
|
||||||
|
mana.setWhite(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return mana;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.Mana;
|
import mage.Mana;
|
||||||
import mage.ObjectColor;
|
import mage.ObjectColor;
|
||||||
|
@ -52,11 +53,6 @@ import mage.util.functions.CopyTokenFunction;
|
||||||
*/
|
*/
|
||||||
public final class CardUtil {
|
public final class CardUtil {
|
||||||
|
|
||||||
private static final String regexBlack = ".*\\x7b.{0,2}B.{0,2}\\x7d.*";
|
|
||||||
private static final String regexBlue = ".*\\x7b.{0,2}U.{0,2}\\x7d.*";
|
|
||||||
private static final String regexRed = ".*\\x7b.{0,2}R.{0,2}\\x7d.*";
|
|
||||||
private static final String regexGreen = ".*\\x7b.{0,2}G.{0,2}\\x7d.*";
|
|
||||||
private static final String regexWhite = ".*\\x7b.{0,2}W.{0,2}\\x7d.*";
|
|
||||||
|
|
||||||
private static final String SOURCE_EXILE_ZONE_TEXT = "SourceExileZone";
|
private static final String SOURCE_EXILE_ZONE_TEXT = "SourceExileZone";
|
||||||
|
|
||||||
|
@ -81,9 +77,6 @@ public final class CardUtil {
|
||||||
public static final Set<String> NON_CREATURE_SUBTYPES = new HashSet<>(Arrays.asList(NON_CHANGELING_SUBTYPES_VALUES));
|
public static final Set<String> NON_CREATURE_SUBTYPES = new HashSet<>(Arrays.asList(NON_CHANGELING_SUBTYPES_VALUES));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increase spell or ability cost to be paid.
|
* Increase spell or ability cost to be paid.
|
||||||
*
|
*
|
||||||
|
@ -164,7 +157,6 @@ public final class CardUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void reduceCost(SpellAbility spellAbility, ManaCosts<ManaCost> manaCostsToReduce) {
|
public static void reduceCost(SpellAbility spellAbility, ManaCosts<ManaCost> manaCostsToReduce) {
|
||||||
adjustCost(spellAbility, manaCostsToReduce, true);
|
adjustCost(spellAbility, manaCostsToReduce, true);
|
||||||
}
|
}
|
||||||
|
@ -513,91 +505,7 @@ public final class CardUtil {
|
||||||
return "<font color = 'blue'>" + text + "</font>";
|
return "<font color = 'blue'>" + text + "</font>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean convertedManaCostsIsEqual(MageObject object1, MageObject object2) {
|
|
||||||
Set<Integer> cmcObject1 = getCMC(object1);
|
|
||||||
Set<Integer> cmcObject2 = getCMC(object2);
|
|
||||||
for (Integer integer : cmcObject1) {
|
|
||||||
if (cmcObject2.contains(integer)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Set<Integer> getCMC(MageObject object) {
|
|
||||||
Set<Integer> cmcObject = new HashSet<>();
|
|
||||||
if (object instanceof Spell) {
|
|
||||||
cmcObject.add(object.getConvertedManaCost());
|
|
||||||
} else if (object instanceof Card) {
|
|
||||||
Card card = (Card) object;
|
|
||||||
cmcObject.add(card.getConvertedManaCost());
|
|
||||||
}
|
|
||||||
return cmcObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the colors that are in the casting cost but also in the rules text
|
|
||||||
* as far as not included in reminder text.
|
|
||||||
*
|
|
||||||
* @param card
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static FilterMana getColorIdentity(Card card) {
|
|
||||||
FilterMana mana = new FilterMana();
|
|
||||||
mana.setBlack(card.getManaCost().getText().matches(regexBlack));
|
|
||||||
mana.setBlue(card.getManaCost().getText().matches(regexBlue));
|
|
||||||
mana.setGreen(card.getManaCost().getText().matches(regexGreen));
|
|
||||||
mana.setRed(card.getManaCost().getText().matches(regexRed));
|
|
||||||
mana.setWhite(card.getManaCost().getText().matches(regexWhite));
|
|
||||||
|
|
||||||
for (String rule : card.getRules()) {
|
|
||||||
rule = rule.replaceAll("(?i)<i.*?</i>", ""); // Ignoring reminder text in italic
|
|
||||||
if (!mana.isBlack() && rule.matches(regexBlack)) {
|
|
||||||
mana.setBlack(true);
|
|
||||||
}
|
|
||||||
if (!mana.isBlue() && rule.matches(regexBlue)) {
|
|
||||||
mana.setBlue(true);
|
|
||||||
}
|
|
||||||
if (!mana.isGreen() && rule.matches(regexGreen)) {
|
|
||||||
mana.setGreen(true);
|
|
||||||
}
|
|
||||||
if (!mana.isRed() && rule.matches(regexRed)) {
|
|
||||||
mana.setRed(true);
|
|
||||||
}
|
|
||||||
if (!mana.isWhite() && rule.matches(regexWhite)) {
|
|
||||||
mana.setWhite(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (card.isTransformable()) {
|
|
||||||
Card secondCard = card.getSecondCardFace();
|
|
||||||
ObjectColor color = secondCard.getColor(null);
|
|
||||||
mana.setBlack(mana.isBlack() || color.isBlack());
|
|
||||||
mana.setGreen(mana.isGreen() || color.isGreen());
|
|
||||||
mana.setRed(mana.isRed() || color.isRed());
|
|
||||||
mana.setBlue(mana.isBlue() || color.isBlue());
|
|
||||||
mana.setWhite(mana.isWhite() || color.isWhite());
|
|
||||||
for (String rule : secondCard.getRules()) {
|
|
||||||
rule = rule.replaceAll("(?i)<i.*?</i>", ""); // Ignoring reminder text in italic
|
|
||||||
if (!mana.isBlack() && rule.matches(regexBlack)) {
|
|
||||||
mana.setBlack(true);
|
|
||||||
}
|
|
||||||
if (!mana.isBlue() && rule.matches(regexBlue)) {
|
|
||||||
mana.setBlue(true);
|
|
||||||
}
|
|
||||||
if (!mana.isGreen() && rule.matches(regexGreen)) {
|
|
||||||
mana.setGreen(true);
|
|
||||||
}
|
|
||||||
if (!mana.isRed() && rule.matches(regexRed)) {
|
|
||||||
mana.setRed(true);
|
|
||||||
}
|
|
||||||
if (!mana.isWhite() && rule.matches(regexWhite)) {
|
|
||||||
mana.setWhite(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mana;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isNonCreatureSubtype(String subtype) {
|
public static boolean isNonCreatureSubtype(String subtype) {
|
||||||
return NON_CREATURE_SUBTYPES.contains(subtype);
|
return NON_CREATURE_SUBTYPES.contains(subtype);
|
||||||
|
|
Loading…
Reference in a new issue