From df7baa5cbb30beb41589efd771593ef055a4ffac Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 04:54:42 +0000 Subject: [PATCH] - Merged Hellfish HandSize code. --- .gitattributes | 1 + res/cards.txt | 72 ++++++++++++++++++ src/forge/CardFactory.java | 109 +++++++++++++++++++++++++++ src/forge/CardFactory_Creatures.java | 109 +++++++++++++++++++++++++++ src/forge/CardFactory_Lands.java | 109 +++++++++++++++++++++++++++ src/forge/Computer_Cleanup.java | 70 +++++++++++++++++ src/forge/HandSizeOp.java | 19 +++++ src/forge/Input_Cleanup.java | 75 ++++++++++++++++++ src/forge/Phase.java | 3 + 9 files changed, 567 insertions(+) create mode 100644 src/forge/HandSizeOp.java diff --git a/.gitattributes b/.gitattributes index 111aafd4d59..976c4977617 100644 --- a/.gitattributes +++ b/.gitattributes @@ -338,6 +338,7 @@ src/forge/Gui_Shops.java -text svneol=native#text/plain src/forge/Gui_Treasury.java -text svneol=native#text/plain src/forge/Gui_Welcome.java svneol=native#text/plain src/forge/Gui_WinLose.java svneol=native#text/plain +src/forge/HandSizeOp.java -text svneol=native#text/plain src/forge/IO.java svneol=native#text/plain src/forge/ImageCache.java svneol=native#text/plain src/forge/ImagePreviewPanel.java -text svneol=native#text/plain diff --git a/res/cards.txt b/res/cards.txt index 6717f380890..652f1561565 100644 --- a/res/cards.txt +++ b/res/cards.txt @@ -1,3 +1,75 @@ +Cursed Rack +4 +Artifact +As Cursed Rack enters the battlefield, choose an opponent. The chosen player's maximum hand size is four. +HandSize = 4 Opponent + +Gnat Miser +B +Creature Rat Shaman +Each opponent's hand size is reduced by one. +1/1 +HandSize - 1 Opponent + +Graceful Adept +2 U +Creature Human Wizard +You have no maximum hand size. +1/3 +HandSize = INF Self + +Locust Miser +2 B B +Creature Rat Shaman +Each opponent's maximum hand size is reduced by two. +2/2 +HandSize - 2 Opponent + +Minamo Scrollkeeper +1 U +Creature Human Wizard +Your maximum hand size is increased by one. +2/3 +HandSize + 1 Self +Defender + +Reliquary Tower +no cost +Land +You have no maximum hand size. +HandSize = INF Self +tap: add 1 + +Spellbook +0 +Artifact +You have no maximum hand size. +HandSize = INF Self + +Thought Devourer +2 U U +Creature Beast +Your maximum hand size is reduced by four. +4/4 +HandSize - 4 Self +Flying + +Thought Eater +1 U +Creature Beast +Your maximum hand size is reduced by three. +2/2 +HandSize - 3 Self +Flying + +Thought Nibbler +U +Creature Beast +Your maximum hand size is reduced by two. +1/1 +HandSize - 2 Self +Flying + Sangrophage B B Creature Zombie diff --git a/src/forge/CardFactory.java b/src/forge/CardFactory.java index b837391b973..aadb7b44754 100644 --- a/src/forge/CardFactory.java +++ b/src/forge/CardFactory.java @@ -22773,6 +22773,115 @@ public class CardFactory implements NewConstants { } }//echo + if(hasKeyword(card,"HandSize") != -1) { + String toParse = card.getKeyword().get(hasKeyword(card,"HandSize")); + card.removeIntrinsicKeyword(toParse); + + String parts[] = toParse.split(" "); + final String Mode = parts[1]; + final int Amount; + if(parts[2].equals("INF")) { + Amount = -1; + } + else { + Amount = Integer.parseInt(parts[2]); + } + final String Target = parts[3]; + + final Command entersPlay,leavesPlay, controllerChanges; + + entersPlay = new Command() { + private static final long serialVersionUID = 98743547743456L; + + public void execute() { + card.setSVar("HSStamp","" + Input_Cleanup.GetHandSizeStamp()); + if(card.getController() == Constant.Player.Human) { + //System.out.println("Human played me! Mode(" + Mode + ") Amount(" + Amount + ") Target(" + Target + ")" ); + if(Target.equals("Self")) { + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("Opponent")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("All")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + } + else + { + //System.out.println("Compy played me! Mode(" + Mode + ") Amount(" + Amount + ") Target(" + Target + ")" ); + if(Target.equals("Self")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("Opponent")) { + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("All")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + } + } + }; + + leavesPlay = new Command() { + private static final long serialVersionUID = -6843545358873L; + + public void execute() { + if(card.getController() == Constant.Player.Human) { + if(Target.equals("Self")) { + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("Opponent")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("All")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + } + else + { + if(Target.equals("Self")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("Opponent")) { + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("All")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + } + } + }; + + controllerChanges = new Command() { + private static final long serialVersionUID = 778987998465463L; + + public void execute() { + System.out.println("Control changed: " + card.getController()); + if(card.getController().equals(Constant.Player.Human)) { + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + + Computer_Cleanup.sortHandSizeOperations(); + } + else if(card.getController().equals(Constant.Player.Computer)) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + + Input_Cleanup.sortHandSizeOperations(); + } + } + }; + + card.addComesIntoPlayCommand(entersPlay); + card.addLeavesPlayCommand(leavesPlay); + card.addChangeControllerCommand(controllerChanges); + } //HandSize + if (card.getManaCost().contains("X")) { SpellAbility sa = card.getSpellAbility()[0]; diff --git a/src/forge/CardFactory_Creatures.java b/src/forge/CardFactory_Creatures.java index 251ae1c7a3b..1cf095d3cac 100644 --- a/src/forge/CardFactory_Creatures.java +++ b/src/forge/CardFactory_Creatures.java @@ -19783,6 +19783,115 @@ public class CardFactory_Creatures { } }//echo + if(hasKeyword(card,"HandSize") != -1) { + String toParse = card.getKeyword().get(hasKeyword(card,"HandSize")); + card.removeIntrinsicKeyword(toParse); + + String parts[] = toParse.split(" "); + final String Mode = parts[1]; + final int Amount; + if(parts[2].equals("INF")) { + Amount = -1; + } + else { + Amount = Integer.parseInt(parts[2]); + } + final String Target = parts[3]; + + final Command entersPlay,leavesPlay, controllerChanges; + + entersPlay = new Command() { + private static final long serialVersionUID = 98743547743456L; + + public void execute() { + card.setSVar("HSStamp","" + Input_Cleanup.GetHandSizeStamp()); + if(card.getController() == Constant.Player.Human) { + //System.out.println("Human played me! Mode(" + Mode + ") Amount(" + Amount + ") Target(" + Target + ")" ); + if(Target.equals("Self")) { + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("Opponent")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("All")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + } + else + { + //System.out.println("Compy played me! Mode(" + Mode + ") Amount(" + Amount + ") Target(" + Target + ")" ); + if(Target.equals("Self")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("Opponent")) { + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("All")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + } + } + }; + + leavesPlay = new Command() { + private static final long serialVersionUID = -6843545358873L; + + public void execute() { + if(card.getController() == Constant.Player.Human) { + if(Target.equals("Self")) { + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("Opponent")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("All")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + } + else + { + if(Target.equals("Self")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("Opponent")) { + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("All")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + } + } + }; + + controllerChanges = new Command() { + private static final long serialVersionUID = 778987998465463L; + + public void execute() { + System.out.println("Control changed: " + card.getController()); + if(card.getController().equals(Constant.Player.Human)) { + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + + Computer_Cleanup.sortHandSizeOperations(); + } + else if(card.getController().equals(Constant.Player.Computer)) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + + Input_Cleanup.sortHandSizeOperations(); + } + } + }; + + card.addComesIntoPlayCommand(entersPlay); + card.addLeavesPlayCommand(leavesPlay); + card.addChangeControllerCommand(controllerChanges); + } //HandSize + if(hasKeyword(card, "Level up") != -1 && hasKeyword(card, "maxLevel") != -1) { int n = hasKeyword(card, "Level up"); diff --git a/src/forge/CardFactory_Lands.java b/src/forge/CardFactory_Lands.java index 73b25ec50a6..d33ea35e092 100644 --- a/src/forge/CardFactory_Lands.java +++ b/src/forge/CardFactory_Lands.java @@ -3308,6 +3308,115 @@ class CardFactory_Lands { } }//transmute + if(hasKeyword(card,"HandSize") != -1) { + String toParse = card.getKeyword().get(hasKeyword(card,"HandSize")); + card.removeIntrinsicKeyword(toParse); + + String parts[] = toParse.split(" "); + final String Mode = parts[1]; + final int Amount; + if(parts[2].equals("INF")) { + Amount = -1; + } + else { + Amount = Integer.parseInt(parts[2]); + } + final String Target = parts[3]; + + final Command entersPlay,leavesPlay, controllerChanges; + + entersPlay = new Command() { + private static final long serialVersionUID = 98743547743456L; + + public void execute() { + card.setSVar("HSStamp","" + Input_Cleanup.GetHandSizeStamp()); + if(card.getController() == Constant.Player.Human) { + //System.out.println("Human played me! Mode(" + Mode + ") Amount(" + Amount + ") Target(" + Target + ")" ); + if(Target.equals("Self")) { + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("Opponent")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("All")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + } + else + { + //System.out.println("Compy played me! Mode(" + Mode + ") Amount(" + Amount + ") Target(" + Target + ")" ); + if(Target.equals("Self")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("Opponent")) { + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + else if(Target.equals("All")) { + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + } + } + } + }; + + leavesPlay = new Command() { + private static final long serialVersionUID = -6843545358873L; + + public void execute() { + if(card.getController() == Constant.Player.Human) { + if(Target.equals("Self")) { + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("Opponent")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("All")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + } + else + { + if(Target.equals("Self")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("Opponent")) { + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + else if(Target.equals("All")) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + } + } + } + }; + + controllerChanges = new Command() { + private static final long serialVersionUID = 778987998465463L; + + public void execute() { + System.out.println("Control changed: " + card.getController()); + if(card.getController().equals(Constant.Player.Human)) { + Input_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Computer_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + + Computer_Cleanup.sortHandSizeOperations(); + } + else if(card.getController().equals(Constant.Player.Computer)) { + Computer_Cleanup.removeHandSizeOperation(Integer.parseInt(card.getSVar("HSStamp"))); + Input_Cleanup.addHandSizeOperation(new HandSizeOp(Mode,Amount,Integer.parseInt(card.getSVar("HSStamp")))); + + Input_Cleanup.sortHandSizeOperations(); + } + } + }; + + card.addComesIntoPlayCommand(entersPlay); + card.addLeavesPlayCommand(leavesPlay); + card.addChangeControllerCommand(controllerChanges); + } //HandSize + return card; } diff --git a/src/forge/Computer_Cleanup.java b/src/forge/Computer_Cleanup.java index e16dced9fa2..c36fa7cf459 100644 --- a/src/forge/Computer_Cleanup.java +++ b/src/forge/Computer_Cleanup.java @@ -2,10 +2,80 @@ package forge; +import java.util.LinkedList; import java.util.Random; public class Computer_Cleanup extends Input { + + private static LinkedList handSizeOperations = new LinkedList(); + private static int MaxHandSize = 7; + + public static void sortHandSizeOperations() { + if(handSizeOperations.size() < 2) { + return; + } + + Object arr[] = handSizeOperations.toArray(); + int changes = 1; + + while(changes > 0) { + changes = 0; + for(int i=1;i= 0) + { + ret = ret + handSizeOperations.get(i).Amount; + } + else if(handSizeOperations.get(i).Mode.equals("-") && ret >= 0) + { + ret = ret - handSizeOperations.get(i).Amount; + if(ret < 0) { + ret = 0; + } + } + } + MaxHandSize = ret; + } + public static void addHandSizeOperation(HandSizeOp theNew) + { + handSizeOperations.add(theNew); + } + public static void removeHandSizeOperation(int timestamp) + { + for(int i=0;i handSizeOperations = new LinkedList(); + private static int MaxHandSize = 7; + + public static void sortHandSizeOperations() { + if(handSizeOperations.size() < 2) { + return; + } + + Object arr[] = handSizeOperations.toArray(); + int changes = 1; + + while(changes > 0) { + changes = 0; + for(int i=1;i= 0) + { + ret = ret + handSizeOperations.get(i).Amount; + } + else if(handSizeOperations.get(i).Mode.equals("-") && ret >= 0) + { + ret = ret - handSizeOperations.get(i).Amount; + if(ret < 0) { + ret = 0; + } + } + } + MaxHandSize = ret; + } + public static void addHandSizeOperation(HandSizeOp theNew) + { + handSizeOperations.add(theNew); + } + public static void removeHandSizeOperation(int timestamp) + { + for(int i=0;i