From df341bd0d6674282cdb398f707183c6c624e9e43 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 5 Jun 2018 23:59:39 +0200 Subject: [PATCH] * Fixed some mana handling problems of conditionalMana (GemstoneCavern) and possible exception of ChromeMox.Fixed some tests. --- Mage.Sets/src/mage/cards/c/ChromeMox.java | 6 +-- .../src/mage/cards/g/GemstoneCaverns.java | 7 ++- .../abilities/keywords/ConstellationTest.java | 9 ++-- .../test/cards/mana/NagaVitalistTest.java | 13 ++++- .../mana/VorinclexVoiceOfHungerTest.java | 3 -- .../decorator/ConditionalManaEffect.java | 13 ++++- .../effects/mana/AddManaOfAnyColorEffect.java | 48 ++++++++++++------- .../mana/ConditionalManaAbility.java | 5 +- Mage/src/main/java/mage/players/ManaPool.java | 37 +++++++------- 9 files changed, 85 insertions(+), 56 deletions(-) diff --git a/Mage.Sets/src/mage/cards/c/ChromeMox.java b/Mage.Sets/src/mage/cards/c/ChromeMox.java index a0a02f20e36..b3b414ee191 100644 --- a/Mage.Sets/src/mage/cards/c/ChromeMox.java +++ b/Mage.Sets/src/mage/cards/c/ChromeMox.java @@ -1,4 +1,3 @@ - package mage.cards.c; import java.util.ArrayList; @@ -127,8 +126,9 @@ class ChromeMoxManaEffect extends ManaEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - checkToFirePossibleEvents(getMana(game, source), game, source); - controller.getManaPool().addMana(getMana(game, source), game, source); + Mana mana = getMana(game, source); + checkToFirePossibleEvents(mana, game, source); + controller.getManaPool().addMana(mana, game, source); return true; } diff --git a/Mage.Sets/src/mage/cards/g/GemstoneCaverns.java b/Mage.Sets/src/mage/cards/g/GemstoneCaverns.java index 18a15d5ae64..ee2b7c14662 100644 --- a/Mage.Sets/src/mage/cards/g/GemstoneCaverns.java +++ b/Mage.Sets/src/mage/cards/g/GemstoneCaverns.java @@ -1,4 +1,3 @@ - package mage.cards.g; import java.util.UUID; @@ -121,6 +120,7 @@ class GemstoneCavernsEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { + boolean result = false; Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Card card = game.getCard(source.getSourceId()); @@ -133,13 +133,12 @@ class GemstoneCavernsEffect extends OneShotEffect { if (permanent != null) { Cost cost = new ExileFromHandCost(new TargetCardInHand()); if (cost.canPay(source, source.getSourceId(), source.getControllerId(), game)) { - cost.pay(source, game, source.getSourceId(), source.getControllerId(), true, null); + result = cost.pay(source, game, source.getSourceId(), source.getControllerId(), true, null); } } } } - return true; } - return false; + return result; } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/ConstellationTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/ConstellationTest.java index a7c55a1cae0..834233f9297 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/ConstellationTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/ConstellationTest.java @@ -135,10 +135,11 @@ public class ConstellationTest extends CardTestPlayerBase { @Test public void test_DaxosGotBoostWithLoseFlyAndGotItAgain() { // 112.10c If two or more effects add and remove the same ability, in general the most recent one prevails. - addCard(Zone.HAND, playerA, daxosCard, 1); - addCard(Zone.BATTLEFIELD, playerA, "Swamp", 4); - addCard(Zone.HAND, playerA, "Gravity Sphere", 1); // All creatures lose flying. - addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); + addCard(Zone.HAND, playerA, daxosCard, 1); // {3}{B} + addCard(Zone.BATTLEFIELD, playerA, "Swamp", 1); + // All creatures lose flying. + addCard(Zone.HAND, playerA, "Gravity Sphere", 1); // World Enchantment {2}{R} + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6); // got fly on enter, lose on gravity, got fly on gravity enter castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, daxosCard); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/mana/NagaVitalistTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/mana/NagaVitalistTest.java index a16e293090e..e979dad8041 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/mana/NagaVitalistTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/mana/NagaVitalistTest.java @@ -1,12 +1,14 @@ package org.mage.test.cards.mana; +import mage.abilities.mana.ManaOptions; import mage.constants.ManaType; import mage.constants.PhaseStep; import mage.constants.Zone; import org.junit.Assert; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; -import static org.mage.test.utils.ManaOptionsTestUtils.manaOptionsContain; +import static org.mage.test.utils.ManaOptionsTestUtils.assertDuplicatedManaOptions; +import static org.mage.test.utils.ManaOptionsTestUtils.assertManaOptions; /** * @@ -47,7 +49,14 @@ public class NagaVitalistTest extends CardTestPlayerBase { setStopAt(1, PhaseStep.PRECOMBAT_MAIN); execute(); - Assert.assertTrue("playerA must cast {Any}{Any}", manaOptionsContain(playerA.getManaAvailable(currentGame), "{Any}{Any}")); + ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame); + assertDuplicatedManaOptions(manaOptions); + Assert.assertEquals("mana variations don't fit", 5, manaOptions.size()); + assertManaOptions("{B}{B}", manaOptions); + assertManaOptions("{W}{W}", manaOptions); + assertManaOptions("{U}{U}", manaOptions); + assertManaOptions("{R}{R}", manaOptions); + assertManaOptions("{G}{G}", manaOptions); } public void nagaVitalist_GiftOfParadisesLandCanGiveAnyColorToNaga_Setup(int giftCastTurn, int nagaManaTapTurn, String nagaManaTapColor) { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/mana/VorinclexVoiceOfHungerTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/mana/VorinclexVoiceOfHungerTest.java index ccfe17b62cf..d6ec862b443 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/mana/VorinclexVoiceOfHungerTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/mana/VorinclexVoiceOfHungerTest.java @@ -4,7 +4,6 @@ import mage.constants.ManaType; import mage.constants.PhaseStep; import mage.constants.Zone; import mage.counters.CounterType; -import org.junit.Ignore; import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; @@ -41,7 +40,6 @@ public class VorinclexVoiceOfHungerTest extends CardTestPlayerBase { * Vorinclex, Voice of Hunger is not mana doubling River of Tears. */ @Test - // @Ignore // TODO: need to fix Vorinclex, Voice of Hunger -- it's double fireup mana tap event public void testVorinclexVoiceofHungerRiverOfTearsManaMultiplier() { // Mana pools don't empty as steps and phases end. addCard(Zone.BATTLEFIELD, playerA, "Upwelling", 1); @@ -64,7 +62,6 @@ public class VorinclexVoiceOfHungerTest extends CardTestPlayerBase { /** * Vorinclex glitches with Gemstone Cavern */ - @Ignore @Test public void testGemstoneCavern() { // Trample diff --git a/Mage/src/main/java/mage/abilities/decorator/ConditionalManaEffect.java b/Mage/src/main/java/mage/abilities/decorator/ConditionalManaEffect.java index baa1e133755..7d2f3a75fe8 100644 --- a/Mage/src/main/java/mage/abilities/decorator/ConditionalManaEffect.java +++ b/Mage/src/main/java/mage/abilities/decorator/ConditionalManaEffect.java @@ -1,5 +1,6 @@ package mage.abilities.decorator; +import java.util.List; import mage.Mana; import mage.abilities.Ability; import mage.abilities.condition.Condition; @@ -47,10 +48,10 @@ public class ConditionalManaEffect extends ManaEffect { return false; } Mana mana = getMana(game, source); - controller.getManaPool().addMana(mana, game, source); if (produceMana(true, game, source).getAny() > 0) { checkToFirePossibleEvents(mana, game, source); } + controller.getManaPool().addMana(mana, game, source); return true; } @@ -64,6 +65,16 @@ public class ConditionalManaEffect extends ManaEffect { return produceMana(false, game, source); } + @Override + public List getNetMana(Game game, Ability source) { + if (condition.apply(game, source)) { + return effect.getNetMana(game, source); + } else if (otherwiseEffect != null) { + return otherwiseEffect.getNetMana(game, source); + } + return null; + } + @Override public Mana produceMana(boolean netMana, Game game, Ability source) { Mana mana = new Mana(); diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyColorEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyColorEffect.java index 8170ed8ebe8..72c2284a204 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyColorEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddManaOfAnyColorEffect.java @@ -1,6 +1,7 @@ - package mage.abilities.effects.mana; +import java.util.ArrayList; +import java.util.List; import mage.Mana; import mage.abilities.Ability; import mage.choices.ChoiceColor; @@ -13,25 +14,28 @@ import mage.util.CardUtil; */ public class AddManaOfAnyColorEffect extends BasicManaEffect { - protected int amount; + protected final int amount; + protected final ArrayList netMana = new ArrayList<>(); public AddManaOfAnyColorEffect() { this(1); } - public AddManaOfAnyColorEffect(final int amount) { + public AddManaOfAnyColorEffect(int amount) { super(new Mana(0, 0, 0, 0, 0, 0, amount, 0)); this.amount = amount; - this.staticText = new StringBuilder("add ") - .append(CardUtil.numberToText(amount)) - .append(" mana of any ") - .append(amount > 1 ? "one " : "") - .append("color").toString(); + netMana.add(Mana.GreenMana(amount)); + netMana.add(Mana.BlueMana(amount)); + netMana.add(Mana.BlackMana(amount)); + netMana.add(Mana.WhiteMana(amount)); + netMana.add(Mana.RedMana(amount)); + this.staticText = "add " + CardUtil.numberToText(amount) + " mana of any " + (amount > 1 ? "one " : "") + "color"; } public AddManaOfAnyColorEffect(final AddManaOfAnyColorEffect effect) { super(effect); this.amount = effect.amount; + this.netMana.addAll(effect.netMana); } @Override @@ -41,23 +45,33 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect { @Override public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + checkToFirePossibleEvents(getMana(game, source), game, source); + controller.getManaPool().addMana(getMana(game, source), game, source); + return true; + } + return false; + } + + @Override + public List getNetMana(Game game, Ability source) { + return netMana; + } + + @Override + public Mana produceMana(boolean netMana, Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { String mes = String.format("Select color of %d mana to add it", this.amount); ChoiceColor choice = new ChoiceColor(true, mes, game.getObject(source.getSourceId())); if (controller.choose(outcome, choice, game)) { - if (choice.getColor() == null) { - return false; + if (choice.getColor() != null) { + return choice.getMana(amount); } - Mana createdMana = choice.getMana(amount); - if (createdMana != null) { - checkToFirePossibleEvents(createdMana, game, source); - controller.getManaPool().addMana(createdMana, game, source); - } - return true; } } - return false; + return null; } public int getAmount() { diff --git a/Mage/src/main/java/mage/abilities/mana/ConditionalManaAbility.java b/Mage/src/main/java/mage/abilities/mana/ConditionalManaAbility.java index 8ae3ad06895..06c2919d175 100644 --- a/Mage/src/main/java/mage/abilities/mana/ConditionalManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/ConditionalManaAbility.java @@ -1,5 +1,3 @@ - - package mage.abilities.mana; import java.util.ArrayList; @@ -14,7 +12,6 @@ import mage.game.Game; * * @author LevelX2 */ - public class ConditionalManaAbility extends ActivatedManaAbilityImpl { ConditionalManaEffect conditionalManaEffect; @@ -37,7 +34,7 @@ public class ConditionalManaAbility extends ActivatedManaAbilityImpl { @Override public List getNetMana(Game game) { List newNetMana = new ArrayList<>(); - newNetMana.add(conditionalManaEffect.getMana(game, this)); + newNetMana.addAll(conditionalManaEffect.getNetMana(game, this)); return newNetMana; } } diff --git a/Mage/src/main/java/mage/players/ManaPool.java b/Mage/src/main/java/mage/players/ManaPool.java index cb099ddebd9..e66b118a8b1 100644 --- a/Mage/src/main/java/mage/players/ManaPool.java +++ b/Mage/src/main/java/mage/players/ManaPool.java @@ -1,4 +1,3 @@ - package mage.players; import java.io.Serializable; @@ -366,25 +365,27 @@ public class ManaPool implements Serializable { } public void addMana(Mana manaToAdd, Game game, Ability source, boolean emptyOnTurnsEnd) { - Mana mana = manaToAdd.copy(); - if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source.getSourceId(), playerId, mana))) { - if (mana instanceof ConditionalMana) { - ManaPoolItem item = new ManaPoolItem((ConditionalMana) mana, source.getSourceObject(game), - ((ConditionalMana) mana).getManaProducerOriginalId() != null ? ((ConditionalMana) mana).getManaProducerOriginalId() : source.getOriginalId()); - if (emptyOnTurnsEnd) { - item.setDuration(Duration.EndOfTurn); + if (manaToAdd != null) { + Mana mana = manaToAdd.copy(); + if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source.getSourceId(), playerId, mana))) { + if (mana instanceof ConditionalMana) { + ManaPoolItem item = new ManaPoolItem((ConditionalMana) mana, source.getSourceObject(game), + ((ConditionalMana) mana).getManaProducerOriginalId() != null ? ((ConditionalMana) mana).getManaProducerOriginalId() : source.getOriginalId()); + if (emptyOnTurnsEnd) { + item.setDuration(Duration.EndOfTurn); + } + this.manaItems.add(item); + } else { + ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getGeneric() + mana.getColorless(), source.getSourceObject(game), source.getOriginalId(), mana.getFlag()); + if (emptyOnTurnsEnd) { + item.setDuration(Duration.EndOfTurn); + } + this.manaItems.add(item); } - this.manaItems.add(item); - } else { - ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getGeneric() + mana.getColorless(), source.getSourceObject(game), source.getOriginalId(), mana.getFlag()); - if (emptyOnTurnsEnd) { - item.setDuration(Duration.EndOfTurn); - } - this.manaItems.add(item); + ManaEvent manaEvent = new ManaEvent(EventType.MANA_ADDED, source.getId(), source.getSourceId(), playerId, mana); + manaEvent.setData(mana.toString()); + game.fireEvent(manaEvent); } - ManaEvent manaEvent = new ManaEvent(EventType.MANA_ADDED, source.getId(), source.getSourceId(), playerId, mana); - manaEvent.setData(mana.toString()); - game.fireEvent(manaEvent); } }