From 8c5f8f16e2c08ebd0803cd15e9a67245571d6517 Mon Sep 17 00:00:00 2001 From: Sloth Date: Mon, 25 Feb 2013 20:26:00 +0000 Subject: [PATCH] - Added AI support for Realmwright. --- res/cardsfolder/r/realmwright.txt | 4 +- res/cardsfolder/s/soul_ransom.txt | 1 - .../ability/effects/ChooseTypeEffect.java | 45 ++++++++++++++++--- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/res/cardsfolder/r/realmwright.txt b/res/cardsfolder/r/realmwright.txt index fd9795e2a54..a5da8c2a34b 100644 --- a/res/cardsfolder/r/realmwright.txt +++ b/res/cardsfolder/r/realmwright.txt @@ -3,10 +3,8 @@ ManaCost:U Types:Creature Vedalken Wizard PT:1/1 K:ETBReplacement:Other:DBChooseBasic -SVar:DBChooseBasic:DB$ ChooseType | Type$ Basic Land | SpellDescription$ As CARDNAME enters the battlefield, choose a basic land type. +SVar:DBChooseBasic:DB$ ChooseType | Type$ Basic Land | AILogic$ MostNeededType | SpellDescription$ As CARDNAME enters the battlefield, choose a basic land type. S:Mode$ Continuous | Affected$ Land.YouCtrl | AddType$ ChosenType | Description$ Lands you control are the chosen type in addition to their other types. -SVar:RemAIDeck:True -SVar:Rarity:Common SVar:Picture:http://www.wizards.com/global/images/magic/general/realmwright.jpg SetInfo:GTC|Rare|http://magiccards.info/scans/en/gtc/45.jpg Oracle:As Realmwright enters the battlefield, choose a basic land type.\nLands you control are the chosen type in addition to their other types. diff --git a/res/cardsfolder/s/soul_ransom.txt b/res/cardsfolder/s/soul_ransom.txt index 080a76f42ef..62f05081bb5 100644 --- a/res/cardsfolder/s/soul_ransom.txt +++ b/res/cardsfolder/s/soul_ransom.txt @@ -6,7 +6,6 @@ K:Enchant creature A:SP$ Attach | Cost$ 2 U B | ValidTgts$ Creature | AILogic$ GainControl A:AB$ Sacrifice | Cost$ Discard<2/Card> | AnyOpponent$ True | SacValid$ Self | SubAbility$ DBDraw | SpellDescription$ CARDNAME's controller sacrifices it, then draws two cards. Only any opponent may activate this ability. SVar:DBDraw:DB$ Draw | NumCards$ 2 | Defined$ SourceController -SVar:RemAIDeck:True SVar:Picture:http://www.wizards.com/global/images/magic/general/soul_ransom.jpg SetInfo:GTC|Rare|http://magiccards.info/scans/en/gtc/198.jpg Oracle:Enchant creature\nYou control enchanted creature.\nDiscard two cards: Soul Ransom's controller sacrifices it, then draws two cards. Only any opponent may activate this ability. diff --git a/src/main/java/forge/card/ability/effects/ChooseTypeEffect.java b/src/main/java/forge/card/ability/effects/ChooseTypeEffect.java index 22893623121..1c8f8ffacab 100644 --- a/src/main/java/forge/card/ability/effects/ChooseTypeEffect.java +++ b/src/main/java/forge/card/ability/effects/ChooseTypeEffect.java @@ -4,8 +4,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import com.google.common.collect.Iterables; + import forge.Card; import forge.CardLists; +import forge.CardPredicates; import forge.Constant; import forge.Singletons; import forge.card.CardType; @@ -102,19 +105,19 @@ public class ChooseTypeEffect extends SpellAbilityEffect { if (logic.equals("MostProminentOnBattlefield")) { chosen = CardFactoryUtil.getMostProminentCreatureType(Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield)); } - if (logic.equals("MostProminentComputerControls")) { + else if (logic.equals("MostProminentComputerControls")) { chosen = CardFactoryUtil.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Battlefield)); } - if (logic.equals("MostProminentHumanControls")) { + else if (logic.equals("MostProminentHumanControls")) { chosen = CardFactoryUtil.getMostProminentCreatureType(opp.getCardsIn(ZoneType.Battlefield)); if (!CardType.isACreatureType(chosen) || invalidTypes.contains(chosen)) { chosen = CardFactoryUtil.getMostProminentCreatureType(CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsInGame(), opp)); } } - if (logic.equals("MostProminentInComputerDeck")) { + else if (logic.equals("MostProminentInComputerDeck")) { chosen = CardFactoryUtil.getMostProminentCreatureType(CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsInGame(), ai)); } - if (logic.equals("MostProminentInComputerGraveyard")) { + else if (logic.equals("MostProminentInComputerGraveyard")) { chosen = CardFactoryUtil.getMostProminentCreatureType(ai.getCardsIn(ZoneType.Graveyard)); } } @@ -143,8 +146,38 @@ public class ChooseTypeEffect extends SpellAbilityEffect { card.setChosenType(choice); } } else { - // TODO AttachAI for ChosenType should have the exact same logic - card.setChosenType("Island"); + Player ai = sa.getActivatingPlayer(); + String chosen = ""; + if (sa.hasParam("AILogic")) { + final String logic = sa.getParam("AILogic"); + if (logic.equals("MostNeededType")) { + // Choose a type that is in the deck, but not in hand or on the battlefield + final ArrayList basics = new ArrayList(); + basics.addAll(Constant.CardTypes.BASIC_TYPES); + List presentCards = ai.getCardsIn(ZoneType.Battlefield); + presentCards.addAll(ai.getCardsIn(ZoneType.Hand)); + List possibleCards = ai.getAllCards(); + + for (String b : basics) { + if(!Iterables.any(presentCards, CardPredicates.isType(b)) && Iterables.any(possibleCards, CardPredicates.isType(b))) { + chosen = b; + } + } + if (chosen.equals("")) { + for (String b : basics) { + if(Iterables.any(possibleCards, CardPredicates.isType(b))) { + chosen = b; + } + } + } + } + } + + if (!CardType.isABasicLandType(chosen) || invalidTypes.contains(chosen)) { + chosen = "Island"; + } + GuiChoose.one("Computer picked: ", new String[]{chosen}); + card.setChosenType(chosen); valid = true; } }