mirror of
https://github.com/correl/mage.git
synced 2025-04-14 09:09:38 -09:00
Challenge Mode. In progress.
This commit is contained in:
parent
86f708b17a
commit
be2fdd6487
10 changed files with 195 additions and 15 deletions
Mage.Client
Mage.Common/src/mage/interfaces
Mage.Server/src/main/java/mage/server
Mage/src/mage/game
29
Mage.Client/UW Control.dck
Normal file
29
Mage.Client/UW Control.dck
Normal file
|
@ -0,0 +1,29 @@
|
|||
NAME:UW Control
|
||||
2 [ROE:236] Island
|
||||
1 [ROE:235] Island
|
||||
1 [ROE:234] Island
|
||||
2 [ROE:233] Island
|
||||
2 [CON:15] Path to Exile
|
||||
3 [ROE:21] Gideon Jura
|
||||
1 [CON:11] Martial Coup
|
||||
2 [ZEN:9] Day of Judgment
|
||||
1 [ZEN:216] Kabira Crossroads
|
||||
4 [WWK:31] Jace, the Mind Sculptor
|
||||
3 [M10:64] Mind Spring
|
||||
3 [WWK:123] Everflowing Chalice
|
||||
1 [ROE:232] Plains
|
||||
4 [ROE:53] Wall of Omens
|
||||
1 [ROE:229] Plains
|
||||
1 [ROE:230] Plains
|
||||
1 [ROE:231] Plains
|
||||
3 [ALA:20] Oblivion Ring
|
||||
4 [ZEN:70] Spreading Seas
|
||||
4 [WWK:145] Tectonic Edge
|
||||
1 [ALA:9] Elspeth, Knight-Errant
|
||||
2 [ROE:59] Deprive
|
||||
1 [ZEN:220] Misty Rainforest
|
||||
4 [WWK:133] Celestial Colonnade
|
||||
1 [ZEN:211] Arid Mesa
|
||||
4 [M10:226] Glacial Fortress
|
||||
1 [WWK:142] Sejiri Steppe
|
||||
2 [M10:65] Negate
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
package mage.client;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.cards.CardsStorage;
|
||||
|
@ -76,7 +77,10 @@ import mage.client.draft.DraftPane;
|
|||
import mage.client.game.GamePane;
|
||||
import mage.client.table.TablesPane;
|
||||
import mage.client.tournament.TournamentPane;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.sets.Sets;
|
||||
import mage.view.TableView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
@ -506,11 +510,12 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
lblStatus = new javax.swing.JLabel();
|
||||
jSeparator6 = new javax.swing.JToolBar.Separator();
|
||||
btnCollectionViewer = new JButton();
|
||||
jSeparator7 = new javax.swing.JToolBar.Separator();
|
||||
btnChallenges = new JButton();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
|
||||
//setMinimumSize(new java.awt.Dimension(1024, 768));
|
||||
|
||||
|
||||
mageToolbar.setFloatable(false);
|
||||
mageToolbar.setRollover(true);
|
||||
|
||||
|
@ -566,6 +571,19 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
mageToolbar.add(btnCollectionViewer);
|
||||
mageToolbar.add(jSeparator6);
|
||||
|
||||
btnChallenges.setText("Challenges");
|
||||
btnChallenges.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
|
||||
btnChallenges.setFocusable(false);
|
||||
btnChallenges.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
|
||||
btnChallenges.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
|
||||
btnChallenges.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnChallengesActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
mageToolbar.add(btnChallenges);
|
||||
mageToolbar.add(jSeparator7);
|
||||
|
||||
btnPreferences.setText("Preferences");
|
||||
btnPreferences.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
|
||||
btnPreferences.setFocusable(false);
|
||||
|
@ -634,6 +652,31 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
showCollectionViewer();
|
||||
}
|
||||
|
||||
private void btnChallengesActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
TableView table;
|
||||
try {
|
||||
MatchOptions options = new MatchOptions("1", "Two Player Duel");
|
||||
options.getPlayerTypes().add("Human");
|
||||
options.getPlayerTypes().add("Computer - default");
|
||||
options.setDeckType("Limited");
|
||||
options.setAttackOption(Constants.MultiplayerAttackOption.LEFT);
|
||||
options.setRange(Constants.RangeOfInfluence.ALL);
|
||||
options.setWinsNeeded(1);
|
||||
|
||||
//TODO: maybe we should have separate room id for quests (so they won't be visible in main tables list)
|
||||
UUID roomId = MageFrame.getSession().getMainRoomId();
|
||||
|
||||
table = session.createTable(roomId, options);
|
||||
session.joinTable(roomId, table.getTableId(), "Human", "Human", 1, Sets.loadDeck("UW Control.dck"));
|
||||
session.joinTable(roomId, table.getTableId(), "Computer", "Computer - default", 1, Sets.loadDeck("UW Control.dck"));
|
||||
|
||||
//hideTables();
|
||||
session.startChallenge(roomId, table.getTableId(), UUID.randomUUID());
|
||||
} catch (Exception ex) {
|
||||
//handleError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnPreferencesActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
PhasesDialog.main(new String[]{});
|
||||
}
|
||||
|
@ -741,6 +784,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
private javax.swing.JButton btnConnect;
|
||||
private javax.swing.JButton btnDeckEditor;
|
||||
private javax.swing.JButton btnCollectionViewer;
|
||||
private javax.swing.JButton btnChallenges;
|
||||
private javax.swing.JButton btnPreferences;
|
||||
private javax.swing.JButton btnExit;
|
||||
private javax.swing.JButton btnGames;
|
||||
|
@ -751,6 +795,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
private javax.swing.JToolBar.Separator jSeparator4;
|
||||
private javax.swing.JToolBar.Separator jSeparator5;
|
||||
private javax.swing.JToolBar.Separator jSeparator6;
|
||||
private javax.swing.JToolBar.Separator jSeparator7;
|
||||
private javax.swing.JLabel lblStatus;
|
||||
private javax.swing.JToolBar mageToolbar;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
|
|
@ -573,6 +573,18 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean startChallenge(UUID roomId, UUID tableId, UUID challengeId) {
|
||||
try {
|
||||
server.startChallenge(sessionId, roomId, tableId, challengeId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean submitDeck(UUID tableId, DeckCardLists deck) {
|
||||
try {
|
||||
return server.submitDeck(sessionId, tableId, deck);
|
||||
|
@ -699,4 +711,8 @@ public class Session {
|
|||
return ui;
|
||||
}
|
||||
|
||||
public Server getServerRef() {
|
||||
return server;
|
||||
}
|
||||
|
||||
}
|
|
@ -101,6 +101,9 @@ public interface Server extends Remote, CallbackServer {
|
|||
public void joinDraft(UUID draftId, UUID sessionId) throws RemoteException, MageException;
|
||||
public DraftPickView sendCardPick(UUID draftId, UUID sessionId, UUID cardId) throws RemoteException, MageException;
|
||||
|
||||
//challenge methods
|
||||
public void startChallenge(UUID sessionId, UUID roomId, UUID tableId, UUID challengeId) throws RemoteException, MageException;
|
||||
|
||||
//replay methods
|
||||
public void replayGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void startReplay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
|
|
|
@ -266,6 +266,23 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startChallenge(final UUID sessionId, final UUID roomId, final UUID tableId, final UUID challengeId) throws RemoteException, MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TableManager.getInstance().startChallenge(sessionId, roomId, tableId, challengeId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startTournament(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
try {
|
||||
|
|
|
@ -28,35 +28,34 @@
|
|||
|
||||
package mage.server;
|
||||
|
||||
import mage.server.draft.DraftManager;
|
||||
import mage.server.tournament.TournamentFactory;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import mage.game.Table;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.Constants.TableState;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.GameOptions;
|
||||
import mage.game.Seat;
|
||||
import mage.game.Table;
|
||||
import mage.game.draft.Draft;
|
||||
import mage.game.draft.DraftPlayer;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.players.Player;
|
||||
import mage.server.game.DeckValidatorFactory;
|
||||
import mage.server.game.GameFactory;
|
||||
import mage.server.game.GameManager;
|
||||
import mage.server.game.PlayerFactory;
|
||||
import mage.server.game.ReplayManager;
|
||||
import mage.server.challenge.ChallengeManager;
|
||||
import mage.server.draft.DraftManager;
|
||||
import mage.server.game.*;
|
||||
import mage.server.tournament.TournamentFactory;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -231,6 +230,38 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void startChallenge(UUID sessionId, UUID challengeId) {
|
||||
if (sessionId.equals(this.sessionId)) {
|
||||
try {
|
||||
match.startMatch();
|
||||
match.startGame();
|
||||
table.initGame();
|
||||
GameOptions options = new GameOptions();
|
||||
options.testMode = true;
|
||||
match.getGame().setGameOptions(options);
|
||||
GameManager.getInstance().createGameSession(match.getGame(), sessionPlayerMap, table.getId(), null);
|
||||
ChallengeManager.getInstance().prepareChallenge(getPlayerId(), match);
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
sessionManager.getSession(entry.getKey()).gameStarted(match.getGame().getId(), entry.getValue());
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
logger.fatal(null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private UUID getPlayerId() throws GameException {
|
||||
UUID playerId = null;
|
||||
for (Entry<UUID, UUID> entry : sessionPlayerMap.entrySet()) {
|
||||
playerId = entry.getValue();
|
||||
break;
|
||||
}
|
||||
if (playerId == null)
|
||||
throw new GameException("Couldn't find a player in challenge mode.");
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public synchronized void startMatch() {
|
||||
if (table.getState() == TableState.STARTING) {
|
||||
try {
|
||||
|
|
|
@ -138,6 +138,10 @@ public class TableManager {
|
|||
controllers.get(tableId).startMatch();
|
||||
}
|
||||
|
||||
public void startChallenge(UUID sessionId, UUID roomId, UUID tableId, UUID challengeId) {
|
||||
controllers.get(tableId).startChallenge(sessionId, challengeId);
|
||||
}
|
||||
|
||||
public void startTournament(UUID sessionId, UUID roomId, UUID tableId) {
|
||||
controllers.get(tableId).startTournament(sessionId);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package mage.server.challenge;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.game.match.Match;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Loads challenges from scenarios.
|
||||
* Configure games by initializing starting game board.
|
||||
*/
|
||||
public class ChallengeManager {
|
||||
|
||||
public static final ChallengeManager fInstance = new ChallengeManager();
|
||||
|
||||
public static ChallengeManager getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
public void prepareChallenge(UUID playerId, Match match) {
|
||||
Map<Constants.Zone, String> commands = new HashMap<Constants.Zone, String>();
|
||||
commands.put(Constants.Zone.OUTSIDE, "life:3");
|
||||
match.getGame().cheat(playerId, commands);
|
||||
}
|
||||
}
|
|
@ -157,6 +157,9 @@ public interface Game extends MageItem, Serializable {
|
|||
public void restoreState();
|
||||
public void removeLastBookmark();
|
||||
|
||||
// game options
|
||||
public void setGameOptions(GameOptions options);
|
||||
|
||||
// game cheats (for tests only)
|
||||
public void cheat(UUID ownerId, Map<Zone, String> commands);
|
||||
public void cheat(UUID ownerId, List<Card> library, List<Card> hand, List<PermanentCard> battlefield, List<Card> graveyard);
|
||||
|
|
|
@ -95,6 +95,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
protected transient GameStates gameStates = new GameStates();
|
||||
protected RangeOfInfluence range;
|
||||
protected MultiplayerAttackOption attackOption;
|
||||
protected GameOptions gameOptions;
|
||||
|
||||
@Override
|
||||
public abstract T copy();
|
||||
|
@ -307,7 +308,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
|
||||
@Override
|
||||
public void start(UUID choosingPlayerId) {
|
||||
start(choosingPlayerId, GameOptions.getDefault());
|
||||
start(choosingPlayerId, this.gameOptions != null ? gameOptions : GameOptions.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1102,4 +1103,8 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
public void clearGraveyard(UUID playerId) {
|
||||
|
||||
}
|
||||
|
||||
public void setGameOptions(GameOptions options) {
|
||||
this.gameOptions = options;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue