diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java index 20163486470..fb6d748a1d8 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java @@ -14,7 +14,6 @@ import mage.constants.MultiplayerAttackOption; import mage.constants.RangeOfInfluence; import mage.constants.SkillLevel; import mage.game.match.MatchOptions; -import mage.game.mulligan.MulliganType; import mage.players.PlayerType; import mage.view.GameTypeView; import mage.view.TableView; @@ -876,7 +875,7 @@ public class NewTableDialog extends MageDialog { } int timeLimit = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_TIME_LIMIT + versionStr, "1500")); for (MatchTimeLimit mtl : MatchTimeLimit.values()) { - if (mtl.getTimeLimit() == timeLimit) { + if (mtl.getPrioritySecs() == timeLimit) { this.cbTimeLimit.setSelectedItem(mtl); break; } @@ -884,7 +883,7 @@ public class NewTableDialog extends MageDialog { // TODO: Rethink defaults with buffer time? int bufferTime = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_BUFFER_TIME + versionStr, "0")); for (MatchBufferTime mtl : MatchBufferTime.values()) { - if (mtl.getBufferTime() == bufferTime) { + if (mtl.getBufferSecs() == bufferTime) { this.cbBufferTime.setSelectedItem(mtl); break; } @@ -951,8 +950,8 @@ public class NewTableDialog extends MageDialog { PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_NAME + versionStr, options.getName()); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_PASSWORD + versionStr, options.getPassword()); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_DECK_TYPE + versionStr, options.getDeckType()); - PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_TIME_LIMIT + versionStr, Integer.toString(options.getPriorityTime())); - PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_BUFFER_TIME + versionStr, Integer.toString(options.getBufferTime())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_TIME_LIMIT + versionStr, Integer.toString(options.getMatchTimeLimit().getPrioritySecs())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_BUFFER_TIME + versionStr, Integer.toString(options.getMatchBufferTime().getBufferSecs())); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_GAME_TYPE + versionStr, options.getGameType()); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_NUMBER_OF_WINS + versionStr, Integer.toString(options.getWinsNeeded())); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_ROLLBACK_TURNS_ALLOWED + versionStr, options.isRollbackTurnsAllowed() ? "Yes" : "No"); diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java index 87ca1abc7ae..ef2cc81ca4a 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java @@ -1345,7 +1345,7 @@ public class NewTournamentDialog extends MageDialog { txtPassword.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PASSWORD + versionStr, "")); int timeLimit = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_TIME_LIMIT + versionStr, "1500")); for (MatchTimeLimit mtl : MatchTimeLimit.values()) { - if (mtl.getTimeLimit() == timeLimit) { + if (mtl.getPrioritySecs() == timeLimit) { this.cbTimeLimit.setSelectedItem(mtl); break; } @@ -1353,7 +1353,7 @@ public class NewTournamentDialog extends MageDialog { // TODO: Rethink default match time with buffer time. int bufferTime = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_BUFFER_TIME + versionStr, "0")); for (MatchBufferTime mtl : MatchBufferTime.values()) { - if (mtl.getBufferTime() == bufferTime) { + if (mtl.getBufferSecs() == bufferTime) { this.cbBufferTime.setSelectedItem(mtl); break; } @@ -1424,8 +1424,8 @@ public class NewTournamentDialog extends MageDialog { String versionStr = prepareVersionStr(version, true); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_NAME + versionStr, tOptions.getName()); PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PASSWORD + versionStr, tOptions.getPassword()); - PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_TIME_LIMIT + versionStr, Integer.toString(tOptions.getMatchOptions().getPriorityTime())); - PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_BUFFER_TIME + versionStr, Integer.toString(tOptions.getMatchOptions().getBufferTime())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_TIME_LIMIT + versionStr, Integer.toString(tOptions.getMatchOptions().getMatchTimeLimit().getPrioritySecs())); + PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_BUFFER_TIME + versionStr, Integer.toString(tOptions.getMatchOptions().getMatchBufferTime().getBufferSecs())); if (this.spnConstructTime.isVisible()) { PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_CONSTR_TIME + versionStr, Integer.toString(tOptions.getLimitedOptions().getConstructionTime())); } diff --git a/Mage.Common/src/main/java/mage/utils/timer/PriorityTimer.java b/Mage.Common/src/main/java/mage/utils/timer/PriorityTimer.java index fa628df4a61..5c1fd5638fb 100644 --- a/Mage.Common/src/main/java/mage/utils/timer/PriorityTimer.java +++ b/Mage.Common/src/main/java/mage/utils/timer/PriorityTimer.java @@ -8,6 +8,9 @@ import mage.interfaces.Action; import org.apache.log4j.Logger; /** + * Priority timer for both server and client sides + * Client side version used for GUI-avatars redraw + * * @author noxx */ public class PriorityTimer extends TimerTask { diff --git a/Mage/src/main/java/mage/constants/MatchBufferTime.java b/Mage/src/main/java/mage/constants/MatchBufferTime.java index 26714b2cc24..195bb72c844 100644 --- a/Mage/src/main/java/mage/constants/MatchBufferTime.java +++ b/Mage/src/main/java/mage/constants/MatchBufferTime.java @@ -21,16 +21,16 @@ public enum MatchBufferTime { SEC__25(25, "25 Seconds"), SEC__30(30, "30 Seconds"); - private final int matchSeconds; + private final int bufferSecs; private final String name; - MatchBufferTime(int matchSeconds, String name) { - this.matchSeconds = matchSeconds; + MatchBufferTime(int bufferSecs, String name) { + this.bufferSecs = bufferSecs; this.name = name; } - public int getBufferTime() { - return matchSeconds; + public int getBufferSecs() { + return bufferSecs; } public String getName() { diff --git a/Mage/src/main/java/mage/constants/MatchTimeLimit.java b/Mage/src/main/java/mage/constants/MatchTimeLimit.java index 1246851d542..139355d4b2b 100644 --- a/Mage/src/main/java/mage/constants/MatchTimeLimit.java +++ b/Mage/src/main/java/mage/constants/MatchTimeLimit.java @@ -22,16 +22,16 @@ public enum MatchTimeLimit { MIN__90(5400, "90 Minutes"), MIN_120(7200, "120 Minutes"); - private final int matchSeconds; + private final int prioritySecs; private final String name; - MatchTimeLimit(int matchSeconds, String name) { - this.matchSeconds = matchSeconds; + MatchTimeLimit(int prioritySecs, String name) { + this.prioritySecs = prioritySecs; this.name = name; } - public int getTimeLimit() { - return matchSeconds; + public int getPrioritySecs() { + return prioritySecs; } public String getName() { diff --git a/Mage/src/main/java/mage/game/match/MatchImpl.java b/Mage/src/main/java/mage/game/match/MatchImpl.java index 1ab1ddbeaf7..db9e51bcddb 100644 --- a/Mage/src/main/java/mage/game/match/MatchImpl.java +++ b/Mage/src/main/java/mage/game/match/MatchImpl.java @@ -198,14 +198,15 @@ public abstract class MatchImpl implements Match { game.loadCards(matchPlayer.getDeck().getCards(), matchPlayer.getPlayer().getId()); game.loadCards(matchPlayer.getDeck().getSideboard(), matchPlayer.getPlayer().getId()); game.addPlayer(matchPlayer.getPlayer(), matchPlayer.getDeck()); - // set the priority time left for the match - if (games.isEmpty()) { // first game full time - matchPlayer.getPlayer().setPriorityTimeLeft(options.getPriorityTime()); - matchPlayer.getPlayer().setBufferTimeLeft(options.getBufferTime()); + // time limits + matchPlayer.getPlayer().setBufferTimeLeft(options.getMatchBufferTime().getBufferSecs()); + if (games.isEmpty()) { + // first game + matchPlayer.getPlayer().setPriorityTimeLeft(options.getMatchTimeLimit().getPrioritySecs()); } else { + // 2+ games must keep times if (matchPlayer.getPriorityTimeLeft() > 0) { matchPlayer.getPlayer().setPriorityTimeLeft(matchPlayer.getPriorityTimeLeft()); - matchPlayer.getPlayer().setBufferTimeLeft(options.getBufferTime()); } } } else { @@ -214,8 +215,8 @@ public abstract class MatchImpl implements Match { } } } - game.setPriorityTime(options.getPriorityTime()); - game.setBufferTime(options.getBufferTime()); + game.setPriorityTime(options.getMatchTimeLimit().getPrioritySecs()); + game.setBufferTime(options.getMatchBufferTime().getBufferSecs()); } protected void shufflePlayers() { diff --git a/Mage/src/main/java/mage/game/match/MatchOptions.java b/Mage/src/main/java/mage/game/match/MatchOptions.java index 6d5f9cc70e9..42b97dde716 100644 --- a/Mage/src/main/java/mage/game/match/MatchOptions.java +++ b/Mage/src/main/java/mage/game/match/MatchOptions.java @@ -43,15 +43,11 @@ public class MatchOptions implements Serializable { protected int minimumRating; protected int edhPowerLevel; protected boolean rated; - protected int numSeatsForMatch; protected Set bannedUsers = new HashSet<>(); - /** - * Time each player has during the game to play using his\her priority. - */ - protected MatchTimeLimit matchTimeLimit; // 0 = no priorityTime handling - protected MatchBufferTime matchBufferTime; // Amount of time each player gets before their normal time limit counts down. Refreshes each time the normal timer is invoked. - protected MulliganType mulliganType; + protected MatchTimeLimit matchTimeLimit = MatchTimeLimit.NONE; // total time limit for priority + protected MatchBufferTime matchBufferTime = MatchBufferTime.NONE; // additional/buffer time limit for each priority before real time ticking starts + protected MulliganType mulliganType = MulliganType.GAME_DEFAULT; protected Collection perPlayerEmblemCards; protected Collection globalEmblemCards; @@ -178,26 +174,12 @@ public class MatchOptions implements Serializable { this.limited = limited; } - public int getPriorityTime() { - if (matchTimeLimit == null) { - return MatchTimeLimit.NONE.getTimeLimit(); - } - return matchTimeLimit.getTimeLimit(); - } - public MatchTimeLimit getMatchTimeLimit() { return this.matchTimeLimit; } public void setMatchTimeLimit(MatchTimeLimit matchTimeLimit) { - this.matchTimeLimit = matchTimeLimit; - } - - public int getBufferTime() { - if (matchBufferTime == null) { - return MatchBufferTime.NONE.getBufferTime(); - } - return matchBufferTime.getBufferTime(); + this.matchTimeLimit = Optional.ofNullable(matchTimeLimit).orElse(MatchTimeLimit.NONE); } public MatchBufferTime getMatchBufferTime() { @@ -205,7 +187,7 @@ public class MatchOptions implements Serializable { } public void setMatchBufferTime(MatchBufferTime matchBufferTime) { - this.matchBufferTime = matchBufferTime; + this.matchBufferTime = Optional.ofNullable(matchBufferTime).orElse(MatchBufferTime.NONE); } public String getPassword() { @@ -295,9 +277,10 @@ public class MatchOptions implements Serializable { .setRated(this.isRated()) .setWinsNeeded(this.getWinsNeeded()); - ResultProtos.SkillLevel skillLevel = ResultProtos.SkillLevel.BEGINNER; + ResultProtos.SkillLevel skillLevel; switch (this.getSkillLevel()) { case BEGINNER: + default: skillLevel = ResultProtos.SkillLevel.BEGINNER; break; case CASUAL: @@ -313,13 +296,10 @@ public class MatchOptions implements Serializable { } public void setMullgianType(MulliganType mulliganType) { - this.mulliganType = mulliganType; + this.mulliganType = Optional.ofNullable(mulliganType).orElse(MulliganType.GAME_DEFAULT); } public MulliganType getMulliganType() { - if (mulliganType == null) { - return MulliganType.GAME_DEFAULT; - } return mulliganType; } diff --git a/Mage/src/main/java/mage/game/match/MatchPlayer.java b/Mage/src/main/java/mage/game/match/MatchPlayer.java index e8a833517be..fd48a7b5881 100644 --- a/Mage/src/main/java/mage/game/match/MatchPlayer.java +++ b/Mage/src/main/java/mage/game/match/MatchPlayer.java @@ -22,7 +22,7 @@ public class MatchPlayer implements Serializable { private boolean quit; private boolean doneSideboarding; - private int priorityTimeLeft; + private int priorityTimeLeft; // keep left time for next game public MatchPlayer(Player player, Deck deck, Match match) { this.player = player; diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index e4ad09d93a5..7c478be0a4a 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -4548,8 +4548,7 @@ public abstract class PlayerImpl implements Player, Serializable { } @Override - public void setPriorityTimeLeft(int timeLeft - ) { + public void setPriorityTimeLeft(int timeLeft) { priorityTimeLeft = timeLeft; }