mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
server: fixed npe error on load tests (miss buffer timer), code refactor
This commit is contained in:
parent
09dbdccfb2
commit
fe8b8e1def
9 changed files with 39 additions and 57 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -43,15 +43,11 @@ public class MatchOptions implements Serializable {
|
|||
protected int minimumRating;
|
||||
protected int edhPowerLevel;
|
||||
protected boolean rated;
|
||||
protected int numSeatsForMatch;
|
||||
protected Set<String> 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<DeckCardInfo> perPlayerEmblemCards;
|
||||
protected Collection<DeckCardInfo> 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -4548,8 +4548,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setPriorityTimeLeft(int timeLeft
|
||||
) {
|
||||
public void setPriorityTimeLeft(int timeLeft) {
|
||||
priorityTimeLeft = timeLeft;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue