- Added some missing functions to AF DestroyAll (namely a proper stack description and doTriggerAI).

- The AI can now use Austere Command.
This commit is contained in:
Sloth
2012-03-10 10:08:19 +00:00
parent ccfe064aef
commit 3147ede39c
3 changed files with 96 additions and 25 deletions

View File

@@ -7,7 +7,6 @@ SVar:DestroyArtifacts:DB$ DestroyAll | ValidCards$ Artifact | SpellDescription$
SVar:DestroyEnchs:DB$ DestroyAll | ValidCards$ Enchantment | SpellDescription$ Destroy all enchantments. SVar:DestroyEnchs:DB$ DestroyAll | ValidCards$ Enchantment | SpellDescription$ Destroy all enchantments.
SVar:DestroyLE3:DB$ DestroyAll | ValidCards$ Creature.cmcLE3 | SpellDescription$ Destroy all creatures with converted mana cost 3 or less. SVar:DestroyLE3:DB$ DestroyAll | ValidCards$ Creature.cmcLE3 | SpellDescription$ Destroy all creatures with converted mana cost 3 or less.
SVar:DestroyGE4:DB$ DestroyAll | ValidCards$ Creature.cmcGE4 | SpellDescription$ Destroy all creatures with converted mana cost 4 or greater. SVar:DestroyGE4:DB$ DestroyAll | ValidCards$ Creature.cmcGE4 | SpellDescription$ Destroy all creatures with converted mana cost 4 or greater.
SVar:RemAIDeck:True
SVar:Rarity:Rare SVar:Rarity:Rare
SVar:Picture:http://www.wizards.com/global/images/magic/general/austere_command.jpg SVar:Picture:http://www.wizards.com/global/images/magic/general/austere_command.jpg
SetInfo:COM|Rare|http://magiccards.info/scans/en/cmd/8.jpg SetInfo:COM|Rare|http://magiccards.info/scans/en/cmd/8.jpg

View File

@@ -142,6 +142,7 @@ public final class AbilityFactoryCharm {
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
//this resets all previous choices //this resets all previous choices
sa.setSubAbility(null); sa.setSubAbility(null);
sa.setActivatingPlayer(AllZone.getComputerPlayer());
final int num = Integer.parseInt(params.containsKey("CharmNum") ? params.get("CharmNum") final int num = Integer.parseInt(params.containsKey("CharmNum") ? params.get("CharmNum")
: "1"); : "1");
final String[] saChoices = params.get("Choices").split(","); final String[] saChoices = params.get("Choices").split(",");
@@ -156,13 +157,13 @@ public final class AbilityFactoryCharm {
for (SpellAbility sub : choices) { for (SpellAbility sub : choices) {
if (sub.doTrigger(false)) { if (sub.doTrigger(false)) {
chosen = (AbilitySub) sub; chosen = (AbilitySub) sub;
choices.remove(sub);
break; break;
} }
} }
if (chosen == null) { if (chosen == null) {
return false; return false;
} }
choices.remove(chosen);
// walk down the SpellAbility tree and add to the child // walk down the SpellAbility tree and add to the child
// Ability_Sub // Ability_Sub

View File

@@ -680,11 +680,7 @@ public class AbilityFactoryDestroy {
@Override @Override
public String getStackDescription() { public String getStackDescription() {
if (this.params.containsKey("SpellDescription")) { return AbilityFactoryDestroy.destroyAllStackDescription(af, this, this.noRegen);
return af.getHostCard().getName() + " - " + this.params.get("SpellDescription");
} else {
return AbilityFactoryDestroy.destroyAllStackDescription(af, this, this.noRegen);
}
} }
@Override @Override
@@ -699,8 +695,7 @@ public class AbilityFactoryDestroy {
@Override @Override
public boolean doTrigger(final boolean mandatory) { public boolean doTrigger(final boolean mandatory) {
// TODO Auto-generated method stub return AbilityFactoryDestroy.destroyAllTriggerAI(af, this, mandatory);
return false;
} }
}; };
@@ -726,26 +721,35 @@ public class AbilityFactoryDestroy {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
final String name = af.getHostCard().getName(); final String name = af.getHostCard().getName();
final HashMap<String, String> params = af.getMapParams(); final HashMap<String, String> params = af.getMapParams();
if (!(sa instanceof AbilitySub)) {
final String conditionDesc = params.get("ConditionDescription"); sb.append(sa.getSourceCard().getName()).append(" - ");
if (conditionDesc != null) {
sb.append(conditionDesc).append(" ");
}
ArrayList<Card> tgtCards;
final Target tgt = sa.getTarget();
if (tgt != null) {
tgtCards = tgt.getTargetCards();
} else { } else {
tgtCards = new ArrayList<Card>(); sb.append(" ");
tgtCards.add(sa.getSourceCard());
} }
sb.append(name).append(" - Destroy permanents."); if (params.containsKey("SpellDescription")) {
sb.append(params.get("SpellDescription"));
} else {
final String conditionDesc = params.get("ConditionDescription");
if (conditionDesc != null) {
sb.append(conditionDesc).append(" ");
}
if (noRegen) { ArrayList<Card> tgtCards;
sb.append(" They can't be regenerated");
final Target tgt = sa.getTarget();
if (tgt != null) {
tgtCards = tgt.getTargetCards();
} else {
tgtCards = new ArrayList<Card>();
tgtCards.add(sa.getSourceCard());
}
sb.append(name).append(" - Destroy permanents.");
if (noRegen) {
sb.append(" They can't be regenerated");
}
} }
final AbilitySub abSub = sa.getSubAbility(); final AbilitySub abSub = sa.getSubAbility();
@@ -756,6 +760,73 @@ public class AbilityFactoryDestroy {
return sb.toString(); return sb.toString();
} }
/**
* <p>
* destroyAllCanPlayAI.
* </p>
*
* @param af
* a {@link forge.card.abilityfactory.AbilityFactory} object.
* @param sa
* a {@link forge.card.spellability.SpellAbility} object.
* @param noRegen
* a boolean.
* @return a boolean.
*/
private static boolean destroyAllTriggerAI(final AbilityFactory af, final SpellAbility sa, final boolean mandatory) {
final Card source = sa.getSourceCard();
final HashMap<String, String> params = af.getMapParams();
final Target tgt = sa.getTarget();
String valid = "";
if (params.containsKey("ValidCards")) {
valid = params.get("ValidCards");
}
CardList humanlist = AllZone.getHumanPlayer().getCardsIn(Zone.Battlefield);
CardList computerlist = AllZone.getComputerPlayer().getCardsIn(Zone.Battlefield);
if (sa.getTarget() != null) {
tgt.resetTargets();
sa.getTarget().addTarget(AllZone.getHumanPlayer());
computerlist.clear();
}
if (mandatory) {
return true;
}
humanlist = humanlist.getValidCards(valid.split(","), source.getController(), source);
computerlist = computerlist.getValidCards(valid.split(","), source.getController(), source);
humanlist = humanlist.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
return !(c.hasKeyword("Indestructible") || c.getSVar("SacMe").length() > 0);
}
});
if (humanlist.isEmpty()) {
return false;
}
computerlist = computerlist.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
return !(c.hasKeyword("Indestructible") || c.getSVar("SacMe").length() > 0);
}
});
// if only creatures are affected evaluate both lists and pass only if
// human creatures are more valuable
if ((humanlist.getNotType("Creature").size() == 0) && (computerlist.getNotType("Creature").size() == 0)) {
if (CardFactoryUtil.evaluateCreatureList(computerlist) >= CardFactoryUtil.evaluateCreatureList(humanlist)) {
return false;
}
} // otherwise evaluate both lists by CMC and pass only if human
// permanents are more valuable
else if (CardFactoryUtil.evaluatePermanentList(computerlist) >= CardFactoryUtil.evaluatePermanentList(humanlist)) {
return false;
}
final AbilitySub subAb = sa.getSubAbility();
if (subAb != null && !subAb.chkAIDrawback()) {
return false;
}
return true;
}
/** /**
* <p> * <p>
* destroyAllCanPlayAI. * destroyAllCanPlayAI.