Adding Towers Standard format and more descriptive deck validation rules.

This commit is contained in:
marcins78@gmail.com
2011-10-18 14:16:48 +00:00
parent da163305c4
commit 45c3c6bd09
5 changed files with 85 additions and 22 deletions

View File

@@ -37,6 +37,14 @@ public class LotroCardBlueprintLibrary {
}
}
public String getBaseBlueprintId(String blueprintId) {
blueprintId = stripBlueprintModifiers(blueprintId);
String base = _blueprintMapping.get(blueprintId);
if (base != null)
return base;
return blueprintId;
}
private void addAlternatives(String blueprint1, String blueprint2) {
addAlternative(blueprint1, blueprint2);
addAlternative(blueprint2, blueprint1);
@@ -62,10 +70,7 @@ public class LotroCardBlueprintLibrary {
}
public LotroCardBlueprint getLotroCardBlueprint(String blueprintId) {
if (blueprintId.endsWith("*"))
blueprintId = blueprintId.substring(0, blueprintId.length() - 1);
if (blueprintId.endsWith("T"))
blueprintId = blueprintId.substring(0, blueprintId.length() - 1);
blueprintId = stripBlueprintModifiers(blueprintId);
if (_blueprintMap.containsKey(blueprintId))
return _blueprintMap.get(blueprintId);
@@ -75,6 +80,14 @@ public class LotroCardBlueprintLibrary {
return blueprint;
}
private String stripBlueprintModifiers(String blueprintId) {
if (blueprintId.endsWith("*"))
blueprintId = blueprintId.substring(0, blueprintId.length() - 1);
if (blueprintId.endsWith("T"))
blueprintId = blueprintId.substring(0, blueprintId.length() - 1);
return blueprintId;
}
// public void initializeLibrary(String setNo, int maxCardIndex) {
// for (int i = 1; i <= maxCardIndex; i++) {
// try {

View File

@@ -20,7 +20,8 @@ public abstract class DefaultLotroFormat implements LotroFormat {
private boolean _validateShadowFPCount = true;
private int _maximumSameName = 4;
private int _minimumDeckSize = 60;
private Set<String> _restrictedCard = new HashSet<String>();
private Set<String> _bannedCards = new HashSet<String>();
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) {
@@ -31,8 +32,12 @@ public abstract class DefaultLotroFormat implements LotroFormat {
_maximumSameName = maximumSameName;
}
protected void addRestrictedCard(String name) {
_restrictedCard.add(name);
protected void addBannedCard(String baseBlueprintId) {
_bannedCards.add(baseBlueprintId);
}
protected void addRestrictedCard(String baseBlueprintId) {
_restrictedCards.add(baseBlueprintId);
}
protected void addValidSet(int setNo) {
@@ -45,7 +50,7 @@ public abstract class DefaultLotroFormat implements LotroFormat {
|| _library.hasAlternateInSet(blueprintId, validSet))
return;
throw new DeckInvalidException("Deck contains card not valid for this format: " + _library.getLotroCardBlueprint(blueprintId).getName());
throw new DeckInvalidException("Deck contains card not from valid set: " + _library.getLotroCardBlueprint(blueprintId).getName());
}
@Override
@@ -56,14 +61,14 @@ public abstract class DefaultLotroFormat implements LotroFormat {
throw new DeckInvalidException("Deck doesn't have a Ring-bearer");
LotroCardBlueprint ringBearer = _library.getLotroCardBlueprint(deck.getRingBearer());
if (!ringBearer.hasKeyword(Keyword.RING_BEARER))
throw new DeckInvalidException("Assigned Ring-bearer can not bear the ring");
throw new DeckInvalidException("Card assigned as Ring-bearer can not bear the ring");
// Ring
if (deck.getRing() == null)
throw new DeckInvalidException("Deck doesn't have a Ring");
LotroCardBlueprint ring = _library.getLotroCardBlueprint(deck.getRing());
if (ring.getCardType() != CardType.THE_ONE_RING)
throw new DeckInvalidException("Assigned Ring is not The One Ring");
throw new DeckInvalidException("Card assigned as Ring is not The One Ring");
// Sites
if (deck.getSites() == null)
@@ -73,9 +78,9 @@ public abstract class DefaultLotroFormat implements LotroFormat {
for (String site : deck.getSites()) {
LotroCardBlueprint siteBlueprint = _library.getLotroCardBlueprint(site);
if (siteBlueprint.getCardType() != CardType.SITE)
throw new DeckInvalidException("Assigned Site is not really a site");
throw new DeckInvalidException("Card assigned as Site is not really a site");
if (siteBlueprint.getSiteBlock() != _siteBlock)
throw new DeckInvalidException("One of the sites is from a different block than the format allows");
throw new DeckInvalidException("Site is not from the block used: " + siteBlueprint.getName());
}
if (_validSets.size() > 0) {
@@ -92,14 +97,14 @@ public abstract class DefaultLotroFormat implements LotroFormat {
for (String site : deck.getSites()) {
LotroCardBlueprint blueprint = _library.getLotroCardBlueprint(site);
if (sites[blueprint.getSiteNumber() - 1])
throw new DeckInvalidException("Deck has multiple of the same site number");
throw new DeckInvalidException("Deck has multiple of the same site number: " + blueprint.getSiteNumber());
sites[blueprint.getSiteNumber() - 1] = true;
}
}
// Deck
if (deck.getAdventureCards().size() < _minimumDeckSize)
throw new DeckInvalidException("Deck contains below minimum number of cards");
throw new DeckInvalidException("Deck contains below minimum number of cards: " + deck.getAdventureCards().size() + "<" + _minimumDeckSize);
if (_validateShadowFPCount) {
int shadow = 0;
int fp = 0;
@@ -118,10 +123,12 @@ public abstract class DefaultLotroFormat implements LotroFormat {
// Card count in deck and Ring-bearer
Map<String, Integer> cardCountByName = new HashMap<String, Integer>();
Map<String, Integer> cardCountByBaseBlueprintId = new HashMap<String, Integer>();
cardCountByName.put(ringBearer.getName(), 1);
for (String blueprintId : deck.getAdventureCards()) {
LotroCardBlueprint cardBlueprint = _library.getLotroCardBlueprint(blueprintId);
increateCount(cardCountByName, cardBlueprint.getName());
increateCount(cardCountByBaseBlueprintId, _library.getBaseBlueprintId(blueprintId));
}
for (Map.Entry<String, Integer> count : cardCountByName.entrySet()) {
if (count.getValue() > _maximumSameName)
@@ -129,10 +136,17 @@ public abstract class DefaultLotroFormat implements LotroFormat {
}
// Restricted cards
for (String name : _restrictedCard) {
Integer count = cardCountByName.get(name);
for (String blueprintId : _restrictedCards) {
Integer count = cardCountByBaseBlueprintId.get(blueprintId);
if (count != null && count > 1)
throw new DeckInvalidException("Deck contains more than one copy of a restricted card: " + name);
throw new DeckInvalidException("Deck contains more than one copy of an R-listed card: " + blueprintId);
}
// Banned cards
for (String blueprintId : _bannedCards) {
Integer count = cardCountByBaseBlueprintId.get(blueprintId);
if (count != null && count > 0)
throw new DeckInvalidException("Deck contains a copy of an X-listed card: " + blueprintId);
}
} catch (IllegalArgumentException exp) {

View File

@@ -6,7 +6,7 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class FotRBlockFormat extends DefaultLotroFormat {
public FotRBlockFormat(LotroCardBlueprintLibrary library) {
super(library, Block.FELLOWSHIP, true, 60, 4);
addRestrictedCard("Forces of Mordor");
addRestrictedCard("1_248");
addValidSet(1);
addValidSet(2);
addValidSet(3);

View File

@@ -0,0 +1,38 @@
package com.gempukku.lotro.game.formats;
import com.gempukku.lotro.common.Block;
import com.gempukku.lotro.game.LotroCardBlueprintLibrary;
public class TowersStandardFormat extends DefaultLotroFormat {
public TowersStandardFormat(LotroCardBlueprintLibrary library) {
super(library, Block.TWO_TOWERS, true, 60, 4);
addBannedCard("1_40");
addBannedCard("1_45");
addBannedCard("1_80");
addBannedCard("1_108");
addBannedCard("1_139");
addBannedCard("1_234");
addBannedCard("1_248");
addBannedCard("1_313");
addBannedCard("2_32");
addBannedCard("2_101");
addBannedCard("2_108");
addBannedCard("3_38");
addBannedCard("3_42");
addBannedCard("3_68");
addBannedCard("4_192");
addValidSet(1);
addValidSet(2);
addValidSet(3);
addValidSet(4);
addValidSet(5);
addValidSet(6);
}
@Override
public boolean isOrderedSites() {
return true;
}
}

View File

@@ -6,10 +6,7 @@ import com.gempukku.lotro.db.CollectionDAO;
import com.gempukku.lotro.db.vo.League;
import com.gempukku.lotro.db.vo.Player;
import com.gempukku.lotro.game.*;
import com.gempukku.lotro.game.formats.FotRBlockFormat;
import com.gempukku.lotro.game.formats.FreeFormat;
import com.gempukku.lotro.game.formats.LotroFormat;
import com.gempukku.lotro.game.formats.TTTBlockFormat;
import com.gempukku.lotro.game.formats.*;
import com.gempukku.lotro.league.LeagueService;
import com.gempukku.lotro.logic.vo.LotroDeck;
@@ -45,6 +42,7 @@ public class HallServer extends AbstractServer {
addFormat("fotr_block", "Fellowship block", "default", new FotRBlockFormat(_lotroServer.getLotroCardBlueprintLibrary()));
addFormat("ttt_block", "Two Towers block", "default", new TTTBlockFormat(_lotroServer.getLotroCardBlueprintLibrary()));
addFormat("towers_standard", "Towers Standard", "default", new TowersStandardFormat(_lotroServer.getLotroCardBlueprintLibrary()));
addFormat("whatever", "Format for testing", "default", new FreeFormat(_lotroServer.getLotroCardBlueprintLibrary()));
}