Some refactoring, and awarding prizes for solo draft leagues

This commit is contained in:
marcin.sciesinski
2018-05-15 23:08:34 -07:00
parent f1623422ec
commit ad23526be4
3 changed files with 23 additions and 28 deletions

View File

@@ -7,6 +7,7 @@ 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.apache.log4j.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -17,6 +18,7 @@ import java.io.InputStreamReader;
import java.util.*;
public class SoloDraftDefinitions {
private static Logger _logger = Logger.getLogger(SoloDraftDefinitions.class);
private Map<String, SoloDraft> draftTypes = new HashMap<String, SoloDraft>();
private StartingPoolBuilder startingPoolBuilder = new StartingPoolBuilder();
private DraftChoiceBuilder draftChoiceBuilder;
@@ -66,6 +68,7 @@ public class SoloDraftDefinitions {
draftChoiceDefinitions.add(draftChoiceDefinition);
}
_logger.debug("Loaded draft definition: "+file);
return new DefaultSoloDraft(format, cardCollectionProducer, draftChoiceDefinitions);
} catch (ParseException exp) {
throw new RuntimeException("Problem loading solo draft " + file, exp);

View File

@@ -2,7 +2,7 @@ package com.gempukku.lotro.draft2.builder;
import com.gempukku.lotro.game.CardCollection;
import com.gempukku.lotro.game.DefaultCardCollection;
import com.google.common.collect.Iterators;
import com.google.common.collect.Iterables;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
@@ -54,8 +54,8 @@ public class StartingPoolBuilder {
@Override
public CardCollection getCardCollection(long seed) {
Random rnd = new Random(seed);
List<String> freePeoplesRun = ((List<List<String>>) freePeoplesRuns).get(rnd.nextInt(freePeoplesRuns.size()));
List<String> shadowRun = ((List<List<String>>) shadowRuns).get(rnd.nextInt(shadowRuns.size()));
List<String> freePeoplesRun = (List<String>) freePeoplesRuns.get(rnd.nextInt(freePeoplesRuns.size()));
List<String> shadowRun = (List<String>) shadowRuns.get(rnd.nextInt(shadowRuns.size()));
int freePeopleLength = freePeoplesRun.size();
int shadowLength = shadowRun.size();
@@ -72,28 +72,20 @@ public class StartingPoolBuilder {
int freePeopleStart = rnd.nextInt(freePeopleLength);
int shadowStart = rnd.nextInt(shadowLength);
Iterator<String> freePeopleIterator = getCyclingIterator(freePeoplesRun, freePeopleStart, runLength);
Iterator<String> shadowIterator = getCyclingIterator(shadowRun, shadowStart, runLength);
Iterable<String> freePeopleIterator = getCyclingIterable(freePeoplesRun, freePeopleStart, runLength);
Iterable<String> shadowIterator = getCyclingIterable(shadowRun, shadowStart, runLength);
final DefaultCardCollection draftCollection = new DefaultCardCollection();
final DefaultCardCollection startingCollection = new DefaultCardCollection();
for (String coreCard : (List<String>) coreCards) {
draftCollection.addItem(coreCard, 1);
}
while (freePeopleIterator.hasNext()) {
draftCollection.addItem(freePeopleIterator.next(), 1);
}
while (shadowIterator.hasNext()) {
draftCollection.addItem(shadowIterator.next(), 1);
}
return draftCollection;
for (String card : Iterables.concat((List<String>) coreCards, freePeopleIterator, shadowIterator))
startingCollection.addItem(card, 1);
return startingCollection;
}
};
}
private static Iterator<String> getCyclingIterator(List<String> list, int start, int length) {
Iterator<String> cycleListIterator = Iterators.cycle(list);
Iterators.skip(cycleListIterator, start);
return Iterators.limit(cycleListIterator, length);
private static Iterable<String> getCyclingIterable(List<String> list, int start, int length) {
return Iterables.limit(Iterables.skip(Iterables.cycle(list), start), length);
}
}

View File

@@ -106,14 +106,14 @@ public class SoloDraftLeagueData implements LeagueData {
if (status == 1) {
if (currentTime > DateUtils.offsetDate(_serie.getEnd(), 1)) {
// for (PlayerStanding leagueStanding : leagueStandings) {
// CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), leagueStanding.getGamesPlayed(), maxGamesTotal, _collectionType);
// if (leaguePrize != null)
// collectionsManager.addItemsToPlayerCollection(true, "End of league prizes", leagueStanding.getPlayerName(), _prizeCollectionType, leaguePrize.getAll().values());
// final CardCollection leagueTrophies = _leaguePrizes.getTrophiesForLeague(leagueStanding.getStanding(), leagueStandings.size(), leagueStanding.getGamesPlayed(), maxGamesTotal, _collectionType);
// if (leagueTrophies != null)
// collectionsManager.addItemsToPlayerCollection(true, "End of league trophies", leagueStanding.getPlayerName(), CollectionType.TROPHY, leagueTrophies.getAll().values());
// }
for (PlayerStanding leagueStanding : leagueStandings) {
CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), leagueStanding.getGamesPlayed(), maxGamesTotal, _collectionType);
if (leaguePrize != null)
collectionsManager.addItemsToPlayerCollection(true, "End of league prizes", leagueStanding.getPlayerName(), _prizeCollectionType, leaguePrize.getAll().values());
final CardCollection leagueTrophies = _leaguePrizes.getTrophiesForLeague(leagueStanding.getStanding(), leagueStandings.size(), leagueStanding.getGamesPlayed(), maxGamesTotal, _collectionType);
if (leagueTrophies != null)
collectionsManager.addItemsToPlayerCollection(true, "End of league trophies", leagueStanding.getPlayerName(), CollectionType.TROPHY, leagueTrophies.getAll().values());
}
status++;
}
}