mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Creating branch for changes for supporting "Produced$ Any" in mana abilities
This commit is contained in:
@@ -2,11 +2,12 @@ Name:City of Brass
|
|||||||
ManaCost:no cost
|
ManaCost:no cost
|
||||||
Types:Land
|
Types:Land
|
||||||
Text:no text
|
Text:no text
|
||||||
A:AB$ Mana | Cost$ T | Produced$ W | SpellDescription$ Add W to your mana pool.
|
A:AB$ Mana | Cost$ T | Produced$ Any | Amount$ 1 | SpellDescription$ Add one mana of any color to your mana pool.
|
||||||
A:AB$ Mana | Cost$ T | Produced$ B | SpellDescription$ Add B to your mana pool.
|
#A:AB$ Mana | Cost$ T | Produced$ W | SpellDescription$ Add W to your mana pool.
|
||||||
A:AB$ Mana | Cost$ T | Produced$ U | SpellDescription$ Add U to your mana pool.
|
#A:AB$ Mana | Cost$ T | Produced$ B | SpellDescription$ Add B to your mana pool.
|
||||||
A:AB$ Mana | Cost$ T | Produced$ R | SpellDescription$ Add R to your mana pool.
|
#A:AB$ Mana | Cost$ T | Produced$ U | SpellDescription$ Add U to your mana pool.
|
||||||
A:AB$ Mana | Cost$ T | Produced$ G | SpellDescription$ Add G to your mana pool.
|
#A:AB$ Mana | Cost$ T | Produced$ R | SpellDescription$ Add R to your mana pool.
|
||||||
|
#A:AB$ Mana | Cost$ T | Produced$ G | SpellDescription$ Add G to your mana pool.
|
||||||
T:Mode$ Taps | ValidCard$ Card.Self | Execute$ TrigDamage | TriggerZones$ Battlefield | TriggerDescription$ Whenever CARDNAME becomes tapped, it deals 1 damage to you.
|
T:Mode$ Taps | ValidCard$ Card.Self | Execute$ TrigDamage | TriggerZones$ Battlefield | TriggerDescription$ Whenever CARDNAME becomes tapped, it deals 1 damage to you.
|
||||||
SVar:TrigDamage:AB$DealDamage | Cost$ 0 | Defined$ You | NumDmg$ 1
|
SVar:TrigDamage:AB$DealDamage | Cost$ 0 | Defined$ You | NumDmg$ 1
|
||||||
SVar:Rarity:Rare
|
SVar:Rarity:Rare
|
||||||
@@ -18,4 +19,4 @@ SetInfo:5ED|Rare|http://magiccards.info/scans/en/5e/413.jpg
|
|||||||
SetInfo:6ED|Rare|http://magiccards.info/scans/en/6e/321.jpg
|
SetInfo:6ED|Rare|http://magiccards.info/scans/en/6e/321.jpg
|
||||||
SetInfo:CHR|Rare|http://magiccards.info/scans/en/ch/92.jpg
|
SetInfo:CHR|Rare|http://magiccards.info/scans/en/ch/92.jpg
|
||||||
SetInfo:ARN|Uncommon|http://magiccards.info/scans/en/an/85.jpg
|
SetInfo:ARN|Uncommon|http://magiccards.info/scans/en/an/85.jpg
|
||||||
End
|
End
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ Name:Glimmervoid
|
|||||||
ManaCost:no cost
|
ManaCost:no cost
|
||||||
Types:Land
|
Types:Land
|
||||||
Text:no text
|
Text:no text
|
||||||
|
#A:AB$ Mana | Cost$ T | Produced$ Any | Amount$ 1 | SpellDescription$ Add one mana of any color to your mana pool.
|
||||||
A:AB$ Mana | Cost$ T | Produced$ W | SpellDescription$ Add W to your mana pool.
|
A:AB$ Mana | Cost$ T | Produced$ W | SpellDescription$ Add W to your mana pool.
|
||||||
A:AB$ Mana | Cost$ T | Produced$ B | SpellDescription$ Add B to your mana pool.
|
A:AB$ Mana | Cost$ T | Produced$ B | SpellDescription$ Add B to your mana pool.
|
||||||
A:AB$ Mana | Cost$ T | Produced$ U | SpellDescription$ Add U to your mana pool.
|
A:AB$ Mana | Cost$ T | Produced$ U | SpellDescription$ Add U to your mana pool.
|
||||||
|
|||||||
@@ -2790,11 +2790,10 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (am.isBasic() && !res.contains(am)) {
|
if ((am.isBasic() || am.isReflectedMana() || am.isAnyMana()) && !res.contains(am)) {
|
||||||
res.add(am);
|
|
||||||
} else if (am.isReflectedMana() && !res.contains(am)) {
|
|
||||||
res.add(am);
|
res.add(am);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import forge.card.spellability.AbilityMana;
|
|||||||
import forge.card.spellability.SpellAbility;
|
import forge.card.spellability.SpellAbility;
|
||||||
import forge.card.spellability.Target;
|
import forge.card.spellability.Target;
|
||||||
import forge.error.ErrorViewer;
|
import forge.error.ErrorViewer;
|
||||||
|
import forge.gui.input.InputPayManaCostUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -177,6 +178,8 @@ public class ComputerUtil {
|
|||||||
final CostPayment pay = new CostPayment(cost, sa);
|
final CostPayment pay = new CostPayment(cost, sa);
|
||||||
if (pay.payComputerCosts()) {
|
if (pay.payComputerCosts()) {
|
||||||
AllZone.getStack().addAndUnfreeze(sa);
|
AllZone.getStack().addAndUnfreeze(sa);
|
||||||
|
//TODO: solve problems with TapsForMana triggers by adding
|
||||||
|
// sources tapped here if possible (ArsenalNut)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -615,6 +618,168 @@ public class ComputerUtil {
|
|||||||
cost.setManaNeededToAvoidNegativeEffect(card.getSVar("ManaNeededToAvoidNegativeEffect").split(","));
|
cost.setManaNeededToAvoidNegativeEffect(card.getSVar("ManaNeededToAvoidNegativeEffect").split(","));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get map of mana abilities
|
||||||
|
HashMap<String, ArrayList<AbilityMana>> manaAbilityMap = mapManaSources(player);
|
||||||
|
// initialize ArrayList list for mana needed
|
||||||
|
ArrayList<ArrayList<AbilityMana>> partSources =
|
||||||
|
new ArrayList<ArrayList<AbilityMana>>();
|
||||||
|
ArrayList<Integer> partPriority = new ArrayList<Integer>();
|
||||||
|
String[] costParts = cost.toString().split(" ");
|
||||||
|
Boolean foundAllSources = true;
|
||||||
|
if (manaAbilityMap.isEmpty()) {
|
||||||
|
foundAllSources = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String[] shortColors = {"W", "U", "B" , "R", "G"};
|
||||||
|
// loop over cost parts
|
||||||
|
for (int nPart = 0; nPart < costParts.length; nPart++) {
|
||||||
|
ManaCost costPart = new ManaCost(costParts[nPart]);
|
||||||
|
ArrayList<AbilityMana> srcFound = new ArrayList<AbilityMana>();
|
||||||
|
// get colored mana required
|
||||||
|
ManaCost onlyColored = costPart;
|
||||||
|
onlyColored.removeColorlessMana();
|
||||||
|
for (String color : shortColors) {
|
||||||
|
if (onlyColored.isColor(color)) {
|
||||||
|
// Is source available?
|
||||||
|
if (manaAbilityMap.containsKey(color)) {
|
||||||
|
srcFound.addAll(manaAbilityMap.get(color));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Test for Colorless
|
||||||
|
if (costPart.isColor("1")) {
|
||||||
|
srcFound.addAll(manaAbilityMap.get("1"));
|
||||||
|
}
|
||||||
|
// Test for Snow
|
||||||
|
if (costPart.isColor("S")) {
|
||||||
|
if (manaAbilityMap.containsKey("S")) {
|
||||||
|
srcFound.addAll(manaAbilityMap.get("S"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add sources to array lists
|
||||||
|
partSources.add(nPart, srcFound);
|
||||||
|
// add to sorted priority list
|
||||||
|
if (srcFound.size() > 0) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < partPriority.size(); i++) {
|
||||||
|
if (srcFound.size() < partSources.get(i).size()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
partPriority.add(i, nPart);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
foundAllSources = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if (!foundAllSources) {
|
||||||
|
if (!test) {
|
||||||
|
// real payment should not arrive here
|
||||||
|
throw new RuntimeException("ComputerUtil : payManaCost() cost was not paid for " + sa.getSourceCard().getName());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
ManaCost testCost = new ManaCost(cost.toString());
|
||||||
|
// Create array to keep track of sources used
|
||||||
|
ArrayList<Card> usedSources = new ArrayList<Card>();
|
||||||
|
//this is to prevent errors for mana sources that have abilities that cost mana.
|
||||||
|
usedSources.add(sa.getSourceCard());
|
||||||
|
// Loop over mana needed
|
||||||
|
int nPriority = 0;
|
||||||
|
while (nPriority < partPriority.size()) {
|
||||||
|
int nPart = partPriority.get(nPriority);
|
||||||
|
ArrayList<AbilityMana> manaAbilities = partSources.get(nPart);
|
||||||
|
ManaCost costPart = new ManaCost(costParts[nPart]);
|
||||||
|
// Loop over mana abilities that can be used to current mana cost part
|
||||||
|
for (AbilityMana m : manaAbilities) {
|
||||||
|
Card sourceCard = m.getSourceCard();
|
||||||
|
|
||||||
|
// Check if source has already been used
|
||||||
|
if (usedSources.contains(sourceCard)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if AI can still play this mana ability
|
||||||
|
m.setActivatingPlayer(player);
|
||||||
|
//if the AI can't pay the additional costs skip the mana ability
|
||||||
|
if (m.getPayCosts() != null) {
|
||||||
|
if (!canPayAdditionalCosts(m, player)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (sourceCard.isTapped()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add source card to used list
|
||||||
|
usedSources.add(sourceCard);
|
||||||
|
|
||||||
|
// // add source card to used list
|
||||||
|
// if (!test) {
|
||||||
|
// //Pay additional costs
|
||||||
|
// if (m.getPayCosts() != null) {
|
||||||
|
// Cost_Payment pay = new Cost_Payment(m.getPayCosts(), m);
|
||||||
|
// if (!pay.payComputerCosts()) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// sourceCard.tap();
|
||||||
|
// }
|
||||||
|
// // resolve mana ability
|
||||||
|
// m.resolve();
|
||||||
|
// // subtract mana from mana pool
|
||||||
|
// cost = manapool.subtractMana(sa, cost, m);
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
String manaProduced;
|
||||||
|
// Check if paying snow mana
|
||||||
|
if ("S".equals(costParts[nPart])) {
|
||||||
|
manaProduced = "S";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// check if ability produces any color
|
||||||
|
//TODO: This won't work with Hybrid mana or colorless costs (111230 - ArsenalNut)
|
||||||
|
if (m.isAnyMana()) {
|
||||||
|
m.setAnyChoice(costParts[nPart]);
|
||||||
|
}
|
||||||
|
// get produced mana
|
||||||
|
manaProduced = m.getManaProduced();
|
||||||
|
}
|
||||||
|
// pay cost
|
||||||
|
String color = InputPayManaCostUtil.getLongColorString(manaProduced);
|
||||||
|
testCost.payMana(color);
|
||||||
|
costPart.payMana(color);
|
||||||
|
// }
|
||||||
|
// check if color is still needed
|
||||||
|
if (costPart.isPaid()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} // end of mana ability loop
|
||||||
|
if (!costPart.isPaid()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nPriority++;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of cost parts loop
|
||||||
|
|
||||||
|
// // check if paid
|
||||||
|
// if (cost.isPaid()) {
|
||||||
|
// //if (sa instanceof Spell_Permanent) // should probably add this
|
||||||
|
// sa.getSourceCard().setColorsPaid(cost.getColorsPaid());
|
||||||
|
// sa.getSourceCard().setSunburstValue(cost.getSunburst());
|
||||||
|
// manapool.clearPay(sa, test);
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
|
||||||
final CardList manaSources = ComputerUtil.getAvailableMana();
|
final CardList manaSources = ComputerUtil.getAvailableMana();
|
||||||
|
|
||||||
// this is to prevent errors for mana sources that have abilities that
|
// this is to prevent errors for mana sources that have abilities that
|
||||||
@@ -861,7 +1026,7 @@ public class ComputerUtil {
|
|||||||
sortedManaSources.add(card);
|
sortedManaSources.add(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//TODO: Check for cards that produce "Any" as base mana (ArsenalNut)
|
||||||
// 2. Search for mana sources that have a certain number of mana
|
// 2. Search for mana sources that have a certain number of mana
|
||||||
// abilities (start with 1 and go up to 5) and no drawback/costs
|
// abilities (start with 1 and go up to 5) and no drawback/costs
|
||||||
for (int number = 1; number < 6; number++) {
|
for (int number = 1; number < 6; number++) {
|
||||||
@@ -983,7 +1148,93 @@ public class ComputerUtil {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// plays a land if one is available
|
/**
|
||||||
|
* <p>mapManaSources.</p>
|
||||||
|
*
|
||||||
|
* @param player a {@link forge.Player} object.
|
||||||
|
* @return HashMap<String, CardList>
|
||||||
|
*/
|
||||||
|
public static HashMap<String, ArrayList<AbilityMana>> mapManaSources(final Player player) {
|
||||||
|
HashMap<String, ArrayList<AbilityMana>> manaMap = new HashMap<String, ArrayList<AbilityMana>>();
|
||||||
|
|
||||||
|
ArrayList<AbilityMana> whiteSources = new ArrayList<AbilityMana>();
|
||||||
|
ArrayList<AbilityMana> blueSources = new ArrayList<AbilityMana>();
|
||||||
|
ArrayList<AbilityMana> blackSources = new ArrayList<AbilityMana>();
|
||||||
|
ArrayList<AbilityMana> redSources = new ArrayList<AbilityMana>();
|
||||||
|
ArrayList<AbilityMana> greenSources = new ArrayList<AbilityMana>();
|
||||||
|
ArrayList<AbilityMana> colorlessSources = new ArrayList<AbilityMana>();
|
||||||
|
ArrayList<AbilityMana> snowSources = new ArrayList<AbilityMana>();
|
||||||
|
|
||||||
|
// Get list of current available mana sources
|
||||||
|
final CardList manaSources = ComputerUtil.getAvailableMana();
|
||||||
|
|
||||||
|
// Loop over all mana sources
|
||||||
|
for (int i = 0; i < manaSources.size(); i++) {
|
||||||
|
Card sourceCard = manaSources.get(i);
|
||||||
|
ArrayList<AbilityMana> manaAbilities = sourceCard.getAIPlayableMana();
|
||||||
|
|
||||||
|
// Loop over all mana abilities for a source
|
||||||
|
for (AbilityMana m : manaAbilities) {
|
||||||
|
|
||||||
|
//don't use abilities with dangerous drawbacks
|
||||||
|
if (m.getSubAbility() != null) {
|
||||||
|
if (!m.getSubAbility().chkAIDrawback()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add to colorless source list
|
||||||
|
colorlessSources.add(m);
|
||||||
|
|
||||||
|
// find possible colors
|
||||||
|
if (m.canProduce("W") || m.isAnyMana()) {
|
||||||
|
whiteSources.add(m);
|
||||||
|
}
|
||||||
|
if (m.canProduce("U") || m.isAnyMana()) {
|
||||||
|
blueSources.add(m);
|
||||||
|
}
|
||||||
|
if (m.canProduce("B") || m.isAnyMana()) {
|
||||||
|
blackSources.add(m);
|
||||||
|
}
|
||||||
|
if (m.canProduce("R") || m.isAnyMana()) {
|
||||||
|
redSources.add(m);
|
||||||
|
}
|
||||||
|
if (m.canProduce("G") || m.isAnyMana()) {
|
||||||
|
greenSources.add(m);
|
||||||
|
}
|
||||||
|
if (m.isSnow()) {
|
||||||
|
snowSources.add(m);
|
||||||
|
}
|
||||||
|
} // end of mana abilities loop
|
||||||
|
} // end of mana sources loop
|
||||||
|
|
||||||
|
// Add sources
|
||||||
|
if (!whiteSources.isEmpty()) {
|
||||||
|
manaMap.put("W", whiteSources);
|
||||||
|
}
|
||||||
|
if (!blueSources.isEmpty()) {
|
||||||
|
manaMap.put("U", blueSources);
|
||||||
|
}
|
||||||
|
if (!blackSources.isEmpty()) {
|
||||||
|
manaMap.put("B", blackSources);
|
||||||
|
}
|
||||||
|
if (!redSources.isEmpty()) {
|
||||||
|
manaMap.put("R", redSources);
|
||||||
|
}
|
||||||
|
if (!greenSources.isEmpty()) {
|
||||||
|
manaMap.put("G", greenSources);
|
||||||
|
}
|
||||||
|
if (!colorlessSources.isEmpty()) {
|
||||||
|
manaMap.put("1", colorlessSources);
|
||||||
|
}
|
||||||
|
if (!snowSources.isEmpty()) {
|
||||||
|
manaMap.put("S", snowSources);
|
||||||
|
}
|
||||||
|
|
||||||
|
return manaMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
//plays a land if one is available
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* chooseLandsToPlay.
|
* chooseLandsToPlay.
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package forge.card.abilityfactory;
|
package forge.card.abilityfactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@@ -85,6 +86,11 @@ public class AbilityFactoryMana {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getManaProduced() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return manaGenerated(this, this.af, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return abMana;
|
return abMana;
|
||||||
}
|
}
|
||||||
@@ -117,6 +123,10 @@ public class AbilityFactoryMana {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getManaProduced() {
|
||||||
|
return manaGenerated(this.tmpMana, this.af, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -168,6 +178,10 @@ public class AbilityFactoryMana {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getManaProduced() {
|
||||||
|
return manaGenerated(this.tmpMana, this.af, this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -241,6 +255,18 @@ public class AbilityFactoryMana {
|
|||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>manaGenerated.</p>
|
||||||
|
*
|
||||||
|
* @param abMana a {@link forge.card.spellability.Ability_Mana} object.
|
||||||
|
* @param af a {@link forge.card.abilityFactory.AbilityFactory} object.
|
||||||
|
* @param sa a {@link forge.card.spellability.SpellAbility} object.
|
||||||
|
* @return a {@link java.lang.String} object.
|
||||||
|
*/
|
||||||
|
public static String manaGenerated(final AbilityMana abMana, final AbilityFactory af, final SpellAbility sa) {
|
||||||
|
return generatedMana(abMana, af, sa);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -277,6 +303,22 @@ public class AbilityFactoryMana {
|
|||||||
tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa);
|
tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (abMana.isAnyMana()) {
|
||||||
|
for (Player p : tgtPlayers) {
|
||||||
|
if (tgt == null || p.canBeTargetedBy(sa)) {
|
||||||
|
// AI color choice is set in ComputerUtils so only human players need to make a choice
|
||||||
|
if (sa.getActivatingPlayer().isHuman()) {
|
||||||
|
Object o = GuiUtils.getChoice("Choose a color", Constant.Color.ONLY_COLORS);
|
||||||
|
if (null == o) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String choice = (String) o;
|
||||||
|
abMana.setAnyChoice(choice.substring(0, 1).toUpperCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (final Player player : tgtPlayers) {
|
for (final Player player : tgtPlayers) {
|
||||||
abMana.produceMana(AbilityFactoryMana.generatedMana(abMana, af, sa), player);
|
abMana.produceMana(AbilityFactoryMana.generatedMana(abMana, af, sa), player);
|
||||||
}
|
}
|
||||||
@@ -319,7 +361,16 @@ public class AbilityFactoryMana {
|
|||||||
int amount = params.containsKey("Amount") ? AbilityFactory.calculateAmount(af.getHostCard(),
|
int amount = params.containsKey("Amount") ? AbilityFactory.calculateAmount(af.getHostCard(),
|
||||||
params.get("Amount"), sa) : 1;
|
params.get("Amount"), sa) : 1;
|
||||||
|
|
||||||
String baseMana = abMana.mana();
|
String baseMana;
|
||||||
|
if (abMana.isAnyMana()) {
|
||||||
|
baseMana = abMana.getAnyChoice();
|
||||||
|
if (baseMana.isEmpty()) {
|
||||||
|
baseMana = "Any";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
baseMana = abMana.mana();
|
||||||
|
}
|
||||||
|
|
||||||
if (baseMana.equals("Chosen")) {
|
if (baseMana.equals("Chosen")) {
|
||||||
// this will only support 1 chosen color for now.
|
// this will only support 1 chosen color for now.
|
||||||
baseMana = InputPayManaCostUtil.getShortColorString(card.getChosenColor().get(0));
|
baseMana = InputPayManaCostUtil.getShortColorString(card.getChosenColor().get(0));
|
||||||
|
|||||||
@@ -246,4 +246,15 @@ public class Mana {
|
|||||||
public final void decrementAmount() {
|
public final void decrementAmount() {
|
||||||
this.amount--;
|
this.amount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* decrementAmount.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param amountDecrement a int.
|
||||||
|
*/
|
||||||
|
public void decrementAmount(final int amountDecrement) {
|
||||||
|
this.amount -= amountDecrement;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -498,7 +498,7 @@ public class ManaPool {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.removeManaFrom(pool, set);
|
this.removeManaFrom(pool, set, mana.getAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -510,21 +510,23 @@ public class ManaPool {
|
|||||||
* a {@link java.util.ArrayList} object.
|
* a {@link java.util.ArrayList} object.
|
||||||
* @param choice
|
* @param choice
|
||||||
* a {@link forge.card.mana.Mana} object.
|
* a {@link forge.card.mana.Mana} object.
|
||||||
|
* @param amount
|
||||||
|
* an int .
|
||||||
*/
|
*/
|
||||||
public final void removeManaFrom(final ArrayList<Mana> pool, final Mana choice) {
|
public final void removeManaFrom(final ArrayList<Mana> pool, final Mana choice, final int amount) {
|
||||||
if (choice != null) {
|
if (choice != null) {
|
||||||
if (choice.getAmount() == 1) {
|
if (choice.getAmount() == amount) {
|
||||||
pool.remove(choice);
|
pool.remove(choice);
|
||||||
} else {
|
} else {
|
||||||
choice.decrementAmount();
|
choice.decrementAmount(amount);
|
||||||
}
|
}
|
||||||
if (pool.equals(this.floatingMana)) {
|
if (pool.equals(this.floatingMana)) {
|
||||||
int i = ManaPool.MAP.get(choice.getColor());
|
int i = ManaPool.MAP.get(choice.getColor());
|
||||||
if (choice.isSnow()) {
|
if (choice.isSnow()) {
|
||||||
this.floatingSnowTotals[i] -= choice.getAmount();
|
this.floatingSnowTotals[i] -= amount;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.floatingTotals[i] -= choice.getAmount();
|
this.floatingTotals[i] -= amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
owner.updateObservers();
|
owner.updateObservers();
|
||||||
@@ -685,7 +687,7 @@ public class ManaPool {
|
|||||||
* @return a {@link forge.card.mana.ManaCost} object.
|
* @return a {@link forge.card.mana.ManaCost} object.
|
||||||
*/
|
*/
|
||||||
public final ManaCost subtractMana(final SpellAbility sa, ManaCost m, final AbilityMana... mAbilities) {
|
public final ManaCost subtractMana(final SpellAbility sa, ManaCost m, final AbilityMana... mAbilities) {
|
||||||
final ArrayList<AbilityMana> paidAbs = sa.getPayingManaAbilities();
|
final ArrayList<AbilityMana> paidAbs = sa.getPayingManaAbilities(); // why???
|
||||||
|
|
||||||
if (mAbilities.length == 0) {
|
if (mAbilities.length == 0) {
|
||||||
// paying from Mana Pool
|
// paying from Mana Pool
|
||||||
@@ -699,8 +701,17 @@ public class ManaPool {
|
|||||||
|
|
||||||
// paying via Mana Abilities
|
// paying via Mana Abilities
|
||||||
for (final AbilityMana mability : mAbilities) {
|
for (final AbilityMana mability : mAbilities) {
|
||||||
paidAbs.add(mability);
|
paidAbs.add(mability); // why???
|
||||||
final String[] cost = ManaPool.formatMana(mability);
|
//TODO: Look at using new getManaProduced() method of Ability_Mana (ArsenalNut)
|
||||||
|
//String[] cost = formatMana(mability);
|
||||||
|
String[] cost = null;
|
||||||
|
if (mability.isAnyMana()) {
|
||||||
|
cost = new String[1];
|
||||||
|
cost[0] = mability.getAnyChoice();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cost = formatMana(mability);
|
||||||
|
}
|
||||||
m = this.subtractMultiple(sa, cost, m);
|
m = this.subtractMultiple(sa, cost, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,7 +749,7 @@ public class ManaPool {
|
|||||||
for (final Mana m : manaArray) {
|
for (final Mana m : manaArray) {
|
||||||
if (manaCost.isNeeded(m)) {
|
if (manaCost.isNeeded(m)) {
|
||||||
manaCost.payMana(m);
|
manaCost.payMana(m);
|
||||||
payMana.add(m);
|
payMana.add(m); // what is this used for? anything
|
||||||
this.findAndRemoveFrom(this.floatingMana, m);
|
this.findAndRemoveFrom(this.floatingMana, m);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@@ -806,78 +817,81 @@ public class ManaPool {
|
|||||||
// TODO account for unpaying mana in payMana and floatingPool
|
// TODO account for unpaying mana in payMana and floatingPool
|
||||||
final ArrayList<Mana> payMana = sa.getPayingMana();
|
final ArrayList<Mana> payMana = sa.getPayingMana();
|
||||||
|
|
||||||
|
if ((payMana.size() == 0) && (this.floatingMana.size() == 0)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
final ArrayList<Mana> removePaying = new ArrayList<Mana>();
|
final ArrayList<Mana> removePaying = new ArrayList<Mana>();
|
||||||
final ArrayList<Mana> removeFloating = new ArrayList<Mana>();
|
final ArrayList<Mana> removeFloating = new ArrayList<Mana>();
|
||||||
|
|
||||||
int i = 0, j = 0;
|
int manaAccounted = 0;
|
||||||
boolean usePay = payMana.size() > 0;
|
// loop over mana paid
|
||||||
final boolean flag = false;
|
for (Mana manaPaid : payMana) {
|
||||||
|
if (manaPaid.fromSourceCard(c)) {
|
||||||
String manaStr = mana[i];
|
for (int i = 0;i < mana.length;i++ ) {
|
||||||
String color = InputPayManaCostUtil.getLongColorString(manaStr);
|
if (manaPaid.getColor().equals(InputPayManaCostUtil.getLongColorString(mana[i]))) {
|
||||||
|
final int amt = manaPaid.getColorlessAmount();
|
||||||
if (!usePay && (this.floatingMana.size() == 0)) {
|
if (amt > 0) {
|
||||||
|
final int difference = Integer.parseInt(mana[i]) - amt;
|
||||||
|
if (difference > 0) {
|
||||||
|
mana[i] = Integer.toString(difference);
|
||||||
|
} else {
|
||||||
|
manaAccounted += amt;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
manaAccounted += manaPaid.getAmount();
|
||||||
|
}
|
||||||
|
removePaying.add(manaPaid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (manaAccounted == mana.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// loop over mana pool if not all of the generated mana is accounted for
|
||||||
|
if (manaAccounted < mana.length) {
|
||||||
|
for (Mana manaFloat : this.floatingMana) {
|
||||||
|
if (manaFloat.fromSourceCard(c)) {
|
||||||
|
for (int i = 0;i < mana.length;i++ ) {
|
||||||
|
if (manaFloat.getColor().equals(InputPayManaCostUtil.getLongColorString(mana[i]))) {
|
||||||
|
final int amt = manaFloat.getColorlessAmount();
|
||||||
|
if (amt > 0) {
|
||||||
|
final int difference = Integer.parseInt(mana[i]) - amt;
|
||||||
|
if (difference > 0) {
|
||||||
|
mana[i] = Integer.toString(difference);
|
||||||
|
} else {
|
||||||
|
manaAccounted += amt;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
manaAccounted += manaFloat.getAmount();
|
||||||
|
}
|
||||||
|
removeFloating.add(manaFloat);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (manaAccounted == mana.length) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// When is it legitimate for all the mana not to be accountable?
|
||||||
|
// Does this condition really indicate an bug in Forge?
|
||||||
|
if (manaAccounted < mana.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (i < mana.length) {
|
|
||||||
|
|
||||||
final Mana m = usePay ? payMana.get(j) : this.floatingMana.get(j);
|
|
||||||
|
|
||||||
if (m.fromSourceCard(c) && m.getColor().equals(color)) {
|
|
||||||
final int amt = m.getColorlessAmount();
|
|
||||||
if (amt > 0) {
|
|
||||||
final int difference = Integer.parseInt(manaStr) - amt;
|
|
||||||
if (difference > 0) {
|
|
||||||
manaStr = Integer.toString(difference);
|
|
||||||
} else {
|
|
||||||
i += amt;
|
|
||||||
if (i < mana.length) {
|
|
||||||
manaStr = mana[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
i += m.getAmount();
|
|
||||||
if (i < mana.length) {
|
|
||||||
manaStr = mana[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
color = InputPayManaCostUtil.getLongColorString(manaStr);
|
|
||||||
if (usePay) {
|
|
||||||
removePaying.add(m);
|
|
||||||
} else {
|
|
||||||
removeFloating.add(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If mana has been depleted, break from loop. All Accounted
|
|
||||||
// for!
|
|
||||||
if (i == mana.length) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
j++; // increase j until we reach the end of paying, then reset and
|
|
||||||
// use floating.
|
|
||||||
if (usePay) {
|
|
||||||
if (payMana.size() == j) {
|
|
||||||
j = 0;
|
|
||||||
usePay = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!usePay && (this.floatingMana.size() == j) && !flag) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int k = 0; k < removePaying.size(); k++) {
|
for (int k = 0; k < removePaying.size(); k++) {
|
||||||
this.removeManaFrom(payMana, removePaying.get(k));
|
this.removeManaFrom(payMana, removePaying.get(k), removePaying.get(k).getAmount());
|
||||||
}
|
}
|
||||||
for (int k = 0; k < removeFloating.size(); k++) {
|
for (int k = 0; k < removeFloating.size(); k++) {
|
||||||
this.removeManaFrom(this.floatingMana, removeFloating.get(k));
|
this.removeManaFrom(this.floatingMana, removeFloating.get(k), removeFloating.get(k).getAmount());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* unpaid.
|
* unpaid.
|
||||||
@@ -896,7 +910,16 @@ public class ManaPool {
|
|||||||
// go through paidAbilities if they are undoable
|
// go through paidAbilities if they are undoable
|
||||||
for (final AbilityMana am : payAbs) {
|
for (final AbilityMana am : payAbs) {
|
||||||
if (am.isUndoable()) {
|
if (am.isUndoable()) {
|
||||||
final String[] formattedMana = ManaPool.formatMana(am);
|
//final String[] formattedMana = ManaPool.formatMana(am);
|
||||||
|
/*String[] formattedMana = null;
|
||||||
|
if (am.isAnyMana()) {
|
||||||
|
formattedMana = new String[1];
|
||||||
|
formattedMana[0] = am.getAnyChoice();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
formattedMana = formatMana(am);
|
||||||
|
}*/
|
||||||
|
final String[] formattedMana = am.getLastProduced().split(" ");
|
||||||
if (this.accountFor(sa, formattedMana, am.getSourceCard())) {
|
if (this.accountFor(sa, formattedMana, am.getSourceCard())) {
|
||||||
am.undo();
|
am.undo();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
|
|||||||
private static final long serialVersionUID = -6816356991224950520L;
|
private static final long serialVersionUID = -6816356991224950520L;
|
||||||
|
|
||||||
private String origProduced;
|
private String origProduced;
|
||||||
|
private String lastAnyChoice = "";
|
||||||
|
private String lastProduced = "";
|
||||||
private int amount = 1;
|
private int amount = 1;
|
||||||
|
|
||||||
/** The reflected. */
|
/** The reflected. */
|
||||||
@@ -177,6 +179,8 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
|
|||||||
// this.getActivatingPlayer().ManaPool.addManaToFloating(origProduced,
|
// this.getActivatingPlayer().ManaPool.addManaToFloating(origProduced,
|
||||||
// getSourceCard());
|
// getSourceCard());
|
||||||
manaPool.addManaToFloating(produced, source);
|
manaPool.addManaToFloating(produced, source);
|
||||||
|
//store produced to last produced
|
||||||
|
this.lastProduced = produced;
|
||||||
|
|
||||||
// TODO all of the following would be better as trigger events
|
// TODO all of the following would be better as trigger events
|
||||||
// "tapped for mana"
|
// "tapped for mana"
|
||||||
@@ -202,6 +206,35 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
|
|||||||
|
|
||||||
} // end produceMana(String)
|
} // end produceMana(String)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* getProducedMana.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @return a {@link java.lang.String} object.
|
||||||
|
*/
|
||||||
|
public String getManaProduced() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
if (this.amount == 0) {
|
||||||
|
sb.append("0");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
// if baseMana is an integer(colorless), just multiply amount and baseMana
|
||||||
|
int base = Integer.parseInt(this.origProduced);
|
||||||
|
sb.append(base * this.amount);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
for (int i = 0; i < this.amount; i++) {
|
||||||
|
if (i != 0) {
|
||||||
|
sb.append(" ");
|
||||||
|
}
|
||||||
|
sb.append(this.origProduced);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* mana.
|
* mana.
|
||||||
@@ -237,6 +270,39 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
|
|||||||
this.reflected = bReflect;
|
this.reflected = bReflect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* setAnyChoice.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param s a {@link java.lang.String} object.
|
||||||
|
*/
|
||||||
|
public void setAnyChoice(String s) {
|
||||||
|
this.lastAnyChoice = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Getter for the field <code>lastAnyChoice</code>.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @return a {@link java.lang.String} object.
|
||||||
|
*/
|
||||||
|
public String getAnyChoice() {
|
||||||
|
return this.lastAnyChoice;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Getter for the field <code>lastProduced</code>.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @return a {@link java.lang.String} object.
|
||||||
|
*/
|
||||||
|
public String getLastProduced() {
|
||||||
|
return this.lastProduced;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* isSnow.
|
* isSnow.
|
||||||
@@ -270,6 +336,17 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
|
|||||||
return this.reflected;
|
return this.reflected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* isAnyMana.
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @return a boolean.
|
||||||
|
*/
|
||||||
|
public boolean isAnyMana() {
|
||||||
|
return this.origProduced.contains("Any");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* canProduce.
|
* canProduce.
|
||||||
@@ -280,6 +357,7 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
|
|||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
public final boolean canProduce(final String s) {
|
public final boolean canProduce(final String s) {
|
||||||
|
//TODO: look at where this called from and take "Any" into account
|
||||||
return this.origProduced.contains(s);
|
return this.origProduced.contains(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,8 @@ public class InputPayManaCostUtil {
|
|||||||
colorMatches.add(am);
|
colorMatches.add(am);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (am.isAnyMana()) {
|
||||||
|
colorMatches.add(am);
|
||||||
} else {
|
} else {
|
||||||
final String[] m = ManaPool.formatMana(am);
|
final String[] m = ManaPool.formatMana(am);
|
||||||
for (final String color : m) {
|
for (final String color : m) {
|
||||||
@@ -130,7 +132,8 @@ public class InputPayManaCostUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((colorMatches.size() == 0) || (colorMatches.size() == abilities.size())) {
|
// Why is choice made "false" if colorMatches and abilities have same size
|
||||||
|
if ((colorMatches.size() == 0)) {
|
||||||
// can only match colorless just grab the first and move on.
|
// can only match colorless just grab the first and move on.
|
||||||
choice = false;
|
choice = false;
|
||||||
} else if (colorMatches.size() < abilities.size()) {
|
} else if (colorMatches.size() < abilities.size()) {
|
||||||
@@ -211,7 +214,9 @@ public class InputPayManaCostUtil {
|
|||||||
if (mana.contains("S") && am.isSnow()) {
|
if (mana.contains("S") && am.isSnow()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (am.isAnyMana()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (am.isReflectedMana()) {
|
if (am.isReflectedMana()) {
|
||||||
final ArrayList<String> reflectableColors = AbilityFactoryMana.reflectableMana(am, am.getAbilityFactory(),
|
final ArrayList<String> reflectableColors = AbilityFactoryMana.reflectableMana(am, am.getAbilityFactory(),
|
||||||
new ArrayList<String>(), new ArrayList<Card>());
|
new ArrayList<String>(), new ArrayList<Card>());
|
||||||
|
|||||||
Reference in New Issue
Block a user