mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
- Implement a mechanism for encoding two CMC values for split card faces that allows Count$TopOfLibraryCMC to correctly process split cards and test against both faces individually (fixes e.g. revealing a split card to Counterbalance).
- There's probably a much better solution to this, feel free to change/improve.
This commit is contained in:
@@ -238,6 +238,8 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
RightSplitCMC
|
||||
}
|
||||
|
||||
public static int SPLIT_CMC_ENCODE_MAGIC_NUMBER = 10000000;
|
||||
|
||||
/**
|
||||
* Instantiates a new card not associated to any paper card.
|
||||
* @param id0 the unique id of the new card.
|
||||
@@ -4844,6 +4846,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
} else if (property.startsWith("power") || property.startsWith("toughness")
|
||||
|| property.startsWith("cmc") || property.startsWith("totalPT")) {
|
||||
int x;
|
||||
int x2 = -1; // used for the special case when counting TopOfLibraryCMC for a split card and then testing against it
|
||||
int y = 0;
|
||||
int y2 = -1; // alternative value for the second split face of a split card
|
||||
String rhs = "";
|
||||
@@ -4870,15 +4873,26 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
x = Integer.parseInt(rhs);
|
||||
} catch (final NumberFormatException e) {
|
||||
x = CardFactoryUtil.xCount(source, source.getSVar(rhs));
|
||||
|
||||
// TODO: find a better solution for handling Count$TopOfLibraryCMC for split cards
|
||||
// (currently two CMCs are encoded in one big integer value)
|
||||
if (property.startsWith("cmc") && x > SPLIT_CMC_ENCODE_MAGIC_NUMBER) {
|
||||
x2 = Math.round(x / SPLIT_CMC_ENCODE_MAGIC_NUMBER);
|
||||
x -= x2 * SPLIT_CMC_ENCODE_MAGIC_NUMBER;
|
||||
}
|
||||
}
|
||||
|
||||
if (y2 == -1) {
|
||||
if (!Expressions.compare(y, property, x)) {
|
||||
return false;
|
||||
if (x2 == -1 || !Expressions.compare(y, property, x2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!Expressions.compare(y, property, x) && !Expressions.compare(y2, property, x)) {
|
||||
return false;
|
||||
if (x2 == -1 || (!Expressions.compare(y, property, x2) && !Expressions.compare(y2, property, x2))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ import forge.game.GameLogEntryType;
|
||||
import forge.game.ability.AbilityFactory;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.ApiType;
|
||||
import forge.game.card.Card.SplitCMCMode;
|
||||
import forge.game.card.CardPredicates.Presets;
|
||||
import forge.game.cost.Cost;
|
||||
import forge.game.cost.CostPayment;
|
||||
@@ -1205,7 +1206,21 @@ public class CardFactoryUtil {
|
||||
// Count$TopOfLibraryCMC
|
||||
if (sq[0].contains("TopOfLibraryCMC")) {
|
||||
final Card topCard = cc.getCardsIn(ZoneType.Library).getFirst();
|
||||
return doXMath(topCard == null ? 0 : topCard.getCMC(), m, c);
|
||||
|
||||
if (topCard == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (topCard.isSplitCard()) {
|
||||
// encode two CMC values so they can be processed individually
|
||||
// TODO: devise a better mechanism for this?
|
||||
int cmcLeft = doXMath(topCard.getCMC(SplitCMCMode.LeftSplitCMC), m, c);
|
||||
int cmcRight = doXMath(topCard.getCMC(SplitCMCMode.RightSplitCMC), m, c);
|
||||
int dualCMC = cmcLeft + Card.SPLIT_CMC_ENCODE_MAGIC_NUMBER * cmcRight;
|
||||
return dualCMC;
|
||||
}
|
||||
|
||||
return doXMath(topCard.getCMC(), m, c);
|
||||
}
|
||||
|
||||
// Count$EnchantedControllerCreatures
|
||||
|
||||
Reference in New Issue
Block a user