server: fixed npe error on load tests (miss buffer timer), code refactor

This commit is contained in:
Oleg Agafonov 2023-10-11 14:14:58 +04:00
parent 09dbdccfb2
commit fe8b8e1def
9 changed files with 39 additions and 57 deletions

View file

@ -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() {

View file

@ -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() {

View file

@ -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() {

View file

@ -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;
}

View file

@ -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;

View file

@ -4548,8 +4548,7 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public void setPriorityTimeLeft(int timeLeft
) {
public void setPriorityTimeLeft(int timeLeft) {
priorityTimeLeft = timeLeft;
}