League prizes after end of league.
This commit is contained in:
@@ -109,6 +109,10 @@ public class CollectionsManager {
|
||||
addItemsToPlayerCollection(_playerDAO.getPlayer(player), collectionType, items);
|
||||
}
|
||||
|
||||
public void moveCollectionToCollection(String player, CollectionType collectionFrom, CollectionType collectionTo) {
|
||||
moveCollectionToCollection(_playerDAO.getPlayer(player), collectionFrom, collectionTo);
|
||||
}
|
||||
|
||||
public void moveCollectionToCollection(Player player, CollectionType collectionFrom, CollectionType collectionTo) {
|
||||
_readWriteLock.writeLock().lock();
|
||||
try {
|
||||
|
||||
@@ -11,5 +11,5 @@ public interface LeagueData {
|
||||
|
||||
public CardCollection joinLeague(CollectionsManager collecionsManager, Player player, int currentTime);
|
||||
|
||||
public int process(CollectionsManager collectionsManager, int oldStatus, int currentTime);
|
||||
public int process(CollectionsManager collectionsManager, List<LeagueStanding> leagueStandings, int oldStatus, int currentTime);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.gempukku.lotro.league;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class LeagueService {
|
||||
private void processLoadedLeagues(int currentDate) {
|
||||
for (League activeLeague : _activeLeagues) {
|
||||
int oldStatus = activeLeague.getStatus();
|
||||
int newStatus = activeLeague.getLeagueData().process(_collectionsManager, oldStatus, currentDate);
|
||||
int newStatus = activeLeague.getLeagueData().process(_collectionsManager, getLeagueStandings(activeLeague), oldStatus, currentDate);
|
||||
if (newStatus != oldStatus)
|
||||
_leagueDao.setStatus(activeLeague, newStatus);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public class SealedLeagueData implements LeagueData {
|
||||
private String _format;
|
||||
private List<LeagueSerieData> _series;
|
||||
private CollectionType _collectionType;
|
||||
private CollectionType _prizeCollectionType = new CollectionType("permanent", "My cards");
|
||||
private SealedLeaguePrizes _leaguePrizes;
|
||||
private SealedLeagueProduct _leagueProduct;
|
||||
|
||||
@@ -71,7 +72,7 @@ public class SealedLeagueData implements LeagueData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int process(CollectionsManager collectionsManager, int oldStatus, int currentTime) {
|
||||
public int process(CollectionsManager collectionsManager, List<LeagueStanding> leagueStandings, int oldStatus, int currentTime) {
|
||||
int status = oldStatus;
|
||||
|
||||
for (int i = status; i < _series.size(); i++) {
|
||||
@@ -89,8 +90,15 @@ public class SealedLeagueData implements LeagueData {
|
||||
if (status == _series.size()) {
|
||||
LeagueSerieData lastSerie = _series.get(_series.size() - 1);
|
||||
if (currentTime >= getDate(lastSerie.getEnd(), 1)) {
|
||||
// Award prizes and move collections
|
||||
for (LeagueStanding leagueStanding : leagueStandings) {
|
||||
CardCollection leaguePrize = _leaguePrizes.getPrizeForLeague(leagueStanding.getStanding(), leagueStandings.size(), _format);
|
||||
collectionsManager.addItemsToPlayerCollection(leagueStanding.getPlayerName(), _prizeCollectionType, leaguePrize.getAll());
|
||||
}
|
||||
for (LeagueStanding leagueStanding : leagueStandings) {
|
||||
collectionsManager.moveCollectionToCollection(leagueStanding.getPlayerName(), _collectionType, _prizeCollectionType);
|
||||
}
|
||||
}
|
||||
status++;
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -11,6 +11,8 @@ public class SealedLeaguePrizes {
|
||||
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 SealedLeaguePrizes() {
|
||||
List<String> fotrPromos = new ArrayList<String>();
|
||||
@@ -35,7 +37,7 @@ public class SealedLeaguePrizes {
|
||||
fotrPromos.add("0_41");
|
||||
fotrPromos.add("0_42");
|
||||
fotrPromos.add("0_43");
|
||||
_blockPromos.put("fotr_block", fotrPromos);
|
||||
_blockPromos.put(FOTR_BLOCK, fotrPromos);
|
||||
|
||||
List<String> tttPromos = new ArrayList<String>();
|
||||
tttPromos.add("0_16");
|
||||
@@ -55,7 +57,7 @@ public class SealedLeaguePrizes {
|
||||
tttPromos.add("0_45");
|
||||
tttPromos.add("0_46");
|
||||
tttPromos.add("0_47");
|
||||
_blockPromos.put("ttt_block", tttPromos);
|
||||
_blockPromos.put(TTT_BLOCK, tttPromos);
|
||||
|
||||
RarityReader rarityReader = new RarityReader();
|
||||
SetRarity fotrRarity = rarityReader.getSetRarity("1");
|
||||
@@ -70,25 +72,25 @@ public class SealedLeaguePrizes {
|
||||
fotrCommons.addAll(fotrRarity.getCardsOfRarity("C"));
|
||||
fotrCommons.addAll(momRarity.getCardsOfRarity("C"));
|
||||
fotrCommons.addAll(rotelRarity.getCardsOfRarity("C"));
|
||||
_blockCommons.put("fotr_block", fotrCommons);
|
||||
_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);
|
||||
_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);
|
||||
_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);
|
||||
_blockUncommons.put(TTT_BLOCK, tttUncommons);
|
||||
}
|
||||
|
||||
public CardCollection getPrizeForLeagueMatchWinner(int winCountThisSerie, int totalGamesPlayedThisSerie, String format) {
|
||||
@@ -119,7 +121,67 @@ public class SealedLeaguePrizes {
|
||||
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<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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class SealedLeagueDataTest {
|
||||
for (int i = 20120101; i < 20120108; i++) {
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(new HashMap<Player, CardCollection>());
|
||||
int result = data.process(collectionsManager, 0, i);
|
||||
int result = data.process(collectionsManager, null, 0, i);
|
||||
assertEquals(1, result);
|
||||
Mockito.verify(collectionsManager, new Times(1)).getPlayersCollection("test");
|
||||
Mockito.verifyNoMoreInteractions(collectionsManager);
|
||||
@@ -111,7 +111,7 @@ public class SealedLeagueDataTest {
|
||||
for (int i = 20120101; i < 20120108; i++) {
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(new HashMap<Player, CardCollection>());
|
||||
int result = data.process(collectionsManager, 1, i);
|
||||
int result = data.process(collectionsManager, null, 1, i);
|
||||
assertEquals(1, result);
|
||||
Mockito.verifyNoMoreInteractions(collectionsManager);
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class SealedLeagueDataTest {
|
||||
Player player = new Player(1, "Test", "A");
|
||||
playersInLeague.put(player, new DefaultCardCollection());
|
||||
Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(playersInLeague);
|
||||
int result = data.process(collectionsManager, 1, i);
|
||||
int result = data.process(collectionsManager, null, 1, i);
|
||||
assertEquals(2, result);
|
||||
Map<String, Integer> expectedToAdd = new HashMap<String, Integer>();
|
||||
expectedToAdd.put("(S)MoM - Starter", 1);
|
||||
@@ -145,7 +145,7 @@ public class SealedLeagueDataTest {
|
||||
for (int i = 20120108; i < 20120115; i++) {
|
||||
CollectionsManager collectionsManager = Mockito.mock(CollectionsManager.class);
|
||||
Mockito.when(collectionsManager.getPlayersCollection("test")).thenReturn(new HashMap<Player, CardCollection>());
|
||||
int result = data.process(collectionsManager, 2, i);
|
||||
int result = data.process(collectionsManager, null, 2, i);
|
||||
assertEquals(2, result);
|
||||
Mockito.verifyNoMoreInteractions(collectionsManager);
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public class CollectionResource extends AbstractResource {
|
||||
|
||||
for (League league : _leagueService.getActiveLeagues()) {
|
||||
LeagueSerieData serie = _leagueService.getCurrentLeagueSerie(league);
|
||||
if (serie.isLimited()) {
|
||||
if (serie != null && serie.isLimited()) {
|
||||
CollectionType collectionType = serie.getCollectionType();
|
||||
Element collectionElem = doc.createElement("collection");
|
||||
collectionElem.setAttribute("type", collectionType.getCode());
|
||||
|
||||
Reference in New Issue
Block a user