mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +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
|
||||
manaProduced = m.getManaProduced();
|
||||
|
||||
@@ -299,12 +299,34 @@ public class AbilityFactoryMana {
|
||||
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 colorsNeeded = abMana.getExpressChoice();
|
||||
String choice = "";
|
||||
if (colorsNeeded.length() == 1) {
|
||||
choice = colorsNeeded;
|
||||
}
|
||||
String choice = (String) o;
|
||||
abMana.setAnyChoice(InputPayManaCostUtil.getShortColorString(choice));
|
||||
else {
|
||||
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 {
|
||||
if (params.containsKey("AILogic")) {
|
||||
@@ -315,9 +337,9 @@ public class AbilityFactoryMana {
|
||||
Zone.Hand));
|
||||
}
|
||||
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();
|
||||
sb.append("AbilityFactoryMana::manaResolve() - any color mana choice is empty for ");
|
||||
sb.append(sa.getSourceCard().getName());
|
||||
@@ -372,7 +394,7 @@ public class AbilityFactoryMana {
|
||||
|
||||
String baseMana;
|
||||
if (abMana.isAnyMana()) {
|
||||
baseMana = abMana.getAnyChoice();
|
||||
baseMana = abMana.getExpressChoice();
|
||||
if (baseMana.isEmpty()) {
|
||||
baseMana = "Any";
|
||||
}
|
||||
|
||||
@@ -707,7 +707,7 @@ public class ManaPool {
|
||||
String[] cost = null;
|
||||
if (mability.isAnyMana()) {
|
||||
cost = new String[1];
|
||||
cost[0] = mability.getAnyChoice();
|
||||
cost[0] = mability.getExpressChoice();
|
||||
}
|
||||
else {
|
||||
cost = formatMana(mability);
|
||||
|
||||
@@ -39,7 +39,7 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se
|
||||
private static final long serialVersionUID = -6816356991224950520L;
|
||||
|
||||
private String origProduced;
|
||||
private String lastAnyChoice = "";
|
||||
private String lastExpressChoice = "";
|
||||
private String lastProduced = "";
|
||||
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.
|
||||
*/
|
||||
public void setAnyChoice(String s) {
|
||||
this.lastAnyChoice = s;
|
||||
public void setExpressChoice(String 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.
|
||||
*/
|
||||
public String getAnyChoice() {
|
||||
return this.lastAnyChoice;
|
||||
public String getExpressChoice() {
|
||||
return this.lastExpressChoice;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,12 +66,17 @@ public class InputPayManaCostUtil {
|
||||
|
||||
ArrayList<AbilityMana> abilities = InputPayManaCostUtil.getManaAbilities(card);
|
||||
final StringBuilder cneeded = new StringBuilder();
|
||||
final StringBuilder colorRequired = new StringBuilder();
|
||||
boolean choice = true;
|
||||
boolean skipExpress = false;
|
||||
|
||||
for (final String color : Constant.Color.MANA_COLORS) {
|
||||
String shortColor = InputPayManaCostUtil.getShortColorString(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;
|
||||
}
|
||||
|
||||
// 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,
|
||||
// skip express Mana choice
|
||||
// if (card.getTrackManaPaid()) skipExpress = true;
|
||||
if (sa.getSourceCard().hasKeyword("Sunburst") && sa.isSpell()) {
|
||||
colorsNeeded = "WUBRG";
|
||||
skipExpress = true;
|
||||
}
|
||||
|
||||
if (!skipExpress) {
|
||||
// express Mana Choice
|
||||
@@ -151,10 +183,16 @@ public class InputPayManaCostUtil {
|
||||
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);
|
||||
|
||||
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();
|
||||
// DO NOT REMOVE THIS, otherwise the cards don't always tap (copied)
|
||||
return manaCost;
|
||||
|
||||
Reference in New Issue
Block a user