diff --git a/src/main/java/forge/GameAction.java b/src/main/java/forge/GameAction.java index 0b35004f1d6..3637d5df76a 100644 --- a/src/main/java/forge/GameAction.java +++ b/src/main/java/forge/GameAction.java @@ -1473,16 +1473,24 @@ public class GameAction { //Ante restricted to Quest Mode for now if (Singletons.getModel().getPreferences().isPlayForAnte()) { - Card humanAnte = CardUtil.getRandom(AllZone.getHumanPlayer().getCardsIn(Zone.Library).toArray()); - moveTo(Zone.Ante, humanAnte); - Card aiAnte = CardUtil.getRandom(AllZone.getComputerPlayer().getCardsIn(Zone.Library).toArray()); - moveTo(Zone.Ante, aiAnte); - final String nl = System.getProperty("line.separator"); final StringBuilder msg = new StringBuilder(); - msg.append("Human ante: ").append(humanAnte).append(nl); - msg.append("Computer ante: ").append(aiAnte).append(nl); - //msg.append("Cards in human ante: ").append(AllZone.getHumanPlayer().getCardsIn(Zone.Ante).get(0)); + for (Player p : AllZone.getPlayersInGame()) { + CardList lib = p.getCardsIn(Zone.Library); + Card ante; + if (lib.size() > 0 && lib.getNotType("Basic").size() > 1) { + ante = CardUtil.getRandom(lib.toArray()); + while (ante.isBasicLand()) { + ante = CardUtil.getRandom(lib.toArray()); + } + } else if (lib.size() > 1) { + ante = lib.get(0); + } else { + throw new RuntimeException(p + " library is empty."); + } + moveTo(Zone.Ante, ante); + msg.append(p.getName()).append(" ante: ").append(ante).append(nl); + } JOptionPane.showConfirmDialog(null, msg, "Ante", JOptionPane.OK_CANCEL_OPTION); } diff --git a/src/main/java/forge/quest/data/QuestUtilCards.java b/src/main/java/forge/quest/data/QuestUtilCards.java index 09df8351981..a4f647a9efa 100644 --- a/src/main/java/forge/quest/data/QuestUtilCards.java +++ b/src/main/java/forge/quest/data/QuestUtilCards.java @@ -213,11 +213,27 @@ public final class QuestUtilCards { * the price */ public void sellCard(final CardPrinted card, final int price) { + sellCard(card, price, true); + } + + /** + * Sell card. + * + * @param card + * the card + * @param price + * the price + * @param addToShop + * true if this card should be added to the shop, false otherwise + */ + public void sellCard(final CardPrinted card, final int price, final boolean addToShop) { if (price > 0) { this.q.setCredits(this.q.getCredits() + price); } this.q.getCardPool().remove(card); - this.q.getShopList().add(card); + if (addToShop) { + this.q.getShopList().add(card); + } // remove card being sold from all decks final int leftInPool = this.q.getCardPool().count(card); diff --git a/src/main/java/forge/quest/gui/QuestWinLoseHandler.java b/src/main/java/forge/quest/gui/QuestWinLoseHandler.java index 08a4300b2a1..0c705f0c55d 100644 --- a/src/main/java/forge/quest/gui/QuestWinLoseHandler.java +++ b/src/main/java/forge/quest/gui/QuestWinLoseHandler.java @@ -29,11 +29,14 @@ import javax.swing.JLabel; import javax.swing.SwingConstants; import forge.AllZone; +import forge.Card; import forge.CardList; import forge.Constant; +import forge.Constant.Zone; import forge.MyRandom; import forge.Player; import forge.SetUtils; +import forge.Singletons; import forge.control.ControlWinLose; import forge.game.GameEndReason; import forge.game.GameFormat; @@ -42,6 +45,7 @@ import forge.game.GamePlayerRating; import forge.game.GameSummary; import forge.gui.GuiUtils; import forge.gui.ListChooser; +import forge.item.CardDb; import forge.item.CardPrinted; import forge.quest.data.QuestData; import forge.quest.data.QuestMatchState; @@ -67,6 +71,7 @@ public class QuestWinLoseHandler extends ControlWinLose { private JLabel lblTemp1; private JLabel lblTemp2; private FSkin skin; + private boolean isAnte; /** The spacer. */ private final int spacer = 50; @@ -90,6 +95,7 @@ public class QuestWinLoseHandler extends ControlWinLose { this.model.qEvent = AllZone.getQuestEvent(); this.wonMatch = this.model.qMatchState.isMatchWonBy(AllZone.getHumanPlayer().getName()); this.skin = AllZone.getSkin(); + this.isAnte = Singletons.getModel().getPreferences().isPlayForAnte(); } /** @@ -139,10 +145,34 @@ public class QuestWinLoseHandler extends ControlWinLose { public final boolean populateCustomPanel() { this.getView().getBtnRestart().setVisible(false); this.model.qData.getCards().resetNewList(); + + //do per-game actions + if (this.model.qMatchState.hasWonLastGame(AllZone.getHumanPlayer().getName())) { + //add the computer's ante card to your card pool + if (isAnte) { + CardList antes = AllZone.getComputerPlayer().getCardsIn(Zone.Ante); + for (Card ante : antes) { + CardPrinted antePrinted = CardDb.instance().getCard(ante.getName(), ante.getCurSetCode()); + AllZone.getQuestData().getCardPool().add(antePrinted); + } + anteWon(antes); + + } + } else { + if (isAnte) { + CardList antes = AllZone.getHumanPlayer().getCardsIn(Zone.Ante); + for (Card ante : antes) { + CardPrinted antePrinted = CardDb.instance().getCard(ante.getName(), ante.getCurSetCode()); + //the last param here determines if this is added to the Card Shop + AllZone.getQuestData().getCards().sellCard(antePrinted, 0, false); + } + anteLost(antes); + } + } if (!this.model.qMatchState.isMatchOver()) { this.getView().getBtnQuit().setText("Quit (15 Credits)"); - return false; + return isAnte; } else { this.getView().getBtnContinue().setVisible(false); if (this.wonMatch) { @@ -193,6 +223,61 @@ public class QuestWinLoseHandler extends ControlWinLose { return true; } + /** + *
+ * anteLost. + *
+ * Displays cards lost to ante this game. + * + */ + private void anteLost(final CardList list) { + + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < list.size(); i++) { + sb.append(list.get(0)); + if (i < list.size() - 1) { + sb.append(" "); + } + } + // Generate Swing components and attach. + this.lblTemp1 = new TitleLabel("Oh no! You lost the following cards in Ante: " + sb.toString() + "."); + + //TODO - idea + //final QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon); + + this.getView().getPnlCustom() + .add(this.lblTemp1, "align center, width 95%!, " + "gaptop " + this.spacer + ", gapbottom 10"); + } + + /** + *+ * anteWon. + *
+ * Displays cards won in ante this game and added to your Card Pool. + * + */ + private void anteWon(final CardList list) { + + StringBuilder sb = new StringBuilder(); + sb.append("You have won the following cards in Ante: "); + for (int i = 0; i < list.size(); i++) { + sb.append(list.get(0)); + if (i < list.size() - 1) { + sb.append(" "); + } + } + sb.append(".\n"); + sb.append("They will be available to you in your card pool after this match."); + // Generate Swing components and attach. + this.lblTemp1 = new TitleLabel(sb.toString()); + + //TODO - idea + //final QuestWinLoseCardViewer cv = new QuestWinLoseCardViewer(cardsWon); + + this.getView().getPnlCustom() + .add(this.lblTemp1, "align center, width 95%!, " + "gaptop " + this.spacer + ", gapbottom 10"); + } + /** ** actionOnQuit.