routed all checks like 'can pay for this shard with mana of certain color' through either player's manapool, or a method in ManaCostBeingPaid. Will add a color conversion matrix at these 2 points later. This change is a prerequisite to implement cards like Daxos of Meletis

This commit is contained in:
Maxmtg
2014-02-06 04:55:30 +00:00
parent 7c419d875d
commit 2f5799f453
5 changed files with 146 additions and 136 deletions

View File

@@ -38,6 +38,7 @@ import forge.game.spellability.AbilitySub;
import forge.game.spellability.SpellAbility;
import forge.game.zone.ZoneType;
import forge.util.CollectionSuppliers;
import forge.util.TextUtil;
import forge.util.maps.EnumMapOfLists;
import forge.util.maps.MapOfLists;
@@ -144,7 +145,6 @@ public class ComputerUtilMana {
List<String> paymentPlan = new ArrayList<String>();
String originalCost = cost.toString(false);
ManaCostShard toPay = null;
// Loop over mana needed
while (!cost.isPaid()) {
@@ -194,7 +194,7 @@ public class ComputerUtilMana {
String manaProduced = toPay.isSnow() ? "S" : GameActionUtil.generatedMana(saPayment);
manaProduced = AbilityManaPart.applyManaReplacement(saPayment, manaProduced);
//System.out.println(manaProduced);
cost.payMultipleMana(manaProduced);
payMultipleMana(cost, manaProduced);
// remove from available lists
for (Collection<SpellAbility> kv : sourcesForShards.values()) {
@@ -267,7 +267,7 @@ public class ComputerUtilMana {
Set<String> reflected = CardUtil.getReflectableManaColors(saPayment);
for (byte c : MagicColor.WUBRG) {
if (toPay.canBePaidWithManaOfColor(c) && reflected.contains(MagicColor.toLongString(c))) {
if (ai.getManaPool().canPayForShardWithColor(toPay, c) && reflected.contains(MagicColor.toLongString(c))) {
m.setExpressChoice(MagicColor.toShortString(c));
return;
}
@@ -278,7 +278,7 @@ public class ComputerUtilMana {
colorChoice = toPay.getColorMask();
else {
for (byte c : MagicColor.WUBRG) {
if (toPay.canBePaidWithManaOfColor(c)) {
if (ai.getManaPool().canPayForShardWithColor(toPay, c)) {
colorChoice = c;
break;
}
@@ -312,7 +312,7 @@ public class ComputerUtilMana {
if (m.isComboMana()) {
for (String s : m.getComboColors().split(" ")) {
if ("Any".equals(s) || toPay.canBePaidWithManaOfColor(MagicColor.fromName(s)))
if ("Any".equals(s) || ai.getManaPool().canPayForShardWithColor(toPay, MagicColor.fromName(s)))
return true;
}
return false;
@@ -321,7 +321,7 @@ public class ComputerUtilMana {
Set<String> reflected = CardUtil.getReflectableManaColors(ma);
for (byte c : MagicColor.WUBRG) {
if (toPay.canBePaidWithManaOfColor(c) && reflected.contains(MagicColor.toLongString(c))) {
if (ai.getManaPool().canPayForShardWithColor(toPay, c) && reflected.contains(MagicColor.toLongString(c))) {
m.setExpressChoice(MagicColor.toShortString(c));
return true;
}
@@ -392,7 +392,7 @@ public class ComputerUtilMana {
byte colorMask = MagicColor.fromName(choice);
if (abMana.canProduce(choice, manaAb) && testCost.isAnyPartPayableWith(colorMask)) {
choiceString.append(choice);
testCost.payMultipleMana(choice);
payMultipleMana(testCost, choice);
continue;
}
}
@@ -401,7 +401,7 @@ public class ComputerUtilMana {
// Loop over combo colors
for (String color : comboColors) {
if (testCost.isAnyPartPayableWith(MagicColor.fromName(color))) {
testCost.payMultipleMana(color);
payMultipleMana(testCost, color);
if (nMana != 1) {
choiceString.append(" ");
}
@@ -437,6 +437,39 @@ public class ComputerUtilMana {
abMana.setExpressChoice(choiceString.toString());
}
/**
* <p>
* payMultipleMana.
* </p>
* @param testCost
*
* @param mana
* a {@link java.lang.String} object.
* @return a boolean.
*/
private final static String payMultipleMana(ManaCostBeingPaid testCost, String mana) {
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");
if (!wasNeeded) {
unused.add(Integer.toString(i));
break;
}
}
}
else {
String color = MagicColor.toShortString(manaPart);
boolean wasNeeded = testCost.ai_payMana(color);
if (!wasNeeded) {
unused.add(color);
}
}
}
return unused.isEmpty() ? null : StringUtils.join(unused, ' ');
}
/**
* Find all mana sources.
* @param manaAbilityMap
@@ -467,7 +500,8 @@ public class ComputerUtilMana {
}
for (Entry<Integer, SpellAbility> kv : manaAbilityMap.entries()) {
if (shard.canBePaidWithManaOfColor(kv.getKey().byteValue())) {
// apply mana color change matrix here
if (ai.getManaPool().canPayForShardWithColor(shard, kv.getKey().byteValue())) {
res.add(shard, kv.getValue());
}
}

View File

@@ -1100,7 +1100,7 @@ public class CardFactoryUtil {
byte colorCode = MagicColor.fromName(colorAbb);
for(Card c0 : cards) {
for(ManaCostShard sh : c0.getManaCost()){
if (sh.canBePaidWithManaOfColor(colorCode))
if ((sh.getColorMask() & colorCode) != 0)
colorOcurrencices++;
}
}
@@ -1112,7 +1112,7 @@ public class CardFactoryUtil {
byte color2 = MagicColor.fromName(sq[2]);
for(Card c0 : cc.getCardsIn(ZoneType.Battlefield)) {
for (ManaCostShard sh : c0.getManaCost()) {
if (sh.canBePaidWithManaOfColor(color1) || sh.canBePaidWithManaOfColor(color2)) {
if ((sh.getColorMask() & (color1 | color2)) != 0) {
colorOcurrencices++;
}
}

View File

@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@@ -42,7 +41,6 @@ import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import forge.game.staticability.StaticAbility;
import forge.game.zone.ZoneType;
import forge.util.TextUtil;
import forge.util.maps.EnumMapToAmount;
import forge.util.maps.MapToAmount;
@@ -215,7 +213,7 @@ public class ManaCostBeingPaid {
return true;
}
}
else if (shard.canBePaidWithManaOfColor(colorMask)) {
else if (shardCanBePaidWithColor(shard, colorMask)) {
return true;
}
}
@@ -225,7 +223,7 @@ public class ManaCostBeingPaid {
// isNeeded(String) still used by the Computer, might have problems activating Snow abilities
public final boolean isAnyPartPayableWith(byte colorMask) {
for (ManaCostShard shard : unpaidShards.keySet()) {
if (shard.canBePaidWithManaOfColor(colorMask)) {
if (shardCanBePaidWithColor(shard, colorMask)) {
return true;
}
}
@@ -245,38 +243,6 @@ public class ManaCostBeingPaid {
return unpaidShards.isEmpty();
}
/**
* <p>
* payMultipleMana.
* </p>
*
* @param mana
* a {@link java.lang.String} object.
* @return a boolean.
*/
public final String payMultipleMana(String mana) {
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 = this.payMana("1");
if (!wasNeeded) {
unused.add(Integer.toString(i));
break;
}
}
}
else {
String color = MagicColor.toShortString(manaPart);
boolean wasNeeded = this.payMana(color);
if (!wasNeeded) {
unused.add(color);
}
}
}
return unused.isEmpty() ? null : StringUtils.join(unused, ' ');
}
public final void increaseColorlessMana(final int manaToAdd) {
increaseShard(ManaCostShard.COLORLESS, manaToAdd);
}
@@ -314,7 +280,7 @@ public class ManaCostBeingPaid {
* a {@link java.lang.String} object.
* @return a boolean.
*/
public final boolean payMana(final String mana) {
public final boolean ai_payMana(final String mana) {
final byte colorMask = MagicColor.fromName(mana);
if (!this.isAnyPartPayableWith(colorMask)) {
//System.out.println("ManaCost : addMana() error, mana not needed - " + mana);
@@ -325,7 +291,7 @@ public class ManaCostBeingPaid {
Predicate<ManaCostShard> predCanBePaid = new Predicate<ManaCostShard>() {
@Override
public boolean apply(ManaCostShard ms) {
return ms.canBePaidWithManaOfColor(colorMask);
return shardCanBePaidWithColor(ms, colorMask);
}
};
@@ -408,9 +374,14 @@ public class ManaCostBeingPaid {
}
byte color = mana.getColorCode();
return shard.canBePaidWithManaOfColor(color);
return shardCanBePaidWithColor(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) {
if (shard == ManaCostShard.X) {

View File

@@ -198,7 +198,7 @@ public class ManaPool {
private List<Pair<Mana, Integer>> selectManaToPayFor(final ManaCostShard shard, final SpellAbility saBeingPaidFor, String restriction) {
final List<Pair<Mana, Integer>> weightedOptions = new ArrayList<Pair<Mana, Integer>>();
for (final Byte manaKey : this.floatingMana.keySet()) {
if (!shard.canBePaidWithManaOfColor(manaKey.byteValue())) {
if (!canPayForShardWithColor(shard, manaKey.byteValue())) {
continue;
}
@@ -207,7 +207,7 @@ public class ManaPool {
continue;
}
boolean canPay = shard.canBePaidWithManaOfColor(thisMana.getColorCode());
boolean canPay = canPayForShardWithColor(shard, thisMana.getColorCode());
if (!canPay || (shard.isSnow() && !thisMana.isSnow())) {
continue;
}
@@ -415,4 +415,9 @@ public class ManaPool {
Player p = sa.getActivatingPlayer();
p.getGame().fireEvent(new GameEventZone(ZoneType.Battlefield, p, EventValueChangeType.ComplexUpdate, null));
}
public boolean canPayForShardWithColor(ManaCostShard shard, byte color) {
// add color changing manipulations here
return shard.canBePaidWithManaOfColor(color);
}
}