Drafts: refactor to use same pack/pick number logic (#8039);

This commit is contained in:
Oleg Agafonov 2021-07-23 16:18:56 +04:00
parent 400acae0c1
commit 06ae494c5b
10 changed files with 41 additions and 52 deletions

View file

@ -17,18 +17,21 @@ public class BoosterDraft extends DraftImpl {
@Override
public void start() {
cardNum = 0;
while (!isAbort() && boosterNum < numberBoosters) {
cardNum = 1;
boosterNum = 1;
while (!isAbort() && boosterNum <= numberBoosters) {
openBooster();
cardNum = 0;
cardNum = 1;
fireUpdatePlayersEvent();
while (!isAbort() && pickCards()) {
if (boosterNum % 2 == 1) {
if ((boosterNum + 1) % 2 == 1) {
passLeft();
} else {
passRight();
}
fireUpdatePlayersEvent();
}
boosterNum++;
}
resetBufferedCards();
this.fireEndDraftEvent();

View file

@ -22,8 +22,8 @@ public abstract class DraftImpl implements Draft {
protected DraftCube draftCube;
protected List<ExpansionSet> sets;
protected List<String> setCodes;
protected int boosterNum = 0;
protected int cardNum = 0; // increases +1 on first picking (so draft get 1 as first card number)
protected int boosterNum = 1; // starts with booster 1
protected int cardNum = 1; // starts with card number 1, increases by +1 after each picking
protected TimingOption timing;
protected boolean abort = false;
@ -192,21 +192,18 @@ public abstract class DraftImpl implements Draft {
}
protected void openBooster() {
if (boosterNum < numberBoosters) {
if (boosterNum <= numberBoosters) {
for (DraftPlayer player : players.values()) {
if (draftCube != null) {
player.setBooster(draftCube.createBooster());
} else {
player.setBooster(sets.get(boosterNum).createBooster());
player.setBooster(sets.get(boosterNum - 1).createBooster());
}
}
}
boosterNum++;
fireUpdatePlayersEvent();
}
protected boolean pickCards() {
cardNum++;
for (DraftPlayer player : players.values()) {
if (player.getBooster().isEmpty()) {
return false;
@ -214,6 +211,7 @@ public abstract class DraftImpl implements Draft {
player.setPicking();
player.getPlayer().pickCard(player.getBooster(), player.getDeck(), this);
}
cardNum++;
synchronized (this) {
while (!donePicking()) {
try {
@ -264,9 +262,7 @@ public abstract class DraftImpl implements Draft {
@Override
public void firePickCardEvent(UUID playerId) {
DraftPlayer player = players.get(playerId);
if (cardNum > 15) {
cardNum = 15;
}
int cardNum = Math.min(15, this.cardNum);
int time = timing.getPickTimeout(cardNum);
playerQueryEventSource.pickCard(playerId, "Pick card", player.getBooster(), time);
}

View file

@ -22,7 +22,7 @@ public class DraftOptions extends LimitedOptions implements Serializable {
REGULAR("x1.5", "Regular (x1.5)", 1.5,
Arrays.asList(113, 105, 98, 90, 83, 75, 68, 60, 35, 30, 25, 20, 15, 10, 8)
),
PROFI("x1.0", "Profi (x1.0)", 1.0,
PROFI("x1.0", "Professional (x1.0)", 1.0,
Arrays.asList(75, 70, 65, 60, 55, 50, 45, 40, 30, 25, 20, 15, 12, 10, 7)
),
NONE("ERROR", "", 0,

View file

@ -69,11 +69,6 @@ public class DraftPlayer {
picking = false;
}
// public void openBooster(ExpansionSet set) {
// synchronized(booster) {
// booster = set.createBooster();
// }
// }
public void setBooster(List<Card> booster) {
this.booster = booster;
}

View file

@ -26,13 +26,11 @@ public class RandomBoosterDraft extends BoosterDraft {
@Override
protected void openBooster() {
if (boosterNum < numberBoosters) {
if (boosterNum <= numberBoosters) {
for (DraftPlayer player: players.values()) {
player.setBooster(getNextBooster().create15CardBooster());
}
}
boosterNum++;
fireUpdatePlayersEvent();
}
private ExpansionSet getNextBooster() {

View file

@ -25,14 +25,17 @@ public class RichManBoosterDraft extends DraftImpl {
@Override
public void start() {
cardNum = 0;
while (!isAbort() && cardNum < 36) {
cardNum = 1;
boosterNum = 1;
while (!isAbort() && cardNum <= 36) {
openBooster();
cardNum = 0;
cardNum = 1;
fireUpdatePlayersEvent();
while (!isAbort() && pickCards()) {
passLeft();
fireUpdatePlayersEvent();
}
boosterNum++;
}
resetBufferedCards();
this.fireEndDraftEvent();
@ -46,7 +49,7 @@ public class RichManBoosterDraft extends DraftImpl {
UUID nextId = table.getNext();
DraftPlayer next = players.get(nextId);
while (true) {
List<Card> nextBooster = sets.get(cardNum % sets.size()).createBooster();
List<Card> nextBooster = sets.get((cardNum - 1) % sets.size()).createBooster();
next.setBooster(nextBooster);
if (Objects.equals(nextId, startId)) {
break;
@ -59,7 +62,6 @@ public class RichManBoosterDraft extends DraftImpl {
@Override
protected boolean pickCards() {
cardNum++;
for (DraftPlayer player : players.values()) {
if (cardNum > 36) {
return false;
@ -67,6 +69,7 @@ public class RichManBoosterDraft extends DraftImpl {
player.setPicking();
player.getPlayer().pickCard(player.getBooster(), player.getDeck(), this);
}
cardNum++;
synchronized (this) {
while (!donePicking()) {
try {
@ -81,13 +84,7 @@ public class RichManBoosterDraft extends DraftImpl {
@Override
public void firePickCardEvent(UUID playerId) {
DraftPlayer player = players.get(playerId);
if (cardNum > 36) {
cardNum = 36;
}
if (cardNum <= 0) {
cardNum = 1;
}
int cardNum = Math.min(36, this.cardNum);
// richman uses custom times
int time = (int) Math.ceil(customProfiTimes[cardNum - 1] * timing.getCustomTimeoutFactor());
playerQueryEventSource.pickCard(playerId, "Pick card", player.getBooster(), time);

View file

@ -23,14 +23,17 @@ public class RichManCubeBoosterDraft extends DraftImpl {
@Override
public void start() {
cardNum = 0;
while (!isAbort() && cardNum < 36) {
cardNum = 1;
boosterNum = 1;
while (!isAbort() && cardNum <= 36) {
openBooster();
cardNum = 0;
cardNum = 1;
fireUpdatePlayersEvent();
while (!isAbort() && pickCards()) {
passLeft();
fireUpdatePlayersEvent();
}
boosterNum++;
}
resetBufferedCards();
this.fireEndDraftEvent();
@ -74,7 +77,6 @@ public class RichManCubeBoosterDraft extends DraftImpl {
@Override
protected boolean pickCards() {
cardNum++;
for (DraftPlayer player : players.values()) {
if (cardNum > 36) {
return false;
@ -82,6 +84,7 @@ public class RichManCubeBoosterDraft extends DraftImpl {
player.setPicking();
player.getPlayer().pickCard(player.getBooster(), player.getDeck(), this);
}
cardNum++;
synchronized (this) {
while (!donePicking()) {
try {
@ -96,12 +99,7 @@ public class RichManCubeBoosterDraft extends DraftImpl {
@Override
public void firePickCardEvent(UUID playerId) {
DraftPlayer player = players.get(playerId);
if (cardNum > 36) {
cardNum = 36;
}
if (cardNum <= 0) {
cardNum = 1;
}
int cardNum = Math.min(36, this.cardNum);
// richman uses custom times
int time = (int) Math.ceil(customProfiTimes[cardNum - 1] * timing.getCustomTimeoutFactor());