mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -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.RangeOfInfluence;
|
||||||
import mage.constants.SkillLevel;
|
import mage.constants.SkillLevel;
|
||||||
import mage.game.match.MatchOptions;
|
import mage.game.match.MatchOptions;
|
||||||
import mage.game.mulligan.MulliganType;
|
|
||||||
import mage.players.PlayerType;
|
import mage.players.PlayerType;
|
||||||
import mage.view.GameTypeView;
|
import mage.view.GameTypeView;
|
||||||
import mage.view.TableView;
|
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"));
|
int timeLimit = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_TIME_LIMIT + versionStr, "1500"));
|
||||||
for (MatchTimeLimit mtl : MatchTimeLimit.values()) {
|
for (MatchTimeLimit mtl : MatchTimeLimit.values()) {
|
||||||
if (mtl.getTimeLimit() == timeLimit) {
|
if (mtl.getPrioritySecs() == timeLimit) {
|
||||||
this.cbTimeLimit.setSelectedItem(mtl);
|
this.cbTimeLimit.setSelectedItem(mtl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -884,7 +883,7 @@ public class NewTableDialog extends MageDialog {
|
||||||
// TODO: Rethink defaults with buffer time?
|
// TODO: Rethink defaults with buffer time?
|
||||||
int bufferTime = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_BUFFER_TIME + versionStr, "0"));
|
int bufferTime = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_BUFFER_TIME + versionStr, "0"));
|
||||||
for (MatchBufferTime mtl : MatchBufferTime.values()) {
|
for (MatchBufferTime mtl : MatchBufferTime.values()) {
|
||||||
if (mtl.getBufferTime() == bufferTime) {
|
if (mtl.getBufferSecs() == bufferTime) {
|
||||||
this.cbBufferTime.setSelectedItem(mtl);
|
this.cbBufferTime.setSelectedItem(mtl);
|
||||||
break;
|
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_NAME + versionStr, options.getName());
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_PASSWORD + versionStr, options.getPassword());
|
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_DECK_TYPE + versionStr, options.getDeckType());
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_TIME_LIMIT + versionStr, Integer.toString(options.getPriorityTime()));
|
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.getBufferTime()));
|
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_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_NUMBER_OF_WINS + versionStr, Integer.toString(options.getWinsNeeded()));
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_ROLLBACK_TURNS_ALLOWED + versionStr, options.isRollbackTurnsAllowed() ? "Yes" : "No");
|
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, ""));
|
txtPassword.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PASSWORD + versionStr, ""));
|
||||||
int timeLimit = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_TIME_LIMIT + versionStr, "1500"));
|
int timeLimit = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_TIME_LIMIT + versionStr, "1500"));
|
||||||
for (MatchTimeLimit mtl : MatchTimeLimit.values()) {
|
for (MatchTimeLimit mtl : MatchTimeLimit.values()) {
|
||||||
if (mtl.getTimeLimit() == timeLimit) {
|
if (mtl.getPrioritySecs() == timeLimit) {
|
||||||
this.cbTimeLimit.setSelectedItem(mtl);
|
this.cbTimeLimit.setSelectedItem(mtl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1353,7 +1353,7 @@ public class NewTournamentDialog extends MageDialog {
|
||||||
// TODO: Rethink default match time with buffer time.
|
// TODO: Rethink default match time with buffer time.
|
||||||
int bufferTime = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_BUFFER_TIME + versionStr, "0"));
|
int bufferTime = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_BUFFER_TIME + versionStr, "0"));
|
||||||
for (MatchBufferTime mtl : MatchBufferTime.values()) {
|
for (MatchBufferTime mtl : MatchBufferTime.values()) {
|
||||||
if (mtl.getBufferTime() == bufferTime) {
|
if (mtl.getBufferSecs() == bufferTime) {
|
||||||
this.cbBufferTime.setSelectedItem(mtl);
|
this.cbBufferTime.setSelectedItem(mtl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1424,8 +1424,8 @@ public class NewTournamentDialog extends MageDialog {
|
||||||
String versionStr = prepareVersionStr(version, true);
|
String versionStr = prepareVersionStr(version, true);
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_NAME + versionStr, tOptions.getName());
|
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_PASSWORD + versionStr, tOptions.getPassword());
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_TIME_LIMIT + versionStr, Integer.toString(tOptions.getMatchOptions().getPriorityTime()));
|
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().getBufferTime()));
|
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_BUFFER_TIME + versionStr, Integer.toString(tOptions.getMatchOptions().getMatchBufferTime().getBufferSecs()));
|
||||||
if (this.spnConstructTime.isVisible()) {
|
if (this.spnConstructTime.isVisible()) {
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_CONSTR_TIME + versionStr, Integer.toString(tOptions.getLimitedOptions().getConstructionTime()));
|
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;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Priority timer for both server and client sides
|
||||||
|
* Client side version used for GUI-avatars redraw
|
||||||
|
*
|
||||||
* @author noxx
|
* @author noxx
|
||||||
*/
|
*/
|
||||||
public class PriorityTimer extends TimerTask {
|
public class PriorityTimer extends TimerTask {
|
||||||
|
|
|
||||||
|
|
@ -21,16 +21,16 @@ public enum MatchBufferTime {
|
||||||
SEC__25(25, "25 Seconds"),
|
SEC__25(25, "25 Seconds"),
|
||||||
SEC__30(30, "30 Seconds");
|
SEC__30(30, "30 Seconds");
|
||||||
|
|
||||||
private final int matchSeconds;
|
private final int bufferSecs;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
MatchBufferTime(int matchSeconds, String name) {
|
MatchBufferTime(int bufferSecs, String name) {
|
||||||
this.matchSeconds = matchSeconds;
|
this.bufferSecs = bufferSecs;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBufferTime() {
|
public int getBufferSecs() {
|
||||||
return matchSeconds;
|
return bufferSecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
|
||||||
|
|
@ -22,16 +22,16 @@ public enum MatchTimeLimit {
|
||||||
MIN__90(5400, "90 Minutes"),
|
MIN__90(5400, "90 Minutes"),
|
||||||
MIN_120(7200, "120 Minutes");
|
MIN_120(7200, "120 Minutes");
|
||||||
|
|
||||||
private final int matchSeconds;
|
private final int prioritySecs;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
MatchTimeLimit(int matchSeconds, String name) {
|
MatchTimeLimit(int prioritySecs, String name) {
|
||||||
this.matchSeconds = matchSeconds;
|
this.prioritySecs = prioritySecs;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTimeLimit() {
|
public int getPrioritySecs() {
|
||||||
return matchSeconds;
|
return prioritySecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
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().getCards(), matchPlayer.getPlayer().getId());
|
||||||
game.loadCards(matchPlayer.getDeck().getSideboard(), matchPlayer.getPlayer().getId());
|
game.loadCards(matchPlayer.getDeck().getSideboard(), matchPlayer.getPlayer().getId());
|
||||||
game.addPlayer(matchPlayer.getPlayer(), matchPlayer.getDeck());
|
game.addPlayer(matchPlayer.getPlayer(), matchPlayer.getDeck());
|
||||||
// set the priority time left for the match
|
// time limits
|
||||||
if (games.isEmpty()) { // first game full time
|
matchPlayer.getPlayer().setBufferTimeLeft(options.getMatchBufferTime().getBufferSecs());
|
||||||
matchPlayer.getPlayer().setPriorityTimeLeft(options.getPriorityTime());
|
if (games.isEmpty()) {
|
||||||
matchPlayer.getPlayer().setBufferTimeLeft(options.getBufferTime());
|
// first game
|
||||||
|
matchPlayer.getPlayer().setPriorityTimeLeft(options.getMatchTimeLimit().getPrioritySecs());
|
||||||
} else {
|
} else {
|
||||||
|
// 2+ games must keep times
|
||||||
if (matchPlayer.getPriorityTimeLeft() > 0) {
|
if (matchPlayer.getPriorityTimeLeft() > 0) {
|
||||||
matchPlayer.getPlayer().setPriorityTimeLeft(matchPlayer.getPriorityTimeLeft());
|
matchPlayer.getPlayer().setPriorityTimeLeft(matchPlayer.getPriorityTimeLeft());
|
||||||
matchPlayer.getPlayer().setBufferTimeLeft(options.getBufferTime());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -214,8 +215,8 @@ public abstract class MatchImpl implements Match {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
game.setPriorityTime(options.getPriorityTime());
|
game.setPriorityTime(options.getMatchTimeLimit().getPrioritySecs());
|
||||||
game.setBufferTime(options.getBufferTime());
|
game.setBufferTime(options.getMatchBufferTime().getBufferSecs());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void shufflePlayers() {
|
protected void shufflePlayers() {
|
||||||
|
|
|
||||||
|
|
@ -43,15 +43,11 @@ public class MatchOptions implements Serializable {
|
||||||
protected int minimumRating;
|
protected int minimumRating;
|
||||||
protected int edhPowerLevel;
|
protected int edhPowerLevel;
|
||||||
protected boolean rated;
|
protected boolean rated;
|
||||||
protected int numSeatsForMatch;
|
|
||||||
protected Set<String> bannedUsers = new HashSet<>();
|
protected Set<String> bannedUsers = new HashSet<>();
|
||||||
|
|
||||||
/**
|
protected MatchTimeLimit matchTimeLimit = MatchTimeLimit.NONE; // total time limit for priority
|
||||||
* Time each player has during the game to play using his\her 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 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 Collection<DeckCardInfo> perPlayerEmblemCards;
|
protected Collection<DeckCardInfo> perPlayerEmblemCards;
|
||||||
protected Collection<DeckCardInfo> globalEmblemCards;
|
protected Collection<DeckCardInfo> globalEmblemCards;
|
||||||
|
|
@ -178,26 +174,12 @@ public class MatchOptions implements Serializable {
|
||||||
this.limited = limited;
|
this.limited = limited;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPriorityTime() {
|
|
||||||
if (matchTimeLimit == null) {
|
|
||||||
return MatchTimeLimit.NONE.getTimeLimit();
|
|
||||||
}
|
|
||||||
return matchTimeLimit.getTimeLimit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatchTimeLimit getMatchTimeLimit() {
|
public MatchTimeLimit getMatchTimeLimit() {
|
||||||
return this.matchTimeLimit;
|
return this.matchTimeLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMatchTimeLimit(MatchTimeLimit matchTimeLimit) {
|
public void setMatchTimeLimit(MatchTimeLimit matchTimeLimit) {
|
||||||
this.matchTimeLimit = matchTimeLimit;
|
this.matchTimeLimit = Optional.ofNullable(matchTimeLimit).orElse(MatchTimeLimit.NONE);
|
||||||
}
|
|
||||||
|
|
||||||
public int getBufferTime() {
|
|
||||||
if (matchBufferTime == null) {
|
|
||||||
return MatchBufferTime.NONE.getBufferTime();
|
|
||||||
}
|
|
||||||
return matchBufferTime.getBufferTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MatchBufferTime getMatchBufferTime() {
|
public MatchBufferTime getMatchBufferTime() {
|
||||||
|
|
@ -205,7 +187,7 @@ public class MatchOptions implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMatchBufferTime(MatchBufferTime matchBufferTime) {
|
public void setMatchBufferTime(MatchBufferTime matchBufferTime) {
|
||||||
this.matchBufferTime = matchBufferTime;
|
this.matchBufferTime = Optional.ofNullable(matchBufferTime).orElse(MatchBufferTime.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
|
|
@ -295,9 +277,10 @@ public class MatchOptions implements Serializable {
|
||||||
.setRated(this.isRated())
|
.setRated(this.isRated())
|
||||||
.setWinsNeeded(this.getWinsNeeded());
|
.setWinsNeeded(this.getWinsNeeded());
|
||||||
|
|
||||||
ResultProtos.SkillLevel skillLevel = ResultProtos.SkillLevel.BEGINNER;
|
ResultProtos.SkillLevel skillLevel;
|
||||||
switch (this.getSkillLevel()) {
|
switch (this.getSkillLevel()) {
|
||||||
case BEGINNER:
|
case BEGINNER:
|
||||||
|
default:
|
||||||
skillLevel = ResultProtos.SkillLevel.BEGINNER;
|
skillLevel = ResultProtos.SkillLevel.BEGINNER;
|
||||||
break;
|
break;
|
||||||
case CASUAL:
|
case CASUAL:
|
||||||
|
|
@ -313,13 +296,10 @@ public class MatchOptions implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMullgianType(MulliganType mulliganType) {
|
public void setMullgianType(MulliganType mulliganType) {
|
||||||
this.mulliganType = mulliganType;
|
this.mulliganType = Optional.ofNullable(mulliganType).orElse(MulliganType.GAME_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MulliganType getMulliganType() {
|
public MulliganType getMulliganType() {
|
||||||
if (mulliganType == null) {
|
|
||||||
return MulliganType.GAME_DEFAULT;
|
|
||||||
}
|
|
||||||
return mulliganType;
|
return mulliganType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ public class MatchPlayer implements Serializable {
|
||||||
|
|
||||||
private boolean quit;
|
private boolean quit;
|
||||||
private boolean doneSideboarding;
|
private boolean doneSideboarding;
|
||||||
private int priorityTimeLeft;
|
private int priorityTimeLeft; // keep left time for next game
|
||||||
|
|
||||||
public MatchPlayer(Player player, Deck deck, Match match) {
|
public MatchPlayer(Player player, Deck deck, Match match) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
|
|
||||||
|
|
@ -4548,8 +4548,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPriorityTimeLeft(int timeLeft
|
public void setPriorityTimeLeft(int timeLeft) {
|
||||||
) {
|
|
||||||
priorityTimeLeft = timeLeft;
|
priorityTimeLeft = timeLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue