mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
Fix shard sort order when deciding if a mana cost is payable.
Prior to this change, the logic would conclude that a {1}{W} cost is not payable with an untapped Scoured Barrens (w/b) and Jungle Hollow (b/g) on the field.
The code is unfortunately too tangled (has too many dependencies) to write a unit test for this. Ideally, we should refactor so it wouldn't depend on the player, etc and just take parameters that can be fed test data.
This commit is contained in:
@@ -697,11 +697,7 @@ public class ComputerUtilMana {
|
|||||||
// * pay hybrids
|
// * pay hybrids
|
||||||
// * pay phyrexian, keep mana for colorless
|
// * pay phyrexian, keep mana for colorless
|
||||||
// * pay colorless
|
// * pay colorless
|
||||||
Iterator<ManaCostShard> shards = cost.getDistinctShards().iterator();
|
return cost.getShardToPayByPriority(cost.getDistinctShards(), MagicColor.ALL_COLORS);
|
||||||
if (shards.hasNext()) {
|
|
||||||
return shards.next();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void adjustManaCostToAvoidNegEffects(ManaCostBeingPaid cost, final Card card, Player ai) {
|
private static void adjustManaCostToAvoidNegEffects(ManaCostBeingPaid cost, final Card card, Player ai) {
|
||||||
|
|||||||
@@ -360,7 +360,7 @@ public class ManaCostBeingPaid {
|
|||||||
return tryPayMana(color, Iterables.filter(unpaidShards.keySet(), predCanBePaid), (byte)0xFF);
|
return tryPayMana(color, Iterables.filter(unpaidShards.keySet(), predCanBePaid), (byte)0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ManaCostShard tryPayMana(final byte colorMask, Iterable<ManaCostShard> payableShards, byte possibleUses) {
|
public ManaCostShard getShardToPayByPriority(Iterable<ManaCostShard> payableShards, byte possibleUses) {
|
||||||
Set<ManaCostShard> choice = EnumSet.noneOf(ManaCostShard.class);
|
Set<ManaCostShard> choice = EnumSet.noneOf(ManaCostShard.class);
|
||||||
int priority = Integer.MIN_VALUE;
|
int priority = Integer.MIN_VALUE;
|
||||||
for (ManaCostShard toPay : payableShards) {
|
for (ManaCostShard toPay : payableShards) {
|
||||||
@@ -378,8 +378,14 @@ public class ManaCostBeingPaid {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ManaCostShard chosenShard = Iterables.getFirst(choice, null);
|
return Iterables.getFirst(choice, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ManaCostShard tryPayMana(final byte colorMask, Iterable<ManaCostShard> payableShards, byte possibleUses) {
|
||||||
|
ManaCostShard chosenShard = getShardToPayByPriority(payableShards, possibleUses);
|
||||||
|
if (chosenShard == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
ShardCount sc = unpaidShards.get(chosenShard);
|
ShardCount sc = unpaidShards.get(chosenShard);
|
||||||
if (sc != null && sc.xCount > 0) {
|
if (sc != null && sc.xCount > 0) {
|
||||||
//if there's any X part of the cost for the chosen shard, pay it off first and track what color was spent to pay X
|
//if there's any X part of the cost for the chosen shard, pay it off first and track what color was spent to pay X
|
||||||
|
|||||||
Reference in New Issue
Block a user