From df71237f46239e3ec3772c324c582465557d68c5 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 30 Oct 2014 20:40:23 +0100 Subject: [PATCH] * Added logic to auto select replacement effects. Some changes to counter size and font size handling. --- .../mage/client/dialog/PickChoiceDialog.form | 28 ++++- .../mage/client/dialog/PickChoiceDialog.java | 108 +++++++++++++++--- .../main/java/mage/client/game/GamePanel.java | 104 +++++++++++++---- .../java/mage/client/game/PlayAreaPanel.java | 13 +++ .../client/remote/CallbackClientImpl.java | 32 +++--- .../java/org/mage/card/arcane/CardPanel.java | 38 +++++- .../src/mage/view/GameClientMessage.java | 11 ++ .../java/mage/player/ai/ComputerPlayer.java | 4 +- .../mage/player/ai/SimulatedPlayerMCTS.java | 4 +- .../src/mage/player/human/HumanPlayer.java | 60 +++++++--- .../java/mage/server/game/GameController.java | 9 +- .../java/mage/server/game/GameSession.java | 5 +- .../sets/modernmasters/DoublingSeason.java | 17 +-- .../org/mage/test/player/RandomPlayer.java | 2 +- .../java/org/mage/test/player/TestPlayer.java | 4 +- .../abilities/effects/ContinuousEffects.java | 17 ++- .../GainProtectionFromColorTargetEffect.java | 30 +++-- .../counter/AddCountersSourceEffect.java | 4 +- .../counter/AddCountersTargetEffect.java | 8 +- Mage/src/mage/choices/Choice.java | 7 +- Mage/src/mage/choices/ChoiceImpl.java | 35 ++++++ Mage/src/mage/constants/PlayerAction.java | 3 +- Mage/src/mage/game/Game.java | 2 +- Mage/src/mage/game/GameImpl.java | 4 +- .../mage/game/events/PlayerQueryEvent.java | 23 +++- .../game/events/PlayerQueryEventSource.java | 5 +- Mage/src/mage/players/Player.java | 2 +- Mage/src/mage/players/PlayerImpl.java | 6 +- 28 files changed, 445 insertions(+), 140 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form index daab703e12..5adaf97cd9 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form @@ -1,6 +1,13 @@
+ + + + + + + @@ -24,6 +31,9 @@ + + + @@ -37,21 +47,31 @@ + + - - - + + - + + + + + + + + + + diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java index db759e2c32..92a455cf6d 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java @@ -34,13 +34,15 @@ package mage.client.dialog; +import java.awt.Point; +import java.util.Map; +import java.util.UUID; +import javax.swing.JLayeredPane; +import mage.choices.Choice; import mage.client.MageFrame; import mage.client.util.SettingsManager; import mage.client.util.gui.GuiDisplayUtil; -import javax.swing.*; -import java.awt.*; - /** * * @author BetaSteward_at_googlemail.com @@ -52,10 +54,28 @@ public class PickChoiceDialog extends MageDialog { initComponents(); this.setModal(true); } + Choice choice; + boolean autoSelect; - public void showDialog(String message, String[] choices) { - this.lblMessage.setText(message); - this.lstChoices.setListData(choices); + public void showDialog(Choice choice, UUID objectId) { + this.lblMessage.setText("" + choice.getMessage()); + this.choice = choice; + this.autoSelect = false; + btnAutoSelect.setVisible(choice.isKeyChoice()); + + if (choice.isKeyChoice()){ + + ComboItem[] comboItems = new ComboItem[choice.getKeyChoices().size()]; + int count = 0; + for (Map.Entry entry : choice.getKeyChoices().entrySet()) { + comboItems[count] = new ComboItem(entry.getKey(), entry.getValue()); + count++; + } + this.lstChoices.setListData(comboItems); + } else { + this.lstChoices.setListData(choice.getChoices().toArray()); + } + MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER); Point centered = SettingsManager.getInstance().getComponentPosition(getWidth(), getHeight()); @@ -65,8 +85,21 @@ public class PickChoiceDialog extends MageDialog { this.setVisible(true); } - public String getChoice() { - return (String)this.lstChoices.getSelectedValue(); + public boolean isAutoSelect() { + return autoSelect; + } + + public void setChoice() { + if (this.lstChoices.getSelectedValue() == null) { + choice.clearChoice(); + } + + if (choice.isKeyChoice()) { + ComboItem item = (ComboItem)this.lstChoices.getSelectedValue(); + choice.setChoiceByKey(item.getValue()); + } else { + choice.setChoice((String)this.lstChoices.getSelectedValue()); + } } /** This method is called from within the constructor to @@ -78,12 +111,25 @@ public class PickChoiceDialog extends MageDialog { // //GEN-BEGIN:initComponents private void initComponents() { + btnAutoSelect = new javax.swing.JButton(); btnCancel = new javax.swing.JButton(); btnOk = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); lstChoices = new javax.swing.JList(); lblMessage = new javax.swing.JLabel(); + setResizable(true); + setMinimumSize(new java.awt.Dimension(280, 200)); + setName(""); // NOI18N + + btnAutoSelect.setText("Auto select"); + btnAutoSelect.setToolTipText("If you select an effect with \"Auto select\", this effect will be selected the next time automatically first."); + btnAutoSelect.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnAutoSelectActionPerformed(evt); + } + }); + btnCancel.setText("Cancel"); btnCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -117,6 +163,9 @@ public class PickChoiceDialog extends MageDialog { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(btnAutoSelect) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnOk) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnCancel)) @@ -126,30 +175,40 @@ public class PickChoiceDialog extends MageDialog { layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(lblMessage) + .addGap(6, 6, 6) + .addComponent(lblMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnCancel) - .addComponent(btnOk)) - .addContainerGap()) + .addComponent(btnOk) + .addComponent(btnAutoSelect)) + .addGap(10, 10, 10)) ); pack(); }// //GEN-END:initComponents private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed + setChoice(); this.hideDialog(); }//GEN-LAST:event_btnOkActionPerformed private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed this.lstChoices.clearSelection(); + this.choice.clearChoice(); this.hideDialog(); }//GEN-LAST:event_btnCancelActionPerformed + private void btnAutoSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAutoSelectActionPerformed + this.autoSelect = true; + setChoice(); + this.hideDialog(); + }//GEN-LAST:event_btnAutoSelectActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnAutoSelect; private javax.swing.JButton btnCancel; private javax.swing.JButton btnOk; private javax.swing.JScrollPane jScrollPane1; @@ -158,3 +217,26 @@ public class PickChoiceDialog extends MageDialog { // End of variables declaration//GEN-END:variables } + class ComboItem { + + private final String value; + private final String label; + + public ComboItem(String value, String label) { + this.value = value; + this.label = label; + } + + public String getValue() { + return this.value; + } + + public String getLabel() { + return this.label; + } + + @Override + public String toString() { + return label; + } + } \ No newline at end of file diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index 509962e833..28952255fe 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -27,8 +27,53 @@ */ package mage.client.game; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import javax.swing.AbstractAction; +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.ImageIcon; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JLayeredPane; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.KeyStroke; +import javax.swing.SwingWorker; +import javax.swing.border.EmptyBorder; +import javax.swing.border.LineBorder; +import javax.swing.plaf.basic.BasicSplitPaneDivider; +import javax.swing.plaf.basic.BasicSplitPaneUI; import mage.cards.Card; import mage.cards.action.ActionCallback; +import mage.choices.Choice; import mage.client.MageFrame; import mage.client.cards.BigCard; import mage.client.chat.ChatPanel; @@ -37,7 +82,12 @@ import mage.client.components.HoverButton; import mage.client.components.MageComponents; import mage.client.components.ext.dlg.DialogManager; import mage.client.components.layout.RelativeLayout; -import mage.client.dialog.*; +import mage.client.dialog.ExileZoneDialog; +import mage.client.dialog.PickChoiceDialog; +import mage.client.dialog.PickNumberDialog; +import mage.client.dialog.PickPileDialog; +import mage.client.dialog.PreferencesDialog; +import mage.client.dialog.ShowCardsDialog; import mage.client.game.FeedbackPanel.FeedbackMode; import mage.client.plugins.adapters.MageActionCallback; import mage.client.plugins.impl.Plugins; @@ -48,25 +98,31 @@ import mage.client.util.gui.ArrowBuilder; import mage.constants.Constants; import mage.constants.EnlargeMode; import mage.constants.PhaseStep; +import static mage.constants.PhaseStep.BEGIN_COMBAT; +import static mage.constants.PhaseStep.COMBAT_DAMAGE; +import static mage.constants.PhaseStep.DECLARE_ATTACKERS; +import static mage.constants.PhaseStep.DECLARE_BLOCKERS; +import static mage.constants.PhaseStep.DRAW; +import static mage.constants.PhaseStep.END_COMBAT; +import static mage.constants.PhaseStep.END_TURN; +import static mage.constants.PhaseStep.FIRST_COMBAT_DAMAGE; +import static mage.constants.PhaseStep.UNTAP; +import static mage.constants.PhaseStep.UPKEEP; +import mage.constants.PlayerAction; import mage.remote.Session; -import mage.view.*; +import mage.view.AbilityPickerView; +import mage.view.CardView; +import mage.view.CardsView; +import mage.view.ExileView; +import mage.view.GameView; +import mage.view.LookedAtView; +import mage.view.MatchView; +import mage.view.PlayerView; +import mage.view.RevealedView; +import mage.view.SimpleCardsView; import org.apache.log4j.Logger; import org.mage.plugins.card.utils.impl.ImageManagerImpl; -import javax.swing.*; -import javax.swing.GroupLayout.Alignment; -import javax.swing.border.LineBorder; -import javax.swing.plaf.basic.BasicSplitPaneDivider; -import javax.swing.plaf.basic.BasicSplitPaneUI; -import java.awt.*; -import java.awt.event.*; -import java.io.Serializable; -import java.util.*; -import java.util.List; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import javax.swing.border.EmptyBorder; -import mage.constants.PlayerAction; /** * @@ -797,11 +853,19 @@ public final class GamePanel extends javax.swing.JPanel { } } - public void getChoice(String message, String[] choices) { + public void getChoice(Choice choice, UUID objectId) { hideAll(); PickChoiceDialog pickChoice = new PickChoiceDialog(); - pickChoice.showDialog(message, choices); - session.sendPlayerString(gameId, pickChoice.getChoice()); + pickChoice.showDialog(choice, objectId); + if (choice.isKeyChoice()) { + if (pickChoice.isAutoSelect()) { + session.sendPlayerString(gameId, "#" + choice.getChoiceKey()); + } else { + session.sendPlayerString(gameId, choice.getChoiceKey()); + } + } else { + session.sendPlayerString(gameId, choice.getChoice()); + } pickChoice.removeDialog(); } @@ -1367,7 +1431,7 @@ public final class GamePanel extends javax.swing.JPanel { .addComponent(phasesContainer, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) ) //.addPreferredGap(ComponentPlacement.RELATED) - .addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING) + .addGroup(gl_jPanel3.createParallelGroup(Alignment.TRAILING) .addGroup(gl_jPanel3.createSequentialGroup() .addComponent(pnlShortCuts, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addGap(0) diff --git a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java index baf160d585..3288a5dd0d 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java @@ -216,6 +216,19 @@ public class PlayAreaPanel extends javax.swing.JPanel { } }); + + menuItem = new JMenuItem("Replacement effects - reset auto select"); + menuItem.setMnemonic(KeyEvent.VK_R); + menuItem.setToolTipText("Reset all effects that were added to the list of auto select replacement effects this game."); + popupMenu.add(menuItem); + // Reset the replacement effcts that were auto selected for the game + menuItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + gamePanel.getSession().sendPlayerAction(PlayerAction.RESET_AUTO_SELECT_REPLACEMENT_EFFECTS, gameId); + } + }); + popupMenu.addSeparator(); menuItem = new JMenuItem("Concede game"); diff --git a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java index adc8a2d4ac..1ebde4bdb9 100644 --- a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java +++ b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java @@ -32,6 +32,7 @@ import java.util.UUID; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import mage.cards.decks.Deck; +import mage.choices.Choice; import mage.client.MageFrame; import mage.client.chat.ChatPanel; import static mage.client.chat.ChatPanel.ChatType.TABLES; @@ -72,7 +73,7 @@ public class CallbackClientImpl implements CallbackClient { private static final Logger logger = Logger.getLogger(CallbackClientImpl.class); private final MageFrame frame; private int messageId = 0; -// private int gameInformMessageId = 0; + private int gameInformMessageId = 0; public CallbackClientImpl(MageFrame frame) { this.frame = frame; @@ -244,12 +245,13 @@ public class CallbackClientImpl implements CallbackClient { panel.pickPile(message.getMessage(), message.getPile1(), message.getPile2()); } break; } - case "gameChoose": + case "gameChooseChoice": { GameClientMessage message = (GameClientMessage) callback.getData(); GamePanel panel = MageFrame.getGame(callback.getObjectId()); + if (panel != null) { - panel.getChoice(message.getMessage(), message.getStrings()); + panel.getChoice(message.getChoice(), callback.getObjectId()); } break; } case "gamePlayMana": @@ -292,20 +294,20 @@ public class CallbackClientImpl implements CallbackClient { JOptionPane.showMessageDialog(null, messageData.get(1), messageData.get(0), JOptionPane.WARNING_MESSAGE); } break; case "gameInform": -// if (callback.getMessageId() > gameInformMessageId) { - { - GameClientMessage message = (GameClientMessage) callback.getData(); - GamePanel panel = MageFrame.getGame(callback.getObjectId()); - if (panel != null) { - panel.inform(message.getMessage(), message.getGameView(), callback.getMessageId()); + if (callback.getMessageId() > gameInformMessageId) { + { + GameClientMessage message = (GameClientMessage) callback.getData(); + GamePanel panel = MageFrame.getGame(callback.getObjectId()); + if (panel != null) { + panel.inform(message.getMessage(), message.getGameView(), callback.getMessageId()); + } } - } // no longer needed because phase skip handling on server side now -// } else { -// logger.warn(new StringBuilder("message out of sequence - ignoring").append("MessageId = ").append(callback.getMessageId()).append(" method = ").append(callback.getMethod())); -// //logger.warn("message out of sequence - ignoring"); -// } -// gameInformMessageId = messageId; + } else { + logger.warn(new StringBuilder("message out of sequence - ignoring").append("MessageId = ").append(callback.getMessageId()).append(" method = ").append(callback.getMethod())); + //logger.warn("message out of sequence - ignoring"); + } + gameInformMessageId = messageId; break; case "gameInformPersonal": { diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java index 9f8bd91896..0aa108f445 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanel.java @@ -12,6 +12,8 @@ import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; @@ -60,7 +62,7 @@ import org.mage.plugins.card.utils.impl.ImageManagerImpl; * @author arcane, nantuko, noxx */ @SuppressWarnings({"unchecked", "rawtypes"}) -public class CardPanel extends MagePermanent implements MouseListener, MouseMotionListener, MouseWheelListener { +public class CardPanel extends MagePermanent implements MouseListener, MouseMotionListener, MouseWheelListener, ComponentListener { private static final long serialVersionUID = -3272134219262184410L; private static final Logger log = Logger.getLogger(CardPanel.class); @@ -83,6 +85,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti private static final float ROT_CENTER_TO_BOTTOM_CORNER = 0.7071067811865475244008443621048f; public CardView gameCard; + public CardView updateCard; // for two faced cards public CardView temporary; @@ -259,7 +262,8 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti addMouseListener(this); addMouseMotionListener(this); addMouseWheelListener(this); - + addComponentListener(this); + displayTitleAnyway = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_CARD_NAMES, "true").equals("true"); titleText = new GlowText(); setText(gameCard); @@ -532,7 +536,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti } @Override - public void layout() { + public void doLayout() { int borderSize = Math.round(cardWidth * BLACK_BORDER_SIZE); imagePanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize); imagePanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2); @@ -764,6 +768,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti @Override public void update(CardView card) { + this.updateCard = card; if (isPermanent && (card instanceof PermanentView)) { boolean needsTapping = isTapped() != ((PermanentView) card).isTapped(); boolean needsFlipping = isFlipped() != ((PermanentView) card).isFlipped(); @@ -886,7 +891,8 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti private static ImageIcon getCounterImageWithAmount(int amount, BufferedImage image, int cardWidth) { int factor = cardWidth > WIDTH_LIMIT ? 2 :1; int xOffset = amount > 9 ? 2 : 5; - int fontSize = amount < 10 ? 9 : amount < 100 ? 9 : 8; + int fontSize = factor == 1 ? amount < 10 ? 12 : amount < 100 ? 10 : amount < 1000 ? 7: 6 + :amount < 10 ? 19 : amount < 100 ? 15 : amount < 1000 ? 12: amount < 10000 ?9 : 8; BufferedImage newImage; if (cardWidth > WIDTH_LIMIT) { newImage = ImageManagerImpl.deepCopy(image); @@ -895,7 +901,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti } Graphics graphics = newImage.getGraphics(); graphics.setColor(Color.BLACK); - graphics.setFont(new Font("Arial Black", Font.BOLD, factor * fontSize )); + graphics.setFont(new Font("Arial Black", amount > 100 ? Font.PLAIN : Font.BOLD, fontSize )); graphics.drawString(Integer.toString(amount), xOffset * factor, 11 * factor); return new ImageIcon(newImage); } @@ -1151,4 +1157,26 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti public JPanel getCardArea() { return cardArea; } + + @Override + public void componentResized(ComponentEvent ce) { + doLayout(); + if (updateCard != null) { + update(updateCard); + } + } + + @Override + public void componentMoved(ComponentEvent ce) { + } + + @Override + public void componentShown(ComponentEvent ce) { + } + + @Override + public void componentHidden(ComponentEvent ce) { + } + + } diff --git a/Mage.Common/src/mage/view/GameClientMessage.java b/Mage.Common/src/mage/view/GameClientMessage.java index aa27e0fe72..33af5e25e9 100644 --- a/Mage.Common/src/mage/view/GameClientMessage.java +++ b/Mage.Common/src/mage/view/GameClientMessage.java @@ -32,6 +32,7 @@ import java.io.Serializable; import java.util.Map; import java.util.Set; import java.util.UUID; +import mage.choices.Choice; /** * @@ -50,6 +51,7 @@ public class GameClientMessage implements Serializable { private int min; private int max; private Map options; + private Choice choice; public GameClientMessage(GameView gameView) { this.gameView = gameView; @@ -101,6 +103,10 @@ public class GameClientMessage implements Serializable { this.message = name; } + public GameClientMessage(Choice choice) { + this.choice = choice; + } + public GameView getGameView() { return gameView; } @@ -144,4 +150,9 @@ public class GameClientMessage implements Serializable { public Map getOptions() { return options; } + + public Choice getChoice() { + return choice; + } + } diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index e385ec6dc9..074d582633 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -1336,8 +1336,8 @@ public class ComputerPlayer extends PlayerImpl implements Player { } @Override - public int chooseEffect(List rEffects, Game game) { - log.debug("chooseEffect"); + public int chooseReplacementEffect(Map rEffects, Game game) { + log.debug("chooseReplacementEffect"); //TODO: implement this return 0; } diff --git a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java index 55fcc4b86a..139710ad9d 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java +++ b/Mage.Server.Plugins/Mage.Player.AIMCTS/src/mage/player/ai/SimulatedPlayerMCTS.java @@ -375,11 +375,11 @@ public class SimulatedPlayerMCTS extends MCTSPlayer { } @Override - public int chooseEffect(List rEffects, Game game) { + public int chooseReplacementEffect(Map rEffects, Game game) { if (this.isHuman()) { return rnd.nextInt(rEffects.size()); } - return super.chooseEffect(rEffects, game); + return super.chooseReplacementEffect(rEffects, game); } @Override diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index 03f040f2a6..b7ed748b06 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -82,6 +82,7 @@ public class HumanPlayer extends PlayerImpl { protected static FilterAttackingCreature filterAttack = new FilterAttackingCreature(); protected static FilterBlockingCreature filterBlock = new FilterBlockingCreature(); protected static final Choice replacementEffectChoice = new ChoiceImpl(true); + private static final Map staticOptions = new HashMap<>(); private static final Logger log = Logger.getLogger(HumanPlayer.class); @@ -91,6 +92,8 @@ public class HumanPlayer extends PlayerImpl { staticOptions.put("UI.right.btn.text", "Done"); } + protected HashSet autoSelectReplacementEffects = new HashSet<>(); + public HumanPlayer(String name, RangeOfInfluence range, int skill) { super(name, range); human = true; @@ -167,29 +170,43 @@ public class HumanPlayer extends PlayerImpl { } @Override - public int chooseEffect(List rEffects, Game game) { + public int chooseReplacementEffect(Map rEffects, Game game) { updateGameStatePriority("chooseEffect", game); - replacementEffectChoice.getChoices().clear(); - int count = 1; - for (String effectText: rEffects) { - replacementEffectChoice.getChoices().add(count + ". " + effectText); - count++; - } - if (replacementEffectChoice.getChoices().size() == 1) { + if (rEffects.size() == 1) { return 0; } + if (!autoSelectReplacementEffects.isEmpty()) { + for (String autoKey :autoSelectReplacementEffects) { + int count = 0; + for (String effectKey : rEffects.keySet()) { + if (effectKey.equals(autoKey)) { + return count; + } + count++; + } + } + } + + replacementEffectChoice.getChoices().clear(); + replacementEffectChoice.setKeyChoices(rEffects); + while (!abort) { - game.fireChooseEvent(playerId, replacementEffectChoice); + game.fireChooseChoiceEvent(playerId, replacementEffectChoice); waitForResponse(game); log.debug("Choose effect: " + response.getString()); if (response.getString() != null) { - replacementEffectChoice.setChoice(response.getString()); - count = 1; - for (int i = 0; i < rEffects.size(); i++) { - if (replacementEffectChoice.getChoice().equals(count + ". " + rEffects.get(i))) { - return i; + if (response.getString().startsWith("#")) { + autoSelectReplacementEffects.add(response.getString().substring(1)); + replacementEffectChoice.setChoiceByKey(response.getString().substring(1)); + } else { + replacementEffectChoice.setChoiceByKey(response.getString()); + } + int index = 0; + for (String key : rEffects.keySet()) { + if (replacementEffectChoice.getChoiceKey().equals(key)) { + return index; } - count++; + index++; } } } @@ -200,7 +217,7 @@ public class HumanPlayer extends PlayerImpl { public boolean choose(Outcome outcome, Choice choice, Game game) { updateGameStatePriority("choose(3)", game); while (!abort) { - game.fireChooseEvent(playerId, choice); + game.fireChooseChoiceEvent(playerId, choice); waitForResponse(game); if (response.getString() != null) { choice.setChoice(response.getString()); @@ -895,7 +912,7 @@ public class HumanPlayer extends PlayerImpl { game.fireGetAmountEvent(playerId, message, min, max); waitForIntegerResponse(game); if (response != null && response.getInteger() != null) { - return response.getInteger().intValue(); + return response.getInteger(); } else { return 0; } @@ -1106,5 +1123,12 @@ public class HumanPlayer extends PlayerImpl { game.getState().setPriorityPlayerId(getId()); } - + @Override + public void sendPlayerAction(PlayerAction playerAction, Game game) { + if (PlayerAction.RESET_AUTO_SELECT_REPLACEMENT_EFFECTS.equals(playerAction)) { + autoSelectReplacementEffects.clear(); + } else { + super.sendPlayerAction(playerAction, game); + } + } } diff --git a/Mage.Server/src/main/java/mage/server/game/GameController.java b/Mage.Server/src/main/java/mage/server/game/GameController.java index ce0a7d3f8f..4e97440c60 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameController.java +++ b/Mage.Server/src/main/java/mage/server/game/GameController.java @@ -65,6 +65,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.zip.GZIPOutputStream; +import mage.choices.Choice; import mage.constants.PlayerAction; /** @@ -215,8 +216,8 @@ public class GameController implements GameCallback { case CHOOSE_MODE: chooseMode(event.getPlayerId(), event.getModes()); break; - case CHOOSE: - choose(event.getPlayerId(), event.getMessage(), event.getChoices()); + case CHOOSE_CHOICE: + chooseChoice(event.getPlayerId(), event.getChoice()); break; case AMOUNT: amount(event.getPlayerId(), event.getMessage(), event.getMin(), event.getMax()); @@ -582,11 +583,11 @@ public class GameController implements GameCallback { }); } - private synchronized void choose(UUID playerId, final String message, final Set choices) throws MageException { + private synchronized void chooseChoice(UUID playerId, final Choice choice) throws MageException { perform(playerId, new Command() { @Override public void execute(UUID playerId) { - getGameSession(playerId).choose(message, choices); + getGameSession(playerId).chooseChoice(choice); } }); } diff --git a/Mage.Server/src/main/java/mage/server/game/GameSession.java b/Mage.Server/src/main/java/mage/server/game/GameSession.java index 3ba8c37f1d..3961856433 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameSession.java +++ b/Mage.Server/src/main/java/mage/server/game/GameSession.java @@ -48,6 +48,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import mage.choices.Choice; import mage.game.Table; /** @@ -123,12 +124,12 @@ public class GameSession extends GameWatcher { } } - public void choose(final String message, final Set choices) { + public void chooseChoice(final Choice choice) { if (!killed) { setupTimeout(); User user = UserManager.getInstance().getUser(userId); if (user != null) { - user.fireCallback(new ClientCallback("gameChoose", game.getId(), new GameClientMessage(choices.toArray(new String[choices.size()]), message))); + user.fireCallback(new ClientCallback("gameChooseChoice", game.getId(), new GameClientMessage(choice))); } } } diff --git a/Mage.Sets/src/mage/sets/modernmasters/DoublingSeason.java b/Mage.Sets/src/mage/sets/modernmasters/DoublingSeason.java index f67df70877..08618b0a05 100644 --- a/Mage.Sets/src/mage/sets/modernmasters/DoublingSeason.java +++ b/Mage.Sets/src/mage/sets/modernmasters/DoublingSeason.java @@ -126,26 +126,13 @@ class DoublingSeasonCounterEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - Permanent p = game.getPermanent(event.getTargetId()); - String counterName = event.getData(); - if (p != null && counterName != null) { - Counter counter; - if (counterName.equals("+1/+1")) { - counter = CounterType.P1P1.createInstance(event.getAmount() * 2); - } else if (counterName.equals("-1/-1")) { - counter = CounterType.M1M1.createInstance(event.getAmount() * 2); - } else { - counter = new Counter(counterName, event.getAmount() * 2); - } - p.addCounters(counter, game, event.getAppliedEffects()); - return true; - } + event.setAmount(event.getAmount() * 2); return false; } @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event.getType() == GameEvent.EventType.ADD_COUNTER) { + if (event.getType() == GameEvent.EventType.ADD_COUNTERS) { Permanent target = game.getPermanent(event.getTargetId()); if (target != null && target.getControllerId().equals(source.getControllerId())) { return true; diff --git a/Mage.Tests/src/test/java/org/mage/test/player/RandomPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/RandomPlayer.java index d9e6ebf605..29b8faed42 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/RandomPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/RandomPlayer.java @@ -356,7 +356,7 @@ public class RandomPlayer extends ComputerPlayer { } @Override - public int chooseEffect(List rEffects, Game game) { + public int chooseReplacementEffect(Map rEffects, Game game) { return rnd.nextInt(rEffects.size()); } diff --git a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java index b369533c5b..8e41f1a854 100644 --- a/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java +++ b/Mage.Tests/src/test/java/org/mage/test/player/TestPlayer.java @@ -283,7 +283,7 @@ public class TestPlayer extends ComputerPlayer { } @Override - public int chooseEffect(List rEffects, Game game) { + public int chooseReplacementEffect(Map rEffects, Game game) { if (!choices.isEmpty()) { for (String choice: choices) { for (int index = 0; index < rEffects.size(); index++) { @@ -294,7 +294,7 @@ public class TestPlayer extends ComputerPlayer { } } } - return super.chooseEffect(rEffects, game); + return super.chooseReplacementEffect(rEffects, game); } @Override diff --git a/Mage/src/mage/abilities/effects/ContinuousEffects.java b/Mage/src/mage/abilities/effects/ContinuousEffects.java index 8d291fa63b..cbe82a1564 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffects.java @@ -37,6 +37,7 @@ import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -675,7 +676,7 @@ public class ContinuousEffects implements Serializable { } else { //20100716 - 616.1c Player player = game.getPlayer(event.getPlayerId()); - index = player.chooseEffect(getReplacementEffectsTexts(rEffects, game), game); + index = player.chooseReplacementEffect(getReplacementEffectsTexts(rEffects, game), game); } // get the selected effect int checked = 0; @@ -867,7 +868,10 @@ public class ContinuousEffects implements Serializable { } public void addEffect(ContinuousEffect effect, Ability source) { - if (source == null && effect != null) { + if (effect == null) { + logger.error("Effect is null: " + source.toString()); + return; + } else if (source == null) { logger.warn("Adding effect without ability : " +effect.toString()); } switch (effect.getEffectType()) { @@ -980,16 +984,17 @@ public class ContinuousEffects implements Serializable { return effects; } - public List getReplacementEffectsTexts(HashMap> rEffects, Game game) { - List texts = new ArrayList<>(); + + public Map getReplacementEffectsTexts(HashMap> rEffects, Game game) { + Map texts = new LinkedHashMap<>(); for (Map.Entry> entry : rEffects.entrySet()) { if (entry.getValue() != null) { for (Ability ability :entry.getValue()) { MageObject object = game.getObject(ability.getSourceId()); if (object != null) { - texts.add(ability.getRule(object.getLogName())); + texts.put(ability.getId().toString() + "_" + entry.getKey().getId().toString(), ability.getRule(object.getLogName())); } else { - texts.add(entry.getKey().getText(null)); + texts.put(ability.getId().toString() + "_" + entry.getKey().getId().toString(), entry.getKey().getText(null)); } } } else { diff --git a/Mage/src/mage/abilities/effects/common/continious/GainProtectionFromColorTargetEffect.java b/Mage/src/mage/abilities/effects/common/continious/GainProtectionFromColorTargetEffect.java index 7b6011a44c..860938fb21 100644 --- a/Mage/src/mage/abilities/effects/common/continious/GainProtectionFromColorTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/continious/GainProtectionFromColorTargetEffect.java @@ -28,6 +28,7 @@ package mage.abilities.effects.common.continious; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.keyword.ProtectionAbility; @@ -64,16 +65,27 @@ public class GainProtectionFromColorTargetEffect extends GainAbilityTargetEffect } @Override - public boolean apply(Game game, Ability source) { - Permanent creature = game.getPermanent(source.getFirstTarget()); - Player player = game.getPlayer(source.getControllerId()); - if (creature != null && player != null) { + public void init(Ability source, Game game) { + super.init(source, game); //To change body of generated methods, choose Tools | Templates. + MageObject sourceObject = game.getObject(source.getSourceId()); + Player controller = game.getPlayer(source.getControllerId()); + if (sourceObject != null && controller != null) { while (!choice.isChosen()) { - player.choose(Outcome.Protect, choice, game); - if (!player.isInGame()) { - return false; + controller.choose(Outcome.Protect, choice, game); + if (!controller.isInGame()) { + return; } } + if (choice.isChosen()) { + game.informPlayers(sourceObject.getLogName() + ": " + controller.getName() + " has chosen protection from " + choice.getChoice()); + } + } + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source)); + if (creature != null) { FilterCard protectionFilter = (FilterCard)((ProtectionAbility)ability).getFilter(); protectionFilter.add(new ColorPredicate(choice.getColor())); protectionFilter.setMessage(choice.getChoice()); @@ -89,8 +101,6 @@ public class GainProtectionFromColorTargetEffect extends GainAbilityTargetEffect if (staticText != null && !staticText.isEmpty()) { return staticText; } - else { - return "target creature you control gains protection from the color of your choice " + duration.toString(); - } + return "target creature you control gains protection from the color of your choice " + duration.toString(); } } diff --git a/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java b/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java index fbc1fadead..cc04782471 100644 --- a/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/counter/AddCountersSourceEffect.java @@ -120,11 +120,13 @@ public class AddCountersSourceEffect extends OneShotEffect { countersToAdd--; } newCounter.add(countersToAdd); + int before = permanent.getCounters().getCount(newCounter.getName()); permanent.addCounters(newCounter, game); + int amountAdded = permanent.getCounters().getCount(newCounter.getName()) - before; if (informPlayers) { Player player = game.getPlayer(source.getControllerId()); if (player != null) { - game.informPlayers(new StringBuilder(player.getName()).append(" puts ").append(newCounter.getCount()).append(" ").append(newCounter.getName().toLowerCase()).append(" counter on ").append(permanent.getLogName()).toString()); + game.informPlayers(player.getName()+" puts "+amountAdded+" "+newCounter.getName().toLowerCase()+" counter on "+permanent.getLogName()); } } } diff --git a/Mage/src/mage/abilities/effects/common/counter/AddCountersTargetEffect.java b/Mage/src/mage/abilities/effects/common/counter/AddCountersTargetEffect.java index d37eaf8794..bc1f96414f 100644 --- a/Mage/src/mage/abilities/effects/common/counter/AddCountersTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/counter/AddCountersTargetEffect.java @@ -91,12 +91,12 @@ public class AddCountersTargetEffect extends OneShotEffect { if (counter != null) { Counter newCounter = counter.copy(); newCounter.add(amount.calculate(game, source, this)); + int before = permanent.getCounters().getCount(counter.getName()); permanent.addCounters(newCounter, game); + int numberAdded = permanent.getCounters().getCount(counter.getName()) - before; affectedTargets ++; - game.informPlayers(new StringBuilder(sourceObject.getLogName()).append(": ") - .append(controller.getName()).append(" puts ") - .append(counter.getCount()).append(" ").append(counter.getName().toLowerCase()) - .append(" counter on ").append(permanent.getLogName()).toString()); + game.informPlayers(sourceObject.getLogName() +": "+ controller.getName()+ " puts " + + numberAdded + " " + counter.getName().toLowerCase() + " counter on " + permanent.getLogName()); } } else { Player player = game.getPlayer(uuid); diff --git a/Mage/src/mage/choices/Choice.java b/Mage/src/mage/choices/Choice.java index 55671a168d..9a20c066bb 100644 --- a/Mage/src/mage/choices/Choice.java +++ b/Mage/src/mage/choices/Choice.java @@ -28,6 +28,7 @@ package mage.choices; +import java.util.Map; import java.util.Set; /** @@ -42,9 +43,13 @@ public interface Choice { String getMessage(); void setMessage(String message); void setChoice(String choice); + void setChoiceByKey(String choiceKey); Set getChoices(); + Map getKeyChoices(); void setChoices(Set choices); + void setKeyChoices(Map choices); String getChoice(); - + String getChoiceKey(); + boolean isKeyChoice(); Choice copy(); } diff --git a/Mage/src/mage/choices/ChoiceImpl.java b/Mage/src/mage/choices/ChoiceImpl.java index f78ad0543d..34512c6fe6 100644 --- a/Mage/src/mage/choices/ChoiceImpl.java +++ b/Mage/src/mage/choices/ChoiceImpl.java @@ -29,7 +29,9 @@ package mage.choices; import java.io.Serializable; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.Map; import java.util.Set; /** @@ -41,7 +43,9 @@ public class ChoiceImpl implements Choice, Serializable { protected boolean chosen; protected boolean required; protected String choice; + protected String choiceKey; protected Set choices = new LinkedHashSet<>(); + protected Map keyChoices = new LinkedHashMap<>(); protected String message; public ChoiceImpl() { @@ -58,6 +62,8 @@ public class ChoiceImpl implements Choice, Serializable { this.required = choice.required; this.message = choice.message; this.choices.addAll(choice.choices); + this.choiceKey = choice.choiceKey; + this.keyChoices = choice.keyChoices; // list should never change for the same object so copy by reference } @Override @@ -114,4 +120,33 @@ public class ChoiceImpl implements Choice, Serializable { return new ChoiceImpl(this); } + @Override + public Map getKeyChoices() { + return keyChoices; + } + + @Override + public void setKeyChoices(Map choices) { + keyChoices = choices; + } + + @Override + public String getChoiceKey() { + return choiceKey; + } + + @Override + public void setChoiceByKey(String choiceKey) { + String choiceToSet = keyChoices.get(choiceKey); + if (choiceToSet != null) { + this.choice = choiceToSet; + this.choiceKey = choiceKey; + } + } + + @Override + public boolean isKeyChoice() { + return !keyChoices.isEmpty(); + } + } diff --git a/Mage/src/mage/constants/PlayerAction.java b/Mage/src/mage/constants/PlayerAction.java index 0767f916ee..6763936ad9 100644 --- a/Mage/src/mage/constants/PlayerAction.java +++ b/Mage/src/mage/constants/PlayerAction.java @@ -41,5 +41,6 @@ public enum PlayerAction { UNDO, CONCEDE, MANA_AUTO_PAYMENT_ON, - MANA_AUTO_PAYMENT_OFF + MANA_AUTO_PAYMENT_OFF, + RESET_AUTO_SELECT_REPLACEMENT_EFFECTS } \ No newline at end of file diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index 147f8199da..e17580beea 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -153,7 +153,7 @@ public interface Game extends MageItem, Serializable { void addTableEventListener(Listener listener); void addPlayerQueryEventListener(Listener listener); void fireAskPlayerEvent(UUID playerId, String message); - void fireChooseEvent(UUID playerId, Choice choice); + void fireChooseChoiceEvent(UUID playerId, Choice choice); void fireSelectTargetEvent(UUID playerId, String message, Set targets, boolean required, Map options); void fireSelectTargetEvent(UUID playerId, String message, Cards cards, boolean required, Map options); void fireSelectTargetEvent(UUID playerId, String message, List abilities); diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 2ba22c3fc3..cede4c13f2 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -1794,11 +1794,11 @@ public abstract class GameImpl implements Game, Serializable { } @Override - public void fireChooseEvent(UUID playerId, Choice choice) { + public void fireChooseChoiceEvent(UUID playerId, Choice choice) { if (simulation) { return; } - playerQueryEventSource.choose(playerId, choice.getMessage(), choice.getChoices()); + playerQueryEventSource.chooseChoice(playerId, choice); } @Override diff --git a/Mage/src/mage/game/events/PlayerQueryEvent.java b/Mage/src/mage/game/events/PlayerQueryEvent.java index bbb33b30f6..894bac0560 100644 --- a/Mage/src/mage/game/events/PlayerQueryEvent.java +++ b/Mage/src/mage/game/events/PlayerQueryEvent.java @@ -37,6 +37,7 @@ import mage.game.permanent.Permanent; import java.io.Serializable; import java.util.*; +import mage.choices.Choice; /** * @@ -45,7 +46,7 @@ import java.util.*; public class PlayerQueryEvent extends EventObject implements ExternalEvent, Serializable { public enum QueryType { - ASK, CHOOSE, CHOOSE_ABILITY, CHOOSE_MODE, PICK_TARGET, PICK_ABILITY, SELECT, PLAY_MANA, PLAY_X_MANA, AMOUNT, PICK_CARD, CONSTRUCT, CHOOSE_PILE, PERSONAL_MESSAGE + ASK, CHOOSE_CHOICE, CHOOSE_ABILITY, CHOOSE_MODE, PICK_TARGET, PICK_ABILITY, SELECT, PLAY_MANA, PLAY_X_MANA, AMOUNT, PICK_CARD, CONSTRUCT, CHOOSE_PILE, PERSONAL_MESSAGE } private String message; @@ -63,7 +64,8 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri private Map options; private Map modes; private List pile1; - private List pile2; + private List pile2; + private Choice choice; private PlayerQueryEvent(UUID playerId, String message, List abilities, Set choices, Set targets, Cards cards, QueryType queryType, int min, int max, boolean required, Map options) { @@ -135,6 +137,13 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri this.playerId = playerId; } + private PlayerQueryEvent(UUID playerId, Choice choice) { + super(playerId); + this.queryType = QueryType.CHOOSE_CHOICE; + this.choice = choice; + this.playerId = playerId; + } + public static PlayerQueryEvent askEvent(UUID playerId, String message) { return new PlayerQueryEvent(playerId, message, null, null, null, null, QueryType.ASK, 0, 0, false); } @@ -142,7 +151,7 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri public static PlayerQueryEvent chooseAbilityEvent(UUID playerId, String message, String objectName, List choices) { Set nameAsSet = null; if (objectName != null) { - nameAsSet = new HashSet(); + nameAsSet = new HashSet<>(); nameAsSet.add(objectName); } return new PlayerQueryEvent(playerId, message, choices, nameAsSet, null, null, QueryType.CHOOSE_ABILITY, 0, 0, false); @@ -156,8 +165,8 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri return new PlayerQueryEvent(playerId, message, modes); } - public static PlayerQueryEvent chooseEvent(UUID playerId, String message, Set choices) { - return new PlayerQueryEvent(playerId, message, null, choices, null, null, QueryType.CHOOSE, 0, 0, false); + public static PlayerQueryEvent chooseChoiceEvent(UUID playerId, Choice choice) { + return new PlayerQueryEvent(playerId, choice); } public static PlayerQueryEvent targetEvent(UUID playerId, String message, Set targets, boolean required) { @@ -276,4 +285,8 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri return pile2; } + public Choice getChoice() { + return choice; + } + } diff --git a/Mage/src/mage/game/events/PlayerQueryEventSource.java b/Mage/src/mage/game/events/PlayerQueryEventSource.java index af5da92e76..d9b023878a 100644 --- a/Mage/src/mage/game/events/PlayerQueryEventSource.java +++ b/Mage/src/mage/game/events/PlayerQueryEventSource.java @@ -36,6 +36,7 @@ import mage.game.permanent.Permanent; import java.io.Serializable; import java.util.*; +import mage.choices.Choice; /** * @@ -107,8 +108,8 @@ public class PlayerQueryEventSource implements EventSource, Se dispatcher.fireEvent(PlayerQueryEvent.amountEvent(playerId, message, min, max)); } - public void choose(UUID playerId, String message, Set choices) { - dispatcher.fireEvent(PlayerQueryEvent.chooseEvent(playerId, message, choices)); + public void chooseChoice(UUID playerId, Choice choice) { + dispatcher.fireEvent(PlayerQueryEvent.chooseChoiceEvent(playerId, choice)); } public void playXMana(UUID playerId, String message) { diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index ffcd32c138..f1cf5b565a 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -308,7 +308,7 @@ public interface Player extends MageItem, Copyable { // set the value for non mana X costs int announceXCost(int min, int max, String message, Game game, Ability ability, VariableCost variableCost); - int chooseEffect(List rEffects, Game game); + int chooseReplacementEffect(Map abilityMap, Game game); TriggeredAbility chooseTriggeredAbility(List abilities, Game game); Mode chooseMode(Modes modes, Ability source, Game game); void selectAttackers(Game game, UUID attackingPlayerId); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 9e02be5345..efa0aa63cd 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -1643,8 +1643,8 @@ public abstract class PlayerImpl implements Player, Serializable { } @Override - public void sendPlayerAction(PlayerAction passPriorityAction, Game game) { - switch(passPriorityAction) { + public void sendPlayerAction(PlayerAction playerAction, Game game) { + switch(playerAction) { case PASS_PRIORITY_UNTIL_MY_NEXT_TURN: // F9 passedUntilNextMain = false; passedUntilEndOfTurn = false; @@ -1681,7 +1681,7 @@ public abstract class PlayerImpl implements Player, Serializable { passedUntilEndOfTurn = false; passedUntilNextMain = false; } - logger.trace("PASS Priority: " + passPriorityAction.toString()); + logger.trace("PASS Priority: " + playerAction.toString()); } @Override