mirror of
https://github.com/correl/mage.git
synced 2024-12-01 03:00:09 +00:00
Drafts: refactor to use same pack/pick number logic (#8039);
This commit is contained in:
parent
400acae0c1
commit
06ae494c5b
10 changed files with 41 additions and 52 deletions
|
@ -62,9 +62,11 @@
|
|||
private List<String> setCodes;
|
||||
|
||||
// Number of the current booster (for draft log writing).
|
||||
// starts with 1
|
||||
private int packNo;
|
||||
|
||||
// Number of the current card pick (for draft log writing).
|
||||
// starts with 1
|
||||
private int pickNo;
|
||||
|
||||
// Cached booster data to be written into the log (see logLastPick).
|
||||
|
@ -155,9 +157,9 @@
|
|||
this.txtPack2.setText(draftView.getSets().get(1));
|
||||
this.txtPack3.setText(draftView.getSets().get(2));
|
||||
}
|
||||
this.chkPack1.setSelected(draftView.getBoosterNum() > 0);
|
||||
this.chkPack2.setSelected(draftView.getBoosterNum() > 1);
|
||||
this.chkPack3.setSelected(draftView.getBoosterNum() > 2);
|
||||
this.chkPack1.setSelected(draftView.getBoosterNum() > 1);
|
||||
this.chkPack2.setSelected(draftView.getBoosterNum() > 2);
|
||||
this.chkPack3.setSelected(draftView.getBoosterNum() > 3);
|
||||
this.txtCardNo.setText(Integer.toString(draftView.getCardNum()));
|
||||
|
||||
packNo = draftView.getBoosterNum();
|
||||
|
@ -169,7 +171,7 @@
|
|||
int left = draftView.getPlayers().size() - right;
|
||||
int height = left * 18;
|
||||
lblTableImage.setSize(new Dimension(lblTableImage.getWidth(), height));
|
||||
Image tableImage = ImageHelper.getImageFromResources(draftView.getBoosterNum() == 2 ? "/draft/table_left.png" : "/draft/table_right.png");
|
||||
Image tableImage = ImageHelper.getImageFromResources((draftView.getBoosterNum() + 1) % 2 == 1 ? "/draft/table_left.png" : "/draft/table_right.png");
|
||||
BufferedImage resizedTable = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(tableImage, BufferedImage.TYPE_INT_ARGB), lblTableImage.getWidth(), lblTableImage.getHeight());
|
||||
lblTableImage.setIcon(new ImageIcon(resizedTable));
|
||||
|
||||
|
@ -414,7 +416,7 @@
|
|||
if (currentBooster != null) {
|
||||
String lastPick = getCardName(getLastPick(pickView.getPicks().values()));
|
||||
if (lastPick != null && currentBooster.length > 1) {
|
||||
draftLogger.logPick(getCurrentSetCode(), packNo, pickNo - 1, lastPick, currentBooster);
|
||||
draftLogger.logPick(getCurrentSetCode(), packNo, pickNo - 1, lastPick, currentBooster); // wtf pickno need -1?
|
||||
}
|
||||
currentBooster = null;
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ public class TableView implements Serializable {
|
|||
case DRAFTING:
|
||||
Draft draft = table.getTournament().getDraft();
|
||||
if (draft != null) {
|
||||
stateText.append(' ').append(draft.getBoosterNum()).append('/').append(draft.getCardNum() - 1);
|
||||
stateText.append(' ').append(draft.getBoosterNum()).append('/').append(draft.getCardNum());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -53,7 +53,7 @@ public class TournamentView implements Serializable {
|
|||
tournamentState = tournament.getTournamentState();
|
||||
|
||||
if (tournament.getTournamentState().equals("Drafting") && tournament.getDraft() != null) {
|
||||
runningInfo = "booster/card: " + tournament.getDraft().getBoosterNum() + '/' + (tournament.getDraft().getCardNum() -1);
|
||||
runningInfo = "booster/card: " + tournament.getDraft().getBoosterNum() + '/' + (tournament.getDraft().getCardNum());
|
||||
} else {
|
||||
runningInfo = "";
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue