mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
- Fixed the AI trying to e.g. Embalm a Vizier of Many Faces ignoring the NeedsToPlay SVar requirement.
This commit is contained in:
@@ -678,41 +678,9 @@ public class AiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private AiPlayDecision canPlaySpellBasic(final Card card, final SpellAbility sa) {
|
private AiPlayDecision canPlaySpellBasic(final Card card, final SpellAbility sa) {
|
||||||
boolean isRightSplit = sa != null && sa.isRightSplit();
|
// add any other necessary logic to play a basic spell here
|
||||||
String needsToPlayName = isRightSplit ? "SplitNeedsToPlay" : "NeedsToPlay";
|
|
||||||
String needsToPlayVarName = isRightSplit ? "SplitNeedsToPlayVar": "NeedsToPlayVar";
|
|
||||||
|
|
||||||
if (card.hasSVar(needsToPlayName)) {
|
return ComputerUtilCard.checkNeedsToPlayReqs(card, sa);
|
||||||
final String needsToPlay = card.getSVar(needsToPlayName);
|
|
||||||
CardCollectionView list = game.getCardsIn(ZoneType.Battlefield);
|
|
||||||
|
|
||||||
list = CardLists.getValidCards(list, needsToPlay.split(","), card.getController(), card, null);
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
return AiPlayDecision.MissingNeededCards;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (card.getSVar(needsToPlayVarName).length() > 0) {
|
|
||||||
final String needsToPlay = card.getSVar(needsToPlayVarName);
|
|
||||||
int x = 0;
|
|
||||||
int y = 0;
|
|
||||||
String sVar = needsToPlay.split(" ")[0];
|
|
||||||
String comparator = needsToPlay.split(" ")[1];
|
|
||||||
String compareTo = comparator.substring(2);
|
|
||||||
try {
|
|
||||||
x = Integer.parseInt(sVar);
|
|
||||||
} catch (final NumberFormatException e) {
|
|
||||||
x = CardFactoryUtil.xCount(card, card.getSVar(sVar));
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
y = Integer.parseInt(compareTo);
|
|
||||||
} catch (final NumberFormatException e) {
|
|
||||||
y = CardFactoryUtil.xCount(card, card.getSVar(compareTo));
|
|
||||||
}
|
|
||||||
if (!Expressions.compare(x, comparator, y)) {
|
|
||||||
return AiPlayDecision.NeedsToPlayCriteriaNotMet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return AiPlayDecision.WillPlay;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// not sure "playing biggest spell" matters?
|
// not sure "playing biggest spell" matters?
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import forge.game.zone.MagicStack;
|
|||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
|
import forge.util.Expressions;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.tuple.MutablePair;
|
import org.apache.commons.lang3.tuple.MutablePair;
|
||||||
@@ -1785,4 +1786,44 @@ public class ComputerUtilCard {
|
|||||||
|
|
||||||
return oppCards;
|
return oppCards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AiPlayDecision checkNeedsToPlayReqs(final Card card, final SpellAbility sa) {
|
||||||
|
Game game = card.getGame();
|
||||||
|
boolean isRightSplit = sa != null && sa.isRightSplit();
|
||||||
|
String needsToPlayName = isRightSplit ? "SplitNeedsToPlay" : "NeedsToPlay";
|
||||||
|
String needsToPlayVarName = isRightSplit ? "SplitNeedsToPlayVar" : "NeedsToPlayVar";
|
||||||
|
|
||||||
|
if (card.hasSVar(needsToPlayName)) {
|
||||||
|
final String needsToPlay = card.getSVar(needsToPlayName);
|
||||||
|
CardCollectionView list = game.getCardsIn(ZoneType.Battlefield);
|
||||||
|
|
||||||
|
list = CardLists.getValidCards(list, needsToPlay.split(","), card.getController(), card, null);
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
return AiPlayDecision.MissingNeededCards;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (card.getSVar(needsToPlayVarName).length() > 0) {
|
||||||
|
final String needsToPlay = card.getSVar(needsToPlayVarName);
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
String sVar = needsToPlay.split(" ")[0];
|
||||||
|
String comparator = needsToPlay.split(" ")[1];
|
||||||
|
String compareTo = comparator.substring(2);
|
||||||
|
try {
|
||||||
|
x = Integer.parseInt(sVar);
|
||||||
|
} catch (final NumberFormatException e) {
|
||||||
|
x = CardFactoryUtil.xCount(card, card.getSVar(sVar));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
y = Integer.parseInt(compareTo);
|
||||||
|
} catch (final NumberFormatException e) {
|
||||||
|
y = CardFactoryUtil.xCount(card, card.getSVar(compareTo));
|
||||||
|
}
|
||||||
|
if (!Expressions.compare(x, comparator, y)) {
|
||||||
|
return AiPlayDecision.NeedsToPlayCriteriaNotMet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return AiPlayDecision.WillPlay;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ package forge.ai.ability;
|
|||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import forge.ai.ComputerUtil;
|
import forge.ai.*;
|
||||||
import forge.ai.ComputerUtilCard;
|
|
||||||
import forge.ai.SpecialCardAi;
|
|
||||||
import forge.ai.SpellAbilityAi;
|
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
import forge.game.card.*;
|
import forge.game.card.*;
|
||||||
import forge.game.card.CardPredicates.Presets;
|
import forge.game.card.CardPredicates.Presets;
|
||||||
@@ -51,6 +48,13 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sa.hasParam("Embalm") || sa.hasParam("Eternalize")) {
|
||||||
|
// E.g. Vizier of Many Faces: check to make sure it makes sense to make the token now
|
||||||
|
if (ComputerUtilCard.checkNeedsToPlayReqs(sa.getHostCard(), sa) != AiPlayDecision.WillPlay) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sa.usesTargeting() && sa.hasParam("TargetingPlayer")) {
|
if (sa.usesTargeting() && sa.hasParam("TargetingPlayer")) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
Player targetingPlayer = AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("TargetingPlayer"), sa).get(0);
|
Player targetingPlayer = AbilityUtils.getDefinedPlayers(sa.getHostCard(), sa.getParam("TargetingPlayer"), sa).get(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user