GUI, table: allow unlimited draft bots amount, fixed computer names in 10+ tables (part of #13701)

This commit is contained in:
Oleg Agafonov 2025-05-31 13:10:03 +04:00
parent 336ab738f0
commit 2e7e78d1e5
10 changed files with 40 additions and 27 deletions

View file

@ -41,7 +41,7 @@ public class NewTournamentDialog extends MageDialog {
private static final Logger logger = Logger.getLogger(NewTournamentDialog.class); 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 // 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 // temp settings on loading players list
private final List<PlayerType> prefPlayerTypes = new ArrayList<>(); 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 // draft bots are loses and hide at the start, so count only human and AI
if (tOptions.getMatchOptions().isSingleGameTourney()) { if (tOptions.getMatchOptions().isSingleGameTourney()) {
int workablePlayers = tOptions.getPlayerTypes().stream() int workablePlayers = tOptions.getPlayerTypes().stream()
.mapToInt(p -> p.equals(PlayerType.COMPUTER_DRAFT_BOT) ? 0 : 1) .mapToInt(p -> p.isWorkablePlayer() ? 1 : 0)
.sum(); .sum();
if (workablePlayers > MAX_PLAYERS_PER_GAME) { if (workablePlayers > MAX_WORKABLE_PLAYERS_PER_GAME) {
JOptionPane.showMessageDialog( JOptionPane.showMessageDialog(
MageFrame.getDesktop(), 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", "Warning",
JOptionPane.WARNING_MESSAGE JOptionPane.WARNING_MESSAGE
); );

View file

@ -41,6 +41,10 @@ public class TablePlayerPanel extends javax.swing.JPanel {
this.newPlayerPanel.setSkillLevel(playerSkill); 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 { public boolean joinTable(UUID roomId, UUID tableId) throws IOException, ClassNotFoundException {
if (this.cbPlayerType.getSelectedItem() != PlayerType.HUMAN) { 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), ""); 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 private void cbPlayerTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPlayerTypeActionPerformed
if (getPlayerType() != PlayerType.HUMAN) { if (getPlayerType() != PlayerType.HUMAN) {
this.newPlayerPanel.setVisible(true); 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 { } else {
this.newPlayerPanel.setVisible(false); this.newPlayerPanel.setVisible(false);
} }

View file

@ -201,7 +201,7 @@
<Component class="javax.swing.JToggleButton" name="btnTypeTourneyConstructed"> <Component class="javax.swing.JToggleButton" name="btnTypeTourneyConstructed">
<Properties> <Properties>
<Property name="selected" type="boolean" value="true"/> <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="toolTipText" type="java.lang.String" value="Shows all constructed tournament tables."/>
<Property name="actionCommand" type="java.lang.String" value="typeTourneyConstructed"/> <Property name="actionCommand" type="java.lang.String" value="typeTourneyConstructed"/>
<Property name="focusPainted" type="boolean" value="false"/> <Property name="focusPainted" type="boolean" value="false"/>
@ -216,7 +216,7 @@
<Component class="javax.swing.JToggleButton" name="btnTypeTourneyLimited"> <Component class="javax.swing.JToggleButton" name="btnTypeTourneyLimited">
<Properties> <Properties>
<Property name="selected" type="boolean" value="true"/> <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="toolTipText" type="java.lang.String" value="Shows all limited tournament tables."/>
<Property name="actionCommand" type="java.lang.String" value="typeTourneyLimited"/> <Property name="actionCommand" type="java.lang.String" value="typeTourneyLimited"/>
<Property name="focusPainted" type="boolean" value="false"/> <Property name="focusPainted" type="boolean" value="false"/>

View file

@ -1163,7 +1163,7 @@ public class TablesPanel extends javax.swing.JPanel {
filterBar1.add(btnTypeMatch); filterBar1.add(btnTypeMatch);
btnTypeTourneyConstructed.setSelected(true); btnTypeTourneyConstructed.setSelected(true);
btnTypeTourneyConstructed.setText("Constructed tourn."); btnTypeTourneyConstructed.setText("Constructed tourney");
btnTypeTourneyConstructed.setToolTipText("Shows all constructed tournament tables."); btnTypeTourneyConstructed.setToolTipText("Shows all constructed tournament tables.");
btnTypeTourneyConstructed.setActionCommand("typeTourneyConstructed"); btnTypeTourneyConstructed.setActionCommand("typeTourneyConstructed");
btnTypeTourneyConstructed.setFocusPainted(false); btnTypeTourneyConstructed.setFocusPainted(false);
@ -1178,7 +1178,7 @@ public class TablesPanel extends javax.swing.JPanel {
filterBar1.add(btnTypeTourneyConstructed); filterBar1.add(btnTypeTourneyConstructed);
btnTypeTourneyLimited.setSelected(true); btnTypeTourneyLimited.setSelected(true);
btnTypeTourneyLimited.setText("Limited tourn."); btnTypeTourneyLimited.setText("Limited tourney");
btnTypeTourneyLimited.setToolTipText("Shows all limited tournament tables."); btnTypeTourneyLimited.setToolTipText("Shows all limited tournament tables.");
btnTypeTourneyLimited.setActionCommand("typeTourneyLimited"); btnTypeTourneyLimited.setActionCommand("typeTourneyLimited");
btnTypeTourneyLimited.setFocusPainted(false); btnTypeTourneyLimited.setFocusPainted(false);

View file

@ -145,7 +145,7 @@ public class TournamentPlayerPanel extends javax.swing.JPanel {
private void cbPlayerTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPlayerTypeActionPerformed private void cbPlayerTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPlayerTypeActionPerformed
if (this.cbPlayerType.getSelectedItem() != PlayerType.HUMAN) { if (this.cbPlayerType.getSelectedItem() != PlayerType.HUMAN) {
this.pnlPlayerName.setVisible(true); 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.setEditable(false);
this.txtPlayerName.setEnabled(false); this.txtPlayerName.setEnabled(false);
} else { } else {

View file

@ -21,7 +21,7 @@
minUserNameLength - minmal allowed length of a user name to connect to the server 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 maxUserNameLength - maximal allowed length of a user name to connect to the server
userNamePattern - pattern for user name validity check 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) 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 authenticationActivated - "true" = user have to register to signon "false" = user need not to register

View file

@ -18,7 +18,7 @@
minUserNameLength - minmal allowed length of a user name to connect to the server 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 maxUserNameLength - maximal allowed length of a user name to connect to the server
userNamePattern - pattern for user name validity check 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) 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 authenticationActivated - "true" = user have to register to signon "false" = user need not to register
* mail configs only needed if authentication is activated: * mail configs only needed if authentication is activated:

View file

@ -222,15 +222,12 @@ public class MageServerImpl implements MageServer {
throw new MageException("No message"); throw new MageException("No message");
} }
// check AI players max // limit number of workable AI opponents (draft bots are unlimited)
String maxAiOpponents = managerFactory.configSettings().getMaxAiOpponents(); String maxAiOpponents = managerFactory.configSettings().getMaxAiOpponents();
if (maxAiOpponents != null) { if (maxAiOpponents != null) {
int aiPlayers = 0; int aiPlayers = options.getPlayerTypes().stream()
for (PlayerType playerType : options.getPlayerTypes()) { .mapToInt(t -> t.isAI() && t.isWorkablePlayer() ? 1 : 0)
if (playerType != PlayerType.HUMAN) { .sum();
aiPlayers++;
}
}
int max = Integer.parseInt(maxAiOpponents); int max = Integer.parseInt(maxAiOpponents);
if (aiPlayers > max) { if (aiPlayers > max) {
user.showUserMessage("Create tournament", "It's only allowed to use a maximum of " + max + " AI players."); 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(); UUID userId = session.get().getUserId();
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
Optional<User> user = managerFactory.userManager().getUser(userId); 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) { if (userId == null) {
logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId); logger.fatal("Got no userId from sessionId" + sessionId + " tableId" + tableId);

View file

@ -94,7 +94,7 @@ public class TableController {
} }
table = new Table(roomId, options.getTournamentType(), options.getName(), controllerName, DeckValidatorFactory.instance.createDeckValidator(options.getMatchOptions().getDeckType()), 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()); 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() { private void init() {
@ -575,7 +575,7 @@ public class TableController {
logger.error("No tournament object - userId: " + userId + " table: " + table.getId()); logger.error("No tournament object - userId: " + userId + " table: " + table.getId());
return; 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.WAITING
|| table.getState() == TableState.READY_TO_START)) { || table.getState() == TableState.READY_TO_START)) {
// table not started yet and user is the owner, removeUserFromAllTablesAndChat the table // table not started yet and user is the owner, removeUserFromAllTablesAndChat the table

View file

@ -8,15 +8,19 @@ package mage.players;
* @author IGOUDT * @author IGOUDT
*/ */
public enum PlayerType { public enum PlayerType {
HUMAN("Human"), HUMAN("Human", false, true),
COMPUTER_DRAFT_BOT("Computer - draftbot"), COMPUTER_DRAFT_BOT("Computer - draftbot", true, false),
COMPUTER_MONTE_CARLO("Computer - monte carlo"), COMPUTER_MONTE_CARLO("Computer - monte carlo", true, true),
COMPUTER_MAD("Computer - mad"); COMPUTER_MAD("Computer - mad", true, true);
final String description; 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.description = description;
this.isAI = isAI;
this.isWorkablePlayer = isWorkablePlayer;
} }
@Override @Override
@ -24,6 +28,14 @@ public enum PlayerType {
return description; return description;
} }
public boolean isAI() {
return this.isAI;
}
public boolean isWorkablePlayer() {
return this.isWorkablePlayer;
}
public static PlayerType getByDescription(String description) { public static PlayerType getByDescription(String description) {
for (PlayerType type : values()) { for (PlayerType type : values()) {
if (type.description.equals(description)) { if (type.description.equals(description)) {