Connecting LotroServer to ChatServer
This commit is contained in:
@@ -9,6 +9,7 @@ import com.gempukku.lotro.logic.decisions.AwaitingDecision;
|
|||||||
import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException;
|
import com.gempukku.lotro.logic.decisions.DecisionResultInvalidException;
|
||||||
import com.gempukku.lotro.logic.modifiers.Modifier;
|
import com.gempukku.lotro.logic.modifiers.Modifier;
|
||||||
import com.gempukku.lotro.logic.timing.DefaultLotroGame;
|
import com.gempukku.lotro.logic.timing.DefaultLotroGame;
|
||||||
|
import com.gempukku.lotro.logic.timing.GameResultListener;
|
||||||
import com.gempukku.lotro.logic.vo.LotroDeck;
|
import com.gempukku.lotro.logic.vo.LotroDeck;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -18,7 +19,7 @@ public class LotroGameMediator {
|
|||||||
private DefaultUserFeedback _userFeedback = new DefaultUserFeedback();
|
private DefaultUserFeedback _userFeedback = new DefaultUserFeedback();
|
||||||
private DefaultLotroGame _lotroGame;
|
private DefaultLotroGame _lotroGame;
|
||||||
|
|
||||||
public LotroGameMediator(LotroFormat lotroFormat, LotroGameParticipant[] participants, LotroCardBlueprintLibrary library) {
|
public LotroGameMediator(LotroFormat lotroFormat, LotroGameParticipant[] participants, LotroCardBlueprintLibrary library, GameResultListener gameResultListener) {
|
||||||
if (participants.length < 1)
|
if (participants.length < 1)
|
||||||
throw new IllegalArgumentException("Game can't have less than one participant");
|
throw new IllegalArgumentException("Game can't have less than one participant");
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ public class LotroGameMediator {
|
|||||||
participantSet.add(participantId);
|
participantSet.add(participantId);
|
||||||
decks.put(participantId, participant.getDeck());
|
decks.put(participantId, participant.getDeck());
|
||||||
}
|
}
|
||||||
_lotroGame = new DefaultLotroGame(decks, _userFeedback, null, library);
|
_lotroGame = new DefaultLotroGame(decks, _userFeedback, gameResultListener, library);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized String produceCardInfo(String participantId, int cardId) {
|
public synchronized String produceCardInfo(String participantId, int cardId) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.gempukku.lotro;
|
package com.gempukku.lotro;
|
||||||
|
|
||||||
|
import com.gempukku.lotro.chat.ChatServer;
|
||||||
import com.gempukku.lotro.common.CardType;
|
import com.gempukku.lotro.common.CardType;
|
||||||
import com.gempukku.lotro.common.Keyword;
|
import com.gempukku.lotro.common.Keyword;
|
||||||
import com.gempukku.lotro.db.DbAccess;
|
import com.gempukku.lotro.db.DbAccess;
|
||||||
@@ -8,13 +9,11 @@ import com.gempukku.lotro.db.PlayerDAO;
|
|||||||
import com.gempukku.lotro.db.vo.Deck;
|
import com.gempukku.lotro.db.vo.Deck;
|
||||||
import com.gempukku.lotro.db.vo.Player;
|
import com.gempukku.lotro.db.vo.Player;
|
||||||
import com.gempukku.lotro.game.*;
|
import com.gempukku.lotro.game.*;
|
||||||
|
import com.gempukku.lotro.logic.timing.GameResultListener;
|
||||||
import com.gempukku.lotro.logic.vo.LotroDeck;
|
import com.gempukku.lotro.logic.vo.LotroDeck;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class LotroServer {
|
public class LotroServer {
|
||||||
private static final Logger log = Logger.getLogger(LotroServer.class);
|
private static final Logger log = Logger.getLogger(LotroServer.class);
|
||||||
@@ -30,8 +29,10 @@ public class LotroServer {
|
|||||||
private PlayerDAO _playerDao;
|
private PlayerDAO _playerDao;
|
||||||
private DeckDAO _deckDao;
|
private DeckDAO _deckDao;
|
||||||
private DefaultCardCollection _defaultCollection;
|
private DefaultCardCollection _defaultCollection;
|
||||||
|
private ChatServer _chatServer;
|
||||||
|
|
||||||
public LotroServer() {
|
public LotroServer(ChatServer chatServer) {
|
||||||
|
_chatServer = chatServer;
|
||||||
_defaultCollection = new DefaultCardCollection();
|
_defaultCollection = new DefaultCardCollection();
|
||||||
for (int i = 1; i <= 1; i++) {
|
for (int i = 1; i <= 1; i++) {
|
||||||
for (int j = 1; j <= 365; j++) {
|
for (int j = 1; j <= 365; j++) {
|
||||||
@@ -88,8 +89,18 @@ public class LotroServer {
|
|||||||
public synchronized String createNewGame(LotroFormat lotroFormat, LotroGameParticipant[] participants) {
|
public synchronized String createNewGame(LotroFormat lotroFormat, LotroGameParticipant[] participants) {
|
||||||
if (participants.length < 2)
|
if (participants.length < 2)
|
||||||
throw new IllegalArgumentException("There has to be at least two players");
|
throw new IllegalArgumentException("There has to be at least two players");
|
||||||
LotroGameMediator lotroGameMediator = new LotroGameMediator(lotroFormat, participants, _lotroCardBlueprintLibrary);
|
|
||||||
String gameId = String.valueOf(_nextGameId);
|
String gameId = String.valueOf(_nextGameId);
|
||||||
|
final String chatRoomName = "Game" + gameId;
|
||||||
|
|
||||||
|
_chatServer.createChatRoom(chatRoomName);
|
||||||
|
LotroGameMediator lotroGameMediator = new LotroGameMediator(lotroFormat, participants, _lotroCardBlueprintLibrary,
|
||||||
|
new GameResultListener() {
|
||||||
|
@Override
|
||||||
|
public void gameFinished(String winnerPlayerId, Set<String> loserPlayerIds) {
|
||||||
|
_chatServer.destroyChatRoom(chatRoomName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
_runningGames.put(gameId, lotroGameMediator);
|
_runningGames.put(gameId, lotroGameMediator);
|
||||||
_nextGameId++;
|
_nextGameId++;
|
||||||
return gameId;
|
return gameId;
|
||||||
|
|||||||
Reference in New Issue
Block a user