- Deck builder now allows to sort cards by name (default), twilight cost, strength and vitality.

- "Legolas, Elven Comrade" now gives the strength penalty correctly to the minion.
This commit is contained in:
marcins78@gmail.com
2011-11-03 20:16:57 +00:00
parent cf74b5a1a3
commit 1feca2f3f5
7 changed files with 142 additions and 22 deletions

View File

@@ -44,11 +44,11 @@ public class Card4_049 extends AbstractCompanion {
action.appendEffect(
new ChooseActiveCardEffect(self, playerId, "Choose unbound companion", Filters.unboundCompanion) {
@Override
protected void cardSelected(LotroGame game, PhysicalCard card) {
int bonus = (card.getBlueprint().getName().equals("Legolas")) ? 2 : 1;
protected void cardSelected(LotroGame game, PhysicalCard companion) {
int bonus = (companion.getBlueprint().getName().equals("Legolas")) ? 2 : 1;
action.insertEffect(
new AddUntilEndOfPhaseModifierEffect(
new StrengthModifier(self, Filters.sameCard(card), bonus), Phase.SKIRMISH));
new StrengthModifier(self, Filters.sameCard(companion), bonus), Phase.SKIRMISH));
}
});
return Collections.singletonList(action);

View File

@@ -50,10 +50,10 @@ public class Card4_074 extends AbstractCompanion {
action.insertEffect(
new ChooseActiveCardEffect(self, playerId, "Choose minion skirmishing companion", Filters.type(CardType.MINION), Filters.inSkirmishAgainst(Filters.sameCard(card))) {
@Override
protected void cardSelected(LotroGame game, PhysicalCard card) {
protected void cardSelected(LotroGame game, PhysicalCard minion) {
action.insertEffect(
new AddUntilEndOfPhaseModifierEffect(
new StrengthModifier(self, Filters.sameCard(self), bonus), Phase.SKIRMISH));
new StrengthModifier(self, Filters.sameCard(minion), bonus), Phase.SKIRMISH));
}
});
}

View File

@@ -10,6 +10,101 @@ public class DefaultCardCollection implements MutableCardCollection {
private Map<String, Integer> _counts = new TreeMap<String, Integer>(new CardBlueprintIdComparator());
private Map<String, LotroCardBlueprint> _cards = new TreeMap<String, LotroCardBlueprint>();
private LotroCardBlueprintLibrary _library;
private static final Comparator<Item> NAME_COMPARATOR = new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2) {
if (o1.getType() == o2.getType()) {
if (o1.getType() == Item.Type.PACK)
return o1.getBlueprintId().compareTo(o2.getBlueprintId());
else
return o1.getCardBlueprint().getName().compareTo(o2.getCardBlueprint().getName());
} else {
if (o1.getType() == Item.Type.PACK)
return -1;
else
return 1;
}
}
};
private static final Comparator<Item> TWILIGHT_COMPARATOR = new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2) {
if (o1.getType() == o2.getType()) {
if (o1.getType() == Item.Type.PACK)
return o1.getBlueprintId().compareTo(o2.getBlueprintId());
else {
int twilightResult = o1.getCardBlueprint().getTwilightCost() - o2.getCardBlueprint().getTwilightCost();
if (twilightResult == 0)
return NAME_COMPARATOR.compare(o1, o2);
return twilightResult;
}
} else {
if (o1.getType() == Item.Type.PACK)
return -1;
else
return 1;
}
}
};
private static final Comparator<Item> STRENGTH_COMPARATOR = new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2) {
if (o1.getType() == o2.getType()) {
if (o1.getType() == Item.Type.PACK)
return o1.getBlueprintId().compareTo(o2.getBlueprintId());
else {
int strengthResult = getStrengthSafely(o1.getCardBlueprint()) - getStrengthSafely(o2.getCardBlueprint());
if (strengthResult == 0)
return NAME_COMPARATOR.compare(o1, o2);
return strengthResult;
}
} else {
if (o1.getType() == Item.Type.PACK)
return -1;
else
return 1;
}
}
private int getStrengthSafely(LotroCardBlueprint blueprint) {
try {
return blueprint.getStrength();
} catch (UnsupportedOperationException exp) {
return Integer.MAX_VALUE;
}
}
};
private static final Comparator<Item> VITALITY_COMPARATOR = new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2) {
if (o1.getType() == o2.getType()) {
if (o1.getType() == Item.Type.PACK)
return o1.getBlueprintId().compareTo(o2.getBlueprintId());
else {
int strengthResult = getVitalitySafely(o1.getCardBlueprint()) - getVitalitySafely(o2.getCardBlueprint());
if (strengthResult == 0)
return NAME_COMPARATOR.compare(o1, o2);
return strengthResult;
}
} else {
if (o1.getType() == Item.Type.PACK)
return -1;
else
return 1;
}
}
private int getVitalitySafely(LotroCardBlueprint blueprint) {
try {
return blueprint.getVitality();
} catch (UnsupportedOperationException exp) {
return Integer.MAX_VALUE;
}
}
};
public DefaultCardCollection(LotroCardBlueprintLibrary library) {
_library = library;
@@ -68,22 +163,16 @@ public class DefaultCardCollection implements MutableCardCollection {
result.add(new Item(Item.Type.CARD, count, blueprintId, blueprint));
}
}
Collections.sort(result, new Comparator<Item>() {
@Override
public int compare(Item o1, Item o2) {
if (o1.getType() == o2.getType()) {
if (o1.getType() == Item.Type.PACK)
return o1.getBlueprintId().compareTo(o2.getBlueprintId());
else
return o1.getCardBlueprint().getName().compareTo(o2.getCardBlueprint().getName());
} else {
if (o1.getType() == Item.Type.PACK)
return -1;
else
return 1;
}
}
});
String sort = getSort(filterParams);
if (sort != null && sort.equals("twilight"))
Collections.sort(result, TWILIGHT_COMPARATOR);
else if (sort != null && sort.equals("strength"))
Collections.sort(result, STRENGTH_COMPARATOR);
else if (sort != null && sort.equals("vitality"))
Collections.sort(result, VITALITY_COMPARATOR);
else
Collections.sort(result, NAME_COMPARATOR);
return result;
}
@@ -120,6 +209,14 @@ public class DefaultCardCollection implements MutableCardCollection {
return null;
}
private String getSort(String[] filterParams) {
for (String filterParam : filterParams) {
if (filterParam.startsWith("sort:"))
return filterParam.substring("sort:".length());
}
return null;
}
private boolean containsAllKeywords(LotroCardBlueprint blueprint, List<Keyword> keywords) {
for (Keyword keyword : keywords) {
if (blueprint == null || !blueprint.hasKeyword(keyword))

View File

@@ -52,6 +52,14 @@
width: 100px;
}
#fullFiltering select {
font-size: 80%;
}
#fullFiltering input {
font-size: 80%;
}
#filtering select {
font-size: 80%;
}

View File

@@ -199,6 +199,7 @@ body {
}
.gameMessage {
padding-top: 2px;
font-size: 80%;
}

View File

@@ -3,6 +3,8 @@
- Deck builder now allows to filter sites, rings and ring-bearers on set/block.
- Deck builder now allows to filter deck cards based on their printed keywords.
- Deck builder now allows to filter by words in card name.
- Deck builder now allows to sort cards by name (default), twilight cost, strength and vitality.
- "Legolas, Elven Comrade" now gives the strength penalty correctly to the minion.
<b>2 Nov. 2011</b>
- "O Elbereth! Gilthoniel!" should correctly give the option to cancel a skirmish with Nazgul when used in skirmish

View File

@@ -146,6 +146,13 @@ var GempLotrDeckBuildingUI = Class.extend({
+ "<option value='10'>10 - Mount Doom</option>"
+ "</select>");
this.fullFilterDiv.append("<input type='text' id='cardName' value='Card name'>");
this.fullFilterDiv.append("<select id='sort'>"
+ "<option value=''>Sort by:</option>"
+ "<option value='name'>Name</option>"
+ "<option value='twilight'>Twilight</option>"
+ "<option value='strength'>Strength</option>"
+ "<option value='vitality'>Vitality</option>"
+ "</select>");
this.collectionDiv.append(this.fullFilterDiv);
this.filterDiv = $("<div id='filtering'></div>");
@@ -224,6 +231,7 @@ var GempLotrDeckBuildingUI = Class.extend({
$("#set").change(fullFilterChanged);
$("#cardName").change(fullFilterChanged);
$("#sort").change(fullFilterChanged);
var filterOut = function() {
that.filter = that.calculateNormalFilter();
@@ -606,6 +614,10 @@ var GempLotrDeckBuildingUI = Class.extend({
if (setNo != "")
setNo = " set:" + setNo;
var sort = $("#sort option:selected").prop("value");
if (sort != "")
sort = " sort:" + sort;
var cardName = $("#cardName").val();
if (cardName == "Card name")
cardName = "";
@@ -616,7 +628,7 @@ var GempLotrDeckBuildingUI = Class.extend({
cardName += " name:" + cardNameElems[i];
}
return setNo + cardName;
return setNo + sort + cardName;
},
calculateNormalFilter: function() {