Fixed inefficiency of most of the packs opening code.
Added "trophy" collection that can be used in Casual games only.
This commit is contained in:
@@ -207,7 +207,7 @@ public class HallServer extends AbstractServer {
|
||||
if (format == null)
|
||||
throw new HallException("This format is not supported: " + type);
|
||||
|
||||
LotroDeck lotroDeck = validateUserAndDeck(format, player, deckName, collectionType);
|
||||
LotroDeck lotroDeck = validateUserAndDeck(format, player, deckName, collectionType, league != null);
|
||||
|
||||
String tableId = String.valueOf(_nextTableId++);
|
||||
AwaitingTable table = new AwaitingTable(format, collectionType, league, leagueSerie);
|
||||
@@ -251,7 +251,7 @@ public class HallServer extends AbstractServer {
|
||||
|
||||
LotroDeck lotroDeck = null;
|
||||
if (tournamentQueue.isRequiresDeck())
|
||||
lotroDeck = validateUserAndDeck(_formatLibrary.getFormat(tournamentQueue.getFormat()), player, deckName, tournamentQueue.getCollectionType());
|
||||
lotroDeck = validateUserAndDeck(_formatLibrary.getFormat(tournamentQueue.getFormat()), player, deckName, tournamentQueue.getCollectionType(), true);
|
||||
|
||||
tournamentQueue.joinPlayer(_collectionsManager, player, lotroDeck);
|
||||
|
||||
@@ -282,7 +282,7 @@ public class HallServer extends AbstractServer {
|
||||
if (awaitingTable.getLeague() != null && !_leagueService.isPlayerInLeague(awaitingTable.getLeague(), player))
|
||||
throw new HallException("You're not in that league");
|
||||
|
||||
LotroDeck lotroDeck = validateUserAndDeck(awaitingTable.getLotroFormat(), player, deckName, awaitingTable.getCollectionType());
|
||||
LotroDeck lotroDeck = validateUserAndDeck(awaitingTable.getLotroFormat(), player, deckName, awaitingTable.getCollectionType(), awaitingTable.getLeague() != null);
|
||||
|
||||
joinTableInternal(tableId, player.getName(), awaitingTable, lotroDeck);
|
||||
|
||||
@@ -377,7 +377,7 @@ public class HallServer extends AbstractServer {
|
||||
LotroFormat format = _formatLibrary.getFormat(tournament.getFormat());
|
||||
|
||||
try {
|
||||
validateUserAndDeck(format, player, tournament.getCollectionType(), lotroDeck);
|
||||
validateUserAndDeck(format, player, tournament.getCollectionType(), lotroDeck, true);
|
||||
|
||||
tournament.playerSummittedDeck(player.getName(), lotroDeck);
|
||||
} catch (DeckInvalidException exp) {
|
||||
@@ -516,13 +516,13 @@ public class HallServer extends AbstractServer {
|
||||
}
|
||||
}
|
||||
|
||||
private LotroDeck validateUserAndDeck(LotroFormat format, Player player, String deckName, CollectionType collectionType) throws HallException {
|
||||
private LotroDeck validateUserAndDeck(LotroFormat format, Player player, String deckName, CollectionType collectionType, boolean competitive) throws HallException {
|
||||
LotroDeck lotroDeck = _lotroServer.getParticipantDeck(player, deckName);
|
||||
if (lotroDeck == null)
|
||||
throw new HallException("You don't have a deck registered yet");
|
||||
|
||||
try {
|
||||
lotroDeck = validateUserAndDeck(format, player, collectionType, lotroDeck);
|
||||
lotroDeck = validateUserAndDeck(format, player, collectionType, lotroDeck, competitive);
|
||||
} catch (DeckInvalidException e) {
|
||||
throw new HallException("Your selected deck is not valid for this format: " + e.getMessage());
|
||||
}
|
||||
@@ -530,12 +530,16 @@ public class HallServer extends AbstractServer {
|
||||
return lotroDeck;
|
||||
}
|
||||
|
||||
private LotroDeck validateUserAndDeck(LotroFormat format, Player player, CollectionType collectionType, LotroDeck lotroDeck) throws HallException, DeckInvalidException {
|
||||
private LotroDeck validateUserAndDeck(LotroFormat format, Player player, CollectionType collectionType, LotroDeck lotroDeck, boolean competitive) throws HallException, DeckInvalidException {
|
||||
format.validateDeck(lotroDeck);
|
||||
|
||||
// Now check if player owns all the cards
|
||||
if (collectionType.getCode().equals("default")) {
|
||||
CardCollection ownedCollection = _collectionsManager.getPlayerCollection(player, "permanent+trophy");
|
||||
CardCollection ownedCollection;
|
||||
if (competitive)
|
||||
ownedCollection = _collectionsManager.getPlayerCollection(player, "permanent");
|
||||
else
|
||||
ownedCollection = _collectionsManager.getPlayerCollection(player, "permanent+trophy");
|
||||
|
||||
LotroDeck filteredSpecialCardsDeck = new LotroDeck(lotroDeck.getDeckName());
|
||||
filteredSpecialCardsDeck.setRing(filterCard(lotroDeck.getRing(), ownedCollection));
|
||||
|
||||
@@ -8,9 +8,27 @@ import java.util.*;
|
||||
public class RarityPackBox implements PackBox {
|
||||
private Random _random = new Random();
|
||||
private SetDefinition _setRarity;
|
||||
private List<String> _possibleRareCards = new ArrayList<String>();
|
||||
private List<String> _possibleFoilRareSlot = new ArrayList<String>();
|
||||
private List<String> _possibleFoilUncommonSlot = new ArrayList<String>();
|
||||
private List<String> _possibleFoilCommonSlot = new ArrayList<String>();
|
||||
|
||||
public RarityPackBox(SetDefinition setDefinition) {
|
||||
_setRarity = setDefinition;
|
||||
|
||||
_possibleRareCards.addAll(_setRarity.getCardsOfRarity("R"));
|
||||
_possibleRareCards.addAll(_setRarity.getCardsOfRarity("R"));
|
||||
_possibleRareCards.addAll(_setRarity.getCardsOfRarity("R"));
|
||||
_possibleRareCards.addAll(_setRarity.getCardsOfRarity("A"));
|
||||
|
||||
_possibleFoilRareSlot.addAll(_setRarity.getCardsOfRarity("R"));
|
||||
_possibleFoilRareSlot.addAll(_setRarity.getCardsOfRarity("P"));
|
||||
_possibleFoilRareSlot.addAll(_setRarity.getCardsOfRarity("A"));
|
||||
|
||||
_possibleFoilUncommonSlot.addAll(_setRarity.getCardsOfRarity("U"));
|
||||
_possibleFoilUncommonSlot.addAll(_setRarity.getCardsOfRarity("S"));
|
||||
|
||||
_possibleFoilCommonSlot.addAll(_setRarity.getCardsOfRarity("C"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -20,48 +38,44 @@ public class RarityPackBox implements PackBox {
|
||||
if (hasFoil) {
|
||||
int foilRarity = _random.nextInt(11);
|
||||
if (foilRarity == 0) {
|
||||
List<String> possibleCards = new ArrayList<String>();
|
||||
possibleCards.addAll(_setRarity.getCardsOfRarity("R"));
|
||||
possibleCards.addAll(_setRarity.getCardsOfRarity("P"));
|
||||
possibleCards.addAll(_setRarity.getCardsOfRarity("A"));
|
||||
Collections.shuffle(possibleCards, _random);
|
||||
addCards(result, possibleCards.subList(0, 1), true);
|
||||
addRandomCardsFromList(result, 1, _possibleFoilRareSlot, true);
|
||||
} else if (foilRarity < 4) {
|
||||
List<String> possibleCards = new ArrayList<String>();
|
||||
possibleCards.addAll(_setRarity.getCardsOfRarity("U"));
|
||||
possibleCards.addAll(_setRarity.getCardsOfRarity("S"));
|
||||
Collections.shuffle(possibleCards, _random);
|
||||
addCards(result, possibleCards.subList(0, 1), true);
|
||||
addRandomCardsFromList(result, 1, _possibleFoilUncommonSlot, true);
|
||||
} else {
|
||||
List<String> possibleCards = new ArrayList<String>(_setRarity.getCardsOfRarity("C"));
|
||||
Collections.shuffle(possibleCards, _random);
|
||||
addCards(result, possibleCards.subList(0, 1), true);
|
||||
addRandomCardsFromList(result, 1, _possibleFoilCommonSlot, true);
|
||||
}
|
||||
}
|
||||
addRandomRareCard(result, 1);
|
||||
|
||||
addCard(result, _possibleRareCards.get(_random.nextInt(_possibleRareCards.size())), false);
|
||||
|
||||
addRandomCardsOfRarity(result, 3, "U");
|
||||
addRandomCardsOfRarity(result, hasFoil ? 6 : 7, "C");
|
||||
return result;
|
||||
}
|
||||
|
||||
private void addRandomRareCard(List<CardCollection.Item> result, int count) {
|
||||
List<String> possibleCards = new ArrayList<String>();
|
||||
possibleCards.addAll(_setRarity.getCardsOfRarity("R"));
|
||||
possibleCards.addAll(_setRarity.getCardsOfRarity("R"));
|
||||
possibleCards.addAll(_setRarity.getCardsOfRarity("R"));
|
||||
possibleCards.addAll(_setRarity.getCardsOfRarity("A"));
|
||||
Collections.shuffle(possibleCards, _random);
|
||||
addCards(result, possibleCards.subList(0, count), false);
|
||||
private void addCard(List<CardCollection.Item> result, String card, boolean foil) {
|
||||
result.add(CardCollection.Item.createItem(card + (foil ? "*" : ""), 1));
|
||||
}
|
||||
|
||||
private void addRandomCardsOfRarity(List<CardCollection.Item> result, int count, String rarity) {
|
||||
List<String> possibleCards = new ArrayList<String>(_setRarity.getCardsOfRarity(rarity));
|
||||
Collections.shuffle(possibleCards, _random);
|
||||
addCards(result, possibleCards.subList(0, count), false);
|
||||
final List<String> cardsOfRarity = _setRarity.getCardsOfRarity(rarity);
|
||||
addRandomCardsFromList(result, count, cardsOfRarity, false);
|
||||
}
|
||||
|
||||
private void addCards(List<CardCollection.Item> result, Collection<String> cards, boolean foil) {
|
||||
for (String card : cards)
|
||||
result.add(CardCollection.Item.createItem(card + (foil ? "*" : ""), 1));
|
||||
private void addRandomCardsFromList(List<CardCollection.Item> result, int count, List<String> cardList, boolean foil) {
|
||||
for (Integer cardIndex : getRandomIndices(count, cardList.size()))
|
||||
addCard(result, cardList.get(cardIndex), foil);
|
||||
}
|
||||
|
||||
private Set<Integer> getRandomIndices(int count, int elementCount) {
|
||||
Set<Integer> addedIndices = new HashSet<Integer>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
int index;
|
||||
do {
|
||||
index = _random.nextInt(elementCount);
|
||||
} while (addedIndices.contains(index));
|
||||
addedIndices.add(index);
|
||||
}
|
||||
return addedIndices;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,16 @@ import com.gempukku.lotro.cards.CardSets;
|
||||
import com.gempukku.lotro.cards.packs.SetDefinition;
|
||||
import com.gempukku.lotro.game.CardCollection;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class ReflectionsPackBox implements PackBox {
|
||||
private Random _random = new Random();
|
||||
private SetDefinition _reflectionsRarity;
|
||||
private List<String> _previousSetCards = new ArrayList<String>();
|
||||
private List<String> _reflectionSlotCards = new ArrayList<String>();
|
||||
|
||||
public ReflectionsPackBox(CardSets cardSets) {
|
||||
_reflectionsRarity = cardSets.getSetDefinitions().get("9");
|
||||
@@ -23,6 +27,12 @@ public class ReflectionsPackBox implements PackBox {
|
||||
for (int i = 0; i < 7; i++)
|
||||
_previousSetCards.addAll(setRarity.getCardsOfRarity("C"));
|
||||
}
|
||||
|
||||
_reflectionSlotCards.addAll(_reflectionsRarity.getCardsOfRarity("R"));
|
||||
_reflectionSlotCards.addAll(_reflectionsRarity.getCardsOfRarity("R"));
|
||||
_reflectionSlotCards.addAll(_reflectionsRarity.getCardsOfRarity("R"));
|
||||
_reflectionSlotCards.addAll(_reflectionsRarity.getCardsOfRarity("R"));
|
||||
_reflectionSlotCards.addAll(_reflectionsRarity.getCardsOfRarity("X"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,13 +57,6 @@ public class ReflectionsPackBox implements PackBox {
|
||||
}
|
||||
|
||||
public String getRandomReflectionsCard() {
|
||||
List<String> possibleCards = new ArrayList<String>();
|
||||
possibleCards.addAll(_reflectionsRarity.getCardsOfRarity("R"));
|
||||
possibleCards.addAll(_reflectionsRarity.getCardsOfRarity("R"));
|
||||
possibleCards.addAll(_reflectionsRarity.getCardsOfRarity("R"));
|
||||
possibleCards.addAll(_reflectionsRarity.getCardsOfRarity("R"));
|
||||
possibleCards.addAll(_reflectionsRarity.getCardsOfRarity("X"));
|
||||
Collections.shuffle(possibleCards, _random);
|
||||
return possibleCards.get(0);
|
||||
return _reflectionSlotCards.get(_random.nextInt(_reflectionSlotCards.size()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.gempukku.lotro.packs;
|
||||
|
||||
import com.gempukku.lotro.cards.CardSets;
|
||||
import com.gempukku.lotro.game.CardCollection;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RarityPackBoxTest {
|
||||
@Test
|
||||
public void openingPacks() {
|
||||
RarityPackBox fellowshipBox = new RarityPackBox(new CardSets().getSetDefinitions().get("1"));
|
||||
for (int i=0; i<10; i++) {
|
||||
System.out.println("Pack: "+(i+1));
|
||||
final List<CardCollection.Item> items = fellowshipBox.openPack();
|
||||
for (CardCollection.Item item : items) {
|
||||
System.out.println(item.getBlueprintId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user