* Draft - Added "Quit Tournament" button to draft panel. Minor formatting.

This commit is contained in:
LevelX2 2014-02-28 17:47:27 +01:00
parent 024ec1169a
commit 8d2f4cc9ac
26 changed files with 340 additions and 157 deletions

View file

@ -158,9 +158,9 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
//TODO: make gray theme, implement theme selector in preferences dialog
private static boolean grayMode = false;
private static final Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
private static final Map<UUID, GamePanel> games = new HashMap<UUID, GamePanel>();
private static final Map<UUID, DraftPanel> drafts = new HashMap<UUID, DraftPanel>();
private static final Map<UUID, ChatPanel> chats = new HashMap<>();
private static final Map<UUID, GamePanel> games = new HashMap<>();
private static final Map<UUID, DraftPanel> drafts = new HashMap<>();
private static final MageUI ui = new MageUI();
private static final ScheduledExecutorService pingTaskExecutor = Executors.newSingleThreadScheduledExecutor();

View file

@ -54,7 +54,6 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="bigCard" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
@ -94,11 +93,22 @@
</Group>
</Group>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="bigCard" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="btnQuitTournament" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="btnQuitTournament" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblPack1" alignment="3" min="-2" max="-2" attributes="0"/>
@ -122,10 +132,10 @@
<Component id="lblCardNo" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtCardNo" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtTimeRemaining" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblMessage" pref="32" max="32767" attributes="0"/>
<Component id="lblMessage" pref="24" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="bigCard" min="-2" max="-2" attributes="0"/>
</Group>
@ -133,58 +143,64 @@
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="mage.client.cards.BigCard" name="bigCard">
</Component>
<Component class="javax.swing.JLabel" name="lblCardNo">
<Component class="javax.swing.JButton" name="btnQuitTournament">
<Properties>
<Property name="text" type="java.lang.String" value="Card #:"/>
<Property name="text" type="java.lang.String" value="Quit Tournament"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnQuitTournamentActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblPack1">
<Properties>
<Property name="text" type="java.lang.String" value="Pack 1:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblPack2">
<Properties>
<Property name="text" type="java.lang.String" value="Pack 2:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblPack3">
<Properties>
<Property name="text" type="java.lang.String" value="Pack 3:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtPack1">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="chkPack1">
</Component>
<Component class="javax.swing.JLabel" name="lblPack2">
<Properties>
<Property name="text" type="java.lang.String" value="Pack 2:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtPack2">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="chkPack2">
</Component>
<Component class="javax.swing.JLabel" name="lblPack3">
<Properties>
<Property name="text" type="java.lang.String" value="Pack 3:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtPack3">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="chkPack3">
</Component>
<Component class="javax.swing.JLabel" name="lblCardNo">
<Properties>
<Property name="text" type="java.lang.String" value="Card #:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtCardNo">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="chkPack1">
</Component>
<Component class="javax.swing.JCheckBox" name="chkPack2">
</Component>
<Component class="javax.swing.JCheckBox" name="chkPack3">
</Component>
<Component class="javax.swing.JTextField" name="txtTimeRemaining">
<Properties>
<Property name="editable" type="boolean" value="false"/>
@ -204,6 +220,8 @@
<Property name="horizontalAlignment" type="int" value="0"/>
</Properties>
</Component>
<Component class="mage.client.cards.BigCard" name="bigCard">
</Component>
</SubComponents>
</Container>
<Component class="mage.client.cards.CardsList" name="draftPicks">

View file

@ -38,6 +38,7 @@ import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.UUID;
import javax.swing.JOptionPane;
import javax.swing.Timer;
import mage.client.MageFrame;
import mage.client.deckeditor.SortSettingDraft;
@ -193,42 +194,50 @@ public class DraftPanel extends javax.swing.JPanel {
jSeparator1 = new javax.swing.JSeparator();
draftLeftPane = new javax.swing.JPanel();
bigCard = new mage.client.cards.BigCard();
lblCardNo = new javax.swing.JLabel();
btnQuitTournament = new javax.swing.JButton();
lblPack1 = new javax.swing.JLabel();
lblPack2 = new javax.swing.JLabel();
lblPack3 = new javax.swing.JLabel();
txtPack1 = new javax.swing.JTextField();
txtPack2 = new javax.swing.JTextField();
txtPack3 = new javax.swing.JTextField();
txtCardNo = new javax.swing.JTextField();
chkPack1 = new javax.swing.JCheckBox();
lblPack2 = new javax.swing.JLabel();
txtPack2 = new javax.swing.JTextField();
chkPack2 = new javax.swing.JCheckBox();
lblPack3 = new javax.swing.JLabel();
txtPack3 = new javax.swing.JTextField();
chkPack3 = new javax.swing.JCheckBox();
lblCardNo = new javax.swing.JLabel();
txtCardNo = new javax.swing.JTextField();
txtTimeRemaining = new javax.swing.JTextField();
lblMessage = new javax.swing.JLabel();
bigCard = new mage.client.cards.BigCard();
draftPicks = new mage.client.cards.CardsList();
draftBooster = new mage.client.cards.DraftGrid();
draftLeftPane.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
lblCardNo.setText("Card #:");
btnQuitTournament.setText("Quit Tournament");
btnQuitTournament.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnQuitTournamentActionPerformed(evt);
}
});
lblPack1.setText("Pack 1:");
lblPack2.setText("Pack 2:");
lblPack3.setText("Pack 3:");
txtPack1.setEditable(false);
txtPack1.setEnabled(false);
lblPack2.setText("Pack 2:");
txtPack2.setEditable(false);
txtPack2.setEnabled(false);
lblPack3.setText("Pack 3:");
txtPack3.setEditable(false);
txtPack3.setEnabled(false);
lblCardNo.setText("Card #:");
txtCardNo.setEditable(false);
txtCardNo.setEnabled(false);
@ -243,7 +252,6 @@ public class DraftPanel extends javax.swing.JPanel {
draftLeftPane.setLayout(draftLeftPaneLayout);
draftLeftPaneLayout.setHorizontalGroup(
draftLeftPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(draftLeftPaneLayout.createSequentialGroup()
.addContainerGap()
.addGroup(draftLeftPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -273,11 +281,19 @@ public class DraftPanel extends javax.swing.JPanel {
.addGroup(draftLeftPaneLayout.createSequentialGroup()
.addComponent(lblMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)
.addContainerGap())))
.addGroup(draftLeftPaneLayout.createSequentialGroup()
.addGroup(draftLeftPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(draftLeftPaneLayout.createSequentialGroup()
.addContainerGap()
.addComponent(btnQuitTournament)))
.addGap(0, 0, Short.MAX_VALUE))
);
draftLeftPaneLayout.setVerticalGroup(
draftLeftPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, draftLeftPaneLayout.createSequentialGroup()
.addContainerGap()
.addComponent(btnQuitTournament)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(draftLeftPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblPack1)
.addComponent(txtPack1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -296,10 +312,10 @@ public class DraftPanel extends javax.swing.JPanel {
.addGroup(draftLeftPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblCardNo)
.addComponent(txtCardNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtTimeRemaining, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
.addComponent(lblMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
@ -338,9 +354,16 @@ public class DraftPanel extends javax.swing.JPanel {
);
}// </editor-fold>//GEN-END:initComponents
private void btnQuitTournamentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitTournamentActionPerformed
if (JOptionPane.showConfirmDialog(this, "Are you sure you want to quit the tournament?", "Confirm quit tournament", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
MageFrame.getSession().quitDraft(draftId);
MageFrame.removeDraft(draftId);
}
}//GEN-LAST:event_btnQuitTournamentActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private mage.client.cards.BigCard bigCard;
private javax.swing.JButton btnQuitTournament;
private javax.swing.JCheckBox chkPack1;
private javax.swing.JCheckBox chkPack2;
private javax.swing.JCheckBox chkPack3;

View file

@ -737,6 +737,7 @@ class TableTableModel extends AbstractTableModel {
}
return "Join";
case CONSTRUCTING:
case DRAFTING:
if (tables[arg0].isTournament()) {
return "Show";
}

View file

@ -420,7 +420,6 @@ public class TournamentPanel extends javax.swing.JPanel {
}//GEN-LAST:event_btnCloseWindowActionPerformed
private void btnQuitTournamentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitTournamentActionPerformed
// TODO add your handling code here:
if (JOptionPane.showConfirmDialog(this, "Are you sure you want to quit the tournament?", "Confirm quit tournament", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
MageFrame.getSession().quitTournament(tournamentId);
}

View file

@ -124,6 +124,7 @@ public interface MageServer {
//draft methods
void joinDraft(UUID draftId, String sessionId) throws MageException;
void quitDraft(UUID draftId, String sessionId) throws MageException;
DraftPickView sendCardPick(UUID draftId, String sessionId, UUID cardId) throws MageException;
//challenge methods

View file

@ -1000,6 +1000,7 @@ public class SessionImpl implements Session {
}
return false;
}
@Override
public boolean quitTournament(UUID tournamentId) {
try {
@ -1015,6 +1016,19 @@ public class SessionImpl implements Session {
return false;
}
@Override
public boolean quitDraft(UUID draftId) {
try {
if (isConnected()) {
server.quitDraft(draftId, sessionId);
return true;
}
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
@Override
public boolean undo(UUID gameId) {
try {

View file

@ -57,6 +57,8 @@ public interface GamePlay {
boolean quitTournament(UUID tournamentId);
boolean quitDraft(UUID draftId);
boolean submitDeck(UUID tableId, DeckCardLists deck);
boolean updateDeck(UUID tableId, DeckCardLists deck);

View file

@ -28,27 +28,51 @@
package mage.player.ai;
import mage.constants.PhaseStep;
import mage.constants.RangeOfInfluence;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.constants.PhaseStep;
import static mage.constants.PhaseStep.BEGIN_COMBAT;
import static mage.constants.PhaseStep.CLEANUP;
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.POSTCOMBAT_MAIN;
import static mage.constants.PhaseStep.PRECOMBAT_MAIN;
import static mage.constants.PhaseStep.UPKEEP;
import mage.constants.RangeOfInfluence;
import mage.game.Game;
import mage.game.combat.Combat;
import mage.game.combat.CombatGroup;
import mage.game.events.GameEvent;
import mage.game.turn.*;
import mage.players.Player;
import mage.game.turn.BeginCombatStep;
import mage.game.turn.CleanupStep;
import mage.game.turn.CombatDamageStep;
import mage.game.turn.CombatPhase;
import mage.game.turn.DeclareAttackersStep;
import mage.game.turn.DeclareBlockersStep;
import mage.game.turn.EndOfCombatStep;
import mage.game.turn.EndPhase;
import mage.game.turn.EndStep;
import mage.game.turn.FirstCombatDamageStep;
import mage.game.turn.PostCombatMainPhase;
import mage.game.turn.PostCombatMainStep;
import mage.game.turn.Step;
import org.apache.log4j.Logger;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
/**
*
* @author ayratn
*/
public class ComputerPlayer7 extends ComputerPlayer6 implements Player {
public class ComputerPlayer7 extends ComputerPlayer6 {
private static final transient Logger logger = Logger.getLogger(ComputerPlayer7.class);

View file

@ -105,10 +105,12 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
super(name, range);
human = false;
userData = new UserData(UserGroup.COMPUTER, 64, false);
pickedCards = new ArrayList<PickedCard>();
}
protected ComputerPlayer(UUID id) {
super(id);
pickedCards = new ArrayList<PickedCard>();
}
public ComputerPlayer(final ComputerPlayer player) {
@ -1450,7 +1452,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
@Override
public void construct(Tournament tournament, Deck deck) {
if (deck.getCards().size() < 40) {
if (deck != null && deck.getCards().size() < 40 && deck.getSideboard().size() > 0 ) {
//pick the top 23 cards
if (chosenColors == null) {
for (Card card: deck.getSideboard()) {
@ -1604,9 +1606,6 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
* @param score
*/
protected void rememberPick(Card card, int score) {
if (pickedCards == null) {
pickedCards = new ArrayList<PickedCard>();
}
pickedCards.add(new PickedCard(card, score));
}
@ -1891,12 +1890,19 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
unplayable = new TreeMap<Mana, Card>();
playableNonInstant = new ArrayList<Card>();
playableInstant = new ArrayList<Card>();
playableAbilities = new ArrayList<ActivatedAbility>();
unplayable = new TreeMap<>();
playableNonInstant = new ArrayList<>();
playableInstant = new ArrayList<>();
playableAbilities = new ArrayList<>();
}
@Override
public void cleanUpOnMatchEnd() {
super.cleanUpOnMatchEnd(); //To change body of generated methods, choose Tools | Templates.
}
@Override
public T copy() {
return (T)new ComputerPlayer(this);

View file

@ -67,6 +67,9 @@ public class BoosterDraftEliminationTournament extends TournamentSingleEliminati
@Override
public void nextStep() {
if (isAbort()) {
currentStep = TournamentStep.COMPETE;
}
switch (currentStep) {
case START:
currentStep = TournamentStep.DRAFT;

View file

@ -40,6 +40,7 @@ import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository;
import mage.game.GameException;
import mage.game.Table;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.interfaces.Action;
@ -659,6 +660,22 @@ public class MageServerImpl implements MageServer {
});
}
@Override
public void quitDraft(final UUID draftId, final String sessionId) throws MageException {
execute("quitDraft", sessionId, new Action() {
@Override
public void execute() {
UUID tableId = DraftManager.getInstance().getControllerByDraftId(draftId).getTableId();
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
Table table = TableManager.getInstance().getTable(tableId);
if (table.isTournament()) {
UUID tournamentId = table.getTournament().getId();
TournamentManager.getInstance().quit(tournamentId, userId);
}
}
});
}
@Override
public void undo(final UUID gameId, final String sessionId) throws MageException {
execute("undo", sessionId, new Action() {

View file

@ -28,10 +28,15 @@
package mage.server;
import java.util.Date;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mage.MageException;
import mage.interfaces.callback.ClientCallback;
import mage.players.net.UserData;
import mage.players.net.UserGroup;
import mage.server.util.ConfigSettings;
import mage.view.UserDataView;
import org.apache.log4j.Logger;
import org.jboss.remoting.callback.AsynchInvokerCallbackHandler;
@ -39,12 +44,6 @@ import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.HandleCallbackException;
import org.jboss.remoting.callback.InvokerCallbackHandler;
import java.util.Date;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mage.server.util.ConfigSettings;
/**
*
* @author BetaSteward_at_googlemail.com
@ -53,13 +52,13 @@ public class Session {
private static final Logger logger = Logger.getLogger(Session.class);
private String sessionId;
private final String sessionId;
private UUID userId;
private String host;
private int messageId = 0;
private Date timeConnected;
private final Date timeConnected;
private boolean isAdmin = false;
private AsynchInvokerCallbackHandler callbackHandler;
private final AsynchInvokerCallbackHandler callbackHandler;
public Session(String sessionId, InvokerCallbackHandler callbackHandler) {
this.sessionId = sessionId;
@ -134,30 +133,42 @@ public class Session {
}
private void updateAvatar(String userName, UserData userData) {
//TODO: move to separate class
//TODO: move to separate class
//TODO: add for checking for private key
if (userName.equals("nantuko")) {
userData.setAvatarId(1000);
} else if (userName.equals("i_no_k")) {
userData.setAvatarId(1002);
} else if (userName.equals("Askael")) {
userData.setAvatarId(1004);
} else if (userName.equals("North")) {
userData.setAvatarId(1006);
} else if (userName.equals("BetaSteward")) {
userData.setAvatarId(1008);
} else if (userName.equals("Arching")) {
userData.setAvatarId(1010);
} else if (userName.equals("loki")) {
userData.setAvatarId(1012);
} else if (userName.equals("Alive")) {
userData.setAvatarId(1014);
} else if (userName.equals("Rahan")) {
userData.setAvatarId(1016);
} else if (userName.equals("Ayrat")) {
userData.setAvatarId(1018);
} else if (userName.equals("Bandit")) {
userData.setAvatarId(1020);
switch (userName) {
case "nantuko":
userData.setAvatarId(1000);
break;
case "i_no_k":
userData.setAvatarId(1002);
break;
case "Askael":
userData.setAvatarId(1004);
break;
case "North":
userData.setAvatarId(1006);
break;
case "BetaSteward":
userData.setAvatarId(1008);
break;
case "Arching":
userData.setAvatarId(1010);
break;
case "loki":
userData.setAvatarId(1012);
break;
case "Alive":
userData.setAvatarId(1014);
break;
case "Rahan":
userData.setAvatarId(1016);
break;
case "Ayrat":
userData.setAvatarId(1018);
break;
case "Bandit":
userData.setAvatarId(1020);
break;
}
}

View file

@ -49,7 +49,7 @@ public class SessionManager {
public static SessionManager getInstance() {
return INSTANCE;
}
private ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<String, Session>();
private final ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<>();
public Session getSession(String sessionId) {
if (sessions == null || sessionId == null) {
@ -116,7 +116,7 @@ public class SessionManager {
}
public Map<String, Session> getSessions() {
Map<String, Session> map = new HashMap<String, Session>();
Map<String, Session> map = new HashMap<>();
for (Map.Entry<String, Session> entry : sessions.entrySet()) {
map.put(entry.getKey(), entry.getValue());
}
@ -139,10 +139,7 @@ public class SessionManager {
}
public boolean isValidSession(String sessionId) {
if (sessions.containsKey(sessionId)) {
return true;
}
return false;
return sessions.containsKey(sessionId);
}
public User getUser(String sessionId) {

View file

@ -168,11 +168,11 @@ public class TableController {
return false;
}
tournament.addPlayer(player, seat.getPlayerType());
table.joinTable(player, seat);
user.addTable(player.getId(), table);
table.joinTable(player, seat);
logger.debug("player joined " + player.getId());
//only inform human players and add them to sessionPlayerMap
if (seat.getPlayer().isHuman()) {
user.addTable(player.getId(), table);
user.joinedTable(table.getRoomId(), table.getId(), true);
userPlayerMap.put(userId, player.getId());
}

View file

@ -55,11 +55,11 @@ public class DraftController {
private static final Logger logger = Logger.getLogger(GameController.class);
public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
private ConcurrentHashMap<UUID, DraftSession> draftSessions = new ConcurrentHashMap<UUID, DraftSession>();
private ConcurrentHashMap<UUID, UUID> userPlayerMap;
private UUID draftSessionId;
private Draft draft;
private UUID tableId;
private final ConcurrentHashMap<UUID, DraftSession> draftSessions = new ConcurrentHashMap<>();
private final ConcurrentHashMap<UUID, UUID> userPlayerMap;
private final UUID draftSessionId;
private final Draft draft;
private final UUID tableId;
public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
draftSessionId = UUID.randomUUID();
@ -130,10 +130,20 @@ public class DraftController {
checkStart();
}
public DraftSession getDraftSession(UUID playerId) {
if (draftSessions.containsKey(playerId)) {
return draftSessions.get(playerId);
}
return null;
}
public boolean replacePlayer(Player oldPlayer, Player newPlayer) {
if (draft.replacePlayer(oldPlayer, newPlayer)) {
draftSessions.get(oldPlayer.getId()).setKilled();
draftSessions.remove(oldPlayer.getId());
if (draft.replacePlayer(oldPlayer, newPlayer)) {
DraftSession draftSession = draftSessions.get(oldPlayer.getId());
if (draftSession != null) {
draftSession.draftOver(); // closes the draft panel of the replaced player
draftSessions.remove(oldPlayer.getId());
}
return true;
}
return false;

View file

@ -46,7 +46,7 @@ public class DraftManager {
private DraftManager() {}
private ConcurrentHashMap<UUID, DraftController> draftControllers = new ConcurrentHashMap<UUID, DraftController>();
private final ConcurrentHashMap<UUID, DraftController> draftControllers = new ConcurrentHashMap<>();
public UUID createDraftSession(Draft draft, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
DraftController draftController = new DraftController(draft, userPlayerMap, tableId);
@ -84,6 +84,10 @@ public class DraftManager {
draftControllers.remove(draftId);
}
public DraftController getControllerByDraftId(UUID draftId) {
return draftControllers.get(draftId);
}
public DraftController getController(UUID tableId) {
for (DraftController controller: draftControllers.values()) {
if (controller.getTableId().equals(tableId)) {

View file

@ -50,7 +50,9 @@ import mage.server.TableController;
import mage.server.TableManager;
import mage.server.User;
import mage.server.UserManager;
import mage.server.draft.DraftController;
import mage.server.draft.DraftManager;
import mage.server.draft.DraftSession;
import mage.server.game.GamesRoomManager;
import mage.server.util.ThreadExecutor;
import mage.view.ChatMessage.MessageColor;
@ -75,8 +77,6 @@ public class TournamentController {
private ConcurrentHashMap<UUID, UUID> userPlayerMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<UUID, TournamentSession> tournamentSessions = new ConcurrentHashMap<>();
private boolean abort = false;
public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
this.userPlayerMap = userPlayerMap;
chatId = ChatManager.getInstance().createChatSession();
@ -99,14 +99,14 @@ public class TournamentController {
startDraft(event.getDraft());
break;
case CONSTRUCT:
if (!abort) {
if (!isAbort()) {
construct();
} else {
endTournament();
}
break;
case START_MATCH:
if (!abort) {
if (!isAbort()) {
initTournament(); // set state
startMatch(event.getPair(), event.getMatchOptions());
}
@ -193,9 +193,12 @@ public class TournamentController {
}
private void endTournament() {
for (TournamentPlayer player: tournament.getPlayers()) {
player.setStateAtTournamentEnd();
}
for (final TournamentSession tournamentSession: tournamentSessions.values()) {
tournamentSession.tournamentOver();
tournamentSession.removeTournament();
tournamentSession.removeTournamentForUser();
}
this.tournamentSessions.clear();
TableManager.getInstance().endTournament(tableId, tournament);
@ -286,7 +289,15 @@ public class TournamentController {
if (tPlayer.getState().equals(TournamentPlayerState.DRAFTING)) {
info = "during Draft phase";
if (!checkToReplaceDraftPlayerByAi(userId, tPlayer)) {
this.abortTournament();
this.abortDraftTournament();
} else {
DraftController draftController = DraftManager.getInstance().getController(tableId);
if (draftController != null) {
DraftSession draftSession = draftController.getDraftSession(playerId);
if (draftSession != null) {
DraftManager.getInstance().kill(draftSession.getDraftId(), userId);
}
}
}
} else if (tPlayer.getState().equals(TournamentPlayerState.CONSTRUCTING)) {
info = "during Construction phase";
@ -315,13 +326,18 @@ public class TournamentController {
if (humans > 1) {
String replacePlayerName = "Draftbot";
User user = UserManager.getInstance().getUser(userId);
if (user != null) {
replacePlayerName = "Draftbot (" + user.getName() + ")";
}
TableController tableController = TableManager.getInstance().getController(tableId);
if (tableController != null) {
if (user != null) {
replacePlayerName = "Draftbot (" + user.getName() + ")";
}
tableController.replaceDraftPlayer(leavingPlayer.getPlayer(), replacePlayerName, "Computer - draftbot", 5);
ChatManager.getInstance().broadcast(chatId, "", leavingPlayer.getPlayer().getName() + " was replaced by draftbot", MessageColor.BLACK, true, null);
if (user != null) {
user.removeDraft(leavingPlayer.getPlayer().getId());
user.removeTable(leavingPlayer.getPlayer().getId());
user.removeTournament(leavingPlayer.getPlayer().getId());
}
ChatManager.getInstance().broadcast(chatId, "", leavingPlayer.getPlayer().getName() + " was replaced by draftbot", MessageColor.BLACK, true, MessageType.STATUS);
}
return true;
}
@ -341,8 +357,12 @@ public class TournamentController {
return new TournamentView(tournament);
}
private void abortTournament() {
this.abort = true;
private void abortDraftTournament() {
tournament.setAbort(true);
DraftManager.getInstance().getController(tableId).abortDraft();
}
public boolean isAbort() {
return tournament.isAbort();
}
}

View file

@ -147,7 +147,7 @@ public class TournamentSession {
}
}
public void removeTournament() {
public void removeTournamentForUser() {
User user = UserManager.getInstance().getUser(userId);
if (user != null) {
user.removeTournament(playerId);
@ -163,7 +163,7 @@ public class TournamentSession {
}
void tournamentOver() {
//TODO: implement this
}
}

View file

@ -39,8 +39,8 @@ import mage.game.GameException;
public class Deck implements Serializable {
private String name;
private Set<Card> cards = new LinkedHashSet<Card>();
private Set<Card> sideboard = new LinkedHashSet<Card>();
private final Set<Card> cards = new LinkedHashSet<>();
private final Set<Card> sideboard = new LinkedHashSet<>();
public static Deck load(DeckCardLists deckCardLists) throws GameException {
return Deck.load(deckCardLists, false);
@ -102,7 +102,7 @@ public class Deck implements Serializable {
}
public Set<String> getExpansionSetCodes() {
Set<String> sets = new LinkedHashSet<String>();
Set<String> sets = new LinkedHashSet<>();
for (Card card : getCards()) {
if (!sets.contains(card.getExpansionSetCode())) {
sets.add(card.getExpansionSetCode());

View file

@ -43,13 +43,12 @@ public class BoosterDraft extends DraftImpl<BoosterDraft> {
@Override
public void start() {
while (boosterNum < numberBoosters) {
while (!isAbort() && boosterNum < numberBoosters) {
openBooster();
while (!isAbort() && pickCards()) {
if (boosterNum % 2 == 1) {
passLeft();
}
else {
} else {
passRight();
}
fireUpdatePlayersEvent();

View file

@ -48,12 +48,13 @@ import mage.players.PlayerList;
/**
*
* @author BetaSteward_at_googlemail.com
* @param <T>
*/
public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
protected final UUID id;
protected Map<UUID, DraftPlayer> players = new HashMap<UUID, DraftPlayer>();
protected PlayerList table = new PlayerList();
protected final Map<UUID, DraftPlayer> players = new HashMap<>();
protected final PlayerList table = new PlayerList();
protected int numberBoosters;
protected DraftCube draftCube;
protected List<ExpansionSet> sets;
@ -95,7 +96,7 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
DraftPlayer newDraftPlayer = new DraftPlayer(newPlayer);
DraftPlayer oldDraftPlayer = players.get(oldPlayer.getId());
newDraftPlayer.setBooster(oldDraftPlayer.getBooster());
Map<UUID, DraftPlayer> newPlayers = new HashMap<UUID, DraftPlayer>();
Map<UUID, DraftPlayer> newPlayers = new HashMap<>();
PlayerList newTable = new PlayerList();
synchronized (players) {
for(Map.Entry<UUID, DraftPlayer> entry :players.entrySet()) {
@ -105,7 +106,10 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
newPlayers.put(entry.getKey(), entry.getValue());
}
}
players = newPlayers;
players.clear();
for (Map.Entry<UUID, DraftPlayer> entry: newPlayers.entrySet()) {
players.put(entry.getKey(), entry.getValue());
}
}
synchronized (table) {
for(UUID playerId :table) {
@ -115,7 +119,8 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
newTable.add(playerId);
}
}
table = newTable;
table.clear();
table.addAll(newTable);
}
if (oldDraftPlayer.isPicking()) {
newDraftPlayer.setPicking();
@ -179,13 +184,13 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
this.addPick(playerId, players.get(playerId).getBooster().get(0).getId());
}
protected void passLeft() {
protected void passLeft() {
synchronized (players) {
UUID startId = table.get(0);
UUID currentId = startId;
UUID nextId = table.getNext();
DraftPlayer current = players.get(currentId);
DraftPlayer next = players.get(nextId);
DraftPlayer current = players.get(currentId);
DraftPlayer next = players.get(nextId);
List<Card> currentBooster = current.booster;
while (true) {
List<Card> nextBooster = next.booster;
@ -194,8 +199,6 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
break;
}
currentBooster = nextBooster;
current = next;
currentId = nextId;
nextId = table.getNext();
next = players.get(nextId);
}
@ -217,8 +220,6 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
break;
}
currentBooster = prevBooster;
current = prev;
currentId = prevId;
prevId = table.getPrevious();
prev = players.get(prevId);
}
@ -261,6 +262,9 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
}
protected boolean donePicking() {
if(isAbort()) {
return true;
}
for (DraftPlayer player: players.values()) {
if (player.isPicking()) {
return false;

View file

@ -87,7 +87,7 @@ public class DraftPlayer {
public List<Card> getBooster() {
synchronized(booster) {
return new ArrayList<Card>(booster);
return new ArrayList<>(booster);
}
}

View file

@ -84,5 +84,6 @@ public interface Tournament {
int getNumberRounds();
void cleanUpOnTournamentEnd();
boolean isAbort();
void setAbort(boolean abort);
}

View file

@ -73,10 +73,12 @@ public abstract class TournamentImpl implements Tournament {
protected Date startTime;
protected Date endTime;
protected boolean abort;
public TournamentImpl(TournamentOptions options) {
this.options = options;
startTime = new Date();
abort = false;
}
@Override
@ -320,22 +322,25 @@ public abstract class TournamentImpl implements Tournament {
public void construct() {
tableEventSource.fireTableEvent(EventType.CONSTRUCT);
for (final TournamentPlayer player: players.values()) {
player.setConstructing();
new Thread(
new Runnable() {
@Override
public void run() {
player.getPlayer().construct(TournamentImpl.this, player.getDeck());
if (!isAbort()) {
for (final TournamentPlayer player: players.values()) {
player.setConstructing();
new Thread(
new Runnable() {
@Override
public void run() {
player.getPlayer().construct(TournamentImpl.this, player.getDeck());
}
}
).start();
}
synchronized(this) {
while (!isDoneConstructing()) {
try {
this.wait();
} catch (InterruptedException ex) { }
}
).start();
}
synchronized(this) {
while (!isDoneConstructing()) {
try {
this.wait();
} catch (InterruptedException ex) { }
}
}
nextStep();
@ -406,7 +411,11 @@ public abstract class TournamentImpl implements Tournament {
for(TournamentPlayer winner: this.getActivePlayers()) {
winner.setState(TournamentPlayerState.FINISHED);
if (options.getNumberRounds() == 0) { // if no swiss, last active is the winner
winner.setStateInfo("Winner");
if (isAbort()) {
winner.setStateInfo("Tournament canceled");
} else {
winner.setStateInfo("Winner");
}
}
}
}
@ -418,4 +427,14 @@ public abstract class TournamentImpl implements Tournament {
}
}
@Override
public boolean isAbort() {
return abort;
}
@Override
public void setAbort(boolean abort) {
this.abort = abort;
}
}

View file

@ -170,5 +170,15 @@ public class TournamentPlayer {
public void CleanUpOnTournamentEnd() {
this.deck = null;
}
public void setStateAtTournamentEnd() {
if (this.getState().equals(TournamentPlayerState.DRAFTING)
|| this.getState().equals(TournamentPlayerState.CONSTRUCTING)
|| this.getState().equals(TournamentPlayerState.DUELING)
|| this.getState().equals(TournamentPlayerState.SIDEBOARDING)
|| this.getState().equals(TournamentPlayerState.WAITING)) {
this.setState(TournamentPlayerState.FINISHED);
}
}
}