Simplifying leagues and formats.

This commit is contained in:
marcins78@gmail.com
2011-12-20 17:12:32 +00:00
parent 061786a38b
commit 03efc07623
18 changed files with 82 additions and 81 deletions

View File

@@ -9,5 +9,7 @@ public interface LotroFormat {
public boolean hasMulliganRule();
public String getName();
public void validateDeck(Player player, LotroDeck deck) throws DeckInvalidException;
}

View File

@@ -0,0 +1,19 @@
package com.gempukku.lotro.db.vo;
public class CollectionType {
private String _code;
private String _fullName;
public CollectionType(String code, String fullName) {
_code = code;
_fullName = fullName;
}
public String getCode() {
return _code;
}
public String getFullName() {
return _fullName;
}
}

View File

@@ -23,6 +23,10 @@ public class League {
return _id;
}
public CollectionType getCollectionType() {
return new CollectionType(_type, _name);
}
public String getType() {
return _type;
}

View File

@@ -107,14 +107,14 @@ public class LotroServer extends AbstractServer {
return "Game" + gameId;
}
public synchronized String createNewGame(LotroFormat lotroFormat, String formatName, LotroGameParticipant[] participants, boolean competetive) {
public synchronized String createNewGame(LotroFormat lotroFormat, LotroGameParticipant[] participants, boolean competetive) {
if (participants.length < 2)
throw new IllegalArgumentException("There has to be at least two players");
final String gameId = String.valueOf(_nextGameId);
String chatRoomName = getChatRoomName(gameId);
ChatRoomMediator room = _chatServer.createChatRoom(chatRoomName, 30);
room.sendMessage("System", "You're starting a game of " + formatName);
room.sendMessage("System", "You're starting a game of " + lotroFormat.getName());
LotroGameMediator lotroGameMediator = new LotroGameMediator(lotroFormat, participants, _lotroCardBlueprintLibrary, competetive ? 60 * 40 : 60 * 80);
lotroGameMediator.addGameResultListener(
@@ -132,7 +132,7 @@ public class LotroServer extends AbstractServer {
for (LotroGameParticipant participant : participants)
deckNames.put(participant.getPlayerId(), participant.getDeckName());
final GameRecorder.GameRecordingInProgress gameRecordingInProgress = _gameRecorder.recordGame(lotroGameMediator, formatName, deckNames);
final GameRecorder.GameRecordingInProgress gameRecordingInProgress = _gameRecorder.recordGame(lotroGameMediator, lotroFormat.getName(), deckNames);
lotroGameMediator.addGameResultListener(
new GameResultListener() {
@Override

View File

@@ -14,6 +14,7 @@ import java.util.Set;
public abstract class DefaultLotroFormat implements LotroFormat {
private LotroCardBlueprintLibrary _library;
private String _name;
private Block _siteBlock;
private boolean _validateShadowFPCount = true;
private int _maximumSameName = 4;
@@ -24,8 +25,9 @@ public abstract class DefaultLotroFormat implements LotroFormat {
private Set<String> _restrictedCards = new HashSet<String>();
private Set<Integer> _validSets = new HashSet<Integer>();
public DefaultLotroFormat(LotroCardBlueprintLibrary library, Block siteBlock, boolean validateShadowFPCount, int minimumDeckSize, int maximumSameName, boolean mulliganRule, boolean canCancelRingBearerSkirmish) {
public DefaultLotroFormat(LotroCardBlueprintLibrary library, String name, Block siteBlock, boolean validateShadowFPCount, int minimumDeckSize, int maximumSameName, boolean mulliganRule, boolean canCancelRingBearerSkirmish) {
_library = library;
_name = name;
_siteBlock = siteBlock;
_validateShadowFPCount = validateShadowFPCount;
_minimumDeckSize = minimumDeckSize;
@@ -34,6 +36,11 @@ public abstract class DefaultLotroFormat implements LotroFormat {
_canCancelRingBearerSkirmish = canCancelRingBearerSkirmish;
}
@Override
public String getName() {
return _name;
}
@Override
public boolean hasMulliganRule() {
return _mulliganRule;

View File

@@ -5,7 +5,7 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class ExpandedFormat extends DefaultLotroFormat {
public ExpandedFormat(LotroCardBlueprintLibrary library) {
super(library, Block.OTHER, true, 60, 4, true, false);
super(library, "Expanded", Block.OTHER, true, 60, 4, true, false);
addValidSet(0);
addValidSet(1);
addValidSet(2);

View File

@@ -5,7 +5,7 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class FotRBlockFormat extends DefaultLotroFormat {
public FotRBlockFormat(LotroCardBlueprintLibrary library, boolean mulliganRule) {
super(library, Block.FELLOWSHIP, true, 60, 4, mulliganRule, true);
super(library, (mulliganRule ? "Community " : "") + "Fellowship block", Block.FELLOWSHIP, true, 60, 4, mulliganRule, true);
addRestrictedCard("1_248");
addValidSet(1);
addValidSet(2);

View File

@@ -1,15 +0,0 @@
package com.gempukku.lotro.game.formats;
import com.gempukku.lotro.common.Block;
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class FreeFormat extends DefaultLotroFormat {
public FreeFormat(LotroCardBlueprintLibrary library) {
super(library, Block.FELLOWSHIP, false, 0, Integer.MAX_VALUE, false, true);
}
@Override
public boolean isOrderedSites() {
return true;
}
}

View File

@@ -5,7 +5,7 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class KingBlockFormat extends DefaultLotroFormat {
public KingBlockFormat(LotroCardBlueprintLibrary library, boolean mulliganRule) {
super(library, Block.KING, true, 60, 4, mulliganRule, true);
super(library, (mulliganRule ? "Community " : "") + "King block", Block.KING, true, 60, 4, mulliganRule, true);
addRestrictedCard("7_49");
addValidSet(7);
addValidSet(8);

View File

@@ -5,7 +5,7 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class MovieFormat extends DefaultLotroFormat {
public MovieFormat(LotroCardBlueprintLibrary library) {
super(library, Block.KING, true, 60, 4, true, false);
super(library, "Movie block", Block.KING, true, 60, 4, true, false);
addBannedCard("8_1");
addBannedCard("3_38");
addBannedCard("3_106");

View File

@@ -5,7 +5,7 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class OpenFormat extends DefaultLotroFormat {
public OpenFormat(LotroCardBlueprintLibrary library) {
super(library, Block.OTHER, true, 60, 4, true, false);
super(library, "Open", Block.OTHER, true, 60, 4, true, false);
addValidSet(0);
addValidSet(1);
addValidSet(2);

View File

@@ -5,7 +5,7 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class TTTBlockFormat extends DefaultLotroFormat {
public TTTBlockFormat(LotroCardBlueprintLibrary library, boolean mulliganRule) {
super(library, Block.TWO_TOWERS, true, 60, 4, mulliganRule, true);
super(library, (mulliganRule ? "Community " : "") + "Two Towers block", Block.TWO_TOWERS, true, 60, 4, mulliganRule, true);
addValidSet(4);
addValidSet(5);
addValidSet(6);

View File

@@ -5,7 +5,7 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class TowersStandardFormat extends DefaultLotroFormat {
public TowersStandardFormat(LotroCardBlueprintLibrary library) {
super(library, Block.TWO_TOWERS, true, 60, 4, true, true);
super(library, "Towers Standard", Block.TWO_TOWERS, true, 60, 4, true, true);
addBannedCard("1_40");
addBannedCard("1_45");

View File

@@ -5,7 +5,7 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class WarOfTheRingBlockFormat extends DefaultLotroFormat {
public WarOfTheRingBlockFormat(LotroCardBlueprintLibrary library, boolean mulliganRule) {
super(library, Block.OTHER, true, 60, 4, mulliganRule, false);
super(library, (mulliganRule ? "Community " : "") + "War of the Ring block", Block.OTHER, true, 60, 4, mulliganRule, false);
addRestrictedCard("11_132");
addRestrictedCard("11_100");
addValidSet(11);

View File

@@ -1,5 +1,6 @@
package com.gempukku.lotro.hall;
import com.gempukku.lotro.db.vo.CollectionType;
import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.db.vo.LeagueSerie;
import com.gempukku.lotro.game.LotroFormat;
@@ -8,8 +9,7 @@ import com.gempukku.lotro.game.LotroGameParticipant;
import java.util.*;
public class AwaitingTable {
private String _formatName;
private String _collectionType;
private CollectionType _collectionType;
private LotroFormat _lotroFormat;
private League _league;
private LeagueSerie _leagueSerie;
@@ -17,10 +17,9 @@ public class AwaitingTable {
private int _capacity = 2;
public AwaitingTable(String formatName, String collectionType, LotroFormat lotroFormat, League league, LeagueSerie leagueSerie) {
_formatName = formatName;
_collectionType = collectionType;
public AwaitingTable(LotroFormat lotroFormat, CollectionType collectionType, League league, LeagueSerie leagueSerie) {
_lotroFormat = lotroFormat;
_collectionType = collectionType;
_league = league;
_leagueSerie = leagueSerie;
}
@@ -47,11 +46,7 @@ public class AwaitingTable {
return Collections.unmodifiableSet(new HashSet<LotroGameParticipant>(_players.values()));
}
public String getFormatName() {
return _formatName;
}
public String getCollectionType() {
public CollectionType getCollectionType() {
return _collectionType;
}

View File

@@ -3,6 +3,7 @@ package com.gempukku.lotro.hall;
import com.gempukku.lotro.AbstractServer;
import com.gempukku.lotro.chat.ChatServer;
import com.gempukku.lotro.db.CollectionDAO;
import com.gempukku.lotro.db.vo.CollectionType;
import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.db.vo.LeagueSerie;
import com.gempukku.lotro.game.*;
@@ -20,9 +21,7 @@ public class HallServer extends AbstractServer {
private CollectionDAO _collectionDao;
private LotroServer _lotroServer;
private Map<String, String> _supportedFormatNames = new LinkedHashMap<String, String>();
private Map<String, LotroFormat> _supportedFormats = new HashMap<String, LotroFormat>();
private Map<String, String> _formatCollectionIds = new HashMap<String, String>();
private Map<String, LotroFormat> _supportedFormats = new LinkedHashMap<String, LotroFormat>();
// TODO Reading/writing from/to these maps is done in multiple threads
private Map<String, AwaitingTable> _awaitingTables = new ConcurrentHashMap<String, AwaitingTable>();
@@ -36,6 +35,8 @@ public class HallServer extends AbstractServer {
private String _motd;
private CollectionType _allCardsCollectionType = new CollectionType("default", "All cards");
public HallServer(LotroServer lotroServer, ChatServer chatServer, LeagueService leagueService, LotroCardBlueprintLibrary library, CollectionDAO collectionDao, boolean test) {
_lotroServer = lotroServer;
_chatServer = chatServer;
@@ -44,18 +45,18 @@ public class HallServer extends AbstractServer {
_collectionDao = collectionDao;
_chatServer.createChatRoom("Game Hall", 10);
addFormat("fotr_block", "Fellowship block", "default", new FotRBlockFormat(library, false));
addFormat("c_fotr_block", "Community Fellowship block", "default", new FotRBlockFormat(library, true));
addFormat("ttt_block", "Two Towers block", "default", new TTTBlockFormat(library, false));
addFormat("c_ttt_block", "Community Two Towers block", "default", new TTTBlockFormat(library, true));
addFormat("towers_standard", "Towers Standard", "default", new TowersStandardFormat(library));
addFormat("king_block", "King block", "default", new KingBlockFormat(library, false));
addFormat("c_king_block", "Community King block", "default", new KingBlockFormat(library, true));
addFormat("movie", "Movie block", "default", new MovieFormat(library));
addFormat("war_block", "War of the Ring block", "default", new WarOfTheRingBlockFormat(library, false));
addFormat("c_war_block", "Community War of the Ring block", "default", new WarOfTheRingBlockFormat(library, true));
addFormat("open", "Open", "default", new OpenFormat(library));
addFormat("expanded", "Expanded", "default", new ExpandedFormat(library));
addFormat("fotr_block", new FotRBlockFormat(library, false));
addFormat("c_fotr_block", new FotRBlockFormat(library, true));
addFormat("ttt_block", new TTTBlockFormat(library, false));
addFormat("c_ttt_block", new TTTBlockFormat(library, true));
addFormat("towers_standard", new TowersStandardFormat(library));
addFormat("king_block", new KingBlockFormat(library, false));
addFormat("c_king_block", new KingBlockFormat(library, true));
addFormat("movie", new MovieFormat(library));
addFormat("war_block", new WarOfTheRingBlockFormat(library, false));
addFormat("c_war_block", new WarOfTheRingBlockFormat(library, true));
addFormat("open", new OpenFormat(library));
addFormat("expanded", new ExpandedFormat(library));
// addFormat("whatever", "Format for testing", "default", new FreeFormat(library));
}
@@ -68,9 +69,7 @@ public class HallServer extends AbstractServer {
_motd = motd;
}
private void addFormat(String formatCode, String formatName, String formatCollectionId, LotroFormat format) {
_supportedFormatNames.put(formatCode, formatName);
_formatCollectionIds.put(formatCode, formatCollectionId);
private void addFormat(String formatCode, LotroFormat format) {
_supportedFormats.put(formatCode, format);
}
@@ -78,12 +77,8 @@ public class HallServer extends AbstractServer {
return _awaitingTables.size() + _runningTables.size();
}
public Map<String, String> getSupportedFormatNames() {
return Collections.unmodifiableMap(_supportedFormatNames);
}
public LotroFormat getSupportedFormat(String formatId) {
return _supportedFormats.get(formatId);
public Map<String, LotroFormat> getSupportedFormats() {
return Collections.unmodifiableMap(_supportedFormats);
}
public Set<League> getRunningLeagues() {
@@ -96,11 +91,8 @@ public class HallServer extends AbstractServer {
public synchronized void createNewTable(String type, Player player, String deckName) throws HallException {
League league = null;
LeagueSerie leagueSerie = null;
String collectionType = _formatCollectionIds.get(type);
CollectionType collectionType = _allCardsCollectionType;
LotroFormat format = _supportedFormats.get(type);
String formatName = null;
if (format != null)
formatName = _supportedFormatNames.get(type);
if (format == null) {
// Maybe it's a league format?
@@ -110,8 +102,7 @@ public class HallServer extends AbstractServer {
if (leagueSerie == null)
throw new HallException("There is no ongoing serie for that league");
format = _supportedFormats.get(leagueSerie.getFormat());
formatName = _supportedFormatNames.get(leagueSerie.getFormat());
collectionType = league.getType();
collectionType = league.getCollectionType();
}
}
// It's not a normal format and also not a league one
@@ -121,13 +112,13 @@ public class HallServer extends AbstractServer {
LotroDeck lotroDeck = validateUserAndDeck(format, player, deckName, collectionType);
String tableId = String.valueOf(_nextTableId++);
AwaitingTable table = new AwaitingTable(formatName, collectionType, format, league, leagueSerie);
AwaitingTable table = new AwaitingTable(format, collectionType, league, leagueSerie);
_awaitingTables.put(tableId, table);
joinTableInternal(tableId, player.getName(), table, deckName, lotroDeck);
}
private LotroDeck validateUserAndDeck(LotroFormat format, Player player, String deckName, String collectionType) throws HallException {
private LotroDeck validateUserAndDeck(LotroFormat format, Player player, String deckName, CollectionType collectionType) throws HallException {
if (isPlayerBusy(player.getName()))
throw new HallException("You can't play more than one game at a time or wait at more than one table");
@@ -142,7 +133,7 @@ public class HallServer extends AbstractServer {
}
// Now check if player owns all the cards
CardCollection collection = _collectionDao.getCollectionForPlayer(player, collectionType);
CardCollection collection = _collectionDao.getCollectionForPlayer(player, collectionType.getCode());
Map<String, Integer> deckCardCounts = CollectionUtils.getTotalCardCountForDeck(lotroDeck);
final Map<String, Integer> collectionCardCounts = collection.getAll();
@@ -184,13 +175,13 @@ public class HallServer extends AbstractServer {
Set<LotroGameParticipant> players = awaitingTable.getPlayers();
LotroGameParticipant[] participants = players.toArray(new LotroGameParticipant[players.size()]);
League league = awaitingTable.getLeague();
String gameId = _lotroServer.createNewGame(awaitingTable.getLotroFormat(), awaitingTable.getFormatName(), participants, league != null);
String gameId = _lotroServer.createNewGame(awaitingTable.getLotroFormat(), participants, league != null);
LotroGameMediator lotroGameMediator = _lotroServer.getGameById(gameId);
if (league != null)
_leagueService.leagueGameStarting(league, awaitingTable.getLeagueSerie(), lotroGameMediator);
lotroGameMediator.startGame();
_runningTables.put(tableId, gameId);
_runningTableFormatNames.put(tableId, awaitingTable.getFormatName());
_runningTableFormatNames.put(tableId, awaitingTable.getLotroFormat().getName());
_awaitingTables.remove(tableId);
}
@@ -218,7 +209,7 @@ public class HallServer extends AbstractServer {
Map<String, AwaitingTable> copy = new HashMap<String, AwaitingTable>(_awaitingTables);
for (Map.Entry<String, AwaitingTable> table : copy.entrySet())
visitor.visitTable(table.getKey(), null, "Waiting", table.getValue().getFormatName(), table.getValue().getPlayerNames(), null);
visitor.visitTable(table.getKey(), null, "Waiting", table.getValue().getLotroFormat().getName(), table.getValue().getPlayerNames(), null);
Map<String, String> runningCopy = new LinkedHashMap<String, String>(_runningTables);
for (Map.Entry<String, String> runningGame : runningCopy.entrySet()) {

View File

@@ -20,7 +20,6 @@ import javax.xml.parsers.ParserConfigurationException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@Singleton
@Path("/deck")
@@ -157,14 +156,12 @@ public class DeckResource extends AbstractResource {
StringBuilder sb = new StringBuilder();
sb.append("<b>Free People</b>: " + fpCount + ", <b>Shadow</b>: " + shadowCount + "<br/>");
for (Map.Entry<String, String> supportedFormats : _hallServer.getSupportedFormatNames().entrySet()) {
String formatName = supportedFormats.getValue();
LotroFormat format = _hallServer.getSupportedFormat(supportedFormats.getKey());
for (LotroFormat format : _hallServer.getSupportedFormats().values()) {
try {
format.validateDeck(resourceOwner, deck);
sb.append("<b>" + formatName + "</b>: <font color='green'>valid</font><br/>");
sb.append("<b>" + format.getName() + "</b>: <font color='green'>valid</font><br/>");
} catch (DeckInvalidException exp) {
sb.append("<b>" + formatName + "</b>: <font color='red'>" + exp.getMessage() + "</font><br/>");
sb.append("<b>" + format.getName() + "</b>: <font color='red'>" + exp.getMessage() + "</font><br/>");
}
}

View File

@@ -1,6 +1,7 @@
package com.gempukku.lotro.server;
import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.game.LotroFormat;
import com.gempukku.lotro.game.Player;
import com.gempukku.lotro.hall.HallException;
import com.gempukku.lotro.hall.HallInfoVisitor;
@@ -45,10 +46,10 @@ public class HallResource extends AbstractResource {
hall.setAttribute("motd", motd);
_hallServer.processTables(resourceOwner, new SerializeHallInfoVisitor(doc, hall));
for (Map.Entry<String, String> format : _hallServer.getSupportedFormatNames().entrySet()) {
for (Map.Entry<String, LotroFormat> format : _hallServer.getSupportedFormats().entrySet()) {
Element formatElem = doc.createElement("format");
formatElem.setAttribute("type", format.getKey());
formatElem.appendChild(doc.createTextNode(format.getValue()));
formatElem.appendChild(doc.createTextNode(format.getValue().getName()));
hall.appendChild(formatElem);
}
for (League league : _hallServer.getRunningLeagues()) {