Some fixes/improvements to generation of available mana.

This commit is contained in:
LevelX2 2015-07-12 09:11:13 +02:00
parent 4dc70048d5
commit 0e3d4b335a
14 changed files with 674 additions and 354 deletions

View file

@ -29,7 +29,6 @@ package org.mage.test.AI.basic;
import mage.constants.PhaseStep; import mage.constants.PhaseStep;
import mage.constants.Zone; import mage.constants.Zone;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBaseAI; import org.mage.test.serverside.base.CardTestPlayerBaseAI;
@ -67,7 +66,6 @@ public class CastCreaturesTest extends CardTestPlayerBaseAI {
} }
@Test @Test
@Ignore // AI should cast Myr Enforcer -> Check why it does not
public void testSimpleCast3() { public void testSimpleCast3() {
// Affinity for artifacts (This spell costs less to cast for each artifact you control.) // Affinity for artifacts (This spell costs less to cast for each artifact you control.)
addCard(Zone.HAND, playerA, "Myr Enforcer"); addCard(Zone.HAND, playerA, "Myr Enforcer");
@ -81,4 +79,83 @@ public class CastCreaturesTest extends CardTestPlayerBaseAI {
assertPermanentCount(playerA, "Myr Enforcer", 1); assertPermanentCount(playerA, "Myr Enforcer", 1);
} }
@Test
public void testSimpleCast4() {
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain");
addCard(Zone.HAND, playerA, "Plains");
skipInitShuffling();
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
addCard(Zone.HAND, playerA, "Fireshrieker");
addCard(Zone.HAND, playerA, "Blazing Specter"); // {2}{R}{B}
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Plains", 2);
assertPermanentCount(playerA, "Fireshrieker", 0);
assertPermanentCount(playerA, "Blazing Specter", 1);
}
@Test
public void testCast4Creature() {
addCard(Zone.LIBRARY, playerA, "Swamp", 1);
addCard(Zone.LIBRARY, playerA, "Mountain", 1);
addCard(Zone.LIBRARY, playerA, "Island", 1);
addCard(Zone.HAND, playerA, "Plains");
skipInitShuffling();
addCard(Zone.HAND, playerA, "Loyal Sentry"); // {W} 1/1
addCard(Zone.HAND, playerA, "Silvercoat Lion"); // {1}{W} 2/2
addCard(Zone.HAND, playerA, "Rootwater Commando"); // {2}{U} 2/2
addCard(Zone.HAND, playerA, "Bog Wraith"); // {3}{B} 3/3
setStopAt(7, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Plains", 1);
assertPermanentCount(playerA, "Mountain", 1);
assertPermanentCount(playerA, "Island", 1);
assertPermanentCount(playerA, "Swamp", 1);
// assertLife(playerB, 11); // 1 + 1+2 + 1+2+2 =
assertPermanentCount(playerA, "Loyal Sentry", 1);
assertPermanentCount(playerA, "Silvercoat Lion", 1);
assertPermanentCount(playerA, "Rootwater Commando", 1);
assertPermanentCount(playerA, "Bog Wraith", 1);
}
@Test
public void testCast4Creature2() {
addCard(Zone.LIBRARY, playerA, "Swamp", 1);
addCard(Zone.LIBRARY, playerA, "Swamp", 1);
addCard(Zone.LIBRARY, playerA, "Plains", 1);
addCard(Zone.HAND, playerA, "Island", 1);
addCard(Zone.HAND, playerA, "Plains");
skipInitShuffling();
addCard(Zone.HAND, playerA, "Loyal Sentry"); // {W} 1/1
addCard(Zone.HAND, playerA, "Steadfast Guard"); // {W}{W} 2/2
addCard(Zone.HAND, playerA, "Rootwater Commando"); // {2}{U} 2/2
addCard(Zone.HAND, playerA, "Bog Wraith"); // {3}{B} 3/3
setStopAt(7, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Plains", 2);
assertPermanentCount(playerA, "Island", 1);
assertPermanentCount(playerA, "Swamp", 1);
// assertLife(playerB, 11); // 1 + 1+2 + 1+2+2 =
assertPermanentCount(playerA, "Loyal Sentry", 1);
assertPermanentCount(playerA, "Steadfast Guard", 1);
assertPermanentCount(playerA, "Rootwater Commando", 1);
assertPermanentCount(playerA, "Bog Wraith", 1);
}
} }

View file

@ -0,0 +1,68 @@
/*
* 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.AI.basic;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBaseAI;
/**
*
* @author LevelX2
*/
public class CastDestroySpellsTest extends CardTestPlayerBaseAI {
/**
*
*
*/
@Test
public void testOrzhovCharm() {
// Choose one -
// Return target creature you control and all Auras you control attached to it to their owner's hand;
// or destroy target creature and you lose life equal to its toughness;
// or return target creature card with converted mana cost 1 or less from your graveyard to the battlefield.
addCard(Zone.HAND, playerA, "Orzhov Charm"); // {W}{B}
addCard(Zone.BATTLEFIELD, playerA, "Fetid Heath", 1);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
// Cycling abilities you activate cost you up to {2} less to activate.
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion");
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertLife(playerA, 18);
assertGraveyardCount(playerA, "Orzhov Charm", 1);
assertGraveyardCount(playerB, "Silvercoat Lion", 1);
}
}

View file

@ -35,7 +35,8 @@ import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase; import org.mage.test.serverside.base.CardTestPlayerBase;
/** /**
* This test checks if the calculated possible mana options are correct related to the given mana sources available. * This test checks if the calculated possible mana options are correct related
* to the given mana sources available.
* *
* @author LevelX2 * @author LevelX2
*/ */
@ -45,12 +46,12 @@ public class ManaOptionsTest extends CardTestPlayerBase {
public void testSimpleMana() { public void testSimpleMana() {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
setStopAt(1, PhaseStep. UPKEEP); setStopAt(1, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",1, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
Assert.assertEquals("{G}{G}{G}", getManaOption(0, manaOptions)); Assert.assertEquals("{G}{G}{G}", getManaOption(0, manaOptions));
} }
@ -62,12 +63,12 @@ public class ManaOptionsTest extends CardTestPlayerBase {
public void testTinderFarm() { public void testTinderFarm() {
addCard(Zone.BATTLEFIELD, playerA, "Tinder Farm", 3); addCard(Zone.BATTLEFIELD, playerA, "Tinder Farm", 3);
setStopAt(2, PhaseStep. UPKEEP); setStopAt(2, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",4, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 4, manaOptions.size());
Assert.assertEquals("{G}{G}{G}", getManaOption(0, manaOptions)); Assert.assertEquals("{G}{G}{G}", getManaOption(0, manaOptions));
Assert.assertEquals("{R}{G}{G}{W}", getManaOption(1, manaOptions)); Assert.assertEquals("{R}{G}{G}{W}", getManaOption(1, manaOptions));
Assert.assertEquals("{R}{R}{G}{W}{W}", getManaOption(2, manaOptions)); Assert.assertEquals("{R}{R}{G}{W}{W}", getManaOption(2, manaOptions));
@ -82,12 +83,12 @@ public class ManaOptionsTest extends CardTestPlayerBase {
public void testAdarkarWastes() { public void testAdarkarWastes() {
addCard(Zone.BATTLEFIELD, playerA, "Adarkar Wastes", 3); addCard(Zone.BATTLEFIELD, playerA, "Adarkar Wastes", 3);
setStopAt(1, PhaseStep. UPKEEP); setStopAt(1, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",4, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 4, manaOptions.size());
Assert.assertEquals("{W}{W}{W}", getManaOption(0, manaOptions)); Assert.assertEquals("{W}{W}{W}", getManaOption(0, manaOptions));
Assert.assertEquals("{U}{W}{W}", getManaOption(1, manaOptions)); Assert.assertEquals("{U}{W}{W}", getManaOption(1, manaOptions));
Assert.assertEquals("{U}{U}{W}", getManaOption(2, manaOptions)); Assert.assertEquals("{U}{U}{W}", getManaOption(2, manaOptions));
@ -95,7 +96,6 @@ public class ManaOptionsTest extends CardTestPlayerBase {
} }
// Chromatic Sphere // Chromatic Sphere
// {1}, {T}, Sacrifice Chromatic Sphere: Add one mana of any color to your mana pool. Draw a card. // {1}, {T}, Sacrifice Chromatic Sphere: Add one mana of any color to your mana pool. Draw a card.
@Test @Test
@ -103,12 +103,12 @@ public class ManaOptionsTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); addCard(Zone.BATTLEFIELD, playerA, "Plains", 2);
addCard(Zone.BATTLEFIELD, playerA, "Chromatic Sphere", 2); addCard(Zone.BATTLEFIELD, playerA, "Chromatic Sphere", 2);
setStopAt(1, PhaseStep. UPKEEP); setStopAt(1, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",1, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
Assert.assertEquals("{Any}{Any}", getManaOption(0, manaOptions)); Assert.assertEquals("{Any}{Any}", getManaOption(0, manaOptions));
} }
@ -120,12 +120,12 @@ public class ManaOptionsTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 2); addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
addCard(Zone.BATTLEFIELD, playerA, "Orochi Leafcaller", 1); addCard(Zone.BATTLEFIELD, playerA, "Orochi Leafcaller", 1);
setStopAt(1, PhaseStep. UPKEEP); setStopAt(1, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",1, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
Assert.assertEquals("{W}{W}{Any}{Any}", getManaOption(0, manaOptions)); Assert.assertEquals("{W}{W}{Any}{Any}", getManaOption(0, manaOptions));
} }
@ -138,14 +138,15 @@ public class ManaOptionsTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 2); addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
addCard(Zone.BATTLEFIELD, playerA, "Crystal Quarry", 1); addCard(Zone.BATTLEFIELD, playerA, "Crystal Quarry", 1);
setStopAt(1, PhaseStep. UPKEEP); setStopAt(1, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",1, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
Assert.assertEquals("{1}{G}{G}{W}{W}", getManaOption(0, manaOptions)); Assert.assertEquals("{1}{G}{G}{W}{W}", getManaOption(0, manaOptions));
} }
// Crystal Quarry // Crystal Quarry
// {T}: {1} Add to your mana pool. // {T}: {1} Add to your mana pool.
// {5}, {T}: Add {W}{U}{B}{R}{G} to your mana pool. // {5}, {T}: Add {W}{U}{B}{R}{G} to your mana pool.
@ -155,12 +156,12 @@ public class ManaOptionsTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
addCard(Zone.BATTLEFIELD, playerA, "Crystal Quarry", 1); addCard(Zone.BATTLEFIELD, playerA, "Crystal Quarry", 1);
setStopAt(1, PhaseStep. UPKEEP); setStopAt(1, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",2, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 2, manaOptions.size());
Assert.assertEquals("{1}{G}{G}{G}{W}{W}", getManaOption(0, manaOptions)); Assert.assertEquals("{1}{G}{G}{G}{W}{W}", getManaOption(0, manaOptions));
Assert.assertEquals("{R}{G}{U}{W}{B}", getManaOption(1, manaOptions)); Assert.assertEquals("{R}{G}{U}{W}{B}", getManaOption(1, manaOptions));
} }
@ -174,12 +175,12 @@ public class ManaOptionsTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
addCard(Zone.BATTLEFIELD, playerA, "Nykthos, Shrine to Nyx", 1); addCard(Zone.BATTLEFIELD, playerA, "Nykthos, Shrine to Nyx", 1);
setStopAt(1, PhaseStep. UPKEEP); setStopAt(1, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",1, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
Assert.assertEquals("{G}{G}{G}{G}{G}", getManaOption(0, manaOptions)); Assert.assertEquals("{G}{G}{G}{G}{G}", getManaOption(0, manaOptions));
} }
@ -190,12 +191,12 @@ public class ManaOptionsTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 3); addCard(Zone.BATTLEFIELD, playerA, "Forest", 3);
addCard(Zone.BATTLEFIELD, playerA, "Nykthos, Shrine to Nyx", 1); addCard(Zone.BATTLEFIELD, playerA, "Nykthos, Shrine to Nyx", 1);
setStopAt(1, PhaseStep. UPKEEP); setStopAt(1, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",2, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 2, manaOptions.size());
Assert.assertEquals("{G}{G}{G}{G}{G}", getManaOption(0, manaOptions)); Assert.assertEquals("{G}{G}{G}{G}{G}", getManaOption(0, manaOptions));
Assert.assertEquals("{R}{R}{R}{G}", getManaOption(1, manaOptions)); Assert.assertEquals("{R}{R}{R}{G}", getManaOption(1, manaOptions));
} }
@ -206,32 +207,88 @@ public class ManaOptionsTest extends CardTestPlayerBase {
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1); addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
addCard(Zone.BATTLEFIELD, playerA, "Nykthos, Shrine to Nyx", 1); addCard(Zone.BATTLEFIELD, playerA, "Nykthos, Shrine to Nyx", 1);
setStopAt(1, PhaseStep. UPKEEP); setStopAt(1, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",1, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
Assert.assertEquals("{1}{G}{Any}", getManaOption(0, manaOptions)); Assert.assertEquals("{1}{G}{Any}", getManaOption(0, manaOptions));
} }
@Test @Test
public void testMix1() { public void testMix1() {
// {1}, {T}, Sacrifice Chromatic Star: Add one mana of any color to your mana pool.
// When Chromatic Star is put into a graveyard from the battlefield, draw a card.
addCard(Zone.BATTLEFIELD, playerA, "Chromatic Star", 1); addCard(Zone.BATTLEFIELD, playerA, "Chromatic Star", 1);
// {1}, {T}, Sacrifice Chromatic Sphere: Add one mana of any color to your mana pool. Draw a card.
addCard(Zone.BATTLEFIELD, playerA, "Chromatic Sphere", 1); addCard(Zone.BATTLEFIELD, playerA, "Chromatic Sphere", 1);
// {T}: Add {1} to your mana pool. If you control an Urza's Mine and an Urza's Power-Plant, add {3} to your mana pool instead.
addCard(Zone.BATTLEFIELD, playerA, "Urza's Tower", 1); addCard(Zone.BATTLEFIELD, playerA, "Urza's Tower", 1);
// {T}: Add {1} to your mana pool.
// {T}: Add {R} or {G} to your mana pool. Each opponent gains 1 life.
addCard(Zone.BATTLEFIELD, playerA, "Grove of the Burnwillows", 1); addCard(Zone.BATTLEFIELD, playerA, "Grove of the Burnwillows", 1);
setStopAt(1, PhaseStep. UPKEEP); setStopAt(1, PhaseStep.UPKEEP);
execute(); execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit",2, manaOptions.size()); Assert.assertEquals("mana variations don't fit", 2, manaOptions.size());
Assert.assertEquals("{Any}{Any}", getManaOption(0, manaOptions)); Assert.assertEquals("{Any}{Any}", getManaOption(0, manaOptions));
Assert.assertEquals("{Any}{Any}", getManaOption(1, manaOptions)); Assert.assertEquals("{Any}{Any}", getManaOption(1, manaOptions));
} }
@Test
public void testFetidHeath() {
addCard(Zone.BATTLEFIELD, playerA, "Fetid Heath", 1);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
setStopAt(1, PhaseStep.UPKEEP);
execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit", 3, manaOptions.size());
Assert.assertEquals("{W}{W}", getManaOption(0, manaOptions));
Assert.assertEquals("{W}{B}", getManaOption(1, manaOptions));
Assert.assertEquals("{B}{B}", getManaOption(2, manaOptions));
}
/**
* Don't use mana sources that only reduce available mana
*/
@Test
public void testCabalCoffers1() {
addCard(Zone.BATTLEFIELD, playerA, "Cabal Coffers", 1);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1);
setStopAt(1, PhaseStep.UPKEEP);
execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
Assert.assertEquals("{W}{B}", getManaOption(0, manaOptions));
}
@Test
public void testCabalCoffers2() {
addCard(Zone.BATTLEFIELD, playerA, "Cabal Coffers", 1);
addCard(Zone.BATTLEFIELD, playerA, "Plains", 1);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
setStopAt(1, PhaseStep.UPKEEP);
execute();
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
Assert.assertEquals("mana variations don't fit", 2, manaOptions.size());
Assert.assertEquals("{W}{B}{B}", getManaOption(0, manaOptions));
Assert.assertEquals("{B}{B}{B}", getManaOption(1, manaOptions));
}
private String getManaOption(int index, ManaOptions manaOptions) { private String getManaOption(int index, ManaOptions manaOptions) {
if (manaOptions.size() < index + 1) { if (manaOptions.size() < index + 1) {
return ""; return "";

View file

@ -1,36 +1,36 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 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 * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * 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 * 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 * 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 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 * 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 * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * 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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage; package mage;
import java.io.Serializable; import java.io.Serializable;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
import mage.constants.ManaType; import mage.constants.ManaType;
import static mage.constants.ManaType.COLORLESS;
import mage.filter.FilterMana; import mage.filter.FilterMana;
import mage.util.Copyable; import mage.util.Copyable;
import mage.util.ThreadLocalStringBuilder; import mage.util.ThreadLocalStringBuilder;
@ -57,7 +57,8 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
public static final Mana BlackMana = BlackMana(1); public static final Mana BlackMana = BlackMana(1);
public static final Mana ColorlessMana = ColorlessMana(1); public static final Mana ColorlessMana = ColorlessMana(1);
public Mana() {} public Mana() {
}
public Mana(final Mana mana) { public Mana(final Mana mana) {
this.red = mana.red; this.red = mana.red;
@ -212,7 +213,6 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
} }
} }
public int count() { public int count() {
return red + green + blue + white + black + colorless + any; return red + green + blue + white + black + colorless + any;
} }
@ -342,38 +342,38 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
Mana compare = avail.copy(); Mana compare = avail.copy();
compare.subtract(this); compare.subtract(this);
if (compare.getRed() < 0 && compare.getAny() > 0) { if (compare.getRed() < 0 && compare.getAny() > 0) {
int diff = Math.min( compare.getAny(), Math.abs(compare.getRed())); int diff = Math.min(compare.getAny(), Math.abs(compare.getRed()));
compare.setAny(compare.getAny() - diff); compare.setAny(compare.getAny() - diff);
compare.setRed(compare.getRed() + diff); compare.setRed(compare.getRed() + diff);
} }
if (compare.getGreen() < 0 && compare.getAny() > 0) { if (compare.getGreen() < 0 && compare.getAny() > 0) {
int diff = Math.min( compare.getAny(), Math.abs(compare.getGreen())); int diff = Math.min(compare.getAny(), Math.abs(compare.getGreen()));
compare.setAny(compare.getAny() - diff); compare.setAny(compare.getAny() - diff);
compare.setGreen(compare.getGreen() + diff); compare.setGreen(compare.getGreen() + diff);
} }
if (compare.getBlue() < 0 && compare.getAny() > 0) { if (compare.getBlue() < 0 && compare.getAny() > 0) {
int diff = Math.min( compare.getAny(), Math.abs(compare.getBlue())); int diff = Math.min(compare.getAny(), Math.abs(compare.getBlue()));
compare.setAny(compare.getAny() - diff); compare.setAny(compare.getAny() - diff);
compare.setBlue(compare.getBlue() + diff); compare.setBlue(compare.getBlue() + diff);
} }
if (compare.getBlack() < 0 && compare.getAny() > 0) { if (compare.getBlack() < 0 && compare.getAny() > 0) {
int diff = Math.min( compare.getAny(), Math.abs(compare.getBlack())); int diff = Math.min(compare.getAny(), Math.abs(compare.getBlack()));
compare.setAny(compare.getAny() - diff); compare.setAny(compare.getAny() - diff);
compare.setBlack(compare.getBlack() + diff); compare.setBlack(compare.getBlack() + diff);
} }
if (compare.getWhite() < 0 && compare.getAny() > 0) { if (compare.getWhite() < 0 && compare.getAny() > 0) {
int diff = Math.min( compare.getAny(), Math.abs(compare.getWhite())); int diff = Math.min(compare.getAny(), Math.abs(compare.getWhite()));
compare.setAny(compare.getAny() - diff); compare.setAny(compare.getAny() - diff);
compare.setWhite(compare.getWhite() + diff); compare.setWhite(compare.getWhite() + diff);
} }
if (compare.getColorless() < 0) { if (compare.getColorless() < 0) {
int remaining = 0; int remaining = 0;
remaining += Math.min(0,compare.getRed()); remaining += Math.min(0, compare.getRed());
remaining += Math.min(0,compare.getWhite()); remaining += Math.min(0, compare.getWhite());
remaining += Math.min(0,compare.getGreen()); remaining += Math.min(0, compare.getGreen());
remaining += Math.min(0,compare.getBlack()); remaining += Math.min(0, compare.getBlack());
remaining += Math.min(0,compare.getBlue()); remaining += Math.min(0, compare.getBlue());
remaining += Math.min(0,compare.getAny()); remaining += Math.min(0, compare.getAny());
if (remaining > 0) { if (remaining > 0) {
int diff = Math.min(remaining, Math.abs(compare.getColorless())); int diff = Math.min(remaining, Math.abs(compare.getColorless()));
compare.setColorless(compare.getColorless() + diff); compare.setColorless(compare.getColorless() + diff);
@ -510,7 +510,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
} }
public int get(ManaType manaType) { public int get(ManaType manaType) {
switch(manaType) { switch (manaType) {
case BLACK: case BLACK:
return black; return black;
case BLUE: case BLUE:
@ -528,7 +528,7 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
} }
public void set(ManaType manaType, int amount) { public void set(ManaType manaType, int amount) {
switch(manaType) { switch (manaType) {
case BLACK: case BLACK:
black = amount; black = amount;
break; break;
@ -569,39 +569,38 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
} }
public boolean equalManaValue(Mana mana) { public boolean equalManaValue(Mana mana) {
return this.any == mana.any && return this.any == mana.any
this.red == mana.red && && this.red == mana.red
this.green == mana.green && && this.green == mana.green
this.white == mana.white && && this.white == mana.white
this.blue == mana.blue && && this.blue == mana.blue
this.black == mana.black && && this.black == mana.black
this.colorless == mana.colorless; && this.colorless == mana.colorless;
} }
/** /**
* Don't takes any mana into account to be usable in calculating available mana * Don't takes any mana into account to be usable in calculating available
* mana
*
* @param mana * @param mana
* @return * @return
*/ */
public boolean includesMana(Mana mana) { public boolean includesMana(Mana mana) {
return this.green >= mana.green && return this.green >= mana.green
this.blue >= mana.blue && && this.blue >= mana.blue
this.white >= mana.white && && this.white >= mana.white
this.black >= mana.black && && this.black >= mana.black
this.red >= mana.red && && this.red >= mana.red
( && (this.colorless >= mana.colorless
this.colorless >= mana.colorless || || this.countColored() >= mana.countColored() + mana.colorless);
this.countColored() >= mana.countColored() + mana.colorless
);
} }
/** /**
* Returns the mana that is more colored but does not contain * Returns the mana that is more colored but does not contain one less mana
* one less mana in any color but colorless * in any color but colorless if you call with {1}{W}{R} and {G}{W}{R} you
* if you call with {1}{W}{R} and {G}{W}{R} you get back {G}{W}{R} * get back {G}{W}{R} if you call with {G}{W}{R} and {G}{W}{R} you get back
* if you call with {G}{W}{R} and {G}{W}{R} you get back {G}{W}{R} * {G}{W}{R} if you call with {G}{W}{B} and {G}{W}{R} you get back null
* if you call with {G}{W}{B} and {G}{W}{R} you get back null
* *
* @param mana1 * @param mana1
* @param mana2 * @param mana2
@ -617,13 +616,12 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
moreMana = mana1; moreMana = mana1;
lessMana = mana2; lessMana = mana2;
} }
if (lessMana.getWhite() > moreMana.getWhite() || if (lessMana.getWhite() > moreMana.getWhite()
lessMana.getRed() > moreMana.getRed() || || lessMana.getRed() > moreMana.getRed()
lessMana.getGreen() > moreMana.getGreen() || || lessMana.getGreen() > moreMana.getGreen()
lessMana.getBlue() > moreMana.getBlue() || || lessMana.getBlue() > moreMana.getBlue()
lessMana.getBlack() > moreMana.getBlack() || || lessMana.getBlack() > moreMana.getBlack()
lessMana.getAny() > moreMana.getAny() || lessMana.getAny() > moreMana.getAny()) {
) {
return null; return null;
} }
return moreMana; return moreMana;

View file

@ -1,38 +1,33 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 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 * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * 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 * 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 * 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 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 * 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 * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * 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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities; package mage.abilities;
import java.util.UUID; import java.util.UUID;
import mage.constants.AbilityType;
import mage.constants.TimingRule;
import mage.constants.Zone;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
import mage.abilities.costs.Costs; import mage.abilities.costs.Costs;
import mage.abilities.costs.mana.ManaCosts; import mage.abilities.costs.mana.ManaCosts;
@ -40,12 +35,14 @@ import mage.abilities.costs.mana.PhyrexianManaCost;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.abilities.effects.Effects; import mage.abilities.effects.Effects;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.AbilityType;
import mage.constants.AsThoughEffectType; import mage.constants.AsThoughEffectType;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.constants.TimingRule;
import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -62,7 +59,7 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
this.checkPlayableMode = false; this.checkPlayableMode = false;
} }
public ActivatedAbilityImpl(ActivatedAbilityImpl ability) { public ActivatedAbilityImpl(final ActivatedAbilityImpl ability) {
super(ability); super(ability);
timing = ability.timing; timing = ability.timing;
mayActivate = ability.mayActivate; mayActivate = ability.mayActivate;
@ -94,7 +91,7 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
public ActivatedAbilityImpl(Zone zone, Effects effects, ManaCosts cost) { public ActivatedAbilityImpl(Zone zone, Effects effects, ManaCosts cost) {
super(AbilityType.ACTIVATED, zone); super(AbilityType.ACTIVATED, zone);
if (effects != null) { if (effects != null) {
for (Effect effect: effects) { for (Effect effect : effects) {
this.addEffect(effect); this.addEffect(effect);
} }
} }
@ -110,7 +107,7 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
} }
if (cost != null) { if (cost != null) {
if (cost instanceof PhyrexianManaCost) { if (cost instanceof PhyrexianManaCost) {
this.addManaCost((PhyrexianManaCost)cost); this.addManaCost((PhyrexianManaCost) cost);
} else { } else {
this.addCost(cost); this.addCost(cost);
} }
@ -123,7 +120,7 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
this.addEffect(effect); this.addEffect(effect);
} }
if (costs != null) { if (costs != null) {
for (Cost cost: costs) { for (Cost cost : costs) {
this.addCost(cost); this.addCost(cost);
} }
} }
@ -132,7 +129,7 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
public ActivatedAbilityImpl(Zone zone, Effects effects, Cost cost) { public ActivatedAbilityImpl(Zone zone, Effects effects, Cost cost) {
super(AbilityType.ACTIVATED, zone); super(AbilityType.ACTIVATED, zone);
if (effects != null) { if (effects != null) {
for (Effect effect: effects) { for (Effect effect : effects) {
this.addEffect(effect); this.addEffect(effect);
} }
} }
@ -143,13 +140,13 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
public ActivatedAbilityImpl(Zone zone, Effects effects, Costs<Cost> costs) { public ActivatedAbilityImpl(Zone zone, Effects effects, Costs<Cost> costs) {
super(AbilityType.ACTIVATED, zone); super(AbilityType.ACTIVATED, zone);
for (Effect effect: effects) { for (Effect effect : effects) {
if (effect != null) { if (effect != null) {
this.addEffect(effect); this.addEffect(effect);
} }
} }
if (costs != null) { if (costs != null) {
for (Cost cost: costs) { for (Cost cost : costs) {
this.addCost(cost); this.addCost(cost);
} }
} }
@ -161,23 +158,23 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
@Override @Override
public boolean canActivate(UUID playerId, Game game) { public boolean canActivate(UUID playerId, Game game) {
//20091005 - 602.2 //20091005 - 602.2
switch(mayActivate){ switch (mayActivate) {
case ANY: case ANY:
break; break;
case NOT_YOU: case NOT_YOU:
if(controlsAbility(playerId, game)){ if (controlsAbility(playerId, game)) {
return false; return false;
} }
break; break;
case OPPONENT: case OPPONENT:
if (! game.getPlayer(controllerId).hasOpponent(playerId, game)){ if (!game.getPlayer(controllerId).hasOpponent(playerId, game)) {
return false; return false;
} }
break; break;
case YOU: case YOU:
if(!controlsAbility(playerId, game)){ if (!controlsAbility(playerId, game)) {
return false; return false;
} }
break; break;
@ -192,8 +189,8 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
return false; return false;
} }
//20091005 - 602.5d/602.5e //20091005 - 602.5d/602.5e
if (timing == TimingRule.INSTANT || game.canPlaySorcery(playerId) || if (timing == TimingRule.INSTANT || game.canPlaySorcery(playerId)
game.getContinuousEffects().asThough(sourceId, AsThoughEffectType.ACTIVATE_AS_INSTANT, this, controllerId, game)) { || game.getContinuousEffects().asThough(sourceId, AsThoughEffectType.ACTIVATE_AS_INSTANT, this, controllerId, game)) {
if (costs.canPay(this, sourceId, controllerId, game) && canChooseTarget(game)) { if (costs.canPay(this, sourceId, controllerId, game) && canChooseTarget(game)) {
this.activatorId = playerId; this.activatorId = playerId;
return true; return true;
@ -205,9 +202,8 @@ public abstract class ActivatedAbilityImpl extends AbilityImpl implements Activa
protected boolean controlsAbility(UUID playerId, Game game) { protected boolean controlsAbility(UUID playerId, Game game) {
if (this.controllerId != null && this.controllerId.equals(playerId)) { if (this.controllerId != null && this.controllerId.equals(playerId)) {
return true; return true;
} } else {
else { Card card = (Card) game.getObject(this.sourceId);
Card card = (Card)game.getObject(this.sourceId);
if (card != null && game.getState().getZone(this.sourceId) != Zone.BATTLEFIELD) { if (card != null && game.getState().getZone(this.sourceId) != Zone.BATTLEFIELD) {
return card.getOwnerId().equals(playerId); return card.getOwnerId().equals(playerId);
} }

View file

@ -1,31 +1,30 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 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 * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * 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 * 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 * 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 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 * 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 * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * 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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities; package mage.abilities;
import java.util.UUID; import java.util.UUID;
@ -65,7 +64,7 @@ public class SpellAbility extends ActivatedAbilityImpl {
this.cardName = cardName; this.cardName = cardName;
this.spellAbilityType = spellAbilityType; this.spellAbilityType = spellAbilityType;
this.addManaCost(cost); this.addManaCost(cost);
switch(spellAbilityType) { switch (spellAbilityType) {
case SPLIT_FUSED: case SPLIT_FUSED:
this.name = "Cast fused " + cardName; this.name = "Cast fused " + cardName;
break; break;
@ -75,7 +74,7 @@ public class SpellAbility extends ActivatedAbilityImpl {
} }
public SpellAbility(SpellAbility ability) { public SpellAbility(final SpellAbility ability) {
super(ability); super(ability);
this.spellAbilityType = ability.spellAbilityType; this.spellAbilityType = ability.spellAbilityType;
this.cardName = ability.cardName; this.cardName = ability.cardName;
@ -83,9 +82,9 @@ public class SpellAbility extends ActivatedAbilityImpl {
public boolean spellCanBeActivatedRegularlyNow(UUID playerId, Game game) { public boolean spellCanBeActivatedRegularlyNow(UUID playerId, Game game) {
MageObject object = game.getObject(sourceId); MageObject object = game.getObject(sourceId);
return timing == TimingRule.INSTANT || return timing == TimingRule.INSTANT
object.hasAbility(FlashAbility.getInstance().getId(), game) || || object.hasAbility(FlashAbility.getInstance().getId(), game)
game.canPlaySorcery(playerId); || game.canPlaySorcery(playerId);
} }
@Override @Override

View file

@ -27,6 +27,8 @@
*/ */
package mage.abilities.costs.mana; package mage.abilities.costs.mana;
import java.util.ArrayList;
import java.util.List;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
@ -130,6 +132,14 @@ public class HybridManaCost extends ManaCostImpl {
return mana1.equals(coloredManaSymbol) || mana2.equals(coloredManaSymbol); return mana1.equals(coloredManaSymbol) || mana2.equals(coloredManaSymbol);
} }
@Override
public List<Mana> getManaOptions() {
List<Mana> manaList = new ArrayList<>();
manaList.add(new Mana(mana1));
manaList.add(new Mana(mana2));
return manaList;
}
public ColoredManaSymbol getMana1() { public ColoredManaSymbol getMana1() {
return mana1; return mana1;
} }

View file

@ -1,33 +1,33 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 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 * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * 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 * 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 * 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 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 * 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 * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * 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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.costs.mana; package mage.abilities.costs.mana;
import java.util.List;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
@ -40,15 +40,27 @@ import mage.players.ManaPool;
public interface ManaCost extends Cost { public interface ManaCost extends Cost {
int convertedManaCost(); int convertedManaCost();
Mana getMana(); Mana getMana();
List<Mana> getManaOptions();
Mana getPayment(); Mana getPayment();
void assignPayment(Game game, Ability ability, ManaPool pool); void assignPayment(Game game, Ability ability, ManaPool pool);
void setPayment(Mana mana); void setPayment(Mana mana);
ManaCost getUnpaid(); ManaCost getUnpaid();
ManaOptions getOptions(); ManaOptions getOptions();
boolean testPay(Mana testMana); boolean testPay(Mana testMana);
Filter getSourceFilter(); Filter getSourceFilter();
void setSourceFilter(Filter filter); void setSourceFilter(Filter filter);
boolean containsColor(ColoredManaSymbol coloredManaSymbol); boolean containsColor(ColoredManaSymbol coloredManaSymbol);
@Override @Override

View file

@ -1,47 +1,47 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 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 * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * 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 * 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 * 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 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 * 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 * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * 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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.costs.mana; package mage.abilities.costs.mana;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.constants.ColoredManaSymbol;
import mage.constants.ManaType;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.CostImpl; import mage.abilities.costs.CostImpl;
import mage.abilities.mana.ManaOptions; import mage.abilities.mana.ManaOptions;
import mage.constants.ColoredManaSymbol;
import mage.constants.ManaType;
import mage.filter.Filter; import mage.filter.Filter;
import mage.game.Game; import mage.game.Game;
import mage.players.ManaPool; import mage.players.ManaPool;
import mage.players.Player; import mage.players.Player;
import mage.util.ManaUtil; import mage.util.ManaUtil;
public abstract class ManaCostImpl extends CostImpl implements ManaCost { public abstract class ManaCostImpl extends CostImpl implements ManaCost {
protected Mana payment; protected Mana payment;
@ -74,6 +74,13 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
return cost; return cost;
} }
@Override
public List<Mana> getManaOptions() {
List<Mana> manaList = new ArrayList<>();
manaList.add(cost);
return manaList;
}
@Override @Override
public ManaOptions getOptions() { public ManaOptions getOptions() {
return options; return options;
@ -214,8 +221,7 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
String promptText = ManaUtil.addSpecialManaPayAbilities(ability, game, unpaid); String promptText = ManaUtil.addSpecialManaPayAbilities(ability, game, unpaid);
if (player.playMana(unpaid, promptText, game)) { if (player.playMana(unpaid, promptText, game)) {
assignPayment(game, ability, player.getManaPool()); assignPayment(game, ability, player.getManaPool());
} } else {
else {
return false; return false;
} }
game.getState().getSpecialActions().removeManaActions(); game.getState().getSpecialActions().removeManaActions();

View file

@ -60,4 +60,5 @@ public interface ManaCosts<T extends ManaCost> extends List<T>, ManaCost {
@Override @Override
ManaCosts<T> copy(); ManaCosts<T> copy();
} }

View file

@ -100,6 +100,15 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
return mana; return mana;
} }
@Override
public List<Mana> getManaOptions() {
List<Mana> manaVariants = new ArrayList<>();
for (ManaCost cost : this) {
manaVariants.addAll(cost.getManaOptions());
}
return manaVariants;
}
@Override @Override
public Mana getPayment() { public Mana getPayment() {
Mana manaTotal = new Mana(); Mana manaTotal = new Mana();

View file

@ -27,6 +27,8 @@
*/ */
package mage.abilities.costs.mana; package mage.abilities.costs.mana;
import java.util.ArrayList;
import java.util.List;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.constants.ColoredManaSymbol; import mage.constants.ColoredManaSymbol;
@ -118,4 +120,12 @@ public class MonoHybridManaCost extends ManaCostImpl {
public boolean containsColor(ColoredManaSymbol coloredManaSymbol) { public boolean containsColor(ColoredManaSymbol coloredManaSymbol) {
return mana.equals(coloredManaSymbol); return mana.equals(coloredManaSymbol);
} }
@Override
public List<Mana> getManaOptions() {
List<Mana> manaList = new ArrayList<>();
manaList.add(new Mana(mana));
manaList.add(Mana.ColorlessMana(2));
return manaList;
}
} }

View file

@ -47,13 +47,12 @@ import mage.util.CardUtil;
* *
* @author LevelX2 * @author LevelX2
*/ */
public class CommanderColorIdentityManaAbility extends ManaAbility { public class CommanderColorIdentityManaAbility extends ManaAbility {
private FilterMana commanderMana; private FilterMana commanderMana;
public CommanderColorIdentityManaAbility() { public CommanderColorIdentityManaAbility() {
super(Zone.BATTLEFIELD, new CommanderIdentityManaEffect(),new TapSourceCost()); super(Zone.BATTLEFIELD, new CommanderIdentityManaEffect(), new TapSourceCost());
} }
public CommanderColorIdentityManaAbility(Cost cost) { public CommanderColorIdentityManaAbility(Cost cost) {
@ -73,7 +72,7 @@ public class CommanderColorIdentityManaAbility extends ManaAbility {
@Override @Override
public List<Mana> getNetMana(Game game) { public List<Mana> getNetMana(Game game) {
if (netMana.isEmpty()) { if (netMana.isEmpty() && game != null) {
Player controller = game.getPlayer(getControllerId()); Player controller = game.getPlayer(getControllerId());
if (controller != null) { if (controller != null) {
if (commanderMana == null) { if (commanderMana == null) {
@ -110,7 +109,6 @@ public class CommanderColorIdentityManaAbility extends ManaAbility {
return true; return true;
} }
} }
class CommanderIdentityManaEffect extends ManaEffect { class CommanderIdentityManaEffect extends ManaEffect {

View file

@ -1,31 +1,30 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 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 * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * 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 * 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 * 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 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 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 * 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 * 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 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * 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 * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.mana; package mage.abilities.mana;
import java.util.ArrayList; import java.util.ArrayList;
@ -37,17 +36,20 @@ import mage.game.Game;
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
* *
* this class is used to build a list of all possible mana combinations * this class is used to build a list of all possible mana combinations it can
* it can be used to find all the ways to pay a mana cost * be used to find all the ways to pay a mana cost or all the different mana
* or all the different mana combinations available to a player * combinations available to a player
* *
*/ */
public class ManaOptions extends ArrayList<Mana> { public class ManaOptions extends ArrayList<Mana> {
public ManaOptions () {}; public ManaOptions() {
}
;
public ManaOptions(final ManaOptions options) { public ManaOptions(final ManaOptions options) {
for (Mana mana: options) { for (Mana mana : options) {
this.add(mana.copy()); this.add(mana.copy());
} }
} }
@ -65,8 +67,8 @@ public class ManaOptions extends ArrayList<Mana> {
} else { } else {
List<Mana> copy = copy(); List<Mana> copy = copy();
this.clear(); this.clear();
for (Mana netMana: netManas) { for (Mana netMana : netManas) {
for (Mana mana: copy) { for (Mana mana : copy) {
Mana newMana = new Mana(); Mana newMana = new Mana();
newMana.add(mana); newMana.add(mana);
newMana.add(netMana); newMana.add(netMana);
@ -75,19 +77,18 @@ public class ManaOptions extends ArrayList<Mana> {
} }
} }
} } else if (abilities.size() > 1) {
else if (abilities.size() > 1) {
//perform a union of all existing options and the new options //perform a union of all existing options and the new options
List<Mana> copy = copy(); List<Mana> copy = copy();
this.clear(); this.clear();
for (ManaAbility ability: abilities) { for (ManaAbility ability : abilities) {
for (Mana netMana: ability.getNetMana(game)) { for (Mana netMana : ability.getNetMana(game)) {
SkipAddMana: SkipAddMana:
for (Mana mana: copy) { for (Mana mana : copy) {
Mana newMana = new Mana(); Mana newMana = new Mana();
newMana.add(mana); newMana.add(mana);
newMana.add(netMana); newMana.add(netMana);
for(Mana existingMana: this) { for (Mana existingMana : this) {
if (existingMana.equalManaValue(newMana)) { if (existingMana.equalManaValue(newMana)) {
continue SkipAddMana; continue SkipAddMana;
} }
@ -122,8 +123,8 @@ public class ManaOptions extends ArrayList<Mana> {
} else { } else {
List<Mana> copy = copy(); List<Mana> copy = copy();
this.clear(); this.clear();
for (Mana netMana: netManas) { for (Mana netMana : netManas) {
for (Mana mana: copy) { for (Mana mana : copy) {
Mana newMana = new Mana(); Mana newMana = new Mana();
newMana.add(mana); newMana.add(mana);
newMana.add(netMana); newMana.add(netMana);
@ -138,8 +139,8 @@ public class ManaOptions extends ArrayList<Mana> {
} else { } else {
List<Mana> copy = copy(); List<Mana> copy = copy();
this.clear(); this.clear();
for (Mana netMana: netManas) { for (Mana netMana : netManas) {
for (Mana mana: copy) { for (Mana mana : copy) {
Mana newMana = new Mana(); Mana newMana = new Mana();
newMana.add(mana); newMana.add(mana);
newMana.add(netMana); newMana.add(netMana);
@ -152,13 +153,13 @@ public class ManaOptions extends ArrayList<Mana> {
//perform a union of all existing options and the new options //perform a union of all existing options and the new options
List<Mana> copy = copy(); List<Mana> copy = copy();
this.clear(); this.clear();
for (ManaAbility ability: abilities) { for (ManaAbility ability : abilities) {
List<Mana> netManas = ability.getNetMana(game); List<Mana> netManas = ability.getNetMana(game);
if (ability.getManaCosts().isEmpty()) { if (ability.getManaCosts().isEmpty()) {
for (Mana netMana: netManas) { for (Mana netMana : netManas) {
for (Mana mana: copy) { for (Mana mana : copy) {
Mana newMana = new Mana(); Mana newMana = new Mana();
newMana.add(mana); newMana.add(mana);
newMana.add(netMana); newMana.add(netMana);
@ -166,15 +167,16 @@ public class ManaOptions extends ArrayList<Mana> {
} }
} }
} else { } else {
for (Mana netMana: netManas) { for (Mana netMana : netManas) {
for (Mana previousMana : copy) {
CombineWithExisting: CombineWithExisting:
for (Mana previousMana: copy) { for (Mana manaOption : ability.getManaCosts().getManaOptions()) {
Mana newMana = new Mana(previousMana); Mana newMana = new Mana(previousMana);
if (previousMana.includesMana(ability.getManaCosts().getMana())) { // costs can be paid if (previousMana.includesMana(manaOption)) { // costs can be paid
newMana.subtractCost(ability.getManaCosts().getMana()); newMana.subtractCost(manaOption);
newMana.add(netMana); newMana.add(netMana);
// if the new mana is in all colors more than another already existing than replace // if the new mana is in all colors more than another already existing than replace
for (Mana existingMana: this) { for (Mana existingMana : this) {
Mana moreValuable = Mana.getMoreValuableMana(newMana, existingMana); Mana moreValuable = Mana.getMoreValuableMana(newMana, existingMana);
if (moreValuable != null) { if (moreValuable != null) {
existingMana.setToMana(moreValuable); existingMana.setToMana(moreValuable);
@ -187,6 +189,7 @@ public class ManaOptions extends ArrayList<Mana> {
} }
} }
} }
}
} }
} }
@ -197,7 +200,7 @@ public class ManaOptions extends ArrayList<Mana> {
if (isEmpty()) { if (isEmpty()) {
this.add(new Mana()); this.add(new Mana());
} }
for (Mana mana: this) { for (Mana mana : this) {
mana.add(addMana); mana.add(addMana);
} }
} }
@ -210,13 +213,12 @@ public class ManaOptions extends ArrayList<Mana> {
if (options.size() == 1) { if (options.size() == 1) {
//if there is only one mana option available add it to all the existing options //if there is only one mana option available add it to all the existing options
addMana(options.get(0)); addMana(options.get(0));
} } else if (options.size() > 1) {
else if (options.size() > 1) {
//perform a union of all existing options and the new options //perform a union of all existing options and the new options
List<Mana> copy = copy(); List<Mana> copy = copy();
this.clear(); this.clear();
for (Mana addMana: options) { for (Mana addMana : options) {
for (Mana mana: copy) { for (Mana mana : copy) {
Mana newMana = new Mana(); Mana newMana = new Mana();
newMana.add(mana); newMana.add(mana);
newMana.add(addMana); newMana.add(addMana);
@ -240,7 +242,26 @@ public class ManaOptions extends ArrayList<Mana> {
// deactivated because it does cause loops TODO: Find reason // deactivated because it does cause loops TODO: Find reason
repeatable = true; // only replace to any with mana costs only will be repeated if able repeatable = true; // only replace to any with mana costs only will be repeated if able
} }
for (Mana mana: this) { List<Mana> copy = copy();
this.clear();
for (Mana mana : copy) {
Mana oldMan = mana.copy();
if (mana.includesMana(cost)) {
// colorless costs can be paid with different colored mana, can lead to different color combinations
if (cost.getColorless() > 0 && cost.getColorless() > mana.getColorless()) {
Mana coloredCost = cost.copy();
coloredCost.setColorless(0);
mana.subtract(coloredCost);
for (Mana payCombination : getPossiblePayCombinations(cost.getColorless(), mana)) {
Mana newMana = mana.copy();
newMana.subtract(payCombination);
newMana.add(addMana);
if (oldMan.contains(newMana) && oldMan.count() > newMana.count()) {
newMana.setToMana(oldMan);
}
this.add(newMana);
}
} else {
while (mana.includesMana(cost)) { while (mana.includesMana(cost)) {
mana.subtractCost(cost); mana.subtractCost(cost);
mana.add(addMana); mana.add(addMana);
@ -248,7 +269,65 @@ public class ManaOptions extends ArrayList<Mana> {
break; break;
} }
} }
// Don't use mana that only reduce the available mana
if (oldMan.contains(mana) && oldMan.count() > mana.count()) {
mana.setToMana(oldMan);
}
this.add(mana);
}
}
} }
} }
private List<Mana> getPossiblePayCombinations(int number, Mana manaAvailable) {
List<Mana> payCombinations = new ArrayList<>();
List<String> payCombinationsStrings = new ArrayList<>();
if (manaAvailable.countColored() > 0) {
for (int i = 0; i < number; i++) {
List<Mana> existingManas = new ArrayList<>();
if (i > 0) {
existingManas.addAll(payCombinations);
payCombinations.clear();
payCombinationsStrings.clear();
} else {
existingManas.add(new Mana());
}
for (Mana existingMana : existingManas) {
Mana manaToPay = manaAvailable.copy();
manaToPay.subtract(existingMana);
if (manaToPay.getBlack() > 0 && !payCombinationsStrings.contains(existingMana.toString() + Mana.BlackMana.toString())) {
manaToPay.subtract(Mana.BlackMana);
addManaCombination(Mana.BlackMana, existingMana, payCombinations, payCombinationsStrings);
}
if (manaToPay.getBlue() > 0 && !payCombinationsStrings.contains(existingMana.toString() + Mana.BlueMana.toString())) {
manaToPay.subtract(Mana.BlueMana);
addManaCombination(Mana.BlueMana, existingMana, payCombinations, payCombinationsStrings);
}
if (manaToPay.getGreen() > 0 && !payCombinationsStrings.contains(existingMana.toString() + Mana.GreenMana.toString())) {
manaToPay.subtract(Mana.GreenMana);
addManaCombination(Mana.GreenMana, existingMana, payCombinations, payCombinationsStrings);
}
if (manaToPay.getRed() > 0 && !payCombinationsStrings.contains(existingMana.toString() + Mana.RedMana.toString())) {
manaToPay.subtract(Mana.RedMana);
addManaCombination(Mana.RedMana, existingMana, payCombinations, payCombinationsStrings);
}
if (manaToPay.getWhite() > 0 && !payCombinationsStrings.contains(existingMana.toString() + Mana.WhiteMana.toString())) {
manaToPay.subtract(Mana.WhiteMana);
addManaCombination(Mana.WhiteMana, existingMana, payCombinations, payCombinationsStrings);
}
}
}
} else {
payCombinations.add(new Mana(0, 0, 0, 0, 0, number, 0));
}
return payCombinations;
}
private void addManaCombination(Mana mana, Mana existingMana, List<Mana> payCombinations, List<String> payCombinationsStrings) {
Mana newMana = existingMana.copy();
newMana.add(mana);
payCombinations.add(newMana);
payCombinationsStrings.add(newMana.toString());
}
} }