mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- Consolidate Sarkhan the Mad specific AI logic in SpecialCardAi until it is generalized.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package forge.ai;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -409,6 +410,43 @@ public class SpecialCardAi {
|
||||
return new CardCollection(toKeep);
|
||||
}
|
||||
}
|
||||
|
||||
// Sarkhan the Mad
|
||||
public static class SarkhanTheMad {
|
||||
public static boolean considerDig(Player ai, SpellAbility sa) {
|
||||
return sa.getHostCard().getCounters(CounterType.LOYALTY) == 1;
|
||||
}
|
||||
|
||||
public static boolean considerMakeDragon(Player ai, SpellAbility sa) {
|
||||
// TODO: expand this logic to make the AI force the opponent to sacrifice a big threat bigger than a 5/5 flier?
|
||||
CardCollection creatures = ai.getCreaturesInPlay();
|
||||
boolean hasValidTgt = !CardLists.filter(creatures, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(Card t) {
|
||||
return t.getCurrentPower() < 5 && t.getCurrentToughness() < 5;
|
||||
}
|
||||
}).isEmpty();
|
||||
if (hasValidTgt) {
|
||||
Card worstCreature = ComputerUtilCard.getWorstCreatureAI(creatures);
|
||||
sa.getTargets().add(worstCreature);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean considerUltimate(Player ai, SpellAbility sa, Player weakestOpp) {
|
||||
int minLife = weakestOpp.getLife();
|
||||
|
||||
int dragonPower = 0;
|
||||
CardCollection dragons = CardLists.filter(ai.getCreaturesInPlay(), CardPredicates.isType("Dragon"));
|
||||
for (Card c : dragons) {
|
||||
dragonPower += c.getCurrentPower();
|
||||
}
|
||||
|
||||
return dragonPower >= minLife;
|
||||
}
|
||||
}
|
||||
|
||||
// Timetwister
|
||||
public static class Timetwister {
|
||||
public static boolean consider(Player ai, SpellAbility sa) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class DamageDealAi extends DamageAiBase {
|
||||
Card source = sa.getHostCard();
|
||||
|
||||
if ("MadSarkhanDigDmg".equals(logic)) {
|
||||
return source.getCounters(CounterType.LOYALTY) == 1;
|
||||
return SpecialCardAi.SarkhanTheMad.considerDig(ai, sa);
|
||||
}
|
||||
|
||||
if (damage.equals("X") && sa.getSVar(damage).equals("Count$ChosenNumber")) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.ai.ability;
|
||||
|
||||
|
||||
import forge.ai.SpecialCardAi;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardCollection;
|
||||
@@ -31,15 +32,7 @@ public class DamageEachAi extends DamageAiBase {
|
||||
}
|
||||
|
||||
if ("MadSarkhanUltimate".equals(logic)) {
|
||||
int minLife = weakestOpp.getLife();
|
||||
|
||||
int dragonPower = 0;
|
||||
CardCollection dragons = CardLists.filter(ai.getCreaturesInPlay(), CardPredicates.isType("Dragon"));
|
||||
for (Card c : dragons) {
|
||||
dragonPower += c.getCurrentPower();
|
||||
}
|
||||
|
||||
return dragonPower >= minLife;
|
||||
return SpecialCardAi.SarkhanTheMad.considerUltimate(ai, sa, weakestOpp);
|
||||
}
|
||||
|
||||
final String damage = sa.getParam("NumDmg");
|
||||
|
||||
@@ -9,6 +9,7 @@ import forge.ai.ComputerUtilCard;
|
||||
import forge.ai.ComputerUtilCost;
|
||||
import forge.ai.ComputerUtilMana;
|
||||
import forge.ai.PlayerControllerAi;
|
||||
import forge.ai.SpecialCardAi;
|
||||
import forge.ai.SpellAbilityAi;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.ability.ApiType;
|
||||
@@ -76,20 +77,7 @@ public class DestroyAi extends SpellAbilityAi {
|
||||
return targetingPlayer.getController().chooseTargetsFor(sa);
|
||||
}
|
||||
if ("MadSarkhanDragon".equals(logic)) {
|
||||
// TODO: expand this logic to make the AI force the opponent to sacrifice a big threat bigger than a 5/5 flier?
|
||||
CardCollection creatures = ai.getCreaturesInPlay();
|
||||
boolean hasValidTgt = !CardLists.filter(creatures, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(Card t) {
|
||||
return t.getCurrentPower() < 5 && t.getCurrentToughness() < 5;
|
||||
}
|
||||
}).isEmpty();
|
||||
if (hasValidTgt) {
|
||||
Card worstCreature = ComputerUtilCard.getWorstCreatureAI(creatures);
|
||||
sa.getTargets().add(worstCreature);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return SpecialCardAi.SarkhanTheMad.considerMakeDragon(ai, sa);
|
||||
} else if ("Polymorph".equals(logic)) {
|
||||
list = CardLists.getTargetableCards(ai.getCardsIn(ZoneType.Battlefield), sa);
|
||||
if (list.isEmpty()) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import forge.ai.ComputerUtil;
|
||||
import forge.ai.ComputerUtilAbility;
|
||||
import forge.ai.ComputerUtilCard;
|
||||
import forge.ai.ComputerUtilMana;
|
||||
import forge.ai.SpecialCardAi;
|
||||
import forge.ai.SpellAbilityAi;
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
@@ -94,7 +95,7 @@ public class DigAi extends SpellAbilityAi {
|
||||
}
|
||||
|
||||
if ("MadSarkhanDigDmg".equals(sa.getParam("AILogic"))) {
|
||||
return host.getCounters(CounterType.LOYALTY) == 1;
|
||||
return SpecialCardAi.SarkhanTheMad.considerDig(ai, sa);
|
||||
}
|
||||
|
||||
return !ComputerUtil.preventRunAwayActivations(sa);
|
||||
|
||||
Reference in New Issue
Block a user