From e9f9dddb5909a5085bdcda91cb8c86fadbb5ce48 Mon Sep 17 00:00:00 2001 From: "marcin.sciesinski" Date: Sun, 15 Apr 2018 14:37:42 -0700 Subject: [PATCH] First test draft fully working --- .../async/LotroServerPipelineFactory.java | 2 - .../main/web/js/gemp-019/leagueResultsUi.js | 14 +- .../src/main/web/js/gemp-019/soloDraftUi.js | 2 +- .../src/main/web/leagueAdmin.html | 2 +- .../gempukku/lotro/builder/ServerBuilder.java | 7 + .../lotro/draft2/SoloDraftDefinitions.java | 9 +- .../draft2/builder/DraftChoiceBuilder.java | 128 +++++++++- .../draft2/builder/StartingPoolBuilder.java | 3 +- .../lotro/game/SortAndFilterCards.java | 19 +- .../lotro/league/SoloDraftLeagueData.java | 3 +- .../src/main/resources/draft/testDraft.json | 230 ++++++++++++++++++ .../src/main/resources/lotrDrafts.json | 4 +- .../draft2/SoloDraftDefinitionsTest.java | 4 +- .../league/ConstructedLeagueDataTest.java | 4 +- .../lotro/league/LeagueServiceTest.java | 14 +- .../lotro/league/SealedLeagueDataTest.java | 14 +- 16 files changed, 420 insertions(+), 39 deletions(-) create mode 100644 gemp-lotr/gemp-lotr-server/src/main/resources/draft/testDraft.json diff --git a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/LotroServerPipelineFactory.java b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/LotroServerPipelineFactory.java index 31c99f673..e1691fb32 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/LotroServerPipelineFactory.java +++ b/gemp-lotr/gemp-lotr-async/src/main/java/com/gempukku/lotro/async/LotroServerPipelineFactory.java @@ -29,7 +29,6 @@ public class LotroServerPipelineFactory implements ChannelPipelineFactory { public LotroServerPipelineFactory() { Map objects = new HashMap(); final CardSets cardSets = new CardSets(); - SoloDraftDefinitions soloDraftDefinitions = new SoloDraftDefinitions(); LoggedUserHolder loggedUserHolder = new LoggedUserHolder(); loggedUserHolder.start(); @@ -40,7 +39,6 @@ public class LotroServerPipelineFactory implements ChannelPipelineFactory { objects.put(LongPollingSystem.class, longPollingSystem); objects.put(CardSets.class, cardSets); - objects.put(SoloDraftDefinitions.class, soloDraftDefinitions); objects.put(PacksStorage.class, PacksStorageBuilder.createPacksStorage(cardSets)); DaoBuilder.fillObjectMap(objects); ServerBuilder.fillObjectMap(objects); diff --git a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-019/leagueResultsUi.js b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-019/leagueResultsUi.js index 0e5bcd141..e4d0ca15f 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-019/leagueResultsUi.js +++ b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-019/leagueResultsUi.js @@ -37,6 +37,18 @@ var LeagueResultsUI = Class.extend({ }); }, + loadResultsWithLeague:function (type) { + var that = this; + this.communication.getLeagues( + function (xml) { + that.loadedLeagueResults(xml); + that.communication.getLeague(type, + function (xml) { + that.loadedLeague(xml); + }); + }); + }, + loadedLeague:function (xml) { var that = this; log(xml); @@ -81,7 +93,7 @@ var LeagueResultsUI = Class.extend({ that.displayBuyAction("Do you want to join the league by paying " + costString + "?", function () { that.communication.joinLeague(leagueCode, function () { - that.loadResults(); + that.loadResultsWithLeague(leagueCode); }, { "409":function () { alert("You don't have enough funds to join this league."); diff --git a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-019/soloDraftUi.js b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-019/soloDraftUi.js index ee7c37f8f..1f544945b 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-019/soloDraftUi.js +++ b/gemp-lotr/gemp-lotr-async/src/main/web/js/gemp-019/soloDraftUi.js @@ -114,7 +114,7 @@ var GempLotrSoloDraftUI = Class.extend({ } }); - this.comm.getCollection(this.leagueType, null, 0, 1000, + this.comm.getCollection(this.leagueType, "sort:cardType,culture,name", 0, 1000, function (xml) { var root = xml.documentElement; if (root.tagName == "collection") { diff --git a/gemp-lotr/gemp-lotr-async/src/main/web/leagueAdmin.html b/gemp-lotr/gemp-lotr-async/src/main/web/leagueAdmin.html index dd33b83e3..6e9a6768c 100644 --- a/gemp-lotr/gemp-lotr-async/src/main/web/leagueAdmin.html +++ b/gemp-lotr/gemp-lotr-async/src/main/web/leagueAdmin.html @@ -203,7 +203,7 @@ Start (YYYYMMDD):
Format:
Series duration in days:
Maximum matches in series:
diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/builder/ServerBuilder.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/builder/ServerBuilder.java index 48db69a21..a9b4baeac 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/builder/ServerBuilder.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/builder/ServerBuilder.java @@ -64,6 +64,13 @@ public class ServerBuilder { extract(objectMap, LotroCardBlueprintLibrary.class), extract(objectMap, CardSets.class))); + objectMap.put(SoloDraftDefinitions.class, + new SoloDraftDefinitions( + extract(objectMap, CollectionsManager.class), + extract(objectMap, LotroCardBlueprintLibrary.class), + extract(objectMap, LotroFormatLibrary.class), + extract(objectMap, CardSets.class).getSetDefinitions())); + objectMap.put(LeagueService.class, new LeagueService( extract(objectMap, LeagueDAO.class), diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/SoloDraftDefinitions.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/SoloDraftDefinitions.java index 748320a0b..35250dfd9 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/SoloDraftDefinitions.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/SoloDraftDefinitions.java @@ -1,8 +1,11 @@ package com.gempukku.lotro.draft2; +import com.gempukku.lotro.cards.packs.SetDefinition; +import com.gempukku.lotro.collection.CollectionsManager; import com.gempukku.lotro.draft2.builder.CardCollectionProducer; import com.gempukku.lotro.draft2.builder.DraftChoiceBuilder; import com.gempukku.lotro.draft2.builder.StartingPoolBuilder; +import com.gempukku.lotro.game.LotroCardBlueprintLibrary; import com.gempukku.lotro.game.formats.LotroFormatLibrary; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -16,9 +19,11 @@ import java.util.*; public class SoloDraftDefinitions { private Map draftTypes = new HashMap(); private StartingPoolBuilder startingPoolBuilder = new StartingPoolBuilder(); - private DraftChoiceBuilder draftChoiceBuilder = new DraftChoiceBuilder(); + private DraftChoiceBuilder draftChoiceBuilder; - public SoloDraftDefinitions() { + public SoloDraftDefinitions(CollectionsManager collectionsManager, LotroCardBlueprintLibrary cardLibrary, + LotroFormatLibrary formatLibrary, Map rarities) { + draftChoiceBuilder = new DraftChoiceBuilder(collectionsManager, cardLibrary, formatLibrary, rarities); try { final InputStreamReader reader = new InputStreamReader(LotroFormatLibrary.class.getResourceAsStream("/lotrDrafts.json"), "UTF-8"); try { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/builder/DraftChoiceBuilder.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/builder/DraftChoiceBuilder.java index a192f3f10..c42445b95 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/builder/DraftChoiceBuilder.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/builder/DraftChoiceBuilder.java @@ -1,15 +1,36 @@ package com.gempukku.lotro.draft2.builder; +import com.gempukku.lotro.cards.packs.SetDefinition; +import com.gempukku.lotro.collection.CollectionsManager; import com.gempukku.lotro.draft2.DraftChoiceDefinition; import com.gempukku.lotro.draft2.SoloDraft; import com.gempukku.lotro.game.CardCollection; import com.gempukku.lotro.game.DefaultCardCollection; +import com.gempukku.lotro.game.LotroCardBlueprintLibrary; +import com.gempukku.lotro.game.SortAndFilterCards; +import com.gempukku.lotro.game.formats.LotroFormatLibrary; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import java.util.*; public class DraftChoiceBuilder { + public static final int HIGH_ENOUGH_PRIME_NUMBER = 9497; + private CollectionsManager _collectionsManager; + private LotroCardBlueprintLibrary _cardLibrary; + private LotroFormatLibrary _formatLibrary; + private Map _rarities; + private SortAndFilterCards _sortAndFilterCards; + + public DraftChoiceBuilder(CollectionsManager collectionsManager, LotroCardBlueprintLibrary cardLibrary, + LotroFormatLibrary formatLibrary, Map rarities) { + _collectionsManager = collectionsManager; + _cardLibrary = cardLibrary; + _formatLibrary = formatLibrary; + _rarities = rarities; + _sortAndFilterCards = new SortAndFilterCards(); + } + public DraftChoiceDefinition buildDraftChoiceDefinition(JSONObject choiceDefinition) { return constructDraftChoiceDefinition(choiceDefinition); } @@ -19,14 +40,71 @@ public class DraftChoiceBuilder { JSONObject data = (JSONObject) choiceDefinition.get("data"); if (choiceDefinitionType.equals("singleCollectionPick")) return buildSingleCollectionPickDraftChoiceDefinition(data); + else if (choiceDefinitionType.equals("weightedSwitch")) + return buildWeightedSwitchDraftChoiceDefinition(data); else if (choiceDefinitionType.equals("multipleCardPick")) return buildMultipleCardPickDraftChoiceDefinition(data); else if (choiceDefinitionType.equals("randomSwitch")) return buildRandomSwitchDraftChoiceDeifinition(data); + else if (choiceDefinitionType.equals("filterPick")) + return buildFilterPickDraftChoiceDefinition(data); else throw new RuntimeException("Unknown choiceDefinitionType: " + choiceDefinitionType); } + private DraftChoiceDefinition buildFilterPickDraftChoiceDefinition(JSONObject data) { + final int optionCount = ((Number) data.get("optionCount")).intValue(); + String filter = (String) data.get("filter"); + + Collection items = _collectionsManager.getDefaultCollection().getAll().values(); + + final List possibleCards = _sortAndFilterCards.process(filter, items, _cardLibrary, _formatLibrary, _rarities); + + return new DraftChoiceDefinition() { + @Override + public Iterable getDraftChoice(long seed, int stage) { + final List cards = getCards(seed, stage); + + List draftChoices = new ArrayList(optionCount); + for (int i = 0; i < Math.min(optionCount, possibleCards.size()); i++) { + final int finalI = i; + draftChoices.add( + new SoloDraft.DraftChoice() { + @Override + public String getChoiceId() { + return cards.get(finalI).getBlueprintId(); + } + + @Override + public String getBlueprintId() { + return cards.get(finalI).getBlueprintId(); + } + + @Override + public String getChoiceUrl() { + return null; + } + }); + } + return draftChoices; + } + + @Override + public CardCollection getCardsForChoiceId(String choiceId, long seed, int stage) { + DefaultCardCollection cardCollection = new DefaultCardCollection(); + cardCollection.addItem(choiceId, 1); + return cardCollection; + } + + private List getCards(long seed, int stage) { + Random rnd = getRandom(seed, stage); + final List cards = new ArrayList(possibleCards); + Collections.shuffle(cards, rnd); + return cards; + } + }; + } + private DraftChoiceDefinition buildSingleCollectionPickDraftChoiceDefinition(JSONObject data) { JSONArray switchResult = (JSONArray) data.get("possiblePicks"); @@ -82,7 +160,6 @@ public class DraftChoiceBuilder { } private DraftChoiceDefinition buildMultipleCardPickDraftChoiceDefinition(JSONObject data) { - final long selectionSeed = ((Number) data.get("seed")).longValue(); final int count = ((Number) data.get("count")).intValue(); JSONArray availableCards = (JSONArray) data.get("availableCards"); @@ -135,7 +212,7 @@ public class DraftChoiceBuilder { } private List getShuffledCards(long seed, int stage) { - Random rnd = new Random(seed + selectionSeed + stage); + Random rnd = getRandom(seed, stage); final List shuffledCards = new ArrayList(cards); Collections.shuffle(shuffledCards, rnd); return shuffledCards; @@ -144,7 +221,6 @@ public class DraftChoiceBuilder { } private DraftChoiceDefinition buildRandomSwitchDraftChoiceDeifinition(JSONObject data) { - final long selectionSeed = ((Number) data.get("seed")).longValue(); JSONArray switchResult = (JSONArray) data.get("switchResult"); final List draftChoiceDefinitionList = new ArrayList(); @@ -154,15 +230,57 @@ public class DraftChoiceBuilder { return new DraftChoiceDefinition() { @Override public Iterable getDraftChoice(long seed, int stage) { - Random rnd = new Random(seed + selectionSeed); + Random rnd = getRandom(seed, stage); return draftChoiceDefinitionList.get(rnd.nextInt(draftChoiceDefinitionList.size())).getDraftChoice(seed, stage); } @Override public CardCollection getCardsForChoiceId(String choiceId, long seed, int stage) { - Random rnd = new Random(seed + selectionSeed); + Random rnd = getRandom(seed, stage); return draftChoiceDefinitionList.get(rnd.nextInt(draftChoiceDefinitionList.size())).getCardsForChoiceId(choiceId, seed, stage); } }; } + + private DraftChoiceDefinition buildWeightedSwitchDraftChoiceDefinition(JSONObject data) { + JSONArray switchResult = (JSONArray) data.get("switchResult"); + + final Map draftChoiceDefinitionMap = new LinkedHashMap(); + float weightTotal = 0; + for (JSONObject switchResultObject : (Iterable) switchResult) { + float weight = ((Number) switchResultObject.get("weight")).floatValue(); + weightTotal += weight; + draftChoiceDefinitionMap.put(weightTotal, constructDraftChoiceDefinition(switchResultObject)); + } + + return new DraftChoiceDefinition() { + @Override + public Iterable getDraftChoice(long seed, int stage) { + Random rnd = getRandom(seed, stage); + float result = rnd.nextFloat(); + for (Map.Entry weightEntry : draftChoiceDefinitionMap.entrySet()) { + if (result < weightEntry.getKey()) + return weightEntry.getValue().getDraftChoice(seed, stage); + } + + return null; + } + + @Override + public CardCollection getCardsForChoiceId(String choiceId, long seed, int stage) { + Random rnd = getRandom(seed, stage); + float result = rnd.nextFloat(); + for (Map.Entry weightEntry : draftChoiceDefinitionMap.entrySet()) { + if (result < weightEntry.getKey()) + return weightEntry.getValue().getCardsForChoiceId(choiceId, seed, stage); + } + + return null; + } + }; + } + + private Random getRandom(long seed, int stage) { + return new Random(seed + stage * HIGH_ENOUGH_PRIME_NUMBER); + } } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/builder/StartingPoolBuilder.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/builder/StartingPoolBuilder.java index 030a905fe..814586d64 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/builder/StartingPoolBuilder.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/draft2/builder/StartingPoolBuilder.java @@ -20,7 +20,6 @@ public class StartingPoolBuilder { } private CardCollectionProducer buildRandomCardPool(JSONObject randomCardPool) { - final long selectionSeed = ((Number) randomCardPool.get("seed")).longValue(); JSONArray cardPools = (JSONArray) randomCardPool.get("randomResult"); final List cardCollections = new ArrayList(); @@ -39,7 +38,7 @@ public class StartingPoolBuilder { return new CardCollectionProducer() { @Override public CardCollection getCardCollection(long seed) { - Random rnd = new Random(seed+selectionSeed); + Random rnd = new Random(seed); return cardCollections.get(rnd.nextInt(cardCollections.size())); } }; diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/SortAndFilterCards.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/SortAndFilterCards.java index 56063b440..b0d559e56 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/SortAndFilterCards.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/SortAndFilterCards.java @@ -19,7 +19,7 @@ public class SortAndFilterCards { Side side = getSideFilter(filterParams); String type = getTypeFilter(filterParams); - String rarity = getRarityFilter(filterParams); + String[] rarity = getRarityFilter(filterParams); String[] sets = getSetFilter(filterParams); List words = getWords(filterParams); Set cardTypes = getEnumFilter(CardType.values(), CardType.class, "cardType", null, filterParams); @@ -76,7 +76,7 @@ public class SortAndFilterCards { } private boolean acceptsFilters( - LotroCardBlueprintLibrary library, Map cardBlueprint, LotroFormatLibrary formatLibrary, Map rarities, String blueprintId, Side side, String type, String rarity, String[] sets, + LotroCardBlueprintLibrary library, Map cardBlueprint, LotroFormatLibrary formatLibrary, Map rarities, String blueprintId, Side side, String type, String[] rarity, String[] sets, Set cardTypes, Set cultures, Set keywords, List words, Integer siteNumber) { if (isPack(blueprintId)) { if (type == null || type.equals("pack")) @@ -118,10 +118,10 @@ public class SortAndFilterCards { return null; } - private String getRarityFilter(String[] filterParams) { + private String[] getRarityFilter(String[] filterParams) { for (String filterParam : filterParams) { if (filterParam.startsWith("rarity:")) - return filterParam.substring("rarity:".length()); + return filterParam.substring("rarity:".length()).split(","); } return null; } @@ -134,11 +134,16 @@ public class SortAndFilterCards { return sets; } - private boolean isRarity(String blueprintId, String rarity, LotroCardBlueprintLibrary library, Map rarities) { + private boolean isRarity(String blueprintId, String[] rarity, LotroCardBlueprintLibrary library, Map rarities) { if (blueprintId.contains("_")) { SetDefinition setRarity = rarities.get(blueprintId.substring(0, blueprintId.indexOf("_"))); - if (setRarity != null && setRarity.getCardRarity(library.stripBlueprintModifiers(blueprintId)).equals(rarity)) - return true; + if (setRarity != null) { + String cardRarity = setRarity.getCardRarity(library.stripBlueprintModifiers(blueprintId)); + for (String r : rarity) { + if (cardRarity.equals(r)) + return true; + } + } return false; } return true; diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SoloDraftLeagueData.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SoloDraftLeagueData.java index 0b5dbcf88..b2ba85434 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SoloDraftLeagueData.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SoloDraftLeagueData.java @@ -15,6 +15,7 @@ import com.gempukku.lotro.game.Player; import java.util.*; public class SoloDraftLeagueData implements LeagueData { + public static final int HIGH_ENOUGH_PRIME_NUMBER = 8963; private SoloDraft _draft; private CollectionType _collectionType; private CollectionType _prizeCollectionType = CollectionType.MY_CARDS; @@ -56,7 +57,7 @@ public class SoloDraftLeagueData implements LeagueData { } private long getSeed(Player player) { - return _collectionType.getCode().hashCode() + player.getId(); + return _collectionType.getCode().hashCode() + player.getId() * HIGH_ENOUGH_PRIME_NUMBER; } @Override diff --git a/gemp-lotr/gemp-lotr-server/src/main/resources/draft/testDraft.json b/gemp-lotr/gemp-lotr-server/src/main/resources/draft/testDraft.json new file mode 100644 index 000000000..22f10b193 --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/resources/draft/testDraft.json @@ -0,0 +1,230 @@ +{ + "format": "limited_fotr", + "startingPool": { + "type": "randomCardPool", + "data": { + "randomResult": [ + ["1_2", "1_290"], + ["1_2", "1_290"] + ] + } + }, + "choices": [ + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "side:FREE_PEOPLE cardType:POSSESSION,ARTIFACT set:1 rarity:R" + } + }, + { + "type": "weightedSwitch", + "repeat": 4, + "data": { + "switchResult": [ + { + "weight": 0.1, + "type": "filterPick", + "data": { + "optionCount": 3, + "filter": "side:FREE_PEOPLE cardType:COMPANION set:1 rarity:R" + } + }, + { + "weight": 0.3, + "type": "filterPick", + "data": { + "optionCount": 4, + "filter": "side:FREE_PEOPLE cardType:COMPANION set:1 rarity:U,P" + } + }, + { + "weight": 0.6, + "type": "filterPick", + "data": { + "optionCount": 5, + "filter": "side:FREE_PEOPLE cardType:COMPANION set:1 rarity:C" + } + } + ] + } + }, + { + "type": "weightedSwitch", + "repeat": 30, + "data": { + "switchResult": [ + { + "weight": 0.1, + "type": "filterPick", + "data": { + "optionCount": 5, + "filter": "side:FREE_PEOPLE set:1 rarity:R" + } + }, + { + "weight": 0.3, + "type": "filterPick", + "data": { + "optionCount": 8, + "filter": "side:FREE_PEOPLE set:1 rarity:U,P" + } + }, + { + "weight": 0.6, + "type": "filterPick", + "data": { + "optionCount": 10, + "filter": "side:FREE_PEOPLE set:1 rarity:C" + } + } + ] + } + }, + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "side:SHADOW cardType:MINION set:1 rarity:R" + } + }, + { + "type": "weightedSwitch", + "repeat": 14, + "data": { + "switchResult": [ + { + "weight": 0.1, + "type": "filterPick", + "data": { + "optionCount": 3, + "filter": "side:SHADOW cardType:MINION set:1 rarity:R" + } + }, + { + "weight": 0.3, + "type": "filterPick", + "data": { + "optionCount": 4, + "filter": "side:SHADOW cardType:MINION set:1 rarity:U,P" + } + }, + { + "weight": 0.6, + "type": "filterPick", + "data": { + "optionCount": 5, + "filter": "side:SHADOW cardType:MINION set:1 rarity:C" + } + } + ] + } + }, + { + "type": "weightedSwitch", + "repeat": 20, + "data": { + "switchResult": [ + { + "weight": 0.1, + "type": "filterPick", + "data": { + "optionCount": 5, + "filter": "side:SHADOW set:1 rarity:R" + } + }, + { + "weight": 0.3, + "type": "filterPick", + "data": { + "optionCount": 8, + "filter": "side:SHADOW set:1 rarity:U,P" + } + }, + { + "weight": 0.6, + "type": "filterPick", + "data": { + "optionCount": 10, + "filter": "side:SHADOW set:1 rarity:C" + } + } + ] + } + }, + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "cardType:SITE set:1 siteNumber:1" + } + }, + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "cardType:SITE set:1 siteNumber:2" + } + }, + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "cardType:SITE set:1 siteNumber:3" + } + }, + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "cardType:SITE set:1 siteNumber:4" + } + }, + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "cardType:SITE set:1 siteNumber:5" + } + }, + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "cardType:SITE set:1 siteNumber:6" + } + }, + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "cardType:SITE set:1 siteNumber:7" + } + }, + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "cardType:SITE set:1 siteNumber:8" + } + }, + { + "type": "filterPick", + "repeat": 1, + "data": { + "optionCount": 3, + "filter": "cardType:SITE set:1 siteNumber:9" + } + } + ] +} diff --git a/gemp-lotr/gemp-lotr-server/src/main/resources/lotrDrafts.json b/gemp-lotr/gemp-lotr-server/src/main/resources/lotrDrafts.json index e7d28f043..7c7203b25 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/resources/lotrDrafts.json +++ b/gemp-lotr/gemp-lotr-server/src/main/resources/lotrDrafts.json @@ -1,6 +1,6 @@ [ { - "type": "hobbit_draft", - "location": "/draft/hobbit.json" + "type": "test_draft", + "location": "/draft/testDraft.json" } ] \ No newline at end of file diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/draft2/SoloDraftDefinitionsTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/draft2/SoloDraftDefinitionsTest.java index ba695f9cc..485ed4db6 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/draft2/SoloDraftDefinitionsTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/draft2/SoloDraftDefinitionsTest.java @@ -8,12 +8,12 @@ import static org.junit.Assert.*; public class SoloDraftDefinitionsTest { @Test public void loadSoloDraftDefinitions() { - SoloDraftDefinitions soloDraftDefinitions = new SoloDraftDefinitions(); + SoloDraftDefinitions soloDraftDefinitions = new SoloDraftDefinitions(null, null, null, null); } @Test public void playerDrafting() { - SoloDraftDefinitions soloDraftDefinitions = new SoloDraftDefinitions(); + SoloDraftDefinitions soloDraftDefinitions = new SoloDraftDefinitions(null, null, null, null); SoloDraft soloDraft = soloDraftDefinitions.getSoloDraft("hobbit_draft"); assertTrue(soloDraft.hasNextStage(0, 0)); Iterable availableChoices = soloDraft.getAvailableChoices(0, 0); diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/ConstructedLeagueDataTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/ConstructedLeagueDataTest.java index 148d346e1..b075714a3 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/ConstructedLeagueDataTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/ConstructedLeagueDataTest.java @@ -10,9 +10,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class ConstructedLeagueDataTest { + private SoloDraftDefinitions soloDraftDefinitions = new SoloDraftDefinitions(null, null, null, null); + @Test public void testParameters() { - ConstructedLeagueData leagueData = new ConstructedLeagueData(new CardSets(), new SoloDraftDefinitions(), "20120312,fotr_block,0.7,default,All cards,7,10,3,fotr1_block,fotr_block,fotr2_block,fotr_block,fotr_block,fotr_block"); + ConstructedLeagueData leagueData = new ConstructedLeagueData(new CardSets(), soloDraftDefinitions, "20120312,fotr_block,0.7,default,All cards,7,10,3,fotr1_block,fotr_block,fotr2_block,fotr_block,fotr_block,fotr_block"); final List series = leagueData.getSeries(); assertTrue(series.size() == 3); assertTrue(series.get(0).getStart() == 20120312); diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeagueServiceTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeagueServiceTest.java index 3598b32c4..d22d120e2 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeagueServiceTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeagueServiceTest.java @@ -20,9 +20,11 @@ import java.util.Set; import static org.junit.Assert.*; public class LeagueServiceTest { + private SoloDraftDefinitions soloDraftDefinitions = new SoloDraftDefinitions(null, null, null, null); private CardSets _cardSets = new CardSets(); @Test public void testJoiningLeagueAfterMaxGamesPlayed() throws Exception { + LeagueDAO leagueDao = Mockito.mock(LeagueDAO.class); StringBuilder sb = new StringBuilder(); @@ -35,7 +37,7 @@ public class LeagueServiceTest { League league = new League(5000, "League name", "leagueType", NewConstructedLeagueData.class.getName(), sb.toString(), 0); leagues.add(league); - LeagueSerieData leagueSerie = league.getLeagueData(_cardSets, new SoloDraftDefinitions()).getSeries().get(0); + LeagueSerieData leagueSerie = league.getLeagueData(_cardSets, soloDraftDefinitions).getSeries().get(0); Mockito.when(leagueDao.loadActiveLeagues(Mockito.anyInt())).thenReturn(leagues); @@ -48,7 +50,7 @@ public class LeagueServiceTest { LeagueParticipationDAO leagueParticipationDAO = Mockito.mock(LeagueParticipationDAO.class); CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); - LeagueService leagueService = new LeagueService(leagueDao, leagueMatchDAO, leagueParticipationDAO, collectionsManager, _cardSets, new SoloDraftDefinitions()); + LeagueService leagueService = new LeagueService(leagueDao, leagueMatchDAO, leagueParticipationDAO, collectionsManager, _cardSets, soloDraftDefinitions); assertTrue(leagueService.canPlayRankedGame(league, leagueSerie, "player1")); assertTrue(leagueService.canPlayRankedGameAgainst(league, leagueSerie, "player1", "player2")); @@ -88,7 +90,7 @@ public class LeagueServiceTest { League league = new League(5000, "League name", "leagueType", NewConstructedLeagueData.class.getName(), sb.toString(), 0); leagues.add(league); - LeagueSerieData leagueSerie = league.getLeagueData(_cardSets, new SoloDraftDefinitions()).getSeries().get(0); + LeagueSerieData leagueSerie = league.getLeagueData(_cardSets, soloDraftDefinitions).getSeries().get(0); Mockito.when(leagueDao.loadActiveLeagues(Mockito.anyInt())).thenReturn(leagues); @@ -102,7 +104,7 @@ public class LeagueServiceTest { LeagueParticipationDAO leagueParticipationDAO = Mockito.mock(LeagueParticipationDAO.class); CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); - LeagueService leagueService = new LeagueService(leagueDao, leagueMatchDAO, leagueParticipationDAO, collectionsManager, _cardSets, new SoloDraftDefinitions()); + LeagueService leagueService = new LeagueService(leagueDao, leagueMatchDAO, leagueParticipationDAO, collectionsManager, _cardSets, soloDraftDefinitions); assertTrue(leagueService.canPlayRankedGame(league, leagueSerie, "player1")); assertFalse(leagueService.canPlayRankedGameAgainst(league, leagueSerie, "player1", "player2")); @@ -134,7 +136,7 @@ public class LeagueServiceTest { League league = new League(5000, "League name", "leagueType", NewConstructedLeagueData.class.getName(), sb.toString(), 0); leagues.add(league); - LeagueSerieData leagueSerie = league.getLeagueData(_cardSets, new SoloDraftDefinitions()).getSeries().get(0); + LeagueSerieData leagueSerie = league.getLeagueData(_cardSets, soloDraftDefinitions).getSeries().get(0); Mockito.when(leagueDao.loadActiveLeagues(Mockito.anyInt())).thenReturn(leagues); @@ -152,7 +154,7 @@ public class LeagueServiceTest { Mockito.when(leagueParticipationDAO.getUsersParticipating(league.getType())).thenReturn(players); CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); - LeagueService leagueService = new LeagueService(leagueDao, leagueMatchDAO, leagueParticipationDAO, collectionsManager, _cardSets, new SoloDraftDefinitions()); + LeagueService leagueService = new LeagueService(leagueDao, leagueMatchDAO, leagueParticipationDAO, collectionsManager, _cardSets, soloDraftDefinitions); leagueService.reportLeagueGameResult(league, leagueSerie, "player1", "player2"); leagueService.reportLeagueGameResult(league, leagueSerie, "player1", "player3"); diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java index 3cb39b1dd..71101ea1d 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeagueDataTest.java @@ -19,9 +19,11 @@ import java.util.*; import static org.junit.Assert.assertEquals; public class SealedLeagueDataTest { + private SoloDraftDefinitions soloDraftDefinitions = new SoloDraftDefinitions(null, null, null, null); + @Test public void testJoinLeagueFirstWeek() { - SealedLeagueData data = new SealedLeagueData(new CardSets(), new SoloDraftDefinitions(), "fotr_block,20120101,test,Test Collection"); + SealedLeagueData data = new SealedLeagueData(new CardSets(), soloDraftDefinitions, "fotr_block,20120101,test,Test Collection"); CollectionType collectionType = new CollectionType("test", "Test Collection"); for (int i = 20120101; i < 20120108; i++) { CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); @@ -56,7 +58,7 @@ public class SealedLeagueDataTest { @Test public void testJoinLeagueSecondWeek() { - SealedLeagueData data = new SealedLeagueData(new CardSets(), new SoloDraftDefinitions(), "fotr_block,20120101,test,Test Collection"); + SealedLeagueData data = new SealedLeagueData(new CardSets(), soloDraftDefinitions, "fotr_block,20120101,test,Test Collection"); CollectionType collectionType = new CollectionType("test", "Test Collection"); for (int i = 20120108; i < 20120115; i++) { CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); @@ -97,7 +99,7 @@ public class SealedLeagueDataTest { @Test public void testSwitchToFirstWeek() { - SealedLeagueData data = new SealedLeagueData(new CardSets(), new SoloDraftDefinitions(), "fotr_block,20120101,test,Test Collection"); + SealedLeagueData data = new SealedLeagueData(new CardSets(), soloDraftDefinitions, "fotr_block,20120101,test,Test Collection"); for (int i = 20120101; i < 20120108; i++) { CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(new HashMap()); @@ -110,7 +112,7 @@ public class SealedLeagueDataTest { @Test public void testProcessMidFirstWeek() { - SealedLeagueData data = new SealedLeagueData(new CardSets(), new SoloDraftDefinitions(), "fotr_block,20120101,test,Test Collection"); + SealedLeagueData data = new SealedLeagueData(new CardSets(), soloDraftDefinitions, "fotr_block,20120101,test,Test Collection"); for (int i = 20120101; i < 20120108; i++) { CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(new HashMap()); @@ -122,7 +124,7 @@ public class SealedLeagueDataTest { @Test public void testSwitchToSecondWeek() { - SealedLeagueData data = new SealedLeagueData(new CardSets(), new SoloDraftDefinitions(), "fotr_block,20120101,test,Test Collection"); + SealedLeagueData data = new SealedLeagueData(new CardSets(), soloDraftDefinitions, "fotr_block,20120101,test,Test Collection"); CollectionType collectionType = new CollectionType("test", "Test Collection"); for (int i = 20120108; i < 20120115; i++) { CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); @@ -158,7 +160,7 @@ public class SealedLeagueDataTest { @Test public void testProcessMidSecondWeek() { - SealedLeagueData data = new SealedLeagueData(new CardSets(), new SoloDraftDefinitions(), "fotr_block,20120101,test,Test Collection"); + SealedLeagueData data = new SealedLeagueData(new CardSets(), soloDraftDefinitions, "fotr_block,20120101,test,Test Collection"); for (int i = 20120108; i < 20120115; i++) { CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class); Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(new HashMap());