mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 20:11:59 -08:00
Challenge Mode. In progress.
This commit is contained in:
parent
86f708b17a
commit
be2fdd6487
10 changed files with 195 additions and 15 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue