mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
GUI, table: allow unlimited draft bots amount, fixed computer names in 10+ tables (part of #13701)
This commit is contained in:
parent
336ab738f0
commit
2e7e78d1e5
10 changed files with 40 additions and 27 deletions
|
|
@ -41,7 +41,7 @@ public class NewTournamentDialog extends MageDialog {
|
|||
private static final Logger logger = Logger.getLogger(NewTournamentDialog.class);
|
||||
|
||||
// it's ok to have 4 players at the screen, 6 is fine for big screens too
|
||||
private static final int MAX_PLAYERS_PER_GAME = 6;
|
||||
private static final int MAX_WORKABLE_PLAYERS_PER_GAME = 6;
|
||||
|
||||
// temp settings on loading players list
|
||||
private final List<PlayerType> prefPlayerTypes = new ArrayList<>();
|
||||
|
|
@ -699,12 +699,12 @@ public class NewTournamentDialog extends MageDialog {
|
|||
// draft bots are loses and hide at the start, so count only human and AI
|
||||
if (tOptions.getMatchOptions().isSingleGameTourney()) {
|
||||
int workablePlayers = tOptions.getPlayerTypes().stream()
|
||||
.mapToInt(p -> p.equals(PlayerType.COMPUTER_DRAFT_BOT) ? 0 : 1)
|
||||
.mapToInt(p -> p.isWorkablePlayer() ? 1 : 0)
|
||||
.sum();
|
||||
if (workablePlayers > MAX_PLAYERS_PER_GAME) {
|
||||
if (workablePlayers > MAX_WORKABLE_PLAYERS_PER_GAME) {
|
||||
JOptionPane.showMessageDialog(
|
||||
MageFrame.getDesktop(),
|
||||
String.format("Warning, in single game mode you can choose %d human/ai players but selected %d", MAX_PLAYERS_PER_GAME, workablePlayers),
|
||||
String.format("Warning, in single game mode you can choose %d human/ai players but selected %d", MAX_WORKABLE_PLAYERS_PER_GAME, workablePlayers),
|
||||
"Warning",
|
||||
JOptionPane.WARNING_MESSAGE
|
||||
);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ public class TablePlayerPanel extends javax.swing.JPanel {
|
|||
this.newPlayerPanel.setSkillLevel(playerSkill);
|
||||
}
|
||||
|
||||
public static String extractAiPlayerNumberFromLabel(String label) {
|
||||
return ClientDefaultSettings.computerName + " " + label.substring(Math.max(0, label.length() - 2)).trim();
|
||||
}
|
||||
|
||||
public boolean joinTable(UUID roomId, UUID tableId) throws IOException, ClassNotFoundException {
|
||||
if (this.cbPlayerType.getSelectedItem() != PlayerType.HUMAN) {
|
||||
return SessionHandler.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), (PlayerType) this.cbPlayerType.getSelectedItem(), this.newPlayerPanel.getSkillLevel(), DeckImporter.importDeckFromFile(this.newPlayerPanel.getDeckFile(), true), "");
|
||||
|
|
@ -124,7 +128,7 @@ public class TablePlayerPanel extends javax.swing.JPanel {
|
|||
private void cbPlayerTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPlayerTypeActionPerformed
|
||||
if (getPlayerType() != PlayerType.HUMAN) {
|
||||
this.newPlayerPanel.setVisible(true);
|
||||
this.newPlayerPanel.setPlayerName(ClientDefaultSettings.computerName + " " + this.lblPlayerNum.getText().charAt(this.lblPlayerNum.getText().length() - 1));
|
||||
this.newPlayerPanel.setPlayerName(extractAiPlayerNumberFromLabel(this.lblPlayerNum.getText()));
|
||||
} else {
|
||||
this.newPlayerPanel.setVisible(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@
|
|||
<Component class="javax.swing.JToggleButton" name="btnTypeTourneyConstructed">
|
||||
<Properties>
|
||||
<Property name="selected" type="boolean" value="true"/>
|
||||
<Property name="text" type="java.lang.String" value="Constructed tourn."/>
|
||||
<Property name="text" type="java.lang.String" value="Constructed tourney"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Shows all constructed tournament tables."/>
|
||||
<Property name="actionCommand" type="java.lang.String" value="typeTourneyConstructed"/>
|
||||
<Property name="focusPainted" type="boolean" value="false"/>
|
||||
|
|
@ -216,7 +216,7 @@
|
|||
<Component class="javax.swing.JToggleButton" name="btnTypeTourneyLimited">
|
||||
<Properties>
|
||||
<Property name="selected" type="boolean" value="true"/>
|
||||
<Property name="text" type="java.lang.String" value="Limited tourn."/>
|
||||
<Property name="text" type="java.lang.String" value="Limited tourney"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Shows all limited tournament tables."/>
|
||||
<Property name="actionCommand" type="java.lang.String" value="typeTourneyLimited"/>
|
||||
<Property name="focusPainted" type="boolean" value="false"/>
|
||||
|
|
|
|||
|
|
@ -1163,7 +1163,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
filterBar1.add(btnTypeMatch);
|
||||
|
||||
btnTypeTourneyConstructed.setSelected(true);
|
||||
btnTypeTourneyConstructed.setText("Constructed tourn.");
|
||||
btnTypeTourneyConstructed.setText("Constructed tourney");
|
||||
btnTypeTourneyConstructed.setToolTipText("Shows all constructed tournament tables.");
|
||||
btnTypeTourneyConstructed.setActionCommand("typeTourneyConstructed");
|
||||
btnTypeTourneyConstructed.setFocusPainted(false);
|
||||
|
|
@ -1178,7 +1178,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
filterBar1.add(btnTypeTourneyConstructed);
|
||||
|
||||
btnTypeTourneyLimited.setSelected(true);
|
||||
btnTypeTourneyLimited.setText("Limited tourn.");
|
||||
btnTypeTourneyLimited.setText("Limited tourney");
|
||||
btnTypeTourneyLimited.setToolTipText("Shows all limited tournament tables.");
|
||||
btnTypeTourneyLimited.setActionCommand("typeTourneyLimited");
|
||||
btnTypeTourneyLimited.setFocusPainted(false);
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ public class TournamentPlayerPanel extends javax.swing.JPanel {
|
|||
private void cbPlayerTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPlayerTypeActionPerformed
|
||||
if (this.cbPlayerType.getSelectedItem() != PlayerType.HUMAN) {
|
||||
this.pnlPlayerName.setVisible(true);
|
||||
this.txtPlayerName.setText(ClientDefaultSettings.computerName + " " + this.lblPlayerNum.getText().charAt(this.lblPlayerNum.getText().length() - 1));
|
||||
this.txtPlayerName.setText(TablePlayerPanel.extractAiPlayerNumberFromLabel(this.lblPlayerNum.getText()));
|
||||
this.txtPlayerName.setEditable(false);
|
||||
this.txtPlayerName.setEnabled(false);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
minUserNameLength - minmal allowed length of a user name to connect to the server
|
||||
maxUserNameLength - maximal allowed length of a user name to connect to the server
|
||||
userNamePattern - pattern for user name validity check
|
||||
maxAiOpponents - number of allowed AI opponents on the server
|
||||
maxAiOpponents - number of allowed workable AI opponents on the server (draft bots are unlimited)
|
||||
saveGameActivated - allow game save and replay options (not working correctly yet)
|
||||
|
||||
authenticationActivated - "true" = user have to register to signon "false" = user need not to register
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
minUserNameLength - minmal allowed length of a user name to connect to the server
|
||||
maxUserNameLength - maximal allowed length of a user name to connect to the server
|
||||
userNamePattern - pattern for user name validity check
|
||||
maxAiOpponents - number of allowed AI opponents on the server
|
||||
maxAiOpponents - number of allowed workable AI opponents on the server (draft bots are unlimited)
|
||||
saveGameActivated - allow game save and replay options (not working correctly yet)
|
||||
authenticationActivated - "true" = user have to register to signon "false" = user need not to register
|
||||
* mail configs only needed if authentication is activated:
|
||||
|
|
|
|||
|
|
@ -222,15 +222,12 @@ public class MageServerImpl implements MageServer {
|
|||
throw new MageException("No message");
|
||||
}
|
||||
|
||||
// check AI players max
|
||||
// limit number of workable AI opponents (draft bots are unlimited)
|
||||
String maxAiOpponents = managerFactory.configSettings().getMaxAiOpponents();
|
||||
if (maxAiOpponents != null) {
|
||||
int aiPlayers = 0;
|
||||
for (PlayerType playerType : options.getPlayerTypes()) {
|
||||
if (playerType != PlayerType.HUMAN) {
|
||||
aiPlayers++;
|
||||
}
|
||||
}
|
||||
int aiPlayers = options.getPlayerTypes().stream()
|
||||
.mapToInt(t -> t.isAI() && t.isWorkablePlayer() ? 1 : 0)
|
||||
.sum();
|
||||
int max = Integer.parseInt(maxAiOpponents);
|
||||
if (aiPlayers > max) {
|
||||
user.showUserMessage("Create tournament", "It's only allowed to use a maximum of " + max + " AI players.");
|
||||
|
|
@ -324,7 +321,7 @@ public class MageServerImpl implements MageServer {
|
|||
UUID userId = session.get().getUserId();
|
||||
if (logger.isTraceEnabled()) {
|
||||
Optional<User> user = managerFactory.userManager().getUser(userId);
|
||||
user.ifPresent(user1 -> logger.trace("join tourn. tableId: " + tableId + ' ' + name));
|
||||
user.ifPresent(user1 -> logger.trace("join tourney tableId: " + tableId + ' ' + name));
|
||||
}
|
||||
if (userId == null) {
|
||||
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class TableController {
|
|||
}
|
||||
table = new Table(roomId, options.getTournamentType(), options.getName(), controllerName, DeckValidatorFactory.instance.createDeckValidator(options.getMatchOptions().getDeckType()),
|
||||
options.getPlayerTypes(), new TableRecorderImpl(managerFactory.userManager()), tournament, options.getMatchOptions().getBannedUsers(), options.isPlaneChase());
|
||||
chatId = managerFactory.chatManager().createChatSession("Tourn. table " + table.getId());
|
||||
chatId = managerFactory.chatManager().createChatSession("Tourney table " + table.getId());
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
|
@ -575,7 +575,7 @@ public class TableController {
|
|||
logger.error("No tournament object - userId: " + userId + " table: " + table.getId());
|
||||
return;
|
||||
}
|
||||
if (this.userId != null && this.userId.equals(userId) // tourn. sub tables have no creator user
|
||||
if (this.userId != null && this.userId.equals(userId) // tourney sub tables have no creator user
|
||||
&& (table.getState() == TableState.WAITING
|
||||
|| table.getState() == TableState.READY_TO_START)) {
|
||||
// table not started yet and user is the owner, removeUserFromAllTablesAndChat the table
|
||||
|
|
|
|||
|
|
@ -8,15 +8,19 @@ package mage.players;
|
|||
* @author IGOUDT
|
||||
*/
|
||||
public enum PlayerType {
|
||||
HUMAN("Human"),
|
||||
COMPUTER_DRAFT_BOT("Computer - draftbot"),
|
||||
COMPUTER_MONTE_CARLO("Computer - monte carlo"),
|
||||
COMPUTER_MAD("Computer - mad");
|
||||
HUMAN("Human", false, true),
|
||||
COMPUTER_DRAFT_BOT("Computer - draftbot", true, false),
|
||||
COMPUTER_MONTE_CARLO("Computer - monte carlo", true, true),
|
||||
COMPUTER_MAD("Computer - mad", true, true);
|
||||
|
||||
final String description;
|
||||
final boolean isAI;
|
||||
final boolean isWorkablePlayer; // false for draft bots cause it does nothing in real game and just loose a game
|
||||
|
||||
PlayerType(String description) {
|
||||
PlayerType(String description, boolean isAI, boolean isWorkablePlayer) {
|
||||
this.description = description;
|
||||
this.isAI = isAI;
|
||||
this.isWorkablePlayer = isWorkablePlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -24,6 +28,14 @@ public enum PlayerType {
|
|||
return description;
|
||||
}
|
||||
|
||||
public boolean isAI() {
|
||||
return this.isAI;
|
||||
}
|
||||
|
||||
public boolean isWorkablePlayer() {
|
||||
return this.isWorkablePlayer;
|
||||
}
|
||||
|
||||
public static PlayerType getByDescription(String description) {
|
||||
for (PlayerType type : values()) {
|
||||
if (type.description.equals(description)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue