mirror of
https://github.com/correl/mage.git
synced 2025-01-11 11:05:23 +00:00
Improved player quits / leaves mage handling for tournaments (not perfect yet, will more improve it).
This commit is contained in:
parent
0d1e45fff6
commit
85b8edf630
12 changed files with 155 additions and 34 deletions
|
@ -66,7 +66,10 @@
|
|||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="btnCloseWindow" min="-2" pref="129" max="-2" 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>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
|
@ -80,6 +83,7 @@
|
|||
<Component id="txtName" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<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"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="9" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
|
@ -152,6 +156,15 @@
|
|||
<Property name="focusable" type="boolean" value="false"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnQuitTournament">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Quit Tournament"/>
|
||||
<Property name="horizontalTextPosition" type="int" value="0"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnQuitTournamentActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btnCloseWindow">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Close Window"/>
|
||||
|
|
|
@ -76,7 +76,8 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
matchesModel = new TournamentMatchesTableModel();
|
||||
|
||||
initComponents();
|
||||
|
||||
btnQuitTournament.setVisible(false);
|
||||
|
||||
df = DateFormat.getDateTimeInstance();
|
||||
|
||||
tablePlayers.createDefaultColumnsFromModel();
|
||||
|
@ -124,6 +125,7 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
else {
|
||||
hideTournament();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public UUID getTournamentId() {
|
||||
|
@ -169,6 +171,20 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
matchesModel.loadData(tournament);
|
||||
this.tablePlayers.repaint();
|
||||
this.tableMatches.repaint();
|
||||
|
||||
// player is active in tournament
|
||||
btnQuitTournament.setVisible(false);
|
||||
if (tournament.getEndTime() == null) {
|
||||
for (TournamentPlayerView player : tournament.getPlayers()) {
|
||||
if (player.getName().equals(session.getUserName())) {
|
||||
if (!player.hasQuit()) {
|
||||
btnQuitTournament.setVisible(true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void startTasks() {
|
||||
|
@ -204,6 +220,7 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
txtStartTime = new javax.swing.JTextField();
|
||||
lablEndTime = new javax.swing.JLabel();
|
||||
txtEndTime = new javax.swing.JTextField();
|
||||
btnQuitTournament = new javax.swing.JButton();
|
||||
btnCloseWindow = new javax.swing.JButton();
|
||||
jSplitPane2 = new javax.swing.JSplitPane();
|
||||
jSplitPane1 = new javax.swing.JSplitPane();
|
||||
|
@ -246,6 +263,14 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
txtEndTime.setText("jTextField2");
|
||||
txtEndTime.setFocusable(false);
|
||||
|
||||
btnQuitTournament.setText("Quit Tournament");
|
||||
btnQuitTournament.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||
btnQuitTournament.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnQuitTournamentActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
btnCloseWindow.setText("Close Window");
|
||||
btnCloseWindow.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||
btnCloseWindow.addActionListener(new java.awt.event.ActionListener() {
|
||||
|
@ -278,7 +303,9 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
.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(btnCloseWindow, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.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))
|
||||
.addContainerGap())
|
||||
);
|
||||
actionPanelLayout.setVerticalGroup(
|
||||
|
@ -289,7 +316,8 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
.addComponent(lblName, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.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(txtStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(btnQuitTournament))
|
||||
.addGap(9, 9, 9)
|
||||
.addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblType)
|
||||
|
@ -345,10 +373,19 @@ public class TournamentPanel extends javax.swing.JPanel {
|
|||
hideTournament();
|
||||
}//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);
|
||||
}
|
||||
|
||||
}//GEN-LAST:event_btnQuitTournamentActionPerformed
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JPanel actionPanel;
|
||||
private javax.swing.JButton btnCloseWindow;
|
||||
private javax.swing.JButton btnQuitTournament;
|
||||
private mage.client.chat.ChatPanel chatPanel1;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JScrollPane jScrollPane2;
|
||||
|
|
|
@ -119,6 +119,7 @@ public interface MageServer {
|
|||
//tournament methods
|
||||
void startTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||
void joinTournament(UUID draftId, String sessionId) throws MageException;
|
||||
void quitTournament(UUID tournamentId, String sessionId) throws MageException;
|
||||
TournamentView getTournament(UUID tournamentId) throws MageException;
|
||||
|
||||
//draft methods
|
||||
|
|
|
@ -953,6 +953,20 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean quitTournament(UUID tournamentId) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
server.quitTournament(tournamentId, sessionId);
|
||||
return true;
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
} catch (Throwable t) {
|
||||
handleThrowable(t);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean undo(UUID gameId) {
|
||||
|
|
|
@ -55,6 +55,8 @@ public interface GamePlay {
|
|||
|
||||
boolean quitMatch(UUID gameId);
|
||||
|
||||
boolean quitTournament(UUID tournamentId);
|
||||
|
||||
boolean submitDeck(UUID tableId, DeckCardLists deck);
|
||||
|
||||
boolean updateDeck(UUID tableId, DeckCardLists deck);
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.constants.TournamentPlayerState;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
|
||||
/**
|
||||
|
@ -42,6 +43,7 @@ public class TournamentPlayerView implements Serializable {
|
|||
private String state;
|
||||
private String results;
|
||||
private int points;
|
||||
private boolean quit;
|
||||
|
||||
TournamentPlayerView(TournamentPlayer player) {
|
||||
this.name = player.getPlayer().getName();
|
||||
|
@ -52,6 +54,7 @@ public class TournamentPlayerView implements Serializable {
|
|||
this.state = sb.toString();
|
||||
this.points = player.getPoints();
|
||||
this.results = player.getResults();
|
||||
this.quit = player.getState().equals(TournamentPlayerState.ELIMINATED) || player.getState().equals(TournamentPlayerState.CANCELED);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -69,4 +72,9 @@ public class TournamentPlayerView implements Serializable {
|
|||
public String getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public boolean hasQuit() {
|
||||
return quit;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -584,6 +584,17 @@ public class MageServerImpl implements MageServer {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void quitTournament(final UUID tournamentId, final String sessionId) throws MageException {
|
||||
execute("quitTournament", sessionId, new Action() {
|
||||
@Override
|
||||
public void execute() {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
TournamentManager.getInstance().quit(tournamentId, userId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undo(final UUID gameId, final String sessionId) throws MageException {
|
||||
execute("undo", sessionId, new Action() {
|
||||
|
|
|
@ -45,6 +45,7 @@ import mage.game.match.MatchOptions;
|
|||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentPairing;
|
||||
import mage.game.tournament.TournamentPlayer;
|
||||
import mage.players.Player;
|
||||
import mage.server.ChatManager;
|
||||
import mage.server.TableManager;
|
||||
import mage.server.UserManager;
|
||||
|
@ -237,10 +238,10 @@ public class TournamentController {
|
|||
public void submitDeck(UUID playerId, Deck deck) {
|
||||
if (tournamentSessions.containsKey(playerId)) {
|
||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
if (player != null && !player.hasQuit()) {
|
||||
tournamentSessions.get(playerId).submitDeck(deck);
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getName() + " has submitted his tournament deck", MessageColor.BLACK);
|
||||
}
|
||||
tournamentSessions.get(playerId).submitDeck(deck);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -257,23 +258,37 @@ public class TournamentController {
|
|||
}
|
||||
}
|
||||
|
||||
// public UUID getSessionId() {
|
||||
// return this.sessionId;
|
||||
// }
|
||||
|
||||
public UUID getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
||||
public void kill(UUID userId) {
|
||||
if (userPlayerMap.containsKey(userId)) {
|
||||
tournamentSessions.get(userPlayerMap.get(userId)).setKilled();
|
||||
tournamentSessions.remove(userPlayerMap.get(userId));
|
||||
leave(userId);
|
||||
userPlayerMap.remove(userId);
|
||||
public void quit(UUID userId) {
|
||||
UUID playerId = userPlayerMap.get(userId);
|
||||
if (playerId != null) {
|
||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
ChatManager.getInstance().broadcast(chatId, "", player.getPlayer().getName() + " has quit the tournament", MessageColor.BLACK);
|
||||
String info;
|
||||
if (tournament.isDoneConstructing()) {
|
||||
info = new StringBuilder("during round ").append(tournament.getRounds().size()).toString();
|
||||
} else {
|
||||
info = "during Construction phase";
|
||||
}
|
||||
player.setQuit(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void kill(UUID userId) {
|
||||
quit(userId);
|
||||
// if (userPlayerMap.containsKey(userId)) {
|
||||
// tournamentSessions.get(userPlayerMap.get(userId)).setKilled();
|
||||
// tournamentSessions.remove(userPlayerMap.get(userId));
|
||||
// leave(userId);
|
||||
// userPlayerMap.remove(userId);
|
||||
// }
|
||||
}
|
||||
|
||||
private void leave(UUID userId) {
|
||||
tournament.leave(getPlayerId(userId));
|
||||
}
|
||||
|
|
|
@ -57,6 +57,11 @@ public class TournamentManager {
|
|||
controllers.get(tournamentId).join(userId);
|
||||
}
|
||||
|
||||
public void quit(UUID tournamentId, UUID userId) {
|
||||
controllers.get(tournamentId).quit(userId);
|
||||
}
|
||||
|
||||
|
||||
public void kill(UUID tournamentId, UUID userId) {
|
||||
controllers.get(tournamentId).kill(userId);
|
||||
}
|
||||
|
|
|
@ -121,6 +121,7 @@ public class TournamentSession {
|
|||
|
||||
public void setKilled() {
|
||||
killed = true;
|
||||
TournamentManager.getInstance().kill(tournament.getId(), userId);
|
||||
}
|
||||
|
||||
private synchronized void setupTimeout(int seconds) {
|
||||
|
|
|
@ -23,36 +23,36 @@ import mage.game.Game;
|
|||
*/
|
||||
public class ConditionalActivatedAbility extends ActivatedAbilityImpl<ConditionalActivatedAbility> {
|
||||
|
||||
private Condition condition;
|
||||
private String staticText = "";
|
||||
private Condition condition;
|
||||
private String ruleText = "";
|
||||
|
||||
private static final Effects emptyEffects = new Effects();
|
||||
private static final Effects emptyEffects = new Effects();
|
||||
|
||||
public ConditionalActivatedAbility(Zone zone, Effect effect, ManaCosts cost, Condition condition, String rule) {
|
||||
public ConditionalActivatedAbility(Zone zone, Effect effect, ManaCosts cost, Condition condition, String rule) {
|
||||
super(zone, effect, cost);
|
||||
this.condition = condition;
|
||||
this.staticText = rule;
|
||||
this.ruleText = rule;
|
||||
}
|
||||
|
||||
public ConditionalActivatedAbility(Zone zone, Effect effect, Costs costs, Condition condition, String rule) {
|
||||
super(zone, effect, costs);
|
||||
this.condition = condition;
|
||||
this.staticText = rule;
|
||||
this.condition = condition;
|
||||
this.ruleText = rule;
|
||||
}
|
||||
|
||||
public ConditionalActivatedAbility(Zone zone, Effect effect, Cost cost, Condition condition, String rule) {
|
||||
super(zone, effect, cost);
|
||||
this.condition = condition;
|
||||
this.staticText = rule;
|
||||
this.condition = condition;
|
||||
this.ruleText = rule;
|
||||
}
|
||||
|
||||
public ConditionalActivatedAbility(ConditionalActivatedAbility ability) {
|
||||
public ConditionalActivatedAbility(final ConditionalActivatedAbility ability) {
|
||||
super(ability);
|
||||
this.condition = ability.condition;
|
||||
this.staticText = ability.staticText;
|
||||
this.condition = ability.condition;
|
||||
this.ruleText = ability.ruleText;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public Effects getEffects(Game game, EffectType effectType) {
|
||||
if (!condition.apply(game, this)) {
|
||||
return emptyEffects;
|
||||
|
@ -60,8 +60,8 @@ public class ConditionalActivatedAbility extends ActivatedAbilityImpl<Conditiona
|
|||
return super.getEffects(game, effectType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canActivate(UUID playerId, Game game) {
|
||||
@Override
|
||||
public boolean canActivate(UUID playerId, Game game) {
|
||||
if (!condition.apply(game, this)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -73,8 +73,8 @@ public class ConditionalActivatedAbility extends ActivatedAbilityImpl<Conditiona
|
|||
return new ConditionalActivatedAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public String getRule() {
|
||||
return staticText;
|
||||
return ruleText;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public class TournamentPlayer {
|
|||
protected Deck deck;
|
||||
protected String results = "";
|
||||
protected boolean eliminated = false;
|
||||
protected boolean quit = false;
|
||||
protected boolean doneConstructing;
|
||||
protected boolean joined = false;
|
||||
|
||||
|
@ -149,5 +150,18 @@ public class TournamentPlayer {
|
|||
public void setStateInfo(String stateInfo) {
|
||||
this.stateInfo = stateInfo;
|
||||
}
|
||||
|
||||
public boolean hasQuit() {
|
||||
return quit;
|
||||
}
|
||||
|
||||
public void setQuit(String info) {
|
||||
setEliminated();
|
||||
this.setState(TournamentPlayerState.CANCELED);
|
||||
this.setStateInfo(info);
|
||||
this.quit = true;
|
||||
this.doneConstructing = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue