Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logic for Henzie #6402

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions forge-core/src/main/java/forge/card/mana/ManaCost.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class ManaCost implements Comparable<ManaCost>, Iterable<ManaCostSh

private List<ManaCostShard> shards;
private final int genericCost;
private boolean hasNoCost = true; // lands cost
private final boolean hasNoCost; // lands cost
private String stringValue; // precalculated for toString;

private Float compareWeight = null;
Expand Down Expand Up @@ -93,14 +93,14 @@ private void sealClass(List<ManaCostShard> shards0) {
public ManaCost(final IParserManaCost parser) {
final List<ManaCostShard> shardsTemp = Lists.newArrayList();
while (parser.hasNext()) {
this.hasNoCost = false;
final ManaCostShard shard = parser.next();
if (shard != null && shard != ManaCostShard.GENERIC) {
shardsTemp.add(shard);
} // null is OK - that was generic mana
}
this.genericCost = parser.getTotalGenericCost(); // collect generic mana
// here
int generic = parser.getTotalGenericCost(); // collect generic mana here
this.hasNoCost = generic == -1;
this.genericCost = generic == -1 ? 0 : generic;
sealClass(shardsTemp);
}

Expand Down
10 changes: 6 additions & 4 deletions forge-core/src/main/java/forge/card/mana/ManaCostParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package forge.card.mana;

import org.apache.commons.lang3.StringUtils;
import com.google.common.primitives.Ints;


/**
Expand Down Expand Up @@ -54,7 +54,7 @@ public final int getTotalGenericCost() {
*/
@Override
public final boolean hasNext() {
return this.nextToken < this.cost.length && !this.cost[this.nextToken].equals("-1");
return this.nextToken < this.cost.length;
}

/*
Expand All @@ -65,8 +65,10 @@ public final boolean hasNext() {
@Override
public final ManaCostShard next() {
final String unparsed = this.cost[this.nextToken++];
if (StringUtils.isNumeric(unparsed)) {
this.genericCost += Integer.parseInt(unparsed);
// consider negation sign
Integer i = Ints.tryParse(unparsed);
if (i != null) {
this.genericCost += i;
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public boolean hasNext() {
@Override
public int getTotalGenericCost() {
ShardCount c = unpaidShards.get(ManaCostShard.GENERIC);
return c == null ? 0 : c.totalCount;
if (c == null) {
return unpaidShards.isEmpty() ? -1 : 0;
}
return c.totalCount;
}
}

Expand Down
Loading