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) {
|
||||
if (event.getEventName().equals("pick-a-card")) {
|
||||
SimpleCardView source = (SimpleCardView) event.getSource();
|
||||
DraftPickView view = session.sendCardPick(draftId, source.getId());
|
||||
DraftPickView view = session.sendCardPick(draftId, source.getId(), cardsHidden);
|
||||
if (view != null) {
|
||||
loadCardsToPickedCardsArea(view.getPicks());
|
||||
draftBooster.loadBooster(emptyView, bigCard);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
package mage.interfaces;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
|
@ -130,7 +131,7 @@ public interface MageServer {
|
|||
//draft methods
|
||||
void joinDraft(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;
|
||||
|
||||
//challenge methods
|
||||
|
|
|
|||
|
|
@ -758,10 +758,10 @@ public class SessionImpl implements Session {
|
|||
}
|
||||
|
||||
@Override
|
||||
public DraftPickView sendCardPick(UUID draftId, UUID cardId) {
|
||||
public DraftPickView sendCardPick(UUID draftId, UUID cardId, Set<UUID> hiddenCards) {
|
||||
try {
|
||||
if (isConnected()) {
|
||||
return server.sendCardPick(draftId, sessionId, cardId);
|
||||
return server.sendCardPick(draftId, sessionId, cardId, hiddenCards);
|
||||
}
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
package mage.remote.interfaces;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.constants.ManaType;
|
||||
|
|
@ -64,7 +65,7 @@ public interface GamePlay {
|
|||
|
||||
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);
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1716,10 +1716,10 @@ public class ComputerPlayer extends PlayerImpl implements Player {
|
|||
}
|
||||
}
|
||||
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) {
|
||||
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.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import mage.MageException;
|
||||
|
|
@ -667,13 +668,13 @@ public class MageServerImpl implements MageServer {
|
|||
}
|
||||
|
||||
@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>() {
|
||||
@Override
|
||||
public DraftPickView execute() {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
return DraftManager.getInstance().sendCardPick(draftId, session.getUserId(), cardPick);
|
||||
return DraftManager.getInstance().sendCardPick(draftId, session.getUserId(), cardPick, hiddenCards);
|
||||
} else{
|
||||
logger.error("Session not found sessionId: "+ sessionId + " draftId:" + draftId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -854,6 +854,7 @@ public class TableController {
|
|||
|
||||
public void endDraft(Draft draft) {
|
||||
for (DraftPlayer player: draft.getPlayers()) {
|
||||
player.prepareDeck();
|
||||
tournament.getPlayer(player.getPlayer().getId()).setDeck(player.getDeck());
|
||||
}
|
||||
tournament.nextStep();
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ package mage.server.draft;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.MageException;
|
||||
|
|
@ -60,7 +61,7 @@ public class DraftController {
|
|||
private final UUID draftSessionId;
|
||||
private final Draft draft;
|
||||
private final UUID tableId;
|
||||
private UUID markedCard;
|
||||
private final UUID markedCard;
|
||||
|
||||
public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||
draftSessionId = UUID.randomUUID();
|
||||
|
|
@ -214,7 +215,7 @@ public class DraftController {
|
|||
if (draftSession != null) {
|
||||
UUID cardId = draftSession.getMarkedCard();
|
||||
if (cardId != null) {
|
||||
sendCardPick(userId, cardId);
|
||||
sendCardPick(userId, cardId, null);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -227,11 +228,11 @@ public class DraftController {
|
|||
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));
|
||||
if (draftSession != null) {
|
||||
draftSession.setMarkedCard(null);
|
||||
return draftSession.sendCardPick(cardId);
|
||||
return draftSession.sendCardPick(cardId, hiddenCards);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.server.draft;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.game.draft.Draft;
|
||||
|
|
@ -62,8 +63,8 @@ public class DraftManager {
|
|||
draftControllers.remove(gameId);
|
||||
}
|
||||
|
||||
public DraftPickView sendCardPick(UUID draftId, UUID userId, UUID cardId) {
|
||||
return draftControllers.get(draftId).sendCardPick(userId, cardId);
|
||||
public DraftPickView sendCardPick(UUID draftId, UUID userId, UUID cardId, Set<UUID> hiddenCards) {
|
||||
return draftControllers.get(draftId).sendCardPick(userId, cardId, hiddenCards);
|
||||
}
|
||||
|
||||
public void sendCardMark(UUID draftId, UUID userId, UUID cardId) {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
package mage.server.draft;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
|
@ -150,9 +151,9 @@ public class DraftSession {
|
|||
killed = true;
|
||||
}
|
||||
|
||||
public DraftPickView sendCardPick(UUID cardId) {
|
||||
public DraftPickView sendCardPick(UUID cardId, Set<UUID> hiddenCards) {
|
||||
cancelTimeout();
|
||||
if (draft.addPick(playerId, cardId)) {
|
||||
if (draft.addPick(playerId, cardId, hiddenCards)) {
|
||||
return getDraftPickView(0);
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ package mage.game.draft;
|
|||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.MageItem;
|
||||
import mage.cards.ExpansionSet;
|
||||
|
|
@ -54,7 +55,7 @@ public interface Draft extends MageItem, Serializable {
|
|||
List<ExpansionSet> getSets();
|
||||
int getBoosterNum();
|
||||
int getCardNum();
|
||||
boolean addPick(UUID playerId, UUID cardId);
|
||||
boolean addPick(UUID playerId, UUID cardId, Set<UUID> hiddenCards);
|
||||
void start();
|
||||
boolean isStarted();
|
||||
void setStarted();
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import java.util.Collection;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
|
|
@ -180,7 +181,7 @@ public abstract class DraftImpl implements Draft {
|
|||
|
||||
@Override
|
||||
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() {
|
||||
|
|
@ -313,12 +314,12 @@ public abstract class DraftImpl implements Draft {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean addPick(UUID playerId, UUID cardId) {
|
||||
public boolean addPick(UUID playerId, UUID cardId, Set<UUID> hiddenCards) {
|
||||
DraftPlayer player = players.get(playerId);
|
||||
if (player.isPicking()) {
|
||||
for (Card card: player.booster) {
|
||||
if (card.getId().equals(cardId)) {
|
||||
player.addPick(card);
|
||||
player.addPick(card, hiddenCards);
|
||||
player.booster.remove(card);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@
|
|||
package mage.game.draft;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
|
|
@ -48,11 +50,13 @@ public class DraftPlayer {
|
|||
protected List<Card> booster;
|
||||
protected boolean picking;
|
||||
protected boolean joined = false;
|
||||
protected Set<UUID> hiddenCards;
|
||||
|
||||
public DraftPlayer(Player player) {
|
||||
id = UUID.randomUUID();
|
||||
this.player = player;
|
||||
this.deck = new Deck();
|
||||
hiddenCards = new HashSet<>();
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
|
|
@ -63,12 +67,30 @@ public class DraftPlayer {
|
|||
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() {
|
||||
return deck;
|
||||
}
|
||||
|
||||
public void addPick(Card card) {
|
||||
public void addPick(Card card, Set<UUID> hiddenCards) {
|
||||
deck.getSideboard().add(card);
|
||||
if (hiddenCards != null) {
|
||||
this.hiddenCards = hiddenCards;
|
||||
}
|
||||
synchronized(booster) {
|
||||
booster.remove(card);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue