mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
- Refactor AI SVar checking for both abilities and replacement effects.
This commit is contained in:
@@ -714,34 +714,7 @@ public class AiController {
|
||||
|
||||
// Check a predefined condition (maybe refactor it later to avoid code duplication with similar replacement effect code?)
|
||||
if (sa.hasParam("AICheckSVar")) {
|
||||
final Card host = sa.getHostCard();
|
||||
final String svarToCheck = sa.getParam("AICheckSVar");
|
||||
String comparator = "GE";
|
||||
int compareTo = 1;
|
||||
|
||||
if (sa.hasParam("AISVarCompare")) {
|
||||
final String fullCmp = sa.getParam("AISVarCompare");
|
||||
comparator = fullCmp.substring(0, 2);
|
||||
final String strCmpTo = fullCmp.substring(2);
|
||||
try {
|
||||
compareTo = Integer.parseInt(strCmpTo);
|
||||
} catch (final Exception ignored) {
|
||||
if (sa == null) {
|
||||
compareTo = AbilityUtils.calculateAmount(host, host.getSVar(strCmpTo), sa);
|
||||
} else {
|
||||
compareTo = AbilityUtils.calculateAmount(host, host.getSVar(strCmpTo), sa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int left = 0;
|
||||
|
||||
if (sa == null) {
|
||||
left = AbilityUtils.calculateAmount(host, svarToCheck, sa);
|
||||
} else {
|
||||
left = AbilityUtils.calculateAmount(host, svarToCheck, sa);
|
||||
}
|
||||
if (!Expressions.compare(left, comparator, compareTo)) {
|
||||
if (!checkAISpecificSVarCondition(sa, sa.getHostCard())) {
|
||||
return AiPlayDecision.AnotherTime;
|
||||
}
|
||||
}
|
||||
@@ -1836,35 +1809,7 @@ public class AiController {
|
||||
}
|
||||
}
|
||||
if (effect.hasParam("AICheckSVar")) {
|
||||
System.out.println("aiShouldRun?" + sa);
|
||||
final String svarToCheck = effect.getParam("AICheckSVar");
|
||||
String comparator = "GE";
|
||||
int compareTo = 1;
|
||||
|
||||
if (effect.hasParam("AISVarCompare")) {
|
||||
final String fullCmp = effect.getParam("AISVarCompare");
|
||||
comparator = fullCmp.substring(0, 2);
|
||||
final String strCmpTo = fullCmp.substring(2);
|
||||
try {
|
||||
compareTo = Integer.parseInt(strCmpTo);
|
||||
} catch (final Exception ignored) {
|
||||
if (sa == null) {
|
||||
compareTo = AbilityUtils.calculateAmount(hostCard, hostCard.getSVar(strCmpTo), effect);
|
||||
} else {
|
||||
compareTo = AbilityUtils.calculateAmount(hostCard, hostCard.getSVar(strCmpTo), sa);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int left = 0;
|
||||
|
||||
if (sa == null) {
|
||||
left = AbilityUtils.calculateAmount(hostCard, svarToCheck, effect);
|
||||
} else {
|
||||
left = AbilityUtils.calculateAmount(hostCard, svarToCheck, sa);
|
||||
}
|
||||
System.out.println("aiShouldRun?" + left + comparator + compareTo);
|
||||
return Expressions.compare(left, comparator, compareTo);
|
||||
return checkAISpecificSVarCondition(effect, hostCard);
|
||||
} else if (effect.hasParam("AICheckDredge")) {
|
||||
return player.getCardsIn(ZoneType.Library).size() > 8 || player.isCardInPlay("Laboratory Maniac");
|
||||
} else return sa != null && doTrigger(sa, false);
|
||||
@@ -2370,4 +2315,37 @@ public class AiController {
|
||||
return Iterables.getFirst(list, null);
|
||||
}
|
||||
|
||||
private static boolean checkAISpecificSVarCondition(CardTraitBase ab, Card host) {
|
||||
if (ab.hasParam("AICheckSVar")) {
|
||||
final String svarToCheck = ab.getParam("AICheckSVar");
|
||||
String comparator = "GE";
|
||||
int compareTo = 1;
|
||||
|
||||
if (ab.hasParam("AISVarCompare")) {
|
||||
final String fullCmp = ab.getParam("AISVarCompare");
|
||||
comparator = fullCmp.substring(0, 2);
|
||||
final String strCmpTo = fullCmp.substring(2);
|
||||
try {
|
||||
compareTo = Integer.parseInt(strCmpTo);
|
||||
} catch (final Exception ignored) {
|
||||
if (ab == null) {
|
||||
compareTo = AbilityUtils.calculateAmount(host, host.getSVar(strCmpTo), ab);
|
||||
} else {
|
||||
compareTo = AbilityUtils.calculateAmount(host, host.getSVar(strCmpTo), ab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int left = 0;
|
||||
|
||||
if (ab == null) {
|
||||
left = AbilityUtils.calculateAmount(host, svarToCheck, ab);
|
||||
} else {
|
||||
left = AbilityUtils.calculateAmount(host, svarToCheck, ab);
|
||||
}
|
||||
return Expressions.compare(left, comparator, compareTo);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user