Rarity filtering.
This commit is contained in:
@@ -7,10 +7,12 @@ import java.util.Map;
|
||||
public class DefaultSetRarity implements SetRarity {
|
||||
private List<String> _tengwarCards;
|
||||
private Map<String, List<String>> _rarityList;
|
||||
private Map<String, String> _cardsRarity;
|
||||
|
||||
public DefaultSetRarity(List<String> tengwarCards, Map<String, List<String>> rarityList) {
|
||||
public DefaultSetRarity(List<String> tengwarCards, Map<String, List<String>> rarityList, Map<String, String> cardsRarity) {
|
||||
_tengwarCards = tengwarCards;
|
||||
_rarityList = rarityList;
|
||||
_cardsRarity = cardsRarity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -27,4 +29,9 @@ public class DefaultSetRarity implements SetRarity {
|
||||
return Collections.emptyList();
|
||||
return Collections.unmodifiableList(_tengwarCards);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCardRarity(String cardId) {
|
||||
return _cardsRarity.get(cardId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public class RarityReader {
|
||||
String line;
|
||||
List<String> tengwar = new LinkedList<String>();
|
||||
Map<String, List<String>> cardsByRarity = new HashMap<String, List<String>>();
|
||||
Map<String, String> cardRarity = new HashMap<String, String>();
|
||||
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
if (line.endsWith("T"))
|
||||
@@ -30,10 +31,11 @@ public class RarityReader {
|
||||
cardsByRarity.put(rarity, cards);
|
||||
}
|
||||
cards.add(line);
|
||||
cardRarity.put(setNo + "_" + line.substring(setNo.length() + 1), rarity);
|
||||
}
|
||||
}
|
||||
|
||||
return new DefaultSetRarity(tengwar, cardsByRarity);
|
||||
return new DefaultSetRarity(tengwar, cardsByRarity, cardRarity);
|
||||
} finally {
|
||||
bufferedReader.close();
|
||||
}
|
||||
|
||||
@@ -4,5 +4,8 @@ import java.util.List;
|
||||
|
||||
public interface SetRarity {
|
||||
public List<String> getCardsOfRarity(String rarity);
|
||||
|
||||
public List<String> getTengwarCards();
|
||||
|
||||
public String getCardRarity(String cardId);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class LotroCardBlueprintLibrary {
|
||||
return blueprint;
|
||||
}
|
||||
|
||||
private String stripBlueprintModifiers(String blueprintId) {
|
||||
public String stripBlueprintModifiers(String blueprintId) {
|
||||
if (blueprintId.endsWith("*"))
|
||||
blueprintId = blueprintId.substring(0, blueprintId.length() - 1);
|
||||
if (blueprintId.endsWith("T"))
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.gempukku.lotro.game;
|
||||
|
||||
import com.gempukku.lotro.cards.packs.SetRarity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -8,7 +10,7 @@ public interface CardCollection extends OwnershipCheck {
|
||||
|
||||
public int getItemCount(String blueprintId);
|
||||
|
||||
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library);
|
||||
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library, Map<String, SetRarity> rarities);
|
||||
|
||||
public static class Item {
|
||||
public enum Type {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.gempukku.lotro.game;
|
||||
|
||||
import com.gempukku.lotro.cards.packs.SetRarity;
|
||||
import com.gempukku.lotro.common.CardType;
|
||||
import com.gempukku.lotro.common.Culture;
|
||||
import com.gempukku.lotro.common.Keyword;
|
||||
@@ -272,12 +273,13 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library) {
|
||||
public List<Item> getItems(String filter, LotroCardBlueprintLibrary library, Map<String, SetRarity> rarities) {
|
||||
if (filter == null)
|
||||
filter = "";
|
||||
String[] filterParams = filter.split(" ");
|
||||
|
||||
String type = getTypeFilter(filterParams);
|
||||
String rarity = getRarityFilter(filterParams);
|
||||
String[] sets = getSetFilter(filterParams);
|
||||
List<String> words = getWords(filterParams);
|
||||
Set<CardType> cardTypes = getEnumFilter(CardType.values(), CardType.class, "cardType", null, filterParams);
|
||||
@@ -291,7 +293,7 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
String blueprintId = itemCount.getKey();
|
||||
int count = itemCount.getValue();
|
||||
|
||||
if (acceptsFilters(library, blueprintId, type, sets, cardTypes, cultures, keywords, words, siteNumber)) {
|
||||
if (acceptsFilters(library, rarities, blueprintId, type, rarity, sets, cardTypes, cultures, keywords, words, siteNumber)) {
|
||||
if (!blueprintId.contains("_"))
|
||||
result.add(new Item(Item.Type.PACK, count, blueprintId));
|
||||
else
|
||||
@@ -315,7 +317,7 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
}
|
||||
|
||||
private boolean acceptsFilters(
|
||||
LotroCardBlueprintLibrary library, String blueprintId, String type, String[] sets,
|
||||
LotroCardBlueprintLibrary library, Map<String, SetRarity> rarities, String blueprintId, String type, String rarity, String[] sets,
|
||||
Set<CardType> cardTypes, Set<Culture> cultures, Set<Keyword> keywords, List<String> words, Integer siteNumber) {
|
||||
if (!blueprintId.contains("_")) {
|
||||
if (type == null || type.equals("pack"))
|
||||
@@ -326,13 +328,14 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
|| (type.equals("foil") && blueprintId.endsWith("*"))
|
||||
|| (type.equals("nonFoil") && !blueprintId.endsWith("*"))) {
|
||||
final LotroCardBlueprint blueprint = library.getLotroCardBlueprint(blueprintId);
|
||||
if (sets == null || isInSets(blueprintId, sets, library))
|
||||
if (cardTypes == null || cardTypes.contains(blueprint.getCardType()))
|
||||
if (cultures == null || cultures.contains(blueprint.getCulture()))
|
||||
if (containsAllKeywords(blueprint, keywords))
|
||||
if (containsAllWords(blueprint, words))
|
||||
if (siteNumber == null || blueprint.getSiteNumber() == siteNumber)
|
||||
return true;
|
||||
if (rarity == null || isRarity(blueprintId, rarity, library, rarities))
|
||||
if (sets == null || isInSets(blueprintId, sets, library))
|
||||
if (cardTypes == null || cardTypes.contains(blueprint.getCardType()))
|
||||
if (cultures == null || cultures.contains(blueprint.getCulture()))
|
||||
if (containsAllKeywords(blueprint, keywords))
|
||||
if (containsAllWords(blueprint, words))
|
||||
if (siteNumber == null || blueprint.getSiteNumber() == siteNumber)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -346,6 +349,14 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getRarityFilter(String[] filterParams) {
|
||||
for (String filterParam : filterParams) {
|
||||
if (filterParam.startsWith("rarity:"))
|
||||
return filterParam.substring("rarity:".length());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String[] getSetFilter(String[] filterParams) {
|
||||
String setStr = getSetNumber(filterParams);
|
||||
String[] sets = null;
|
||||
@@ -354,6 +365,18 @@ public class DefaultCardCollection implements MutableCardCollection {
|
||||
return sets;
|
||||
}
|
||||
|
||||
private boolean isRarity(String blueprintId, String rarity, LotroCardBlueprintLibrary library, Map<String, SetRarity> rarities) {
|
||||
if (blueprintId.contains("_")) {
|
||||
SetRarity setRarity = rarities.get(blueprintId.substring(0, blueprintId.indexOf("_")));
|
||||
if (setRarity == null && rarity.equals("unknown"))
|
||||
return true;
|
||||
if (setRarity != null && setRarity.getCardRarity(library.stripBlueprintModifiers(blueprintId)).equals(rarity))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isInSets(String blueprintId, String[] sets, LotroCardBlueprintLibrary library) {
|
||||
for (String set : sets)
|
||||
if (blueprintId.startsWith(set + "_") || library.hasAlternateInSet(blueprintId, Integer.parseInt(set)))
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.gempukku.lotro.server;
|
||||
|
||||
import com.gempukku.lotro.cards.packs.RarityReader;
|
||||
import com.gempukku.lotro.cards.packs.SetRarity;
|
||||
import com.gempukku.lotro.collection.CollectionsManager;
|
||||
import com.gempukku.lotro.common.Side;
|
||||
import com.gempukku.lotro.db.LeagueDAO;
|
||||
@@ -24,6 +26,7 @@ import javax.ws.rs.core.Response;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -45,6 +48,20 @@ public class CollectionResource extends AbstractResource {
|
||||
@Context
|
||||
private PacksStorage _packStorage;
|
||||
|
||||
private Map<String, SetRarity> _rarities;
|
||||
|
||||
public CollectionResource() {
|
||||
_rarities = new HashMap<String, SetRarity>();
|
||||
RarityReader reader = new RarityReader();
|
||||
_rarities.put("0", reader.getSetRarity("0"));
|
||||
_rarities.put("1", reader.getSetRarity("1"));
|
||||
_rarities.put("2", reader.getSetRarity("2"));
|
||||
_rarities.put("3", reader.getSetRarity("3"));
|
||||
_rarities.put("4", reader.getSetRarity("4"));
|
||||
_rarities.put("5", reader.getSetRarity("5"));
|
||||
_rarities.put("6", reader.getSetRarity("6"));
|
||||
}
|
||||
|
||||
@Path("/{collectionType}")
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
@@ -62,7 +79,7 @@ public class CollectionResource extends AbstractResource {
|
||||
if (collection == null)
|
||||
sendError(Response.Status.NOT_FOUND);
|
||||
|
||||
List<CardCollection.Item> filteredResult = collection.getItems(filter, _library);
|
||||
List<CardCollection.Item> filteredResult = collection.getItems(filter, _library, _rarities);
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
|
||||
@@ -21,6 +21,7 @@ var CardFilter = Class.extend({
|
||||
setSelect: null,
|
||||
nameInput: null,
|
||||
sortSelect: null,
|
||||
raritySelect: null,
|
||||
|
||||
init: function(url, elem, clearCollectionFunc, addCardFunc, finishCollectionFunc) {
|
||||
this.communication = new GempLotrCommunication(url,
|
||||
@@ -129,7 +130,7 @@ var CardFilter = Class.extend({
|
||||
+ "<option value='13'>13 - Bloodlines</option>"
|
||||
+ "<option value='14'>14 - Expanded Middle-earth</option>"
|
||||
+ "</select>");
|
||||
this.nameInput = $("<input type='text' value='Card name' style='width: 130px; font-size: 80%;'>");
|
||||
this.nameInput = $("<input type='text' value='Card name' style='width: 130px; font-size: 70%;'>");
|
||||
this.sortSelect = $("<select style='width: 80px; font-size: 80%;'>"
|
||||
+ "<option value=''>Sort by:</option>"
|
||||
+ "<option value='name'>Name</option>"
|
||||
@@ -138,10 +139,20 @@ var CardFilter = Class.extend({
|
||||
+ "<option value='strength'>Strength</option>"
|
||||
+ "<option value='vitality'>Vitality</option>"
|
||||
+ "</select>");
|
||||
this.raritySelect = $("<select style='width: 40px; font-size: 80%;'>"
|
||||
+ "<option value=''>Rarity:</option>"
|
||||
+ "<option value='R'>Rare</option>"
|
||||
+ "<option value='U'>Uncommon</option>"
|
||||
+ "<option value='C'>Common</option>"
|
||||
+ "<option value='A'>Alternate Image</option>"
|
||||
+ "<option value='P'>Promo</option>"
|
||||
+ "<option value='unknown'>Unknown</option>"
|
||||
+ "</select>");
|
||||
|
||||
this.fullFilterDiv.append(this.setSelect);
|
||||
this.fullFilterDiv.append(this.nameInput);
|
||||
this.fullFilterDiv.append(this.sortSelect);
|
||||
this.fullFilterDiv.append(this.raritySelect);
|
||||
|
||||
elem.append(this.fullFilterDiv);
|
||||
|
||||
@@ -237,6 +248,7 @@ var CardFilter = Class.extend({
|
||||
this.setSelect.change(fullFilterChanged);
|
||||
this.nameInput.change(fullFilterChanged);
|
||||
this.sortSelect.change(fullFilterChanged);
|
||||
this.raritySelect.change(fullFilterChanged);
|
||||
|
||||
var filterOut = function() {
|
||||
that.filter = that.calculateNormalFilter();
|
||||
@@ -317,7 +329,11 @@ var CardFilter = Class.extend({
|
||||
cardName += " name:" + cardNameElems[i];
|
||||
}
|
||||
|
||||
return setNo + sort + cardName;
|
||||
var rarity = $("option:selected", this.raritySelect).prop("value");
|
||||
if (rarity != "")
|
||||
rarity = " rarity:" + rarity;
|
||||
|
||||
return setNo + sort + cardName + rarity;
|
||||
},
|
||||
|
||||
getCollection: function() {
|
||||
|
||||
Reference in New Issue
Block a user