From fa152b7e3d9b0d36f6311f4e7e5314e80f71c3af Mon Sep 17 00:00:00 2001 From: "marcins78@gmail.com" Date: Thu, 8 Mar 2012 12:16:34 +0000 Subject: [PATCH] Added constructed league format. --- .../lotro/league/ConstructedLeagueData.java | 81 +++++++ ...eData.java => DefaultLeagueSerieData.java} | 16 +- .../gempukku/lotro/league/LeaguePrizes.java | 197 ++++++++++++++++-- .../lotro/league/SealedLeagueData.java | 13 +- .../lotro/league/SealedLeaguePrizes.java | 187 ----------------- .../src/main/resources/lotrFormats.json | 18 ++ .../league/ConstructedLeagueDataTest.java | 26 +++ ...ePrizesTest.java => LeaguePrizesTest.java} | 4 +- 8 files changed, 326 insertions(+), 216 deletions(-) create mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/ConstructedLeagueData.java rename gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/{SealedLeagueSerieData.java => DefaultLeagueSerieData.java} (69%) delete mode 100644 gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeaguePrizes.java create mode 100644 gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/ConstructedLeagueDataTest.java rename gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/{SealedLeaguePrizesTest.java => LeaguePrizesTest.java} (79%) diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/ConstructedLeagueData.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/ConstructedLeagueData.java new file mode 100644 index 000000000..54b4d9dee --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/ConstructedLeagueData.java @@ -0,0 +1,81 @@ +package com.gempukku.lotro.league; + +import com.gempukku.lotro.collection.CollectionsManager; +import com.gempukku.lotro.db.vo.CollectionType; +import com.gempukku.lotro.game.CardCollection; +import com.gempukku.lotro.game.Player; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class ConstructedLeagueData implements LeagueData { + private List _series = new ArrayList(); + private String _leaguePrizePool; + private CollectionType _prizeCollectionType = new CollectionType("permanent", "My cards"); + private float _prizeMultiplier; + private LeaguePrizes _leaguePrizes = new LeaguePrizes(); + + // Example params - 20120312,fotr_block,0.7,default,All cards,7,10,3,fotr1_block,fotr_block,fotr2_block,fotr_block,fotr_block,fotr_block + // Which means - start date,league prize pool,prizes multiplier,collection type,collection name,serie length,serie match count,series count, + // serie1 format, serie1 prize pool, + // serie2 format, serie2 prize pool, + // serie3 format, serie3 prize pool, + public ConstructedLeagueData(String parameters) { + String[] params = parameters.split(","); + final int start = Integer.parseInt(params[0]); + _leaguePrizePool = params[1]; + _prizeMultiplier = Float.parseFloat(params[2]); + CollectionType collectionType = new CollectionType(params[3], params[4]); + int days = Integer.parseInt(params[5]); + int matchCount = Integer.parseInt(params[6]); + int series = Integer.parseInt(params[7]); + for (int i = 0; i < series; i++) { + String format = params[8 + i * 2]; + String seriePrizePool = params[9 + i * 2]; + + DefaultLeagueSerieData data = new DefaultLeagueSerieData(_leaguePrizes, false, "Week " + (i + 1), getDate(start, i * days), getDate(start, ((i + 1) * days) - 1), matchCount, format, seriePrizePool, collectionType); + _series.add(data); + } + } + + private int getDate(int start, int dayOffset) { + try { + SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); + Date date = format.parse(String.valueOf(start)); + date.setDate(date.getDate() + dayOffset); + return Integer.parseInt(format.format(date)); + } catch (ParseException exp) { + throw new RuntimeException("Can't parse date", exp); + } + } + + @Override + public List getSeries() { + return _series; + } + + @Override + public CardCollection joinLeague(CollectionsManager collecionsManager, Player player, int currentTime) { + return null; + } + + @Override + public int process(CollectionsManager collectionsManager, List leagueStandings, int oldStatus, int currentTime) { + int status = oldStatus; + if (status == 0) { + LeagueSerieData lastSerie = _series.get(_series.size() - 1); + if (currentTime > getDate(lastSerie.getEnd(), 1)) { + for (LeagueStanding leagueStanding : leagueStandings) { + CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), _prizeMultiplier, _leaguePrizePool); + collectionsManager.addItemsToPlayerCollection(leagueStanding.getPlayerName(), _prizeCollectionType, leaguePrize.getAll()); + } + status++; + } + } + + return status; + } +} diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueSerieData.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/DefaultLeagueSerieData.java similarity index 69% rename from gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueSerieData.java rename to gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/DefaultLeagueSerieData.java index ed706328e..8d3eaa4d1 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueSerieData.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/DefaultLeagueSerieData.java @@ -3,22 +3,26 @@ package com.gempukku.lotro.league; import com.gempukku.lotro.db.vo.CollectionType; import com.gempukku.lotro.game.CardCollection; -public class SealedLeagueSerieData implements LeagueSerieData { - private SealedLeaguePrizes _leaguePrizes; +public class DefaultLeagueSerieData implements LeagueSerieData { + private LeaguePrizes _leaguePrizes; + private boolean _limited; private String _name; private int _start; private int _end; private int _maxMatches; private String _format; + private String _prizePool; private CollectionType _collectionType; - public SealedLeagueSerieData(SealedLeaguePrizes leaguePrizes, String name, int start, int end, int maxMatches, String format, CollectionType collectionType) { + public DefaultLeagueSerieData(LeaguePrizes leaguePrizes, boolean limited, String name, int start, int end, int maxMatches, String format, String prizePool, CollectionType collectionType) { _leaguePrizes = leaguePrizes; + _limited = limited; _name = name; _start = start; _end = end; _maxMatches = maxMatches; _format = format; + _prizePool = prizePool; _collectionType = collectionType; } @@ -44,7 +48,7 @@ public class SealedLeagueSerieData implements LeagueSerieData { @Override public boolean isLimited() { - return true; + return _limited; } @Override @@ -59,11 +63,11 @@ public class SealedLeagueSerieData implements LeagueSerieData { @Override public CardCollection getPrizeForLeagueMatchWinner(int winCountThisSerie, int totalGamesPlayedThisSerie) { - return _leaguePrizes.getPrizeForLeagueMatchWinner(winCountThisSerie, totalGamesPlayedThisSerie, _format); + return _leaguePrizes.getPrizeForLeagueMatchWinner(winCountThisSerie, totalGamesPlayedThisSerie, _prizePool); } @Override public CardCollection getPrizeForLeagueMatchLoser(int winCountThisSerie, int totalGamesPlayedThisSerie) { - return _leaguePrizes.getPrizeForLeagueMatchLoser(winCountThisSerie, totalGamesPlayedThisSerie, _format); + return _leaguePrizes.getPrizeForLeagueMatchLoser(winCountThisSerie, totalGamesPlayedThisSerie, _prizePool); } } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeaguePrizes.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeaguePrizes.java index 4937a792f..aaaa92433 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeaguePrizes.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/LeaguePrizes.java @@ -1,22 +1,189 @@ package com.gempukku.lotro.league; +import com.gempukku.lotro.cards.packs.RarityReader; +import com.gempukku.lotro.cards.packs.SetRarity; +import com.gempukku.lotro.game.CardCollection; +import com.gempukku.lotro.game.DefaultCardCollection; + +import java.util.*; + public class LeaguePrizes { - public static void main(String[] args) { - int players = 32; - int lastDisplayed = 0; - int lastCount = Integer.MAX_VALUE; - for (int i = 1; i <= players; i++) { - int count = (int) Math.floor((2 * players + 24) / (i + 9) - 2.4); - if (lastCount != count) { - if (lastDisplayed > 0 && lastCount > 0) { - if (lastDisplayed == (i - 1)) - System.out.println(lastDisplayed + ": " + lastCount); - else - System.out.println(lastDisplayed + "-" + (i - 1) + ": " + lastCount); - } - lastCount = count; - lastDisplayed = i; + private Map> _blockPromos = new HashMap>(); + private Map> _blockCommons = new HashMap>(); + private Map> _blockUncommons = new HashMap>(); + private static final String FOTR_BLOCK = "fotr_block"; + private static final String TTT_BLOCK = "ttt_block"; + + public LeaguePrizes() { + List fotrPromos = new ArrayList(); + fotrPromos.add("0_1"); + fotrPromos.add("0_2"); + fotrPromos.add("0_3"); + fotrPromos.add("0_4"); + fotrPromos.add("0_5"); + fotrPromos.add("0_6"); + fotrPromos.add("0_7"); + fotrPromos.add("0_8"); + fotrPromos.add("0_9"); + fotrPromos.add("0_10"); + fotrPromos.add("0_11"); + fotrPromos.add("0_12"); + fotrPromos.add("0_13"); + fotrPromos.add("0_14"); + fotrPromos.add("0_15"); + fotrPromos.add("0_34"); + fotrPromos.add("0_36"); + fotrPromos.add("0_37"); + fotrPromos.add("0_41"); + fotrPromos.add("0_42"); + fotrPromos.add("0_43"); + _blockPromos.put(FOTR_BLOCK, fotrPromos); + + List tttPromos = new ArrayList(); + tttPromos.add("0_16"); + tttPromos.add("0_17"); + tttPromos.add("0_18"); + tttPromos.add("0_19"); + tttPromos.add("0_21"); + tttPromos.add("0_22"); + tttPromos.add("0_30"); + tttPromos.add("0_32"); + tttPromos.add("0_33"); + tttPromos.add("0_35"); + tttPromos.add("0_38"); + tttPromos.add("0_39"); + tttPromos.add("0_40"); + tttPromos.add("0_44"); + tttPromos.add("0_45"); + tttPromos.add("0_46"); + tttPromos.add("0_47"); + _blockPromos.put(TTT_BLOCK, tttPromos); + + RarityReader rarityReader = new RarityReader(); + SetRarity fotrRarity = rarityReader.getSetRarity("1"); + SetRarity momRarity = rarityReader.getSetRarity("2"); + SetRarity rotelRarity = rarityReader.getSetRarity("3"); + + SetRarity tttRarity = rarityReader.getSetRarity("4"); + SetRarity bohdRarity = rarityReader.getSetRarity("5"); + SetRarity eofRarity = rarityReader.getSetRarity("6"); + + List fotrCommons = new ArrayList(); + fotrCommons.addAll(fotrRarity.getCardsOfRarity("C")); + fotrCommons.addAll(momRarity.getCardsOfRarity("C")); + fotrCommons.addAll(rotelRarity.getCardsOfRarity("C")); + _blockCommons.put(FOTR_BLOCK, fotrCommons); + + List fotrUncommons = new ArrayList(); + fotrUncommons.addAll(fotrRarity.getCardsOfRarity("U")); + fotrUncommons.addAll(momRarity.getCardsOfRarity("U")); + fotrUncommons.addAll(rotelRarity.getCardsOfRarity("U")); + _blockUncommons.put(FOTR_BLOCK, fotrUncommons); + + List tttCommons = new ArrayList(); + tttCommons.addAll(tttRarity.getCardsOfRarity("C")); + tttCommons.addAll(bohdRarity.getCardsOfRarity("C")); + tttCommons.addAll(eofRarity.getCardsOfRarity("C")); + _blockCommons.put(TTT_BLOCK, tttCommons); + + List tttUncommons = new ArrayList(); + tttUncommons.addAll(tttRarity.getCardsOfRarity("U")); + tttUncommons.addAll(bohdRarity.getCardsOfRarity("U")); + tttUncommons.addAll(eofRarity.getCardsOfRarity("U")); + _blockUncommons.put(TTT_BLOCK, tttUncommons); + } + + public CardCollection getPrizeForLeagueMatchWinner(int winCountThisSerie, int totalGamesPlayedThisSerie, String format) { + DefaultCardCollection winnerPrize = new DefaultCardCollection(); + if (winCountThisSerie == 1 || winCountThisSerie == 3 || winCountThisSerie == 5 || winCountThisSerie == 8 || winCountThisSerie == 10) + winnerPrize.addItem("(S)Booster Choice", 1); + else { + List blockCommons = _blockCommons.get(format); + List blockUncommons = _blockUncommons.get(format); + List blockPromos = _blockPromos.get(format); + if (winCountThisSerie == 2) + winnerPrize.addItem(getRandom(blockCommons) + "*", 1); + else if (winCountThisSerie == 4) + winnerPrize.addItem(getRandom(blockPromos), 1); + else if (winCountThisSerie == 6) + winnerPrize.addItem(getRandom(blockPromos) + "*", 1); + else if (winCountThisSerie == 7) + winnerPrize.addItem(getRandom(blockUncommons) + "*", 1); + else if (winCountThisSerie == 9) { + winnerPrize.addItem(getRandom(blockPromos), 1); + winnerPrize.addItem(getRandom(blockCommons) + "*", 1); } } + return winnerPrize; + } + + public CardCollection getPrizeForLeagueMatchLoser(int winCountThisSerie, int totalGamesPlayedThisSerie, String format) { + return null; + } + + public CardCollection getPrizeForLeague(int position, int playersCount, float multiplier, String format) { + DefaultCardCollection leaguePrize = new DefaultCardCollection(); + int count = (int) Math.floor((2 * playersCount + 24) / (position + 9) - 2.4); + if (count > 0) { + count = 1 + (int) Math.floor((count - 1) * multiplier); + leaguePrize.addItem("(S)Booster Choice", count); + } + int tengwar = getTengwarCount(position); + if (tengwar > 0) { + if (format.equals(FOTR_BLOCK)) + leaguePrize.addItem("(S)FotR - Tengwar", tengwar); + else if (format.equals(TTT_BLOCK)) + leaguePrize.addItem("(S)TTT - Tengwar", tengwar); + } + if (position == 1) { + addPrizes(leaguePrize, getRandomFoil(_blockPromos.get(format), 3)); + } else if (position == 2) { + addPrizes(leaguePrize, getRandomFoil(_blockPromos.get(format), 2)); + addPrizes(leaguePrize, getRandom(_blockPromos.get(format), 1)); + } else if (position == 3) { + addPrizes(leaguePrize, getRandomFoil(_blockPromos.get(format), 1)); + addPrizes(leaguePrize, getRandom(_blockPromos.get(format), 2)); + } else if (position >= 4 && position <= 6) { + addPrizes(leaguePrize, getRandom(_blockPromos.get(format), 7 - position)); + } else if (position >= 9 && position <= 12) { + addPrizes(leaguePrize, getRandom(_blockPromos.get(format), 1)); + } + + return leaguePrize; + } + + private void addPrizes(DefaultCardCollection leaguePrize, List cards) { + for (String card : cards) + leaguePrize.addItem(card, 1); + } + + private int getTengwarCount(int position) { + if (position == 1) + return 4; + else if (position == 2) + return 3; + else if (position == 3) + return 2; + else if (position <= 8) + return 1; + return 0; + } + + private String getRandom(List list) { + return list.get(new Random().nextInt(list.size())); + } + + private List getRandom(List list, int count) { + List result = new LinkedList(list); + Collections.shuffle(result); + return result.subList(0, count); + } + + private List getRandomFoil(List list, int count) { + List result = new LinkedList(); + for (String element : list) + result.add(element + "*"); + Collections.shuffle(result); + return result.subList(0, count); } } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueData.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueData.java index e8fdea568..4eac89d2e 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueData.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeagueData.java @@ -16,7 +16,7 @@ public class SealedLeagueData implements LeagueData { private List _series; private CollectionType _collectionType; private CollectionType _prizeCollectionType = new CollectionType("permanent", "My cards"); - private SealedLeaguePrizes _leaguePrizes; + private LeaguePrizes _leaguePrizes; private SealedLeagueProduct _leagueProduct; public SealedLeagueData(String parameters) { @@ -28,14 +28,15 @@ public class SealedLeagueData implements LeagueData { int serieDuration = 7; int maxMatches = 10; - _leaguePrizes = new SealedLeaguePrizes(); + _leaguePrizes = new LeaguePrizes(); _leagueProduct = new SealedLeagueProduct(); _series = new LinkedList(); for (int i = 0; i < 4; i++) { _series.add( - new SealedLeagueSerieData(_leaguePrizes, "Week " + (i + 1), - getDate(start, i * serieDuration), getDate(start, (i + 1) * serieDuration - 1), maxMatches, _format, _collectionType)); + new DefaultLeagueSerieData(_leaguePrizes, true, "Week " + (i + 1), + getDate(start, i * serieDuration), getDate(start, (i + 1) * serieDuration - 1), maxMatches, + _format, _format, _collectionType)); } } @@ -89,9 +90,9 @@ public class SealedLeagueData implements LeagueData { if (status == _series.size()) { LeagueSerieData lastSerie = _series.get(_series.size() - 1); - if (currentTime >= getDate(lastSerie.getEnd(), 1)) { + if (currentTime > getDate(lastSerie.getEnd(), 1)) { for (LeagueStanding leagueStanding : leagueStandings) { - CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), _format); + CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), 1f, _format); collectionsManager.addItemsToPlayerCollection(leagueStanding.getPlayerName(), _prizeCollectionType, leaguePrize.getAll()); } for (LeagueStanding leagueStanding : leagueStandings) { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeaguePrizes.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeaguePrizes.java deleted file mode 100644 index 3c6347655..000000000 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/SealedLeaguePrizes.java +++ /dev/null @@ -1,187 +0,0 @@ -package com.gempukku.lotro.league; - -import com.gempukku.lotro.cards.packs.RarityReader; -import com.gempukku.lotro.cards.packs.SetRarity; -import com.gempukku.lotro.game.CardCollection; -import com.gempukku.lotro.game.DefaultCardCollection; - -import java.util.*; - -public class SealedLeaguePrizes { - private Map> _blockPromos = new HashMap>(); - private Map> _blockCommons = new HashMap>(); - private Map> _blockUncommons = new HashMap>(); - private static final String FOTR_BLOCK = "fotr_block"; - private static final String TTT_BLOCK = "ttt_block"; - - public SealedLeaguePrizes() { - List fotrPromos = new ArrayList(); - fotrPromos.add("0_1"); - fotrPromos.add("0_2"); - fotrPromos.add("0_3"); - fotrPromos.add("0_4"); - fotrPromos.add("0_5"); - fotrPromos.add("0_6"); - fotrPromos.add("0_7"); - fotrPromos.add("0_8"); - fotrPromos.add("0_9"); - fotrPromos.add("0_10"); - fotrPromos.add("0_11"); - fotrPromos.add("0_12"); - fotrPromos.add("0_13"); - fotrPromos.add("0_14"); - fotrPromos.add("0_15"); - fotrPromos.add("0_34"); - fotrPromos.add("0_36"); - fotrPromos.add("0_37"); - fotrPromos.add("0_41"); - fotrPromos.add("0_42"); - fotrPromos.add("0_43"); - _blockPromos.put(FOTR_BLOCK, fotrPromos); - - List tttPromos = new ArrayList(); - tttPromos.add("0_16"); - tttPromos.add("0_17"); - tttPromos.add("0_18"); - tttPromos.add("0_19"); - tttPromos.add("0_21"); - tttPromos.add("0_22"); - tttPromos.add("0_30"); - tttPromos.add("0_32"); - tttPromos.add("0_33"); - tttPromos.add("0_35"); - tttPromos.add("0_38"); - tttPromos.add("0_39"); - tttPromos.add("0_40"); - tttPromos.add("0_44"); - tttPromos.add("0_45"); - tttPromos.add("0_46"); - tttPromos.add("0_47"); - _blockPromos.put(TTT_BLOCK, tttPromos); - - RarityReader rarityReader = new RarityReader(); - SetRarity fotrRarity = rarityReader.getSetRarity("1"); - SetRarity momRarity = rarityReader.getSetRarity("2"); - SetRarity rotelRarity = rarityReader.getSetRarity("3"); - - SetRarity tttRarity = rarityReader.getSetRarity("4"); - SetRarity bohdRarity = rarityReader.getSetRarity("5"); - SetRarity eofRarity = rarityReader.getSetRarity("6"); - - List fotrCommons = new ArrayList(); - fotrCommons.addAll(fotrRarity.getCardsOfRarity("C")); - fotrCommons.addAll(momRarity.getCardsOfRarity("C")); - fotrCommons.addAll(rotelRarity.getCardsOfRarity("C")); - _blockCommons.put(FOTR_BLOCK, fotrCommons); - - List fotrUncommons = new ArrayList(); - fotrUncommons.addAll(fotrRarity.getCardsOfRarity("U")); - fotrUncommons.addAll(momRarity.getCardsOfRarity("U")); - fotrUncommons.addAll(rotelRarity.getCardsOfRarity("U")); - _blockUncommons.put(FOTR_BLOCK, fotrUncommons); - - List tttCommons = new ArrayList(); - tttCommons.addAll(tttRarity.getCardsOfRarity("C")); - tttCommons.addAll(bohdRarity.getCardsOfRarity("C")); - tttCommons.addAll(eofRarity.getCardsOfRarity("C")); - _blockCommons.put(TTT_BLOCK, tttCommons); - - List tttUncommons = new ArrayList(); - tttUncommons.addAll(tttRarity.getCardsOfRarity("U")); - tttUncommons.addAll(bohdRarity.getCardsOfRarity("U")); - tttUncommons.addAll(eofRarity.getCardsOfRarity("U")); - _blockUncommons.put(TTT_BLOCK, tttUncommons); - } - - public CardCollection getPrizeForLeagueMatchWinner(int winCountThisSerie, int totalGamesPlayedThisSerie, String format) { - DefaultCardCollection winnerPrize = new DefaultCardCollection(); - if (winCountThisSerie == 1 || winCountThisSerie == 3 || winCountThisSerie == 5 || winCountThisSerie == 8 || winCountThisSerie == 10) - winnerPrize.addItem("(S)Booster Choice", 1); - else { - List blockCommons = _blockCommons.get(format); - List blockUncommons = _blockUncommons.get(format); - List blockPromos = _blockPromos.get(format); - if (winCountThisSerie == 2) - winnerPrize.addItem(getRandom(blockCommons) + "*", 1); - else if (winCountThisSerie == 4) - winnerPrize.addItem(getRandom(blockPromos), 1); - else if (winCountThisSerie == 6) - winnerPrize.addItem(getRandom(blockPromos) + "*", 1); - else if (winCountThisSerie == 7) - winnerPrize.addItem(getRandom(blockUncommons) + "*", 1); - else if (winCountThisSerie == 9) { - winnerPrize.addItem(getRandom(blockPromos), 1); - winnerPrize.addItem(getRandom(blockCommons) + "*", 1); - } - } - return winnerPrize; - } - - public CardCollection getPrizeForLeagueMatchLoser(int winCountThisSerie, int totalGamesPlayedThisSerie, String format) { - return null; - } - - public CardCollection getPrizeForLeague(int position, int playersCount, String format) { - DefaultCardCollection leaguePrize = new DefaultCardCollection(); - int count = (int) Math.floor((2 * playersCount + 24) / (position + 9) - 2.4); - if (count > 0) - leaguePrize.addItem("(S)Booster Choice", count); - int tengwar = getTengwarCount(position); - if (tengwar > 0) { - if (format.equals(FOTR_BLOCK)) - leaguePrize.addItem("(S)FotR - Tengwar", tengwar); - else if (format.equals(TTT_BLOCK)) - leaguePrize.addItem("(S)TTT - Tengwar", tengwar); - } - if (position == 1) { - addPrizes(leaguePrize, getRandomFoil(_blockPromos.get(format), 3)); - } else if (position == 2) { - addPrizes(leaguePrize, getRandomFoil(_blockPromos.get(format), 2)); - addPrizes(leaguePrize, getRandom(_blockPromos.get(format), 1)); - } else if (position == 3) { - addPrizes(leaguePrize, getRandomFoil(_blockPromos.get(format), 1)); - addPrizes(leaguePrize, getRandom(_blockPromos.get(format), 2)); - } else if (position >= 4 && position <= 6) { - addPrizes(leaguePrize, getRandom(_blockPromos.get(format), 7 - position)); - } else if (position >= 9 && position <= 12) { - addPrizes(leaguePrize, getRandom(_blockPromos.get(format), 1)); - } - - return leaguePrize; - } - - private void addPrizes(DefaultCardCollection leaguePrize, List cards) { - for (String card : cards) - leaguePrize.addItem(card, 1); - } - - private int getTengwarCount(int position) { - if (position == 1) - return 4; - else if (position == 2) - return 3; - else if (position == 3) - return 2; - else if (position <= 8) - return 1; - return 0; - } - - private String getRandom(List list) { - return list.get(new Random().nextInt(list.size())); - } - - private List getRandom(List list, int count) { - List result = new LinkedList(list); - Collections.shuffle(result); - return result.subList(0, count); - } - - private List getRandomFoil(List list, int count) { - List result = new LinkedList(); - for (String element : list) - result.add(element + "*"); - Collections.shuffle(result); - return result.subList(0, count); - } -} diff --git a/gemp-lotr/gemp-lotr-server/src/main/resources/lotrFormats.json b/gemp-lotr/gemp-lotr-server/src/main/resources/lotrFormats.json index 9fbc0a0ce..6c617f3aa 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/resources/lotrFormats.json +++ b/gemp-lotr/gemp-lotr-server/src/main/resources/lotrFormats.json @@ -7,6 +7,24 @@ "restricted": ["1_248"], "set": [1,2,3] }, + { + "name": "Fellowship block - Part 1", + "code": "fotr1_block", + "sites": "FELLOWSHIP", + "cancelRingBearerSkirmish": true, + "restricted": ["1_248"], + "set": [1], + "hall": false + }, + { + "name": "Fellowship block - Part 2", + "code": "fotr2_block", + "sites": "FELLOWSHIP", + "cancelRingBearerSkirmish": true, + "restricted": ["1_248"], + "set": [1,2], + "hall": false + }, { "name": "Towers block", "code": "ttt_block", 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 new file mode 100644 index 000000000..8e14bde65 --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/ConstructedLeagueDataTest.java @@ -0,0 +1,26 @@ +package com.gempukku.lotro.league; + +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ConstructedLeagueDataTest { + @Test + public void testParameters() { + ConstructedLeagueData leagueData = new ConstructedLeagueData("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); + assertTrue(series.get(0).getEnd() == 20120318); + assertEquals("fotr1_block", series.get(0).getFormat()); + assertTrue(series.get(1).getStart() == 20120319); + assertTrue(series.get(1).getEnd() == 20120325); + assertEquals("fotr2_block", series.get(1).getFormat()); + assertTrue(series.get(2).getStart() == 20120326); + assertTrue(series.get(2).getEnd() == 20120401); + assertEquals("fotr_block", series.get(2).getFormat()); + } +} diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeaguePrizesTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeaguePrizesTest.java similarity index 79% rename from gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeaguePrizesTest.java rename to gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeaguePrizesTest.java index 5fba5319e..88782e999 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/SealedLeaguePrizesTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeaguePrizesTest.java @@ -5,10 +5,10 @@ import org.junit.Test; import java.util.Map; -public class SealedLeaguePrizesTest { +public class LeaguePrizesTest { @Test public void test() { - SealedLeaguePrizes leaguePrizes = new SealedLeaguePrizes(); + LeaguePrizes leaguePrizes = new LeaguePrizes(); CardCollection prize = leaguePrizes.getPrizeForLeagueMatchWinner(2, 2, "fotr_block"); for (Map.Entry stringIntegerEntry : prize.getAll().entrySet()) { System.out.println(stringIntegerEntry.getKey() + ": " + stringIntegerEntry.getValue());