forked from External/mage
*Draft - Non hidden picked cards go to the deck. Hidden cards to sideboard.
This commit is contained in:
parent
b0238b402e
commit
c22b54d262
13 changed files with 53 additions and 22 deletions
|
|
@ -270,7 +270,7 @@ public class DraftPanel extends javax.swing.JPanel {
|
||||||
public void event(Event event) {
|
public void event(Event event) {
|
||||||
if (event.getEventName().equals("pick-a-card")) {
|
if (event.getEventName().equals("pick-a-card")) {
|
||||||
SimpleCardView source = (SimpleCardView) event.getSource();
|
SimpleCardView source = (SimpleCardView) event.getSource();
|
||||||
DraftPickView view = session.sendCardPick(draftId, source.getId());
|
DraftPickView view = session.sendCardPick(draftId, source.getId(), cardsHidden);
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
loadCardsToPickedCardsArea(view.getPicks());
|
loadCardsToPickedCardsArea(view.getPicks());
|
||||||
draftBooster.loadBooster(emptyView, bigCard);
|
draftBooster.loadBooster(emptyView, bigCard);
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
package mage.interfaces;
|
package mage.interfaces;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
|
|
@ -130,7 +131,7 @@ public interface MageServer {
|
||||||
//draft methods
|
//draft methods
|
||||||
void joinDraft(UUID draftId, String sessionId) throws MageException;
|
void joinDraft(UUID draftId, String sessionId) throws MageException;
|
||||||
void quitDraft(UUID draftId, String sessionId) throws MageException;
|
void quitDraft(UUID draftId, String sessionId) throws MageException;
|
||||||
DraftPickView sendCardPick(UUID draftId, String sessionId, UUID cardId) throws MageException;
|
DraftPickView sendCardPick(UUID draftId, String sessionId, UUID cardId, Set<UUID> hiddenCards) throws MageException;
|
||||||
void sendCardMark(UUID draftId, String sessionId, UUID cardId) throws MageException;
|
void sendCardMark(UUID draftId, String sessionId, UUID cardId) throws MageException;
|
||||||
|
|
||||||
//challenge methods
|
//challenge methods
|
||||||
|
|
|
||||||
|
|
@ -758,10 +758,10 @@ public class SessionImpl implements Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DraftPickView sendCardPick(UUID draftId, UUID cardId) {
|
public DraftPickView sendCardPick(UUID draftId, UUID cardId, Set<UUID> hiddenCards) {
|
||||||
try {
|
try {
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
return server.sendCardPick(draftId, sessionId, cardId);
|
return server.sendCardPick(draftId, sessionId, cardId, hiddenCards);
|
||||||
}
|
}
|
||||||
} catch (MageException ex) {
|
} catch (MageException ex) {
|
||||||
handleMageException(ex);
|
handleMageException(ex);
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
*/
|
*/
|
||||||
package mage.remote.interfaces;
|
package mage.remote.interfaces;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
import mage.constants.ManaType;
|
import mage.constants.ManaType;
|
||||||
|
|
@ -64,7 +65,7 @@ public interface GamePlay {
|
||||||
|
|
||||||
boolean updateDeck(UUID tableId, DeckCardLists deck);
|
boolean updateDeck(UUID tableId, DeckCardLists deck);
|
||||||
|
|
||||||
DraftPickView sendCardPick(UUID draftId, UUID cardId);
|
DraftPickView sendCardPick(UUID draftId, UUID cardId, Set<UUID> hiddenCards);
|
||||||
DraftPickView sendCardMark(UUID draftId, UUID cardId);
|
DraftPickView sendCardMark(UUID draftId, UUID cardId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1716,10 +1716,10 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.debug("[DEBUG] AI picked: " + bestCard.getName() + ", score=" + maxScore + ", deck colors=" + colors);
|
log.debug("[DEBUG] AI picked: " + bestCard.getName() + ", score=" + maxScore + ", deck colors=" + colors);
|
||||||
draft.addPick(playerId, bestCard.getId());
|
draft.addPick(playerId, bestCard.getId(), null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
draft.addPick(playerId, cards.get(0).getId());
|
draft.addPick(playerId, cards.get(0).getId(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ package mage.server;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
|
|
@ -667,13 +668,13 @@ public class MageServerImpl implements MageServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DraftPickView sendCardPick(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
|
public DraftPickView sendCardPick(final UUID draftId, final String sessionId, final UUID cardPick, final Set<UUID> hiddenCards) throws MageException {
|
||||||
return executeWithResult("sendCardPick", sessionId, new ActionWithNullNegativeResult<DraftPickView>() {
|
return executeWithResult("sendCardPick", sessionId, new ActionWithNullNegativeResult<DraftPickView>() {
|
||||||
@Override
|
@Override
|
||||||
public DraftPickView execute() {
|
public DraftPickView execute() {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
return DraftManager.getInstance().sendCardPick(draftId, session.getUserId(), cardPick);
|
return DraftManager.getInstance().sendCardPick(draftId, session.getUserId(), cardPick, hiddenCards);
|
||||||
} else{
|
} else{
|
||||||
logger.error("Session not found sessionId: "+ sessionId + " draftId:" + draftId);
|
logger.error("Session not found sessionId: "+ sessionId + " draftId:" + draftId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -854,6 +854,7 @@ public class TableController {
|
||||||
|
|
||||||
public void endDraft(Draft draft) {
|
public void endDraft(Draft draft) {
|
||||||
for (DraftPlayer player: draft.getPlayers()) {
|
for (DraftPlayer player: draft.getPlayers()) {
|
||||||
|
player.prepareDeck();
|
||||||
tournament.getPlayer(player.getPlayer().getId()).setDeck(player.getDeck());
|
tournament.getPlayer(player.getPlayer().getId()).setDeck(player.getDeck());
|
||||||
}
|
}
|
||||||
tournament.nextStep();
|
tournament.nextStep();
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ package mage.server.draft;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
|
|
@ -60,7 +61,7 @@ public class DraftController {
|
||||||
private final UUID draftSessionId;
|
private final UUID draftSessionId;
|
||||||
private final Draft draft;
|
private final Draft draft;
|
||||||
private final UUID tableId;
|
private final UUID tableId;
|
||||||
private UUID markedCard;
|
private final UUID markedCard;
|
||||||
|
|
||||||
public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||||
draftSessionId = UUID.randomUUID();
|
draftSessionId = UUID.randomUUID();
|
||||||
|
|
@ -214,7 +215,7 @@ public class DraftController {
|
||||||
if (draftSession != null) {
|
if (draftSession != null) {
|
||||||
UUID cardId = draftSession.getMarkedCard();
|
UUID cardId = draftSession.getMarkedCard();
|
||||||
if (cardId != null) {
|
if (cardId != null) {
|
||||||
sendCardPick(userId, cardId);
|
sendCardPick(userId, cardId, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -227,11 +228,11 @@ public class DraftController {
|
||||||
return this.draftSessionId;
|
return this.draftSessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DraftPickView sendCardPick(UUID userId, UUID cardId) {
|
public DraftPickView sendCardPick(UUID userId, UUID cardId, Set<UUID> hiddenCards) {
|
||||||
DraftSession draftSession = draftSessions.get(userPlayerMap.get(userId));
|
DraftSession draftSession = draftSessions.get(userPlayerMap.get(userId));
|
||||||
if (draftSession != null) {
|
if (draftSession != null) {
|
||||||
draftSession.setMarkedCard(null);
|
draftSession.setMarkedCard(null);
|
||||||
return draftSession.sendCardPick(cardId);
|
return draftSession.sendCardPick(cardId, hiddenCards);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
package mage.server.draft;
|
package mage.server.draft;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mage.game.draft.Draft;
|
import mage.game.draft.Draft;
|
||||||
|
|
@ -62,8 +63,8 @@ public class DraftManager {
|
||||||
draftControllers.remove(gameId);
|
draftControllers.remove(gameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DraftPickView sendCardPick(UUID draftId, UUID userId, UUID cardId) {
|
public DraftPickView sendCardPick(UUID draftId, UUID userId, UUID cardId, Set<UUID> hiddenCards) {
|
||||||
return draftControllers.get(draftId).sendCardPick(userId, cardId);
|
return draftControllers.get(draftId).sendCardPick(userId, cardId, hiddenCards);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendCardMark(UUID draftId, UUID userId, UUID cardId) {
|
public void sendCardMark(UUID draftId, UUID userId, UUID cardId) {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
package mage.server.draft;
|
package mage.server.draft;
|
||||||
|
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
|
|
@ -150,9 +151,9 @@ public class DraftSession {
|
||||||
killed = true;
|
killed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DraftPickView sendCardPick(UUID cardId) {
|
public DraftPickView sendCardPick(UUID cardId, Set<UUID> hiddenCards) {
|
||||||
cancelTimeout();
|
cancelTimeout();
|
||||||
if (draft.addPick(playerId, cardId)) {
|
if (draft.addPick(playerId, cardId, hiddenCards)) {
|
||||||
return getDraftPickView(0);
|
return getDraftPickView(0);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ package mage.game.draft;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.MageItem;
|
import mage.MageItem;
|
||||||
import mage.cards.ExpansionSet;
|
import mage.cards.ExpansionSet;
|
||||||
|
|
@ -54,7 +55,7 @@ public interface Draft extends MageItem, Serializable {
|
||||||
List<ExpansionSet> getSets();
|
List<ExpansionSet> getSets();
|
||||||
int getBoosterNum();
|
int getBoosterNum();
|
||||||
int getCardNum();
|
int getCardNum();
|
||||||
boolean addPick(UUID playerId, UUID cardId);
|
boolean addPick(UUID playerId, UUID cardId, Set<UUID> hiddenCards);
|
||||||
void start();
|
void start();
|
||||||
boolean isStarted();
|
boolean isStarted();
|
||||||
void setStarted();
|
void setStarted();
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.cards.ExpansionSet;
|
import mage.cards.ExpansionSet;
|
||||||
|
|
@ -180,7 +181,7 @@ public abstract class DraftImpl implements Draft {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void autoPick(UUID playerId) {
|
public void autoPick(UUID playerId) {
|
||||||
this.addPick(playerId, players.get(playerId).getBooster().get(0).getId());
|
this.addPick(playerId, players.get(playerId).getBooster().get(0).getId(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void passLeft() {
|
protected void passLeft() {
|
||||||
|
|
@ -313,12 +314,12 @@ public abstract class DraftImpl implements Draft {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addPick(UUID playerId, UUID cardId) {
|
public boolean addPick(UUID playerId, UUID cardId, Set<UUID> hiddenCards) {
|
||||||
DraftPlayer player = players.get(playerId);
|
DraftPlayer player = players.get(playerId);
|
||||||
if (player.isPicking()) {
|
if (player.isPicking()) {
|
||||||
for (Card card: player.booster) {
|
for (Card card: player.booster) {
|
||||||
if (card.getId().equals(cardId)) {
|
if (card.getId().equals(cardId)) {
|
||||||
player.addPick(card);
|
player.addPick(card, hiddenCards);
|
||||||
player.booster.remove(card);
|
player.booster.remove(card);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,9 @@
|
||||||
package mage.game.draft;
|
package mage.game.draft;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.cards.ExpansionSet;
|
import mage.cards.ExpansionSet;
|
||||||
|
|
@ -48,11 +50,13 @@ public class DraftPlayer {
|
||||||
protected List<Card> booster;
|
protected List<Card> booster;
|
||||||
protected boolean picking;
|
protected boolean picking;
|
||||||
protected boolean joined = false;
|
protected boolean joined = false;
|
||||||
|
protected Set<UUID> hiddenCards;
|
||||||
|
|
||||||
public DraftPlayer(Player player) {
|
public DraftPlayer(Player player) {
|
||||||
id = UUID.randomUUID();
|
id = UUID.randomUUID();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.deck = new Deck();
|
this.deck = new Deck();
|
||||||
|
hiddenCards = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getId() {
|
public UUID getId() {
|
||||||
|
|
@ -63,12 +67,30 @@ public class DraftPlayer {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void prepareDeck() {
|
||||||
|
if (!hiddenCards.isEmpty()) {
|
||||||
|
Set<Card> cardsToDeck = new HashSet<>();
|
||||||
|
for(Card card: deck.getSideboard()) {
|
||||||
|
if (!hiddenCards.contains(card.getId())) {
|
||||||
|
cardsToDeck.add(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(Card card: cardsToDeck) {
|
||||||
|
deck.getSideboard().remove(card);
|
||||||
|
deck.getCards().add(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Deck getDeck() {
|
public Deck getDeck() {
|
||||||
return deck;
|
return deck;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPick(Card card) {
|
public void addPick(Card card, Set<UUID> hiddenCards) {
|
||||||
deck.getSideboard().add(card);
|
deck.getSideboard().add(card);
|
||||||
|
if (hiddenCards != null) {
|
||||||
|
this.hiddenCards = hiddenCards;
|
||||||
|
}
|
||||||
synchronized(booster) {
|
synchronized(booster) {
|
||||||
booster.remove(card);
|
booster.remove(card);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue