diff --git a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/packs/RarityReader.java b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/packs/RarityReader.java index 17a1a7b03..fc73f2920 100644 --- a/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/packs/RarityReader.java +++ b/gemp-lotr/gemp-lotr-cards/src/main/java/com/gempukku/lotro/cards/packs/RarityReader.java @@ -22,12 +22,6 @@ public class RarityReader { if (line.endsWith("T")) { if (!line.substring(0, setNo.length()).equals(setNo)) throw new IllegalStateException("Seems the rarity is for some other set"); - String rarity = line.substring(setNo.length(), setNo.length() + 1); - List cards = cardsByRarity.get(rarity); - if (cards == null) { - cards = new LinkedList(); - cardsByRarity.put(rarity, cards); - } String blueprintId = setNo + "_" + line.substring(setNo.length() + 1); tengwar.add(blueprintId); } else { diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java index 690b2a2fa..03546fc12 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/db/LeagueDAO.java @@ -17,18 +17,19 @@ public class LeagueDAO { _dbAccess = dbAccess; } - public void addLeague(int cost, String name, String type, String clazz, String parameters, int endTime) throws SQLException, IOException { + public void addLeague(int cost, String name, String type, String clazz, String parameters, int start, int endTime) throws SQLException, IOException { Connection conn = _dbAccess.getDataSource().getConnection(); try { - PreparedStatement statement = conn.prepareStatement("insert into league (name, type, class, parameters, end, status, cost) values (?, ?, ?, ?, ?, ?, ?)"); + PreparedStatement statement = conn.prepareStatement("insert into league (name, type, class, parameters, start, end, status, cost) values (?, ?, ?, ?, ?, ?, ?, ?)"); try { statement.setString(1, name); statement.setString(2, type); statement.setString(3, clazz); statement.setString(4, parameters); - statement.setInt(5, endTime); - statement.setInt(6, 0); - statement.setInt(7, cost); + statement.setInt(5, start); + statement.setInt(6, endTime); + statement.setInt(7, 0); + statement.setInt(8, cost); statement.execute(); } finally { statement.close(); 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 index 9382c7ed3..749190d1a 100644 --- 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 @@ -14,7 +14,7 @@ public class ConstructedLeagueData implements LeagueData { private String _leaguePrizePool; private CollectionType _prizeCollectionType = new CollectionType("permanent", "My cards"); private float _prizeMultiplier; - private LeaguePrizes _leaguePrizes = new LeaguePrizes(); + private LeaguePrizes _leaguePrizes = new OldLeaguePrizes(); // 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, 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 26a6ad360..aa5639876 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,191 +1,11 @@ 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 interface LeaguePrizes { + public CardCollection getPrizeForLeagueMatchWinner(int winCountThisSerie, int totalGamesPlayedThisSerie, String format); -public class LeaguePrizes { - 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 CardCollection getPrizeForLeagueMatchLoser(int winCountThisSerie, int totalGamesPlayedThisSerie, String format); - 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)); - } - - if (leaguePrize.getAll().size() == 0) - return null; - 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); - } + public CardCollection getPrizeForLeague(int position, int playersCount, float multiplier, String format); } diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/NewLeaguePrizes.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/NewLeaguePrizes.java new file mode 100644 index 000000000..8e3c8d0c0 --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/NewLeaguePrizes.java @@ -0,0 +1,115 @@ +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 NewLeaguePrizes implements LeaguePrizes { + private List _commons = new ArrayList(); + private List _uncommons = new ArrayList(); + private List _promos = new ArrayList(); + + public NewLeaguePrizes() { + RarityReader rarityReader = new RarityReader(); + + for (int i = 0; i <= 19; i++) { + SetRarity setRarity = rarityReader.getSetRarity(String.valueOf(i)); + _commons.addAll(setRarity.getCardsOfRarity("C")); + _uncommons.addAll(setRarity.getCardsOfRarity("U")); + _promos.addAll(setRarity.getCardsOfRarity("P")); + } + } + + 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 { + if (winCountThisSerie == 2) + winnerPrize.addItem(getRandom(_commons) + "*", 1); + else if (winCountThisSerie == 4) + winnerPrize.addItem(getRandom(_promos), 1); + else if (winCountThisSerie == 6) + winnerPrize.addItem(getRandom(_promos) + "*", 1); + else if (winCountThisSerie == 7) + winnerPrize.addItem(getRandom(_uncommons) + "*", 1); + else if (winCountThisSerie == 9) { + winnerPrize.addItem(getRandom(_promos), 1); + winnerPrize.addItem(getRandom(_commons) + "*", 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) + leaguePrize.addItem("(S)Tengwar", tengwar); + + if (position == 1) { + addPrizes(leaguePrize, getRandomFoil(_promos, 3)); + } else if (position == 2) { + addPrizes(leaguePrize, getRandomFoil(_promos, 2)); + addPrizes(leaguePrize, getRandom(_promos, 1)); + } else if (position == 3) { + addPrizes(leaguePrize, getRandomFoil(_promos, 1)); + addPrizes(leaguePrize, getRandom(_promos, 2)); + } else if (position >= 4 && position <= 6) { + addPrizes(leaguePrize, getRandom(_promos, 7 - position)); + } else if (position >= 9 && position <= 12) { + addPrizes(leaguePrize, getRandom(_promos, 1)); + } + + if (leaguePrize.getAll().size() == 0) + return null; + 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/NewSealedLeagueData.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/NewSealedLeagueData.java new file mode 100644 index 000000000..c61b089f5 --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/NewSealedLeagueData.java @@ -0,0 +1,99 @@ +package com.gempukku.lotro.league; + +import com.gempukku.lotro.DateUtils; +import com.gempukku.lotro.collection.CollectionsManager; +import com.gempukku.lotro.db.vo.CollectionType; +import com.gempukku.lotro.game.CardCollection; +import com.gempukku.lotro.game.DefaultCardCollection; +import com.gempukku.lotro.game.MutableCardCollection; +import com.gempukku.lotro.game.Player; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +public class NewSealedLeagueData implements LeagueData { + private String _format; + private List _series; + private CollectionType _collectionType; + private CollectionType _prizeCollectionType = new CollectionType("permanent", "My cards"); + private NewLeaguePrizes _leaguePrizes; + private SealedLeagueProduct _leagueProduct; + + public NewSealedLeagueData(String parameters) { + String[] params = parameters.split(","); + _format = params[0]; + int start = Integer.parseInt(params[1]); + int serieDuration = Integer.parseInt(params[2]); + int maxMatches = Integer.parseInt(params[3]); + + _collectionType = new CollectionType(params[4], params[5]); + + _leaguePrizes = new NewLeaguePrizes(); + _leagueProduct = new SealedLeagueProduct(); + + _series = new LinkedList(); + for (int i = 0; i < 4; i++) { + _series.add( + new DefaultLeagueSerieData(_leaguePrizes, true, "Week " + (i + 1), + DateUtils.offsetDate(start, i * serieDuration), DateUtils.offsetDate(start, (i + 1) * serieDuration - 1), maxMatches, + _format, _format, _collectionType)); + } + } + + @Override + public List getSeries() { + return Collections.unmodifiableList(_series); + } + + @Override + public CardCollection joinLeague(CollectionsManager collectionManager, Player player, int currentTime) { + MutableCardCollection startingCollection = new DefaultCardCollection(); + for (int i = 0; i < _series.size(); i++) { + LeagueSerieData serie = _series.get(i); + if (currentTime >= serie.getStart()) { + CardCollection leagueProduct = _leagueProduct.getCollectionForSerie(_format, i); + + for (Map.Entry serieCollectionItem : leagueProduct.getAll().entrySet()) + startingCollection.addItem(serieCollectionItem.getKey(), serieCollectionItem.getValue()); + } + } + collectionManager.addPlayerCollection(player, _collectionType, startingCollection); + return startingCollection; + } + + @Override + public int process(CollectionsManager collectionsManager, List leagueStandings, int oldStatus, int currentTime) { + int status = oldStatus; + + for (int i = status; i < _series.size(); i++) { + LeagueSerieData serie = _series.get(i); + if (currentTime >= serie.getStart()) { + CardCollection leagueProduct = _leagueProduct.getCollectionForSerie(_format, i); + Map map = collectionsManager.getPlayersCollection(_collectionType.getCode()); + for (Map.Entry playerCardCollectionEntry : map.entrySet()) { + collectionsManager.addItemsToPlayerCollection(playerCardCollectionEntry.getKey(), _collectionType, leagueProduct.getAll()); + } + status = i + 1; + } + } + + if (status == _series.size()) { + LeagueSerieData lastSerie = _series.get(_series.size() - 1); + if (currentTime > DateUtils.offsetDate(lastSerie.getEnd(), 1)) { + for (LeagueStanding leagueStanding : leagueStandings) { + CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), 1f, _format); + if (leaguePrize != null) + collectionsManager.addItemsToPlayerCollection(leagueStanding.getPlayerName(), _prizeCollectionType, leaguePrize.getAll()); + } +// for (LeagueStanding leagueStanding : leagueStandings) { +// collectionsManager.moveCollectionToCollection(leagueStanding.getPlayerName(), _collectionType, _prizeCollectionType); +// } + status++; + } + } + + return status; + } +} \ No newline at end of file diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/OldLeaguePrizes.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/OldLeaguePrizes.java new file mode 100644 index 000000000..0e9b80d86 --- /dev/null +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/league/OldLeaguePrizes.java @@ -0,0 +1,191 @@ +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 OldLeaguePrizes implements LeaguePrizes { + 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 OldLeaguePrizes() { + 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)); + } + + if (leaguePrize.getAll().size() == 0) + return null; + 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); + } +} \ No newline at end of file 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 2db46f4a6..e83334291 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 @@ -30,7 +30,7 @@ public class SealedLeagueData implements LeagueData { int serieDuration = 7; int maxMatches = 10; - _leaguePrizes = new LeaguePrizes(); + _leaguePrizes = new OldLeaguePrizes(); _leagueProduct = new SealedLeagueProduct(); _series = new LinkedList(); diff --git a/gemp-lotr/gemp-lotr-server/src/main/resources/packs.txt b/gemp-lotr/gemp-lotr-server/src/main/resources/packs.txt index 9194bede9..5ccfa6748 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/resources/packs.txt +++ b/gemp-lotr/gemp-lotr-server/src/main/resources/packs.txt @@ -39,4 +39,5 @@ BL - Booster HU - Booster RoS - Booster TaD - Booster -REF - Booster \ No newline at end of file +REF - Booster +(S)Tengwar \ No newline at end of file diff --git a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeaguePrizesTest.java b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeaguePrizesTest.java index 4af028e69..47e79794e 100644 --- a/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeaguePrizesTest.java +++ b/gemp-lotr/gemp-lotr-server/src/test/java/com/gempukku/lotro/league/LeaguePrizesTest.java @@ -8,7 +8,7 @@ import java.util.Map; public class LeaguePrizesTest { @Test public void test() { - LeaguePrizes leaguePrizes = new LeaguePrizes(); + LeaguePrizes leaguePrizes = new NewLeaguePrizes(); CardCollection prize = leaguePrizes.getPrizeForLeagueMatchWinner(2, 2, "fotr_block"); for (Map.Entry stringIntegerEntry : prize.getAll().entrySet()) { System.out.println(stringIntegerEntry.getKey() + ": " + stringIntegerEntry.getValue()); @@ -17,7 +17,7 @@ public class LeaguePrizesTest { @Test public void testLeaguePrize() { - LeaguePrizes leaguePrizes = new LeaguePrizes(); + LeaguePrizes leaguePrizes = new NewLeaguePrizes(); CardCollection prize = leaguePrizes.getPrizeForLeague(1, 100, 2f, "fotr_block"); for (Map.Entry stringIntegerEntry : prize.getAll().entrySet()) { System.out.println(stringIntegerEntry.getKey() + ": " + stringIntegerEntry.getValue()); diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/AbstractResource.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/AbstractResource.java index 0ad301c6a..473bf8b29 100644 --- a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/AbstractResource.java +++ b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/AbstractResource.java @@ -70,7 +70,7 @@ public abstract class AbstractResource { if (resourceOwner == null) throw new WebApplicationException(Response.Status.UNAUTHORIZED); - if (resourceOwner.getType().equals("a") && participantId != null && !participantId.equals("null")) { + if (resourceOwner.getType().contains("a") && participantId != null && !participantId.equals("null")) { resourceOwner = _playerDao.getPlayer(participantId); if (resourceOwner == null) throw new WebApplicationException(Response.Status.UNAUTHORIZED); diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/AdminResource.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/AdminResource.java index 8c29ad332..c763d257a 100644 --- a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/AdminResource.java +++ b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/AdminResource.java @@ -1,5 +1,6 @@ package com.gempukku.lotro.server; +import com.gempukku.lotro.DateUtils; import com.gempukku.lotro.collection.CollectionsManager; import com.gempukku.lotro.db.DeckDAO; import com.gempukku.lotro.db.LeagueDAO; @@ -10,7 +11,9 @@ import com.gempukku.lotro.game.LotroCardBlueprintLibrary; import com.gempukku.lotro.game.LotroServer; import com.gempukku.lotro.game.Player; import com.gempukku.lotro.hall.HallServer; +import com.gempukku.lotro.league.LeagueSerieData; import com.gempukku.lotro.league.LeagueService; +import com.gempukku.lotro.league.NewSealedLeagueData; import com.sun.jersey.spi.resource.Singleton; import javax.servlet.http.HttpServletRequest; @@ -80,19 +83,28 @@ public class AdminResource extends AbstractResource { return "OK"; } - @Path("/addLeague") + @Path("/addSealedLeague") @POST - public String addLeague( + public String addSealedLeague( @FormParam("cost") int cost, + @FormParam("format") String format, @FormParam("name") String name, - @FormParam("type") String type, - @FormParam("class") String clazz, - @FormParam("parameters") String parameters, - @FormParam("end") int end, + @FormParam("start") String start, + @FormParam("serieDuration") int serieDuration, + @FormParam("maxMatches") int maxMatches, @Context HttpServletRequest request) throws Exception { - validateAdmin(request); + validateLeagueAdmin(request); - _leagueDao.addLeague(cost, name, type, clazz, parameters, end); + String code = String.valueOf(System.currentTimeMillis()); + + String parameters = format + "," + start + "," + serieDuration + "," + maxMatches + "," + code + "," + name; + NewSealedLeagueData leagueData = new NewSealedLeagueData(parameters); + List series = leagueData.getSeries(); + int displayEnd = DateUtils.offsetDate(series.get(series.size() - 1).getEnd(), 2); + + _leagueDao.addLeague(cost, name, String.valueOf(System.currentTimeMillis()), NewSealedLeagueData.class.getName(), parameters, DateUtils.getCurrentDate(), displayEnd); + + _leagueService.clearCache(); return "OK"; } @@ -150,7 +162,14 @@ public class AdminResource extends AbstractResource { private void validateAdmin(HttpServletRequest request) { Player player = getResourceOwnerSafely(request, null); - if (!player.getType().equals("a")) + if (!player.getType().contains("a")) + sendError(Response.Status.FORBIDDEN); + } + + private void validateLeagueAdmin(HttpServletRequest request) { + Player player = getResourceOwnerSafely(request, null); + + if (!player.getType().contains("l")) sendError(Response.Status.FORBIDDEN); } diff --git a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/PacksStorageProvider.java b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/PacksStorageProvider.java index be9f15924..4dbb195fd 100644 --- a/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/PacksStorageProvider.java +++ b/gemp-lotr/gemp-lotr-web-server/src/main/java/com/gempukku/lotro/server/provider/PacksStorageProvider.java @@ -48,6 +48,7 @@ public class PacksStorageProvider implements Injectable, Injectabl packStorage.addPackBox("(S)TTT - Tengwar", new TengwarPackBox(new int[]{4, 5, 6})); packStorage.addPackBox("(S)RotK - Tengwar", new TengwarPackBox(new int[]{7, 8, 10})); packStorage.addPackBox("(S)SH - Tengwar", new TengwarPackBox(new int[]{11, 12, 13})); + packStorage.addPackBox("(S)Tengwar", new TengwarPackBox(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19})); packStorage.addPackBox("(S)Booster Choice", new FixedPackBox("(S)Booster Choice")); diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/admin.html b/gemp-lotr/gemp-lotr-web/src/main/webapp/admin.html index a4a5679f5..27d48d658 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/admin.html +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/admin.html @@ -10,24 +10,6 @@ -

League

- -

Add league

- -
- Name:
- Code:
- Type: -
- Parameters:
- Cost:
- End:
- -
-

Collections

Add items

diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/images/boosters/tengwar_selection.png b/gemp-lotr/gemp-lotr-web/src/main/webapp/images/boosters/tengwar_selection.png new file mode 100644 index 000000000..f93461f11 Binary files /dev/null and b/gemp-lotr/gemp-lotr-web/src/main/webapp/images/boosters/tengwar_selection.png differ diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-003/jCards.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-003/jCards.js index f58476c5f..76bd39123 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-003/jCards.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gemp-003/jCards.js @@ -22,6 +22,7 @@ var packBlueprints = { "(S)TTT - Tengwar": "/gemp-lotr/images/boosters/ttt_tengwar_selection.png", "(S)RotK - Tengwar": "/gemp-lotr/images/boosters/rotk_tengwar_selection.png", "(S)SH - Tengwar": "/gemp-lotr/images/boosters/sh_tengwar_selection.png", + "(S)Tengwar": "/gemp-lotr/images/boosters/tengwar_selection.png", "(S)Booster Choice": "/gemp-lotr/images/boosters/booster_selection.png", diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/leagueAdmin.html b/gemp-lotr/gemp-lotr-web/src/main/webapp/leagueAdmin.html new file mode 100644 index 000000000..f37aa2ac6 --- /dev/null +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/leagueAdmin.html @@ -0,0 +1,22 @@ + + +

League

+ +

Add sealed league

+ +
+ Name:
+ Cost (in silver):
+ Format: +
+ Start (YYYYMMDD):
+ Serie duration in days:
+ Maximum matches in serie:
+ +
+ + + \ No newline at end of file