From 3707e3ad96b2b99f281ea72b91f1b621626e8cf8 Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 07:18:23 +0000 Subject: [PATCH] add Drop of Honey (from Arabian Nights) --- .gitattributes | 1 + res/cardsfolder/drop_of_honey.txt | 7 +++ src/forge/CardFactoryUtil.java | 21 +++++++++ src/forge/GameActionUtil.java | 71 +++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 res/cardsfolder/drop_of_honey.txt diff --git a/.gitattributes b/.gitattributes index bf9a70b4880..620f0b9bfb2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -963,6 +963,7 @@ res/cardsfolder/drifting_meadow.txt -text svneol=native#text/plain res/cardsfolder/dripping_tongue_zubera.txt -text svneol=native#text/plain res/cardsfolder/dromad_purebred.txt -text svneol=native#text/plain res/cardsfolder/dromars_attendant.txt -text svneol=native#text/plain +res/cardsfolder/drop_of_honey.txt -text svneol=native#text/plain res/cardsfolder/dross_crocodile.txt -text svneol=native#text/plain res/cardsfolder/dross_golem.txt -text svneol=native#text/plain res/cardsfolder/dross_harvester.txt -text svneol=native#text/plain diff --git a/res/cardsfolder/drop_of_honey.txt b/res/cardsfolder/drop_of_honey.txt new file mode 100644 index 00000000000..ae1f0c9a44d --- /dev/null +++ b/res/cardsfolder/drop_of_honey.txt @@ -0,0 +1,7 @@ +Name:Drop of Honey +ManaCost:G +Types:Enchantment +Text:At the beginning of your upkeep, destroy the creature with the least power. It can't be regenerated. If two or more creatures are tied for least power, you choose one of them.\r\nWhen there are no creatures on the battlefield, sacrifice Drop of Honey. +K:SVar:Rarity:Rare +K:SVar:Picture:http://www.wizards.com/global/images/magic/general/drop_of_honey.jpg +End diff --git a/src/forge/CardFactoryUtil.java b/src/forge/CardFactoryUtil.java index 455d3489798..f93895d9180 100644 --- a/src/forge/CardFactoryUtil.java +++ b/src/forge/CardFactoryUtil.java @@ -719,6 +719,27 @@ public class CardFactoryUtil { return target; }//input_sacrifice() + public static Input input_destroyNoRegeneration(final CardList choices, final String message) { + Input target = new Input() { + private static final long serialVersionUID = -6637588517573573232L; + + @Override + public void showMessage() { + AllZone.Display.showMessage(message); + ButtonUtil.disableAll(); + } + + @Override + public void selectCard(Card card, PlayerZone zone) { + if(choices.contains(card)) { + AllZone.GameAction.destroyNoRegeneration(card); + stop(); + } + } + }; + return target; + }//input_destroyNoRegeneration() + public static Input input_sacrificePermanents(final int nCards) { Input target = new Input() { private static final long serialVersionUID = -8149416676562317629L; diff --git a/src/forge/GameActionUtil.java b/src/forge/GameActionUtil.java index dcb70ce0bda..ea892cb52fa 100644 --- a/src/forge/GameActionUtil.java +++ b/src/forge/GameActionUtil.java @@ -23,6 +23,7 @@ public class GameActionUtil { AllZone.GameAction.CheckWheneverKeyword(AllZone.CardFactory.HumanNullCard, "BeginningOfUpkeep", null); + upkeep_Drop_of_Honey(); upkeep_Genesis(); upkeep_Phyrexian_Arena(); upkeep_Master_of_the_Wild_Hunt(); @@ -3528,6 +3529,76 @@ public class GameActionUtil { } }//damageUpkeepCost + private static void upkeep_Drop_of_Honey() { + /* + * At the beginning of your upkeep, destroy the creature with the + * least power. It can't be regenerated. If two or more creatures + * are tied for least power, you choose one of them. + * + * When there are no creatures on the battlefield, sacrifice Drop of Honey. + */ + final String player = AllZone.Phase.getActivePlayer(); + final CardList cards = AllZoneUtil.getPlayerCardsInPlay(player, "Drop of Honey"); + + //if no creatures in play, sacrifice all "Drop of Honey"s + if(AllZoneUtil.getCreaturesInPlay().size() == 0) { + for(Card drop:cards) { + AllZone.GameAction.sacrifice(drop); + } + return; + } + + for(int i = 0; i < cards.size(); i++) { + final Card c = cards.get(i); + + final Ability ability = new Ability(c, "") { + @Override + public void resolve() { + CardList creatures = AllZoneUtil.getCreaturesInPlay(); + CardListUtil.sortAttackLowFirst(creatures); + int power = creatures.get(0).getNetAttack(); + if(player.equals(Constant.Player.Human)) { + AllZone.InputControl.setInput(CardFactoryUtil.input_destroyNoRegeneration(getLowestPowerList(creatures), "Select creature with power: "+power+" to sacrifice.")); + } + else { //computer + Card compyTarget = getCompyCardToDestroy(creatures); + AllZone.GameAction.destroyNoRegeneration(compyTarget); + } + }//resolve + + private CardList getLowestPowerList(CardList original) { + CardList lowestPower = new CardList(); + int power = original.get(0).getNetAttack(); + int i = 0; + while(original.get(i).getNetAttack() == power) { + lowestPower.add(original.get(i)); + i++; + } + return lowestPower; + } + + private Card getCompyCardToDestroy(CardList original) { + CardList options = getLowestPowerList(original); + CardList humanCreatures = options.filter(new CardListFilter() { + public boolean addCard(Card c) { + return c.getController().equals(Constant.Player.Human); + } + }); + if(humanCreatures.isEmpty()) { + options.shuffle(); + return options.get(0); + } + else { + humanCreatures.shuffle(); + return humanCreatures.get(0); + } + } + }; + ability.setStackDescription(c.getName()+" - destroy 1 creature with lowest power."); + AllZone.Stack.add(ability); + }//end for + } + /** * runs the upkeep for Genesis */