mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Refactored anyChoice to expressChoice. Added logic to make automatic color choices for "Any" keyword mana sources.
This commit is contained in:
@@ -835,7 +835,7 @@ public class ComputerUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.setAnyChoice(colorChoice);
|
m.setExpressChoice(colorChoice);
|
||||||
}
|
}
|
||||||
// get produced mana
|
// get produced mana
|
||||||
manaProduced = m.getManaProduced();
|
manaProduced = m.getManaProduced();
|
||||||
|
|||||||
@@ -299,12 +299,34 @@ public class AbilityFactoryMana {
|
|||||||
if (tgt == null || p.canBeTargetedBy(sa)) {
|
if (tgt == null || p.canBeTargetedBy(sa)) {
|
||||||
// AI color choice is set in ComputerUtils so only human players need to make a choice
|
// AI color choice is set in ComputerUtils so only human players need to make a choice
|
||||||
if (sa.getActivatingPlayer().isHuman()) {
|
if (sa.getActivatingPlayer().isHuman()) {
|
||||||
Object o = GuiUtils.getChoice("Choose a color", Constant.Color.ONLY_COLORS);
|
String colorsNeeded = abMana.getExpressChoice();
|
||||||
if (null == o) {
|
String choice = "";
|
||||||
return;
|
if (colorsNeeded.length() == 1) {
|
||||||
|
choice = colorsNeeded;
|
||||||
}
|
}
|
||||||
String choice = (String) o;
|
else {
|
||||||
abMana.setAnyChoice(InputPayManaCostUtil.getShortColorString(choice));
|
String[] colorMenu = null;
|
||||||
|
if (colorsNeeded.length() > 1 && colorsNeeded.length() < 5) {
|
||||||
|
colorMenu = new String[colorsNeeded.length()];
|
||||||
|
//loop through colors to make menu
|
||||||
|
for (int nChar = 0; nChar < colorsNeeded.length(); nChar++) {
|
||||||
|
colorMenu[nChar] = InputPayManaCostUtil.getLongColorString(colorsNeeded.substring(nChar, nChar + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
colorMenu = Constant.Color.ONLY_COLORS;
|
||||||
|
}
|
||||||
|
Object o = GuiUtils.getChoice("Select Mana to Produce", colorMenu);
|
||||||
|
if (o == null) {
|
||||||
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("AbilityFactoryMana::manaResolve() - Human color mana choice is empty for ");
|
||||||
|
sb.append(sa.getSourceCard().getName());
|
||||||
|
throw new RuntimeException(sb.toString());
|
||||||
|
} else {
|
||||||
|
choice = InputPayManaCostUtil.getShortColorString((String) o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
abMana.setExpressChoice(choice);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (params.containsKey("AILogic")) {
|
if (params.containsKey("AILogic")) {
|
||||||
@@ -315,9 +337,9 @@ public class AbilityFactoryMana {
|
|||||||
Zone.Hand));
|
Zone.Hand));
|
||||||
}
|
}
|
||||||
GuiUtils.getChoice("Computer picked: ", chosen);
|
GuiUtils.getChoice("Computer picked: ", chosen);
|
||||||
abMana.setAnyChoice(InputPayManaCostUtil.getShortColorString(chosen));
|
abMana.setExpressChoice(InputPayManaCostUtil.getShortColorString(chosen));
|
||||||
}
|
}
|
||||||
if (abMana.getAnyChoice().isEmpty()) {
|
if (abMana.getExpressChoice().isEmpty()) {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
sb.append("AbilityFactoryMana::manaResolve() - any color mana choice is empty for ");
|
sb.append("AbilityFactoryMana::manaResolve() - any color mana choice is empty for ");
|
||||||
sb.append(sa.getSourceCard().getName());
|
sb.append(sa.getSourceCard().getName());
|
||||||
@@ -372,7 +394,7 @@ public class AbilityFactoryMana {
|
|||||||
|
|
||||||
String baseMana;
|
String baseMana;
|
||||||
if (abMana.isAnyMana()) {
|
if (abMana.isAnyMana()) {
|
||||||
baseMana = abMana.getAnyChoice();
|
baseMana = abMana.getExpressChoice();
|
||||||
if (baseMana.isEmpty()) {
|
if (baseMana.isEmpty()) {
|
||||||
baseMana = "Any";
|
baseMana = "Any";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -707,7 +707,7 @@ public class ManaPool {
|
|||||||
String[] cost = null;
|
String[] cost = null;
|
||||||
if (mability.isAnyMana()) {
|
if (mability.isAnyMana()) {
|
||||||
cost = new String[1];
|
cost = new String[1];
|
||||||
cost[0] = mability.getAnyChoice();
|
cost[0] = mability.getExpressChoice();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cost = formatMana(mability);
|
cost = formatMana(mability);
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ 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 lastExpressChoice = "";
|
||||||
private String lastProduced = "";
|
private String lastProduced = "";
|
||||||
private int amount = 1;
|
private int amount = 1;
|
||||||
|
|
||||||
@@ -277,8 +277,8 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
|
|||||||
*
|
*
|
||||||
* @param s a {@link java.lang.String} object.
|
* @param s a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public void setAnyChoice(String s) {
|
public void setExpressChoice(String s) {
|
||||||
this.lastAnyChoice = s;
|
this.lastExpressChoice = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -288,8 +288,8 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
|
|||||||
*
|
*
|
||||||
* @return a {@link java.lang.String} object.
|
* @return a {@link java.lang.String} object.
|
||||||
*/
|
*/
|
||||||
public String getAnyChoice() {
|
public String getExpressChoice() {
|
||||||
return this.lastAnyChoice;
|
return this.lastExpressChoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -66,12 +66,17 @@ public class InputPayManaCostUtil {
|
|||||||
|
|
||||||
ArrayList<AbilityMana> abilities = InputPayManaCostUtil.getManaAbilities(card);
|
ArrayList<AbilityMana> abilities = InputPayManaCostUtil.getManaAbilities(card);
|
||||||
final StringBuilder cneeded = new StringBuilder();
|
final StringBuilder cneeded = new StringBuilder();
|
||||||
|
final StringBuilder colorRequired = new StringBuilder();
|
||||||
boolean choice = true;
|
boolean choice = true;
|
||||||
boolean skipExpress = false;
|
boolean skipExpress = false;
|
||||||
|
|
||||||
for (final String color : Constant.Color.MANA_COLORS) {
|
for (final String color : Constant.Color.MANA_COLORS) {
|
||||||
|
String shortColor = InputPayManaCostUtil.getShortColorString(color);
|
||||||
if (manaCost.isNeeded(color)) {
|
if (manaCost.isNeeded(color)) {
|
||||||
cneeded.append(InputPayManaCostUtil.getShortColorString(color));
|
cneeded.append(shortColor);
|
||||||
|
}
|
||||||
|
if (manaCost.isColor(shortColor)) {
|
||||||
|
colorRequired.append(shortColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,10 +105,37 @@ public class InputPayManaCostUtil {
|
|||||||
return manaCost;
|
return manaCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO when implementing sunburst
|
// Store some information about color costs to help with any mana choices
|
||||||
|
String colorsNeeded = colorRequired.toString();
|
||||||
|
if ("1".equals(colorsNeeded)) { // only colorless left
|
||||||
|
if (sa.getSourceCard().getSVar("ManaNeededToAvoidNegativeEffect") != "") {
|
||||||
|
colorsNeeded = "";
|
||||||
|
String[] negEffects = sa.getSourceCard().getSVar("ManaNeededToAvoidNegativeEffect").split(",");
|
||||||
|
for (String negColor : negEffects) {
|
||||||
|
// convert long color strings to short color strings
|
||||||
|
if (negColor.length() > 1) {
|
||||||
|
negColor = InputPayManaCostUtil.getShortColorString(negColor);
|
||||||
|
}
|
||||||
|
if (!colorsNeeded.contains(negColor)) {
|
||||||
|
colorsNeeded = colorsNeeded.concat(negColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
colorsNeeded = "W";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// remove colorless from colors needed
|
||||||
|
colorsNeeded = colorsNeeded.replace("1", "");
|
||||||
|
}
|
||||||
|
|
||||||
// If the card has sunburst or any other ability that tracks mana spent,
|
// If the card has sunburst or any other ability that tracks mana spent,
|
||||||
// skip express Mana choice
|
// skip express Mana choice
|
||||||
// if (card.getTrackManaPaid()) skipExpress = true;
|
if (sa.getSourceCard().hasKeyword("Sunburst") && sa.isSpell()) {
|
||||||
|
colorsNeeded = "WUBRG";
|
||||||
|
skipExpress = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (!skipExpress) {
|
if (!skipExpress) {
|
||||||
// express Mana Choice
|
// express Mana Choice
|
||||||
@@ -151,10 +183,16 @@ public class InputPayManaCostUtil {
|
|||||||
chosen = (AbilityMana) GuiUtils.getChoice("Choose mana ability", abilities.toArray());
|
chosen = (AbilityMana) GuiUtils.getChoice("Choose mana ability", abilities.toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save off color needed for use by any mana and reflected mana
|
||||||
|
chosen.setExpressChoice(colorsNeeded);
|
||||||
|
|
||||||
AllZone.getGameAction().playSpellAbility(chosen);
|
AllZone.getGameAction().playSpellAbility(chosen);
|
||||||
|
|
||||||
manaCost = AllZone.getHumanPlayer().getManaPool().subtractMana(sa, manaCost, chosen);
|
manaCost = AllZone.getHumanPlayer().getManaPool().subtractMana(sa, manaCost, chosen);
|
||||||
|
|
||||||
|
// reset choice to blank, make sure this done after subtractMana
|
||||||
|
chosen.setExpressChoice("");
|
||||||
|
|
||||||
AllZone.getHumanPlayer().getZone(Zone.Battlefield).updateObservers();
|
AllZone.getHumanPlayer().getZone(Zone.Battlefield).updateObservers();
|
||||||
// DO NOT REMOVE THIS, otherwise the cards don't always tap (copied)
|
// DO NOT REMOVE THIS, otherwise the cards don't always tap (copied)
|
||||||
return manaCost;
|
return manaCost;
|
||||||
|
|||||||
Reference in New Issue
Block a user