mirror of
https://github.com/magefree/mage.git
synced 2026-01-23 19:59:54 -08:00
* Draft - Added "Quit Tournament" button to draft panel. Minor formatting.
This commit is contained in:
parent
024ec1169a
commit
8d2f4cc9ac
26 changed files with 340 additions and 157 deletions
|
|
@ -39,8 +39,8 @@ import mage.game.GameException;
|
|||
public class Deck implements Serializable {
|
||||
|
||||
private String name;
|
||||
private Set<Card> cards = new LinkedHashSet<Card>();
|
||||
private Set<Card> sideboard = new LinkedHashSet<Card>();
|
||||
private final Set<Card> cards = new LinkedHashSet<>();
|
||||
private final Set<Card> sideboard = new LinkedHashSet<>();
|
||||
|
||||
public static Deck load(DeckCardLists deckCardLists) throws GameException {
|
||||
return Deck.load(deckCardLists, false);
|
||||
|
|
@ -102,7 +102,7 @@ public class Deck implements Serializable {
|
|||
}
|
||||
|
||||
public Set<String> getExpansionSetCodes() {
|
||||
Set<String> sets = new LinkedHashSet<String>();
|
||||
Set<String> sets = new LinkedHashSet<>();
|
||||
for (Card card : getCards()) {
|
||||
if (!sets.contains(card.getExpansionSetCode())) {
|
||||
sets.add(card.getExpansionSetCode());
|
||||
|
|
|
|||
|
|
@ -43,13 +43,12 @@ public class BoosterDraft extends DraftImpl<BoosterDraft> {
|
|||
|
||||
@Override
|
||||
public void start() {
|
||||
while (boosterNum < numberBoosters) {
|
||||
while (!isAbort() && boosterNum < numberBoosters) {
|
||||
openBooster();
|
||||
while (!isAbort() && pickCards()) {
|
||||
if (boosterNum % 2 == 1) {
|
||||
passLeft();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
passRight();
|
||||
}
|
||||
fireUpdatePlayersEvent();
|
||||
|
|
|
|||
|
|
@ -48,12 +48,13 @@ import mage.players.PlayerList;
|
|||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
||||
|
||||
protected final UUID id;
|
||||
protected Map<UUID, DraftPlayer> players = new HashMap<UUID, DraftPlayer>();
|
||||
protected PlayerList table = new PlayerList();
|
||||
protected final Map<UUID, DraftPlayer> players = new HashMap<>();
|
||||
protected final PlayerList table = new PlayerList();
|
||||
protected int numberBoosters;
|
||||
protected DraftCube draftCube;
|
||||
protected List<ExpansionSet> sets;
|
||||
|
|
@ -95,7 +96,7 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
|||
DraftPlayer newDraftPlayer = new DraftPlayer(newPlayer);
|
||||
DraftPlayer oldDraftPlayer = players.get(oldPlayer.getId());
|
||||
newDraftPlayer.setBooster(oldDraftPlayer.getBooster());
|
||||
Map<UUID, DraftPlayer> newPlayers = new HashMap<UUID, DraftPlayer>();
|
||||
Map<UUID, DraftPlayer> newPlayers = new HashMap<>();
|
||||
PlayerList newTable = new PlayerList();
|
||||
synchronized (players) {
|
||||
for(Map.Entry<UUID, DraftPlayer> entry :players.entrySet()) {
|
||||
|
|
@ -105,7 +106,10 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
|||
newPlayers.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
players = newPlayers;
|
||||
players.clear();
|
||||
for (Map.Entry<UUID, DraftPlayer> entry: newPlayers.entrySet()) {
|
||||
players.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
synchronized (table) {
|
||||
for(UUID playerId :table) {
|
||||
|
|
@ -115,7 +119,8 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
|||
newTable.add(playerId);
|
||||
}
|
||||
}
|
||||
table = newTable;
|
||||
table.clear();
|
||||
table.addAll(newTable);
|
||||
}
|
||||
if (oldDraftPlayer.isPicking()) {
|
||||
newDraftPlayer.setPicking();
|
||||
|
|
@ -179,13 +184,13 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
|||
this.addPick(playerId, players.get(playerId).getBooster().get(0).getId());
|
||||
}
|
||||
|
||||
protected void passLeft() {
|
||||
protected void passLeft() {
|
||||
synchronized (players) {
|
||||
UUID startId = table.get(0);
|
||||
UUID currentId = startId;
|
||||
UUID nextId = table.getNext();
|
||||
DraftPlayer current = players.get(currentId);
|
||||
DraftPlayer next = players.get(nextId);
|
||||
DraftPlayer current = players.get(currentId);
|
||||
DraftPlayer next = players.get(nextId);
|
||||
List<Card> currentBooster = current.booster;
|
||||
while (true) {
|
||||
List<Card> nextBooster = next.booster;
|
||||
|
|
@ -194,8 +199,6 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
|||
break;
|
||||
}
|
||||
currentBooster = nextBooster;
|
||||
current = next;
|
||||
currentId = nextId;
|
||||
nextId = table.getNext();
|
||||
next = players.get(nextId);
|
||||
}
|
||||
|
|
@ -217,8 +220,6 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
|||
break;
|
||||
}
|
||||
currentBooster = prevBooster;
|
||||
current = prev;
|
||||
currentId = prevId;
|
||||
prevId = table.getPrevious();
|
||||
prev = players.get(prevId);
|
||||
}
|
||||
|
|
@ -261,6 +262,9 @@ public abstract class DraftImpl<T extends DraftImpl<T>> implements Draft {
|
|||
}
|
||||
|
||||
protected boolean donePicking() {
|
||||
if(isAbort()) {
|
||||
return true;
|
||||
}
|
||||
for (DraftPlayer player: players.values()) {
|
||||
if (player.isPicking()) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public class DraftPlayer {
|
|||
|
||||
public List<Card> getBooster() {
|
||||
synchronized(booster) {
|
||||
return new ArrayList<Card>(booster);
|
||||
return new ArrayList<>(booster);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,5 +84,6 @@ public interface Tournament {
|
|||
|
||||
int getNumberRounds();
|
||||
void cleanUpOnTournamentEnd();
|
||||
|
||||
boolean isAbort();
|
||||
void setAbort(boolean abort);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,10 +73,12 @@ public abstract class TournamentImpl implements Tournament {
|
|||
|
||||
protected Date startTime;
|
||||
protected Date endTime;
|
||||
protected boolean abort;
|
||||
|
||||
public TournamentImpl(TournamentOptions options) {
|
||||
this.options = options;
|
||||
startTime = new Date();
|
||||
abort = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -320,22 +322,25 @@ public abstract class TournamentImpl implements Tournament {
|
|||
|
||||
public void construct() {
|
||||
tableEventSource.fireTableEvent(EventType.CONSTRUCT);
|
||||
for (final TournamentPlayer player: players.values()) {
|
||||
player.setConstructing();
|
||||
new Thread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.getPlayer().construct(TournamentImpl.this, player.getDeck());
|
||||
if (!isAbort()) {
|
||||
for (final TournamentPlayer player: players.values()) {
|
||||
|
||||
player.setConstructing();
|
||||
new Thread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.getPlayer().construct(TournamentImpl.this, player.getDeck());
|
||||
}
|
||||
}
|
||||
).start();
|
||||
}
|
||||
synchronized(this) {
|
||||
while (!isDoneConstructing()) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException ex) { }
|
||||
}
|
||||
).start();
|
||||
}
|
||||
synchronized(this) {
|
||||
while (!isDoneConstructing()) {
|
||||
try {
|
||||
this.wait();
|
||||
} catch (InterruptedException ex) { }
|
||||
}
|
||||
}
|
||||
nextStep();
|
||||
|
|
@ -406,7 +411,11 @@ public abstract class TournamentImpl implements Tournament {
|
|||
for(TournamentPlayer winner: this.getActivePlayers()) {
|
||||
winner.setState(TournamentPlayerState.FINISHED);
|
||||
if (options.getNumberRounds() == 0) { // if no swiss, last active is the winner
|
||||
winner.setStateInfo("Winner");
|
||||
if (isAbort()) {
|
||||
winner.setStateInfo("Tournament canceled");
|
||||
} else {
|
||||
winner.setStateInfo("Winner");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -418,4 +427,14 @@ public abstract class TournamentImpl implements Tournament {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbort() {
|
||||
return abort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAbort(boolean abort) {
|
||||
this.abort = abort;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,5 +170,15 @@ public class TournamentPlayer {
|
|||
public void CleanUpOnTournamentEnd() {
|
||||
this.deck = null;
|
||||
}
|
||||
|
||||
public void setStateAtTournamentEnd() {
|
||||
if (this.getState().equals(TournamentPlayerState.DRAFTING)
|
||||
|| this.getState().equals(TournamentPlayerState.CONSTRUCTING)
|
||||
|| this.getState().equals(TournamentPlayerState.DUELING)
|
||||
|| this.getState().equals(TournamentPlayerState.SIDEBOARDING)
|
||||
|| this.getState().equals(TournamentPlayerState.WAITING)) {
|
||||
this.setState(TournamentPlayerState.FINISHED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue