Fixed that in tournament a automatically generated deck will be submitted if player doesn't submit a deck in time (fixes #421).

This commit is contained in:
LevelX2 2014-04-29 17:32:24 +02:00
parent 21b582fbd3
commit 915651335a
12 changed files with 261 additions and 87 deletions

View file

@ -50,9 +50,9 @@ import mage.constants.Rarity;
public class AddLandDialog extends MageDialog {
private Deck deck;
private Set<String> setCodesland = new HashSet<String>();
private final Set<String> setCodesland = new HashSet<>();
private static int DEFAULT_SEALED_DECK_CARD_NUMBER = 40;
private static final int DEFAULT_SEALED_DECK_CARD_NUMBER = 40;
/** Creates new form AddLandDialog */
public AddLandDialog() {

View file

@ -428,7 +428,8 @@ public class NewTournamentDialog extends MageDialog {
if (tOptions.getLimitedOptions() == null) {
tOptions.setLimitedOptions(new LimitedOptions());
}
tOptions.getLimitedOptions().setConstructionTime((Integer)this.spnConstructTime.getValue() * 60);
tOptions.getLimitedOptions().setConstructionTime(60);
// tOptions.getLimitedOptions().setConstructionTime((Integer)this.spnConstructTime.getValue() * 60);
if (tournamentType.isCubeBooster()) {
tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
} else {

View file

@ -22,7 +22,7 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="actionPanel" alignment="0" max="32767" attributes="0"/>
<Component id="jSplitPane2" alignment="1" pref="908" max="32767" attributes="0"/>
<Component id="jSplitPane2" alignment="1" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -30,7 +30,7 @@
<Group type="102" attributes="0">
<Component id="actionPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jSplitPane2" pref="494" max="32767" attributes="0"/>
<Component id="jSplitPane2" pref="511" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -49,26 +49,30 @@
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="txtName" pref="260" max="32767" attributes="0"/>
<Component id="txtName" pref="175" max="32767" attributes="0"/>
<Component id="txtType" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="lablEndTime" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="txtEndTime" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="lblStartTime" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtStartTime" min="-2" pref="203" max="-2" attributes="0"/>
</Group>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="lblStartTime" min="-2" max="-2" attributes="0"/>
<Component id="lblTournamentState" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="txtTournamentState" max="32767" attributes="0"/>
<Component id="txtStartTime" pref="203" max="32767" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="btnCloseWindow" alignment="1" min="-2" pref="129" max="-2" attributes="0"/>
<Component id="btnQuitTournament" alignment="1" min="-2" pref="129" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
<Component id="txtEndTime" min="-2" pref="203" max="-2" attributes="0"/>
<EmptySpace type="unrelated" pref="47" max="32767" attributes="0"/>
<Component id="btnQuitTournament" min="-2" pref="129" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="154" max="-2" attributes="0"/>
<Component id="btnCloseWindow" min="-2" pref="129" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -84,16 +88,17 @@
<Component id="lblStartTime" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtStartTime" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnQuitTournament" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtEndTime" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="9" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblType" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtType" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lablEndTime" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtEndTime" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnCloseWindow" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblTournamentState" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtTournamentState" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="14" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -109,7 +114,6 @@
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="horizontalAlignment" type="int" value="2"/>
<Property name="text" type="java.lang.String" value="tournament name"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[50, 22]"/>
@ -126,36 +130,43 @@
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="horizontalAlignment" type="int" value="2"/>
<Property name="text" type="java.lang.String" value="tournament type"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblStartTime">
<Properties>
<Property name="text" type="java.lang.String" value="Start time:"/>
<Property name="text" type="java.lang.String" value="Start / end time:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtStartTime">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="jTextField1"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lablEndTime">
<Properties>
<Property name="text" type="java.lang.String" value="End time:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtEndTime">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="text" type="java.lang.String" value="jTextField2"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblTournamentState">
<Properties>
<Property name="text" type="java.lang.String" value="State:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtTournamentState">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="focusable" type="boolean" value="false"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value=""/>
</AuxValues>
</Component>
<Component class="javax.swing.JButton" name="btnQuitTournament">
<Properties>
<Property name="text" type="java.lang.String" value="Quit Tournament"/>

View file

@ -209,6 +209,8 @@ public class TournamentPanel extends javax.swing.JPanel {
firstInitDone = true;
}
txtTournamentState.setText(tournament.getTournamentState());
if (txtEndTime == null) {
return;
}
@ -267,8 +269,9 @@ public class TournamentPanel extends javax.swing.JPanel {
txtType = new javax.swing.JTextField();
lblStartTime = new javax.swing.JLabel();
txtStartTime = new javax.swing.JTextField();
lablEndTime = new javax.swing.JLabel();
txtEndTime = new javax.swing.JTextField();
lblTournamentState = new javax.swing.JLabel();
txtTournamentState = new javax.swing.JTextField();
btnQuitTournament = new javax.swing.JButton();
btnCloseWindow = new javax.swing.JButton();
jSplitPane2 = new javax.swing.JSplitPane();
@ -286,7 +289,6 @@ public class TournamentPanel extends javax.swing.JPanel {
txtName.setEditable(false);
txtName.setHorizontalAlignment(javax.swing.JTextField.LEFT);
txtName.setText("tournament name");
txtName.setFocusable(false);
txtName.setMaximumSize(new java.awt.Dimension(50, 22));
@ -295,23 +297,24 @@ public class TournamentPanel extends javax.swing.JPanel {
txtType.setEditable(false);
txtType.setHorizontalAlignment(javax.swing.JTextField.LEFT);
txtType.setText("tournament type");
txtType.setFocusable(false);
lblStartTime.setText("Start time:");
lblStartTime.setText("Start / end time:");
txtStartTime.setEditable(false);
txtStartTime.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtStartTime.setText("jTextField1");
txtStartTime.setFocusable(false);
lablEndTime.setText("End time:");
txtEndTime.setEditable(false);
txtEndTime.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtEndTime.setText("jTextField2");
txtEndTime.setFocusable(false);
lblTournamentState.setText("State:");
txtTournamentState.setEditable(false);
txtTournamentState.setHorizontalAlignment(javax.swing.JTextField.CENTER);
txtTournamentState.setFocusable(false);
btnQuitTournament.setText("Quit Tournament");
btnQuitTournament.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btnQuitTournament.addActionListener(new java.awt.event.ActionListener() {
@ -339,22 +342,25 @@ public class TournamentPanel extends javax.swing.JPanel {
.addComponent(lblType))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
.addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
.addComponent(txtType))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblStartTime)
.addComponent(lblTournamentState))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(actionPanelLayout.createSequentialGroup()
.addComponent(lablEndTime)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtEndTime))
.addGroup(actionPanelLayout.createSequentialGroup()
.addComponent(lblStartTime)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtTournamentState)
.addComponent(txtStartTime, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE))
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnCloseWindow, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnQuitTournament, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(actionPanelLayout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(txtEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 47, Short.MAX_VALUE)
.addComponent(btnQuitTournament, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, actionPanelLayout.createSequentialGroup()
.addGap(154, 154, 154)
.addComponent(btnCloseWindow, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
actionPanelLayout.setVerticalGroup(
@ -366,15 +372,16 @@ public class TournamentPanel extends javax.swing.JPanel {
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblStartTime)
.addComponent(txtStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnQuitTournament))
.addGap(9, 9, 9)
.addComponent(btnQuitTournament)
.addComponent(txtEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblType)
.addComponent(txtType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lablEndTime)
.addComponent(txtEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnCloseWindow))
.addGap(0, 14, Short.MAX_VALUE))
.addComponent(btnCloseWindow)
.addComponent(lblTournamentState)
.addComponent(txtTournamentState, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, Short.MAX_VALUE))
);
jSplitPane2.setResizeWeight(1.0);
@ -407,14 +414,14 @@ public class TournamentPanel extends javax.swing.JPanel {
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(actionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jSplitPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 908, Short.MAX_VALUE)
.addComponent(jSplitPane2, javax.swing.GroupLayout.Alignment.TRAILING)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE))
.addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
@ -439,15 +446,16 @@ public class TournamentPanel extends javax.swing.JPanel {
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JSplitPane jSplitPane2;
private javax.swing.JLabel lablEndTime;
private javax.swing.JLabel lblName;
private javax.swing.JLabel lblStartTime;
private javax.swing.JLabel lblTournamentState;
private javax.swing.JLabel lblType;
private javax.swing.JTable tableMatches;
private javax.swing.JTable tablePlayers;
private javax.swing.JTextField txtEndTime;
private javax.swing.JTextField txtName;
private javax.swing.JTextField txtStartTime;
private javax.swing.JTextField txtTournamentState;
private javax.swing.JTextField txtType;
// End of variables declaration//GEN-END:variables

View file

@ -46,7 +46,8 @@ public class TournamentView implements Serializable {
private final String tournamentName;
private final String tournamentType;
private final String tournamentState;
private final Date startTime;
private final Date endTime;
@ -63,6 +64,7 @@ public class TournamentView implements Serializable {
startTime = tournament.getStartTime();
endTime = tournament.getEndTime();
watchingAllowed = tournament.getOptions().isWatchingAllowed();
tournamentState = tournament.getTournamentState();
for (TournamentPlayer player: tournament.getPlayers()) {
players.add(new TournamentPlayerView(player));
@ -103,4 +105,9 @@ public class TournamentView implements Serializable {
public List<RoundView> getRounds() {
return rounds;
}
public String getTournamentState() {
return tournamentState;
}
}

View file

@ -1512,7 +1512,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
}
chosenColors = chooseDeckColorsIfPossible();
}
deck = buildDeck(new ArrayList<Card>(deck.getSideboard()), chosenColors);
deck = buildDeck(new ArrayList<>(deck.getSideboard()), chosenColors);
}
tournament.submitDeck(playerId, deck);
}

View file

@ -53,7 +53,6 @@ import mage.server.UserManager;
import mage.server.draft.DraftController;
import mage.server.draft.DraftManager;
import mage.server.draft.DraftSession;
import mage.server.game.GameManager;
import mage.server.game.GamesRoomManager;
import mage.server.util.ThreadExecutor;
import mage.view.ChatMessage.MessageColor;

View file

@ -58,7 +58,7 @@ public class Table implements Serializable {
private boolean isTournament;
private boolean tournamentSubTable;
private DeckValidator validator;
private TableState state = TableState.WAITING;
private TableState state;
private Match match;
private Tournament tournament;
@ -68,12 +68,14 @@ public class Table implements Serializable {
this(roomId, gameType, name, controllerName, validator, playerTypes);
this.tournament = tournament;
this.isTournament = true;
setState(TableState.WAITING);
}
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, Match match) {
this(roomId, gameType, name, controllerName, validator, playerTypes);
this.match = match;
this.isTournament = false;
this.isTournament = false;
setState(TableState.WAITING);
}
protected Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes) {
@ -106,23 +108,24 @@ public class Table implements Serializable {
}
public void initGame() {
state = TableState.DUELING;
setState(TableState.DUELING);
}
public void initTournament() {
state = TableState.DUELING;
setState(TableState.DUELING);
}
public void endTournament() {
state = TableState.FINISHED;
setState(TableState.FINISHED);
}
public void initDraft() {
state = TableState.DRAFTING;
setState(TableState.DRAFTING);
}
public void construct() {
state = TableState.CONSTRUCTING;
setState(TableState.CONSTRUCTING);
}
/**
@ -131,7 +134,7 @@ public class Table implements Serializable {
*
*/
public void closeTable() {
state = TableState.FINISHED;
setState(TableState.FINISHED);
this.validator = null;
}
@ -167,7 +170,7 @@ public class Table implements Serializable {
}
seat.setPlayer(player);
if (isReady()) {
state = TableState.STARTING;
setState(TableState.STARTING);
}
return seat.getPlayer().getId();
}
@ -203,14 +206,21 @@ public class Table implements Serializable {
Player player = seats[i].getPlayer();
if (player != null && player.getId().equals(playerId)) {
seats[i].setPlayer(null);
if (state == TableState.STARTING) {
state = TableState.WAITING;
if (getState().equals(TableState.STARTING)) {
setState(TableState.WAITING);
}
break;
}
}
}
final public void setState(TableState state) {
this.state = state;
if (isTournament()) {
getTournament().setTournamentState(state.toString());
}
}
public TableState getState() {
return state;
}
@ -220,7 +230,7 @@ public class Table implements Serializable {
}
public void sideboard() {
state = TableState.SIDEBOARDING;
setState(TableState.SIDEBOARDING);
}
public String getName() {

View file

@ -81,7 +81,10 @@ public interface Tournament {
// tournament type
TournamentType getTournamentType();
void setTournamentType(TournamentType tournamentType);
// tournamentState
String getTournamentState();
void setTournamentState(String tournamentState);
int getNumberRounds();
void cleanUpOnTournamentEnd();
boolean isAbort();

View file

@ -75,7 +75,8 @@ public abstract class TournamentImpl implements Tournament {
protected Date startTime;
protected Date endTime;
protected boolean abort;
protected String tournamentState;
public TournamentImpl(TournamentOptions options) {
this.options = options;
startTime = new Date();
@ -107,6 +108,9 @@ public abstract class TournamentImpl implements Tournament {
if (players.containsKey(playerId)) {
players.get(playerId).submitDeck(deck);
}
synchronized (this) {
this.notifyAll();
}
}
@Override
@ -358,11 +362,16 @@ public abstract class TournamentImpl implements Tournament {
}
).start();
}
// add autosubmit trigger
synchronized(this) {
while (!isDoneConstructing()) {
try {
this.wait();
} catch (InterruptedException ex) { }
} catch (InterruptedException ex) {
}
}
}
}
@ -460,4 +469,14 @@ public abstract class TournamentImpl implements Tournament {
this.abort = abort;
}
@Override
public String getTournamentState() {
return tournamentState;
}
@Override
public void setTournamentState(String tournamentState) {
this.tournamentState = tournamentState;
}
}

View file

@ -28,10 +28,18 @@
package mage.game.tournament;
import java.util.List;
import java.util.Random;
import java.util.Set;
import mage.cards.Card;
import mage.cards.decks.Deck;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.Rarity;
import mage.constants.TournamentPlayerState;
import mage.players.Player;
import mage.util.TournamentUtil;
/**
*
@ -105,7 +113,7 @@ public class TournamentPlayer {
}
public void submitDeck(Deck deck) {
this.deck = deck;
this.deck = deck; // Check if player manipulated available cards???
this.doneConstructing = true;
this.setState(TournamentPlayerState.WAITING);
}
@ -115,15 +123,30 @@ public class TournamentPlayer {
}
public Deck generateDeck() {
//TODO: improve this
while (deck.getCards().size() < 40 && deck.getSideboard().size() > 0) {
Card card = deck.getSideboard().iterator().next();
deck.getCards().add(card);
deck.getSideboard().remove(card);
// user passed to submit deck in time
// all all cards to deck
deck.getCards().addAll(deck.getSideboard());
deck.getSideboard().clear();
// add lands to deck
int landsPerType = 7;
if (deck.getCards().size() >= 90) {
landsPerType = 14;
}
Set<String> landSets = TournamentUtil.getLandSetCodeForDeckSets(deck.getExpansionSetCodes());
deck.getCards().addAll(TournamentUtil.getLands("Mountain", landsPerType, landSets));
deck.getCards().addAll(TournamentUtil.getLands("Plains", landsPerType, landSets));
deck.getCards().addAll(TournamentUtil.getLands("Swamp", landsPerType, landSets));
deck.getCards().addAll(TournamentUtil.getLands("Forest", landsPerType, landSets));
deck.getCards().addAll(TournamentUtil.getLands("Island", landsPerType, landSets));
this.doneConstructing = true;
this.setState(TournamentPlayerState.WAITING);
return deck;
}
public boolean isDoneConstructing() {
return this.doneConstructing;
}

View file

@ -0,0 +1,93 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import mage.cards.Card;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository;
import mage.constants.Rarity;
/**
*
* @author LevelX2
*/
public class TournamentUtil {
/**
* Tries to calculate the most appropiate sets to add basic lands for cards of a deck
*
* @param setCodesDeck
* @return setCode for lands
*/
public static Set<String> getLandSetCodeForDeckSets(Set<String> setCodesDeck) {
Set<String> setCodesland = new HashSet<>();
// decide from which sets basic lands are taken from
for (String setCode :setCodesDeck) {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
if (expansionInfo.hasBasicLands()) {
setCodesland.add(expansionInfo.getCode());
}
}
// if sets have no basic land, take land from block
if (setCodesland.isEmpty()) {
for (String setCode :setCodesDeck) {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
ExpansionInfo [] blockSets = ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
for (ExpansionInfo blockSet: blockSets) {
if (blockSet.hasBasicLands()) {
setCodesland.add(blockSet.getCode());
}
}
}
}
// if still no set with lands found, take one by random
if (setCodesland.isEmpty()) {
// if sets have no basic lands and also it has no parent or parent has no lands get last set with lands
// select a set with basic lands by random
Random generator = new Random();
List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
if (basicLandSets.size() > 0) {
setCodesland.add(basicLandSets.get(generator.nextInt(basicLandSets.size())).getCode());
}
}
if (setCodesland.isEmpty()) {
throw new IllegalArgumentException("No set with basic land was found");
}
return setCodesland;
}
public static List<Card> getLands(String landName, int number, Set<String> landSets) {
Random random = new Random();
CardCriteria criteria = new CardCriteria();
if (!landSets.isEmpty()) {
criteria.setCodes(landSets.toArray(new String[landSets.size()]));
}
criteria.rarities(Rarity.LAND).name(landName);
List<CardInfo> lands = CardRepository.instance.findCards(criteria);
List<Card> cards = new ArrayList<>();
if (!lands.isEmpty()) {
for (int i = 0; i < number; i++) {
Card land = lands.get(random.nextInt(lands.size())).getCard();
cards.add(land);
}
}
return cards;
}
}