mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Mulligan code moved to GameAction
UI will no longer ask you to keep or re-deal in ai-vs-ai games
This commit is contained in:
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -14132,9 +14132,8 @@ src/main/java/forge/control/input/InputAutoPassPriority.java -text
|
|||||||
src/main/java/forge/control/input/InputBase.java svneol=native#text/plain
|
src/main/java/forge/control/input/InputBase.java svneol=native#text/plain
|
||||||
src/main/java/forge/control/input/InputBlock.java svneol=native#text/plain
|
src/main/java/forge/control/input/InputBlock.java svneol=native#text/plain
|
||||||
src/main/java/forge/control/input/InputCleanup.java svneol=native#text/plain
|
src/main/java/forge/control/input/InputCleanup.java svneol=native#text/plain
|
||||||
|
src/main/java/forge/control/input/InputConfirmMulligan.java svneol=native#text/plain
|
||||||
src/main/java/forge/control/input/InputLockUI.java -text
|
src/main/java/forge/control/input/InputLockUI.java -text
|
||||||
src/main/java/forge/control/input/InputMulligan.java svneol=native#text/plain
|
|
||||||
src/main/java/forge/control/input/InputMulliganPartialParis.java -text
|
|
||||||
src/main/java/forge/control/input/InputPassPriority.java svneol=native#text/plain
|
src/main/java/forge/control/input/InputPassPriority.java svneol=native#text/plain
|
||||||
src/main/java/forge/control/input/InputPayManaBase.java -text
|
src/main/java/forge/control/input/InputPayManaBase.java -text
|
||||||
src/main/java/forge/control/input/InputPayManaExecuteCommands.java svneol=native#text/plain
|
src/main/java/forge/control/input/InputPayManaExecuteCommands.java svneol=native#text/plain
|
||||||
|
|||||||
@@ -21,18 +21,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.FThreads;
|
|
||||||
import forge.game.GameState;
|
import forge.game.GameState;
|
||||||
import forge.game.GameType;
|
|
||||||
import forge.game.MatchController;
|
|
||||||
import forge.game.ai.ComputerUtil;
|
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.zone.Zone;
|
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.gui.GuiDialog;
|
import forge.gui.GuiDialog;
|
||||||
import forge.gui.framework.SDisplayUtil;
|
import forge.gui.framework.SDisplayUtil;
|
||||||
import forge.gui.match.CMatchUI;
|
|
||||||
import forge.gui.match.nonsingleton.VField;
|
|
||||||
import forge.gui.match.views.VMessage;
|
import forge.gui.match.views.VMessage;
|
||||||
import forge.util.Lang;
|
import forge.util.Lang;
|
||||||
import forge.view.ButtonUtil;
|
import forge.view.ButtonUtil;
|
||||||
@@ -44,24 +37,23 @@ import forge.view.ButtonUtil;
|
|||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class InputMulligan extends InputBase {
|
public class InputConfirmMulligan extends InputSyncronizedBase {
|
||||||
/** Constant <code>serialVersionUID=-8112954303001155622L</code>. */
|
/** Constant <code>serialVersionUID=-8112954303001155622L</code>. */
|
||||||
private static final long serialVersionUID = -8112954303001155622L;
|
private static final long serialVersionUID = -8112954303001155622L;
|
||||||
|
|
||||||
private final MatchController match;
|
boolean keepHand = false;
|
||||||
|
final boolean isCommander;
|
||||||
|
final List<Card> selected = new ArrayList<Card>();
|
||||||
|
|
||||||
public InputMulligan(MatchController match0, Player humanPlayer) {
|
public InputConfirmMulligan(Player humanPlayer, boolean commander) {
|
||||||
super(humanPlayer);
|
super(humanPlayer);
|
||||||
match = match0;
|
isCommander = commander;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public final void showMessage() {
|
public final void showMessage() {
|
||||||
ButtonUtil.setButtonText("Keep", "Mulligan");
|
GameState game = player.getGame();
|
||||||
ButtonUtil.enableAllFocusOk();
|
|
||||||
|
|
||||||
GameState game = match.getCurrentGame();
|
|
||||||
Player startingPlayer = game.getPhaseHandler().getPlayerTurn();
|
Player startingPlayer = game.getPhaseHandler().getPlayerTurn();
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@@ -72,73 +64,78 @@ public class InputMulligan extends InputBase {
|
|||||||
sb.append("You are going ").append(Lang.getOrdinal(game.getPosition(player, startingPlayer))).append(".\n");
|
sb.append("You are going ").append(Lang.getOrdinal(game.getPosition(player, startingPlayer))).append(".\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append("Do you want to keep your hand?");
|
if ( isCommander ) {
|
||||||
|
ButtonUtil.setButtonText("Keep", "Exile");
|
||||||
|
ButtonUtil.enableOnlyOk();
|
||||||
|
sb.append("Will you keep your hand or choose some cards to exile those and draw one less card?");
|
||||||
|
} else {
|
||||||
|
ButtonUtil.setButtonText("Keep", "Mulligan");
|
||||||
|
ButtonUtil.enableAllFocusOk();
|
||||||
|
sb.append("Do you want to keep your hand?");
|
||||||
|
}
|
||||||
|
|
||||||
showMessage(sb.toString());
|
showMessage(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public final void selectButtonOK() {
|
protected final void onOk() {
|
||||||
this.end();
|
keepHand = true;
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public final void selectButtonCancel() {
|
protected final void onCancel() {
|
||||||
player.doMulligan();
|
keepHand = false;
|
||||||
|
done();
|
||||||
if (player.getCardsIn(ZoneType.Hand).isEmpty()) {
|
|
||||||
this.end();
|
|
||||||
} else {
|
|
||||||
ButtonUtil.enableAllFocusOk();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final void end() {
|
private void done() {
|
||||||
|
|
||||||
// Computer mulligan
|
|
||||||
final GameState game = match.getCurrentGame();
|
|
||||||
for (Player p : game.getPlayers()) {
|
|
||||||
if (!p.isComputer()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
while (ComputerUtil.wantMulligan(p)) {
|
|
||||||
p.doMulligan();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ButtonUtil.reset();
|
ButtonUtil.reset();
|
||||||
Player next = game.getPhaseHandler().getPlayerTurn();
|
stop();
|
||||||
if(game.getType() == GameType.Planechase)
|
|
||||||
{
|
|
||||||
next.initPlane();
|
|
||||||
}
|
|
||||||
//Set Field shown to current player.
|
|
||||||
VField nextField = CMatchUI.SINGLETON_INSTANCE.getFieldViewFor(next);
|
|
||||||
SDisplayUtil.showTab(nextField);
|
|
||||||
|
|
||||||
FThreads.invokeInNewThread( new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
match.afterMulligans();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectCard(Card c0, boolean isMetaDown) {
|
protected void onCardSelected(Card c0) { // the only place that would cause troubles - input is supposed only to confirm, not to fire abilities
|
||||||
Zone z0 = match.getCurrentGame().getZoneOf(c0);
|
|
||||||
if (c0.getName().equals("Serum Powder") && z0.is(ZoneType.Hand)) {
|
boolean fromHand = player.getZone(ZoneType.Hand).contains(c0);
|
||||||
if (GuiDialog.confirm(c0, "Use " + c0.getName() + "'s ability?")) {
|
boolean isSerumPowder = c0.getName().equals("Serum Powder");
|
||||||
List<Card> hand = new ArrayList<Card>(c0.getController().getCardsIn(ZoneType.Hand));
|
boolean isLegalChoice = fromHand && (isCommander || isSerumPowder);
|
||||||
for (Card c : hand) {
|
if ( !isLegalChoice ) {
|
||||||
match.getCurrentGame().getAction().exile(c);
|
|
||||||
}
|
|
||||||
c0.getController().drawCards(hand.size());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
|
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSerumPowder && GuiDialog.confirm(c0, "Use " + c0.getName() + "'s ability?")) {
|
||||||
|
List<Card> hand = new ArrayList<Card>(c0.getController().getCardsIn(ZoneType.Hand));
|
||||||
|
for (Card c : hand) {
|
||||||
|
player.getGame().getAction().exile(c);
|
||||||
|
}
|
||||||
|
c0.getController().drawCards(hand.size());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isCommander ) { // allow to choose cards for partial paris
|
||||||
|
if(selected.contains(c0)) {
|
||||||
|
c0.setUsedToPay(false);
|
||||||
|
selected.remove(c0);
|
||||||
|
} else {
|
||||||
|
c0.setUsedToPay(true);
|
||||||
|
selected.add(c0);
|
||||||
|
}
|
||||||
|
if( selected.isEmpty())
|
||||||
|
ButtonUtil.enableOnlyOk();
|
||||||
|
else
|
||||||
|
ButtonUtil.enableAllFocusOk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final boolean isKeepHand() {
|
||||||
|
return keepHand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Card> getSelectedCards() {
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,215 +0,0 @@
|
|||||||
/*
|
|
||||||
* Forge: Play Magic: the Gathering.
|
|
||||||
* Copyright (C) 2011 Forge Team
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package forge.control.input;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import forge.Card;
|
|
||||||
import forge.FThreads;
|
|
||||||
import forge.game.GameState;
|
|
||||||
import forge.game.GameType;
|
|
||||||
import forge.game.MatchController;
|
|
||||||
import forge.game.ai.ComputerUtil;
|
|
||||||
import forge.game.player.Player;
|
|
||||||
import forge.game.zone.Zone;
|
|
||||||
import forge.game.zone.ZoneType;
|
|
||||||
import forge.gui.GuiDialog;
|
|
||||||
import forge.gui.framework.SDisplayUtil;
|
|
||||||
import forge.gui.match.CMatchUI;
|
|
||||||
import forge.gui.match.nonsingleton.VField;
|
|
||||||
import forge.util.Lang;
|
|
||||||
import forge.view.ButtonUtil;
|
|
||||||
/**
|
|
||||||
* <p>
|
|
||||||
* InputMulligan class.
|
|
||||||
* </p>
|
|
||||||
*
|
|
||||||
* @author Forge
|
|
||||||
* @version $Id: InputMulligan.java 20698 2013-04-01 09:56:12Z Max mtg $
|
|
||||||
*/
|
|
||||||
public class InputMulliganPartialParis extends InputBase {
|
|
||||||
/** Constant <code>serialVersionUID=-8112954303001155622L</code>. */
|
|
||||||
private static final long serialVersionUID = -8112954303001155622L;
|
|
||||||
|
|
||||||
private final MatchController match;
|
|
||||||
private final GameState game;
|
|
||||||
|
|
||||||
private final List<Card> lastExiled = new ArrayList<Card>();
|
|
||||||
private final List<Card> allExiled = new ArrayList<Card>();
|
|
||||||
|
|
||||||
public InputMulliganPartialParis(MatchController match0, Player humanPlayer) {
|
|
||||||
super(humanPlayer);
|
|
||||||
match = match0;
|
|
||||||
game = match.getCurrentGame();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public final void showMessage() {
|
|
||||||
ButtonUtil.setButtonText("Done", "Exile");
|
|
||||||
ButtonUtil.enableOnlyOk();
|
|
||||||
|
|
||||||
GameState game = match.getCurrentGame();
|
|
||||||
Player startingPlayer = game.getPhaseHandler().getPlayerTurn();
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
if( startingPlayer == player ) {
|
|
||||||
sb.append("You are going first.\n");
|
|
||||||
} else {
|
|
||||||
sb.append(startingPlayer.getName()).append(" is going first. ");
|
|
||||||
sb.append("You are going ").append(Lang.getOrdinal(game.getPosition(player, startingPlayer))).append(".\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append("Do you want to Mulligan?");
|
|
||||||
showMessage(sb.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public final void selectButtonOK() {
|
|
||||||
this.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public final void selectButtonCancel() {
|
|
||||||
for(Card c : lastExiled)
|
|
||||||
{
|
|
||||||
game.action.exile(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
player.drawCards(lastExiled.size()-1);
|
|
||||||
allExiled.addAll(lastExiled);
|
|
||||||
lastExiled.clear();
|
|
||||||
|
|
||||||
final List<Card> aiAllExiled = new ArrayList<Card>();
|
|
||||||
for (Player p : game.getPlayers()) {
|
|
||||||
if (!(p.isComputer())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int ppcandidates = -1;
|
|
||||||
|
|
||||||
|
|
||||||
while (ComputerUtil.wantMulligan(p) && ppcandidates != 0) {
|
|
||||||
List<Card> cand = ComputerUtil.getPartialParisCandidates(p);
|
|
||||||
ppcandidates = cand.size();
|
|
||||||
if(ppcandidates != 0)
|
|
||||||
{
|
|
||||||
aiAllExiled.addAll(cand);
|
|
||||||
for(Card c : cand)
|
|
||||||
{
|
|
||||||
game.action.exile(c);
|
|
||||||
}
|
|
||||||
p.drawCards(ppcandidates-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.getCardsIn(ZoneType.Hand).isEmpty()) {
|
|
||||||
this.end();
|
|
||||||
} else {
|
|
||||||
ButtonUtil.enableAllFocusOk();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final void end() {
|
|
||||||
|
|
||||||
for(Card c : allExiled)
|
|
||||||
{
|
|
||||||
game.action.moveToLibrary(c);
|
|
||||||
}
|
|
||||||
player.shuffle();
|
|
||||||
|
|
||||||
// Computer mulligan
|
|
||||||
final List<Card> aiAllExiled = new ArrayList<Card>();
|
|
||||||
for (Player p : game.getPlayers()) {
|
|
||||||
if (!(p.isComputer())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int ppcandidates = -1;
|
|
||||||
|
|
||||||
while (ComputerUtil.wantMulligan(p) && ppcandidates != 0) {
|
|
||||||
List<Card> cand = ComputerUtil.getPartialParisCandidates(p);
|
|
||||||
ppcandidates = cand.size();
|
|
||||||
if(ppcandidates != 0)
|
|
||||||
{
|
|
||||||
aiAllExiled.addAll(cand);
|
|
||||||
for(Card c : cand)
|
|
||||||
{
|
|
||||||
game.action.exile(c);
|
|
||||||
}
|
|
||||||
p.drawCards(ppcandidates-1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Human Leylines & Chancellors
|
|
||||||
ButtonUtil.reset();
|
|
||||||
Player next = game.getPhaseHandler().getPlayerTurn();
|
|
||||||
if(game.getType() == GameType.Planechase)
|
|
||||||
{
|
|
||||||
next.initPlane();
|
|
||||||
}
|
|
||||||
//Set Field shown to current player.
|
|
||||||
VField nextField = CMatchUI.SINGLETON_INSTANCE.getFieldViewFor(next);
|
|
||||||
SDisplayUtil.showTab(nextField);
|
|
||||||
|
|
||||||
FThreads.invokeInNewThread( new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
match.afterMulligans();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void selectCard(Card c0, boolean isMetaDown) {
|
|
||||||
if(lastExiled.contains(c0))
|
|
||||||
{
|
|
||||||
lastExiled.remove(c0);
|
|
||||||
c0.setUsedToPay(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Zone z0 = match.getCurrentGame().getZoneOf(c0);
|
|
||||||
if (c0.getName().equals("Serum Powder") && z0.is(ZoneType.Hand)) {
|
|
||||||
if (GuiDialog.confirm(c0, "Use " + c0.getName() + "'s ability?")) {
|
|
||||||
List<Card> hand = new ArrayList<Card>(c0.getController().getCardsIn(ZoneType.Hand));
|
|
||||||
for (Card c : hand) {
|
|
||||||
game.getAction().exile(c);
|
|
||||||
}
|
|
||||||
c0.getController().drawCards(hand.size());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
lastExiled.add(c0);
|
|
||||||
c0.setUsedToPay(true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
lastExiled.add(c0);
|
|
||||||
c0.setUsedToPay(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(lastExiled.size() > 0)
|
|
||||||
ButtonUtil.enableAllFocusOk();
|
|
||||||
else
|
|
||||||
ButtonUtil.enableOnlyOk();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,12 +19,8 @@ package forge.control.input;
|
|||||||
|
|
||||||
import java.util.concurrent.BlockingDeque;
|
import java.util.concurrent.BlockingDeque;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
|
||||||
import forge.Singletons;
|
|
||||||
import forge.game.GameAge;
|
import forge.game.GameAge;
|
||||||
import forge.game.GameState;
|
import forge.game.GameState;
|
||||||
import forge.game.GameType;
|
|
||||||
import forge.game.MatchController;
|
|
||||||
import forge.game.phase.PhaseHandler;
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -46,10 +42,8 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
|
|||||||
|
|
||||||
private final BlockingDeque<Input> inputStack = new LinkedBlockingDeque<Input>();
|
private final BlockingDeque<Input> inputStack = new LinkedBlockingDeque<Input>();
|
||||||
|
|
||||||
private final MatchController match;
|
|
||||||
public InputQueue(MatchController matchController) {
|
public InputQueue() {}
|
||||||
match = matchController;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -125,12 +119,7 @@ public class InputQueue extends MyObservable implements java.io.Serializable {
|
|||||||
*/
|
*/
|
||||||
public final Input getActualInput(GameState game) {
|
public final Input getActualInput(GameState game) {
|
||||||
GameAge age = game.getAge();
|
GameAge age = game.getAge();
|
||||||
if ( age == GameAge.Mulligan ) {
|
if ( age != GameAge.Play && age != GameAge.Mulligan)
|
||||||
Player human = Singletons.getControl().getPlayer();
|
|
||||||
return game.getType() == GameType.Commander ? new InputMulliganPartialParis(match, human) : new InputMulligan(match, human);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( age != GameAge.Play )
|
|
||||||
return inputLock;
|
return inputLock;
|
||||||
|
|
||||||
Input topMost = inputStack.peek(); // incoming input to Control
|
Input topMost = inputStack.peek(); // incoming input to Control
|
||||||
|
|||||||
@@ -18,15 +18,17 @@
|
|||||||
package forge.game;
|
package forge.game;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.CardCharacteristicName;
|
import forge.CardCharacteristicName;
|
||||||
@@ -61,13 +63,15 @@ import forge.game.event.CardSacrificedEvent;
|
|||||||
import forge.game.player.GameLossReason;
|
import forge.game.player.GameLossReason;
|
||||||
import forge.game.player.HumanPlay;
|
import forge.game.player.HumanPlay;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerType;
|
|
||||||
import forge.game.zone.PlayerZone;
|
import forge.game.zone.PlayerZone;
|
||||||
import forge.game.zone.PlayerZoneBattlefield;
|
import forge.game.zone.PlayerZoneBattlefield;
|
||||||
import forge.game.zone.Zone;
|
import forge.game.zone.Zone;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.gui.GuiChoose;
|
import forge.gui.GuiChoose;
|
||||||
import forge.gui.GuiDialog;
|
import forge.gui.GuiDialog;
|
||||||
|
import forge.util.maps.CollectionSuppliers;
|
||||||
|
import forge.util.maps.HashMapOfLists;
|
||||||
|
import forge.util.maps.MapOfLists;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methods for common actions performed during a game.
|
* Methods for common actions performed during a game.
|
||||||
@@ -1466,13 +1470,56 @@ public class GameAction {
|
|||||||
game.getAction().checkStateEffects();
|
game.getAction().checkStateEffects();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void performMulligans(final Player firstPlayer, final boolean isCommander) {
|
||||||
* <p>
|
List<Player> whoCanMulligan = Lists.newArrayList(game.getPlayers());
|
||||||
* playCardWithoutManaCost.
|
int offset = whoCanMulligan.indexOf(firstPlayer);
|
||||||
* </p>
|
|
||||||
*
|
// Have to cycle-shift the list to get the first player on index 0
|
||||||
* @param c
|
for( int i = 0; i < offset; i++ ) {
|
||||||
* a {@link forge.Card} object.
|
whoCanMulligan.add(whoCanMulligan.remove(0));
|
||||||
*/
|
}
|
||||||
|
|
||||||
|
MapOfLists<Player, Card> exiledDuringMulligans = new HashMapOfLists<Player, Card>(CollectionSuppliers.<Card>arrayLists());
|
||||||
|
|
||||||
|
do {
|
||||||
|
for (int i = 0; i < whoCanMulligan.size(); i++) {
|
||||||
|
Player p = whoCanMulligan.get(i);
|
||||||
|
List<Card> toMulligan = p.canMulligan() ? p.getController().getCardsToMulligan(isCommander) : null;
|
||||||
|
if ( toMulligan != null ) {
|
||||||
|
if( !isCommander ) {
|
||||||
|
toMulligan = new ArrayList<Card>(p.getCardsIn(ZoneType.Hand));
|
||||||
|
for (final Card c : toMulligan) {
|
||||||
|
moveToLibrary(c);
|
||||||
|
}
|
||||||
|
p.shuffle();
|
||||||
|
p.drawCards(toMulligan.size() - 1);
|
||||||
|
|
||||||
|
} else if ( !toMulligan.isEmpty() ){
|
||||||
|
List<Card> toExile = Lists.newArrayList(toMulligan);
|
||||||
|
for(Card c : toExile) {
|
||||||
|
exile(c);
|
||||||
|
}
|
||||||
|
exiledDuringMulligans.addAll(p, toExile);
|
||||||
|
p.drawCards(toExile.size() - 1);
|
||||||
|
} else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
p.onMulliganned();
|
||||||
|
} else {
|
||||||
|
whoCanMulligan.remove(i--);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while( !whoCanMulligan.isEmpty() );
|
||||||
|
|
||||||
|
if( isCommander )
|
||||||
|
for(Entry<Player, Collection<Card>> kv : exiledDuringMulligans.entrySet() ) {
|
||||||
|
Player p = kv.getKey();
|
||||||
|
Collection<Card> cc = kv.getValue();
|
||||||
|
for(Card c : cc) {
|
||||||
|
moveToLibrary(c);
|
||||||
|
}
|
||||||
|
p.shuffle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ public class MatchController {
|
|||||||
*/
|
*/
|
||||||
public void startRound() {
|
public void startRound() {
|
||||||
|
|
||||||
inputQueue = new InputQueue(this);
|
inputQueue = new InputQueue();
|
||||||
currentGame = new GameState(players, gameType, this);
|
currentGame = new GameState(players, gameType, this);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -146,16 +146,38 @@ public class MatchController {
|
|||||||
|
|
||||||
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
|
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
|
||||||
GameNew.newGame(currentGame, canRandomFoil);
|
GameNew.newGame(currentGame, canRandomFoil);
|
||||||
determineFirstTurnPlayer(getLastGameOutcome(), currentGame);
|
|
||||||
|
|
||||||
currentGame.setAge(GameAge.Mulligan);
|
currentGame.setAge(GameAge.Mulligan);
|
||||||
getInput().clearInput();
|
|
||||||
|
|
||||||
// Update observers
|
|
||||||
currentGame.getGameLog().updateObservers();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
BugReporter.reportException(e);
|
BugReporter.reportException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Player firstPlayer = determineFirstTurnPlayer(getLastGameOutcome(), currentGame);
|
||||||
|
|
||||||
|
getInput().clearInput();
|
||||||
|
if(currentGame.getType() == GameType.Planechase)
|
||||||
|
firstPlayer.initPlane();
|
||||||
|
|
||||||
|
//Set Field shown to current player.
|
||||||
|
VField nextField = CMatchUI.SINGLETON_INSTANCE.getFieldViewFor(firstPlayer);
|
||||||
|
SDisplayUtil.showTab(nextField);
|
||||||
|
|
||||||
|
// Update observers
|
||||||
|
currentGame.getGameLog().updateObservers();
|
||||||
|
|
||||||
|
// This code was run from EDT.
|
||||||
|
FThreads.invokeInNewThread( new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
currentGame.getAction().performMulligans(firstPlayer, currentGame.getType() == GameType.Commander);
|
||||||
|
currentGame.getAction().handleLeylinesAndChancellors();
|
||||||
|
// Run Trigger beginning of the game
|
||||||
|
final HashMap<String, Object> runParams = new HashMap<String, Object>();
|
||||||
|
currentGame.getTriggerHandler().runTrigger(TriggerType.NewGame, runParams, false);
|
||||||
|
currentGame.setAge(GameAge.Play);
|
||||||
|
getInput().clearInput();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void attachUiToMatch(MatchController match, LobbyPlayerHuman humanLobbyPlayer) {
|
public static void attachUiToMatch(MatchController match, LobbyPlayerHuman humanLobbyPlayer) {
|
||||||
@@ -328,22 +350,12 @@ public class MatchController {
|
|||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterMulligans()
|
|
||||||
{
|
|
||||||
currentGame.getAction().handleLeylinesAndChancellors();
|
|
||||||
// Run Trigger beginning of the game
|
|
||||||
final HashMap<String, Object> runParams = new HashMap<String, Object>();
|
|
||||||
currentGame.getTriggerHandler().runTrigger(TriggerType.NewGame, runParams, false);
|
|
||||||
currentGame.setAge(GameAge.Play);
|
|
||||||
getInput().clearInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Write javadoc for this method.
|
* TODO: Write javadoc for this method.
|
||||||
* @param match
|
* @param match
|
||||||
* @param game
|
* @param game
|
||||||
*/
|
*/
|
||||||
private void determineFirstTurnPlayer(final GameOutcome lastGameOutcome, final GameState game) {
|
private Player determineFirstTurnPlayer(final GameOutcome lastGameOutcome, final GameState game) {
|
||||||
// Only cut/coin toss if it's the first game of the match
|
// Only cut/coin toss if it's the first game of the match
|
||||||
Player goesFirst;
|
Player goesFirst;
|
||||||
Player humanPlayer = Singletons.getControl().getPlayer();
|
Player humanPlayer = Singletons.getControl().getPlayer();
|
||||||
@@ -360,6 +372,7 @@ public class MatchController {
|
|||||||
}
|
}
|
||||||
goesFirst = willPlay ? goesFirst : goesFirst.getOpponent();
|
goesFirst = willPlay ? goesFirst : goesFirst.getOpponent();
|
||||||
game.getPhaseHandler().setPlayerTurn(goesFirst);
|
game.getPhaseHandler().setPlayerTurn(goesFirst);
|
||||||
|
return goesFirst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// decides who goes first when starting another game, used by newGame()
|
// decides who goes first when starting another game, used by newGame()
|
||||||
|
|||||||
@@ -1205,6 +1205,10 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
return this.drawCards(1);
|
return this.drawCards(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean canMulligan() {
|
||||||
|
return !getZone(ZoneType.Hand).isEmpty();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* TODO Write javadoc for this method.
|
* TODO Write javadoc for this method.
|
||||||
@@ -3123,4 +3127,15 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
public final void setHighlited(boolean value) { highlited = value; }
|
public final void setHighlited(boolean value) { highlited = value; }
|
||||||
public final boolean isHighlited() { return highlited; }
|
public final boolean isHighlited() { return highlited; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Write javadoc for this method.
|
||||||
|
*/
|
||||||
|
public void onMulliganned() {
|
||||||
|
game.getEvents().post(new MulliganEvent(this)); // quest listener may interfere here
|
||||||
|
final int newHand = getCardsIn(ZoneType.Hand).size();
|
||||||
|
game.getGameLog().add("Mulligan", this + " has mulliganed down to " + newHand + " cards.", 0);
|
||||||
|
stats.notifyHasMulliganed();
|
||||||
|
stats.notifyOpeningHandSize(newHand);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,4 +139,5 @@ public abstract class PlayerController {
|
|||||||
|
|
||||||
public abstract String chooseSomeType(String kindOfType, String aiLogic, List<String> validTypes, List<String> invalidTypes);
|
public abstract String chooseSomeType(String kindOfType, String aiLogic, List<String> validTypes, List<String> invalidTypes);
|
||||||
public abstract boolean confirmReplacementEffect(ReplacementEffect replacementEffect, SpellAbility effectSA, String question);
|
public abstract boolean confirmReplacementEffect(ReplacementEffect replacementEffect, SpellAbility effectSA, String question);
|
||||||
|
public abstract List<Card> getCardsToMulligan(boolean isCommander);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -287,5 +287,14 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
return ReplacementEffect.aiShouldRun(replacementEffect, effectSA, player);
|
return ReplacementEffect.aiShouldRun(replacementEffect, effectSA, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Card> getCardsToMulligan(boolean isCommander) {
|
||||||
|
if( !ComputerUtil.wantMulligan(player) )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (!isCommander)
|
||||||
|
return player.getCardsIn(ZoneType.Hand);
|
||||||
|
else
|
||||||
|
return ComputerUtil.getPartialParisCandidates(player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import forge.card.spellability.TargetSelection;
|
|||||||
import forge.control.input.Input;
|
import forge.control.input.Input;
|
||||||
import forge.control.input.InputBlock;
|
import forge.control.input.InputBlock;
|
||||||
import forge.control.input.InputCleanup;
|
import forge.control.input.InputCleanup;
|
||||||
|
import forge.control.input.InputConfirmMulligan;
|
||||||
import forge.control.input.InputPassPriority;
|
import forge.control.input.InputPassPriority;
|
||||||
import forge.control.input.InputSelectCards;
|
import forge.control.input.InputSelectCards;
|
||||||
import forge.control.input.InputSelectCardsFromList;
|
import forge.control.input.InputSelectCardsFromList;
|
||||||
@@ -467,4 +468,11 @@ public class PlayerControllerHuman extends PlayerController {
|
|||||||
return GuiDialog.confirm(replacementEffect.getHostCard(), question);
|
return GuiDialog.confirm(replacementEffect.getHostCard(), question);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Card> getCardsToMulligan(boolean isCommander) {
|
||||||
|
final InputConfirmMulligan inp = new InputConfirmMulligan(player, isCommander);
|
||||||
|
FThreads.setInputAndWait(inp);
|
||||||
|
return inp.isKeepHand() ? null : inp.getSelectedCards();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
package forge.gui.match;
|
package forge.gui.match;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|||||||
Reference in New Issue
Block a user