mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
ControlExchangeAi: add some Logic for chkAIDrawback that is used in Triggers
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package forge.ai.ability;
|
package forge.ai.ability;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
@@ -15,9 +16,6 @@ import forge.game.spellability.TargetRestrictions;
|
|||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ControlExchangeAi extends SpellAbilityAi {
|
public class ControlExchangeAi extends SpellAbilityAi {
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -30,15 +28,14 @@ public class ControlExchangeAi extends SpellAbilityAi {
|
|||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
|
|
||||||
List<Card> list =
|
CardCollection list =
|
||||||
CardLists.getValidCards(ai.getOpponent().getCardsIn(ZoneType.Battlefield), tgt.getValidTgts(), ai, sa.getHostCard(), sa);
|
CardLists.getValidCards(ai.getOpponent().getCardsIn(ZoneType.Battlefield), tgt.getValidTgts(), ai, sa.getHostCard(), sa);
|
||||||
// AI won't try to grab cards that are filtered out of AI decks on
|
// AI won't try to grab cards that are filtered out of AI decks on
|
||||||
// purpose
|
// purpose
|
||||||
list = CardLists.filter(list, new Predicate<Card>() {
|
list = CardLists.filter(list, new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final Card c) {
|
public boolean apply(final Card c) {
|
||||||
final Map<String, String> vars = c.getSVars();
|
return !c.hasSVar("RemAIDeck") && c.canBeTargetedBy(sa);
|
||||||
return !vars.containsKey("RemAIDeck") && c.canBeTargetedBy(sa);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
object1 = ComputerUtilCard.getBestAI(list);
|
object1 = ComputerUtilCard.getBestAI(list);
|
||||||
@@ -62,28 +59,54 @@ public class ControlExchangeAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||||
TargetRestrictions tgt = sa.getTargetRestrictions();
|
if (!sa.usesTargeting()) {
|
||||||
if (tgt == null) {
|
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
CardCollection list2 = CardLists.getValidCards(aiPlayer.getGame().getCardsIn(ZoneType.Battlefield),
|
return chkAIDrawback(sa, aiPlayer);
|
||||||
tgt.getValidTgts(), aiPlayer, sa.getHostCard(), sa);
|
|
||||||
while (!list2.isEmpty()) {
|
|
||||||
Card best = ComputerUtilCard.getBestAI(list2);
|
|
||||||
if (sa.canTarget(best)) {
|
|
||||||
sa.getTargets().add(best);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
list2.remove(best);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} else {
|
} else {
|
||||||
return canPlayAI(aiPlayer, sa);
|
return canPlayAI(aiPlayer, sa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean chkAIDrawback(SpellAbility sa, Player aiPlayer) {
|
||||||
|
if (!sa.usesTargeting()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
|
|
||||||
|
CardCollection list = CardLists.getValidCards(aiPlayer.getGame().getCardsIn(ZoneType.Battlefield),
|
||||||
|
tgt.getValidTgts(), aiPlayer, sa.getHostCard(), sa);
|
||||||
|
|
||||||
|
// only select the cards that can be targeted
|
||||||
|
list = CardLists.getTargetableCards(list, sa);
|
||||||
|
|
||||||
|
if (list.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Card best = ComputerUtilCard.getBestAI(list);
|
||||||
|
|
||||||
|
// if Param has Defined, check if the best Target is better than the Defined
|
||||||
|
if (sa.hasParam("Defined")) {
|
||||||
|
final Card object = AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Defined"), sa).get(0);
|
||||||
|
// TODO add evaluate Land if able
|
||||||
|
final Card realBest = ComputerUtilCard.getBestAI(Lists.newArrayList(best, object));
|
||||||
|
|
||||||
|
// Defined card is better than this one, try to avoid trade
|
||||||
|
if (!best.equals(realBest)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add best Target
|
||||||
|
sa.getTargets().add(best);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user