- Added AI support to AF ExchangeControl.

This commit is contained in:
Sloth
2012-07-13 19:48:04 +00:00
parent 08fe22d5b6
commit 2dea227a39
3 changed files with 34 additions and 11 deletions

View File

@@ -4,7 +4,6 @@ Types:Creature Minion
Text:no text
PT:2/2
A:AB$ ExchangeControl | Cost$ 2 U U | Defined$ Self | ValidTgts$ Creature | TgtPrompt$ Select target creature | SpellDescription$ Exchange control of CARDNAME and target creature. (This effect lasts indefinitely.)
SVar:RemAIDeck:True
SVar:Rarity:Rare
SVar:Picture:http://www.wizards.com/global/images/magic/general/phyrexian_infiltrator.jpg
SetInfo:INV|Rare|http://magiccards.info/scans/en/in/116.jpg

View File

@@ -3,7 +3,6 @@ ManaCost:4 U
Types:Sorcery
Text:no text
A:SP$ ExchangeControl | Cost$ 4 U | ValidTgts$ Creature | TgtPrompt$ Select target creature | TargetMin$ 2 | TargetMax$ 2 | SpellDescription$ Exchange control of two target creatures.
SVar:RemAIDeck:True
SVar:Rarity:Uncommon
SVar:Picture:http://www.wizards.com/global/images/magic/general/switcheroo.jpg
SetInfo:M13|Uncommon|http://magiccards.info/scans/en/m13/71.jpg

View File

@@ -42,6 +42,7 @@ import forge.game.phase.PhaseType;
import forge.game.player.ComputerUtil;
import forge.game.player.Player;
import forge.game.zone.ZoneType;
import forge.util.MyRandom;
//AB:GainControl|ValidTgts$Creature|TgtPrompt$Select target legendary creature|LoseControl$Untap,LoseControl|SpellDescription$Gain control of target xxxxxxx
@@ -721,16 +722,10 @@ public class AbilityFactoryGainControl {
this.af.getAbTgt()) {
private static final long serialVersionUID = 8004957182752960518L;
private final AbilityFactory af = AbilityFactoryGainControl.this.af;
private final HashMap<String, String> params = this.af.getMapParams();
@Override
public String getStackDescription() {
if (this.params.containsKey("SpellDescription")) {
return af.getHostCard().getName() + " - "
+ this.params.get("SpellDescription");
} else {
return exchangeControlStackDescription(this.af, this);
}
return exchangeControlStackDescription(this.af, this);
}
@Override
@@ -841,9 +836,39 @@ public class AbilityFactoryGainControl {
}
private boolean exchangeControlCanPlayAI(final AbilityFactory af, final SpellAbility sa) {
final HashMap<String, String> params = af.getMapParams();
Card object1 = null;
Card object2 = null;
final Target tgt = sa.getTarget();
tgt.resetTargets();
//final Target tgt = sa.getTarget();
CardList list = AllZone.getHumanPlayer().getCardsIn(ZoneType.Battlefield);
list = list.getValidCards(tgt.getValidTgts(), AllZone.getComputerPlayer(), this.hostCard);
// AI won't try to grab cards that are filtered out of AI decks on
// purpose
list = list.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
final Map<String, String> vars = c.getSVars();
return !vars.containsKey("RemAIDeck") && c.canBeTargetedBy(sa);
}
});
object1 = CardFactoryUtil.getBestAI(list);
if (params.containsKey("Defined")) {
object2 = AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa).get(0);
} else if (tgt.getMinTargets(sa.getSourceCard(), sa) > 1) {
CardList list2 = AllZone.getComputerPlayer().getCardsIn(ZoneType.Battlefield);
list2 = list2.getValidCards(tgt.getValidTgts(), AllZone.getComputerPlayer(), this.hostCard);
object2 = CardFactoryUtil.getWorstAI(list2);
tgt.addTarget(object2);
}
if (object1 == null || object2 == null) {
return false;
}
if (CardFactoryUtil.evaluateCreature(object1) > CardFactoryUtil.evaluateCreature(object2) + 40) {
tgt.addTarget(object1);
return MyRandom.getRandom().nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
}
return false;
}