New leagues management and prizes.
This commit is contained in:
@@ -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<String> cards = cardsByRarity.get(rarity);
|
||||
if (cards == null) {
|
||||
cards = new LinkedList<String>();
|
||||
cardsByRarity.put(rarity, cards);
|
||||
}
|
||||
String blueprintId = setNo + "_" + line.substring(setNo.length() + 1);
|
||||
tengwar.add(blueprintId);
|
||||
} else {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<String, List<String>> _blockPromos = new HashMap<String, List<String>>();
|
||||
private Map<String, List<String>> _blockCommons = new HashMap<String, List<String>>();
|
||||
private Map<String, List<String>> _blockUncommons = new HashMap<String, List<String>>();
|
||||
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<String> fotrPromos = new ArrayList<String>();
|
||||
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<String> tttPromos = new ArrayList<String>();
|
||||
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<String> fotrCommons = new ArrayList<String>();
|
||||
fotrCommons.addAll(fotrRarity.getCardsOfRarity("C"));
|
||||
fotrCommons.addAll(momRarity.getCardsOfRarity("C"));
|
||||
fotrCommons.addAll(rotelRarity.getCardsOfRarity("C"));
|
||||
_blockCommons.put(FOTR_BLOCK, fotrCommons);
|
||||
|
||||
List<String> fotrUncommons = new ArrayList<String>();
|
||||
fotrUncommons.addAll(fotrRarity.getCardsOfRarity("U"));
|
||||
fotrUncommons.addAll(momRarity.getCardsOfRarity("U"));
|
||||
fotrUncommons.addAll(rotelRarity.getCardsOfRarity("U"));
|
||||
_blockUncommons.put(FOTR_BLOCK, fotrUncommons);
|
||||
|
||||
List<String> tttCommons = new ArrayList<String>();
|
||||
tttCommons.addAll(tttRarity.getCardsOfRarity("C"));
|
||||
tttCommons.addAll(bohdRarity.getCardsOfRarity("C"));
|
||||
tttCommons.addAll(eofRarity.getCardsOfRarity("C"));
|
||||
_blockCommons.put(TTT_BLOCK, tttCommons);
|
||||
|
||||
List<String> tttUncommons = new ArrayList<String>();
|
||||
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<String> blockCommons = _blockCommons.get(format);
|
||||
List<String> blockUncommons = _blockUncommons.get(format);
|
||||
List<String> 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<String> 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<String> list) {
|
||||
return list.get(new Random().nextInt(list.size()));
|
||||
}
|
||||
|
||||
private List<String> getRandom(List<String> list, int count) {
|
||||
List<String> result = new LinkedList<String>(list);
|
||||
Collections.shuffle(result);
|
||||
return result.subList(0, count);
|
||||
}
|
||||
|
||||
private List<String> getRandomFoil(List<String> list, int count) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<String> _commons = new ArrayList<String>();
|
||||
private List<String> _uncommons = new ArrayList<String>();
|
||||
private List<String> _promos = new ArrayList<String>();
|
||||
|
||||
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<String> 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<String> list) {
|
||||
return list.get(new Random().nextInt(list.size()));
|
||||
}
|
||||
|
||||
private List<String> getRandom(List<String> list, int count) {
|
||||
List<String> result = new LinkedList<String>(list);
|
||||
Collections.shuffle(result);
|
||||
return result.subList(0, count);
|
||||
}
|
||||
|
||||
private List<String> getRandomFoil(List<String> list, int count) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
for (String element : list)
|
||||
result.add(element + "*");
|
||||
Collections.shuffle(result);
|
||||
return result.subList(0, count);
|
||||
}
|
||||
}
|
||||
@@ -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<LeagueSerieData> _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<LeagueSerieData>();
|
||||
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<LeagueSerieData> 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<String, Integer> serieCollectionItem : leagueProduct.getAll().entrySet())
|
||||
startingCollection.addItem(serieCollectionItem.getKey(), serieCollectionItem.getValue());
|
||||
}
|
||||
}
|
||||
collectionManager.addPlayerCollection(player, _collectionType, startingCollection);
|
||||
return startingCollection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int process(CollectionsManager collectionsManager, List<LeagueStanding> 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<Player, CardCollection> map = collectionsManager.getPlayersCollection(_collectionType.getCode());
|
||||
for (Map.Entry<Player, CardCollection> 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;
|
||||
}
|
||||
}
|
||||
@@ -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<String, List<String>> _blockPromos = new HashMap<String, List<String>>();
|
||||
private Map<String, List<String>> _blockCommons = new HashMap<String, List<String>>();
|
||||
private Map<String, List<String>> _blockUncommons = new HashMap<String, List<String>>();
|
||||
private static final String FOTR_BLOCK = "fotr_block";
|
||||
private static final String TTT_BLOCK = "ttt_block";
|
||||
|
||||
public OldLeaguePrizes() {
|
||||
List<String> fotrPromos = new ArrayList<String>();
|
||||
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<String> tttPromos = new ArrayList<String>();
|
||||
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<String> fotrCommons = new ArrayList<String>();
|
||||
fotrCommons.addAll(fotrRarity.getCardsOfRarity("C"));
|
||||
fotrCommons.addAll(momRarity.getCardsOfRarity("C"));
|
||||
fotrCommons.addAll(rotelRarity.getCardsOfRarity("C"));
|
||||
_blockCommons.put(FOTR_BLOCK, fotrCommons);
|
||||
|
||||
List<String> fotrUncommons = new ArrayList<String>();
|
||||
fotrUncommons.addAll(fotrRarity.getCardsOfRarity("U"));
|
||||
fotrUncommons.addAll(momRarity.getCardsOfRarity("U"));
|
||||
fotrUncommons.addAll(rotelRarity.getCardsOfRarity("U"));
|
||||
_blockUncommons.put(FOTR_BLOCK, fotrUncommons);
|
||||
|
||||
List<String> tttCommons = new ArrayList<String>();
|
||||
tttCommons.addAll(tttRarity.getCardsOfRarity("C"));
|
||||
tttCommons.addAll(bohdRarity.getCardsOfRarity("C"));
|
||||
tttCommons.addAll(eofRarity.getCardsOfRarity("C"));
|
||||
_blockCommons.put(TTT_BLOCK, tttCommons);
|
||||
|
||||
List<String> tttUncommons = new ArrayList<String>();
|
||||
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<String> blockCommons = _blockCommons.get(format);
|
||||
List<String> blockUncommons = _blockUncommons.get(format);
|
||||
List<String> 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<String> 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<String> list) {
|
||||
return list.get(new Random().nextInt(list.size()));
|
||||
}
|
||||
|
||||
private List<String> getRandom(List<String> list, int count) {
|
||||
List<String> result = new LinkedList<String>(list);
|
||||
Collections.shuffle(result);
|
||||
return result.subList(0, count);
|
||||
}
|
||||
|
||||
private List<String> getRandomFoil(List<String> list, int count) {
|
||||
List<String> result = new LinkedList<String>();
|
||||
for (String element : list)
|
||||
result.add(element + "*");
|
||||
Collections.shuffle(result);
|
||||
return result.subList(0, count);
|
||||
}
|
||||
}
|
||||
@@ -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<LeagueSerieData>();
|
||||
|
||||
@@ -39,4 +39,5 @@ BL - Booster
|
||||
HU - Booster
|
||||
RoS - Booster
|
||||
TaD - Booster
|
||||
REF - Booster
|
||||
REF - Booster
|
||||
(S)Tengwar
|
||||
@@ -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<String, Integer> 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<String, Integer> stringIntegerEntry : prize.getAll().entrySet()) {
|
||||
System.out.println(stringIntegerEntry.getKey() + ": " + stringIntegerEntry.getValue());
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<LeagueSerieData> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ public class PacksStorageProvider implements Injectable<PacksStorage>, 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"));
|
||||
|
||||
|
||||
@@ -10,24 +10,6 @@
|
||||
<input type="submit" value="Set MotD">
|
||||
</form>
|
||||
|
||||
<h1>League</h1>
|
||||
|
||||
<h2>Add league</h2>
|
||||
|
||||
<form method="POST" action="/gemp-lotr-server/admin/addLeague">
|
||||
Name: <input type="text" name="name"><br/>
|
||||
Code: <input type="text" name="type"><br/>
|
||||
Type:
|
||||
<select name="class">
|
||||
<option value="com.gempukku.lotro.league.ConstructedLeagueData">Constructed</option>
|
||||
<option value="com.gempukku.lotro.league.SealedLeagueData">Sealed</option>
|
||||
</select><br/>
|
||||
Parameters: <input type="text" name="parameters"><br/>
|
||||
Cost: <input type="text" name="cost"><br/>
|
||||
End: <input type="text" name="end"><br/>
|
||||
<input type="submit" value="Add league">
|
||||
</form>
|
||||
|
||||
<h1>Collections</h1>
|
||||
|
||||
<h2>Add items</h2>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
@@ -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",
|
||||
|
||||
|
||||
22
gemp-lotr/gemp-lotr-web/src/main/webapp/leagueAdmin.html
Normal file
22
gemp-lotr/gemp-lotr-web/src/main/webapp/leagueAdmin.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<html>
|
||||
<body>
|
||||
<h1>League</h1>
|
||||
|
||||
<h2>Add sealed league</h2>
|
||||
|
||||
<form method="POST" action="/gemp-lotr-server/admin/addSealedLeague">
|
||||
Name: <input type="text" name="name"><br/>
|
||||
Cost (in silver): <input type="text" name="cost"><br/>
|
||||
Format:
|
||||
<select name="format">
|
||||
<option value="fotr_block">Fellowship block</option>
|
||||
<option value="ttt_block">Towers block</option>
|
||||
</select><br/>
|
||||
Start (YYYYMMDD): <input type="text" name="start"><br/>
|
||||
Serie duration in days: <input type="text" name="serieDuration"><br/>
|
||||
Maximum matches in serie: <input type="text" name="maxMatches"><br/>
|
||||
<input type="submit" value="Add sealed league">
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user