- Cleanup and performance fixes in AI functions.

This commit is contained in:
Sloth
2014-10-12 21:06:55 +00:00
parent 10bd22a944
commit 4cbd16d7b5
3 changed files with 28 additions and 24 deletions

View File

@@ -1253,7 +1253,7 @@ public class AiController {
for (final SpellAbility sa : getOriginalAndAltCostAbilities(all)) {
// Don't add Counterspells to the "normal" playcard lookups
if (sa.getApi() == ApiType.Counter && skipCounter) {
if (skipCounter && sa.getApi() == ApiType.Counter) {
continue;
}
sa.setActivatingPlayer(player);

View File

@@ -1019,18 +1019,6 @@ public class ComputerUtil {
int defense = 0;
boolean grantIndestructible = false;
boolean grantShroud = false;
if (saviourApi == ApiType.Pump || saviourApi == ApiType.PumpAll) {
defense = saviour.hasParam("NumDef") ?
AbilityUtils.calculateAmount(saviour.getHostCard(), saviour.getParam("NumDef"), saviour) : 0;
final List<String> keywords = saviour.hasParam("KW") ?
Arrays.asList(saviour.getParam("KW").split(" & ")) : new ArrayList<String>();
if (keywords.contains("Indestructible")) {
grantIndestructible = true;
}
if (keywords.contains("Hexproof") || keywords.contains("Shroud")) {
grantShroud = true;
}
}
if (topStack == null) {
return objects;
@@ -1051,20 +1039,36 @@ public class ComputerUtil {
} else if (topStack.hasParam("ValidCards")) {
CardCollectionView battleField = aiPlayer.getCardsIn(ZoneType.Battlefield);
objects = CardLists.getValidCards(battleField, topStack.getParam("ValidCards").split(","), source.getController(), source);
} else {
return threatened;
}
} else {
objects = topStack.getTargets().getTargets();
if (tgt != null) {
final ArrayList<GameObject> canBeTargeted = new ArrayList<GameObject>();
for (Object o : objects) {
if (o instanceof Card) {
final Card c = (Card) o;
if (c.canBeTargetedBy(topStack)) {
canBeTargeted.add(c);
}
final ArrayList<GameObject> canBeTargeted = new ArrayList<GameObject>();
for (Object o : objects) {
if (o instanceof Card) {
final Card c = (Card) o;
if (c.canBeTargetedBy(topStack)) {
canBeTargeted.add(c);
}
}
objects = canBeTargeted;
}
if (canBeTargeted.isEmpty()) {
return threatened;
}
objects = canBeTargeted;
}
if (saviourApi == ApiType.Pump || saviourApi == ApiType.PumpAll) {
defense = saviour.hasParam("NumDef") ?
AbilityUtils.calculateAmount(saviour.getHostCard(), saviour.getParam("NumDef"), saviour) : 0;
final List<String> keywords = saviour.hasParam("KW") ?
Arrays.asList(saviour.getParam("KW").split(" & ")) : new ArrayList<String>();
if (keywords.contains("Indestructible")) {
grantIndestructible = true;
}
if (keywords.contains("Hexproof") || keywords.contains("Shroud")) {
grantShroud = true;
}
}

View File

@@ -796,7 +796,7 @@ public class PlayerControllerAi extends PlayerController {
if (!ai.getGame().getStack().isEmpty()) {
final List<GameObject> objects = ComputerUtil.predictThreatenedObjects(sa.getActivatingPlayer(), null);
for (Card c : blockers) {
if (objects.contains(c) && blockers.contains(c)) {
if (objects.contains(c)) {
untappedCreats.add(c);
}
}