forked from External/mage
Fixed color identity evaluation not checking second card face.
This commit is contained in:
parent
853456377a
commit
6c141a1f3e
3 changed files with 146 additions and 5 deletions
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package org.mage.test.commander;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.filter.FilterMana;
|
||||
import mage.util.CardUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mage.test.serverside.base.CardTestCommander3PlayersFFA;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class CommanderColorIdentityTest extends CardTestCommander3PlayersFFA {
|
||||
|
||||
@Test
|
||||
public void TestColors() {
|
||||
// Basic Colors
|
||||
Assert.assertEquals("{B}", getColorIdentityString("Sengir Vampire"));
|
||||
Assert.assertEquals("{G}", getColorIdentityString("Elvish Visionary"));
|
||||
Assert.assertEquals("{R}", getColorIdentityString("Demolish"));
|
||||
Assert.assertEquals("{U}", getColorIdentityString("Negate"));
|
||||
Assert.assertEquals("{W}", getColorIdentityString("Silvercoat Lion"));
|
||||
|
||||
// Multicolor
|
||||
Assert.assertEquals("{G}{W}", getColorIdentityString("Veteran Warleader"));
|
||||
Assert.assertEquals("{B}{R}", getColorIdentityString("Forerunner of Slaughter"));
|
||||
Assert.assertEquals("{R}{U}", getColorIdentityString("Brutal Expulsion"));
|
||||
Assert.assertEquals("{B}{G}", getColorIdentityString("Catacomb Sifter"));
|
||||
Assert.assertEquals("{B}{U}", getColorIdentityString("Fathom Feeder"));
|
||||
|
||||
Assert.assertEquals("{R}{W}", getColorIdentityString("Angelic Captain"));
|
||||
Assert.assertEquals("{G}{U}", getColorIdentityString("Bring to Light"));
|
||||
Assert.assertEquals("{B}{W}", getColorIdentityString("Drana's Emissary"));
|
||||
Assert.assertEquals("{G}{R}", getColorIdentityString("Grove Rumbler"));
|
||||
Assert.assertEquals("{U}{W}", getColorIdentityString("Roil Spout"));
|
||||
|
||||
// Cards with colors in the rule text
|
||||
Assert.assertEquals("{B}{R}", getColorIdentityString("Fires of Undeath"));
|
||||
|
||||
// Cards without casting costs
|
||||
Assert.assertEquals("{B}", getColorIdentityString("Living End"));
|
||||
Assert.assertEquals("{G}", getColorIdentityString("Hypergenesis"));
|
||||
|
||||
// Phyrexian Mana
|
||||
Assert.assertEquals("{B}", getColorIdentityString("Dismember"));
|
||||
|
||||
// Hybrid mana
|
||||
Assert.assertEquals("{G}{W}", getColorIdentityString("Kitchen Finks"));
|
||||
|
||||
// Lands with colored activation costs
|
||||
Assert.assertEquals("{G}", getColorIdentityString("Treetop Village"));
|
||||
|
||||
// Cards with extort don't use extort to determine color identity
|
||||
Assert.assertEquals("{W}", getColorIdentityString("Knight of Obligation"));
|
||||
|
||||
// Two face cards
|
||||
Assert.assertEquals("{G}{R}", getColorIdentityString("Daybreak Ranger"));
|
||||
Assert.assertEquals("{R}{W}", getColorIdentityString("Archangel Avacyn"));
|
||||
Assert.assertEquals("{R}{U}", getColorIdentityString("Civilized Scholar"));
|
||||
|
||||
}
|
||||
|
||||
private String getColorIdentityString(String cardName) {
|
||||
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
|
||||
if (cardInfo == null) {
|
||||
throw new IllegalArgumentException("Couldn't find the card " + cardName + " in the DB.");
|
||||
}
|
||||
Card card = cardInfo.getCard();
|
||||
FilterMana filterMana = CardUtil.getColorIdentity(card);
|
||||
return filterMana.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -114,4 +114,14 @@ public class FilterMana implements Serializable {
|
|||
public FilterMana copy() {
|
||||
return new FilterMana(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (black ? "{B}" : "")
|
||||
+ (green ? "{G}" : "")
|
||||
+ (red ? "{R}" : "")
|
||||
+ (blue ? "{U}" : "")
|
||||
+ (white ? "{W}" : "");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.util.Set;
|
|||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.ActivatedAbility;
|
||||
import mage.abilities.SpellAbility;
|
||||
|
|
@ -623,22 +624,50 @@ public class CardUtil {
|
|||
|
||||
for (String rule : card.getRules()) {
|
||||
rule = rule.replaceAll("(?i)<i.*?</i>", ""); // Ignoring reminder text in italic
|
||||
if (rule.matches(regexBlack)) {
|
||||
if (!mana.isBlack() && rule.matches(regexBlack)) {
|
||||
mana.setBlack(true);
|
||||
}
|
||||
if (rule.matches(regexBlue)) {
|
||||
if (!mana.isBlue() && rule.matches(regexBlue)) {
|
||||
mana.setBlue(true);
|
||||
}
|
||||
if (rule.matches(regexGreen)) {
|
||||
if (!mana.isGreen() && rule.matches(regexGreen)) {
|
||||
mana.setGreen(true);
|
||||
}
|
||||
if (rule.matches(regexRed)) {
|
||||
if (!mana.isRed() && rule.matches(regexRed)) {
|
||||
mana.setRed(true);
|
||||
}
|
||||
if (rule.matches(regexWhite)) {
|
||||
if (!mana.isWhite() && rule.matches(regexWhite)) {
|
||||
mana.setWhite(true);
|
||||
}
|
||||
}
|
||||
if (card.canTransform()) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue