From 285a544ae53e122184dc4746a0148a67d2ec1aef Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 04:44:40 +0000 Subject: [PATCH] * fix getColor * NullPointer fix * Harrow fix * new card Natural Order --- res/cards.txt | 5 ++ src/forge/CardFactory.java | 88 +++++++++++++++++++++++++++++++++- src/forge/CardFactoryUtil.java | 16 +++++++ src/forge/CardList.java | 2 +- src/forge/gui/ListChooser.java | 2 +- 5 files changed, 109 insertions(+), 4 deletions(-) diff --git a/res/cards.txt b/res/cards.txt index d623b60e4f5..32bd42f4d2a 100644 --- a/res/cards.txt +++ b/res/cards.txt @@ -1,3 +1,8 @@ +Natural Order +2 G G +Sorcery +As an additional cost to cast Natural Order, sacrifice a green creature. Search your library for a green creature card and put it onto the battlefield. Then shuffle your library. + Elvish Farmer 1 G Creature Elf diff --git a/src/forge/CardFactory.java b/src/forge/CardFactory.java index ba6897d589b..b4ec1e78856 100644 --- a/src/forge/CardFactory.java +++ b/src/forge/CardFactory.java @@ -18635,7 +18635,7 @@ public class CardFactory implements NewConstants { PlayerZone library = AllZone.getZone(Constant.Zone.Library, Constant.Player.Computer); CardList list = new CardList(library.getCards()); list = list.getType("Basic"); - PlayerZone inPlay = AllZone.getZone(Constant.Zone.Library, Constant.Player.Computer); + PlayerZone inPlay = AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer); CardList listInPlay = new CardList(inPlay.getCards()); listInPlay = listInPlay.getType("Land"); // One or more lands in library, 2 or more lands in play @@ -21048,7 +21048,91 @@ public class CardFactory implements NewConstants { }//*************** END ************ END ************************** - + //*************** START *********** START ************************** + else if (cardName.equals("Natural Order")){ + final SpellAbility spell = new Spell(card) { + + private static final long serialVersionUID = -6598323179507468746L; + + @Override + public void resolve() { + String controller = card.getController(); + + PlayerZone battlezone = AllZone.getZone(Constant.Zone.Play, controller); + PlayerZone library = AllZone.getZone(Constant.Zone.Library, controller); + + CardList list = new CardList(library.getCards()); + list = list.getType("Creature").getColor("G"); + + if(list.size() == 0) return; + + if(controller.equals(Constant.Player.Human)) { + + Card c = AllZone.Display.getChoiceOptional("Choose a green creature", list.toArray()); + if(c != null) { + list.remove(c); + library.remove(c); + battlezone.add(c); + + }//if + } else { + Card c = CardFactoryUtil.AI_getBestCreature(new CardList(library.getCards())); + if(c != null) { + list.remove(c); + library.remove(c); + battlezone.add(c); + + }//if + } + } // resolve + + public void chooseTargetAI() { + Card target = null; + target = CardFactoryUtil.AI_getWorstCreature(new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer).getCards())); + setTargetCard(target); + AllZone.GameAction.sacrifice(getTargetCard()); + }//chooseTargetAI() + + + public boolean canPlayAI() + { + PlayerZone library = AllZone.getZone(Constant.Zone.Library, Constant.Player.Computer); + CardList list = new CardList(library.getCards()); + list = list.getType("Creature").getColor("G"); + PlayerZone inPlay = AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer); + CardList listInPlay = new CardList(inPlay.getCards()); + listInPlay = listInPlay.getType("Creature").getColor("G"); + Card inPlayCreature = CardFactoryUtil.AI_getWorstCreature(new CardList(AllZone.getZone(Constant.Zone.Play, Constant.Player.Computer).getCards())); + Card inLibraryCreature = CardFactoryUtil.AI_getBestCreature(new CardList(AllZone.getZone(Constant.Zone.Library, Constant.Player.Computer).getCards())); + return (list.size() > 0) && (listInPlay.size() > 0) && (inPlayCreature.getNetAttack() < inLibraryCreature.getNetAttack()); + } + };//SpellAbility + Input runtime = new Input() { + + private static final long serialVersionUID = -7551607354431165941L; + + @Override + public void showMessage() { + String player = card.getController(); + PlayerZone play = AllZone.getZone(Constant.Zone.Play, player); + CardList choice = new CardList(play.getCards()); + choice = choice.getType("Creature").getColor("G"); + + boolean free = false; + if (this.isFree()) + free = true; + + if (player.equals(Constant.Player.Human)) { + stopSetNext(CardFactoryUtil.input_sacrifice(spell, choice, "Select a green creature to sacrifice.", free)); + } + } + }; + + card.clearSpellAbility(); + card.addSpellAbility(spell); + spell.setBeforePayMana(runtime); + + } //*************** END ************ END ************************** // Cards with Cycling abilities // -1 means keyword "Cycling" not found diff --git a/src/forge/CardFactoryUtil.java b/src/forge/CardFactoryUtil.java index 362447cf9f8..385f12be685 100644 --- a/src/forge/CardFactoryUtil.java +++ b/src/forge/CardFactoryUtil.java @@ -295,6 +295,22 @@ public class CardFactoryUtil { return biggest; } + //returns null if list.size() == 0 + public static Card AI_getWorstCreature(CardList list) { + CardList all = list; + all = all.getType("Creature"); + //get smallest creature + Card smallest = null; + + if(all.size() != 0) { + smallest = all.get(0); + + for(int i = 0; i < all.size(); i++) + if(smallest.getNetAttack() > all.get(i).getNetAttack()) smallest = all.get(i); + } + return smallest; + } + public static Input input_targetCreaturePlayer(final SpellAbility spell, boolean targeted, boolean free) { return input_targetCreaturePlayer(spell, Command.Blank, targeted, free); } diff --git a/src/forge/CardList.java b/src/forge/CardList.java index 1f8aaa4beb4..c85c08462c6 100644 --- a/src/forge/CardList.java +++ b/src/forge/CardList.java @@ -35,7 +35,7 @@ public class CardList implements Iterable { for(int i = 0; i < size(); i++) { card = getCard(i); - if(0 < card.getManaCost().indexOf(cardColor)) //hopefully this line works + if(-1 < card.getManaCost().indexOf(cardColor)) //hopefully this line works c.add(getCard(i)); } return c; diff --git a/src/forge/gui/ListChooser.java b/src/forge/gui/ListChooser.java index 88a36fe7074..dbfb02aa26a 100644 --- a/src/forge/gui/ListChooser.java +++ b/src/forge/gui/ListChooser.java @@ -164,7 +164,7 @@ public class ListChooser { //this assert checks if we really don't return on a cancel if input is mandatory assert minChoices == 0 || value == OK_OPTION; called = true; - return value == OK_OPTION; + return value != null && value == OK_OPTION; } /**