more paths require manapool

This commit is contained in:
Maxmtg
2014-02-08 11:33:17 +00:00
parent 1ec656f2ed
commit c5a791f361
4 changed files with 22 additions and 26 deletions

View File

@@ -96,7 +96,7 @@ public class ComputerUtilMana {
}
private static boolean payManaCost(final ManaCostBeingPaid cost, final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable, boolean clearManaPaid) {
adjustManaCostToAvoidNegEffects(cost, sa.getSourceCard());
adjustManaCostToAvoidNegEffects(cost, sa.getSourceCard(), ai);
final ManaPool manapool = ai.getManaPool();
List<ManaCostShard> unpaidShards = cost.getUnpaidShards();
@@ -194,7 +194,7 @@ public class ComputerUtilMana {
String manaProduced = toPay.isSnow() ? "S" : GameActionUtil.generatedMana(saPayment);
manaProduced = AbilityManaPart.applyManaReplacement(saPayment, manaProduced);
//System.out.println(manaProduced);
payMultipleMana(cost, manaProduced);
payMultipleMana(cost, manaProduced, ai);
// remove from available lists
for (Collection<SpellAbility> kv : sourcesForShards.values()) {
@@ -346,14 +346,14 @@ public class ComputerUtilMana {
return null;
}
private static void adjustManaCostToAvoidNegEffects(ManaCostBeingPaid cost, final Card card) {
private static void adjustManaCostToAvoidNegEffects(ManaCostBeingPaid cost, final Card card, Player ai) {
// Make mana needed to avoid negative effect a mandatory cost for the AI
for (String manaPart : card.getSVar("ManaNeededToAvoidNegativeEffect").split(",")) {
// convert long color strings to short color strings
byte mask = MagicColor.fromName(manaPart);
// make mana mandatory for AI
if (!cost.needsColor(mask) && cost.getColorlessManaAmount() > 0) {
if (!cost.needsColor(mask, ai.getManaPool()) && cost.getColorlessManaAmount() > 0) {
ManaCostShard shard = ManaCostShard.valueOf(mask);
cost.increaseShard(shard, 1);
cost.decreaseColorlessMana(1);
@@ -390,9 +390,9 @@ public class ComputerUtilMana {
choice = abMana.getExpressChoice();
abMana.clearExpressChoice();
byte colorMask = MagicColor.fromName(choice);
if (abMana.canProduce(choice, manaAb) && testCost.isAnyPartPayableWith(colorMask)) {
if (abMana.canProduce(choice, manaAb) && testCost.isAnyPartPayableWith(colorMask, ai.getManaPool())) {
choiceString.append(choice);
payMultipleMana(testCost, choice);
payMultipleMana(testCost, choice, ai);
continue;
}
}
@@ -400,8 +400,8 @@ public class ComputerUtilMana {
if (!testCost.isPaid()) {
// Loop over combo colors
for (String color : comboColors) {
if (testCost.isAnyPartPayableWith(MagicColor.fromName(color))) {
payMultipleMana(testCost, color);
if (testCost.isAnyPartPayableWith(MagicColor.fromName(color), ai.getManaPool())) {
payMultipleMana(testCost, color, ai);
if (nMana != 1) {
choiceString.append(" ");
}
@@ -447,12 +447,12 @@ public class ComputerUtilMana {
* a {@link java.lang.String} object.
* @return a boolean.
*/
private final static String payMultipleMana(ManaCostBeingPaid testCost, String mana) {
private final static String payMultipleMana(ManaCostBeingPaid testCost, String mana, final Player p) {
List<String> unused = new ArrayList<String>(4);
for (String manaPart : TextUtil.split(mana, ' ')) {
if (StringUtils.isNumeric(manaPart)) {
for (int i = Integer.parseInt(manaPart); i > 0; i--) {
boolean wasNeeded = testCost.ai_payMana("1");
boolean wasNeeded = testCost.ai_payMana("1", p.getManaPool());
if (!wasNeeded) {
unused.add(Integer.toString(i));
break;
@@ -461,7 +461,7 @@ public class ComputerUtilMana {
}
else {
String color = MagicColor.toShortString(manaPart);
boolean wasNeeded = testCost.ai_payMana(color);
boolean wasNeeded = testCost.ai_payMana(color, p.getManaPool());
if (!wasNeeded) {
unused.add(color);
}

View File

@@ -187,7 +187,7 @@ public class ManaCostBeingPaid {
// takes a Short Color and returns true if it exists in the mana cost.
// Easier for split costs
public final boolean needsColor(final byte colorMask) {
public final boolean needsColor(final byte colorMask, final ManaPool pool) {
for (ManaCostShard shard : unpaidShards.keySet()) {
if (shard == ManaCostShard.COLORLESS) {
continue;
@@ -197,7 +197,7 @@ public class ManaCostBeingPaid {
return true;
}
}
else if (shardCanBePaidWithColor(shard, colorMask)) {
else if (pool.canPayForShardWithColor(shard, colorMask)) {
return true;
}
}
@@ -205,9 +205,9 @@ public class ManaCostBeingPaid {
}
// isNeeded(String) still used by the Computer, might have problems activating Snow abilities
public final boolean isAnyPartPayableWith(byte colorMask) {
public final boolean isAnyPartPayableWith(byte colorMask, final ManaPool pool) {
for (ManaCostShard shard : unpaidShards.keySet()) {
if (shardCanBePaidWithColor(shard, colorMask)) {
if (pool.canPayForShardWithColor(shard, colorMask)) {
return true;
}
}
@@ -264,9 +264,9 @@ public class ManaCostBeingPaid {
* a {@link java.lang.String} object.
* @return a boolean.
*/
public final boolean ai_payMana(final String mana) {
public final boolean ai_payMana(final String mana, final ManaPool pool) {
final byte colorMask = MagicColor.fromName(mana);
if (!this.isAnyPartPayableWith(colorMask)) {
if (!this.isAnyPartPayableWith(colorMask, pool)) {
//System.out.println("ManaCost : addMana() error, mana not needed - " + mana);
return false;
//throw new RuntimeException("ManaCost : addMana() error, mana not needed - " + mana);
@@ -275,7 +275,7 @@ public class ManaCostBeingPaid {
Predicate<ManaCostShard> predCanBePaid = new Predicate<ManaCostShard>() {
@Override
public boolean apply(ManaCostShard ms) {
return shardCanBePaidWithColor(ms, colorMask);
return pool.canPayForShardWithColor(ms, colorMask);
}
};
@@ -361,10 +361,6 @@ public class ManaCostBeingPaid {
return pool.canPayForShardWithColor(shard, color);
}
private boolean shardCanBePaidWithColor(ManaCostShard shard, byte manaColor) {
// add color changing matrix here to support Daxos of Melethis
return shard.canBePaidWithManaOfColor(manaColor);
}
public final void combineManaCost(final ManaCost extra) {
for (ManaCostShard shard : extra) {