From 465449c81434cb581eb56a0b92f3dbd9ad1bda5f Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 03:16:05 +0000 Subject: [PATCH] - Fixed Cumulative Upkeep code. - Fixed a small bug with Fastbond (it would sometimes subtract more than 1 life). - Fixed some big bugs with Fastbond, Exploration, Azusa, Lost but Seeking (computer won't be able to use them if it doesn't control them). - AI should lose life when using Fastbond now. --- .gitattributes | 1 + src/forge/AllZone.java | 1 + src/forge/Card.java | 5 +- src/forge/CardFactory.java | 2 +- src/forge/CardFactoryUtil.java | 9 +++- src/forge/Computer.java | 3 -- src/forge/ComputerAI_General.java | 22 +++----- src/forge/ComputerUtil.java | 9 ++++ src/forge/GameAction.java | 12 +++-- src/forge/GameActionUtil.java | 4 +- src/forge/GameInfo.java | 67 +++++++++++++++++++++++++ src/forge/InputControl.java | 2 +- src/forge/InputUtil.java | 9 ++-- src/forge/Input_Attack.java | 2 - src/forge/Input_Draw.java | 10 ++-- src/forge/Input_Main.java | 15 ++---- src/forge/Phase.java | 1 + src/forge/PlayerZone_ComesIntoPlay.java | 36 ++++++++----- 18 files changed, 147 insertions(+), 63 deletions(-) create mode 100644 src/forge/GameInfo.java diff --git a/.gitattributes b/.gitattributes index 226e6e31b3e..0ad12ff413b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -144,6 +144,7 @@ src/forge/GUI_PictureHQ.java -text svneol=native#text/plain src/forge/GUI_Quest_Filter.java -text svneol=native#text/plain src/forge/GameAction.java svneol=native#text/plain src/forge/GameActionUtil.java svneol=native#text/plain +src/forge/GameInfo.java -text svneol=native#text/plain src/forge/GenerateConstructedDeck.java svneol=native#text/plain src/forge/GenerateConstructedMultiColorDeck.java -text svneol=native#text/plain src/forge/GenerateDraftDeck.java svneol=native#text/plain diff --git a/src/forge/AllZone.java b/src/forge/AllZone.java index 1ce5ea76117..13b7cd54244 100644 --- a/src/forge/AllZone.java +++ b/src/forge/AllZone.java @@ -25,6 +25,7 @@ public class AllZone implements NewConstants { public static final InputControl InputControl = new InputControl(); public static final GameAction GameAction = new GameAction(); public static final StateBasedEffects StateBasedEffects = new StateBasedEffects(); + public static final GameInfo GameInfo = new GameInfo(); //initialized at Runtime since it has to be the last object constructed diff --git a/src/forge/Card.java b/src/forge/Card.java index b62b486d150..579963060f7 100644 --- a/src/forge/Card.java +++ b/src/forge/Card.java @@ -301,7 +301,10 @@ public class Card extends MyObservable if (k.startsWith("Scry")) { String kk[] = k.split(" "); - sb.append("Scry " + kk[1] + " (To scry X, look at the top X cards of your library, then put any number of them on the bottom of your library and the rest on top in any order.)\r\n"); + //sb.append("Scry " + kk[1] + " (To scry X, look at the top X cards of your library, then put any number of them on the bottom of your library and the rest on top in any order.)\r\n"); + sb.append("Scry "); + sb.append(kk[1]); + sb.append(" (To scry X, look at the top X cards of your library, then put any number of them on the bottom of your library and the rest on top in any order.)\r\n"); } } diff --git a/src/forge/CardFactory.java b/src/forge/CardFactory.java index 64d71fe9a6d..5acf2f0a3cd 100644 --- a/src/forge/CardFactory.java +++ b/src/forge/CardFactory.java @@ -17967,7 +17967,7 @@ return land.size() > 1 && CardFactoryUtil.AI_isMainPhase(); } }; - bounce.setDescription("You may return two Islands you control to their owner's hand rather than pay Thwart's mana cost."); + bounce.setDescription("You may return three Islands you control to their owner's hand rather than pay Thwart's mana cost."); bounce.setStackDescription(card.getName() + " - Counter target spell."); bounce.setManaCost("0"); diff --git a/src/forge/CardFactoryUtil.java b/src/forge/CardFactoryUtil.java index efcbc266c03..f2aa851b244 100644 --- a/src/forge/CardFactoryUtil.java +++ b/src/forge/CardFactoryUtil.java @@ -2158,20 +2158,25 @@ public class CardFactoryUtil sb.append(tokenized[0]); } else { - for (int i=0; i playMain1Cards; @SuppressWarnings("unchecked") @@ -20,8 +20,8 @@ public class ComputerAI_General implements Computer { } public void main1() { - if(numberPlayLand > 0) { - numberPlayLand--; + if(AllZone.GameInfo.getComputerCanPlayNumberOfLands() > 0) { + AllZone.GameInfo.addComputerCanPlayNumberOfLands(-1); ComputerUtil.playLand(); for(String effect:AllZone.StateBasedEffects.getStateBasedMap().keySet()) { Command com = GameActionUtil.commands.get(effect); @@ -35,9 +35,9 @@ public class ComputerAI_General implements Computer { playCards(Constant.Phase.Main1); //for cards like Exploration, Fastbond, Azusa, ... - while(numberPlayLand > 0) + while(AllZone.GameInfo.getComputerCanPlayNumberOfLands() > 0) { - numberPlayLand--; + AllZone.GameInfo.addComputerCanPlayNumberOfLands(-1); ComputerUtil.playLand(); for(String effect:AllZone.StateBasedEffects.getStateBasedMap().keySet()) { @@ -49,7 +49,7 @@ public class ComputerAI_General implements Computer { }//main1() public void main2() { - numberPlayLand = CardFactoryUtil.getCanPlayNumberOfLands(Constant.Player.Computer); + AllZone.GameInfo.setComputerCanPlayNumberOfLands(CardFactoryUtil.getCanPlayNumberOfLands(Constant.Player.Computer)); playCards(Constant.Phase.Main2); } @@ -313,16 +313,6 @@ public class ComputerAI_General implements Computer { return library.toArray(); } - public void addNumberPlayLands(int n) - { - numberPlayLand += n; - } - - public void setNumberPlayLands(int n) - { - numberPlayLand = n; - } - public void stack_not_empty() { //same as Input.stop() method //ends the method diff --git a/src/forge/ComputerUtil.java b/src/forge/ComputerUtil.java index 31faed81b60..b1a08ca8651 100644 --- a/src/forge/ComputerUtil.java +++ b/src/forge/ComputerUtil.java @@ -335,6 +335,15 @@ public class ComputerUtil AllZone.Computer_Hand.remove(landList.get(0)); AllZone.Computer_Play.add(landList.get(0)); + if (!AllZone.GameInfo.computerPlayedFirstLandThisTurn()) { + AllZone.GameInfo.setComputerPlayedFirstLandThisTurn(true); + } + else + { + if (CardFactoryUtil.getFastbonds(Constant.Player.Computer).size() > 0) + AllZone.GameAction.getPlayerLife(Constant.Player.Computer).subtractLife(1); + } + AllZone.GameAction.checkStateEffects(); } } diff --git a/src/forge/GameAction.java b/src/forge/GameAction.java index 10c7aec05e7..20524bdee17 100644 --- a/src/forge/GameAction.java +++ b/src/forge/GameAction.java @@ -945,8 +945,8 @@ private Card getCurrentCard(int ID) //System.gc(); //garbage collection... does it make a difference though? lastPlayerToDraw = Constant.Player.Human; - Input_Main.canPlayNumberOfLands = 1; - AllZone.Computer.getComputer().setNumberPlayLands(1); + AllZone.GameInfo.setComputerCanPlayNumberOfLands(1); + AllZone.GameInfo.setHumanCanPlayNumberOfLands(1); AllZone.Computer_Life.setLife(20); AllZone.Human_Life.setLife(20); @@ -1277,7 +1277,7 @@ private int getDifferentLand(CardList list, String land) ArrayList choices = new ArrayList(); - if (Input_Main.canPlayNumberOfLands > 0 && AllZone.Stack.size() == 0 && + if (AllZone.GameInfo.getHumanCanPlayNumberOfLands() > 0 && AllZone.Stack.size() == 0 && (AllZone.Phase.getPhase().equals(Constant.Phase.Main1) || AllZone.Phase.getPhase().equals(Constant.Phase.Main2)) ) choices.add("Play land"); @@ -1304,8 +1304,8 @@ private int getDifferentLand(CardList list, String land) { AllZone.Human_Hand.remove(c); AllZone.Human_Play.add(c); - Input_Main.canPlayNumberOfLands--; - Input_Main.firstLandHasBeenPlayed = true; + AllZone.GameInfo.addHumanCanPlayNumberOfLands(-1); + AllZone.GameInfo.setHumanPlayedFirstLandThisTurn(true); } else { @@ -1343,11 +1343,13 @@ private int getDifferentLand(CardList list, String land) SpellAbility sa; //TODO: add Buyback, Kicker, ... , spells here + /* ArrayList additional = c.getAdditionalCostSpells(); for (SpellAbility s : additional) { } + */ /* System.out.println(choices.length); for(int i = 0; i < choices.length; i++) diff --git a/src/forge/GameActionUtil.java b/src/forge/GameActionUtil.java index d7b661203da..01a1493980e 100644 --- a/src/forge/GameActionUtil.java +++ b/src/forge/GameActionUtil.java @@ -2715,7 +2715,9 @@ public class GameActionUtil { String k[] = a.get(i).toString().split(":"); c.addCounter(Counters.AGE, 1); - c.setUpkeepCost(CardFactoryUtil.multiplyManaCost(k[1], c.getCounters(Counters.AGE))); + String upkeepCost = CardFactoryUtil.multiplyManaCost(k[1], c.getCounters(Counters.AGE)); + c.setUpkeepCost(upkeepCost); + System.out.println("Multiplied cost: " + upkeepCost); //c.setUpkeepCost(k[1]); return true; } diff --git a/src/forge/GameInfo.java b/src/forge/GameInfo.java new file mode 100644 index 00000000000..856be85c8a7 --- /dev/null +++ b/src/forge/GameInfo.java @@ -0,0 +1,67 @@ +package forge; + +public class GameInfo { + private int computerCanPlayNumberOfLands; + private int humanCanPlayNumberOfLands; + + private boolean computerPlayedFirstLandThisTurn; + private boolean humanPlayedFirstLandThisTurn; + + private boolean preventCombatDamageThisTurn; + + public void setComputerCanPlayNumberOfLands(int n) { + computerCanPlayNumberOfLands = n; + } + + public int getComputerCanPlayNumberOfLands() { + return computerCanPlayNumberOfLands; + } + + public void addComputerCanPlayNumberOfLands(int n) + { + computerCanPlayNumberOfLands += n; + } + + public void setHumanCanPlayNumberOfLands(int n) { + humanCanPlayNumberOfLands = n; + } + + public int getHumanCanPlayNumberOfLands() { + return humanCanPlayNumberOfLands; + } + + public void addHumanCanPlayNumberOfLands(int n) + { + humanCanPlayNumberOfLands += n; + } + + + public void setComputerPlayedFirstLandThisTurn(boolean b) { + computerPlayedFirstLandThisTurn = b; + } + + public boolean computerPlayedFirstLandThisTurn() { + return computerPlayedFirstLandThisTurn; + } + + public void setHumanPlayedFirstLandThisTurn(boolean b) { + humanPlayedFirstLandThisTurn = b; + } + + public boolean humanPlayedFirstLandThisTurn() { + return humanPlayedFirstLandThisTurn; + } + + + + public void setPreventCombatDamageThisTurn(boolean b) { + preventCombatDamageThisTurn = b; + } + + public boolean isPreventCombatDamageThisTurn() { + return preventCombatDamageThisTurn; + } + + + +} diff --git a/src/forge/InputControl.java b/src/forge/InputControl.java index 00cf665fde1..1bab126c298 100644 --- a/src/forge/InputControl.java +++ b/src/forge/InputControl.java @@ -185,7 +185,7 @@ import java.util.*; } else if(phase.equals(Constant.Phase.End_Of_Turn)) { - System.out.println("Cache size: " + ImageCache.cache.size()); + //System.out.println("Cache size: " + ImageCache.cache.size()); /* CardList visibleCards = new CardList(); diff --git a/src/forge/InputUtil.java b/src/forge/InputUtil.java index e69ed79c78c..3a05f7f4967 100644 --- a/src/forge/InputUtil.java +++ b/src/forge/InputUtil.java @@ -33,16 +33,17 @@ public class InputUtil { AllZone.Human_Hand.remove(card); AllZone.Human_Play.add(card); - Input_Main.canPlayNumberOfLands--; - Input_Main.firstLandHasBeenPlayed = true; + AllZone.GameInfo.addHumanCanPlayNumberOfLands(-1); + AllZone.GameInfo.setHumanPlayedFirstLandThisTurn(true); + } } else //play the land { AllZone.Human_Hand.remove(card); AllZone.Human_Play.add(card); - Input_Main.canPlayNumberOfLands--; - Input_Main.firstLandHasBeenPlayed = true; + AllZone.GameInfo.addHumanCanPlayNumberOfLands(-1); + AllZone.GameInfo.setHumanPlayedFirstLandThisTurn(true); } } //land else if(zone.is(Constant.Zone.Hand, Constant.Player.Human) && diff --git a/src/forge/Input_Attack.java b/src/forge/Input_Attack.java index de16bc7ecf7..a6adfb61a2d 100644 --- a/src/forge/Input_Attack.java +++ b/src/forge/Input_Attack.java @@ -22,9 +22,7 @@ public void showMessage() if (!c.getKeyword().contains("Vigilance")) c.tap(); } - } - } public void selectButtonOK() { diff --git a/src/forge/Input_Draw.java b/src/forge/Input_Draw.java index 76f76c33c6f..fb01be59827 100644 --- a/src/forge/Input_Draw.java +++ b/src/forge/Input_Draw.java @@ -24,8 +24,8 @@ package forge; if(AllZone.Phase.getPhase().equals(Constant.Phase.Draw) && humanSkipsDrawPhase){ //Input_Main.canPlayLand = true; - Input_Main.canPlayNumberOfLands = CardFactoryUtil.getCanPlayNumberOfLands(Constant.Player.Human); - Input_Main.firstLandHasBeenPlayed = false; + AllZone.GameInfo.setHumanCanPlayNumberOfLands(CardFactoryUtil.getCanPlayNumberOfLands(Constant.Player.Human)); + AllZone.GameInfo.setHumanPlayedFirstLandThisTurn(false); AllZone.Phase.setNeedToNextPhase(true); } @@ -60,9 +60,9 @@ package forge; if(AllZone.Phase.getPhase().equals(Constant.Phase.Draw)) { //Input_Main.canPlayLand = true; - Input_Main.canPlayNumberOfLands = CardFactoryUtil.getCanPlayNumberOfLands(Constant.Player.Human); - Input_Main.firstLandHasBeenPlayed = false; - + AllZone.GameInfo.setHumanCanPlayNumberOfLands(CardFactoryUtil.getCanPlayNumberOfLands(Constant.Player.Human)); + AllZone.GameInfo.setHumanPlayedFirstLandThisTurn(false); + //AllZone.Phase.nextPhase(); //for debugging: System.out.println("need to nextPhase(from Input_Draw on human's draw) = true"); AllZone.Phase.setNeedToNextPhase(true); diff --git a/src/forge/Input_Main.java b/src/forge/Input_Main.java index 141d14e8f88..7d57240a669 100644 --- a/src/forge/Input_Main.java +++ b/src/forge/Input_Main.java @@ -1,14 +1,12 @@ package forge; -import java.util.*; -@SuppressWarnings("unused") // java.util.* public class Input_Main extends Input { private static final long serialVersionUID = -2162856359060870957L; //Input_Draw changes this //public static boolean canPlayLand; - public static boolean firstLandHasBeenPlayed; - public static int canPlayNumberOfLands; + //public static boolean firstLandHasBeenPlayed; + //public static int canPlayNumberOfLands; public void showMessage() { @@ -30,16 +28,13 @@ public class Input_Main extends Input //these if statements cannot be combined if(card.isLand() && zone.is(Constant.Zone.Hand, Constant.Player.Human)) { - if(canPlayNumberOfLands > 0 ) + if(AllZone.GameInfo.getHumanCanPlayNumberOfLands() > 0 ) { CardList fastbonds = CardFactoryUtil.getFastbonds(Constant.Player.Human); if (fastbonds.size() > 0){ - if (firstLandHasBeenPlayed) + if (AllZone.GameInfo.humanPlayedFirstLandThisTurn()) { - for ( Card vard : fastbonds) - { - AllZone.GameAction.getPlayerLife(Constant.Player.Human).subtractLife(1); - } + AllZone.GameAction.getPlayerLife(Constant.Player.Human).subtractLife(1); } } InputUtil.playAnyCard(card, zone); diff --git a/src/forge/Phase.java b/src/forge/Phase.java index e21fe197c1d..59fdebe1e04 100644 --- a/src/forge/Phase.java +++ b/src/forge/Phase.java @@ -201,6 +201,7 @@ public class Phase extends MyObservable } else if (is(Constant.Phase.Untap, Constant.Player.Computer)) { + AllZone.GameInfo.setComputerPlayedFirstLandThisTurn(false); turn++; /* if (computerExtraTurns > 0) diff --git a/src/forge/PlayerZone_ComesIntoPlay.java b/src/forge/PlayerZone_ComesIntoPlay.java index afbf057dbaf..a49db290df3 100644 --- a/src/forge/PlayerZone_ComesIntoPlay.java +++ b/src/forge/PlayerZone_ComesIntoPlay.java @@ -28,16 +28,22 @@ public class PlayerZone_ComesIntoPlay extends DefaultPlayerZone //cannot use addComesIntoPlayCommand - trigger might be set to false; if (c.getName().equals("Exploration")) { - Input_Main.canPlayNumberOfLands++; - AllZone.Computer.getComputer().addNumberPlayLands(1); + if (c.getController().equals(Constant.Player.Human)) + AllZone.GameInfo.addHumanCanPlayNumberOfLands(1); + else + AllZone.GameInfo.addComputerCanPlayNumberOfLands(1); } else if (c.getName().equals("Azusa, Lost but Seeking")) { - Input_Main.canPlayNumberOfLands+=2; - AllZone.Computer.getComputer().addNumberPlayLands(2); + if (c.getController().equals(Constant.Player.Human)) + AllZone.GameInfo.addHumanCanPlayNumberOfLands(2); + else + AllZone.GameInfo.addComputerCanPlayNumberOfLands(2); } else if( c.getName().equals("Fastbond")) { - Input_Main.canPlayNumberOfLands+=100; - AllZone.Computer.getComputer().addNumberPlayLands(100); + if (c.getController().equals(Constant.Player.Human)) + AllZone.GameInfo.addHumanCanPlayNumberOfLands(100); + else + AllZone.GameInfo.addComputerCanPlayNumberOfLands(100); } if (trigger) @@ -198,16 +204,22 @@ public class PlayerZone_ComesIntoPlay extends DefaultPlayerZone //cannot use addLeavesPlayCommand - trigger might be set to false if (c.getName().equals("Exploration")) { - Input_Main.canPlayNumberOfLands--; - AllZone.Computer.getComputer().addNumberPlayLands(-1); + if (c.getController().equals(Constant.Player.Human)) + AllZone.GameInfo.addHumanCanPlayNumberOfLands(-1); + else + AllZone.GameInfo.addComputerCanPlayNumberOfLands(-1); } else if (c.getName().equals("Azusa, Lost but Seeking")) { - Input_Main.canPlayNumberOfLands-=2; - AllZone.Computer.getComputer().addNumberPlayLands(-2); + if (c.getController().equals(Constant.Player.Human)) + AllZone.GameInfo.addHumanCanPlayNumberOfLands(-2); + else + AllZone.GameInfo.addComputerCanPlayNumberOfLands(-2); } else if( c.getName().equals("Fastbond")) { - Input_Main.canPlayNumberOfLands-=100; - AllZone.Computer.getComputer().addNumberPlayLands(-100); + if (c.getController().equals(Constant.Player.Human)) + AllZone.GameInfo.addHumanCanPlayNumberOfLands(-100); + else + AllZone.GameInfo.addComputerCanPlayNumberOfLands(-100); }