- Added check in DamageDealAi for planeswalkers

This commit is contained in:
excessum
2015-11-01 07:34:25 +00:00
parent ab8c60646b
commit 411039b779
5 changed files with 44 additions and 8 deletions

View File

@@ -98,6 +98,20 @@ public class ComputerUtilCard {
return Aggregates.itemWithMax(all, CardPredicates.Accessors.fnGetCmc); return Aggregates.itemWithMax(all, CardPredicates.Accessors.fnGetCmc);
} }
/**
* Returns the best Planeswalker from a given list
* @param list list of cards to evaluate
* @return best Planeswalker
*/
public static Card getBestPlaneswalkerAI(final List<Card> list) {
List<Card> all = CardLists.filter(list, CardPredicates.Presets.PLANEWALKERS);
if (all.size() == 0) {
return null;
}
// no AI logic, just return most expensive
return Aggregates.itemWithMax(all, CardPredicates.Accessors.fnGetCmc);
}
// The AI doesn't really pick the best enchantment, just the most expensive. // The AI doesn't really pick the best enchantment, just the most expensive.
/** /**
* <p> * <p>

View File

@@ -2080,7 +2080,7 @@ public class ComputerUtilCombat {
*/ */
public static final int getEnoughDamageToKill(final Card c, final int maxDamage, final Card source, final boolean isCombat, public static final int getEnoughDamageToKill(final Card c, final int maxDamage, final Card source, final boolean isCombat,
final boolean noPrevention) { final boolean noPrevention) {
final int killDamage = ComputerUtilCombat.getDamageToKill(c); final int killDamage = c.isPlaneswalker() ? c.getCurrentLoyalty() : ComputerUtilCombat.getDamageToKill(c);
if (c.hasKeyword("Indestructible") || c.getShieldCount() > 0) { if (c.hasKeyword("Indestructible") || c.getShieldCount() > 0) {
if (!(source.hasKeyword("Wither") || source.hasKeyword("Infect"))) { if (!(source.hasKeyword("Wither") || source.hasKeyword("Infect"))) {

View File

@@ -31,7 +31,6 @@ import forge.game.card.Card;
import forge.game.card.CardCollection; import forge.game.card.CardCollection;
import forge.game.card.CardCollectionView; import forge.game.card.CardCollectionView;
import forge.game.card.CardLists; import forge.game.card.CardLists;
import forge.game.card.CardPredicates;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
@@ -175,8 +174,7 @@ public class ControlGainAi extends SpellAbilityAi {
} }
if (hasPW) { if (hasPW) {
CardCollection planeswalkers = CardLists.filter(list, CardPredicates.Presets.PLANEWALKERS); t = ComputerUtilCard.getBestPlaneswalkerAI(list);
t = ComputerUtilCard.getMostExpensivePermanentAI(planeswalkers, sa, true);
} else if (hasCreature) { } else if (hasCreature) {
t = ComputerUtilCard.getBestCreatureAI(list); t = ComputerUtilCard.getBestCreatureAI(list);
if (lose != null && lose.contains("EOT")) { if (lose != null && lose.contains("EOT")) {

View File

@@ -176,9 +176,14 @@ public class DamageDealAi extends DamageAiBase {
} }
}); });
Card targetCard; Card targetCard = null;
if (pl.isOpponentOf(ai) && !killables.isEmpty()) { if (pl.isOpponentOf(ai) && !killables.isEmpty()) {
if (sa.getTargetRestrictions().canTgtPlaneswalker()) {
targetCard = ComputerUtilCard.getBestPlaneswalkerAI(killables);
}
if (targetCard == null) {
targetCard = ComputerUtilCard.getBestCreatureAI(killables); targetCard = ComputerUtilCard.getBestCreatureAI(killables);
}
return targetCard; return targetCard;
} }
@@ -189,7 +194,12 @@ public class DamageDealAi extends DamageAiBase {
if (!hPlay.isEmpty()) { if (!hPlay.isEmpty()) {
if (pl.isOpponentOf(ai)) { if (pl.isOpponentOf(ai)) {
if (sa.getTargetRestrictions().canTgtPlaneswalker()) {
targetCard = ComputerUtilCard.getBestPlaneswalkerAI(hPlay);
}
if (targetCard == null) {
targetCard = ComputerUtilCard.getBestCreatureAI(hPlay); targetCard = ComputerUtilCard.getBestCreatureAI(hPlay);
}
} else { } else {
targetCard = ComputerUtilCard.getWorstCreatureAI(hPlay); targetCard = ComputerUtilCard.getWorstCreatureAI(hPlay);
} }
@@ -400,7 +410,7 @@ public class DamageDealAi extends DamageAiBase {
} }
} }
} else if (tgt.canTgtCreature()) { } else if (tgt.canTgtCreature() || tgt.canTgtPlaneswalker()) {
final Card c = this.dealDamageChooseTgtC(ai, sa, dmg, noPrevention, enemy, mandatory); final Card c = this.dealDamageChooseTgtC(ai, sa, dmg, noPrevention, enemy, mandatory);
if (c != null) { if (c != null) {
//option to hold removal instead only applies for single targeted removal //option to hold removal instead only applies for single targeted removal

View File

@@ -423,6 +423,20 @@ public class TargetRestrictions {
return false; return false;
} }
/**
* Can tgt planeswalker.
*
* @return true, if successful
*/
public final boolean canTgtPlaneswalker() {
for (final String s : this.validTgts) {
if (s.startsWith("Planeswalker")) {
return true;
}
}
return false;
}
/** /**
* <p> * <p>
* canTgtCreatureAndPlayer. * canTgtCreatureAndPlayer.