Added ManaOptions test and some changes in handling.

This commit is contained in:
LevelX2 2015-02-11 01:10:34 +01:00
parent 7961b35cbf
commit 874b170a74
4 changed files with 192 additions and 6 deletions

View file

@ -64,6 +64,7 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.abilities.mana.ManaAbility;
import mage.abilities.mana.ManaOptions;
import mage.cards.Card;
import mage.constants.Zone;
import mage.target.TargetSource;
@ -366,12 +367,19 @@ public class TestPlayer extends ComputerPlayer {
String[] targetList = targetDefinition.split("\\^");
boolean targetFound = false;
for (String targetName: targetList) {
boolean allowCopy = true;
if (targetName.endsWith("[no copy]")) {
allowCopy = false;
targetName = targetName.substring(0, targetName.length()-9);
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents((FilterPermanent)target.getFilter(), game)) {
if (permanent.getName().equals(targetName) || (permanent.getName()+"-"+permanent.getExpansionSetCode()).equals(targetName)) {
if (((TargetPermanent)target).canTarget(source.getControllerId(), permanent.getId(), source, game) && !target.getTargets().contains(permanent.getId())) {
target.add(permanent.getId(), game);
targetFound = true;
break;
if (((TargetPermanent)target).canTarget(source == null ? this.getId(): source.getControllerId(), permanent.getId(), source, game) && !target.getTargets().contains(permanent.getId())) {
if (!permanent.isCopy() || allowCopy) {
target.add(permanent.getId(), game);
targetFound = true;
break;
}
}
}
}
@ -621,5 +629,9 @@ public class TestPlayer extends ComputerPlayer {
}
return result;
}
public ManaOptions getAvailableManaTest(Game game) {
return getManaAvailable(game);
}
}

View file

@ -0,0 +1,137 @@
/*
* 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.utils;
import mage.abilities.mana.ManaOptions;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class ManaOptionsTest extends CardTestPlayerBase {
@Test
public void testSimpleMana() {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
setStopAt(1, PhaseStep. UPKEEP);
execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",1, manaOptions.size());
Assert.assertEquals("{G}{G}{G}", getManaOption(0, manaOptions));
}
// Tinder Farm enters the battlefield tapped.
// {T}: Add {G} to your mana pool.
// {T}, Sacrifice Tinder Farm: Add {R}{W} to your mana pool.
@Test
public void testTinderFarm() {
addCard(Zone.BATTLEFIELD, playerA, "Tinder Farm", 3);
setStopAt(2, PhaseStep. UPKEEP);
execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",4, manaOptions.size());
Assert.assertEquals("{G}{G}{G}", getManaOption(0, manaOptions));
Assert.assertEquals("{R}{G}{G}{W}", getManaOption(1, manaOptions));
Assert.assertEquals("{R}{R}{G}{W}{W}", getManaOption(2, manaOptions));
Assert.assertEquals("{R}{R}{R}{W}{W}{W}", getManaOption(3, manaOptions));
}
// Adarkar Wastes
// {T}: Add {1} to your mana pool.
// {T}: Add {W} or {U} to your mana pool. Adarkar Wastes deals 1 damage to you.
@Test
public void testAdarkarWastes() {
addCard(Zone.BATTLEFIELD, playerA, "Adarkar Wastes", 3);
setStopAt(1, PhaseStep. UPKEEP);
execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",4, manaOptions.size());
Assert.assertEquals("{W}{W}{W}", getManaOption(0, manaOptions));
Assert.assertEquals("{U}{W}{W}", getManaOption(1, manaOptions));
Assert.assertEquals("{U}{U}{W}", getManaOption(2, manaOptions));
Assert.assertEquals("{U}{U}{U}", getManaOption(3, manaOptions));
}
// Chromatic Sphere
// {1}, {T}, Sacrifice Chromatic Sphere: Add one mana of any color to your mana pool. Draw a card.
@Test
public void testChromaticSphere() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
addCard(Zone.BATTLEFIELD, playerA, "Chromatic Sphere", 2);
setStopAt(1, PhaseStep. UPKEEP);
execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",1, manaOptions.size());
Assert.assertEquals("{Any}{Any}", getManaOption(0, manaOptions));
}
// Orochi Leafcaller
// {G}: Add one mana of any color to your mana pool.
@Test
public void testOrochiLeafcaller() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
addCard(Zone.BATTLEFIELD, playerA, "Orochi Leafcaller", 1);
setStopAt(1, PhaseStep. UPKEEP);
execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",1, manaOptions.size());
Assert.assertEquals("{W}{W}{Any}{Any}", getManaOption(0, manaOptions));
}
private String getManaOption(int index, ManaOptions manaOptions) {
if (manaOptions.size() < index + 1) {
return "";
}
return manaOptions.get(index).toString();
}
}