mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
* Benthic Explorer - Fixed mana type calculation.
* DynamicManaEffect - Fixed mana type calculation. Some code clean up.
This commit is contained in:
parent
66d5b915db
commit
457557852e
7 changed files with 148 additions and 193 deletions
|
@ -23,7 +23,10 @@ import mage.target.common.TargetLandPermanent;
|
|||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -135,46 +138,20 @@ class BenthicExplorersManaEffect extends ManaEffect {
|
|||
|
||||
@Override
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
List<Mana> netManas = new ArrayList<>();
|
||||
if (game == null) {
|
||||
return netManas;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Mana types = new Mana();
|
||||
Set<ManaType> manaTypes = EnumSet.noneOf(ManaType.class);
|
||||
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
|
||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponentId)) {
|
||||
if (permanent.isLand() && permanent.isTapped()) {
|
||||
for (ActivatedManaAbilityImpl ability : permanent.getAbilities(game).getActivatedManaAbilities(Zone.BATTLEFIELD)) {
|
||||
for (Mana mana : ability.getNetMana(game)) {
|
||||
types.add(mana);
|
||||
}
|
||||
manaTypes.addAll(ability.getProducableManaTypes(game));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (types.getBlack() > 0) {
|
||||
netManas.add(new Mana(ColoredManaSymbol.B));
|
||||
}
|
||||
if (types.getRed() > 0) {
|
||||
netManas.add(new Mana(ColoredManaSymbol.R));
|
||||
}
|
||||
if (types.getBlue() > 0) {
|
||||
netManas.add(new Mana(ColoredManaSymbol.U));
|
||||
}
|
||||
if (types.getGreen() > 0) {
|
||||
netManas.add(new Mana(ColoredManaSymbol.G));
|
||||
}
|
||||
if (types.getWhite() > 0) {
|
||||
netManas.add(new Mana(ColoredManaSymbol.W));
|
||||
}
|
||||
if (types.getColorless() > 0) {
|
||||
netManas.add(Mana.ColorlessMana(1));
|
||||
}
|
||||
if (types.getAny() > 0) {
|
||||
netManas.add(Mana.AnyMana(1));
|
||||
}
|
||||
return netManas;
|
||||
return ManaType.getManaListFromManaTypes(manaTypes, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -183,37 +160,7 @@ class BenthicExplorersManaEffect extends ManaEffect {
|
|||
if (game == null) {
|
||||
return mana;
|
||||
}
|
||||
Mana types = getManaTypes(game, source);
|
||||
Choice choice = new ChoiceColor(true);
|
||||
choice.getChoices().clear();
|
||||
choice.setMessage("Pick a mana color");
|
||||
if (types.getBlack() > 0) {
|
||||
choice.getChoices().add("Black");
|
||||
}
|
||||
if (types.getRed() > 0) {
|
||||
choice.getChoices().add("Red");
|
||||
}
|
||||
if (types.getBlue() > 0) {
|
||||
choice.getChoices().add("Blue");
|
||||
}
|
||||
if (types.getGreen() > 0) {
|
||||
choice.getChoices().add("Green");
|
||||
}
|
||||
if (types.getWhite() > 0) {
|
||||
choice.getChoices().add("White");
|
||||
}
|
||||
if (types.getColorless() > 0) {
|
||||
choice.getChoices().add("Colorless");
|
||||
}
|
||||
if (types.getAny() > 0) {
|
||||
choice.getChoices().add("Black");
|
||||
choice.getChoices().add("Red");
|
||||
choice.getChoices().add("Blue");
|
||||
choice.getChoices().add("Green");
|
||||
choice.getChoices().add("White");
|
||||
choice.getChoices().add("Colorless");
|
||||
|
||||
}
|
||||
Choice choice = ManaType.getChoiceOfManaTypes(getManaTypes(game, source), false);
|
||||
if (!choice.getChoices().isEmpty()) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (choice.getChoices().size() == 1) {
|
||||
|
@ -250,8 +197,8 @@ class BenthicExplorersManaEffect extends ManaEffect {
|
|||
return mana;
|
||||
}
|
||||
|
||||
private Mana getManaTypes(Game game, Ability source) {
|
||||
Mana types = new Mana();
|
||||
private Set<ManaType> getManaTypes(Game game, Ability source) {
|
||||
Set<ManaType> types = EnumSet.noneOf(ManaType.class);
|
||||
if (game == null
|
||||
|| game.getPhase() == null) {
|
||||
return types;
|
||||
|
@ -261,9 +208,7 @@ class BenthicExplorersManaEffect extends ManaEffect {
|
|||
Abilities<ActivatedManaAbilityImpl> mana = land.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD);
|
||||
for (ActivatedManaAbilityImpl ability : mana) {
|
||||
if (ability.definesMana(game)) {
|
||||
for (Mana netMana : ability.getNetMana(game)) {
|
||||
types.add(netMana);
|
||||
}
|
||||
types.addAll(ability.getProducableManaTypes(game));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,6 @@ class SquanderedResourcesEffect extends ManaEffect {
|
|||
|
||||
@Override
|
||||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
List<Mana> netManas = new ArrayList<>();
|
||||
if (game != null && game.inCheckPlayableState()) {
|
||||
// add color combinations of available mana
|
||||
ManaOptions allPossibleMana = new ManaOptions();
|
||||
|
@ -88,30 +87,7 @@ class SquanderedResourcesEffect extends ManaEffect {
|
|||
allPossibleMana.removeDuplicated();
|
||||
return allPossibleMana.stream().collect(Collectors.toList());
|
||||
}
|
||||
Set<ManaType> manaTypes = getManaTypesFromSacrificedPermanent(game, source);
|
||||
if (manaTypes.size() == 5 && !manaTypes.contains(ManaType.COLORLESS) && !manaTypes.contains(ManaType.GENERIC)) {
|
||||
netManas.add(Mana.AnyMana(1));
|
||||
} else {
|
||||
if (manaTypes.contains(ManaType.BLACK)) {
|
||||
netManas.add(Mana.BlackMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.RED)) {
|
||||
netManas.add(Mana.RedMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.BLUE)) {
|
||||
netManas.add(Mana.BlueMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.GREEN)) {
|
||||
netManas.add(Mana.GreenMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.WHITE)) {
|
||||
netManas.add(Mana.WhiteMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.COLORLESS)) {
|
||||
netManas.add(Mana.ColorlessMana(1));
|
||||
}
|
||||
}
|
||||
return netManas;
|
||||
return ManaType.getManaListFromManaTypes(getManaTypesFromSacrificedPermanent(game, source), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -120,28 +96,7 @@ class SquanderedResourcesEffect extends ManaEffect {
|
|||
if (game == null) {
|
||||
return mana;
|
||||
}
|
||||
Set<ManaType> manaTypes = getManaTypesFromSacrificedPermanent(game, source);
|
||||
Choice choice = new ChoiceColor(true);
|
||||
choice.getChoices().clear();
|
||||
choice.setMessage("Pick a mana color");
|
||||
if (manaTypes.contains(ManaType.BLACK)) {
|
||||
choice.getChoices().add("Black");
|
||||
}
|
||||
if (manaTypes.contains(ManaType.RED)) {
|
||||
choice.getChoices().add("Red");
|
||||
}
|
||||
if (manaTypes.contains(ManaType.BLUE)) {
|
||||
choice.getChoices().add("Blue");
|
||||
}
|
||||
if (manaTypes.contains(ManaType.GREEN)) {
|
||||
choice.getChoices().add("Green");
|
||||
}
|
||||
if (manaTypes.contains(ManaType.WHITE)) {
|
||||
choice.getChoices().add("White");
|
||||
}
|
||||
if (manaTypes.contains(ManaType.COLORLESS)) {
|
||||
choice.getChoices().add("Colorless");
|
||||
}
|
||||
Choice choice = ManaType.getChoiceOfManaTypes(getManaTypesFromSacrificedPermanent(game, source), false);
|
||||
if (!choice.getChoices().isEmpty()) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player == null) {
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package org.mage.test.cards.cost.modification;
|
||||
|
||||
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.CardTestPlayerBaseWithAIHelps;
|
||||
import static org.mage.test.utils.ManaOptionsTestUtils.assertManaOptions;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
|
@ -215,6 +218,27 @@ public class CostReduceForEachTest extends CardTestPlayerBaseWithAIHelps {
|
|||
|
||||
assertPermanentCount(playerA, "Balduvian Bears", 1);
|
||||
}
|
||||
@Test
|
||||
public void test_BenthicExplorers_BottomlessVault() {
|
||||
// {T}, Untap a tapped land an opponent controls: Add one mana of any type that land could produce.
|
||||
addCard(Zone.BATTLEFIELD, playerA, "Benthic Explorers", 1);
|
||||
|
||||
// Bottomless Vault enters the battlefield tapped.
|
||||
// You may choose not to untap Bottomless Vault during your untap step.
|
||||
// At the beginning of your upkeep, if Bottomless Vault is tapped, put a storage counter on it.
|
||||
// Tap, Remove any number of storage counters from Bottomless Vault: Add Black for each storage counter removed this way.
|
||||
addCard(Zone.BATTLEFIELD, playerB, "Bottomless Vault", 1); // give 1 mana
|
||||
|
||||
setStrictChooseMode(true);
|
||||
setStopAt(1, PhaseStep.PRECOMBAT_MAIN);
|
||||
execute();
|
||||
assertAllCommandsUsed();
|
||||
|
||||
ManaOptions manaOptions = playerA.getAvailableManaTest(currentGame);
|
||||
Assert.assertEquals("mana variations don't fit", 1, manaOptions.size());
|
||||
assertManaOptions("{B}", manaOptions);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_CloudKey_ChooseCardTypeForCostReduce() {
|
||||
|
|
|
@ -92,41 +92,10 @@ public abstract class ManaEffect extends OneShotEffect {
|
|||
* @return
|
||||
*/
|
||||
public Set<ManaType> getProducableManaTypes(Game game, Ability source) {
|
||||
return getManaTypesFromManaList(getNetMana(game, source));
|
||||
}
|
||||
|
||||
public static Set<ManaType> getManaTypesFromManaList(List<Mana> manaList) {
|
||||
Set<ManaType> manaTypes = new HashSet<>();
|
||||
for (Mana mana : manaList) {
|
||||
if (mana.getAny() > 0) {
|
||||
manaTypes.add(ManaType.BLACK);
|
||||
manaTypes.add(ManaType.BLUE);
|
||||
manaTypes.add(ManaType.GREEN);
|
||||
manaTypes.add(ManaType.WHITE);
|
||||
manaTypes.add(ManaType.RED);
|
||||
}
|
||||
if (mana.getBlack() > 0) {
|
||||
manaTypes.add(ManaType.BLACK);
|
||||
}
|
||||
if (mana.getBlue() > 0) {
|
||||
manaTypes.add(ManaType.BLUE);
|
||||
}
|
||||
if (mana.getGreen() > 0) {
|
||||
manaTypes.add(ManaType.GREEN);
|
||||
}
|
||||
if (mana.getWhite() > 0) {
|
||||
manaTypes.add(ManaType.WHITE);
|
||||
}
|
||||
if (mana.getRed() > 0) {
|
||||
manaTypes.add(ManaType.RED);
|
||||
}
|
||||
if (mana.getColorless() > 0) {
|
||||
manaTypes.add(ManaType.COLORLESS);
|
||||
}
|
||||
}
|
||||
return manaTypes;
|
||||
return ManaType.getManaTypesFromManaList(getNetMana(game, source));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Produced the mana the effect can produce (DO NOT add it to mana pool --
|
||||
* return all added as mana object to process by replace events)
|
||||
|
|
|
@ -12,6 +12,8 @@ import mage.players.Player;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import mage.constants.ManaType;
|
||||
|
||||
/**
|
||||
* @author North
|
||||
|
@ -116,6 +118,11 @@ public class DynamicManaEffect extends ManaEffect {
|
|||
return netMana;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ManaType> getProducableManaTypes(Game game, Ability source) {
|
||||
return ManaType.getManaTypesFromManaList(baseMana);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mana produceMana(Game game, Ability source) {
|
||||
Mana computedMana = new Mana();
|
||||
|
|
|
@ -6,8 +6,6 @@ import mage.abilities.Ability;
|
|||
import mage.abilities.costs.common.TapSourceCost;
|
||||
import mage.abilities.effects.common.ManaEffect;
|
||||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceColor;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.constants.TargetController;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterPermanent;
|
||||
|
@ -101,29 +99,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
|
|||
public List<Mana> getNetMana(Game game, Ability source) {
|
||||
List<Mana> netManas = new ArrayList<>();
|
||||
if (game != null) {
|
||||
Set<ManaType> manaTypes = getManaTypes(game, source);
|
||||
if ((manaTypes.size() == 5 && !manaTypes.contains(ManaType.COLORLESS)) || manaTypes.size() == 6) { // GENERIC should never be returned from getManaTypes
|
||||
netManas.add(Mana.AnyMana(1));
|
||||
} else {
|
||||
if (manaTypes.contains(ManaType.BLACK)) {
|
||||
netManas.add(Mana.BlackMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.RED)) {
|
||||
netManas.add(Mana.RedMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.BLUE)) {
|
||||
netManas.add(Mana.BlueMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.GREEN)) {
|
||||
netManas.add(Mana.GreenMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.WHITE)) {
|
||||
netManas.add(Mana.WhiteMana(1));
|
||||
}
|
||||
}
|
||||
if (!onlyColors && manaTypes.contains(ManaType.COLORLESS)) {
|
||||
netManas.add(Mana.ColorlessMana(1));
|
||||
}
|
||||
netManas = ManaType.getManaListFromManaTypes(getManaTypes(game, source), onlyColors);
|
||||
}
|
||||
return netManas;
|
||||
}
|
||||
|
@ -134,28 +110,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
|
|||
if (game == null) {
|
||||
return mana;
|
||||
}
|
||||
Set<ManaType> types = getManaTypes(game, source);
|
||||
Choice choice = new ChoiceColor(true);
|
||||
choice.getChoices().clear();
|
||||
choice.setMessage("Pick a mana " + (onlyColors ? "color" : "type"));
|
||||
if (types.contains(ManaType.BLACK)) {
|
||||
choice.getChoices().add("Black");
|
||||
}
|
||||
if (types.contains(ManaType.RED)) {
|
||||
choice.getChoices().add("Red");
|
||||
}
|
||||
if (types.contains(ManaType.BLUE)) {
|
||||
choice.getChoices().add("Blue");
|
||||
}
|
||||
if (types.contains(ManaType.GREEN)) {
|
||||
choice.getChoices().add("Green");
|
||||
}
|
||||
if (types.contains(ManaType.WHITE)) {
|
||||
choice.getChoices().add("White");
|
||||
}
|
||||
if (types.contains(ManaType.COLORLESS)) {
|
||||
choice.getChoices().add("Colorless");
|
||||
}
|
||||
Choice choice = ManaType.getChoiceOfManaTypes(getManaTypes(game, source), onlyColors);
|
||||
if (!choice.getChoices().isEmpty()) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (choice.getChoices().size() == 1) {
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
package mage.constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import mage.Mana;
|
||||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceColor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
|
@ -24,4 +33,95 @@ public enum ManaType {
|
|||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static Choice getChoiceOfManaTypes(Set<ManaType> types, boolean onlyColors) {
|
||||
Choice choice = new ChoiceColor(true);
|
||||
choice.getChoices().clear();
|
||||
choice.setMessage("Pick a mana " + (onlyColors ? "color" : "type"));
|
||||
if (types.contains(ManaType.BLACK)) {
|
||||
choice.getChoices().add("Black");
|
||||
}
|
||||
if (types.contains(ManaType.RED)) {
|
||||
choice.getChoices().add("Red");
|
||||
}
|
||||
if (types.contains(ManaType.BLUE)) {
|
||||
choice.getChoices().add("Blue");
|
||||
}
|
||||
if (types.contains(ManaType.GREEN)) {
|
||||
choice.getChoices().add("Green");
|
||||
}
|
||||
if (types.contains(ManaType.WHITE)) {
|
||||
choice.getChoices().add("White");
|
||||
}
|
||||
if (types.contains(ManaType.COLORLESS)) {
|
||||
choice.getChoices().add("Colorless");
|
||||
}
|
||||
return choice;
|
||||
}
|
||||
|
||||
public static List<Mana> getManaListFromManaTypes(Set<ManaType> manaTypes, boolean onlyColors) {
|
||||
List<Mana> netManas = new ArrayList<>();
|
||||
if ((manaTypes.size() == 5 && !manaTypes.contains(ManaType.COLORLESS)) || manaTypes.size() == 6) { // GENERIC should never be returned from getManaTypes
|
||||
netManas.add(Mana.AnyMana(1));
|
||||
} else {
|
||||
if (manaTypes.contains(ManaType.BLACK)) {
|
||||
netManas.add(Mana.BlackMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.RED)) {
|
||||
netManas.add(Mana.RedMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.BLUE)) {
|
||||
netManas.add(Mana.BlueMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.GREEN)) {
|
||||
netManas.add(Mana.GreenMana(1));
|
||||
}
|
||||
if (manaTypes.contains(ManaType.WHITE)) {
|
||||
netManas.add(Mana.WhiteMana(1));
|
||||
}
|
||||
}
|
||||
if (!onlyColors && manaTypes.contains(ManaType.COLORLESS)) {
|
||||
netManas.add(Mana.ColorlessMana(1));
|
||||
}
|
||||
|
||||
return netManas;
|
||||
}
|
||||
|
||||
public static Set<ManaType> getManaTypesFromManaList(Mana mana) {
|
||||
Set<ManaType> manaTypes = EnumSet.noneOf(ManaType.class);
|
||||
if (mana.getAny() > 0) {
|
||||
manaTypes.add(ManaType.BLACK);
|
||||
manaTypes.add(ManaType.BLUE);
|
||||
manaTypes.add(ManaType.GREEN);
|
||||
manaTypes.add(ManaType.WHITE);
|
||||
manaTypes.add(ManaType.RED);
|
||||
}
|
||||
if (mana.getBlack() > 0) {
|
||||
manaTypes.add(ManaType.BLACK);
|
||||
}
|
||||
if (mana.getBlue() > 0) {
|
||||
manaTypes.add(ManaType.BLUE);
|
||||
}
|
||||
if (mana.getGreen() > 0) {
|
||||
manaTypes.add(ManaType.GREEN);
|
||||
}
|
||||
if (mana.getWhite() > 0) {
|
||||
manaTypes.add(ManaType.WHITE);
|
||||
}
|
||||
if (mana.getRed() > 0) {
|
||||
manaTypes.add(ManaType.RED);
|
||||
}
|
||||
if (mana.getColorless() > 0) {
|
||||
manaTypes.add(ManaType.COLORLESS);
|
||||
}
|
||||
return manaTypes;
|
||||
}
|
||||
|
||||
public static Set<ManaType> getManaTypesFromManaList(List<Mana> manaList) {
|
||||
Set<ManaType> manaTypes = new HashSet<>();
|
||||
for (Mana mana : manaList) {
|
||||
manaTypes.addAll(getManaTypesFromManaList(mana));
|
||||
}
|
||||
return manaTypes;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue