From 7985bc0e488e85bd44a43b9ddac0721784d737e5 Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 07:15:57 +0000 Subject: [PATCH] Centralized all milling I could find. --- src/forge/CardFactory.java | 31 ++------------- src/forge/CardFactory_Creatures.java | 48 ++---------------------- src/forge/CardFactory_Instants.java | 15 +------- src/forge/CardFactory_Lands.java | 15 +------- src/forge/CardFactory_Planeswalkers.java | 15 +------- src/forge/CardFactory_Sorceries.java | 39 ++----------------- src/forge/CombatUtil.java | 20 +--------- src/forge/GameAction.java | 16 ++++++++ src/forge/GameActionUtil.java | 23 +----------- 9 files changed, 32 insertions(+), 190 deletions(-) diff --git a/src/forge/CardFactory.java b/src/forge/CardFactory.java index 01c27bfa839..d2c38ff1309 100644 --- a/src/forge/CardFactory.java +++ b/src/forge/CardFactory.java @@ -8841,20 +8841,7 @@ public class CardFactory implements NewConstants { @Override public void resolve() { - String player = getTargetPlayer(); - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int max = 2; - if(libList.size() < 2) max = libList.size(); - - for(int i = 0; i < max; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } + AllZone.GameAction.mill(getTargetPlayer(), 2); } }; ab1.setChooseTargetAI(CardFactoryUtil.AI_targetHuman()); @@ -9457,20 +9444,8 @@ public class CardFactory implements NewConstants { @Override public void resolve() { String player = getTargetPlayer(); - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int numCards = grave.size(); - - int max = libList.size(); - if(numCards > max) numCards = max; - - for(int i = 0; i < numCards; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } + AllZone.GameAction.mill(player, + AllZone.getZone(Constant.Zone.Graveyard, player).size()); } }; ab1.setChooseTargetAI(CardFactoryUtil.AI_targetHuman()); diff --git a/src/forge/CardFactory_Creatures.java b/src/forge/CardFactory_Creatures.java index e3a0b45fdbd..12e55198007 100644 --- a/src/forge/CardFactory_Creatures.java +++ b/src/forge/CardFactory_Creatures.java @@ -17803,21 +17803,7 @@ public class CardFactory_Creatures { @Override public void resolve() { - String player = getTargetPlayer(); - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int max = 3; - if(libList.size() < 3) max = libList.size(); - - for(int i = 0; i < max; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } - + AllZone.GameAction.mill(getTargetPlayer(),3); } @Override @@ -17843,20 +17829,7 @@ public class CardFactory_Creatures { @Override public void resolve() { - String player = getTargetPlayer(); - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int max = 2; - if(libList.size() < 2) max = libList.size(); - - for(int i = 0; i < max; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } + AllZone.GameAction.mill(getTargetPlayer(),2); } @@ -17883,20 +17856,7 @@ public class CardFactory_Creatures { @Override public void resolve() { - String player = getTargetPlayer(); - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int max = 1; - if(libList.size() < 1) max = libList.size(); - - for(int i = 0; i < max; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } + AllZone.GameAction.mill(getTargetPlayer(),1); } @@ -20569,7 +20529,7 @@ public class CardFactory_Creatures { AllZone.Computer_Life.subtractLife(1,card); }//resolve() };//SpellAbility - ability.setDescription("G: Ifh-Bíff Efreet deals 1 damage to each creature with flying and each player. Any player may activate this ability"); + ability.setDescription("G: Ifh-B�ff Efreet deals 1 damage to each creature with flying and each player. Any player may activate this ability"); ability.setStackDescription(card + " deals 1 damage to each flying creature and each player."); ability.setAnyPlayer(true); card.addSpellAbility(ability); diff --git a/src/forge/CardFactory_Instants.java b/src/forge/CardFactory_Instants.java index d807af49595..3c74d4887c0 100644 --- a/src/forge/CardFactory_Instants.java +++ b/src/forge/CardFactory_Instants.java @@ -1451,20 +1451,7 @@ public class CardFactory_Instants { @Override public void resolve() { - String player = getTargetPlayer(); - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int max = 3; - if(libList.size() < max) max = libList.size(); - - for(int i = 0; i < max; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } + AllZone.GameAction.mill(getTargetPlayer(),3); } };//SpellAbility spell.setBeforePayMana(CardFactoryUtil.input_targetPlayer(spell)); diff --git a/src/forge/CardFactory_Lands.java b/src/forge/CardFactory_Lands.java index 2ed6e39b673..0f36643ed38 100644 --- a/src/forge/CardFactory_Lands.java +++ b/src/forge/CardFactory_Lands.java @@ -2850,20 +2850,7 @@ class CardFactory_Lands { @Override public void resolve() { - String player = getTargetPlayer(); - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int max = 1; - if(libList.size() < 1) max = libList.size(); - - for(int i = 0; i < max; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } + AllZone.GameAction.mill(getTargetPlayer(),1); } }; ability.setBeforePayMana(CardFactoryUtil.input_targetPlayer(ability)); diff --git a/src/forge/CardFactory_Planeswalkers.java b/src/forge/CardFactory_Planeswalkers.java index b0e95327ef1..426efc67379 100644 --- a/src/forge/CardFactory_Planeswalkers.java +++ b/src/forge/CardFactory_Planeswalkers.java @@ -1912,20 +1912,7 @@ class CardFactory_Planeswalkers { card2.subtractCounter(Counters.LOYALTY, 10); turn[0] = AllZone.Phase.getTurn(); - String player = getTargetPlayer(); - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int max = 20; - if(libList.size() < 20) max = libList.size(); - - for(int i = 0; i < max; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } + AllZone.GameAction.mill(getTargetPlayer(),20); }//resolve() diff --git a/src/forge/CardFactory_Sorceries.java b/src/forge/CardFactory_Sorceries.java index d22d61401ec..633d369c71d 100644 --- a/src/forge/CardFactory_Sorceries.java +++ b/src/forge/CardFactory_Sorceries.java @@ -5261,22 +5261,8 @@ public class CardFactory_Sorceries { @Override public void resolve() { - String player = getTargetPlayer(); - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int max = 0; - if(cardName.equals("Glimpse the Unthinkable")) max = 10; - else max = 5; - if(libList.size() < max) max = libList.size(); - - for(int i = 0; i < max; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } + AllZone.GameAction.mill(getTargetPlayer(), + (cardName.equals("Glimpse the Unthinkable")) ? 10 : 5); } };//SpellAbility spell.setBeforePayMana(CardFactoryUtil.input_targetPlayer(spell)); @@ -6335,26 +6321,7 @@ public class CardFactory_Sorceries { public void resolve() { - String player = getTargetPlayer(); - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int limit; - - if (card.getXManaCostPaid() > lib.size()) { - limit = lib.size(); - } else { - limit = card.getXManaCostPaid(); - } - - // for (int i = 0; i < card.getXManaCostPaid(); i++) { - for (int i = 0; i < limit; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } + AllZone.GameAction.mill(getTargetPlayer(),card.getXManaCostPaid()); AllZone.GameAction.getPlayerLife(card.getController()).addLife(card.getXManaCostPaid()); card.setXManaCostPaid(0); diff --git a/src/forge/CombatUtil.java b/src/forge/CombatUtil.java index d3a5347b902..54170e7d4b9 100644 --- a/src/forge/CombatUtil.java +++ b/src/forge/CombatUtil.java @@ -1778,25 +1778,7 @@ public class CombatUtil { }//Preeminent Captain else if(c.getName().equals("Nemesis of Reason") && !c.getCreatureAttackedThisCombat()) { - String player = AllZone.GameAction.getOpponent(c.getController()); - //if (c.getController().equals(Constant.Player.Human)) - //player="Human"; - //else if (c.getController().equals(Constant.Player.Computer)) - //player="Computer"; - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int max = 10; - if(libList.size() < 10) max = libList.size(); - - for(int i = 0; i < max; i++) { - Card c1 = libList.get(i); - lib.remove(c1); - grave.add(c1); - } - + AllZone.GameAction.mill( AllZone.GameAction.getOpponent(c.getController()),10); }//Nemesis of Reason else if(c.getName().equals("Novablast Wurm") && !c.getCreatureAttackedThisCombat()) { diff --git a/src/forge/GameAction.java b/src/forge/GameAction.java index 4055b0fde42..605b515884e 100644 --- a/src/forge/GameAction.java +++ b/src/forge/GameAction.java @@ -138,6 +138,17 @@ public class GameAction { } */ + public void mill(String player, int n) + { + CardList lib = AllZoneUtil.getPlayerCardsInLibrary(player); + + int max = Math.min(n, lib.size()); + + for(int i = 0; i < max; i++) { + AllZone.GameAction.moveToGraveyard(lib.get(i)); + } + } + public void discard(Card c, SpellAbility sa) { if (sa!= null) @@ -1632,6 +1643,7 @@ public class GameAction { Command_Effects[F_Target] = Proper_resolve; StackDescription = StackDescription + F_TargetPlayer[F_Target] + " draws " + F_Amount[0] + " card(s)"; } + // Discard Cards if(Effect[y].contains("DiscardCards")) { @@ -2301,10 +2313,14 @@ public class GameAction { * to match the mechanics in Forge * @param c */ + + public void exile(Card c) { removeFromGame(c); } + + public void removeUnearth(Card c) { PlayerZone removed = AllZone.getZone(Constant.Zone.Removed_From_Play, c.getOwner()); diff --git a/src/forge/GameActionUtil.java b/src/forge/GameActionUtil.java index 6c82c10f460..dcb70ce0bda 100644 --- a/src/forge/GameActionUtil.java +++ b/src/forge/GameActionUtil.java @@ -4708,20 +4708,7 @@ public class GameActionUtil { final Ability ability = new Ability(c, "0") { @Override public void resolve() { - String player = getTargetPlayer(); - - PlayerZone lib = AllZone.getZone(Constant.Zone.Library, player); - PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList libList = new CardList(lib.getCards()); - - int max = 3; - if(libList.size() < 3) max = libList.size(); - - for(int i = 0; i < max; i++) { - Card c = libList.get(i); - lib.remove(c); - grave.add(c); - } + AllZone.GameAction.mill(getTargetPlayer(),3); } }; ability.setStackDescription(c.getName() + " - Landfall: " + targetPlayer + " puts the top three cards of his or her library into his or her graveyard."); @@ -5004,13 +4991,7 @@ public class GameActionUtil { new String[] {"Creature", "Wolf"}, 2, 2, new String[] {""}); - CardList lib = AllZoneUtil.getPlayerCardsInLibrary(opponent); - int max = lib.size(); - if (max > 10) - max = 10; - - for (int i=0;i