Merge branch 'ai-haste-detection' into 'master'

Improve the AI Haste detection from Command zone and opponent's Battlefield

See merge request core-developers/forge!410
This commit is contained in:
swordshine
2018-04-16 00:51:09 +00:00

View File

@@ -951,7 +951,8 @@ public class ComputerUtil {
return true;
}
if (card.isCreature() && !card.hasKeyword("Defender") && (card.hasKeyword("Haste") || ComputerUtil.hasACardGivingHaste(ai) || sa.isDash())) {
if (card.isCreature() && !card.hasKeyword("Defender")
&& (card.hasKeyword("Haste") || ComputerUtil.hasACardGivingHaste(ai, true) || sa.isDash())) {
return true;
}
@@ -1237,9 +1238,9 @@ public class ComputerUtil {
return false;
}
public static boolean hasACardGivingHaste(final Player ai) {
final CardCollection all = new CardCollection(ai.getCardsIn(ZoneType.Battlefield));
public static boolean hasACardGivingHaste(final Player ai, final boolean checkOpponentCards) {
final CardCollection all = new CardCollection(ai.getCardsIn(Lists.newArrayList(ZoneType.Battlefield, ZoneType.Command)));
// Special for Anger
if (!ai.getGame().isCardInPlay("Yixlid Jailer")
&& !ai.getCardsIn(ZoneType.Graveyard, "Anger").isEmpty()
@@ -1305,6 +1306,28 @@ public class ComputerUtil {
}
}
}
if (checkOpponentCards) {
// Check if the opponents have any cards giving Haste to all creatures on the battlefield
CardCollection opp = new CardCollection();
opp.addAll(ai.getOpponents().getCardsIn(ZoneType.Battlefield));
opp.addAll(ai.getOpponents().getCardsIn(ZoneType.Command));
for (final Card c : opp) {
for (StaticAbility stAb : c.getStaticAbilities()) {
Map<String, String> params = stAb.getMapParams();
if ("Continuous".equals(params.get("Mode")) && params.containsKey("AddKeyword")
&& params.get("AddKeyword").contains("Haste")) {
final ArrayList affected = Lists.newArrayList(params.get("Affected").split(","));
if (affected.contains("Creature")) {
return true;
}
}
}
}
}
return false;
}