diff --git a/.gitattributes b/.gitattributes index 29024a6cbf1..92d8fcc71b7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9399,13 +9399,9 @@ res/quest/decks/quest6.dck -text res/quest/decks/quest7.dck -text res/quest/decks/quest8.dck -text res/quest/decks/quest9.dck -text -res/quest/easy.txt svneol=native#text/plain -res/quest/hard.txt svneol=native#text/plain -res/quest/medium.txt svneol=native#text/plain res/quest/price.txt svneol=native#text/plain res/quest/quest.preferences -text res/quest/quest.properties svneol=native#text/plain -res/quest/quests.txt svneol=native#text/plain res/quest/themes/-1[!!-~]-1[!!-~]Counters[!!-~]BG.thm -text res/quest/themes/Anti[!!-~]Black[!!-~]WB.thm -text res/quest/themes/Anti[!!-~]Black[!!-~]WG.thm -text @@ -9474,7 +9470,6 @@ res/quest/themes/Vigilance[!!-~]Meekstone[!!-~]W.thm -text res/quest/themes/White.thm -text res/quest/themes/Wolves[!!-~]WG.thm -text res/quest/themes/Zombies[!!-~]B.thm -text -res/quest/veryhard.txt svneol=native#text/plain res/reprintSetInfo.py svneol=native#text/x-python res/sealed/juzamjedi.zsealed -text res/setInfoScript.py svneol=native#text/x-python @@ -9583,8 +9578,6 @@ src/main/java/forge/PlayerType.java svneol=native#text/plain src/main/java/forge/PlayerUtil.java svneol=native#text/plain src/main/java/forge/PlayerZone.java svneol=native#text/plain src/main/java/forge/PlayerZone_ComesIntoPlay.java svneol=native#text/plain -src/main/java/forge/Quest_Assignment.java svneol=native#text/plain -src/main/java/forge/ReadQuest_Assignment.java svneol=native#text/plain src/main/java/forge/SetInfo.java svneol=native#text/plain src/main/java/forge/SetUtils.java svneol=native#text/plain src/main/java/forge/SimpleCombat.java svneol=native#text/plain @@ -9768,7 +9761,7 @@ src/main/java/forge/game/limited/CardPoolLimitation.java -text src/main/java/forge/game/limited/CustomLimited.java svneol=native#text/plain src/main/java/forge/game/limited/DeckColors.java svneol=native#text/plain src/main/java/forge/game/limited/SealedDeck.java svneol=native#text/plain -src/main/java/forge/game/limited/package-info.java -text svneol=native#text/plain +src/main/java/forge/game/limited/package-info.java svneol=native#text/plain src/main/java/forge/game/package-info.java -text src/main/java/forge/gui/CardListViewer.java -text src/main/java/forge/gui/ForgeAction.java svneol=native#text/plain @@ -9835,10 +9828,8 @@ src/main/java/forge/properties/NewConstants.java svneol=native#text/plain src/main/java/forge/properties/Preferences.java svneol=native#text/plain src/main/java/forge/properties/SavePreferencesListener.java svneol=native#text/plain src/main/java/forge/properties/package-info.java svneol=native#text/plain -src/main/java/forge/quest/data/QuestBattleManager.java svneol=native#text/plain src/main/java/forge/quest/data/QuestData.java svneol=native#text/plain src/main/java/forge/quest/data/QuestDataIO.java svneol=native#text/plain -src/main/java/forge/quest/data/QuestEvent.java -text src/main/java/forge/quest/data/QuestMatchState.java svneol=native#text/plain src/main/java/forge/quest/data/QuestPreferences.java svneol=native#text/plain src/main/java/forge/quest/data/QuestUtil.java svneol=native#text/plain @@ -9869,15 +9860,19 @@ src/main/java/forge/quest/data/pet/QuestPetWolf.java svneol=native#text/plain src/main/java/forge/quest/data/pet/package-info.java svneol=native#text/plain src/main/java/forge/quest/gui/QuestAbstractPanel.java svneol=native#text/plain src/main/java/forge/quest/gui/QuestFrame.java svneol=native#text/plain +src/main/java/forge/quest/gui/QuestMainPanel.java -text src/main/java/forge/quest/gui/QuestOptions.java svneol=native#text/plain src/main/java/forge/quest/gui/bazaar/QuestBazaarItem.java svneol=native#text/plain src/main/java/forge/quest/gui/bazaar/QuestBazaarPanel.java svneol=native#text/plain src/main/java/forge/quest/gui/bazaar/QuestBazaarStall.java svneol=native#text/plain src/main/java/forge/quest/gui/bazaar/package-info.java svneol=native#text/plain -src/main/java/forge/quest/gui/main/QuestBattle.java svneol=native#text/plain -src/main/java/forge/quest/gui/main/QuestMainPanel.java svneol=native#text/plain +src/main/java/forge/quest/gui/main/QuestDuel.java svneol=native#text/plain +src/main/java/forge/quest/gui/main/QuestDuelPanel.java -text +src/main/java/forge/quest/gui/main/QuestEvent.java -text +src/main/java/forge/quest/gui/main/QuestEventManager.java svneol=native#text/plain src/main/java/forge/quest/gui/main/QuestQuest.java svneol=native#text/plain -src/main/java/forge/quest/gui/main/QuestSelectablePanel.java svneol=native#text/plain +src/main/java/forge/quest/gui/main/QuestQuestPanel.java -text +src/main/java/forge/quest/gui/main/QuestSelectablePanel.java -text src/main/java/forge/quest/gui/main/package-info.java svneol=native#text/plain src/main/java/forge/quest/gui/package-info.java svneol=native#text/plain src/main/java/forge/quest/package-info.java svneol=native#text/plain @@ -9937,7 +9932,6 @@ src/test/java/forge/GuiQuestOptionsTest.java svneol=native#text/plain src/test/java/forge/GuiWinLoseTest.java svneol=native#text/plain src/test/java/forge/PanelTest.java svneol=native#text/plain src/test/java/forge/PhaseTest.java svneol=native#text/plain -src/test/java/forge/ReadQuestAssignmentTest.java svneol=native#text/plain src/test/java/forge/RunTest.java svneol=native#text/plain src/test/java/forge/TinyTest.java svneol=native#text/plain src/test/java/forge/card/cardFactory/CardFactoryTest.java svneol=native#text/plain diff --git a/res/cardsfolder/t/temporal_isolation.txt b/res/cardsfolder/t/temporal_isolation.txt index 1b30749daa6..71b35790659 100644 --- a/res/cardsfolder/t/temporal_isolation.txt +++ b/res/cardsfolder/t/temporal_isolation.txt @@ -5,7 +5,7 @@ Text:no text K:Flash K:Enchant creature A:SP$ Attach | Cost$ 1 W | ValidTgts$ Creature | AILogic$ Curse -S:Mode$ Continuous | Affected$ Creature.EnchantedBy | AddKeyword$ Shadow | AddHiddenKeyword$ HIDDEN Prevent all damage that would be dealt by CARDNAME. | Description$ Enchanted creature has shadow. Prevent all damage that would be dealt by enchanted creature. +S:Mode$ Continuous | Affected$ Creature.EnchantedBy | AddKeyword$ Shadow & HIDDEN Prevent all damage that would be dealt by CARDNAME. | Description$ Enchanted creature has shadow. Prevent all damage that would be dealt by enchanted creature. SVar:Rarity:Common SVar:Picture:http://www.wizards.com/global/images/magic/general/temporal_isolation.jpg SetInfo:TSP|Common|http://magiccards.info/scans/en/ts/43.jpg diff --git a/res/quest/easy.txt b/res/quest/easy.txt deleted file mode 100644 index 425ea898de8..00000000000 --- a/res/quest/easy.txt +++ /dev/null @@ -1,55 +0,0 @@ -Aquaman 1 -Aragorn 1 -Bamm Bamm Rubble 1 -Barney Rubble 1 -Bart Simpson 1 -Buffy 1 -C3PO 1 -Catwoman 1 -Conan the Barbarian 1 -Cow 1 -Crocodile Dundee 1 -Da Vinci 1 -Darrin Stephens 1 -Dino 1 -Doc Holiday 1 -Elrond 1 -Fat Albert 1 -Fin Fang Foom 1 -Frankenstein 1 -Frodo 1 -Galahad 1 -Genghis Khan 1 -George of the Jungle 1 -Grampa Simpson 1 -Green Arrow 1 -Harry Potter 1 -Hercules 1 -Homer Simpson 1 -Indiana Jones 1 -Jack Sparrow 1 -James Bond 1 -Joe Kidd 1 -Kang 1 -King Arthur 1 -King Edward 1 -King Goldemar 1 -King Kong 1 -Kojak 1 -Leprechaun 1 -Magnum 1 -Ned Flanders 1 -Oberon 1 -Odin 1 -Princess Selenia 1 -Rocky 1 -Samantha Stephens 1 -Seabiscuit 1 -Sherlock Holmes 1 -Shrek 1 -Storm 1 -Tarzan 1 -Treebeard 1 -Wilma Flintstone 1 -White Knight 1 -Wyatt Earp 1 diff --git a/res/quest/hard.txt b/res/quest/hard.txt deleted file mode 100644 index b745d56afce..00000000000 --- a/res/quest/hard.txt +++ /dev/null @@ -1,119 +0,0 @@ -Abraham Lincoln 3 -Albert Einstein 3 -Alice in Wonderland 3 -Aquaman 3 -Atomic Robo 3 -Barney Rubble 3 -Bart Simpson 3 -Batman 3 -Bela Lugosi 3 -Betty Rubble 3 -Blackbeard 3 -Boba Fett 3 -Boris Karloff 3 -Boromir 3 -Bridge Troll 3 -Buffy 3 -C3PO 3 -Captain America 3 -Cave Troll 3 -Comic Book Guy 3 -Crocodile Dundee 3 -Cyclops 3 -Da Vinci 3 -Darrin Stephens 3 -Darth Vader 3 -Data 3 -Deadpool 3 -Demon 3 -Dilbert 3 -Dino 3 -Doc Holiday 3 -Doran 3 -Dream 3 -Dr No 3 -Dr Strangelove 3 -Electro 3 -Elrond 3 -Endora 3 -Ezio 3 -Fat Albert 3 -Fin Fang Foom 3 -Frankenstein 3 -Fred Flintstone 3 -Frodo 3 -Galahad 3 -Genghis Khan 3 -George of the Jungle 3 -Gimli 3 -Gold Finger 3 -Grampa Simpson 3 -Green Arrow 3 -Green Lantern 3 -Han Solo 3 -Hans 3 -Harry Potter 3 -Hellboy 3 -Hercules 3 -Hermione Granger 3 -Higgins 3 -Hobbes 3 -Homer Simpson 3 -Iceman 3 -Indiana Jones 3 -Jabba the Hut 3 -James Bond 3 -James T Kirk 3 -Joe Kidd 3 -Kang 3 -King Arthur 3 -King Edward 3 -King Kong 3 -Kojak 3 -Krypto 3 -Luke Skywalker 3 -Maggie Simpson 3 -Magneto 3 -Magnum 3 -Mister Fantastic 3 -Morpheus 3 -Mr Slate 3 -Napoleon 3 -Ned Flanders 3 -Neo 3 -Newton 3 -Oberon 3 -Odin 3 -Optimus Prime 3 -Pebbles Flintstone 3 -Picard 3 -Pointy Haired Boss 3 -Professor X 3 -R2-D2 3 -Radiant 3 -Radioactive Man 3 -Riddler 3 -Rocky 3 -Sabertooth 3 -Samantha Stephens 3 -Samwise Gamgee 3 -Saruman 3 -Scooby Doo 3 -Scotty 3 -Seabiscuit 3 -Secret Squirrel 3 -Sherlock Holmes 3 -Silver Surfer 3 -Spiderman 3 -Storm 3 -Superman 3 -Terminator 3 -The Great Gazoo 3 -Tom Bombadil 3 -Treebeard 3 -Uncle Owen 3 -Wally 3 -White Knight 3 -Wilma Flintstone 3 -Wolverine 3 -Wyatt Earp 3 diff --git a/res/quest/medium.txt b/res/quest/medium.txt deleted file mode 100644 index 01e7c73941c..00000000000 --- a/res/quest/medium.txt +++ /dev/null @@ -1,89 +0,0 @@ -Albert Einstein 2 -Alice in Wonderland 2 -Apu Nahasapeemapetilon 2 -Aquaman 2 -Aragorn 2 -Barney Rubble 2 -Bart Simpson 2 -Boromir 2 -Buffy 2 -C3PO 2 -Captain America 2 -Catwoman 2 -Conan the Barbarian 2 -Crocodile Dundee 2 -Cyclops 2 -Da Vinci 2 -Darrin Stephens 2 -Deadpool 2 -Dino 2 -Doc Holiday 2 -Dogbert 2 -Electro 2 -Elrond 2 -Endora 2 -Eomer 2 -Fat Albert 2 -Fin Fang Foom 2 -Frankenstein 2 -Frodo 2 -Galadriel 2 -Galahad 2 -Gambit 2 -Genghis Khan 2 -George of the Jungle 2 -Gimli 2 -Grampa Simpson 2 -Green Arrow 2 -Hagrid 2 -Harry Potter 2 -Hercules 2 -Homer Simpson 2 -Indiana Jones 2 -Jack Sparrow 2 -James Bond 2 -Joe Kidd 2 -Kang 2 -King Arthur 2 -King Edward 2 -King Kong 2 -Kojak 2 -Krypto 2 -Lisa Simpson 2 -Magnum 2 -Marge Simpson 2 -Nagini 2 -Ned Flanders 2 -Neo 2 -Oberon 2 -Odin 2 -Pebbles Flintstone 2 -Pinky and the Brain 2 -Professor X 2 -Radagast 2 -Ratbert 2 -Redwall 2 -Reverend Lovejoy 2 -Rocky 2 -Samantha Stephens 2 -Samwise Gamgee 2 -Saruman 2 -Sauron 2 -Scotty 2 -Seabiscuit 2 -Sherlock Holmes 2 -Silver Samurai 2 -Spiderman 2 -Spock 2 -Storm 2 -Sun Quan 2 -Swan 2 -Tarzan 2 -The Thing 2 -Totoro 2 -Treebeard 2 -Walle 2 -White Knight 2 -Wilma Flintstone 2 -Wonder Woman 2 -Wyatt Earp 2 diff --git a/res/quest/quests.txt b/res/quest/quests.txt deleted file mode 100644 index 74873c6ed41..00000000000 --- a/res/quest/quests.txt +++ /dev/null @@ -1,315 +0,0 @@ -Notes -- A [quest] line triggers a new quest object. -- Properties can be in any order -- IDs are mandatory, and must be sequential. -- Any other property, if empty, will use a default value. -- Both AI and human can have extra legal cards and/or tokens at match start. - -[quest] -id=1 -Icon=Dungeon Crawling White.jpg -Title=Dungeon Crawling (White) -Desc=This realm is guarded by a divine entity laying his protecting hand on each living being. -Diff=Medium -AILife=25 -Repeat=true -Wins=20 -Card Reward=3 white rares -Credit Reward=100 -HumanExtras= -AIExtras=Divine Presence - -[quest] -id=2 -Icon=Dungeon Crawling Blue.jpg -Title=Dungeon Crawling (Blue) -Desc=This realm holds knowledge so vast it can overburden the unwary. -Diff=Medium -AILife=25 -Repeat=true -Wins=20 -Card Reward=3 blue rares -Credit Reward=100 -HumanExtras=Quest for Ancient Secrets -AIExtras=Forced Fruition - -[quest] -id=3 -Icon=Dungeon Crawling Black.jpg -Title=Dungeon Crawling (Black) -Desc=The dead cannot be silenced, and want you to join their ranks. -Diff=Medium -AILife=25 -Repeat=true -Wins=20 -Card Reward=3 black rares -Credit Reward=100 -HumanExtras= -AIExtras=Infernal Genesis - -[quest] -id=4 -Icon=Dungeon Crawling Red.jpg -Title=Dungeon Crawling (Red) -Desc=Untold treasure awaits you, should you successfully dodge the lightning and lava. -Diff=Medium -AILife=25 -Repeat=true -Wins=20 -Card Reward=3 red rares -Credit Reward=100 -HumanExtras= -AIExtras=Furnace of Rath - -[quest] -id=5 -Icon=Dungeon Crawling Green.jpg -Title=Dungeon Crawling (Green) -Desc=Gnarled, twisting, sinister growths slowly rend the walls in twain and try to silence all who cross their path. -Diff=Medium -AILife=25 -Repeat=true -Wins=20 -Card Reward=3 green rares -Credit Reward=100 -HumanExtras=Defense of the Heart -AIExtras=Eladamri's Vineyard|Upwelling - -[quest] -id=6 -Icon=Dungeon Crawling Colorless.jpg -Title=Dungeon Crawling (Colorless) -Desc=The inhabitants of this plane tread with a light step. -Diff=Hard -AILife=30 -Repeat=true -Wins=28 -Card Reward=3 colorless rares -Credit Reward=150 -HumanExtras= -AIExtras=Eon Hub|Eon Hub|Eon Hub - -[quest] -id=7 -Icon=Dungeon Crawling Gold.jpg -Title=Dungeon Crawling (Gold) -Desc=Clever sorcerers draw energy from countless sources - can you outwit them? -Diff=Hard -AILife=30 -Repeat=true -Wins=28 -Card Reward=3 multi-colored rares -Credit Reward=150 -HumanExtras= -AIExtras=Darksteel Ingot - -[quest] -id=8 -Icon=A Wolf in Sheeps Clothing.jpg -Title=A Wolf in Sheep's Clothing -Desc=The local sheep farm is under attack by a pack of wolves. Kill the wolves, save the sheep! -Diff=Medium -AILife=25 -Repeat=false -Wins=28 -Card Reward=3 random rares -Credit Reward=200 -HumanExtras=TOKEN;G;0;1;Sheep;Creature;Sheep|TOKEN;G;0;1;Sheep;Creature;Sheep|TOKEN;G;0;1;Sheep;Creature;Sheep -AIExtras= - -[quest] -id=9 -Icon=Bushwhacked.jpg -Title=Bushwhacked! -Desc=You find yourself surrounded by carnivorous plants and poisonous vines. Cut your way out of this foresty mess and make it home safe. -Diff=Hard -AILife=30 -Repeat=false -Wins=40 -Card Reward=4 green rares -Credit Reward=225 -HumanExtras=Trusty Machete -AIExtras=Wall of Wood|Wall of Wood|Wall of Wood - -[quest] -id=10 -Icon=Zombie Attack.jpg -Title=Zombie Attack! -Desc=The village of Haven is getting attacked by the Zombie horde! Protect the village. -Diff=Hard -AILife=30 -Repeat=false -Wins=40 -Card Reward=4 black rares -Credit Reward=200 -HumanExtras=TOKEN;W;1;1;Citizen;Creature|TOKEN;W;1;1;Citizen;Creature|TOKEN;W;1;1;Citizen;Creature|Wall of Spears -AIExtras=Scathe Zombies|Mass of Ghouls - -[quest] -id=11 -Icon=The Kings Contest.jpg -Title=The King's Contest -Desc=The king is holding a contest. You are invited to participate and compete against other legends of this era. -Diff=Hard -AILife=30 -Repeat=false -Wins=40 -Card Reward=3 random rares -Credit Reward=150 -HumanExtras=Seal of Cleansing -AIExtras=Loyal Retainers - -[quest] -id=12 -Icon=Barroom Brawl.jpg -Title=Barroom Brawl -Desc=A drunken giant of a man takes a swing at you, your brew spills and a fight breaks out. -Diff=Hard -AILife=30 -Repeat=false -Wins=64 -Card Reward=4 random rares -Credit Reward=250 -HumanExtras=TOKEN;W;1;1;Soldier Ally;Creature;Soldier;Ally|TOKEN;W;1;1;Soldier Ally;Creature;Soldier;Ally|TOKEN;W;1;1;Soldier Ally;Creature;Soldier;Ally -AIExtras=Lowland Giant - -[quest] -id=13 -Icon=The Court Jester.jpg -Title=The Court Jester -Desc=The Court Jester pulls a prank on you. Will you laugh it off or pay him back? -Diff=Hard -AILife=30 -Repeat=false -Wins=52 -Card Reward=4 multi-colored rares -Credit Reward=300 -HumanExtras=Sensei's Divining Top -AIExtras=Teferi's Puzzle Box - -[quest] -id=14 -Title=Ancient Battlefield -Desc=You visit an ancient battlefield at midnight. It is overgrown and dark. You trip on a root, utter a curse and wish that you could see. -Diff=Hard -AILife=30 -Repeat=false -Wins=64 -Card Reward=4 random rares -Credit Reward=250 -Icon=Ancient Battlefield.jpg -HumanExtras=Glasses of Urza|Blight Sickle -AIExtras=Bad Moon|Wall of Brambles - -[quest] -id=15 -Title=Don't Play With Matches -Desc=The goblins are battling the elves. Those pesky elves, will they ever learn. Do not play with fire! -Diff=Hard -AILife=30 -Repeat=false -Wins=52 -Card Reward=4 red rares -Credit Reward=200 -Icon=Dont Play With Matches.jpg -HumanExtras=Mudbutton Torchrunner|Scuzzback Scrapper -AIExtras=Heedless One|Norwood Archers|Wildslayer Elves - -[quest] -id=16 -Title=Mines of Kazum Durl -Desc=While exploring a mine with a group of dwarves the mine caves in. You start to dig out and then realize that your group is not alone. -Diff=Hard -AILife=30 -Repeat=false -Wins=52 -Card Reward=4 green rares -Credit Reward=250 -Icon=Mines of Kazum Durl.jpg -HumanExtras=Dwarven Demolition Team|Dwarven Pony|Dwarven Trader -AIExtras=Wall of Earth|Wall of Air|Wall of Ice|Wall of Light|Carrion Wall|Steel Wall - -[quest] -id=17 -Title=House Party -Desc=Your friends decide to hold a house party at your home tonight. Later that night uninvited guests show up and disrupt the party. -Diff=Hard -AILife=30 -Repeat=false -Wins=64 -Card Reward=4 colorless rares -Credit Reward=250 -Icon=House Party.jpg -HumanExtras=Hopping Automaton|Honden of Life's Web|Forbidden Orchard -AIExtras=Honden of Infinite Rage|Mikokoro, Center of the Sea - -[quest] -id=18 -Title=Crows in the Field -Desc=Crows are eating the seed planted in the local farm fields. The farmers are scared. Those crows are big, you will need some help. -Diff=Hard -AILife=30 -Repeat=false -Wins=64 -Card Reward=5 random rares -Credit Reward=300 -Icon=Crows in the Field.jpg -HumanExtras=Straw Soldiers|Femeref Archers|Moonglove Extract -AIExtras=Defiant Falcon|Soulcatcher|Storm Crow|Hypnotic Specter - -[quest] -id=19 -Title=The Desert Caravan -Desc=A caravan is transporting silk across the desert. While setting up camp for the night you are attacked by thieves. Defend yourself. -Diff=Hard -AILife=30 -Repeat=false -Wins=80 -Card Reward=5 random rares -Credit Reward=300 -Icon=The Desert Caravan.jpg -HumanExtras=Spidersilk Net|Dromad Purebred -AIExtras=Ambush Party|Ambush Party|Ambush Party|Ambush Party|Gnat Alley Creeper - - -[quest] -id=20 -Title=Blood Oath -Desc=A druid saves your life and the two of you take a blood oath. It is now time to fulfill your oath. -Diff=Hard -AILife=30 -Repeat=false -Wins=80 -Card Reward=5 colorless rares -Credit Reward=300 -Icon=Blood Oath.jpg -HumanExtras=Counterbalance|Hatching Plans|Ley Druid -AIExtras=Ior Ruin Expedition|Oversold Cemetery|Trapjaw Kelpie - -[quest] -id=21 -Title=Private Domain -Desc=During your travels, you accidentally stumble upon the domain of an evil, powerful wizard. A fight to the death ensues. -Diff=Expert -AILife=50 -Repeat=false -Wins=96 -Card Reward=6 random rares -Credit Reward=500 -Icon=Private Domain.jpg -HumanExtras=Strip Mine -AIExtras=Plains|Island|Mountain|Swamp|Forest - -[quest] -id=22 -Title=The Pied Piper -Desc=A mysterious man threatens to flood the land with a relentless stream of hungry rats. Cross his plan before it's too late. -Diff=Hard -AILife=30 -Repeat=false -Wins=32 -Card Reward=3 random rares -Credit Reward=150 -Icon=The Pied Piper.jpg -HumanExtras=Volunteer Militia|Land Tax|Elvish Farmer|An-Havva Township -AIExtras=Darksteel Citadel|Relentless Rats \ No newline at end of file diff --git a/res/quest/veryhard.txt b/res/quest/veryhard.txt deleted file mode 100644 index 5c93adc634f..00000000000 --- a/res/quest/veryhard.txt +++ /dev/null @@ -1,9 +0,0 @@ -Boromir 4 -Darrin Stephens 4 -Dino 4 -Gold Finger 4 -Hobbes 4 -Ned Flanders 4 -Radioactive Man 4 -Riddler 4 -Samantha Stephens 4 \ No newline at end of file diff --git a/src/main/java/forge/AllZone.java b/src/main/java/forge/AllZone.java index 41fe213057a..d74209b8385 100644 --- a/src/main/java/forge/AllZone.java +++ b/src/main/java/forge/AllZone.java @@ -17,6 +17,7 @@ import forge.properties.ForgeProps; import forge.properties.NewConstants; import forge.quest.data.QuestMatchState; import forge.quest.data.QuestData; +import forge.quest.gui.main.QuestQuest; /** * Please use public getters and setters instead of direct field access. @@ -42,7 +43,7 @@ public final class AllZone implements NewConstants { private static forge.quest.data.QuestData questData = null; /** Global QuestAssignment. */ - private static Quest_Assignment questAssignment = null; + private static QuestQuest questquest = null; /** Constant NAME_CHANGER. */ private static final NameChanger NAME_CHANGER = new NameChanger(); @@ -136,8 +137,8 @@ public final class AllZone implements NewConstants { * @return a {@link forge.Quest_Assignment} object. * @since 1.0.15 */ - public static Quest_Assignment getQuestAssignment() { - return questAssignment; + public static QuestQuest getQuestQuest() { + return questquest; } /** @@ -146,8 +147,8 @@ public final class AllZone implements NewConstants { * @param assignment a {@link forge.Quest_Assignment} object. * @since 1.0.15 */ - public static void setQuestAssignment(final Quest_Assignment assignment) { - questAssignment = assignment; + public static void setQuestQuest(final QuestQuest q) { + questquest = q; } /** diff --git a/src/main/java/forge/GameAction.java b/src/main/java/forge/GameAction.java index 53f5725ca70..de603e648c2 100644 --- a/src/main/java/forge/GameAction.java +++ b/src/main/java/forge/GameAction.java @@ -29,6 +29,7 @@ import forge.gui.input.Input_PayManaCost_Ability; import forge.item.CardPrinted; import forge.properties.ForgeProps; import forge.properties.NewConstants.LANG.GameAction.GAMEACTION_TEXT; +import forge.quest.gui.main.QuestQuest; import java.util.ArrayList; import java.util.Comparator; @@ -653,7 +654,7 @@ public class GameAction { AllZone.getDisplay().savePrefs(); frame.setEnabled(false); //frame.dispose(); - Gui_WinLose gwl = new Gui_WinLose(AllZone.getMatchState(), AllZone.getQuestData(), AllZone.getQuestAssignment()); + Gui_WinLose gwl = new Gui_WinLose(AllZone.getMatchState(), AllZone.getQuestData(), AllZone.getQuestQuest()); //gwl.setAlwaysOnTop(true); gwl.toFront(); canShowWinLose = false; @@ -1074,15 +1075,15 @@ public class GameAction { * @param computer a {@link forge.CardList} object. */ public final void newGame(final Deck humanDeck, final Deck computerDeck, final CardList human, - final CardList computer, final int humanLife, final int computerLife, final Quest_Assignment qa) + final CardList computer, final int humanLife, final int computerLife, final QuestQuest qq) { this.newGame(humanDeck, computerDeck); AllZone.getComputerPlayer().setLife(computerLife, null); AllZone.getHumanPlayer().setLife(humanLife, null); - if (qa != null) { - computer.addAll(forge.quest.data.QuestUtil.getComputerStartingCards(AllZone.getQuestData(), AllZone.getQuestAssignment())); + if (qq != null) { + computer.addAll(forge.quest.data.QuestUtil.getComputerStartingCards(AllZone.getQuestData(), AllZone.getQuestQuest())); } for (Card c : human) { diff --git a/src/main/java/forge/Gui_WinLose.java b/src/main/java/forge/Gui_WinLose.java index e31613c67e7..43b48e13f1f 100644 --- a/src/main/java/forge/Gui_WinLose.java +++ b/src/main/java/forge/Gui_WinLose.java @@ -17,6 +17,7 @@ import forge.quest.data.QuestData; import forge.quest.data.QuestMatchState; import forge.quest.data.QuestPreferences; import forge.quest.gui.QuestFrame; +import forge.quest.gui.main.QuestQuest; import forge.view.swing.OldGuiNewGame; import net.miginfocom.swing.MigLayout; @@ -65,7 +66,7 @@ public class Gui_WinLose extends JFrame implements NewConstants { private class WinLoseModel { public QuestMatchState match; public QuestData quest; - public Quest_Assignment qa; + public QuestQuest qq; } private WinLoseModel model; @@ -77,11 +78,11 @@ public class Gui_WinLose extends JFrame implements NewConstants { * @param quest a QuestData object * @param qa a Quest_Assignment object */ - public Gui_WinLose(final QuestMatchState matchState, final QuestData quest, final Quest_Assignment qa) { + public Gui_WinLose(final QuestMatchState matchState, final QuestData quest, final QuestQuest qq) { model = new WinLoseModel(); model.match = matchState; model.quest = quest; - model.qa = qa; + model.qq = qq; try { jbInit(); @@ -186,25 +187,25 @@ public class Gui_WinLose extends JFrame implements NewConstants { void prepareForNextRound() { if (Constant.Quest.fantasyQuest[0]) { int extraLife = 0; - if (model.qa != null) { + if (model.qq != null) { if (model.quest.getInventory().hasItem("Zeppelin")) { extraLife = 3; } } //AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], //humanList, computerList, humanLife, computerLife); - CardList humanList = forge.quest.data.QuestUtil.getHumanStartingCards(model.quest, model.qa); + CardList humanList = forge.quest.data.QuestUtil.getHumanStartingCards(model.quest, model.qq); CardList computerList = new CardList(); int humanLife = model.quest.getLife() + extraLife; int computerLife = 20; - if (model.qa != null) { - computerLife = model.qa.getComputerLife(); + if (model.qq != null) { + computerLife = model.qq.getAILife(); } AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], - humanList, computerList, humanLife, computerLife, model.qa); + humanList, computerList, humanLife, computerLife, model.qq); } else { AllZone.getGameAction().newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]); } @@ -362,7 +363,7 @@ public class Gui_WinLose extends JFrame implements NewConstants { giveQuestRewards(wonMatch); model.match.reset(); - AllZone.setQuestAssignment(null); + AllZone.setQuestQuest(null); model.quest.saveData(); @@ -440,11 +441,11 @@ public class Gui_WinLose extends JFrame implements NewConstants { } // Rewards from QuestAssignment - if (wonMatch && model.qa != null) { + if (wonMatch && model.qq != null) { model.quest.addQuestsPlayed(); - List questRewardCards = model.qa.getCardRewardList(); - long questRewardCredits = model.qa.getCreditsReward(); + List questRewardCards = model.qq.getCardRewardList(); + long questRewardCredits = model.qq.getCreditsReward(); StringBuilder sb = new StringBuilder(); sb.append("Quest Completed - \r\n"); @@ -465,7 +466,7 @@ public class Gui_WinLose extends JFrame implements NewConstants { String fileName = "BoxIcon.png"; ImageIcon icon = getIcon(fileName); - String title = "Quest Rewards for " + model.qa.getName(); + String title = "Quest Rewards for " + model.qq.getTitle(); JOptionPane.showMessageDialog(null, sb.toString(), title, JOptionPane.INFORMATION_MESSAGE, icon); } /* diff --git a/src/main/java/forge/Quest_Assignment.java b/src/main/java/forge/Quest_Assignment.java deleted file mode 100644 index c5e7dddd13e..00000000000 --- a/src/main/java/forge/Quest_Assignment.java +++ /dev/null @@ -1,289 +0,0 @@ -package forge; - -import java.util.ArrayList; -import java.util.List; - -import forge.item.CardPrinted; - -/** - *

Quest_Assignment class.

- * An instance of a single quest assignment. Holds values that aren't defined in - * Deck class, such as credit reward. - * - * @author Forge - * @version $Id$ - */ -public class Quest_Assignment { - // ID (default -1, should be explicitly set at later time.) - private int id = -1; - - // Default vals if none provided for this ID in quests.txt. - private int requiredNumberWins = 20; - private int computerLife = 25; - private long creditsReward = 100; - private String name = "Mystery Quest"; - private String desc = ""; - private String difficulty = "Medium"; - private String cardReward = "1 colorless rare"; - private String iconName = "Unknown.jpg"; - private boolean repeatable = false; - - // Other cards used in assignment: starting, and reward. - private CardList humanExtraCards = new CardList(); - private CardList aiExtraCards = new CardList(); - private List cardRewardList = new ArrayList(); - - // No constructor required; fields are set dynamically. - - // Setters and getters, in alphabetical order. - - /** - *

Setter for the field aiExtraCards.

- * Sets list of cards automatically played at start of match. - * - * @param s a CardList object. - */ - public final void setAIExtraCards(final CardList cl) { - this.aiExtraCards = cl; - } - - /** - *

Getter for the field aiExtraCards.

- * Gets list of cards automatically played at start of match. - * - * @return a {@link java.util.ArrayList} object. - */ - public final CardList getAIExtraCards() { - return aiExtraCards; - } - /** - *

Setter for the field cardReward.

- * Sets string notated card reward received if match is won. - * - * @param cardRewardIn a {@link java.lang.String} object. - */ - public final void setCardReward(final String cardRewardIn) { - this.cardReward = cardRewardIn; - } - - /** - *

Getter for the field cardReward.

- * Gets string notated card reward received if match is won. - * - * @return a {@link java.lang.String} object. - */ - public final String getCardReward() { - return cardReward; - } - - /** - *

Setter for the field cardRewardList.

- * Sets card reward list for cards received if match is won. - * - * @return a {@link java.util.ArrayList} object. - */ - public void setCardRewardList(final List cp) { - this.cardRewardList = cp; - } - - /** - *

Getter for the field cardRewardList.

- * Gets card reward list for cards received if match is won. - * - * @return a {@link java.util.ArrayList} object. - */ - public final List getCardRewardList() { - return cardRewardList; - } - - /** - *

Setter for the field computerLife.

- * Sets computer life at start of match. - * - * @param computerLifeIn a int. - */ - public final void setComputerLife(final int computerLifeIn) { - this.computerLife = computerLifeIn; - } - - /** - *

Getter for the field computerLife.

- * Gets computer life at start of match. - * - * @return a int. - */ - public final int getComputerLife() { - return computerLife; - } - - /** - *

Setter for the field creditsReward.

- * Sets credit reward received if match is won. - * - * @param creditsRewardIn a long. - */ - public final void setCreditsReward(final long creditsRewardIn) { - this.creditsReward = creditsRewardIn; - } - - /** - *

Getter for the field creditsReward.

- * Gets credit reward received if match is won. - * - * @return a long. - */ - public final long getCreditsReward() { - return creditsReward; - } - - /** - *

Setter for the field desc.

- * - * @param descIn a {@link java.lang.String} object. - */ - public final void setDesc(final String descIn) { - this.desc = descIn; - } - - /** - *

Getter for the field desc.

- * - * @return a {@link java.lang.String} object. - */ - public final String getDesc() { - return desc; - } - - /** - *

Setter for the field difficulty.

- * - * @param difficultyIn a {@link java.lang.String} object. - */ - public final void setDifficulty(final String difficultyIn) { - this.difficulty = difficultyIn; - } - - /** - *

Setter for the field humanExtraCards.

- * Sets list of cards automatically played at start of match. - * - * @param s a CardList object. - */ - public final void setHumanExtraCards(final CardList cl) { - this.humanExtraCards = cl; - } - - /** - *

Getter for the field humanExtraCards.

- * Gets list of cards automatically played at start of match. - * - * @return a {@link forge.CardList} object. - */ - public final CardList getHumanExtraCards() { - return humanExtraCards; - } - - /** - *

Getter for the field difficulty.

- * - * @return a {@link java.lang.String} object. - */ - public final String getDifficulty() { - return difficulty; - } - - /** - *

Setter for the field id.

- * - * @param idIn a int. - */ - public final void setId(final int idIn) { - this.id = idIn; - } - - /** - *

Getter for the field id.

- * - * @return a int. - */ - public final int getId() { - return id; - } - - /** - *

Setter for the field iconName.

- * Sets filename of icon used when displaying this quest. - * - * @param s a {@link java.lang.String} object. - */ - public final void setIconName(final String s) { - iconName = s; - } - - /** - *

Getter for the field iconName.

- * Gets filename of icon used when displaying this quest. - * - * @return a {@link java.lang.String} object. - */ - public final String getIconName() { - return iconName; - } - - /** - *

Setter for the field name.

- * - * @param nameIn a {@link java.lang.String} object. - */ - public final void setName(final String nameIn) { - this.name = nameIn; - } - - /** - *

Getter for the field name.

- * - * @return a {@link java.lang.String} object. - */ - public final String getName() { - return name; - } - - /** - *

Setter for the field repeatable.

- * - * @param repeatableIn a boolean. - */ - public final void setRepeatable(final boolean repeatableIn) { - this.repeatable = repeatableIn; - } - - /** - *

isRepeatable.

- * - * @return a boolean. - */ - public final boolean isRepeatable() { - return repeatable; - } - - /** - *

Setter for the field requiredNumberWins.

- * Sets number of wins required to unlock this quest. - * - * @param requiredNumberWinsIn a int. - */ - public final void setRequiredNumberWins(final int requiredNumberWinsIn) { - this.requiredNumberWins = requiredNumberWinsIn; - } - - /** - *

Getter for the field requiredNumberWins.

- * Gets number of wins required to unlock this quest. - * - * @return a int. - */ - public final int getRequiredNumberWins() { - return requiredNumberWins; - } - -} diff --git a/src/main/java/forge/ReadQuest_Assignment.java b/src/main/java/forge/ReadQuest_Assignment.java deleted file mode 100644 index f247fcdc481..00000000000 --- a/src/main/java/forge/ReadQuest_Assignment.java +++ /dev/null @@ -1,278 +0,0 @@ -package forge; - -import forge.error.ErrorViewer; -import forge.properties.NewConstants; -import forge.quest.data.QuestUtil; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - *

ReadQuest_Assignment class.

- * - * @author Forge - * @version $Id$ - */ -public class ReadQuest_Assignment implements Runnable, NewConstants { - - ArrayList allQuests = new ArrayList(); - private ArrayList ids = new ArrayList(); - - private BufferedReader br; - private int totalWins; - private List completedQuests = new ArrayList(); - - // Constants, tied to properties in the quests.txt file. - private static final String ID = "id"; - private static final String ICON = "Icon"; - private static final String TITLE = "Title"; - private static final String DESC = "Desc"; - private static final String DIFF = "Diff"; - private static final String AILIFE = "AILife"; - private static final String REPEAT = "Repeat"; - private static final String WINS = "Wins"; - private static final String CARDS = "Card Reward"; - private static final String CREDITS = "Credit Reward"; - private static final String HUMANEXTRAS = "HumanExtras"; - private static final String AIEXTRAS = "AIExtras"; - - /** - *

Constructor for ReadQuest_Assignment.

- * Sets parameters for available quests and prepares buffered reader for quests.txt. - * - * @param filename a {@link java.lang.String} object. - * @param questData a {@link forge.quest.data.QuestData} object. - */ - public ReadQuest_Assignment(String filename, forge.quest.data.QuestData questData) { - this(new File(filename), questData); - } - - /** - *

Constructor for ReadQuest_Assignment.

- * Sets parameters for available quests and prepares buffered reader for quests.txt. - * - * @param file a {@link java.io.File} object. - * @param questData a {@link forge.quest.data.QuestData} object. - */ - public ReadQuest_Assignment(File file, forge.quest.data.QuestData questData) { - if (questData != null) { - totalWins = questData.getWin(); - if (questData.getCompletedQuests() != null) { - completedQuests = questData.getCompletedQuests(); - } - else { - completedQuests = new ArrayList(); - } - } - - try { - br = new BufferedReader(new FileReader(file)); - } catch (Exception ex) { - ErrorViewer.showError(ex, "File \"%s\" not found", file.getAbsolutePath()); - throw new RuntimeException("ReadQuest_Assignment > constructor error: "+ - "BufferedReader failed, '"+file.getAbsolutePath()+"' not found."); - } - } // ReadQuest_Assignment() - - /** - *

getAvailableQuests.

- * Returns list of currently available quest objects. - * - * @return a {@link java.util.List} object. - */ - public List getAvailableQuests() { - ArrayList availableQuests = new ArrayList(); - - for(Quest_Assignment qa : allQuests) { - if (qa.getRequiredNumberWins() <= totalWins && !completedQuests.contains(qa.getId())) { - availableQuests.add(qa); - } - } - - return availableQuests; - } - - /** - *

getQuests.

- * Returns complete list of all quest objects. - * - * @return a {@link java.util.List} object. - */ - public List getAllQuests() { - return allQuests; - } - - /** - *

getQuestsByIds.

- * - * @param availableQuestIds a {@link java.util.List} object. - * @return a {@link java.util.List} object. - */ - public List getQuestsByIds(List availableQuestIds) { - List q = new ArrayList(); - - for (Quest_Assignment qa : allQuests) { - if (availableQuestIds.contains(qa.getId())) { - q.add(qa); - } - } - - return q; - } - - /** - *

getQuestById.

- * - * @param i a int. - * @return a {@link forge.Quest_Assignment} object. - */ - public Quest_Assignment getQuestById(int id) { - // Error handling for OOB ID? - return allQuests.get(id); - } - - /** - *

run.

- * Assembles Quest_Assignment instances into allQuests. - */ - public void run() { - Quest_Assignment qa = null; - String line; - int i; - String[] linedata; - - try { - while ((line = br.readLine()) != null) { - if(line.equals("[quest]")) { - qa = new Quest_Assignment(); - allQuests.add(qa); - } - else if(!line.equals("") && qa != null) { - linedata = line.split("=", 2); - linedata[1] = linedata[1].trim(); - - // If empty data, ignore the line (assignment will use default). - if(linedata[1].equals("")) { - continue; - } - - // Data OK. - if(linedata[0].equals(ID)) { - i = Integer.parseInt(linedata[1]); - - // Duplicate ID check - if(ids.contains(i)) { - throw new RuntimeException("ReadQuest_Assignment > run() error: duplicate quest ID ("+i+")"); - } - // Non-sequential ID check - else if(i != allQuests.size()) { - throw new RuntimeException("ReadQuest_Assignment > run() error: non-sequential quest ID ("+i+")"); - } - // ID OK. - else { - ids.add(i); - qa.setId(i); - } - } - else if(linedata[0].equals(ICON)) { - qa.setIconName(linedata[1]); - } - else if(linedata[0].equals(TITLE)) { - qa.setName(linedata[1]); - } - else if(linedata[0].equals(DESC)) { - qa.setDesc(linedata[1]); - } - else if(linedata[0].equals(DIFF)) { - qa.setDifficulty(linedata[1]); - } - else if(linedata[0].equals(REPEAT)) { - qa.setRepeatable(Boolean.parseBoolean(linedata[1])); - } - else if(linedata[0].equals(AILIFE)) { - qa.setComputerLife(Integer.parseInt(linedata[1])); - } - else if(linedata[0].equals(WINS)) { - qa.setRequiredNumberWins(Integer.parseInt(linedata[1])); - } - else if(linedata[0].equals(CREDITS)) { - qa.setCreditsReward(Integer.parseInt(linedata[1])); - } - // Card reward list assembled here. - else if(linedata[0].equals(CARDS)) { - qa.setCardReward(linedata[1]); - qa.setCardRewardList(QuestUtil.generateCardRewardList(linedata[1])); - } - // Human extra card list assembled here. - else if(linedata[0].equals(HUMANEXTRAS)) { - String[] names = linedata[1].split("\\|"); - CardList templist = new CardList(); - Card tempcard; - - for(String s : names) { - // Token card creation - if(s.substring(0,5).equals("TOKEN")) { - tempcard = QuestUtil.createToken(s); - tempcard.addController(AllZone.getHumanPlayer()); - tempcard.setOwner(AllZone.getHumanPlayer()); - templist.add(tempcard); - } - // Standard card creation - else { - tempcard = AllZone.getCardFactory().getCard(s, AllZone.getHumanPlayer()); - tempcard.setCurSetCode(tempcard.getMostRecentSet()); - tempcard.setImageFilename(CardUtil.buildFilename(tempcard)); - templist.add(tempcard); - } - } - - qa.setHumanExtraCards(templist); - } - // AI extra card list assembled here. - else if(linedata[0].equals(AIEXTRAS)) { - String[] names = linedata[1].split("\\|"); - CardList templist = new CardList(); - Card tempcard; - - for(String s : names) { - // Token card creation - if(s.substring(0,5).equals("TOKEN")) { - tempcard = QuestUtil.createToken(s); - tempcard.addController(AllZone.getComputerPlayer()); - tempcard.setOwner(AllZone.getComputerPlayer()); - templist.add(tempcard); - } - // Standard card creation - else { - tempcard = AllZone.getCardFactory().getCard(s, AllZone.getComputerPlayer()); - tempcard.setCurSetCode(tempcard.getMostRecentSet()); - tempcard.setImageFilename(CardUtil.buildFilename(tempcard)); - templist.add(tempcard); - } - } - - qa.setAIExtraCards(templist); - } - } // else if() - } // while() - - br.close(); - } - catch (IOException e) { - e.printStackTrace(); - } - - // Confirm that all quests have IDs. - for(Quest_Assignment q : allQuests) { - if(q.getId()==-1) { - throw new RuntimeException("ReadQuest_Assignment > getQuests() error: "+ - "Quest ID missing for '"+q.getName()+"'."); - } - } - - } // run() -} diff --git a/src/main/java/forge/card/BoosterUtils.java b/src/main/java/forge/card/BoosterUtils.java index ba8883071a6..7d6b8df9c95 100644 --- a/src/main/java/forge/card/BoosterUtils.java +++ b/src/main/java/forge/card/BoosterUtils.java @@ -53,7 +53,7 @@ public final class BoosterUtils { int nRares = numRare, nMythics = 0; Predicate filterMythics = Predicate.and(filter, CardPrinted.Predicates.Presets.isMythicRare); - boolean haveMythics = filterMythics.any(cardpool); + boolean haveMythics = false;//filterMythics.any(cardpool); for(int iSlot = 0; haveMythics && iSlot < numRare; iSlot++) { if (MyRandom.random.nextInt(7) < 1) { // a bit higher chance to get a mythic nRares--; diff --git a/src/main/java/forge/game/limited/package-info.java b/src/main/java/forge/game/limited/package-info.java index 858872b6fae..a8e7e05b8a1 100644 --- a/src/main/java/forge/game/limited/package-info.java +++ b/src/main/java/forge/game/limited/package-info.java @@ -1,2 +1,2 @@ -/** Forge Card Game */ -package forge.game.limited; +/** Forge Card Game */ +package forge.game.limited; diff --git a/src/main/java/forge/quest/data/QuestBattleManager.java b/src/main/java/forge/quest/data/QuestBattleManager.java deleted file mode 100644 index 97c2f887b4f..00000000000 --- a/src/main/java/forge/quest/data/QuestBattleManager.java +++ /dev/null @@ -1,194 +0,0 @@ -package forge.quest.data; - -import forge.AllZone; -import forge.FileUtil; -import forge.deck.Deck; -import forge.deck.DeckManager; -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - -import java.io.File; -import java.util.*; - -import org.apache.commons.lang3.StringUtils; - -/** - *

QuestBattleManager class.

- * - * @author Forge - * @version $Id$ - */ -public class QuestBattleManager { - /** Constant easyAIDecks */ - private static transient List easyAIDecks; - /** Constant mediumAIDecks */ - private static transient List mediumAIDecks; - /** Constant hardAIDecks */ - private static transient List hardAIDecks; - /** Constant veryHardAIDecks */ - private static transient List veryHardAIDecks; - - static { - easyAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.EASY)); - mediumAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.MEDIUM)); - hardAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.HARD)); - veryHardAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.VERYHARD)); - } - - /** - *

getOpponent.

- * - * Badly named; AllZoneUtil already has a method called getOpponents. - * ????? - * - * @param aiDeck a {@link java.util.List} object. - * @param number a int. - * @return a {@link java.lang.String} object. - */ - public static String getOpponent(List aiDeck, int number) { - //This is to make sure that the opponents do not change when the deck editor is launched. - List deckListCopy = new ArrayList(aiDeck); - Collections.shuffle(deckListCopy, new Random(AllZone.getQuestData().getRandomSeed())); - - return deckListCopy.get(number); - } - - - /** - *

generateBattles.

- * Generates an array of new opponents based on current win conditions. - * - * @return an array of {@link java.lang.String} objects. - */ - public static String[] generateBattles() { - int index = AllZone.getQuestData().getDifficultyIndex(); - - if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForMediumAI(index)) { - return new String[]{ - getOpponent(easyAIDecks, 0), - getOpponent(easyAIDecks, 1), - getOpponent(easyAIDecks, 2)}; - } - - if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForMediumAI(index)) { - return new String[]{ - getOpponent(easyAIDecks, 0), - getOpponent(mediumAIDecks, 0), - getOpponent(mediumAIDecks, 1)}; - } - - if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForHardAI(index)) { - return new String[]{ - getOpponent(mediumAIDecks, 0), - getOpponent(mediumAIDecks, 1), - getOpponent(mediumAIDecks, 2)}; - } - - if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForHardAI(index)) { - return new String[]{ - getOpponent(mediumAIDecks, 0), - getOpponent(hardAIDecks, 0), - getOpponent(hardAIDecks, 1)}; - } - - if (AllZone.getQuestData().getWin() >= QuestPreferences.getWinsForVeryHardAI(index)) { - return new String[]{ - getOpponent(hardAIDecks, 0), - getOpponent(hardAIDecks, 1), - getOpponent(veryHardAIDecks, 0)}; - } - - return new String[]{ - getOpponent(hardAIDecks, 0), - getOpponent(hardAIDecks, 1), - getOpponent(hardAIDecks, 2)}; - } - - /** - *

getDeckFromFile.

- * Returns a deck object built from a file name. - * - * @param deckName a {@link java.lang.String} object. - * @return a {@link forge.deck.Deck} object. - */ - public static Deck getAIDeckFromFile(String deckName) { - final File file = ForgeProps.getFile(NewConstants.QUEST.DECKS); - final DeckManager manager = new DeckManager(file); - return manager.getDeck(deckName); - } - - /** - *

getQuestEventFromFile.

- * Returns QuestEvent data for the challenge stored in that file name. - * - * @param deckName a {@link java.lang.String} object. - * @return a {@link forge.deck.Deck} object. - */ - public static QuestEvent getQuestEventFromFile(String deckName) { - final File deckPath = ForgeProps.getFile(NewConstants.QUEST.DECKS); - File deckFile = new File(deckPath, deckName + ".dck"); - - QuestEvent result = readQuestBattleMetadataFromDeckFile(deckFile); - return result; - } - - /** - *

readFile.

- * A reader util for accessing the AI deck list text files. - * - * @param file a {@link java.io.File} object. - * @param aiDecks a {@link java.util.List} object. - * @return a {@link java.util.List} object. - */ - private static List readFile(File file) { - ArrayList list = FileUtil.readFile(file); - - //remove any blank lines - ArrayList noBlankLines = new ArrayList(); - String s; - for (String aList : list) { - s = aList.trim(); - if (!s.equals("")) { - noBlankLines.add(s); - } - } - list = noBlankLines; - - if (list.size() < 3) { - ErrorViewer.showError(new Exception(), - "QuestData : readFile() error, file %s is too short, it must contain at least 3 ai deck names", - file); - } - - return list; - } - - private static QuestEvent readQuestBattleMetadataFromDeckFile(final File f) { - QuestEvent out = new QuestEvent(); - List contents = FileUtil.readFile(f); - - for (String s : contents) { - if ("[main]".equals(s)) { break; } - if (StringUtils.isBlank(s) || s.charAt(0) == '[') { continue; } - - int eqPos = s.indexOf('='); - if (eqPos < 0) { continue; } // no equals sign here - String key = s.substring(0, eqPos); - String value = s.substring(eqPos + 1); - - if ("DisplayName".equalsIgnoreCase(key)) { - out.displayName = value; - } else if ("Difficulty".equalsIgnoreCase(key)) { - out.difficulty = value; - } else if ("Description".equalsIgnoreCase(key)) { - out.description = value; - } else if ("Icon".equalsIgnoreCase(key)) { - out.icon = value; - } - } - - return out; - } - -} diff --git a/src/main/java/forge/quest/data/QuestEvent.java b/src/main/java/forge/quest/data/QuestEvent.java deleted file mode 100644 index 7b3de62e747..00000000000 --- a/src/main/java/forge/quest/data/QuestEvent.java +++ /dev/null @@ -1,17 +0,0 @@ -package forge.quest.data; - -/** - * TODO: Write javadoc for this type. - * - */ -public class QuestEvent { - String displayName; - String difficulty; - String description; - String icon; - - public final String getDisplayName() { return displayName; } - public final String getDifficulty() { return difficulty; } - public final String getDescription() { return description; } - public final String getIcon() { return icon; } -} diff --git a/src/main/java/forge/quest/data/QuestUtil.java b/src/main/java/forge/quest/data/QuestUtil.java index 374dd4736c9..dfdf1e39845 100644 --- a/src/main/java/forge/quest/data/QuestUtil.java +++ b/src/main/java/forge/quest/data/QuestUtil.java @@ -3,21 +3,21 @@ package forge.quest.data; import forge.Card; import forge.CardList; import forge.Constant; -import forge.Quest_Assignment; import forge.card.CardRarity; import forge.card.BoosterUtils; import forge.item.CardPrinted; +import forge.quest.gui.main.QuestQuest; import java.util.List; /** *

QuestUtil class.

+ * MODEL - Static utility methods to help with minor tasks around Quest. * * @author Forge * @version $Id$ */ public class QuestUtil { - /** *

getComputerStartingCards.

* @@ -36,11 +36,11 @@ public class QuestUtil { * @param qa a {@link forge.Quest_Assignment} object. * @return a {@link forge.CardList} object. */ - public static CardList getComputerStartingCards(final QuestData qd, Quest_Assignment qa) { + public static CardList getComputerStartingCards(final QuestData qd, QuestQuest qq) { CardList list = new CardList(); - if (qa != null) { - list.addAll(qa.getAIExtraCards()); + if (qq != null) { + list.addAll(qq.getAIExtraCards()); } return list; } @@ -75,11 +75,11 @@ public class QuestUtil { * @param qa a {@link forge.Quest_Assignment} object. * @return a {@link forge.CardList} object. */ - public static CardList getHumanStartingCards(final QuestData qd, Quest_Assignment qa) { + public static CardList getHumanStartingCards(final QuestData qd, QuestQuest qq) { CardList list = getHumanStartingCards(qd); - if (qa != null) { - list.addAll(qa.getHumanExtraCards()); + if (qq != null) { + list.addAll(qq.getHumanExtraCards()); } return list; @@ -163,17 +163,5 @@ public class QuestUtil { return BoosterUtils.generateCards(qty, rar, col); } - - /** - *

setupQuest.

- * Assembled hard-coded quest options. - * All non-deck-specific handling now takes place in quests.txt. - * - * @deprecated - * @param qa - */ - public static void setupQuest(Quest_Assignment qa) { - - } } //QuestUtil diff --git a/src/main/java/forge/quest/gui/QuestFrame.java b/src/main/java/forge/quest/gui/QuestFrame.java index d72750139ce..fea70f40e95 100644 --- a/src/main/java/forge/quest/gui/QuestFrame.java +++ b/src/main/java/forge/quest/gui/QuestFrame.java @@ -3,7 +3,7 @@ package forge.quest.gui; import forge.AllZone; import forge.gui.GuiUtils; import forge.quest.gui.bazaar.QuestBazaarPanel; -import forge.quest.gui.main.QuestMainPanel; +import forge.quest.gui.main.QuestEventManager; import forge.view.swing.OldGuiNewGame; import javax.swing.*; @@ -24,6 +24,7 @@ public class QuestFrame extends JFrame { JPanel visiblePanel; CardLayout questLayout; + QuestEventManager qem = new QuestEventManager(); /** Constant MAIN_PANEL="Main" */ public static final String MAIN_PANEL = "Main"; @@ -39,7 +40,14 @@ public class QuestFrame extends JFrame { */ public QuestFrame() throws HeadlessException { this.setTitle("Quest Mode"); - + // DOUBLESTRIKE SEZ - this assembles all events, once. + // Unfortunately, QuestFrame is called several times. + // This is THE WRONG PLACE for this method, feel free to move, + // I'll do it very soon anyways, this is only a temporary thing. + if(qem.getAllDuels()==null) { + qem.assembleAllEvents(); + } + visiblePanel = new JPanel(new BorderLayout()); visiblePanel.setBorder(new EmptyBorder(2, 2, 2, 2)); questLayout = new CardLayout(); @@ -53,7 +61,6 @@ public class QuestFrame extends JFrame { visiblePanel.add(newPanel, BAZAAR_PANEL); subPanelMap.put(BAZAAR_PANEL, newPanel); - this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add(visiblePanel, BorderLayout.CENTER); this.setPreferredSize(new Dimension(1024, 768)); diff --git a/src/main/java/forge/quest/gui/main/QuestMainPanel.java b/src/main/java/forge/quest/gui/QuestMainPanel.java similarity index 86% rename from src/main/java/forge/quest/gui/main/QuestMainPanel.java rename to src/main/java/forge/quest/gui/QuestMainPanel.java index 22552117de4..89227f85cd9 100644 --- a/src/main/java/forge/quest/gui/main/QuestMainPanel.java +++ b/src/main/java/forge/quest/gui/QuestMainPanel.java @@ -1,804 +1,811 @@ -package forge.quest.gui.main; - - -import forge.*; -import forge.deck.Deck; -import forge.gui.GuiUtils; -import forge.gui.deckeditor.DeckEditorShop; -import forge.gui.deckeditor.DeckEditorQuest; -import forge.quest.data.QuestBattleManager; -import forge.quest.data.QuestData; -import forge.quest.data.item.QuestItemZeppelin; -import forge.quest.gui.QuestAbstractPanel; -import forge.quest.gui.QuestFrame; - -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import javax.swing.border.EtchedBorder; -import javax.swing.border.TitledBorder; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.*; -import java.util.List; - - -/** - *

QuestMainPanel class.

- * - * @author Forge - * @version $Id$ - */ -public class QuestMainPanel extends QuestAbstractPanel { - /** Constant serialVersionUID=6142934729724012402L */ - private static final long serialVersionUID = 6142934729724012402L; - - private forge.quest.data.QuestData questData; - - JLabel creditsLabel = new JLabel(); - JLabel lifeLabel = new JLabel(); - JLabel statsLabel = new JLabel(); - JLabel titleLabel = new JLabel(); - JLabel nextQuestLabel = new JLabel(); - - JComboBox petComboBox = new JComboBox(); - JComboBox deckComboBox = new JComboBox(); - - JButton questButton = new JButton("Quests"); - JButton playButton = new JButton("Play"); - - private QuestSelectablePanel selectedOpponent; - - JPanel nextMatchPanel = new JPanel(); - CardLayout nextMatchLayout; - - boolean isShowingQuests = false; - private JCheckBox devModeCheckBox = new JCheckBox("Developer Mode"); - //private JCheckBox newGUICheckbox = new JCheckBox("Use new UI", true); - private JCheckBox smoothLandCheckBox = new JCheckBox("Adjust AI Land"); - private JCheckBox petCheckBox = new JCheckBox("Summon Pet"); - - private JCheckBox plantBox = new JCheckBox("Summon Plant"); - /** Constant NO_DECKS_AVAILABLE="No decks available" */ - private static final String NO_DECKS_AVAILABLE = "No decks available"; - /** Constant BATTLES="Battles" */ - private static final String BATTLES = "Battles"; - /** Constant QUESTS="Quests" */ - private static final String QUESTS = "Quests"; - - //TODO: Make this ordering permanent - /** Constant lastUsedDeck="//TODO: Make this ordering permanent" */ - private static String lastUsedDeck; - private JButton zeppelinButton = new JButton("Launch
Zeppelin", - GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("ZeppelinIcon.png"), 40, 40)); - private JPanel zeppelinPanel = new JPanel(); - - /** - *

Constructor for QuestMainPanel.

- * - * @param mainFrame a {@link forge.quest.gui.QuestFrame} object. - */ - public QuestMainPanel(QuestFrame mainFrame) { - super(mainFrame); - questData = AllZone.getQuestData(); - - initUI(); - } - - /** - *

initUI.

- */ - private void initUI() { - refresh(); - this.setLayout(new BorderLayout(5, 5)); - JPanel centerPanel = new JPanel(new BorderLayout()); - this.add(centerPanel, BorderLayout.CENTER); - - JPanel northPanel = createStatusPanel(); - this.add(northPanel, BorderLayout.NORTH); - - JPanel eastPanel = createSidePanel(); - this.add(eastPanel, BorderLayout.EAST); - - JPanel matchSettingsPanel = createMatchSettingsPanel(); - centerPanel.add(matchSettingsPanel, BorderLayout.SOUTH); - - centerPanel.add(nextMatchPanel, BorderLayout.CENTER); - this.setBorder(new EmptyBorder(5, 5, 5, 5)); - - } - - /** - *

createStatusPanel.

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createStatusPanel() { - JPanel northPanel = new JPanel(); - JLabel modeLabel; - JLabel difficultyLabel;//Create labels at the top - titleLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 28)); - titleLabel.setAlignmentX(LEFT_ALIGNMENT); - northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS)); - northPanel.add(titleLabel); - - northPanel.add(Box.createVerticalStrut(5)); - - JPanel statusPanel = new JPanel(); - statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); - statusPanel.setAlignmentX(LEFT_ALIGNMENT); - - modeLabel = new JLabel(questData.getMode()); - statusPanel.add(modeLabel); - statusPanel.add(Box.createHorizontalGlue()); - - difficultyLabel = new JLabel(questData.getDifficulty()); - statusPanel.add(difficultyLabel); - statusPanel.add(Box.createHorizontalGlue()); - - statusPanel.add(statsLabel); - - northPanel.add(statusPanel); - return northPanel; - } - - /** - *

createSidePanel.

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createSidePanel() { - JPanel panel = new JPanel(); - JPanel optionsPanel; //Create options checkbox list - optionsPanel = createOptionsPanel(); - - List eastComponents = new ArrayList(); - //Create buttons - - JButton mainMenuButton = new JButton("Return to Main Menu"); - mainMenuButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - mainFrame.returnToMainMenu(); - } - }); - eastComponents.add(mainMenuButton); - - JButton cardShopButton = new JButton("Card Shop"); - cardShopButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - QuestMainPanel.this.showCardShop(); - } - }); - eastComponents.add(cardShopButton); - cardShopButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); - - JButton bazaarButton = null; - if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { - - bazaarButton = new JButton("Bazaar"); - bazaarButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - QuestMainPanel.this.showBazaar(); - } - }); - eastComponents.add(bazaarButton); - bazaarButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); - } - - - questButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - QuestMainPanel.this.showQuests(); - } - }); - eastComponents.add(questButton); - questButton.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 18)); - questButton.setPreferredSize(new Dimension(0, 60)); - - - playButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - QuestMainPanel.this.launchGame(); - } - }); - - playButton.setFont(new Font(Font.DIALOG, Font.BOLD, 28)); - playButton.setPreferredSize(new Dimension(0, 100)); - - - eastComponents.add(playButton); - eastComponents.add(optionsPanel); - - GuiUtils.setWidthToMax(eastComponents); - - panel.add(mainMenuButton); - GuiUtils.addGap(panel); - panel.add(optionsPanel); - panel.add(Box.createVerticalGlue()); - panel.add(Box.createVerticalGlue()); - - if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { - panel.add(this.lifeLabel); - this.lifeLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); - this.lifeLabel.setIcon(GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("Life.png"), 30, 30)); - } - - GuiUtils.addGap(panel); - panel.add(this.creditsLabel); - this.creditsLabel.setIcon(GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("CoinStack.png"), 30, 30)); - this.creditsLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); - GuiUtils.addGap(panel, 10); - panel.add(cardShopButton); - - if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { - GuiUtils.addGap(panel); - panel.add(bazaarButton); - } - - panel.add(Box.createVerticalGlue()); - - panel.add(questButton); - this.nextQuestLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 11)); - panel.add(nextQuestLabel); - GuiUtils.addGap(panel); - - panel.add(playButton); - - panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - return panel; - } - - /** - *

createOptionsPanel.

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createOptionsPanel() { - JPanel optionsPanel; - optionsPanel = new JPanel(); - optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS)); - - //optionsPanel.add(this.newGUICheckbox); - optionsPanel.add(Box.createVerticalStrut(5)); - optionsPanel.add(this.smoothLandCheckBox); - optionsPanel.add(Box.createVerticalStrut(5)); - optionsPanel.add(this.devModeCheckBox); - optionsPanel.setBorder(new TitledBorder(new EtchedBorder(), "Options")); - return optionsPanel; - } - - /** - *

createMatchSettingsPanel.

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createMatchSettingsPanel() { - - JPanel matchPanel = new JPanel(); - matchPanel.setLayout(new BoxLayout(matchPanel, BoxLayout.Y_AXIS)); - - JPanel deckPanel = new JPanel(); - deckPanel.setLayout(new BoxLayout(deckPanel, BoxLayout.X_AXIS)); - - JLabel deckLabel = new JLabel("Use Deck"); - deckPanel.add(deckLabel); - GuiUtils.addGap(deckPanel); - - this.deckComboBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - playButton.setEnabled(canGameBeLaunched()); - lastUsedDeck = (String) deckComboBox.getSelectedItem(); - } - }); - - deckPanel.add(this.deckComboBox); - GuiUtils.addGap(deckPanel); - - JButton editDeckButton = new JButton("Deck Editor"); - editDeckButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - showDeckEditor(); - } - }); - deckPanel.add(editDeckButton); - deckPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, deckPanel.getPreferredSize().height)); - deckPanel.setAlignmentX(LEFT_ALIGNMENT); - matchPanel.add(deckPanel); - - - GuiUtils.addGap(matchPanel); - - if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { - JPanel fantasyPanel = new JPanel(); - fantasyPanel.setLayout(new BorderLayout()); - - JPanel petPanel = new JPanel(); - petPanel.setLayout(new BoxLayout(petPanel, BoxLayout.X_AXIS)); - - this.petCheckBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - if (petCheckBox.isSelected()) { - questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); - } else { - questData.getPetManager().setSelectedPet(null); - } - - petComboBox.setEnabled(petCheckBox.isSelected()); - } - }); - - petPanel.add(this.petCheckBox); - GuiUtils.addGap(petPanel); - this.petComboBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - if (petCheckBox.isSelected()) { - questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); - } else { - questData.getPetManager().setSelectedPet(null); - } - } - }); - this.petComboBox.setMaximumSize( - new Dimension(Integer.MAX_VALUE, - (int) this.petCheckBox.getPreferredSize().getHeight())); - petPanel.add(this.petComboBox); - - this.plantBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - questData.getPetManager().usePlant = plantBox.isSelected(); - } - }); - - GuiUtils.addGap(petPanel, 10); - petPanel.add(this.plantBox); - petPanel.setMaximumSize(petPanel.getPreferredSize()); - petPanel.setAlignmentX(LEFT_ALIGNMENT); - - fantasyPanel.add(petPanel, BorderLayout.WEST); - - zeppelinButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent actionEvent) { - questData.randomizeOpponents(); - refreshNextMatchPanel(); - QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); - zeppelin.setZeppelinUsed(true); - zeppelinButton.setEnabled(false); - } - }); - - zeppelinButton.setMaximumSize(zeppelinButton.getPreferredSize()); - zeppelinPanel.setLayout(new BorderLayout()); - - fantasyPanel.add(zeppelinPanel, BorderLayout.EAST); - fantasyPanel.setAlignmentX(Component.LEFT_ALIGNMENT); - matchPanel.add(fantasyPanel); - } - return matchPanel; - } - - /** - *

createBattlePanel.

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createBattlePanel() { - JPanel BattlePanel = new JPanel(); - BattlePanel.setLayout(new BoxLayout(BattlePanel, BoxLayout.Y_AXIS)); - BattlePanel.setBorder(new TitledBorder(new EtchedBorder(), "Available Battles")); - - List Battles = QuestBattle.getBattles(); - - for (QuestSelectablePanel Battle : Battles) { - BattlePanel.add(Battle); - Battle.addMouseListener(new SelectionAdapter(Battle)); - - GuiUtils.addGap(BattlePanel, 3); - } - - BattlePanel.setAlignmentX(LEFT_ALIGNMENT); - - return BattlePanel; - } - - /** - *

createQuestPanel.

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel createQuestPanel() { - JPanel questPanel = new JPanel(); - questPanel.setLayout(new BoxLayout(questPanel, BoxLayout.Y_AXIS)); - questPanel.setBorder(new TitledBorder(new EtchedBorder(), "Available Quests")); - - - List quests = QuestQuest.getQuests(); - - for (QuestQuest quest : quests) { - questPanel.add(quest); - quest.addMouseListener(new SelectionAdapter(quest)); - - GuiUtils.addGap(questPanel, 3); - } - - - return questPanel; - } - - /** - *

refresh.

- */ - void refresh() { - AllZone.getQuestData().saveData(); - - devModeCheckBox.setSelected(Constant.Runtime.DevMode[0]); - smoothLandCheckBox.setSelected(Constant.Runtime.Smooth[0]); - //newGUICheckbox.setSelected(OldGuiNewGame.preferences.newGui); - - creditsLabel.setText(" " + questData.getCredits()); - statsLabel.setText(questData.getWin() + " wins / " + questData.getLost() + " losses"); - titleLabel.setText(questData.getRank()); - - //copy lastUsedDeck as removal triggers selection change. - String lastUsedDeck = QuestMainPanel.lastUsedDeck; - deckComboBox.removeAllItems(); - - if (questData.getDeckNames().size() > 0) { - deckComboBox.setEnabled(true); - - List deckNames = new ArrayList(questData.getDeckNames()); - - Collections.sort(deckNames, new Comparator() { - public int compare(String s, String s1) { - return s.compareToIgnoreCase(s1); - } - }); - - if (deckNames.contains(lastUsedDeck)) { - deckNames.remove(lastUsedDeck); - deckNames.add(0, lastUsedDeck); - } - - for (String deckName : deckNames) { - deckComboBox.addItem(deckName); - } - } else { - deckComboBox.addItem(NO_DECKS_AVAILABLE); - deckComboBox.setEnabled(false); - } - deckComboBox.setMinimumSize(new Dimension(150, 0)); - - questButton.setEnabled(nextQuestInWins() == 0); - - playButton.setEnabled(canGameBeLaunched()); - - if (questData.getMode().equals(QuestData.FANTASY)) { - lifeLabel.setText(" " + questData.getLife()); - - petComboBox.removeAllItems(); - - Set petList = questData.getPetManager().getAvailablePetNames(); - - if (petList.size() > 0) { - petComboBox.setEnabled(true); - petCheckBox.setEnabled(true); - for (String aPetList : petList) { - petComboBox.addItem(aPetList); - } - } else { - petComboBox.addItem("No pets available"); - petComboBox.setEnabled(false); - petCheckBox.setEnabled(false); - } - - if (!questData.getPetManager().shouldPetBeUsed()) { - petCheckBox.setSelected(false); - petComboBox.setEnabled(false); - } else { - petCheckBox.setSelected(true); - petComboBox.setSelectedItem(questData.getPetManager().getSelectedPet().getName()); - } - - - this.plantBox.setEnabled(questData.getPetManager().getPlant().getLevel() > 0); - this.plantBox.setSelected(questData.getPetManager().shouldPlantBeUsed()); - - QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); - - if (zeppelin.getLevel() > 0) { - zeppelinPanel.removeAll(); - zeppelinPanel.add(zeppelinButton, BorderLayout.CENTER); - } - - if (!zeppelin.hasBeenUsed()) { - zeppelinButton.setEnabled(true); - } else { - zeppelinButton.setEnabled(false); - } - - - } - - if (nextQuestInWins() > 0) { - nextQuestLabel.setText("Next Quest in " + nextQuestInWins() + " Wins."); - } else { - nextQuestLabel.setText("Next Quest available now."); - } - - nextMatchLayout = new CardLayout(); - - refreshNextMatchPanel(); - } - - /** - *

refreshNextMatchPanel.

- */ - private void refreshNextMatchPanel() { - nextMatchPanel.removeAll(); - nextMatchLayout = new CardLayout(); - nextMatchPanel.setLayout(nextMatchLayout); - nextMatchPanel.add(createBattlePanel(), BATTLES); - nextMatchPanel.add(createQuestPanel(), QUESTS); - if (isShowingQuests) { - this.nextMatchLayout.show(nextMatchPanel, QUESTS); - } else { - this.nextMatchLayout.show(nextMatchPanel, BATTLES); - } - } - - /** - *

nextQuestInWins.

- * - * @return a int. - */ - private int nextQuestInWins() { - - // Number of wins was 25, lowereing the number to 20 to help short term questers. - if (questData.getWin() < 20) { - return 20 - questData.getWin(); - } - - // The int mul has been lowered by one, should face special opps more frequently. - int questsPlayed = questData.getQuestsPlayed(); - int mul = 5; - - if (questData.getInventory().hasItem("Zeppelin")) { - mul = 3; - } else if (questData.getInventory().hasItem("Map")) { - mul = 4; - } - - int delta = (questsPlayed * mul) - questData.getWin(); - - return (delta > 0) ? delta : 0; - } - - - /** - *

showDeckEditor.

- */ - void showDeckEditor() { - Command exit = new Command() { - private static final long serialVersionUID = -5110231879431074581L; - - public void execute() { - //saves all deck data - AllZone.getQuestData().saveData(); - - new QuestFrame(); - } - }; - - DeckEditorQuest g = new DeckEditorQuest(AllZone.getQuestData()); - - g.show(exit); - g.setVisible(true); - mainFrame.dispose(); - }//deck editor button - - /** - *

showBazaar.

- */ - void showBazaar() { - mainFrame.showBazaarPane(); - } - - /** - *

showCardShop.

- */ - void showCardShop() { - Command exit = new Command() { - private static final long serialVersionUID = 8567193482568076362L; - - public void execute() { - //saves all deck data - AllZone.getQuestData().saveData(); - - new QuestFrame(); - } - }; - - DeckEditorShop g = new DeckEditorShop(questData); - - g.show(exit); - g.setVisible(true); - - this.mainFrame.dispose(); - - }//card shop button - - /** - *

launchGame.

- */ - private void launchGame() { - - //TODO: This is a temporary hack to see if the image cache affects the heap usage significantly. - ImageCache.clear(); - - QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); - zeppelin.setZeppelinUsed(false); - questData.randomizeOpponents(); - - String humanDeckName = (String) deckComboBox.getSelectedItem(); - Deck humanDeck = questData.getDeck(humanDeckName); - Constant.Runtime.HumanDeck[0] = humanDeck; - moveDeckToTop(humanDeckName); - - Constant.Quest.oppIconName[0] = getMatchIcon(); - - // Dev Mode occurs before Display - Constant.Runtime.DevMode[0] = devModeCheckBox.isSelected(); - - //DO NOT CHANGE THIS ORDER, GuiDisplay needs to be created before cards are added - //if (newGUICheckbox.isSelected()) { - AllZone.setDisplay(new GuiDisplay4()); - //} else { - // AllZone.setDisplay(new GuiDisplay3()); - //} - - //OldGuiNewGame.preferences.newGui = newGUICheckbox.isSelected(); - - Constant.Runtime.Smooth[0] = smoothLandCheckBox.isSelected(); - - AllZone.getMatchState().reset(); - if (isShowingQuests) { - setupQuest(humanDeck); - } else { - setupBattle(humanDeck); - } - - AllZone.getQuestData().saveData(); - - AllZone.getDisplay().setVisible(true); - mainFrame.dispose(); - } - - - /** - *

setupBattle.

- * - * @param humanDeck a {@link forge.deck.Deck} object. - */ - void setupBattle(Deck humanDeck) { - - Deck computer = QuestBattleManager.getAIDeckFromFile((selectedOpponent).getName()); - Constant.Runtime.ComputerDeck[0] = computer; - - AllZone.getGameAction().newGame(humanDeck, computer, forge.quest.data.QuestUtil.getHumanStartingCards(questData), - new CardList(), questData.getLife(), 20, null); - } - - /** - *

setupQuest.

- * - * @param humanDeck a {@link forge.deck.Deck} object. - */ - private void setupQuest(Deck humanDeck) { - Quest_Assignment selectedQuest = ((QuestQuest) selectedOpponent).getQuestAssignment(); - - Deck computerDeck = QuestBattleManager.getAIDeckFromFile("quest" + selectedQuest.getId()); - Constant.Runtime.ComputerDeck[0] = computerDeck; - - AllZone.setQuestAssignment(selectedQuest); - - int extraLife = 0; - - if (questData.getInventory().getItemLevel("Gear") == 2) { - extraLife = 3; - } - - AllZone.getGameAction().newGame(humanDeck, computerDeck, - forge.quest.data.QuestUtil.getHumanStartingCards(questData, selectedQuest), new CardList(), - questData.getLife() + extraLife, selectedQuest.getComputerLife(), selectedQuest); - - } - - /** - *

getMatchIcon.

- * - * @return a {@link java.lang.String} object. - */ - String getMatchIcon() { - String oppIconName; - - if (isShowingQuests) { - Quest_Assignment selectedQuest = ((QuestQuest) selectedOpponent).getQuestAssignment(); - oppIconName = selectedQuest.getIconName(); - } else { - oppIconName = selectedOpponent.getName(); - oppIconName = oppIconName.substring(0, oppIconName.length() - 1).trim() + ".jpg"; - } - return oppIconName; - } - - /** - *

showQuests.

- */ - void showQuests() { - if (isShowingQuests) { - isShowingQuests = false; - questButton.setText("Quests"); - } else { - isShowingQuests = true; - questButton.setText("Battles"); - } - - if (selectedOpponent != null) { - selectedOpponent.setSelected(false); - } - - selectedOpponent = null; - - refresh(); - } - - class SelectionAdapter extends MouseAdapter { - QuestSelectablePanel selectablePanel; - - SelectionAdapter(QuestSelectablePanel selectablePanel) { - super(); - this.selectablePanel = selectablePanel; - } - - @Override - public void mouseClicked(MouseEvent mouseEvent) { - - if (selectedOpponent != null) { - selectedOpponent.setSelected(false); - } - - selectablePanel.setSelected(true); - - selectedOpponent = selectablePanel; - playButton.setEnabled(canGameBeLaunched()); - } - - } - - /** - *

moveDeckToTop.

- * - * @param humanDeckName a {@link java.lang.String} object. - */ - private void moveDeckToTop(String humanDeckName) { - QuestMainPanel.lastUsedDeck = humanDeckName; - } - - - /** - *

canGameBeLaunched.

- * - * @return a boolean. - */ - boolean canGameBeLaunched() { - return !(NO_DECKS_AVAILABLE.equals(deckComboBox.getSelectedItem()) || selectedOpponent == null); - } - - /** {@inheritDoc} */ - @Override - public void refreshState() { - this.refresh(); - } - -} +package forge.quest.gui; + + +import forge.*; +import forge.deck.Deck; +import forge.gui.GuiUtils; +import forge.gui.deckeditor.DeckEditorShop; +import forge.gui.deckeditor.DeckEditorQuest; +import forge.quest.data.QuestData; +import forge.quest.data.item.QuestItemZeppelin; +import forge.quest.gui.main.QuestDuel; +import forge.quest.gui.main.QuestDuelPanel; +import forge.quest.gui.main.QuestQuest; +import forge.quest.gui.main.QuestQuestPanel; +import forge.quest.gui.main.QuestSelectablePanel; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.*; +import java.util.List; + + +/** + *

QuestMainPanel class.

+ * VIEW - lays out swing components for duel and quest events. + * + * @author Forge + * @version $Id: QuestMainPanel.java 10358 2011-09-11 05:20:13Z Doublestrike $ + */ +public class QuestMainPanel extends QuestAbstractPanel { + /** Constant serialVersionUID=6142934729724012402L */ + private static final long serialVersionUID = 6142934729724012402L; + + private forge.quest.data.QuestData questData; + + JLabel creditsLabel = new JLabel(); + JLabel lifeLabel = new JLabel(); + JLabel statsLabel = new JLabel(); + JLabel titleLabel = new JLabel(); + JLabel nextQuestLabel = new JLabel(); + + JComboBox petComboBox = new JComboBox(); + JComboBox deckComboBox = new JComboBox(); + + JButton questButton = new JButton("Quests"); + JButton playButton = new JButton("Play"); + + private QuestSelectablePanel selectedOpponent; + + JPanel nextMatchPanel = new JPanel(); + CardLayout nextMatchLayout; + + boolean isShowingQuests = false; + private JCheckBox devModeCheckBox = new JCheckBox("Developer Mode"); + //private JCheckBox newGUICheckbox = new JCheckBox("Use new UI", true); + private JCheckBox smoothLandCheckBox = new JCheckBox("Adjust AI Land"); + private JCheckBox petCheckBox = new JCheckBox("Summon Pet"); + + private JCheckBox plantBox = new JCheckBox("Summon Plant"); + /** Constant NO_DECKS_AVAILABLE="No decks available" */ + private static final String NO_DECKS_AVAILABLE = "No decks available"; + /** Constant BATTLES="Battles" */ + private static final String BATTLES = "Battles"; + /** Constant QUESTS="Quests" */ + private static final String QUESTS = "Quests"; + + //TODO: Make this ordering permanent + /** Constant lastUsedDeck="//TODO: Make this ordering permanent" */ + private static String lastUsedDeck; + private JButton zeppelinButton = new JButton("Launch
Zeppelin", + GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("ZeppelinIcon.png"), 40, 40)); + private JPanel zeppelinPanel = new JPanel(); + + //TODO: DOUBLESTRIKE SEZ - the event manager is currently linked to + // the QuestFrame. There is almost definitely a better way to do that. + // I'll be fixing it very soon, after this core commit is up and working. + QuestFrame TEST = null; + + /** + *

Constructor for QuestMainPanel.

+ * + * @param mainFrame a {@link forge.quest.gui.QuestFrame} object. + */ + public QuestMainPanel(QuestFrame mainFrame) { + super(mainFrame); + questData = AllZone.getQuestData(); + + TEST = mainFrame; + + initUI(); + } + + /** + *

initUI.

+ */ + private void initUI() { + refresh(); + this.setLayout(new BorderLayout(5, 5)); + JPanel centerPanel = new JPanel(new BorderLayout()); + this.add(centerPanel, BorderLayout.CENTER); + + JPanel northPanel = createStatusPanel(); + this.add(northPanel, BorderLayout.NORTH); + + JPanel eastPanel = createSidePanel(); + this.add(eastPanel, BorderLayout.EAST); + + JPanel matchSettingsPanel = createMatchSettingsPanel(); + centerPanel.add(matchSettingsPanel, BorderLayout.SOUTH); + + centerPanel.add(nextMatchPanel, BorderLayout.CENTER); + this.setBorder(new EmptyBorder(5, 5, 5, 5)); + + } + + /** + *

createStatusPanel.

+ * + * @return a {@link javax.swing.JPanel} object. + */ + private JPanel createStatusPanel() { + JPanel northPanel = new JPanel(); + JLabel modeLabel; + JLabel difficultyLabel;//Create labels at the top + titleLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 28)); + titleLabel.setAlignmentX(LEFT_ALIGNMENT); + northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS)); + northPanel.add(titleLabel); + + northPanel.add(Box.createVerticalStrut(5)); + + JPanel statusPanel = new JPanel(); + statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS)); + statusPanel.setAlignmentX(LEFT_ALIGNMENT); + + modeLabel = new JLabel(questData.getMode()); + statusPanel.add(modeLabel); + statusPanel.add(Box.createHorizontalGlue()); + + difficultyLabel = new JLabel(questData.getDifficulty()); + statusPanel.add(difficultyLabel); + statusPanel.add(Box.createHorizontalGlue()); + + statusPanel.add(statsLabel); + + northPanel.add(statusPanel); + return northPanel; + } + + /** + *

createSidePanel.

+ * + * @return a {@link javax.swing.JPanel} object. + */ + private JPanel createSidePanel() { + JPanel panel = new JPanel(); + JPanel optionsPanel; //Create options checkbox list + optionsPanel = createOptionsPanel(); + + List eastComponents = new ArrayList(); + //Create buttons + + JButton mainMenuButton = new JButton("Return to Main Menu"); + mainMenuButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + mainFrame.returnToMainMenu(); + } + }); + eastComponents.add(mainMenuButton); + + JButton cardShopButton = new JButton("Card Shop"); + cardShopButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + QuestMainPanel.this.showCardShop(); + } + }); + eastComponents.add(cardShopButton); + cardShopButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); + + JButton bazaarButton = null; + if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { + + bazaarButton = new JButton("Bazaar"); + bazaarButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + QuestMainPanel.this.showBazaar(); + } + }); + eastComponents.add(bazaarButton); + bazaarButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); + } + + + questButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + QuestMainPanel.this.showQuests(); + } + }); + eastComponents.add(questButton); + questButton.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 18)); + questButton.setPreferredSize(new Dimension(0, 60)); + + + playButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + QuestMainPanel.this.launchGame(); + } + }); + + playButton.setFont(new Font(Font.DIALOG, Font.BOLD, 28)); + playButton.setPreferredSize(new Dimension(0, 100)); + + + eastComponents.add(playButton); + eastComponents.add(optionsPanel); + + GuiUtils.setWidthToMax(eastComponents); + + panel.add(mainMenuButton); + GuiUtils.addGap(panel); + panel.add(optionsPanel); + panel.add(Box.createVerticalGlue()); + panel.add(Box.createVerticalGlue()); + + if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { + panel.add(this.lifeLabel); + this.lifeLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); + this.lifeLabel.setIcon(GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("Life.png"), 30, 30)); + } + + GuiUtils.addGap(panel); + panel.add(this.creditsLabel); + this.creditsLabel.setIcon(GuiUtils.getResizedIcon(GuiUtils.getIconFromFile("CoinStack.png"), 30, 30)); + this.creditsLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); + GuiUtils.addGap(panel, 10); + panel.add(cardShopButton); + + if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { + GuiUtils.addGap(panel); + panel.add(bazaarButton); + } + + panel.add(Box.createVerticalGlue()); + + panel.add(questButton); + this.nextQuestLabel.setFont(new Font(Font.DIALOG, Font.PLAIN, 11)); + panel.add(nextQuestLabel); + GuiUtils.addGap(panel); + + panel.add(playButton); + + panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); + return panel; + } + + /** + *

createOptionsPanel.

+ * + * @return a {@link javax.swing.JPanel} object. + */ + private JPanel createOptionsPanel() { + JPanel optionsPanel; + optionsPanel = new JPanel(); + optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.Y_AXIS)); + + //optionsPanel.add(this.newGUICheckbox); + optionsPanel.add(Box.createVerticalStrut(5)); + optionsPanel.add(this.smoothLandCheckBox); + optionsPanel.add(Box.createVerticalStrut(5)); + optionsPanel.add(this.devModeCheckBox); + optionsPanel.setBorder(new TitledBorder(new EtchedBorder(), "Options")); + return optionsPanel; + } + + /** + *

createMatchSettingsPanel.

+ * + * @return a {@link javax.swing.JPanel} object. + */ + private JPanel createMatchSettingsPanel() { + + JPanel matchPanel = new JPanel(); + matchPanel.setLayout(new BoxLayout(matchPanel, BoxLayout.Y_AXIS)); + + JPanel deckPanel = new JPanel(); + deckPanel.setLayout(new BoxLayout(deckPanel, BoxLayout.X_AXIS)); + + JLabel deckLabel = new JLabel("Use Deck"); + deckPanel.add(deckLabel); + GuiUtils.addGap(deckPanel); + + this.deckComboBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + playButton.setEnabled(canGameBeLaunched()); + lastUsedDeck = (String) deckComboBox.getSelectedItem(); + } + }); + + deckPanel.add(this.deckComboBox); + GuiUtils.addGap(deckPanel); + + JButton editDeckButton = new JButton("Deck Editor"); + editDeckButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + showDeckEditor(); + } + }); + deckPanel.add(editDeckButton); + deckPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, deckPanel.getPreferredSize().height)); + deckPanel.setAlignmentX(LEFT_ALIGNMENT); + matchPanel.add(deckPanel); + + + GuiUtils.addGap(matchPanel); + + if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { + JPanel fantasyPanel = new JPanel(); + fantasyPanel.setLayout(new BorderLayout()); + + JPanel petPanel = new JPanel(); + petPanel.setLayout(new BoxLayout(petPanel, BoxLayout.X_AXIS)); + + this.petCheckBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + if (petCheckBox.isSelected()) { + questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); + } else { + questData.getPetManager().setSelectedPet(null); + } + + petComboBox.setEnabled(petCheckBox.isSelected()); + } + }); + + petPanel.add(this.petCheckBox); + GuiUtils.addGap(petPanel); + this.petComboBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + if (petCheckBox.isSelected()) { + questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); + } else { + questData.getPetManager().setSelectedPet(null); + } + } + }); + this.petComboBox.setMaximumSize( + new Dimension(Integer.MAX_VALUE, + (int) this.petCheckBox.getPreferredSize().getHeight())); + petPanel.add(this.petComboBox); + + this.plantBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + questData.getPetManager().usePlant = plantBox.isSelected(); + } + }); + + GuiUtils.addGap(petPanel, 10); + petPanel.add(this.plantBox); + petPanel.setMaximumSize(petPanel.getPreferredSize()); + petPanel.setAlignmentX(LEFT_ALIGNMENT); + + fantasyPanel.add(petPanel, BorderLayout.WEST); + + zeppelinButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent actionEvent) { + questData.randomizeOpponents(); + refreshNextMatchPanel(); + QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); + zeppelin.setZeppelinUsed(true); + zeppelinButton.setEnabled(false); + } + }); + + zeppelinButton.setMaximumSize(zeppelinButton.getPreferredSize()); + zeppelinPanel.setLayout(new BorderLayout()); + + fantasyPanel.add(zeppelinPanel, BorderLayout.EAST); + fantasyPanel.setAlignmentX(Component.LEFT_ALIGNMENT); + matchPanel.add(fantasyPanel); + } + return matchPanel; + } + + /** + *

createDuelPanel.

+ * Makes a parent panel, then selectable panel instances for all available duels. + * + * @return a {@link javax.swing.JPanel} object. + */ + private JPanel createDuelPanel() { + JPanel DuelPanel = new JPanel(); + QuestDuelPanel duelEvent; + DuelPanel.setLayout(new BoxLayout(DuelPanel, BoxLayout.Y_AXIS)); + DuelPanel.setBorder(new TitledBorder(new EtchedBorder(), "Available Battles")); + + List duels = TEST.qem.generateDuels(); + + for (QuestDuel qd : duels) { + duelEvent = new QuestDuelPanel(qd); + DuelPanel.add(duelEvent); + duelEvent.addMouseListener(new SelectionAdapter(duelEvent)); + + GuiUtils.addGap(DuelPanel, 3); + } + + DuelPanel.setAlignmentX(LEFT_ALIGNMENT); + + return DuelPanel; + } + + /** + *

createQuestPanel.

+ * Makes a parent panel, then selectable panel instances for all available battles. + * + * @return a {@link javax.swing.JPanel} object. + */ + private JPanel createQuestPanel() { + JPanel QuestPanel = new JPanel(); + + QuestSelectablePanel selpan; + QuestPanel.setLayout(new BoxLayout(QuestPanel, BoxLayout.Y_AXIS)); + QuestPanel.setBorder(new TitledBorder(new EtchedBorder(), "Available Quests")); + + List quests = TEST.qem.generateQuests(); + + for (QuestQuest qq : quests) { + selpan = new QuestQuestPanel(qq); + QuestPanel.add(selpan); + selpan.addMouseListener(new SelectionAdapter(selpan)); + + GuiUtils.addGap(QuestPanel, 3); + } + + + return QuestPanel; + } + + /** + *

refresh.

+ */ + void refresh() { + AllZone.getQuestData().saveData(); + + devModeCheckBox.setSelected(Constant.Runtime.DevMode[0]); + smoothLandCheckBox.setSelected(Constant.Runtime.Smooth[0]); + //newGUICheckbox.setSelected(OldGuiNewGame.preferences.newGui); + + creditsLabel.setText(" " + questData.getCredits()); + statsLabel.setText(questData.getWin() + " wins / " + questData.getLost() + " losses"); + titleLabel.setText(questData.getRank()); + + //copy lastUsedDeck as removal triggers selection change. + String lastUsedDeck = QuestMainPanel.lastUsedDeck; + deckComboBox.removeAllItems(); + + if (questData.getDeckNames().size() > 0) { + deckComboBox.setEnabled(true); + + List deckNames = new ArrayList(questData.getDeckNames()); + + Collections.sort(deckNames, new Comparator() { + public int compare(String s, String s1) { + return s.compareToIgnoreCase(s1); + } + }); + + if (deckNames.contains(lastUsedDeck)) { + deckNames.remove(lastUsedDeck); + deckNames.add(0, lastUsedDeck); + } + + for (String deckName : deckNames) { + deckComboBox.addItem(deckName); + } + } else { + deckComboBox.addItem(NO_DECKS_AVAILABLE); + deckComboBox.setEnabled(false); + } + deckComboBox.setMinimumSize(new Dimension(150, 0)); + + questButton.setEnabled(nextQuestInWins() == 0); + + playButton.setEnabled(canGameBeLaunched()); + + if (questData.getMode().equals(QuestData.FANTASY)) { + lifeLabel.setText(" " + questData.getLife()); + + petComboBox.removeAllItems(); + + Set petList = questData.getPetManager().getAvailablePetNames(); + + if (petList.size() > 0) { + petComboBox.setEnabled(true); + petCheckBox.setEnabled(true); + for (String aPetList : petList) { + petComboBox.addItem(aPetList); + } + } else { + petComboBox.addItem("No pets available"); + petComboBox.setEnabled(false); + petCheckBox.setEnabled(false); + } + + if (!questData.getPetManager().shouldPetBeUsed()) { + petCheckBox.setSelected(false); + petComboBox.setEnabled(false); + } else { + petCheckBox.setSelected(true); + petComboBox.setSelectedItem(questData.getPetManager().getSelectedPet().getName()); + } + + + this.plantBox.setEnabled(questData.getPetManager().getPlant().getLevel() > 0); + this.plantBox.setSelected(questData.getPetManager().shouldPlantBeUsed()); + + QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); + + if (zeppelin.getLevel() > 0) { + zeppelinPanel.removeAll(); + zeppelinPanel.add(zeppelinButton, BorderLayout.CENTER); + } + + if (!zeppelin.hasBeenUsed()) { + zeppelinButton.setEnabled(true); + } else { + zeppelinButton.setEnabled(false); + } + + + } + + if (nextQuestInWins() > 0) { + nextQuestLabel.setText("Next Quest in " + nextQuestInWins() + " Wins."); + } else { + nextQuestLabel.setText("Next Quest available now."); + } + + nextMatchLayout = new CardLayout(); + + refreshNextMatchPanel(); + } + + /** + *

refreshNextMatchPanel.

+ */ + private void refreshNextMatchPanel() { + nextMatchPanel.removeAll(); + nextMatchLayout = new CardLayout(); + nextMatchPanel.setLayout(nextMatchLayout); + nextMatchPanel.add(createDuelPanel(), BATTLES); + nextMatchPanel.add(createQuestPanel(), QUESTS); + if (isShowingQuests) { + this.nextMatchLayout.show(nextMatchPanel, QUESTS); + } else { + this.nextMatchLayout.show(nextMatchPanel, BATTLES); + } + } + + /** + *

nextQuestInWins.

+ * + * @return a int. + */ + private int nextQuestInWins() { + + // Number of wins was 25, lowereing the number to 20 to help short term questers. + if (questData.getWin() < 20) { + return 20 - questData.getWin(); + } + + // The int mul has been lowered by one, should face special opps more frequently. + int questsPlayed = questData.getQuestsPlayed(); + int mul = 5; + + if (questData.getInventory().hasItem("Zeppelin")) { + mul = 3; + } else if (questData.getInventory().hasItem("Map")) { + mul = 4; + } + + int delta = (questsPlayed * mul) - questData.getWin(); + + return (delta > 0) ? delta : 0; + } + + + /** + *

showDeckEditor.

+ */ + void showDeckEditor() { + Command exit = new Command() { + private static final long serialVersionUID = -5110231879431074581L; + + public void execute() { + //saves all deck data + AllZone.getQuestData().saveData(); + + new QuestFrame(); + } + }; + + DeckEditorQuest g = new DeckEditorQuest(AllZone.getQuestData()); + + g.show(exit); + g.setVisible(true); + mainFrame.dispose(); + }//deck editor button + + /** + *

showBazaar.

+ */ + void showBazaar() { + mainFrame.showBazaarPane(); + } + + /** + *

showCardShop.

+ */ + void showCardShop() { + Command exit = new Command() { + private static final long serialVersionUID = 8567193482568076362L; + + public void execute() { + //saves all deck data + AllZone.getQuestData().saveData(); + + new QuestFrame(); + } + }; + + DeckEditorShop g = new DeckEditorShop(questData); + + g.show(exit); + g.setVisible(true); + + this.mainFrame.dispose(); + + }//card shop button + + /** + *

launchGame.

+ */ + private void launchGame() { + //TODO: This is a temporary hack to see if the image cache affects the heap usage significantly. + ImageCache.clear(); + + QuestItemZeppelin zeppelin = (QuestItemZeppelin) questData.getInventory().getItem("Zeppelin"); + zeppelin.setZeppelinUsed(false); + questData.randomizeOpponents(); + + String humanDeckName = (String) deckComboBox.getSelectedItem(); + + Deck humanDeck = questData.getDeck(humanDeckName); + + Constant.Runtime.HumanDeck[0] = humanDeck; + moveDeckToTop(humanDeckName); + + Constant.Quest.oppIconName[0] = getEventIconFilename(); + + // Dev Mode occurs before Display + Constant.Runtime.DevMode[0] = devModeCheckBox.isSelected(); + + //DO NOT CHANGE THIS ORDER, GuiDisplay needs to be created before cards are added + //if (newGUICheckbox.isSelected()) { + AllZone.setDisplay(new GuiDisplay4()); + //} else { + // AllZone.setDisplay(new GuiDisplay3()); + //} + + //OldGuiNewGame.preferences.newGui = newGUICheckbox.isSelected(); + + Constant.Runtime.Smooth[0] = smoothLandCheckBox.isSelected(); + + AllZone.getMatchState().reset(); + if (isShowingQuests) { + setupQuest(humanDeck); + } else { + setupDuel(humanDeck); + } + + AllZone.getQuestData().saveData(); + + AllZone.getDisplay().setVisible(true); + mainFrame.dispose(); + } + + + /** + *

setupDuel.

+ * + * @param humanDeck a {@link forge.deck.Deck} object. + */ + void setupDuel(Deck humanDeck) { + Deck computer = selectedOpponent.getEvent().getEventDeck(); + Constant.Runtime.ComputerDeck[0] = computer; + + AllZone.getGameAction().newGame(humanDeck, computer, forge.quest.data.QuestUtil.getHumanStartingCards(questData), + new CardList(), questData.getLife(), 20, null); + } + + /** + *

setupQuest.

+ * + * @param humanDeck a {@link forge.deck.Deck} object. + */ + private void setupQuest(Deck humanDeck) { + QuestQuest selectedQuest = (QuestQuest)selectedOpponent.getEvent(); + + Deck computer = selectedOpponent.getEvent().getEventDeck(); + Constant.Runtime.ComputerDeck[0] = computer; + + AllZone.setQuestQuest(selectedQuest); + + int extraLife = 0; + + if (questData.getInventory().getItemLevel("Gear") == 2) { + extraLife = 3; + } + + AllZone.getGameAction().newGame(humanDeck, computer, + forge.quest.data.QuestUtil.getHumanStartingCards(questData, selectedQuest), new CardList(), + questData.getLife() + extraLife, selectedQuest.getAILife(), selectedQuest); + + } + + /** + *

getEventIconFilename.

+ * + * @return a {@link java.lang.String} object. + */ + private String getEventIconFilename() { + return selectedOpponent.getIconFilename(); + } + + /** + *

showQuests.

+ */ + void showQuests() { + if (isShowingQuests) { + isShowingQuests = false; + questButton.setText("Quests"); + } else { + isShowingQuests = true; + questButton.setText("Battles"); + } + + if (selectedOpponent != null) { + selectedOpponent.setSelected(false); + } + + selectedOpponent = null; + + refresh(); + } + + class SelectionAdapter extends MouseAdapter { + QuestSelectablePanel selectablePanel; + + SelectionAdapter(QuestSelectablePanel selectablePanel) { + super(); + this.selectablePanel = selectablePanel; + } + + @Override + public void mouseClicked(MouseEvent mouseEvent) { + + if (selectedOpponent != null) { + selectedOpponent.setSelected(false); + } + + selectablePanel.setSelected(true); + + selectedOpponent = selectablePanel; + playButton.setEnabled(canGameBeLaunched()); + } + + } + + /** + *

moveDeckToTop.

+ * + * @param humanDeckName a {@link java.lang.String} object. + */ + private void moveDeckToTop(String humanDeckName) { + QuestMainPanel.lastUsedDeck = humanDeckName; + } + + + /** + *

canGameBeLaunched.

+ * + * @return a boolean. + */ + boolean canGameBeLaunched() { + return !(NO_DECKS_AVAILABLE.equals(deckComboBox.getSelectedItem()) || selectedOpponent == null); + } + + /** {@inheritDoc} */ + @Override + public void refreshState() { + this.refresh(); + } + +} diff --git a/src/main/java/forge/quest/gui/main/QuestBattle.java b/src/main/java/forge/quest/gui/main/QuestBattle.java deleted file mode 100644 index 2ca8e212e10..00000000000 --- a/src/main/java/forge/quest/gui/main/QuestBattle.java +++ /dev/null @@ -1,90 +0,0 @@ -package forge.quest.gui.main; - - -import forge.gui.GuiUtils; -import forge.quest.data.QuestBattleManager; -import forge.quest.data.QuestEvent; - -import javax.swing.*; - -import org.apache.commons.lang3.StringUtils; - -import java.util.ArrayList; -import java.util.List; - -/** - *

QuestBattle class.

- * Manages QuestSelectablePanel instances for "battle" style matches. - * - * @author Forge - * @version $Id$ - */ -public class QuestBattle extends QuestSelectablePanel { - /** Constant serialVersionUID=3112668476017792084L */ - private static final long serialVersionUID = 3112668476017792084L; - - private String deckName; - - - - /** - *

Constructor for QuestBattle.

- * - * @param name a {@link java.lang.String}, stores display name of opponent. - * @param diff a {@link java.lang.String} stores difficulty of opponent. - * @param description a {@link java.lang.String} stores description of opponent's deck. - * @param icon a {@link javax.swing.ImageIcon} stores opponent's icon. - */ - private QuestBattle(String name, String deck, String diff, String desc, ImageIcon icon) { - super(name, diff, desc, icon); - this.deckName = deck; - } - - /** - *

getBattles.

- * - * Returns list of QuestBattle objects storing data - * of the battles currently available. - * - * @return a {@link java.util.List} object. - */ - - // There's got to be a better place for this method. - public static List getBattles() { - List opponentList = new ArrayList(); - - String[] oppDecks = QuestBattleManager.generateBattles(); - for (String oppDeckName : oppDecks) { - // Get deck object and properties for this opponent. - QuestEvent event1 = QuestBattleManager.getQuestEventFromFile(oppDeckName); - - String oppName = event1.getDisplayName(); - String oppDiff = event1.getDifficulty(); - String oppDesc = event1.getDescription(); - String oppIconAddress = event1.getIcon(); - - ImageIcon icon; - // If non-default icon defined, use it - if (StringUtils.isBlank(oppIconAddress)) { - icon = GuiUtils.getIconFromFile(oppName + ".jpg"); - } - else - icon = GuiUtils.getIconFromFile(oppIconAddress + ".jpg"); - - // Add to list of current quest opponents. - opponentList.add( - new QuestBattle(oppName, oppDeckName, oppDiff, oppDesc, icon) - ); - } - - return opponentList; - } - - /** {@inheritDoc} */ - @Override - public String getName() { - // Called by ???? to get deck name for image icon generation. - // Exception should be thrown somewhere if image can't be found. - return deckName; - } -} diff --git a/src/main/java/forge/quest/gui/main/QuestDuel.java b/src/main/java/forge/quest/gui/main/QuestDuel.java new file mode 100644 index 00000000000..6ec4ba452ff --- /dev/null +++ b/src/main/java/forge/quest/gui/main/QuestDuel.java @@ -0,0 +1,12 @@ +package forge.quest.gui.main; + +/** + *

QuestDuel class.

+ * MODEL - A single duel event data instance, including meta and deck. + * + */ +public class QuestDuel extends QuestEvent { + + // [QuestDuel has no unique properties yet.] + +} diff --git a/src/main/java/forge/quest/gui/main/QuestDuelPanel.java b/src/main/java/forge/quest/gui/main/QuestDuelPanel.java new file mode 100644 index 00000000000..ca20ef0bcb7 --- /dev/null +++ b/src/main/java/forge/quest/gui/main/QuestDuelPanel.java @@ -0,0 +1,20 @@ +package forge.quest.gui.main; + + +/** + *

QuestDuelPanel.

+ * VIEW - Creates a QuestSelectablePanel instance for a "battle" style event. + */ +@SuppressWarnings("serial") +public class QuestDuelPanel extends QuestSelectablePanel { + + /**

QuestDuelPanel.

+ * Constructor, using duel data instance. + * + * @param {@link forge.quest.gui.main.QuestDuel} + */ + public QuestDuelPanel(QuestDuel d) { + super(d); + } + +} diff --git a/src/main/java/forge/quest/gui/main/QuestEvent.java b/src/main/java/forge/quest/gui/main/QuestEvent.java new file mode 100644 index 00000000000..adeb6f5bba5 --- /dev/null +++ b/src/main/java/forge/quest/gui/main/QuestEvent.java @@ -0,0 +1,73 @@ +package forge.quest.gui.main; + +import forge.deck.Deck; + +/** + *

QuestEvent.

+ * + * MODEL - A basic event instance in Quest mode. Can be extended for use in + * unique event types: battles, quests, and others. + */ +public class QuestEvent { + // Default vals if none provided in the event file. + public Deck eventDeck = null; + public String title = "Mystery Event"; + public String description = ""; + public String difficulty = "Medium"; + public String icon = "Unknown.jpg"; + public String name = "Noname"; + + /** + *

getTitle.

+ * + * @return a {@link java.lang.String}. + */ + public final String getTitle() { + return title; + } + + /** + *

getDifficulty.

+ * + * @return a {@link java.lang.String}. + */ + public final String getDifficulty() { + return difficulty; + } + + /** + *

getDescription.

+ * + * @return a {@link java.lang.String}. + */ + public final String getDescription() { + return description; + } + + /** + *

getEventDeck.

+ * + * @return {@link forge.deck.Deck} + */ + public final Deck getEventDeck() { + return eventDeck; + } + + /** + *

getIcon.

+ * + * @return a {@link java.lang.String}. + */ + public final String getIcon() { + return icon; + } + + /** + *

getName.

+ * + * @return a {@link java.lang.String}. + */ + public final String getName() { + return name; + } +} diff --git a/src/main/java/forge/quest/gui/main/QuestEventManager.java b/src/main/java/forge/quest/gui/main/QuestEventManager.java new file mode 100644 index 00000000000..e335cd15082 --- /dev/null +++ b/src/main/java/forge/quest/gui/main/QuestEventManager.java @@ -0,0 +1,406 @@ +package forge.quest.gui.main; + +import forge.AllZone; +import forge.Card; +import forge.CardList; +import forge.CardUtil; +import forge.FileUtil; +import forge.deck.DeckManager; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; +import forge.quest.data.QuestPreferences; +import forge.quest.data.QuestUtil; + +import java.io.File; +import java.util.*; + +/** + *

QuestEventManager.

+ * MODEL - Manages collections of quest events (duelsquests, etc.) + * + * @author Forge + * @version $Id$ + */ +public class QuestEventManager { + public List easyAIduels = null; + public List mediumAIduels = null; + public List hardAIduels = null; + public List veryHardAIduels = null; + + public List allDuels = null; + public List allQuests = null; + + /**

assembleAllEvents.

* + * Reads all quest and battle files to extract quest data. + * Instantiates all duel and quest events, and difficulty lists accordingly. + * Should be used sparingly. + */ + public void assembleAllEvents() { + this.allDuels = new ArrayList(); + this.allQuests = new ArrayList(); + + List contents; + QuestEvent tempEvent; + + File file = ForgeProps.getFile(NewConstants.QUEST.DECKS); + + DeckManager manager = new DeckManager(file); + + File[] allFiles = ForgeProps.getFile(NewConstants.QUEST.DECKS).listFiles(); + + for(File f : allFiles) { + contents = FileUtil.readFile(f); + + if(contents.get(0).trim().equals("[quest]")) { + tempEvent = new QuestQuest(); + assembleQuestUniquedata(contents,(QuestQuest)tempEvent); + allQuests.add((QuestQuest)tempEvent); + } // End if([quest]) + else { + tempEvent = new QuestDuel(); + assembleDuelUniquedata(contents,(QuestDuel)tempEvent); + allDuels.add((QuestDuel)tempEvent); + } + + // Assemble metadata (may not be necessary later) and deck object. + assembleEventMetadata(contents,tempEvent); + tempEvent.eventDeck = manager.getDeck(tempEvent.getName()); + } // End for(allFiles) + + assembleDuelDifficultyLists(); + + } // End assembleAllEvents() + + /** + *

assembleDuelUniqueData.

+ * Handler for any unique data contained in duel files. + * + * @param contents + * @param qd + */ + private void assembleDuelUniquedata(List contents, QuestDuel qd) { + int eqpos; + String key, value; + + for(String s : contents) { + if (s.equals("[metadata]")) { break; } + if (s.equals("[duel]")) { continue; } + if (s.equals("")) { continue; } + + eqpos = s.indexOf('='); + key = s.substring(0, eqpos); + value = s.substring(eqpos + 1); + + if (key.equalsIgnoreCase("Name")) { + qd.name = value; + } + } + } + + /** + *

assembleQuestUniquedata.

+ * Handler for any unique data contained in quest files. + * + * @param contents + * @param qq + */ + private void assembleQuestUniquedata(List contents, QuestQuest qq) { + int eqpos; + String key, value; + + // Unique properties + for(String s : contents) { + if (s.equals("[metadata]")) { break; } + if (s.equals("[quest]")) { continue; } + if (s.equals("")) { continue; } + + eqpos = s.indexOf('='); + key = s.substring(0, eqpos); + value = s.substring(eqpos + 1).trim(); + + if (key.equalsIgnoreCase("ID")) { + qq.id = Integer.parseInt(value); + } + else if (key.equalsIgnoreCase("Repeat")) { + qq.repeatable = Boolean.parseBoolean(value); + } + else if (key.equalsIgnoreCase("AILife")) { + qq.aiLife = Integer.parseInt(value); + } + else if (key.equalsIgnoreCase("Wins")) { + qq.winsReqd = Integer.parseInt(value); + } + else if (key.equalsIgnoreCase("Credit Reward")) { + qq.creditsReward = Integer.parseInt(value); + } + else if (key.equalsIgnoreCase("Card Reward")) { + qq.cardReward = value; + qq.cardRewardList = QuestUtil.generateCardRewardList(value); + } + // Human extra card list assembled here. + else if(key.equalsIgnoreCase("HumanExtras") && !value.equals("")) { + String[] names = value.split("\\|"); + CardList templist = new CardList(); + Card tempcard; + + for(String n : names) { + // Token card creation + if(n.substring(0,5).equals("TOKEN")) { + tempcard = QuestUtil.createToken(n); + tempcard.addController(AllZone.getHumanPlayer()); + tempcard.setOwner(AllZone.getHumanPlayer()); + templist.add(tempcard); + } + // Standard card creation + else { + tempcard = AllZone.getCardFactory().getCard(n, AllZone.getHumanPlayer()); + tempcard.setCurSetCode(tempcard.getMostRecentSet()); + tempcard.setImageFilename(CardUtil.buildFilename(tempcard)); + templist.add(tempcard); + } + } + + qq.humanExtraCards = templist; + } + // AI extra card list assembled here. + else if(key.equalsIgnoreCase("AIExtras") && !value.equals("")) { + String[] names = value.split("\\|"); + CardList templist = new CardList(); + Card tempcard; + + for(String n : names) { + // Token card creation + if(n.substring(0,5).equals("TOKEN")) { + tempcard = QuestUtil.createToken(n); + tempcard.addController(AllZone.getComputerPlayer()); + tempcard.setOwner(AllZone.getComputerPlayer()); + templist.add(tempcard); + } + // Standard card creation + else { + tempcard = AllZone.getCardFactory().getCard(n, AllZone.getComputerPlayer()); + tempcard.setCurSetCode(tempcard.getMostRecentSet()); + tempcard.setImageFilename(CardUtil.buildFilename(tempcard)); + templist.add(tempcard); + } + } + + qq.aiExtraCards = templist; + } + // Card reward list assembled here. + else if(key.equalsIgnoreCase("Card Reward")) { + qq.cardReward = value; + qq.cardRewardList = QuestUtil.generateCardRewardList(value); + } + } + } + + /** + *

assembleEventMetadata.

+ * Handler for metadata contained in event files. + * + * @param contents + * @param qe + */ + private void assembleEventMetadata(List contents, QuestEvent qe) { + int eqpos; + String key, value; + + for(String s : contents) { + s = s.trim(); + eqpos = s.indexOf('='); + + if (s.equals("[main]")) { break; } + if (s.equals("[metadata]")) { continue; } + if (s.equals("")) { continue; } + if (eqpos==-1) { continue; } + + key = s.substring(0, eqpos); + value = s.substring(eqpos + 1); + + if (key.equalsIgnoreCase("Name")) { + qe.name = value; + } + else if (key.equalsIgnoreCase("Title")) { + qe.title = value; + } + else if (key.equalsIgnoreCase("Difficulty")) { + qe.difficulty = value; + } + else if (key.equalsIgnoreCase("Description")) { + qe.description = value; + } + else if (key.equalsIgnoreCase("Icon")) { + qe.icon = value; + } + } + } + + /** + *

getAllDuels.

+ * Returns complete list of all duel objects. + * + * @return a {@link java.util.List} object. + */ + public List getAllDuels() { + return this.allDuels; + } + + /** + *

getAllQuests.

+ * Returns complete list of all quest objects. + * + * @return a {@link java.util.List} object. + */ + public List getAllQuests() { + return this.allQuests; + } + + /** + *

assembleDuelDifficultyLists.

+ * Assemble duel deck difficulty lists + */ + private void assembleDuelDifficultyLists() { + easyAIduels = new ArrayList(); + mediumAIduels = new ArrayList(); + hardAIduels = new ArrayList(); + veryHardAIduels = new ArrayList(); + String s; + + for(QuestDuel qd : allDuels) { + s = qd.getDifficulty(); + if(s.equalsIgnoreCase("easy")) { + easyAIduels.add(qd); + } + else if(s.equalsIgnoreCase("medium")) { + mediumAIduels.add(qd); + } + else if(s.equalsIgnoreCase("hard")) { + hardAIduels.add(qd); + } + else if(s.equalsIgnoreCase("very hard")) { + veryHardAIduels.add(qd); + } + } + } + + /** + *

getDuelOpponent.

+ * Returns specific duel opponent from current shuffle of available duels. + * This is to make sure that the opponents do not change + * when the deck editor is launched. + * + * @param aiDeck a {@link java.util.List} object. + * @param number a int. + * @return a {@link java.lang.String} object. + */ + private static QuestDuel getDuelOpponentByNumber(List aiDeck, int n) { + List deckListCopy = new ArrayList(aiDeck); + Collections.shuffle(deckListCopy, new Random(AllZone.getQuestData().getRandomSeed())); + + return deckListCopy.get(n); + } + + private QuestQuest getQuestOpponentByNumber(int n) { + for(QuestQuest qq : allQuests) { + if(qq.getId()==n) { + return qq; + } + } + return null; + } + + + /** + *

generateDuels.

+ * Generates an array of new duel opponents based on current win conditions. + * + * @return an array of {@link java.lang.String} objects. + */ + public List generateDuels() { + + int index = AllZone.getQuestData().getDifficultyIndex(); + List duelOpponents = new ArrayList(); + + if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForMediumAI(index)) { + duelOpponents.add(getDuelOpponentByNumber(easyAIduels, 0)); + duelOpponents.add(getDuelOpponentByNumber(easyAIduels, 1)); + duelOpponents.add(getDuelOpponentByNumber(easyAIduels, 2)); + } + else if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForMediumAI(index)) { + duelOpponents.add(getDuelOpponentByNumber(easyAIduels, 0)); + duelOpponents.add(getDuelOpponentByNumber(mediumAIduels, 0)); + duelOpponents.add(getDuelOpponentByNumber(mediumAIduels, 1)); + } + else if (AllZone.getQuestData().getWin() < QuestPreferences.getWinsForHardAI(index)) { + duelOpponents.add(getDuelOpponentByNumber(mediumAIduels, 0)); + duelOpponents.add(getDuelOpponentByNumber(mediumAIduels, 1)); + duelOpponents.add(getDuelOpponentByNumber(mediumAIduels, 2)); + } + + else if (AllZone.getQuestData().getWin() == QuestPreferences.getWinsForHardAI(index)) { + duelOpponents.add( getDuelOpponentByNumber(mediumAIduels, 0)); + duelOpponents.add(getDuelOpponentByNumber(hardAIduels, 0)); + duelOpponents.add(getDuelOpponentByNumber(hardAIduels, 1)); + } + + else if (AllZone.getQuestData().getWin() >= QuestPreferences.getWinsForVeryHardAI(index)) { + duelOpponents.add(getDuelOpponentByNumber(hardAIduels, 0)); + duelOpponents.add(getDuelOpponentByNumber(hardAIduels, 1)); + duelOpponents.add(getDuelOpponentByNumber(veryHardAIduels, 0)); + } + else { + duelOpponents.add(getDuelOpponentByNumber(veryHardAIduels, 0)); + duelOpponents.add(getDuelOpponentByNumber(veryHardAIduels, 1)); + duelOpponents.add(getDuelOpponentByNumber(veryHardAIduels, 2)); + } + + return duelOpponents; + } + + /** + *

generateQuests.

+ * Generates an array of new quest opponents based on current win conditions. + * + * @return a {@link java.util.List} object. + */ + public List generateQuests() { + forge.quest.data.QuestData questData = AllZone.getQuestData(); + + List questOpponents = new ArrayList(); + + // If no quests available right now, generate new IDs. + if (questData.getAvailableQuests() == null || questData.getAvailableQuests().size() == 0) { + // Assemble full list of currently available IDs. + List availableQuestIds = new ArrayList(); + for(QuestQuest qq : allQuests) { + if (qq.getWinsReqd() <= questData.getWin() && + !questData.getCompletedQuests().contains(qq.getId())) { + availableQuestIds.add(qq.getId()); + } + } + + // Filter that list as needed. + int maxQuests = questData.getWin() / 10; + if (maxQuests > 5) { + maxQuests = 5; + } + + Collections.shuffle(availableQuestIds); + + for (int i = 0; i < maxQuests; i++) { + availableQuestIds.add(i); + } + questData.setAvailableQuests(availableQuestIds); + questData.saveData(); + } // + + // Finally, pull quest events from available IDs and return. + for(int i : questData.getAvailableQuests()) { + questOpponents.add(getQuestOpponentByNumber(i)); + } + + return questOpponents; + } + +} diff --git a/src/main/java/forge/quest/gui/main/QuestQuest.java b/src/main/java/forge/quest/gui/main/QuestQuest.java index 11ddababe8a..6c9ad3458c8 100644 --- a/src/main/java/forge/quest/gui/main/QuestQuest.java +++ b/src/main/java/forge/quest/gui/main/QuestQuest.java @@ -1,116 +1,114 @@ package forge.quest.gui.main; -import forge.AllZone; -import forge.Quest_Assignment; -import forge.ReadQuest_Assignment; -import forge.gui.GuiUtils; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; +import forge.CardList; +import forge.item.CardPrinted; -import javax.swing.*; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** *

QuestQuest class.

* - * Manages QuestSelectablePanel instances for "quest" style matches. - * - * @author Forge - * @version $Id$ + * MODEL - A single quest event data instance, including meta, + * deck, and quest-specific properties. + * */ -public class QuestQuest extends QuestSelectablePanel { - /** Constant serialVersionUID=-162817410327650160L */ - private static final long serialVersionUID = -162817410327650160L; +public class QuestQuest extends QuestEvent { + // ID (default -1, should be explicitly set at later time.) + public int id = -1; + + // Default vals if none provided for this ID + public int aiLife = 25; + public int creditsReward = 100; + public String cardReward = "1 colorless rare"; + public boolean repeatable = false; + public int winsReqd = 20; - Quest_Assignment assignment; + // Other cards used in assignment: starting, and reward. + public CardList humanExtraCards = new CardList(); + public CardList aiExtraCards = new CardList(); + public List cardRewardList = new ArrayList(); /** - *

Constructor for QuestQuest.

+ *

getAILife.

* - * @param assignment a {@link forge.Quest_Assignment} object. + * @return {@link java.lang.Integer}. */ - public QuestQuest(Quest_Assignment assignment) { - super(assignment.getName(), assignment.getDifficulty(), assignment.getDesc(), GuiUtils.getIconFromFile(assignment.getIconName())); - this.assignment = assignment; - - JLabel repeatabilityLabel; - if (assignment.isRepeatable()) { - repeatabilityLabel = new JLabel("This quest is repeatable"); - } else { - repeatabilityLabel = new JLabel("This quest is not repeatable"); - } - - GuiUtils.addGap(centerPanel); - this.centerPanel.add(repeatabilityLabel); + public final int getAILife() { + return aiLife; } - + /** - *

getQuests.

+ *

getCardReward.

* - * @return a {@link java.util.List} object. + * @return {@link java.lang.String}. */ - public static List getQuests() { - List quests = new ArrayList(); - - List questList = readQuests(); - - for (Quest_Assignment assignment : questList) { - quests.add(new QuestQuest(assignment)); - } - return quests; + public final String getCardReward() { + return cardReward; } - + /** - *

readQuests.

+ *

getCreditsReward.

* - * @return a {@link java.util.List} object. + * @return {@link java.lang.Integer}. */ - private static List readQuests() { - forge.quest.data.QuestData questData = AllZone.getQuestData(); - ReadQuest_Assignment read = new ReadQuest_Assignment(ForgeProps.getFile(NewConstants.QUEST.QUESTS), questData); - read.run(); - - List questsToDisplay = new ArrayList(); - - if (questData.getAvailableQuests() != null && questData.getAvailableQuests().size() > 0) { - List availableQuests = read.getQuestsByIds(questData.getAvailableQuests()); - questsToDisplay = availableQuests; - - } else { - List allAvailableQuests = read.getAvailableQuests(); - - List availableInts = new ArrayList(); - - int maxQuests = questData.getWin() / 10; - if (maxQuests > 5) { - maxQuests = 5; - } - if (allAvailableQuests.size() < maxQuests) { - maxQuests = allAvailableQuests.size(); - } - - Collections.shuffle(allAvailableQuests); - - for (int i = 0; i < maxQuests; i++) { - Quest_Assignment qa = allAvailableQuests.get(i); - - availableInts.add(qa.getId()); - questsToDisplay.add(qa); - } - questData.setAvailableQuests(availableInts); - questData.saveData(); - }//else - return questsToDisplay; + public final int getCreditsReward() { + return creditsReward; } - + /** - *

getQuestAssignment.

+ *

getId.

* - * @return a {@link forge.Quest_Assignment} object. + * @return {@link java.lang.Integer}. */ - public Quest_Assignment getQuestAssignment() { - return assignment; + public final int getId() { + return id; + } + + /** + *

getRepeatable.

+ * + * @return {@link java.lang.Boolean}. + */ + public final boolean getRepeatable() { + return repeatable; + } + + /** + *

getWinsReqd.

+ * + * @return {@link java.lang.Integer}. + */ + public final int getWinsReqd() { + return winsReqd; + } + + /** + *

getAIExtraCards.

+ * Retrieves list of cards AI has in play at the beginning of this quest. + * + * @return + */ + public final CardList getAIExtraCards() { + return aiExtraCards; + } + + /** + *

getHumanExtraCards.

+ * Retrieves list of cards human has in play at the beginning of this quest. + * + * @return + */ + public final CardList getHumanExtraCards() { + return humanExtraCards; + } + + /** + *

getCardRewardList.

+ * + * @return + */ + public final List getCardRewardList() { + return cardRewardList; } } diff --git a/src/main/java/forge/quest/gui/main/QuestQuestPanel.java b/src/main/java/forge/quest/gui/main/QuestQuestPanel.java new file mode 100644 index 00000000000..cc53dc735b0 --- /dev/null +++ b/src/main/java/forge/quest/gui/main/QuestQuestPanel.java @@ -0,0 +1,35 @@ +package forge.quest.gui.main; + +//import javax.swing.JLabel; + +/** + *

QuestQuestPanel.

+ * VIEW - Creates a QuestSelectablePanel instance for a "quest" style event. + */ + +@SuppressWarnings("serial") +public class QuestQuestPanel extends QuestSelectablePanel { + + //private JLabel repeatabilityLabel; + + /**

QuestQuestPanel.

+ * Constructor, using quest data instance. + * + * @param {@link forge.quest.gui.main.QuestDuel} + */ + public QuestQuestPanel(QuestQuest q) { + super(q); + + // Repeatability is currently meaningless. + // Can be added here later if necessary. + /* + * if (q.getRepeatable()) { + repeatabilityLabel = new JLabel("This quest is repeatable"); + } else { + repeatabilityLabel = new JLabel("This quest is not repeatable"); + } + + super.rootPanel.add(repeatabilityLabel); + */ + } +} diff --git a/src/main/java/forge/quest/gui/main/QuestSelectablePanel.java b/src/main/java/forge/quest/gui/main/QuestSelectablePanel.java index a711628577d..9567459c3a1 100644 --- a/src/main/java/forge/quest/gui/main/QuestSelectablePanel.java +++ b/src/main/java/forge/quest/gui/main/QuestSelectablePanel.java @@ -1,15 +1,19 @@ package forge.quest.gui.main; import forge.gui.GuiUtils; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; import javax.swing.*; import javax.swing.border.CompoundBorder; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; import java.awt.*; +import java.io.File; /** *

QuestSelectablePanel class.

+ * VIEW - Creates a selectable panel, used for picking events. * * @author Forge * @version $Id$ @@ -20,35 +24,38 @@ public class QuestSelectablePanel extends JPanel { protected Color backgroundColor; private boolean selected; - - ImageIcon icon; - String name; - String description; - String difficulty; - JPanel centerPanel = new JPanel(); + private QuestEvent event; + private String iconfilename; + public JPanel rootPanel = new JPanel(); /** *

Constructor for QuestSelectablePanel.

+ * VIEW - A JPanel for selecting quest events. * * @param name a {@link java.lang.String} object. * @param difficulty a {@link java.lang.String} object. * @param description a {@link java.lang.String} object. * @param icon a {@link javax.swing.ImageIcon} object. */ - public QuestSelectablePanel(String name, String difficulty, String description, ImageIcon icon) { + public QuestSelectablePanel(QuestEvent qe) { + this.event = qe; + this.iconfilename = qe.icon; + File base = ForgeProps.getFile(NewConstants.IMAGE_ICON); + File file = new File(base, iconfilename); + + if(!file.exists()) { + file = new File(base,"Unknown.jpg"); + this.iconfilename = "Unknown.jpg"; + } + + ImageIcon icon = new ImageIcon(file.toString()); + this.backgroundColor = getBackground(); - - this.name = name; - this.difficulty = difficulty; - this.description = description; - this.icon = icon; - this.setLayout(new BorderLayout(5, 5)); - JLabel iconLabel; - if (icon == null) { + if (icon.getIconHeight() == -1) { iconLabel = new JLabel(GuiUtils.getEmptyIcon(40, 40)); } else { iconLabel = new JLabel(GuiUtils.getResizedIcon(icon, 40, 40)); @@ -62,32 +69,32 @@ public class QuestSelectablePanel extends JPanel { iconPanel.add(iconLabel, BorderLayout.NORTH); this.add(iconPanel, BorderLayout.WEST); - centerPanel.setOpaque(false); - centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); - this.add(centerPanel, BorderLayout.CENTER); + rootPanel.setOpaque(false); + rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.Y_AXIS)); + this.add(rootPanel, BorderLayout.CENTER); JPanel centerTopPanel = new JPanel(); centerTopPanel.setOpaque(false); centerTopPanel.setAlignmentX(LEFT_ALIGNMENT); centerTopPanel.setLayout(new BoxLayout(centerTopPanel, BoxLayout.X_AXIS)); - JLabel nameLabel = new JLabel(this.name); + JLabel nameLabel = new JLabel(qe.getTitle()); GuiUtils.setFontSize(nameLabel, 20); nameLabel.setAlignmentY(BOTTOM_ALIGNMENT); centerTopPanel.add(nameLabel); GuiUtils.addExpandingHorizontalSpace(centerTopPanel); - JLabel difficultyLabel = new JLabel(this.difficulty); + JLabel difficultyLabel = new JLabel(qe.getDifficulty()); difficultyLabel.setAlignmentY(BOTTOM_ALIGNMENT); centerTopPanel.add(difficultyLabel); - centerPanel.add(centerTopPanel); + rootPanel.add(centerTopPanel); - GuiUtils.addGap(centerPanel); + GuiUtils.addGap(rootPanel); - JLabel descriptionLabel = new JLabel(description); + JLabel descriptionLabel = new JLabel(qe.getDescription()); descriptionLabel.setAlignmentX(LEFT_ALIGNMENT); - centerPanel.add(descriptionLabel); + rootPanel.add(descriptionLabel); this.setMaximumSize(new Dimension(Integer.MAX_VALUE, 80)); this.setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(5, 5, 5, 5))); @@ -117,9 +124,21 @@ public class QuestSelectablePanel extends JPanel { this.selected = selected; } - /** {@inheritDoc} */ - @Override - public String getName() { - return name; + /** + *

getIconFilename.

+ * + * @return String + */ + public String getIconFilename() { + return this.iconfilename; + } + + /** + *

getEvent.

+ * + * @return QuestEvent + */ + public QuestEvent getEvent() { + return this.event; } } diff --git a/src/test/java/forge/ReadQuestAssignmentTest.java b/src/test/java/forge/ReadQuestAssignmentTest.java deleted file mode 100644 index 9e426d40bbd..00000000000 --- a/src/test/java/forge/ReadQuestAssignmentTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package forge; - -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; -import org.testng.annotations.Test; - -/** - * Created by IntelliJ IDEA. - * User: dhudson - */ -@Test(groups = {"UnitTest"}, timeOut = 1000) -public class ReadQuestAssignmentTest implements NewConstants { - /** - * - * - */ - @Test(groups = {"UnitTest", "fast"}, timeOut = 1000) - public void ReadQuestAssignmentTest1() { - try { - ReadQuest_Assignment read = new ReadQuest_Assignment(ForgeProps.getFile(QUEST.QUESTS), null); - - javax.swing.SwingUtilities.invokeAndWait(read); - // read.run(); - - Quest_Assignment qa[] = new Quest_Assignment[read.allQuests.size()]; - read.allQuests.toArray(qa); - for (int i = 0; i < qa.length; i++) { - System.out.println(qa[i].getId()); - System.out.println(qa[i].getName()); - System.out.println(qa[i].getDesc()); - System.out.println(qa[i].getDifficulty()); - System.out.println(qa[i].isRepeatable()); - System.out.println(qa[i].getRequiredNumberWins()); - } - } catch (Exception ex) { - ErrorViewer.showError(ex); - System.out.println("Error reading file " + ex); - } - } -}