diff --git a/.gitattributes b/.gitattributes index 87a54cff2cb..e8025a7cc25 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7256,7 +7256,7 @@ src/forge/GUI_DeckAnalysis.java -text svneol=native#text/plain src/forge/GUI_Filter.java -text svneol=native#text/plain src/forge/GUI_ImportPicture.java -text svneol=native#text/plain src/forge/GUI_Quest_Filter.java -text svneol=native#text/plain -src/forge/GameAction.java -text svneol=native#text/plain +src/forge/GameAction.java svneol=native#text/plain src/forge/GameActionUtil.java -text svneol=native#text/plain src/forge/GameInfo.java -text svneol=native#text/plain src/forge/Generate2ColorDeck.java -text svneol=native#text/plain @@ -7268,7 +7268,7 @@ src/forge/GenerateSealedDeck.java svneol=native#text/plain src/forge/GenerateThemeDeck.java -text svneol=native#text/plain src/forge/GuiDisplay.java svneol=native#text/plain src/forge/GuiDisplay2.java svneol=native#text/plain -src/forge/GuiDisplay3.java -text svneol=native#text/plain +src/forge/GuiDisplay3.java svneol=native#text/plain src/forge/GuiDisplay4.java svneol=native#text/plain src/forge/GuiDisplayUtil.java svneol=native#text/plain src/forge/GuiInput.java svneol=native#text/plain @@ -7281,23 +7281,23 @@ src/forge/Gui_DownloadPictures.java svneol=native#text/plain src/forge/Gui_DownloadPictures_LQ.java -text svneol=native#text/plain src/forge/Gui_DownloadPrices.java -text svneol=native#text/plain src/forge/Gui_DownloadSetPictures_LQ.java -text svneol=native#text/plain -src/forge/Gui_ElixirShop.java -text svneol=native#text/plain -src/forge/Gui_Gear.java -text svneol=native#text/plain -src/forge/Gui_Library.java -text svneol=native#text/plain +src/forge/Gui_ElixirShop.java svneol=native#text/plain +src/forge/Gui_Gear.java svneol=native#text/plain +src/forge/Gui_Library.java svneol=native#text/plain src/forge/Gui_MultipleBlockers.java svneol=native#text/plain src/forge/Gui_NewGame.java svneol=native#text/plain -src/forge/Gui_PetShop.java -text svneol=native#text/plain -src/forge/Gui_PlantShop.java -text svneol=native#text/plain +src/forge/Gui_PetShop.java svneol=native#text/plain +src/forge/Gui_PlantShop.java svneol=native#text/plain src/forge/Gui_Quest.java svneol=native#text/plain src/forge/Gui_QuestOptions.java svneol=native#text/plain src/forge/Gui_Quest_Assignments.java svneol=native#text/plain -src/forge/Gui_Quest_DeckEditor.java -text svneol=native#text/plain -src/forge/Gui_Quest_DeckEditor_Menu.java -text svneol=native#text/plain +src/forge/Gui_Quest_DeckEditor.java svneol=native#text/plain +src/forge/Gui_Quest_DeckEditor_Menu.java svneol=native#text/plain src/forge/Gui_Quest_Deck_Info.java svneol=native#text/plain src/forge/Gui_SealedDeck.java svneol=native#text/plain src/forge/Gui_SetEditor.java svneol=native#text/plain src/forge/Gui_Shops.java -text svneol=native#text/plain -src/forge/Gui_Treasury.java -text svneol=native#text/plain +src/forge/Gui_Treasury.java svneol=native#text/plain src/forge/Gui_Welcome.java svneol=native#text/plain src/forge/Gui_WinLose.java svneol=native#text/plain src/forge/HandSizeOp.java -text svneol=native#text/plain @@ -7350,15 +7350,15 @@ src/forge/PrintCardNames.java svneol=native#text/plain src/forge/PrintCardPictures.java svneol=native#text/plain src/forge/QuestData.java svneol=native#text/plain src/forge/QuestData_BoosterPack.java svneol=native#text/plain -src/forge/QuestData_Prefs.java -text svneol=native#text/plain +src/forge/QuestData_Prefs.java svneol=native#text/plain src/forge/QuestData_State.java svneol=native#text/plain -src/forge/QuestUtil.java -text svneol=native#text/plain +src/forge/QuestUtil.java svneol=native#text/plain src/forge/Quest_Assignment.java -text svneol=native#text/plain src/forge/ReadBoosterPack.java svneol=native#text/plain src/forge/ReadCard.java svneol=native#text/plain src/forge/ReadDraftBoosterPack.java -text svneol=native#text/plain src/forge/ReadPriceList.java -text svneol=native#text/plain -src/forge/ReadQuest_Assignment.java -text svneol=native#text/plain +src/forge/ReadQuest_Assignment.java svneol=native#text/plain src/forge/Run.java svneol=native#text/plain src/forge/RunTest.java svneol=native#text/plain src/forge/SetInfo.java -text svneol=native#text/plain @@ -7428,8 +7428,8 @@ src/forge/quest/data/QuestUtil.java svneol=native#text/plain src/forge/quest/data/pet/QuestPetAbstract.java svneol=native#text/plain src/forge/quest/data/pet/QuestPetBird.java svneol=native#text/plain src/forge/quest/data/pet/QuestPetCrocodile.java svneol=native#text/plain -src/forge/quest/data/pet/QuestPetFactory.java svneol=native#text/plain src/forge/quest/data/pet/QuestPetHound.java svneol=native#text/plain +src/forge/quest/data/pet/QuestPetManager.java svneol=native#text/plain src/forge/quest/data/pet/QuestPetPlant.java svneol=native#text/plain src/forge/quest/data/pet/QuestPetWolf.java svneol=native#text/plain src/forge/quest/gui/QuestAbstractPanel.java svneol=native#text/plain diff --git a/src/QuestData_State.java b/src/QuestData_State.java index cd1fed6ff69..9955b615dfe 100644 --- a/src/QuestData_State.java +++ b/src/QuestData_State.java @@ -19,6 +19,8 @@ import java.util.Map.Entry; * * @author Clemens Koza */ +@SuppressWarnings({"deprecation"}) +@Deprecated public class QuestData_State implements Serializable { private static final long serialVersionUID = 7007940230351051937L; diff --git a/src/forge/AllZone.java b/src/forge/AllZone.java index 181f4b5110d..e304d1ef223 100644 --- a/src/forge/AllZone.java +++ b/src/forge/AllZone.java @@ -1,13 +1,13 @@ package forge; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; + import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - public class AllZone implements NewConstants { //only for testing, should read decks from local directory @@ -16,7 +16,7 @@ public class AllZone implements NewConstants { public static final Player HumanPlayer = new HumanPlayer("Human"); public static final Player ComputerPlayer = new AIPlayer("Computer"); - public static QuestData QuestData = null; + public static forge.quest.data.QuestData QuestData = null; public static Quest_Assignment QuestAssignment = null; public static final NameChanger NameChanger = new NameChanger(); diff --git a/src/forge/Constant.java b/src/forge/Constant.java index a2563d10602..48455e6bce7 100644 --- a/src/forge/Constant.java +++ b/src/forge/Constant.java @@ -2,12 +2,13 @@ package forge; +import forge.quest.data.QuestMatchState; + +import javax.swing.*; import java.util.Arrays; import java.util.Collections; import java.util.List; -import javax.swing.ImageIcon; - public interface Constant { public static final String ProgramName = "Forge - http://cardforge.org"; @@ -17,7 +18,7 @@ public interface Constant { public static final Deck[] HumanDeck = new Deck[1]; public static final Deck[] ComputerDeck = new Deck[1]; public static final String[] GameType = new String[1]; - public static final WinLose WinLose = new WinLose(); + public static final QuestMatchState matchState = new QuestMatchState(); public static final boolean[] Smooth = new boolean[1]; public static final boolean[] Mill = new boolean[1]; public static final boolean[] DevMode = new boolean[1]; // one for normal mode one for quest mode diff --git a/src/forge/GameAction.java b/src/forge/GameAction.java index ac8a2338445..3d87ca53ad5 100644 --- a/src/forge/GameAction.java +++ b/src/forge/GameAction.java @@ -1,3673 +1,3666 @@ - -package forge; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Random; - -import javax.swing.JFrame; -import javax.swing.JOptionPane; - -import forge.gui.GuiUtils; -import forge.properties.ForgeProps; -import forge.properties.NewConstants.LANG.GameAction.GAMEACTION_TEXT; - -public class GameAction { - - public void resetActivationsPerTurn(){ - CardList all = AllZoneUtil.getCardsInGame(); - - // Reset Activations per Turn - for(Card card : all){ - for(SpellAbility sa : card.getSpellAbility()) - sa.getRestrictions().resetTurnActivations(); - } - } - - // todo(sol) Combine all of these move tos - - public Card moveTo(PlayerZone zone, Card c) { - // Ideally move to should never be called without a prevZone - // Remove card from Current Zone, if it has one - String prevName = ""; - PlayerZone prev = AllZone.getZone(c); - - //Card lastKnownInfo = getLastKnownInformation(c); - Card lastKnownInfo = c; - - if(prev != null){ - if (prev.is(Constant.Zone.Battlefield) && c.isCreature()) - AllZone.Combat.removeFromCombat(c); - prevName = prev.getZoneName(); - prev.remove(c); - } - else{ - // things that were just created will not have zones! - //System.out.println(c.getName() + " " + zone.getZoneName()); - } - - // Don't add the Token, unless it's moving to the battlefield - if (!c.isToken() || zone.is(Constant.Zone.Battlefield)){ - // If a nontoken card is moving from the Battlefield, to non-Battlefield zone copy it - if (prev != null && prev.is(Constant.Zone.Battlefield) && !zone.is(Constant.Zone.Battlefield)) - c = AllZone.CardFactory.copyCard(c); - - c.setUnearthed(lastKnownInfo.isUnearthed()); // this might be unnecessary - if (lastKnownInfo.wasSuspendCast()) // these probably can be moved back to SubtractCounters - c = addSuspendTriggers(c); - - // todo: if zone is battlefied and prevZone is battlefield, temporarily disable enters battlefield triggers - zone.add(c); - } - - if (zone.is(Constant.Zone.Battlefield) && c.isAura()){ - // todo: add attachment code here - } - - // copyCard above seems to already clearRemembered, commenting out for now - //if (!zone.is(Constant.Zone.Battlefield)) - //{ - //Other characteristics should be cleared here also. - // c.clearRemembered(); - //} - - //Run triggers - HashMap runParams = new HashMap(); - - runParams.put("Card", lastKnownInfo); - runParams.put("Origin", prevName); - runParams.put("Destination", zone.getZoneName()); - AllZone.TriggerHandler.runTrigger("ChangesZone", runParams); - - return c; - } - - public Card getLastKnownInformation(Card card){ - // this may be necessary at some point, but I'm not certain - // record last known information before moving zones - Card lastKnown = AllZone.CardFactory.copyCard(card); - - for(Card eq : card.getEquippedBy()) - eq.equipCard(lastKnown); - - for(Card en : card.getEnchantedBy()) - en.enchantCard(lastKnown); - - lastKnown.setExtrinsicKeyword(card.getExtrinsicKeyword()); - - return lastKnown; - } - - public void changeController(CardList list, Player oldController, Player newController){ - if (oldController.equals(newController)) - return; - - // Consolidating this code for now. In the future I want moveTo to handle this garbage - PlayerZone oldBattlefield = AllZone.getZone(Constant.Zone.Battlefield, oldController); - PlayerZone newBattlefield = AllZone.getZone(Constant.Zone.Battlefield, newController); - - AllZone.TriggerHandler.suppressMode("ChangesZone"); - ((PlayerZone_ComesIntoPlay) AllZone.Human_Battlefield).setTriggers(false); - ((PlayerZone_ComesIntoPlay) AllZone.Computer_Battlefield).setTriggers(false); - //so "enters the battlefield" abilities don't trigger - - for(Card c : list){ - oldBattlefield.remove(c); - c.setController(newController); - newBattlefield.add(c); - if (c.isCreature()) - AllZone.Combat.removeFromCombat(c); - } - - AllZone.TriggerHandler.clearSuppression("ChangesZone"); - ((PlayerZone_ComesIntoPlay) AllZone.Human_Battlefield).setTriggers(true); - ((PlayerZone_ComesIntoPlay) AllZone.Computer_Battlefield).setTriggers(true); - } - - public Card moveToStack(Card c){ - PlayerZone stack = AllZone.getZone(Constant.Zone.Stack, null); - return moveTo(stack, c); - } - - public Card moveToGraveyard(Card c) { - - final PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, c.getOwner()); - - if (AllZoneUtil.isCardInPlay("Leyline of the Void", c.getOwner().getOpponent())) { - return moveTo(AllZone.getZone(Constant.Zone.Exile, c.getOwner()), c); - } - - if(c.hasKeyword("If CARDNAME would be put into a graveyard this turn, exile it instead.")) { - return moveTo(AllZone.getZone(Constant.Zone.Exile, c.getOwner()), c); - } - - if (AllZoneUtil.isCardInPlay("Planar Void")) { - CardList pVoids = AllZoneUtil.getCardsInPlay("Planar Void"); - for(int i = 0; i < pVoids.size(); i++) { - Card pVoid = pVoids.get(i); - final Card voidingCard = c; - if (!c.equals(pVoid)) { - Ability ability = new Ability(pVoid, "0") { - @Override - public void resolve() { - if(AllZone.GameAction.isCardInZone(voidingCard, grave)) - moveTo(AllZone.getZone(Constant.Zone.Exile, voidingCard.getOwner()), voidingCard); - } - - };// Ability - StringBuilder sb = new StringBuilder(); - sb.append("Planar Void - exile ").append(c); - ability.setStackDescription(sb.toString()); - - AllZone.Stack.add(ability); - } - } - } - - //must put card in OWNER's graveyard not controller's - c = moveTo(grave, c); - - //Recover keyword - if(c.isType("Creature")) - { - for(final Card recoverable : grave.getCards()) - { - if(recoverable.hasStartOfKeyword("Recover")) - { - SpellAbility abRecover = new Ability(recoverable,"0") - { - @Override - public void resolve() - { - AllZone.GameAction.moveToHand(recoverable); - } - - @Override - public String getStackDescription() - { - StringBuilder SD = new StringBuilder(recoverable.getName()); - SD.append(" - Recover."); - - return SD.toString(); - } - }; - - String recoverCost = recoverable.getKeyword().get(recoverable.getKeywordPosition("Recover")).split(":")[1]; - Ability_Cost abCost = new Ability_Cost(recoverCost,recoverable.getName(),false); - abRecover.setPayCosts(abCost); - - StringBuilder question = new StringBuilder("Recover "); - question.append(recoverable.getName()); - question.append("("); - question.append(recoverable.getUniqueNumber()); - question.append(")"); - question.append("?"); - - boolean shouldRecoverForAI = false; - boolean shouldRecoverForHuman = false; - - if(c.getOwner().equals(AllZone.HumanPlayer)) - { - shouldRecoverForHuman = GameActionUtil.showYesNoDialog(recoverable, question.toString()); - } - else if(c.getOwner().equals(AllZone.ComputerPlayer)) - { - shouldRecoverForAI = ComputerUtil.canPayCost(abRecover); - } - - if(shouldRecoverForHuman) - { - AllZone.GameAction.playSpellAbility(abRecover); - } - else if(shouldRecoverForAI) - { - ComputerUtil.playStack(abRecover); - } - - if(!grave.hasChanged()) //If the controller declined Recovery or didn't pay the cost, exile the recoverable - { - AllZone.GameAction.exile(recoverable); - } - } - } - } - return c; - } - - public Card moveToHand(Card c) { - PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, c.getOwner()); - return moveTo(hand, c); - } - - public Card moveToPlay(Card c) { - PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, c.getOwner()); - return moveTo(play, c); - } - - public Card moveToPlay(Card c, Player p) { - // move to a specific player's Battlefield - PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, p); - return moveTo(play, c); - } - - public Card moveToBottomOfLibrary(Card c) { - return moveToLibrary(c, -1); - } - - public Card moveToLibrary(Card c) { - return moveToLibrary(c, 0); - } - - public Card moveToLibrary(Card c, int libPosition){ - PlayerZone p = AllZone.getZone(c); - PlayerZone library = AllZone.getZone(Constant.Zone.Library, c.getOwner()); - - if(p != null) p.remove(c); - - - if (c.isToken()) - return c; - - if (p != null && p.is(Constant.Zone.Battlefield)) - c = AllZone.CardFactory.copyCard(c); - - if (libPosition == -1 || libPosition > library.getCards().length) - libPosition = library.getCards().length; - - library.add(c, libPosition); - return c; - } - - public Card exile(Card c) { - if(AllZone.GameAction.isCardExiled(c)) return c; - - PlayerZone removed = AllZone.getZone(Constant.Zone.Exile, c.getOwner()); - - return AllZone.GameAction.moveTo(removed, c); - } - - public Card moveTo(String name, Card c, int libPosition){ - // Call specific functions to set PlayerZone, then move onto moveTo - if (name.equals(Constant.Zone.Hand)) - return moveToHand(c); - else if (name.equals(Constant.Zone.Library)) - return moveToLibrary(c, libPosition); - else if (name.equals(Constant.Zone.Battlefield)) - return moveToPlay(c); - else if (name.equals(Constant.Zone.Graveyard)) - return moveToGraveyard(c); - else if (name.equals(Constant.Zone.Exile)) - return exile(c); - else //if (name.equals(Constant.Zone.Stack)) - return moveToStack(c); - } - - public boolean AI_discardNumType(int numDiscard, String[] uTypes, SpellAbility sa) { - CardList hand = new CardList(); - hand.addAll(AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer).getCards()); - CardList tHand = hand.getValidCards(uTypes,sa.getActivatingPlayer(),sa.getSourceCard()); - - if(tHand.size() >= numDiscard) { - CardListUtil.sortCMC(tHand); - tHand.reverse(); - for(int i = 0; i < numDiscard; i++) - tHand.get(i).getController().discard(tHand.get(i), sa); - return true; - } - return false; - } - - public void discard_nath(Card discardedCard) { - final Player owner = discardedCard.getOwner(); - final Player opponent = owner.getOpponent(); - - PlayerZone opponentZone = AllZone.getZone(Constant.Zone.Battlefield, opponent); - CardList opponentList = new CardList(opponentZone.getCards()); - - for(int i = 0; i < opponentList.size(); i++) { - Card card = opponentList.get(i); - if(card.getName().equals("Nath of the Gilt-Leaf")) { - CardFactoryUtil.makeToken("Elf Warrior", "G 1 1 Elf Warrior", opponent, "G", - new String[] {"Creature", "Elf", "Warrior"}, 1, 1, new String[] {}); - } - } - } - - public void discard_PutIntoPlayInstead(Card c) - { - moveToPlay(c); - - if (c.getName().equals("Dodecapod")) - c.setCounter(Counters.P1P1, 2, false); - } - - public void discard_megrim(Card c) { - /* - * Whenever an opponent discards a card, Megrim deals 2 damage to that player. - */ - final Player owner = c.getOwner(); //discarded card owner - final Player opponent = owner.getOpponent(); //check this for Megrim - CardList megrims = AllZoneUtil.getPlayerCardsInPlay(opponent, "Megrim"); - for(Card megrim:megrims) { - final Card thisMegrim = megrim; - final Ability ability = new Ability(megrim, "0") { - @Override - public void resolve() { - owner.addDamage(2, thisMegrim); - } - }; - - StringBuilder sb = new StringBuilder(); - sb.append(megrim.getName()).append(" - deals 2 damage to ").append(owner); - ability.setStackDescription(sb.toString()); - - AllZone.Stack.add(ability); - } - } - - public void discard_madness(Card c) { - // Whenever a card with madness is discarded, you may cast it for it's madness cost - if (!c.hasMadness()) - return; - - final Card madness = c; - final Ability cast = new Ability(madness, madness.getMadnessCost()) { - @Override - public void resolve() { - playCardNoCost(madness); - System.out.println("Madness cost paid"); - } - }; - - StringBuilder sb = new StringBuilder(); - sb.append(madness.getName()).append(" - Cast via Madness"); - cast.setStackDescription(sb.toString()); - - final Ability activate = new Ability(madness, "0") { - @Override - public void resolve() { - // pay madness cost here. - if (madness.getOwner().isHuman()){ - if (GameActionUtil.showYesNoDialog(madness, madness + " - Discarded. Pay Madness Cost?")){ - if (cast.getManaCost().equals("0")) - AllZone.Stack.add(cast); - else - AllZone.InputControl.setInput(new Input_PayManaCost(cast)); - } - } - else // computer will ALWAYS pay a madness cost if he has the mana. - ComputerUtil.playStack(cast); - } - }; - - StringBuilder sbAct = new StringBuilder(); - sbAct.append(madness.getName()).append(" - Discarded. Pay Madness Cost?"); - activate.setStackDescription(sbAct.toString()); - - AllZone.Stack.add(activate); - } - - public boolean checkEndGameSate(){ - // Win / Lose - boolean humanWins = false; - boolean computerWins = false; - Player computer = AllZone.ComputerPlayer; - Player human = AllZone.HumanPlayer; - - int gameWon = Constant.Runtime.WinLose.getWin(); - - if (human.hasWon()){ // Winning Conditions can be worth more than losing conditions - // Human wins - humanWins = true; - if (human.getAltWin()){ - Constant.Runtime.WinLose.setWinMethod(gameWon, human.getWinCondition()); - } - Constant.Runtime.WinLose.addWin(); - } - - else if (computer.hasLost()){ - // Human wins - humanWins = true; - - if (computer.getAltLose()){ - Constant.Runtime.WinLose.setWinMethod(gameWon, computer.getLoseCondition()); - } - Constant.Runtime.WinLose.addWin(); - } - - - if (computer.hasWon() || human.hasLost()){ - if (humanWins){ - // both players won/lost at the same time. - // TODO: Handle a Draw here - } - - // Computer wins - computerWins = true; - Constant.Runtime.WinLose.addLose(); - } - - return humanWins || computerWins; - } - - - public void checkStateEffects() { - // sol(10/29) added for Phase updates, state effects shouldn't be checked during Spell Resolution - if (AllZone.Stack.getResolving()) - return; - - boolean refreeze = AllZone.Stack.isFrozen(); - AllZone.Stack.setFrozen(true); - - JFrame frame = (JFrame) AllZone.Display; - if(!frame.isDisplayable()) return; - - if(checkEndGameSate()) { - AllZone.Display.savePrefs(); - frame.dispose(); - if (!Constant.Quest.fantasyQuest[0]) - new Gui_WinLose(); - else - new Gui_WinLose(Constant.Quest.humanList[0], Constant.Quest.computerList[0], - Constant.Quest.humanLife[0], Constant.Quest.computerLife[0]); - return; - } - //do this twice, sometimes creatures/permanents will survive when they shouldn't - for (int q=0;q<2;q++) - { - //int size = AllZone.StaticEffects.getStateBasedMap().keySet().size(); - //Object[] arr = AllZone.StaticEffects.getStateBasedMap().keySet().toArray(); - - //card state effects like Glorious Anthem - for(String effect:AllZone.StaticEffects.getStateBasedMap().keySet()) { - Command com = GameActionUtil.commands.get(effect); - com.execute(); - } - - GameActionUtil.executeCardStateEffects(); - GameActionUtil.stSetPT.execute(); - GameActionUtil.stPump.execute(); - - //System.out.println("checking state effects"); - ArrayList creature = PlayerZoneUtil.getCardType(AllZone.Computer_Battlefield, "Creature"); - creature.addAll(PlayerZoneUtil.getCardType(AllZone.Human_Battlefield, "Creature")); - - Card c; - Iterator it = creature.iterator(); - - while(it.hasNext()) { - c = it.next(); - - if(c.isEquipped()) { - for(int i = 0; i < c.getEquippedBy().size(); i++) { - Card equipment = c.getEquippedBy().get(i); - if(!AllZone.GameAction.isCardInPlay(equipment)) { - equipment.unEquipCard(c); - } - } - }//if isEquipped() - - if(c.getNetDefense() <= c.getDamage() && !c.getKeyword().contains("Indestructible")) { - destroy(c); - AllZone.Combat.removeFromCombat(c); //this is untested with instants and abilities but required for First Strike combat phase - } - - else if(c.getNetDefense() <= 0) { - destroy(c); - AllZone.Combat.removeFromCombat(c); - } - - }//while it.hasNext() - - - ArrayList enchantments = PlayerZoneUtil.getCardType(AllZone.Computer_Battlefield, "Enchantment"); - enchantments.addAll(PlayerZoneUtil.getCardType(AllZone.Human_Battlefield, "Enchantment")); - - Iterator iterate = enchantments.iterator(); - while(iterate.hasNext()) { - c = iterate.next(); - - if(c.isAura()) { - for(int i = 0; i < c.getEnchanting().size(); i++) { - Card perm = c.getEnchanting().get(i); - if(!AllZone.GameAction.isCardInPlay(perm) - || CardFactoryUtil.hasProtectionFrom(c, perm) - || ((c.getKeyword().contains("Enchant creature") || c.getKeyword().contains("Enchant tapped creature") ) - && !perm.getType().contains("Creature")) - || (c.getKeyword().contains("Enchant tapped creature") && perm.isUntapped() ) ) { - c.unEnchantCard(perm); - //changed from destroy (and rules-wise, I don't think it's a sacrifice) - moveToGraveyard(c); - } - } - }//if isAura - - }//while iterate.hasNext() - - //Make sure all equipment stops equipping previously equipped creatures that have left play. - ArrayList equip = PlayerZoneUtil.getCardType(AllZone.Computer_Battlefield, "Equipment"); - equip.addAll(PlayerZoneUtil.getCardType(AllZone.Human_Battlefield, "Equipment")); - - Iterator iter = equip.iterator(); - while(iter.hasNext()) { - c = iter.next(); - if(c.isEquipping()) { - Card equippedCreature = c.getEquipping().get(0); - if(!AllZone.GameAction.isCardInPlay(equippedCreature)) c.unEquipCard(equippedCreature); - } - }//while iter.hasNext() - }//for q=0;q<2 - - destroyLegendaryCreatures(); - destroyPlaneswalkers(); - - if (!refreeze) - AllZone.Stack.unfreezeStack(); - }//checkStateEffects() - - - private void destroyPlaneswalkers() { - //get all Planeswalkers - CardList list = AllZoneUtil.getTypeInPlay("Planeswalker"); - - Card c; - for(int i = 0; i < list.size(); i++) { - c = list.get(i); - - if(c.getCounters(Counters.LOYALTY) <= 0) AllZone.GameAction.moveToGraveyard(c); - - String subtype = c.getType().get(c.getType().size() - 1); - CardList cl = list.getType(subtype); - - if(cl.size() > 1) { - for(Card crd:cl) { - AllZone.GameAction.moveToGraveyard(crd); - } - } - } - - } - - private void destroyLegendaryCreatures() { - CardList a = AllZoneUtil.getTypeInPlay("Legendary"); - - while(!a.isEmpty() && !AllZoneUtil.isCardInPlay("Mirror Gallery")) { - CardList b = AllZoneUtil.getCardsInPlay(a.get(0).getName()); - a.remove(0); - if(1 < b.size()) { - for(int i = 0; i < b.size(); i++) - AllZone.GameAction.sacrificeDestroy(b.get(i)); - } - } - }//destroyLegendaryCreatures() - - //ArrayList search is all Card objects, returns ArrayList of Cards - public ArrayList getCardsNamed(ArrayList search, String name) { - ArrayList a = new ArrayList(); - Card c[] = CardUtil.toCard(search); - - for(int i = 0; i < c.length; i++) { - if(c[i].getName().equals(name)) a.add(c[i]); - } - return a; - } - - public void sacrifice(Card c) { - if(c.getName().equals("Mana Pool")) { - System.out.println("Trying to sacrifice mana pool..."); - return; - } - sacrificeDestroy(c); - - //Run triggers - HashMap runParams = new HashMap(); - runParams.put("Card", c); - AllZone.TriggerHandler.runTrigger("Sacrificed", runParams); - } - - public void destroyNoRegeneration(Card c) { - if(!AllZone.GameAction.isCardInPlay(c) || c.getKeyword().contains("Indestructible")) return; - - if (c.isEnchanted()) - { - CardList list = new CardList(c.getEnchantedBy().toArray()); - list = list.filter(new CardListFilter() - { - public boolean addCard(Card crd) - { - return crd.getKeyword().contains("Totem armor"); - } - }); - CardListUtil.sortCMC(list); - - if (list.size() != 0) - { - final Card crd; - if (list.size() == 1) - { - crd = list.get(0); - } - else { - if (c.getController().isHuman()) - crd = GuiUtils.getChoiceOptional("Select totem armor to destroy", list.toArray()); - else - crd = list.get(0); - } - - final Card card = c; - Ability_Static ability = new Ability_Static(crd, "0") - { - public void resolve() - { - destroy(crd); - card.setDamage(0); - - } - }; - - StringBuilder sb = new StringBuilder(); - sb.append(crd).append(" - Totem armor: destroy this aura."); - ability.setStackDescription(sb.toString()); - - AllZone.Stack.add(ability); - return; - } - }//totem armor - - sacrificeDestroy(c); - } - - public Card addSuspendTriggers(final Card c){ - c.setSVar("HasteFromSuspend", "True"); - - Command intoPlay = new Command() { - private static final long serialVersionUID = -4514610171270596654L; - - public void execute() { - if(AllZone.GameAction.isCardInPlay(c) && c.isCreature()) - c.addExtrinsicKeyword("Haste"); - }//execute() - }; - - c.addComesIntoPlayCommand(intoPlay); - - Command loseControl = new Command() { - private static final long serialVersionUID = -4514610171270596654L; - - public void execute() { - if (c.getSVar("HasteFromSuspend").equals("True")){ - c.setSVar("HasteFromSuspend", "False"); - c.removeExtrinsicKeyword("Haste"); - } - }//execute() - }; - - c.addChangeControllerCommand(loseControl); - c.addLeavesPlayCommand(loseControl); - return c; - } - - - // Whenever Keyword - public void checkWheneverKeyword(Card Triggering_Card,String Event, Object[] Custom_Parameters) { - checkStateEffects(); - - PlayerZone Hplay = AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer); - PlayerZone Cplay = AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer); - PlayerZone Hgrave = AllZone.getZone(Constant.Zone.Graveyard, AllZone.HumanPlayer); - PlayerZone Cgrave = AllZone.getZone(Constant.Zone.Graveyard, AllZone.ComputerPlayer); - PlayerZone HRFG = AllZone.getZone(Constant.Zone.Exile, AllZone.HumanPlayer); - PlayerZone CRFG = AllZone.getZone(Constant.Zone.Exile, AllZone.ComputerPlayer); - - CardList Cards_WithKeyword = new CardList(); - Cards_WithKeyword.add(new CardList(Hplay.getCards())); - Cards_WithKeyword.add(new CardList(Cplay.getCards())); - Cards_WithKeyword.add(new CardList(Hgrave.getCards())); - Cards_WithKeyword.add(new CardList(Cgrave.getCards())); - Cards_WithKeyword.add(new CardList(HRFG.getCards())); - Cards_WithKeyword.add(new CardList(CRFG.getCards())); - Cards_WithKeyword = Cards_WithKeyword.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(c.getKeyword().toString().contains("WheneverKeyword")) return true; - return false; - } - }); - - if(!Cards_WithKeyword.contains(Triggering_Card)) Cards_WithKeyword.add(Triggering_Card); - - boolean Triggered = false; - for(int i = 0; i < Cards_WithKeyword.size() ; i++) { - if(Triggered == false) { - Card card = Cards_WithKeyword.get(i); - ArrayList a = card.getKeyword(); - int WheneverKeywords = 0; - int WheneverKeyword_Number[] = new int[a.size()]; - for(int x = 0; x < a.size(); x++) - if(a.get(x).toString().startsWith("WheneverKeyword")) { - WheneverKeyword_Number[WheneverKeywords] = x; - WheneverKeywords = WheneverKeywords + 1; - } - for(int CKeywords = 0; CKeywords < WheneverKeywords; CKeywords++) { - if(Triggered == false) { - String parse = card.getKeyword().get(WheneverKeyword_Number[CKeywords]).toString(); - String k[] = parse.split(":"); - if((k[1].contains(Event))) { - runWheneverKeyword(Triggering_Card, Event, Custom_Parameters); // Beached - Triggered = true; - } - } - } - } - } - } - - static boolean MultiTarget_Cancelled = false; - public void runWheneverKeyword(Card c, String Event, Object[] Custom_Parameters) { - /** - * Custom_Parameters Info: - * For GainLife : Custom_Parameters[0] = Amount of Life Gained - * For DealsDamage : Custom_Parameters[0] = Player Target - * : Custom_Parameters[2] = Damage Source - * For DrawCard : Custom_Parameters[0] = Initiating Player - */ - final Card F_TriggeringCard = c; - final String[] Custom_Strings = new String[10]; - int Custom_Strings_Count = 0; - boolean Stop = false; - for(int i = 0; i < Custom_Strings.length; i++) Custom_Strings[i] = "Null"; - PlayerZone Hplay = AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer); - PlayerZone Cplay = AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer); - PlayerZone Hgrave = AllZone.getZone(Constant.Zone.Graveyard, AllZone.HumanPlayer); - PlayerZone Cgrave = AllZone.getZone(Constant.Zone.Graveyard, AllZone.ComputerPlayer); - PlayerZone HRFG = AllZone.getZone(Constant.Zone.Exile, AllZone.HumanPlayer); - PlayerZone CRFG = AllZone.getZone(Constant.Zone.Exile, AllZone.ComputerPlayer); - - CardList Cards_WithKeyword = new CardList(); - Cards_WithKeyword.add(new CardList(Hplay.getCards())); - Cards_WithKeyword.add(new CardList(Cplay.getCards())); - Cards_WithKeyword.add(new CardList(Hgrave.getCards())); - Cards_WithKeyword.add(new CardList(Cgrave.getCards())); - Cards_WithKeyword.add(new CardList(HRFG.getCards())); - Cards_WithKeyword.add(new CardList(CRFG.getCards())); - Cards_WithKeyword = Cards_WithKeyword.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(c.getKeyword().toString().contains("WheneverKeyword")) return true; - return false; - } - }); - - if(!Cards_WithKeyword.contains(c)) Cards_WithKeyword.add(c); - - for(int i = 0; i < Cards_WithKeyword.size() ; i++) { - Card card = Cards_WithKeyword.get(i); - final Card F_card = card; - ArrayList a = card.getKeyword(); - int WheneverKeywords = 0; - int WheneverKeyword_Number[] = new int[a.size()]; - for(int x = 0; x < a.size(); x++) - if(a.get(x).toString().startsWith("WheneverKeyword")) { - WheneverKeyword_Number[WheneverKeywords] = x; - WheneverKeywords = WheneverKeywords + 1; - } - for(int CKeywords = 0; CKeywords < WheneverKeywords; CKeywords++) { - String parse = card.getKeyword().get(WheneverKeyword_Number[CKeywords]).toString(); - String k[] = parse.split(":"); - final String F_k[] = k; - // Conditions - if((k[1].contains(Event))) - { - if(k[1].contains("DealsDamage")) { - boolean Nullified = true; - String DamageTakerParse = k[1]; - String DamageTaker[] = DamageTakerParse.split("/"); - for(int z = 0; z < DamageTaker.length - 1; z++) { - if(DamageTaker[z + 1].equals("Opponent") && Custom_Parameters[0].equals(card.getController().getOpponent())) Nullified = false; - } - if(Nullified == true) k[4] = "Null"; - } - if(k[1].contains("CastSpell")) { - boolean Nullified = true; - String SpellControllerParse = k[1]; - String SpellController[] = SpellControllerParse.split("/"); - for(int z = 0; z < SpellController.length - 1; z++) { - if(SpellController[z + 1].equals("Controller") && (c.getController()).equals(card.getController())) Nullified = false; - if(SpellController[z + 1].equals("Opponent") && (c.getController()).equals(card.getController().getOpponent())) Nullified = false; - if(SpellController[z + 1].equals("Any")) Nullified = false; - } - if(Nullified == true) k[4] = "Null"; - } - if(k[1].contains("PlayLand")) { - boolean Nullified = true; - String SpellControllerParse = k[1]; - String SpellController[] = SpellControllerParse.split("/"); - for(int z = 0; z < SpellController.length - 1; z++) { - if(SpellController[z + 1].equals("Controller") && (c.getController()).equals(card.getController())) Nullified = false; - if(SpellController[z + 1].equals("Opponent") && (c.getController()).equals(card.getController().getOpponent())) Nullified = false; - if(SpellController[z + 1].equals("Any")) Nullified = false; - } - if(Nullified == true) k[4] = "Null"; - } - int Initiator_Conditions = 1; - String ConditionsParse = k[2]; - String Conditions[] = ConditionsParse.split("!"); - Initiator_Conditions = Conditions.length; - for(int y = 0; y < Initiator_Conditions; y++) { - if(Conditions[y].contains("Self") && !Conditions[y].contains("ControllingPlayer_Self")) { - if(!card.equals(c)) k[4] = "Null"; - } - if(Conditions[y].contains("ControllingPlayer_Self")) { - if(!card.getController().equals(Custom_Parameters[0])) k[4] = "Null"; - } - if(Conditions[y].contains("ControllingPlayer_Opponent")) { - // Special Case for Draw Card - if(Event.equals("DrawCard")) { - if(!card.getController().equals(((Player) Custom_Parameters[0]).getOpponent())) k[4] = "Null"; - } else if(!card.getController().equals(c.getController().getOpponent())) k[4] = "Null"; - } - - if(Conditions[y].contains("Enchanted_Creature")) { - if(((Card)Custom_Parameters[2]).getEnchantedBy().contains(card) == false) k[4] = "Null"; - } - if(Conditions[y].contains("Equipped_Creature")) { - if(((Card)Custom_Parameters[2]).getEquippedBy().contains(card) == false) k[4] = "Null"; - } - if(Conditions[y].contains("Type") && !Conditions[y].contains("OneTypeOfMany")) { - String TypeParse = Conditions[y]; - String Type[] = TypeParse.split("/"); - for(int z = 0; z < Type.length - 1; z++) if(!c.isType(Type[z + 1])) k[4] = "Null"; - } - if(Conditions[y].contains("OneTypeOfMany")) { - boolean Nullified = true; - String TypeParse = Conditions[y]; - String Type[] = TypeParse.split("/"); - for(int z = 0; z < Type.length - 1; z++) if(c.isType(Type[z + 1])) Nullified = false; - if(Nullified == true) k[4] = "Null"; - } - if(Conditions[y].contains("Color")) { - String ColorParse = Conditions[y]; - String Color[] = ColorParse.split("/"); - for(int z = 0; z < Color.length - 1; z++) if(!CardUtil.getColors(c).contains(Color[z + 1])) k[4] = "Null"; - } - } - // Zone Condition - String Zones = k[3]; - PlayerZone[] Required_Zones = new PlayerZone[1]; - if(Zones.equals("Hand")) Required_Zones[0] = AllZone.getZone(Constant.Zone.Hand, card.getController()); - if(Zones.equals("Graveyard")) Required_Zones[0] = AllZone.getZone(Constant.Zone.Graveyard, card.getController()); - if(Zones.equals("Play") || Zones.equals("Any")) Required_Zones[0] = AllZone.getZone(Constant.Zone.Battlefield, card.getController()); - if(Zones.contains("Library")) Required_Zones[0] = AllZone.getZone(Constant.Zone.Library, card.getController()); - if(Zones.contains("Exiled")) Required_Zones[0] = AllZone.getZone(Constant.Zone.Exile, card.getController()); - // if(Zones.contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, card.getController()); - final PlayerZone Required_Zone = Required_Zones[0]; - final String F_Zones = Zones; - // Special Conditions - int Special_Conditions = 1; - String Special_ConditionsParse = k[8]; - String Special_Condition[] = Special_ConditionsParse.split("!"); - Special_Conditions = Special_Condition.length; - for(int y = 0; y < Special_Conditions; y++) { - - if(Special_Condition[y].contains("Initiator - Other than Self")) { - if(card.equals(c)) k[4] = "Null"; - } - if(Special_Condition[y].contains("Initiator - OwnedByController")) { - if(!c.getController().equals(card.getController())) k[4] = "Null"; - } - if(Special_Condition[y].contains("Initiator - Has Keyword")) { - boolean Nullified = true; - String KeywordParse = Special_Condition[y]; - String Keyword[] = KeywordParse.split("/"); - for(int z = 0; z < Keyword.length - 1; z++) if((c.getKeyword()).contains(Keyword[z + 1])) Nullified = false; - if(Nullified == true) k[4] = "Null"; - } - if(Special_Condition[y].contains("ControllerUpkeep")) { - if(!AllZone.Phase.isPlayerTurn(card.getController())) k[4] = "Null"; - } - if(Special_Condition[y].contains("ControllerEndStep")) { - if(!AllZone.Phase.isPlayerTurn(card.getController())) k[4] = "Null"; - } - if(Special_Condition[y].contains("MoreCardsInHand")) { - if(((AllZone.getZone(Constant.Zone.Hand, card.getController())).getCards()).length - <= (AllZone.getZone(Constant.Zone.Hand, card.getController().getOpponent())).getCards().length) k[4] = "Null"; - } - if(Special_Condition[y].contains("SearchType")) { - for(int TypeRestrict = 0; TypeRestrict < (Special_Condition[y].split("/")).length - 1; TypeRestrict ++) { - Custom_Strings[Custom_Strings_Count] = "Type" + (Special_Condition[y].split("/"))[TypeRestrict + 1]; - Custom_Strings_Count++; - } - } - if(Special_Condition[y].contains("SearchColor")) { - for(int ColorRestrict = 0; ColorRestrict < (Special_Condition[y].split("/")).length - 1; ColorRestrict ++) { - Custom_Strings[Custom_Strings_Count] = "Color" + (Special_Condition[y].split("/"))[ColorRestrict + 1]; - Custom_Strings_Count++; - } - } - if(Special_Condition[y].contains("Suspended")) { - if(!card.hasSuspend()) k[4] = "Null"; - } - } - - // Mana Cost (if Any) - String ManaCost = "0"; - if(k[7].contains("PayMana")) { - String PayAmountParse = k[7]; - ManaCost = PayAmountParse.split("/")[1]; - } - - // Targets - - int Target_Conditions = 1; - String TargetParse = k[5]; - String Targets[] = TargetParse.split("!"); - Target_Conditions = Targets.length; - Player TargetPlayer[] = new Player[Target_Conditions]; - Card TargetCard[] = new Card[Target_Conditions]; - for(int y = 0; y < Target_Conditions; y++) { - if(Targets[y].equals("ControllingPlayer_Self")) TargetPlayer[y] = card.getController(); - if(Targets[y].equals("ControllingPlayer_Opponent")) TargetPlayer[y] = card.getController().getOpponent(); - if(Targets[y].equals("ControllingPlayer_Initiator")) TargetPlayer[y] = F_TriggeringCard.getController(); - if(Targets[y].equals("Self")) TargetCard[y] = F_card; - if(Targets[y].equals("Initiating_Card")) TargetCard[y] = c; - } - - final Player[] F_TargetPlayer = TargetPlayer; - final Card[] F_TargetCard = TargetCard; - // JOptionPane.showMessageDialog(null, Targets, "", JOptionPane.INFORMATION_MESSAGE); - - // Effects - - int Effects = 1; - String EffectParse = k[4]; - String Effect[] = EffectParse.split("!"); - Effects = Effect.length; - final Command[] Command_Effects = new Command[Effects]; - final Command[] CommandExecute = new Command[1]; - String StackDescription = F_card + " - "; - final int[] Effects_Count = new int[1]; - - final Ability Ability = new Ability(card, ManaCost) { - @Override - public void resolve() { - for(int Commands = 0; Commands < Command_Effects.length; Commands++) Whenever_ManaPaid(F_card, F_k, Command_Effects[Commands], this); - } - }; - - final Spell Spell = new Spell(card) { - private static final long serialVersionUID = -4909393989689642952L; - - @Override - public void resolve() { - for(int Commands = 0; Commands < Command_Effects.length; Commands++) Whenever_ManaPaid(F_card, F_k, Command_Effects[Commands], this); - } - }; - - SpellAbility[] SpellAbility = new SpellAbility[1]; - if(k[1].equals("ActualSpell")) SpellAbility[0] = Spell; - else SpellAbility[0] = Ability; - - final SpellAbility F_SpellAbility = SpellAbility[0]; - - if(k[7].contains("Choice_Instant") && k[4] != "Null") { - if(card.getController().equals(AllZone.HumanPlayer)) { - Object[] possibleValues = {"Yes", "No"}; - Object q = JOptionPane.showOptionDialog(null, "Activate - " + card.getName(),card.getName() + " Ability", - JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, - null, possibleValues, possibleValues[0]); - if(q.equals(1)) { - Stop = true; - } - } - } - if(Stop == false) { - - for(int y = 0; y < Effects; y++) { - // Variables - String AmountParse = Effect[y]; - String[] S_Amount = AmountParse.split("/"); - int[] I_Amount = new int[S_Amount.length - 1]; - int Multiple_Targets = 1; - - for(int b = 0; b < S_Amount.length - 1; b++) { - if(S_Amount[b+1].equals("Toughness")) I_Amount[b] = F_TriggeringCard.getNetDefense(); - else if(S_Amount[b+1].equals("Power")) I_Amount[b] = F_TriggeringCard.getNetAttack(); - else if(S_Amount[b+1].equals("Life_Gained")) I_Amount[b] = ((Integer)Custom_Parameters[0]); - else if(S_Amount[b+1].contains("ControlledAmountType")) { - final String[] TypeSplit = AmountParse.split("/"); - CardList Cards_WithAllTypes = new CardList(); - Cards_WithAllTypes.add(new CardList(AllZone.getZone(Constant.Zone.Battlefield, card.getController()).getCards())); - Cards_WithAllTypes = Cards_WithAllTypes.filter(new CardListFilter() { - public boolean addCard(Card c) { - for(int z = 0; z < TypeSplit.length - 1; z++) - if(c.isType(TypeSplit[z + 1])) return true; - return false; - } - }); - I_Amount[b] = Cards_WithAllTypes.size(); - } - else if(!S_Amount[0].equals("KeywordPumpEOT")&& !S_Amount[1].contains("ControlledAmountType")) I_Amount[b] = Integer.valueOf(S_Amount[b+1]); - - // NOTE: Multiple Targets and Groups of Integers is not supported - - if(k[8].contains("MultipleTargets")) { - Multiple_Targets = I_Amount[0]; - I_Amount[0] = 1; - } - } // For - // Input for Targets - - final int F_Multiple_Targets = Multiple_Targets; - final Object[] Targets_Multi = new Object[Multiple_Targets]; - final int[] index = new int[1]; - final int[] F_Amount = I_Amount; - final String[] F_S_Amount = S_Amount; - final int F_Target = Effects_Count[0]; - - - final Command MultiTargetsCommand = new Command() { - private static final long serialVersionUID = -83034517601871955L; - - public void execute() { - MultiTarget_Cancelled = false; - for(int i = 0; i < F_Multiple_Targets; i++) { - AllZone.InputControl.setInput(CardFactoryUtil.input_MultitargetCreatureOrPlayer(F_SpellAbility , i , F_Amount[0]*F_Multiple_Targets,new Command() { - - private static final long serialVersionUID = -328305150127775L; - - public void execute() { - Targets_Multi[index[0]] = F_SpellAbility.getTargetPlayer(); - if(Targets_Multi[index[0]] == null) Targets_Multi[index[0]] = F_SpellAbility.getTargetCard(); - index[0]++; - if(F_Multiple_Targets == 1) AllZone.Stack.updateObservers(); - } - })); - } - AllZone.Stack.add(F_SpellAbility); - } - }; - - final Command InputCommand = new Command() { - private static final long serialVersionUID = -83034517601871955L; - - public void execute() { - String WhichInput = F_k[5].split("/")[1]; - if(WhichInput.equals("Creature")) - if(F_card.getController().equals(AllZone.HumanPlayer)) - AllZone.InputControl.setInput(CardFactoryUtil.input_targetCreature(F_SpellAbility, GetTargetsCommand)); - else { - CardList PossibleTargets = new CardList(); - PossibleTargets.addAll(AllZone.Human_Battlefield.getCards()); - PossibleTargets.addAll(AllZone.Computer_Battlefield.getCards()); - PossibleTargets = PossibleTargets.getType("Creature"); - if(Whenever_AI_GoodEffect(F_k)) { - PossibleTargets = PossibleTargets.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(c.getController().equals(AllZone.ComputerPlayer)) return true; - return false; - } - }); - if(PossibleTargets.size() > 0) { - Targets_Multi[index[0]] = CardFactoryUtil.AI_getBestCreature(PossibleTargets,F_card); - AllZone.Stack.add(F_SpellAbility); - } - index[0]++; - } else { - PossibleTargets = PossibleTargets.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(c.getController().equals(AllZone.HumanPlayer)) return true; - return false; - } - }); - if(PossibleTargets.size() > 0) { - Targets_Multi[index[0]] = CardFactoryUtil.AI_getBestCreature(PossibleTargets,F_card); - AllZone.Stack.add(F_SpellAbility); - } - index[0]++; - } - - } - if(WhichInput.equals("Player")) - if(F_card.getController().equals(AllZone.HumanPlayer)) - AllZone.InputControl.setInput(CardFactoryUtil.input_targetPlayer(F_SpellAbility, GetTargetsCommand)); - else { - if(Whenever_AI_GoodEffect(F_k)) { - Targets_Multi[index[0]] = AllZone.ComputerPlayer; - if(Targets_Multi[index[0]] != null) AllZone.Stack.add(F_SpellAbility); - index[0]++; - } - else { - Targets_Multi[index[0]] = AllZone.HumanPlayer; - if(Targets_Multi[index[0]] != null) AllZone.Stack.add(F_SpellAbility); - index[0]++; - } - - } - if(WhichInput.contains("Specific")) { - CardList Cards_inPlay = new CardList(); - Cards_inPlay.addAll(AllZone.Human_Battlefield.getCards()); - Cards_inPlay.addAll(AllZone.Computer_Battlefield.getCards()); - final String[] Specific = F_k[5].split("/"); - final int[] Restriction_Count = new int[1]; - for(int i = 0; i < Specific.length - 2;i++) { - if(Specific[i+2].contains("Type.") && !Specific[i+2].contains("NonType.")) { - Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(c.isType(Specific[Restriction_Count[0] + 2].replaceFirst("Type.", ""))) return true; - return false; - } - }); - } - if(Specific[i+2].contains("NonType.")) { - Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(!c.isType(Specific[Restriction_Count[0] + 2].replaceFirst("NonType.", ""))) return true; - return false; - } - }); - } - if(Specific[i+2].contains("Color.") && !Specific[i+2].contains("NonColor.")) { - Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(CardUtil.getColors(c).contains(Specific[Restriction_Count[0] + 2].replaceFirst("Color.", ""))) return true; - return false; - } - }); - } - if(Specific[i+2].contains("NonColor.")) { - Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(!CardUtil.getColors(c).contains(Specific[Restriction_Count[0] + 2].replaceFirst("NonColor.", ""))) return true; - return false; - } - }); - } - if(Specific[i+2].equals("NotSelf")) { - Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(!c.equals(F_card)) return true; - return false; - } - }); - } - Restriction_Count[0]++; - } - if(F_card.getController().equals(AllZone.HumanPlayer)) - AllZone.InputControl.setInput(CardFactoryUtil.input_targetSpecific(F_SpellAbility, Cards_inPlay, "Select a Valid Card", GetTargetsCommand, true, true)); - else { - if(Whenever_AI_GoodEffect(F_k)) { - Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(c.getController().equals(AllZone.ComputerPlayer)) return true; - return false; - } - }); - if(Cards_inPlay.size() > 0) { - Targets_Multi[index[0]] = CardFactoryUtil.AI_getBestCreature(Cards_inPlay,F_card); - AllZone.Stack.add(F_SpellAbility); - } - index[0]++; - } else { - Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(c.getController().equals(AllZone.HumanPlayer)) return true; - return false; - } - }); - if(Cards_inPlay.size() > 0) { - Targets_Multi[index[0]] = CardFactoryUtil.AI_getBestCreature(Cards_inPlay,F_card); - AllZone.Stack.add(F_SpellAbility); - } - index[0]++; - } - - } - } - - AllZone.Stack.updateObservers(); - } - - final Command GetTargetsCommand = new Command() { - - private static final long serialVersionUID = -328305150127775L; - - public void execute() { - Targets_Multi[index[0]] = F_SpellAbility.getTargetPlayer(); - if(Targets_Multi[index[0]] == null) Targets_Multi[index[0]] = F_SpellAbility.getTargetCard(); - if(F_k[8].contains("AttachTarget")) F_card.attachCard((Card) Targets_Multi[index[0]]); - index[0]++; - if(F_Multiple_Targets == 1) AllZone.Stack.updateObservers(); - } - }; - - }; - - if(k[8].contains("MultipleTargets")) CommandExecute[0] = MultiTargetsCommand; - else if(k[8].contains("SingleTarget")) CommandExecute[0] = MultiTargetsCommand; - else if(k[5].contains("NormalInput")) CommandExecute[0] = InputCommand; - else { - if(F_TargetPlayer[y] != null) Targets_Multi[index[0]] = F_TargetPlayer[y]; - if(F_TargetCard[y] != null) Targets_Multi[index[0]] = F_TargetCard[y]; - index[0]++; - CommandExecute[0] = Command.Blank; - } - - // Null - if(Effect[y].equals("Null")) { - Command_Effects[F_Target] = Command.Blank; - } - - // +1 +1 Counters - if(Effect[y].contains("+1+1 Counters")) { - - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - if(Whenever_Go(F_card,F_k) == true) { - CardList All = Check_if_All_Targets(F_card, F_k); - if(All.size() > 0) { - for(int i = 0; i < All.size(); i++) { - if(AllZone.GameAction.isCardInZone(All.get(i),Required_Zone) || F_Zones.equals("Any")) - All.get(i).addCounter(Counters.P1P1, F_Amount[0]); - } - } - if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Required_Zone) || F_Zones.equals("Any")) - F_TargetCard[F_Target].addCounter(Counters.P1P1, F_Amount[0]); - } - }; - }; - Command_Effects[F_Target] = Proper_resolve; - if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + "all specified permanents get" + F_Amount[0] + " +1/+1 counters"; - else StackDescription = StackDescription + F_TargetCard[y] + " gets " + F_Amount[0] + " +1/+1 counters"; - } - - // CustomCounters.(What Counter)/Amount - if(Effect[y].contains("CustomCounter")) { - - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - if(Whenever_Go(F_card,F_k) == true) { - String PossibleCounter = (F_k[4].split("/")[0]).replaceFirst("CustomCounter.", ""); - Counters Counter = null; - for(int i = 0; i < Counters.values().length ; i++) { - if(Counters.values()[i].toString().equals(PossibleCounter)) - Counter = Counters.values()[i]; - } - CardList All = Check_if_All_Targets(F_card, F_k); - if(All.size() > 0) { - for(int i = 0; i < All.size(); i++) { - if(AllZone.GameAction.isCardInZone(All.get(i),Required_Zone) || F_Zones.equals("Any")) - All.get(i).addCounter(Counter, F_Amount[0]); - } - } - if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Required_Zone) || F_Zones.equals("Any")) - F_TargetCard[F_Target].addCounter(Counter, F_Amount[0]); - } - }; - }; - Command_Effects[F_Target] = Proper_resolve; - if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + "all specified permanents get" + F_Amount[0] + " +1/+1 counters"; - else StackDescription = StackDescription + F_TargetCard[y] + " gets " + F_Amount[0] + - " " + (F_k[4].split("/")[0]).replaceFirst("CustomCounter.", "") + " "+((F_Amount[0]>1)?"counters":"counter"); - } - - // StatsPumpEOT/Power/Toughness - if(Effect[y].contains("StatsPumpEOT")) { - - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - final Command untilEOT = new Command() { - private static final long serialVersionUID = 1497565871061029469L; - - public void execute() { - if(AllZone.GameAction.isCardInPlay(F_card)) { - F_TargetCard[F_Target].addTempAttackBoost(- F_Amount[0]); - F_TargetCard[F_Target].addTempDefenseBoost(- F_Amount[1]); - } - } - }; //Command - - if(Whenever_Go(F_card,F_k) == true) { - CardList All = Check_if_All_Targets(F_card, F_k); - if(All.size() > 0) { - for(int i = 0; i < All.size(); i++) { - F_TargetCard[F_Target].addTempAttackBoost(F_Amount[0]); - F_TargetCard[F_Target].addTempDefenseBoost(F_Amount[1]); - AllZone.EndOfTurn.addUntil(untilEOT); - } - } - else if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Required_Zone) || F_Zones.equals("Any")) { - F_TargetCard[F_Target].addTempAttackBoost(F_Amount[0]); - F_TargetCard[F_Target].addTempDefenseBoost(F_Amount[1]); - AllZone.EndOfTurn.addUntil(untilEOT); - } - } - }; - }; - Command_Effects[F_Target] = Proper_resolve; - if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + "all specified permanents get" + ((F_Amount[0] > -1)? "+" :"") + F_Amount[0] - + "/" + ((F_Amount[1] > -1)? "+" :"") + F_Amount[1] + " until End of Turn"; - else StackDescription = StackDescription + F_TargetCard[y] + " gets " + ((F_Amount[0] > -1)? "+" :"") + F_Amount[0] - + "/" + ((F_Amount[1] > -1)? "+" :"") + F_Amount[1] + " until End of Turn"; - } - - // KeywordPumpEOT/Keyword(s) - if(Effect[y].contains("KeywordPumpEOT")) { - - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - final Command untilEOT = new Command() { - private static final long serialVersionUID = 1497565871061029469L; - - public void execute() { - if(AllZone.GameAction.isCardInPlay(F_card)) { - for(int i =0; i < F_S_Amount.length - 1; i++) { - F_card.removeIntrinsicKeyword(F_S_Amount[i + 1]); - } - } - } - };//Command - if(Whenever_Go(F_card,F_k) == true) { - CardList All = Check_if_All_Targets(F_card, F_k); - if(All.size() > 0) { - for(int i = 0; i < All.size(); i++) { - for(int i2 =0; i2 < F_S_Amount.length - 1; i2++) { - F_card.addIntrinsicKeyword(F_S_Amount[i2 + 1]); - } - AllZone.EndOfTurn.addUntil(untilEOT); - } - } - else if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Required_Zone) || F_Zones.equals("Any")) { - for(int i =0; i < F_S_Amount.length - 1; i++) { - F_card.addIntrinsicKeyword(F_S_Amount[i + 1]); - } - AllZone.EndOfTurn.addUntil(untilEOT); - } - } - }; - }; - String Desc = ""; - for(int KW =0; KW < F_S_Amount.length - 1; KW++) { - Desc = Desc + F_S_Amount[KW + 1]; - if(KW < F_S_Amount.length - 2) Desc = Desc + ", "; - } - Command_Effects[F_Target] = Proper_resolve; - if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + "all specified permanents get" + Desc + " until End of Turn"; - else StackDescription = StackDescription + F_TargetCard[y] + " gets " + Desc + " until End of Turn"; - } - - // ModifyLife/Amount - if(Effect[y].contains("ModifyLife")) { - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - if(Whenever_Go(F_card,F_k) == true) - if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { - if(F_Amount[0] > -1) - F_TargetPlayer[F_Target].gainLife(F_Amount[0], F_card); - else - F_TargetPlayer[F_Target].loseLife(F_Amount[0] * -1,F_card); - } - - } - }; - Command_Effects[F_Target] = Proper_resolve; - StackDescription = StackDescription + F_TargetPlayer[F_Target] + ((F_Amount[0] > -1)? " gains " + F_Amount[0]:"") + ((F_Amount[0] <= -1)? " loses " + F_Amount[0] * -1:"") + " life"; - } - - // Destroy - if(Effect[y].contains("Destroy")) { - - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - if(Whenever_Go(F_card,F_k) == true) { - CardList All = Check_if_All_Targets(F_card, F_k); - if(All.size() > 0) { - for(int i = 0; i < All.size(); i++) { - destroy(All.get(i)); - } - } else if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { - for(int z = 0; z < Targets_Multi.length; z++) { - if(AllZone.GameAction.isCardInPlay((Card) Targets_Multi[z]) - && CardFactoryUtil.canTarget(F_card, (Card) Targets_Multi[z])) { - Card c = (Card) Targets_Multi[z]; - destroy(c); - } - } - } - } - }; - }; - Command_Effects[F_Target] = Proper_resolve; - if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + " destroys all specified permanents"; - else StackDescription = StackDescription + " destroys " + (((Card) Targets_Multi[y] != null)? (Card) Targets_Multi[y]:""); - } - - // TapPermanent - if(Effect[y].contains("TapPermanent")) { - - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - if(Whenever_Go(F_card,F_k) == true) { - CardList All = Check_if_All_Targets(F_card, F_k); - if(All.size() > 0) { - for(int i = 0; i < All.size(); i++) { - All.get(i).tap(); - } - } - else if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { - for(int z = 0; z < Targets_Multi.length; z++) { - if(AllZone.GameAction.isCardInPlay((Card) Targets_Multi[z]) - && CardFactoryUtil.canTarget(F_card, (Card) Targets_Multi[z])) { - Card c = (Card) Targets_Multi[z]; - c.tap(); - } - } - } - } - }; - }; - Command_Effects[F_Target] = Proper_resolve; - if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + " taps all specified permanents"; - else StackDescription = StackDescription + " taps " + (((Card) Targets_Multi[y] != null)? (Card) Targets_Multi[y]:""); - } - - // UntapPermanent - if(Effect[y].contains("UntapPermanent")) { - - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - if(Whenever_Go(F_card,F_k) == true) { - CardList All = Check_if_All_Targets(F_card, F_k); - if(All.size() > 0) { - for(int i = 0; i < All.size(); i++) { - All.get(i).untap(); - } - } - else if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { - for(int z = 0; z < Targets_Multi.length; z++) { - if(AllZone.GameAction.isCardInPlay((Card) Targets_Multi[z]) - && CardFactoryUtil.canTarget(F_card, (Card) Targets_Multi[z])) { - Card c = (Card) Targets_Multi[z]; - c.untap(); - } - } - } - } - }; - }; - Command_Effects[F_Target] = Proper_resolve; - if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + " untaps all specified permanents"; - else StackDescription = StackDescription + " untaps " + (((Card) Targets_Multi[y] != null)? (Card) Targets_Multi[y]:""); - } - - - // Draw Cards - if(Effect[y].contains("DrawCards")) { - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - if(Whenever_Go(F_card,F_k) == true) - if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { - F_TargetPlayer[F_Target].drawCard(); - } - - } - }; - Command_Effects[F_Target] = Proper_resolve; - StackDescription = StackDescription + F_TargetPlayer[F_Target] + " draws " + F_Amount[0] + " card(s)"; - } - - - // Discard Cards - if(Effect[y].contains("DiscardCards")) { - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - if(Whenever_Go(F_card,F_k) == true) - if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { - //this might not work: - F_TargetPlayer[F_Target].discard(F_Amount[0], Ability, false); - } - - } - }; - Command_Effects[F_Target] = Proper_resolve; - StackDescription = StackDescription + F_TargetPlayer[F_Target] + " discards " + F_Amount[0] + " card(s)"; - } - - // Make Token-Type-color-Power-Toughness-Keywords---Amount - if(Effect[y].contains("MakeToken")) { - String[] TokenConditions = AmountParse.split("-"); - - String[] KeyWordConditions = new String[TokenConditions.length - 6]; - for(int z = 5; z < TokenConditions.length - 1; z++) - if(!TokenConditions[z - 5].equals("None")) KeyWordConditions[z - 5] = TokenConditions[z]; - final String[] F_TokenConditions = TokenConditions; - final String[] F_KeyWordConditions = KeyWordConditions; - - String Color = F_TokenConditions[2]; - if(F_TokenConditions[2].equals("c")) Color = "Colorless"; - else if(F_TokenConditions[2].equals("W")) Color = "White"; - else if(F_TokenConditions[2].equals("U")) Color = "Blue"; - else if(F_TokenConditions[2].equals("G")) Color = "Green"; - else if(F_TokenConditions[2].equals("R")) Color = "Red"; - else if(F_TokenConditions[2].equals("B")) Color = "Black"; - else Color = "Multicolored"; - final String F_Color = Color; - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - if(Whenever_Go(F_card,F_k) == true) - if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { - String[] types = F_TokenConditions[1].split(" "); - String[] creatTypes = new String[types.length+1]; - creatTypes[0] = "Creature"; - for (int i=0;i 0) { - for(int i = 0; i < All.size(); i++) { - AllZone.GameAction.moveTo(Whenever_GetMoveToZone(All.get(i), F_k)[1], All.get(i)); - checkStateEffects(); // For Legendaries - } - } - else { - Card NewSearch[] = Search(F_card,F_TriggeringCard, F_k,Custom_Strings); - if(NewSearch[0] != null) { - for(int i = 0; i < NewSearch.length; i++) { - AllZone.GameAction.moveTo(Whenever_GetMoveToZone(NewSearch[i], F_k)[1], NewSearch[i]); - checkStateEffects(); // For Legendaries - } - } else { - if(F_TargetCard[F_Target] == null) { - for(int z = 0; z < Targets_Multi.length; z++) { - F_TargetCard[F_Target] = (Card) Targets_Multi[z]; - if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Whenever_GetMoveToZone(F_TargetCard[F_Target], F_k)[0])) { - AllZone.GameAction.moveTo(Whenever_GetMoveToZone(F_TargetCard[F_Target], F_k)[1], F_TargetCard[F_Target]); - checkStateEffects(); // For Legendaries - } - } - } else if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Whenever_GetMoveToZone(F_TargetCard[F_Target], F_k)[0])) { - AllZone.GameAction.moveTo(Whenever_GetMoveToZone(F_TargetCard[F_Target], F_k)[1], F_TargetCard[F_Target]); - checkStateEffects(); // For Legendaries - } - } - } - } - } - }; - Command_Effects[F_Target] = Proper_resolve; - if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + " moves to all specified permanents from " + ZoneConditions[1] + " to " + ZoneConditions[2] + " zone"; - else if(F_TargetCard[y] != null) StackDescription = StackDescription + F_TargetCard[y] + " moves from " + ZoneConditions[1] + " to " + ZoneConditions[2] + " zone"; - else { - String[] SD = Search_Description(F_TriggeringCard ,k, Custom_Strings); - StackDescription = StackDescription + F_card.getController() + " searches his/her " + SD[0] + " for a " + SD[1] + "card and moves it to the " + ZoneConditions[2] - + " zone. If that player searches a library this way, shuffle it"; - } - } - - // Deal Damage - if(Effect[y].contains("Damage")) { - Command Proper_resolve = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - if(Whenever_Go(F_card,F_k) == true) { - CardList All = Check_if_All_Targets(F_card, F_k); - if(All.size() > 0) { - for(int i = 0; i < All.size(); i++) { - All.get(i).addDamage(F_Amount[0], F_card); - } - } - else if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { - if(F_card.getController().equals(AllZone.HumanPlayer)) { - for(int z = 0; z < Targets_Multi.length; z++) { - if(!(Targets_Multi[z].equals(AllZone.HumanPlayer) || Targets_Multi[z].equals(AllZone.ComputerPlayer))) { - if(AllZone.GameAction.isCardInPlay((Card) Targets_Multi[z]) - && CardFactoryUtil.canTarget(F_card, (Card) Targets_Multi[z])) { - Card c = (Card) Targets_Multi[z]; - c.addDamage(F_Amount[0], F_card); - } - } - else { - ((Player) Targets_Multi[z]).addDamage(F_Amount[0], F_card); - } - } - } - if(F_card.getController().equals(AllZone.ComputerPlayer)) AllZone.HumanPlayer.addDamage(F_Amount[0]*F_Multiple_Targets, F_card); - } - } - }; - - }; - Command_Effects[F_Target] = Proper_resolve; - if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + "deals " + F_Amount[0]*F_Multiple_Targets + " damage" + " to all specified permanents/players"; - else if(F_Multiple_Targets != 1) StackDescription = StackDescription + "deals " + F_Amount[0]*F_Multiple_Targets + " damage" + " divided among up to " + Multiple_Targets + " target creatures and/or players"; - else if(F_card.getController().equals(AllZone.ComputerPlayer)) StackDescription = StackDescription + "targeting Human "; - else StackDescription = StackDescription + "targeting " + ((F_TargetCard[y] != null)? F_TargetCard[y]:"") + - ((F_TargetPlayer[y] != null)? F_TargetPlayer[y]:""); - } - - Effects_Count[0]++; - if(Effects_Count[0] != Effects) StackDescription = StackDescription + " and "; - else StackDescription = StackDescription + "."; - } // For - F_SpellAbility.setStackDescription(StackDescription); - for(int Check = 0; Check < Command_Effects.length; Check++) - if(!Command_Effects[Check].equals(Command.Blank)) { - Whenever_Input(F_card,F_k,CommandExecute[0],F_SpellAbility); - break; - } - } - } - } - } - } - - PlayerZone[] Whenever_GetMoveToZone (Card Target, String[] Keyword_Details) { - String Zones = Keyword_Details[4]; - String[] Zone = Zones.split("-"); - PlayerZone[] Required_Zone = new PlayerZone[2]; - if(Zone[1].contains("Hand")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Hand, Target.getController()); - if(Zone[1].contains("Graveyard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Graveyard, Target.getController()); - if(Zone[1].contains("Play") || Zones.equals("Any")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Battlefield, Target.getController()); - if(Zone[1].contains("Library")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Library, Target.getController()); - if(Zone[1].contains("Exiled")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Exile, Target.getController()); - // if(Zone[1].contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, Target.getController()); - - if(Zone[2].contains("Hand")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Hand, Target.getController()); - if(Zone[2].contains("Graveyard")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Graveyard, Target.getController()); - if(Zone[2].contains("Play") || Zones.equals("Any")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Battlefield, Target.getController()); - if(Zone[2].contains("Library")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Library, Target.getController()); - if(Zone[2].contains("Exiled")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Exile, Target.getController()); - // if(Zone[2].contains("Sideboard")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Sideboard, Target.getController()); - - return Required_Zone; - } - - CardList Check_if_All_Targets (final Card Triggering_Card, String[] Keyword_Details) { - CardList Cards_inPlay = new CardList(); - if(Keyword_Details[5].contains("All") && Keyword_Details[4] != "Null") { - final String[] AllTargets = Keyword_Details[5].split("/"); - - Cards_inPlay.addAll(AllZone.Human_Battlefield.getCards()); - Cards_inPlay.addAll(AllZone.Computer_Battlefield.getCards()); - for(int i2 = 0; i2 < AllTargets.length - 1;i2++) { - final int[] Restriction_Count = new int[1]; - if(AllTargets[i2+1].contains("Type.")) { - Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(c.isType(AllTargets[Restriction_Count[0] + 1].replaceFirst("Type.", ""))) return true; - return false; - } - }); - } - if(AllTargets[i2+1].contains("Color.")) { - Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(CardUtil.getColors(c).contains(AllTargets[Restriction_Count[0] + 1].replaceFirst("Color.", ""))) return true; - return false; - } - }); - } - if(AllTargets[i2+1].contains("AttachedCards")) { - Cards_inPlay.clear(); - Cards_inPlay.addAll(Triggering_Card.getAttachedCards()); - - } - Restriction_Count[0]++; - } - - // All Special Conditions - if(Keyword_Details[8].contains("AllTargets - Except Self")) { - Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(c != Triggering_Card) return true; - return false; - } - }); - } - if(Cards_inPlay.size() == 0) Cards_inPlay.add(AllZone.CardFactory.HumanNullCard); - } - return Cards_inPlay; - } - - boolean Whenever_AI_GoodEffect(String[] Keyword_Details) { - boolean Good = true; - // List all the bad / possibly bad effects here - // Movefrom is bad because in order for it to have a target, the target must be in play. - if(Keyword_Details[4].contains("TapPermanent") || Keyword_Details[4].contains("DiscardCards") - || Keyword_Details[4].contains("MoveFrom") || Keyword_Details[4].contains("Damage")) - Good = false; - // Situational Effects - else { - String EffectInQuestion = Keyword_Details[4].split("/")[1]; - if(Keyword_Details[4].contains("ModifyLife") && EffectInQuestion.contains("-")) Good = false; - if(Keyword_Details[4].contains("StatsPumpEOT") && EffectInQuestion.contains("-")) Good = false; - } - return Good; - } - - Card[] Search (Card Source, Card Initiator ,String[] Keyword_Details, final String[] Custom_Strings) { - String SearchDescription = " "; - boolean SearchLib = true; - if(Keyword_Details[7].contains("Choice_Instant-SearchLibrary")) { - if(Source.getController().equals(AllZone.HumanPlayer)) { - Object[] possibleValues = {"Yes", "No"}; - Object q = JOptionPane.showOptionDialog(null, "Search Libraries?",Source.getName() + " F_SpellAbility", - JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, - null, possibleValues, possibleValues[0]); - if(q.equals(1)) { - SearchLib = false; - } - } - } - int Target_Conditions = 1; - String TargetParse = Keyword_Details[5]; - String Targets[] = TargetParse.split("!"); - Target_Conditions = Targets.length; - Player Zone_Owner = Source.getController(); - Card SearchedCard[] = new Card[Target_Conditions]; - for(int y = 0; y < Target_Conditions; y++) { - if(Targets[y].contains("SearchShuffle") /** && Keyword_Details[4] != "Null" **/) { - if(Targets[y].contains("OSearchShuffle")) { - Zone_Owner = Source.getController().getOpponent(); - SearchDescription = SearchDescription + "Opponent's "; - } - else Zone_Owner = Source.getController(); - String SearchParse = Targets[y]; - String Search[] = SearchParse.split("/"); - String[] SearchZone = new String[Search.length - 1]; - PlayerZone[] PZones = new PlayerZone[SearchZone.length]; - CardList SearchBase = new CardList(); - for(int z = 0; z < PZones.length; z++) { - SearchZone[z] = Search[z+1]; - if(SearchZone[z].equals("Hand")) PZones[z] = AllZone.getZone(Constant.Zone.Hand, Zone_Owner); - if(SearchZone[z].equals("Graveyard")) PZones[z] = AllZone.getZone(Constant.Zone.Graveyard, Zone_Owner); - if(SearchZone[z].equals("Play")) PZones[z] = AllZone.getZone(Constant.Zone.Battlefield, Zone_Owner); - if(SearchZone[z].contains("Library") && SearchLib) PZones[z] = AllZone.getZone(Constant.Zone.Library, Zone_Owner); - if(SearchZone[z].contains("Exiled")) PZones[z] = AllZone.getZone(Constant.Zone.Exile, Zone_Owner); - // if(ZoneConditions[z].contains("Sideboard")) PZones[z] = AllZone.getZone(Constant.Zone.Sideboard, Zone_Owner); - if(PZones[z] != null) { - SearchBase.addAll(PZones[z].getCards()); - SearchDescription = SearchDescription + SearchZone[z] + " "; - } - if(z + 2 < PZones.length && PZones[z] != null) SearchDescription = SearchDescription + ", "; - else if(z + 2 == PZones.length) SearchDescription = SearchDescription + "and "; - } - - @SuppressWarnings("unused") - Object check2 = GuiUtils.getChoiceOptional("View" + SearchDescription, - SearchBase.toArray()); - if(Search[0].contains("SearchShuffle_SameName")) SearchBase = SearchBase.getName(Initiator.getName()); - if(Search[0].contains("SearchShuffle_Type")) { - for(int TypeRestrict = 0; TypeRestrict < Custom_Strings.length; TypeRestrict ++) { - if(Custom_Strings[TypeRestrict].startsWith("Type")) SearchBase = SearchBase.getType(Custom_Strings[TypeRestrict].replaceFirst("Type", "")); - if(Custom_Strings[TypeRestrict].startsWith("Color")) { - final int Number = TypeRestrict; - SearchBase = SearchBase.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(CardUtil.getColors(c).contains(Custom_Strings[Number].replaceFirst("Color", ""))) return true; - return false; - } - }); - } - } - } - if(SearchBase.size() != 0) { - Object check = GuiUtils.getChoiceOptional("Select a Suitable Card", - SearchBase.toArray()); - if(check != null) { - SearchedCard[y] = (Card) check; - if(SearchLib) ((Card) check).getController().shuffle(); - } - } else { - JOptionPane.showMessageDialog(null, "No suitable cards in" + SearchDescription, "", JOptionPane.INFORMATION_MESSAGE); - if(SearchLib && Targets[y].contains("OSearchShuffle")) Source.getController().getOpponent().shuffle(); - else if(SearchLib) Source.getController().shuffle(); - } - } - } - return SearchedCard; - } - - String[] Search_Description(Card Initiator ,String[] Keyword_Details, final String[] Custom_Strings) { - String[] SD = new String[2]; - String SearchDescription = ""; - String SearchType = ""; - int Target_Conditions = 1; - String TargetParse = Keyword_Details[5]; - String Targets[] = TargetParse.split("!"); - Target_Conditions = Targets.length; - for(int y = 0; y < Target_Conditions; y++) { - if(Targets[y].contains("SearchShuffle")) { - if(Targets[y].contains("OSearchShuffle")) { - SearchDescription = SearchDescription + "Opponent's"; - } - String SearchParse = Targets[y]; - String Search[] = SearchParse.split("/"); - - for(int z = 0; z < Search.length - 1; z++) { - SearchDescription = SearchDescription + Search[z+1]; - if(z + 3 < Search.length) SearchDescription = SearchDescription + ", "; - else if(z + 2 != Search.length) SearchDescription = SearchDescription + " and/or "; - } - if(Search[0].contains("SearchShuffle_SameName")) SearchType = Initiator.getName() + " "; - if(Search[0].contains("SearchShuffle_Type")) { - for(int TypeRestrict = 0; TypeRestrict < Custom_Strings.length; TypeRestrict ++) { - if(Custom_Strings[TypeRestrict].startsWith("Color")) { - SearchType = SearchType + Custom_Strings[TypeRestrict].replaceFirst("Color", ""); - if(TypeRestrict + 1 != Custom_Strings.length) SearchType = SearchType + " "; - } - } - for(int TypeRestrict = 0; TypeRestrict < Custom_Strings.length; TypeRestrict ++) { - if(Custom_Strings[TypeRestrict].startsWith("Type")) { - SearchType = SearchType + Custom_Strings[TypeRestrict].replaceFirst("Type", ""); - if(TypeRestrict + 1 != Custom_Strings.length) SearchType = SearchType + " "; - } - } - } - } - } - SD[0] = SearchDescription; - SD[1] = SearchType; - - return SD; - } - - void Whenever_ManaPaid (Card Source, String[] Keyword_Details, final Command Proper_Resolve, SpellAbility ability) { - String S_Amount = "0"; - if(!Keyword_Details[7].contains("No_Condition") && !Keyword_Details[7].equals("Yes_No") - && !Keyword_Details[7].equals("Opponent_Yes_No")&& !Keyword_Details[7].contains("Choice_Instant")) { - if(Keyword_Details[7].contains("PayMana")) { - String PayAmountParse = Keyword_Details[7]; - S_Amount = PayAmountParse.split("/")[1]; - - if(Source.getController().equals(AllZone.HumanPlayer)) { - final Command paid = new Command() { - private static final long serialVersionUID = 151367344511590317L; - - public void execute() { - Proper_Resolve.execute(); - } - }; - StringBuilder sb = new StringBuilder(); - sb.append("Activate ").append(Source.getName()).append("'s ability: \n"); - - GameActionUtil.payManaDuringAbilityResolve(sb.toString(), S_Amount, paid, Command.Blank); - } else { - if(ComputerUtil.canPayCost(S_Amount)) { - ComputerUtil.payManaCost(ability); - Proper_Resolve.execute(); - } - } - } - if(Keyword_Details[7].contains("SacrificeType")) { - String PayAmountParse = Keyword_Details[7]; - S_Amount = PayAmountParse.split("/")[1]; - PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, Source.getController()); - CardList choice = new CardList(play.getCards()); - choice = choice.getType(S_Amount); - if(Source.getController().equals(AllZone.HumanPlayer)) { - AllZone.InputControl.setInput(CardFactoryUtil.Wheneverinput_sacrifice(ability, choice, "Select a " + S_Amount +" to sacrifice.",Proper_Resolve)); - } /*else { - if(choice.size() > 5) { - sacrifice(choice.get(0)); - Proper_Resolve.execute(); - } - } */ - } - } else Proper_Resolve.execute(); - - } - - - boolean Whenever_Go (Card Source, String[] Keyword_Details) { - boolean Go = true; - String Zones = Keyword_Details[3]; - PlayerZone[] Required_Zone = new PlayerZone[1]; - if(Zones.equals("Hand")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Hand, Source.getController()); - if(Zones.equals("Graveyard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Graveyard, Source.getController()); - if(Zones.equals("Play") || Zones.equals("Any")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Battlefield, Source.getController()); - if(Zones.contains("Library")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Library, Source.getController()); - if(Zones.contains("Exiled")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Exile, Source.getController()); - //if(Zones.contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, Source.getController()); - - if(AllZone.GameAction.isCardInZone(Source,Required_Zone[0]) || Zones.equals("Any")) { - if(Keyword_Details[7].equals("Yes_No")) { - if(Source.getController().equals(AllZone.HumanPlayer)) { - Object[] possibleValues = {"Yes", "No"}; - Object q = JOptionPane.showOptionDialog(null, "Activate - " + Source.getName(),Source.getName() + " Ability", - JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, - null, possibleValues, possibleValues[0]); - if(q.equals(1)) { - Go = false; - } - } - } - if(Keyword_Details[7].equals("Opponent_Yes_No")) { - if(!Source.getController().equals(AllZone.HumanPlayer)) { - Object[] possibleValues = {"Yes", "No"}; - Object q = JOptionPane.showOptionDialog(null, "Activate - " + Source.getName(),Source.getName() + " Ability", - JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, - null, possibleValues, possibleValues[0]); - if(q.equals(1)) { - Go = false; - } - } - } - } - - return Go; - } - - public void Whenever_Input(Card Source, String[] Keyword_Details, Command paidCommand, final SpellAbility ability) { - if(!Keyword_Details[8].contains("ActualEffect")) { - String Zones = Keyword_Details[3]; - PlayerZone[] Required_Zone = new PlayerZone[1]; - if(Zones.equals("Hand")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Hand, Source.getController()); - if(Zones.equals("Graveyard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Graveyard, Source.getController()); - if(Zones.equals("Play") || Zones.equals("Any")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Battlefield, Source.getController()); - if(Zones.contains("Library")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Library, Source.getController()); - if(Zones.contains("Exiled")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Exile, Source.getController()); - //if(Zones.contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, Source.getController()); - - if(AllZone.GameAction.isCardInZone(Source,Required_Zone[0]) || Zones.equals("Any")) { - if(Keyword_Details[6].equals("ASAP")) { - if(Keyword_Details[5].equals("InputType - CreatureORPlayer") && Source.getController().equals(AllZone.HumanPlayer)) { - paidCommand.execute(); - } - else if(Keyword_Details[5].equals("InputType - CreatureORPlayer") && Source.getController().equals(AllZone.ComputerPlayer)) - AllZone.Stack.add(ability); - else if(Keyword_Details[5].contains("NormalInput")) { - paidCommand.execute(); - } - else AllZone.Stack.add(ability); - } - } - } else paidCommand.execute(); - } - // Whenever Keyword - - public void sacrificeDestroy(Card c) { - if(!isCardInPlay(c)) return; - - Player owner = c.getOwner(); - if (!(owner.isComputer() || owner.isHuman())) - throw new RuntimeException("GameAction : destroy() invalid card.getOwner() - " + c + " " + owner); - - boolean persist = (c.getKeyword().contains("Persist") && c.getCounters(Counters.M1M1) == 0); - - Card newCard = moveToGraveyard(c); - - // Destroy needs to be called with Last Known Information - c.destroy(); - - //destroy card effects: - CardList list = AllZoneUtil.getCardsInPlay(); - list = list.filter(new CardListFilter() { - public boolean addCard(Card c) { - ArrayList keywords = c.getKeyword(); - for(String kw:keywords) { - if(kw.startsWith("Whenever ") && kw.contains(" put into") - && kw.contains("graveyard from the battlefield,")) return true; - } - return false; - } - }); - - checkWheneverKeyword(c, "PermanentIntoGraveyard",null); - for(int i = 0; i < list.size(); i++) - GameActionUtil.executeDestroyCardEffects(list.get(i), c); - - if(persist) { - final Card persistCard = newCard; - Ability persistAb = new Ability(persistCard, "0"){ - - @Override - public void resolve() { - if (AllZone.getZone(persistCard).is(Constant.Zone.Graveyard)){ - PlayerZone ownerPlay = AllZone.getZone(Constant.Zone.Battlefield, persistCard.getOwner()); - Card card = moveTo(ownerPlay, persistCard); - card.addCounter(Counters.M1M1, 1); - } - } - }; - persistAb.setStackDescription(newCard.getName() + " - Returning from Persist"); - AllZone.Stack.add(persistAb); - } - - if(c.getName().equals("Nissa's Chosen")) { - PlayerZone library = AllZone.getZone(Constant.Zone.Library, newCard.getOwner()); - moveTo(library, newCard); - } - - else if(c.getName().equals("Guan Yu, Sainted Warrior")) { - PlayerZone library = AllZone.getZone(Constant.Zone.Library, newCard.getOwner()); - newCard = moveTo(library, newCard); - owner.shuffle(); - } - }//sacrificeDestroy() - - public boolean destroy(Card c) { - if(!AllZone.GameAction.isCardInPlay(c) - || (c.getKeyword().contains("Indestructible") && (!c.isCreature() || c.getNetDefense() > 0))) return false; - - if(c.canBeShielded() && c.getShield() > 0) { - c.subtractShield(); - c.setDamage(0); - c.tap(); - AllZone.Combat.removeFromCombat(c); - return false; - } - - if (c.isEnchanted()) - { - CardList list = new CardList(c.getEnchantedBy().toArray()); - list = list.filter(new CardListFilter() - { - public boolean addCard(Card crd) - { - return crd.getKeyword().contains("Totem armor"); - } - }); - CardListUtil.sortCMC(list); - - - - if (list.size() != 0) - { - final Card crd; - if (list.size() == 1) - { - crd = list.get(0); - } - else { - if (c.getController().isHuman()) - crd = GuiUtils.getChoiceOptional("Select totem armor to destroy", list.toArray()); - else - crd = list.get(0); - } - - final Card card = c; - Ability_Static ability = new Ability_Static(crd, "0") - { - public void resolve() - { - destroy(crd); - card.setDamage(0); - - } - }; - - StringBuilder sb = new StringBuilder(); - sb.append(crd).append(" - Totem armor: destroy this aura."); - ability.setStackDescription(sb.toString()); - - AllZone.Stack.add(ability); - return false; - } - }//totem armor - - //System.out.println("Card " + c.getName() + " is getting sent to GY, and this turn it got damaged by: "); - for(Card crd:c.getReceivedDamageFromThisTurn().keySet()) { - if(c.getReceivedDamageFromThisTurn().get(crd) > 0) { - //System.out.println(crd.getName() ); - GameActionUtil.executeVampiricEffects(crd); - } - } - - this.sacrificeDestroy(c); - return true; - } - - //is this card a permanent that is in play? - public boolean isCardInPlay(Card c) { - return PlayerZoneUtil.isCardInZone(AllZone.Computer_Battlefield, c) - || PlayerZoneUtil.isCardInZone(AllZone.Human_Battlefield, c); - } - - public boolean isCardInGrave(Card c) { - return PlayerZoneUtil.isCardInZone(AllZone.Computer_Graveyard, c) - || PlayerZoneUtil.isCardInZone(AllZone.Human_Graveyard, c); - } - - public boolean isCardExiled(Card c) { - return PlayerZoneUtil.isCardInZone(AllZone.Computer_Exile, c) - || PlayerZoneUtil.isCardInZone(AllZone.Human_Exile, c); - } - - /** - * prompts Human to see if a target player's library should be shuffled. This should - * only be called when the choice is made by the Human (target can be either), then - * shuffles that player's library if appropriate - * - * @param player the player's library we want to shuffle - */ - public void promptForShuffle(final Player player) { - String[] choices = new String[] {"Yes", "No"}; - Object o = GuiUtils.getChoice("Shuffle "+player+"'s library?", choices); - String myChoice = (String) o; - if(myChoice.equals("Yes")) { - player.shuffle(); - } - } - - public boolean isCardInZone(Card card, PlayerZone p) { - ArrayList list = new ArrayList(Arrays.asList(p.getCards())); - return list.contains(card); - } - - //removes all damage from player's creatures - public void removeDamage(Player player) { - PlayerZone p = AllZone.getZone(Constant.Zone.Battlefield, player); - ArrayList a = PlayerZoneUtil.getCardType(p, "Creature"); - Card c[] = CardUtil.toCard(a); - for(int i = 0; i < c.length; i++) - c[i].setDamage(0); - } - - //for Quest fantasy mode - public void newGame(Deck humanDeck, Deck computerDeck, CardList human, CardList computer, int humanLife, int computerLife, Quest_Assignment qa) - { - this.newGame(humanDeck, computerDeck); - - AllZone.ComputerPlayer.setLife(computerLife, null); - AllZone.HumanPlayer.setLife(humanLife, null); - - if (qa != null){ - computer.addAll(QuestUtil.getComputerCreatures(AllZone.QuestData, AllZone.QuestAssignment).toArray()); - } - - for (Card c : human) - { - AllZone.Human_Battlefield.add(c); - c.setSickness(true); - } - - for (Card c: computer) - { - AllZone.Computer_Battlefield.add(c); - c.setSickness(true); - } - Constant.Quest.fantasyQuest[0] = true; - } - - boolean Start_Cut = false; - boolean StaticEffectKeywordReset = true; - public void newGame(Deck humanDeck, Deck computerDeck) { -// AllZone.Computer = new ComputerAI_Input(new ComputerAI_General()); - Constant.Quest.fantasyQuest[0] = false; - - AllZone.GameInfo.setPreventCombatDamageThisTurn(false); - AllZone.GameInfo.setHumanNumberOfTimesMulliganed(0); - AllZone.GameInfo.setHumanMulliganedToZero(false); - AllZone.GameInfo.setComputerStartedThisGame(false); - - AllZone.HumanPlayer.reset(); - AllZone.ComputerPlayer.reset(); - - AllZone.Phase.reset(); - AllZone.Stack.reset(); - AllZone.Combat.reset(); - AllZone.Display.showCombat(""); - AllZone.Display.loadPrefs(); - - AllZone.Human_Graveyard.reset(); - AllZone.Human_Hand.reset(); - AllZone.Human_Library.reset(); - AllZone.Human_Battlefield.reset(); - AllZone.Human_Exile.reset(); - - AllZone.Computer_Graveyard.reset(); - AllZone.Computer_Hand.reset(); - AllZone.Computer_Library.reset(); - AllZone.Computer_Battlefield.reset(); - AllZone.Computer_Exile.reset(); - - AllZone.InputControl.clearInput(); - - AllZone.StaticEffects.reset(); - StaticEffectKeywordReset = true; - - AllZone.HumanPlayer.clearHandSizeOperations(); - AllZone.ComputerPlayer.clearHandSizeOperations(); - - AllZone.TriggerHandler.clearRegistered(); - - - {//re-number cards just so their unique numbers are low, just for user friendliness - CardFactory c = AllZone.CardFactory; - Card card; - int nextUniqueNumber = 1; - - Random generator = new Random(); - - for(int i = 0; i < humanDeck.countMain(); i++) { - card = c.getCard(humanDeck.getMain(i), AllZone.HumanPlayer); - card.setUniqueNumber(nextUniqueNumber++); - - //if(card.isBasicLand()) { - //String PC = card.getSVar("PicCount"); - //if (PC.matches("[0-9][0-9]?")) - // n = Integer.parseInt(PC); - - if ((card.getSets().size() > 0) && card.getCurSetCode().equals("")) - card.setRandomSetCode(); - - if (!card.getCurSetCode().equals("")) { - int n = SetInfoUtil.getSetInfo_Code(card.getSets(), card.getCurSetCode()).PicCount; - if (n > 1) - card.setRandomPicture(generator.nextInt(n-1) + 1); - - card.setImageFilename(CardUtil.buildFilename(card)); - } - - //System.out.println("human random number:" + card.getRandomPicture()); - //} - - AllZone.Human_Library.add(card); - - for(Trigger trig : card.getTriggers()) - { - AllZone.TriggerHandler.registerTrigger(trig); - } - } - - ArrayList RAICards = new ArrayList(); - for(int i = 0; i < computerDeck.countMain(); i++) { - card = c.getCard(computerDeck.getMain(i), AllZone.ComputerPlayer); - card.setUniqueNumber(nextUniqueNumber++); - - //if(card.isBasicLand()) { - //String PC = card.getSVar("PicCount"); - //int n = 0; - //if (PC.matches("[0-9][0-9]?")) - // n = Integer.parseInt(PC); - //if (n > 1) - // card.setRandomPicture(generator.nextInt(n)); - //System.out.println("computer random number:" + card.getRandomPicture()); - //} - if ((card.getSets().size() > 0) && card.getCurSetCode().equals("")) - card.setRandomSetCode(); - - if (!card.getCurSetCode().equals("")) { - int n = SetInfoUtil.getSetInfo_Code(card.getSets(), card.getCurSetCode()).PicCount; - if (n > 1) - card.setRandomPicture(generator.nextInt(n-1) + 1); - - card.setImageFilename(CardUtil.buildFilename(card)); - } - - AllZone.Computer_Library.add(card); - - for(Trigger trig : card.getTriggers()) - { - AllZone.TriggerHandler.registerTrigger(trig); - } - - if (card.getSVar("RemAIDeck").equals("True")) - RAICards.add(card.getName()); - //get card picture so that it is in the image cache -// ImageCache.getImage(card); - } - - if (RAICards.size() > 0) - { - StringBuilder sb = new StringBuilder("AI deck contains the following cards that it can't play or may be buggy:\n"); - for (int i=0; i 0)) - sb.append("\n"); - else if (i != (RAICards.size() - 1)) - sb.append(", "); - } - - JOptionPane.showMessageDialog(null, sb.toString(), "", JOptionPane.INFORMATION_MESSAGE); - - } - }//end re-numbering - - for(int i = 0; i < 100; i++) - AllZone.HumanPlayer.shuffle(); - - //do this instead of shuffling Computer's deck - boolean smoothLand = Constant.Runtime.Smooth[0]; - - if(smoothLand) { - Card[] c = smoothComputerManaCurve(AllZone.Computer_Library.getCards()); - AllZone.Computer_Library.setCards(c); - } else { - AllZone.Computer_Library.setCards(AllZone.Computer_Library.getCards()); - AllZone.ComputerPlayer.shuffle(); - } - - // Only cut/coin toss if it's the first game of the match - if (Constant.Runtime.WinLose.countWinLose() == 0) - { - // New code to determine who goes first. Delete this if it doesn't work properly - if(Start_Cut) - seeWhoPlaysFirst(); - else - seeWhoPlaysFirst_CoinToss(); - } - else if (Constant.Runtime.WinLose.didWinRecently()) // if player won last, AI starts - computerStartsGame(); - - for(int i = 0; i < 7; i++) { - AllZone.HumanPlayer.drawCard(); - AllZone.ComputerPlayer.drawCard(); - } - - // todo: ManaPool should be moved to Player and be represented in the player panel - ManaPool mp = AllZone.ManaPool; - mp.setImageFilename("mana_pool"); - AllZone.Human_Battlefield.add(mp); - - AllZone.InputControl.setInput(new Input_Mulligan()); - Phase.GameBegins = 1; - }//newGame() - - //this is where the computer cheats - //changes AllZone.Computer_Library - private Card[] smoothComputerManaCurve(Card[] in) { - CardList library = new CardList(in); - library.shuffle(); - - //remove all land, keep non-basicland in there, shuffled - CardList land = library.getType("Land"); - for(int i = 0; i < land.size(); i++) - if(land.get(i).isLand()) library.remove(land.get(i)); - - //non-basic lands are removed, because the computer doesn't seem to - //effectively use them very well - land = threadLand(land); - - try { - //mana weave, total of 7 land - // The Following have all been reduced by 1, to account for the computer starting first. - library.add(6, land.get(0)); - library.add(7, land.get(1)); - library.add(8, land.get(2)); - library.add(9, land.get(3)); - library.add(10, land.get(4)); - - library.add(12, land.get(5)); - library.add(15, land.get(6)); - } catch(IndexOutOfBoundsException e) { - System.err.println("Error: cannot smooth mana curve, not enough land"); - return in; - } - - //add the rest of land to the end of the deck - for(int i = 0; i < land.size(); i++) - if(!library.contains(land.get(i))) library.add(land.get(i)); - - - //check - for(int i = 0; i < library.size(); i++) - System.out.println(library.get(i)); - - - return library.toArray(); - }//smoothComputerManaCurve() - - /* - @SuppressWarnings("unused") - // getComputerLand - private CardList getComputerLand(CardList in) { - CardList land; - land = in.filter(new CardListFilter() { - public boolean addCard(Card c) { - return c.isLand(); - } - }); - - return land; - }//getComputerLand() - */ - - //non-basic lands are removed, because the computer doesn't seem to - //effectively used them very well - public CardList threadLand(CardList in) { - //String[] basicLand = {"Forest", "Swamp", "Mountain", "Island", "Plains"}; //unused - - //Thread stuff with as large a spread of colors as possible: - String[] allLand = { - "Bayou", "Volcanic Island", "Savannah", "Badlands", "Tundra", "Taiga", "Underground Sea", - "Plateau", "Tropical Island", "Scrubland", "Overgrown Tomb", "Steam Vents", "Temple Garden", - "Blood Crypt", "Hallowed Fountain", "Stomping Ground", "Watery Grave", "Sacred Foundry", - "Breeding Pool", "Godless Shrine", "Pendelhaven", "Flagstones of Trokair", "Forest", "Swamp", - "Mountain", "Island", "Plains", "Tree of Tales", "Vault of Whispers", "Great Furnace", - "Seat of the Synod", "Ancient Den", "Treetop Village", "Ghitu Encampment", "Faerie Conclave", - "Forbidding Watchtower", "Savage Lands", "Arcane Sanctum", "Jungle Shrine", - "Crumbling Necropolis", "Seaside Citadel", "Elfhame Palace", "Coastal Tower", "Salt Marsh", - "Kher Keep", "Library of Alexandria", "Dryad Arbor"}; - - - ArrayList land = new ArrayList(); - - //get different CardList of all Forest, Swamps, etc... - CardList check; - for(int i = 0; i < allLand.length; i++) { - check = in.getName(allLand[i]); - - if(!check.isEmpty()) land.add(check); - } - /* - //get non-basic land CardList - check = in.filter(new CardListFilter() - { - public boolean addCard(Card c) - { - return c.isLand() && !c.isBasicLand(); - } - }); - if(! check.isEmpty()) - land.add(check); - */ - - //thread all separate CardList's of land together to get something like - //Mountain, Plains, Island, Mountain, Plains, Island - CardList out = new CardList(); - - int i = 0; - while(!land.isEmpty()) { - i = (i + 1) % land.size(); - - check = land.get(i); - if(check.isEmpty()) { - //System.out.println("removed"); - land.remove(i); - i--; - continue; - } - - out.add(check.get(0)); - check.remove(0); - }//while - - return out; - }//threadLand() - - - @SuppressWarnings("unused") - // getDifferentLand - private int getDifferentLand(CardList list, String land) { - int out = 0; - - return out; - } - - //decides who goes first when starting another game, used by newGame() - public void seeWhoPlaysFirst_CoinToss() { - Object[] possibleValues = {ForgeProps.getLocalized(GAMEACTION_TEXT.HEADS), ForgeProps.getLocalized(GAMEACTION_TEXT.TAILS)}; - Object q = JOptionPane.showOptionDialog(null, ForgeProps.getLocalized(GAMEACTION_TEXT.HEADS_OR_TAILS), ForgeProps.getLocalized(GAMEACTION_TEXT.COIN_TOSS), - JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, - null, possibleValues, possibleValues[0]); - - int Flip = MyRandom.random.nextInt(2); - String Human_Flip = " "; - String Computer_Flip = " "; - // JOptionPane.showMessageDialog(null, q, "", JOptionPane.INFORMATION_MESSAGE); - if(q.equals(0)) { - Human_Flip = ForgeProps.getLocalized(GAMEACTION_TEXT.HEADS); - Computer_Flip = ForgeProps.getLocalized(GAMEACTION_TEXT.TAILS); - } - else { - Human_Flip = ForgeProps.getLocalized(GAMEACTION_TEXT.TAILS); - Computer_Flip = ForgeProps.getLocalized(GAMEACTION_TEXT.HEADS); - } - - if((Flip == 0 && q.equals(0)) || (Flip == 1 && q.equals(1))) - JOptionPane.showMessageDialog(null, Human_Flip + "\r\n" + ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_WIN), "", JOptionPane.INFORMATION_MESSAGE); - else { - computerStartsGame(); - JOptionPane.showMessageDialog(null, Computer_Flip + "\r\n" + ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_WIN), "", JOptionPane.INFORMATION_MESSAGE); - } - }//seeWhoPlaysFirst_CoinToss() - - Card HumanCut = null; - Card ComputerCut = null; - - public void seeWhoPlaysFirst() { - - CardList HLibrary = new CardList(AllZone.getZone(Constant.Zone.Library, AllZone.HumanPlayer).getCards()); - HLibrary = HLibrary.filter(new CardListFilter() { - public boolean addCard(Card c) { - return !c.isLand(); - } - }); - CardList CLibrary = new CardList(AllZone.getZone(Constant.Zone.Library, AllZone.ComputerPlayer).getCards()); - CLibrary = CLibrary.filter(new CardListFilter() { - public boolean addCard(Card c) { - return !c.isLand(); - } - }); - - boolean Starter_Determined = false; - int Cut_Count = 0; - int Cut_CountMax = 20; - for(int i = 0; i < Cut_CountMax; i++) { - if(Starter_Determined == true) break; - - if(HLibrary.size() > 0) - HumanCut = HLibrary.get(MyRandom.random.nextInt(HLibrary.size())); - else { - computerStartsGame(); - JOptionPane.showMessageDialog(null, ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_MANA_COST) + "\r\n" + ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_STARTS), "", JOptionPane.INFORMATION_MESSAGE); - return; - } - - if(CLibrary.size() > 0) - ComputerCut = CLibrary.get(MyRandom.random.nextInt(CLibrary.size())); - else { - JOptionPane.showMessageDialog(null, ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_MANA_COST) + "\r\n" + ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_STARTS), "", JOptionPane.INFORMATION_MESSAGE); - return; - } - - Cut_Count = Cut_Count + 1; - AllZone.GameAction.moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.HumanPlayer),AllZone.GameAction.HumanCut); - AllZone.GameAction.moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.ComputerPlayer),AllZone.GameAction.ComputerCut); - - StringBuilder sb = new StringBuilder(); - sb.append(ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_CUT) + HumanCut.getName() + " (" + HumanCut.getManaCost() + ")" + "\r\n"); - sb.append(ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_CUT) + ComputerCut.getName() + " (" + ComputerCut.getManaCost() + ")" + "\r\n"); - sb.append("\r\n" + "Number of times the deck has been cut: " + Cut_Count + "\r\n"); - if(CardUtil.getConvertedManaCost(ComputerCut.getManaCost()) > CardUtil.getConvertedManaCost(HumanCut.getManaCost())){ - computerStartsGame(); - JOptionPane.showMessageDialog(null, sb + ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_STARTS), "", JOptionPane.INFORMATION_MESSAGE); - return; - } - else if(CardUtil.getConvertedManaCost(ComputerCut.getManaCost()) < CardUtil.getConvertedManaCost(HumanCut.getManaCost())) { - JOptionPane.showMessageDialog(null, sb + ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_STARTS), "", JOptionPane.INFORMATION_MESSAGE); - return; - } - else{ - sb.append(ForgeProps.getLocalized(GAMEACTION_TEXT.EQUAL_CONVERTED_MANA) + "\r\n"); - if (i == Cut_CountMax-1) - { - sb.append(ForgeProps.getLocalized(GAMEACTION_TEXT.RESOLVE_STARTER)); - if(MyRandom.random.nextInt(2) == 1) - JOptionPane.showMessageDialog(null,sb + ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_WIN), "", JOptionPane.INFORMATION_MESSAGE); - else { - computerStartsGame(); - JOptionPane.showMessageDialog(null,sb + ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_WIN), "", JOptionPane.INFORMATION_MESSAGE); - } - return; - } - else - { - sb.append(ForgeProps.getLocalized(GAMEACTION_TEXT.CUTTING_AGAIN)); - } - JOptionPane.showMessageDialog(null,sb, "", JOptionPane.INFORMATION_MESSAGE); - } - } // for-loop for multiple card cutting - - - }//seeWhoPlaysFirst() - - public void computerStartsGame() - { - AllZone.Phase.setPlayerTurn(AllZone.ComputerPlayer); - AllZone.GameInfo.setComputerStartedThisGame(true); - } - - //if Card had the type "Aura" this method would always return true, since local enchantments are always attached to something - //if Card is "Equipment", returns true if attached to something - public boolean isAttachee(Card c) { - CardList list = new CardList(AllZone.Computer_Battlefield.getCards()); - list.addAll(AllZone.Human_Battlefield.getCards()); - - for(int i = 0; i < list.size(); i++) { - CardList check = new CardList(list.getCard(i).getAttachedCards()); - if(check.contains(c)) return true; - } - - return false; - }//isAttached(Card c) - - public boolean playCard(Card c) { - // this can only be called by the Human - HashMap map = new HashMap(); - SpellAbility[] abilities = canPlaySpellAbility(c.getSpellAbility()); - ArrayList choices = new ArrayList(); - - if(c.isLand() && isCardInZone(c, AllZone.Human_Hand) && AllZone.HumanPlayer.canPlayLand()) - choices.add("Play land"); - - for(SpellAbility sa:abilities) { - // for uncastables like lotus bloom, check if manaCost is blank - sa.setActivatingPlayer(AllZone.HumanPlayer); - if(sa.canPlay() && (!sa.isSpell() || !sa.getManaCost().equals(""))) { - choices.add(sa.toString()); - map.put(sa.toString(), sa); - } - } - - String choice; - if (choices.size() == 0) - return false; - else if (choices.size() == 1) - choice = choices.get(0); - else - choice = (String) GuiUtils.getChoiceOptional("Choose", choices.toArray()); - - if (choice == null) - return false; - - if(choice.equals("Play land")){ - AllZone.HumanPlayer.playLand(c); - return true; - } - - SpellAbility ability = map.get(choice); - if(ability != null){ - playSpellAbility(ability); - return true; - } - return false; - } - - public void playCardNoCost(Card c) { - //SpellAbility[] choices = (SpellAbility[]) c.getSpells().toArray(); - ArrayList choices = c.getBasicSpells(); - SpellAbility sa; - - //TODO: add Buyback, Kicker, ... , spells here - /* - ArrayList additional = c.getAdditionalCostSpells(); - for (SpellAbility s : additional) - { - - } - */ - /* - System.out.println(choices.length); - for(int i = 0; i < choices.length; i++) - System.out.println(choices[i]); - */ - if(choices.size() == 0) return; - else if(choices.size() == 1) sa = choices.get(0); - else sa = (SpellAbility) GuiUtils.getChoiceOptional("Choose", choices.toArray()); - - if(sa == null) return; - - // Ripple causes a crash because it doesn't set the activatingPlayer in this entrance - if (sa.getActivatingPlayer() == null) - sa.setActivatingPlayer(AllZone.HumanPlayer); - playSpellAbilityForFree(sa); - } - - public void playSpellAbilityForFree(final SpellAbility sa) { - - if (sa.getPayCosts() != null){ - Target_Selection ts = new Target_Selection(sa.getTarget(), sa); - Cost_Payment payment = new Cost_Payment(sa.getPayCosts(), sa); - - SpellAbility_Requirements req = new SpellAbility_Requirements(sa, ts, payment); - req.setFree(true); - req.fillRequirements(); - } - else if(sa.getBeforePayMana() == null) { - if (sa.isSpell()){ - Card c = sa.getSourceCard(); - if (!c.isCopiedSpell()) - AllZone.GameAction.moveToStack(c); - } - boolean x = false; - if (sa.getSourceCard().getManaCost().contains("X")) - x = true; - - if (sa.isKickerAbility()) { - Command paid1 = new Command() { - private static final long serialVersionUID = -6531785460264284794L; - - public void execute() { - AllZone.Stack.add(sa); - } - }; - AllZone.InputControl.setInput(new Input_PayManaCost_Ability(sa.getAdditionalManaCost(),paid1)); - }else { - AllZone.Stack.add(sa, x); - } - } else { - sa.setManaCost("0"); // Beached As - if (sa.isKickerAbility()) { - sa.getBeforePayMana().setFree(false); - sa.setManaCost(sa.getAdditionalManaCost()); - } else { - sa.getBeforePayMana().setFree(true); - } - AllZone.InputControl.setInput(sa.getBeforePayMana()); - } - } - - int CostCutting_GetMultiMickerManaCostPaid = 0; - String CostCutting_GetMultiMickerManaCostPaid_Colored = ""; - public ManaCost getSpellCostChange(SpellAbility sa, ManaCost originalCost) { - // Beached - Card originalCard = sa.getSourceCard(); - SpellAbility spell = sa; - ManaCost manaCost = new ManaCost(originalCost.toString()); - - if(spell.isSpell() == true) { - if(originalCard.getName().equals("Avatar of Woe")){ - Player player = AllZone.Phase.getPlayerTurn(); - Player opponent = player.getOpponent(); - PlayerZone PlayerGraveyard = AllZone.getZone(Constant.Zone.Graveyard, player); - CardList PlayerCreatureList = new CardList(PlayerGraveyard.getCards()); - PlayerCreatureList = PlayerCreatureList.getType("Creature"); - PlayerZone OpponentGraveyard = AllZone.getZone(Constant.Zone.Graveyard, opponent); - CardList OpponentCreatureList = new CardList(OpponentGraveyard.getCards()); - OpponentCreatureList = OpponentCreatureList.getType("Creature"); - if((PlayerCreatureList.size() + OpponentCreatureList.size()) >= 10) { - manaCost = new ManaCost("B B"); - } // Avatar of Woe - } else if(originalCard.getName().equals("Avatar of Will")) { - Player player = AllZone.Phase.getPlayerTurn(); - Player opponent = player.getOpponent(); - PlayerZone OpponentHand = AllZone.getZone(Constant.Zone.Hand, opponent); - CardList OpponentHandList = new CardList(OpponentHand.getCards()); - if(OpponentHandList.size() == 0) { - manaCost = new ManaCost("U U"); - } // Avatar of Will - } else if(originalCard.getName().equals("Avatar of Fury")) { - Player player = AllZone.Phase.getPlayerTurn(); - Player opponent = player.getOpponent(); - PlayerZone OpponentPlay = AllZone.getZone(Constant.Zone.Battlefield, opponent); - CardList OpponentLand = new CardList(OpponentPlay.getCards()); - OpponentLand = OpponentLand.getType("Land"); - if(OpponentLand.size() >= 7) { - manaCost = new ManaCost("R R"); - } // Avatar of Fury - } else if(originalCard.getName().equals("Avatar of Might")) { - Player player = AllZone.Phase.getPlayerTurn(); - Player opponent = player.getOpponent(); - PlayerZone PlayerPlay = AllZone.getZone(Constant.Zone.Battlefield, player); - CardList PlayerCreature = new CardList(PlayerPlay.getCards()); - PlayerCreature = PlayerCreature.getType("Creature"); - PlayerZone OpponentPlay = AllZone.getZone(Constant.Zone.Battlefield, opponent); - CardList OpponentCreature = new CardList(OpponentPlay.getCards()); - OpponentCreature = OpponentCreature.getType("Creature"); - if(OpponentCreature.size() - PlayerCreature.size() >= 4) { - manaCost = new ManaCost("G G"); - } // Avatar of Might - } - } // isSpell - - // Get Cost Reduction - if(Phase.GameBegins == 1) { // Remove GameBegins from Phase and into The starting game code - CardList Cards_In_Play = new CardList(); - Cards_In_Play.addAll(AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer).getCards()); - Cards_In_Play.addAll(AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer).getCards()); - Cards_In_Play = Cards_In_Play.filter(new CardListFilter() { - public boolean addCard(Card c) { - if(c.getKeyword().toString().contains("CostChange")) return true; - return false; - } - }); - Cards_In_Play.add(originalCard); - String Mana = manaCost.toString(); - CardList Player_Play = new CardList(AllZone.getZone(Constant.Zone.Battlefield, sa.getSourceCard().getController()).getCards()); - CardList Player_Hand = new CardList(AllZone.getZone(Constant.Zone.Hand, sa.getSourceCard().getController()).getCards()); - int XBonus = 0; - int Max = 25; - if(sa.isXCost() && !sa.getSourceCard().isCopiedSpell()) sa.getSourceCard().setXManaCostPaid(0); - if(sa.isMultiKicker()) CostCutting_GetMultiMickerManaCostPaid_Colored = ""; - if(Mana.toString().length() == 0) Mana = "0"; - for(int i = 0; i < Cards_In_Play.size() ; i++) { - Card card = Cards_In_Play.get(i); - ArrayList a = card.getKeyword(); - int CostKeywords = 0; - int CostKeyword_Number[] = new int[a.size()]; - for(int x = 0; x < a.size(); x++) - if(a.get(x).toString().startsWith("CostChange")) { - CostKeyword_Number[CostKeywords] = x; - CostKeywords = CostKeywords + 1; - } - for(int CKeywords = 0; CKeywords < CostKeywords; CKeywords++) { - String parse = card.getKeyword().get(CostKeyword_Number[CKeywords]).toString(); - String k[] = parse.split(":"); - if(card.equals(originalCard)) { - if(!k[4].equals("Self")) k[2] = "Owned"; - } - if(k[2].equals("More")) { - if(k[7].equals("OnlyOneBonus")) { // Only Works for Color and Type - for(int string_no = 5; string_no < 7; string_no++) { - String spilt = k[string_no]; - String color_spilt[] = spilt.split("/"); - - for(int cs_num = 0; cs_num < color_spilt.length; cs_num++) { - k[string_no] = color_spilt[cs_num]; - if(string_no == 5 && CardUtil.getColors(sa.getSourceCard()).contains(k[5])) break; - if(string_no == 6 && (sa.getSourceCard().isType(k[6]))) break; - } - } - } - if(k[7].contains("All Conditions")) { // Only Works for Color and Type - for(int string_no = 5; string_no < 7; string_no++) { - String spilt = k[string_no]; - String color_spilt[] = spilt.split("/"); - for(int cs_num = 0; cs_num < color_spilt.length; cs_num++) { - k[string_no] = color_spilt[cs_num]; - if(string_no == 5) { - if(CardUtil.getColors(sa.getSourceCard()).contains(k[5]) || k[5].equals("All")) { - } else { - k[5] = "Nullified"; - break; - } - } - if(string_no == 6) { - if(sa.getSourceCard().isType(k[6]) || k[6].equals("All")) { - } else { - k[6] = "Nullified"; - break; - } - } - } - } - if(!k[5].equals("Nullified")) k[5] = "All"; - if(!k[6].equals("Nullified")) k[6] = "All"; - } - if((k[1].equals("Player") && card.getController().equals(sa.getSourceCard().getController()) - || (k[1].equals("Opponent") && card.getController().equals(sa.getSourceCard().getController().getOpponent())) || k[1].equals("All")) - && ((k[4].equals("Spell") && sa.isSpell() == true) || (k[4].equals("Ability") && sa.isAbility() == true) - || (k[4].startsWith("Ability_Cycling") && sa.isCycling()) || (k[4].equals("Self") && originalCard.equals(card)) - || (k[4].equals("Enchanted") && originalCard.getEnchantedBy().contains(card)) || k[4].equals("All")) - && ((CardUtil.getColors(sa.getSourceCard()).contains(k[5])) || k[5].equals("All")) - && ((sa.getSourceCard().isType(k[6])) - || (!(sa.getSourceCard().isType(k[6])) && k[7].contains("NonType")) || k[6].equals("All"))) { - if(k[7].contains("CardIsTapped")) { - if(card.isTapped() == false) k[3] = "0"; - } - if(k[7].contains("TargetInPlay")) { - if(!Player_Play.contains(sa.getSourceCard())) k[3] = "0"; - } - if(k[7].contains("TargetInHand")) { - if(!Player_Hand.contains(sa.getSourceCard())) k[3] = "0"; - } - if(k[7].contains("NonType")) { - if(originalCard.isType(k[6])) k[3] = "0"; - } - if(k[7].contains("OpponentTurn")) { - if(AllZone.Phase.isPlayerTurn(originalCard.getController())) k[3] = "0"; - } - if(k[7].contains("Affinity")) { - String spilt = k[7]; - String color_spilt[] = spilt.split("/"); - k[7] = color_spilt[1]; - PlayerZone PlayerPlay = AllZone.getZone(Constant.Zone.Battlefield, originalCard.getController()); - CardList PlayerList = new CardList(PlayerPlay.getCards()); - PlayerList = PlayerList.getType(k[7]); - k[3] = String.valueOf(PlayerList.size()); - } - String[] Numbers = new String[Max]; - if("X".equals(k[3])) { - for(int no = 0; no < Max; no ++) Numbers[no] = String.valueOf(no); - String Number_ManaCost = " "; - if(Mana.toString().length() == 1) { - Number_ManaCost = Mana.toString().substring(0, 1); - } - else if(Mana.toString().length() == 0) { - Number_ManaCost = "0"; // Should Never Occur - } - else { - Number_ManaCost = Mana.toString().substring(0, 2); - } - Number_ManaCost = Number_ManaCost.trim(); - for(int check = 0; check < Max; check ++) { - if(Number_ManaCost.equals(Numbers[check])) { - int xValue = CardFactoryUtil.xCount(originalCard, originalCard.getSVar("X")); - //if((spell.isXCost()) || (spell.isMultiKicker()) && (check - Integer.valueOf(k[3])) < 0) XBonus = XBonus - check + Integer.valueOf(k[3]); - Mana = Mana.replaceFirst(String.valueOf(check),String.valueOf(check + xValue)); - } - if(Mana.equals("")) Mana = "0"; - manaCost = new ManaCost(Mana); - } - } - else if(!"WUGRB".contains(k[3])) { - for(int no = 0; no < Max; no ++) Numbers[no] = String.valueOf(no); - String Number_ManaCost = " "; - if(Mana.toString().length() == 1) Number_ManaCost = Mana.toString().substring(0, 1); - else if(Mana.toString().length() == 0) Number_ManaCost = "0"; // Should Never Occur - else Number_ManaCost = Mana.toString().substring(0, 2); - Number_ManaCost = Number_ManaCost.trim(); - - for(int check = 0; check < Max; check ++) { - if(Number_ManaCost.equals(Numbers[check])) { - Mana = Mana.replaceFirst(String.valueOf(check),String.valueOf(check + Integer.valueOf(k[3]))); - } - if(Mana.equals("")) Mana = "0"; - manaCost = new ManaCost(Mana); - } - if(!manaCost.toString().contains("0") && !manaCost.toString().contains("1") && !manaCost.toString().contains("2") - && !manaCost.toString().contains("3") && !manaCost.toString().contains("4") && !manaCost.toString().contains("5") - && !manaCost.toString().contains("6") && !manaCost.toString().contains("7") && !manaCost.toString().contains("8") - && !manaCost.toString().contains("9")) { - Mana = k[3] + " " + Mana; - manaCost = new ManaCost(Mana); - } - } else { - Mana = Mana + " " + k[3]; - manaCost = new ManaCost(Mana); - } - } - } - } - } - - if(Mana.equals("0") && spell.isAbility()) { - } else { - for(int i = 0; i < Cards_In_Play.size() ; i++) { - Card card = Cards_In_Play.get(i); - ArrayList a = card.getKeyword(); - int CostKeywords = 0; - int CostKeyword_Number[] = new int[a.size()]; - for(int x = 0; x < a.size(); x++) - if(a.get(x).toString().startsWith("CostChange")) { - CostKeyword_Number[CostKeywords] = x; - CostKeywords = CostKeywords + 1; - } - for(int CKeywords = 0; CKeywords < CostKeywords; CKeywords++) { - String parse = card.getKeyword().get(CostKeyword_Number[CKeywords]).toString(); - String k[] = parse.split(":"); - if(card.equals(originalCard)) { - if(!k[4].equals("Self")) k[2] = "Owned"; - } - if(k[2].equals("Less")) { - if(k[7].equals("OnlyOneBonus")) { // Only Works for Color and Type - for(int string_no = 5; string_no < 7; string_no++) { - String spilt = k[string_no]; - String color_spilt[] = spilt.split("/"); - - for(int cs_num = 0; cs_num < color_spilt.length; cs_num++) { - k[string_no] = color_spilt[cs_num]; - if(string_no == 5 && CardUtil.getColors(sa.getSourceCard()).contains(k[5])) break; - if(string_no == 6 && (sa.getSourceCard().isType(k[6]))) break; - } - } - } - if(k[7].contains("All Conditions")) { // Only Works for Color and Type - for(int string_no = 5; string_no < 7; string_no++) { - String spilt = k[string_no]; - String color_spilt[] = spilt.split("/"); - for(int cs_num = 0; cs_num < color_spilt.length; cs_num++) { - k[string_no] = color_spilt[cs_num]; - if(string_no == 5) { - if(CardUtil.getColors(sa.getSourceCard()).contains(k[5]) || k[5].equals("All")) { - } else { - k[5] = "Nullified"; - break; - } - } - if(string_no == 6) { - if(sa.getSourceCard().isType(k[6]) || k[6].equals("All")) { - } else { - k[6] = "Nullified"; - break; - } - } - } - } - if(!k[5].equals("Nullified")) k[5] = "All"; - if(!k[6].equals("Nullified")) k[6] = "All"; - } - if((k[1].equals("Player") && card.getController().equals(sa.getSourceCard().getController()) - || (k[1].equals("Opponent") && card.getController().equals(sa.getSourceCard().getController().getOpponent())) || k[1].equals("All")) - && ((k[4].equals("Spell") && sa.isSpell() == true) || (k[4].equals("Ability") && sa.isAbility() == true) - || (k[4].startsWith("Ability_Cycling") && sa.isCycling()) || (k[4].equals("Self") && originalCard.equals(card)) - || (k[4].equals("Enchanted") && originalCard.getEnchantedBy().contains(card)) || k[4].equals("All")) - && ((CardUtil.getColors(sa.getSourceCard()).contains(k[5])) || k[5].equals("All")) - /** - * Chris added a test for Changeling. - * This appears to reduce the cost correctly. - * Works for both the computer and the human. - */ - && ((sa.getSourceCard().isType(k[6])) - - || (!(sa.getSourceCard().isType(k[6])) && k[7].contains("NonType")) || k[6].equals("All"))) { - if(k[7].contains("CardIsTapped")) { - if(card.isTapped() == false) k[3] = "0"; - } - if(k[7].contains("TargetInPlay")) { - if(!Player_Play.contains(sa.getSourceCard())) k[3] = "0"; - } - if(k[7].contains("TargetInHand")) { - if(!Player_Hand.contains(sa.getSourceCard())) k[3] = "0"; - } - if(k[7].contains("NonType")) { - if(originalCard.isType(k[6])) k[3] = "0"; - } - if(k[7].contains("OpponentTurn")) { - if(AllZone.Phase.isPlayerTurn(originalCard.getController())) k[3] = "0"; - } - if(k[7].contains("Affinity")) { - String spilt = k[7]; - String color_spilt[] = spilt.split("/"); - k[7] = color_spilt[1]; - PlayerZone PlayerPlay = AllZone.getZone(Constant.Zone.Battlefield, originalCard.getController()); - CardList PlayerList = new CardList(PlayerPlay.getCards()); - PlayerList = PlayerList.getType(k[7]); - k[3] = String.valueOf(PlayerList.size()); - } - - String[] Numbers = new String[Max]; - if("X".equals(k[3])) { - for(int no = 0; no < Max; no ++) Numbers[no] = String.valueOf(no); - String Number_ManaCost = " "; - if(Mana.toString().length() == 1) { - Number_ManaCost = Mana.toString().substring(0, 1); - } - else if(Mana.toString().length() == 0) { - Number_ManaCost = "0"; // Should Never Occur - } - else { - Number_ManaCost = Mana.toString().substring(0, 2); - } - Number_ManaCost = Number_ManaCost.trim(); - for(int check = 0; check < Max; check ++) { - if(Number_ManaCost.equals(Numbers[check])) { - int xValue = CardFactoryUtil.xCount(originalCard, originalCard.getSVar("X")); - //if((spell.isXCost()) || (spell.isMultiKicker()) && (check - Integer.valueOf(k[3])) < 0) XBonus = XBonus - check + Integer.valueOf(k[3]); - Mana = Mana.replaceFirst(String.valueOf(check),String.valueOf(check - xValue)); - } - if(Mana.equals("")) Mana = "0"; - manaCost = new ManaCost(Mana); - } - } - else if(!"WUGRB".contains(k[3])) { - for(int no = 0; no < Max; no ++) Numbers[no] = String.valueOf(no); - String Number_ManaCost = " "; - if(Mana.toString().length() == 1) Number_ManaCost = Mana.toString().substring(0, 1); - else if(Mana.toString().length() == 0) Number_ManaCost = "0"; // Should Never Occur - else Number_ManaCost = Mana.toString().substring(0, 2); - Number_ManaCost = Number_ManaCost.trim(); - - for(int check = 0; check < Max; check ++) { - if(Number_ManaCost.equals(Numbers[check])) { - if((spell.isXCost()) || (spell.isMultiKicker()) && (check - Integer.valueOf(k[3])) < 0) XBonus = XBonus - check + Integer.valueOf(k[3]); - if(check - Integer.valueOf(k[3]) < 0) k[3] = String.valueOf(check); - Mana = Mana.replaceFirst(String.valueOf(check),String.valueOf(check - Integer.valueOf(k[3]))); - } - if(Mana.equals("")) Mana = "0"; - manaCost = new ManaCost(Mana); - } - } else { - // JOptionPane.showMessageDialog(null, Mana + " " + Mana.replaceFirst(k[3],""), "", JOptionPane.INFORMATION_MESSAGE); - if(Mana.equals(Mana.replaceFirst(k[3], ""))) { - // if(sa.isXCost()) sa.getSourceCard().addXManaCostPaid(1); Not Included as X Costs are not in Colored Mana - if(sa.isMultiKicker()) CostCutting_GetMultiMickerManaCostPaid_Colored = CostCutting_GetMultiMickerManaCostPaid_Colored + k[3]; - // JOptionPane.showMessageDialog(null, CostCutting_GetMultiMickerManaCostPaid_Colored, "", JOptionPane.INFORMATION_MESSAGE); - } else { - Mana = Mana.replaceFirst(k[3], ""); - Mana = Mana.trim(); - if(Mana.equals("")) Mana = "0"; - manaCost = new ManaCost(Mana); - } - } - } - Mana = Mana.trim(); - if(Mana.length() == 0 || Mana.equals("0")) { - if(sa.isSpell() || sa.isCycling()) Mana = "0"; - else { - Mana = "1"; - } - } - } - manaCost = new ManaCost(Mana); - } - } - } - if(sa.isXCost()) { - - for(int XPaid = 0; XPaid < XBonus; XPaid++) sa.getSourceCard().addXManaCostPaid(1); - } - if(sa.isMultiKicker()) { - CostCutting_GetMultiMickerManaCostPaid = 0; - for(int XPaid = 0; XPaid < XBonus; XPaid++) CostCutting_GetMultiMickerManaCostPaid = CostCutting_GetMultiMickerManaCostPaid + 1; - } - } - if(originalCard.getName().equals("Khalni Hydra") && spell.isSpell() == true) { - Player player = AllZone.Phase.getPlayerTurn(); - PlayerZone PlayerPlay = AllZone.getZone(Constant.Zone.Battlefield, player); - CardList PlayerCreature = new CardList(PlayerPlay.getCards()); - PlayerCreature = PlayerCreature.getType("Creature"); - PlayerCreature = PlayerCreature.filter(new CardListFilter() { - public boolean addCard(Card c) { - return c.isCreature() && c.isGreen(); - } - }); - String Mana = manaCost + " "; - if(PlayerCreature.size() > 0) { - for(int i = 0; i < PlayerCreature.size(); i++) { - Mana = Mana.replaceFirst("G ", ""); - } - Mana = Mana.trim(); - if(Mana.equals("")) Mana = "0"; - manaCost = new ManaCost(Mana); - } - } // Khalni Hydra - return manaCost; - }//GetSpellCostChange - - public void playSpellAbility(SpellAbility sa) { - sa.setActivatingPlayer(AllZone.HumanPlayer); - - if (sa.getPayCosts() != null || sa.getTarget() != null){ - Target_Selection ts = new Target_Selection(sa.getTarget(), sa); - Cost_Payment payment = null; - if(sa.getPayCosts() == null) - { - payment = new Cost_Payment(new Ability_Cost("0",sa.getSourceCard().getName(),sa.isAbility()), sa); - } - else - { - payment = new Cost_Payment(sa.getPayCosts(),sa); - } - - payment.changeCost(); - - SpellAbility_Requirements req = new SpellAbility_Requirements(sa, ts, payment); - req.fillRequirements(); - } - else{ - ManaCost manaCost = new ManaCost(sa.getManaCost()); - if(sa.getSourceCard().isCopiedSpell() && sa.isSpell()) { - manaCost = new ManaCost("0"); - } else { - - manaCost = getSpellCostChange(sa, new ManaCost(sa.getManaCost())); - } - if(manaCost.isPaid() && sa.getBeforePayMana() == null) { - if (sa.getAfterPayMana() == null){ - Card source = sa.getSourceCard(); - if(sa.isSpell() && !source.isCopiedSpell()) - AllZone.GameAction.moveToStack(source); - - AllZone.Stack.add(sa); - if(sa.isTapAbility() && !sa.wasCancelled()) sa.getSourceCard().tap(); - if(sa.isUntapAbility()) sa.getSourceCard().untap(); - return; - } - else - AllZone.InputControl.setInput(sa.getAfterPayMana()); - } - else if(sa.getBeforePayMana() == null) - AllZone.InputControl.setInput(new Input_PayManaCost(sa)); - else - AllZone.InputControl.setInput(sa.getBeforePayMana()); - } - } - - public void playSpellAbility_NoStack(SpellAbility sa,boolean skipTargeting) { - sa.setActivatingPlayer(AllZone.HumanPlayer); - - if (sa.getPayCosts() != null){ - Target_Selection ts = new Target_Selection(sa.getTarget(),sa); - Cost_Payment payment = new Cost_Payment(sa.getPayCosts(), sa); - - payment.changeCost(); - - SpellAbility_Requirements req = new SpellAbility_Requirements(sa, ts, payment); - req.setSkipStack(true); - req.fillRequirements(skipTargeting); - } - else{ - ManaCost manaCost = new ManaCost(sa.getManaCost()); - if(sa.getSourceCard().isCopiedSpell() && sa.isSpell()) { - manaCost = new ManaCost("0"); - } else { - - manaCost = getSpellCostChange(sa, new ManaCost(sa.getManaCost())); - } - if(manaCost.isPaid() && sa.getBeforePayMana() == null) { - if (sa.getAfterPayMana() == null){ - sa.resolve(); - if(sa.isTapAbility() && !sa.wasCancelled()) sa.getSourceCard().tap(); - if(sa.isUntapAbility()) sa.getSourceCard().untap(); - return; - } - else - AllZone.InputControl.setInput(sa.getAfterPayMana()); - } - else if(sa.getBeforePayMana() == null) - AllZone.InputControl.setInput(new Input_PayManaCost(sa,true)); - else - AllZone.InputControl.setInput(sa.getBeforePayMana()); - } - } - - public SpellAbility[] canPlaySpellAbility(SpellAbility[] sa) { - ArrayList list = new ArrayList(); - - for(int i = 0; i < sa.length; i++){ - sa[i].setActivatingPlayer(AllZone.HumanPlayer); - if(sa[i].canPlay()) - list.add(sa[i]); - } - - SpellAbility[] array = new SpellAbility[list.size()]; - list.toArray(array); - return array; - }//canPlaySpellAbility() - - public void skullClamp_destroy(Card c) { - CardList equipment = new CardList(); - equipment.addAll(c.getEquippedBy().toArray()); - equipment = equipment.getName("Skullclamp"); - - if(equipment.size() == 0) return; - - final Card crd = c; - for(int i = 0; i < equipment.size(); i++) { - final Card skullclamp = equipment.get(i); - final Ability draw = new Ability(crd, "0") { - @Override - public void resolve() { - Player player = skullclamp.getController(); - player.drawCards(2); - } - };//Ability - - StringBuilder sb = new StringBuilder(); - sb.append("Skullclamp - ").append(skullclamp.getController()); - sb.append(" draws 2 cards (").append(c.getName()).append(")."); - draw.setStackDescription(sb.toString()); - - AllZone.Stack.add(draw); - } - } - - public void searchLibraryBasicLand(Player player, String Zone1, boolean tapLand) { - searchLibraryTwoLand("Basic", player, Zone1, tapLand, "", false); - } - - public void searchLibraryTwoLand(String type, Player player, - String Zone1, boolean tapFirstLand, - String Zone2, boolean tapSecondLand) { - if(player.equals(AllZone.HumanPlayer)) { - humanSearchTwoLand(type, Zone1, tapFirstLand, Zone2, tapSecondLand); - } else { - aiSearchTwoLand(type, Zone1, tapFirstLand, Zone2, tapSecondLand); - } - - player.shuffle(); - - } - public void searchLibraryTwoBasicLand(Player player, - String Zone1, boolean tapFirstLand, - String Zone2, boolean tapSecondLand) { - searchLibraryTwoLand("Basic", player, Zone1, tapFirstLand, Zone2, tapSecondLand); - } - - private void aiSearchTwoLand(String type, String Zone1, boolean tapFirstLand, - String Zone2, boolean tapSecondLand) { - CardList land = new CardList(AllZone.Computer_Library.getCards()); - land = land.getType(type); - PlayerZone firstZone = AllZone.getZone(Zone1, AllZone.ComputerPlayer); - - if (type.contains("Basic")) { - // No need for special sorting for basic land - // just shuffle to make the computer a little less predictable - land.shuffle(); - } else { - Comparator aiLandComparator = new Comparator() - { - private int scoreLand(Card a) { - String valakutName = "Valakut, the Molten Pinnacle"; - - int theScore = 0; - if (!a.isBasicLand()) { - // favor non-basic land - theScore++; - if (a.getName().contains(valakutName)) { - // TODO: Add names of other special lands - theScore++; - } - } - return theScore; - } - public int compare(Card a, Card b) - { - int aScore = scoreLand(a); - int bScore = scoreLand(b); - return bScore - aScore; - } // compare - };//Comparator - - // Prioritize the land somewhat - land.sort(aiLandComparator); - } - //3 branches: 1-no land in deck, 2-one land in deck, 3-two or more land in deck - if(land.size() != 0) { - //branch 2 - at least 1 land in library - Card firstLand = land.remove(0); - if (tapFirstLand) - firstLand.tap(); - - AllZone.GameAction.moveTo(firstZone, firstLand); - - //branch 3 - if(Zone2.trim().length() != 0 && (land.size() != 0)) { - PlayerZone secondZone = AllZone.getZone(Zone2, AllZone.ComputerPlayer); - Card secondLand = land.remove(0); - if (tapSecondLand) - secondLand.tap(); - AllZone.GameAction.moveTo(secondZone, secondLand); - } - } - } - - private void humanSearchTwoLand(String type, String Zone1, boolean tapFirstLand, String Zone2, boolean tapSecondLand) { - PlayerZone firstZone = AllZone.getZone(Zone1, AllZone.HumanPlayer); - PlayerZone library = AllZone.getZone(Constant.Zone.Library, AllZone.HumanPlayer); - - CardList list = new CardList(library.getCards()); - list = list.getType(type); - - //3 branches: 1-no land in deck, 2-one land in deck, 3-two or more land in deck - - //branch 1 - if(list.size() == 0) return; - - // Check whether we were only asked for one land, and adjust the prompt accordingly - boolean onlyOneLand = (Zone2.trim().length() == 0); - String firstPrompt; - if (onlyOneLand) - firstPrompt = "Choose a land"; - else - firstPrompt = "Choose first land"; - - //branch 2 - Object o = GuiUtils.getChoiceOptional(firstPrompt, list.toArray()); - if(o != null) { - Card c = (Card) o; - list.remove(c); - if (tapFirstLand) - c.tap(); - moveTo(firstZone, c); - }//if - if ((list.size() == 0) || onlyOneLand) return; - //branch 3 - o = GuiUtils.getChoiceOptional(ForgeProps.getLocalized(GAMEACTION_TEXT.CHOOSE_2ND_LAND), list.toArray()); - if(o != null) { - PlayerZone secondZone = AllZone.getZone(Zone2, AllZone.HumanPlayer); - - Card c = (Card) o; - list.remove(c); - if (tapSecondLand) - c.tap(); - moveTo(secondZone, c); - } - } - - public void proliferate(final Card c, String cost) - { - Ability p = getProliferateAbility(c, cost); - AllZone.Stack.add(p); - } - - public Ability getProliferateAbility(final Card c, final String cost) - { - final Ability ability = new Ability(c, cost) - { - public void resolve() - { - CardList hperms = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer); - hperms = hperms.filter(new CardListFilter(){ - public boolean addCard(Card crd) - { - return !crd.getName().equals("Mana Pool") /*&& crd.hasCounters()*/; - } - }); - - CardList cperms = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer); - cperms = cperms.filter(new CardListFilter(){ - public boolean addCard(Card crd) - { - return !crd.getName().equals("Mana Pool") /*&& crd.hasCounters()*/; - } - }); - - if (c.getController().equals(AllZone.HumanPlayer)) - { - cperms.addAll(hperms.toArray()); - final CardList unchosen = cperms; - AllZone.InputControl.setInput(new Input() { - private static final long serialVersionUID = -1779224307654698954L; - - @Override - public void showMessage() { - AllZone.Display.showMessage("Choose permanents and/or players"); - ButtonUtil.enableOnlyOK(); - } - - @Override - public void selectButtonOK() { - stop(); - } - - @Override - public void selectCard(Card card, PlayerZone zone) - { - if(!unchosen.contains(card)) return; - unchosen.remove(card); - ArrayList choices = new ArrayList(); - for(Counters c_1:Counters.values()) - if(card.getCounters(c_1) != 0) choices.add(c_1.getName()); - if (choices.size() > 0) - card.addCounter(Counters.getType((choices.size() == 1 ? choices.get(0) : GuiUtils.getChoice("Select counter type", choices.toArray()).toString())), 1); - } - boolean selComputer = false; - boolean selHuman = false; - @Override - public void selectPlayer(Player player){ - if (player.equals(AllZone.HumanPlayer) && selHuman == false) - { - selHuman = true; - if (AllZone.HumanPlayer.getPoisonCounters() > 0) - AllZone.HumanPlayer.addPoisonCounters(1); - } - if (player.equals(AllZone.ComputerPlayer) && selComputer == false) - { - selComputer = true; - if (AllZone.ComputerPlayer.getPoisonCounters() > 0) - AllZone.ComputerPlayer.addPoisonCounters(1); - } - } - }); - } - else //comp - { - cperms = cperms.filter(new CardListFilter(){ - public boolean addCard(Card crd) - { - int pos = 0; - int neg = 0; - for(Counters c_1:Counters.values()) { - if(crd.getCounters(c_1) != 0) - { - if (CardFactoryUtil.isNegativeCounter(c_1)) - neg++; - else - pos++; - } - } - return pos > neg; - } - }); - - hperms = hperms.filter(new CardListFilter(){ - public boolean addCard(Card crd) - { - int pos = 0; - int neg = 0; - for(Counters c_1:Counters.values()) { - if(crd.getCounters(c_1) != 0) - { - if (CardFactoryUtil.isNegativeCounter(c_1)) - neg++; - else - pos++; - } - } - return pos < neg; - } - }); - - StringBuilder sb = new StringBuilder(); - sb.append("Proliferate:
Computer selects "); - if (cperms.size() == 0 && hperms.size() == 0 && AllZone.HumanPlayer.getPoisonCounters() == 0) - sb.append("nothing."); - else - { - if (cperms.size()>0) { - sb.append("
From Computer's permanents:
"); - for (Card c:cperms) - { - sb.append(c); - sb.append(" "); - } - sb.append("
"); - } - if (hperms.size()>0) { - sb.append("
From Human's permanents:
"); - for (Card c:cperms) - { - sb.append(c); - sb.append(" "); - } - sb.append("
"); - } - if (AllZone.HumanPlayer.getPoisonCounters() > 0) - sb.append("Human Player."); - }//else - sb.append(""); - - - //add a counter for each counter type, if it would benefit the computer - for (Card c:cperms) - { - for(Counters c_1:Counters.values()) - if(c.getCounters(c_1) != 0) c.addCounter(c_1, 1); - } - - //add a counter for each counter type, if it would screw over the player - for (Card c:hperms) - { - for(Counters c_1:Counters.values()) - if(c.getCounters(c_1) != 0) c.addCounter(c_1, 1); - } - - //give human a poison counter, if he has one - if (AllZone.HumanPlayer.getPoisonCounters() > 0) - AllZone.HumanPlayer.addPoisonCounters(1); - - } //comp - } - }; - - StringBuilder sb = new StringBuilder(); - sb.append(c).append(" - Proliferate (You choose any number of permanents and/or players with "); - sb.append("counters on them, then give each another counter of a kind already there.)"); - ability.setStackDescription(sb.toString()); - - return ability; - } - - public static void main(String[] args) { - GameAction gameAction = new GameAction(); - GenerateConstructedDeck gen = new GenerateConstructedDeck(); - - for(int i = 0; i < 2000; i++) { - CardList list = gen.generateDeck(); - - Card[] card = gameAction.smoothComputerManaCurve(list.toArray()); - - CardList check = new CardList(); - for(int a = 0; a < 30; a++) - check.add(card[a]); - - if(check.getType("Land").size() != 7) { - System.out.println("error - " + check); - break; - } - }//for - } -} + +package forge; + + +import forge.gui.GuiUtils; +import forge.properties.ForgeProps; +import forge.properties.NewConstants.LANG.GameAction.GAMEACTION_TEXT; + +import javax.swing.*; +import java.util.*; + +public class GameAction { + + public void resetActivationsPerTurn(){ + CardList all = AllZoneUtil.getCardsInGame(); + + // Reset Activations per Turn + for(Card card : all){ + for(SpellAbility sa : card.getSpellAbility()) + sa.getRestrictions().resetTurnActivations(); + } + } + + // todo(sol) Combine all of these move tos + + public Card moveTo(PlayerZone zone, Card c) { + // Ideally move to should never be called without a prevZone + // Remove card from Current Zone, if it has one + String prevName = ""; + PlayerZone prev = AllZone.getZone(c); + + //Card lastKnownInfo = getLastKnownInformation(c); + Card lastKnownInfo = c; + + if(prev != null){ + if (prev.is(Constant.Zone.Battlefield) && c.isCreature()) + AllZone.Combat.removeFromCombat(c); + prevName = prev.getZoneName(); + prev.remove(c); + } + else{ + // things that were just created will not have zones! + //System.out.println(c.getName() + " " + zone.getZoneName()); + } + + // Don't add the Token, unless it's moving to the battlefield + if (!c.isToken() || zone.is(Constant.Zone.Battlefield)){ + // If a nontoken card is moving from the Battlefield, to non-Battlefield zone copy it + if (prev != null && prev.is(Constant.Zone.Battlefield) && !zone.is(Constant.Zone.Battlefield)) + c = AllZone.CardFactory.copyCard(c); + + c.setUnearthed(lastKnownInfo.isUnearthed()); // this might be unnecessary + if (lastKnownInfo.wasSuspendCast()) // these probably can be moved back to SubtractCounters + c = addSuspendTriggers(c); + + // todo: if zone is battlefied and prevZone is battlefield, temporarily disable enters battlefield triggers + zone.add(c); + } + + if (zone.is(Constant.Zone.Battlefield) && c.isAura()){ + // todo: add attachment code here + } + + // copyCard above seems to already clearRemembered, commenting out for now + //if (!zone.is(Constant.Zone.Battlefield)) + //{ + //Other characteristics should be cleared here also. + // c.clearRemembered(); + //} + + //Run triggers + HashMap runParams = new HashMap(); + + runParams.put("Card", lastKnownInfo); + runParams.put("Origin", prevName); + runParams.put("Destination", zone.getZoneName()); + AllZone.TriggerHandler.runTrigger("ChangesZone", runParams); + + return c; + } + + public Card getLastKnownInformation(Card card){ + // this may be necessary at some point, but I'm not certain + // record last known information before moving zones + Card lastKnown = AllZone.CardFactory.copyCard(card); + + for(Card eq : card.getEquippedBy()) + eq.equipCard(lastKnown); + + for(Card en : card.getEnchantedBy()) + en.enchantCard(lastKnown); + + lastKnown.setExtrinsicKeyword(card.getExtrinsicKeyword()); + + return lastKnown; + } + + public void changeController(CardList list, Player oldController, Player newController){ + if (oldController.equals(newController)) + return; + + // Consolidating this code for now. In the future I want moveTo to handle this garbage + PlayerZone oldBattlefield = AllZone.getZone(Constant.Zone.Battlefield, oldController); + PlayerZone newBattlefield = AllZone.getZone(Constant.Zone.Battlefield, newController); + + AllZone.TriggerHandler.suppressMode("ChangesZone"); + ((PlayerZone_ComesIntoPlay) AllZone.Human_Battlefield).setTriggers(false); + ((PlayerZone_ComesIntoPlay) AllZone.Computer_Battlefield).setTriggers(false); + //so "enters the battlefield" abilities don't trigger + + for(Card c : list){ + oldBattlefield.remove(c); + c.setController(newController); + newBattlefield.add(c); + if (c.isCreature()) + AllZone.Combat.removeFromCombat(c); + } + + AllZone.TriggerHandler.clearSuppression("ChangesZone"); + ((PlayerZone_ComesIntoPlay) AllZone.Human_Battlefield).setTriggers(true); + ((PlayerZone_ComesIntoPlay) AllZone.Computer_Battlefield).setTriggers(true); + } + + public Card moveToStack(Card c){ + PlayerZone stack = AllZone.getZone(Constant.Zone.Stack, null); + return moveTo(stack, c); + } + + public Card moveToGraveyard(Card c) { + + final PlayerZone grave = AllZone.getZone(Constant.Zone.Graveyard, c.getOwner()); + + if (AllZoneUtil.isCardInPlay("Leyline of the Void", c.getOwner().getOpponent())) { + return moveTo(AllZone.getZone(Constant.Zone.Exile, c.getOwner()), c); + } + + if(c.hasKeyword("If CARDNAME would be put into a graveyard this turn, exile it instead.")) { + return moveTo(AllZone.getZone(Constant.Zone.Exile, c.getOwner()), c); + } + + if (AllZoneUtil.isCardInPlay("Planar Void")) { + CardList pVoids = AllZoneUtil.getCardsInPlay("Planar Void"); + for(int i = 0; i < pVoids.size(); i++) { + Card pVoid = pVoids.get(i); + final Card voidingCard = c; + if (!c.equals(pVoid)) { + Ability ability = new Ability(pVoid, "0") { + @Override + public void resolve() { + if(AllZone.GameAction.isCardInZone(voidingCard, grave)) + moveTo(AllZone.getZone(Constant.Zone.Exile, voidingCard.getOwner()), voidingCard); + } + + };// Ability + StringBuilder sb = new StringBuilder(); + sb.append("Planar Void - exile ").append(c); + ability.setStackDescription(sb.toString()); + + AllZone.Stack.add(ability); + } + } + } + + //must put card in OWNER's graveyard not controller's + c = moveTo(grave, c); + + //Recover keyword + if(c.isType("Creature")) + { + for(final Card recoverable : grave.getCards()) + { + if(recoverable.hasStartOfKeyword("Recover")) + { + SpellAbility abRecover = new Ability(recoverable,"0") + { + @Override + public void resolve() + { + AllZone.GameAction.moveToHand(recoverable); + } + + @Override + public String getStackDescription() + { + StringBuilder SD = new StringBuilder(recoverable.getName()); + SD.append(" - Recover."); + + return SD.toString(); + } + }; + + String recoverCost = recoverable.getKeyword().get(recoverable.getKeywordPosition("Recover")).split(":")[1]; + Ability_Cost abCost = new Ability_Cost(recoverCost,recoverable.getName(),false); + abRecover.setPayCosts(abCost); + + StringBuilder question = new StringBuilder("Recover "); + question.append(recoverable.getName()); + question.append("("); + question.append(recoverable.getUniqueNumber()); + question.append(")"); + question.append("?"); + + boolean shouldRecoverForAI = false; + boolean shouldRecoverForHuman = false; + + if(c.getOwner().equals(AllZone.HumanPlayer)) + { + shouldRecoverForHuman = GameActionUtil.showYesNoDialog(recoverable, question.toString()); + } + else if(c.getOwner().equals(AllZone.ComputerPlayer)) + { + shouldRecoverForAI = ComputerUtil.canPayCost(abRecover); + } + + if(shouldRecoverForHuman) + { + AllZone.GameAction.playSpellAbility(abRecover); + } + else if(shouldRecoverForAI) + { + ComputerUtil.playStack(abRecover); + } + + if(!grave.hasChanged()) //If the controller declined Recovery or didn't pay the cost, exile the recoverable + { + AllZone.GameAction.exile(recoverable); + } + } + } + } + return c; + } + + public Card moveToHand(Card c) { + PlayerZone hand = AllZone.getZone(Constant.Zone.Hand, c.getOwner()); + return moveTo(hand, c); + } + + public Card moveToPlay(Card c) { + PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, c.getOwner()); + return moveTo(play, c); + } + + public Card moveToPlay(Card c, Player p) { + // move to a specific player's Battlefield + PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, p); + return moveTo(play, c); + } + + public Card moveToBottomOfLibrary(Card c) { + return moveToLibrary(c, -1); + } + + public Card moveToLibrary(Card c) { + return moveToLibrary(c, 0); + } + + public Card moveToLibrary(Card c, int libPosition){ + PlayerZone p = AllZone.getZone(c); + PlayerZone library = AllZone.getZone(Constant.Zone.Library, c.getOwner()); + + if(p != null) p.remove(c); + + + if (c.isToken()) + return c; + + if (p != null && p.is(Constant.Zone.Battlefield)) + c = AllZone.CardFactory.copyCard(c); + + if (libPosition == -1 || libPosition > library.getCards().length) + libPosition = library.getCards().length; + + library.add(c, libPosition); + return c; + } + + public Card exile(Card c) { + if(AllZone.GameAction.isCardExiled(c)) return c; + + PlayerZone removed = AllZone.getZone(Constant.Zone.Exile, c.getOwner()); + + return AllZone.GameAction.moveTo(removed, c); + } + + public Card moveTo(String name, Card c, int libPosition){ + // Call specific functions to set PlayerZone, then move onto moveTo + if (name.equals(Constant.Zone.Hand)) + return moveToHand(c); + else if (name.equals(Constant.Zone.Library)) + return moveToLibrary(c, libPosition); + else if (name.equals(Constant.Zone.Battlefield)) + return moveToPlay(c); + else if (name.equals(Constant.Zone.Graveyard)) + return moveToGraveyard(c); + else if (name.equals(Constant.Zone.Exile)) + return exile(c); + else //if (name.equals(Constant.Zone.Stack)) + return moveToStack(c); + } + + public boolean AI_discardNumType(int numDiscard, String[] uTypes, SpellAbility sa) { + CardList hand = new CardList(); + hand.addAll(AllZone.getZone(Constant.Zone.Hand, AllZone.ComputerPlayer).getCards()); + CardList tHand = hand.getValidCards(uTypes,sa.getActivatingPlayer(),sa.getSourceCard()); + + if(tHand.size() >= numDiscard) { + CardListUtil.sortCMC(tHand); + tHand.reverse(); + for(int i = 0; i < numDiscard; i++) + tHand.get(i).getController().discard(tHand.get(i), sa); + return true; + } + return false; + } + + public void discard_nath(Card discardedCard) { + final Player owner = discardedCard.getOwner(); + final Player opponent = owner.getOpponent(); + + PlayerZone opponentZone = AllZone.getZone(Constant.Zone.Battlefield, opponent); + CardList opponentList = new CardList(opponentZone.getCards()); + + for(int i = 0; i < opponentList.size(); i++) { + Card card = opponentList.get(i); + if(card.getName().equals("Nath of the Gilt-Leaf")) { + CardFactoryUtil.makeToken("Elf Warrior", "G 1 1 Elf Warrior", opponent, "G", + new String[] {"Creature", "Elf", "Warrior"}, 1, 1, new String[] {}); + } + } + } + + public void discard_PutIntoPlayInstead(Card c) + { + moveToPlay(c); + + if (c.getName().equals("Dodecapod")) + c.setCounter(Counters.P1P1, 2, false); + } + + public void discard_megrim(Card c) { + /* + * Whenever an opponent discards a card, Megrim deals 2 damage to that player. + */ + final Player owner = c.getOwner(); //discarded card owner + final Player opponent = owner.getOpponent(); //check this for Megrim + CardList megrims = AllZoneUtil.getPlayerCardsInPlay(opponent, "Megrim"); + for(Card megrim:megrims) { + final Card thisMegrim = megrim; + final Ability ability = new Ability(megrim, "0") { + @Override + public void resolve() { + owner.addDamage(2, thisMegrim); + } + }; + + StringBuilder sb = new StringBuilder(); + sb.append(megrim.getName()).append(" - deals 2 damage to ").append(owner); + ability.setStackDescription(sb.toString()); + + AllZone.Stack.add(ability); + } + } + + public void discard_madness(Card c) { + // Whenever a card with madness is discarded, you may cast it for it's madness cost + if (!c.hasMadness()) + return; + + final Card madness = c; + final Ability cast = new Ability(madness, madness.getMadnessCost()) { + @Override + public void resolve() { + playCardNoCost(madness); + System.out.println("Madness cost paid"); + } + }; + + StringBuilder sb = new StringBuilder(); + sb.append(madness.getName()).append(" - Cast via Madness"); + cast.setStackDescription(sb.toString()); + + final Ability activate = new Ability(madness, "0") { + @Override + public void resolve() { + // pay madness cost here. + if (madness.getOwner().isHuman()){ + if (GameActionUtil.showYesNoDialog(madness, madness + " - Discarded. Pay Madness Cost?")){ + if (cast.getManaCost().equals("0")) + AllZone.Stack.add(cast); + else + AllZone.InputControl.setInput(new Input_PayManaCost(cast)); + } + } + else // computer will ALWAYS pay a madness cost if he has the mana. + ComputerUtil.playStack(cast); + } + }; + + StringBuilder sbAct = new StringBuilder(); + sbAct.append(madness.getName()).append(" - Discarded. Pay Madness Cost?"); + activate.setStackDescription(sbAct.toString()); + + AllZone.Stack.add(activate); + } + + public boolean checkEndGameSate(){ + // Win / Lose + boolean humanWins = false; + boolean computerWins = false; + Player computer = AllZone.ComputerPlayer; + Player human = AllZone.HumanPlayer; + + int gameWon = Constant.Runtime.matchState.getWin(); + + if (human.hasWon()){ // Winning Conditions can be worth more than losing conditions + // Human wins + humanWins = true; + if (human.getAltWin()){ + Constant.Runtime.matchState.setWinMethod(gameWon, human.getWinCondition()); + } + Constant.Runtime.matchState.addWin(); + } + + else if (computer.hasLost()){ + // Human wins + humanWins = true; + + if (computer.getAltLose()){ + Constant.Runtime.matchState.setWinMethod(gameWon, computer.getLoseCondition()); + } + Constant.Runtime.matchState.addWin(); + } + + + if (computer.hasWon() || human.hasLost()){ + if (humanWins){ + // both players won/lost at the same time. + // TODO: Handle a Draw here + } + + // Computer wins + computerWins = true; + Constant.Runtime.matchState.addLose(); + } + + return humanWins || computerWins; + } + + + public void checkStateEffects() { + // sol(10/29) added for Phase updates, state effects shouldn't be checked during Spell Resolution + if (AllZone.Stack.getResolving()) + return; + + boolean refreeze = AllZone.Stack.isFrozen(); + AllZone.Stack.setFrozen(true); + + JFrame frame = (JFrame) AllZone.Display; + if(!frame.isDisplayable()) return; + + if(checkEndGameSate()) { + AllZone.Display.savePrefs(); + frame.dispose(); + if (!Constant.Quest.fantasyQuest[0]) + new Gui_WinLose(); + else + new Gui_WinLose(Constant.Quest.humanList[0], Constant.Quest.computerList[0], + Constant.Quest.humanLife[0], Constant.Quest.computerLife[0]); + return; + } + //do this twice, sometimes creatures/permanents will survive when they shouldn't + for (int q=0;q<2;q++) + { + //int size = AllZone.StaticEffects.getStateBasedMap().keySet().size(); + //Object[] arr = AllZone.StaticEffects.getStateBasedMap().keySet().toArray(); + + //card state effects like Glorious Anthem + for(String effect:AllZone.StaticEffects.getStateBasedMap().keySet()) { + Command com = GameActionUtil.commands.get(effect); + com.execute(); + } + + GameActionUtil.executeCardStateEffects(); + GameActionUtil.stSetPT.execute(); + GameActionUtil.stPump.execute(); + + //System.out.println("checking state effects"); + ArrayList creature = PlayerZoneUtil.getCardType(AllZone.Computer_Battlefield, "Creature"); + creature.addAll(PlayerZoneUtil.getCardType(AllZone.Human_Battlefield, "Creature")); + + Card c; + Iterator it = creature.iterator(); + + while(it.hasNext()) { + c = it.next(); + + if(c.isEquipped()) { + for(int i = 0; i < c.getEquippedBy().size(); i++) { + Card equipment = c.getEquippedBy().get(i); + if(!AllZone.GameAction.isCardInPlay(equipment)) { + equipment.unEquipCard(c); + } + } + }//if isEquipped() + + if(c.getNetDefense() <= c.getDamage() && !c.getKeyword().contains("Indestructible")) { + destroy(c); + AllZone.Combat.removeFromCombat(c); //this is untested with instants and abilities but required for First Strike combat phase + } + + else if(c.getNetDefense() <= 0) { + destroy(c); + AllZone.Combat.removeFromCombat(c); + } + + }//while it.hasNext() + + + ArrayList enchantments = PlayerZoneUtil.getCardType(AllZone.Computer_Battlefield, "Enchantment"); + enchantments.addAll(PlayerZoneUtil.getCardType(AllZone.Human_Battlefield, "Enchantment")); + + Iterator iterate = enchantments.iterator(); + while(iterate.hasNext()) { + c = iterate.next(); + + if(c.isAura()) { + for(int i = 0; i < c.getEnchanting().size(); i++) { + Card perm = c.getEnchanting().get(i); + if(!AllZone.GameAction.isCardInPlay(perm) + || CardFactoryUtil.hasProtectionFrom(c, perm) + || ((c.getKeyword().contains("Enchant creature") || c.getKeyword().contains("Enchant tapped creature") ) + && !perm.getType().contains("Creature")) + || (c.getKeyword().contains("Enchant tapped creature") && perm.isUntapped() ) ) { + c.unEnchantCard(perm); + //changed from destroy (and rules-wise, I don't think it's a sacrifice) + moveToGraveyard(c); + } + } + }//if isAura + + }//while iterate.hasNext() + + //Make sure all equipment stops equipping previously equipped creatures that have left play. + ArrayList equip = PlayerZoneUtil.getCardType(AllZone.Computer_Battlefield, "Equipment"); + equip.addAll(PlayerZoneUtil.getCardType(AllZone.Human_Battlefield, "Equipment")); + + Iterator iter = equip.iterator(); + while(iter.hasNext()) { + c = iter.next(); + if(c.isEquipping()) { + Card equippedCreature = c.getEquipping().get(0); + if(!AllZone.GameAction.isCardInPlay(equippedCreature)) c.unEquipCard(equippedCreature); + } + }//while iter.hasNext() + }//for q=0;q<2 + + destroyLegendaryCreatures(); + destroyPlaneswalkers(); + + if (!refreeze) + AllZone.Stack.unfreezeStack(); + }//checkStateEffects() + + + private void destroyPlaneswalkers() { + //get all Planeswalkers + CardList list = AllZoneUtil.getTypeInPlay("Planeswalker"); + + Card c; + for(int i = 0; i < list.size(); i++) { + c = list.get(i); + + if(c.getCounters(Counters.LOYALTY) <= 0) AllZone.GameAction.moveToGraveyard(c); + + String subtype = c.getType().get(c.getType().size() - 1); + CardList cl = list.getType(subtype); + + if(cl.size() > 1) { + for(Card crd:cl) { + AllZone.GameAction.moveToGraveyard(crd); + } + } + } + + } + + private void destroyLegendaryCreatures() { + CardList a = AllZoneUtil.getTypeInPlay("Legendary"); + + while(!a.isEmpty() && !AllZoneUtil.isCardInPlay("Mirror Gallery")) { + CardList b = AllZoneUtil.getCardsInPlay(a.get(0).getName()); + a.remove(0); + if(1 < b.size()) { + for(int i = 0; i < b.size(); i++) + AllZone.GameAction.sacrificeDestroy(b.get(i)); + } + } + }//destroyLegendaryCreatures() + + //ArrayList search is all Card objects, returns ArrayList of Cards + public ArrayList getCardsNamed(ArrayList search, String name) { + ArrayList a = new ArrayList(); + Card c[] = CardUtil.toCard(search); + + for(int i = 0; i < c.length; i++) { + if(c[i].getName().equals(name)) a.add(c[i]); + } + return a; + } + + public void sacrifice(Card c) { + if(c.getName().equals("Mana Pool")) { + System.out.println("Trying to sacrifice mana pool..."); + return; + } + sacrificeDestroy(c); + + //Run triggers + HashMap runParams = new HashMap(); + runParams.put("Card", c); + AllZone.TriggerHandler.runTrigger("Sacrificed", runParams); + } + + public void destroyNoRegeneration(Card c) { + if(!AllZone.GameAction.isCardInPlay(c) || c.getKeyword().contains("Indestructible")) return; + + if (c.isEnchanted()) + { + CardList list = new CardList(c.getEnchantedBy().toArray()); + list = list.filter(new CardListFilter() + { + public boolean addCard(Card crd) + { + return crd.getKeyword().contains("Totem armor"); + } + }); + CardListUtil.sortCMC(list); + + if (list.size() != 0) + { + final Card crd; + if (list.size() == 1) + { + crd = list.get(0); + } + else { + if (c.getController().isHuman()) + crd = GuiUtils.getChoiceOptional("Select totem armor to destroy", list.toArray()); + else + crd = list.get(0); + } + + final Card card = c; + Ability_Static ability = new Ability_Static(crd, "0") + { + public void resolve() + { + destroy(crd); + card.setDamage(0); + + } + }; + + StringBuilder sb = new StringBuilder(); + sb.append(crd).append(" - Totem armor: destroy this aura."); + ability.setStackDescription(sb.toString()); + + AllZone.Stack.add(ability); + return; + } + }//totem armor + + sacrificeDestroy(c); + } + + public Card addSuspendTriggers(final Card c){ + c.setSVar("HasteFromSuspend", "True"); + + Command intoPlay = new Command() { + private static final long serialVersionUID = -4514610171270596654L; + + public void execute() { + if(AllZone.GameAction.isCardInPlay(c) && c.isCreature()) + c.addExtrinsicKeyword("Haste"); + }//execute() + }; + + c.addComesIntoPlayCommand(intoPlay); + + Command loseControl = new Command() { + private static final long serialVersionUID = -4514610171270596654L; + + public void execute() { + if (c.getSVar("HasteFromSuspend").equals("True")){ + c.setSVar("HasteFromSuspend", "False"); + c.removeExtrinsicKeyword("Haste"); + } + }//execute() + }; + + c.addChangeControllerCommand(loseControl); + c.addLeavesPlayCommand(loseControl); + return c; + } + + + // Whenever Keyword + public void checkWheneverKeyword(Card Triggering_Card,String Event, Object[] Custom_Parameters) { + checkStateEffects(); + + PlayerZone Hplay = AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer); + PlayerZone Cplay = AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer); + PlayerZone Hgrave = AllZone.getZone(Constant.Zone.Graveyard, AllZone.HumanPlayer); + PlayerZone Cgrave = AllZone.getZone(Constant.Zone.Graveyard, AllZone.ComputerPlayer); + PlayerZone HRFG = AllZone.getZone(Constant.Zone.Exile, AllZone.HumanPlayer); + PlayerZone CRFG = AllZone.getZone(Constant.Zone.Exile, AllZone.ComputerPlayer); + + CardList Cards_WithKeyword = new CardList(); + Cards_WithKeyword.add(new CardList(Hplay.getCards())); + Cards_WithKeyword.add(new CardList(Cplay.getCards())); + Cards_WithKeyword.add(new CardList(Hgrave.getCards())); + Cards_WithKeyword.add(new CardList(Cgrave.getCards())); + Cards_WithKeyword.add(new CardList(HRFG.getCards())); + Cards_WithKeyword.add(new CardList(CRFG.getCards())); + Cards_WithKeyword = Cards_WithKeyword.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(c.getKeyword().toString().contains("WheneverKeyword")) return true; + return false; + } + }); + + if(!Cards_WithKeyword.contains(Triggering_Card)) Cards_WithKeyword.add(Triggering_Card); + + boolean Triggered = false; + for(int i = 0; i < Cards_WithKeyword.size() ; i++) { + if(Triggered == false) { + Card card = Cards_WithKeyword.get(i); + ArrayList a = card.getKeyword(); + int WheneverKeywords = 0; + int WheneverKeyword_Number[] = new int[a.size()]; + for(int x = 0; x < a.size(); x++) + if(a.get(x).toString().startsWith("WheneverKeyword")) { + WheneverKeyword_Number[WheneverKeywords] = x; + WheneverKeywords = WheneverKeywords + 1; + } + for(int CKeywords = 0; CKeywords < WheneverKeywords; CKeywords++) { + if(Triggered == false) { + String parse = card.getKeyword().get(WheneverKeyword_Number[CKeywords]).toString(); + String k[] = parse.split(":"); + if((k[1].contains(Event))) { + runWheneverKeyword(Triggering_Card, Event, Custom_Parameters); // Beached + Triggered = true; + } + } + } + } + } + } + + static boolean MultiTarget_Cancelled = false; + public void runWheneverKeyword(Card c, String Event, Object[] Custom_Parameters) { + /** + * Custom_Parameters Info: + * For GainLife : Custom_Parameters[0] = Amount of Life Gained + * For DealsDamage : Custom_Parameters[0] = Player Target + * : Custom_Parameters[2] = Damage Source + * For DrawCard : Custom_Parameters[0] = Initiating Player + */ + final Card F_TriggeringCard = c; + final String[] Custom_Strings = new String[10]; + int Custom_Strings_Count = 0; + boolean Stop = false; + for(int i = 0; i < Custom_Strings.length; i++) Custom_Strings[i] = "Null"; + PlayerZone Hplay = AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer); + PlayerZone Cplay = AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer); + PlayerZone Hgrave = AllZone.getZone(Constant.Zone.Graveyard, AllZone.HumanPlayer); + PlayerZone Cgrave = AllZone.getZone(Constant.Zone.Graveyard, AllZone.ComputerPlayer); + PlayerZone HRFG = AllZone.getZone(Constant.Zone.Exile, AllZone.HumanPlayer); + PlayerZone CRFG = AllZone.getZone(Constant.Zone.Exile, AllZone.ComputerPlayer); + + CardList Cards_WithKeyword = new CardList(); + Cards_WithKeyword.add(new CardList(Hplay.getCards())); + Cards_WithKeyword.add(new CardList(Cplay.getCards())); + Cards_WithKeyword.add(new CardList(Hgrave.getCards())); + Cards_WithKeyword.add(new CardList(Cgrave.getCards())); + Cards_WithKeyword.add(new CardList(HRFG.getCards())); + Cards_WithKeyword.add(new CardList(CRFG.getCards())); + Cards_WithKeyword = Cards_WithKeyword.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(c.getKeyword().toString().contains("WheneverKeyword")) return true; + return false; + } + }); + + if(!Cards_WithKeyword.contains(c)) Cards_WithKeyword.add(c); + + for(int i = 0; i < Cards_WithKeyword.size() ; i++) { + Card card = Cards_WithKeyword.get(i); + final Card F_card = card; + ArrayList a = card.getKeyword(); + int WheneverKeywords = 0; + int WheneverKeyword_Number[] = new int[a.size()]; + for(int x = 0; x < a.size(); x++) + if(a.get(x).toString().startsWith("WheneverKeyword")) { + WheneverKeyword_Number[WheneverKeywords] = x; + WheneverKeywords = WheneverKeywords + 1; + } + for(int CKeywords = 0; CKeywords < WheneverKeywords; CKeywords++) { + String parse = card.getKeyword().get(WheneverKeyword_Number[CKeywords]).toString(); + String k[] = parse.split(":"); + final String F_k[] = k; + // Conditions + if((k[1].contains(Event))) + { + if(k[1].contains("DealsDamage")) { + boolean Nullified = true; + String DamageTakerParse = k[1]; + String DamageTaker[] = DamageTakerParse.split("/"); + for(int z = 0; z < DamageTaker.length - 1; z++) { + if(DamageTaker[z + 1].equals("Opponent") && Custom_Parameters[0].equals(card.getController().getOpponent())) Nullified = false; + } + if(Nullified == true) k[4] = "Null"; + } + if(k[1].contains("CastSpell")) { + boolean Nullified = true; + String SpellControllerParse = k[1]; + String SpellController[] = SpellControllerParse.split("/"); + for(int z = 0; z < SpellController.length - 1; z++) { + if(SpellController[z + 1].equals("Controller") && (c.getController()).equals(card.getController())) Nullified = false; + if(SpellController[z + 1].equals("Opponent") && (c.getController()).equals(card.getController().getOpponent())) Nullified = false; + if(SpellController[z + 1].equals("Any")) Nullified = false; + } + if(Nullified == true) k[4] = "Null"; + } + if(k[1].contains("PlayLand")) { + boolean Nullified = true; + String SpellControllerParse = k[1]; + String SpellController[] = SpellControllerParse.split("/"); + for(int z = 0; z < SpellController.length - 1; z++) { + if(SpellController[z + 1].equals("Controller") && (c.getController()).equals(card.getController())) Nullified = false; + if(SpellController[z + 1].equals("Opponent") && (c.getController()).equals(card.getController().getOpponent())) Nullified = false; + if(SpellController[z + 1].equals("Any")) Nullified = false; + } + if(Nullified == true) k[4] = "Null"; + } + int Initiator_Conditions = 1; + String ConditionsParse = k[2]; + String Conditions[] = ConditionsParse.split("!"); + Initiator_Conditions = Conditions.length; + for(int y = 0; y < Initiator_Conditions; y++) { + if(Conditions[y].contains("Self") && !Conditions[y].contains("ControllingPlayer_Self")) { + if(!card.equals(c)) k[4] = "Null"; + } + if(Conditions[y].contains("ControllingPlayer_Self")) { + if(!card.getController().equals(Custom_Parameters[0])) k[4] = "Null"; + } + if(Conditions[y].contains("ControllingPlayer_Opponent")) { + // Special Case for Draw Card + if(Event.equals("DrawCard")) { + if(!card.getController().equals(((Player) Custom_Parameters[0]).getOpponent())) k[4] = "Null"; + } else if(!card.getController().equals(c.getController().getOpponent())) k[4] = "Null"; + } + + if(Conditions[y].contains("Enchanted_Creature")) { + if(((Card)Custom_Parameters[2]).getEnchantedBy().contains(card) == false) k[4] = "Null"; + } + if(Conditions[y].contains("Equipped_Creature")) { + if(((Card)Custom_Parameters[2]).getEquippedBy().contains(card) == false) k[4] = "Null"; + } + if(Conditions[y].contains("Type") && !Conditions[y].contains("OneTypeOfMany")) { + String TypeParse = Conditions[y]; + String Type[] = TypeParse.split("/"); + for(int z = 0; z < Type.length - 1; z++) if(!c.isType(Type[z + 1])) k[4] = "Null"; + } + if(Conditions[y].contains("OneTypeOfMany")) { + boolean Nullified = true; + String TypeParse = Conditions[y]; + String Type[] = TypeParse.split("/"); + for(int z = 0; z < Type.length - 1; z++) if(c.isType(Type[z + 1])) Nullified = false; + if(Nullified == true) k[4] = "Null"; + } + if(Conditions[y].contains("Color")) { + String ColorParse = Conditions[y]; + String Color[] = ColorParse.split("/"); + for(int z = 0; z < Color.length - 1; z++) if(!CardUtil.getColors(c).contains(Color[z + 1])) k[4] = "Null"; + } + } + // Zone Condition + String Zones = k[3]; + PlayerZone[] Required_Zones = new PlayerZone[1]; + if(Zones.equals("Hand")) Required_Zones[0] = AllZone.getZone(Constant.Zone.Hand, card.getController()); + if(Zones.equals("Graveyard")) Required_Zones[0] = AllZone.getZone(Constant.Zone.Graveyard, card.getController()); + if(Zones.equals("Play") || Zones.equals("Any")) Required_Zones[0] = AllZone.getZone(Constant.Zone.Battlefield, card.getController()); + if(Zones.contains("Library")) Required_Zones[0] = AllZone.getZone(Constant.Zone.Library, card.getController()); + if(Zones.contains("Exiled")) Required_Zones[0] = AllZone.getZone(Constant.Zone.Exile, card.getController()); + // if(Zones.contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, card.getController()); + final PlayerZone Required_Zone = Required_Zones[0]; + final String F_Zones = Zones; + // Special Conditions + int Special_Conditions = 1; + String Special_ConditionsParse = k[8]; + String Special_Condition[] = Special_ConditionsParse.split("!"); + Special_Conditions = Special_Condition.length; + for(int y = 0; y < Special_Conditions; y++) { + + if(Special_Condition[y].contains("Initiator - Other than Self")) { + if(card.equals(c)) k[4] = "Null"; + } + if(Special_Condition[y].contains("Initiator - OwnedByController")) { + if(!c.getController().equals(card.getController())) k[4] = "Null"; + } + if(Special_Condition[y].contains("Initiator - Has Keyword")) { + boolean Nullified = true; + String KeywordParse = Special_Condition[y]; + String Keyword[] = KeywordParse.split("/"); + for(int z = 0; z < Keyword.length - 1; z++) if((c.getKeyword()).contains(Keyword[z + 1])) Nullified = false; + if(Nullified == true) k[4] = "Null"; + } + if(Special_Condition[y].contains("ControllerUpkeep")) { + if(!AllZone.Phase.isPlayerTurn(card.getController())) k[4] = "Null"; + } + if(Special_Condition[y].contains("ControllerEndStep")) { + if(!AllZone.Phase.isPlayerTurn(card.getController())) k[4] = "Null"; + } + if(Special_Condition[y].contains("MoreCardsInHand")) { + if(((AllZone.getZone(Constant.Zone.Hand, card.getController())).getCards()).length + <= (AllZone.getZone(Constant.Zone.Hand, card.getController().getOpponent())).getCards().length) k[4] = "Null"; + } + if(Special_Condition[y].contains("SearchType")) { + for(int TypeRestrict = 0; TypeRestrict < (Special_Condition[y].split("/")).length - 1; TypeRestrict ++) { + Custom_Strings[Custom_Strings_Count] = "Type" + (Special_Condition[y].split("/"))[TypeRestrict + 1]; + Custom_Strings_Count++; + } + } + if(Special_Condition[y].contains("SearchColor")) { + for(int ColorRestrict = 0; ColorRestrict < (Special_Condition[y].split("/")).length - 1; ColorRestrict ++) { + Custom_Strings[Custom_Strings_Count] = "Color" + (Special_Condition[y].split("/"))[ColorRestrict + 1]; + Custom_Strings_Count++; + } + } + if(Special_Condition[y].contains("Suspended")) { + if(!card.hasSuspend()) k[4] = "Null"; + } + } + + // Mana Cost (if Any) + String ManaCost = "0"; + if(k[7].contains("PayMana")) { + String PayAmountParse = k[7]; + ManaCost = PayAmountParse.split("/")[1]; + } + + // Targets + + int Target_Conditions = 1; + String TargetParse = k[5]; + String Targets[] = TargetParse.split("!"); + Target_Conditions = Targets.length; + Player TargetPlayer[] = new Player[Target_Conditions]; + Card TargetCard[] = new Card[Target_Conditions]; + for(int y = 0; y < Target_Conditions; y++) { + if(Targets[y].equals("ControllingPlayer_Self")) TargetPlayer[y] = card.getController(); + if(Targets[y].equals("ControllingPlayer_Opponent")) TargetPlayer[y] = card.getController().getOpponent(); + if(Targets[y].equals("ControllingPlayer_Initiator")) TargetPlayer[y] = F_TriggeringCard.getController(); + if(Targets[y].equals("Self")) TargetCard[y] = F_card; + if(Targets[y].equals("Initiating_Card")) TargetCard[y] = c; + } + + final Player[] F_TargetPlayer = TargetPlayer; + final Card[] F_TargetCard = TargetCard; + // JOptionPane.showMessageDialog(null, Targets, "", JOptionPane.INFORMATION_MESSAGE); + + // Effects + + int Effects = 1; + String EffectParse = k[4]; + String Effect[] = EffectParse.split("!"); + Effects = Effect.length; + final Command[] Command_Effects = new Command[Effects]; + final Command[] CommandExecute = new Command[1]; + String StackDescription = F_card + " - "; + final int[] Effects_Count = new int[1]; + + final Ability Ability = new Ability(card, ManaCost) { + @Override + public void resolve() { + for(int Commands = 0; Commands < Command_Effects.length; Commands++) Whenever_ManaPaid(F_card, F_k, Command_Effects[Commands], this); + } + }; + + final Spell Spell = new Spell(card) { + private static final long serialVersionUID = -4909393989689642952L; + + @Override + public void resolve() { + for(int Commands = 0; Commands < Command_Effects.length; Commands++) Whenever_ManaPaid(F_card, F_k, Command_Effects[Commands], this); + } + }; + + SpellAbility[] SpellAbility = new SpellAbility[1]; + if(k[1].equals("ActualSpell")) SpellAbility[0] = Spell; + else SpellAbility[0] = Ability; + + final SpellAbility F_SpellAbility = SpellAbility[0]; + + if(k[7].contains("Choice_Instant") && k[4] != "Null") { + if(card.getController().equals(AllZone.HumanPlayer)) { + Object[] possibleValues = {"Yes", "No"}; + Object q = JOptionPane.showOptionDialog(null, "Activate - " + card.getName(),card.getName() + " Ability", + JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, + null, possibleValues, possibleValues[0]); + if(q.equals(1)) { + Stop = true; + } + } + } + if(Stop == false) { + + for(int y = 0; y < Effects; y++) { + // Variables + String AmountParse = Effect[y]; + String[] S_Amount = AmountParse.split("/"); + int[] I_Amount = new int[S_Amount.length - 1]; + int Multiple_Targets = 1; + + for(int b = 0; b < S_Amount.length - 1; b++) { + if(S_Amount[b+1].equals("Toughness")) I_Amount[b] = F_TriggeringCard.getNetDefense(); + else if(S_Amount[b+1].equals("Power")) I_Amount[b] = F_TriggeringCard.getNetAttack(); + else if(S_Amount[b+1].equals("Life_Gained")) I_Amount[b] = ((Integer)Custom_Parameters[0]); + else if(S_Amount[b+1].contains("ControlledAmountType")) { + final String[] TypeSplit = AmountParse.split("/"); + CardList Cards_WithAllTypes = new CardList(); + Cards_WithAllTypes.add(new CardList(AllZone.getZone(Constant.Zone.Battlefield, card.getController()).getCards())); + Cards_WithAllTypes = Cards_WithAllTypes.filter(new CardListFilter() { + public boolean addCard(Card c) { + for(int z = 0; z < TypeSplit.length - 1; z++) + if(c.isType(TypeSplit[z + 1])) return true; + return false; + } + }); + I_Amount[b] = Cards_WithAllTypes.size(); + } + else if(!S_Amount[0].equals("KeywordPumpEOT")&& !S_Amount[1].contains("ControlledAmountType")) I_Amount[b] = Integer.valueOf(S_Amount[b+1]); + + // NOTE: Multiple Targets and Groups of Integers is not supported + + if(k[8].contains("MultipleTargets")) { + Multiple_Targets = I_Amount[0]; + I_Amount[0] = 1; + } + } // For + // Input for Targets + + final int F_Multiple_Targets = Multiple_Targets; + final Object[] Targets_Multi = new Object[Multiple_Targets]; + final int[] index = new int[1]; + final int[] F_Amount = I_Amount; + final String[] F_S_Amount = S_Amount; + final int F_Target = Effects_Count[0]; + + + final Command MultiTargetsCommand = new Command() { + private static final long serialVersionUID = -83034517601871955L; + + public void execute() { + MultiTarget_Cancelled = false; + for(int i = 0; i < F_Multiple_Targets; i++) { + AllZone.InputControl.setInput(CardFactoryUtil.input_MultitargetCreatureOrPlayer(F_SpellAbility , i , F_Amount[0]*F_Multiple_Targets,new Command() { + + private static final long serialVersionUID = -328305150127775L; + + public void execute() { + Targets_Multi[index[0]] = F_SpellAbility.getTargetPlayer(); + if(Targets_Multi[index[0]] == null) Targets_Multi[index[0]] = F_SpellAbility.getTargetCard(); + index[0]++; + if(F_Multiple_Targets == 1) AllZone.Stack.updateObservers(); + } + })); + } + AllZone.Stack.add(F_SpellAbility); + } + }; + + final Command InputCommand = new Command() { + private static final long serialVersionUID = -83034517601871955L; + + public void execute() { + String WhichInput = F_k[5].split("/")[1]; + if(WhichInput.equals("Creature")) + if(F_card.getController().equals(AllZone.HumanPlayer)) + AllZone.InputControl.setInput(CardFactoryUtil.input_targetCreature(F_SpellAbility, GetTargetsCommand)); + else { + CardList PossibleTargets = new CardList(); + PossibleTargets.addAll(AllZone.Human_Battlefield.getCards()); + PossibleTargets.addAll(AllZone.Computer_Battlefield.getCards()); + PossibleTargets = PossibleTargets.getType("Creature"); + if(Whenever_AI_GoodEffect(F_k)) { + PossibleTargets = PossibleTargets.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(c.getController().equals(AllZone.ComputerPlayer)) return true; + return false; + } + }); + if(PossibleTargets.size() > 0) { + Targets_Multi[index[0]] = CardFactoryUtil.AI_getBestCreature(PossibleTargets,F_card); + AllZone.Stack.add(F_SpellAbility); + } + index[0]++; + } else { + PossibleTargets = PossibleTargets.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(c.getController().equals(AllZone.HumanPlayer)) return true; + return false; + } + }); + if(PossibleTargets.size() > 0) { + Targets_Multi[index[0]] = CardFactoryUtil.AI_getBestCreature(PossibleTargets,F_card); + AllZone.Stack.add(F_SpellAbility); + } + index[0]++; + } + + } + if(WhichInput.equals("Player")) + if(F_card.getController().equals(AllZone.HumanPlayer)) + AllZone.InputControl.setInput(CardFactoryUtil.input_targetPlayer(F_SpellAbility, GetTargetsCommand)); + else { + if(Whenever_AI_GoodEffect(F_k)) { + Targets_Multi[index[0]] = AllZone.ComputerPlayer; + if(Targets_Multi[index[0]] != null) AllZone.Stack.add(F_SpellAbility); + index[0]++; + } + else { + Targets_Multi[index[0]] = AllZone.HumanPlayer; + if(Targets_Multi[index[0]] != null) AllZone.Stack.add(F_SpellAbility); + index[0]++; + } + + } + if(WhichInput.contains("Specific")) { + CardList Cards_inPlay = new CardList(); + Cards_inPlay.addAll(AllZone.Human_Battlefield.getCards()); + Cards_inPlay.addAll(AllZone.Computer_Battlefield.getCards()); + final String[] Specific = F_k[5].split("/"); + final int[] Restriction_Count = new int[1]; + for(int i = 0; i < Specific.length - 2;i++) { + if(Specific[i+2].contains("Type.") && !Specific[i+2].contains("NonType.")) { + Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(c.isType(Specific[Restriction_Count[0] + 2].replaceFirst("Type.", ""))) return true; + return false; + } + }); + } + if(Specific[i+2].contains("NonType.")) { + Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(!c.isType(Specific[Restriction_Count[0] + 2].replaceFirst("NonType.", ""))) return true; + return false; + } + }); + } + if(Specific[i+2].contains("Color.") && !Specific[i+2].contains("NonColor.")) { + Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(CardUtil.getColors(c).contains(Specific[Restriction_Count[0] + 2].replaceFirst("Color.", ""))) return true; + return false; + } + }); + } + if(Specific[i+2].contains("NonColor.")) { + Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(!CardUtil.getColors(c).contains(Specific[Restriction_Count[0] + 2].replaceFirst("NonColor.", ""))) return true; + return false; + } + }); + } + if(Specific[i+2].equals("NotSelf")) { + Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(!c.equals(F_card)) return true; + return false; + } + }); + } + Restriction_Count[0]++; + } + if(F_card.getController().equals(AllZone.HumanPlayer)) + AllZone.InputControl.setInput(CardFactoryUtil.input_targetSpecific(F_SpellAbility, Cards_inPlay, "Select a Valid Card", GetTargetsCommand, true, true)); + else { + if(Whenever_AI_GoodEffect(F_k)) { + Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(c.getController().equals(AllZone.ComputerPlayer)) return true; + return false; + } + }); + if(Cards_inPlay.size() > 0) { + Targets_Multi[index[0]] = CardFactoryUtil.AI_getBestCreature(Cards_inPlay,F_card); + AllZone.Stack.add(F_SpellAbility); + } + index[0]++; + } else { + Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(c.getController().equals(AllZone.HumanPlayer)) return true; + return false; + } + }); + if(Cards_inPlay.size() > 0) { + Targets_Multi[index[0]] = CardFactoryUtil.AI_getBestCreature(Cards_inPlay,F_card); + AllZone.Stack.add(F_SpellAbility); + } + index[0]++; + } + + } + } + + AllZone.Stack.updateObservers(); + } + + final Command GetTargetsCommand = new Command() { + + private static final long serialVersionUID = -328305150127775L; + + public void execute() { + Targets_Multi[index[0]] = F_SpellAbility.getTargetPlayer(); + if(Targets_Multi[index[0]] == null) Targets_Multi[index[0]] = F_SpellAbility.getTargetCard(); + if(F_k[8].contains("AttachTarget")) F_card.attachCard((Card) Targets_Multi[index[0]]); + index[0]++; + if(F_Multiple_Targets == 1) AllZone.Stack.updateObservers(); + } + }; + + }; + + if(k[8].contains("MultipleTargets")) CommandExecute[0] = MultiTargetsCommand; + else if(k[8].contains("SingleTarget")) CommandExecute[0] = MultiTargetsCommand; + else if(k[5].contains("NormalInput")) CommandExecute[0] = InputCommand; + else { + if(F_TargetPlayer[y] != null) Targets_Multi[index[0]] = F_TargetPlayer[y]; + if(F_TargetCard[y] != null) Targets_Multi[index[0]] = F_TargetCard[y]; + index[0]++; + CommandExecute[0] = Command.Blank; + } + + // Null + if(Effect[y].equals("Null")) { + Command_Effects[F_Target] = Command.Blank; + } + + // +1 +1 Counters + if(Effect[y].contains("+1+1 Counters")) { + + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + if(Whenever_Go(F_card,F_k) == true) { + CardList All = Check_if_All_Targets(F_card, F_k); + if(All.size() > 0) { + for(int i = 0; i < All.size(); i++) { + if(AllZone.GameAction.isCardInZone(All.get(i),Required_Zone) || F_Zones.equals("Any")) + All.get(i).addCounter(Counters.P1P1, F_Amount[0]); + } + } + if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Required_Zone) || F_Zones.equals("Any")) + F_TargetCard[F_Target].addCounter(Counters.P1P1, F_Amount[0]); + } + }; + }; + Command_Effects[F_Target] = Proper_resolve; + if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + "all specified permanents get" + F_Amount[0] + " +1/+1 counters"; + else StackDescription = StackDescription + F_TargetCard[y] + " gets " + F_Amount[0] + " +1/+1 counters"; + } + + // CustomCounters.(What Counter)/Amount + if(Effect[y].contains("CustomCounter")) { + + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + if(Whenever_Go(F_card,F_k) == true) { + String PossibleCounter = (F_k[4].split("/")[0]).replaceFirst("CustomCounter.", ""); + Counters Counter = null; + for(int i = 0; i < Counters.values().length ; i++) { + if(Counters.values()[i].toString().equals(PossibleCounter)) + Counter = Counters.values()[i]; + } + CardList All = Check_if_All_Targets(F_card, F_k); + if(All.size() > 0) { + for(int i = 0; i < All.size(); i++) { + if(AllZone.GameAction.isCardInZone(All.get(i),Required_Zone) || F_Zones.equals("Any")) + All.get(i).addCounter(Counter, F_Amount[0]); + } + } + if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Required_Zone) || F_Zones.equals("Any")) + F_TargetCard[F_Target].addCounter(Counter, F_Amount[0]); + } + }; + }; + Command_Effects[F_Target] = Proper_resolve; + if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + "all specified permanents get" + F_Amount[0] + " +1/+1 counters"; + else StackDescription = StackDescription + F_TargetCard[y] + " gets " + F_Amount[0] + + " " + (F_k[4].split("/")[0]).replaceFirst("CustomCounter.", "") + " "+((F_Amount[0]>1)?"counters":"counter"); + } + + // StatsPumpEOT/Power/Toughness + if(Effect[y].contains("StatsPumpEOT")) { + + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + final Command untilEOT = new Command() { + private static final long serialVersionUID = 1497565871061029469L; + + public void execute() { + if(AllZone.GameAction.isCardInPlay(F_card)) { + F_TargetCard[F_Target].addTempAttackBoost(- F_Amount[0]); + F_TargetCard[F_Target].addTempDefenseBoost(- F_Amount[1]); + } + } + }; //Command + + if(Whenever_Go(F_card,F_k) == true) { + CardList All = Check_if_All_Targets(F_card, F_k); + if(All.size() > 0) { + for(int i = 0; i < All.size(); i++) { + F_TargetCard[F_Target].addTempAttackBoost(F_Amount[0]); + F_TargetCard[F_Target].addTempDefenseBoost(F_Amount[1]); + AllZone.EndOfTurn.addUntil(untilEOT); + } + } + else if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Required_Zone) || F_Zones.equals("Any")) { + F_TargetCard[F_Target].addTempAttackBoost(F_Amount[0]); + F_TargetCard[F_Target].addTempDefenseBoost(F_Amount[1]); + AllZone.EndOfTurn.addUntil(untilEOT); + } + } + }; + }; + Command_Effects[F_Target] = Proper_resolve; + if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + "all specified permanents get" + ((F_Amount[0] > -1)? "+" :"") + F_Amount[0] + + "/" + ((F_Amount[1] > -1)? "+" :"") + F_Amount[1] + " until End of Turn"; + else StackDescription = StackDescription + F_TargetCard[y] + " gets " + ((F_Amount[0] > -1)? "+" :"") + F_Amount[0] + + "/" + ((F_Amount[1] > -1)? "+" :"") + F_Amount[1] + " until End of Turn"; + } + + // KeywordPumpEOT/Keyword(s) + if(Effect[y].contains("KeywordPumpEOT")) { + + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + final Command untilEOT = new Command() { + private static final long serialVersionUID = 1497565871061029469L; + + public void execute() { + if(AllZone.GameAction.isCardInPlay(F_card)) { + for(int i =0; i < F_S_Amount.length - 1; i++) { + F_card.removeIntrinsicKeyword(F_S_Amount[i + 1]); + } + } + } + };//Command + if(Whenever_Go(F_card,F_k) == true) { + CardList All = Check_if_All_Targets(F_card, F_k); + if(All.size() > 0) { + for(int i = 0; i < All.size(); i++) { + for(int i2 =0; i2 < F_S_Amount.length - 1; i2++) { + F_card.addIntrinsicKeyword(F_S_Amount[i2 + 1]); + } + AllZone.EndOfTurn.addUntil(untilEOT); + } + } + else if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Required_Zone) || F_Zones.equals("Any")) { + for(int i =0; i < F_S_Amount.length - 1; i++) { + F_card.addIntrinsicKeyword(F_S_Amount[i + 1]); + } + AllZone.EndOfTurn.addUntil(untilEOT); + } + } + }; + }; + String Desc = ""; + for(int KW =0; KW < F_S_Amount.length - 1; KW++) { + Desc = Desc + F_S_Amount[KW + 1]; + if(KW < F_S_Amount.length - 2) Desc = Desc + ", "; + } + Command_Effects[F_Target] = Proper_resolve; + if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + "all specified permanents get" + Desc + " until End of Turn"; + else StackDescription = StackDescription + F_TargetCard[y] + " gets " + Desc + " until End of Turn"; + } + + // ModifyLife/Amount + if(Effect[y].contains("ModifyLife")) { + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + if(Whenever_Go(F_card,F_k) == true) + if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { + if(F_Amount[0] > -1) + F_TargetPlayer[F_Target].gainLife(F_Amount[0], F_card); + else + F_TargetPlayer[F_Target].loseLife(F_Amount[0] * -1,F_card); + } + + } + }; + Command_Effects[F_Target] = Proper_resolve; + StackDescription = StackDescription + F_TargetPlayer[F_Target] + ((F_Amount[0] > -1)? " gains " + F_Amount[0]:"") + ((F_Amount[0] <= -1)? " loses " + F_Amount[0] * -1:"") + " life"; + } + + // Destroy + if(Effect[y].contains("Destroy")) { + + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + if(Whenever_Go(F_card,F_k) == true) { + CardList All = Check_if_All_Targets(F_card, F_k); + if(All.size() > 0) { + for(int i = 0; i < All.size(); i++) { + destroy(All.get(i)); + } + } else if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { + for(int z = 0; z < Targets_Multi.length; z++) { + if(AllZone.GameAction.isCardInPlay((Card) Targets_Multi[z]) + && CardFactoryUtil.canTarget(F_card, (Card) Targets_Multi[z])) { + Card c = (Card) Targets_Multi[z]; + destroy(c); + } + } + } + } + }; + }; + Command_Effects[F_Target] = Proper_resolve; + if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + " destroys all specified permanents"; + else StackDescription = StackDescription + " destroys " + (((Card) Targets_Multi[y] != null)? (Card) Targets_Multi[y]:""); + } + + // TapPermanent + if(Effect[y].contains("TapPermanent")) { + + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + if(Whenever_Go(F_card,F_k) == true) { + CardList All = Check_if_All_Targets(F_card, F_k); + if(All.size() > 0) { + for(int i = 0; i < All.size(); i++) { + All.get(i).tap(); + } + } + else if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { + for(int z = 0; z < Targets_Multi.length; z++) { + if(AllZone.GameAction.isCardInPlay((Card) Targets_Multi[z]) + && CardFactoryUtil.canTarget(F_card, (Card) Targets_Multi[z])) { + Card c = (Card) Targets_Multi[z]; + c.tap(); + } + } + } + } + }; + }; + Command_Effects[F_Target] = Proper_resolve; + if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + " taps all specified permanents"; + else StackDescription = StackDescription + " taps " + (((Card) Targets_Multi[y] != null)? (Card) Targets_Multi[y]:""); + } + + // UntapPermanent + if(Effect[y].contains("UntapPermanent")) { + + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + if(Whenever_Go(F_card,F_k) == true) { + CardList All = Check_if_All_Targets(F_card, F_k); + if(All.size() > 0) { + for(int i = 0; i < All.size(); i++) { + All.get(i).untap(); + } + } + else if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { + for(int z = 0; z < Targets_Multi.length; z++) { + if(AllZone.GameAction.isCardInPlay((Card) Targets_Multi[z]) + && CardFactoryUtil.canTarget(F_card, (Card) Targets_Multi[z])) { + Card c = (Card) Targets_Multi[z]; + c.untap(); + } + } + } + } + }; + }; + Command_Effects[F_Target] = Proper_resolve; + if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + " untaps all specified permanents"; + else StackDescription = StackDescription + " untaps " + (((Card) Targets_Multi[y] != null)? (Card) Targets_Multi[y]:""); + } + + + // Draw Cards + if(Effect[y].contains("DrawCards")) { + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + if(Whenever_Go(F_card,F_k) == true) + if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { + F_TargetPlayer[F_Target].drawCard(); + } + + } + }; + Command_Effects[F_Target] = Proper_resolve; + StackDescription = StackDescription + F_TargetPlayer[F_Target] + " draws " + F_Amount[0] + " card(s)"; + } + + + // Discard Cards + if(Effect[y].contains("DiscardCards")) { + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + if(Whenever_Go(F_card,F_k) == true) + if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { + //this might not work: + F_TargetPlayer[F_Target].discard(F_Amount[0], Ability, false); + } + + } + }; + Command_Effects[F_Target] = Proper_resolve; + StackDescription = StackDescription + F_TargetPlayer[F_Target] + " discards " + F_Amount[0] + " card(s)"; + } + + // Make Token-Type-color-Power-Toughness-Keywords---Amount + if(Effect[y].contains("MakeToken")) { + String[] TokenConditions = AmountParse.split("-"); + + String[] KeyWordConditions = new String[TokenConditions.length - 6]; + for(int z = 5; z < TokenConditions.length - 1; z++) + if(!TokenConditions[z - 5].equals("None")) KeyWordConditions[z - 5] = TokenConditions[z]; + final String[] F_TokenConditions = TokenConditions; + final String[] F_KeyWordConditions = KeyWordConditions; + + String Color = F_TokenConditions[2]; + if(F_TokenConditions[2].equals("c")) Color = "Colorless"; + else if(F_TokenConditions[2].equals("W")) Color = "White"; + else if(F_TokenConditions[2].equals("U")) Color = "Blue"; + else if(F_TokenConditions[2].equals("G")) Color = "Green"; + else if(F_TokenConditions[2].equals("R")) Color = "Red"; + else if(F_TokenConditions[2].equals("B")) Color = "Black"; + else Color = "Multicolored"; + final String F_Color = Color; + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + if(Whenever_Go(F_card,F_k) == true) + if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { + String[] types = F_TokenConditions[1].split(" "); + String[] creatTypes = new String[types.length+1]; + creatTypes[0] = "Creature"; + for (int i=0;i 0) { + for(int i = 0; i < All.size(); i++) { + AllZone.GameAction.moveTo(Whenever_GetMoveToZone(All.get(i), F_k)[1], All.get(i)); + checkStateEffects(); // For Legendaries + } + } + else { + Card NewSearch[] = Search(F_card,F_TriggeringCard, F_k,Custom_Strings); + if(NewSearch[0] != null) { + for(int i = 0; i < NewSearch.length; i++) { + AllZone.GameAction.moveTo(Whenever_GetMoveToZone(NewSearch[i], F_k)[1], NewSearch[i]); + checkStateEffects(); // For Legendaries + } + } else { + if(F_TargetCard[F_Target] == null) { + for(int z = 0; z < Targets_Multi.length; z++) { + F_TargetCard[F_Target] = (Card) Targets_Multi[z]; + if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Whenever_GetMoveToZone(F_TargetCard[F_Target], F_k)[0])) { + AllZone.GameAction.moveTo(Whenever_GetMoveToZone(F_TargetCard[F_Target], F_k)[1], F_TargetCard[F_Target]); + checkStateEffects(); // For Legendaries + } + } + } else if(AllZone.GameAction.isCardInZone(F_TargetCard[F_Target],Whenever_GetMoveToZone(F_TargetCard[F_Target], F_k)[0])) { + AllZone.GameAction.moveTo(Whenever_GetMoveToZone(F_TargetCard[F_Target], F_k)[1], F_TargetCard[F_Target]); + checkStateEffects(); // For Legendaries + } + } + } + } + } + }; + Command_Effects[F_Target] = Proper_resolve; + if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + " moves to all specified permanents from " + ZoneConditions[1] + " to " + ZoneConditions[2] + " zone"; + else if(F_TargetCard[y] != null) StackDescription = StackDescription + F_TargetCard[y] + " moves from " + ZoneConditions[1] + " to " + ZoneConditions[2] + " zone"; + else { + String[] SD = Search_Description(F_TriggeringCard ,k, Custom_Strings); + StackDescription = StackDescription + F_card.getController() + " searches his/her " + SD[0] + " for a " + SD[1] + "card and moves it to the " + ZoneConditions[2] + + " zone. If that player searches a library this way, shuffle it"; + } + } + + // Deal Damage + if(Effect[y].contains("Damage")) { + Command Proper_resolve = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + if(Whenever_Go(F_card,F_k) == true) { + CardList All = Check_if_All_Targets(F_card, F_k); + if(All.size() > 0) { + for(int i = 0; i < All.size(); i++) { + All.get(i).addDamage(F_Amount[0], F_card); + } + } + else if(AllZone.GameAction.isCardInZone(F_card,Required_Zone) || F_Zones.equals("Any")) { + if(F_card.getController().equals(AllZone.HumanPlayer)) { + for(int z = 0; z < Targets_Multi.length; z++) { + if(!(Targets_Multi[z].equals(AllZone.HumanPlayer) || Targets_Multi[z].equals(AllZone.ComputerPlayer))) { + if(AllZone.GameAction.isCardInPlay((Card) Targets_Multi[z]) + && CardFactoryUtil.canTarget(F_card, (Card) Targets_Multi[z])) { + Card c = (Card) Targets_Multi[z]; + c.addDamage(F_Amount[0], F_card); + } + } + else { + ((Player) Targets_Multi[z]).addDamage(F_Amount[0], F_card); + } + } + } + if(F_card.getController().equals(AllZone.ComputerPlayer)) AllZone.HumanPlayer.addDamage(F_Amount[0]*F_Multiple_Targets, F_card); + } + } + }; + + }; + Command_Effects[F_Target] = Proper_resolve; + if(Check_if_All_Targets(F_card, F_k).size() > 0) StackDescription = StackDescription + "deals " + F_Amount[0]*F_Multiple_Targets + " damage" + " to all specified permanents/players"; + else if(F_Multiple_Targets != 1) StackDescription = StackDescription + "deals " + F_Amount[0]*F_Multiple_Targets + " damage" + " divided among up to " + Multiple_Targets + " target creatures and/or players"; + else if(F_card.getController().equals(AllZone.ComputerPlayer)) StackDescription = StackDescription + "targeting Human "; + else StackDescription = StackDescription + "targeting " + ((F_TargetCard[y] != null)? F_TargetCard[y]:"") + + ((F_TargetPlayer[y] != null)? F_TargetPlayer[y]:""); + } + + Effects_Count[0]++; + if(Effects_Count[0] != Effects) StackDescription = StackDescription + " and "; + else StackDescription = StackDescription + "."; + } // For + F_SpellAbility.setStackDescription(StackDescription); + for(int Check = 0; Check < Command_Effects.length; Check++) + if(!Command_Effects[Check].equals(Command.Blank)) { + Whenever_Input(F_card,F_k,CommandExecute[0],F_SpellAbility); + break; + } + } + } + } + } + } + + PlayerZone[] Whenever_GetMoveToZone (Card Target, String[] Keyword_Details) { + String Zones = Keyword_Details[4]; + String[] Zone = Zones.split("-"); + PlayerZone[] Required_Zone = new PlayerZone[2]; + if(Zone[1].contains("Hand")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Hand, Target.getController()); + if(Zone[1].contains("Graveyard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Graveyard, Target.getController()); + if(Zone[1].contains("Play") || Zones.equals("Any")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Battlefield, Target.getController()); + if(Zone[1].contains("Library")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Library, Target.getController()); + if(Zone[1].contains("Exiled")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Exile, Target.getController()); + // if(Zone[1].contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, Target.getController()); + + if(Zone[2].contains("Hand")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Hand, Target.getController()); + if(Zone[2].contains("Graveyard")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Graveyard, Target.getController()); + if(Zone[2].contains("Play") || Zones.equals("Any")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Battlefield, Target.getController()); + if(Zone[2].contains("Library")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Library, Target.getController()); + if(Zone[2].contains("Exiled")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Exile, Target.getController()); + // if(Zone[2].contains("Sideboard")) Required_Zone[1] = AllZone.getZone(Constant.Zone.Sideboard, Target.getController()); + + return Required_Zone; + } + + CardList Check_if_All_Targets (final Card Triggering_Card, String[] Keyword_Details) { + CardList Cards_inPlay = new CardList(); + if(Keyword_Details[5].contains("All") && Keyword_Details[4] != "Null") { + final String[] AllTargets = Keyword_Details[5].split("/"); + + Cards_inPlay.addAll(AllZone.Human_Battlefield.getCards()); + Cards_inPlay.addAll(AllZone.Computer_Battlefield.getCards()); + for(int i2 = 0; i2 < AllTargets.length - 1;i2++) { + final int[] Restriction_Count = new int[1]; + if(AllTargets[i2+1].contains("Type.")) { + Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(c.isType(AllTargets[Restriction_Count[0] + 1].replaceFirst("Type.", ""))) return true; + return false; + } + }); + } + if(AllTargets[i2+1].contains("Color.")) { + Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(CardUtil.getColors(c).contains(AllTargets[Restriction_Count[0] + 1].replaceFirst("Color.", ""))) return true; + return false; + } + }); + } + if(AllTargets[i2+1].contains("AttachedCards")) { + Cards_inPlay.clear(); + Cards_inPlay.addAll(Triggering_Card.getAttachedCards()); + + } + Restriction_Count[0]++; + } + + // All Special Conditions + if(Keyword_Details[8].contains("AllTargets - Except Self")) { + Cards_inPlay = Cards_inPlay.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(c != Triggering_Card) return true; + return false; + } + }); + } + if(Cards_inPlay.size() == 0) Cards_inPlay.add(AllZone.CardFactory.HumanNullCard); + } + return Cards_inPlay; + } + + boolean Whenever_AI_GoodEffect(String[] Keyword_Details) { + boolean Good = true; + // List all the bad / possibly bad effects here + // Movefrom is bad because in order for it to have a target, the target must be in play. + if(Keyword_Details[4].contains("TapPermanent") || Keyword_Details[4].contains("DiscardCards") + || Keyword_Details[4].contains("MoveFrom") || Keyword_Details[4].contains("Damage")) + Good = false; + // Situational Effects + else { + String EffectInQuestion = Keyword_Details[4].split("/")[1]; + if(Keyword_Details[4].contains("ModifyLife") && EffectInQuestion.contains("-")) Good = false; + if(Keyword_Details[4].contains("StatsPumpEOT") && EffectInQuestion.contains("-")) Good = false; + } + return Good; + } + + Card[] Search (Card Source, Card Initiator ,String[] Keyword_Details, final String[] Custom_Strings) { + String SearchDescription = " "; + boolean SearchLib = true; + if(Keyword_Details[7].contains("Choice_Instant-SearchLibrary")) { + if(Source.getController().equals(AllZone.HumanPlayer)) { + Object[] possibleValues = {"Yes", "No"}; + Object q = JOptionPane.showOptionDialog(null, "Search Libraries?",Source.getName() + " F_SpellAbility", + JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, + null, possibleValues, possibleValues[0]); + if(q.equals(1)) { + SearchLib = false; + } + } + } + int Target_Conditions = 1; + String TargetParse = Keyword_Details[5]; + String Targets[] = TargetParse.split("!"); + Target_Conditions = Targets.length; + Player Zone_Owner = Source.getController(); + Card SearchedCard[] = new Card[Target_Conditions]; + for(int y = 0; y < Target_Conditions; y++) { + if(Targets[y].contains("SearchShuffle") /** && Keyword_Details[4] != "Null" **/) { + if(Targets[y].contains("OSearchShuffle")) { + Zone_Owner = Source.getController().getOpponent(); + SearchDescription = SearchDescription + "Opponent's "; + } + else Zone_Owner = Source.getController(); + String SearchParse = Targets[y]; + String Search[] = SearchParse.split("/"); + String[] SearchZone = new String[Search.length - 1]; + PlayerZone[] PZones = new PlayerZone[SearchZone.length]; + CardList SearchBase = new CardList(); + for(int z = 0; z < PZones.length; z++) { + SearchZone[z] = Search[z+1]; + if(SearchZone[z].equals("Hand")) PZones[z] = AllZone.getZone(Constant.Zone.Hand, Zone_Owner); + if(SearchZone[z].equals("Graveyard")) PZones[z] = AllZone.getZone(Constant.Zone.Graveyard, Zone_Owner); + if(SearchZone[z].equals("Play")) PZones[z] = AllZone.getZone(Constant.Zone.Battlefield, Zone_Owner); + if(SearchZone[z].contains("Library") && SearchLib) PZones[z] = AllZone.getZone(Constant.Zone.Library, Zone_Owner); + if(SearchZone[z].contains("Exiled")) PZones[z] = AllZone.getZone(Constant.Zone.Exile, Zone_Owner); + // if(ZoneConditions[z].contains("Sideboard")) PZones[z] = AllZone.getZone(Constant.Zone.Sideboard, Zone_Owner); + if(PZones[z] != null) { + SearchBase.addAll(PZones[z].getCards()); + SearchDescription = SearchDescription + SearchZone[z] + " "; + } + if(z + 2 < PZones.length && PZones[z] != null) SearchDescription = SearchDescription + ", "; + else if(z + 2 == PZones.length) SearchDescription = SearchDescription + "and "; + } + + @SuppressWarnings("unused") + Object check2 = GuiUtils.getChoiceOptional("View" + SearchDescription, + SearchBase.toArray()); + if(Search[0].contains("SearchShuffle_SameName")) SearchBase = SearchBase.getName(Initiator.getName()); + if(Search[0].contains("SearchShuffle_Type")) { + for(int TypeRestrict = 0; TypeRestrict < Custom_Strings.length; TypeRestrict ++) { + if(Custom_Strings[TypeRestrict].startsWith("Type")) SearchBase = SearchBase.getType(Custom_Strings[TypeRestrict].replaceFirst("Type", "")); + if(Custom_Strings[TypeRestrict].startsWith("Color")) { + final int Number = TypeRestrict; + SearchBase = SearchBase.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(CardUtil.getColors(c).contains(Custom_Strings[Number].replaceFirst("Color", ""))) return true; + return false; + } + }); + } + } + } + if(SearchBase.size() != 0) { + Object check = GuiUtils.getChoiceOptional("Select a Suitable Card", + SearchBase.toArray()); + if(check != null) { + SearchedCard[y] = (Card) check; + if(SearchLib) ((Card) check).getController().shuffle(); + } + } else { + JOptionPane.showMessageDialog(null, "No suitable cards in" + SearchDescription, "", JOptionPane.INFORMATION_MESSAGE); + if(SearchLib && Targets[y].contains("OSearchShuffle")) Source.getController().getOpponent().shuffle(); + else if(SearchLib) Source.getController().shuffle(); + } + } + } + return SearchedCard; + } + + String[] Search_Description(Card Initiator ,String[] Keyword_Details, final String[] Custom_Strings) { + String[] SD = new String[2]; + String SearchDescription = ""; + String SearchType = ""; + int Target_Conditions = 1; + String TargetParse = Keyword_Details[5]; + String Targets[] = TargetParse.split("!"); + Target_Conditions = Targets.length; + for(int y = 0; y < Target_Conditions; y++) { + if(Targets[y].contains("SearchShuffle")) { + if(Targets[y].contains("OSearchShuffle")) { + SearchDescription = SearchDescription + "Opponent's"; + } + String SearchParse = Targets[y]; + String Search[] = SearchParse.split("/"); + + for(int z = 0; z < Search.length - 1; z++) { + SearchDescription = SearchDescription + Search[z+1]; + if(z + 3 < Search.length) SearchDescription = SearchDescription + ", "; + else if(z + 2 != Search.length) SearchDescription = SearchDescription + " and/or "; + } + if(Search[0].contains("SearchShuffle_SameName")) SearchType = Initiator.getName() + " "; + if(Search[0].contains("SearchShuffle_Type")) { + for(int TypeRestrict = 0; TypeRestrict < Custom_Strings.length; TypeRestrict ++) { + if(Custom_Strings[TypeRestrict].startsWith("Color")) { + SearchType = SearchType + Custom_Strings[TypeRestrict].replaceFirst("Color", ""); + if(TypeRestrict + 1 != Custom_Strings.length) SearchType = SearchType + " "; + } + } + for(int TypeRestrict = 0; TypeRestrict < Custom_Strings.length; TypeRestrict ++) { + if(Custom_Strings[TypeRestrict].startsWith("Type")) { + SearchType = SearchType + Custom_Strings[TypeRestrict].replaceFirst("Type", ""); + if(TypeRestrict + 1 != Custom_Strings.length) SearchType = SearchType + " "; + } + } + } + } + } + SD[0] = SearchDescription; + SD[1] = SearchType; + + return SD; + } + + void Whenever_ManaPaid (Card Source, String[] Keyword_Details, final Command Proper_Resolve, SpellAbility ability) { + String S_Amount = "0"; + if(!Keyword_Details[7].contains("No_Condition") && !Keyword_Details[7].equals("Yes_No") + && !Keyword_Details[7].equals("Opponent_Yes_No")&& !Keyword_Details[7].contains("Choice_Instant")) { + if(Keyword_Details[7].contains("PayMana")) { + String PayAmountParse = Keyword_Details[7]; + S_Amount = PayAmountParse.split("/")[1]; + + if(Source.getController().equals(AllZone.HumanPlayer)) { + final Command paid = new Command() { + private static final long serialVersionUID = 151367344511590317L; + + public void execute() { + Proper_Resolve.execute(); + } + }; + StringBuilder sb = new StringBuilder(); + sb.append("Activate ").append(Source.getName()).append("'s ability: \n"); + + GameActionUtil.payManaDuringAbilityResolve(sb.toString(), S_Amount, paid, Command.Blank); + } else { + if(ComputerUtil.canPayCost(S_Amount)) { + ComputerUtil.payManaCost(ability); + Proper_Resolve.execute(); + } + } + } + if(Keyword_Details[7].contains("SacrificeType")) { + String PayAmountParse = Keyword_Details[7]; + S_Amount = PayAmountParse.split("/")[1]; + PlayerZone play = AllZone.getZone(Constant.Zone.Battlefield, Source.getController()); + CardList choice = new CardList(play.getCards()); + choice = choice.getType(S_Amount); + if(Source.getController().equals(AllZone.HumanPlayer)) { + AllZone.InputControl.setInput(CardFactoryUtil.Wheneverinput_sacrifice(ability, choice, "Select a " + S_Amount +" to sacrifice.",Proper_Resolve)); + } /*else { + if(choice.size() > 5) { + sacrifice(choice.get(0)); + Proper_Resolve.execute(); + } + } */ + } + } else Proper_Resolve.execute(); + + } + + + boolean Whenever_Go (Card Source, String[] Keyword_Details) { + boolean Go = true; + String Zones = Keyword_Details[3]; + PlayerZone[] Required_Zone = new PlayerZone[1]; + if(Zones.equals("Hand")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Hand, Source.getController()); + if(Zones.equals("Graveyard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Graveyard, Source.getController()); + if(Zones.equals("Play") || Zones.equals("Any")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Battlefield, Source.getController()); + if(Zones.contains("Library")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Library, Source.getController()); + if(Zones.contains("Exiled")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Exile, Source.getController()); + //if(Zones.contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, Source.getController()); + + if(AllZone.GameAction.isCardInZone(Source,Required_Zone[0]) || Zones.equals("Any")) { + if(Keyword_Details[7].equals("Yes_No")) { + if(Source.getController().equals(AllZone.HumanPlayer)) { + Object[] possibleValues = {"Yes", "No"}; + Object q = JOptionPane.showOptionDialog(null, "Activate - " + Source.getName(),Source.getName() + " Ability", + JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, + null, possibleValues, possibleValues[0]); + if(q.equals(1)) { + Go = false; + } + } + } + if(Keyword_Details[7].equals("Opponent_Yes_No")) { + if(!Source.getController().equals(AllZone.HumanPlayer)) { + Object[] possibleValues = {"Yes", "No"}; + Object q = JOptionPane.showOptionDialog(null, "Activate - " + Source.getName(),Source.getName() + " Ability", + JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, + null, possibleValues, possibleValues[0]); + if(q.equals(1)) { + Go = false; + } + } + } + } + + return Go; + } + + public void Whenever_Input(Card Source, String[] Keyword_Details, Command paidCommand, final SpellAbility ability) { + if(!Keyword_Details[8].contains("ActualEffect")) { + String Zones = Keyword_Details[3]; + PlayerZone[] Required_Zone = new PlayerZone[1]; + if(Zones.equals("Hand")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Hand, Source.getController()); + if(Zones.equals("Graveyard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Graveyard, Source.getController()); + if(Zones.equals("Play") || Zones.equals("Any")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Battlefield, Source.getController()); + if(Zones.contains("Library")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Library, Source.getController()); + if(Zones.contains("Exiled")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Exile, Source.getController()); + //if(Zones.contains("Sideboard")) Required_Zone[0] = AllZone.getZone(Constant.Zone.Sideboard, Source.getController()); + + if(AllZone.GameAction.isCardInZone(Source,Required_Zone[0]) || Zones.equals("Any")) { + if(Keyword_Details[6].equals("ASAP")) { + if(Keyword_Details[5].equals("InputType - CreatureORPlayer") && Source.getController().equals(AllZone.HumanPlayer)) { + paidCommand.execute(); + } + else if(Keyword_Details[5].equals("InputType - CreatureORPlayer") && Source.getController().equals(AllZone.ComputerPlayer)) + AllZone.Stack.add(ability); + else if(Keyword_Details[5].contains("NormalInput")) { + paidCommand.execute(); + } + else AllZone.Stack.add(ability); + } + } + } else paidCommand.execute(); + } + // Whenever Keyword + + public void sacrificeDestroy(Card c) { + if(!isCardInPlay(c)) return; + + Player owner = c.getOwner(); + if (!(owner.isComputer() || owner.isHuman())) + throw new RuntimeException("GameAction : destroy() invalid card.getOwner() - " + c + " " + owner); + + boolean persist = (c.getKeyword().contains("Persist") && c.getCounters(Counters.M1M1) == 0); + + Card newCard = moveToGraveyard(c); + + // Destroy needs to be called with Last Known Information + c.destroy(); + + //destroy card effects: + CardList list = AllZoneUtil.getCardsInPlay(); + list = list.filter(new CardListFilter() { + public boolean addCard(Card c) { + ArrayList keywords = c.getKeyword(); + for(String kw:keywords) { + if(kw.startsWith("Whenever ") && kw.contains(" put into") + && kw.contains("graveyard from the battlefield,")) return true; + } + return false; + } + }); + + checkWheneverKeyword(c, "PermanentIntoGraveyard",null); + for(int i = 0; i < list.size(); i++) + GameActionUtil.executeDestroyCardEffects(list.get(i), c); + + if(persist) { + final Card persistCard = newCard; + Ability persistAb = new Ability(persistCard, "0"){ + + @Override + public void resolve() { + if (AllZone.getZone(persistCard).is(Constant.Zone.Graveyard)){ + PlayerZone ownerPlay = AllZone.getZone(Constant.Zone.Battlefield, persistCard.getOwner()); + Card card = moveTo(ownerPlay, persistCard); + card.addCounter(Counters.M1M1, 1); + } + } + }; + persistAb.setStackDescription(newCard.getName() + " - Returning from Persist"); + AllZone.Stack.add(persistAb); + } + + if(c.getName().equals("Nissa's Chosen")) { + PlayerZone library = AllZone.getZone(Constant.Zone.Library, newCard.getOwner()); + moveTo(library, newCard); + } + + else if(c.getName().equals("Guan Yu, Sainted Warrior")) { + PlayerZone library = AllZone.getZone(Constant.Zone.Library, newCard.getOwner()); + newCard = moveTo(library, newCard); + owner.shuffle(); + } + }//sacrificeDestroy() + + public boolean destroy(Card c) { + if(!AllZone.GameAction.isCardInPlay(c) + || (c.getKeyword().contains("Indestructible") && (!c.isCreature() || c.getNetDefense() > 0))) return false; + + if(c.canBeShielded() && c.getShield() > 0) { + c.subtractShield(); + c.setDamage(0); + c.tap(); + AllZone.Combat.removeFromCombat(c); + return false; + } + + if (c.isEnchanted()) + { + CardList list = new CardList(c.getEnchantedBy().toArray()); + list = list.filter(new CardListFilter() + { + public boolean addCard(Card crd) + { + return crd.getKeyword().contains("Totem armor"); + } + }); + CardListUtil.sortCMC(list); + + + + if (list.size() != 0) + { + final Card crd; + if (list.size() == 1) + { + crd = list.get(0); + } + else { + if (c.getController().isHuman()) + crd = GuiUtils.getChoiceOptional("Select totem armor to destroy", list.toArray()); + else + crd = list.get(0); + } + + final Card card = c; + Ability_Static ability = new Ability_Static(crd, "0") + { + public void resolve() + { + destroy(crd); + card.setDamage(0); + + } + }; + + StringBuilder sb = new StringBuilder(); + sb.append(crd).append(" - Totem armor: destroy this aura."); + ability.setStackDescription(sb.toString()); + + AllZone.Stack.add(ability); + return false; + } + }//totem armor + + //System.out.println("Card " + c.getName() + " is getting sent to GY, and this turn it got damaged by: "); + for(Card crd:c.getReceivedDamageFromThisTurn().keySet()) { + if(c.getReceivedDamageFromThisTurn().get(crd) > 0) { + //System.out.println(crd.getName() ); + GameActionUtil.executeVampiricEffects(crd); + } + } + + this.sacrificeDestroy(c); + return true; + } + + //is this card a permanent that is in play? + public boolean isCardInPlay(Card c) { + return PlayerZoneUtil.isCardInZone(AllZone.Computer_Battlefield, c) + || PlayerZoneUtil.isCardInZone(AllZone.Human_Battlefield, c); + } + + public boolean isCardInGrave(Card c) { + return PlayerZoneUtil.isCardInZone(AllZone.Computer_Graveyard, c) + || PlayerZoneUtil.isCardInZone(AllZone.Human_Graveyard, c); + } + + public boolean isCardExiled(Card c) { + return PlayerZoneUtil.isCardInZone(AllZone.Computer_Exile, c) + || PlayerZoneUtil.isCardInZone(AllZone.Human_Exile, c); + } + + /** + * prompts Human to see if a target player's library should be shuffled. This should + * only be called when the choice is made by the Human (target can be either), then + * shuffles that player's library if appropriate + * + * @param player the player's library we want to shuffle + */ + public void promptForShuffle(final Player player) { + String[] choices = new String[] {"Yes", "No"}; + Object o = GuiUtils.getChoice("Shuffle "+player+"'s library?", choices); + String myChoice = (String) o; + if(myChoice.equals("Yes")) { + player.shuffle(); + } + } + + public boolean isCardInZone(Card card, PlayerZone p) { + ArrayList list = new ArrayList(Arrays.asList(p.getCards())); + return list.contains(card); + } + + //removes all damage from player's creatures + public void removeDamage(Player player) { + PlayerZone p = AllZone.getZone(Constant.Zone.Battlefield, player); + ArrayList a = PlayerZoneUtil.getCardType(p, "Creature"); + Card c[] = CardUtil.toCard(a); + for(int i = 0; i < c.length; i++) + c[i].setDamage(0); + } + + //for Quest fantasy mode + public void newGame(Deck humanDeck, Deck computerDeck, CardList human, CardList computer, int humanLife, int computerLife, Quest_Assignment qa) + { + this.newGame(humanDeck, computerDeck); + + AllZone.ComputerPlayer.setLife(computerLife, null); + AllZone.HumanPlayer.setLife(humanLife, null); + + if (qa != null){ + computer.addAll(forge.quest.data.QuestUtil.getComputerCreatures(AllZone.QuestData, AllZone.QuestAssignment).toArray()); + } + + for (Card c : human) + { + AllZone.Human_Battlefield.add(c); + c.setSickness(true); + } + + for (Card c: computer) + { + AllZone.Computer_Battlefield.add(c); + c.setSickness(true); + } + Constant.Quest.fantasyQuest[0] = true; + } + + boolean Start_Cut = false; + boolean StaticEffectKeywordReset = true; + public void newGame(Deck humanDeck, Deck computerDeck) { +// AllZone.Computer = new ComputerAI_Input(new ComputerAI_General()); + Constant.Quest.fantasyQuest[0] = false; + + AllZone.GameInfo.setPreventCombatDamageThisTurn(false); + AllZone.GameInfo.setHumanNumberOfTimesMulliganed(0); + AllZone.GameInfo.setHumanMulliganedToZero(false); + AllZone.GameInfo.setComputerStartedThisGame(false); + + AllZone.HumanPlayer.reset(); + AllZone.ComputerPlayer.reset(); + + AllZone.Phase.reset(); + AllZone.Stack.reset(); + AllZone.Combat.reset(); + AllZone.Display.showCombat(""); + AllZone.Display.loadPrefs(); + + AllZone.Human_Graveyard.reset(); + AllZone.Human_Hand.reset(); + AllZone.Human_Library.reset(); + AllZone.Human_Battlefield.reset(); + AllZone.Human_Exile.reset(); + + AllZone.Computer_Graveyard.reset(); + AllZone.Computer_Hand.reset(); + AllZone.Computer_Library.reset(); + AllZone.Computer_Battlefield.reset(); + AllZone.Computer_Exile.reset(); + + AllZone.InputControl.clearInput(); + + AllZone.StaticEffects.reset(); + StaticEffectKeywordReset = true; + + AllZone.HumanPlayer.clearHandSizeOperations(); + AllZone.ComputerPlayer.clearHandSizeOperations(); + + AllZone.TriggerHandler.clearRegistered(); + + + {//re-number cards just so their unique numbers are low, just for user friendliness + CardFactory c = AllZone.CardFactory; + Card card; + int nextUniqueNumber = 1; + + Random generator = new Random(); + + for(int i = 0; i < humanDeck.countMain(); i++) { + card = c.getCard(humanDeck.getMain(i), AllZone.HumanPlayer); + card.setUniqueNumber(nextUniqueNumber++); + + //if(card.isBasicLand()) { + //String PC = card.getSVar("PicCount"); + //if (PC.matches("[0-9][0-9]?")) + // n = Integer.parseInt(PC); + + if ((card.getSets().size() > 0) && card.getCurSetCode().equals("")) + card.setRandomSetCode(); + + if (!card.getCurSetCode().equals("")) { + int n = SetInfoUtil.getSetInfo_Code(card.getSets(), card.getCurSetCode()).PicCount; + if (n > 1) + card.setRandomPicture(generator.nextInt(n-1) + 1); + + card.setImageFilename(CardUtil.buildFilename(card)); + } + + //System.out.println("human random number:" + card.getRandomPicture()); + //} + + AllZone.Human_Library.add(card); + + for(Trigger trig : card.getTriggers()) + { + AllZone.TriggerHandler.registerTrigger(trig); + } + } + + ArrayList RAICards = new ArrayList(); + for(int i = 0; i < computerDeck.countMain(); i++) { + card = c.getCard(computerDeck.getMain(i), AllZone.ComputerPlayer); + card.setUniqueNumber(nextUniqueNumber++); + + //if(card.isBasicLand()) { + //String PC = card.getSVar("PicCount"); + //int n = 0; + //if (PC.matches("[0-9][0-9]?")) + // n = Integer.parseInt(PC); + //if (n > 1) + // card.setRandomPicture(generator.nextInt(n)); + //System.out.println("computer random number:" + card.getRandomPicture()); + //} + if ((card.getSets().size() > 0) && card.getCurSetCode().equals("")) + card.setRandomSetCode(); + + if (!card.getCurSetCode().equals("")) { + int n = SetInfoUtil.getSetInfo_Code(card.getSets(), card.getCurSetCode()).PicCount; + if (n > 1) + card.setRandomPicture(generator.nextInt(n-1) + 1); + + card.setImageFilename(CardUtil.buildFilename(card)); + } + + AllZone.Computer_Library.add(card); + + for(Trigger trig : card.getTriggers()) + { + AllZone.TriggerHandler.registerTrigger(trig); + } + + if (card.getSVar("RemAIDeck").equals("True")) + RAICards.add(card.getName()); + //get card picture so that it is in the image cache +// ImageCache.getImage(card); + } + + if (RAICards.size() > 0) + { + StringBuilder sb = new StringBuilder("AI deck contains the following cards that it can't play or may be buggy:\n"); + for (int i=0; i 0)) + sb.append("\n"); + else if (i != (RAICards.size() - 1)) + sb.append(", "); + } + + JOptionPane.showMessageDialog(null, sb.toString(), "", JOptionPane.INFORMATION_MESSAGE); + + } + }//end re-numbering + + for(int i = 0; i < 100; i++) + AllZone.HumanPlayer.shuffle(); + + //do this instead of shuffling Computer's deck + boolean smoothLand = Constant.Runtime.Smooth[0]; + + if(smoothLand) { + Card[] c = smoothComputerManaCurve(AllZone.Computer_Library.getCards()); + AllZone.Computer_Library.setCards(c); + } else { + AllZone.Computer_Library.setCards(AllZone.Computer_Library.getCards()); + AllZone.ComputerPlayer.shuffle(); + } + + // Only cut/coin toss if it's the first game of the match + if (Constant.Runtime.matchState.countWinLose() == 0) + { + // New code to determine who goes first. Delete this if it doesn't work properly + if(Start_Cut) + seeWhoPlaysFirst(); + else + seeWhoPlaysFirst_CoinToss(); + } + else if (Constant.Runtime.matchState.didWinRecently()) // if player won last, AI starts + computerStartsGame(); + + for(int i = 0; i < 7; i++) { + AllZone.HumanPlayer.drawCard(); + AllZone.ComputerPlayer.drawCard(); + } + + // todo: ManaPool should be moved to Player and be represented in the player panel + ManaPool mp = AllZone.ManaPool; + mp.setImageFilename("mana_pool"); + AllZone.Human_Battlefield.add(mp); + + AllZone.InputControl.setInput(new Input_Mulligan()); + Phase.GameBegins = 1; + }//newGame() + + //this is where the computer cheats + //changes AllZone.Computer_Library + private Card[] smoothComputerManaCurve(Card[] in) { + CardList library = new CardList(in); + library.shuffle(); + + //remove all land, keep non-basicland in there, shuffled + CardList land = library.getType("Land"); + for(int i = 0; i < land.size(); i++) + if(land.get(i).isLand()) library.remove(land.get(i)); + + //non-basic lands are removed, because the computer doesn't seem to + //effectively use them very well + land = threadLand(land); + + try { + //mana weave, total of 7 land + // The Following have all been reduced by 1, to account for the computer starting first. + library.add(6, land.get(0)); + library.add(7, land.get(1)); + library.add(8, land.get(2)); + library.add(9, land.get(3)); + library.add(10, land.get(4)); + + library.add(12, land.get(5)); + library.add(15, land.get(6)); + } catch(IndexOutOfBoundsException e) { + System.err.println("Error: cannot smooth mana curve, not enough land"); + return in; + } + + //add the rest of land to the end of the deck + for(int i = 0; i < land.size(); i++) + if(!library.contains(land.get(i))) library.add(land.get(i)); + + + //check + for(int i = 0; i < library.size(); i++) + System.out.println(library.get(i)); + + + return library.toArray(); + }//smoothComputerManaCurve() + + /* + @SuppressWarnings("unused") + // getComputerLand + private CardList getComputerLand(CardList in) { + CardList land; + land = in.filter(new CardListFilter() { + public boolean addCard(Card c) { + return c.isLand(); + } + }); + + return land; + }//getComputerLand() + */ + + //non-basic lands are removed, because the computer doesn't seem to + //effectively used them very well + public CardList threadLand(CardList in) { + //String[] basicLand = {"Forest", "Swamp", "Mountain", "Island", "Plains"}; //unused + + //Thread stuff with as large a spread of colors as possible: + String[] allLand = { + "Bayou", "Volcanic Island", "Savannah", "Badlands", "Tundra", "Taiga", "Underground Sea", + "Plateau", "Tropical Island", "Scrubland", "Overgrown Tomb", "Steam Vents", "Temple Garden", + "Blood Crypt", "Hallowed Fountain", "Stomping Ground", "Watery Grave", "Sacred Foundry", + "Breeding Pool", "Godless Shrine", "Pendelhaven", "Flagstones of Trokair", "Forest", "Swamp", + "Mountain", "Island", "Plains", "Tree of Tales", "Vault of Whispers", "Great Furnace", + "Seat of the Synod", "Ancient Den", "Treetop Village", "Ghitu Encampment", "Faerie Conclave", + "Forbidding Watchtower", "Savage Lands", "Arcane Sanctum", "Jungle Shrine", + "Crumbling Necropolis", "Seaside Citadel", "Elfhame Palace", "Coastal Tower", "Salt Marsh", + "Kher Keep", "Library of Alexandria", "Dryad Arbor"}; + + + ArrayList land = new ArrayList(); + + //get different CardList of all Forest, Swamps, etc... + CardList check; + for(int i = 0; i < allLand.length; i++) { + check = in.getName(allLand[i]); + + if(!check.isEmpty()) land.add(check); + } + /* + //get non-basic land CardList + check = in.filter(new CardListFilter() + { + public boolean addCard(Card c) + { + return c.isLand() && !c.isBasicLand(); + } + }); + if(! check.isEmpty()) + land.add(check); + */ + + //thread all separate CardList's of land together to get something like + //Mountain, Plains, Island, Mountain, Plains, Island + CardList out = new CardList(); + + int i = 0; + while(!land.isEmpty()) { + i = (i + 1) % land.size(); + + check = land.get(i); + if(check.isEmpty()) { + //System.out.println("removed"); + land.remove(i); + i--; + continue; + } + + out.add(check.get(0)); + check.remove(0); + }//while + + return out; + }//threadLand() + + + @SuppressWarnings("unused") + // getDifferentLand + private int getDifferentLand(CardList list, String land) { + int out = 0; + + return out; + } + + //decides who goes first when starting another game, used by newGame() + public void seeWhoPlaysFirst_CoinToss() { + Object[] possibleValues = {ForgeProps.getLocalized(GAMEACTION_TEXT.HEADS), ForgeProps.getLocalized(GAMEACTION_TEXT.TAILS)}; + Object q = JOptionPane.showOptionDialog(null, ForgeProps.getLocalized(GAMEACTION_TEXT.HEADS_OR_TAILS), ForgeProps.getLocalized(GAMEACTION_TEXT.COIN_TOSS), + JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, + null, possibleValues, possibleValues[0]); + + int Flip = MyRandom.random.nextInt(2); + String Human_Flip = " "; + String Computer_Flip = " "; + // JOptionPane.showMessageDialog(null, q, "", JOptionPane.INFORMATION_MESSAGE); + if(q.equals(0)) { + Human_Flip = ForgeProps.getLocalized(GAMEACTION_TEXT.HEADS); + Computer_Flip = ForgeProps.getLocalized(GAMEACTION_TEXT.TAILS); + } + else { + Human_Flip = ForgeProps.getLocalized(GAMEACTION_TEXT.TAILS); + Computer_Flip = ForgeProps.getLocalized(GAMEACTION_TEXT.HEADS); + } + + if((Flip == 0 && q.equals(0)) || (Flip == 1 && q.equals(1))) + JOptionPane.showMessageDialog(null, Human_Flip + "\r\n" + ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_WIN), "", JOptionPane.INFORMATION_MESSAGE); + else { + computerStartsGame(); + JOptionPane.showMessageDialog(null, Computer_Flip + "\r\n" + ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_WIN), "", JOptionPane.INFORMATION_MESSAGE); + } + }//seeWhoPlaysFirst_CoinToss() + + Card HumanCut = null; + Card ComputerCut = null; + + public void seeWhoPlaysFirst() { + + CardList HLibrary = new CardList(AllZone.getZone(Constant.Zone.Library, AllZone.HumanPlayer).getCards()); + HLibrary = HLibrary.filter(new CardListFilter() { + public boolean addCard(Card c) { + return !c.isLand(); + } + }); + CardList CLibrary = new CardList(AllZone.getZone(Constant.Zone.Library, AllZone.ComputerPlayer).getCards()); + CLibrary = CLibrary.filter(new CardListFilter() { + public boolean addCard(Card c) { + return !c.isLand(); + } + }); + + boolean Starter_Determined = false; + int Cut_Count = 0; + int Cut_CountMax = 20; + for(int i = 0; i < Cut_CountMax; i++) { + if(Starter_Determined == true) break; + + if(HLibrary.size() > 0) + HumanCut = HLibrary.get(MyRandom.random.nextInt(HLibrary.size())); + else { + computerStartsGame(); + JOptionPane.showMessageDialog(null, ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_MANA_COST) + "\r\n" + ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_STARTS), "", JOptionPane.INFORMATION_MESSAGE); + return; + } + + if(CLibrary.size() > 0) + ComputerCut = CLibrary.get(MyRandom.random.nextInt(CLibrary.size())); + else { + JOptionPane.showMessageDialog(null, ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_MANA_COST) + "\r\n" + ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_STARTS), "", JOptionPane.INFORMATION_MESSAGE); + return; + } + + Cut_Count = Cut_Count + 1; + AllZone.GameAction.moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.HumanPlayer),AllZone.GameAction.HumanCut); + AllZone.GameAction.moveTo(AllZone.getZone(Constant.Zone.Library, AllZone.ComputerPlayer),AllZone.GameAction.ComputerCut); + + StringBuilder sb = new StringBuilder(); + sb.append(ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_CUT) + HumanCut.getName() + " (" + HumanCut.getManaCost() + ")" + "\r\n"); + sb.append(ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_CUT) + ComputerCut.getName() + " (" + ComputerCut.getManaCost() + ")" + "\r\n"); + sb.append("\r\n" + "Number of times the deck has been cut: " + Cut_Count + "\r\n"); + if(CardUtil.getConvertedManaCost(ComputerCut.getManaCost()) > CardUtil.getConvertedManaCost(HumanCut.getManaCost())){ + computerStartsGame(); + JOptionPane.showMessageDialog(null, sb + ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_STARTS), "", JOptionPane.INFORMATION_MESSAGE); + return; + } + else if(CardUtil.getConvertedManaCost(ComputerCut.getManaCost()) < CardUtil.getConvertedManaCost(HumanCut.getManaCost())) { + JOptionPane.showMessageDialog(null, sb + ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_STARTS), "", JOptionPane.INFORMATION_MESSAGE); + return; + } + else{ + sb.append(ForgeProps.getLocalized(GAMEACTION_TEXT.EQUAL_CONVERTED_MANA) + "\r\n"); + if (i == Cut_CountMax-1) + { + sb.append(ForgeProps.getLocalized(GAMEACTION_TEXT.RESOLVE_STARTER)); + if(MyRandom.random.nextInt(2) == 1) + JOptionPane.showMessageDialog(null,sb + ForgeProps.getLocalized(GAMEACTION_TEXT.HUMAN_WIN), "", JOptionPane.INFORMATION_MESSAGE); + else { + computerStartsGame(); + JOptionPane.showMessageDialog(null,sb + ForgeProps.getLocalized(GAMEACTION_TEXT.COMPUTER_WIN), "", JOptionPane.INFORMATION_MESSAGE); + } + return; + } + else + { + sb.append(ForgeProps.getLocalized(GAMEACTION_TEXT.CUTTING_AGAIN)); + } + JOptionPane.showMessageDialog(null,sb, "", JOptionPane.INFORMATION_MESSAGE); + } + } // for-loop for multiple card cutting + + + }//seeWhoPlaysFirst() + + public void computerStartsGame() + { + AllZone.Phase.setPlayerTurn(AllZone.ComputerPlayer); + AllZone.GameInfo.setComputerStartedThisGame(true); + } + + //if Card had the type "Aura" this method would always return true, since local enchantments are always attached to something + //if Card is "Equipment", returns true if attached to something + public boolean isAttachee(Card c) { + CardList list = new CardList(AllZone.Computer_Battlefield.getCards()); + list.addAll(AllZone.Human_Battlefield.getCards()); + + for(int i = 0; i < list.size(); i++) { + CardList check = new CardList(list.getCard(i).getAttachedCards()); + if(check.contains(c)) return true; + } + + return false; + }//isAttached(Card c) + + public boolean playCard(Card c) { + // this can only be called by the Human + HashMap map = new HashMap(); + SpellAbility[] abilities = canPlaySpellAbility(c.getSpellAbility()); + ArrayList choices = new ArrayList(); + + if(c.isLand() && isCardInZone(c, AllZone.Human_Hand) && AllZone.HumanPlayer.canPlayLand()) + choices.add("Play land"); + + for(SpellAbility sa:abilities) { + // for uncastables like lotus bloom, check if manaCost is blank + sa.setActivatingPlayer(AllZone.HumanPlayer); + if(sa.canPlay() && (!sa.isSpell() || !sa.getManaCost().equals(""))) { + choices.add(sa.toString()); + map.put(sa.toString(), sa); + } + } + + String choice; + if (choices.size() == 0) + return false; + else if (choices.size() == 1) + choice = choices.get(0); + else + choice = (String) GuiUtils.getChoiceOptional("Choose", choices.toArray()); + + if (choice == null) + return false; + + if(choice.equals("Play land")){ + AllZone.HumanPlayer.playLand(c); + return true; + } + + SpellAbility ability = map.get(choice); + if(ability != null){ + playSpellAbility(ability); + return true; + } + return false; + } + + public void playCardNoCost(Card c) { + //SpellAbility[] choices = (SpellAbility[]) c.getSpells().toArray(); + ArrayList choices = c.getBasicSpells(); + SpellAbility sa; + + //TODO: add Buyback, Kicker, ... , spells here + /* + ArrayList additional = c.getAdditionalCostSpells(); + for (SpellAbility s : additional) + { + + } + */ + /* + System.out.println(choices.length); + for(int i = 0; i < choices.length; i++) + System.out.println(choices[i]); + */ + if(choices.size() == 0) return; + else if(choices.size() == 1) sa = choices.get(0); + else sa = (SpellAbility) GuiUtils.getChoiceOptional("Choose", choices.toArray()); + + if(sa == null) return; + + // Ripple causes a crash because it doesn't set the activatingPlayer in this entrance + if (sa.getActivatingPlayer() == null) + sa.setActivatingPlayer(AllZone.HumanPlayer); + playSpellAbilityForFree(sa); + } + + public void playSpellAbilityForFree(final SpellAbility sa) { + + if (sa.getPayCosts() != null){ + Target_Selection ts = new Target_Selection(sa.getTarget(), sa); + Cost_Payment payment = new Cost_Payment(sa.getPayCosts(), sa); + + SpellAbility_Requirements req = new SpellAbility_Requirements(sa, ts, payment); + req.setFree(true); + req.fillRequirements(); + } + else if(sa.getBeforePayMana() == null) { + if (sa.isSpell()){ + Card c = sa.getSourceCard(); + if (!c.isCopiedSpell()) + AllZone.GameAction.moveToStack(c); + } + boolean x = false; + if (sa.getSourceCard().getManaCost().contains("X")) + x = true; + + if (sa.isKickerAbility()) { + Command paid1 = new Command() { + private static final long serialVersionUID = -6531785460264284794L; + + public void execute() { + AllZone.Stack.add(sa); + } + }; + AllZone.InputControl.setInput(new Input_PayManaCost_Ability(sa.getAdditionalManaCost(),paid1)); + }else { + AllZone.Stack.add(sa, x); + } + } else { + sa.setManaCost("0"); // Beached As + if (sa.isKickerAbility()) { + sa.getBeforePayMana().setFree(false); + sa.setManaCost(sa.getAdditionalManaCost()); + } else { + sa.getBeforePayMana().setFree(true); + } + AllZone.InputControl.setInput(sa.getBeforePayMana()); + } + } + + int CostCutting_GetMultiMickerManaCostPaid = 0; + String CostCutting_GetMultiMickerManaCostPaid_Colored = ""; + public ManaCost getSpellCostChange(SpellAbility sa, ManaCost originalCost) { + // Beached + Card originalCard = sa.getSourceCard(); + SpellAbility spell = sa; + ManaCost manaCost = new ManaCost(originalCost.toString()); + + if(spell.isSpell() == true) { + if(originalCard.getName().equals("Avatar of Woe")){ + Player player = AllZone.Phase.getPlayerTurn(); + Player opponent = player.getOpponent(); + PlayerZone PlayerGraveyard = AllZone.getZone(Constant.Zone.Graveyard, player); + CardList PlayerCreatureList = new CardList(PlayerGraveyard.getCards()); + PlayerCreatureList = PlayerCreatureList.getType("Creature"); + PlayerZone OpponentGraveyard = AllZone.getZone(Constant.Zone.Graveyard, opponent); + CardList OpponentCreatureList = new CardList(OpponentGraveyard.getCards()); + OpponentCreatureList = OpponentCreatureList.getType("Creature"); + if((PlayerCreatureList.size() + OpponentCreatureList.size()) >= 10) { + manaCost = new ManaCost("B B"); + } // Avatar of Woe + } else if(originalCard.getName().equals("Avatar of Will")) { + Player player = AllZone.Phase.getPlayerTurn(); + Player opponent = player.getOpponent(); + PlayerZone OpponentHand = AllZone.getZone(Constant.Zone.Hand, opponent); + CardList OpponentHandList = new CardList(OpponentHand.getCards()); + if(OpponentHandList.size() == 0) { + manaCost = new ManaCost("U U"); + } // Avatar of Will + } else if(originalCard.getName().equals("Avatar of Fury")) { + Player player = AllZone.Phase.getPlayerTurn(); + Player opponent = player.getOpponent(); + PlayerZone OpponentPlay = AllZone.getZone(Constant.Zone.Battlefield, opponent); + CardList OpponentLand = new CardList(OpponentPlay.getCards()); + OpponentLand = OpponentLand.getType("Land"); + if(OpponentLand.size() >= 7) { + manaCost = new ManaCost("R R"); + } // Avatar of Fury + } else if(originalCard.getName().equals("Avatar of Might")) { + Player player = AllZone.Phase.getPlayerTurn(); + Player opponent = player.getOpponent(); + PlayerZone PlayerPlay = AllZone.getZone(Constant.Zone.Battlefield, player); + CardList PlayerCreature = new CardList(PlayerPlay.getCards()); + PlayerCreature = PlayerCreature.getType("Creature"); + PlayerZone OpponentPlay = AllZone.getZone(Constant.Zone.Battlefield, opponent); + CardList OpponentCreature = new CardList(OpponentPlay.getCards()); + OpponentCreature = OpponentCreature.getType("Creature"); + if(OpponentCreature.size() - PlayerCreature.size() >= 4) { + manaCost = new ManaCost("G G"); + } // Avatar of Might + } + } // isSpell + + // Get Cost Reduction + if(Phase.GameBegins == 1) { // Remove GameBegins from Phase and into The starting game code + CardList Cards_In_Play = new CardList(); + Cards_In_Play.addAll(AllZone.getZone(Constant.Zone.Battlefield, AllZone.HumanPlayer).getCards()); + Cards_In_Play.addAll(AllZone.getZone(Constant.Zone.Battlefield, AllZone.ComputerPlayer).getCards()); + Cards_In_Play = Cards_In_Play.filter(new CardListFilter() { + public boolean addCard(Card c) { + if(c.getKeyword().toString().contains("CostChange")) return true; + return false; + } + }); + Cards_In_Play.add(originalCard); + String Mana = manaCost.toString(); + CardList Player_Play = new CardList(AllZone.getZone(Constant.Zone.Battlefield, sa.getSourceCard().getController()).getCards()); + CardList Player_Hand = new CardList(AllZone.getZone(Constant.Zone.Hand, sa.getSourceCard().getController()).getCards()); + int XBonus = 0; + int Max = 25; + if(sa.isXCost() && !sa.getSourceCard().isCopiedSpell()) sa.getSourceCard().setXManaCostPaid(0); + if(sa.isMultiKicker()) CostCutting_GetMultiMickerManaCostPaid_Colored = ""; + if(Mana.toString().length() == 0) Mana = "0"; + for(int i = 0; i < Cards_In_Play.size() ; i++) { + Card card = Cards_In_Play.get(i); + ArrayList a = card.getKeyword(); + int CostKeywords = 0; + int CostKeyword_Number[] = new int[a.size()]; + for(int x = 0; x < a.size(); x++) + if(a.get(x).toString().startsWith("CostChange")) { + CostKeyword_Number[CostKeywords] = x; + CostKeywords = CostKeywords + 1; + } + for(int CKeywords = 0; CKeywords < CostKeywords; CKeywords++) { + String parse = card.getKeyword().get(CostKeyword_Number[CKeywords]).toString(); + String k[] = parse.split(":"); + if(card.equals(originalCard)) { + if(!k[4].equals("Self")) k[2] = "Owned"; + } + if(k[2].equals("More")) { + if(k[7].equals("OnlyOneBonus")) { // Only Works for Color and Type + for(int string_no = 5; string_no < 7; string_no++) { + String spilt = k[string_no]; + String color_spilt[] = spilt.split("/"); + + for(int cs_num = 0; cs_num < color_spilt.length; cs_num++) { + k[string_no] = color_spilt[cs_num]; + if(string_no == 5 && CardUtil.getColors(sa.getSourceCard()).contains(k[5])) break; + if(string_no == 6 && (sa.getSourceCard().isType(k[6]))) break; + } + } + } + if(k[7].contains("All Conditions")) { // Only Works for Color and Type + for(int string_no = 5; string_no < 7; string_no++) { + String spilt = k[string_no]; + String color_spilt[] = spilt.split("/"); + for(int cs_num = 0; cs_num < color_spilt.length; cs_num++) { + k[string_no] = color_spilt[cs_num]; + if(string_no == 5) { + if(CardUtil.getColors(sa.getSourceCard()).contains(k[5]) || k[5].equals("All")) { + } else { + k[5] = "Nullified"; + break; + } + } + if(string_no == 6) { + if(sa.getSourceCard().isType(k[6]) || k[6].equals("All")) { + } else { + k[6] = "Nullified"; + break; + } + } + } + } + if(!k[5].equals("Nullified")) k[5] = "All"; + if(!k[6].equals("Nullified")) k[6] = "All"; + } + if((k[1].equals("Player") && card.getController().equals(sa.getSourceCard().getController()) + || (k[1].equals("Opponent") && card.getController().equals(sa.getSourceCard().getController().getOpponent())) || k[1].equals("All")) + && ((k[4].equals("Spell") && sa.isSpell() == true) || (k[4].equals("Ability") && sa.isAbility() == true) + || (k[4].startsWith("Ability_Cycling") && sa.isCycling()) || (k[4].equals("Self") && originalCard.equals(card)) + || (k[4].equals("Enchanted") && originalCard.getEnchantedBy().contains(card)) || k[4].equals("All")) + && ((CardUtil.getColors(sa.getSourceCard()).contains(k[5])) || k[5].equals("All")) + && ((sa.getSourceCard().isType(k[6])) + || (!(sa.getSourceCard().isType(k[6])) && k[7].contains("NonType")) || k[6].equals("All"))) { + if(k[7].contains("CardIsTapped")) { + if(card.isTapped() == false) k[3] = "0"; + } + if(k[7].contains("TargetInPlay")) { + if(!Player_Play.contains(sa.getSourceCard())) k[3] = "0"; + } + if(k[7].contains("TargetInHand")) { + if(!Player_Hand.contains(sa.getSourceCard())) k[3] = "0"; + } + if(k[7].contains("NonType")) { + if(originalCard.isType(k[6])) k[3] = "0"; + } + if(k[7].contains("OpponentTurn")) { + if(AllZone.Phase.isPlayerTurn(originalCard.getController())) k[3] = "0"; + } + if(k[7].contains("Affinity")) { + String spilt = k[7]; + String color_spilt[] = spilt.split("/"); + k[7] = color_spilt[1]; + PlayerZone PlayerPlay = AllZone.getZone(Constant.Zone.Battlefield, originalCard.getController()); + CardList PlayerList = new CardList(PlayerPlay.getCards()); + PlayerList = PlayerList.getType(k[7]); + k[3] = String.valueOf(PlayerList.size()); + } + String[] Numbers = new String[Max]; + if("X".equals(k[3])) { + for(int no = 0; no < Max; no ++) Numbers[no] = String.valueOf(no); + String Number_ManaCost = " "; + if(Mana.toString().length() == 1) { + Number_ManaCost = Mana.toString().substring(0, 1); + } + else if(Mana.toString().length() == 0) { + Number_ManaCost = "0"; // Should Never Occur + } + else { + Number_ManaCost = Mana.toString().substring(0, 2); + } + Number_ManaCost = Number_ManaCost.trim(); + for(int check = 0; check < Max; check ++) { + if(Number_ManaCost.equals(Numbers[check])) { + int xValue = CardFactoryUtil.xCount(originalCard, originalCard.getSVar("X")); + //if((spell.isXCost()) || (spell.isMultiKicker()) && (check - Integer.valueOf(k[3])) < 0) XBonus = XBonus - check + Integer.valueOf(k[3]); + Mana = Mana.replaceFirst(String.valueOf(check),String.valueOf(check + xValue)); + } + if(Mana.equals("")) Mana = "0"; + manaCost = new ManaCost(Mana); + } + } + else if(!"WUGRB".contains(k[3])) { + for(int no = 0; no < Max; no ++) Numbers[no] = String.valueOf(no); + String Number_ManaCost = " "; + if(Mana.toString().length() == 1) Number_ManaCost = Mana.toString().substring(0, 1); + else if(Mana.toString().length() == 0) Number_ManaCost = "0"; // Should Never Occur + else Number_ManaCost = Mana.toString().substring(0, 2); + Number_ManaCost = Number_ManaCost.trim(); + + for(int check = 0; check < Max; check ++) { + if(Number_ManaCost.equals(Numbers[check])) { + Mana = Mana.replaceFirst(String.valueOf(check),String.valueOf(check + Integer.valueOf(k[3]))); + } + if(Mana.equals("")) Mana = "0"; + manaCost = new ManaCost(Mana); + } + if(!manaCost.toString().contains("0") && !manaCost.toString().contains("1") && !manaCost.toString().contains("2") + && !manaCost.toString().contains("3") && !manaCost.toString().contains("4") && !manaCost.toString().contains("5") + && !manaCost.toString().contains("6") && !manaCost.toString().contains("7") && !manaCost.toString().contains("8") + && !manaCost.toString().contains("9")) { + Mana = k[3] + " " + Mana; + manaCost = new ManaCost(Mana); + } + } else { + Mana = Mana + " " + k[3]; + manaCost = new ManaCost(Mana); + } + } + } + } + } + + if(Mana.equals("0") && spell.isAbility()) { + } else { + for(int i = 0; i < Cards_In_Play.size() ; i++) { + Card card = Cards_In_Play.get(i); + ArrayList a = card.getKeyword(); + int CostKeywords = 0; + int CostKeyword_Number[] = new int[a.size()]; + for(int x = 0; x < a.size(); x++) + if(a.get(x).toString().startsWith("CostChange")) { + CostKeyword_Number[CostKeywords] = x; + CostKeywords = CostKeywords + 1; + } + for(int CKeywords = 0; CKeywords < CostKeywords; CKeywords++) { + String parse = card.getKeyword().get(CostKeyword_Number[CKeywords]).toString(); + String k[] = parse.split(":"); + if(card.equals(originalCard)) { + if(!k[4].equals("Self")) k[2] = "Owned"; + } + if(k[2].equals("Less")) { + if(k[7].equals("OnlyOneBonus")) { // Only Works for Color and Type + for(int string_no = 5; string_no < 7; string_no++) { + String spilt = k[string_no]; + String color_spilt[] = spilt.split("/"); + + for(int cs_num = 0; cs_num < color_spilt.length; cs_num++) { + k[string_no] = color_spilt[cs_num]; + if(string_no == 5 && CardUtil.getColors(sa.getSourceCard()).contains(k[5])) break; + if(string_no == 6 && (sa.getSourceCard().isType(k[6]))) break; + } + } + } + if(k[7].contains("All Conditions")) { // Only Works for Color and Type + for(int string_no = 5; string_no < 7; string_no++) { + String spilt = k[string_no]; + String color_spilt[] = spilt.split("/"); + for(int cs_num = 0; cs_num < color_spilt.length; cs_num++) { + k[string_no] = color_spilt[cs_num]; + if(string_no == 5) { + if(CardUtil.getColors(sa.getSourceCard()).contains(k[5]) || k[5].equals("All")) { + } else { + k[5] = "Nullified"; + break; + } + } + if(string_no == 6) { + if(sa.getSourceCard().isType(k[6]) || k[6].equals("All")) { + } else { + k[6] = "Nullified"; + break; + } + } + } + } + if(!k[5].equals("Nullified")) k[5] = "All"; + if(!k[6].equals("Nullified")) k[6] = "All"; + } + if((k[1].equals("Player") && card.getController().equals(sa.getSourceCard().getController()) + || (k[1].equals("Opponent") && card.getController().equals(sa.getSourceCard().getController().getOpponent())) || k[1].equals("All")) + && ((k[4].equals("Spell") && sa.isSpell() == true) || (k[4].equals("Ability") && sa.isAbility() == true) + || (k[4].startsWith("Ability_Cycling") && sa.isCycling()) || (k[4].equals("Self") && originalCard.equals(card)) + || (k[4].equals("Enchanted") && originalCard.getEnchantedBy().contains(card)) || k[4].equals("All")) + && ((CardUtil.getColors(sa.getSourceCard()).contains(k[5])) || k[5].equals("All")) + /** + * Chris added a test for Changeling. + * This appears to reduce the cost correctly. + * Works for both the computer and the human. + */ + && ((sa.getSourceCard().isType(k[6])) + + || (!(sa.getSourceCard().isType(k[6])) && k[7].contains("NonType")) || k[6].equals("All"))) { + if(k[7].contains("CardIsTapped")) { + if(card.isTapped() == false) k[3] = "0"; + } + if(k[7].contains("TargetInPlay")) { + if(!Player_Play.contains(sa.getSourceCard())) k[3] = "0"; + } + if(k[7].contains("TargetInHand")) { + if(!Player_Hand.contains(sa.getSourceCard())) k[3] = "0"; + } + if(k[7].contains("NonType")) { + if(originalCard.isType(k[6])) k[3] = "0"; + } + if(k[7].contains("OpponentTurn")) { + if(AllZone.Phase.isPlayerTurn(originalCard.getController())) k[3] = "0"; + } + if(k[7].contains("Affinity")) { + String spilt = k[7]; + String color_spilt[] = spilt.split("/"); + k[7] = color_spilt[1]; + PlayerZone PlayerPlay = AllZone.getZone(Constant.Zone.Battlefield, originalCard.getController()); + CardList PlayerList = new CardList(PlayerPlay.getCards()); + PlayerList = PlayerList.getType(k[7]); + k[3] = String.valueOf(PlayerList.size()); + } + + String[] Numbers = new String[Max]; + if("X".equals(k[3])) { + for(int no = 0; no < Max; no ++) Numbers[no] = String.valueOf(no); + String Number_ManaCost = " "; + if(Mana.toString().length() == 1) { + Number_ManaCost = Mana.toString().substring(0, 1); + } + else if(Mana.toString().length() == 0) { + Number_ManaCost = "0"; // Should Never Occur + } + else { + Number_ManaCost = Mana.toString().substring(0, 2); + } + Number_ManaCost = Number_ManaCost.trim(); + for(int check = 0; check < Max; check ++) { + if(Number_ManaCost.equals(Numbers[check])) { + int xValue = CardFactoryUtil.xCount(originalCard, originalCard.getSVar("X")); + //if((spell.isXCost()) || (spell.isMultiKicker()) && (check - Integer.valueOf(k[3])) < 0) XBonus = XBonus - check + Integer.valueOf(k[3]); + Mana = Mana.replaceFirst(String.valueOf(check),String.valueOf(check - xValue)); + } + if(Mana.equals("")) Mana = "0"; + manaCost = new ManaCost(Mana); + } + } + else if(!"WUGRB".contains(k[3])) { + for(int no = 0; no < Max; no ++) Numbers[no] = String.valueOf(no); + String Number_ManaCost = " "; + if(Mana.toString().length() == 1) Number_ManaCost = Mana.toString().substring(0, 1); + else if(Mana.toString().length() == 0) Number_ManaCost = "0"; // Should Never Occur + else Number_ManaCost = Mana.toString().substring(0, 2); + Number_ManaCost = Number_ManaCost.trim(); + + for(int check = 0; check < Max; check ++) { + if(Number_ManaCost.equals(Numbers[check])) { + if((spell.isXCost()) || (spell.isMultiKicker()) && (check - Integer.valueOf(k[3])) < 0) XBonus = XBonus - check + Integer.valueOf(k[3]); + if(check - Integer.valueOf(k[3]) < 0) k[3] = String.valueOf(check); + Mana = Mana.replaceFirst(String.valueOf(check),String.valueOf(check - Integer.valueOf(k[3]))); + } + if(Mana.equals("")) Mana = "0"; + manaCost = new ManaCost(Mana); + } + } else { + // JOptionPane.showMessageDialog(null, Mana + " " + Mana.replaceFirst(k[3],""), "", JOptionPane.INFORMATION_MESSAGE); + if(Mana.equals(Mana.replaceFirst(k[3], ""))) { + // if(sa.isXCost()) sa.getSourceCard().addXManaCostPaid(1); Not Included as X Costs are not in Colored Mana + if(sa.isMultiKicker()) CostCutting_GetMultiMickerManaCostPaid_Colored = CostCutting_GetMultiMickerManaCostPaid_Colored + k[3]; + // JOptionPane.showMessageDialog(null, CostCutting_GetMultiMickerManaCostPaid_Colored, "", JOptionPane.INFORMATION_MESSAGE); + } else { + Mana = Mana.replaceFirst(k[3], ""); + Mana = Mana.trim(); + if(Mana.equals("")) Mana = "0"; + manaCost = new ManaCost(Mana); + } + } + } + Mana = Mana.trim(); + if(Mana.length() == 0 || Mana.equals("0")) { + if(sa.isSpell() || sa.isCycling()) Mana = "0"; + else { + Mana = "1"; + } + } + } + manaCost = new ManaCost(Mana); + } + } + } + if(sa.isXCost()) { + + for(int XPaid = 0; XPaid < XBonus; XPaid++) sa.getSourceCard().addXManaCostPaid(1); + } + if(sa.isMultiKicker()) { + CostCutting_GetMultiMickerManaCostPaid = 0; + for(int XPaid = 0; XPaid < XBonus; XPaid++) CostCutting_GetMultiMickerManaCostPaid = CostCutting_GetMultiMickerManaCostPaid + 1; + } + } + if(originalCard.getName().equals("Khalni Hydra") && spell.isSpell() == true) { + Player player = AllZone.Phase.getPlayerTurn(); + PlayerZone PlayerPlay = AllZone.getZone(Constant.Zone.Battlefield, player); + CardList PlayerCreature = new CardList(PlayerPlay.getCards()); + PlayerCreature = PlayerCreature.getType("Creature"); + PlayerCreature = PlayerCreature.filter(new CardListFilter() { + public boolean addCard(Card c) { + return c.isCreature() && c.isGreen(); + } + }); + String Mana = manaCost + " "; + if(PlayerCreature.size() > 0) { + for(int i = 0; i < PlayerCreature.size(); i++) { + Mana = Mana.replaceFirst("G ", ""); + } + Mana = Mana.trim(); + if(Mana.equals("")) Mana = "0"; + manaCost = new ManaCost(Mana); + } + } // Khalni Hydra + return manaCost; + }//GetSpellCostChange + + public void playSpellAbility(SpellAbility sa) { + sa.setActivatingPlayer(AllZone.HumanPlayer); + + if (sa.getPayCosts() != null || sa.getTarget() != null){ + Target_Selection ts = new Target_Selection(sa.getTarget(), sa); + Cost_Payment payment = null; + if(sa.getPayCosts() == null) + { + payment = new Cost_Payment(new Ability_Cost("0",sa.getSourceCard().getName(),sa.isAbility()), sa); + } + else + { + payment = new Cost_Payment(sa.getPayCosts(),sa); + } + + payment.changeCost(); + + SpellAbility_Requirements req = new SpellAbility_Requirements(sa, ts, payment); + req.fillRequirements(); + } + else{ + ManaCost manaCost = new ManaCost(sa.getManaCost()); + if(sa.getSourceCard().isCopiedSpell() && sa.isSpell()) { + manaCost = new ManaCost("0"); + } else { + + manaCost = getSpellCostChange(sa, new ManaCost(sa.getManaCost())); + } + if(manaCost.isPaid() && sa.getBeforePayMana() == null) { + if (sa.getAfterPayMana() == null){ + Card source = sa.getSourceCard(); + if(sa.isSpell() && !source.isCopiedSpell()) + AllZone.GameAction.moveToStack(source); + + AllZone.Stack.add(sa); + if(sa.isTapAbility() && !sa.wasCancelled()) sa.getSourceCard().tap(); + if(sa.isUntapAbility()) sa.getSourceCard().untap(); + return; + } + else + AllZone.InputControl.setInput(sa.getAfterPayMana()); + } + else if(sa.getBeforePayMana() == null) + AllZone.InputControl.setInput(new Input_PayManaCost(sa)); + else + AllZone.InputControl.setInput(sa.getBeforePayMana()); + } + } + + public void playSpellAbility_NoStack(SpellAbility sa,boolean skipTargeting) { + sa.setActivatingPlayer(AllZone.HumanPlayer); + + if (sa.getPayCosts() != null){ + Target_Selection ts = new Target_Selection(sa.getTarget(),sa); + Cost_Payment payment = new Cost_Payment(sa.getPayCosts(), sa); + + payment.changeCost(); + + SpellAbility_Requirements req = new SpellAbility_Requirements(sa, ts, payment); + req.setSkipStack(true); + req.fillRequirements(skipTargeting); + } + else{ + ManaCost manaCost = new ManaCost(sa.getManaCost()); + if(sa.getSourceCard().isCopiedSpell() && sa.isSpell()) { + manaCost = new ManaCost("0"); + } else { + + manaCost = getSpellCostChange(sa, new ManaCost(sa.getManaCost())); + } + if(manaCost.isPaid() && sa.getBeforePayMana() == null) { + if (sa.getAfterPayMana() == null){ + sa.resolve(); + if(sa.isTapAbility() && !sa.wasCancelled()) sa.getSourceCard().tap(); + if(sa.isUntapAbility()) sa.getSourceCard().untap(); + return; + } + else + AllZone.InputControl.setInput(sa.getAfterPayMana()); + } + else if(sa.getBeforePayMana() == null) + AllZone.InputControl.setInput(new Input_PayManaCost(sa,true)); + else + AllZone.InputControl.setInput(sa.getBeforePayMana()); + } + } + + public SpellAbility[] canPlaySpellAbility(SpellAbility[] sa) { + ArrayList list = new ArrayList(); + + for(int i = 0; i < sa.length; i++){ + sa[i].setActivatingPlayer(AllZone.HumanPlayer); + if(sa[i].canPlay()) + list.add(sa[i]); + } + + SpellAbility[] array = new SpellAbility[list.size()]; + list.toArray(array); + return array; + }//canPlaySpellAbility() + + public void skullClamp_destroy(Card c) { + CardList equipment = new CardList(); + equipment.addAll(c.getEquippedBy().toArray()); + equipment = equipment.getName("Skullclamp"); + + if(equipment.size() == 0) return; + + final Card crd = c; + for(int i = 0; i < equipment.size(); i++) { + final Card skullclamp = equipment.get(i); + final Ability draw = new Ability(crd, "0") { + @Override + public void resolve() { + Player player = skullclamp.getController(); + player.drawCards(2); + } + };//Ability + + StringBuilder sb = new StringBuilder(); + sb.append("Skullclamp - ").append(skullclamp.getController()); + sb.append(" draws 2 cards (").append(c.getName()).append(")."); + draw.setStackDescription(sb.toString()); + + AllZone.Stack.add(draw); + } + } + + public void searchLibraryBasicLand(Player player, String Zone1, boolean tapLand) { + searchLibraryTwoLand("Basic", player, Zone1, tapLand, "", false); + } + + public void searchLibraryTwoLand(String type, Player player, + String Zone1, boolean tapFirstLand, + String Zone2, boolean tapSecondLand) { + if(player.equals(AllZone.HumanPlayer)) { + humanSearchTwoLand(type, Zone1, tapFirstLand, Zone2, tapSecondLand); + } else { + aiSearchTwoLand(type, Zone1, tapFirstLand, Zone2, tapSecondLand); + } + + player.shuffle(); + + } + public void searchLibraryTwoBasicLand(Player player, + String Zone1, boolean tapFirstLand, + String Zone2, boolean tapSecondLand) { + searchLibraryTwoLand("Basic", player, Zone1, tapFirstLand, Zone2, tapSecondLand); + } + + private void aiSearchTwoLand(String type, String Zone1, boolean tapFirstLand, + String Zone2, boolean tapSecondLand) { + CardList land = new CardList(AllZone.Computer_Library.getCards()); + land = land.getType(type); + PlayerZone firstZone = AllZone.getZone(Zone1, AllZone.ComputerPlayer); + + if (type.contains("Basic")) { + // No need for special sorting for basic land + // just shuffle to make the computer a little less predictable + land.shuffle(); + } else { + Comparator aiLandComparator = new Comparator() + { + private int scoreLand(Card a) { + String valakutName = "Valakut, the Molten Pinnacle"; + + int theScore = 0; + if (!a.isBasicLand()) { + // favor non-basic land + theScore++; + if (a.getName().contains(valakutName)) { + // TODO: Add names of other special lands + theScore++; + } + } + return theScore; + } + public int compare(Card a, Card b) + { + int aScore = scoreLand(a); + int bScore = scoreLand(b); + return bScore - aScore; + } // compare + };//Comparator + + // Prioritize the land somewhat + land.sort(aiLandComparator); + } + //3 branches: 1-no land in deck, 2-one land in deck, 3-two or more land in deck + if(land.size() != 0) { + //branch 2 - at least 1 land in library + Card firstLand = land.remove(0); + if (tapFirstLand) + firstLand.tap(); + + AllZone.GameAction.moveTo(firstZone, firstLand); + + //branch 3 + if(Zone2.trim().length() != 0 && (land.size() != 0)) { + PlayerZone secondZone = AllZone.getZone(Zone2, AllZone.ComputerPlayer); + Card secondLand = land.remove(0); + if (tapSecondLand) + secondLand.tap(); + AllZone.GameAction.moveTo(secondZone, secondLand); + } + } + } + + private void humanSearchTwoLand(String type, String Zone1, boolean tapFirstLand, String Zone2, boolean tapSecondLand) { + PlayerZone firstZone = AllZone.getZone(Zone1, AllZone.HumanPlayer); + PlayerZone library = AllZone.getZone(Constant.Zone.Library, AllZone.HumanPlayer); + + CardList list = new CardList(library.getCards()); + list = list.getType(type); + + //3 branches: 1-no land in deck, 2-one land in deck, 3-two or more land in deck + + //branch 1 + if(list.size() == 0) return; + + // Check whether we were only asked for one land, and adjust the prompt accordingly + boolean onlyOneLand = (Zone2.trim().length() == 0); + String firstPrompt; + if (onlyOneLand) + firstPrompt = "Choose a land"; + else + firstPrompt = "Choose first land"; + + //branch 2 + Object o = GuiUtils.getChoiceOptional(firstPrompt, list.toArray()); + if(o != null) { + Card c = (Card) o; + list.remove(c); + if (tapFirstLand) + c.tap(); + moveTo(firstZone, c); + }//if + if ((list.size() == 0) || onlyOneLand) return; + //branch 3 + o = GuiUtils.getChoiceOptional(ForgeProps.getLocalized(GAMEACTION_TEXT.CHOOSE_2ND_LAND), list.toArray()); + if(o != null) { + PlayerZone secondZone = AllZone.getZone(Zone2, AllZone.HumanPlayer); + + Card c = (Card) o; + list.remove(c); + if (tapSecondLand) + c.tap(); + moveTo(secondZone, c); + } + } + + public void proliferate(final Card c, String cost) + { + Ability p = getProliferateAbility(c, cost); + AllZone.Stack.add(p); + } + + public Ability getProliferateAbility(final Card c, final String cost) + { + final Ability ability = new Ability(c, cost) + { + public void resolve() + { + CardList hperms = AllZoneUtil.getPlayerCardsInPlay(AllZone.HumanPlayer); + hperms = hperms.filter(new CardListFilter(){ + public boolean addCard(Card crd) + { + return !crd.getName().equals("Mana Pool") /*&& crd.hasCounters()*/; + } + }); + + CardList cperms = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer); + cperms = cperms.filter(new CardListFilter(){ + public boolean addCard(Card crd) + { + return !crd.getName().equals("Mana Pool") /*&& crd.hasCounters()*/; + } + }); + + if (c.getController().equals(AllZone.HumanPlayer)) + { + cperms.addAll(hperms.toArray()); + final CardList unchosen = cperms; + AllZone.InputControl.setInput(new Input() { + private static final long serialVersionUID = -1779224307654698954L; + + @Override + public void showMessage() { + AllZone.Display.showMessage("Choose permanents and/or players"); + ButtonUtil.enableOnlyOK(); + } + + @Override + public void selectButtonOK() { + stop(); + } + + @Override + public void selectCard(Card card, PlayerZone zone) + { + if(!unchosen.contains(card)) return; + unchosen.remove(card); + ArrayList choices = new ArrayList(); + for(Counters c_1:Counters.values()) + if(card.getCounters(c_1) != 0) choices.add(c_1.getName()); + if (choices.size() > 0) + card.addCounter(Counters.getType((choices.size() == 1 ? choices.get(0) : GuiUtils.getChoice("Select counter type", choices.toArray()).toString())), 1); + } + boolean selComputer = false; + boolean selHuman = false; + @Override + public void selectPlayer(Player player){ + if (player.equals(AllZone.HumanPlayer) && selHuman == false) + { + selHuman = true; + if (AllZone.HumanPlayer.getPoisonCounters() > 0) + AllZone.HumanPlayer.addPoisonCounters(1); + } + if (player.equals(AllZone.ComputerPlayer) && selComputer == false) + { + selComputer = true; + if (AllZone.ComputerPlayer.getPoisonCounters() > 0) + AllZone.ComputerPlayer.addPoisonCounters(1); + } + } + }); + } + else //comp + { + cperms = cperms.filter(new CardListFilter(){ + public boolean addCard(Card crd) + { + int pos = 0; + int neg = 0; + for(Counters c_1:Counters.values()) { + if(crd.getCounters(c_1) != 0) + { + if (CardFactoryUtil.isNegativeCounter(c_1)) + neg++; + else + pos++; + } + } + return pos > neg; + } + }); + + hperms = hperms.filter(new CardListFilter(){ + public boolean addCard(Card crd) + { + int pos = 0; + int neg = 0; + for(Counters c_1:Counters.values()) { + if(crd.getCounters(c_1) != 0) + { + if (CardFactoryUtil.isNegativeCounter(c_1)) + neg++; + else + pos++; + } + } + return pos < neg; + } + }); + + StringBuilder sb = new StringBuilder(); + sb.append("Proliferate:
Computer selects "); + if (cperms.size() == 0 && hperms.size() == 0 && AllZone.HumanPlayer.getPoisonCounters() == 0) + sb.append("nothing."); + else + { + if (cperms.size()>0) { + sb.append("
From Computer's permanents:
"); + for (Card c:cperms) + { + sb.append(c); + sb.append(" "); + } + sb.append("
"); + } + if (hperms.size()>0) { + sb.append("
From Human's permanents:
"); + for (Card c:cperms) + { + sb.append(c); + sb.append(" "); + } + sb.append("
"); + } + if (AllZone.HumanPlayer.getPoisonCounters() > 0) + sb.append("Human Player."); + }//else + sb.append(""); + + + //add a counter for each counter type, if it would benefit the computer + for (Card c:cperms) + { + for(Counters c_1:Counters.values()) + if(c.getCounters(c_1) != 0) c.addCounter(c_1, 1); + } + + //add a counter for each counter type, if it would screw over the player + for (Card c:hperms) + { + for(Counters c_1:Counters.values()) + if(c.getCounters(c_1) != 0) c.addCounter(c_1, 1); + } + + //give human a poison counter, if he has one + if (AllZone.HumanPlayer.getPoisonCounters() > 0) + AllZone.HumanPlayer.addPoisonCounters(1); + + } //comp + } + }; + + StringBuilder sb = new StringBuilder(); + sb.append(c).append(" - Proliferate (You choose any number of permanents and/or players with "); + sb.append("counters on them, then give each another counter of a kind already there.)"); + ability.setStackDescription(sb.toString()); + + return ability; + } + + public static void main(String[] args) { + GameAction gameAction = new GameAction(); + GenerateConstructedDeck gen = new GenerateConstructedDeck(); + + for(int i = 0; i < 2000; i++) { + CardList list = gen.generateDeck(); + + Card[] card = gameAction.smoothComputerManaCurve(list.toArray()); + + CardList check = new CardList(); + for(int a = 0; a < 30; a++) + check.add(card[a]); + + if(check.getType("Land").size() != 7) { + System.out.println("error - " + check); + break; + } + }//for + } +} diff --git a/src/forge/GuiDisplay2.java b/src/forge/GuiDisplay2.java index 61b9b8a1455..c8c7dd1a6dc 100644 --- a/src/forge/GuiDisplay2.java +++ b/src/forge/GuiDisplay2.java @@ -2,24 +2,6 @@ package forge; -import java.awt.BorderLayout; -import java.awt.Frame; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; -import java.util.Observable; -import java.util.Observer; - -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JSeparator; - import forge.gui.GuiUtils; import forge.gui.game.CardDetailPanel; import forge.gui.game.CardPanel; @@ -27,6 +9,13 @@ import forge.gui.game.CardPicturePanel; import forge.properties.ForgeProps; import forge.properties.NewConstants; +import javax.swing.*; +import java.awt.BorderLayout; +import java.awt.Frame; +import java.awt.event.*; +import java.util.Observable; +import java.util.Observer; + public class GuiDisplay2 extends javax.swing.JFrame implements CardContainer, Display, NewConstants { private static final long serialVersionUID = 8974795337536720207L; @@ -109,7 +98,7 @@ public class GuiDisplay2 extends javax.swing.JFrame implements CardContainer, Di concedeGame.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { dispose(); - Constant.Runtime.WinLose.addLose(); + Constant.Runtime.matchState.addLose(); new Gui_WinLose(); } }); @@ -796,7 +785,7 @@ public class GuiDisplay2 extends javax.swing.JFrame implements CardContainer, Di private void exitForm(java.awt.event.WindowEvent evt)//GEN-FIRST:event_exitForm { dispose(); - Constant.Runtime.WinLose.addLose(); + Constant.Runtime.matchState.addLose(); new Gui_WinLose(); }//GEN-LAST:event_exitForm diff --git a/src/forge/GuiDisplay3.java b/src/forge/GuiDisplay3.java index 02599d67f39..62d18ac41f9 100644 --- a/src/forge/GuiDisplay3.java +++ b/src/forge/GuiDisplay3.java @@ -1,1363 +1,1324 @@ - -package forge; - - -import static org.jdesktop.swingx.MultiSplitLayout.parseModel; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.Frame; -import java.awt.GridLayout; -import java.awt.Insets; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.beans.XMLDecoder; -import java.beans.XMLEncoder; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Observable; -import java.util.Observer; - -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSeparator; -import javax.swing.JTextArea; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; -import javax.swing.border.Border; -import javax.swing.border.EmptyBorder; -import javax.swing.border.EtchedBorder; -import javax.swing.border.TitledBorder; - -import org.jdesktop.swingx.JXMultiSplitPane; -import org.jdesktop.swingx.MultiSplitLayout.Node; - -import forge.error.ErrorViewer; -import forge.gui.ForgeAction; -import forge.gui.GuiUtils; -import forge.gui.game.CardDetailPanel; -import forge.gui.game.CardPanel; -import forge.gui.game.CardPicturePanel; -import forge.properties.ForgePreferences; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - -public class GuiDisplay3 extends JFrame implements CardContainer, Display, NewConstants, NewConstants.GUI.GuiDisplay, NewConstants.LANG.GuiDisplay { - private static final long serialVersionUID = 4519302185194841060L; - - private GuiInput inputControl; - - Font statFont = new Font("Dialog", Font.PLAIN, 12); - Font lifeFont = new Font("Dialog", Font.PLAIN, 40); - Font checkboxFont = new Font("Dialog", Font.PLAIN, 9); - - - public static Color greenColor = new Color(0, 164, 0); - - private Action HUMAN_GRAVEYARD_ACTION; - private Action HUMAN_REMOVED_ACTION; - private Action HUMAN_FLASHBACK_ACTION; - private Action COMPUTER_GRAVEYARD_ACTION; - private Action COMPUTER_REMOVED_ACTION; - private Action CONCEDE_ACTION; - public Card cCardHQ; - - //private CardList multiBlockers = new CardList(); - - public GuiDisplay3() { - AllZone.Display = this; - setupActions(); - initComponents(); - - addObservers(); - addListeners(); - addMenu(); - inputControl = new GuiInput(); - } - - @Override - public void setVisible(boolean visible) { - if(visible) { - //causes an error if put in the constructor, causes some random null pointer exception - AllZone.InputControl.updateObservers(); - - //Use both so that when "un"maximizing, the frame isn't tiny - setSize(1024, 740); - System.out.println(getExtendedState()); - setExtendedState(Frame.MAXIMIZED_BOTH); - System.out.println(getExtendedState()); - } - super.setVisible(visible); - } - - public void assignDamage(Card attacker, CardList blockers, int damage) { - if (damage == 0) - return; - new Gui_MultipleBlockers3(attacker, blockers, damage, this); - } - - /* - public void addAssignDamage(Card attacker, Card blocker, int damage) - { - multiBlockers.add(blocker); - } - - public void addAssignDamage(Card attacker, int damage) { - //new Gui_MultipleBlockers3(attacker, blockers, damage, this); - new Gui_MultipleBlockers3(attacker, multiBlockers, damage, this); - } - */ - - private void setupActions() { - HUMAN_GRAVEYARD_ACTION = new ZoneAction(AllZone.Human_Graveyard, HUMAN_GRAVEYARD); - HUMAN_REMOVED_ACTION = new ZoneAction(AllZone.Human_Exile, HUMAN_REMOVED); - HUMAN_FLASHBACK_ACTION = new ZoneAction(AllZone.Human_Exile, HUMAN_FLASHBACK) { - - private static final long serialVersionUID = 8120331222693706164L; - - @Override - protected Card[] getCards() { - return CardFactoryUtil.getGraveyardActivationCards(AllZone.HumanPlayer).toArray(); - } - - @Override - protected void doAction(Card c) { - if(!c.isLand()) - { - SpellAbility[] sa = c.getSpellAbility(); - sa[1].setActivatingPlayer(AllZone.HumanPlayer); - if(sa[1].canPlay() && !c.isUnCastable()) AllZone.GameAction.playSpellAbility(sa[1]); - } - else // PlayLand checks if the land can be played - AllZone.HumanPlayer.playLand(c); - } - }; - COMPUTER_GRAVEYARD_ACTION = new ZoneAction(AllZone.Computer_Graveyard, COMPUTER_GRAVEYARD); - COMPUTER_REMOVED_ACTION = new ZoneAction(AllZone.Computer_Exile, COMPUTER_REMOVED); - CONCEDE_ACTION = new ConcedeAction(); - } - - private void addMenu() { - Object[] obj = { - HUMAN_GRAVEYARD_ACTION, HUMAN_REMOVED_ACTION, HUMAN_FLASHBACK_ACTION, COMPUTER_GRAVEYARD_ACTION, - COMPUTER_REMOVED_ACTION, new JSeparator(), - playsoundCheckboxForMenu, new JSeparator(), ErrorViewer.ALL_THREADS_ACTION, - CONCEDE_ACTION}; - - JMenu gameMenu = new JMenu(ForgeProps.getLocalized(MENU_BAR.MENU.TITLE)); - for(Object o:obj) { - if(o instanceof ForgeAction) gameMenu.add(((ForgeAction) o).setupButton(new JMenuItem())); - else if(o instanceof Action) gameMenu.add((Action) o); - else if(o instanceof Component) gameMenu.add((Component) o); - else throw new AssertionError(); - } - - JMenu gamePhases = new JMenu(ForgeProps.getLocalized(MENU_BAR.PHASE.TITLE)); - - JMenuItem aiLabel = new JMenuItem("Computer"); - JMenuItem humanLabel = new JMenuItem("Human"); - - Component[] objPhases = { aiLabel, cbAIUpkeep, cbAIDraw, cbAIBeginCombat, - cbAIEndCombat, cbAIEndOfTurn, new JSeparator(), - humanLabel, cbHumanUpkeep, cbHumanDraw, cbHumanBeginCombat, - cbHumanEndCombat, cbHumanEndOfTurn }; - - for(Component cmp:objPhases) { - gamePhases.add(cmp); - } - - // Dev Mode Creation - JMenu devMenu = new JMenu(ForgeProps.getLocalized(MENU_BAR.DEV.TITLE)); - - devMenu.setEnabled(Constant.Runtime.DevMode[0]); - - if (Constant.Runtime.DevMode[0]){ - canLoseByDecking.setSelected(Constant.Runtime.Mill[0]); - - Action viewAIHand = new ZoneAction(AllZone.Computer_Hand, COMPUTER_HAND.BASE); - Action viewAILibrary = new ZoneAction(AllZone.Computer_Library, COMPUTER_LIBRARY.BASE); - Action viewHumanLibrary = new ZoneAction(AllZone.Human_Library, HUMAN_LIBRARY.BASE); - ForgeAction generateMana = new ForgeAction(MANAGEN) { - private static final long serialVersionUID = 7171104690016706405L; - - public void actionPerformed(ActionEvent arg0) { - GuiDisplayUtil.devModeGenerateMana(); - } - }; - - Object[] objDev = { GuiDisplay4.canLoseByDecking, viewAIHand, viewAILibrary, viewHumanLibrary, generateMana }; - for(Object o:objDev) { - if(o instanceof ForgeAction) - devMenu.add(((ForgeAction) o).setupButton(new JMenuItem())); - else if (o instanceof Component) - devMenu.add((Component)o); - else if (o instanceof Action) - devMenu.add((Action)o); - } - } - - JMenuBar menuBar = new JMenuBar(); - menuBar.add(gameMenu); - menuBar.add(gamePhases); - menuBar.add(devMenu); - menuBar.add(new MenuItem_HowToPlay()); - this.setJMenuBar(menuBar); - }//addMenu() - - public MyButton getButtonOK() { - MyButton ok = new MyButton() { - public void select() { - inputControl.selectButtonOK(); - } - - public boolean isSelectable() { - return okButton.isEnabled(); - } - - public void setSelectable(boolean b) { - okButton.setEnabled(b); - } - - public String getText() { - return okButton.getText(); - } - - public void setText(String text) { - okButton.setText(text); - } - - public void reset() { - okButton.setText("OK"); - } - }; - - return ok; - }//getButtonOK() - - public MyButton getButtonCancel() { - MyButton cancel = new MyButton() { - public void select() { - inputControl.selectButtonCancel(); - } - - public boolean isSelectable() { - return cancelButton.isEnabled(); - } - - public void setSelectable(boolean b) { - cancelButton.setEnabled(b); - } - - public String getText() { - return cancelButton.getText(); - } - - public void setText(String text) { - cancelButton.setText(text); - } - - public void reset() { - cancelButton.setText("Cancel"); - } - }; - return cancel; - }//getButtonCancel() - - public void showCombat(String message) { - combatArea.setText(message); - } - - public void showMessage(String s) { - messageArea.setText(s); - - messageArea.setText(s); - Border border = new EmptyBorder(1, 1, 1, 1); - - messageArea.setBorder(border); - - int thickness = 3; - - if (s.contains("Main")) - border = BorderFactory.createLineBorder(new Color(30, 0, 255), thickness); - else if (s.contains("To Block")) - border = BorderFactory.createLineBorder(new Color(13, 179, 0), thickness); - else if (s.contains("Play Instants and Abilities") || s.contains("Combat") || s.contains("Damage")) - border = BorderFactory.createLineBorder(new Color(255, 174, 0), thickness); - else if (s.contains("Declare Attackers")) - border = BorderFactory.createLineBorder(new Color(255, 0, 0), thickness); - else if (s.contains("Upkeep") || s.contains("Draw") || s.contains("End of Turn")) - border = BorderFactory.createLineBorder(new Color(200, 0, 170), thickness); - - messageArea.setBorder(border); - } - - private void addListeners() { - //mouse Card Detail - playerHandPanel.addMouseMotionListener(GuiDisplayUtil.getCardDetailMouse(this)); - playerLandPanel.addMouseMotionListener(GuiDisplayUtil.getCardDetailMouse(this)); - playerCreaturePanel.addMouseMotionListener(GuiDisplayUtil.getCardDetailMouse(this)); - - oppLandPanel.addMouseMotionListener(GuiDisplayUtil.getCardDetailMouse(this)); - oppCreaturePanel.addMouseMotionListener(GuiDisplayUtil.getCardDetailMouse(this)); - - - //opponent life mouse listener - oppLifeLabel.addMouseListener(new MouseAdapter() { - - @Override - public void mousePressed(MouseEvent e) { - inputControl.selectPlayer(AllZone.ComputerPlayer); - } - }); - - //self life mouse listener - playerLifeLabel.addMouseListener(new MouseAdapter() { - - @Override - public void mousePressed(MouseEvent e) { - inputControl.selectPlayer(AllZone.HumanPlayer); - } - }); - - //self play (land) ---- Mouse - playerLandPanel.addMouseListener(new MouseAdapter() { - - @Override - public void mousePressed(MouseEvent e) { - Object o = playerLandPanel.getComponentAt(e.getPoint()); - if(o instanceof CardPanel) { - CardPanel cardPanel = (CardPanel) o; - - if(cardPanel.getCard().isUntapped()) { - MP3Player mp3 = new MP3Player("tap.mp3"); - mp3.play(); - } - - if(cardPanel.getCard().isTapped() - && (inputControl.input instanceof Input_PayManaCost || inputControl.input instanceof Input_PayManaCost_Ability)) { - - while(cardPanel.connectedCard != null) { - cardPanel = cardPanel.connectedCard; - - if(cardPanel.getCard().isUntapped()) { - - break; - } - } - } - - inputControl.selectCard(cardPanel.getCard(), AllZone.Human_Battlefield); - - } - } - }); - //self play (no land) ---- Mouse - playerCreaturePanel.addMouseListener(new MouseAdapter() { - - @Override - public void mousePressed(MouseEvent e) { - Object o = playerCreaturePanel.getComponentAt(e.getPoint()); - if(o instanceof CardPanel) { - CardPanel cardPanel = (CardPanel) o; - - CardList att = new CardList(AllZone.Combat.getAttackers()); - //CardList block = AllZone.Combat.getAllBlockers(); - - if((cardPanel.getCard().isTapped() || cardPanel.getCard().hasSickness() || ((cardPanel.getCard().getKeyword().contains("Vigilance")) && att.contains(cardPanel.getCard()))) - && (inputControl.input instanceof Input_Attack)) { - while(cardPanel.connectedCard != null) { - cardPanel = cardPanel.connectedCard; - if(cardPanel.getCard().isUntapped() && !cardPanel.getCard().hasSickness()) { - break; - } - } - } - //right click: - if(e.isMetaDown()) { - if(att.contains(cardPanel.getCard()) && (inputControl.input instanceof Input_Attack)) { - cardPanel.getCard().untap(); - AllZone.Combat.removeFromCombat(cardPanel.getCard()); - } - - else if (inputControl.input instanceof Input_Block){ - Card crd = cardPanel.getCard(); - if(crd.getController().isHuman()) - AllZone.Combat.removeFromCombat(crd); - ((Input_Block)inputControl.input).removeFromAllBlocking(crd); - } - } - - else inputControl.selectCard(cardPanel.getCard(), AllZone.Human_Battlefield); - } - } - }); - //self hand ---- Mouse - playerHandPanel.addMouseListener(new MouseAdapter() { - - @Override - public void mousePressed(MouseEvent e) { - Object o = playerHandPanel.getComponentAt(e.getPoint()); - if(o instanceof CardPanel) { - CardContainer cardPanel = (CardContainer) o; - inputControl.selectCard(cardPanel.getCard(), AllZone.Human_Hand); - okButton.requestFocusInWindow(); - } - } - }); - - //***************************************************************** - //computer - - //computer play (land) ---- Mouse - oppLandPanel.addMouseListener(new MouseAdapter() { - - @Override - public void mousePressed(MouseEvent e) { - Object o = oppLandPanel.getComponentAt(e.getPoint()); - if(o instanceof CardPanel) { - CardContainer cardPanel = (CardContainer) o; - inputControl.selectCard(cardPanel.getCard(), AllZone.Computer_Battlefield); - } - } - }); - - //computer play (no land) ---- Mouse - oppCreaturePanel.addMouseListener(new MouseAdapter() { - - @Override - public void mousePressed(MouseEvent e) { - Object o = oppCreaturePanel.getComponentAt(e.getPoint()); - if(o instanceof CardPanel) { - CardContainer cardPanel = (CardContainer) o; - inputControl.selectCard(cardPanel.getCard(), AllZone.Computer_Battlefield); - } - } - }); - - - }//addListener() - - public Card getCard() { - return detail.getCard(); - } - - public void setCard(Card card) { - detail.setCard(card); - picture.setCard(card); - } - - private void addObservers() { - //Human Hand, Graveyard, and Library totals - {//make sure to not interfer with anything below, since this is a very long method - Observer o = new Observer() { - public void update(Observable a, Object b) { - playerHandValue.setText("" + AllZone.Human_Hand.getCards().length); - playerGraveValue.setText("" + AllZone.Human_Graveyard.getCards().length); - playerLibraryValue.setText("" + AllZone.Human_Library.getCards().length); - playerFBValue.setText("" + CardFactoryUtil.getGraveyardActivationCards(AllZone.HumanPlayer).size()); - playerRemovedValue.setText("" + AllZone.Human_Exile.getCards().length); - - } - }; - AllZone.Human_Hand.addObserver(o); - AllZone.Human_Graveyard.addObserver(o); - AllZone.Human_Library.addObserver(o); - } - - //opponent Hand, Graveyard, and Library totals - {//make sure to not interfer with anything below, since this is a very long method - Observer o = new Observer() { - public void update(Observable a, Object b) { - oppHandValue.setText("" + AllZone.Computer_Hand.getCards().length); - oppGraveValue.setText("" + AllZone.Computer_Graveyard.getCards().length); - oppLibraryValue.setText("" + AllZone.Computer_Library.getCards().length); - oppRemovedValue.setText("" + AllZone.Computer_Exile.getCards().length); - } - }; - AllZone.Computer_Hand.addObserver(o); - AllZone.Computer_Graveyard.addObserver(o); - AllZone.Computer_Library.addObserver(o); - } - - - //opponent life - oppLifeLabel.setText("" + AllZone.ComputerPlayer.getLife()); - AllZone.ComputerPlayer.addObserver(new Observer() { - public void update(Observable a, Object b) { - int life = AllZone.ComputerPlayer.getLife(); - oppLifeLabel.setText("" + life); - } - }); - AllZone.ComputerPlayer.updateObservers(); - - if (AllZone.QuestData != null) { - File base = ForgeProps.getFile(IMAGE_ICON); - String iconName = ""; - if (Constant.Quest.oppIconName[0] != null) { - iconName = Constant.Quest.oppIconName[0]; - File file = new File(base, iconName); - ImageIcon icon = new ImageIcon(file.toString()); - oppIconLabel.setIcon(icon); - oppIconLabel.setAlignmentX(100); - - } - } - - oppPCLabel.setText("Poison Counters: " + AllZone.ComputerPlayer.getPoisonCounters()); - AllZone.ComputerPlayer.addObserver(new Observer() { - public void update(Observable a, Object b) { - int pcs = AllZone.ComputerPlayer.getPoisonCounters(); - oppPCLabel.setText("Poison Counters: " + pcs); - } - }); - AllZone.ComputerPlayer.updateObservers(); - - //player life - playerLifeLabel.setText("" + AllZone.HumanPlayer.getLife()); - AllZone.HumanPlayer.addObserver(new Observer() { - public void update(Observable a, Object b) { - int life = AllZone.HumanPlayer.getLife(); - playerLifeLabel.setText("" + life); - } - }); - AllZone.HumanPlayer.updateObservers(); - - playerPCLabel.setText("Poison Counters: " + AllZone.HumanPlayer.getPoisonCounters()); - AllZone.HumanPlayer.addObserver(new Observer() { - public void update(Observable a, Object b) { - int pcs = AllZone.HumanPlayer.getPoisonCounters(); - playerPCLabel.setText("Poison Counters: " + pcs); - } - }); - AllZone.HumanPlayer.updateObservers(); - - //stack - AllZone.Stack.addObserver(new Observer() { - public void update(Observable a, Object b) { - stackPanel.removeAll(); - MagicStack stack = AllZone.Stack; - int count = 1; - JLabel label; - - for(int i = stack.size() - 1; 0 <= i; i--) { - label = new JLabel("" + (count++) + ". " + stack.peek(i).getStackDescription()); - - - //update card detail - final CardPanel cardPanel = new CardPanel(stack.peek(i).getSourceCard()); - cardPanel.setLayout(new BorderLayout()); - cardPanel.add(label); - cardPanel.addMouseMotionListener(new MouseMotionAdapter() { - - @Override - public void mouseMoved(MouseEvent me) { - setCard(cardPanel.getCard()); - }//mouseMoved - }); - - stackPanel.add(cardPanel); - } - - stackPanel.revalidate(); - stackPanel.repaint(); - - okButton.requestFocusInWindow(); - - } - }); - AllZone.Stack.updateObservers(); - //END, stack - - - //self hand - AllZone.Human_Hand.addObserver(new Observer() { - public void update(Observable a, Object b) { - PlayerZone pZone = (PlayerZone) a; - JPanel p = playerHandPanel; - p.removeAll(); - - Card c[] = pZone.getCards(); - JPanel panel; - for(int i = 0; i < c.length; i++) { - panel = new CardPanel(c[i]); - p.add(panel); - } - - p.revalidate(); - p.repaint(); - } - }); - AllZone.Human_Hand.updateObservers(); - //END, self hand - - //self play (land) - AllZone.Human_Battlefield.addObserver(new Observer() { - public void update(Observable a, Object b) { - //PlayerZone pZone = (PlayerZone) a; //unused - JPanel p = playerLandPanel; - p.removeAll(); - - GuiDisplayUtil.setupLandPanel(p, AllZone.Human_Battlefield.getCards()); - p.revalidate(); - p.repaint(); - } - }); - AllZone.Human_Battlefield.updateObservers(); - //END - self play (only land) - - - //self play (no land) - AllZone.Human_Battlefield.addObserver(new Observer() { - public void update(Observable a, Object b) { - //PlayerZone pZone = (PlayerZone) a; //unused - JPanel p = playerCreaturePanel; - p.removeAll(); - - GuiDisplayUtil.setupNoLandPanel(p, AllZone.Human_Battlefield.getCards()); - p.revalidate(); - p.repaint(); - } - }); - AllZone.Human_Battlefield.updateObservers(); - //END - self play (no land) - - - //computer play (no land) - AllZone.Computer_Battlefield.addObserver(new Observer() { - public void update(Observable a, Object b) { - //PlayerZone pZone = (PlayerZone) a; //unused - JPanel p = oppCreaturePanel; - p.removeAll(); - - GuiDisplayUtil.setupNoLandPanel(p, AllZone.Computer_Battlefield.getCards()); - - p.revalidate(); - p.repaint(); - } - }); - AllZone.Computer_Battlefield.updateObservers(); - //END - computer play (no land) - - //computer play (land) - AllZone.Computer_Battlefield.addObserver(new Observer() { - public void update(Observable a, Object b) { - //PlayerZone pZone = (PlayerZone) a; //unused - JPanel p = oppLandPanel; - p.removeAll(); - - GuiDisplayUtil.setupLandPanel(p, AllZone.Computer_Battlefield.getCards()); - p.revalidate(); - p.repaint(); - } - }); - AllZone.Computer_Battlefield.updateObservers(); - //END - computer play (only land) - - }//addObservers() - - private void initComponents() { - //Preparing the Frame - setTitle(ForgeProps.getLocalized(LANG.PROGRAM_NAME)); - if(!Gui_NewGame.useLAFFonts.isSelected()) setFont(new Font("Times New Roman", 0, 16)); - getContentPane().setLayout(new BorderLayout()); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent evt) { - concede(); - } - - @Override - public void windowClosed(WindowEvent e) { - File f = ForgeProps.getFile(LAYOUT); - Node layout = pane.getMultiSplitLayout().getModel(); - try { - XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(f))); - encoder.writeObject(layout); - encoder.close(); - } catch(IOException ex) { - ex.printStackTrace(); - } - } - }); - - //making the multi split pane - Node model; - File f = ForgeProps.getFile(LAYOUT); - try { - XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(f))); - model = (Node) decoder.readObject(); - decoder.close(); - pane.getMultiSplitLayout().setModel(model); - //pane.getMultiSplitLayout().setFloatingDividers(false); - } catch(Exception ex) { - model = parseModel(""// - + "(ROW "// - + "(COLUMN"// - + " (LEAF weight=0.2 name=info)"// - + " (LEAF weight=0.2 name=compy)"// - + " (LEAF weight=0.2 name=stack)"// - + " (LEAF weight=0.2 name=combat)"// - + " (LEAF weight=0.2 name=human)) "// - + "(COLUMN weight=1"// - + " (LEAF weight=0.2 name=compyLand)"// - + " (LEAF weight=0.2 name=compyPlay)"// - + " (LEAF weight=0.2 name=humanPlay)"// - + " (LEAF weight=0.2 name=humanLand)"// - + " (LEAF weight=0.2 name=humanHand)) "// - + "(COLUMN"// - + " (LEAF weight=0.5 name=detail)"// - + " (LEAF weight=0.5 name=picture)))"); - pane.setModel(model); - } - pane.getMultiSplitLayout().setFloatingDividers(false); - getContentPane().add(pane); - - //adding the individual parts - - if(!Gui_NewGame.useLAFFonts.isSelected()) initFonts(pane); - - initMsgYesNo(pane); - initOpp(pane); - initStackCombat(pane); - initPlayer(pane); - initZones(pane); - initCardPicture(pane); - } - - private void initFonts(JPanel pane) { - messageArea.setFont(getFont()); - - oppLifeLabel.setFont(lifeFont); - - oppPCLabel.setFont(statFont); - oppLibraryLabel.setFont(statFont); - - oppHandValue.setFont(statFont); - oppLibraryValue.setFont(statFont); - oppRemovedValue.setFont(statFont); - oppGraveValue.setFont(statFont); - - playerLifeLabel.setFont(lifeFont); - playerPCLabel.setFont(statFont); - - playerHandValue.setFont(statFont); - playerLibraryValue.setFont(statFont); - playerRemovedValue.setFont(statFont); - playerGraveValue.setFont(statFont); - playerFBValue.setFont(statFont); - - combatArea.setFont(getFont()); - } - - private void initMsgYesNo(JPanel pane) { -// messageArea.setBorder(BorderFactory.createEtchedBorder()); - messageArea.setEditable(false); - messageArea.setLineWrap(true); - messageArea.setWrapStyleWord(true); - - cancelButton.setText("Cancel"); - cancelButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - cancelButtonActionPerformed(evt); - okButton.requestFocusInWindow(); - } - }); - okButton.setText("OK"); - okButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent evt) { - okButtonActionPerformed(evt); - - if(AllZone.Phase.isNeedToNextPhase()) { - //for debugging: System.out.println("There better be no nextPhase in the stack."); - AllZone.Phase.setNeedToNextPhase(false); - AllZone.Phase.nextPhase(); - } - okButton.requestFocusInWindow(); - } - }); - okButton.addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent arg0) { - // TODO make triggers on escape - int code = arg0.getKeyCode(); - if(code == KeyEvent.VK_ESCAPE) { - cancelButton.doClick(); - } - } - }); - - okButton.requestFocusInWindow(); - - //if(okButton.isEnabled()) - //okButton.doClick(); - JPanel yesNoPanel = new JPanel(new FlowLayout()); - yesNoPanel.setBorder(new EtchedBorder()); - yesNoPanel.add(cancelButton); - yesNoPanel.add(okButton); - - JPanel panel = new JPanel(new BorderLayout()); - JScrollPane scroll = new JScrollPane(messageArea); - scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - panel.add(scroll); - panel.add(yesNoPanel, BorderLayout.SOUTH); - pane.add(new ExternalPanel(panel), "info"); - } - - private void initOpp(JPanel pane) { - //oppLifeLabel.setHorizontalAlignment(SwingConstants.CENTER); - - //oppPCLabel.setHorizontalAlignment(SwingConstants.TOP); - oppPCLabel.setForeground(greenColor); - - JLabel oppHandLabel = new JLabel(ForgeProps.getLocalized(COMPUTER_HAND.BUTTON), SwingConstants.TRAILING); - if(!Gui_NewGame.useLAFFonts.isSelected()) oppHandLabel.setFont(statFont); - - //JLabel oppGraveLabel = new JLabel("Grave:", SwingConstants.TRAILING); - JButton oppGraveButton = new JButton(COMPUTER_GRAVEYARD_ACTION); - oppGraveButton.setText((String) COMPUTER_GRAVEYARD_ACTION.getValue("buttonText")); - oppGraveButton.setMargin(new Insets(0, 0, 0, 0)); - oppGraveButton.setHorizontalAlignment(SwingConstants.TRAILING); - if(!Gui_NewGame.useLAFFonts.isSelected()) oppGraveButton.setFont(statFont); - - - JPanel gravePanel = new JPanel(new BorderLayout()); - gravePanel.add(oppGraveButton, BorderLayout.EAST); - - JButton oppRemovedButton = new JButton(COMPUTER_REMOVED_ACTION); - oppRemovedButton.setText((String) COMPUTER_REMOVED_ACTION.getValue("buttonText")); - oppRemovedButton.setMargin(new Insets(0, 0, 0, 0)); - //removedButton.setHorizontalAlignment(SwingConstants.TRAILING); - if(!Gui_NewGame.useLAFFonts.isSelected()) oppRemovedButton.setFont(statFont); - - - oppHandValue.setHorizontalAlignment(SwingConstants.LEADING); - oppLibraryValue.setHorizontalAlignment(SwingConstants.LEADING); - oppGraveValue.setHorizontalAlignment(SwingConstants.LEADING); - oppRemovedValue.setHorizontalAlignment(SwingConstants.LEADING); - - JPanel oppNumbersPanel = new JPanel(new GridLayout(0, 2, 3, 1)); - oppNumbersPanel.add(oppHandLabel); - oppNumbersPanel.add(oppHandValue); - oppNumbersPanel.add(oppRemovedButton); - oppNumbersPanel.add(oppRemovedValue); - oppNumbersPanel.add(oppLibraryLabel); - oppNumbersPanel.add(oppLibraryValue); - oppNumbersPanel.add(gravePanel); - oppNumbersPanel.add(oppGraveValue); - - oppLifeLabel.setHorizontalAlignment(SwingConstants.CENTER); - - JPanel oppIconLifePanel = new JPanel(new GridLayout(0, 1, 0, 0)); - oppIconLifePanel.add(oppIconLabel); - oppIconLifePanel.add(oppLifeLabel); - - JPanel oppPanel = new JPanel(); - oppPanel.setBorder(new TitledBorder(new EtchedBorder(), ForgeProps.getLocalized(COMPUTER_TITLE))); - oppPanel.setLayout(new BorderLayout()); - oppPanel.add(oppNumbersPanel, BorderLayout.WEST); - // oppPanel.add(oppIconLabel, BorderLayout.CENTER); - // oppPanel.add(oppLifeLabel, BorderLayout.EAST); - oppPanel.add(oppIconLifePanel, BorderLayout.EAST); - oppPanel.add(oppPCLabel, BorderLayout.AFTER_LAST_LINE); - pane.add(new ExternalPanel(oppPanel), "compy"); - } - - private void initStackCombat(JPanel pane) { - stackPanel.setLayout(new GridLayout(0, 1, 10, 10)); - JScrollPane stackPane = new JScrollPane(stackPanel); - stackPane.setBorder(new EtchedBorder()); - pane.add(new ExternalPanel(stackPane), "stack"); - - combatArea.setEditable(false); - combatArea.setLineWrap(true); - combatArea.setWrapStyleWord(true); - - JScrollPane combatPane = new JScrollPane(combatArea); - - combatPane.setBorder(new TitledBorder(new EtchedBorder(), ForgeProps.getLocalized(COMBAT))); - pane.add(new ExternalPanel(combatPane), "combat"); - } - - private void initPlayer(JPanel pane) { - //int fontSize = 12; - playerLifeLabel.setHorizontalAlignment(SwingConstants.CENTER); - - playerPCLabel.setForeground(greenColor); - - JLabel playerLibraryLabel = new JLabel(ForgeProps.getLocalized(HUMAN_LIBRARY.BUTTON), - SwingConstants.TRAILING); - if(!Gui_NewGame.useLAFFonts.isSelected()) playerLibraryLabel.setFont(statFont); - - JLabel playerHandLabel = new JLabel(ForgeProps.getLocalized(HUMAN_HAND.TITLE), SwingConstants.TRAILING); - if(!Gui_NewGame.useLAFFonts.isSelected()) playerHandLabel.setFont(statFont); - - //JLabel playerGraveLabel = new JLabel("Grave:", SwingConstants.TRAILING); - JButton playerGraveButton = new JButton(HUMAN_GRAVEYARD_ACTION); - playerGraveButton.setText((String) HUMAN_GRAVEYARD_ACTION.getValue("buttonText")); - playerGraveButton.setMargin(new Insets(0, 0, 0, 0)); - playerGraveButton.setHorizontalAlignment(SwingConstants.TRAILING); - if(!Gui_NewGame.useLAFFonts.isSelected()) playerGraveButton.setFont(statFont); - - - JButton playerFlashBackButton = new JButton(HUMAN_FLASHBACK_ACTION); - playerFlashBackButton.setText((String) HUMAN_FLASHBACK_ACTION.getValue("buttonText")); - playerFlashBackButton.setMargin(new Insets(0, 0, 0, 0)); - playerFlashBackButton.setHorizontalAlignment(SwingConstants.TRAILING); - if(!Gui_NewGame.useLAFFonts.isSelected()) playerFlashBackButton.setFont(statFont); - - - JPanel gravePanel = new JPanel(new BorderLayout()); - gravePanel.add(playerGraveButton, BorderLayout.EAST); - - JPanel playerFBPanel = new JPanel(new BorderLayout()); - playerFBPanel.add(playerFlashBackButton, BorderLayout.EAST); - - JButton playerRemovedButton = new JButton(HUMAN_REMOVED_ACTION); - playerRemovedButton.setText((String) HUMAN_REMOVED_ACTION.getValue("buttonText")); - playerRemovedButton.setMargin(new Insets(0, 0, 0, 0)); - //removedButton.setHorizontalAlignment(SwingConstants.TRAILING); - if(!Gui_NewGame.useLAFFonts.isSelected()) playerRemovedButton.setFont(statFont); - - playerHandValue.setHorizontalAlignment(SwingConstants.LEADING); - playerLibraryValue.setHorizontalAlignment(SwingConstants.LEADING); - playerGraveValue.setHorizontalAlignment(SwingConstants.LEADING); - playerFBValue.setHorizontalAlignment(SwingConstants.LEADING); - - //playerRemovedValue.setFont(new Font("MS Sans Serif", 0, fontSize)); - playerRemovedValue.setHorizontalAlignment(SwingConstants.LEADING); - - JPanel playerNumbersPanel = new JPanel(new GridLayout(0, 2, 5, 1)); - playerNumbersPanel.add(playerHandLabel); - playerNumbersPanel.add(playerHandValue); - playerNumbersPanel.add(playerRemovedButton); - playerNumbersPanel.add(playerRemovedValue); - playerNumbersPanel.add(playerLibraryLabel); - playerNumbersPanel.add(playerLibraryValue); - playerNumbersPanel.add(gravePanel); - playerNumbersPanel.add(playerGraveValue); - playerNumbersPanel.add(playerFBPanel); - playerNumbersPanel.add(playerFBValue); - - JPanel playerPanel = new JPanel(); - playerPanel.setBorder(new TitledBorder(new EtchedBorder(), ForgeProps.getLocalized(HUMAN_TITLE))); - playerPanel.setLayout(new BorderLayout()); - playerPanel.add(playerNumbersPanel, BorderLayout.WEST); - playerPanel.add(playerLifeLabel, BorderLayout.EAST); - playerPanel.add(playerPCLabel, BorderLayout.AFTER_LAST_LINE); - pane.add(new ExternalPanel(playerPanel), "human"); - } - - private void initZones(JPanel pane) { - JPanel[] zones = {oppLandPanel, oppCreaturePanel, playerCreaturePanel, playerLandPanel, playerHandPanel}; - String[] names = {"compyLand", "compyPlay", "humanPlay", "humanLand", "humanHand"}; - for(int i = 0; i < names.length; i++) { - zones[i].setLayout(null); - zones[i].setBorder(BorderFactory.createEtchedBorder()); - Dimension d = zones[i].getPreferredSize(); - d.height = 100; - zones[i].setPreferredSize(d); - pane.add(new ExternalPanel(new JScrollPane(zones[i])), names[i]); - } - playerHandPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); - } - - private void initCardPicture(JPanel pane) { - pane.add(new ExternalPanel(detail), "detail"); - pane.add(new ExternalPanel(picture), "picture"); - } - - private void cancelButtonActionPerformed(ActionEvent evt) { - inputControl.selectButtonCancel(); - } - - private void okButtonActionPerformed(ActionEvent evt) { - inputControl.selectButtonOK(); - } - - /** - * Exit the Application - */ - private void concede() { - savePrefs(); - dispose(); - Constant.Runtime.WinLose.addLose(); - if (!Constant.Quest.fantasyQuest[0]) - new Gui_WinLose(); - else { - //new Gui_WinLose(Constant.Quest.humanList[0], Constant.Quest.computerList[0],Constant.Quest.humanLife[0], Constant.Quest.computerLife[0]); - CardList humanList = QuestUtil.getHumanPlantAndPet(AllZone.QuestData, AllZone.QuestAssignment); - CardList computerList = QuestUtil.getComputerCreatures(AllZone.QuestData, AllZone.QuestAssignment); - - int humanLife = QuestUtil.getLife(AllZone.QuestData); - int computerLife = 20; - - if (AllZone.QuestAssignment!=null) - computerLife = AllZone.QuestAssignment.getComputerLife(); - new Gui_WinLose(humanList, computerList, humanLife, computerLife); - } - } - - // ********** Phase stuff in Display ****************** - public boolean stopAtPhase(Player turn, String phase) { - if (turn.isComputer()){ - if (phase.equals(Constant.Phase.End_Of_Turn)) - return cbAIEndOfTurn.isSelected(); - else if (phase.equals(Constant.Phase.Upkeep)) - return cbAIUpkeep.isSelected(); - else if (phase.equals(Constant.Phase.Draw)) - return cbAIDraw.isSelected(); - else if (phase.equals(Constant.Phase.Combat_Begin)) - return cbAIBeginCombat.isSelected(); - else if (phase.equals(Constant.Phase.Combat_End)) - return cbAIEndCombat.isSelected(); - } - else{ - if (phase.equals(Constant.Phase.End_Of_Turn)) - return cbHumanEndOfTurn.isSelected(); - else if (phase.equals(Constant.Phase.Upkeep)) - return cbHumanUpkeep.isSelected(); - else if (phase.equals(Constant.Phase.Draw)) - return cbHumanDraw.isSelected(); - else if (phase.equals(Constant.Phase.Combat_Begin)) - return cbHumanBeginCombat.isSelected(); - else if (phase.equals(Constant.Phase.Combat_End)) - return cbHumanEndCombat.isSelected(); - } - return true; - } - - public boolean loadPrefs(){ - ForgePreferences fp = Gui_NewGame.preferences; - - cbAIUpkeep.setSelected(fp.bAIUpkeep); - cbAIDraw.setSelected(fp.bAIDraw); - cbAIEndOfTurn.setSelected(fp.bAIEOT); - cbAIBeginCombat.setSelected(fp.bAIBeginCombat); - cbAIEndCombat.setSelected(fp.bAIEndCombat); - - cbHumanUpkeep.setSelected(fp.bHumanUpkeep); - cbHumanDraw.setSelected(fp.bHumanDraw); - cbHumanEndOfTurn.setSelected(fp.bHumanEOT); - cbHumanBeginCombat.setSelected(fp.bHumanBeginCombat); - cbHumanEndCombat.setSelected(fp.bHumanEndCombat); - - return true; - } - - public boolean savePrefs(){ - Constant.Runtime.Mill[0] = canLoseByDecking.isSelected(); - ForgePreferences fp = Gui_NewGame.preferences; - - fp.bAIUpkeep = cbAIUpkeep.isSelected(); - fp.bAIDraw = cbAIDraw.isSelected(); - fp.bAIEOT = cbAIEndOfTurn.isSelected(); - fp.bAIBeginCombat = cbAIBeginCombat.isSelected(); - fp.bAIEndCombat = cbAIEndCombat.isSelected(); - - fp.bHumanUpkeep = cbHumanUpkeep.isSelected(); - fp.bHumanDraw = cbHumanDraw.isSelected(); - fp.bHumanEOT = cbHumanEndOfTurn.isSelected(); - fp.bHumanBeginCombat = cbHumanBeginCombat.isSelected(); - fp.bHumanEndCombat = cbHumanEndCombat.isSelected(); - - return true; - } - - public static JCheckBoxMenuItem playsoundCheckboxForMenu = new JCheckBoxMenuItem("Play Sound", false); - - // Phases - public static JCheckBoxMenuItem cbAIUpkeep = new JCheckBoxMenuItem("Upkeep", true); - public static JCheckBoxMenuItem cbAIDraw = new JCheckBoxMenuItem("Draw", true); - public static JCheckBoxMenuItem cbAIEndOfTurn = new JCheckBoxMenuItem("End of Turn", true); - public static JCheckBoxMenuItem cbAIBeginCombat = new JCheckBoxMenuItem("Begin Combat", true); - public static JCheckBoxMenuItem cbAIEndCombat = new JCheckBoxMenuItem("End Combat", true); - - public static JCheckBoxMenuItem cbHumanUpkeep = new JCheckBoxMenuItem("Upkeep", true); - public static JCheckBoxMenuItem cbHumanDraw = new JCheckBoxMenuItem("Draw", true); - public static JCheckBoxMenuItem cbHumanEndOfTurn = new JCheckBoxMenuItem("End of Turn", true); - public static JCheckBoxMenuItem cbHumanBeginCombat = new JCheckBoxMenuItem("Begin Combat", true); - public static JCheckBoxMenuItem cbHumanEndCombat = new JCheckBoxMenuItem("End Combat", true); - - // ********** End of Phase stuff in Display ****************** - - // ****** Developer Mode ******* - - public static JCheckBoxMenuItem canLoseByDecking = new JCheckBoxMenuItem("Lose by Decking", true); - - // ***************************** - - JXMultiSplitPane pane = new JXMultiSplitPane(); - JButton cancelButton = new JButton(); - JButton okButton = new JButton(); - JTextArea messageArea = new JTextArea(1, 10); - JTextArea combatArea = new JTextArea(); - JPanel stackPanel = new JPanel(); - JPanel oppLandPanel = new JPanel(); - JPanel oppCreaturePanel = new JPanel(); - JPanel playerCreaturePanel = new JPanel(); - JPanel playerLandPanel = new JPanel(); - JPanel playerHandPanel = new JPanel(); - JPanel cdPanel = new JPanel(); - JLabel oppLifeLabel = new JLabel(); - JLabel oppIconLabel = new JLabel(); - JLabel playerLifeLabel = new JLabel(); - JLabel oppPCLabel = new JLabel(); - JLabel playerPCLabel = new JLabel(); - JLabel oppLibraryLabel = new JLabel( - ForgeProps.getLocalized(COMPUTER_LIBRARY.BUTTON), - SwingConstants.TRAILING); - JLabel oppHandValue = new JLabel(); - JLabel oppLibraryValue = new JLabel(); - JLabel oppGraveValue = new JLabel(); - JLabel oppRemovedValue = new JLabel(); - JLabel playerHandValue = new JLabel(); - JLabel playerLibraryValue = new JLabel(); - JLabel playerGraveValue = new JLabel(); - JLabel playerFBValue = new JLabel(); - JLabel playerRemovedValue = new JLabel(); - - CardDetailPanel detail = new CardDetailPanel(null); - CardPicturePanel picture = new CardPicturePanel(null); - - private class ZoneAction extends ForgeAction { - private static final long serialVersionUID = -5822976087772388839L; - private PlayerZone zone; - private String title; - - public ZoneAction(PlayerZone zone, String property) { - super(property); - title = ForgeProps.getLocalized(property + "/title"); - this.zone = zone; - } - - public void actionPerformed(ActionEvent e) { - Card[] c = getCards(); - - if(AllZone.NameChanger.shouldChangeCardName()) c = AllZone.NameChanger.changeCard(c); - - if(c.length == 0) GuiUtils.getChoiceOptional(title, new String[] {"no cards"}); - else { - Card choice = GuiUtils.getChoiceOptional(title, c); - if(choice != null) doAction(choice); - } - } - - /* - protected PlayerZone getZone() { - return zone; - } - */ - protected Card[] getCards() { - return zone.getCards(); - } - - protected void doAction(Card c) {} - } - - private class ConcedeAction extends ForgeAction { - - private static final long serialVersionUID = -6976695235601916762L; - - public ConcedeAction() { - super(CONCEDE); - } - - public void actionPerformed(ActionEvent e) { - concede(); - } - } - - public boolean canLoseByDecking(){ - return canLoseByDecking.isSelected(); - } -} - -//very hacky - - -class Gui_MultipleBlockers3 extends JFrame { - private static final long serialVersionUID = 7622818310877381045L; - - private int assignDamage; - private Card att; - private CardList blockers; - private CardContainer guiDisplay; - - private BorderLayout borderLayout1 = new BorderLayout(); - private JPanel mainPanel = new JPanel(); - private JScrollPane jScrollPane1 = new JScrollPane(); - private JLabel numberLabel = new JLabel(); - private JPanel jPanel3 = new JPanel(); - private BorderLayout borderLayout3 = new BorderLayout(); - private JPanel creaturePanel = new JPanel(); - - - public static void main(String[] args) { - CardList list = new CardList(); - list.add(AllZone.CardFactory.getCard("Elvish Piper", null)); - list.add(AllZone.CardFactory.getCard("Lantern Kami", null)); - list.add(AllZone.CardFactory.getCard("Frostling", null)); - list.add(AllZone.CardFactory.getCard("Frostling", null)); - - for(int i = 0; i < 2; i++) - new Gui_MultipleBlockers3(null, list, i + 1, null); - } - - Gui_MultipleBlockers3(Card attacker, CardList creatureList, int damage, CardContainer display) { - this(); - assignDamage = damage; - updateDamageLabel();//update user message about assigning damage - guiDisplay = display; - att = attacker; - blockers = creatureList; - - for(int i = 0; i < creatureList.size(); i++) - creaturePanel.add(new CardPanel(creatureList.get(i))); - - if (att.getKeyword().contains("Trample")) { - Card player = new Card(); - player.setName("Player"); - player.addIntrinsicKeyword("Shroud"); - player.addIntrinsicKeyword("Indestructible"); - creaturePanel.add(new CardPanel(player)); - } - - JDialog dialog = new JDialog(this, true); - dialog.setTitle("Multiple Blockers"); - dialog.setContentPane(mainPanel); - dialog.setSize(470, 260); - dialog.setVisible(true); - } - - public Gui_MultipleBlockers3() { - try { - jbInit(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - } -// setSize(470, 280); -// show(); - } - - private void jbInit() throws Exception { - this.getContentPane().setLayout(borderLayout1); - this.setTitle("Multiple Blockers"); - mainPanel.setLayout(null); - numberLabel.setHorizontalAlignment(SwingConstants.CENTER); - numberLabel.setHorizontalTextPosition(SwingConstants.CENTER); - numberLabel.setText("Assign"); - numberLabel.setBounds(new Rectangle(52, 30, 343, 24)); - jPanel3.setLayout(borderLayout3); - jPanel3.setBounds(new Rectangle(26, 75, 399, 114)); - creaturePanel.addMouseListener(new java.awt.event.MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - creaturePanel_mousePressed(e); - } - }); - creaturePanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { - @Override - public void mouseMoved(MouseEvent e) { - creaturePanel_mouseMoved(e); - } - }); - mainPanel.add(jPanel3, null); - jPanel3.add(jScrollPane1, BorderLayout.CENTER); - mainPanel.add(numberLabel, null); - jScrollPane1.getViewport().add(creaturePanel, null); - this.getContentPane().add(mainPanel, BorderLayout.CENTER); - } - - void okButton_actionPerformed(ActionEvent e) { - dispose(); - } - - void creaturePanel_mousePressed(MouseEvent e) { - Object o = creaturePanel.getComponentAt(e.getPoint()); - if(o instanceof CardPanel) { - - boolean assignedDamage = true; - - CardContainer cardPanel = (CardContainer) o; - Card c = cardPanel.getCard(); - //c.setAssignedDamage(c.getAssignedDamage() + 1); - CardList cl = new CardList(); - cl.add(att); - - boolean assignedLethalDamageToAllBlockers = true; - for (Card crd : blockers ) - { - if (crd.getTotalAssignedDamage() < ( crd.getNetDefense() - crd.getDamage() )) - assignedLethalDamageToAllBlockers = false; - } - - - if (c.getName().equals("Player") && att.getKeyword().contains("Trample") && assignedLethalDamageToAllBlockers) - { - AllZone.Combat.addDefendingDamage(1, att); - c.addAssignedDamage(1, att); - } - else if (!c.getName().equals("Player")){ - c.addAssignedDamage(1, att); - } - else - assignedDamage = false; - - if (assignedDamage) - { - assignDamage--; - updateDamageLabel(); - if(assignDamage == 0) dispose(); - } - - if(guiDisplay != null) { - guiDisplay.setCard(c); - } - } - //reduce damage, show new user message, exit if necessary - - }//creaturePanel_mousePressed() - - void updateDamageLabel() { - numberLabel.setText("Assign " + assignDamage + " damage - click on card to assign damage"); - } - - void creaturePanel_mouseMoved(MouseEvent e) { - Object o = creaturePanel.getComponentAt(e.getPoint()); - if(o instanceof CardPanel) { - CardContainer cardPanel = (CardContainer) o; - Card c = cardPanel.getCard(); - - if(guiDisplay != null) { - guiDisplay.setCard(c); - } - } - } -} + +package forge; + + +import forge.error.ErrorViewer; +import forge.gui.ForgeAction; +import forge.gui.GuiUtils; +import forge.gui.game.CardDetailPanel; +import forge.gui.game.CardPanel; +import forge.gui.game.CardPicturePanel; +import forge.properties.ForgePreferences; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; +import org.jdesktop.swingx.JXMultiSplitPane; +import org.jdesktop.swingx.MultiSplitLayout.Node; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; +import java.awt.*; +import java.awt.Color; +import java.awt.event.*; +import java.beans.XMLDecoder; +import java.beans.XMLEncoder; +import java.io.*; +import java.util.Observable; +import java.util.Observer; + +import static org.jdesktop.swingx.MultiSplitLayout.parseModel; + +public class GuiDisplay3 extends JFrame implements CardContainer, Display, NewConstants, NewConstants.GUI.GuiDisplay, NewConstants.LANG.GuiDisplay { + private static final long serialVersionUID = 4519302185194841060L; + + private GuiInput inputControl; + + Font statFont = new Font("Dialog", Font.PLAIN, 12); + Font lifeFont = new Font("Dialog", Font.PLAIN, 40); + Font checkboxFont = new Font("Dialog", Font.PLAIN, 9); + + + public static Color greenColor = new Color(0, 164, 0); + + private Action HUMAN_GRAVEYARD_ACTION; + private Action HUMAN_REMOVED_ACTION; + private Action HUMAN_FLASHBACK_ACTION; + private Action COMPUTER_GRAVEYARD_ACTION; + private Action COMPUTER_REMOVED_ACTION; + private Action CONCEDE_ACTION; + public Card cCardHQ; + + //private CardList multiBlockers = new CardList(); + + public GuiDisplay3() { + AllZone.Display = this; + setupActions(); + initComponents(); + + addObservers(); + addListeners(); + addMenu(); + inputControl = new GuiInput(); + } + + @Override + public void setVisible(boolean visible) { + if(visible) { + //causes an error if put in the constructor, causes some random null pointer exception + AllZone.InputControl.updateObservers(); + + //Use both so that when "un"maximizing, the frame isn't tiny + setSize(1024, 740); + System.out.println(getExtendedState()); + setExtendedState(Frame.MAXIMIZED_BOTH); + System.out.println(getExtendedState()); + } + super.setVisible(visible); + } + + public void assignDamage(Card attacker, CardList blockers, int damage) { + if (damage == 0) + return; + new Gui_MultipleBlockers3(attacker, blockers, damage, this); + } + + /* + public void addAssignDamage(Card attacker, Card blocker, int damage) + { + multiBlockers.add(blocker); + } + + public void addAssignDamage(Card attacker, int damage) { + //new Gui_MultipleBlockers3(attacker, blockers, damage, this); + new Gui_MultipleBlockers3(attacker, multiBlockers, damage, this); + } + */ + + private void setupActions() { + HUMAN_GRAVEYARD_ACTION = new ZoneAction(AllZone.Human_Graveyard, HUMAN_GRAVEYARD); + HUMAN_REMOVED_ACTION = new ZoneAction(AllZone.Human_Exile, HUMAN_REMOVED); + HUMAN_FLASHBACK_ACTION = new ZoneAction(AllZone.Human_Exile, HUMAN_FLASHBACK) { + + private static final long serialVersionUID = 8120331222693706164L; + + @Override + protected Card[] getCards() { + return CardFactoryUtil.getGraveyardActivationCards(AllZone.HumanPlayer).toArray(); + } + + @Override + protected void doAction(Card c) { + if(!c.isLand()) + { + SpellAbility[] sa = c.getSpellAbility(); + sa[1].setActivatingPlayer(AllZone.HumanPlayer); + if(sa[1].canPlay() && !c.isUnCastable()) AllZone.GameAction.playSpellAbility(sa[1]); + } + else // PlayLand checks if the land can be played + AllZone.HumanPlayer.playLand(c); + } + }; + COMPUTER_GRAVEYARD_ACTION = new ZoneAction(AllZone.Computer_Graveyard, COMPUTER_GRAVEYARD); + COMPUTER_REMOVED_ACTION = new ZoneAction(AllZone.Computer_Exile, COMPUTER_REMOVED); + CONCEDE_ACTION = new ConcedeAction(); + } + + private void addMenu() { + Object[] obj = { + HUMAN_GRAVEYARD_ACTION, HUMAN_REMOVED_ACTION, HUMAN_FLASHBACK_ACTION, COMPUTER_GRAVEYARD_ACTION, + COMPUTER_REMOVED_ACTION, new JSeparator(), + playsoundCheckboxForMenu, new JSeparator(), ErrorViewer.ALL_THREADS_ACTION, + CONCEDE_ACTION}; + + JMenu gameMenu = new JMenu(ForgeProps.getLocalized(MENU_BAR.MENU.TITLE)); + for(Object o:obj) { + if(o instanceof ForgeAction) gameMenu.add(((ForgeAction) o).setupButton(new JMenuItem())); + else if(o instanceof Action) gameMenu.add((Action) o); + else if(o instanceof Component) gameMenu.add((Component) o); + else throw new AssertionError(); + } + + JMenu gamePhases = new JMenu(ForgeProps.getLocalized(MENU_BAR.PHASE.TITLE)); + + JMenuItem aiLabel = new JMenuItem("Computer"); + JMenuItem humanLabel = new JMenuItem("Human"); + + Component[] objPhases = { aiLabel, cbAIUpkeep, cbAIDraw, cbAIBeginCombat, + cbAIEndCombat, cbAIEndOfTurn, new JSeparator(), + humanLabel, cbHumanUpkeep, cbHumanDraw, cbHumanBeginCombat, + cbHumanEndCombat, cbHumanEndOfTurn }; + + for(Component cmp:objPhases) { + gamePhases.add(cmp); + } + + // Dev Mode Creation + JMenu devMenu = new JMenu(ForgeProps.getLocalized(MENU_BAR.DEV.TITLE)); + + devMenu.setEnabled(Constant.Runtime.DevMode[0]); + + if (Constant.Runtime.DevMode[0]){ + canLoseByDecking.setSelected(Constant.Runtime.Mill[0]); + + Action viewAIHand = new ZoneAction(AllZone.Computer_Hand, COMPUTER_HAND.BASE); + Action viewAILibrary = new ZoneAction(AllZone.Computer_Library, COMPUTER_LIBRARY.BASE); + Action viewHumanLibrary = new ZoneAction(AllZone.Human_Library, HUMAN_LIBRARY.BASE); + ForgeAction generateMana = new ForgeAction(MANAGEN) { + private static final long serialVersionUID = 7171104690016706405L; + + public void actionPerformed(ActionEvent arg0) { + GuiDisplayUtil.devModeGenerateMana(); + } + }; + + Object[] objDev = { GuiDisplay4.canLoseByDecking, viewAIHand, viewAILibrary, viewHumanLibrary, generateMana }; + for(Object o:objDev) { + if(o instanceof ForgeAction) + devMenu.add(((ForgeAction) o).setupButton(new JMenuItem())); + else if (o instanceof Component) + devMenu.add((Component)o); + else if (o instanceof Action) + devMenu.add((Action)o); + } + } + + JMenuBar menuBar = new JMenuBar(); + menuBar.add(gameMenu); + menuBar.add(gamePhases); + menuBar.add(devMenu); + menuBar.add(new MenuItem_HowToPlay()); + this.setJMenuBar(menuBar); + }//addMenu() + + public MyButton getButtonOK() { + MyButton ok = new MyButton() { + public void select() { + inputControl.selectButtonOK(); + } + + public boolean isSelectable() { + return okButton.isEnabled(); + } + + public void setSelectable(boolean b) { + okButton.setEnabled(b); + } + + public String getText() { + return okButton.getText(); + } + + public void setText(String text) { + okButton.setText(text); + } + + public void reset() { + okButton.setText("OK"); + } + }; + + return ok; + }//getButtonOK() + + public MyButton getButtonCancel() { + MyButton cancel = new MyButton() { + public void select() { + inputControl.selectButtonCancel(); + } + + public boolean isSelectable() { + return cancelButton.isEnabled(); + } + + public void setSelectable(boolean b) { + cancelButton.setEnabled(b); + } + + public String getText() { + return cancelButton.getText(); + } + + public void setText(String text) { + cancelButton.setText(text); + } + + public void reset() { + cancelButton.setText("Cancel"); + } + }; + return cancel; + }//getButtonCancel() + + public void showCombat(String message) { + combatArea.setText(message); + } + + public void showMessage(String s) { + messageArea.setText(s); + + messageArea.setText(s); + Border border = new EmptyBorder(1, 1, 1, 1); + + messageArea.setBorder(border); + + int thickness = 3; + + if (s.contains("Main")) + border = BorderFactory.createLineBorder(new Color(30, 0, 255), thickness); + else if (s.contains("To Block")) + border = BorderFactory.createLineBorder(new Color(13, 179, 0), thickness); + else if (s.contains("Play Instants and Abilities") || s.contains("Combat") || s.contains("Damage")) + border = BorderFactory.createLineBorder(new Color(255, 174, 0), thickness); + else if (s.contains("Declare Attackers")) + border = BorderFactory.createLineBorder(new Color(255, 0, 0), thickness); + else if (s.contains("Upkeep") || s.contains("Draw") || s.contains("End of Turn")) + border = BorderFactory.createLineBorder(new Color(200, 0, 170), thickness); + + messageArea.setBorder(border); + } + + private void addListeners() { + //mouse Card Detail + playerHandPanel.addMouseMotionListener(GuiDisplayUtil.getCardDetailMouse(this)); + playerLandPanel.addMouseMotionListener(GuiDisplayUtil.getCardDetailMouse(this)); + playerCreaturePanel.addMouseMotionListener(GuiDisplayUtil.getCardDetailMouse(this)); + + oppLandPanel.addMouseMotionListener(GuiDisplayUtil.getCardDetailMouse(this)); + oppCreaturePanel.addMouseMotionListener(GuiDisplayUtil.getCardDetailMouse(this)); + + + //opponent life mouse listener + oppLifeLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mousePressed(MouseEvent e) { + inputControl.selectPlayer(AllZone.ComputerPlayer); + } + }); + + //self life mouse listener + playerLifeLabel.addMouseListener(new MouseAdapter() { + + @Override + public void mousePressed(MouseEvent e) { + inputControl.selectPlayer(AllZone.HumanPlayer); + } + }); + + //self play (land) ---- Mouse + playerLandPanel.addMouseListener(new MouseAdapter() { + + @Override + public void mousePressed(MouseEvent e) { + Object o = playerLandPanel.getComponentAt(e.getPoint()); + if(o instanceof CardPanel) { + CardPanel cardPanel = (CardPanel) o; + + if(cardPanel.getCard().isUntapped()) { + MP3Player mp3 = new MP3Player("tap.mp3"); + mp3.play(); + } + + if(cardPanel.getCard().isTapped() + && (inputControl.input instanceof Input_PayManaCost || inputControl.input instanceof Input_PayManaCost_Ability)) { + + while(cardPanel.connectedCard != null) { + cardPanel = cardPanel.connectedCard; + + if(cardPanel.getCard().isUntapped()) { + + break; + } + } + } + + inputControl.selectCard(cardPanel.getCard(), AllZone.Human_Battlefield); + + } + } + }); + //self play (no land) ---- Mouse + playerCreaturePanel.addMouseListener(new MouseAdapter() { + + @Override + public void mousePressed(MouseEvent e) { + Object o = playerCreaturePanel.getComponentAt(e.getPoint()); + if(o instanceof CardPanel) { + CardPanel cardPanel = (CardPanel) o; + + CardList att = new CardList(AllZone.Combat.getAttackers()); + //CardList block = AllZone.Combat.getAllBlockers(); + + if((cardPanel.getCard().isTapped() || cardPanel.getCard().hasSickness() || ((cardPanel.getCard().getKeyword().contains("Vigilance")) && att.contains(cardPanel.getCard()))) + && (inputControl.input instanceof Input_Attack)) { + while(cardPanel.connectedCard != null) { + cardPanel = cardPanel.connectedCard; + if(cardPanel.getCard().isUntapped() && !cardPanel.getCard().hasSickness()) { + break; + } + } + } + //right click: + if(e.isMetaDown()) { + if(att.contains(cardPanel.getCard()) && (inputControl.input instanceof Input_Attack)) { + cardPanel.getCard().untap(); + AllZone.Combat.removeFromCombat(cardPanel.getCard()); + } + + else if (inputControl.input instanceof Input_Block){ + Card crd = cardPanel.getCard(); + if(crd.getController().isHuman()) + AllZone.Combat.removeFromCombat(crd); + ((Input_Block)inputControl.input).removeFromAllBlocking(crd); + } + } + + else inputControl.selectCard(cardPanel.getCard(), AllZone.Human_Battlefield); + } + } + }); + //self hand ---- Mouse + playerHandPanel.addMouseListener(new MouseAdapter() { + + @Override + public void mousePressed(MouseEvent e) { + Object o = playerHandPanel.getComponentAt(e.getPoint()); + if(o instanceof CardPanel) { + CardContainer cardPanel = (CardContainer) o; + inputControl.selectCard(cardPanel.getCard(), AllZone.Human_Hand); + okButton.requestFocusInWindow(); + } + } + }); + + //***************************************************************** + //computer + + //computer play (land) ---- Mouse + oppLandPanel.addMouseListener(new MouseAdapter() { + + @Override + public void mousePressed(MouseEvent e) { + Object o = oppLandPanel.getComponentAt(e.getPoint()); + if(o instanceof CardPanel) { + CardContainer cardPanel = (CardContainer) o; + inputControl.selectCard(cardPanel.getCard(), AllZone.Computer_Battlefield); + } + } + }); + + //computer play (no land) ---- Mouse + oppCreaturePanel.addMouseListener(new MouseAdapter() { + + @Override + public void mousePressed(MouseEvent e) { + Object o = oppCreaturePanel.getComponentAt(e.getPoint()); + if(o instanceof CardPanel) { + CardContainer cardPanel = (CardContainer) o; + inputControl.selectCard(cardPanel.getCard(), AllZone.Computer_Battlefield); + } + } + }); + + + }//addListener() + + public Card getCard() { + return detail.getCard(); + } + + public void setCard(Card card) { + detail.setCard(card); + picture.setCard(card); + } + + private void addObservers() { + //Human Hand, Graveyard, and Library totals + {//make sure to not interfer with anything below, since this is a very long method + Observer o = new Observer() { + public void update(Observable a, Object b) { + playerHandValue.setText("" + AllZone.Human_Hand.getCards().length); + playerGraveValue.setText("" + AllZone.Human_Graveyard.getCards().length); + playerLibraryValue.setText("" + AllZone.Human_Library.getCards().length); + playerFBValue.setText("" + CardFactoryUtil.getGraveyardActivationCards(AllZone.HumanPlayer).size()); + playerRemovedValue.setText("" + AllZone.Human_Exile.getCards().length); + + } + }; + AllZone.Human_Hand.addObserver(o); + AllZone.Human_Graveyard.addObserver(o); + AllZone.Human_Library.addObserver(o); + } + + //opponent Hand, Graveyard, and Library totals + {//make sure to not interfer with anything below, since this is a very long method + Observer o = new Observer() { + public void update(Observable a, Object b) { + oppHandValue.setText("" + AllZone.Computer_Hand.getCards().length); + oppGraveValue.setText("" + AllZone.Computer_Graveyard.getCards().length); + oppLibraryValue.setText("" + AllZone.Computer_Library.getCards().length); + oppRemovedValue.setText("" + AllZone.Computer_Exile.getCards().length); + } + }; + AllZone.Computer_Hand.addObserver(o); + AllZone.Computer_Graveyard.addObserver(o); + AllZone.Computer_Library.addObserver(o); + } + + + //opponent life + oppLifeLabel.setText("" + AllZone.ComputerPlayer.getLife()); + AllZone.ComputerPlayer.addObserver(new Observer() { + public void update(Observable a, Object b) { + int life = AllZone.ComputerPlayer.getLife(); + oppLifeLabel.setText("" + life); + } + }); + AllZone.ComputerPlayer.updateObservers(); + + if (AllZone.QuestData != null) { + File base = ForgeProps.getFile(IMAGE_ICON); + String iconName = ""; + if (Constant.Quest.oppIconName[0] != null) { + iconName = Constant.Quest.oppIconName[0]; + File file = new File(base, iconName); + ImageIcon icon = new ImageIcon(file.toString()); + oppIconLabel.setIcon(icon); + oppIconLabel.setAlignmentX(100); + + } + } + + oppPCLabel.setText("Poison Counters: " + AllZone.ComputerPlayer.getPoisonCounters()); + AllZone.ComputerPlayer.addObserver(new Observer() { + public void update(Observable a, Object b) { + int pcs = AllZone.ComputerPlayer.getPoisonCounters(); + oppPCLabel.setText("Poison Counters: " + pcs); + } + }); + AllZone.ComputerPlayer.updateObservers(); + + //player life + playerLifeLabel.setText("" + AllZone.HumanPlayer.getLife()); + AllZone.HumanPlayer.addObserver(new Observer() { + public void update(Observable a, Object b) { + int life = AllZone.HumanPlayer.getLife(); + playerLifeLabel.setText("" + life); + } + }); + AllZone.HumanPlayer.updateObservers(); + + playerPCLabel.setText("Poison Counters: " + AllZone.HumanPlayer.getPoisonCounters()); + AllZone.HumanPlayer.addObserver(new Observer() { + public void update(Observable a, Object b) { + int pcs = AllZone.HumanPlayer.getPoisonCounters(); + playerPCLabel.setText("Poison Counters: " + pcs); + } + }); + AllZone.HumanPlayer.updateObservers(); + + //stack + AllZone.Stack.addObserver(new Observer() { + public void update(Observable a, Object b) { + stackPanel.removeAll(); + MagicStack stack = AllZone.Stack; + int count = 1; + JLabel label; + + for(int i = stack.size() - 1; 0 <= i; i--) { + label = new JLabel("" + (count++) + ". " + stack.peek(i).getStackDescription()); + + + //update card detail + final CardPanel cardPanel = new CardPanel(stack.peek(i).getSourceCard()); + cardPanel.setLayout(new BorderLayout()); + cardPanel.add(label); + cardPanel.addMouseMotionListener(new MouseMotionAdapter() { + + @Override + public void mouseMoved(MouseEvent me) { + setCard(cardPanel.getCard()); + }//mouseMoved + }); + + stackPanel.add(cardPanel); + } + + stackPanel.revalidate(); + stackPanel.repaint(); + + okButton.requestFocusInWindow(); + + } + }); + AllZone.Stack.updateObservers(); + //END, stack + + + //self hand + AllZone.Human_Hand.addObserver(new Observer() { + public void update(Observable a, Object b) { + PlayerZone pZone = (PlayerZone) a; + JPanel p = playerHandPanel; + p.removeAll(); + + Card c[] = pZone.getCards(); + JPanel panel; + for(int i = 0; i < c.length; i++) { + panel = new CardPanel(c[i]); + p.add(panel); + } + + p.revalidate(); + p.repaint(); + } + }); + AllZone.Human_Hand.updateObservers(); + //END, self hand + + //self play (land) + AllZone.Human_Battlefield.addObserver(new Observer() { + public void update(Observable a, Object b) { + //PlayerZone pZone = (PlayerZone) a; //unused + JPanel p = playerLandPanel; + p.removeAll(); + + GuiDisplayUtil.setupLandPanel(p, AllZone.Human_Battlefield.getCards()); + p.revalidate(); + p.repaint(); + } + }); + AllZone.Human_Battlefield.updateObservers(); + //END - self play (only land) + + + //self play (no land) + AllZone.Human_Battlefield.addObserver(new Observer() { + public void update(Observable a, Object b) { + //PlayerZone pZone = (PlayerZone) a; //unused + JPanel p = playerCreaturePanel; + p.removeAll(); + + GuiDisplayUtil.setupNoLandPanel(p, AllZone.Human_Battlefield.getCards()); + p.revalidate(); + p.repaint(); + } + }); + AllZone.Human_Battlefield.updateObservers(); + //END - self play (no land) + + + //computer play (no land) + AllZone.Computer_Battlefield.addObserver(new Observer() { + public void update(Observable a, Object b) { + //PlayerZone pZone = (PlayerZone) a; //unused + JPanel p = oppCreaturePanel; + p.removeAll(); + + GuiDisplayUtil.setupNoLandPanel(p, AllZone.Computer_Battlefield.getCards()); + + p.revalidate(); + p.repaint(); + } + }); + AllZone.Computer_Battlefield.updateObservers(); + //END - computer play (no land) + + //computer play (land) + AllZone.Computer_Battlefield.addObserver(new Observer() { + public void update(Observable a, Object b) { + //PlayerZone pZone = (PlayerZone) a; //unused + JPanel p = oppLandPanel; + p.removeAll(); + + GuiDisplayUtil.setupLandPanel(p, AllZone.Computer_Battlefield.getCards()); + p.revalidate(); + p.repaint(); + } + }); + AllZone.Computer_Battlefield.updateObservers(); + //END - computer play (only land) + + }//addObservers() + + private void initComponents() { + //Preparing the Frame + setTitle(ForgeProps.getLocalized(LANG.PROGRAM_NAME)); + if(!Gui_NewGame.useLAFFonts.isSelected()) setFont(new Font("Times New Roman", 0, 16)); + getContentPane().setLayout(new BorderLayout()); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent evt) { + concede(); + } + + @Override + public void windowClosed(WindowEvent e) { + File f = ForgeProps.getFile(LAYOUT); + Node layout = pane.getMultiSplitLayout().getModel(); + try { + XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(f))); + encoder.writeObject(layout); + encoder.close(); + } catch(IOException ex) { + ex.printStackTrace(); + } + } + }); + + //making the multi split pane + Node model; + File f = ForgeProps.getFile(LAYOUT); + try { + XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(f))); + model = (Node) decoder.readObject(); + decoder.close(); + pane.getMultiSplitLayout().setModel(model); + //pane.getMultiSplitLayout().setFloatingDividers(false); + } catch(Exception ex) { + model = parseModel(""// + + "(ROW "// + + "(COLUMN"// + + " (LEAF weight=0.2 name=info)"// + + " (LEAF weight=0.2 name=compy)"// + + " (LEAF weight=0.2 name=stack)"// + + " (LEAF weight=0.2 name=combat)"// + + " (LEAF weight=0.2 name=human)) "// + + "(COLUMN weight=1"// + + " (LEAF weight=0.2 name=compyLand)"// + + " (LEAF weight=0.2 name=compyPlay)"// + + " (LEAF weight=0.2 name=humanPlay)"// + + " (LEAF weight=0.2 name=humanLand)"// + + " (LEAF weight=0.2 name=humanHand)) "// + + "(COLUMN"// + + " (LEAF weight=0.5 name=detail)"// + + " (LEAF weight=0.5 name=picture)))"); + pane.setModel(model); + } + pane.getMultiSplitLayout().setFloatingDividers(false); + getContentPane().add(pane); + + //adding the individual parts + + if(!Gui_NewGame.useLAFFonts.isSelected()) initFonts(pane); + + initMsgYesNo(pane); + initOpp(pane); + initStackCombat(pane); + initPlayer(pane); + initZones(pane); + initCardPicture(pane); + } + + private void initFonts(JPanel pane) { + messageArea.setFont(getFont()); + + oppLifeLabel.setFont(lifeFont); + + oppPCLabel.setFont(statFont); + oppLibraryLabel.setFont(statFont); + + oppHandValue.setFont(statFont); + oppLibraryValue.setFont(statFont); + oppRemovedValue.setFont(statFont); + oppGraveValue.setFont(statFont); + + playerLifeLabel.setFont(lifeFont); + playerPCLabel.setFont(statFont); + + playerHandValue.setFont(statFont); + playerLibraryValue.setFont(statFont); + playerRemovedValue.setFont(statFont); + playerGraveValue.setFont(statFont); + playerFBValue.setFont(statFont); + + combatArea.setFont(getFont()); + } + + private void initMsgYesNo(JPanel pane) { +// messageArea.setBorder(BorderFactory.createEtchedBorder()); + messageArea.setEditable(false); + messageArea.setLineWrap(true); + messageArea.setWrapStyleWord(true); + + cancelButton.setText("Cancel"); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + cancelButtonActionPerformed(evt); + okButton.requestFocusInWindow(); + } + }); + okButton.setText("OK"); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent evt) { + okButtonActionPerformed(evt); + + if(AllZone.Phase.isNeedToNextPhase()) { + //for debugging: System.out.println("There better be no nextPhase in the stack."); + AllZone.Phase.setNeedToNextPhase(false); + AllZone.Phase.nextPhase(); + } + okButton.requestFocusInWindow(); + } + }); + okButton.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent arg0) { + // TODO make triggers on escape + int code = arg0.getKeyCode(); + if(code == KeyEvent.VK_ESCAPE) { + cancelButton.doClick(); + } + } + }); + + okButton.requestFocusInWindow(); + + //if(okButton.isEnabled()) + //okButton.doClick(); + JPanel yesNoPanel = new JPanel(new FlowLayout()); + yesNoPanel.setBorder(new EtchedBorder()); + yesNoPanel.add(cancelButton); + yesNoPanel.add(okButton); + + JPanel panel = new JPanel(new BorderLayout()); + JScrollPane scroll = new JScrollPane(messageArea); + scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + panel.add(scroll); + panel.add(yesNoPanel, BorderLayout.SOUTH); + pane.add(new ExternalPanel(panel), "info"); + } + + private void initOpp(JPanel pane) { + //oppLifeLabel.setHorizontalAlignment(SwingConstants.CENTER); + + //oppPCLabel.setHorizontalAlignment(SwingConstants.TOP); + oppPCLabel.setForeground(greenColor); + + JLabel oppHandLabel = new JLabel(ForgeProps.getLocalized(COMPUTER_HAND.BUTTON), SwingConstants.TRAILING); + if(!Gui_NewGame.useLAFFonts.isSelected()) oppHandLabel.setFont(statFont); + + //JLabel oppGraveLabel = new JLabel("Grave:", SwingConstants.TRAILING); + JButton oppGraveButton = new JButton(COMPUTER_GRAVEYARD_ACTION); + oppGraveButton.setText((String) COMPUTER_GRAVEYARD_ACTION.getValue("buttonText")); + oppGraveButton.setMargin(new Insets(0, 0, 0, 0)); + oppGraveButton.setHorizontalAlignment(SwingConstants.TRAILING); + if(!Gui_NewGame.useLAFFonts.isSelected()) oppGraveButton.setFont(statFont); + + + JPanel gravePanel = new JPanel(new BorderLayout()); + gravePanel.add(oppGraveButton, BorderLayout.EAST); + + JButton oppRemovedButton = new JButton(COMPUTER_REMOVED_ACTION); + oppRemovedButton.setText((String) COMPUTER_REMOVED_ACTION.getValue("buttonText")); + oppRemovedButton.setMargin(new Insets(0, 0, 0, 0)); + //removedButton.setHorizontalAlignment(SwingConstants.TRAILING); + if(!Gui_NewGame.useLAFFonts.isSelected()) oppRemovedButton.setFont(statFont); + + + oppHandValue.setHorizontalAlignment(SwingConstants.LEADING); + oppLibraryValue.setHorizontalAlignment(SwingConstants.LEADING); + oppGraveValue.setHorizontalAlignment(SwingConstants.LEADING); + oppRemovedValue.setHorizontalAlignment(SwingConstants.LEADING); + + JPanel oppNumbersPanel = new JPanel(new GridLayout(0, 2, 3, 1)); + oppNumbersPanel.add(oppHandLabel); + oppNumbersPanel.add(oppHandValue); + oppNumbersPanel.add(oppRemovedButton); + oppNumbersPanel.add(oppRemovedValue); + oppNumbersPanel.add(oppLibraryLabel); + oppNumbersPanel.add(oppLibraryValue); + oppNumbersPanel.add(gravePanel); + oppNumbersPanel.add(oppGraveValue); + + oppLifeLabel.setHorizontalAlignment(SwingConstants.CENTER); + + JPanel oppIconLifePanel = new JPanel(new GridLayout(0, 1, 0, 0)); + oppIconLifePanel.add(oppIconLabel); + oppIconLifePanel.add(oppLifeLabel); + + JPanel oppPanel = new JPanel(); + oppPanel.setBorder(new TitledBorder(new EtchedBorder(), ForgeProps.getLocalized(COMPUTER_TITLE))); + oppPanel.setLayout(new BorderLayout()); + oppPanel.add(oppNumbersPanel, BorderLayout.WEST); + // oppPanel.add(oppIconLabel, BorderLayout.CENTER); + // oppPanel.add(oppLifeLabel, BorderLayout.EAST); + oppPanel.add(oppIconLifePanel, BorderLayout.EAST); + oppPanel.add(oppPCLabel, BorderLayout.AFTER_LAST_LINE); + pane.add(new ExternalPanel(oppPanel), "compy"); + } + + private void initStackCombat(JPanel pane) { + stackPanel.setLayout(new GridLayout(0, 1, 10, 10)); + JScrollPane stackPane = new JScrollPane(stackPanel); + stackPane.setBorder(new EtchedBorder()); + pane.add(new ExternalPanel(stackPane), "stack"); + + combatArea.setEditable(false); + combatArea.setLineWrap(true); + combatArea.setWrapStyleWord(true); + + JScrollPane combatPane = new JScrollPane(combatArea); + + combatPane.setBorder(new TitledBorder(new EtchedBorder(), ForgeProps.getLocalized(COMBAT))); + pane.add(new ExternalPanel(combatPane), "combat"); + } + + private void initPlayer(JPanel pane) { + //int fontSize = 12; + playerLifeLabel.setHorizontalAlignment(SwingConstants.CENTER); + + playerPCLabel.setForeground(greenColor); + + JLabel playerLibraryLabel = new JLabel(ForgeProps.getLocalized(HUMAN_LIBRARY.BUTTON), + SwingConstants.TRAILING); + if(!Gui_NewGame.useLAFFonts.isSelected()) playerLibraryLabel.setFont(statFont); + + JLabel playerHandLabel = new JLabel(ForgeProps.getLocalized(HUMAN_HAND.TITLE), SwingConstants.TRAILING); + if(!Gui_NewGame.useLAFFonts.isSelected()) playerHandLabel.setFont(statFont); + + //JLabel playerGraveLabel = new JLabel("Grave:", SwingConstants.TRAILING); + JButton playerGraveButton = new JButton(HUMAN_GRAVEYARD_ACTION); + playerGraveButton.setText((String) HUMAN_GRAVEYARD_ACTION.getValue("buttonText")); + playerGraveButton.setMargin(new Insets(0, 0, 0, 0)); + playerGraveButton.setHorizontalAlignment(SwingConstants.TRAILING); + if(!Gui_NewGame.useLAFFonts.isSelected()) playerGraveButton.setFont(statFont); + + + JButton playerFlashBackButton = new JButton(HUMAN_FLASHBACK_ACTION); + playerFlashBackButton.setText((String) HUMAN_FLASHBACK_ACTION.getValue("buttonText")); + playerFlashBackButton.setMargin(new Insets(0, 0, 0, 0)); + playerFlashBackButton.setHorizontalAlignment(SwingConstants.TRAILING); + if(!Gui_NewGame.useLAFFonts.isSelected()) playerFlashBackButton.setFont(statFont); + + + JPanel gravePanel = new JPanel(new BorderLayout()); + gravePanel.add(playerGraveButton, BorderLayout.EAST); + + JPanel playerFBPanel = new JPanel(new BorderLayout()); + playerFBPanel.add(playerFlashBackButton, BorderLayout.EAST); + + JButton playerRemovedButton = new JButton(HUMAN_REMOVED_ACTION); + playerRemovedButton.setText((String) HUMAN_REMOVED_ACTION.getValue("buttonText")); + playerRemovedButton.setMargin(new Insets(0, 0, 0, 0)); + //removedButton.setHorizontalAlignment(SwingConstants.TRAILING); + if(!Gui_NewGame.useLAFFonts.isSelected()) playerRemovedButton.setFont(statFont); + + playerHandValue.setHorizontalAlignment(SwingConstants.LEADING); + playerLibraryValue.setHorizontalAlignment(SwingConstants.LEADING); + playerGraveValue.setHorizontalAlignment(SwingConstants.LEADING); + playerFBValue.setHorizontalAlignment(SwingConstants.LEADING); + + //playerRemovedValue.setFont(new Font("MS Sans Serif", 0, fontSize)); + playerRemovedValue.setHorizontalAlignment(SwingConstants.LEADING); + + JPanel playerNumbersPanel = new JPanel(new GridLayout(0, 2, 5, 1)); + playerNumbersPanel.add(playerHandLabel); + playerNumbersPanel.add(playerHandValue); + playerNumbersPanel.add(playerRemovedButton); + playerNumbersPanel.add(playerRemovedValue); + playerNumbersPanel.add(playerLibraryLabel); + playerNumbersPanel.add(playerLibraryValue); + playerNumbersPanel.add(gravePanel); + playerNumbersPanel.add(playerGraveValue); + playerNumbersPanel.add(playerFBPanel); + playerNumbersPanel.add(playerFBValue); + + JPanel playerPanel = new JPanel(); + playerPanel.setBorder(new TitledBorder(new EtchedBorder(), ForgeProps.getLocalized(HUMAN_TITLE))); + playerPanel.setLayout(new BorderLayout()); + playerPanel.add(playerNumbersPanel, BorderLayout.WEST); + playerPanel.add(playerLifeLabel, BorderLayout.EAST); + playerPanel.add(playerPCLabel, BorderLayout.AFTER_LAST_LINE); + pane.add(new ExternalPanel(playerPanel), "human"); + } + + private void initZones(JPanel pane) { + JPanel[] zones = {oppLandPanel, oppCreaturePanel, playerCreaturePanel, playerLandPanel, playerHandPanel}; + String[] names = {"compyLand", "compyPlay", "humanPlay", "humanLand", "humanHand"}; + for(int i = 0; i < names.length; i++) { + zones[i].setLayout(null); + zones[i].setBorder(BorderFactory.createEtchedBorder()); + Dimension d = zones[i].getPreferredSize(); + d.height = 100; + zones[i].setPreferredSize(d); + pane.add(new ExternalPanel(new JScrollPane(zones[i])), names[i]); + } + playerHandPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); + } + + private void initCardPicture(JPanel pane) { + pane.add(new ExternalPanel(detail), "detail"); + pane.add(new ExternalPanel(picture), "picture"); + } + + private void cancelButtonActionPerformed(ActionEvent evt) { + inputControl.selectButtonCancel(); + } + + private void okButtonActionPerformed(ActionEvent evt) { + inputControl.selectButtonOK(); + } + + /** + * Exit the Application + */ + private void concede() { + savePrefs(); + dispose(); + Constant.Runtime.matchState.addLose(); + if (!Constant.Quest.fantasyQuest[0]) + new Gui_WinLose(); + else { + //new Gui_WinLose(Constant.Quest.humanList[0], Constant.Quest.computerList[0],Constant.Quest.humanLife[0], Constant.Quest.computerLife[0]); + CardList humanList = forge.quest.data.QuestUtil.getHumanPlantAndPet(AllZone.QuestData, AllZone.QuestAssignment); + CardList computerList = forge.quest.data.QuestUtil.getComputerCreatures(AllZone.QuestData, AllZone.QuestAssignment); + + int humanLife = AllZone.QuestData.getLife(); + int computerLife = 20; + + if (AllZone.QuestAssignment!=null) + computerLife = AllZone.QuestAssignment.getComputerLife(); + new Gui_WinLose(humanList, computerList, humanLife, computerLife); + } + } + + // ********** Phase stuff in Display ****************** + public boolean stopAtPhase(Player turn, String phase) { + if (turn.isComputer()){ + if (phase.equals(Constant.Phase.End_Of_Turn)) + return cbAIEndOfTurn.isSelected(); + else if (phase.equals(Constant.Phase.Upkeep)) + return cbAIUpkeep.isSelected(); + else if (phase.equals(Constant.Phase.Draw)) + return cbAIDraw.isSelected(); + else if (phase.equals(Constant.Phase.Combat_Begin)) + return cbAIBeginCombat.isSelected(); + else if (phase.equals(Constant.Phase.Combat_End)) + return cbAIEndCombat.isSelected(); + } + else{ + if (phase.equals(Constant.Phase.End_Of_Turn)) + return cbHumanEndOfTurn.isSelected(); + else if (phase.equals(Constant.Phase.Upkeep)) + return cbHumanUpkeep.isSelected(); + else if (phase.equals(Constant.Phase.Draw)) + return cbHumanDraw.isSelected(); + else if (phase.equals(Constant.Phase.Combat_Begin)) + return cbHumanBeginCombat.isSelected(); + else if (phase.equals(Constant.Phase.Combat_End)) + return cbHumanEndCombat.isSelected(); + } + return true; + } + + public boolean loadPrefs(){ + ForgePreferences fp = Gui_NewGame.preferences; + + cbAIUpkeep.setSelected(fp.bAIUpkeep); + cbAIDraw.setSelected(fp.bAIDraw); + cbAIEndOfTurn.setSelected(fp.bAIEOT); + cbAIBeginCombat.setSelected(fp.bAIBeginCombat); + cbAIEndCombat.setSelected(fp.bAIEndCombat); + + cbHumanUpkeep.setSelected(fp.bHumanUpkeep); + cbHumanDraw.setSelected(fp.bHumanDraw); + cbHumanEndOfTurn.setSelected(fp.bHumanEOT); + cbHumanBeginCombat.setSelected(fp.bHumanBeginCombat); + cbHumanEndCombat.setSelected(fp.bHumanEndCombat); + + return true; + } + + public boolean savePrefs(){ + Constant.Runtime.Mill[0] = canLoseByDecking.isSelected(); + ForgePreferences fp = Gui_NewGame.preferences; + + fp.bAIUpkeep = cbAIUpkeep.isSelected(); + fp.bAIDraw = cbAIDraw.isSelected(); + fp.bAIEOT = cbAIEndOfTurn.isSelected(); + fp.bAIBeginCombat = cbAIBeginCombat.isSelected(); + fp.bAIEndCombat = cbAIEndCombat.isSelected(); + + fp.bHumanUpkeep = cbHumanUpkeep.isSelected(); + fp.bHumanDraw = cbHumanDraw.isSelected(); + fp.bHumanEOT = cbHumanEndOfTurn.isSelected(); + fp.bHumanBeginCombat = cbHumanBeginCombat.isSelected(); + fp.bHumanEndCombat = cbHumanEndCombat.isSelected(); + + return true; + } + + public static JCheckBoxMenuItem playsoundCheckboxForMenu = new JCheckBoxMenuItem("Play Sound", false); + + // Phases + public static JCheckBoxMenuItem cbAIUpkeep = new JCheckBoxMenuItem("Upkeep", true); + public static JCheckBoxMenuItem cbAIDraw = new JCheckBoxMenuItem("Draw", true); + public static JCheckBoxMenuItem cbAIEndOfTurn = new JCheckBoxMenuItem("End of Turn", true); + public static JCheckBoxMenuItem cbAIBeginCombat = new JCheckBoxMenuItem("Begin Combat", true); + public static JCheckBoxMenuItem cbAIEndCombat = new JCheckBoxMenuItem("End Combat", true); + + public static JCheckBoxMenuItem cbHumanUpkeep = new JCheckBoxMenuItem("Upkeep", true); + public static JCheckBoxMenuItem cbHumanDraw = new JCheckBoxMenuItem("Draw", true); + public static JCheckBoxMenuItem cbHumanEndOfTurn = new JCheckBoxMenuItem("End of Turn", true); + public static JCheckBoxMenuItem cbHumanBeginCombat = new JCheckBoxMenuItem("Begin Combat", true); + public static JCheckBoxMenuItem cbHumanEndCombat = new JCheckBoxMenuItem("End Combat", true); + + // ********** End of Phase stuff in Display ****************** + + // ****** Developer Mode ******* + + public static JCheckBoxMenuItem canLoseByDecking = new JCheckBoxMenuItem("Lose by Decking", true); + + // ***************************** + + JXMultiSplitPane pane = new JXMultiSplitPane(); + JButton cancelButton = new JButton(); + JButton okButton = new JButton(); + JTextArea messageArea = new JTextArea(1, 10); + JTextArea combatArea = new JTextArea(); + JPanel stackPanel = new JPanel(); + JPanel oppLandPanel = new JPanel(); + JPanel oppCreaturePanel = new JPanel(); + JPanel playerCreaturePanel = new JPanel(); + JPanel playerLandPanel = new JPanel(); + JPanel playerHandPanel = new JPanel(); + JPanel cdPanel = new JPanel(); + JLabel oppLifeLabel = new JLabel(); + JLabel oppIconLabel = new JLabel(); + JLabel playerLifeLabel = new JLabel(); + JLabel oppPCLabel = new JLabel(); + JLabel playerPCLabel = new JLabel(); + JLabel oppLibraryLabel = new JLabel( + ForgeProps.getLocalized(COMPUTER_LIBRARY.BUTTON), + SwingConstants.TRAILING); + JLabel oppHandValue = new JLabel(); + JLabel oppLibraryValue = new JLabel(); + JLabel oppGraveValue = new JLabel(); + JLabel oppRemovedValue = new JLabel(); + JLabel playerHandValue = new JLabel(); + JLabel playerLibraryValue = new JLabel(); + JLabel playerGraveValue = new JLabel(); + JLabel playerFBValue = new JLabel(); + JLabel playerRemovedValue = new JLabel(); + + CardDetailPanel detail = new CardDetailPanel(null); + CardPicturePanel picture = new CardPicturePanel(null); + + private class ZoneAction extends ForgeAction { + private static final long serialVersionUID = -5822976087772388839L; + private PlayerZone zone; + private String title; + + public ZoneAction(PlayerZone zone, String property) { + super(property); + title = ForgeProps.getLocalized(property + "/title"); + this.zone = zone; + } + + public void actionPerformed(ActionEvent e) { + Card[] c = getCards(); + + if(AllZone.NameChanger.shouldChangeCardName()) c = AllZone.NameChanger.changeCard(c); + + if(c.length == 0) GuiUtils.getChoiceOptional(title, new String[] {"no cards"}); + else { + Card choice = GuiUtils.getChoiceOptional(title, c); + if(choice != null) doAction(choice); + } + } + + /* + protected PlayerZone getZone() { + return zone; + } + */ + protected Card[] getCards() { + return zone.getCards(); + } + + protected void doAction(Card c) {} + } + + private class ConcedeAction extends ForgeAction { + + private static final long serialVersionUID = -6976695235601916762L; + + public ConcedeAction() { + super(CONCEDE); + } + + public void actionPerformed(ActionEvent e) { + concede(); + } + } + + public boolean canLoseByDecking(){ + return canLoseByDecking.isSelected(); + } +} + +//very hacky + + +class Gui_MultipleBlockers3 extends JFrame { + private static final long serialVersionUID = 7622818310877381045L; + + private int assignDamage; + private Card att; + private CardList blockers; + private CardContainer guiDisplay; + + private BorderLayout borderLayout1 = new BorderLayout(); + private JPanel mainPanel = new JPanel(); + private JScrollPane jScrollPane1 = new JScrollPane(); + private JLabel numberLabel = new JLabel(); + private JPanel jPanel3 = new JPanel(); + private BorderLayout borderLayout3 = new BorderLayout(); + private JPanel creaturePanel = new JPanel(); + + + public static void main(String[] args) { + CardList list = new CardList(); + list.add(AllZone.CardFactory.getCard("Elvish Piper", null)); + list.add(AllZone.CardFactory.getCard("Lantern Kami", null)); + list.add(AllZone.CardFactory.getCard("Frostling", null)); + list.add(AllZone.CardFactory.getCard("Frostling", null)); + + for(int i = 0; i < 2; i++) + new Gui_MultipleBlockers3(null, list, i + 1, null); + } + + Gui_MultipleBlockers3(Card attacker, CardList creatureList, int damage, CardContainer display) { + this(); + assignDamage = damage; + updateDamageLabel();//update user message about assigning damage + guiDisplay = display; + att = attacker; + blockers = creatureList; + + for(int i = 0; i < creatureList.size(); i++) + creaturePanel.add(new CardPanel(creatureList.get(i))); + + if (att.getKeyword().contains("Trample")) { + Card player = new Card(); + player.setName("Player"); + player.addIntrinsicKeyword("Shroud"); + player.addIntrinsicKeyword("Indestructible"); + creaturePanel.add(new CardPanel(player)); + } + + JDialog dialog = new JDialog(this, true); + dialog.setTitle("Multiple Blockers"); + dialog.setContentPane(mainPanel); + dialog.setSize(470, 260); + dialog.setVisible(true); + } + + public Gui_MultipleBlockers3() { + try { + jbInit(); + } catch(Exception ex) { + ErrorViewer.showError(ex); + } +// setSize(470, 280); +// show(); + } + + private void jbInit() throws Exception { + this.getContentPane().setLayout(borderLayout1); + this.setTitle("Multiple Blockers"); + mainPanel.setLayout(null); + numberLabel.setHorizontalAlignment(SwingConstants.CENTER); + numberLabel.setHorizontalTextPosition(SwingConstants.CENTER); + numberLabel.setText("Assign"); + numberLabel.setBounds(new Rectangle(52, 30, 343, 24)); + jPanel3.setLayout(borderLayout3); + jPanel3.setBounds(new Rectangle(26, 75, 399, 114)); + creaturePanel.addMouseListener(new java.awt.event.MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + creaturePanel_mousePressed(e); + } + }); + creaturePanel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { + @Override + public void mouseMoved(MouseEvent e) { + creaturePanel_mouseMoved(e); + } + }); + mainPanel.add(jPanel3, null); + jPanel3.add(jScrollPane1, BorderLayout.CENTER); + mainPanel.add(numberLabel, null); + jScrollPane1.getViewport().add(creaturePanel, null); + this.getContentPane().add(mainPanel, BorderLayout.CENTER); + } + + void okButton_actionPerformed(ActionEvent e) { + dispose(); + } + + void creaturePanel_mousePressed(MouseEvent e) { + Object o = creaturePanel.getComponentAt(e.getPoint()); + if(o instanceof CardPanel) { + + boolean assignedDamage = true; + + CardContainer cardPanel = (CardContainer) o; + Card c = cardPanel.getCard(); + //c.setAssignedDamage(c.getAssignedDamage() + 1); + CardList cl = new CardList(); + cl.add(att); + + boolean assignedLethalDamageToAllBlockers = true; + for (Card crd : blockers ) + { + if (crd.getTotalAssignedDamage() < ( crd.getNetDefense() - crd.getDamage() )) + assignedLethalDamageToAllBlockers = false; + } + + + if (c.getName().equals("Player") && att.getKeyword().contains("Trample") && assignedLethalDamageToAllBlockers) + { + AllZone.Combat.addDefendingDamage(1, att); + c.addAssignedDamage(1, att); + } + else if (!c.getName().equals("Player")){ + c.addAssignedDamage(1, att); + } + else + assignedDamage = false; + + if (assignedDamage) + { + assignDamage--; + updateDamageLabel(); + if(assignDamage == 0) dispose(); + } + + if(guiDisplay != null) { + guiDisplay.setCard(c); + } + } + //reduce damage, show new user message, exit if necessary + + }//creaturePanel_mousePressed() + + void updateDamageLabel() { + numberLabel.setText("Assign " + assignDamage + " damage - click on card to assign damage"); + } + + void creaturePanel_mouseMoved(MouseEvent e) { + Object o = creaturePanel.getComponentAt(e.getPoint()); + if(o instanceof CardPanel) { + CardContainer cardPanel = (CardContainer) o; + Card c = cardPanel.getCard(); + + if(guiDisplay != null) { + guiDisplay.setCard(c); + } + } + } +} diff --git a/src/forge/GuiDisplay4.java b/src/forge/GuiDisplay4.java index aca0f9154eb..353cd4afd99 100644 --- a/src/forge/GuiDisplay4.java +++ b/src/forge/GuiDisplay4.java @@ -1,68 +1,6 @@ package forge; -import static org.jdesktop.swingx.MultiSplitLayout.parseModel; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.Frame; -import java.awt.GridLayout; -import java.awt.Insets; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseMotionAdapter; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.beans.XMLDecoder; -import java.beans.XMLEncoder; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Observable; -import java.util.Observer; - -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JLayeredPane; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSeparator; -import javax.swing.JTextArea; -import javax.swing.ScrollPaneConstants; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.border.Border; -import javax.swing.border.EmptyBorder; -import javax.swing.border.EtchedBorder; -import javax.swing.border.TitledBorder; - -import org.jdesktop.swingx.JXMultiSplitPane; -import org.jdesktop.swingx.MultiSplitLayout.Node; - import arcane.ui.HandArea; import arcane.ui.PlayArea; import arcane.ui.ViewPanel; @@ -75,6 +13,24 @@ import forge.gui.game.CardPanel; import forge.properties.ForgePreferences; import forge.properties.ForgeProps; import forge.properties.NewConstants; +import org.jdesktop.swingx.JXMultiSplitPane; +import org.jdesktop.swingx.MultiSplitLayout.Node; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; +import java.awt.*; +import java.awt.Color; +import java.awt.event.*; +import java.beans.XMLDecoder; +import java.beans.XMLEncoder; +import java.io.*; +import java.util.*; +import java.util.List; + +import static org.jdesktop.swingx.MultiSplitLayout.parseModel; public class GuiDisplay4 extends JFrame implements CardContainer, Display, NewConstants, NewConstants.GUI.GuiDisplay, NewConstants.LANG.GuiDisplay { @@ -995,15 +951,15 @@ public class GuiDisplay4 extends JFrame implements CardContainer, Display, NewCo private void concede() { savePrefs(); dispose(); - Constant.Runtime.WinLose.addLose(); + Constant.Runtime.matchState.addLose(); if (!Constant.Quest.fantasyQuest[0]) new Gui_WinLose(); else { //new Gui_WinLose(Constant.Quest.humanList[0], Constant.Quest.computerList[0],Constant.Quest.humanLife[0], Constant.Quest.computerLife[0]); - CardList humanList = QuestUtil.getHumanPlantAndPet(AllZone.QuestData, AllZone.QuestAssignment); - CardList computerList = QuestUtil.getComputerCreatures(AllZone.QuestData, AllZone.QuestAssignment); + CardList humanList = forge.quest.data.QuestUtil.getHumanPlantAndPet(AllZone.QuestData, AllZone.QuestAssignment); + CardList computerList = forge.quest.data.QuestUtil.getComputerCreatures(AllZone.QuestData, AllZone.QuestAssignment); - int humanLife = QuestUtil.getLife(AllZone.QuestData); + int humanLife = AllZone.QuestData.getLife(); int computerLife = 20; if (AllZone.QuestAssignment!=null) diff --git a/src/forge/Gui_CardShop.java b/src/forge/Gui_CardShop.java index a2d0cd1a9e4..7cf5116036b 100644 --- a/src/forge/Gui_CardShop.java +++ b/src/forge/Gui_CardShop.java @@ -2,45 +2,26 @@ package forge; -import java.awt.Color; -import java.awt.Component; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.GridLayout; -import java.awt.Image; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Map; -import java.util.Random; +import forge.error.ErrorViewer; +import forge.gui.game.CardDetailPanel; +import forge.gui.game.CardPicturePanel; +import forge.properties.NewConstants; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.SwingUtilities; +import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; import javax.swing.event.MouseInputListener; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.TableCellRenderer; - -import forge.error.ErrorViewer; -import forge.gui.game.CardDetailPanel; -import forge.gui.game.CardPicturePanel; -import forge.properties.NewConstants; +import java.awt.Color; +import java.awt.*; +import java.awt.event.*; +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Map; +import java.util.Random; public class Gui_CardShop extends JFrame implements CardContainer, DeckDisplay, NewConstants { @@ -84,7 +65,7 @@ public class Gui_CardShop extends JFrame implements CardContainer, DeckDisplay, private CardPicturePanel picture = new CardPicturePanel(null); private JPanel glassPane; - private QuestData questData; + private forge.quest.data.QuestData questData; @Override public void setTitle(String message) { super.setTitle(message); @@ -281,49 +262,57 @@ public class Gui_CardShop extends JFrame implements CardContainer, DeckDisplay, } else //grab existing shopList { - ArrayList shopList = questData.getShopList(); + java.util.List shopList = questData.getShopList(); shop = new CardList(); - - for(int i = 0; i < shopList.size(); i++) { - Card c = AllZone.CardFactory.getCard(shopList.get(i).toString(), null); - c.setRarity(pack.getRarity(c.getName())); - if (map.containsKey(c.getName())) - c.setValue(map.get(c.getName())); - else //card is not on pricelist - { - System.out.println("Card " + c.getName() + " is not in the price list."); - if (c.getRarity().equals("Common")) - c.setValue(10); - else if (c.getRarity().equals("Uncommon")) - c.setValue(50); - else if (c.getRarity().equals("Rare")) - c.setValue(200); - } - - shop.add(c); - } + + for (String aShopList : shopList) { + Card c = AllZone.CardFactory.getCard(aShopList, null); + c.setRarity(pack.getRarity(c.getName())); + if (map.containsKey(c.getName())) { + c.setValue(map.get(c.getName())); + } + else //card is not on pricelist + { + System.out.println("Card " + c.getName() + " is not in the price list."); + if (c.getRarity().equals("Common")) { + c.setValue(10); + } + else if (c.getRarity().equals("Uncommon")) { + c.setValue(50); + } + else if (c.getRarity().equals("Rare")) { + c.setValue(200); + } + } + + shop.add(c); + } } - ArrayList list = questData.getCardpool(); + java.util.List list = questData.getCardpool(); CardList owned = new CardList(); - - for(int i = 0; i < list.size(); i++) { - Card c = AllZone.CardFactory.getCard(list.get(i).toString(), null); - + + for (String aList : list) { + Card c = AllZone.CardFactory.getCard(aList, null); + c.setRarity(pack.getRarity(c.getName())); - if (map.containsKey(c.getName())) - c.setValue(map.get(c.getName())); + if (map.containsKey(c.getName())) { + c.setValue(map.get(c.getName())); + } else //card is not on pricelist { - System.out.println("Card " + c.getName() + " is not in the price list."); - if (c.getRarity().equals("Common")) - c.setValue(10); - else if (c.getRarity().equals("Uncommon")) - c.setValue(50); - else if (c.getRarity().equals("Rare")) - c.setValue(200); + System.out.println("Card " + c.getName() + " is not in the price list."); + if (c.getRarity().equals("Common")) { + c.setValue(10); + } + else if (c.getRarity().equals("Uncommon")) { + c.setValue(50); + } + else if (c.getRarity().equals("Rare")) { + c.setValue(200); + } } - owned.add(c); + owned.add(c); } customMenu.populateShop(shop, owned); @@ -402,7 +391,7 @@ public class Gui_CardShop extends JFrame implements CardContainer, DeckDisplay, if (multi > 0.6) multi = 0.6; - if (questData.getMode().equals(QuestData.FANTASY)) + if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { if (questData.getEstatesLevel()==1) multi+=0.01; @@ -443,7 +432,7 @@ public class Gui_CardShop extends JFrame implements CardContainer, DeckDisplay, // setExtendedState(Frame.MAXIMIZED_BOTH); }//setupAndDisplay() - public Gui_CardShop(QuestData qd) { + public Gui_CardShop(forge.quest.data.QuestData qd) { questData = qd; try { jbInit(); @@ -625,7 +614,7 @@ public class Gui_CardShop extends JFrame implements CardContainer, DeckDisplay, creditsLabel.setText("Total credits: " + questData.getCredits()); //remove sold cards from all decks: - ArrayList deckNames = questData.getDeckNames(); + java.util.List deckNames = questData.getDeckNames(); for (String deckName:deckNames) { Deck deck = questData.getDeck(deckName); @@ -633,7 +622,7 @@ public class Gui_CardShop extends JFrame implements CardContainer, DeckDisplay, { //count occurences: int cardPoolCount = 0; - ArrayList cpList = questData.getCards(); + java.util.List cpList = questData.getCards(); while(cpList.contains(c.getName())) { cpList.remove(cpList.indexOf(c.getName())); diff --git a/src/forge/Gui_ElixirShop.java b/src/forge/Gui_ElixirShop.java index 79bba0b114a..0f1ace3eb86 100644 --- a/src/forge/Gui_ElixirShop.java +++ b/src/forge/Gui_ElixirShop.java @@ -1,221 +1,216 @@ -package forge; - -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; -import java.io.File; - -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.SwingConstants; - -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - -public class Gui_ElixirShop extends JFrame implements NewConstants{ - - private static final long serialVersionUID = 2409591658245091210L; - - private JFrame shopsGUI; - private JLabel titleLabel = new JLabel(); - - private JLabel potionDescLabel = new JLabel(); - private JLabel potionStatsLabel = new JLabel(); - private JLabel potionPriceLabel = new JLabel(); - private JLabel potionIconLabel = new JLabel(); - - private JLabel creditsLabel = new JLabel(); - - private ImageIcon potionIcon = new ImageIcon(); - - private JButton buyPotionButton = new JButton(); - private JButton quitButton = new JButton(); - - private QuestData questData = AllZone.QuestData; - - public Gui_ElixirShop(JFrame parent) { - try { - jbInit(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - } - - shopsGUI = parent; - - setup(); - - //for some reason, the Bazaar window does not return when closing with X - //for now, just disable X closing: - this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - - Dimension screen = this.getToolkit().getScreenSize(); - setBounds(screen.width / 3, 100, //position - 530, 430); //size - setVisible(true); - - - } - - //only do this ONCE: - private void setup() { - buyPotionButton.setBounds(new Rectangle(10, 297, 120, 50)); - buyPotionButton.setText(getButtonText()); - //buyPlantButton.setIcon(icon); - buyPotionButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - buyPotionButton_actionPerformed(e); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - }); - - }//setup(); - - private String getDesc() - { - StringBuilder sb = new StringBuilder(); - sb.append(""); - - sb.append("Gives +1 to max Life.
"); - sb.append("Current life:" + questData.getLife()); - - sb.append(""); - return sb.toString(); - } - - private long getPrice() - { - long l = 0; - if (questData.getLife() < 20) - l = 250; - else if (questData.getLife() < 25) - l = 500; - else - l = 750; - - return l; - } - - private String getButtonText() - { - return "Buy Elixir"; - } - - private String getStats() - { - return "Elixir of Health"; - } - - private String getImageString() - { - return "ElixirIcon.png"; - } - - private void jbInit() throws Exception { - titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); - titleLabel.setHorizontalAlignment(SwingConstants.CENTER); - titleLabel.setText("Apothecary"); - titleLabel.setBounds(new Rectangle(130, 5, 198, 60)); - this.getContentPane().setLayout(null); - - potionStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); - potionStatsLabel.setText(getStats()); - potionStatsLabel.setBounds(new Rectangle(10, 65, 100, 15)); - - potionDescLabel.setFont(new Font("sserif", 0, 12)); - potionDescLabel.setText(getDesc()); - potionDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); - - potionPriceLabel.setFont(new Font("sserif", 0, 12)); - potionPriceLabel.setText("Price: " + getPrice() + " credits"); - potionPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); - - creditsLabel.setFont(new Font("sserif", 0, 12)); - creditsLabel.setText("Credits: " + questData.getCredits()); - creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); - - potionIcon = getIcon(getImageString()); - potionIconLabel.setText(""); - potionIconLabel.setIcon(potionIcon); - potionIconLabel.setBounds(new Rectangle(280, 65, 201, 280)); - potionIconLabel.setIconTextGap(0); - - //String fileName = "LeafIconSmall.png"; - //ImageIcon icon = getIcon(fileName); - - buyPotionButton.setEnabled(true); - if (questData.getCredits() < getPrice() || questData.getLife() >= 30) - buyPotionButton.setEnabled(false); - - quitButton.setBounds(new Rectangle(140, 297, 120, 50)); - quitButton.setText("Quit"); - quitButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - quitButton_actionPerformed(e); - } - }); - - - //jPanel2.add(quitButton, null); - this.getContentPane().add(buyPotionButton, null); - this.getContentPane().add(titleLabel, null); - this.getContentPane().add(potionStatsLabel, null); - this.getContentPane().add(potionDescLabel, null); - this.getContentPane().add(potionIconLabel, null); - this.getContentPane().add(potionPriceLabel, null); - this.getContentPane().add(creditsLabel, null); - this.getContentPane().add(quitButton,null); - } - - void editDeckButton_actionPerformed(ActionEvent e) { - Command exit = new Command() { - private static final long serialVersionUID = 4735992294414389187L; - - public void execute() { - new Gui_WinLose(); - } - }; - Gui_DeckEditor editor = new Gui_DeckEditor(); - - editor.show(exit); - - dispose(); - }//editDeckButton_actionPerformed() - - void buyPotionButton_actionPerformed(ActionEvent e) throws Exception { - questData.subtractCredits(getPrice()); - questData.addLife(1); - QuestData.saveData(questData); - jbInit(); - } - - private ImageIcon getIcon(String fileName) - { - File base = ForgeProps.getFile(IMAGE_ICON); - File file = new File(base, fileName); - ImageIcon icon = new ImageIcon(file.toString()); - return icon; - } - - void quitButton_actionPerformed(ActionEvent e) { - QuestData.saveData(questData); - //new Gui_Shops(); - shopsGUI.setVisible(true); - - dispose(); - - } - - void this_windowClosing(WindowEvent e) { - quitButton_actionPerformed(null); - } - -} +package forge; + +import forge.error.ErrorViewer; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; + +import javax.swing.*; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.WindowEvent; +import java.io.File; + +public class Gui_ElixirShop extends JFrame implements NewConstants{ + + private static final long serialVersionUID = 2409591658245091210L; + + private JFrame shopsGUI; + private JLabel titleLabel = new JLabel(); + + private JLabel potionDescLabel = new JLabel(); + private JLabel potionStatsLabel = new JLabel(); + private JLabel potionPriceLabel = new JLabel(); + private JLabel potionIconLabel = new JLabel(); + + private JLabel creditsLabel = new JLabel(); + + private ImageIcon potionIcon = new ImageIcon(); + + private JButton buyPotionButton = new JButton(); + private JButton quitButton = new JButton(); + + private forge.quest.data.QuestData questData = AllZone.QuestData; + + public Gui_ElixirShop(JFrame parent) { + try { + jbInit(); + } catch(Exception ex) { + ErrorViewer.showError(ex); + } + + shopsGUI = parent; + + setup(); + + //for some reason, the Bazaar window does not return when closing with X + //for now, just disable X closing: + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + + Dimension screen = this.getToolkit().getScreenSize(); + setBounds(screen.width / 3, 100, //position + 530, 430); //size + setVisible(true); + + + } + + //only do this ONCE: + private void setup() { + buyPotionButton.setBounds(new Rectangle(10, 297, 120, 50)); + buyPotionButton.setText(getButtonText()); + //buyPlantButton.setIcon(icon); + buyPotionButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + buyPotionButton_actionPerformed(e); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + + }//setup(); + + private String getDesc() + { + StringBuilder sb = new StringBuilder(); + sb.append(""); + + sb.append("Gives +1 to max Life.
"); + sb.append("Current life:" + questData.getLife()); + + sb.append(""); + return sb.toString(); + } + + private long getPrice() + { + long l = 0; + if (questData.getLife() < 20) + l = 250; + else if (questData.getLife() < 25) + l = 500; + else + l = 750; + + return l; + } + + private String getButtonText() + { + return "Buy Elixir"; + } + + private String getStats() + { + return "Elixir of Health"; + } + + private String getImageString() + { + return "ElixirIcon.png"; + } + + private void jbInit() throws Exception { + titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); + titleLabel.setHorizontalAlignment(SwingConstants.CENTER); + titleLabel.setText("Apothecary"); + titleLabel.setBounds(new Rectangle(130, 5, 198, 60)); + this.getContentPane().setLayout(null); + + potionStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); + potionStatsLabel.setText(getStats()); + potionStatsLabel.setBounds(new Rectangle(10, 65, 100, 15)); + + potionDescLabel.setFont(new Font("sserif", 0, 12)); + potionDescLabel.setText(getDesc()); + potionDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); + + potionPriceLabel.setFont(new Font("sserif", 0, 12)); + potionPriceLabel.setText("Price: " + getPrice() + " credits"); + potionPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); + + creditsLabel.setFont(new Font("sserif", 0, 12)); + creditsLabel.setText("Credits: " + questData.getCredits()); + creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); + + potionIcon = getIcon(getImageString()); + potionIconLabel.setText(""); + potionIconLabel.setIcon(potionIcon); + potionIconLabel.setBounds(new Rectangle(280, 65, 201, 280)); + potionIconLabel.setIconTextGap(0); + + //String fileName = "LeafIconSmall.png"; + //ImageIcon icon = getIcon(fileName); + + buyPotionButton.setEnabled(true); + if (questData.getCredits() < getPrice() || questData.getLife() >= 30) + buyPotionButton.setEnabled(false); + + quitButton.setBounds(new Rectangle(140, 297, 120, 50)); + quitButton.setText("Quit"); + quitButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + quitButton_actionPerformed(e); + } + }); + + + //jPanel2.add(quitButton, null); + this.getContentPane().add(buyPotionButton, null); + this.getContentPane().add(titleLabel, null); + this.getContentPane().add(potionStatsLabel, null); + this.getContentPane().add(potionDescLabel, null); + this.getContentPane().add(potionIconLabel, null); + this.getContentPane().add(potionPriceLabel, null); + this.getContentPane().add(creditsLabel, null); + this.getContentPane().add(quitButton,null); + } + + void editDeckButton_actionPerformed(ActionEvent e) { + Command exit = new Command() { + private static final long serialVersionUID = 4735992294414389187L; + + public void execute() { + new Gui_WinLose(); + } + }; + Gui_DeckEditor editor = new Gui_DeckEditor(); + + editor.show(exit); + + dispose(); + }//editDeckButton_actionPerformed() + + void buyPotionButton_actionPerformed(ActionEvent e) throws Exception { + questData.subtractCredits(getPrice()); + questData.addLife(1); + questData.saveData(); + jbInit(); + } + + private ImageIcon getIcon(String fileName) + { + File base = ForgeProps.getFile(IMAGE_ICON); + File file = new File(base, fileName); + ImageIcon icon = new ImageIcon(file.toString()); + return icon; + } + + void quitButton_actionPerformed(ActionEvent e) { + questData.saveData(); + //new Gui_Shops(); + shopsGUI.setVisible(true); + + dispose(); + + } + + void this_windowClosing(WindowEvent e) { + quitButton_actionPerformed(null); + } + +} diff --git a/src/forge/Gui_Gear.java b/src/forge/Gui_Gear.java index 739aaceafda..34f1c6d66fb 100644 --- a/src/forge/Gui_Gear.java +++ b/src/forge/Gui_Gear.java @@ -1,222 +1,217 @@ -package forge; - -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; -import java.io.File; - -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.SwingConstants; - -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - -public class Gui_Gear extends JFrame implements NewConstants{ - - private static final long serialVersionUID = -2124386606846472829L; - - private JFrame shopsGUI; - private JLabel titleLabel = new JLabel(); - - private JLabel gearDescLabel = new JLabel(); - - private JLabel gearPriceLabel = new JLabel(); - private JLabel gearIconLabel = new JLabel(); - - private JLabel creditsLabel = new JLabel(); - - private ImageIcon gearIcon = new ImageIcon(); - - private JButton gearButton = new JButton(); - private JButton quitButton = new JButton(); - - private QuestData questData = AllZone.QuestData; - - public Gui_Gear(JFrame parent) { - try { - jbInit(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - } - - shopsGUI = parent; - - setup(); - - //for some reason, the Bazaar window does not return when closing with X - //for now, just disable X closing: - this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - - Dimension screen = this.getToolkit().getScreenSize(); - setBounds(screen.width / 3, 100, //position - 530, 430); //size - setVisible(true); - - - } - - //only do this ONCE: - private void setup() { - gearButton.setBounds(new Rectangle(10, 297, 120, 50)); - gearButton.setText(getButtonText()); - //buyPlantButton.setIcon(icon); - gearButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - learnEstatesButton_actionPerformed(e); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - }); - - }//setup(); - - private String getDesc() - { - StringBuilder sb = new StringBuilder(); - sb.append(""); - - if (questData.getGearLevel() == 0) - { - sb.append("Adventurer's Map
"); - sb.append("These ancient charts should facilitate navigation during your travels significantly.
"); - sb.append("Quest assignments become available more frequently."); - } - else if (questData.getGearLevel() == 1) - { - sb.append("Adventurer's Zeppelin
"); - sb.append("This extremely comfortable airship allows for more efficient and safe travel to faraway destinations.
"); - sb.append("Quest assignments become available more frequently, adds +3 to max life."); - } - else - { - sb.append("Currently nothing for sale.
Please check back later."); - } - - sb.append(""); - return sb.toString(); - } - - private long getPrice() - { - long l = 0; - if (questData.getGearLevel() == 0) - l = 2000; - else if (questData.getGearLevel() == 1) - l = 5000; - - return l; - } - - private String getButtonText() - { - return "Buy"; - } - - private String getImageString() - { - if (questData.getGearLevel() == 0) - return "MapIconLarge.png"; - else if (questData.getGearLevel() == 1) - return "ZeppelinIcon.png"; - - return ""; - } - - private void jbInit() throws Exception { - titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); - titleLabel.setHorizontalAlignment(SwingConstants.CENTER); - titleLabel.setText("Adventurer's Gear"); - titleLabel.setBounds(new Rectangle(155, 5, 198, 60)); - this.getContentPane().setLayout(null); - - /* - potionStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); - potionStatsLabel.setText(getStats()); - potionStatsLabel.setBounds(new Rectangle(10, 65, 100, 15)); - */ - - gearDescLabel.setFont(new Font("sserif", 0, 12)); - gearDescLabel.setText(getDesc()); - gearDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); - - gearPriceLabel.setFont(new Font("sserif", 0, 12)); - gearPriceLabel.setText("Price: " + getPrice() + " credits"); - gearPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); - - creditsLabel.setFont(new Font("sserif", 0, 12)); - creditsLabel.setText("Credits: " + questData.getCredits()); - creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); - - gearIcon = getIcon(getImageString()); - gearIconLabel.setText(""); - gearIconLabel.setIcon(gearIcon); - gearIconLabel.setBounds(new Rectangle(325, 100, 128, 128)); - gearIconLabel.setIconTextGap(0); - - //String fileName = "LeafIconSmall.png"; - //ImageIcon icon = getIcon(fileName); - - gearButton.setEnabled(true); - if (questData.getCredits() < getPrice() || questData.getGearLevel() >= 2) - gearButton.setEnabled(false); - - quitButton.setBounds(new Rectangle(140, 297, 120, 50)); - quitButton.setText("Quit"); - quitButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - quitButton_actionPerformed(e); - } - }); - - //jPanel2.add(quitButton, null); - this.getContentPane().add(gearButton, null); - this.getContentPane().add(titleLabel, null); - this.getContentPane().add(gearDescLabel, null); - this.getContentPane().add(gearIconLabel, null); - this.getContentPane().add(gearPriceLabel, null); - this.getContentPane().add(creditsLabel, null); - this.getContentPane().add(quitButton,null); - } - - void learnEstatesButton_actionPerformed(ActionEvent e) throws Exception { - questData.subtractCredits(getPrice()); - - if (questData.getGearLevel() < 2) - { - questData.addGearLevel(1); - } - QuestData.saveData(questData); - jbInit(); - } - - private ImageIcon getIcon(String fileName) - { - File base = ForgeProps.getFile(IMAGE_ICON); - File file = new File(base, fileName); - ImageIcon icon = new ImageIcon(file.toString()); - return icon; - } - - void quitButton_actionPerformed(ActionEvent e) { - QuestData.saveData(questData); - //new Gui_Shops(); - shopsGUI.setVisible(true); - - dispose(); - - } - - void this_windowClosing(WindowEvent e) { - quitButton_actionPerformed(null); - } - -} +package forge; + +import forge.error.ErrorViewer; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; + +import javax.swing.*; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.WindowEvent; +import java.io.File; + +public class Gui_Gear extends JFrame implements NewConstants{ + + private static final long serialVersionUID = -2124386606846472829L; + + private JFrame shopsGUI; + private JLabel titleLabel = new JLabel(); + + private JLabel gearDescLabel = new JLabel(); + + private JLabel gearPriceLabel = new JLabel(); + private JLabel gearIconLabel = new JLabel(); + + private JLabel creditsLabel = new JLabel(); + + private ImageIcon gearIcon = new ImageIcon(); + + private JButton gearButton = new JButton(); + private JButton quitButton = new JButton(); + + private forge.quest.data.QuestData questData = AllZone.QuestData; + + public Gui_Gear(JFrame parent) { + try { + jbInit(); + } catch(Exception ex) { + ErrorViewer.showError(ex); + } + + shopsGUI = parent; + + setup(); + + //for some reason, the Bazaar window does not return when closing with X + //for now, just disable X closing: + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + + Dimension screen = this.getToolkit().getScreenSize(); + setBounds(screen.width / 3, 100, //position + 530, 430); //size + setVisible(true); + + + } + + //only do this ONCE: + private void setup() { + gearButton.setBounds(new Rectangle(10, 297, 120, 50)); + gearButton.setText(getButtonText()); + //buyPlantButton.setIcon(icon); + gearButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + learnEstatesButton_actionPerformed(e); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + + }//setup(); + + private String getDesc() + { + StringBuilder sb = new StringBuilder(); + sb.append(""); + + if (questData.getGearLevel() == 0) + { + sb.append("Adventurer's Map
"); + sb.append("These ancient charts should facilitate navigation during your travels significantly.
"); + sb.append("Quest assignments become available more frequently."); + } + else if (questData.getGearLevel() == 1) + { + sb.append("Adventurer's Zeppelin
"); + sb.append("This extremely comfortable airship allows for more efficient and safe travel to faraway destinations.
"); + sb.append("Quest assignments become available more frequently, adds +3 to max life."); + } + else + { + sb.append("Currently nothing for sale.
Please check back later."); + } + + sb.append(""); + return sb.toString(); + } + + private long getPrice() + { + long l = 0; + if (questData.getGearLevel() == 0) + l = 2000; + else if (questData.getGearLevel() == 1) + l = 5000; + + return l; + } + + private String getButtonText() + { + return "Buy"; + } + + private String getImageString() + { + if (questData.getGearLevel() == 0) + return "MapIconLarge.png"; + else if (questData.getGearLevel() == 1) + return "ZeppelinIcon.png"; + + return ""; + } + + private void jbInit() throws Exception { + titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); + titleLabel.setHorizontalAlignment(SwingConstants.CENTER); + titleLabel.setText("Adventurer's Gear"); + titleLabel.setBounds(new Rectangle(155, 5, 198, 60)); + this.getContentPane().setLayout(null); + + /* + potionStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); + potionStatsLabel.setText(getStats()); + potionStatsLabel.setBounds(new Rectangle(10, 65, 100, 15)); + */ + + gearDescLabel.setFont(new Font("sserif", 0, 12)); + gearDescLabel.setText(getDesc()); + gearDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); + + gearPriceLabel.setFont(new Font("sserif", 0, 12)); + gearPriceLabel.setText("Price: " + getPrice() + " credits"); + gearPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); + + creditsLabel.setFont(new Font("sserif", 0, 12)); + creditsLabel.setText("Credits: " + questData.getCredits()); + creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); + + gearIcon = getIcon(getImageString()); + gearIconLabel.setText(""); + gearIconLabel.setIcon(gearIcon); + gearIconLabel.setBounds(new Rectangle(325, 100, 128, 128)); + gearIconLabel.setIconTextGap(0); + + //String fileName = "LeafIconSmall.png"; + //ImageIcon icon = getIcon(fileName); + + gearButton.setEnabled(true); + if (questData.getCredits() < getPrice() || questData.getGearLevel() >= 2) + gearButton.setEnabled(false); + + quitButton.setBounds(new Rectangle(140, 297, 120, 50)); + quitButton.setText("Quit"); + quitButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + quitButton_actionPerformed(e); + } + }); + + //jPanel2.add(quitButton, null); + this.getContentPane().add(gearButton, null); + this.getContentPane().add(titleLabel, null); + this.getContentPane().add(gearDescLabel, null); + this.getContentPane().add(gearIconLabel, null); + this.getContentPane().add(gearPriceLabel, null); + this.getContentPane().add(creditsLabel, null); + this.getContentPane().add(quitButton,null); + } + + void learnEstatesButton_actionPerformed(ActionEvent e) throws Exception { + questData.subtractCredits(getPrice()); + + if (questData.getGearLevel() < 2) + { + questData.addGearLevel(1); + } + questData.saveData(); + jbInit(); + } + + private ImageIcon getIcon(String fileName) + { + File base = ForgeProps.getFile(IMAGE_ICON); + File file = new File(base, fileName); + ImageIcon icon = new ImageIcon(file.toString()); + return icon; + } + + void quitButton_actionPerformed(ActionEvent e) { + questData.saveData(); + //new Gui_Shops(); + shopsGUI.setVisible(true); + + dispose(); + + } + + void this_windowClosing(WindowEvent e) { + quitButton_actionPerformed(null); + } + +} diff --git a/src/forge/Gui_Library.java b/src/forge/Gui_Library.java index bb9d230592b..423b9a3b487 100644 --- a/src/forge/Gui_Library.java +++ b/src/forge/Gui_Library.java @@ -1,210 +1,205 @@ -package forge; - -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; -import java.io.File; - -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.SwingConstants; - -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - -public class Gui_Library extends JFrame implements NewConstants{ - - private static final long serialVersionUID = 2409591658245091210L; - - private JFrame shopsGUI; - private JLabel titleLabel = new JLabel(); - - private JLabel sleightOfHandDescLabel = new JLabel(); - - private JLabel sleightOfHandPriceLabel = new JLabel(); - private JLabel sleightOfHandIconLabel = new JLabel(); - - private JLabel creditsLabel = new JLabel(); - - private ImageIcon sleightOfHandIcon = new ImageIcon(); - - private JButton sleightOfHandButton= new JButton(); - private JButton quitButton = new JButton(); - - private QuestData questData = AllZone.QuestData; - - public Gui_Library(JFrame parent) { - try { - jbInit(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - } - - shopsGUI = parent; - - setup(); - - //for some reason, the Bazaar window does not return when closing with X - //for now, just disable X closing: - this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - - Dimension screen = this.getToolkit().getScreenSize(); - setBounds(screen.width / 3, 100, //position - 530, 430); //size - setVisible(true); - - - } - - //only do this ONCE: - private void setup() { - sleightOfHandButton.setBounds(new Rectangle(10, 297, 120, 50)); - sleightOfHandButton.setText(getButtonText()); - //buyPlantButton.setIcon(icon); - sleightOfHandButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - learnEstatesButton_actionPerformed(e); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - }); - - }//setup(); - - private String getDesc() - { - StringBuilder sb = new StringBuilder(); - sb.append(""); - - if (questData.getSleightOfHandLevel() == 0) - { - sb.append("Sleight of Hand Vol. I
"); - sb.append("These volumes explain how to perform the most difficult of sleights.
"); - sb.append("Your first mulligan is free."); - } - else - { - sb.append("Currently nothing to study at the Library.
Please check back later."); - } - - sb.append(""); - return sb.toString(); - } - - private long getPrice() - { - long l = 0; - if (questData.getSleightOfHandLevel() == 0) - l = 2000; - - return l; - } - - private String getButtonText() - { - return "Learn Sleight"; - } - - private String getImageString() - { - return "BookIcon.png"; - } - - private void jbInit() throws Exception { - titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); - titleLabel.setHorizontalAlignment(SwingConstants.CENTER); - titleLabel.setText("Library"); - titleLabel.setBounds(new Rectangle(130, 5, 198, 60)); - this.getContentPane().setLayout(null); - - /* - potionStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); - potionStatsLabel.setText(getStats()); - potionStatsLabel.setBounds(new Rectangle(10, 65, 100, 15)); - */ - - sleightOfHandDescLabel.setFont(new Font("sserif", 0, 12)); - sleightOfHandDescLabel.setText(getDesc()); - sleightOfHandDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); - - sleightOfHandPriceLabel.setFont(new Font("sserif", 0, 12)); - sleightOfHandPriceLabel.setText("Price: " + getPrice() + " credits"); - sleightOfHandPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); - - creditsLabel.setFont(new Font("sserif", 0, 12)); - creditsLabel.setText("Credits: " + questData.getCredits()); - creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); - - sleightOfHandIcon = getIcon(getImageString()); - sleightOfHandIconLabel.setText(""); - sleightOfHandIconLabel.setIcon(sleightOfHandIcon); - sleightOfHandIconLabel.setBounds(new Rectangle(300, 135, 128, 128)); - sleightOfHandIconLabel.setIconTextGap(0); - - //String fileName = "LeafIconSmall.png"; - //ImageIcon icon = getIcon(fileName); - - sleightOfHandButton.setEnabled(true); - if (questData.getCredits() < getPrice() || questData.getSleightOfHandLevel() >= 1) - sleightOfHandButton.setEnabled(false); - - quitButton.setBounds(new Rectangle(140, 297, 120, 50)); - quitButton.setText("Quit"); - quitButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - quitButton_actionPerformed(e); - } - }); - - - //jPanel2.add(quitButton, null); - this.getContentPane().add(sleightOfHandButton, null); - this.getContentPane().add(titleLabel, null); - this.getContentPane().add(sleightOfHandDescLabel, null); - this.getContentPane().add(sleightOfHandIconLabel, null); - this.getContentPane().add(sleightOfHandPriceLabel, null); - this.getContentPane().add(creditsLabel, null); - this.getContentPane().add(quitButton,null); - } - - void learnEstatesButton_actionPerformed(ActionEvent e) throws Exception { - questData.subtractCredits(getPrice()); - - if (questData.getSleightOfHandLevel() < 1) - { - questData.addSleightOfHandLevel(1); - } - QuestData.saveData(questData); - jbInit(); - } - - private ImageIcon getIcon(String fileName) - { - File base = ForgeProps.getFile(IMAGE_ICON); - File file = new File(base, fileName); - ImageIcon icon = new ImageIcon(file.toString()); - return icon; - } - - void quitButton_actionPerformed(ActionEvent e) { - QuestData.saveData(questData); - //new Gui_Shops(); - shopsGUI.setVisible(true); - - dispose(); - - } - - void this_windowClosing(WindowEvent e) { - quitButton_actionPerformed(null); - } - -} +package forge; + +import forge.error.ErrorViewer; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; + +import javax.swing.*; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.WindowEvent; +import java.io.File; + +public class Gui_Library extends JFrame implements NewConstants{ + + private static final long serialVersionUID = 2409591658245091210L; + + private JFrame shopsGUI; + private JLabel titleLabel = new JLabel(); + + private JLabel sleightOfHandDescLabel = new JLabel(); + + private JLabel sleightOfHandPriceLabel = new JLabel(); + private JLabel sleightOfHandIconLabel = new JLabel(); + + private JLabel creditsLabel = new JLabel(); + + private ImageIcon sleightOfHandIcon = new ImageIcon(); + + private JButton sleightOfHandButton= new JButton(); + private JButton quitButton = new JButton(); + + private forge.quest.data.QuestData questData = AllZone.QuestData; + + public Gui_Library(JFrame parent) { + try { + jbInit(); + } catch(Exception ex) { + ErrorViewer.showError(ex); + } + + shopsGUI = parent; + + setup(); + + //for some reason, the Bazaar window does not return when closing with X + //for now, just disable X closing: + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + + Dimension screen = this.getToolkit().getScreenSize(); + setBounds(screen.width / 3, 100, //position + 530, 430); //size + setVisible(true); + + + } + + //only do this ONCE: + private void setup() { + sleightOfHandButton.setBounds(new Rectangle(10, 297, 120, 50)); + sleightOfHandButton.setText(getButtonText()); + //buyPlantButton.setIcon(icon); + sleightOfHandButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + learnEstatesButton_actionPerformed(e); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + + }//setup(); + + private String getDesc() + { + StringBuilder sb = new StringBuilder(); + sb.append(""); + + if (questData.getSleightOfHandLevel() == 0) + { + sb.append("Sleight of Hand Vol. I
"); + sb.append("These volumes explain how to perform the most difficult of sleights.
"); + sb.append("Your first mulligan is free."); + } + else + { + sb.append("Currently nothing to study at the Library.
Please check back later."); + } + + sb.append(""); + return sb.toString(); + } + + private long getPrice() + { + long l = 0; + if (questData.getSleightOfHandLevel() == 0) + l = 2000; + + return l; + } + + private String getButtonText() + { + return "Learn Sleight"; + } + + private String getImageString() + { + return "BookIcon.png"; + } + + private void jbInit() throws Exception { + titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); + titleLabel.setHorizontalAlignment(SwingConstants.CENTER); + titleLabel.setText("Library"); + titleLabel.setBounds(new Rectangle(130, 5, 198, 60)); + this.getContentPane().setLayout(null); + + /* + potionStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); + potionStatsLabel.setText(getStats()); + potionStatsLabel.setBounds(new Rectangle(10, 65, 100, 15)); + */ + + sleightOfHandDescLabel.setFont(new Font("sserif", 0, 12)); + sleightOfHandDescLabel.setText(getDesc()); + sleightOfHandDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); + + sleightOfHandPriceLabel.setFont(new Font("sserif", 0, 12)); + sleightOfHandPriceLabel.setText("Price: " + getPrice() + " credits"); + sleightOfHandPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); + + creditsLabel.setFont(new Font("sserif", 0, 12)); + creditsLabel.setText("Credits: " + questData.getCredits()); + creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); + + sleightOfHandIcon = getIcon(getImageString()); + sleightOfHandIconLabel.setText(""); + sleightOfHandIconLabel.setIcon(sleightOfHandIcon); + sleightOfHandIconLabel.setBounds(new Rectangle(300, 135, 128, 128)); + sleightOfHandIconLabel.setIconTextGap(0); + + //String fileName = "LeafIconSmall.png"; + //ImageIcon icon = getIcon(fileName); + + sleightOfHandButton.setEnabled(true); + if (questData.getCredits() < getPrice() || questData.getSleightOfHandLevel() >= 1) + sleightOfHandButton.setEnabled(false); + + quitButton.setBounds(new Rectangle(140, 297, 120, 50)); + quitButton.setText("Quit"); + quitButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + quitButton_actionPerformed(e); + } + }); + + + //jPanel2.add(quitButton, null); + this.getContentPane().add(sleightOfHandButton, null); + this.getContentPane().add(titleLabel, null); + this.getContentPane().add(sleightOfHandDescLabel, null); + this.getContentPane().add(sleightOfHandIconLabel, null); + this.getContentPane().add(sleightOfHandPriceLabel, null); + this.getContentPane().add(creditsLabel, null); + this.getContentPane().add(quitButton,null); + } + + void learnEstatesButton_actionPerformed(ActionEvent e) throws Exception { + questData.subtractCredits(getPrice()); + + if (questData.getSleightOfHandLevel() < 1) + { + questData.addSleightOfHandLevel(1); + } + questData.saveData(); + jbInit(); + } + + private ImageIcon getIcon(String fileName) + { + File base = ForgeProps.getFile(IMAGE_ICON); + File file = new File(base, fileName); + ImageIcon icon = new ImageIcon(file.toString()); + return icon; + } + + void quitButton_actionPerformed(ActionEvent e) { + questData.saveData(); + //new Gui_Shops(); + shopsGUI.setVisible(true); + + dispose(); + + } + + void this_windowClosing(WindowEvent e) { + quitButton_actionPerformed(null); + } + +} diff --git a/src/forge/Gui_NewGame.java b/src/forge/Gui_NewGame.java index d144db2c7cf..5cfb113fc05 100644 --- a/src/forge/Gui_NewGame.java +++ b/src/forge/Gui_NewGame.java @@ -1,5 +1,24 @@ package forge; +import arcane.ui.util.ManaSymbols; +import arcane.util.MultiplexOutputStream; +import com.esotericsoftware.minlog.Log; +import forge.error.ErrorViewer; +import forge.error.ExceptionHandler; +import forge.gui.GuiUtils; +import forge.gui.ListChooser; +import forge.properties.ForgePreferences; +import forge.properties.ForgePreferences.CardSizeType; +import forge.properties.ForgePreferences.StackOffsetType; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; +import forge.properties.NewConstants.LANG.Gui_NewGame.MENU_BAR.MENU; +import forge.properties.NewConstants.LANG.Gui_NewGame.MENU_BAR.OPTIONS; +import net.miginfocom.swing.MigLayout; + +import javax.swing.*; +import javax.swing.UIManager.LookAndFeelInfo; +import javax.swing.border.TitledBorder; import java.awt.Color; import java.awt.Component; import java.awt.Font; @@ -8,59 +27,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Random; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JComboBox; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JTextArea; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import javax.swing.UIManager.LookAndFeelInfo; -import javax.swing.border.TitledBorder; - -import net.miginfocom.swing.MigLayout; -import arcane.ui.util.ManaSymbols; -import arcane.util.MultiplexOutputStream; - -import com.esotericsoftware.minlog.Log; - -import forge.error.ErrorViewer; -import forge.error.ExceptionHandler; -import forge.gui.GuiUtils; -import forge.gui.ListChooser; -import forge.properties.ForgePreferences; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; -import forge.properties.ForgePreferences.CardSizeType; -import forge.properties.ForgePreferences.StackOffsetType; -import forge.properties.NewConstants.LANG.Gui_NewGame.MENU_BAR.MENU; -import forge.properties.NewConstants.LANG.Gui_NewGame.MENU_BAR.OPTIONS; +import java.io.*; +import java.util.*; /*CHOPPIC*/ @@ -193,7 +161,7 @@ public class Gui_NewGame extends JFrame implements NewConstants, NewConstants.LA AllZone.QuestData = null; allDecks = getDecks(); - Constant.Runtime.WinLose.reset(); + Constant.Runtime.matchState.reset(); if(Constant.Runtime.width[0] == 0) Constant.Runtime.width[0] = 70; diff --git a/src/forge/Gui_PetShop.java b/src/forge/Gui_PetShop.java index 822938e5e8c..aec3d6c7990 100644 --- a/src/forge/Gui_PetShop.java +++ b/src/forge/Gui_PetShop.java @@ -1,516 +1,543 @@ -package forge; - -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; -import java.io.File; - -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.SwingConstants; - -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - -public class Gui_PetShop extends JFrame implements NewConstants{ - - private static final long serialVersionUID = -2910767196498677881L; - private JFrame shopsGUI; - private JLabel titleLabel = new JLabel(); - - private JLabel petDescLabel = new JLabel(); - private JLabel petStatsLabel = new JLabel(); - private JLabel petPriceLabel = new JLabel(); - private JLabel petIconLabel = new JLabel(); - - private JLabel creditsLabel = new JLabel(); - - private ImageIcon petIcon = new ImageIcon(); - - private JButton buyPetButton = new JButton(); - private JButton quitButton = new JButton(); - - private QuestData questData = AllZone.QuestData; - - public Gui_PetShop(JFrame parent) { - try { - jbInit(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - } - - shopsGUI = parent; - - setup(); - - //for some reason, the Bazaar window does not return when closing with X - //for now, just disable X closing: - this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - - Dimension screen = this.getToolkit().getScreenSize(); - setBounds(screen.width / 3, 100, //position - 530, 430); //size - setVisible(true); - - - } - - //only do this ONCE: - private void setup() { - //String fileName = "LeafIconSmall.png"; - //ImageIcon icon = getIcon(fileName); - buyPetButton.setBounds(new Rectangle(10, 297, 120, 50)); - - buyPetButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - buyPetButton_actionPerformed(e); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - }); - - }//setup(); - - private String getDesc() - { - StringBuilder sb = new StringBuilder(); - sb.append(""); - if (questData.getWolfPetLevel() == 0) - { - sb.append("This ferocious animal may have been raised
in captivity, but it has been trained to kill.
"); - sb.append("Eats goblins for breakfast.

"); - sb.append("Level 1: 1/1
"); - sb.append("Next Level: 1/2
"); - sb.append("Can learn: Flanking"); - } - else if (questData.getWolfPetLevel() == 1) - { - sb.append("Improve the toughness of your wolf.
"); - sb.append("Level 2: 1/2
"); - sb.append("Next Level: 2/2
"); - sb.append("Can learn: Flanking"); - } - else if (questData.getWolfPetLevel() == 2) - { - sb.append("Improve the attack power of your wolf.
"); - sb.append("Level 3: 2/2
"); - sb.append("Next Level: Flanking
"); - sb.append("Can learn: Flanking"); - } - else if (questData.getWolfPetLevel() == 3) - { - sb.append("Gives Flanking to your wolf.
"); - sb.append("Level 4: 2/2 Flanking
"); - } - else if (questData.getWolfPetLevel() >= 4) - { - //sb.append("Wolf Level Maxed out.
"); - - if (questData.getCrocPetLevel() == 0) - { - sb.append("With its razor sharp teeth, this swamp-dwelling monster is extremely dangerous."); - sb.append("Crikey mate!

"); - sb.append("Level 1: 1/1
"); - sb.append("Next Level: 2/1
"); - sb.append("Can learn: Swampwalk"); - } - else if (questData.getCrocPetLevel() == 1) - { - sb.append("Improve the attack power of your croc.
"); - sb.append("Level 2: 2/1
"); - sb.append("Next Level: 3/1
"); - sb.append("Can learn: Swampwalk"); - } - else if (questData.getCrocPetLevel() == 2) - { - sb.append("Improve the attack power of your croc.
"); - sb.append("Level 3: 3/1
"); - sb.append("Next Level: 3/1 Swampwalk
"); - } - else if (questData.getCrocPetLevel() == 3) - { - sb.append("Gives Swampwalk to your croc.
"); - sb.append("Level 4: 3/1 Swampwalk
"); - } - /* - else if (questData.getCrocPetLevel() >= 4) - { - sb.append("Croc Level Maxed out.
"); - } - */ - - else if (questData.getBirdPetLevel() == 0) - { - sb.append("Unmatched in speed, agility and awareness,
"); - sb.append("this trained hawk makes a fantastic hunter.

"); - sb.append("Level 1: 0/1 Flying
"); - sb.append("Next Level: 1/1
"); - sb.append("Can learn: First strike"); - } - else if (questData.getBirdPetLevel() == 1) - { - sb.append("Improve the attack power of your bird.
"); - sb.append("Level 2: 1/1
"); - sb.append("Next Level: 2/1
"); - sb.append("Can learn: First strike"); - } - else if (questData.getBirdPetLevel() == 2) - { - sb.append("Improve the attack power of your bird.
"); - sb.append("Level 3: 2/1
"); - sb.append("Next Level: 2/1 First strike
"); - } - else if (questData.getBirdPetLevel() == 3) - { - sb.append("Gives First strike to your bird.
"); - sb.append("Level 4: 2/1 First strike
"); - } - else if (questData.getHoundPetLevel() == 0) - { - sb.append("Dogs are said to be man's best friend.
"); - sb.append("Definitely not this one.

"); - sb.append("Level 1: 1/1
"); - sb.append("Next Level: 1/1 Haste
"); - sb.append("Can learn: Whenever this creature attacks alone,
it gets +2/+0 until end of turn."); - } - else if (questData.getHoundPetLevel() == 1) - { - sb.append("Gives haste to your hound.
"); - sb.append("Level 2: 1/1 Haste
"); - sb.append("Next Level: 2/1 Haste
"); - sb.append("Can learn: Whenever this creature attacks alone,
it gets +2/+0 until end of turn."); - } - else if (questData.getHoundPetLevel() == 2) - { - sb.append("Improve the attack power of your hound.
"); - sb.append("Level 3: 2/1 Haste
"); - sb.append("Next Level: 2/1 Whenever this creature attacks
alone, it gets +2/+0 until end of turn.
"); - } - else if (questData.getHoundPetLevel() == 3) - { - sb.append("Greatly improves your hound's attack power if it
attacks alone.
"); - sb.append("Level 4: 2/1 Haste, whenever this creature attacks alone, it gets +2/+0 until end of turn.
"); - } - }//wolfPetLevel >= 4 - - - sb.append(""); - return sb.toString(); - } - - private long getPrice() - { - long l = 0; - if (questData.getWolfPetLevel() == 0) - l = 250; - else if (questData.getWolfPetLevel() == 1) - l = 250; - else if (questData.getWolfPetLevel() == 2) - l = 500; - else if (questData.getWolfPetLevel() == 3) - l = 550; - else if (questData.getWolfPetLevel() >= 4) - { - if (questData.getCrocPetLevel() == 0) - l = 250; - else if (questData.getCrocPetLevel() == 1) - l = 300; - else if (questData.getCrocPetLevel() == 2) - l = 450; - else if (questData.getCrocPetLevel() == 3) - l = 600; - else if (questData.getBirdPetLevel() == 0) - l = 200; - else if (questData.getBirdPetLevel() == 1) - l = 300; - else if (questData.getBirdPetLevel() == 2) - l = 450; - else if (questData.getBirdPetLevel() == 3) - l = 400; - else if (questData.getHoundPetLevel() == 0) - l = 200; - else if (questData.getHoundPetLevel() == 1) - l = 350; - else if (questData.getHoundPetLevel() == 2) - l = 450; - else if (questData.getHoundPetLevel() == 3) - l = 750; - } - return l; - } - - private String getButtonText(String pet) - { - String s = ""; - if (pet.equals("Wolf")) { - if (questData.getWolfPetLevel() == 0) - s = "Buy " + pet; - else - s = "Train " + pet; - } - else if (pet.equals("Croc")) - { - if (questData.getCrocPetLevel() == 0) - s = "Buy " + pet; - else - s = "Train " + pet; - } - else if (pet.equals("Bird")) - { - if (questData.getBirdPetLevel() == 0) - s = "Buy " + pet; - else - s = "Train " + pet; - } - else if (pet.equals("Hound")) - { - if (questData.getHoundPetLevel() == 0) - s = "Buy " + pet; - else - s = "Train " + pet; - } - return s; - } - - private String getPetStats() - { - StringBuilder sb = new StringBuilder(); - if (questData.getWolfPetLevel() < 4) { - if (questData.getWolfPetLevel() == 1) - sb.append("1/1"); - else if (questData.getWolfPetLevel() == 2) - sb.append("1/2"); - else if (questData.getWolfPetLevel() >= 3) - sb.append("2/2"); - - sb.append(" Wolf Pet (current level "); - sb.append(questData.getWolfPetLevel()); - } //getWolfPetLevel < 4 - else if (questData.getCrocPetLevel() < 4) - { - if (questData.getCrocPetLevel() == 1) - sb.append("1/1"); - else if (questData.getCrocPetLevel() == 2) - sb.append("2/1"); - else if (questData.getCrocPetLevel() >= 3) - sb.append("3/1"); - - sb.append(" Croc Pet (current level "); - sb.append(questData.getCrocPetLevel()); - } - else if (questData.getBirdPetLevel() < 4) - { - if (questData.getBirdPetLevel() == 1) - sb.append("0/1"); - else if (questData.getBirdPetLevel() == 2) - sb.append("1/1"); - else if (questData.getBirdPetLevel() >= 3) - sb.append("2/1"); - - sb.append(" Bird Pet (current level "); - sb.append(questData.getBirdPetLevel()); - } - else if (questData.getHoundPetLevel() <= 4) - { - if (questData.getHoundPetLevel() == 1) - sb.append("1/1"); - else if (questData.getHoundPetLevel() == 2) - sb.append("1/1"); - else if (questData.getHoundPetLevel() >= 3) - sb.append("2/1"); - - sb.append(" Hound Pet (current level "); - sb.append(questData.getHoundPetLevel()); - } - - sb.append("/4)"); - if (questData.getWolfPetLevel() == 0) - return ""; - - return sb.toString(); - } - - private String getImageString() - { - String s = ""; - if (questData.getWolfPetLevel() < 4) - { - if (questData.getWolfPetLevel() == 0) - s = "g_1_1_wolf_pet_small.jpg"; - else if (questData.getWolfPetLevel() == 1) - s = "g_1_2_wolf_pet_small.jpg"; - else if (questData.getWolfPetLevel() == 2) - s = "g_2_2_wolf_pet_small.jpg"; - else if (questData.getWolfPetLevel() == 3) - s = "g_2_2_wolf_pet_flanking_small.jpg"; - } - else if (questData.getCrocPetLevel() < 4) - { - if (questData.getCrocPetLevel() == 0) - s = "b_1_1_crocodile_pet_small.jpg"; - else if (questData.getCrocPetLevel() == 1) - s = "b_2_1_crocodile_pet_small.jpg"; - else if (questData.getCrocPetLevel() == 2) - s = "b_3_1_crocodile_pet_small.jpg"; - else if (questData.getCrocPetLevel() == 3) - s = "b_3_1_crocodile_pet_swampwalk_small.jpg"; - } - else if (questData.getBirdPetLevel() < 4) - { - if (questData.getBirdPetLevel() == 0) - s = "w_0_1_bird_pet_small.jpg"; - else if (questData.getBirdPetLevel() == 1) - s = "w_1_1_bird_pet_small.jpg"; - else if (questData.getBirdPetLevel() == 2) - s = "w_2_1_bird_pet_small.jpg"; - else if (questData.getBirdPetLevel() == 3) - s = "w_2_1_bird_pet_first_strike_small.jpg"; - } - - else if (questData.getHoundPetLevel() < 4) - { - if (questData.getHoundPetLevel() == 0) - s = "r_1_1_hound_pet_small.jpg"; - else if (questData.getHoundPetLevel() == 1) - s = "r_1_1_hound_pet_haste_small.jpg"; - else if (questData.getHoundPetLevel() == 2) - s = "r_2_1_hound_pet_small.jpg"; - else if (questData.getHoundPetLevel() == 3) - s = "r_2_1_hound_pet_alone_small.jpg"; - } - - return s; - } - - private void jbInit() throws Exception { - titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); - titleLabel.setHorizontalAlignment(SwingConstants.CENTER); - titleLabel.setText("Beast Emporium"); - titleLabel.setBounds(new Rectangle(150, 5, 198, 60)); - this.getContentPane().setLayout(null); - - petStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); - petStatsLabel.setText(getPetStats()); - petStatsLabel.setBounds(new Rectangle(10, 65, 200, 15)); - - petDescLabel.setFont(new Font("sserif", 0, 12)); - petDescLabel.setText(getDesc()); - petDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); - - petPriceLabel.setFont(new Font("sserif", 0, 12)); - petPriceLabel.setText("Price: " + getPrice() + " credits"); - petPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); - - creditsLabel.setFont(new Font("sserif", 0, 12)); - creditsLabel.setText("Credits: " + questData.getCredits()); - creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); - - petIcon = getIcon(getImageString()); - petIconLabel.setText(""); - petIconLabel.setIcon(petIcon); - petIconLabel.setBounds(new Rectangle(280, 65, 201, 280)); - petIconLabel.setIconTextGap(0); - - if (questData.getWolfPetLevel() < 4) - buyPetButton.setText(getButtonText("Wolf")); - else if (questData.getCrocPetLevel() < 4) - buyPetButton.setText(getButtonText("Croc")); - else if (questData.getBirdPetLevel() < 4) - buyPetButton.setText(getButtonText("Bird")); - else if (questData.getHoundPetLevel() < 4) - buyPetButton.setText(getButtonText("Hound")); - - buyPetButton.setEnabled(true); - if (questData.getCredits() < getPrice() || questData.getHoundPetLevel() >= 4) - buyPetButton.setEnabled(false); - - quitButton.setBounds(new Rectangle(140, 297, 120, 50)); - quitButton.setText("Quit"); - quitButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - quitButton_actionPerformed(e); - } - }); - - - //jPanel2.add(quitButton, null); - this.getContentPane().add(buyPetButton, null); - this.getContentPane().add(titleLabel, null); - this.getContentPane().add(petStatsLabel, null); - this.getContentPane().add(petDescLabel, null); - this.getContentPane().add(petIconLabel, null); - this.getContentPane().add(petPriceLabel, null); - this.getContentPane().add(creditsLabel, null); - this.getContentPane().add(quitButton,null); - } - - void editDeckButton_actionPerformed(ActionEvent e) { - Command exit = new Command() { - private static final long serialVersionUID = 4735992294414389187L; - - public void execute() { - new Gui_WinLose(); - } - }; - Gui_DeckEditor editor = new Gui_DeckEditor(); - - editor.show(exit); - - dispose(); - }//editDeckButton_actionPerformed() - - void buyPetButton_actionPerformed(ActionEvent e) throws Exception { - questData.subtractCredits(getPrice()); - - if (questData.getWolfPetLevel() < 4) - questData.addWolfPetLevel(); - else if (questData.getCrocPetLevel() < 4) - questData.addCrocPetLevel(); - else if (questData.getBirdPetLevel() < 4) - questData.addBirdPetLevel(); - else if (questData.getHoundPetLevel() < 4) - questData.addHoundPetLevel(); - - QuestData.saveData(questData); - jbInit(); - } - - void restartButton_actionPerformed(ActionEvent e) { - Constant.Runtime.WinLose.reset(); - AllZone.GameAction.newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]); - AllZone.Display.setVisible(true); - - dispose(); - } - - private ImageIcon getIcon(String fileName) - { - File base = ForgeProps.getFile(IMAGE_ICON); - File file = new File(base, fileName); - ImageIcon icon = new ImageIcon(file.toString()); - return icon; - } - - void quitButton_actionPerformed(ActionEvent e) { - QuestData.saveData(questData); - //new Gui_Shops(); - shopsGUI.setVisible(true); - - - dispose(); - - } - - void this_windowClosing(WindowEvent e) { - quitButton_actionPerformed(null); - } - -} +package forge; + +import forge.error.ErrorViewer; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; + +import javax.swing.*; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.WindowEvent; +import java.io.File; + +public class Gui_PetShop extends JFrame implements NewConstants { + + private static final long serialVersionUID = -2910767196498677881L; + private JFrame shopsGUI; + private JLabel titleLabel = new JLabel(); + + private JLabel petDescLabel = new JLabel(); + private JLabel petStatsLabel = new JLabel(); + private JLabel petPriceLabel = new JLabel(); + private JLabel petIconLabel = new JLabel(); + + private JLabel creditsLabel = new JLabel(); + + private ImageIcon petIcon = new ImageIcon(); + + private JButton buyPetButton = new JButton(); + private JButton quitButton = new JButton(); + + private forge.quest.data.QuestData questData = AllZone.QuestData; + + public Gui_PetShop(JFrame parent) { + try { + jbInit(); + } catch (Exception ex) { + ErrorViewer.showError(ex); + } + + shopsGUI = parent; + + setup(); + + //for some reason, the Bazaar window does not return when closing with X + //for now, just disable X closing: + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + + Dimension screen = this.getToolkit().getScreenSize(); + setBounds(screen.width / 3, 100, //position + 530, 430); //size + setVisible(true); + + + } + + //only do this ONCE: + private void setup() { + //String fileName = "LeafIconSmall.png"; + //ImageIcon icon = getIcon(fileName); + buyPetButton.setBounds(new Rectangle(10, 297, 120, 50)); + + buyPetButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + buyPetButton_actionPerformed(e); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + + }//setup(); + + private String getDesc() { + StringBuilder sb = new StringBuilder(); + sb.append(""); + if (questData.getPetManager().getPet("Wolf").getLevel() == 0) { + sb.append( + "This ferocious animal may have been raised
in captivity, but it has been trained to kill.
"); + sb.append("Eats goblins for breakfast.

"); + sb.append("Level 1: 1/1
"); + sb.append("Next Level: 1/2
"); + sb.append("Can learn: Flanking"); + } + else if (questData.getPetManager().getPet("Wolf").getLevel() == 1) { + sb.append("Improve the toughness of your wolf.
"); + sb.append("Level 2: 1/2
"); + sb.append("Next Level: 2/2
"); + sb.append("Can learn: Flanking"); + } + else if (questData.getPetManager().getPet("Wolf").getLevel() == 2) { + sb.append("Improve the attack power of your wolf.
"); + sb.append("Level 3: 2/2
"); + sb.append("Next Level: Flanking
"); + sb.append("Can learn: Flanking"); + } + else if (questData.getPetManager().getPet("Wolf").getLevel() == 3) { + sb.append("Gives Flanking to your wolf.
"); + sb.append("Level 4: 2/2 Flanking
"); + } + else if (questData.getPetManager().getPet("Wolf").getLevel() >= 4) { + //sb.append("Wolf Level Maxed out.
"); + + if (questData.getPetManager().getPet("Crocodile").getLevel() == 0) { + sb.append("With its razor sharp teeth, this swamp-dwelling monster is extremely dangerous."); + sb.append("Crikey mate!

"); + sb.append("Level 1: 1/1
"); + sb.append("Next Level: 2/1
"); + sb.append("Can learn: Swampwalk"); + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 1) { + sb.append("Improve the attack power of your croc.
"); + sb.append("Level 2: 2/1
"); + sb.append("Next Level: 3/1
"); + sb.append("Can learn: Swampwalk"); + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 2) { + sb.append("Improve the attack power of your croc.
"); + sb.append("Level 3: 3/1
"); + sb.append("Next Level: 3/1 Swampwalk
"); + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 3) { + sb.append("Gives Swampwalk to your croc.
"); + sb.append("Level 4: 3/1 Swampwalk
"); + } + /* + else if (questData.getPetManager().getPet("Crocodile").getLevel() >= 4) + { + sb.append("Croc Level Maxed out.
"); + } + */ + + else if (questData.getPetManager().getPet("Bird").getLevel() == 0) { + sb.append("Unmatched in speed, agility and awareness,
"); + sb.append("this trained hawk makes a fantastic hunter.

"); + sb.append("Level 1: 0/1 Flying
"); + sb.append("Next Level: 1/1
"); + sb.append("Can learn: First strike"); + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 1) { + sb.append("Improve the attack power of your bird.
"); + sb.append("Level 2: 1/1
"); + sb.append("Next Level: 2/1
"); + sb.append("Can learn: First strike"); + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 2) { + sb.append("Improve the attack power of your bird.
"); + sb.append("Level 3: 2/1
"); + sb.append("Next Level: 2/1 First strike
"); + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 3) { + sb.append("Gives First strike to your bird.
"); + sb.append("Level 4: 2/1 First strike
"); + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 0) { + sb.append("Dogs are said to be man's best friend.
"); + sb.append("Definitely not this one.

"); + sb.append("Level 1: 1/1
"); + sb.append("Next Level: 1/1 Haste
"); + sb.append( + "Can learn: Whenever this creature attacks alone,
it gets +2/+0 until end of turn."); + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 1) { + sb.append("Gives haste to your hound.
"); + sb.append("Level 2: 1/1 Haste
"); + sb.append("Next Level: 2/1 Haste
"); + sb.append( + "Can learn: Whenever this creature attacks alone,
it gets +2/+0 until end of turn."); + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 2) { + sb.append("Improve the attack power of your hound.
"); + sb.append("Level 3: 2/1 Haste
"); + sb.append( + "Next Level: 2/1 Whenever this creature attacks
alone, it gets +2/+0 until end of turn.
"); + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 3) { + sb.append("Greatly improves your hound's attack power if it
attacks alone.
"); + sb.append( + "Level 4: 2/1 Haste, whenever this creature attacks alone, it gets +2/+0 until end of turn.
"); + } + }//wolfPetLevel >= 4 + + + sb.append(""); + return sb.toString(); + } + + private long getPrice() { + long l = 0; + if (questData.getPetManager().getPet("Wolf").getLevel() == 0) { + l = 250; + } + else if (questData.getPetManager().getPet("Wolf").getLevel() == 1) { + l = 250; + } + else if (questData.getPetManager().getPet("Wolf").getLevel() == 2) { + l = 500; + } + else if (questData.getPetManager().getPet("Wolf").getLevel() == 3) { + l = 550; + } + + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 0) { + l = 250; + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 1) { + l = 300; + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 2) { + l = 450; + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 3) { + l = 600; + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 0) { + l = 200; + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 1) { + l = 300; + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 2) { + l = 450; + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 3) { + l = 400; + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 0) { + l = 200; + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 1) { + l = 350; + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 2) { + l = 450; + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 3) { + l = 750; + } + return l; + } + + private String getButtonText(String pet) { + String s = ""; + if (pet.equals("Wolf")) { + if (questData.getPetManager().getPet("Wolf").getLevel() == 0) { + s = "Buy " + pet; + } + else { + s = "Train " + pet; + } + } + else if (pet.equals("Croc")) { + if (questData.getPetManager().getPet("Crocodile").getLevel() == 0) { + s = "Buy " + pet; + } + else { + s = "Train " + pet; + } + } + else if (pet.equals("Bird")) { + if (questData.getPetManager().getPet("Bird").getLevel() == 0) { + s = "Buy " + pet; + } + else { + s = "Train " + pet; + } + } + else if (pet.equals("Hound")) { + if (questData.getPetManager().getPet("Hound").getLevel() == 0) { + s = "Buy " + pet; + } + else { + s = "Train " + pet; + } + } + return s; + } + + private String getPetStats() { + StringBuilder sb = new StringBuilder(); + if (questData.getPetManager().getPet("Wolf").getLevel() < 4) { + if (questData.getPetManager().getPet("Wolf").getLevel() == 1) { + sb.append("1/1"); + } + else if (questData.getPetManager().getPet("Wolf").getLevel() == 2) { + sb.append("1/2"); + } + else if (questData.getPetManager().getPet("Wolf").getLevel() >= 3) { + sb.append("2/2"); + } + + sb.append(" Wolf Pet (current level "); + sb.append(questData.getPetManager().getPet("Wolf").getLevel()); + } //getWolfPetLevel < 4 + else if (questData.getPetManager().getPet("Crocodile").getLevel() < 4) { + if (questData.getPetManager().getPet("Crocodile").getLevel() == 1) { + sb.append("1/1"); + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 2) { + sb.append("2/1"); + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() >= 3) { + sb.append("3/1"); + } + + sb.append(" Croc Pet (current level "); + sb.append(questData.getPetManager().getPet("Crocodile").getLevel()); + } + else if (questData.getPetManager().getPet("Bird").getLevel() < 4) { + if (questData.getPetManager().getPet("Bird").getLevel() == 1) { + sb.append("0/1"); + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 2) { + sb.append("1/1"); + } + else if (questData.getPetManager().getPet("Bird").getLevel() >= 3) { + sb.append("2/1"); + } + + sb.append(" Bird Pet (current level "); + sb.append(questData.getPetManager().getPet("Bird").getLevel()); + } + else if (questData.getPetManager().getPet("Hound").getLevel() <= 4) { + if (questData.getPetManager().getPet("Hound").getLevel() == 1) { + sb.append("1/1"); + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 2) { + sb.append("1/1"); + } + else if (questData.getPetManager().getPet("Hound").getLevel() >= 3) { + sb.append("2/1"); + } + + sb.append(" Hound Pet (current level "); + sb.append(questData.getPetManager().getPet("Hound").getLevel()); + } + + sb.append("/4)"); + if (questData.getPetManager().getPet("Wolf").getLevel() == 0) { + return ""; + } + + return sb.toString(); + } + + private String getImageString() { + String s = ""; + if (questData.getPetManager().getPet("Wolf").getLevel() < 4) { + if (questData.getPetManager().getPet("Wolf").getLevel() == 0) { + s = "g_1_1_wolf_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Wolf").getLevel() == 1) { + s = "g_1_2_wolf_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Wolf").getLevel() == 2) { + s = "g_2_2_wolf_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Wolf").getLevel() == 3) { + s = "g_2_2_wolf_pet_flanking_small.jpg"; + } + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() < 4) { + if (questData.getPetManager().getPet("Crocodile").getLevel() == 0) { + s = "b_1_1_crocodile_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 1) { + s = "b_2_1_crocodile_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 2) { + s = "b_3_1_crocodile_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() == 3) { + s = "b_3_1_crocodile_pet_swampwalk_small.jpg"; + } + } + else if (questData.getPetManager().getPet("Bird").getLevel() < 4) { + if (questData.getPetManager().getPet("Bird").getLevel() == 0) { + s = "w_0_1_bird_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 1) { + s = "w_1_1_bird_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 2) { + s = "w_2_1_bird_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Bird").getLevel() == 3) { + s = "w_2_1_bird_pet_first_strike_small.jpg"; + } + } + + else if (questData.getPetManager().getPet("Hound").getLevel() < 4) { + if (questData.getPetManager().getPet("Hound").getLevel() == 0) { + s = "r_1_1_hound_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 1) { + s = "r_1_1_hound_pet_haste_small.jpg"; + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 2) { + s = "r_2_1_hound_pet_small.jpg"; + } + else if (questData.getPetManager().getPet("Hound").getLevel() == 3) { + s = "r_2_1_hound_pet_alone_small.jpg"; + } + } + + return s; + } + + private void jbInit() throws Exception { + titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); + titleLabel.setHorizontalAlignment(SwingConstants.CENTER); + titleLabel.setText("Beast Emporium"); + titleLabel.setBounds(new Rectangle(150, 5, 198, 60)); + this.getContentPane().setLayout(null); + + petStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); + petStatsLabel.setText(getPetStats()); + petStatsLabel.setBounds(new Rectangle(10, 65, 200, 15)); + + petDescLabel.setFont(new Font("sserif", 0, 12)); + petDescLabel.setText(getDesc()); + petDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); + + petPriceLabel.setFont(new Font("sserif", 0, 12)); + petPriceLabel.setText("Price: " + getPrice() + " credits"); + petPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); + + creditsLabel.setFont(new Font("sserif", 0, 12)); + creditsLabel.setText("Credits: " + questData.getCredits()); + creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); + + petIcon = getIcon(getImageString()); + petIconLabel.setText(""); + petIconLabel.setIcon(petIcon); + petIconLabel.setBounds(new Rectangle(280, 65, 201, 280)); + petIconLabel.setIconTextGap(0); + + if (questData.getPetManager().getPet("Wolf").getLevel() < 4) { + buyPetButton.setText(getButtonText("Wolf")); + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() < 4) { + buyPetButton.setText(getButtonText("Croc")); + } + else if (questData.getPetManager().getPet("Bird").getLevel() < 4) { + buyPetButton.setText(getButtonText("Bird")); + } + else if (questData.getPetManager().getPet("Hound").getLevel() < 4) { + buyPetButton.setText(getButtonText("Hound")); + } + + buyPetButton.setEnabled(true); + if (questData.getCredits() < getPrice() || questData.getPetManager().getPet("Hound").getLevel() >= 4) { + buyPetButton.setEnabled(false); + } + + quitButton.setBounds(new Rectangle(140, 297, 120, 50)); + quitButton.setText("Quit"); + quitButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + quitButton_actionPerformed(e); + } + }); + + + //jPanel2.add(quitButton, null); + this.getContentPane().add(buyPetButton, null); + this.getContentPane().add(titleLabel, null); + this.getContentPane().add(petStatsLabel, null); + this.getContentPane().add(petDescLabel, null); + this.getContentPane().add(petIconLabel, null); + this.getContentPane().add(petPriceLabel, null); + this.getContentPane().add(creditsLabel, null); + this.getContentPane().add(quitButton, null); + } + + void editDeckButton_actionPerformed(ActionEvent e) { + Command exit = new Command() { + private static final long serialVersionUID = 4735992294414389187L; + + public void execute() { + new Gui_WinLose(); + } + }; + Gui_DeckEditor editor = new Gui_DeckEditor(); + + editor.show(exit); + + dispose(); + }//editDeckButton_actionPerformed() + + void buyPetButton_actionPerformed(ActionEvent e) throws Exception { + questData.subtractCredits(getPrice()); + + if (questData.getPetManager().getPet("Wolf").getLevel() < 4) { + questData.getPetManager().addPetLevel("Wolf"); + } + else if (questData.getPetManager().getPet("Crocodile").getLevel() < 4) { + questData.getPetManager().addPetLevel("Crocodile"); + } + else if (questData.getPetManager().getPet("Bird").getLevel() < 4) { + questData.getPetManager().addPetLevel("Bird"); + } + else if (questData.getPetManager().getPet("Hound").getLevel() < 4) { + questData.getPetManager().addPetLevel("hound"); + } + + questData.saveData(); + jbInit(); + } + + void restartButton_actionPerformed(ActionEvent e) { + Constant.Runtime.matchState.reset(); + AllZone.GameAction.newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]); + AllZone.Display.setVisible(true); + + dispose(); + } + + private ImageIcon getIcon(String fileName) { + File base = ForgeProps.getFile(IMAGE_ICON); + File file = new File(base, fileName); + ImageIcon icon = new ImageIcon(file.toString()); + return icon; + } + + void quitButton_actionPerformed(ActionEvent e) { + questData.saveData(); + //new Gui_Shops(); + shopsGUI.setVisible(true); + + + dispose(); + + } + + void this_windowClosing(WindowEvent e) { + quitButton_actionPerformed(null); + } + +} diff --git a/src/forge/Gui_PlantShop.java b/src/forge/Gui_PlantShop.java index a6cdf951f9d..5af02679bf1 100644 --- a/src/forge/Gui_PlantShop.java +++ b/src/forge/Gui_PlantShop.java @@ -1,311 +1,306 @@ -package forge; - -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; -import java.io.File; - -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.SwingConstants; - -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - -public class Gui_PlantShop extends JFrame implements NewConstants{ - - private static final long serialVersionUID = 2409591658245091210L; - private JFrame shopsGUI; - private JLabel titleLabel = new JLabel(); - - private JLabel plantDescLabel = new JLabel(); - private JLabel plantStatsLabel = new JLabel(); - private JLabel plantPriceLabel = new JLabel(); - private JLabel plantIconLabel = new JLabel(); - - private JLabel creditsLabel = new JLabel(); - - private ImageIcon plantIcon = new ImageIcon(); - - private JButton buyPlantButton = new JButton(); - private JButton quitButton = new JButton(); - - private QuestData questData = AllZone.QuestData; - - public Gui_PlantShop(JFrame parent) { - try { - jbInit(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - } - - shopsGUI = parent; - - setup(); - - //for some reason, the Bazaar window does not return when closing with X - //for now, just disable X closing: - this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - - Dimension screen = this.getToolkit().getScreenSize(); - setBounds(screen.width / 3, 100, //position - 530, 430); //size - setVisible(true); - - } - - private void setup() { - //buyPlantButton.setIcon(icon); - buyPlantButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - buyPlantButton_actionPerformed(e); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - }); - - }//setup(); - - private String getDesc() - { - StringBuilder sb = new StringBuilder(); - sb.append(""); - if (questData.getPlantLevel() == 0) - { - sb.append("Start each of your battles with this lush,
verdant plant on your side.
"); - sb.append("Excellent at blocking the nastiest of critters!

"); - sb.append("Level 1: 0/1
"); - sb.append("Next Level: 0/2
"); - sb.append("Can learn: Deathtouch"); - } - else if (questData.getPlantLevel() == 1) - { - sb.append("Improve the toughness of your plant.
"); - sb.append("Level 2: 0/2
"); - sb.append("Next Level: 0/3
"); - sb.append("Can learn: Deathtouch"); - } - else if (questData.getPlantLevel() == 2) - { - sb.append("Improve the toughness of your plant.
"); - sb.append("Level 3: 0/3
"); - sb.append("Next Level: 1/3
"); - sb.append("Can learn: Deathtouch"); - } - else if (questData.getPlantLevel() == 3) - { - sb.append("Improve the power of your plant.
"); - sb.append("Level 4: 1/3
"); - sb.append("Next Level: Deathtouch
"); - sb.append("Can learn: Deathtouch"); - } - else if (questData.getPlantLevel() == 4) - { - sb.append("Grow venomous thorns on your plant.
"); - sb.append("Level 5: Deathtouch
"); - sb.append("Next Level: 1/4
"); - } - else if (questData.getPlantLevel() == 5) - { - sb.append("As well as gaining more toughness,
"); - sb.append("your plant will have healing properties.
"); - sb.append("Level 6: 1/4 and Tap, you gain 1 life."); - } - else - { - sb.append("Plant Level Maxed out."); - } - - sb.append(""); - return sb.toString(); - } - - private long getPrice() - { - long l = 0; - if (questData.getPlantLevel() == 0) - l = 100; - else if (questData.getPlantLevel() == 1) - l = 150; - else if (questData.getPlantLevel() == 2) - l = 200; - else if (questData.getPlantLevel() == 3) - l = 300; - else if (questData.getPlantLevel() == 4) - l = 750; - else if (questData.getPlantLevel() == 5) - l = 1000; - return l; - } - - private String getButtonText() - { - String s = ""; - if (questData.getPlantLevel() == 0) - s = "Buy Plant"; - else - s = "Upgrade Plant"; - return s; - } - - private String getStats() - { - StringBuilder sb = new StringBuilder(); - if (questData.getPlantLevel() == 0) - sb.append("0/1"); - else if (questData.getPlantLevel() == 1) - sb.append("0/2"); - else if (questData.getPlantLevel() == 2) - sb.append("0/3"); - else if (questData.getPlantLevel() == 3) - sb.append("1/3"); - else if (questData.getPlantLevel() == 4) - sb.append("1/3"); - else - sb.append("1/4"); - - sb.append(" Plant Wall (current level "); - sb.append(questData.getPlantLevel()); - sb.append("/6)"); - - return sb.toString(); - } - - private String getImageString() - { - String s = ""; - if (questData.getPlantLevel() == 0) - s = "g_0_1_plant_wall_small.jpg"; - else if (questData.getPlantLevel() == 1) - s = "g_0_2_plant_wall_small.jpg"; - else if (questData.getPlantLevel() == 2) - s = "g_0_3_plant_wall_small.jpg"; - else if (questData.getPlantLevel() == 3) - s = "g_1_3_plant_wall_small.jpg"; - else if (questData.getPlantLevel() == 4) - s = "g_1_3_plant_wall_deathtouch_small.jpg"; - else if (questData.getPlantLevel() == 5) - s = "g_1_4_plant_wall_small.jpg"; - - return s; - } - - private void jbInit() throws Exception { - titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); - titleLabel.setHorizontalAlignment(SwingConstants.CENTER); - titleLabel.setText("Plant Nursery"); - titleLabel.setBounds(new Rectangle(130, 5, 198, 60)); - this.getContentPane().setLayout(null); - - plantStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); - plantStatsLabel.setText(getStats()); - plantStatsLabel.setBounds(new Rectangle(10, 65, 200, 15)); - - plantDescLabel.setFont(new Font("sserif", 0, 12)); - plantDescLabel.setText(getDesc()); - plantDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); - - plantPriceLabel.setFont(new Font("sserif", 0, 12)); - plantPriceLabel.setText("Price: " + getPrice() + " credits"); - plantPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); - - creditsLabel.setFont(new Font("sserif", 0, 12)); - creditsLabel.setText("Credits: " + questData.getCredits()); - creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); - - plantIcon = getIcon(getImageString()); - plantIconLabel.setText(""); - plantIconLabel.setIcon(plantIcon); - plantIconLabel.setBounds(new Rectangle(280, 65, 201, 280)); - plantIconLabel.setIconTextGap(0); - - //String fileName = "LeafIconSmall.png"; - //ImageIcon icon = getIcon(fileName); - buyPlantButton.setBounds(new Rectangle(10, 297, 120, 50)); - buyPlantButton.setText(getButtonText()); - - - buyPlantButton.setEnabled(true); - if (questData.getCredits() < getPrice() || questData.getPlantLevel() >= 6) - buyPlantButton.setEnabled(false); - - quitButton.setBounds(new Rectangle(140, 297, 120, 50)); - quitButton.setText("Quit"); - quitButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - quitButton_actionPerformed(e); - } - }); - - - //jPanel2.add(quitButton, null); - this.getContentPane().add(buyPlantButton, null); - this.getContentPane().add(titleLabel, null); - this.getContentPane().add(plantStatsLabel, null); - this.getContentPane().add(plantDescLabel, null); - this.getContentPane().add(plantIconLabel, null); - this.getContentPane().add(plantPriceLabel, null); - this.getContentPane().add(creditsLabel, null); - this.getContentPane().add(quitButton,null); - } - - void editDeckButton_actionPerformed(ActionEvent e) { - Command exit = new Command() { - private static final long serialVersionUID = 4735992294414389187L; - - public void execute() { - new Gui_WinLose(); - } - }; - Gui_DeckEditor editor = new Gui_DeckEditor(); - - editor.show(exit); - - dispose(); - }//editDeckButton_actionPerformed() - - void buyPlantButton_actionPerformed(ActionEvent e) throws Exception { - questData.subtractCredits(getPrice()); - questData.addPlantLevel(); - jbInit(); - } - - void restartButton_actionPerformed(ActionEvent e) { - Constant.Runtime.WinLose.reset(); - AllZone.GameAction.newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]); - AllZone.Display.setVisible(true); - - dispose(); - } - - private ImageIcon getIcon(String fileName) - { - File base = ForgeProps.getFile(IMAGE_ICON); - File file = new File(base, fileName); - ImageIcon icon = new ImageIcon(file.toString()); - return icon; - } - - void quitButton_actionPerformed(ActionEvent e) { - QuestData.saveData(questData); - //new Gui_Shops(); - shopsGUI.setVisible(true); - - - dispose(); - - } - - void this_windowClosing(WindowEvent e) { - quitButton_actionPerformed(null); - } - -} +package forge; + +import forge.error.ErrorViewer; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; + +import javax.swing.*; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.WindowEvent; +import java.io.File; + +public class Gui_PlantShop extends JFrame implements NewConstants{ + + private static final long serialVersionUID = 2409591658245091210L; + private JFrame shopsGUI; + private JLabel titleLabel = new JLabel(); + + private JLabel plantDescLabel = new JLabel(); + private JLabel plantStatsLabel = new JLabel(); + private JLabel plantPriceLabel = new JLabel(); + private JLabel plantIconLabel = new JLabel(); + + private JLabel creditsLabel = new JLabel(); + + private ImageIcon plantIcon = new ImageIcon(); + + private JButton buyPlantButton = new JButton(); + private JButton quitButton = new JButton(); + + private forge.quest.data.QuestData questData = AllZone.QuestData; + + public Gui_PlantShop(JFrame parent) { + try { + jbInit(); + } catch(Exception ex) { + ErrorViewer.showError(ex); + } + + shopsGUI = parent; + + setup(); + + //for some reason, the Bazaar window does not return when closing with X + //for now, just disable X closing: + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + + Dimension screen = this.getToolkit().getScreenSize(); + setBounds(screen.width / 3, 100, //position + 530, 430); //size + setVisible(true); + + } + + private void setup() { + //buyPlantButton.setIcon(icon); + buyPlantButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + buyPlantButton_actionPerformed(e); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + + }//setup(); + + private String getDesc() + { + StringBuilder sb = new StringBuilder(); + sb.append(""); + if (questData.getPetManager().getPlant().getLevel() == 0) + { + sb.append("Start each of your battles with this lush,
verdant plant on your side.
"); + sb.append("Excellent at blocking the nastiest of critters!

"); + sb.append("Level 1: 0/1
"); + sb.append("Next Level: 0/2
"); + sb.append("Can learn: Deathtouch"); + } + else if (questData.getPetManager().getPlant().getLevel() == 1) + { + sb.append("Improve the toughness of your plant.
"); + sb.append("Level 2: 0/2
"); + sb.append("Next Level: 0/3
"); + sb.append("Can learn: Deathtouch"); + } + else if (questData.getPetManager().getPlant().getLevel() == 2) + { + sb.append("Improve the toughness of your plant.
"); + sb.append("Level 3: 0/3
"); + sb.append("Next Level: 1/3
"); + sb.append("Can learn: Deathtouch"); + } + else if (questData.getPetManager().getPlant().getLevel() == 3) + { + sb.append("Improve the power of your plant.
"); + sb.append("Level 4: 1/3
"); + sb.append("Next Level: Deathtouch
"); + sb.append("Can learn: Deathtouch"); + } + else if (questData.getPetManager().getPlant().getLevel() == 4) + { + sb.append("Grow venomous thorns on your plant.
"); + sb.append("Level 5: Deathtouch
"); + sb.append("Next Level: 1/4
"); + } + else if (questData.getPetManager().getPlant().getLevel() == 5) + { + sb.append("As well as gaining more toughness,
"); + sb.append("your plant will have healing properties.
"); + sb.append("Level 6: 1/4 and Tap, you gain 1 life."); + } + else + { + sb.append("Plant Level Maxed out."); + } + + sb.append(""); + return sb.toString(); + } + + private long getPrice() + { + long l = 0; + if (questData.getPetManager().getPlant().getLevel() == 0) + l = 100; + else if (questData.getPetManager().getPlant().getLevel() == 1) + l = 150; + else if (questData.getPetManager().getPlant().getLevel() == 2) + l = 200; + else if (questData.getPetManager().getPlant().getLevel() == 3) + l = 300; + else if (questData.getPetManager().getPlant().getLevel() == 4) + l = 750; + else if (questData.getPetManager().getPlant().getLevel() == 5) + l = 1000; + return l; + } + + private String getButtonText() + { + String s = ""; + if (questData.getPetManager().getPlant().getLevel() == 0) + s = "Buy Plant"; + else + s = "Upgrade Plant"; + return s; + } + + private String getStats() + { + StringBuilder sb = new StringBuilder(); + if (questData.getPetManager().getPlant().getLevel() == 0) + sb.append("0/1"); + else if (questData.getPetManager().getPlant().getLevel() == 1) + sb.append("0/2"); + else if (questData.getPetManager().getPlant().getLevel() == 2) + sb.append("0/3"); + else if (questData.getPetManager().getPlant().getLevel() == 3) + sb.append("1/3"); + else if (questData.getPetManager().getPlant().getLevel() == 4) + sb.append("1/3"); + else + sb.append("1/4"); + + sb.append(" Plant Wall (current level "); + sb.append(questData.getPetManager().getPlant().getLevel()); + sb.append("/6)"); + + return sb.toString(); + } + + private String getImageString() + { + String s = ""; + if (questData.getPetManager().getPlant().getLevel() == 0) + s = "g_0_1_plant_wall_small.jpg"; + else if (questData.getPetManager().getPlant().getLevel() == 1) + s = "g_0_2_plant_wall_small.jpg"; + else if (questData.getPetManager().getPlant().getLevel() == 2) + s = "g_0_3_plant_wall_small.jpg"; + else if (questData.getPetManager().getPlant().getLevel() == 3) + s = "g_1_3_plant_wall_small.jpg"; + else if (questData.getPetManager().getPlant().getLevel() == 4) + s = "g_1_3_plant_wall_deathtouch_small.jpg"; + else if (questData.getPetManager().getPlant().getLevel() == 5) + s = "g_1_4_plant_wall_small.jpg"; + + return s; + } + + private void jbInit() throws Exception { + titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); + titleLabel.setHorizontalAlignment(SwingConstants.CENTER); + titleLabel.setText("Plant Nursery"); + titleLabel.setBounds(new Rectangle(130, 5, 198, 60)); + this.getContentPane().setLayout(null); + + plantStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); + plantStatsLabel.setText(getStats()); + plantStatsLabel.setBounds(new Rectangle(10, 65, 200, 15)); + + plantDescLabel.setFont(new Font("sserif", 0, 12)); + plantDescLabel.setText(getDesc()); + plantDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); + + plantPriceLabel.setFont(new Font("sserif", 0, 12)); + plantPriceLabel.setText("Price: " + getPrice() + " credits"); + plantPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); + + creditsLabel.setFont(new Font("sserif", 0, 12)); + creditsLabel.setText("Credits: " + questData.getCredits()); + creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); + + plantIcon = getIcon(getImageString()); + plantIconLabel.setText(""); + plantIconLabel.setIcon(plantIcon); + plantIconLabel.setBounds(new Rectangle(280, 65, 201, 280)); + plantIconLabel.setIconTextGap(0); + + //String fileName = "LeafIconSmall.png"; + //ImageIcon icon = getIcon(fileName); + buyPlantButton.setBounds(new Rectangle(10, 297, 120, 50)); + buyPlantButton.setText(getButtonText()); + + + buyPlantButton.setEnabled(true); + if (questData.getCredits() < getPrice() || questData.getPetManager().getPlant().getLevel() >= 6) + buyPlantButton.setEnabled(false); + + quitButton.setBounds(new Rectangle(140, 297, 120, 50)); + quitButton.setText("Quit"); + quitButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + quitButton_actionPerformed(e); + } + }); + + + //jPanel2.add(quitButton, null); + this.getContentPane().add(buyPlantButton, null); + this.getContentPane().add(titleLabel, null); + this.getContentPane().add(plantStatsLabel, null); + this.getContentPane().add(plantDescLabel, null); + this.getContentPane().add(plantIconLabel, null); + this.getContentPane().add(plantPriceLabel, null); + this.getContentPane().add(creditsLabel, null); + this.getContentPane().add(quitButton,null); + } + + void editDeckButton_actionPerformed(ActionEvent e) { + Command exit = new Command() { + private static final long serialVersionUID = 4735992294414389187L; + + public void execute() { + new Gui_WinLose(); + } + }; + Gui_DeckEditor editor = new Gui_DeckEditor(); + + editor.show(exit); + + dispose(); + }//editDeckButton_actionPerformed() + + void buyPlantButton_actionPerformed(ActionEvent e) throws Exception { + questData.subtractCredits(getPrice()); + questData.getPetManager().addPlantLevel(); + jbInit(); + } + + void restartButton_actionPerformed(ActionEvent e) { + Constant.Runtime.matchState.reset(); + AllZone.GameAction.newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]); + AllZone.Display.setVisible(true); + + dispose(); + } + + private ImageIcon getIcon(String fileName) + { + File base = ForgeProps.getFile(IMAGE_ICON); + File file = new File(base, fileName); + ImageIcon icon = new ImageIcon(file.toString()); + return icon; + } + + void quitButton_actionPerformed(ActionEvent e) { + questData.saveData(); + //new Gui_Shops(); + shopsGUI.setVisible(true); + + + dispose(); + + } + + void this_windowClosing(WindowEvent e) { + quitButton_actionPerformed(null); + } + +} diff --git a/src/forge/Gui_Quest.java b/src/forge/Gui_Quest.java index fcd3fbe8698..a073c84227b 100644 --- a/src/forge/Gui_Quest.java +++ b/src/forge/Gui_Quest.java @@ -1,28 +1,20 @@ package forge; + +import forge.error.ErrorViewer; +import forge.properties.NewConstants; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.TitledBorder; import java.awt.Color; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.util.ArrayList; import java.util.Collections; - -import javax.swing.BorderFactory; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.SwingConstants; -import javax.swing.border.Border; -import javax.swing.border.TitledBorder; - -import forge.error.ErrorViewer; -import forge.properties.NewConstants; +import java.util.List; +import java.util.Set; //presumes AllZone.QuestData is not null @@ -30,7 +22,7 @@ import forge.properties.NewConstants; public class Gui_Quest extends JFrame implements NewConstants{ private static final long serialVersionUID = -6432089669283627896L; - private QuestData questData; + private forge.quest.data.QuestData questData; private JLabel jLabel1 = new JLabel(); private JLabel difficultyLabel = new JLabel(); @@ -100,7 +92,7 @@ public class Gui_Quest extends JFrame implements NewConstants{ rankLabel.setText(questData.getRank()); creditsLabel.setText("Credits: " + questData.getCredits()); - if (questData.getMode().equals(QuestData.FANTASY)) + if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { int life = questData.getLife(); if (life<15) @@ -121,14 +113,16 @@ public class Gui_Quest extends JFrame implements NewConstants{ //get deck names as Strings - ArrayList list = questData.getDeckNames(); + List list = questData.getDeckNames(); Collections.sort(list); - for(int i = 0; i < list.size(); i++) - deckComboBox.addItem(list.get(i)); + + for (String aList : list) { + deckComboBox.addItem(aList); + } if(Constant.Runtime.HumanDeck[0] != null) deckComboBox.setSelectedItem(Constant.Runtime.HumanDeck[0].getName()); - if (QuestData.FANTASY.equals(questData.getMode())) + if (forge.quest.data.QuestData.FANTASY.equals(questData.getMode())) { } @@ -178,7 +172,7 @@ public class Gui_Quest extends JFrame implements NewConstants{ }); //if (questData.getMode().equals("Fantasy")) - if (QuestData.FANTASY.equals(questData.getMode())) + if (forge.quest.data.QuestData.FANTASY.equals(questData.getMode())) { refreshPets(); @@ -272,7 +266,7 @@ public class Gui_Quest extends JFrame implements NewConstants{ jPanel2.add(oppOneRadio, null); jPanel2.add(oppTwoRadio, null); jPanel2.add(oppThreeRadio, null); - if (QuestData.FANTASY.equals(questData.getMode())) { + if (forge.quest.data.QuestData.FANTASY.equals(questData.getMode())) { this.getContentPane().add(otherShopsButton, null); this.getContentPane().add(lifeLabel,null); this.getContentPane().add(questsButton, null); @@ -316,10 +310,12 @@ public class Gui_Quest extends JFrame implements NewConstants{ void refreshPets(){ petComboBox.removeAllItems(); - ArrayList petList = QuestUtil.getPetNames(questData); - for (int i=0;i petList = questData.getPetManager().getAvailablePetNames(); + + for (String s : petList) { + petComboBox.addItem(s); + } + petComboBox.addItem("None"); petComboBox.addItem("No Plant/Pet"); } @@ -344,7 +340,7 @@ public class Gui_Quest extends JFrame implements NewConstants{ public void execute() { //saves all deck data - QuestData.saveData(AllZone.QuestData); + AllZone.QuestData.saveData(); new Gui_Quest(); } @@ -372,7 +368,7 @@ public class Gui_Quest extends JFrame implements NewConstants{ public void execute() { //saves all deck data - QuestData.saveData(AllZone.QuestData); + AllZone.QuestData.saveData(); new Gui_Quest(); } @@ -413,16 +409,16 @@ public class Gui_Quest extends JFrame implements NewConstants{ Constant.Runtime.Smooth[0] = smoothLandCheckBox.isSelected(); - if (questData.getMode().equals(QuestData.REALISTIC)) + if (questData.getMode().equals(forge.quest.data.QuestData.REALISTIC)) AllZone.GameAction.newGame(human, computer); else { - Object pet = petComboBox.getSelectedItem(); - if (pet != null) - questData.setSelectedPet(pet.toString()); + Object petName = petComboBox.getSelectedItem(); + if (petName != null) + questData.getPetManager().setSelectedPet((String) petName); - CardList hCl = QuestUtil.getHumanPlantAndPet(questData); - int hLife = QuestUtil.getLife(questData); + CardList hCl = forge.quest.data.QuestUtil.getHumanPlantAndPet(questData); + int hLife = questData.getLife(); AllZone.GameAction.newGame(human, computer, hCl, new CardList(), hLife, 20, null); } @@ -448,7 +444,7 @@ public class Gui_Quest extends JFrame implements NewConstants{ Object pet = petComboBox.getSelectedItem(); if (pet != null) - questData.setSelectedPet(pet.toString()); + questData.getPetManager().setSelectedPet((String) pet); Gui_Quest_Assignments g = new Gui_Quest_Assignments(this, human); g.setVisible(true); diff --git a/src/forge/Gui_QuestOptions.java b/src/forge/Gui_QuestOptions.java index d73840925ec..8ea43e28589 100644 --- a/src/forge/Gui_QuestOptions.java +++ b/src/forge/Gui_QuestOptions.java @@ -13,13 +13,12 @@ import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.util.ArrayList; public class Gui_QuestOptions extends JFrame { private static final long serialVersionUID = 2018518804206822235L; - - private QuestData questData = new QuestData(); - + + private forge.quest.data.QuestData questData = new forge.quest.data.QuestData(); + private JLabel jLabel1 = new JLabel(); private JButton continueQuestButton = new JButton(); private JPanel jPanel1 = new JPanel(); @@ -79,7 +78,7 @@ public class Gui_QuestOptions extends JFrame { //show total number of games for each difficulty private void setupRadioButtonText() { - String[] diff = questData.getDifficutlyChoices(); + String[] diff = questData.getDifficultyChoices(); JRadioButton[] b = {easyRadio, mediumRadio, hardRadio, veryHardRadio}; for(int i = 0; i < diff.length; i++) { @@ -188,7 +187,7 @@ public class Gui_QuestOptions extends JFrame { void continueQuestButton_actionPerformed(ActionEvent e) { //set global variable - AllZone.QuestData = QuestData.loadData(); + AllZone.QuestData = forge.quest.data.QuestData.loadData(); AllZone.QuestData.setDifficultyIndex(); dispose(); @@ -207,7 +206,7 @@ public class Gui_QuestOptions extends JFrame { void newQuestButton_actionPerformed(ActionEvent e) { int difficulty = 0; - String mode = fantasyRadio.isSelected() ? QuestData.FANTASY : QuestData.REALISTIC; + String mode = fantasyRadio.isSelected() ? forge.quest.data.QuestData.FANTASY : forge.quest.data.QuestData.REALISTIC; if(easyRadio.isSelected()) difficulty = 0; @@ -234,10 +233,8 @@ public class Gui_QuestOptions extends JFrame { //give the user a few cards to build a deck questData.newGame(difficulty, mode); - copyAIDecks(questData, QuestData.loadData()); - QuestData.saveData(questData); + questData.saveData(); - questData.readAIQuestDeckFiles(); //set global variable AllZone.QuestData = questData; @@ -254,9 +251,10 @@ public class Gui_QuestOptions extends JFrame { } //copy AI decks from old to newData - void copyAIDecks(QuestData newData, QuestData old) { - ArrayList a = old.ai_getDeckNames(); - for(int i = 0; i < a.size(); i++) - newData.ai_addDeck(old.ai_getDeck(a.get(i).toString())); + void copyAIDecks(forge.quest.data.QuestData newData, forge.quest.data.QuestData old) { + java.util.List oldDeckNames = old.ai_getDeckNames(); + for (String oldDeckName : oldDeckNames) { + newData.ai_addDeck(old.ai_getDeck(oldDeckName)); + } } } diff --git a/src/forge/Gui_Quest_Assignments.java b/src/forge/Gui_Quest_Assignments.java index d6ef11f1d2b..d586799f097 100644 --- a/src/forge/Gui_Quest_Assignments.java +++ b/src/forge/Gui_Quest_Assignments.java @@ -13,6 +13,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; +import java.util.List; public class Gui_Quest_Assignments extends JFrame implements NewConstants{ @@ -26,7 +27,7 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{ private ButtonGroup buttonGroup = new ButtonGroup(); - private QuestData questData; + private forge.quest.data.QuestData questData; private Deck hDeck; @@ -79,11 +80,11 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{ read = new ReadQuest_Assignment(ForgeProps.getFile(QUEST.QUESTS), questData); read.run(); - ArrayList questsToDisplay = new ArrayList(); + List questsToDisplay = new ArrayList(); if (questData.getAvailableQuests()!= null && questData.getAvailableQuests().size() > 0) { - ArrayList availableQuests = read.getQuestsByIds(questData.getAvailableQuests()); + List availableQuests = read.getQuestsByIds(questData.getAvailableQuests()); questsToDisplay = availableQuests; /* @@ -97,7 +98,7 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{ else //generate some random quests { //System.out.println("null"); - ArrayList allAvailableQuests = read.getQuests(); + List allAvailableQuests = read.getQuests(); ArrayList availableInts = new ArrayList(); @@ -116,7 +117,7 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{ questsToDisplay.add(qa); } questData.setAvailableQuests(availableInts); - QuestData.saveData(questData); + questData.saveData(); }//else JRadioButton radio; @@ -262,7 +263,7 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{ if(Gui_Quest.newGUICheckbox.isSelected()) AllZone.Display = new GuiDisplay4(); else AllZone.Display = new GuiDisplay3(); - AllZone.GameAction.newGame(hDeck, computerDeck, QuestUtil.getHumanPlantAndPet(questData, selectedQuest), new CardList(), questData.getLife()+extraLife, + AllZone.GameAction.newGame(hDeck, computerDeck, forge.quest.data.QuestUtil.getHumanPlantAndPet(questData, selectedQuest), new CardList(), questData.getLife()+extraLife, selectedQuest.getComputerLife(), selectedQuest); AllZone.Display.setVisible(true); @@ -278,7 +279,7 @@ public class Gui_Quest_Assignments extends JFrame implements NewConstants{ } void quitButton_actionPerformed(ActionEvent e) { - //QuestData.saveData(questData); + //questData.saveData(); //new Gui_Shops(); questGui.setVisible(true); diff --git a/src/forge/Gui_Quest_DeckEditor.java b/src/forge/Gui_Quest_DeckEditor.java index b11406e5069..89517373fab 100644 --- a/src/forge/Gui_Quest_DeckEditor.java +++ b/src/forge/Gui_Quest_DeckEditor.java @@ -1,1025 +1,1001 @@ - -package forge; - - -import java.awt.Color; -import java.awt.Component; -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.GridLayout; -import java.awt.Image; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Random; - -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.SwingUtilities; -import javax.swing.border.Border; -import javax.swing.border.EtchedBorder; -import javax.swing.border.TitledBorder; -import javax.swing.event.MouseInputListener; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.filechooser.FileFilter; - -import forge.error.ErrorViewer; -import forge.gui.game.CardDetailPanel; -import forge.gui.game.CardPicturePanel; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - - -public class Gui_Quest_DeckEditor extends JFrame implements CardContainer, DeckDisplay, NewConstants { - private static final long serialVersionUID = 152061168634545L; - - Gui_Quest_DeckEditor_Menu customMenu; - - //private ImageIcon upIcon = Constant.IO.upIcon; - //private ImageIcon downIcon = Constant.IO.downIcon; - - public TableModel topModel; - public TableModel bottomModel; - - private JScrollPane jScrollPane1 = new JScrollPane(); - private JScrollPane jScrollPane2 = new JScrollPane(); - private JButton removeButton = new JButton(); - @SuppressWarnings("unused") - // border1 - private Border border1; - private TitledBorder titledBorder1; - private Border border2; - private TitledBorder titledBorder2; - private JButton addButton = new JButton(); - private JButton analysisButton = new JButton(); - private JButton changePictureButton = new JButton(); - private JButton removePictureButton = new JButton(); - private JLabel statsLabel = new JLabel(); - private JTable topTable = new JTable(); - private JTable bottomTable = new JTable(); - private GridLayout gridLayout1 = new GridLayout(); - private JLabel statsLabel2 = new JLabel(); - private JLabel jLabel1 = new JLabel(); - - public JCheckBox whiteCheckBox = new JCheckBox("W", true); - public JCheckBox blueCheckBox = new JCheckBox("U", true); - public JCheckBox blackCheckBox = new JCheckBox("B", true); - public JCheckBox redCheckBox = new JCheckBox("R", true); - public JCheckBox greenCheckBox = new JCheckBox("G", true); - public JCheckBox colorlessCheckBox = new JCheckBox("C", true); - - public JCheckBox landCheckBox = new JCheckBox("Land", true); - public JCheckBox creatureCheckBox = new JCheckBox("Creature", true); - public JCheckBox sorceryCheckBox = new JCheckBox("Sorcery", true); - public JCheckBox instantCheckBox = new JCheckBox("Instant", true); - public JCheckBox planeswalkerCheckBox = new JCheckBox("Planeswalker", true); - public JCheckBox artifactCheckBox = new JCheckBox("Artifact", true); - public JCheckBox enchantmentCheckBox = new JCheckBox("Enchant", true); - public CardList stCardList; - public boolean filterUsed; - private CardList top; - private CardList bottom; - public Card cCardHQ; - private static File previousDirectory = null; - - private CardDetailPanel detail = new CardDetailPanel(null); - private CardPicturePanel picture = new CardPicturePanel(null); - private JPanel glassPane; - - @Override - public void setTitle(String message) { - super.setTitle(message); - } - - public void updateDisplay(CardList top, CardList bottom) { - - this.top = top; - this.bottom = bottom; - - topModel.clear(); - bottomModel.clear(); - - if(AllZone.NameChanger.shouldChangeCardName()) { - top = new CardList(AllZone.NameChanger.changeCard(top.toArray())); - bottom = new CardList(AllZone.NameChanger.changeCard(bottom.toArray())); - } - - Card c; - String cardName; - QuestData_BoosterPack pack = new QuestData_BoosterPack(); - - ArrayList addedList = AllZone.QuestData.getAddedCards(); - - - //update top - for(int i = 0; i < top.size(); i++) { - c = top.get(i); - - cardName = c.getName(); - c.setRarity(pack.getRarity(cardName)); - - if(addedList.contains(cardName)) c.setRarity("new"); - - //String PC = c.getSVar("PicCount"); - Random r = new Random(); - //int n = 0; - //if (!PC.equals("")) { - // if (PC.matches("[0-9][0-9]?")) - // n = Integer.parseInt(PC); - // if (n > 1) - // c.setRandomPicture(r.nextInt(n)); - //} - - if (c.getCurSetCode().equals("")) - c.setCurSetCode(c.getMostRecentSet()); - - if (!c.getCurSetCode().equals("")) { - int n = SetInfoUtil.getSetInfo_Code(c.getSets(), c.getCurSetCode()).PicCount; - if (n > 1) - c.setRandomPicture(r.nextInt(n-1) + 1); - - c.setImageFilename(CardUtil.buildFilename(c)); - } - - - topModel.addCard(c); - }//for - - //update bottom - for(int i = 0; i < bottom.size(); i++) { - c = bottom.get(i); - - c.setRarity(pack.getRarity(c.getName()));; - - //String PC = c.getSVar("PicCount"); - Random r = new Random(); - //int n = 0; - //if (!PC.equals("")){ - // if (PC.matches("[0-9][0-9]?")) - // n = Integer.parseInt(PC); - // if (n > 1) - // c.setRandomPicture(r.nextInt(n)); - //} - - if (c.getCurSetCode().equals("")) - c.setCurSetCode(c.getMostRecentSet()); - - if (!c.getCurSetCode().equals("")) { - int n = SetInfoUtil.getSetInfo_Code(c.getSets(), c.getCurSetCode()).PicCount; - if (n > 1) - c.setRandomPicture(r.nextInt(n-1) + 1); - - c.setImageFilename(CardUtil.buildFilename(c)); - } - - bottomModel.addCard(c); - }//for - - topModel.resort(); - bottomModel.resort(); - }//updateDisplay - - public void updateDisplay() { - //updateDisplay(this.top, this.bottom); - - topModel.clear(); - - if(AllZone.NameChanger.shouldChangeCardName()) { - top = new CardList(AllZone.NameChanger.changeCard(top.toArray())); - bottom = new CardList(AllZone.NameChanger.changeCard(bottom.toArray())); - } - - Card c; - String cardName; - ReadBoosterPack pack = new ReadBoosterPack(); - - // update top - for(int i = 0; i < top.size(); i++) { - c = top.get(i); - - // add rarity to card if this is a sealed card pool - - cardName = AllZone.NameChanger.getOriginalName(c.getName()); - if(!pack.getRarity(cardName).equals("error")) { - c.setRarity(pack.getRarity(cardName)); - } - - boolean filteredOut = filterByColor(c); - - if(!filteredOut) { - filteredOut = filterByType(c); - } - - if(!filteredOut) { - topModel.addCard(c); - } - }// for - - topModel.resort(); - } - - private boolean filterByColor(Card c) { - boolean filterOut = false; - - if(!whiteCheckBox.isSelected()) { - if(CardUtil.getColors(c).contains(Constant.Color.White)) { - filterOut = true; - } - } - - if(!blueCheckBox.isSelected()) { - if(CardUtil.getColors(c).contains(Constant.Color.Blue)) { - filterOut = true; - } - } - - if(!blackCheckBox.isSelected()) { - if(CardUtil.getColors(c).contains(Constant.Color.Black)) { - filterOut = true; - } - } - - if(!redCheckBox.isSelected()) { - if(CardUtil.getColors(c).contains(Constant.Color.Red)) { - filterOut = true; - } - } - - if(!greenCheckBox.isSelected()) { - if(CardUtil.getColors(c).contains(Constant.Color.Green)) { - filterOut = true; - } - } - - if(!colorlessCheckBox.isSelected()) { - if(CardUtil.getColors(c).contains(Constant.Color.Colorless)) { - filterOut = true; - } - } - - return filterOut; - } - - private boolean filterByType(Card c) { - boolean filterOut = false; - - if(!landCheckBox.isSelected() && c.isLand()) { - filterOut = true; - } - - if(!creatureCheckBox.isSelected() && c.isCreature()) { - filterOut = true; - } - - if(!sorceryCheckBox.isSelected() && c.isSorcery()) { - filterOut = true; - } - - if(!instantCheckBox.isSelected() && c.isInstant()) { - filterOut = true; - } - - if(!planeswalkerCheckBox.isSelected() && c.isPlaneswalker()) { - filterOut = true; - } - - if(!artifactCheckBox.isSelected() && c.isArtifact()) { - filterOut = true; - } - - if(!enchantmentCheckBox.isSelected() && c.isEnchantment()) { - filterOut = true; - } - - return filterOut; - } - - public TableModel getTopTableModel() { - return topModel; - } - - - //top shows available card pool - public CardList getTop() { - return topModel.getCards(); - } - - //bottom shows cards that the user has chosen for his library - public CardList getBottom() { - return bottomModel.getCards(); - } - - - public void show(final Command exitCommand) { - final Command exit = new Command() { - private static final long serialVersionUID = -7428793574300520612L; - - public void execute() { - Gui_Quest_DeckEditor.this.dispose(); - exitCommand.execute(); - } - }; - - //do not change this!!!! - this.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent ev) { - customMenu.close(); - } - }); - - - setup(); - - customMenu = new Gui_Quest_DeckEditor_Menu(this, exit); - this.setJMenuBar(customMenu); - - - QuestData questData = AllZone.QuestData; - Deck deck = null; - - //open deck that the player used if QuestData has it - if(Constant.Runtime.HumanDeck[0] != null - && questData.getDeckNames().contains(Constant.Runtime.HumanDeck[0].getName())) { - deck = questData.getDeck(Constant.Runtime.HumanDeck[0].getName()); - } else { - deck = new Deck(Constant.GameType.Sealed); - deck.setName(""); - } - - //tell Gui_Quest_DeckEditor the name of the deck - customMenu.setHumanPlayer(deck.getName()); - - - //convert Deck main into CardList to show on the screen - //convert Deck main into CardList to show on the screen - CardList bottom = new CardList(); - for(int i = 0; i < deck.countMain(); i++) { - bottom.add(AllZone.CardFactory.getCard(deck.getMain(i), null)); - } - - - ArrayList list = AllZone.QuestData.getCardpool(); - CardList cardpool = Gui_Quest_DeckEditor_Menu.covertToCardList(list); - - //remove bottom cards that are in the deck from the card pool - for(int i = 0; i < bottom.size(); i++) { - if(cardpool.containsName(bottom.get(i).getName())) cardpool.remove(bottom.get(i).getName()); - } - - //show cards, makes this user friendly, lol, well may, ha - updateDisplay(cardpool, bottom); - - - //this affects the card pool - topModel.sort(4, true);//sort by type - topModel.sort(3, true);//then sort by color - - bottomModel.sort(1, true); - }//show(Command) - - private void addListeners() { - MouseInputListener l = new MouseInputListener() { - public void mouseReleased(MouseEvent e) { - redispatchMouseEvent(e); - } - - public void mousePressed(MouseEvent e) { - redispatchMouseEvent(e); - } - - public void mouseExited(MouseEvent e) { - redispatchMouseEvent(e); - } - - public void mouseEntered(MouseEvent e) { - redispatchMouseEvent(e); - } - - public void mouseClicked(MouseEvent e) { - redispatchMouseEvent(e); - } - - public void mouseMoved(MouseEvent e) { - redispatchMouseEvent(e); - } - - public void mouseDragged(MouseEvent e) { - redispatchMouseEvent(e); - } - - private void redispatchMouseEvent(MouseEvent e) { - Container content = getContentPane(); - Point glassPoint = e.getPoint(); - Point contentPoint = SwingUtilities.convertPoint(glassPane, glassPoint, content); - - Component component = SwingUtilities.getDeepestComponentAt(content, contentPoint.x, contentPoint.y); - if(component == null || !SwingUtilities.isDescendingFrom(component, picture)) { - glassPane.setVisible(false); - } - } - }; - - glassPane.addMouseMotionListener(l); - glassPane.addMouseListener(l); - - picture.addMouseListener(new MouseAdapter() { - @Override - public void mouseEntered(MouseEvent e) { - Card c = picture.getCard(); - if(c == null) return; - Image i = ImageCache.getOriginalImage(c); - if(i == null) return; - if(i.getWidth(null) < 200) return; - glassPane.setVisible(true); - } - }); - }//addListeners() - - public void setup() { - addListeners(); - - //construct topTable, get all cards - topModel = new TableModel(new CardList(), this); - topModel.addListeners(topTable); - topTable.setModel(topModel); - topModel.resizeCols(topTable); - - //construct bottomModel - bottomModel = new TableModel(this); - bottomModel.addListeners(bottomTable); - bottomTable.setModel(bottomModel); - bottomModel.resizeCols(bottomTable); - - //get stats from deck - bottomModel.addTableModelListener(new TableModelListener() { - public void tableChanged(TableModelEvent ev) { - CardList deck = bottomModel.getCards(); - statsLabel.setText(getStats(deck)); - } - }); - - - //get stats from all cards - topModel.addTableModelListener(new TableModelListener() { - public void tableChanged(TableModelEvent ev) { - CardList deck = topModel.getCards(); - statsLabel2.setText(getStats(deck)); - } - }); - - setSize(1024, 768); - this.setResizable(false); - Dimension screen = getToolkit().getScreenSize(); - Rectangle bounds = getBounds(); - bounds.width = 1024; - bounds.height = 768; - bounds.x = (screen.width - bounds.width) / 2; - bounds.y = (screen.height - bounds.height) / 2; - setBounds(bounds); - - - //TODO use this as soon the deck editor has resizable GUI -// //Use both so that when "un"maximizing, the frame isn't tiny -// setSize(1024, 740); -// setExtendedState(Frame.MAXIMIZED_BOTH); - }//setupAndDisplay() - - private String getStats(CardList deck) { - int total = deck.size(); - int creature = deck.getType("Creature").size(); - int land = deck.getType("Land").size(); - - StringBuffer show = new StringBuffer(); - show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ").append(land); - String[] color = Constant.Color.Colors; - for(int i = 0; i < 5; i++) - show.append(", ").append(color[i]).append(" - ").append(CardListUtil.getColor(deck, color[i]).size()); - - return show.toString(); - }//getStats() - - public Gui_Quest_DeckEditor() { - try { - filterUsed = false; - jbInit(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - } - } - - public Card getCard() { - return detail.getCard(); - } - - public void setCard(Card card) { - detail.setCard(card); - picture.setCard(card); - } - - private void jbInit() throws Exception { - - border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white, new Color(148, 145, 140)); - titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)), - "All Cards"); - border2 = BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)); - titledBorder2 = new TitledBorder(border2, "Deck"); - this.getContentPane().setLayout(null); - jScrollPane1.setBorder(titledBorder1); - jScrollPane1.setBounds(new Rectangle(19, 20, 726, 346)); - jScrollPane2.setBorder(titledBorder2); - jScrollPane2.setBounds(new Rectangle(19, 458, 726, 218)); - removeButton.setBounds(new Rectangle(180, 403, 146, 49)); - //removeButton.setIcon(upIcon); - if(!Gui_NewGame.useLAFFonts.isSelected()) removeButton.setFont(new java.awt.Font("Dialog", 0, 13)); - removeButton.setText("Remove Card"); - removeButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - removeButton_actionPerformed(e); - } - }); - addButton.setText("Add Card"); - addButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - addButton_actionPerformed(e); - } - }); - //addButton.setIcon(downIcon); - if(!Gui_NewGame.useLAFFonts.isSelected()) addButton.setFont(new java.awt.Font("Dialog", 0, 13)); - addButton.setBounds(new Rectangle(23, 403, 146, 49)); - - analysisButton.setText("Deck Analysis"); - analysisButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - analysisButton_actionPerformed(e); - } - }); - if(!Gui_NewGame.useLAFFonts.isSelected()) analysisButton.setFont(new java.awt.Font("Dialog", 0, 13)); - analysisButton.setBounds(new Rectangle(578, 426, 166, 25)); - - changePictureButton.setText("Change picture..."); - changePictureButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - changePictureButton_actionPerformed(e); - } - }); - if(!Gui_NewGame.useLAFFonts.isSelected()) changePictureButton.setFont(new java.awt.Font("Dialog", 0, 10)); - changePictureButton.setBounds(new Rectangle(765, 349, 118, 20)); - - removePictureButton.setText("Remove picture..."); - removePictureButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - removePictureButton_actionPerformed(e); - } - }); - if(!Gui_NewGame.useLAFFonts.isSelected()) removePictureButton.setFont(new java.awt.Font("Dialog", 0, 10)); - removePictureButton.setBounds(new Rectangle(885, 349, 118, 20)); - - /** - * Type filtering - */ - Font f = new Font("Tahoma", Font.PLAIN, 10); - landCheckBox.setBounds(340, 400, 48, 20); - if(!Gui_NewGame.useLAFFonts.isSelected()) landCheckBox.setFont(f); - landCheckBox.setOpaque(false); - landCheckBox.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - creatureCheckBox.setBounds(385, 400, 65, 20); - if(!Gui_NewGame.useLAFFonts.isSelected()) creatureCheckBox.setFont(f); - creatureCheckBox.setOpaque(false); - creatureCheckBox.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - sorceryCheckBox.setBounds(447, 400, 62, 20); - if(!Gui_NewGame.useLAFFonts.isSelected()) sorceryCheckBox.setFont(f); - sorceryCheckBox.setOpaque(false); - sorceryCheckBox.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - instantCheckBox.setBounds(505, 400, 60, 20); - if(!Gui_NewGame.useLAFFonts.isSelected()) instantCheckBox.setFont(f); - instantCheckBox.setOpaque(false); - instantCheckBox.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - planeswalkerCheckBox.setBounds(558, 400, 85, 20); - if(!Gui_NewGame.useLAFFonts.isSelected()) planeswalkerCheckBox.setFont(f); - planeswalkerCheckBox.setOpaque(false); - planeswalkerCheckBox.addItemListener(new ItemListener() { - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - artifactCheckBox.setBounds(638, 400, 58, 20); - if(!Gui_NewGame.useLAFFonts.isSelected()) artifactCheckBox.setFont(f); - artifactCheckBox.setOpaque(false); - artifactCheckBox.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - enchantmentCheckBox.setBounds(692, 400, 80, 20); - if(!Gui_NewGame.useLAFFonts.isSelected()) enchantmentCheckBox.setFont(f); - enchantmentCheckBox.setOpaque(false); - enchantmentCheckBox.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - - /** - * Color filtering - */ - whiteCheckBox.setBounds(340, 430, 40, 20); - whiteCheckBox.setOpaque(false); - whiteCheckBox.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - blueCheckBox.setBounds(380, 430, 40, 20); - blueCheckBox.setOpaque(false); - blueCheckBox.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - blackCheckBox.setBounds(420, 430, 40, 20); - blackCheckBox.setOpaque(false); - blackCheckBox.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - redCheckBox.setBounds(460, 430, 40, 20); - redCheckBox.setOpaque(false); - redCheckBox.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - greenCheckBox.setBounds(500, 430, 40, 20); - greenCheckBox.setOpaque(false); - greenCheckBox.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - updateDisplay(); - } - }); - colorlessCheckBox.setBounds(540, 430, 40, 20); - colorlessCheckBox.setOpaque(false); - colorlessCheckBox.addItemListener(new ItemListener() { - - public void itemStateChanged(ItemEvent e) { - - updateDisplay(); - } - }); - - /** - * Other - */ - - detail.setBounds(new Rectangle(765, 23, 239, 323)); - picture.setBounds(new Rectangle(765, 372, 239, 338)); - picture.addMouseListener(new CustomListener()); - if(!Gui_NewGame.useLAFFonts.isSelected()) statsLabel.setFont(new java.awt.Font("Dialog", 0, 14)); - statsLabel.setText("Total - 0, Creatures - 0 Land - 0"); - statsLabel.setBounds(new Rectangle(19, 672, 720, 31)); - //Do not lower statsLabel any lower, we want this to be visible at 1024 x 768 screen size - this.setTitle("Deck Editor"); - gridLayout1.setColumns(1); - gridLayout1.setRows(0); - statsLabel2.setBounds(new Rectangle(19, 365, 720, 31)); - statsLabel2.setText("Total - 0, Creatures - 0 Land - 0"); - if(!Gui_NewGame.useLAFFonts.isSelected()) statsLabel2.setFont(new java.awt.Font("Dialog", 0, 14)); - jLabel1.setText("Click on the column name (like name or color) to sort the cards"); - jLabel1.setBounds(new Rectangle(20, 1, 400, 19)); - this.getContentPane().add(detail, null); - this.getContentPane().add(picture, null); - this.getContentPane().add(jScrollPane1, null); - this.getContentPane().add(jScrollPane2, null); - this.getContentPane().add(addButton, null); - this.getContentPane().add(removeButton, null); - this.getContentPane().add(analysisButton, null); - this.getContentPane().add(changePictureButton, null); - this.getContentPane().add(removePictureButton, null); - this.getContentPane().add(statsLabel2, null); - this.getContentPane().add(statsLabel, null); - this.getContentPane().add(jLabel1, null); - jScrollPane2.getViewport().add(bottomTable, null); - jScrollPane1.getViewport().add(topTable, null); - - this.getContentPane().add(landCheckBox, null); - this.getContentPane().add(creatureCheckBox, null); - this.getContentPane().add(sorceryCheckBox, null); - this.getContentPane().add(instantCheckBox, null); - this.getContentPane().add(planeswalkerCheckBox, null); - this.getContentPane().add(artifactCheckBox, null); - this.getContentPane().add(enchantmentCheckBox, null); - - this.getContentPane().add(whiteCheckBox, null); - this.getContentPane().add(blueCheckBox, null); - this.getContentPane().add(blackCheckBox, null); - this.getContentPane().add(redCheckBox, null); - this.getContentPane().add(greenCheckBox, null); - this.getContentPane().add(colorlessCheckBox, null); - - glassPane = new JPanel() { - private static final long serialVersionUID = 7394924497724994317L; - - @Override - protected void paintComponent(java.awt.Graphics g) { - Image image = ImageCache.getOriginalImage(picture.getCard()); - g.drawImage(image, glassPane.getWidth() - image.getWidth(null), glassPane.getHeight() - - image.getHeight(null), null); - } - }; - setGlassPane(glassPane); - } - - void addButton_actionPerformed(ActionEvent e) { - setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved"); - - int n = topTable.getSelectedRow(); - if(n != -1) { - Card c = topModel.rowToCard(n); - bottomModel.addCard(c); - bottomModel.resort(); - if(filterUsed == true) { - stCardList.remove(c.getName()); - stCardList.shuffle(); - } - - - if(!Constant.GameType.Constructed.equals(customMenu.getGameType())) { - topModel.removeCard(c); - if(filterUsed == false) { - stCardList = this.getTop(); - } - - } - - //3 conditions" 0 cards left, select the same row, select next row - int size = topModel.getRowCount(); - if(size != 0) { - if(size == n) n--; - topTable.addRowSelectionInterval(n, n); - } - }//if(valid row) - - - }//addButton_actionPerformed - - void analysisButton_actionPerformed(ActionEvent e) { - - if(bottomModel.getRowCount() == 0) { - JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck", - JOptionPane.INFORMATION_MESSAGE); - } else { - Gui_Quest_DeckEditor g = Gui_Quest_DeckEditor.this; - GUI_DeckAnalysis dAnalysis = new GUI_DeckAnalysis(g, bottomModel); - dAnalysis.setVisible(true); - g.setEnabled(false); - } - } - - void changePictureButton_actionPerformed(ActionEvent e) { - if(cCardHQ != null) { - File file = getImportFilename(); - if(file != null) { - String fileName = GuiDisplayUtil.cleanString(cCardHQ.getName()) + ".jpg"; - File base = ForgeProps.getFile(IMAGE_BASE); - File f = new File(base, fileName); - f.delete(); - - try { - - f.createNewFile(); - FileOutputStream fos = new FileOutputStream(f); - FileInputStream fis = new FileInputStream(file); - byte[] buff = new byte[32 * 1024]; - int length; - while(fis.available() > 0) { - length = fis.read(buff); - if(length > 0) fos.write(buff, 0, length); - } - fos.flush(); - fis.close(); - fos.close(); - setCard(cCardHQ); - - } catch(IOException e1) { - e1.printStackTrace(); - } - - } - } - } - - private File getImportFilename() { - JFileChooser chooser = new JFileChooser(previousDirectory); - ImagePreviewPanel preview = new ImagePreviewPanel(); - chooser.setAccessory(preview); - chooser.addPropertyChangeListener(preview); - chooser.addChoosableFileFilter(dckFilter); - int returnVal = chooser.showOpenDialog(null); - - if(returnVal == JFileChooser.APPROVE_OPTION) { - File file = chooser.getSelectedFile(); - previousDirectory = file.getParentFile(); - return file; - } - - - return null; - - } - - private FileFilter dckFilter = new FileFilter() { - - @Override - public boolean accept(File f) { - return f.getName().endsWith(".jpg") || f.isDirectory(); - } - - @Override - public String getDescription() { - return "*.jpg"; - } - - }; - - - void removePictureButton_actionPerformed(ActionEvent e) { - if(cCardHQ != null) { - String options[] = {"Yes", "No"}; - int value = JOptionPane.showOptionDialog(null, - "Do you want delete " + cCardHQ.getName() + " picture?", "Delete picture", - JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); - if(value == 0) { - String fileName = GuiDisplayUtil.cleanString(cCardHQ.getName()) + ".jpg"; - File base = ForgeProps.getFile(IMAGE_BASE); - File f = new File(base, fileName); - f.delete(); - JOptionPane.showMessageDialog(null, "Picture " + cCardHQ.getName() + " deleted.", - "Delete picture", JOptionPane.INFORMATION_MESSAGE); - setCard(cCardHQ); - } - } - - } - - - void removeButton_actionPerformed(ActionEvent e) { - setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved"); - - int n = bottomTable.getSelectedRow(); - if(n != -1) { - Card c = bottomModel.rowToCard(n); - bottomModel.removeCard(c); - if(filterUsed == true) { - stCardList.add(c); - } - - if(!Constant.GameType.Constructed.equals(customMenu.getGameType())) { - topModel.addCard(c); - topModel.resort(); - if(filterUsed == false) { - stCardList = this.getTop(); - } - } - - //3 conditions" 0 cards left, select the same row, select next row - int size = bottomModel.getRowCount(); - if(size != 0) { - if(size == n) n--; - bottomTable.addRowSelectionInterval(n, n); - } - }//if(valid row) - - - }//removeButton_actionPerformed - - @SuppressWarnings("unused") - // stats_actionPerformed - private void stats_actionPerformed(CardList list) { - - } - - //refresh Gui from deck, Gui shows the cards in the deck - @SuppressWarnings("unused") - // refreshGui - private void refreshGui() { - Deck deck = Constant.Runtime.HumanDeck[0]; - if(deck == null) //this is just a patch, i know - deck = new Deck(Constant.Runtime.GameType[0]); - - topModel.clear(); - bottomModel.clear(); - - Card c; - ReadBoosterPack pack = new ReadBoosterPack(); - for(int i = 0; i < deck.countMain(); i++) { - c = AllZone.CardFactory.getCard(deck.getMain(i), AllZone.HumanPlayer); - - c.setRarity(pack.getRarity(c.getName())); - - - bottomModel.addCard(c); - }//for - - if(deck.isSealed() || deck.isDraft()) { - //add sideboard to GUI - for(int i = 0; i < deck.countSideboard(); i++) { - c = AllZone.CardFactory.getCard(deck.getSideboard(i), AllZone.HumanPlayer); - c.setRarity(pack.getRarity(c.getName())); - topModel.addCard(c); - } - } else { - CardList all = AllZone.CardFactory.getAllCards(); - for(int i = 0; i < all.size(); i++) - topModel.addCard(all.get(i)); - } - - topModel.resort(); - bottomModel.resort(); - }////refreshGui() - - public class CustomListener extends MouseAdapter { -// TODO reenable -// public void mouseEntered(MouseEvent e) { -// -// if(picturePanel.getComponentCount() != 0) { -// -// -// if(GuiDisplayUtil.IsPictureHQExists(cCardHQ)) { -// int cWidth = 0; -// try { -// cWidth = GuiDisplayUtil.getPictureHQwidth(cCardHQ); -// } catch(IOException e2) { -// // TODO Auto-generated catch block -// e2.printStackTrace(); -// } -// int cHeight = 0; -// try { -// cHeight = GuiDisplayUtil.getPictureHQheight(cCardHQ); -// } catch(IOException e2) { -// // TODO Auto-generated catch block -// e2.printStackTrace(); -// } -// -// if(cWidth >= 312 && cHeight >= 445) { -// -// GUI_PictureHQ hq = new GUI_PictureHQ(Gui_Quest_DeckEditor.this, cCardHQ); -// try { -// hq.letsGo(Gui_Quest_DeckEditor.this, cCardHQ); -// } catch(IOException e1) { -// e1.printStackTrace(); -// } -// } -// -// } -// } -// -// } - } - -} + +package forge; + + +import forge.error.ErrorViewer; +import forge.gui.game.CardDetailPanel; +import forge.gui.game.CardPicturePanel; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; +import forge.quest.data.QuestBoosterPack; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; +import javax.swing.event.MouseInputListener; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import javax.swing.filechooser.FileFilter; +import java.awt.Color; +import java.awt.*; +import java.awt.event.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Random; + + +public class Gui_Quest_DeckEditor extends JFrame implements CardContainer, DeckDisplay, NewConstants { + private static final long serialVersionUID = 152061168634545L; + + Gui_Quest_DeckEditor_Menu customMenu; + + //private ImageIcon upIcon = Constant.IO.upIcon; + //private ImageIcon downIcon = Constant.IO.downIcon; + + public TableModel topModel; + public TableModel bottomModel; + + private JScrollPane jScrollPane1 = new JScrollPane(); + private JScrollPane jScrollPane2 = new JScrollPane(); + private JButton removeButton = new JButton(); + @SuppressWarnings("unused") + // border1 + private Border border1; + private TitledBorder titledBorder1; + private Border border2; + private TitledBorder titledBorder2; + private JButton addButton = new JButton(); + private JButton analysisButton = new JButton(); + private JButton changePictureButton = new JButton(); + private JButton removePictureButton = new JButton(); + private JLabel statsLabel = new JLabel(); + private JTable topTable = new JTable(); + private JTable bottomTable = new JTable(); + private GridLayout gridLayout1 = new GridLayout(); + private JLabel statsLabel2 = new JLabel(); + private JLabel jLabel1 = new JLabel(); + + public JCheckBox whiteCheckBox = new JCheckBox("W", true); + public JCheckBox blueCheckBox = new JCheckBox("U", true); + public JCheckBox blackCheckBox = new JCheckBox("B", true); + public JCheckBox redCheckBox = new JCheckBox("R", true); + public JCheckBox greenCheckBox = new JCheckBox("G", true); + public JCheckBox colorlessCheckBox = new JCheckBox("C", true); + + public JCheckBox landCheckBox = new JCheckBox("Land", true); + public JCheckBox creatureCheckBox = new JCheckBox("Creature", true); + public JCheckBox sorceryCheckBox = new JCheckBox("Sorcery", true); + public JCheckBox instantCheckBox = new JCheckBox("Instant", true); + public JCheckBox planeswalkerCheckBox = new JCheckBox("Planeswalker", true); + public JCheckBox artifactCheckBox = new JCheckBox("Artifact", true); + public JCheckBox enchantmentCheckBox = new JCheckBox("Enchant", true); + public CardList stCardList; + public boolean filterUsed; + private CardList top; + private CardList bottom; + public Card cCardHQ; + private static File previousDirectory = null; + + private CardDetailPanel detail = new CardDetailPanel(null); + private CardPicturePanel picture = new CardPicturePanel(null); + private JPanel glassPane; + + @Override + public void setTitle(String message) { + super.setTitle(message); + } + + public void updateDisplay(CardList top, CardList bottom) { + + this.top = top; + this.bottom = bottom; + + topModel.clear(); + bottomModel.clear(); + + if(AllZone.NameChanger.shouldChangeCardName()) { + top = new CardList(AllZone.NameChanger.changeCard(top.toArray())); + bottom = new CardList(AllZone.NameChanger.changeCard(bottom.toArray())); + } + + Card c; + String cardName; + QuestBoosterPack pack = new QuestBoosterPack(); + + java.util.List addedList = AllZone.QuestData.getAddedCards(); + + + //update top + for(int i = 0; i < top.size(); i++) { + c = top.get(i); + + cardName = c.getName(); + c.setRarity(pack.getRarity(cardName)); + + if(addedList.contains(cardName)) c.setRarity("new"); + + //String PC = c.getSVar("PicCount"); + Random r = new Random(); + //int n = 0; + //if (!PC.equals("")) { + // if (PC.matches("[0-9][0-9]?")) + // n = Integer.parseInt(PC); + // if (n > 1) + // c.setRandomPicture(r.nextInt(n)); + //} + + if (c.getCurSetCode().equals("")) + c.setCurSetCode(c.getMostRecentSet()); + + if (!c.getCurSetCode().equals("")) { + int n = SetInfoUtil.getSetInfo_Code(c.getSets(), c.getCurSetCode()).PicCount; + if (n > 1) + c.setRandomPicture(r.nextInt(n-1) + 1); + + c.setImageFilename(CardUtil.buildFilename(c)); + } + + + topModel.addCard(c); + }//for + + //update bottom + for(int i = 0; i < bottom.size(); i++) { + c = bottom.get(i); + + c.setRarity(pack.getRarity(c.getName()));; + + //String PC = c.getSVar("PicCount"); + Random r = new Random(); + //int n = 0; + //if (!PC.equals("")){ + // if (PC.matches("[0-9][0-9]?")) + // n = Integer.parseInt(PC); + // if (n > 1) + // c.setRandomPicture(r.nextInt(n)); + //} + + if (c.getCurSetCode().equals("")) + c.setCurSetCode(c.getMostRecentSet()); + + if (!c.getCurSetCode().equals("")) { + int n = SetInfoUtil.getSetInfo_Code(c.getSets(), c.getCurSetCode()).PicCount; + if (n > 1) + c.setRandomPicture(r.nextInt(n-1) + 1); + + c.setImageFilename(CardUtil.buildFilename(c)); + } + + bottomModel.addCard(c); + }//for + + topModel.resort(); + bottomModel.resort(); + }//updateDisplay + + public void updateDisplay() { + //updateDisplay(this.top, this.bottom); + + topModel.clear(); + + if(AllZone.NameChanger.shouldChangeCardName()) { + top = new CardList(AllZone.NameChanger.changeCard(top.toArray())); + bottom = new CardList(AllZone.NameChanger.changeCard(bottom.toArray())); + } + + Card c; + String cardName; + ReadBoosterPack pack = new ReadBoosterPack(); + + // update top + for(int i = 0; i < top.size(); i++) { + c = top.get(i); + + // add rarity to card if this is a sealed card pool + + cardName = AllZone.NameChanger.getOriginalName(c.getName()); + if(!pack.getRarity(cardName).equals("error")) { + c.setRarity(pack.getRarity(cardName)); + } + + boolean filteredOut = filterByColor(c); + + if(!filteredOut) { + filteredOut = filterByType(c); + } + + if(!filteredOut) { + topModel.addCard(c); + } + }// for + + topModel.resort(); + } + + private boolean filterByColor(Card c) { + boolean filterOut = false; + + if(!whiteCheckBox.isSelected()) { + if(CardUtil.getColors(c).contains(Constant.Color.White)) { + filterOut = true; + } + } + + if(!blueCheckBox.isSelected()) { + if(CardUtil.getColors(c).contains(Constant.Color.Blue)) { + filterOut = true; + } + } + + if(!blackCheckBox.isSelected()) { + if(CardUtil.getColors(c).contains(Constant.Color.Black)) { + filterOut = true; + } + } + + if(!redCheckBox.isSelected()) { + if(CardUtil.getColors(c).contains(Constant.Color.Red)) { + filterOut = true; + } + } + + if(!greenCheckBox.isSelected()) { + if(CardUtil.getColors(c).contains(Constant.Color.Green)) { + filterOut = true; + } + } + + if(!colorlessCheckBox.isSelected()) { + if(CardUtil.getColors(c).contains(Constant.Color.Colorless)) { + filterOut = true; + } + } + + return filterOut; + } + + private boolean filterByType(Card c) { + boolean filterOut = false; + + if(!landCheckBox.isSelected() && c.isLand()) { + filterOut = true; + } + + if(!creatureCheckBox.isSelected() && c.isCreature()) { + filterOut = true; + } + + if(!sorceryCheckBox.isSelected() && c.isSorcery()) { + filterOut = true; + } + + if(!instantCheckBox.isSelected() && c.isInstant()) { + filterOut = true; + } + + if(!planeswalkerCheckBox.isSelected() && c.isPlaneswalker()) { + filterOut = true; + } + + if(!artifactCheckBox.isSelected() && c.isArtifact()) { + filterOut = true; + } + + if(!enchantmentCheckBox.isSelected() && c.isEnchantment()) { + filterOut = true; + } + + return filterOut; + } + + public TableModel getTopTableModel() { + return topModel; + } + + + //top shows available card pool + public CardList getTop() { + return topModel.getCards(); + } + + //bottom shows cards that the user has chosen for his library + public CardList getBottom() { + return bottomModel.getCards(); + } + + + public void show(final Command exitCommand) { + final Command exit = new Command() { + private static final long serialVersionUID = -7428793574300520612L; + + public void execute() { + Gui_Quest_DeckEditor.this.dispose(); + exitCommand.execute(); + } + }; + + //do not change this!!!! + this.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent ev) { + customMenu.close(); + } + }); + + + setup(); + + customMenu = new Gui_Quest_DeckEditor_Menu(this, exit); + this.setJMenuBar(customMenu); + + + forge.quest.data.QuestData questData = AllZone.QuestData; + Deck deck = null; + + //open deck that the player used if QuestData has it + if(Constant.Runtime.HumanDeck[0] != null + && questData.getDeckNames().contains(Constant.Runtime.HumanDeck[0].getName())) { + deck = questData.getDeck(Constant.Runtime.HumanDeck[0].getName()); + } else { + deck = new Deck(Constant.GameType.Sealed); + deck.setName(""); + } + + //tell Gui_Quest_DeckEditor the name of the deck + customMenu.setHumanPlayer(deck.getName()); + + + //convert Deck main into CardList to show on the screen + //convert Deck main into CardList to show on the screen + CardList bottom = new CardList(); + for(int i = 0; i < deck.countMain(); i++) { + bottom.add(AllZone.CardFactory.getCard(deck.getMain(i), null)); + } + + + java.util.List list = AllZone.QuestData.getCardpool(); + CardList cardpool = Gui_Quest_DeckEditor_Menu.covertToCardList(list); + + //remove bottom cards that are in the deck from the card pool + for(int i = 0; i < bottom.size(); i++) { + if(cardpool.containsName(bottom.get(i).getName())) cardpool.remove(bottom.get(i).getName()); + } + + //show cards, makes this user friendly, lol, well may, ha + updateDisplay(cardpool, bottom); + + + //this affects the card pool + topModel.sort(4, true);//sort by type + topModel.sort(3, true);//then sort by color + + bottomModel.sort(1, true); + }//show(Command) + + private void addListeners() { + MouseInputListener l = new MouseInputListener() { + public void mouseReleased(MouseEvent e) { + redispatchMouseEvent(e); + } + + public void mousePressed(MouseEvent e) { + redispatchMouseEvent(e); + } + + public void mouseExited(MouseEvent e) { + redispatchMouseEvent(e); + } + + public void mouseEntered(MouseEvent e) { + redispatchMouseEvent(e); + } + + public void mouseClicked(MouseEvent e) { + redispatchMouseEvent(e); + } + + public void mouseMoved(MouseEvent e) { + redispatchMouseEvent(e); + } + + public void mouseDragged(MouseEvent e) { + redispatchMouseEvent(e); + } + + private void redispatchMouseEvent(MouseEvent e) { + Container content = getContentPane(); + Point glassPoint = e.getPoint(); + Point contentPoint = SwingUtilities.convertPoint(glassPane, glassPoint, content); + + Component component = SwingUtilities.getDeepestComponentAt(content, contentPoint.x, contentPoint.y); + if(component == null || !SwingUtilities.isDescendingFrom(component, picture)) { + glassPane.setVisible(false); + } + } + }; + + glassPane.addMouseMotionListener(l); + glassPane.addMouseListener(l); + + picture.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + Card c = picture.getCard(); + if(c == null) return; + Image i = ImageCache.getOriginalImage(c); + if(i == null) return; + if(i.getWidth(null) < 200) return; + glassPane.setVisible(true); + } + }); + }//addListeners() + + public void setup() { + addListeners(); + + //construct topTable, get all cards + topModel = new TableModel(new CardList(), this); + topModel.addListeners(topTable); + topTable.setModel(topModel); + topModel.resizeCols(topTable); + + //construct bottomModel + bottomModel = new TableModel(this); + bottomModel.addListeners(bottomTable); + bottomTable.setModel(bottomModel); + bottomModel.resizeCols(bottomTable); + + //get stats from deck + bottomModel.addTableModelListener(new TableModelListener() { + public void tableChanged(TableModelEvent ev) { + CardList deck = bottomModel.getCards(); + statsLabel.setText(getStats(deck)); + } + }); + + + //get stats from all cards + topModel.addTableModelListener(new TableModelListener() { + public void tableChanged(TableModelEvent ev) { + CardList deck = topModel.getCards(); + statsLabel2.setText(getStats(deck)); + } + }); + + setSize(1024, 768); + this.setResizable(false); + Dimension screen = getToolkit().getScreenSize(); + Rectangle bounds = getBounds(); + bounds.width = 1024; + bounds.height = 768; + bounds.x = (screen.width - bounds.width) / 2; + bounds.y = (screen.height - bounds.height) / 2; + setBounds(bounds); + + + //TODO use this as soon the deck editor has resizable GUI +// //Use both so that when "un"maximizing, the frame isn't tiny +// setSize(1024, 740); +// setExtendedState(Frame.MAXIMIZED_BOTH); + }//setupAndDisplay() + + private String getStats(CardList deck) { + int total = deck.size(); + int creature = deck.getType("Creature").size(); + int land = deck.getType("Land").size(); + + StringBuffer show = new StringBuffer(); + show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ").append(land); + String[] color = Constant.Color.Colors; + for(int i = 0; i < 5; i++) + show.append(", ").append(color[i]).append(" - ").append(CardListUtil.getColor(deck, color[i]).size()); + + return show.toString(); + }//getStats() + + public Gui_Quest_DeckEditor() { + try { + filterUsed = false; + jbInit(); + } catch(Exception ex) { + ErrorViewer.showError(ex); + } + } + + public Card getCard() { + return detail.getCard(); + } + + public void setCard(Card card) { + detail.setCard(card); + picture.setCard(card); + } + + private void jbInit() throws Exception { + + border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white, new Color(148, 145, 140)); + titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)), + "All Cards"); + border2 = BorderFactory.createEtchedBorder(Color.white, new Color(148, 145, 140)); + titledBorder2 = new TitledBorder(border2, "Deck"); + this.getContentPane().setLayout(null); + jScrollPane1.setBorder(titledBorder1); + jScrollPane1.setBounds(new Rectangle(19, 20, 726, 346)); + jScrollPane2.setBorder(titledBorder2); + jScrollPane2.setBounds(new Rectangle(19, 458, 726, 218)); + removeButton.setBounds(new Rectangle(180, 403, 146, 49)); + //removeButton.setIcon(upIcon); + if(!Gui_NewGame.useLAFFonts.isSelected()) removeButton.setFont(new java.awt.Font("Dialog", 0, 13)); + removeButton.setText("Remove Card"); + removeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + removeButton_actionPerformed(e); + } + }); + addButton.setText("Add Card"); + addButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + addButton_actionPerformed(e); + } + }); + //addButton.setIcon(downIcon); + if(!Gui_NewGame.useLAFFonts.isSelected()) addButton.setFont(new java.awt.Font("Dialog", 0, 13)); + addButton.setBounds(new Rectangle(23, 403, 146, 49)); + + analysisButton.setText("Deck Analysis"); + analysisButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + analysisButton_actionPerformed(e); + } + }); + if(!Gui_NewGame.useLAFFonts.isSelected()) analysisButton.setFont(new java.awt.Font("Dialog", 0, 13)); + analysisButton.setBounds(new Rectangle(578, 426, 166, 25)); + + changePictureButton.setText("Change picture..."); + changePictureButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + changePictureButton_actionPerformed(e); + } + }); + if(!Gui_NewGame.useLAFFonts.isSelected()) changePictureButton.setFont(new java.awt.Font("Dialog", 0, 10)); + changePictureButton.setBounds(new Rectangle(765, 349, 118, 20)); + + removePictureButton.setText("Remove picture..."); + removePictureButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + removePictureButton_actionPerformed(e); + } + }); + if(!Gui_NewGame.useLAFFonts.isSelected()) removePictureButton.setFont(new java.awt.Font("Dialog", 0, 10)); + removePictureButton.setBounds(new Rectangle(885, 349, 118, 20)); + + /** + * Type filtering + */ + Font f = new Font("Tahoma", Font.PLAIN, 10); + landCheckBox.setBounds(340, 400, 48, 20); + if(!Gui_NewGame.useLAFFonts.isSelected()) landCheckBox.setFont(f); + landCheckBox.setOpaque(false); + landCheckBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + creatureCheckBox.setBounds(385, 400, 65, 20); + if(!Gui_NewGame.useLAFFonts.isSelected()) creatureCheckBox.setFont(f); + creatureCheckBox.setOpaque(false); + creatureCheckBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + sorceryCheckBox.setBounds(447, 400, 62, 20); + if(!Gui_NewGame.useLAFFonts.isSelected()) sorceryCheckBox.setFont(f); + sorceryCheckBox.setOpaque(false); + sorceryCheckBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + instantCheckBox.setBounds(505, 400, 60, 20); + if(!Gui_NewGame.useLAFFonts.isSelected()) instantCheckBox.setFont(f); + instantCheckBox.setOpaque(false); + instantCheckBox.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + planeswalkerCheckBox.setBounds(558, 400, 85, 20); + if(!Gui_NewGame.useLAFFonts.isSelected()) planeswalkerCheckBox.setFont(f); + planeswalkerCheckBox.setOpaque(false); + planeswalkerCheckBox.addItemListener(new ItemListener() { + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + artifactCheckBox.setBounds(638, 400, 58, 20); + if(!Gui_NewGame.useLAFFonts.isSelected()) artifactCheckBox.setFont(f); + artifactCheckBox.setOpaque(false); + artifactCheckBox.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + enchantmentCheckBox.setBounds(692, 400, 80, 20); + if(!Gui_NewGame.useLAFFonts.isSelected()) enchantmentCheckBox.setFont(f); + enchantmentCheckBox.setOpaque(false); + enchantmentCheckBox.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + + /** + * Color filtering + */ + whiteCheckBox.setBounds(340, 430, 40, 20); + whiteCheckBox.setOpaque(false); + whiteCheckBox.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + blueCheckBox.setBounds(380, 430, 40, 20); + blueCheckBox.setOpaque(false); + blueCheckBox.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + blackCheckBox.setBounds(420, 430, 40, 20); + blackCheckBox.setOpaque(false); + blackCheckBox.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + redCheckBox.setBounds(460, 430, 40, 20); + redCheckBox.setOpaque(false); + redCheckBox.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + greenCheckBox.setBounds(500, 430, 40, 20); + greenCheckBox.setOpaque(false); + greenCheckBox.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + updateDisplay(); + } + }); + colorlessCheckBox.setBounds(540, 430, 40, 20); + colorlessCheckBox.setOpaque(false); + colorlessCheckBox.addItemListener(new ItemListener() { + + public void itemStateChanged(ItemEvent e) { + + updateDisplay(); + } + }); + + /** + * Other + */ + + detail.setBounds(new Rectangle(765, 23, 239, 323)); + picture.setBounds(new Rectangle(765, 372, 239, 338)); + picture.addMouseListener(new CustomListener()); + if(!Gui_NewGame.useLAFFonts.isSelected()) statsLabel.setFont(new java.awt.Font("Dialog", 0, 14)); + statsLabel.setText("Total - 0, Creatures - 0 Land - 0"); + statsLabel.setBounds(new Rectangle(19, 672, 720, 31)); + //Do not lower statsLabel any lower, we want this to be visible at 1024 x 768 screen size + this.setTitle("Deck Editor"); + gridLayout1.setColumns(1); + gridLayout1.setRows(0); + statsLabel2.setBounds(new Rectangle(19, 365, 720, 31)); + statsLabel2.setText("Total - 0, Creatures - 0 Land - 0"); + if(!Gui_NewGame.useLAFFonts.isSelected()) statsLabel2.setFont(new java.awt.Font("Dialog", 0, 14)); + jLabel1.setText("Click on the column name (like name or color) to sort the cards"); + jLabel1.setBounds(new Rectangle(20, 1, 400, 19)); + this.getContentPane().add(detail, null); + this.getContentPane().add(picture, null); + this.getContentPane().add(jScrollPane1, null); + this.getContentPane().add(jScrollPane2, null); + this.getContentPane().add(addButton, null); + this.getContentPane().add(removeButton, null); + this.getContentPane().add(analysisButton, null); + this.getContentPane().add(changePictureButton, null); + this.getContentPane().add(removePictureButton, null); + this.getContentPane().add(statsLabel2, null); + this.getContentPane().add(statsLabel, null); + this.getContentPane().add(jLabel1, null); + jScrollPane2.getViewport().add(bottomTable, null); + jScrollPane1.getViewport().add(topTable, null); + + this.getContentPane().add(landCheckBox, null); + this.getContentPane().add(creatureCheckBox, null); + this.getContentPane().add(sorceryCheckBox, null); + this.getContentPane().add(instantCheckBox, null); + this.getContentPane().add(planeswalkerCheckBox, null); + this.getContentPane().add(artifactCheckBox, null); + this.getContentPane().add(enchantmentCheckBox, null); + + this.getContentPane().add(whiteCheckBox, null); + this.getContentPane().add(blueCheckBox, null); + this.getContentPane().add(blackCheckBox, null); + this.getContentPane().add(redCheckBox, null); + this.getContentPane().add(greenCheckBox, null); + this.getContentPane().add(colorlessCheckBox, null); + + glassPane = new JPanel() { + private static final long serialVersionUID = 7394924497724994317L; + + @Override + protected void paintComponent(java.awt.Graphics g) { + Image image = ImageCache.getOriginalImage(picture.getCard()); + g.drawImage(image, glassPane.getWidth() - image.getWidth(null), glassPane.getHeight() + - image.getHeight(null), null); + } + }; + setGlassPane(glassPane); + } + + void addButton_actionPerformed(ActionEvent e) { + setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved"); + + int n = topTable.getSelectedRow(); + if(n != -1) { + Card c = topModel.rowToCard(n); + bottomModel.addCard(c); + bottomModel.resort(); + if(filterUsed == true) { + stCardList.remove(c.getName()); + stCardList.shuffle(); + } + + + if(!Constant.GameType.Constructed.equals(customMenu.getGameType())) { + topModel.removeCard(c); + if(filterUsed == false) { + stCardList = this.getTop(); + } + + } + + //3 conditions" 0 cards left, select the same row, select next row + int size = topModel.getRowCount(); + if(size != 0) { + if(size == n) n--; + topTable.addRowSelectionInterval(n, n); + } + }//if(valid row) + + + }//addButton_actionPerformed + + void analysisButton_actionPerformed(ActionEvent e) { + + if(bottomModel.getRowCount() == 0) { + JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck", + JOptionPane.INFORMATION_MESSAGE); + } else { + Gui_Quest_DeckEditor g = Gui_Quest_DeckEditor.this; + GUI_DeckAnalysis dAnalysis = new GUI_DeckAnalysis(g, bottomModel); + dAnalysis.setVisible(true); + g.setEnabled(false); + } + } + + void changePictureButton_actionPerformed(ActionEvent e) { + if(cCardHQ != null) { + File file = getImportFilename(); + if(file != null) { + String fileName = GuiDisplayUtil.cleanString(cCardHQ.getName()) + ".jpg"; + File base = ForgeProps.getFile(IMAGE_BASE); + File f = new File(base, fileName); + f.delete(); + + try { + + f.createNewFile(); + FileOutputStream fos = new FileOutputStream(f); + FileInputStream fis = new FileInputStream(file); + byte[] buff = new byte[32 * 1024]; + int length; + while(fis.available() > 0) { + length = fis.read(buff); + if(length > 0) fos.write(buff, 0, length); + } + fos.flush(); + fis.close(); + fos.close(); + setCard(cCardHQ); + + } catch(IOException e1) { + e1.printStackTrace(); + } + + } + } + } + + private File getImportFilename() { + JFileChooser chooser = new JFileChooser(previousDirectory); + ImagePreviewPanel preview = new ImagePreviewPanel(); + chooser.setAccessory(preview); + chooser.addPropertyChangeListener(preview); + chooser.addChoosableFileFilter(dckFilter); + int returnVal = chooser.showOpenDialog(null); + + if(returnVal == JFileChooser.APPROVE_OPTION) { + File file = chooser.getSelectedFile(); + previousDirectory = file.getParentFile(); + return file; + } + + + return null; + + } + + private FileFilter dckFilter = new FileFilter() { + + @Override + public boolean accept(File f) { + return f.getName().endsWith(".jpg") || f.isDirectory(); + } + + @Override + public String getDescription() { + return "*.jpg"; + } + + }; + + + void removePictureButton_actionPerformed(ActionEvent e) { + if(cCardHQ != null) { + String options[] = {"Yes", "No"}; + int value = JOptionPane.showOptionDialog(null, + "Do you want delete " + cCardHQ.getName() + " picture?", "Delete picture", + JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); + if(value == 0) { + String fileName = GuiDisplayUtil.cleanString(cCardHQ.getName()) + ".jpg"; + File base = ForgeProps.getFile(IMAGE_BASE); + File f = new File(base, fileName); + f.delete(); + JOptionPane.showMessageDialog(null, "Picture " + cCardHQ.getName() + " deleted.", + "Delete picture", JOptionPane.INFORMATION_MESSAGE); + setCard(cCardHQ); + } + } + + } + + + void removeButton_actionPerformed(ActionEvent e) { + setTitle("Deck Editor : " + customMenu.getDeckName() + " : unsaved"); + + int n = bottomTable.getSelectedRow(); + if(n != -1) { + Card c = bottomModel.rowToCard(n); + bottomModel.removeCard(c); + if(filterUsed == true) { + stCardList.add(c); + } + + if(!Constant.GameType.Constructed.equals(customMenu.getGameType())) { + topModel.addCard(c); + topModel.resort(); + if(filterUsed == false) { + stCardList = this.getTop(); + } + } + + //3 conditions" 0 cards left, select the same row, select next row + int size = bottomModel.getRowCount(); + if(size != 0) { + if(size == n) n--; + bottomTable.addRowSelectionInterval(n, n); + } + }//if(valid row) + + + }//removeButton_actionPerformed + + @SuppressWarnings("unused") + // stats_actionPerformed + private void stats_actionPerformed(CardList list) { + + } + + //refresh Gui from deck, Gui shows the cards in the deck + @SuppressWarnings("unused") + // refreshGui + private void refreshGui() { + Deck deck = Constant.Runtime.HumanDeck[0]; + if(deck == null) //this is just a patch, i know + deck = new Deck(Constant.Runtime.GameType[0]); + + topModel.clear(); + bottomModel.clear(); + + Card c; + ReadBoosterPack pack = new ReadBoosterPack(); + for(int i = 0; i < deck.countMain(); i++) { + c = AllZone.CardFactory.getCard(deck.getMain(i), AllZone.HumanPlayer); + + c.setRarity(pack.getRarity(c.getName())); + + + bottomModel.addCard(c); + }//for + + if(deck.isSealed() || deck.isDraft()) { + //add sideboard to GUI + for(int i = 0; i < deck.countSideboard(); i++) { + c = AllZone.CardFactory.getCard(deck.getSideboard(i), AllZone.HumanPlayer); + c.setRarity(pack.getRarity(c.getName())); + topModel.addCard(c); + } + } else { + CardList all = AllZone.CardFactory.getAllCards(); + for(int i = 0; i < all.size(); i++) + topModel.addCard(all.get(i)); + } + + topModel.resort(); + bottomModel.resort(); + }////refreshGui() + + public class CustomListener extends MouseAdapter { +// TODO reenable +// public void mouseEntered(MouseEvent e) { +// +// if(picturePanel.getComponentCount() != 0) { +// +// +// if(GuiDisplayUtil.IsPictureHQExists(cCardHQ)) { +// int cWidth = 0; +// try { +// cWidth = GuiDisplayUtil.getPictureHQwidth(cCardHQ); +// } catch(IOException e2) { +// // TODO Auto-generated catch block +// e2.printStackTrace(); +// } +// int cHeight = 0; +// try { +// cHeight = GuiDisplayUtil.getPictureHQheight(cCardHQ); +// } catch(IOException e2) { +// // TODO Auto-generated catch block +// e2.printStackTrace(); +// } +// +// if(cWidth >= 312 && cHeight >= 445) { +// +// GUI_PictureHQ hq = new GUI_PictureHQ(Gui_Quest_DeckEditor.this, cCardHQ); +// try { +// hq.letsGo(Gui_Quest_DeckEditor.this, cCardHQ); +// } catch(IOException e1) { +// e1.printStackTrace(); +// } +// } +// +// } +// } +// +// } + } + +} diff --git a/src/forge/Gui_Quest_DeckEditor_Menu.java b/src/forge/Gui_Quest_DeckEditor_Menu.java index ab1fdbeac72..3db8cd0f4b9 100644 --- a/src/forge/Gui_Quest_DeckEditor_Menu.java +++ b/src/forge/Gui_Quest_DeckEditor_Menu.java @@ -1,1045 +1,1030 @@ - -package forge; - - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; - -import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.JList; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.filechooser.FileFilter; - -import forge.error.ErrorViewer; -import forge.gui.GuiUtils; - - -//presumes AllZone.QuestData is not null -public class Gui_Quest_DeckEditor_Menu extends JMenuBar { - private static final long serialVersionUID = -4052319220021158574L; - - //this should be false in the public version - //if true, the Quest Deck editor will let you edit the computer's decks - private final boolean canEditComputerDecks; - - private static final String deckEditorName = "Deck Editor"; - - //used for import and export, try to made the gui user friendly - private static File previousDirectory = null; - - private Command exitCommand; - private QuestData questData; - private Deck currentDeck; - - //the class DeckDisplay is in the file "Gui_DeckEditor_Menu.java" - private DeckDisplay deckDisplay; - - - public Gui_Quest_DeckEditor_Menu(DeckDisplay d, Command exit) { - //is a file named "edit" in this directory - //lame but it works, I don't like 2 versions of MTG Forge floating around - //one that lets you edit the AI decks and one that doesn't - File f = new File("edit"); - if(f.exists()) canEditComputerDecks = true; - else canEditComputerDecks = false; - - - deckDisplay = d; - d.setTitle(deckEditorName); - - questData = AllZone.QuestData; - - exitCommand = exit; - - setupMenu(); - setupFilterMenu(); - - if(canEditComputerDecks) setupComputerMenu(); - } - - private void setupFilterMenu() { - JMenuItem filter = new JMenuItem("New filter"); - JMenuItem clearfilter = new JMenuItem("Clear filter"); - JMenu menu = new JMenu("Filter"); - menu.add(filter); - menu.add(clearfilter); - this.add(menu); - - filter.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent ev) { - Gui_Quest_DeckEditor g = (Gui_Quest_DeckEditor) deckDisplay; - if(g.stCardList == null) { - g.blackCheckBox.setSelected(true); - g.blackCheckBox.setEnabled(true); - g.blueCheckBox.setSelected(true); - g.blueCheckBox.setEnabled(true); - g.greenCheckBox.setSelected(true); - g.greenCheckBox.setEnabled(true); - g.redCheckBox.setSelected(true); - g.redCheckBox.setEnabled(true); - g.whiteCheckBox.setSelected(true); - g.whiteCheckBox.setEnabled(true); - g.colorlessCheckBox.setSelected(true); - g.colorlessCheckBox.setEnabled(true); - g.artifactCheckBox.setSelected(true); - g.artifactCheckBox.setEnabled(true); - g.creatureCheckBox.setSelected(true); - g.creatureCheckBox.setEnabled(true); - g.enchantmentCheckBox.setSelected(true); - g.enchantmentCheckBox.setEnabled(true); - g.instantCheckBox.setSelected(true); - g.instantCheckBox.setEnabled(true); - g.landCheckBox.setSelected(true); - g.landCheckBox.setEnabled(true); - g.planeswalkerCheckBox.setSelected(true); - g.planeswalkerCheckBox.setEnabled(true); - g.sorceryCheckBox.setSelected(true); - g.sorceryCheckBox.setEnabled(true); - g.stCardList = g.getTop(); - GUI_Quest_Filter filt = new GUI_Quest_Filter(g, deckDisplay); - g.setEnabled(false); - g.filterUsed = true; - filt.setVisible(true); - } else { - g.blackCheckBox.setSelected(true); - g.blackCheckBox.setEnabled(true); - g.blueCheckBox.setSelected(true); - g.blueCheckBox.setEnabled(true); - g.greenCheckBox.setSelected(true); - g.greenCheckBox.setEnabled(true); - g.redCheckBox.setSelected(true); - g.redCheckBox.setEnabled(true); - g.whiteCheckBox.setSelected(true); - g.whiteCheckBox.setEnabled(true); - g.colorlessCheckBox.setSelected(true); - g.colorlessCheckBox.setEnabled(true); - g.artifactCheckBox.setSelected(true); - g.artifactCheckBox.setEnabled(true); - g.creatureCheckBox.setSelected(true); - g.creatureCheckBox.setEnabled(true); - g.enchantmentCheckBox.setSelected(true); - g.enchantmentCheckBox.setEnabled(true); - g.instantCheckBox.setSelected(true); - g.instantCheckBox.setEnabled(true); - g.landCheckBox.setSelected(true); - g.landCheckBox.setEnabled(true); - g.planeswalkerCheckBox.setSelected(true); - g.planeswalkerCheckBox.setEnabled(true); - g.sorceryCheckBox.setSelected(true); - g.sorceryCheckBox.setEnabled(true); - GUI_Quest_Filter filt = new GUI_Quest_Filter(g, deckDisplay); - g.filterUsed = true; - g.setEnabled(false); - filt.setVisible(true); - } - } - }); - clearfilter.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent ev) { - - Gui_Quest_DeckEditor g = (Gui_Quest_DeckEditor) deckDisplay; - if(g.stCardList == null) { - g.blackCheckBox.setSelected(true); - g.blackCheckBox.setEnabled(true); - g.blueCheckBox.setSelected(true); - g.blueCheckBox.setEnabled(true); - g.greenCheckBox.setSelected(true); - g.greenCheckBox.setEnabled(true); - g.redCheckBox.setSelected(true); - g.redCheckBox.setEnabled(true); - g.whiteCheckBox.setSelected(true); - g.whiteCheckBox.setEnabled(true); - g.colorlessCheckBox.setSelected(true); - g.colorlessCheckBox.setEnabled(true); - g.artifactCheckBox.setSelected(true); - g.artifactCheckBox.setEnabled(true); - g.creatureCheckBox.setSelected(true); - g.creatureCheckBox.setEnabled(true); - g.enchantmentCheckBox.setSelected(true); - g.enchantmentCheckBox.setEnabled(true); - g.instantCheckBox.setSelected(true); - g.instantCheckBox.setEnabled(true); - g.landCheckBox.setSelected(true); - g.landCheckBox.setEnabled(true); - g.planeswalkerCheckBox.setSelected(true); - g.planeswalkerCheckBox.setEnabled(true); - g.sorceryCheckBox.setSelected(true); - g.sorceryCheckBox.setEnabled(true); - g.filterUsed = false; - } else { - g.blackCheckBox.setSelected(true); - g.blackCheckBox.setEnabled(true); - g.blueCheckBox.setSelected(true); - g.blueCheckBox.setEnabled(true); - g.greenCheckBox.setSelected(true); - g.greenCheckBox.setEnabled(true); - g.redCheckBox.setSelected(true); - g.redCheckBox.setEnabled(true); - g.whiteCheckBox.setSelected(true); - g.whiteCheckBox.setEnabled(true); - g.colorlessCheckBox.setSelected(true); - g.colorlessCheckBox.setEnabled(true); - g.artifactCheckBox.setSelected(true); - g.artifactCheckBox.setEnabled(true); - g.creatureCheckBox.setSelected(true); - g.creatureCheckBox.setEnabled(true); - g.enchantmentCheckBox.setSelected(true); - g.enchantmentCheckBox.setEnabled(true); - g.instantCheckBox.setSelected(true); - g.instantCheckBox.setEnabled(true); - g.landCheckBox.setSelected(true); - g.landCheckBox.setEnabled(true); - g.planeswalkerCheckBox.setSelected(true); - g.planeswalkerCheckBox.setEnabled(true); - g.sorceryCheckBox.setSelected(true); - g.sorceryCheckBox.setEnabled(true); - g.filterUsed = false; - deckDisplay.updateDisplay(g.stCardList, deckDisplay.getBottom()); - } - - - } - }); - - } - - - private void addImportExport(JMenu menu, final boolean isHumanMenu) { - JMenuItem import2 = new JMenuItem("Import"); - JMenuItem export = new JMenuItem("Export"); - - import2.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - importDeck(isHumanMenu); - } - });//import - - export.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - exportDeck(); - } - });//export - - menu.add(import2); - menu.add(export); - - }//addImportExport() - - private void exportDeck() { - File filename = getExportFilename(); - - if(filename == null) return; - - //write is an Object variable because you might just - //write one Deck object - Deck deck = convertCardListToDeck(deckDisplay.getBottom());; - Object write = deck; - - deck.setName(filename.getName()); - - - try { - ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename)); - out.writeObject(write); - out.flush(); - out.close(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeck() error, " + ex); - } - - exportDeckText(getExportDeckText(deck), filename.getAbsolutePath()); - - }//exportDeck() - - // TableSorter type safety - private String getExportDeckText(Deck aDeck) { - //convert Deck into CardList - CardList all = new CardList(); - for(int i = 0; i < aDeck.countMain(); i++) { - String cardName = aDeck.getMain(i); - Card c = AllZone.CardFactory.getCard(cardName, null); - - all.add(c); - } - - //sort by card name - all.sort(new TableSorter(all, 1, true)); - - //remove all copies of cards - //make a singleton - CardList noCopies = new CardList(); - for(int i = 0; i < all.size(); i++) { - Card c = all.get(i); - - if(!noCopies.containsName(c.getName())) noCopies.add(c); - } - - StringBuffer sb = new StringBuffer(); - String newLine = "\r\n"; - int count = 0; - - sb.append(all.size()).append(" Total Cards").append(newLine).append(newLine); - - //creatures - sb.append(all.getType("Creature").size()).append(" Creatures").append(newLine); - sb.append("-------------").append(newLine); - - for(int i = 0; i < noCopies.size(); i++) { - Card c = noCopies.get(i); - if(c.isCreature()) { - count = all.getName(c.getName()).size(); - sb.append(count).append("x ").append(c.getName()).append(newLine); - } - } - - //count spells, arg! this is tough - CardListFilter cf = new CardListFilter() { - public boolean addCard(Card c) { - return !(c.isCreature() || c.isLand()); - } - };//CardListFilter - count = all.filter(cf).size(); - - //spells - sb.append(newLine).append(count).append(" Spells").append(newLine); - sb.append("----------").append(newLine); - - for(int i = 0; i < noCopies.size(); i++) { - Card c = noCopies.get(i); - if(!(c.isCreature() || c.isLand())) { - count = all.getName(c.getName()).size(); - sb.append(count).append("x ").append(c.getName()).append(newLine); - } - } - - //land - sb.append(newLine).append(all.getType("Land").size()).append(" Land").append(newLine); - sb.append("--------").append(newLine); - - for(int i = 0; i < noCopies.size(); i++) { - Card c = noCopies.get(i); - if(c.isLand()) { - count = all.getName(c.getName()).size(); - sb.append(count).append("x ").append(c.getName()).append(newLine); - } - } - - sb.append(newLine); - - return sb.toString(); - }//getExportDeckText - - private void exportDeckText(String deckText, String filename) { - - //remove ".deck" extension - int cut = filename.indexOf("."); - filename = filename.substring(0, cut); - - try { - FileWriter writer = new FileWriter(filename + ".txt"); - writer.write(deckText); - - writer.flush(); - writer.close(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeckText() error, " + ex.getMessage() - + " : " + Arrays.toString(ex.getStackTrace())); - } - }//exportDeckText() - - - private FileFilter getFileFilter() { - FileFilter filter = new FileFilter() { - @Override - public boolean accept(File f) { - return f.getName().endsWith(".deck") || f.isDirectory(); - } - - @Override - public String getDescription() { - return "Deck File .deck"; - } - }; - - return filter; - }//getFileFilter() - - private File getExportFilename() { - //Object o = null; // unused - - JFileChooser save = new JFileChooser(previousDirectory); - - save.setDialogTitle("Export Deck Filename"); - save.setDialogType(JFileChooser.SAVE_DIALOG); - save.addChoosableFileFilter(getFileFilter()); - save.setSelectedFile(new File(currentDeck.getName() + ".deck")); - - int returnVal = save.showSaveDialog(null); - - if(returnVal == JFileChooser.APPROVE_OPTION) { - File file = save.getSelectedFile(); - String check = file.getAbsolutePath(); - - previousDirectory = file.getParentFile(); - - if(check.endsWith(".deck")) return file; - else return new File(check + ".deck"); - } - - return null; - }//getExportFilename() - - private void importDeck(boolean isHumanDeck) { - File file = getImportFilename(); - - if(file == null) return; - - Object check = null; - - try { - ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); - check = in.readObject(); - - //deck migration - this is a little hard to read, because i can't just plainly reference a class in the - //default package - Class deckConverterClass = Class.forName("DeckConverter"); - //invoke public static Object toForgeDeck(Object o) of DeckConverter - check = deckConverterClass.getDeclaredMethod("toForgeDeck", Object.class).invoke(null, check); - - in.close(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_Quest_DeckEditor_Menu : importDeck() error, " + ex); - } - - Deck deck = (Deck) check; - - deckDisplay.setTitle(deckEditorName + " - " + deck.getName()); - - CardList cardpool; - - if(isHumanDeck) { - questData.addDeck(deck); - - //convert ArrayList of card names (Strings), into Card objects - cardpool = new CardList(); - ArrayList list = questData.getCardpool(); - - for(int i = 0; i < list.size(); i++) - cardpool.add(AllZone.CardFactory.getCard(list.get(i).toString(), null)); - } else { - questData.ai_addDeck(deck); - cardpool = AllZone.CardFactory.getAllCards(); - } - - //convert Deck main to CardList - CardList deckList = new CardList(); - for(int i = 0; i < deck.countMain(); i++) - deckList.add(AllZone.CardFactory.getCard(deck.getMain(i), null)); - - //update gui - deckDisplay.updateDisplay(cardpool, deckList); - - }//importDeck() - - - private File getImportFilename() { - JFileChooser chooser = new JFileChooser(previousDirectory); - - chooser.addChoosableFileFilter(getFileFilter()); - int returnVal = chooser.showOpenDialog(null); - - if(returnVal == JFileChooser.APPROVE_OPTION) { - File file = chooser.getSelectedFile(); - previousDirectory = file.getParentFile(); - return file; - } - - return null; - }//openFileDialog() - - //edit the AI decks - private void setupComputerMenu() { - JMenuItem open = new JMenuItem("Open"); - JMenuItem new2 = new JMenuItem("New"); - JMenuItem rename = new JMenuItem("Rename"); - JMenuItem save = new JMenuItem("Save"); - JMenuItem copy = new JMenuItem("Copy"); - JMenuItem delete = new JMenuItem("Delete"); - JMenuItem exit = new JMenuItem("Exit"); - - - JMenuItem viewAllDecks = new JMenuItem("View All Decks"); - - - //AI - viewAllDecks.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - ArrayList nameList = questData.ai_getDeckNames(); - Collections.sort(nameList); - - Deck deck; - StringBuffer allText = new StringBuffer(); - - for(int i = 0; i < nameList.size(); i++) { - deck = questData.ai_getDeck(nameList.get(i).toString()); - allText.append(deck.getName()).append("\r\n"); - allText.append(getExportDeckText(deck)); - allText.append("++++++++++++++++++++++++++++++++++++++++++++++++++++++ \r\n \r\n"); - } - - JTextArea area = new JTextArea(allText.toString(), 30, 30); - JOptionPane.showMessageDialog(null, new JScrollPane(area)); - - }//actionPerformed() - });//viewAllDecks - - //AI - open.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - String deckName = getUserInput_OpenDeck(questData.ai_getDeckNames()); - - //check if user selected "cancel" - if(deckName.equals("")) return; - - - setComputerPlayer(deckName); - - Deck d = questData.ai_getDeck(deckName); - CardList deck = new CardList(); - - for(int i = 0; i < d.countMain(); i++) - deck.add(AllZone.CardFactory.getCard(d.getMain(i), null)); - - CardList cardpool = AllZone.CardFactory.getAllCards(); - - deckDisplay.updateDisplay(cardpool, deck); - - } - });//open - - //AI - new2.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - deckDisplay.updateDisplay(AllZone.CardFactory.getAllCards(), new CardList()); - - setComputerPlayer(""); - } - });//new - - - //AI - rename.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - String name = getUserInput_GetDeckName(questData.ai_getDeckNames()); - - //check if user cancels - if(name.equals("")) return; - - //is the current deck already saved and in QuestData? - if(questData.ai_getDeckNames().contains(currentDeck.getName())) questData.ai_removeDeck(currentDeck.getName());//remove old deck - - currentDeck.setName(name); - - Deck deck = convertCardListToDeck(deckDisplay.getBottom()); - deck.setName(name); - questData.ai_addDeck(deck); - - setComputerPlayer(name); - } - });//rename - - - //AI - save.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - String name = currentDeck.getName(); - - //check to see if name is set - if(name.equals("")) { - name = getUserInput_GetDeckName(questData.ai_getDeckNames()); - - //check if user cancels - if(name.equals("")) return; - } - - setComputerPlayer(name); - - Deck deck = convertCardListToDeck(deckDisplay.getBottom()); - deck.setName(name); - - questData.ai_addDeck(deck); - } - });//save - - - //AI - copy.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - String name = getUserInput_GetDeckName(questData.ai_getDeckNames()); - - //check if user cancels - if(name.equals("")) return; - - setComputerPlayer(name); - - Deck deck = convertCardListToDeck(deckDisplay.getBottom()); - deck.setName(name); - - questData.ai_addDeck(deck); - } - });//copy - - - //AI - delete.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - if(currentDeck.getName().equals("")) return; - - int check = JOptionPane.showConfirmDialog(null, "Do you really want to delete this deck?", - "Delete", JOptionPane.YES_NO_OPTION); - if(check == JOptionPane.NO_OPTION) return;//stop here - - questData.ai_removeDeck(currentDeck.getName()); - - //show card pool - CardList cardpool = AllZone.CardFactory.getAllCards(); - deckDisplay.updateDisplay(cardpool, new CardList()); - - setComputerPlayer(""); - } - });//delete - - - //AI - exit.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - Gui_Quest_DeckEditor_Menu.this.close(); - } - }); - - JMenu deckMenu = new JMenu("AI Deck"); - deckMenu.add(open); - deckMenu.add(rename); - deckMenu.add(new2); - deckMenu.add(save); - deckMenu.add(copy); - - deckMenu.addSeparator(); - addImportExport(deckMenu, false); - - deckMenu.add(viewAllDecks); - - deckMenu.addSeparator(); - deckMenu.add(delete); - deckMenu.addSeparator(); - deckMenu.add(exit); - - this.add(deckMenu); - - }//setupComputerMenu() - - private void openHumanDeck(String deckName) { - setHumanPlayer(deckName); - - CardList cardpool = covertToCardList(questData.getCardpool()); - - //covert Deck main to CardList - Deck d = questData.getDeck(deckName); - CardList deck = new CardList(); - - for(int i = 0; i < d.countMain(); i++) { - deck.add(AllZone.CardFactory.getCard(d.getMain(i), null)); - - //remove any cards that are in the deck from the card pool - cardpool.remove(d.getMain(i)); - } - - deckDisplay.updateDisplay(cardpool, deck); - - }//openHumanDeck - - - //the usual menu options that will be used - private void setupMenu() { - JMenuItem open = new JMenuItem("Open"); - JMenuItem new2 = new JMenuItem("New"); - JMenuItem rename = new JMenuItem("Rename"); - JMenuItem save = new JMenuItem("Save"); - JMenuItem copy = new JMenuItem("Copy"); - JMenuItem delete = new JMenuItem("Delete"); - JMenuItem exit = new JMenuItem("Exit"); - - //////////////////////////////////////////// - //below is new code - - //adds a card to human player's cardpool - JMenuItem addCard = new JMenuItem("Cheat - Add Card"); - - //add card - addCard.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent a) - { - //sort cards by card name - CardList cardList = AllZone.CardFactory.getAllCards(); - TableSorter sorter = new TableSorter(cardList, 1, true); - cardList.sort(sorter); - - //create a new Card object with a different toString() method - //so that that JList only shows the card's name - // - //this is alot of work just to make it a little - //easier and prettier for the user, gui stuff is very complicated - class BetterCard extends Card - { - private Card card; - - BetterCard(Card c) - { - card = c; - - //this line is very important - //if you omit this, errors will occur - this.setName(c.getName()); - } - - public String toString() - { - return card.getName(); - } - }//BetterCard - - Card[] card = cardList.toArray(); - - for(int i = 0; i < card.length; i++) - { - card[i] = new BetterCard(card[i]); - } - - final JList list = new JList(card); - list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - - //update the "card detail" on the right with the card info - list.addListSelectionListener(new ListSelectionListener() - { - public void valueChanged(ListSelectionEvent e) - { - - /* I think that the code that was based in CardDetailUtil - has been changed and moved to a new/different class? - - CardDetail cd = (CardDetail)deckDisplay; - cd.updateCardDetail((Card)list.getSelectedValue()); - - */ - - } - }); - - Object[] o = {"Add Card to Your Cardpool", new JScrollPane(list)}; - JOptionPane pane = new JOptionPane(o, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); - - JDialog dialog = pane.createDialog(null, "Cheat - Add Card"); - dialog.setModal(true); - dialog.setVisible(true); - - Object choice = pane.getValue(); - boolean cancel = false; - - //there are a ton of ways to cancel - if( - choice == null || - choice.equals(JOptionPane.UNINITIALIZED_VALUE) - ) - cancel = true; - else - { - int n = ((Integer)choice).intValue(); - if(n == JOptionPane.CANCEL_OPTION) - cancel = true; - } - - if(cancel || list.getSelectedValue() == null) - { - //System.out.println("cancelled"); - } - else - { - //show the choice that the user selected - //System.out.println(list.getSelectedValue()); - - Card c = (Card) list.getSelectedValue(); - - Gui_Quest_DeckEditor g = (Gui_Quest_DeckEditor)deckDisplay; - TableModel table = g.getTopTableModel(); - table.addCard(c); - table.resort(); - } - }//actionPerformed() - });//add card - - - //above is new code - /////////////////////////////////////// - - //human - open.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - String deckName = getUserInput_OpenDeck(questData.getDeckNames()); - - //check if user selected "cancel" - if(deckName.equals("")) return; - - openHumanDeck(deckName); - } - });//open - - //human - new2.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - CardList cardpool = covertToCardList(questData.getCardpool()); - deckDisplay.updateDisplay(cardpool, new CardList()); - - setHumanPlayer(""); - } - });//new - - - //human - rename.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - String name = getUserInput_GetDeckName(questData.getDeckNames()); - - //check if user cancels - if(name.equals("")) return; - - //is the current deck already saved and in QuestData? - if(questData.getDeckNames().contains(currentDeck.getName())) questData.removeDeck(currentDeck.getName());//remove old deck - - currentDeck.setName(name); - - Deck deck = convertCardListToDeck(deckDisplay.getBottom()); - deck.setName(name); - questData.addDeck(deck); - - setHumanPlayer(name); - } - });//rename - - - //human - save.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - String name = currentDeck.getName(); - - //check to see if name is set - if(name.equals("")) { - name = getUserInput_GetDeckName(questData.getDeckNames()); - - //check if user cancels - if(name.equals("")) return; - } - - setHumanPlayer(name); - - Deck deck = convertCardListToDeck(deckDisplay.getBottom()); - deck.setName(name); - - questData.addDeck(deck); - } - });//save - - - //human - copy.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - String name = getUserInput_GetDeckName(questData.getDeckNames()); - - //check if user cancels - if(name.equals("")) return; - - setHumanPlayer(name); - - Deck deck = convertCardListToDeck(deckDisplay.getBottom()); - deck.setName(name); - - questData.addDeck(deck); - } - });//copy - - - //human - delete.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - if(currentDeck.getName().equals("")) return; - - int check = JOptionPane.showConfirmDialog(null, "Do you really want to delete this deck?", - "Delete", JOptionPane.YES_NO_OPTION); - if(check == JOptionPane.NO_OPTION) return;//stop here - - questData.removeDeck(currentDeck.getName()); - - //show card pool - CardList cardpool = covertToCardList(questData.getCardpool()); - deckDisplay.updateDisplay(cardpool, new CardList()); - - setHumanPlayer(""); - } - });//delete - - - //human - exit.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent a) { - Gui_Quest_DeckEditor_Menu.this.close(); - } - }); - - JMenu deckMenu = new JMenu("Deck"); - deckMenu.add(open); - deckMenu.add(new2); - deckMenu.add(rename); - deckMenu.add(save); - deckMenu.add(copy); - - // The "Cheat - Add Card" menu item is buggy. - // There are other, safer and less buggy ways for people to cheat. - - // deckMenu.addSeparator();//new code - // deckMenu.add(addCard); //new code - - deckMenu.addSeparator(); - addImportExport(deckMenu, true); - - deckMenu.addSeparator(); - deckMenu.add(delete); - deckMenu.addSeparator(); - deckMenu.add(exit); - - this.add(deckMenu); - - }//setupMenu() - - private Deck convertCardListToDeck(CardList list) { - //put CardList into Deck main - Deck deck = new Deck(Constant.GameType.Sealed); - - for(int i = 0; i < list.size(); i++) - deck.addMain(list.get(i).getName()); - - return deck; - } - - //needs to be public because Gui_Quest_DeckEditor.show(Command) uses it - public void setHumanPlayer(String deckName) { - //the gui uses this, Gui_Quest_DeckEditor - currentDeck = new Deck(Constant.GameType.Sealed); - currentDeck.setName(deckName); - - deckDisplay.setTitle(deckEditorName + " - " + deckName); - } - - private void setComputerPlayer(String deckName) { - //the gui uses this, Gui_Quest_DeckEditor - currentDeck = new Deck(Constant.GameType.Constructed); - currentDeck.setName(deckName); - - deckDisplay.setTitle(deckEditorName + " - " + deckName); - } - - //only accepts numbers, letters or dashes up to 20 characters in length - private String cleanString(String in) { - StringBuffer out = new StringBuffer(); - char[] c = in.toCharArray(); - - for(int i = 0; i < c.length && i < 20; i++) - if(Character.isLetterOrDigit(c[i]) || c[i] == '-' || c[i] == '_' || c[i] == ' ') out.append(c[i]); - - return out.toString(); - } - - //if user cancels, returns "" - private String getUserInput_GetDeckName(ArrayList nameList) { - Object o = JOptionPane.showInputDialog(null, "", "Deck Name", JOptionPane.OK_CANCEL_OPTION); - - if(o == null) return ""; - - String deckName = cleanString(o.toString()); - - if(nameList.contains(deckName) || deckName.equals("")) { - JOptionPane.showMessageDialog(null, "Please pick another deck name, a deck currently has that name."); - return getUserInput_GetDeckName(nameList); - } - - return deckName; - }//getUserInput_GetDeckName() - - - //if user cancels, it will return "" - private String getUserInput_OpenDeck(ArrayList deckNameList) { - ArrayList choices = deckNameList; - if(choices.size() == 0) { - JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE); - return ""; - } - - //Object o = JOptionPane.showInputDialog(null, "Deck Name", "Open Deck", JOptionPane.OK_CANCEL_OPTION, null, - // choices.toArray(), choices.toArray()[0]); - Object o = GuiUtils.getChoiceOptional("Select Deck", choices.toArray()); - - if(o == null) return ""; - - return o.toString(); - }//getUserInput_OpenDeck() - - //used by Gui_Quest_DeckEditor - public void close() { - exitCommand.execute(); - } - - //used by Gui_Quest_DeckEditor - public String getDeckName() { - return currentDeck.getName(); - } - - //used by Gui_Quest_DeckEditor - public String getGameType() { - return currentDeck.getDeckType(); - } - - - //returns CardList of Card objects, - //argument ArrayList holds String card names - public static CardList covertToCardList(ArrayList list) { - CardList c = new CardList(); - Card card; - for(int i = 0; i < list.size(); i++) { - card = AllZone.CardFactory.getCard(list.get(i).toString(), null); - c.add(card); - } - - return c; - } - -} + +package forge; + + +import forge.error.ErrorViewer; +import forge.gui.GuiUtils; + +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.filechooser.FileFilter; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + +//presumes AllZone.QuestData is not null +public class Gui_Quest_DeckEditor_Menu extends JMenuBar { + private static final long serialVersionUID = -4052319220021158574L; + + //this should be false in the public version + //if true, the Quest Deck editor will let you edit the computer's decks + private final boolean canEditComputerDecks; + + private static final String deckEditorName = "Deck Editor"; + + //used for import and export, try to made the gui user friendly + private static File previousDirectory = null; + + private Command exitCommand; + private forge.quest.data.QuestData questData; + private Deck currentDeck; + + //the class DeckDisplay is in the file "Gui_DeckEditor_Menu.java" + private DeckDisplay deckDisplay; + + + public Gui_Quest_DeckEditor_Menu(DeckDisplay d, Command exit) { + //is a file named "edit" in this directory + //lame but it works, I don't like 2 versions of MTG Forge floating around + //one that lets you edit the AI decks and one that doesn't + File f = new File("edit"); + if(f.exists()) canEditComputerDecks = true; + else canEditComputerDecks = false; + + + deckDisplay = d; + d.setTitle(deckEditorName); + + questData = AllZone.QuestData; + + exitCommand = exit; + + setupMenu(); + setupFilterMenu(); + + if(canEditComputerDecks) setupComputerMenu(); + } + + private void setupFilterMenu() { + JMenuItem filter = new JMenuItem("New filter"); + JMenuItem clearfilter = new JMenuItem("Clear filter"); + JMenu menu = new JMenu("Filter"); + menu.add(filter); + menu.add(clearfilter); + this.add(menu); + + filter.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ev) { + Gui_Quest_DeckEditor g = (Gui_Quest_DeckEditor) deckDisplay; + if(g.stCardList == null) { + g.blackCheckBox.setSelected(true); + g.blackCheckBox.setEnabled(true); + g.blueCheckBox.setSelected(true); + g.blueCheckBox.setEnabled(true); + g.greenCheckBox.setSelected(true); + g.greenCheckBox.setEnabled(true); + g.redCheckBox.setSelected(true); + g.redCheckBox.setEnabled(true); + g.whiteCheckBox.setSelected(true); + g.whiteCheckBox.setEnabled(true); + g.colorlessCheckBox.setSelected(true); + g.colorlessCheckBox.setEnabled(true); + g.artifactCheckBox.setSelected(true); + g.artifactCheckBox.setEnabled(true); + g.creatureCheckBox.setSelected(true); + g.creatureCheckBox.setEnabled(true); + g.enchantmentCheckBox.setSelected(true); + g.enchantmentCheckBox.setEnabled(true); + g.instantCheckBox.setSelected(true); + g.instantCheckBox.setEnabled(true); + g.landCheckBox.setSelected(true); + g.landCheckBox.setEnabled(true); + g.planeswalkerCheckBox.setSelected(true); + g.planeswalkerCheckBox.setEnabled(true); + g.sorceryCheckBox.setSelected(true); + g.sorceryCheckBox.setEnabled(true); + g.stCardList = g.getTop(); + GUI_Quest_Filter filt = new GUI_Quest_Filter(g, deckDisplay); + g.setEnabled(false); + g.filterUsed = true; + filt.setVisible(true); + } else { + g.blackCheckBox.setSelected(true); + g.blackCheckBox.setEnabled(true); + g.blueCheckBox.setSelected(true); + g.blueCheckBox.setEnabled(true); + g.greenCheckBox.setSelected(true); + g.greenCheckBox.setEnabled(true); + g.redCheckBox.setSelected(true); + g.redCheckBox.setEnabled(true); + g.whiteCheckBox.setSelected(true); + g.whiteCheckBox.setEnabled(true); + g.colorlessCheckBox.setSelected(true); + g.colorlessCheckBox.setEnabled(true); + g.artifactCheckBox.setSelected(true); + g.artifactCheckBox.setEnabled(true); + g.creatureCheckBox.setSelected(true); + g.creatureCheckBox.setEnabled(true); + g.enchantmentCheckBox.setSelected(true); + g.enchantmentCheckBox.setEnabled(true); + g.instantCheckBox.setSelected(true); + g.instantCheckBox.setEnabled(true); + g.landCheckBox.setSelected(true); + g.landCheckBox.setEnabled(true); + g.planeswalkerCheckBox.setSelected(true); + g.planeswalkerCheckBox.setEnabled(true); + g.sorceryCheckBox.setSelected(true); + g.sorceryCheckBox.setEnabled(true); + GUI_Quest_Filter filt = new GUI_Quest_Filter(g, deckDisplay); + g.filterUsed = true; + g.setEnabled(false); + filt.setVisible(true); + } + } + }); + clearfilter.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ev) { + + Gui_Quest_DeckEditor g = (Gui_Quest_DeckEditor) deckDisplay; + if(g.stCardList == null) { + g.blackCheckBox.setSelected(true); + g.blackCheckBox.setEnabled(true); + g.blueCheckBox.setSelected(true); + g.blueCheckBox.setEnabled(true); + g.greenCheckBox.setSelected(true); + g.greenCheckBox.setEnabled(true); + g.redCheckBox.setSelected(true); + g.redCheckBox.setEnabled(true); + g.whiteCheckBox.setSelected(true); + g.whiteCheckBox.setEnabled(true); + g.colorlessCheckBox.setSelected(true); + g.colorlessCheckBox.setEnabled(true); + g.artifactCheckBox.setSelected(true); + g.artifactCheckBox.setEnabled(true); + g.creatureCheckBox.setSelected(true); + g.creatureCheckBox.setEnabled(true); + g.enchantmentCheckBox.setSelected(true); + g.enchantmentCheckBox.setEnabled(true); + g.instantCheckBox.setSelected(true); + g.instantCheckBox.setEnabled(true); + g.landCheckBox.setSelected(true); + g.landCheckBox.setEnabled(true); + g.planeswalkerCheckBox.setSelected(true); + g.planeswalkerCheckBox.setEnabled(true); + g.sorceryCheckBox.setSelected(true); + g.sorceryCheckBox.setEnabled(true); + g.filterUsed = false; + } else { + g.blackCheckBox.setSelected(true); + g.blackCheckBox.setEnabled(true); + g.blueCheckBox.setSelected(true); + g.blueCheckBox.setEnabled(true); + g.greenCheckBox.setSelected(true); + g.greenCheckBox.setEnabled(true); + g.redCheckBox.setSelected(true); + g.redCheckBox.setEnabled(true); + g.whiteCheckBox.setSelected(true); + g.whiteCheckBox.setEnabled(true); + g.colorlessCheckBox.setSelected(true); + g.colorlessCheckBox.setEnabled(true); + g.artifactCheckBox.setSelected(true); + g.artifactCheckBox.setEnabled(true); + g.creatureCheckBox.setSelected(true); + g.creatureCheckBox.setEnabled(true); + g.enchantmentCheckBox.setSelected(true); + g.enchantmentCheckBox.setEnabled(true); + g.instantCheckBox.setSelected(true); + g.instantCheckBox.setEnabled(true); + g.landCheckBox.setSelected(true); + g.landCheckBox.setEnabled(true); + g.planeswalkerCheckBox.setSelected(true); + g.planeswalkerCheckBox.setEnabled(true); + g.sorceryCheckBox.setSelected(true); + g.sorceryCheckBox.setEnabled(true); + g.filterUsed = false; + deckDisplay.updateDisplay(g.stCardList, deckDisplay.getBottom()); + } + + + } + }); + + } + + + private void addImportExport(JMenu menu, final boolean isHumanMenu) { + JMenuItem import2 = new JMenuItem("Import"); + JMenuItem export = new JMenuItem("Export"); + + import2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + importDeck(isHumanMenu); + } + });//import + + export.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + exportDeck(); + } + });//export + + menu.add(import2); + menu.add(export); + + }//addImportExport() + + private void exportDeck() { + File filename = getExportFilename(); + + if(filename == null) return; + + //write is an Object variable because you might just + //write one Deck object + Deck deck = convertCardListToDeck(deckDisplay.getBottom());; + Object write = deck; + + deck.setName(filename.getName()); + + + try { + ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(filename)); + out.writeObject(write); + out.flush(); + out.close(); + } catch(Exception ex) { + ErrorViewer.showError(ex); + throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeck() error, " + ex); + } + + exportDeckText(getExportDeckText(deck), filename.getAbsolutePath()); + + }//exportDeck() + + // TableSorter type safety + private String getExportDeckText(Deck aDeck) { + //convert Deck into CardList + CardList all = new CardList(); + for(int i = 0; i < aDeck.countMain(); i++) { + String cardName = aDeck.getMain(i); + Card c = AllZone.CardFactory.getCard(cardName, null); + + all.add(c); + } + + //sort by card name + all.sort(new TableSorter(all, 1, true)); + + //remove all copies of cards + //make a singleton + CardList noCopies = new CardList(); + for(int i = 0; i < all.size(); i++) { + Card c = all.get(i); + + if(!noCopies.containsName(c.getName())) noCopies.add(c); + } + + StringBuffer sb = new StringBuffer(); + String newLine = "\r\n"; + int count = 0; + + sb.append(all.size()).append(" Total Cards").append(newLine).append(newLine); + + //creatures + sb.append(all.getType("Creature").size()).append(" Creatures").append(newLine); + sb.append("-------------").append(newLine); + + for(int i = 0; i < noCopies.size(); i++) { + Card c = noCopies.get(i); + if(c.isCreature()) { + count = all.getName(c.getName()).size(); + sb.append(count).append("x ").append(c.getName()).append(newLine); + } + } + + //count spells, arg! this is tough + CardListFilter cf = new CardListFilter() { + public boolean addCard(Card c) { + return !(c.isCreature() || c.isLand()); + } + };//CardListFilter + count = all.filter(cf).size(); + + //spells + sb.append(newLine).append(count).append(" Spells").append(newLine); + sb.append("----------").append(newLine); + + for(int i = 0; i < noCopies.size(); i++) { + Card c = noCopies.get(i); + if(!(c.isCreature() || c.isLand())) { + count = all.getName(c.getName()).size(); + sb.append(count).append("x ").append(c.getName()).append(newLine); + } + } + + //land + sb.append(newLine).append(all.getType("Land").size()).append(" Land").append(newLine); + sb.append("--------").append(newLine); + + for(int i = 0; i < noCopies.size(); i++) { + Card c = noCopies.get(i); + if(c.isLand()) { + count = all.getName(c.getName()).size(); + sb.append(count).append("x ").append(c.getName()).append(newLine); + } + } + + sb.append(newLine); + + return sb.toString(); + }//getExportDeckText + + private void exportDeckText(String deckText, String filename) { + + //remove ".deck" extension + int cut = filename.indexOf("."); + filename = filename.substring(0, cut); + + try { + FileWriter writer = new FileWriter(filename + ".txt"); + writer.write(deckText); + + writer.flush(); + writer.close(); + } catch(Exception ex) { + ErrorViewer.showError(ex); + throw new RuntimeException("Gui_Quest_DeckEditor_Menu : exportDeckText() error, " + ex.getMessage() + + " : " + Arrays.toString(ex.getStackTrace())); + } + }//exportDeckText() + + + private FileFilter getFileFilter() { + FileFilter filter = new FileFilter() { + @Override + public boolean accept(File f) { + return f.getName().endsWith(".deck") || f.isDirectory(); + } + + @Override + public String getDescription() { + return "Deck File .deck"; + } + }; + + return filter; + }//getFileFilter() + + private File getExportFilename() { + //Object o = null; // unused + + JFileChooser save = new JFileChooser(previousDirectory); + + save.setDialogTitle("Export Deck Filename"); + save.setDialogType(JFileChooser.SAVE_DIALOG); + save.addChoosableFileFilter(getFileFilter()); + save.setSelectedFile(new File(currentDeck.getName() + ".deck")); + + int returnVal = save.showSaveDialog(null); + + if(returnVal == JFileChooser.APPROVE_OPTION) { + File file = save.getSelectedFile(); + String check = file.getAbsolutePath(); + + previousDirectory = file.getParentFile(); + + if(check.endsWith(".deck")) return file; + else return new File(check + ".deck"); + } + + return null; + }//getExportFilename() + + private void importDeck(boolean isHumanDeck) { + File file = getImportFilename(); + + if(file == null) return; + + Object check = null; + + try { + ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); + check = in.readObject(); + + //deck migration - this is a little hard to read, because i can't just plainly reference a class in the + //default package + Class deckConverterClass = Class.forName("DeckConverter"); + //invoke public static Object toForgeDeck(Object o) of DeckConverter + check = deckConverterClass.getDeclaredMethod("toForgeDeck", Object.class).invoke(null, check); + + in.close(); + } catch(Exception ex) { + ErrorViewer.showError(ex); + throw new RuntimeException("Gui_Quest_DeckEditor_Menu : importDeck() error, " + ex); + } + + Deck deck = (Deck) check; + + deckDisplay.setTitle(deckEditorName + " - " + deck.getName()); + + CardList cardpool; + + if(isHumanDeck) { + questData.addDeck(deck); + + //convert ArrayList of card names (Strings), into Card objects + cardpool = new CardList(); + List list = questData.getCardpool(); + + for(int i = 0; i < list.size(); i++) + cardpool.add(AllZone.CardFactory.getCard(list.get(i).toString(), null)); + } else { + questData.ai_addDeck(deck); + cardpool = AllZone.CardFactory.getAllCards(); + } + + //convert Deck main to CardList + CardList deckList = new CardList(); + for(int i = 0; i < deck.countMain(); i++) + deckList.add(AllZone.CardFactory.getCard(deck.getMain(i), null)); + + //update gui + deckDisplay.updateDisplay(cardpool, deckList); + + }//importDeck() + + + private File getImportFilename() { + JFileChooser chooser = new JFileChooser(previousDirectory); + + chooser.addChoosableFileFilter(getFileFilter()); + int returnVal = chooser.showOpenDialog(null); + + if(returnVal == JFileChooser.APPROVE_OPTION) { + File file = chooser.getSelectedFile(); + previousDirectory = file.getParentFile(); + return file; + } + + return null; + }//openFileDialog() + + //edit the AI decks + private void setupComputerMenu() { + JMenuItem open = new JMenuItem("Open"); + JMenuItem new2 = new JMenuItem("New"); + JMenuItem rename = new JMenuItem("Rename"); + JMenuItem save = new JMenuItem("Save"); + JMenuItem copy = new JMenuItem("Copy"); + JMenuItem delete = new JMenuItem("Delete"); + JMenuItem exit = new JMenuItem("Exit"); + + + JMenuItem viewAllDecks = new JMenuItem("View All Decks"); + + + //AI + viewAllDecks.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + List nameList = questData.ai_getDeckNames(); + Collections.sort(nameList); + + Deck deck; + StringBuffer allText = new StringBuffer(); + + for(int i = 0; i < nameList.size(); i++) { + deck = questData.ai_getDeck(nameList.get(i).toString()); + allText.append(deck.getName()).append("\r\n"); + allText.append(getExportDeckText(deck)); + allText.append("++++++++++++++++++++++++++++++++++++++++++++++++++++++ \r\n \r\n"); + } + + JTextArea area = new JTextArea(allText.toString(), 30, 30); + JOptionPane.showMessageDialog(null, new JScrollPane(area)); + + }//actionPerformed() + });//viewAllDecks + + //AI + open.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + String deckName = getUserInput_OpenDeck(questData.ai_getDeckNames()); + + //check if user selected "cancel" + if(deckName.equals("")) return; + + + setComputerPlayer(deckName); + + Deck d = questData.ai_getDeck(deckName); + CardList deck = new CardList(); + + for(int i = 0; i < d.countMain(); i++) + deck.add(AllZone.CardFactory.getCard(d.getMain(i), null)); + + CardList cardpool = AllZone.CardFactory.getAllCards(); + + deckDisplay.updateDisplay(cardpool, deck); + + } + });//open + + //AI + new2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + deckDisplay.updateDisplay(AllZone.CardFactory.getAllCards(), new CardList()); + + setComputerPlayer(""); + } + });//new + + + //AI + rename.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + String name = getUserInput_GetDeckName(questData.ai_getDeckNames()); + + //check if user cancels + if(name.equals("")) return; + + //is the current deck already saved and in QuestData? + if(questData.ai_getDeckNames().contains(currentDeck.getName())) questData.ai_removeDeck(currentDeck.getName());//remove old deck + + currentDeck.setName(name); + + Deck deck = convertCardListToDeck(deckDisplay.getBottom()); + deck.setName(name); + questData.ai_addDeck(deck); + + setComputerPlayer(name); + } + });//rename + + + //AI + save.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + String name = currentDeck.getName(); + + //check to see if name is set + if(name.equals("")) { + name = getUserInput_GetDeckName(questData.ai_getDeckNames()); + + //check if user cancels + if(name.equals("")) return; + } + + setComputerPlayer(name); + + Deck deck = convertCardListToDeck(deckDisplay.getBottom()); + deck.setName(name); + + questData.ai_addDeck(deck); + } + });//save + + + //AI + copy.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + String name = getUserInput_GetDeckName(questData.ai_getDeckNames()); + + //check if user cancels + if(name.equals("")) return; + + setComputerPlayer(name); + + Deck deck = convertCardListToDeck(deckDisplay.getBottom()); + deck.setName(name); + + questData.ai_addDeck(deck); + } + });//copy + + + //AI + delete.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + if(currentDeck.getName().equals("")) return; + + int check = JOptionPane.showConfirmDialog(null, "Do you really want to delete this deck?", + "Delete", JOptionPane.YES_NO_OPTION); + if(check == JOptionPane.NO_OPTION) return;//stop here + + questData.ai_removeDeck(currentDeck.getName()); + + //show card pool + CardList cardpool = AllZone.CardFactory.getAllCards(); + deckDisplay.updateDisplay(cardpool, new CardList()); + + setComputerPlayer(""); + } + });//delete + + + //AI + exit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + Gui_Quest_DeckEditor_Menu.this.close(); + } + }); + + JMenu deckMenu = new JMenu("AI Deck"); + deckMenu.add(open); + deckMenu.add(rename); + deckMenu.add(new2); + deckMenu.add(save); + deckMenu.add(copy); + + deckMenu.addSeparator(); + addImportExport(deckMenu, false); + + deckMenu.add(viewAllDecks); + + deckMenu.addSeparator(); + deckMenu.add(delete); + deckMenu.addSeparator(); + deckMenu.add(exit); + + this.add(deckMenu); + + }//setupComputerMenu() + + private void openHumanDeck(String deckName) { + setHumanPlayer(deckName); + + CardList cardpool = covertToCardList(questData.getCardpool()); + + //covert Deck main to CardList + Deck d = questData.getDeck(deckName); + CardList deck = new CardList(); + + for(int i = 0; i < d.countMain(); i++) { + deck.add(AllZone.CardFactory.getCard(d.getMain(i), null)); + + //remove any cards that are in the deck from the card pool + cardpool.remove(d.getMain(i)); + } + + deckDisplay.updateDisplay(cardpool, deck); + + }//openHumanDeck + + + //the usual menu options that will be used + private void setupMenu() { + JMenuItem open = new JMenuItem("Open"); + JMenuItem new2 = new JMenuItem("New"); + JMenuItem rename = new JMenuItem("Rename"); + JMenuItem save = new JMenuItem("Save"); + JMenuItem copy = new JMenuItem("Copy"); + JMenuItem delete = new JMenuItem("Delete"); + JMenuItem exit = new JMenuItem("Exit"); + + //////////////////////////////////////////// + //below is new code + + //adds a card to human player's cardpool + JMenuItem addCard = new JMenuItem("Cheat - Add Card"); + + //add card + addCard.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent a) + { + //sort cards by card name + CardList cardList = AllZone.CardFactory.getAllCards(); + TableSorter sorter = new TableSorter(cardList, 1, true); + cardList.sort(sorter); + + //create a new Card object with a different toString() method + //so that that JList only shows the card's name + // + //this is alot of work just to make it a little + //easier and prettier for the user, gui stuff is very complicated + class BetterCard extends Card + { + private Card card; + + BetterCard(Card c) + { + card = c; + + //this line is very important + //if you omit this, errors will occur + this.setName(c.getName()); + } + + public String toString() + { + return card.getName(); + } + }//BetterCard + + Card[] card = cardList.toArray(); + + for(int i = 0; i < card.length; i++) + { + card[i] = new BetterCard(card[i]); + } + + final JList list = new JList(card); + list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + + //update the "card detail" on the right with the card info + list.addListSelectionListener(new ListSelectionListener() + { + public void valueChanged(ListSelectionEvent e) + { + + /* I think that the code that was based in CardDetailUtil + has been changed and moved to a new/different class? + + CardDetail cd = (CardDetail)deckDisplay; + cd.updateCardDetail((Card)list.getSelectedValue()); + + */ + + } + }); + + Object[] o = {"Add Card to Your Cardpool", new JScrollPane(list)}; + JOptionPane pane = new JOptionPane(o, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); + + JDialog dialog = pane.createDialog(null, "Cheat - Add Card"); + dialog.setModal(true); + dialog.setVisible(true); + + Object choice = pane.getValue(); + boolean cancel = false; + + //there are a ton of ways to cancel + if( + choice == null || + choice.equals(JOptionPane.UNINITIALIZED_VALUE) + ) + cancel = true; + else + { + int n = ((Integer)choice).intValue(); + if(n == JOptionPane.CANCEL_OPTION) + cancel = true; + } + + if(cancel || list.getSelectedValue() == null) + { + //System.out.println("cancelled"); + } + else + { + //show the choice that the user selected + //System.out.println(list.getSelectedValue()); + + Card c = (Card) list.getSelectedValue(); + + Gui_Quest_DeckEditor g = (Gui_Quest_DeckEditor)deckDisplay; + TableModel table = g.getTopTableModel(); + table.addCard(c); + table.resort(); + } + }//actionPerformed() + });//add card + + + //above is new code + /////////////////////////////////////// + + //human + open.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + String deckName = getUserInput_OpenDeck(questData.getDeckNames()); + + //check if user selected "cancel" + if(deckName.equals("")) return; + + openHumanDeck(deckName); + } + });//open + + //human + new2.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + CardList cardpool = covertToCardList(questData.getCardpool()); + deckDisplay.updateDisplay(cardpool, new CardList()); + + setHumanPlayer(""); + } + });//new + + + //human + rename.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + String name = getUserInput_GetDeckName(questData.getDeckNames()); + + //check if user cancels + if(name.equals("")) return; + + //is the current deck already saved and in QuestData? + if(questData.getDeckNames().contains(currentDeck.getName())) questData.removeDeck(currentDeck.getName());//remove old deck + + currentDeck.setName(name); + + Deck deck = convertCardListToDeck(deckDisplay.getBottom()); + deck.setName(name); + questData.addDeck(deck); + + setHumanPlayer(name); + } + });//rename + + + //human + save.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + String name = currentDeck.getName(); + + //check to see if name is set + if(name.equals("")) { + name = getUserInput_GetDeckName(questData.getDeckNames()); + + //check if user cancels + if(name.equals("")) return; + } + + setHumanPlayer(name); + + Deck deck = convertCardListToDeck(deckDisplay.getBottom()); + deck.setName(name); + + questData.addDeck(deck); + } + });//save + + + //human + copy.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + String name = getUserInput_GetDeckName(questData.getDeckNames()); + + //check if user cancels + if(name.equals("")) return; + + setHumanPlayer(name); + + Deck deck = convertCardListToDeck(deckDisplay.getBottom()); + deck.setName(name); + + questData.addDeck(deck); + } + });//copy + + + //human + delete.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + if(currentDeck.getName().equals("")) return; + + int check = JOptionPane.showConfirmDialog(null, "Do you really want to delete this deck?", + "Delete", JOptionPane.YES_NO_OPTION); + if(check == JOptionPane.NO_OPTION) return;//stop here + + questData.removeDeck(currentDeck.getName()); + + //show card pool + CardList cardpool = covertToCardList(questData.getCardpool()); + deckDisplay.updateDisplay(cardpool, new CardList()); + + setHumanPlayer(""); + } + });//delete + + + //human + exit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent a) { + Gui_Quest_DeckEditor_Menu.this.close(); + } + }); + + JMenu deckMenu = new JMenu("Deck"); + deckMenu.add(open); + deckMenu.add(new2); + deckMenu.add(rename); + deckMenu.add(save); + deckMenu.add(copy); + + // The "Cheat - Add Card" menu item is buggy. + // There are other, safer and less buggy ways for people to cheat. + + // deckMenu.addSeparator();//new code + // deckMenu.add(addCard); //new code + + deckMenu.addSeparator(); + addImportExport(deckMenu, true); + + deckMenu.addSeparator(); + deckMenu.add(delete); + deckMenu.addSeparator(); + deckMenu.add(exit); + + this.add(deckMenu); + + }//setupMenu() + + private Deck convertCardListToDeck(CardList list) { + //put CardList into Deck main + Deck deck = new Deck(Constant.GameType.Sealed); + + for(int i = 0; i < list.size(); i++) + deck.addMain(list.get(i).getName()); + + return deck; + } + + //needs to be public because Gui_Quest_DeckEditor.show(Command) uses it + public void setHumanPlayer(String deckName) { + //the gui uses this, Gui_Quest_DeckEditor + currentDeck = new Deck(Constant.GameType.Sealed); + currentDeck.setName(deckName); + + deckDisplay.setTitle(deckEditorName + " - " + deckName); + } + + private void setComputerPlayer(String deckName) { + //the gui uses this, Gui_Quest_DeckEditor + currentDeck = new Deck(Constant.GameType.Constructed); + currentDeck.setName(deckName); + + deckDisplay.setTitle(deckEditorName + " - " + deckName); + } + + //only accepts numbers, letters or dashes up to 20 characters in length + private String cleanString(String in) { + StringBuffer out = new StringBuffer(); + char[] c = in.toCharArray(); + + for(int i = 0; i < c.length && i < 20; i++) + if(Character.isLetterOrDigit(c[i]) || c[i] == '-' || c[i] == '_' || c[i] == ' ') out.append(c[i]); + + return out.toString(); + } + + //if user cancels, returns "" + private String getUserInput_GetDeckName(List nameList) { + Object o = JOptionPane.showInputDialog(null, "", "Deck Name", JOptionPane.OK_CANCEL_OPTION); + + if(o == null) return ""; + + String deckName = cleanString(o.toString()); + + if(nameList.contains(deckName) || deckName.equals("")) { + JOptionPane.showMessageDialog(null, "Please pick another deck name, a deck currently has that name."); + return getUserInput_GetDeckName(nameList); + } + + return deckName; + }//getUserInput_GetDeckName() + + + //if user cancels, it will return "" + private String getUserInput_OpenDeck(List deckNameList) { + List choices = deckNameList; + if(choices.size() == 0) { + JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE); + return ""; + } + + //Object o = JOptionPane.showInputDialog(null, "Deck Name", "Open Deck", JOptionPane.OK_CANCEL_OPTION, null, + // choices.toArray(), choices.toArray()[0]); + Object o = GuiUtils.getChoiceOptional("Select Deck", choices.toArray()); + + if(o == null) return ""; + + return o.toString(); + }//getUserInput_OpenDeck() + + //used by Gui_Quest_DeckEditor + public void close() { + exitCommand.execute(); + } + + //used by Gui_Quest_DeckEditor + public String getDeckName() { + return currentDeck.getName(); + } + + //used by Gui_Quest_DeckEditor + public String getGameType() { + return currentDeck.getDeckType(); + } + + + //returns CardList of Card objects, + //argument ArrayList holds String card names + public static CardList covertToCardList(List list) { + CardList c = new CardList(); + Card card; + for (String aList : list) { + card = AllZone.CardFactory.getCard(aList, null); + c.add(card); + } + + return c; + } + +} diff --git a/src/forge/Gui_Treasury.java b/src/forge/Gui_Treasury.java index 475acb7a999..1a083d21df2 100644 --- a/src/forge/Gui_Treasury.java +++ b/src/forge/Gui_Treasury.java @@ -1,249 +1,244 @@ -package forge; - -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; -import java.io.File; - -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.SwingConstants; - -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - -public class Gui_Treasury extends JFrame implements NewConstants{ - - private static final long serialVersionUID = 2409591658245091210L; - - private JFrame shopsGUI; - private JLabel titleLabel = new JLabel(); - - private JLabel estatesDescLabel = new JLabel(); - //private JLabel estatesStatsLabel = new JLabel(); - private JLabel estatesPriceLabel = new JLabel(); - private JLabel estatesIconLabel = new JLabel(); - - private JLabel creditsLabel = new JLabel(); - - private ImageIcon estatesIcon = new ImageIcon(); - - private JButton learnEstatesButton= new JButton(); - private JButton quitButton = new JButton(); - - private QuestData questData = AllZone.QuestData; - - public Gui_Treasury(JFrame parent) { - try { - jbInit(); - } catch(Exception ex) { - ErrorViewer.showError(ex); - } - - shopsGUI = parent; - - setup(); - - //for some reason, the Bazaar window does not return when closing with X - //for now, just disable X closing: - this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - - Dimension screen = this.getToolkit().getScreenSize(); - setBounds(screen.width / 3, 100, //position - 530, 430); //size - setVisible(true); - - - } - - //only do this ONCE: - private void setup() { - learnEstatesButton.setBounds(new Rectangle(10, 297, 120, 50)); - learnEstatesButton.setText(getButtonText()); - //buyPlantButton.setIcon(icon); - learnEstatesButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - try { - learnEstatesButton_actionPerformed(e); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - } - }); - - }//setup(); - - private String getDesc() - { - StringBuilder sb = new StringBuilder(); - sb.append(""); - - if (questData.getEstatesLevel() == 0) - { - sb.append("Level 1 Estates
"); - sb.append("Gives a bonus of 10% to match winnings.
"); - sb.append("Improves sell percentage by 1.0%."); - } - else if (questData.getEstatesLevel() == 1) - { - sb.append("Level 2 Estates
"); - sb.append("Gives a bonus of 15% to match winnings.
"); - sb.append("Improves sell percentage by 1.75%."); - } - else if (questData.getEstatesLevel() == 2) - { - sb.append("Level 3 Estates
"); - sb.append("Gives a bonus of 20% to match winnings.
"); - sb.append("Improves sell percentage by 2.5%."); - } - else if (questData.getEstatesLevel() >= 3 && questData.getLuckyCoinLevel() == 0) - { - sb.append("Estates Level Maxed out.
"); - sb.append("Lucky Coin
"); - sb.append("This coin is believed to give good luck to its owner.
"); - sb.append("Improves the chance of getting a random
rare after each match by 15%."); - /*sb.append("Current Level: 3/3
"); - sb.append("Gives a bonus of 20% to match winnings.
"); - sb.append("Improves sell percentage by 2.5%.");*/ - } - else - { - sb.append("Currently nothing for sale at the Treasury.
Please check back later."); - } - - sb.append(""); - return sb.toString(); - } - - private long getPrice() - { - long l = 0; - if (questData.getEstatesLevel() == 0) - l = 500; - else if (questData.getEstatesLevel() == 1) - l = 750; - else if (questData.getEstatesLevel() == 2) - l = 1000; - else if (questData.getEstatesLevel() >= 3 && questData.getLuckyCoinLevel() == 0) - l = 500; - - - return l; - } - - private String getButtonText() - { - if (questData.getEstatesLevel() < 3) - return "Learn Estates"; - else - return "Buy Coin"; - } - - private String getImageString() - { - if (questData.getEstatesLevel() < 3) - return "GoldIconLarge.png"; - else - return "CoinIcon.png"; - } - - private void jbInit() throws Exception { - titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); - titleLabel.setHorizontalAlignment(SwingConstants.CENTER); - titleLabel.setText("Treasury"); - titleLabel.setBounds(new Rectangle(130, 5, 198, 60)); - this.getContentPane().setLayout(null); - - /* - potionStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); - potionStatsLabel.setText(getStats()); - potionStatsLabel.setBounds(new Rectangle(10, 65, 100, 15)); - */ - - estatesDescLabel.setFont(new Font("sserif", 0, 12)); - estatesDescLabel.setText(getDesc()); - estatesDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); - - estatesPriceLabel.setFont(new Font("sserif", 0, 12)); - estatesPriceLabel.setText("Price: " + getPrice() + " credits"); - estatesPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); - - creditsLabel.setFont(new Font("sserif", 0, 12)); - creditsLabel.setText("Credits: " + questData.getCredits()); - creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); - - estatesIcon = getIcon(getImageString()); - estatesIconLabel.setText(""); - estatesIconLabel.setIcon(estatesIcon); - estatesIconLabel.setBounds(new Rectangle(255, 65, 256, 256)); - estatesIconLabel.setIconTextGap(0); - - //String fileName = "LeafIconSmall.png"; - //ImageIcon icon = getIcon(fileName); - - learnEstatesButton.setEnabled(true); - if (questData.getCredits() < getPrice() || (questData.getEstatesLevel() >= 3 && questData.getLuckyCoinLevel() >= 1)) - learnEstatesButton.setEnabled(false); - - quitButton.setBounds(new Rectangle(140, 297, 120, 50)); - quitButton.setText("Quit"); - quitButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - quitButton_actionPerformed(e); - } - }); - - - //jPanel2.add(quitButton, null); - this.getContentPane().add(learnEstatesButton, null); - this.getContentPane().add(titleLabel, null); - this.getContentPane().add(estatesDescLabel, null); - this.getContentPane().add(estatesIconLabel, null); - this.getContentPane().add(estatesPriceLabel, null); - this.getContentPane().add(creditsLabel, null); - this.getContentPane().add(quitButton,null); - } - - void learnEstatesButton_actionPerformed(ActionEvent e) throws Exception { - questData.subtractCredits(getPrice()); - - if (questData.getEstatesLevel() < 3) - { - questData.addEstatesLevel(1); - } - else if (questData.getLuckyCoinLevel() < 1) - { - questData.addLuckyCoinLevel(1); - } - QuestData.saveData(questData); - jbInit(); - } - - private ImageIcon getIcon(String fileName) - { - File base = ForgeProps.getFile(IMAGE_ICON); - File file = new File(base, fileName); - ImageIcon icon = new ImageIcon(file.toString()); - return icon; - } - - void quitButton_actionPerformed(ActionEvent e) { - QuestData.saveData(questData); - //new Gui_Shops(); - shopsGUI.setVisible(true); - - dispose(); - - } - - void this_windowClosing(WindowEvent e) { - quitButton_actionPerformed(null); - } - -} +package forge; + +import forge.error.ErrorViewer; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; + +import javax.swing.*; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.WindowEvent; +import java.io.File; + +public class Gui_Treasury extends JFrame implements NewConstants{ + + private static final long serialVersionUID = 2409591658245091210L; + + private JFrame shopsGUI; + private JLabel titleLabel = new JLabel(); + + private JLabel estatesDescLabel = new JLabel(); + //private JLabel estatesStatsLabel = new JLabel(); + private JLabel estatesPriceLabel = new JLabel(); + private JLabel estatesIconLabel = new JLabel(); + + private JLabel creditsLabel = new JLabel(); + + private ImageIcon estatesIcon = new ImageIcon(); + + private JButton learnEstatesButton= new JButton(); + private JButton quitButton = new JButton(); + + private forge.quest.data.QuestData questData = AllZone.QuestData; + + public Gui_Treasury(JFrame parent) { + try { + jbInit(); + } catch(Exception ex) { + ErrorViewer.showError(ex); + } + + shopsGUI = parent; + + setup(); + + //for some reason, the Bazaar window does not return when closing with X + //for now, just disable X closing: + this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + + Dimension screen = this.getToolkit().getScreenSize(); + setBounds(screen.width / 3, 100, //position + 530, 430); //size + setVisible(true); + + + } + + //only do this ONCE: + private void setup() { + learnEstatesButton.setBounds(new Rectangle(10, 297, 120, 50)); + learnEstatesButton.setText(getButtonText()); + //buyPlantButton.setIcon(icon); + learnEstatesButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + learnEstatesButton_actionPerformed(e); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + }); + + }//setup(); + + private String getDesc() + { + StringBuilder sb = new StringBuilder(); + sb.append(""); + + if (questData.getEstatesLevel() == 0) + { + sb.append("Level 1 Estates
"); + sb.append("Gives a bonus of 10% to match winnings.
"); + sb.append("Improves sell percentage by 1.0%."); + } + else if (questData.getEstatesLevel() == 1) + { + sb.append("Level 2 Estates
"); + sb.append("Gives a bonus of 15% to match winnings.
"); + sb.append("Improves sell percentage by 1.75%."); + } + else if (questData.getEstatesLevel() == 2) + { + sb.append("Level 3 Estates
"); + sb.append("Gives a bonus of 20% to match winnings.
"); + sb.append("Improves sell percentage by 2.5%."); + } + else if (questData.getEstatesLevel() >= 3 && questData.getLuckyCoinLevel() == 0) + { + sb.append("Estates Level Maxed out.
"); + sb.append("Lucky Coin
"); + sb.append("This coin is believed to give good luck to its owner.
"); + sb.append("Improves the chance of getting a random
rare after each match by 15%."); + /*sb.append("Current Level: 3/3
"); + sb.append("Gives a bonus of 20% to match winnings.
"); + sb.append("Improves sell percentage by 2.5%.");*/ + } + else + { + sb.append("Currently nothing for sale at the Treasury.
Please check back later."); + } + + sb.append(""); + return sb.toString(); + } + + private long getPrice() + { + long l = 0; + if (questData.getEstatesLevel() == 0) + l = 500; + else if (questData.getEstatesLevel() == 1) + l = 750; + else if (questData.getEstatesLevel() == 2) + l = 1000; + else if (questData.getEstatesLevel() >= 3 && questData.getLuckyCoinLevel() == 0) + l = 500; + + + return l; + } + + private String getButtonText() + { + if (questData.getEstatesLevel() < 3) + return "Learn Estates"; + else + return "Buy Coin"; + } + + private String getImageString() + { + if (questData.getEstatesLevel() < 3) + return "GoldIconLarge.png"; + else + return "CoinIcon.png"; + } + + private void jbInit() throws Exception { + titleLabel.setFont(new java.awt.Font("sserif", Font.BOLD, 22)); + titleLabel.setHorizontalAlignment(SwingConstants.CENTER); + titleLabel.setText("Treasury"); + titleLabel.setBounds(new Rectangle(130, 5, 198, 60)); + this.getContentPane().setLayout(null); + + /* + potionStatsLabel.setFont(new Font("sserif", Font.BOLD, 12)); + potionStatsLabel.setText(getStats()); + potionStatsLabel.setBounds(new Rectangle(10, 65, 100, 15)); + */ + + estatesDescLabel.setFont(new Font("sserif", 0, 12)); + estatesDescLabel.setText(getDesc()); + estatesDescLabel.setBounds(new Rectangle(10, 80, 300, 150)); + + estatesPriceLabel.setFont(new Font("sserif", 0, 12)); + estatesPriceLabel.setText("Price: " + getPrice() + " credits"); + estatesPriceLabel.setBounds(new Rectangle(10, 230, 150, 15)); + + creditsLabel.setFont(new Font("sserif", 0, 12)); + creditsLabel.setText("Credits: " + questData.getCredits()); + creditsLabel.setBounds(new Rectangle(10, 265, 150, 15)); + + estatesIcon = getIcon(getImageString()); + estatesIconLabel.setText(""); + estatesIconLabel.setIcon(estatesIcon); + estatesIconLabel.setBounds(new Rectangle(255, 65, 256, 256)); + estatesIconLabel.setIconTextGap(0); + + //String fileName = "LeafIconSmall.png"; + //ImageIcon icon = getIcon(fileName); + + learnEstatesButton.setEnabled(true); + if (questData.getCredits() < getPrice() || (questData.getEstatesLevel() >= 3 && questData.getLuckyCoinLevel() >= 1)) + learnEstatesButton.setEnabled(false); + + quitButton.setBounds(new Rectangle(140, 297, 120, 50)); + quitButton.setText("Quit"); + quitButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(ActionEvent e) { + quitButton_actionPerformed(e); + } + }); + + + //jPanel2.add(quitButton, null); + this.getContentPane().add(learnEstatesButton, null); + this.getContentPane().add(titleLabel, null); + this.getContentPane().add(estatesDescLabel, null); + this.getContentPane().add(estatesIconLabel, null); + this.getContentPane().add(estatesPriceLabel, null); + this.getContentPane().add(creditsLabel, null); + this.getContentPane().add(quitButton,null); + } + + void learnEstatesButton_actionPerformed(ActionEvent e) throws Exception { + questData.subtractCredits(getPrice()); + + if (questData.getEstatesLevel() < 3) + { + questData.addEstatesLevel(1); + } + else if (questData.getLuckyCoinLevel() < 1) + { + questData.addLuckyCoinLevel(1); + } + questData.saveData(); + jbInit(); + } + + private ImageIcon getIcon(String fileName) + { + File base = ForgeProps.getFile(IMAGE_ICON); + File file = new File(base, fileName); + ImageIcon icon = new ImageIcon(file.toString()); + return icon; + } + + void quitButton_actionPerformed(ActionEvent e) { + questData.saveData(); + //new Gui_Shops(); + shopsGUI.setVisible(true); + + dispose(); + + } + + void this_windowClosing(WindowEvent e) { + quitButton_actionPerformed(null); + } + +} diff --git a/src/forge/Gui_WinLose.java b/src/forge/Gui_WinLose.java index 67ec5bdd8e0..c74da9343ca 100644 --- a/src/forge/Gui_WinLose.java +++ b/src/forge/Gui_WinLose.java @@ -6,6 +6,8 @@ import forge.error.ErrorViewer; import forge.properties.ForgeProps; import forge.properties.NewConstants; import forge.properties.NewConstants.LANG.Gui_WinLose.WINLOSE_TEXT; +import forge.quest.data.QuestMatchState; +import forge.quest.data.QuestPreferences; import forge.quest.gui.QuestFrame; import net.miginfocom.swing.MigLayout; @@ -46,8 +48,8 @@ public class Gui_WinLose extends JFrame implements NewConstants { public static void main(String[] args) { Constant.Runtime.GameType[0] = Constant.GameType.Sealed; - Constant.Runtime.WinLose.addWin(); - Constant.Runtime.WinLose.addLose(); + Constant.Runtime.matchState.addWin(); + Constant.Runtime.matchState.addLose(); //setup limited deck Deck deck = new Deck(Constant.GameType.Sealed); @@ -114,7 +116,7 @@ public class Gui_WinLose extends JFrame implements NewConstants { private void setup() { AllZone.GameInfo.clearColorChanges(); - WinLose winLose = Constant.Runtime.WinLose; + QuestMatchState winLose = Constant.Runtime.matchState; Phase.GameBegins = 0; //3 is the match length, 3 is the number of games //disable buttons if match is up, or human player won 2 or lost 2 games already @@ -228,16 +230,16 @@ public class Gui_WinLose extends JFrame implements NewConstants { else{ int extraLife = 0; if (AllZone.QuestAssignment != null) { - QuestUtil.setupQuest(AllZone.QuestAssignment); + forge.quest.data.QuestUtil.setupQuest(AllZone.QuestAssignment); if (AllZone.QuestData.getGearLevel() == 2) extraLife = 3; } //AllZone.GameAction.newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife); - CardList humanList = QuestUtil.getHumanPlantAndPet(AllZone.QuestData, AllZone.QuestAssignment); + CardList humanList = forge.quest.data.QuestUtil.getHumanPlantAndPet(AllZone.QuestData, AllZone.QuestAssignment); CardList computerList = new CardList(); - int humanLife = QuestUtil.getLife(AllZone.QuestData) + extraLife; + int humanLife = AllZone.QuestData.getLife() + extraLife; int computerLife = 20; if (AllZone.QuestAssignment!=null) computerLife = AllZone.QuestAssignment.getComputerLife(); @@ -250,7 +252,7 @@ public class Gui_WinLose extends JFrame implements NewConstants { } void restartButton_actionPerformed(ActionEvent e) { - Constant.Runtime.WinLose.reset(); + Constant.Runtime.matchState.reset(); if (!Constant.Quest.fantasyQuest[0]) AllZone.GameAction.newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0]); @@ -258,16 +260,16 @@ public class Gui_WinLose extends JFrame implements NewConstants { int extraLife = 0; //AllZone.GameAction.newGame(Constant.Runtime.HumanDeck[0], Constant.Runtime.ComputerDeck[0], humanList, computerList, humanLife, computerLife); if (AllZone.QuestAssignment != null) { - QuestUtil.setupQuest(AllZone.QuestAssignment); + forge.quest.data.QuestUtil.setupQuest(AllZone.QuestAssignment); if (AllZone.QuestData.getGearLevel() == 2) extraLife = 3; } - CardList humanList = QuestUtil.getHumanPlantAndPet(AllZone.QuestData, AllZone.QuestAssignment); + CardList humanList = forge.quest.data.QuestUtil.getHumanPlantAndPet(AllZone.QuestData, AllZone.QuestAssignment); //CardList computerList = QuestUtil.getComputerCreatures(AllZone.QuestData, AllZone.QuestAssignment); CardList computerList = new CardList(); - int humanLife = QuestUtil.getLife(AllZone.QuestData) +extraLife; + int humanLife = AllZone.QuestData.getLife() +extraLife; int computerLife = 20; if (AllZone.QuestAssignment!=null) @@ -280,7 +282,7 @@ public class Gui_WinLose extends JFrame implements NewConstants { dispose(); } - private String getWinText(long creds, WinLose winLose, QuestData q) + private String getWinText(long creds, QuestMatchState winLose, forge.quest.data.QuestData q) { // todo use q.qdPrefs to write bonus credits in prefs file StringBuilder sb = new StringBuilder(); @@ -288,7 +290,7 @@ public class Gui_WinLose extends JFrame implements NewConstants { sb.append(""); - QuestData_Prefs qdPrefs = q.qdPrefs; + QuestPreferences qdPrefs = q.getQuestPreferences(); for (String s : wins) { @@ -394,11 +396,11 @@ public class Gui_WinLose extends JFrame implements NewConstants { new Gui_NewGame(); } else { //Quest - WinLose winLose = Constant.Runtime.WinLose; - QuestData quest = AllZone.QuestData; + QuestMatchState matchState = Constant.Runtime.matchState; + forge.quest.data.QuestData quest = AllZone.QuestData; boolean wonMatch = false; - if(winLose.getWin() == 2){ + if(matchState.getWin() == 2){ quest.addWin(); wonMatch = true; } @@ -425,8 +427,8 @@ public class Gui_WinLose extends JFrame implements NewConstants { } if (wonMatch){ - long creds = quest.getCreditsToAdd(winLose); - String s = getWinText(creds, winLose, quest); + long creds = quest.getCreditsToAdd(matchState); + String s = getWinText(creds, matchState, quest); String fileName = "GoldIcon.png"; ImageIcon icon = getIcon(fileName); @@ -489,11 +491,11 @@ public class Gui_WinLose extends JFrame implements NewConstants { JOptionPane.showMessageDialog(null, "", "You have won a random rare.", JOptionPane.INFORMATION_MESSAGE, icon); } - winLose.reset(); + matchState.reset(); AllZone.QuestAssignment = null; - QuestData.saveData(quest); + quest.saveData(); if (AllZone.QuestData.useNewQuestUI){ new QuestFrame(); } diff --git a/src/forge/QuestData.java b/src/forge/QuestData.java index 054309851eb..94a279f9e8c 100644 --- a/src/forge/QuestData.java +++ b/src/forge/QuestData.java @@ -1,24 +1,14 @@ package forge; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Random; - import com.esotericsoftware.minlog.Log; - import forge.error.ErrorViewer; import forge.properties.ForgeProps; import forge.properties.NewConstants; +import java.io.*; +import java.util.*; + //when you create QuestData and AFTER you copy the AI decks over //you have to call one of these two methods below @@ -27,6 +17,8 @@ import forge.properties.NewConstants; //static readAIQuestDeckFiles(QuestData data, ArrayList aiDeckNames) //OR non-static readAIQuestDeckFiles() //which reads the files "questDecks-easy", "questDecks-medium","questDecks-hard", +@SuppressWarnings({"deprecation"}) +@Deprecated public class QuestData implements NewConstants { QuestData_Prefs qdPrefs = null; diff --git a/src/forge/QuestData_BoosterPack.java b/src/forge/QuestData_BoosterPack.java index f76453f122a..82df7527836 100644 --- a/src/forge/QuestData_BoosterPack.java +++ b/src/forge/QuestData_BoosterPack.java @@ -9,6 +9,7 @@ import java.util.*; //balance the number of colors and creature/spells for //new cards that are won in quest mode +@Deprecated public class QuestData_BoosterPack implements NewConstants { // final private static String comment = "//"; diff --git a/src/forge/QuestData_Prefs.java b/src/forge/QuestData_Prefs.java index e726288e933..28d5b3aa77c 100644 --- a/src/forge/QuestData_Prefs.java +++ b/src/forge/QuestData_Prefs.java @@ -1,357 +1,358 @@ -package forge; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.Serializable; - -import forge.properties.ForgeProps; -import forge.properties.NewConstants.QUEST; - -public class QuestData_Prefs implements Serializable { - private static final long serialVersionUID = 3266336025656577905L; - - private int numDiff = 4; - - // Descriptive difficulty names - private String[] sDifficulty = { "Easy", "Normal", "Hard", "Very Hard" }; - - // Default match wins it takes to gain a booster - private int[] winsForBooster = { 1, 1, 2, 2 }; - private int[] winsForRankIncrease = { 1, 2, 3, 4 }; - private int[] winsForMediumAI = { 6, 6, 11, 11 }; - private int[] winsForHardAI = { 9, 9, 21, 21 }; - - // Default starting land for a quest - private int startingBasicLand = 20; - private int startingSnowBasicLand = 20; - - // Default starting amount of each rarity - private int[] startingCommons = {45, 40, 40, 40}; - private int[] startingUncommons = {20, 15, 15, 15}; - private int[] startingRares = {10, 10, 10, 10}; - - private int startingCredits = 250; - - private int boosterPackRare = 1; - private int boosterPackUncommon = 3; - private int boosterPackCommon = 9; - - private int matchRewardBase = 10; - private double matchRewardTotalWins = 0.3; - private int matchRewardNoLosses = 10; - - private int matchRewardPoisonWinBonus = 50; - private int matchRewardMilledWinBonus = 40; - private int matchRewardAltWinBonus = 100; - - private int matchRewardWinOnFirstTurn = 1500; - private int matchRewardWinByTurnFive = 250; - private int matchRewardWinByTurnTen = 50; - private int matchRewardWinByTurnFifteen = 5; - private int matchRewardMullToZero = 500; - - public QuestData_Prefs() - { - // if quest.prefs exists - grabPrefsFromFile(); - } - - public void grabPrefsFromFile(){ - try{ - BufferedReader input = new BufferedReader(new FileReader(ForgeProps.getFile(QUEST.PREFS))); - String line = null; - while((line = input.readLine()) != null){ - if (line.startsWith("#") || line.length() == 0) - continue; - String[] split = line.split("="); - - if (split[0].equals("difficultyString")) - setDifficulty(split[1]); - else if (split[0].equals("winsForBooster")) - setWinsForBooster(split[1]); - else if (split[0].equals("winsForRankIncrease")) - setWinsForRank(split[1]); - else if (split[0].equals("winsForMediumAI")) - setWinsForMediumAI(split[1]); - else if (split[0].equals("winsForHardAI")) - setWinsForHardAI(split[1]); - else if (split[0].equals("startingBasicLand")) - setStartingBasic(split[1]); - else if (split[0].equals("startingSnowBasicLand")) - setStartingSnowBasic(split[1]); - else if (split[0].equals("startingCommons")) - setStartingCommons(split[1]); - else if (split[0].equals("startingUncommons")) - setStartingUncommons(split[1]); - else if (split[0].equals("startingRares")) - setStartingRares(split[1]); - else if (split[0].equals("startingCredits")) - setStartingCredits(split[1]); - else if (split[0].equals("boosterPackCommon")) - setNumCommon(split[1]); - else if (split[0].equals("boosterPackUncommon")) - setNumUncommon(split[1]); - else if (split[0].equals("boosterPackRare")) - setNumRares(split[1]); - else if (split[0].equals("matchRewardBase")) - setMatchRewardBase(split[1]); - else if (split[0].equals("matchRewardTotalWins")) - setMatchRewardTotalWins(split[1]); - else if (split[0].equals("matchRewardNoLosses")) - setMatchRewardNoLosses(split[1]); - else if (split[0].equals("matchRewardMilledWinBonus")) - setMatchRewardMilledWinBonus(split[1]); - else if (split[0].equals("matchRewardPoisonWinBonus")) - setMatchRewardPoisonWinBonus(split[1]); - else if (split[0].equals("matchRewardAltWinBonus")) - setMatchRewardAltWinBonus(split[1]); - else if (split[0].equals("matchRewardWinOnFirstTurn")) - setMatchRewardWinFirst(split[1]); - else if (split[0].equals("matchRewardWinByTurnFive")) - setMatchRewardWinByFifth(split[1]); - else if (split[0].equals("matchRewardWinByTurnTen")) - setMatchRewardWinByTen(split[1]); - else if (split[0].equals("matchRewardWinByTurnFifteen")) - setMatchRewardWinByFifteen(split[1]); - else if (split[0].equals("matchRewardMullToZero")) - setMatchMullToZero(split[1]); - } - } - catch(Exception e) - { - System.out.println("Trouble grabbing quest data preferences. Using default values."); - } - } - - // getters - public String[] getDifficulty(){ - return sDifficulty; - } - - public String getDifficulty(int index){ - return sDifficulty[index]; - } - - public int getWinsForBooster(int index){ - return winsForBooster[index]; - } - - public int getWinsForRankIncrease(int index){ - return winsForRankIncrease[index]; - } - - public int getWinsForMediumAI(int index){ - return winsForMediumAI[index]; - } - - public int getWinsForHardAI(int index){ - return winsForHardAI[index]; - } - - public int getStartingBasic(){ - return startingBasicLand; - } - - public int getStartingSnowBasic(){ - return startingSnowBasicLand; - } - - public int getStartingCommons(int index){ - return startingCommons[index]; - } - - public int getStartingUncommons(int index){ - return startingUncommons[index]; - } - - public int getStartingRares(int index){ - return startingRares[index]; - } - - public int getStartingCredits(){ - return startingCredits; - } - - public int getNumCommon(){ - return boosterPackCommon; - } - - public int getNumUncommon(){ - return boosterPackUncommon; - } - - public int getNumRare(){ - return boosterPackRare; - } - - - public int getMatchRewardBase(){ - return matchRewardBase; - } - - public double getMatchRewardTotalWins(){ - return matchRewardTotalWins; - } - - public int getMatchRewardNoLosses(){ - return matchRewardNoLosses; - } - - public int getMatchRewardPoisonWinBonus(){ - return matchRewardPoisonWinBonus; - } - - public int getMatchRewardMilledWinBonus(){ - return matchRewardMilledWinBonus; - } - - public int getMatchRewardAltWinBonus(){ - return matchRewardAltWinBonus; - } - - - public int getMatchRewardWinFirst(){ - return matchRewardWinOnFirstTurn; - } - - public int getMatchRewardWinByFifth(){ - return matchRewardWinByTurnFive; - } - - public int getMatchRewardWinByTen(){ - return matchRewardWinByTurnTen; - } - - public int getMatchRewardWinByFifteen(){ - return matchRewardWinByTurnFifteen; - } - - public int getMatchMullToZero(){ - return matchRewardMullToZero; - } - - - // setters - public void setDifficulty(String diff){ - this.sDifficulty = diff.split(","); - } - - public void setWinsForBooster(String wins){ - String[] winsStr = wins.split(","); - - for(int i = 0; i < numDiff; i++) - this.winsForBooster[i] = Integer.parseInt(winsStr[i]); - } - - public void setWinsForRank(String wins){ - String[] winsStr = wins.split(","); - - for(int i = 0; i < numDiff; i++) - this.winsForRankIncrease[i] = Integer.parseInt(winsStr[i]); - } - - public void setWinsForMediumAI(String wins){ - String[] winsStr = wins.split(","); - - for(int i = 0; i < numDiff; i++) - this.winsForMediumAI[i] = Integer.parseInt(winsStr[i]); - } - - public void setWinsForHardAI(String wins){ - String[] winsStr = wins.split(","); - - for(int i = 0; i < numDiff; i++) - this.winsForHardAI[i] = Integer.parseInt(winsStr[i]); - } - - public void setStartingBasic(String land){ - this.startingBasicLand = Integer.parseInt(land); - } - - public void setStartingSnowBasic(String land){ - this.startingSnowBasicLand = Integer.parseInt(land); - } - - public void setStartingCommons(String rarity){ - String[] splitStr = rarity.split(","); - - for(int i = 0; i < numDiff; i++) - this.startingCommons[i] = Integer.parseInt(splitStr[i]); - } - - public void setStartingUncommons(String rarity){ - String[] splitStr = rarity.split(","); - - for(int i = 0; i < numDiff; i++) - this.startingUncommons[i] = Integer.parseInt(splitStr[i]); - } - - public void setStartingRares(String rarity){ - String[] splitStr = rarity.split(","); - - for(int i = 0; i < numDiff; i++) - this.startingRares[i] = Integer.parseInt(splitStr[i]); - } - - public void setStartingCredits(String credits){ - this.startingCredits = Integer.parseInt(credits); - } - - public void setNumCommon(String pack){ - this.boosterPackCommon = Integer.parseInt(pack); - } - - public void setNumUncommon(String pack){ - this.boosterPackUncommon = Integer.parseInt(pack); - } - - public void setNumRares(String pack){ - this.boosterPackRare = Integer.parseInt(pack); - } - - - public void setMatchRewardBase(String match){ - this.matchRewardBase = Integer.parseInt(match); - } - - public void setMatchRewardTotalWins(String match){ - this.matchRewardTotalWins = Double.parseDouble(match); - } - - public void setMatchRewardNoLosses(String match){ - this.matchRewardNoLosses = Integer.parseInt(match); - } - - public void setMatchRewardPoisonWinBonus(String match){ - this.matchRewardPoisonWinBonus = Integer.parseInt(match); - } - - public void setMatchRewardMilledWinBonus(String match){ - this.matchRewardMilledWinBonus = Integer.parseInt(match); - } - - public void setMatchRewardAltWinBonus(String match){ - this.matchRewardAltWinBonus = Integer.parseInt(match); - } - - - public void setMatchRewardWinFirst(String match){ - this.matchRewardWinOnFirstTurn = Integer.parseInt(match); - } - - public void setMatchRewardWinByFifth(String match){ - this.matchRewardWinByTurnFive = Integer.parseInt(match); - } - - public void setMatchRewardWinByTen(String match){ - this.matchRewardWinByTurnTen = Integer.parseInt(match); - } - - public void setMatchRewardWinByFifteen(String match){ - this.matchRewardWinByTurnFifteen = Integer.parseInt(match); - } - - public void setMatchMullToZero(String match){ - this.matchRewardMullToZero = Integer.parseInt(match); - } -} +package forge; + +import forge.properties.ForgeProps; +import forge.properties.NewConstants.QUEST; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.Serializable; + +@Deprecated +public class QuestData_Prefs implements Serializable { + private static final long serialVersionUID = 3266336025656577905L; + + private int numDiff = 4; + + // Descriptive difficulty names + private String[] sDifficulty = { "Easy", "Normal", "Hard", "Very Hard" }; + + // Default match wins it takes to gain a booster + private int[] winsForBooster = { 1, 1, 2, 2 }; + private int[] winsForRankIncrease = { 1, 2, 3, 4 }; + private int[] winsForMediumAI = { 6, 6, 11, 11 }; + private int[] winsForHardAI = { 9, 9, 21, 21 }; + + // Default starting land for a quest + private int startingBasicLand = 20; + private int startingSnowBasicLand = 20; + + // Default starting amount of each rarity + private int[] startingCommons = {45, 40, 40, 40}; + private int[] startingUncommons = {20, 15, 15, 15}; + private int[] startingRares = {10, 10, 10, 10}; + + private int startingCredits = 250; + + private int boosterPackRare = 1; + private int boosterPackUncommon = 3; + private int boosterPackCommon = 9; + + private int matchRewardBase = 10; + private double matchRewardTotalWins = 0.3; + private int matchRewardNoLosses = 10; + + private int matchRewardPoisonWinBonus = 50; + private int matchRewardMilledWinBonus = 40; + private int matchRewardAltWinBonus = 100; + + private int matchRewardWinOnFirstTurn = 1500; + private int matchRewardWinByTurnFive = 250; + private int matchRewardWinByTurnTen = 50; + private int matchRewardWinByTurnFifteen = 5; + private int matchRewardMullToZero = 500; + + public QuestData_Prefs() + { + // if quest.prefs exists + grabPrefsFromFile(); + } + + public void grabPrefsFromFile(){ + try{ + BufferedReader input = new BufferedReader(new FileReader(ForgeProps.getFile(QUEST.PREFS))); + String line = null; + while((line = input.readLine()) != null){ + if (line.startsWith("#") || line.length() == 0) + continue; + String[] split = line.split("="); + + if (split[0].equals("difficultyString")) + setDifficulty(split[1]); + else if (split[0].equals("winsForBooster")) + setWinsForBooster(split[1]); + else if (split[0].equals("winsForRankIncrease")) + setWinsForRank(split[1]); + else if (split[0].equals("winsForMediumAI")) + setWinsForMediumAI(split[1]); + else if (split[0].equals("winsForHardAI")) + setWinsForHardAI(split[1]); + else if (split[0].equals("startingBasicLand")) + setStartingBasic(split[1]); + else if (split[0].equals("startingSnowBasicLand")) + setStartingSnowBasic(split[1]); + else if (split[0].equals("startingCommons")) + setStartingCommons(split[1]); + else if (split[0].equals("startingUncommons")) + setStartingUncommons(split[1]); + else if (split[0].equals("startingRares")) + setStartingRares(split[1]); + else if (split[0].equals("startingCredits")) + setStartingCredits(split[1]); + else if (split[0].equals("boosterPackCommon")) + setNumCommon(split[1]); + else if (split[0].equals("boosterPackUncommon")) + setNumUncommon(split[1]); + else if (split[0].equals("boosterPackRare")) + setNumRares(split[1]); + else if (split[0].equals("matchRewardBase")) + setMatchRewardBase(split[1]); + else if (split[0].equals("matchRewardTotalWins")) + setMatchRewardTotalWins(split[1]); + else if (split[0].equals("matchRewardNoLosses")) + setMatchRewardNoLosses(split[1]); + else if (split[0].equals("matchRewardMilledWinBonus")) + setMatchRewardMilledWinBonus(split[1]); + else if (split[0].equals("matchRewardPoisonWinBonus")) + setMatchRewardPoisonWinBonus(split[1]); + else if (split[0].equals("matchRewardAltWinBonus")) + setMatchRewardAltWinBonus(split[1]); + else if (split[0].equals("matchRewardWinOnFirstTurn")) + setMatchRewardWinFirst(split[1]); + else if (split[0].equals("matchRewardWinByTurnFive")) + setMatchRewardWinByFifth(split[1]); + else if (split[0].equals("matchRewardWinByTurnTen")) + setMatchRewardWinByTen(split[1]); + else if (split[0].equals("matchRewardWinByTurnFifteen")) + setMatchRewardWinByFifteen(split[1]); + else if (split[0].equals("matchRewardMullToZero")) + setMatchMullToZero(split[1]); + } + } + catch(Exception e) + { + System.out.println("Trouble grabbing quest data preferences. Using default values."); + } + } + + // getters + public String[] getDifficulty(){ + return sDifficulty; + } + + public String getDifficulty(int index){ + return sDifficulty[index]; + } + + public int getWinsForBooster(int index){ + return winsForBooster[index]; + } + + public int getWinsForRankIncrease(int index){ + return winsForRankIncrease[index]; + } + + public int getWinsForMediumAI(int index){ + return winsForMediumAI[index]; + } + + public int getWinsForHardAI(int index){ + return winsForHardAI[index]; + } + + public int getStartingBasic(){ + return startingBasicLand; + } + + public int getStartingSnowBasic(){ + return startingSnowBasicLand; + } + + public int getStartingCommons(int index){ + return startingCommons[index]; + } + + public int getStartingUncommons(int index){ + return startingUncommons[index]; + } + + public int getStartingRares(int index){ + return startingRares[index]; + } + + public int getStartingCredits(){ + return startingCredits; + } + + public int getNumCommon(){ + return boosterPackCommon; + } + + public int getNumUncommon(){ + return boosterPackUncommon; + } + + public int getNumRare(){ + return boosterPackRare; + } + + + public int getMatchRewardBase(){ + return matchRewardBase; + } + + public double getMatchRewardTotalWins(){ + return matchRewardTotalWins; + } + + public int getMatchRewardNoLosses(){ + return matchRewardNoLosses; + } + + public int getMatchRewardPoisonWinBonus(){ + return matchRewardPoisonWinBonus; + } + + public int getMatchRewardMilledWinBonus(){ + return matchRewardMilledWinBonus; + } + + public int getMatchRewardAltWinBonus(){ + return matchRewardAltWinBonus; + } + + + public int getMatchRewardWinFirst(){ + return matchRewardWinOnFirstTurn; + } + + public int getMatchRewardWinByFifth(){ + return matchRewardWinByTurnFive; + } + + public int getMatchRewardWinByTen(){ + return matchRewardWinByTurnTen; + } + + public int getMatchRewardWinByFifteen(){ + return matchRewardWinByTurnFifteen; + } + + public int getMatchMullToZero(){ + return matchRewardMullToZero; + } + + + // setters + public void setDifficulty(String diff){ + this.sDifficulty = diff.split(","); + } + + public void setWinsForBooster(String wins){ + String[] winsStr = wins.split(","); + + for(int i = 0; i < numDiff; i++) + this.winsForBooster[i] = Integer.parseInt(winsStr[i]); + } + + public void setWinsForRank(String wins){ + String[] winsStr = wins.split(","); + + for(int i = 0; i < numDiff; i++) + this.winsForRankIncrease[i] = Integer.parseInt(winsStr[i]); + } + + public void setWinsForMediumAI(String wins){ + String[] winsStr = wins.split(","); + + for(int i = 0; i < numDiff; i++) + this.winsForMediumAI[i] = Integer.parseInt(winsStr[i]); + } + + public void setWinsForHardAI(String wins){ + String[] winsStr = wins.split(","); + + for(int i = 0; i < numDiff; i++) + this.winsForHardAI[i] = Integer.parseInt(winsStr[i]); + } + + public void setStartingBasic(String land){ + this.startingBasicLand = Integer.parseInt(land); + } + + public void setStartingSnowBasic(String land){ + this.startingSnowBasicLand = Integer.parseInt(land); + } + + public void setStartingCommons(String rarity){ + String[] splitStr = rarity.split(","); + + for(int i = 0; i < numDiff; i++) + this.startingCommons[i] = Integer.parseInt(splitStr[i]); + } + + public void setStartingUncommons(String rarity){ + String[] splitStr = rarity.split(","); + + for(int i = 0; i < numDiff; i++) + this.startingUncommons[i] = Integer.parseInt(splitStr[i]); + } + + public void setStartingRares(String rarity){ + String[] splitStr = rarity.split(","); + + for(int i = 0; i < numDiff; i++) + this.startingRares[i] = Integer.parseInt(splitStr[i]); + } + + public void setStartingCredits(String credits){ + this.startingCredits = Integer.parseInt(credits); + } + + public void setNumCommon(String pack){ + this.boosterPackCommon = Integer.parseInt(pack); + } + + public void setNumUncommon(String pack){ + this.boosterPackUncommon = Integer.parseInt(pack); + } + + public void setNumRares(String pack){ + this.boosterPackRare = Integer.parseInt(pack); + } + + + public void setMatchRewardBase(String match){ + this.matchRewardBase = Integer.parseInt(match); + } + + public void setMatchRewardTotalWins(String match){ + this.matchRewardTotalWins = Double.parseDouble(match); + } + + public void setMatchRewardNoLosses(String match){ + this.matchRewardNoLosses = Integer.parseInt(match); + } + + public void setMatchRewardPoisonWinBonus(String match){ + this.matchRewardPoisonWinBonus = Integer.parseInt(match); + } + + public void setMatchRewardMilledWinBonus(String match){ + this.matchRewardMilledWinBonus = Integer.parseInt(match); + } + + public void setMatchRewardAltWinBonus(String match){ + this.matchRewardAltWinBonus = Integer.parseInt(match); + } + + + public void setMatchRewardWinFirst(String match){ + this.matchRewardWinOnFirstTurn = Integer.parseInt(match); + } + + public void setMatchRewardWinByFifth(String match){ + this.matchRewardWinByTurnFive = Integer.parseInt(match); + } + + public void setMatchRewardWinByTen(String match){ + this.matchRewardWinByTurnTen = Integer.parseInt(match); + } + + public void setMatchRewardWinByFifteen(String match){ + this.matchRewardWinByTurnFifteen = Integer.parseInt(match); + } + + public void setMatchMullToZero(String match){ + this.matchRewardMullToZero = Integer.parseInt(match); + } +} diff --git a/src/forge/QuestData_State.java b/src/forge/QuestData_State.java index b2102a09fc1..adb2e8f1cef 100644 --- a/src/forge/QuestData_State.java +++ b/src/forge/QuestData_State.java @@ -20,6 +20,9 @@ import java.util.Map; * @version V0.0 26.10.2009 * @author Clemens Koza */ + + +@Deprecated public class QuestData_State implements Serializable { private static final long serialVersionUID = 7007940230351051937L; diff --git a/src/forge/QuestUtil.java b/src/forge/QuestUtil.java index 6cf362b2427..d5071142fc1 100644 --- a/src/forge/QuestUtil.java +++ b/src/forge/QuestUtil.java @@ -1,892 +1,894 @@ -package forge; - -import java.util.ArrayList; - -public class QuestUtil { - - public static int getLife(QuestData qd) - { - return qd.getLife(); - } - - public static CardList getComputerCreatures(QuestData qd) - { - return new CardList(); - } - - public static CardList getComputerCreatures(QuestData qd, Quest_Assignment qa) - { - CardList list = new CardList(); - if (qa!=null) - { - ArrayList compCards = qa.getCompy(); - - for (String s:compCards) - { - Card c = AllZone.CardFactory.getCard(s, AllZone.ComputerPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - list.add(c); - } - } - return list; - } - - public static CardList getHumanPlantAndPet(QuestData qd) - { - CardList list = new CardList(); - - if (qd.getSelectedPet() != null) - { - if (qd.getSelectedPet().equals("No Plant/Pet")) - return list; - - if (qd.getSelectedPet().equals("Wolf") && qd.getWolfPetLevel() > 0) - list.add(getWolfPetToken(qd.getWolfPetLevel())); - else if (qd.getSelectedPet().equals("Croc") && qd.getCrocPetLevel() > 0) - list.add(getCrocPetToken(qd.getCrocPetLevel())); - else if (qd.getSelectedPet().equals("Bird") && qd.getBirdPetLevel() > 0) - list.add(getBirdPetToken(qd.getBirdPetLevel())); - else if (qd.getSelectedPet().equals("Hound") && qd.getHoundPetLevel() > 0) - list.add(getHoundPetToken(qd.getHoundPetLevel())); - } - - if (qd.getPlantLevel() > 0) - list.add(getPlantToken(qd.getPlantLevel())); - - return list; - } - - public static CardList getHumanPlantAndPet(QuestData qd, Quest_Assignment qa) - { - CardList list = getHumanPlantAndPet(qd); - - if (qa!=null) - list.addAll(qa.getHuman().toArray()); - - return list; - } - - //makeToken(String name, String imageName, Card source, String manaCost, String[] types, int baseAttack, int baseDefense, String[] intrinsicKeywords) { - - public static Card getPlantToken(int level) - { - String imageName = ""; - int baseAttack = 0; - int baseDefense = 0; - - String keyword = ""; - - if (level == 1) - { - imageName = "G 0 1 Plant Wall"; - baseDefense = 1; - } - else if (level == 2) - { - imageName = "G 0 2 Plant Wall"; - baseDefense = 2; - } - else if (level == 3) - { - imageName = "G 0 3 Plant Wall"; - baseDefense = 3; - } - else if (level == 4) - { - imageName = "G 1 3 Plant Wall"; - baseDefense = 3; - baseAttack = 1; - } - else if (level == 5) - { - imageName = "G 1 3 Plant Wall Deathtouch"; - baseDefense = 3; - baseAttack = 1; - keyword = "Deathtouch"; - } - - else if (level == 6) - { - imageName = "G 1 4 Plant Wall"; - baseDefense = 4; - baseAttack = 1; - keyword = "Deathtouch"; - } - - - - Card c = new Card(); - c.setName("Plant Wall"); - - c.setImageName(imageName); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("G"); - c.addColor("G"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Plant"); - c.addType("Wall"); - - c.addIntrinsicKeyword("Defender"); - if (!keyword.equals("")) - c.addIntrinsicKeyword("Deathtouch"); - - c.setBaseAttack(baseAttack); - c.setBaseDefense(baseDefense); - - if (level == 6) - { - final Card crd = c; - Ability_Cost abCost = new Ability_Cost("T", crd.getName(), true); - final SpellAbility ability = new Ability_Activated(crd, abCost, null){ - private static final long serialVersionUID = 7546242087593613719L; - - @Override - public boolean canPlayAI() { - return AllZone.Phase.getPhase().equals(Constant.Phase.Main2); - } - - @Override - public void resolve() { - crd.getController().gainLife(1, crd); - } - }; - c.addSpellAbility(ability); - ability.setDescription("tap: You gain 1 life."); - - StringBuilder sb = new StringBuilder(); - sb.append("Plant Wall - ").append(c.getController()).append(" gains 1 life."); - ability.setStackDescription(sb.toString()); - - c.setText("tap: You gain 1 life."); - } - - - return c; - }//getPlantToken - - public static Card getWolfPetToken(int level) - { - String imageName = ""; - int baseAttack = 0; - int baseDefense = 0; - - if (level == 1) - { - imageName = "G 1 1 Wolf Pet"; - baseDefense = 1; - baseAttack = 1; - } - else if (level == 2) - { - imageName = "G 1 2 Wolf Pet"; - baseDefense = 2; - baseAttack = 1; - } - else if (level == 3) - { - imageName = "G 2 2 Wolf Pet"; - baseDefense = 2; - baseAttack = 2; - } - else if (level == 4) - { - imageName = "G 2 2 Wolf Pet Flanking"; - baseDefense = 2; - baseAttack = 2; - } - - - Card c = new Card(); - c.setName("Wolf Pet"); - - c.setImageName(imageName); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("G"); - c.addColor("G"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Wolf"); - c.addType("Pet"); - - if (level >= 4) - c.addIntrinsicKeyword("Flanking"); - - c.setBaseAttack(baseAttack); - c.setBaseDefense(baseDefense); - - return c; - }//getWolfPetToken - - public static Card getCrocPetToken(int level) - { - String imageName = ""; - int baseAttack = 0; - int baseDefense = 0; - - if (level == 1) - { - imageName = "B 1 1 Crocodile Pet"; - baseDefense = 1; - baseAttack = 1; - } - else if (level == 2) - { - imageName = "B 2 1 Crocodile Pet"; - baseDefense = 1; - baseAttack = 2; - } - else if (level == 3) - { - imageName = "B 3 1 Crocodile Pet"; - baseDefense = 1; - baseAttack = 3; - } - else if (level == 4) - { - imageName = "B 3 1 Crocodile Pet Swampwalk"; - baseDefense = 1; - baseAttack = 3; - } - - - Card c = new Card(); - c.setName("Crocodile Pet"); - - c.setImageName(imageName); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("B"); - c.addColor("B"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Crocodile"); - c.addType("Pet"); - - if (level >= 4) - c.addIntrinsicKeyword("Swampwalk"); - - c.setBaseAttack(baseAttack); - c.setBaseDefense(baseDefense); - - return c; - }//getCrocPetToken - - public static Card getBirdPetToken(int level) - { - String imageName = ""; - int baseAttack = 0; - int baseDefense = 0; - - if (level == 1) - { - imageName = "W 0 1 Bird Pet"; - baseDefense = 1; - baseAttack = 0; - } - else if (level == 2) - { - imageName = "W 1 1 Bird Pet"; - baseDefense = 1; - baseAttack = 1; - } - else if (level == 3) - { - imageName = "W 2 1 Bird Pet"; - baseDefense = 1; - baseAttack = 2; - } - else if (level == 4) - { - imageName = "W 2 1 Bird Pet First Strike"; - baseDefense = 1; - baseAttack = 2; - } - - - Card c = new Card(); - c.setName("Bird Pet"); - - c.setImageName(imageName); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("W"); - c.addColor("W"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Bird"); - c.addType("Pet"); - - c.addIntrinsicKeyword("Flying"); - - if (level >= 4) - c.addIntrinsicKeyword("First Strike"); - - c.setBaseAttack(baseAttack); - c.setBaseDefense(baseDefense); - - return c; - } - - public static Card getHoundPetToken(int level) - { - String imageName = ""; - int baseAttack = 0; - int baseDefense = 0; - - if (level == 1) - { - imageName = "R 1 1 Hound Pet"; - baseDefense = 1; - baseAttack = 0; - } - else if (level == 2) - { - imageName = "R 1 1 Hound Pet Haste"; - baseDefense = 1; - baseAttack = 1; - } - else if (level == 3) - { - imageName = "R 2 1 Hound Pet"; - baseDefense = 1; - baseAttack = 2; - } - else if (level == 4) - { - imageName = "R 2 1 Hound Pet Alone"; - baseDefense = 1; - baseAttack = 2; - } - - - Card c = new Card(); - c.setName("Hound Pet"); - - c.setImageName(imageName); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("R"); - c.addColor("R"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Hound"); - c.addType("Pet"); - - if (level >= 2) - c.addIntrinsicKeyword("Haste"); - - if (level >= 4) - c.addIntrinsicKeyword("Whenever this creature attacks alone, it gets +2/+0 until end of turn."); - - c.setBaseAttack(baseAttack); - c.setBaseDefense(baseDefense); - - return c; - } - - public static ArrayList getPetNames(QuestData questData) - { - ArrayList list = new ArrayList(); - if (questData.getWolfPetLevel() > 0) - list.add("Wolf"); - if (questData.getCrocPetLevel() > 0) - list.add("Croc"); - if (questData.getBirdPetLevel() > 0) - list.add("Bird"); - if (questData.getHoundPetLevel() > 0) - list.add("Hound"); - - return list; - } - - public static void setupQuest(Quest_Assignment qa) - { - /* - * Gold = 0 - * Colorless = 1 - * Black = 2 - * Blue = 3 - * Green = 4 - * Red = 5 - * White = 6 - */ - - QuestData_BoosterPack pack = new QuestData_BoosterPack(); - qa.clearCompy(); - - int id = qa.getId(); - - if (id == 1) //White Dungeon - { - CardList humanList = new CardList(); - Card c = AllZone.CardFactory.getCard("Adventuring Gear", AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - - qa.setHuman(humanList); - - for (int i=0;i<2;i++) - qa.addCompy("Savannah Lions"); - - qa.setCardRewardList(pack.getRare(3, 6)); - } - - else if (id == 2) //Blue Dungeon - { - for (int i=0;i<3;i++) - qa.addCompy("Merfolk of the Pearl Trident"); - - qa.setCardRewardList(pack.getRare(3, 3)); - } - - else if (id == 3) //Black Dungeon - { - qa.setCardRewardList(pack.getRare(3, 2)); - } - - else if (id == 4) //Red Dungeon - { - for (int i=0;i<3;i++) - qa.addCompy("Mons's Goblin Raiders"); - - qa.setCardRewardList(pack.getRare(3, 5)); - } - - else if (id == 5) //Green Dungeon - { - qa.setCardRewardList(pack.getRare(3, 4)); - } - - else if (id == 6) //Colorless Dungeon - { - for (int i=0;i<2;i++) - qa.addCompy("Ornithopter"); - qa.setCardRewardList(pack.getRare(3, 1)); - } - - else if (id == 7) //Gold Dungeon - { - CardList humanList = new CardList(); - Card c = AllZone.CardFactory.getCard("Trailblazer's Boots", AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - - qa.setHuman(humanList); - qa.setCardRewardList(pack.getRare(3, 0)); - } - - else if (id == 8) - { - CardList humanList = new CardList(); - for (int i=0;i<3;i++) - { - //CANNOT use makeToken because of WheneverKeyword - Card c = new Card(); - c.setName("Sheep"); - c.setImageName("G 0 1 Sheep"); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("G"); - c.addColor("G"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Sheep"); - - c.setBaseAttack(0); - c.setBaseDefense(1); - - humanList.add(c); - } - qa.setHuman(humanList); - qa.setCardRewardList(pack.getRare(3)); - } - - else if (id == 9) - { - CardList humanList = new CardList(); - Card c = AllZone.CardFactory.getCard("Trusty Machete", AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - - qa.setHuman(humanList); - - for (int i=0;i<3;i++) - qa.addCompy("Wall of Wood"); - - qa.setCardRewardList(pack.getRare(4, 4)); - } - - else if (id == 10) - { - CardList humanList = new CardList(); - - Card crd = AllZone.CardFactory.getCard("Wall of Spears", AllZone.HumanPlayer); - - crd.setCurSetCode(crd.getMostRecentSet()); - crd.setImageFilename(CardUtil.buildFilename(crd)); - - humanList.add(crd); - - for (int i=0;i<3;i++) - { - Card c = new Card(); - c.setName("Citizen"); - c.setImageName("W 1 1 Citizen"); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - c.setManaCost("W"); - c.addColor("W"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Citizen"); - - c.setBaseAttack(1); - c.setBaseDefense(1); - - humanList.add(c); - } - - qa.setHuman(humanList); - - for (int i=0;i<3;i++) - qa.addCompy("Scathe Zombies"); - qa.addCompy("Mass of Ghouls"); - - qa.setCardRewardList(pack.getRare(4, 2)); - } - - else if (id == 11) // The King's Contest - { - CardList humanList = new CardList(); - Card c = AllZone.CardFactory.getCard("Seal of Cleansing", AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - - qa.setHuman(humanList); - - qa.addCompy("Loyal Retainers"); - - qa.setCardRewardList(pack.getRare(3)); - } - - else if (id == 12) // Barroom Brawl - { - CardList humanList = new CardList(); - for (int i = 0; i < 3; i ++) - { - Card c = new Card(); - c.setName("Soldier Ally"); - c.setImageName("W 1 1 Soldier Ally"); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - c.setManaCost("W"); - c.addColor("W"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Soldier"); - c.addType("Ally"); - - c.setBaseAttack(1); - c.setBaseDefense(1); - - - humanList.add(c); - } - qa.setHuman(humanList); - - - qa.addCompy("Lowland Giant"); - - qa.setCardRewardList(pack.getRare(4)); - } - - else if (id == 13) // The Court Jester - { - CardList humanList = new CardList(); - Card c = AllZone.CardFactory.getCard("Sensei's Divining Top", AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - - qa.setHuman(humanList); - - qa.addCompy("Teferi's Puzzle Box"); - - qa.setCardRewardList(pack.getRare(4, 0)); - } - - else if (id == 14) // Ancient Battlefield - { - CardList humanList = new CardList(); - String humanSetupCards[] = {"Glasses of Urza", "Blight Sickle"}; - - for (int i = 0; i < 2; i ++) - { - Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - } - qa.setHuman(humanList); - - String compySetupCards[] = {"Bad Moon", "Wall of Brambles"}; - - for (int i = 0; i < 2; i ++) - { - qa.addCompy(compySetupCards[i]); - } - - qa.setCardRewardList(pack.getRare(4)); - } - - else if (id == 15) // Don't Play With Matches - { - CardList humanList = new CardList(); - String humanSetupCards[] = {"Mudbutton Torchrunner", "Scuzzback Scrapper"}; - - for (int i = 0; i < 2; i ++) - { - Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - } - qa.setHuman(humanList); - - String compySetupCards[] = {"Heedless One", "Norwood Archers", "Wildslayer Elves"}; - - for (int i = 0; i < 3; i ++) - { - qa.addCompy(compySetupCards[i]); - } - - qa.setCardRewardList(pack.getRare(4, 5)); - } - - else if (id == 16) // Mines of Kazum Durl - { - CardList humanList = new CardList(); - String humanSetupCards[] = {"Dwarven Demolition Team", "Dwarven Pony", "Dwarven Trader"}; - - for (int i = 0; i < 3; i ++) - { - Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - } - qa.setHuman(humanList); - - String compySetupCards[] = - {"Wall of Earth", "Wall of Air", "Wall of Ice", "Wall of Light", "Carrion Wall" ,"Steel Wall"}; - - for (int i = 0; i < 6; i ++) - { - qa.addCompy(compySetupCards[i]); - } - - qa.setCardRewardList(pack.getRare(4, 4)); - } - - else if (id == 17) // House Party - { - CardList humanList = new CardList(); - String humanSetupCards[] = {"Hopping Automaton", "Honden of Life's Web", "Forbidden Orchard"}; - - for (int i = 0; i < 3; i ++) - { - Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - } - qa.setHuman(humanList); - - String compySetupCards[] = {"Honden of Infinite Rage", "Mikokoro, Center of the Sea", "Tidehollow Strix"}; - - for (int i = 0; i < 3; i ++) - { - qa.addCompy(compySetupCards[i]); - } - - qa.setCardRewardList(pack.getRare(4, 1)); - } - - else if (id == 18) // Crows in the Field - { - CardList humanList = new CardList(); - String humanSetupCards[] = {"Straw Soldiers", "Femeref Archers", "Moonglove Extract"}; - - for (int i = 0; i < 3; i ++) - { - Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - } - qa.setHuman(humanList); - - String compySetupCards[] = {"Defiant Falcon", "Soulcatcher", "Storm Crow", "Hypnotic Specter"}; - - for (int i = 0; i < 4; i ++) - { - qa.addCompy(compySetupCards[i]); - } - - qa.setCardRewardList(pack.getRare(5)); - } - - else if (id == 19) // The Desert Caravan - { - CardList humanList = new CardList(); - String humanSetupCards[] = {"Spidersilk Net", "Dromad Purebred"}; - - for (int i = 0; i < 2; i ++) - { - Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - } - qa.setHuman(humanList); - - String compySetupCards[] = {"Ambush Party", "Ambush Party", "Gnat Alley Creeper", "Ambush Party", "Ambush Party"}; - - for (int i = 0; i < 5; i ++) - { - qa.addCompy(compySetupCards[i]); - } - - qa.setCardRewardList(pack.getRare(5)); - } - - else if (id == 20) // Blood Oath - { - CardList humanList = new CardList(); - String humanSetupCards[] = {"Counterbalance", "Hatching Plans", "Ley Druid"}; - - for (int i = 0; i < 3; i ++) - { - Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - } - qa.setHuman(humanList); - - String compySetupCards[] = {"Ior Ruin Expedition", "Oversold Cemetery", "Trapjaw Kelpie"}; - - for (int i = 0; i < 3; i ++) - { - qa.addCompy(compySetupCards[i]); - } - - qa.setCardRewardList(pack.getRare(5, 1)); - } - - else if (id == 21) // Private Domain - { - CardList humanList = new CardList(); - - Card c = AllZone.CardFactory.getCard("Strip Mine", AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - - qa.setHuman(humanList); - - String compySetupCards[] = {"Plains", "Island", "Swamp", "Mountain", "Forest"}; - - for (int i = 0; i < 5; i ++) - qa.addCompy(compySetupCards[i]); - - qa.setCardRewardList(pack.getRare(6)); - } - - else if (id == 22) // Pied Piper - { - CardList humanList = new CardList(); - String humanSetupCards[] = {"Volunteer Militia", "Land Tax", "Elvish Farmer", "An-Havva Township"}; - - for (int i = 0; i < 4; i ++) - { - Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); - - c.setCurSetCode(c.getMostRecentSet()); - c.setImageFilename(CardUtil.buildFilename(c)); - - humanList.add(c); - } - qa.setHuman(humanList); - - String compySetupCards[] = {"Darksteel Citadel", "Relentless Rats"}; - - for (int i = 0; i < 2; i ++) - qa.addCompy(compySetupCards[i]); - - qa.setCardRewardList(pack.getRare(3)); - } - - } - -}//QuestUtil +package forge; + +import java.util.ArrayList; + +@Deprecated +@SuppressWarnings("deprecation") +public class QuestUtil { + + public static int getLife(QuestData qd) + { + return qd.getLife(); + } + + public static CardList getComputerCreatures(QuestData qd) + { + return new CardList(); + } + + public static CardList getComputerCreatures(QuestData qd, Quest_Assignment qa) + { + CardList list = new CardList(); + if (qa!=null) + { + ArrayList compCards = qa.getCompy(); + + for (String s:compCards) + { + Card c = AllZone.CardFactory.getCard(s, AllZone.ComputerPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + list.add(c); + } + } + return list; + } + + public static CardList getHumanPlantAndPet(QuestData qd) + { + CardList list = new CardList(); + + if (qd.getSelectedPet() != null) + { + if (qd.getSelectedPet().equals("No Plant/Pet")) + return list; + + if (qd.getSelectedPet().equals("Wolf") && qd.getWolfPetLevel() > 0) + list.add(getWolfPetToken(qd.getWolfPetLevel())); + else if (qd.getSelectedPet().equals("Croc") && qd.getCrocPetLevel() > 0) + list.add(getCrocPetToken(qd.getCrocPetLevel())); + else if (qd.getSelectedPet().equals("Bird") && qd.getBirdPetLevel() > 0) + list.add(getBirdPetToken(qd.getBirdPetLevel())); + else if (qd.getSelectedPet().equals("Hound") && qd.getHoundPetLevel() > 0) + list.add(getHoundPetToken(qd.getHoundPetLevel())); + } + + if (qd.getPlantLevel() > 0) + list.add(getPlantToken(qd.getPlantLevel())); + + return list; + } + + public static CardList getHumanPlantAndPet(QuestData qd, Quest_Assignment qa) + { + CardList list = getHumanPlantAndPet(qd); + + if (qa!=null) + list.addAll(qa.getHuman().toArray()); + + return list; + } + + //makeToken(String name, String imageName, Card source, String manaCost, String[] types, int baseAttack, int baseDefense, String[] intrinsicKeywords) { + + public static Card getPlantToken(int level) + { + String imageName = ""; + int baseAttack = 0; + int baseDefense = 0; + + String keyword = ""; + + if (level == 1) + { + imageName = "G 0 1 Plant Wall"; + baseDefense = 1; + } + else if (level == 2) + { + imageName = "G 0 2 Plant Wall"; + baseDefense = 2; + } + else if (level == 3) + { + imageName = "G 0 3 Plant Wall"; + baseDefense = 3; + } + else if (level == 4) + { + imageName = "G 1 3 Plant Wall"; + baseDefense = 3; + baseAttack = 1; + } + else if (level == 5) + { + imageName = "G 1 3 Plant Wall Deathtouch"; + baseDefense = 3; + baseAttack = 1; + keyword = "Deathtouch"; + } + + else if (level == 6) + { + imageName = "G 1 4 Plant Wall"; + baseDefense = 4; + baseAttack = 1; + keyword = "Deathtouch"; + } + + + + Card c = new Card(); + c.setName("Plant Wall"); + + c.setImageName(imageName); + + c.setController(AllZone.HumanPlayer); + c.setOwner(AllZone.HumanPlayer); + + //c.setManaCost("G"); + c.addColor("G"); + c.setToken(true); + + c.addType("Creature"); + c.addType("Plant"); + c.addType("Wall"); + + c.addIntrinsicKeyword("Defender"); + if (!keyword.equals("")) + c.addIntrinsicKeyword("Deathtouch"); + + c.setBaseAttack(baseAttack); + c.setBaseDefense(baseDefense); + + if (level == 6) + { + final Card crd = c; + Ability_Cost abCost = new Ability_Cost("T", crd.getName(), true); + final SpellAbility ability = new Ability_Activated(crd, abCost, null){ + private static final long serialVersionUID = 7546242087593613719L; + + @Override + public boolean canPlayAI() { + return AllZone.Phase.getPhase().equals(Constant.Phase.Main2); + } + + @Override + public void resolve() { + crd.getController().gainLife(1, crd); + } + }; + c.addSpellAbility(ability); + ability.setDescription("tap: You gain 1 life."); + + StringBuilder sb = new StringBuilder(); + sb.append("Plant Wall - ").append(c.getController()).append(" gains 1 life."); + ability.setStackDescription(sb.toString()); + + c.setText("tap: You gain 1 life."); + } + + + return c; + }//getPlantToken + + public static Card getWolfPetToken(int level) + { + String imageName = ""; + int baseAttack = 0; + int baseDefense = 0; + + if (level == 1) + { + imageName = "G 1 1 Wolf Pet"; + baseDefense = 1; + baseAttack = 1; + } + else if (level == 2) + { + imageName = "G 1 2 Wolf Pet"; + baseDefense = 2; + baseAttack = 1; + } + else if (level == 3) + { + imageName = "G 2 2 Wolf Pet"; + baseDefense = 2; + baseAttack = 2; + } + else if (level == 4) + { + imageName = "G 2 2 Wolf Pet Flanking"; + baseDefense = 2; + baseAttack = 2; + } + + + Card c = new Card(); + c.setName("Wolf Pet"); + + c.setImageName(imageName); + + c.setController(AllZone.HumanPlayer); + c.setOwner(AllZone.HumanPlayer); + + //c.setManaCost("G"); + c.addColor("G"); + c.setToken(true); + + c.addType("Creature"); + c.addType("Wolf"); + c.addType("Pet"); + + if (level >= 4) + c.addIntrinsicKeyword("Flanking"); + + c.setBaseAttack(baseAttack); + c.setBaseDefense(baseDefense); + + return c; + }//getWolfPetToken + + public static Card getCrocPetToken(int level) + { + String imageName = ""; + int baseAttack = 0; + int baseDefense = 0; + + if (level == 1) + { + imageName = "B 1 1 Crocodile Pet"; + baseDefense = 1; + baseAttack = 1; + } + else if (level == 2) + { + imageName = "B 2 1 Crocodile Pet"; + baseDefense = 1; + baseAttack = 2; + } + else if (level == 3) + { + imageName = "B 3 1 Crocodile Pet"; + baseDefense = 1; + baseAttack = 3; + } + else if (level == 4) + { + imageName = "B 3 1 Crocodile Pet Swampwalk"; + baseDefense = 1; + baseAttack = 3; + } + + + Card c = new Card(); + c.setName("Crocodile Pet"); + + c.setImageName(imageName); + + c.setController(AllZone.HumanPlayer); + c.setOwner(AllZone.HumanPlayer); + + //c.setManaCost("B"); + c.addColor("B"); + c.setToken(true); + + c.addType("Creature"); + c.addType("Crocodile"); + c.addType("Pet"); + + if (level >= 4) + c.addIntrinsicKeyword("Swampwalk"); + + c.setBaseAttack(baseAttack); + c.setBaseDefense(baseDefense); + + return c; + }//getCrocPetToken + + public static Card getBirdPetToken(int level) + { + String imageName = ""; + int baseAttack = 0; + int baseDefense = 0; + + if (level == 1) + { + imageName = "W 0 1 Bird Pet"; + baseDefense = 1; + baseAttack = 0; + } + else if (level == 2) + { + imageName = "W 1 1 Bird Pet"; + baseDefense = 1; + baseAttack = 1; + } + else if (level == 3) + { + imageName = "W 2 1 Bird Pet"; + baseDefense = 1; + baseAttack = 2; + } + else if (level == 4) + { + imageName = "W 2 1 Bird Pet First Strike"; + baseDefense = 1; + baseAttack = 2; + } + + + Card c = new Card(); + c.setName("Bird Pet"); + + c.setImageName(imageName); + + c.setController(AllZone.HumanPlayer); + c.setOwner(AllZone.HumanPlayer); + + //c.setManaCost("W"); + c.addColor("W"); + c.setToken(true); + + c.addType("Creature"); + c.addType("Bird"); + c.addType("Pet"); + + c.addIntrinsicKeyword("Flying"); + + if (level >= 4) + c.addIntrinsicKeyword("First Strike"); + + c.setBaseAttack(baseAttack); + c.setBaseDefense(baseDefense); + + return c; + } + + public static Card getHoundPetToken(int level) + { + String imageName = ""; + int baseAttack = 0; + int baseDefense = 0; + + if (level == 1) + { + imageName = "R 1 1 Hound Pet"; + baseDefense = 1; + baseAttack = 0; + } + else if (level == 2) + { + imageName = "R 1 1 Hound Pet Haste"; + baseDefense = 1; + baseAttack = 1; + } + else if (level == 3) + { + imageName = "R 2 1 Hound Pet"; + baseDefense = 1; + baseAttack = 2; + } + else if (level == 4) + { + imageName = "R 2 1 Hound Pet Alone"; + baseDefense = 1; + baseAttack = 2; + } + + + Card c = new Card(); + c.setName("Hound Pet"); + + c.setImageName(imageName); + + c.setController(AllZone.HumanPlayer); + c.setOwner(AllZone.HumanPlayer); + + //c.setManaCost("R"); + c.addColor("R"); + c.setToken(true); + + c.addType("Creature"); + c.addType("Hound"); + c.addType("Pet"); + + if (level >= 2) + c.addIntrinsicKeyword("Haste"); + + if (level >= 4) + c.addIntrinsicKeyword("Whenever this creature attacks alone, it gets +2/+0 until end of turn."); + + c.setBaseAttack(baseAttack); + c.setBaseDefense(baseDefense); + + return c; + } + + public static ArrayList getPetNames(QuestData questData) + { + ArrayList list = new ArrayList(); + if (questData.getWolfPetLevel() > 0) + list.add("Wolf"); + if (questData.getCrocPetLevel() > 0) + list.add("Croc"); + if (questData.getBirdPetLevel() > 0) + list.add("Bird"); + if (questData.getHoundPetLevel() > 0) + list.add("Hound"); + + return list; + } + + public static void setupQuest(Quest_Assignment qa) + { + /* + * Gold = 0 + * Colorless = 1 + * Black = 2 + * Blue = 3 + * Green = 4 + * Red = 5 + * White = 6 + */ + + QuestData_BoosterPack pack = new QuestData_BoosterPack(); + qa.clearCompy(); + + int id = qa.getId(); + + if (id == 1) //White Dungeon + { + CardList humanList = new CardList(); + Card c = AllZone.CardFactory.getCard("Adventuring Gear", AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + + qa.setHuman(humanList); + + for (int i=0;i<2;i++) + qa.addCompy("Savannah Lions"); + + qa.setCardRewardList(pack.getRare(3, 6)); + } + + else if (id == 2) //Blue Dungeon + { + for (int i=0;i<3;i++) + qa.addCompy("Merfolk of the Pearl Trident"); + + qa.setCardRewardList(pack.getRare(3, 3)); + } + + else if (id == 3) //Black Dungeon + { + qa.setCardRewardList(pack.getRare(3, 2)); + } + + else if (id == 4) //Red Dungeon + { + for (int i=0;i<3;i++) + qa.addCompy("Mons's Goblin Raiders"); + + qa.setCardRewardList(pack.getRare(3, 5)); + } + + else if (id == 5) //Green Dungeon + { + qa.setCardRewardList(pack.getRare(3, 4)); + } + + else if (id == 6) //Colorless Dungeon + { + for (int i=0;i<2;i++) + qa.addCompy("Ornithopter"); + qa.setCardRewardList(pack.getRare(3, 1)); + } + + else if (id == 7) //Gold Dungeon + { + CardList humanList = new CardList(); + Card c = AllZone.CardFactory.getCard("Trailblazer's Boots", AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + + qa.setHuman(humanList); + qa.setCardRewardList(pack.getRare(3, 0)); + } + + else if (id == 8) + { + CardList humanList = new CardList(); + for (int i=0;i<3;i++) + { + //CANNOT use makeToken because of WheneverKeyword + Card c = new Card(); + c.setName("Sheep"); + c.setImageName("G 0 1 Sheep"); + + c.setController(AllZone.HumanPlayer); + c.setOwner(AllZone.HumanPlayer); + + //c.setManaCost("G"); + c.addColor("G"); + c.setToken(true); + + c.addType("Creature"); + c.addType("Sheep"); + + c.setBaseAttack(0); + c.setBaseDefense(1); + + humanList.add(c); + } + qa.setHuman(humanList); + qa.setCardRewardList(pack.getRare(3)); + } + + else if (id == 9) + { + CardList humanList = new CardList(); + Card c = AllZone.CardFactory.getCard("Trusty Machete", AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + + qa.setHuman(humanList); + + for (int i=0;i<3;i++) + qa.addCompy("Wall of Wood"); + + qa.setCardRewardList(pack.getRare(4, 4)); + } + + else if (id == 10) + { + CardList humanList = new CardList(); + + Card crd = AllZone.CardFactory.getCard("Wall of Spears", AllZone.HumanPlayer); + + crd.setCurSetCode(crd.getMostRecentSet()); + crd.setImageFilename(CardUtil.buildFilename(crd)); + + humanList.add(crd); + + for (int i=0;i<3;i++) + { + Card c = new Card(); + c.setName("Citizen"); + c.setImageName("W 1 1 Citizen"); + + c.setController(AllZone.HumanPlayer); + c.setOwner(AllZone.HumanPlayer); + + c.setManaCost("W"); + c.addColor("W"); + c.setToken(true); + + c.addType("Creature"); + c.addType("Citizen"); + + c.setBaseAttack(1); + c.setBaseDefense(1); + + humanList.add(c); + } + + qa.setHuman(humanList); + + for (int i=0;i<3;i++) + qa.addCompy("Scathe Zombies"); + qa.addCompy("Mass of Ghouls"); + + qa.setCardRewardList(pack.getRare(4, 2)); + } + + else if (id == 11) // The King's Contest + { + CardList humanList = new CardList(); + Card c = AllZone.CardFactory.getCard("Seal of Cleansing", AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + + qa.setHuman(humanList); + + qa.addCompy("Loyal Retainers"); + + qa.setCardRewardList(pack.getRare(3)); + } + + else if (id == 12) // Barroom Brawl + { + CardList humanList = new CardList(); + for (int i = 0; i < 3; i ++) + { + Card c = new Card(); + c.setName("Soldier Ally"); + c.setImageName("W 1 1 Soldier Ally"); + + c.setController(AllZone.HumanPlayer); + c.setOwner(AllZone.HumanPlayer); + + c.setManaCost("W"); + c.addColor("W"); + c.setToken(true); + + c.addType("Creature"); + c.addType("Soldier"); + c.addType("Ally"); + + c.setBaseAttack(1); + c.setBaseDefense(1); + + + humanList.add(c); + } + qa.setHuman(humanList); + + + qa.addCompy("Lowland Giant"); + + qa.setCardRewardList(pack.getRare(4)); + } + + else if (id == 13) // The Court Jester + { + CardList humanList = new CardList(); + Card c = AllZone.CardFactory.getCard("Sensei's Divining Top", AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + + qa.setHuman(humanList); + + qa.addCompy("Teferi's Puzzle Box"); + + qa.setCardRewardList(pack.getRare(4, 0)); + } + + else if (id == 14) // Ancient Battlefield + { + CardList humanList = new CardList(); + String humanSetupCards[] = {"Glasses of Urza", "Blight Sickle"}; + + for (int i = 0; i < 2; i ++) + { + Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + } + qa.setHuman(humanList); + + String compySetupCards[] = {"Bad Moon", "Wall of Brambles"}; + + for (int i = 0; i < 2; i ++) + { + qa.addCompy(compySetupCards[i]); + } + + qa.setCardRewardList(pack.getRare(4)); + } + + else if (id == 15) // Don't Play With Matches + { + CardList humanList = new CardList(); + String humanSetupCards[] = {"Mudbutton Torchrunner", "Scuzzback Scrapper"}; + + for (int i = 0; i < 2; i ++) + { + Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + } + qa.setHuman(humanList); + + String compySetupCards[] = {"Heedless One", "Norwood Archers", "Wildslayer Elves"}; + + for (int i = 0; i < 3; i ++) + { + qa.addCompy(compySetupCards[i]); + } + + qa.setCardRewardList(pack.getRare(4, 5)); + } + + else if (id == 16) // Mines of Kazum Durl + { + CardList humanList = new CardList(); + String humanSetupCards[] = {"Dwarven Demolition Team", "Dwarven Pony", "Dwarven Trader"}; + + for (int i = 0; i < 3; i ++) + { + Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + } + qa.setHuman(humanList); + + String compySetupCards[] = + {"Wall of Earth", "Wall of Air", "Wall of Ice", "Wall of Light", "Carrion Wall" ,"Steel Wall"}; + + for (int i = 0; i < 6; i ++) + { + qa.addCompy(compySetupCards[i]); + } + + qa.setCardRewardList(pack.getRare(4, 4)); + } + + else if (id == 17) // House Party + { + CardList humanList = new CardList(); + String humanSetupCards[] = {"Hopping Automaton", "Honden of Life's Web", "Forbidden Orchard"}; + + for (int i = 0; i < 3; i ++) + { + Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + } + qa.setHuman(humanList); + + String compySetupCards[] = {"Honden of Infinite Rage", "Mikokoro, Center of the Sea", "Tidehollow Strix"}; + + for (int i = 0; i < 3; i ++) + { + qa.addCompy(compySetupCards[i]); + } + + qa.setCardRewardList(pack.getRare(4, 1)); + } + + else if (id == 18) // Crows in the Field + { + CardList humanList = new CardList(); + String humanSetupCards[] = {"Straw Soldiers", "Femeref Archers", "Moonglove Extract"}; + + for (int i = 0; i < 3; i ++) + { + Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + } + qa.setHuman(humanList); + + String compySetupCards[] = {"Defiant Falcon", "Soulcatcher", "Storm Crow", "Hypnotic Specter"}; + + for (int i = 0; i < 4; i ++) + { + qa.addCompy(compySetupCards[i]); + } + + qa.setCardRewardList(pack.getRare(5)); + } + + else if (id == 19) // The Desert Caravan + { + CardList humanList = new CardList(); + String humanSetupCards[] = {"Spidersilk Net", "Dromad Purebred"}; + + for (int i = 0; i < 2; i ++) + { + Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + } + qa.setHuman(humanList); + + String compySetupCards[] = {"Ambush Party", "Ambush Party", "Gnat Alley Creeper", "Ambush Party", "Ambush Party"}; + + for (int i = 0; i < 5; i ++) + { + qa.addCompy(compySetupCards[i]); + } + + qa.setCardRewardList(pack.getRare(5)); + } + + else if (id == 20) // Blood Oath + { + CardList humanList = new CardList(); + String humanSetupCards[] = {"Counterbalance", "Hatching Plans", "Ley Druid"}; + + for (int i = 0; i < 3; i ++) + { + Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + } + qa.setHuman(humanList); + + String compySetupCards[] = {"Ior Ruin Expedition", "Oversold Cemetery", "Trapjaw Kelpie"}; + + for (int i = 0; i < 3; i ++) + { + qa.addCompy(compySetupCards[i]); + } + + qa.setCardRewardList(pack.getRare(5, 1)); + } + + else if (id == 21) // Private Domain + { + CardList humanList = new CardList(); + + Card c = AllZone.CardFactory.getCard("Strip Mine", AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + + qa.setHuman(humanList); + + String compySetupCards[] = {"Plains", "Island", "Swamp", "Mountain", "Forest"}; + + for (int i = 0; i < 5; i ++) + qa.addCompy(compySetupCards[i]); + + qa.setCardRewardList(pack.getRare(6)); + } + + else if (id == 22) // Pied Piper + { + CardList humanList = new CardList(); + String humanSetupCards[] = {"Volunteer Militia", "Land Tax", "Elvish Farmer", "An-Havva Township"}; + + for (int i = 0; i < 4; i ++) + { + Card c = AllZone.CardFactory.getCard(humanSetupCards[i], AllZone.HumanPlayer); + + c.setCurSetCode(c.getMostRecentSet()); + c.setImageFilename(CardUtil.buildFilename(c)); + + humanList.add(c); + } + qa.setHuman(humanList); + + String compySetupCards[] = {"Darksteel Citadel", "Relentless Rats"}; + + for (int i = 0; i < 2; i ++) + qa.addCompy(compySetupCards[i]); + + qa.setCardRewardList(pack.getRare(3)); + } + + } + +}//QuestUtil diff --git a/src/forge/ReadQuest_Assignment.java b/src/forge/ReadQuest_Assignment.java index 11f8af30f8c..68cc0643a26 100644 --- a/src/forge/ReadQuest_Assignment.java +++ b/src/forge/ReadQuest_Assignment.java @@ -1,194 +1,195 @@ -package forge; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.util.ArrayList; - -import forge.error.ErrorViewer; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; - - - -public class ReadQuest_Assignment implements Runnable, NewConstants { - private BufferedReader in; - private ArrayList allQuests = new ArrayList(); - - private int totalWins; - private ArrayList completedQuests = new ArrayList(); - - public static void main(String args[]) throws Exception { - 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); - } - } - - public ArrayList getQuests() { - return new ArrayList(allQuests); - } - - public ArrayList getQuestsByIds(ArrayList availableQuestIds) { - ArrayList quests = new ArrayList(); - - for(Quest_Assignment qa:allQuests) - { - if (availableQuestIds.contains(qa.getId())) - quests.add(qa); - } - - return quests; - } - - public Quest_Assignment getQuestById(int i) - { - for(Quest_Assignment qa:allQuests) - { - if (qa.getId() == i) - return qa; - } - return null; - } - - /* - public Quest_Assignment getQuestById(int id) { - return allQuests.get(id); - } - */ - - public ReadQuest_Assignment(String filename, QuestData questData) { - this(new File(filename), questData); - } - - public ReadQuest_Assignment(File file, QuestData questData) { - - if (questData != null) { - totalWins = questData.getWin(); - if (questData.getCompletedQuests() != null) - completedQuests = questData.getCompletedQuests(); - else - completedQuests = new ArrayList(); - } - - if(!file.exists()) - throw new RuntimeException("ReadQuest_Assignment : constructor error -- file not found -- filename is " - + file.getAbsolutePath()); - - //makes the checked exception, into an unchecked runtime exception - try { - in = new BufferedReader(new FileReader(file)); - } catch(Exception ex) { - ErrorViewer.showError(ex, "File \"%s\" not found", file.getAbsolutePath()); - throw new RuntimeException("ReadQuest_Assignment : constructor error -- file not found -- filename is " - + file.getPath()); - } - }//ReadCard() - - /* id - * name - * desc - * difficulty - * repeatable - * numberWinsRequired - * cardReward - * creditsReward - */ - - public void run() { - Quest_Assignment qa; - String s = readLine(); - ArrayList ids = new ArrayList(); - - while(!s.equals("End")) { - qa = new Quest_Assignment(); - if(s.equals("")) throw new RuntimeException("ReadQuest_Assignment : run() reading error, id is blank"); - int id = Integer.parseInt(s); - qa.setId(id); - - s = readLine(); - qa.setName(s); - - s = readLine(); - qa.setDesc(s); - - - s = readLine(); - qa.setDifficulty(s); - if (qa.getDifficulty().equals("Medium")) - qa.setComputerLife(25); - else if (qa.getDifficulty().equals("Hard")) - qa.setComputerLife(30); - else if (qa.getDifficulty().equals("Very Hard")) - qa.setComputerLife(35); - else if (qa.getDifficulty().equals("Expert")) - qa.setComputerLife(50); - else if (qa.getDifficulty().equals("Insane")) - qa.setComputerLife(100); - - s = readLine(); - if (s.equals("Repeatable")) - qa.setRepeatable(true); - else - qa.setRepeatable(false); - - s = readLine(); - int wins = Integer.valueOf(s); - qa.setRequiredNumberWins(wins); - - s = readLine(); - qa.setCardReward(s); - - s = readLine(); - long reward = Long.parseLong(s.trim()); - qa.setCreditsReward(reward); - - s = readLine(); - qa.setIconName(s); - - //s = readLine(); - s = readLine(); - - if(ids.contains(qa.getId())) { - System.out.println("ReadQuest_Assignment:run() error - duplicate card name: " + qa.getId()); - throw new RuntimeException("ReadQuest_Assignment:run() error - duplicate card name: " + qa.getId()); - } - - ids.add(qa.getId()); - if (qa.getRequiredNumberWins() <= totalWins && !completedQuests.contains(qa.getId()) ) { - QuestUtil.setupQuest(qa); - allQuests.add(qa); - } - - //id: - s = readLine(); - } - }//run() - - private String readLine() { - //makes the checked exception, into an unchecked runtime exception - try { - String s = in.readLine(); - if(s != null) s = s.trim(); - return s; - } catch(Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("ReadQuest_Assignment: readLine(Quest_Assignment) error"); - } - }//readLine(Quest_Assignment) +package forge; + +import forge.error.ErrorViewer; +import forge.properties.ForgeProps; +import forge.properties.NewConstants; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + + +public class ReadQuest_Assignment implements Runnable, NewConstants { + private BufferedReader in; + private ArrayList allQuests = new ArrayList(); + + private int totalWins; + private List completedQuests = new ArrayList(); + + public static void main(String args[]) throws Exception { + 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); + } + } + + public List getQuests() { + return new ArrayList(allQuests); + } + + public List getQuestsByIds(List availableQuestIds) { + List quests = new ArrayList(); + + for(Quest_Assignment qa:allQuests) + { + if (availableQuestIds.contains(qa.getId())) + quests.add(qa); + } + + return quests; + } + + public Quest_Assignment getQuestById(int i) + { + for(Quest_Assignment qa:allQuests) + { + if (qa.getId() == i) + return qa; + } + return null; + } + + /* + public Quest_Assignment getQuestById(int id) { + return allQuests.get(id); + } + */ + + public ReadQuest_Assignment(String filename, forge.quest.data.QuestData questData) { + this(new File(filename), questData); + } + + 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(); + } + + if(!file.exists()) + throw new RuntimeException("ReadQuest_Assignment : constructor error -- file not found -- filename is " + + file.getAbsolutePath()); + + //makes the checked exception, into an unchecked runtime exception + try { + in = new BufferedReader(new FileReader(file)); + } catch(Exception ex) { + ErrorViewer.showError(ex, "File \"%s\" not found", file.getAbsolutePath()); + throw new RuntimeException("ReadQuest_Assignment : constructor error -- file not found -- filename is " + + file.getPath()); + } + }//ReadCard() + + /* id + * name + * desc + * difficulty + * repeatable + * numberWinsRequired + * cardReward + * creditsReward + */ + + public void run() { + Quest_Assignment qa; + String s = readLine(); + ArrayList ids = new ArrayList(); + + while(!s.equals("End")) { + qa = new Quest_Assignment(); + if(s.equals("")) throw new RuntimeException("ReadQuest_Assignment : run() reading error, id is blank"); + int id = Integer.parseInt(s); + qa.setId(id); + + s = readLine(); + qa.setName(s); + + s = readLine(); + qa.setDesc(s); + + + s = readLine(); + qa.setDifficulty(s); + if (qa.getDifficulty().equals("Medium")) + qa.setComputerLife(25); + else if (qa.getDifficulty().equals("Hard")) + qa.setComputerLife(30); + else if (qa.getDifficulty().equals("Very Hard")) + qa.setComputerLife(35); + else if (qa.getDifficulty().equals("Expert")) + qa.setComputerLife(50); + else if (qa.getDifficulty().equals("Insane")) + qa.setComputerLife(100); + + s = readLine(); + if (s.equals("Repeatable")) + qa.setRepeatable(true); + else + qa.setRepeatable(false); + + s = readLine(); + int wins = Integer.valueOf(s); + qa.setRequiredNumberWins(wins); + + s = readLine(); + qa.setCardReward(s); + + s = readLine(); + long reward = Long.parseLong(s.trim()); + qa.setCreditsReward(reward); + + s = readLine(); + qa.setIconName(s); + + //s = readLine(); + s = readLine(); + + if(ids.contains(qa.getId())) { + System.out.println("ReadQuest_Assignment:run() error - duplicate card name: " + qa.getId()); + throw new RuntimeException("ReadQuest_Assignment:run() error - duplicate card name: " + qa.getId()); + } + + ids.add(qa.getId()); + if (qa.getRequiredNumberWins() <= totalWins && !completedQuests.contains(qa.getId()) ) { + forge.quest.data.QuestUtil.setupQuest(qa); + allQuests.add(qa); + } + + //id: + s = readLine(); + } + }//run() + + private String readLine() { + //makes the checked exception, into an unchecked runtime exception + try { + String s = in.readLine(); + if(s != null) s = s.trim(); + return s; + } catch(Exception ex) { + ErrorViewer.showError(ex); + throw new RuntimeException("ReadQuest_Assignment: readLine(Quest_Assignment) error"); + } + }//readLine(Quest_Assignment) } \ No newline at end of file diff --git a/src/forge/WinLose.java b/src/forge/WinLose.java index faade7fb5d6..dcbb6c6e637 100644 --- a/src/forge/WinLose.java +++ b/src/forge/WinLose.java @@ -1,4 +1,5 @@ package forge; +@Deprecated public class WinLose { //the way wins were achieved: diff --git a/src/forge/gui/GuiUtils.java b/src/forge/gui/GuiUtils.java index d50ab030bf4..103a6c173e2 100644 --- a/src/forge/gui/GuiUtils.java +++ b/src/forge/gui/GuiUtils.java @@ -1,28 +1,19 @@ package forge.gui; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.Frame; -import java.awt.Image; -import java.awt.Rectangle; -import java.awt.image.BufferedImage; -import java.io.File; -import java.util.Collection; -import java.util.List; - -import javax.swing.Box; -import javax.swing.ImageIcon; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - import forge.AllZone; import forge.Card; import forge.properties.ForgeProps; import forge.properties.NewConstants; +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.util.Collection; +import java.util.List; + public class GuiUtils { @@ -87,11 +78,11 @@ public class GuiUtils { public static ImageIcon getIconFromFile(String iconName) { File base = ForgeProps.getFile(NewConstants.IMAGE_ICON); File file = new File(base, iconName); - if (file.exists()) { - return new ImageIcon(file.toString()); + if (iconName.equals("") || !file.exists()) { + return null; } else { - return null; + return new ImageIcon(file.toString()); } } diff --git a/src/forge/quest/data/QuestData.java b/src/forge/quest/data/QuestData.java index 64b0ea7566c..2e7de4ec0ba 100644 --- a/src/forge/quest/data/QuestData.java +++ b/src/forge/quest/data/QuestData.java @@ -14,66 +14,60 @@ import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; -//when you create QuestData and AFTER you copy the AI decks over +//when you create QuestDataOld and AFTER you copy the AI decks over //you have to call one of these two methods below //see Gui_QuestOptions for more details // -//static readAIQuestDeckFiles(QuestData data, ArrayList aiDeckNames) +//static readAIQuestDeckFiles(QuestDataOld data, ArrayList aiDeckNames) //OR non-static readAIQuestDeckFiles() //which reads the files "questDecks-easy", "questDecks-medium","questDecks-hard", public class QuestData { - QuestPreferences qdPrefs = null; + QuestPreferences preferences = null; private int rankIndex; private int win; private int lost; - private List pets; - - private QuestPetAbstract selectedPet; - private int life; private int estatesLevel; private int luckyCoinLevel; private int sleightOfHandLevel; + private int gearLevel; private int questsPlayed; private long credits; - private int diffIndex; private String difficulty; + private String mode = ""; - private transient ArrayList easyAIDecks; - private transient ArrayList mediumAIDecks; - private transient ArrayList hardAIDecks; + private transient Map aiDecks; + private transient List easyAIDecks; + private transient List mediumAIDecks; + private transient List hardAIDecks; private Map myDecks = new HashMap(); - private transient Map aiDecks = new HashMap(); //holds String card names - private ArrayList cardPool = new ArrayList(); - private ArrayList newCardList = new ArrayList(); - private ArrayList shopList = new ArrayList(); + private List cardPool = new ArrayList(); + private List newCardList = new ArrayList(); - private ArrayList availableQuests = new ArrayList(); - private ArrayList completedQuests = new ArrayList(); + private List shopList = new ArrayList(); + private List availableQuests = new ArrayList(); - private transient QuestBoosterPack boosterPack = new QuestBoosterPack(); + private List completedQuests = new ArrayList(); + + private transient QuestBoosterPack boosterPack; //used by shouldAddAdditionalCards() private Random random = new Random(); - //feel free to change this to something funnier - private transient String[] rankArray = { - "Level 0 - Confused Wizard", "Level 1 - Mana Mage", "Level 2 - Death by Megrim", - "Level 3 - Shattered the Competition", "Level 4 - Black Knighted", "Level 5 - Shockingly Good", - "Level 6 - Regressed into Timmy", "Level 7 - Loves Blue Control", "Level 8 - Immobilized by Fear", - "Level 9 - Lands = Friends", "Saltblasted for your talent", "Serra Angel is your girlfriend",}; + //feel free to change this to something funnier + private transient String[] rankArray; public static final String FANTASY = "Fantasy"; public static final String REALISTIC = "Realistic"; @@ -81,10 +75,12 @@ public class QuestData { //TODO: Temporary. public boolean useNewQuestUI = false; - public QuestData() { - qdPrefs = new QuestPreferences(); + public final QuestPetManager petManager = new QuestPetManager(); - for (int i = 0; i < qdPrefs.getStartingBasic(); i++) { + public QuestData() { + preferences = new QuestPreferences(); + + for (int i = 0; i < preferences.getStartingBasic(); i++) { cardPool.add("Forest"); cardPool.add("Mountain"); cardPool.add("Swamp"); @@ -92,7 +88,7 @@ public class QuestData { cardPool.add("Plains"); } - for (int i = 0; i < qdPrefs.getStartingSnowBasic(); i++) { + for (int i = 0; i < preferences.getStartingSnowBasic(); i++) { cardPool.add("Snow-Covered Forest"); cardPool.add("Snow-Covered Mountain"); cardPool.add("Snow-Covered Swamp"); @@ -100,21 +96,46 @@ public class QuestData { cardPool.add("Snow-Covered Plains"); } - readAIQuestDeckFiles(); - }//QuestData + initTransients(); + } + + private void initTransients() { + aiDecks = new HashMap(); + List aiDeckNames = ai_getDeckNames(); + easyAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.EASY), aiDeckNames); + mediumAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.MEDIUM), aiDeckNames); + hardAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.HARD), aiDeckNames); + + rankArray = new String[]{ + "Level 0 - Confused Wizard", + "Level 1 - Mana Mage", + "Level 2 - Death by Megrim", + "Level 3 - Shattered the Competition", + "Level 4 - Black Knighted", + "Level 5 - Shockingly Good", + "Level 6 - Regressed into Timmy", + "Level 7 - Loves Blue Control", + "Level 8 - Immobilized by Fear", + "Level 9 - Lands = Friends", + "Saltblasted for your talent", + "Serra Angel is your girlfriend",}; + + boosterPack = new QuestBoosterPack(); + } + //adds cards to card pool and sets difficulty public void newGame(int difficulty, String m) { setDifficulty(difficulty); ArrayList list = new ArrayList(); - list.addAll(boosterPack.getCommon(qdPrefs.getStartingCommons(difficulty))); - list.addAll(boosterPack.getUncommon(qdPrefs.getStartingUncommons(difficulty))); - list.addAll(boosterPack.getRare(qdPrefs.getStartingRares(difficulty))); + list.addAll(boosterPack.getCommon(preferences.getStartingCommons(difficulty))); + list.addAll(boosterPack.getUncommon(preferences.getStartingUncommons(difficulty))); + list.addAll(boosterPack.getRare(preferences.getStartingRares(difficulty))); //because cardPool already has basic land added to it cardPool.addAll(list); - credits = qdPrefs.getStartingCredits(); + credits = preferences.getStartingCredits(); mode = m; if (mode.equals(FANTASY)) { @@ -125,36 +146,28 @@ public class QuestData { } } - public String[] getOpponents() { int index = getDifficultyIndex(); - if (getWin() < qdPrefs.getWinsForMediumAI(index)) { + if (getWin() < preferences.getWinsForMediumAI(index)) { return getOpponents(easyAIDecks); } - if (getWin() < qdPrefs.getWinsForHardAI(index)) { + if (getWin() < preferences.getWinsForHardAI(index)) { return getOpponents(mediumAIDecks); } return getOpponents(hardAIDecks); - }//getOpponents() - - - private void readAIQuestDeckFiles(QuestData data, ArrayList aiDeckNames) { - data.easyAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.EASY), aiDeckNames); - data.mediumAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.MEDIUM), aiDeckNames); - data.hardAIDecks = readFile(ForgeProps.getFile(NewConstants.QUEST.HARD), aiDeckNames); } - public String[] getOpponents(ArrayList aiDeck) { + public String[] getOpponents(List aiDeck) { Collections.shuffle(aiDeck); return new String[]{aiDeck.get(0).toString(), aiDeck.get(1).toString(), aiDeck.get(2).toString()}; - }//getOpponents() + } - private static ArrayList readFile(File file, ArrayList aiDecks) { + private static List readFile(File file, List aiDecks) { ArrayList list = FileUtil.readFile(file); //remove any blank lines @@ -177,7 +190,7 @@ public class QuestData { for (int i = 0; i < list.size(); i++) /*if(!aiDecks.contains(list.get(i).toString())) ErrorViewer.showError(new Exception(), - "QuestData : readFile() error, file %s contains the invalid ai deck name: %s", file, + "QuestDataOld : readFile() error, file %s contains the invalid ai deck name: %s", file, list.get(i));*/ { if (!aiDecks.contains(list.get(i).toString())) { aiDecks.add(list.get(i).toString()); @@ -186,12 +199,9 @@ public class QuestData { return list; - }//readFile() - - public void readAIQuestDeckFiles() { - readAIQuestDeckFiles(this, ai_getDeckNames()); } + static public QuestData loadData() { try { //read file "questData" @@ -213,7 +223,6 @@ public class QuestData { XStream xStream = new XStream(); data = (QuestData) xStream.fromXML(zin); - data.readAIQuestDeckFiles(data, new ArrayList()); zin.close(); } @@ -226,6 +235,24 @@ public class QuestData { } } + public void saveData() { + try { + File f = ForgeProps.getFile(NewConstants.QUEST.XMLDATA); + BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(f)); + GZIPOutputStream zout = new GZIPOutputStream(bout); + + XStream xStream = new XStream(); + xStream.toXML(this, zout); + + zout.flush(); + zout.close(); + } catch (Exception ex) { + ErrorViewer.showError(ex, "Error saving Quest Data"); + throw new RuntimeException(ex); + } + } + + @SuppressWarnings({"deprecation"}) private static QuestData convertSaveFormat() { forge.QuestData oldData = forge.QuestData.loadData(); QuestData newData = new QuestData(); @@ -233,7 +260,7 @@ public class QuestData { newData.difficulty = oldData.getDifficulty(); newData.diffIndex = oldData.getDiffIndex(); - newData.rankIndex = oldData.getWin()/newData.qdPrefs.getWinsForRankIncrease(newData.diffIndex); + newData.rankIndex = oldData.getWin() / newData.preferences.getWinsForRankIncrease(newData.diffIndex); newData.win = oldData.getWin(); newData.lost = oldData.getLost(); @@ -259,46 +286,47 @@ public class QuestData { newData.availableQuests = oldData.getAvailableQuests(); newData.completedQuests = oldData.getCompletedQuests(); - newData.pets = new ArrayList(); QuestPetAbstract newPet; - if(oldData.getBirdPetLevel() > 0){ + if (oldData.getBirdPetLevel() > 0) { newPet = new QuestPetBird(); newPet.setLevel(oldData.getBirdPetLevel()); - newData.pets.add(newPet); + newData.petManager.addPet(newPet); } - if(oldData.getHoundPetLevel() > 0){ + if (oldData.getHoundPetLevel() > 0) { newPet = new QuestPetHound(); newPet.setLevel(oldData.getHoundPetLevel()); - newData.pets.add(newPet); + newData.petManager.addPet(newPet); } - if(oldData.getWolfPetLevel() > 0){ + if (oldData.getWolfPetLevel() > 0) { newPet = new QuestPetWolf(); newPet.setLevel(oldData.getWolfPetLevel()); - newData.pets.add(newPet); + newData.petManager.addPet(newPet); } - if(oldData.getCrocPetLevel() > 0){ + if (oldData.getCrocPetLevel() > 0) { newPet = new QuestPetCrocodile(); newPet.setLevel(oldData.getCrocPetLevel()); - newData.pets.add(newPet); + newData.petManager.addPet(newPet); } - if(oldData.getPlantLevel() > 0){ + if (oldData.getPlantLevel() > 0) { newPet = new QuestPetPlant(); newPet.setLevel(oldData.getPlantLevel()); - newData.pets.add(newPet); + newData.petManager.getPlant().setLevel(oldData.getPlantLevel()); } + newData.getPetManager().setSelectedPet(null); + return newData; } //returns Strings of the card names - public ArrayList getCardpool() { + public List getCardpool() { //make a copy so the internal ArrrayList cannot be changed externally return new ArrayList(cardPool); } - public ArrayList getShopList() { + public List getShopList() { if (shopList != null) { return new ArrayList(shopList); } @@ -307,12 +335,12 @@ public class QuestData { } } - public void setShopList(ArrayList list) { + public void setShopList(List list) { shopList = list; } - public ArrayList getAvailableQuests() { + public List getAvailableQuests() { if (availableQuests != null) { return new ArrayList(availableQuests); } @@ -321,7 +349,7 @@ public class QuestData { } } - public void setAvailableQuests(ArrayList list) { + public void setAvailableQuests(List list) { availableQuests = list; } @@ -329,7 +357,7 @@ public class QuestData { availableQuests.clear(); } - public ArrayList getCompletedQuests() { + public List getCompletedQuests() { if (completedQuests != null) { return new ArrayList(completedQuests); } @@ -338,7 +366,7 @@ public class QuestData { } } - public void setCompletedQuests(ArrayList list) { + public void setCompletedQuests(List list) { completedQuests = list; } @@ -347,8 +375,6 @@ public class QuestData { shopList.clear(); } - //rename - removeDeck, addDeck - //copy - addDeck public void removeDeck(String deckName) { myDecks.remove(deckName); @@ -416,18 +442,18 @@ public class QuestData { //returns human player decks //returns ArrayList of String deck names - public ArrayList getDeckNames() { + public List getDeckNames() { return getDeckNames_String(myDecks); - }//getDecks() + } //returns AI computer decks //returns ArrayList of String deck names - public ArrayList ai_getDeckNames() { + public List ai_getDeckNames() { return getDeckNames_String(aiDecks); } //returns ArrayList of Deck String names - private ArrayList getDeckNames_String(Map map) { + private List getDeckNames_String(Map map) { ArrayList out = new ArrayList(); Iterator it = map.keySet().iterator(); @@ -439,16 +465,16 @@ public class QuestData { } //get new cards that were added to your card pool by addCards() - public ArrayList getAddedCards() { + public List getAddedCards() { return new ArrayList(newCardList); } //adds 11 cards, to the current card pool //(I chose 11 cards instead of 15 in order to make things more challenging) public void addCards() { - int nCommon = qdPrefs.getNumCommon(); - int nUncommon = qdPrefs.getNumUncommon(); - int nRare = qdPrefs.getNumRare(); + int nCommon = preferences.getNumCommon(); + int nUncommon = preferences.getNumUncommon(); + int nRare = preferences.getNumRare(); ArrayList newCards = new ArrayList(); newCards.addAll(boosterPack.getCommon(nCommon)); @@ -461,18 +487,6 @@ public class QuestData { //getAddedCards() uses newCardList newCardList = newCards; - }//addCards() - - public ArrayList getRandomRares(int n, int colorIndex) { - ArrayList newCards = new ArrayList(); - newCards.addAll(boosterPack.getRare(n, colorIndex)); - - /* - for(String s : newCards ) { - Card c = AllZone.CardFactory.getCard(s, AllZone.HumanPlayer); - list.add(c); - }*/ - return newCards; } public void addRandomRare(int n) { @@ -541,49 +555,49 @@ public class QuestData { } public long getCreditsToAdd(QuestMatchState matchState) { - long creds = (long) (qdPrefs.getMatchRewardBase() + (qdPrefs.getMatchRewardTotalWins() * win)); + long creds = (long) (preferences.getMatchRewardBase() + (preferences.getMatchRewardTotalWins() * win)); String[] wins = matchState.getWinMethods(); int[] winTurns = matchState.getWinTurns(); boolean[] mulliganedToZero = matchState.getMulliganedToZero(); if (matchState.getLose() == 0) { - creds += qdPrefs.getMatchRewardNoLosses(); + creds += preferences.getMatchRewardNoLosses(); } for (String s : wins) { if (s != null) { if (s.equals("Poison Counters")) { - creds += qdPrefs.getMatchRewardPoisonWinBonus(); + creds += preferences.getMatchRewardPoisonWinBonus(); } else if (s.equals("Milled")) { - creds += qdPrefs.getMatchRewardMilledWinBonus(); + creds += preferences.getMatchRewardMilledWinBonus(); } else if (s.equals("Battle of Wits") || s.equals("Felidar Sovereign") || s.equals("Helix Pinnacle") || s.equals("Epic Struggle") || s.equals("Door to Nothingness") || s.equals("Barren Glory") || s.equals("Near-Death Experience") || s.equals("Mortal Combat") || s.equals("Test of Endurance")) { - creds += qdPrefs.getMatchRewardAltWinBonus(); + creds += preferences.getMatchRewardAltWinBonus(); } } } for (int i : winTurns) { if (i == 1) { - creds += qdPrefs.getMatchRewardWinFirst(); + creds += preferences.getMatchRewardWinFirst(); } else if (i <= 5) { - creds += qdPrefs.getMatchRewardWinByFifth(); + creds += preferences.getMatchRewardWinByFifth(); } else if (i <= 10) { - creds += qdPrefs.getMatchRewardWinByTen(); + creds += preferences.getMatchRewardWinByTen(); } else if (i <= 15) { - creds += qdPrefs.getMatchRewardWinByFifteen(); + creds += preferences.getMatchRewardWinByFifteen(); } } for (boolean b : mulliganedToZero) { if (b == true) { - creds += qdPrefs.getMatchMullToZero(); + creds += preferences.getMatchMullToZero(); } } @@ -603,7 +617,7 @@ public class QuestData { } //gets all of the cards that are in the cardpool - public ArrayList getCards() { + public List getCards() { //copy CardList in order to keep private variables private //if we just return cardPool, it could be changed externally return new ArrayList(cardPool); @@ -613,7 +627,7 @@ public class QuestData { public int getTotalNumberOfGames(int difficulty) { //-2 because you start a level 1, and the last level is secret int numberLevels = rankArray.length - 2; - int nMatches = qdPrefs.getWinsForRankIncrease(difficulty); + int nMatches = preferences.getWinsForRankIncrease(difficulty); return numberLevels * nMatches; } @@ -622,10 +636,10 @@ public class QuestData { public void addWin() { win++; - if (win % qdPrefs.getWinsForRankIncrease(diffIndex) == 0) { + if (win % preferences.getWinsForRankIncrease(diffIndex) == 0) { rankIndex++; } - }//addWin() + } public void addLost() { lost++; @@ -641,15 +655,6 @@ public class QuestData { //********************FANTASY STUFF START*********************** - - public void setSelectedPet(QuestPetAbstract pet) { - selectedPet = pet; - } - - public QuestPetAbstract getSelectedPet() { - return selectedPet; - } - public void setLife(int n) { life = n; } @@ -726,6 +731,10 @@ public class QuestData { return mode; } + //should be called first, because the difficultly won't change + public String getDifficulty() { + return difficulty; + } public int getDifficultyIndex() { return diffIndex; @@ -733,14 +742,26 @@ public class QuestData { public void setDifficulty(int i) { diffIndex = i; - difficulty = qdPrefs.getDifficulty(i); + difficulty = preferences.getDifficulty(i); } + public void setDifficultyIndex() { + String[] diffStr = preferences.getDifficulty(); + for (int i = 0; i < diffStr.length; i++) { + if (difficulty.equals(diffStr[i])) { + diffIndex = i; + } + } + } + + public String[] getDifficultyChoices() { + return preferences.getDifficulty(); + } public String getRank() { //is rankIndex too big? - if (rankIndex == rankArray.length) { - rankIndex--; + if (rankIndex >= rankArray.length) { + rankIndex = rankArray.length - 1; } return rankArray[rankIndex]; @@ -748,7 +769,7 @@ public class QuestData { //add cards after a certain number of wins or losses public boolean shouldAddCards(boolean didWin) { - int n = qdPrefs.getWinsForBooster(diffIndex); + int n = preferences.getWinsForBooster(diffIndex); if (didWin) { return getWin() % n == 0; @@ -777,26 +798,10 @@ public class QuestData { } public boolean hasSaveFile() { - return ForgeProps.getFile(NewConstants.QUEST.DATA).exists(); + return ForgeProps.getFile(NewConstants.QUEST.DATA).exists()|| + ForgeProps.getFile(NewConstants.QUEST.XMLDATA).exists(); } - - public void saveData() { - try { - File f = ForgeProps.getFile(NewConstants.QUEST.XMLDATA); - BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(f)); - GZIPOutputStream zout = new GZIPOutputStream(bout); - - XStream xStream = new XStream(); - xStream.toXML(this, zout); - - zout.flush(); - zout.close(); - } catch (Exception ex) { - ErrorViewer.showError(ex, "Error saving Quest Data"); - throw new RuntimeException(ex); - } - }//saveData() - + public static void main(String[] args) { QuestData q = new QuestData(); for (int i = 0; i < 20; i++) { @@ -811,5 +816,21 @@ public class QuestData { System.exit(1); } + public QuestPetManager getPetManager() { + return petManager; + } + public QuestPreferences getQuestPreferences() { + return preferences; + } + + //get new cards that were added to your card pool by addCards() + public void addToNewList(ArrayList added) { + newCardList.addAll(added); + } + + public Object readResolve() { + initTransients(); + return this; + } } diff --git a/src/forge/quest/data/QuestUtil.java b/src/forge/quest/data/QuestUtil.java index 1cd2d31574f..ce5b9337aa9 100644 --- a/src/forge/quest/data/QuestUtil.java +++ b/src/forge/quest/data/QuestUtil.java @@ -5,12 +5,7 @@ import forge.*; import java.util.ArrayList; public class QuestUtil { - - public static int getLife(QuestData qd) - { - return qd.getLife(); - } - + public static CardList getComputerCreatures(QuestData qd) { return new CardList(); @@ -39,24 +34,14 @@ public class QuestUtil { public static CardList getHumanPlantAndPet(QuestData qd) { CardList list = new CardList(); - - if (qd.getSelectedPet() != null) - { - if (qd.getSelectedPet().equals("No Plant/Pet")) - return list; - - if (qd.getSelectedPet().equals("Wolf") && qd.getWolfPetLevel() > 0) - list.add(getWolfPetToken(qd.getWolfPetLevel())); - else if (qd.getSelectedPet().equals("Croc") && qd.getCrocPetLevel() > 0) - list.add(getCrocPetToken(qd.getCrocPetLevel())); - else if (qd.getSelectedPet().equals("Bird") && qd.getBirdPetLevel() > 0) - list.add(getBirdPetToken(qd.getBirdPetLevel())); - else if (qd.getSelectedPet().equals("Hound") && qd.getHoundPetLevel() > 0) - list.add(getHoundPetToken(qd.getHoundPetLevel())); - } - - if (qd.getPlantLevel() > 0) - list.add(getPlantToken(qd.getPlantLevel())); + + if (qd.getPetManager().shouldPetBeUsed()){ + list.add(qd.getPetManager().getSelectedPet().getPetCard()); + } + + if (qd.getPetManager().shouldPlantBeUsed()){ + list.add(qd.getPetManager().getPlant().getPetCard()); + } return list; } @@ -70,357 +55,7 @@ public class QuestUtil { return list; } - - //makeToken(String name, String imageName, Card source, String manaCost, String[] types, int baseAttack, int baseDefense, String[] intrinsicKeywords) { - - public static Card getPlantToken(int level) - { - String imageName = ""; - int baseAttack = 0; - int baseDefense = 0; - - String keyword = ""; - - if (level == 1) - { - imageName = "G 0 1 Plant Wall"; - baseDefense = 1; - } - else if (level == 2) - { - imageName = "G 0 2 Plant Wall"; - baseDefense = 2; - } - else if (level == 3) - { - imageName = "G 0 3 Plant Wall"; - baseDefense = 3; - } - else if (level == 4) - { - imageName = "G 1 3 Plant Wall"; - baseDefense = 3; - baseAttack = 1; - } - else if (level == 5) - { - imageName = "G 1 3 Plant Wall Deathtouch"; - baseDefense = 3; - baseAttack = 1; - keyword = "Deathtouch"; - } - - else if (level == 6) - { - imageName = "G 1 4 Plant Wall"; - baseDefense = 4; - baseAttack = 1; - keyword = "Deathtouch"; - } - - - Card c = new Card(); - c.setName("Plant Wall"); - - c.setImageName(imageName); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("G"); - c.addColor("G"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Plant"); - c.addType("Wall"); - - c.addIntrinsicKeyword("Defender"); - if (!keyword.equals("")) - c.addIntrinsicKeyword("Deathtouch"); - - c.setBaseAttack(baseAttack); - c.setBaseDefense(baseDefense); - - if (level == 6) - { - final Card crd = c; - Ability_Cost abCost = new Ability_Cost("T", crd.getName(), true); - final SpellAbility ability = new Ability_Activated(crd, abCost, null){ - private static final long serialVersionUID = 7546242087593613719L; - - @Override - public boolean canPlayAI() { - return AllZone.Phase.getPhase().equals(Constant.Phase.Main2); - } - - @Override - public void resolve() { - crd.getController().gainLife(1, crd); - } - }; - c.addSpellAbility(ability); - ability.setDescription("tap: You gain 1 life."); - - StringBuilder sb = new StringBuilder(); - sb.append("Plant Wall - ").append(c.getController()).append(" gains 1 life."); - ability.setStackDescription(sb.toString()); - - c.setText("tap: You gain 1 life."); - } - - - return c; - }//getPlantToken - - public static Card getWolfPetToken(int level) - { - String imageName = ""; - int baseAttack = 0; - int baseDefense = 0; - - if (level == 1) - { - imageName = "G 1 1 Wolf Pet"; - baseDefense = 1; - baseAttack = 1; - } - else if (level == 2) - { - imageName = "G 1 2 Wolf Pet"; - baseDefense = 2; - baseAttack = 1; - } - else if (level == 3) - { - imageName = "G 2 2 Wolf Pet"; - baseDefense = 2; - baseAttack = 2; - } - else if (level == 4) - { - imageName = "G 2 2 Wolf Pet Flanking"; - baseDefense = 2; - baseAttack = 2; - } - - - Card c = new Card(); - c.setName("Wolf Pet"); - - c.setImageName(imageName); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("G"); - c.addColor("G"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Wolf"); - c.addType("Pet"); - - if (level >= 4) - c.addIntrinsicKeyword("Flanking"); - - c.setBaseAttack(baseAttack); - c.setBaseDefense(baseDefense); - - return c; - }//getWolfPetToken - - public static Card getCrocPetToken(int level) - { - String imageName = ""; - int baseAttack = 0; - int baseDefense = 0; - - if (level == 1) - { - imageName = "B 1 1 Crocodile Pet"; - baseDefense = 1; - baseAttack = 1; - } - else if (level == 2) - { - imageName = "B 2 1 Crocodile Pet"; - baseDefense = 1; - baseAttack = 2; - } - else if (level == 3) - { - imageName = "B 3 1 Crocodile Pet"; - baseDefense = 1; - baseAttack = 3; - } - else if (level == 4) - { - imageName = "B 3 1 Crocodile Pet Swampwalk"; - baseDefense = 1; - baseAttack = 3; - } - - - Card c = new Card(); - c.setName("Crocodile Pet"); - - c.setImageName(imageName); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("B"); - c.addColor("B"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Crocodile"); - c.addType("Pet"); - - if (level >= 4) - c.addIntrinsicKeyword("Swampwalk"); - - c.setBaseAttack(baseAttack); - c.setBaseDefense(baseDefense); - - return c; - }//getCrocPetToken - - public static Card getBirdPetToken(int level) - { - String imageName = ""; - int baseAttack = 0; - int baseDefense = 0; - - if (level == 1) - { - imageName = "W 0 1 Bird Pet"; - baseDefense = 1; - baseAttack = 0; - } - else if (level == 2) - { - imageName = "W 1 1 Bird Pet"; - baseDefense = 1; - baseAttack = 1; - } - else if (level == 3) - { - imageName = "W 2 1 Bird Pet"; - baseDefense = 1; - baseAttack = 2; - } - else if (level == 4) - { - imageName = "W 2 1 Bird Pet First Strike"; - baseDefense = 1; - baseAttack = 2; - } - - - Card c = new Card(); - c.setName("Bird Pet"); - - c.setImageName(imageName); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("W"); - c.addColor("W"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Bird"); - c.addType("Pet"); - - c.addIntrinsicKeyword("Flying"); - - if (level >= 4) - c.addIntrinsicKeyword("First Strike"); - - c.setBaseAttack(baseAttack); - c.setBaseDefense(baseDefense); - - return c; - } - - public static Card getHoundPetToken(int level) - { - String imageName = ""; - int baseAttack = 0; - int baseDefense = 0; - - if (level == 1) - { - imageName = "R 1 1 Hound Pet"; - baseDefense = 1; - baseAttack = 1; - } - else if (level == 2) - { - imageName = "R 1 1 Hound Pet Haste"; - baseDefense = 1; - baseAttack = 1; - } - else if (level == 3) - { - imageName = "R 2 1 Hound Pet"; - baseDefense = 1; - baseAttack = 2; - } - else if (level == 4) - { - imageName = "R 2 1 Hound Pet Alone"; - baseDefense = 1; - baseAttack = 2; - } - - - Card c = new Card(); - c.setName("Hound Pet"); - - c.setImageName(imageName); - - c.setController(AllZone.HumanPlayer); - c.setOwner(AllZone.HumanPlayer); - - //c.setManaCost("R"); - c.addColor("R"); - c.setToken(true); - - c.addType("Creature"); - c.addType("Hound"); - c.addType("Pet"); - - if (level >= 2) - c.addIntrinsicKeyword("Haste"); - - if (level >= 4) - c.addIntrinsicKeyword("Whenever this creature attacks alone, it gets +2/+0 until end of turn."); - - c.setBaseAttack(baseAttack); - c.setBaseDefense(baseDefense); - - return c; - } - - public static ArrayList getPetNames(QuestData questData) - { - ArrayList list = new ArrayList(); - if (questData.getWolfPetLevel() > 0) - list.add("Wolf"); - if (questData.getCrocPetLevel() > 0) - list.add("Croc"); - if (questData.getBirdPetLevel() > 0) - list.add("Bird"); - if (questData.getHoundPetLevel() > 0) - list.add("Hound"); - - return list; - } public static void setupQuest(Quest_Assignment qa) { diff --git a/src/forge/quest/data/pet/QuestPetAbstract.java b/src/forge/quest/data/pet/QuestPetAbstract.java index b7fd9f5e744..840948077cc 100644 --- a/src/forge/quest/data/pet/QuestPetAbstract.java +++ b/src/forge/quest/data/pet/QuestPetAbstract.java @@ -2,7 +2,7 @@ package forge.quest.data.pet; import forge.Card; -public abstract class QuestPetAbstract { +public abstract class QuestPetAbstract implements Comparable{ int level; private int maxLevel; private String name; @@ -55,4 +55,21 @@ public abstract class QuestPetAbstract { public void setLevel(int level){ this.level = level; } + + public String getDescription() { + return description; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return name; + } + + public int compareTo(Object o) { + return name.compareTo(o.toString()); + } } diff --git a/src/forge/quest/data/pet/QuestPetFactory.java b/src/forge/quest/data/pet/QuestPetFactory.java deleted file mode 100644 index f3cb990cf06..00000000000 --- a/src/forge/quest/data/pet/QuestPetFactory.java +++ /dev/null @@ -1,17 +0,0 @@ -package forge.quest.data.pet; - -import java.util.ArrayList; -import java.util.List; - -public class QuestPetFactory { - static List getAllPets(){ - List pets = new ArrayList(); - - pets.add(new QuestPetWolf()); - pets.add(new QuestPetCrocodile()); - pets.add(new QuestPetBird()); - pets.add(new QuestPetHound()); - - return pets; - } -} diff --git a/src/forge/quest/data/pet/QuestPetManager.java b/src/forge/quest/data/pet/QuestPetManager.java new file mode 100644 index 00000000000..cc88e9697ba --- /dev/null +++ b/src/forge/quest/data/pet/QuestPetManager.java @@ -0,0 +1,102 @@ +package forge.quest.data.pet; + +import java.util.*; + +public class QuestPetManager{ + + public Map pets = new HashMap(); + public QuestPetAbstract selectedPet; + public QuestPetAbstract plant; + public boolean usePlant; + + public QuestPetManager() { + plant = new QuestPetPlant(); + for (QuestPetAbstract pet : getAllPets()) { + addPet(pet); + } + } + + public void setSelectedPet(String pet) { + selectedPet = (pet == null) ? null : getPet(pet); + } + + public QuestPetAbstract getSelectedPet() { + return selectedPet; + } + + public QuestPetAbstract getPlant() { + return plant; + } + + public void addPlantLevel() { + if (plant == null) { + plant = new QuestPetPlant(); + } + else { + plant.incrementLevel(); + } + } + + public QuestPetAbstract getPet(String petName) { + + return pets.get(petName); + } + + public void addPet(QuestPetAbstract newPet) { + pets.put(newPet.getName(), newPet); + } + + public Set getPetNames() { + return pets.keySet(); + } + + public void addPetLevel(String s) { + pets.get(s).incrementLevel(); + } + + public boolean shouldPlantBeUsed() { + return usePlant; + } + + public boolean shouldPetBeUsed() { + return selectedPet != null; + } + + public static Set getAllPets() { + SortedSet set = new TreeSet(); + + set.add(new QuestPetBird()); + set.add(new QuestPetCrocodile()); + set.add(new QuestPetHound()); + set.add(new QuestPetWolf()); + + return set; + } + + + + public Set getAvailablePetNames() { + SortedSet set = new TreeSet(); + for (Map.Entry pet : pets.entrySet()) { + if (pet.getValue().getLevel() > 0){ + set.add(pet.getKey()); + } + } + return set; + } + + + public Collection getPets() { + return pets.values(); + } + + //Magic to support added pet types when reading saves. + private Object readResolve() { + for (QuestPetAbstract pet : getAllPets()) { + if (!pets.containsKey(pet.getName())) { + addPet(pet); + } + } + return this; + } +} diff --git a/src/forge/quest/gui/QuestFrame.java b/src/forge/quest/gui/QuestFrame.java index 65357d7b07e..63b6360e9e1 100644 --- a/src/forge/quest/gui/QuestFrame.java +++ b/src/forge/quest/gui/QuestFrame.java @@ -2,7 +2,6 @@ package forge.quest.gui; import forge.AllZone; import forge.Gui_NewGame; -import forge.QuestData; import forge.gui.GuiUtils; import forge.quest.gui.bazaar.QuestBazaarPanel; import forge.quest.gui.main.QuestMainPanel; @@ -24,7 +23,6 @@ public class QuestFrame extends JFrame { public static final String MAIN_PANEL = "Main"; public static final String BAZAAR_PANEL = "Bazaar"; - private static final String QUESTS_PANEL = "Quests"; Map subPanelMap = new HashMap(); @@ -79,7 +77,7 @@ public class QuestFrame extends JFrame { public void returnToMainMenu() { - QuestData.saveData(AllZone.QuestData); + AllZone.QuestData.saveData(); (new Gui_NewGame()).setVisible(true) ; this.dispose(); } diff --git a/src/forge/quest/gui/bazaar/QuestAbstractBazaarItem.java b/src/forge/quest/gui/bazaar/QuestAbstractBazaarItem.java index 1b69d73a02f..01cbf47e699 100644 --- a/src/forge/quest/gui/bazaar/QuestAbstractBazaarItem.java +++ b/src/forge/quest/gui/bazaar/QuestAbstractBazaarItem.java @@ -1,7 +1,6 @@ package forge.quest.gui.bazaar; import forge.AllZone; -import forge.QuestData; import forge.gui.GuiUtils; import javax.swing.*; @@ -72,7 +71,7 @@ public abstract class QuestAbstractBazaarItem { public void actionPerformed(ActionEvent e) { AllZone.QuestData.subtractCredits(price); purchaseItem(); - QuestData.saveData(AllZone.QuestData); + AllZone.QuestData.saveData(); QuestBazaarPanel.refreshLastInstance(); } }); diff --git a/src/forge/quest/gui/bazaar/QuestAbstractBazaarStall.java b/src/forge/quest/gui/bazaar/QuestAbstractBazaarStall.java index 54e07d6cb4a..5b6fc0a40f9 100644 --- a/src/forge/quest/gui/bazaar/QuestAbstractBazaarStall.java +++ b/src/forge/quest/gui/bazaar/QuestAbstractBazaarStall.java @@ -1,9 +1,9 @@ package forge.quest.gui.bazaar; import forge.AllZone; -import forge.QuestData; import forge.gui.GuiUtils; import forge.properties.NewConstants; +import forge.quest.data.QuestData; import javax.swing.*; import javax.swing.border.EmptyBorder; diff --git a/src/forge/quest/gui/bazaar/QuestNurseryStall.java b/src/forge/quest/gui/bazaar/QuestNurseryStall.java index cd580e5aa9d..13d87aef063 100644 --- a/src/forge/quest/gui/bazaar/QuestNurseryStall.java +++ b/src/forge/quest/gui/bazaar/QuestNurseryStall.java @@ -1,133 +1,44 @@ package forge.quest.gui.bazaar; import forge.gui.GuiUtils; +import forge.quest.data.pet.QuestPetAbstract; import java.util.ArrayList; import java.util.List; -public class QuestNurseryStall extends QuestAbstractBazaarStall{ - private static final long serialVersionUID = 9217496944324343390L; +public class QuestNurseryStall extends QuestAbstractBazaarStall { + private static final long serialVersionUID = 9217496944324343390L; - public QuestNurseryStall() { - super("Nursery", "LeafIconSmall.png", "The smells of the one hundred and one different plants forms a unique fragrance."); + public QuestNurseryStall() { + super("Nursery", + "LeafIconSmall.png", + "The smells of the one hundred and one different plants forms a unique fragrance."); } @Override protected List populateItems() { - if (questData.getPlantLevel()>=6){ + QuestPetAbstract plant = questData.getPetManager().getPlant(); + + if (plant.getLevel() >= 6) { return new ArrayList(); } List itemList = new ArrayList(); - itemList.add(new QuestAbstractBazaarItem("Wall of plants", - getDesc(), - getPrice(), - GuiUtils.getIconFromFile(getImageString())) { + + itemList.add(new QuestAbstractBazaarItem(plant.getName(), + plant.getUpgradeDescription(), + plant.getUpgradePrice(), + GuiUtils.getIconFromFile(plant.getImageName())) { @Override public void purchaseItem() { - questData.addPlantLevel(); + questData.getPetManager().getPlant().incrementLevel(); } }); return itemList; } - private String getDesc() - { - StringBuilder sb = new StringBuilder(); - sb.append(""); - if (questData.getPlantLevel() == 0) - { - sb.append("
Start each of your battles with this lush, verdant plant on your side.
"); - sb.append("Excellent at blocking the nastiest of critters!

"); - sb.append("Current Level: Not purchased
"); - sb.append("Level 1: 0/1
"); - sb.append("Level 2: 0/2
"); - sb.append("Can learn: Deathtouch"); - } - else if (questData.getPlantLevel() == 1) - { - sb.append("Improve the toughness of your plant.
"); - sb.append("Current Level: 0/1
"); - sb.append("Level 2: 0/2
"); - sb.append("Level 3: 0/3
"); - sb.append("Can learn: Deathtouch"); - } - else if (questData.getPlantLevel() == 2) - { - sb.append("Improve the toughness of your plant.
"); - sb.append("Current Level: 0/2
"); - sb.append("Level 3: 0/3
"); - sb.append("Level 4: 1/3
"); - sb.append("Can learn: Deathtouch"); - } - else if (questData.getPlantLevel() == 3) - { - sb.append("Improve the power of your plant.
"); - sb.append("Current Level: 0/3
"); - sb.append("Level 4: 1/3
"); - sb.append("Level 5: Deathtouch
"); - sb.append("Can learn: Deathtouch"); - } - else if (questData.getPlantLevel() == 4) - { - sb.append("Grow venomous thorns on your plant.
"); - sb.append("Current Level: 1/3
"); - sb.append("Level 5: 1/3, Deathtouch
"); - sb.append("Level 6: 1/4, Deathtouch, Tap: you gain 1 life.
"); - } - else if (questData.getPlantLevel() == 5) - { - sb.append("As well as gaining more toughness,
"); - sb.append("your plant will have healing properties.
"); - sb.append("Current Level: 1/3, Deathtouch
"); - sb.append("Level 6: 1/4, Deathtouch, Tap: you gain 1 life."); - } - else - { - sb.append("Plant Level Maxed out."); - } - - sb.append(""); - return sb.toString(); - } - private int getPrice() - { - int l = 0; - if (questData.getPlantLevel() == 0) - l = 100; - else if (questData.getPlantLevel() == 1) - l = 150; - else if (questData.getPlantLevel() == 2) - l = 200; - else if (questData.getPlantLevel() == 3) - l = 300; - else if (questData.getPlantLevel() == 4) - l = 750; - else if (questData.getPlantLevel() == 5) - l = 1000; - return l; - } - - private String getImageString() - { - String s = ""; - if (questData.getPlantLevel() == 0) - s = "g_0_1_plant_wall_small.jpg"; - else if (questData.getPlantLevel() == 1) - s = "g_0_2_plant_wall_small.jpg"; - else if (questData.getPlantLevel() == 2) - s = "g_0_3_plant_wall_small.jpg"; - else if (questData.getPlantLevel() == 3) - s = "g_1_3_plant_wall_small.jpg"; - else if (questData.getPlantLevel() == 4) - s = "g_1_3_plant_wall_deathtouch_small.jpg"; - else if (questData.getPlantLevel() == 5) - s = "g_1_4_plant_wall_small.jpg"; - - return s; - } } diff --git a/src/forge/quest/gui/bazaar/QuestPetStall.java b/src/forge/quest/gui/bazaar/QuestPetStall.java index 5f7b7e7bb1f..c082f5e4020 100644 --- a/src/forge/quest/gui/bazaar/QuestPetStall.java +++ b/src/forge/quest/gui/bazaar/QuestPetStall.java @@ -1,8 +1,10 @@ package forge.quest.gui.bazaar; import forge.gui.GuiUtils; +import forge.quest.data.pet.QuestPetAbstract; import java.util.ArrayList; +import java.util.Collection; import java.util.List; public class QuestPetStall extends QuestAbstractBazaarStall { @@ -17,246 +19,25 @@ public class QuestPetStall extends QuestAbstractBazaarStall { protected List populateItems() { List itemList = new ArrayList(); - if (questData.getWolfPetLevel()<=3){ - itemList.add(new QuestAbstractBazaarItem("Wolf Pet", - getDesc(WOLF), - getPrice(WOLF), - GuiUtils.getIconFromFile(getImageString(WOLF))) { - @Override - public void purchaseItem() { - questData.addWolfPetLevel(); - } - }); - } - if (questData.getCrocPetLevel()<=3){ - itemList.add(new QuestAbstractBazaarItem("Crocodile Pet", - getDesc(CROC), - getPrice(CROC), - GuiUtils.getIconFromFile(getImageString(CROC))) { - @Override - public void purchaseItem() { - questData.addCrocPetLevel(); - } - }); - } - if (questData.getBirdPetLevel()<=3){ - itemList.add(new QuestAbstractBazaarItem("Bird Pet", - getDesc(BIRD), - getPrice(BIRD), - GuiUtils.getIconFromFile(getImageString(BIRD))) { - @Override - public void purchaseItem() { - questData.addBirdPetLevel(); - } - }); - } - if (questData.getHoundPetLevel()<=3){ - itemList.add(new QuestAbstractBazaarItem("Hound Pet", - getDesc(HOUND), - getPrice(HOUND), - GuiUtils.getIconFromFile(getImageString(HOUND))) { - @Override - public void purchaseItem() { - questData.addHoundPetLevel(); - } - }); + Collection pets = questData.getPetManager().getPets(); + + for (final QuestPetAbstract pet : pets) { + if (pet.getLevel() < pet.getMaxLevel()){ + itemList.add(new QuestAbstractBazaarItem( + pet.getName(), + pet.getUpgradeDescription(), + pet.getUpgradePrice(), + GuiUtils.getIconFromFile(pet.getImageName())) { + @Override + public void purchaseItem() { + questData.getPetManager().addPetLevel(pet.getName()); + } + }); + } } + return itemList; } - private String getDesc(int petType) { - StringBuilder sb = new StringBuilder(); - sb.append("
"); - switch (petType) { - case WOLF: - if (questData.getWolfPetLevel() == 0) { - sb.append("This ferocious animal may have been raised in captivity, but it has been trained to
kill.
"); - sb.append("Eats goblins for breakfast.

"); - sb.append("Level 1: 1/1
"); - sb.append("Next Level: 1/2
"); - sb.append("Can learn: Flanking"); - } else if (questData.getWolfPetLevel() == 1) { - sb.append("Improve the toughness of your wolf.
"); - sb.append("Level 2: 1/2
"); - sb.append("Next Level: 2/2
"); - sb.append("Can learn: Flanking"); - } else if (questData.getWolfPetLevel() == 2) { - sb.append("Improve the attack power of your wolf.
"); - sb.append("Level 3: 2/2
"); - sb.append("Next Level: Flanking
"); - sb.append("Can learn: Flanking"); - } else if (questData.getWolfPetLevel() == 3) { - sb.append("Gives Flanking to your wolf.
"); - sb.append("Level 4: 2/2 Flanking
"); - } - break; - case CROC: - if (questData.getCrocPetLevel() == 0) { - sb.append("With its razor sharp teeth, this swamp-dwelling monster is extremely dangerous.
"); - sb.append("Crikey mate!

"); - sb.append("Level 1: 1/1
"); - sb.append("Next Level: 2/1
"); - sb.append("Can learn: Swampwalk"); - } else if (questData.getCrocPetLevel() == 1) { - sb.append("Improve the attack power of your croc.
"); - sb.append("Level 2: 2/1
"); - sb.append("Next Level: 3/1
"); - sb.append("Can learn: Swampwalk"); - } else if (questData.getCrocPetLevel() == 2) { - sb.append("Improve the attack power of your croc.
"); - sb.append("Level 3: 3/1
"); - sb.append("Next Level: 3/1 Swampwalk
"); - } else if (questData.getCrocPetLevel() == 3) { - sb.append("Gives Swampwalk to your croc.
"); - sb.append("Level 4: 3/1 Swampwalk
"); - } - break; - case BIRD: - if (questData.getBirdPetLevel() == 0) { - sb.append("Unmatched in speed, agility and awareness,
"); - sb.append("this trained hawk makes a fantastic hunter.

"); - sb.append("Level 1: 0/1 Flying
"); - sb.append("Next Level: 1/1
"); - sb.append("Can learn: First strike"); - } else if (questData.getBirdPetLevel() == 1) { - sb.append("Improve the attack power of your bird.
"); - sb.append("Level 2: 1/1
"); - sb.append("Next Level: 2/1
"); - sb.append("Can learn: First strike"); - } else if (questData.getBirdPetLevel() == 2) { - sb.append("Improve the attack power of your bird.
"); - sb.append("Level 3: 2/1
"); - sb.append("Next Level: 2/1 First strike
"); - } else if (questData.getBirdPetLevel() == 3) { - sb.append("Gives First strike to your bird.
"); - sb.append("Level 4: 2/1 First strike
"); - } - break; - case HOUND: - if (questData.getHoundPetLevel() == 0) { - sb.append("Dogs are said to be man's best friend.
"); - sb.append("Definitely not this one.

"); - sb.append("Level 1: 1/1
"); - sb.append("Next Level: 1/1 Haste
"); - sb.append("Can learn: Whenever this creature attacks alone,
it gets +2/+0 until end of turn."); - } else if (questData.getHoundPetLevel() == 1) { - sb.append("Gives haste to your hound.
"); - sb.append("Level 2: 1/1 Haste
"); - sb.append("Next Level: 2/1 Haste
"); - sb.append("Can learn: Whenever this creature attacks alone,
it gets +2/+0 until end of turn."); - } else if (questData.getHoundPetLevel() == 2) { - sb.append("Improve the attack power of your hound.
"); - sb.append("Level 3: 2/1 Haste
"); - sb.append("Next Level: 2/1 Whenever this creature attacks
alone, it gets +2/+0 until end of turn.
"); - } else if (questData.getHoundPetLevel() == 3) { - sb.append("Greatly improves your hound's attack power if it
attacks alone.
"); - sb.append("Level 4: 2/1 Haste, whenever this creature attacks alone, it gets +2/+0 until end of turn.
"); - } - break; - } - - sb.append(""); - return sb.toString(); - } - - private int getPrice(int petType) { - int l = 0; - switch (petType) { - case WOLF: - if (questData.getWolfPetLevel() == 0) - l = 250; - else if (questData.getWolfPetLevel() == 1) - l = 250; - else if (questData.getWolfPetLevel() == 2) - l = 500; - else if (questData.getWolfPetLevel() == 3) - l = 550; - break; - case CROC: - if (questData.getCrocPetLevel() == 0) - l = 250; - else if (questData.getCrocPetLevel() == 1) - l = 300; - else if (questData.getCrocPetLevel() == 2) - l = 450; - else if (questData.getCrocPetLevel() == 3) - l = 600; - break; - case BIRD: - if (questData.getBirdPetLevel() == 0) - l = 200; - else if (questData.getBirdPetLevel() == 1) - l = 300; - else if (questData.getBirdPetLevel() == 2) - l = 450; - else if (questData.getBirdPetLevel() == 3) - l = 400; - break; - case HOUND: - if (questData.getHoundPetLevel() == 0) - l = 200; - else if (questData.getHoundPetLevel() == 1) - l = 350; - else if (questData.getHoundPetLevel() == 2) - l = 450; - else if (questData.getHoundPetLevel() == 3) - l = 750; - break; - } - return l; - } - - - private String getImageString(int petType) { - String s = null; - - switch (petType) { - case WOLF: - if (questData.getWolfPetLevel() == 0) - s = "g_1_1_wolf_pet_small.jpg"; - else if (questData.getWolfPetLevel() == 1) - s = "g_1_2_wolf_pet_small.jpg"; - else if (questData.getWolfPetLevel() == 2) - s = "g_2_2_wolf_pet_small.jpg"; - else if (questData.getWolfPetLevel() == 3) - s = "g_2_2_wolf_pet_flanking_small.jpg"; - break; - case CROC: - if (questData.getCrocPetLevel() == 0) - s = "b_1_1_crocodile_pet_small.jpg"; - else if (questData.getCrocPetLevel() == 1) - s = "b_2_1_crocodile_pet_small.jpg"; - else if (questData.getCrocPetLevel() == 2) - s = "b_3_1_crocodile_pet_small.jpg"; - else if (questData.getCrocPetLevel() == 3) - s = "b_3_1_crocodile_pet_swampwalk_small.jpg"; - break; - case BIRD: - if (questData.getBirdPetLevel() == 0) - s = "w_0_1_bird_pet_small.jpg"; - else if (questData.getBirdPetLevel() == 1) - s = "w_1_1_bird_pet_small.jpg"; - else if (questData.getBirdPetLevel() == 2) - s = "w_2_1_bird_pet_small.jpg"; - else if (questData.getBirdPetLevel() == 3) - s = "w_2_1_bird_pet_first_strike_small.jpg"; - case HOUND: - if (questData.getHoundPetLevel() == 0) - s = "r_1_1_hound_pet_small.jpg"; - else if (questData.getHoundPetLevel() == 1) - s = "r_1_1_hound_pet_haste_small.jpg"; - else if (questData.getHoundPetLevel() == 2) - s = "r_2_1_hound_pet_small.jpg"; - else if (questData.getHoundPetLevel() == 3) - s = "r_2_1_hound_pet_alone_small.jpg"; - break; - } - return s; - } - - public static final int WOLF = 1; - public static final int CROC = 2; - public static final int HOUND = 3; - public static final int BIRD = 4; } diff --git a/src/forge/quest/gui/main/QuestBattle.java b/src/forge/quest/gui/main/QuestBattle.java index 2f8b8b7dc52..156fe40435d 100644 --- a/src/forge/quest/gui/main/QuestBattle.java +++ b/src/forge/quest/gui/main/QuestBattle.java @@ -2,8 +2,8 @@ package forge.quest.gui.main; import forge.AllZone; -import forge.QuestData; import forge.gui.GuiUtils; +import forge.quest.data.QuestData; import javax.swing.*; import java.util.ArrayList; @@ -233,23 +233,23 @@ public class QuestBattle extends QuestSelectablePanel { public static List getBattles(){ List opponentList = new ArrayList(); - try{ QuestData questData = AllZone.QuestData; String[] opponentNames = questData.getOpponents(); for (String opponentName : opponentNames) { - String oppIconName = opponentName.substring(0, opponentName.length() - 1).trim() + ".jpg"; - ImageIcon icon = GuiUtils.getIconFromFile(oppIconName); + try { + String oppIconName = opponentName.substring(0, opponentName.length() - 1).trim() + ".jpg"; + ImageIcon icon = GuiUtils.getIconFromFile(oppIconName); - opponentList.add(new QuestBattle(opponentName, - nameDeckMap.get(opponentName).difficulty, - nameDeckMap.get(opponentName).description, - icon)); - } - } - catch (NullPointerException e) - { - System.out.println("Break Here"); + opponentList.add(new QuestBattle(opponentName, + nameDeckMap.get(opponentName).difficulty, + nameDeckMap.get(opponentName).description, + icon)); + } + catch (NullPointerException e) { + System.out.println("Caught NPE, Fix me:" + opponentName); + } } + return opponentList; } diff --git a/src/forge/quest/gui/main/QuestMainPanel.java b/src/forge/quest/gui/main/QuestMainPanel.java index b66776295ce..9579dfe1711 100644 --- a/src/forge/quest/gui/main/QuestMainPanel.java +++ b/src/forge/quest/gui/main/QuestMainPanel.java @@ -2,6 +2,7 @@ package forge.quest.gui.main; import forge.*; import forge.gui.GuiUtils; +import forge.quest.data.QuestData; import forge.quest.gui.QuestAbstractPanel; import forge.quest.gui.QuestFrame; @@ -14,17 +15,15 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; +import java.util.*; import java.util.List; -//presumes AllZone.QuestData is not null +//presumes AllZone.QuestDataOld is not null -//AllZone.QuestData should be set by Gui_QuestOptions +//AllZone.QuestDataOld should be set by Gui_QuestOptions public class QuestMainPanel extends QuestAbstractPanel { - private QuestData questData; + private forge.quest.data.QuestData questData; JLabel creditsLabel = new JLabel(); JLabel lifeLabel = new JLabel(); @@ -148,7 +147,7 @@ public class QuestMainPanel extends QuestAbstractPanel { cardShopButton.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 20)); JButton bazaarButton = null; - if (questData.getMode().equals(QuestData.FANTASY)) { + if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { bazaarButton = new JButton("Bazaar"); bazaarButton.addActionListener(new ActionListener() { @@ -192,7 +191,7 @@ public class QuestMainPanel extends QuestAbstractPanel { panel.add(Box.createVerticalGlue()); panel.add(Box.createVerticalGlue()); - if (questData.getMode().equals(QuestData.FANTASY)) { + if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { panel.add(this.lifeLabel); this.lifeLabel.setFont(new Font(Font.DIALOG, Font.BOLD, 14)); @@ -206,7 +205,7 @@ public class QuestMainPanel extends QuestAbstractPanel { GuiUtils.addGap(panel, 10); panel.add(cardShopButton); - if (questData.getMode().equals(QuestData.FANTASY)) { + if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { GuiUtils.addGap(panel); panel.add(bazaarButton); } @@ -274,17 +273,17 @@ public class QuestMainPanel extends QuestAbstractPanel { GuiUtils.addGap(matchPanel); - if (questData.getMode().equals(QuestData.FANTASY)) { + if (questData.getMode().equals(forge.quest.data.QuestData.FANTASY)) { 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.setSelectedPet((String) petComboBox.getSelectedItem()); + questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); } else { - questData.setSelectedPet("No Plant/Pet"); + questData.getPetManager().setSelectedPet(null); } petComboBox.setEnabled(petCheckBox.isSelected()); @@ -296,10 +295,10 @@ public class QuestMainPanel extends QuestAbstractPanel { this.petComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { if (petCheckBox.isSelected()) { - questData.setSelectedPet((String) petComboBox.getSelectedItem()); + questData.getPetManager().setSelectedPet((String) petComboBox.getSelectedItem()); } else { - questData.setSelectedPet("No Plant/Pet"); + questData.getPetManager().setSelectedPet(null); } } }); @@ -350,7 +349,7 @@ public class QuestMainPanel extends QuestAbstractPanel { } void refresh() { - QuestData.saveData(AllZone.QuestData); + AllZone.QuestData.saveData(); devModeCheckBox.setSelected(Constant.Runtime.DevMode[0]); smoothLandCheckBox.setSelected(Constant.Runtime.Smooth[0]); @@ -400,7 +399,7 @@ public class QuestMainPanel extends QuestAbstractPanel { petComboBox.removeAllItems(); - List petList = QuestUtil.getPetNames(questData); + Set petList = questData.getPetManager().getAvailablePetNames(); if (petList.size() > 0) { petComboBox.setEnabled(true); @@ -416,13 +415,13 @@ public class QuestMainPanel extends QuestAbstractPanel { petCheckBox.setEnabled(false); } - if (questData.getSelectedPet() == null || questData.getSelectedPet().equals("No Plant/Pet")) { + if (!questData.getPetManager().shouldPetBeUsed()) { petCheckBox.setSelected(false); petComboBox.setEnabled(false); } else { petCheckBox.setSelected(true); - petComboBox.setSelectedItem(questData.getSelectedPet()); + petComboBox.setSelectedItem(questData.getPetManager().getSelectedPet().getName()); } } @@ -462,7 +461,7 @@ public class QuestMainPanel extends QuestAbstractPanel { public void execute() { //saves all deck data - QuestData.saveData(AllZone.QuestData); + AllZone.QuestData.saveData(); new QuestFrame(); } @@ -485,7 +484,7 @@ public class QuestMainPanel extends QuestAbstractPanel { public void execute() { //saves all deck data - QuestData.saveData(AllZone.QuestData); + AllZone.QuestData.saveData(); new QuestFrame(); } @@ -549,9 +548,9 @@ public class QuestMainPanel extends QuestAbstractPanel { AllZone.GameAction.newGame( humanDeck, computer, - QuestUtil.getHumanPlantAndPet(questData), + forge.quest.data.QuestUtil.getHumanPlantAndPet(questData), new CardList(), - QuestUtil.getLife(questData), + questData.getLife(), 20, null); } @@ -573,7 +572,7 @@ public class QuestMainPanel extends QuestAbstractPanel { AllZone.GameAction.newGame( humanDeck, computerDeck, - QuestUtil.getHumanPlantAndPet(questData, selectedQuest), + forge.quest.data.QuestUtil.getHumanPlantAndPet(questData, selectedQuest), new CardList(), questData.getLife() + extraLife, selectedQuest.getComputerLife(), diff --git a/src/forge/quest/gui/main/QuestQuest.java b/src/forge/quest/gui/main/QuestQuest.java index 5208b822d53..1a5d85f340d 100644 --- a/src/forge/quest/gui/main/QuestQuest.java +++ b/src/forge/quest/gui/main/QuestQuest.java @@ -1,7 +1,6 @@ package forge.quest.gui.main; import forge.AllZone; -import forge.QuestData; import forge.Quest_Assignment; import forge.ReadQuest_Assignment; import forge.gui.GuiUtils; @@ -46,21 +45,21 @@ public class QuestQuest extends QuestSelectablePanel { } private static List readQuests() { - QuestData questData = AllZone.QuestData; + forge.quest.data.QuestData questData = AllZone.QuestData; ReadQuest_Assignment read = new ReadQuest_Assignment(ForgeProps.getFile(NewConstants.QUEST.QUESTS), questData); read.run(); - ArrayList questsToDisplay = new ArrayList(); + List questsToDisplay = new ArrayList(); if (questData.getAvailableQuests() != null && questData.getAvailableQuests().size() > 0) { - ArrayList availableQuests = read.getQuestsByIds(questData.getAvailableQuests()); + List availableQuests = read.getQuestsByIds(questData.getAvailableQuests()); questsToDisplay = availableQuests; } else { - ArrayList allAvailableQuests = read.getQuests(); + List allAvailableQuests = read.getQuests(); - ArrayList availableInts = new ArrayList(); + List availableInts = new ArrayList(); int maxQuests = questData.getWin() / 10; if (maxQuests > 5) { @@ -80,7 +79,7 @@ public class QuestQuest extends QuestSelectablePanel { questsToDisplay.add(qa); } questData.setAvailableQuests(availableInts); - QuestData.saveData(questData); + questData.saveData(); }//else return questsToDisplay; }