mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Quests with reward description like '2 rares' won't crash
This commit is contained in:
@@ -134,8 +134,8 @@ public enum CSubmenuChallenges implements ICDoc {
|
|||||||
view.getPnlChallenges().removeAll();
|
view.getPnlChallenges().removeAll();
|
||||||
qCtrl.regenerateChallenges();
|
qCtrl.regenerateChallenges();
|
||||||
final List<QuestEventChallenge> challenges = new ArrayList<QuestEventChallenge>();
|
final List<QuestEventChallenge> challenges = new ArrayList<QuestEventChallenge>();
|
||||||
for(String id : qCtrl.getAchievements().getCurrentChallenges()) {
|
for(Object id : qCtrl.getAchievements().getCurrentChallenges()) {
|
||||||
challenges.add(qCtrl.getChallenges().get(id));
|
challenges.add(qCtrl.getChallenges().get(id.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
JXButtonPanel grpPanel = new JXButtonPanel();
|
JXButtonPanel grpPanel = new JXButtonPanel();
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import com.google.common.collect.Lists;
|
|||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.CardRules;
|
import forge.card.CardRules;
|
||||||
import forge.card.CardRulesPredicates;
|
import forge.card.CardRulesPredicates;
|
||||||
|
import forge.card.MagicColor;
|
||||||
import forge.item.BoosterPack;
|
import forge.item.BoosterPack;
|
||||||
import forge.item.CardDb;
|
import forge.item.CardDb;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
@@ -81,11 +82,11 @@ public final class BoosterUtils {
|
|||||||
colorFilters.add(CardRulesPredicates.Presets.IS_COLORLESS);
|
colorFilters.add(CardRulesPredicates.Presets.IS_COLORLESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
colorFilters.add(Predicates.and(CardRulesPredicates.Presets.IS_MONOCOLOR, CardRulesPredicates.Presets.IS_WHITE));
|
colorFilters.add(CardRulesPredicates.isMonoColor(MagicColor.WHITE));
|
||||||
colorFilters.add(Predicates.and(CardRulesPredicates.Presets.IS_MONOCOLOR, CardRulesPredicates.Presets.IS_RED));
|
colorFilters.add(CardRulesPredicates.isMonoColor(MagicColor.RED));
|
||||||
colorFilters.add(Predicates.and(CardRulesPredicates.Presets.IS_MONOCOLOR, CardRulesPredicates.Presets.IS_BLUE));
|
colorFilters.add(CardRulesPredicates.isMonoColor(MagicColor.BLUE));
|
||||||
colorFilters.add(Predicates.and(CardRulesPredicates.Presets.IS_MONOCOLOR, CardRulesPredicates.Presets.IS_BLACK));
|
colorFilters.add(CardRulesPredicates.isMonoColor(MagicColor.BLACK));
|
||||||
colorFilters.add(Predicates.and(CardRulesPredicates.Presets.IS_MONOCOLOR, CardRulesPredicates.Presets.IS_GREEN));
|
colorFilters.add(CardRulesPredicates.isMonoColor(MagicColor.GREEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will save CPU time when sets are limited
|
// This will save CPU time when sets are limited
|
||||||
@@ -183,35 +184,21 @@ public final class BoosterUtils {
|
|||||||
if (null == input || "random".equalsIgnoreCase(input))
|
if (null == input || "random".equalsIgnoreCase(input))
|
||||||
return Predicates.alwaysTrue();
|
return Predicates.alwaysTrue();
|
||||||
|
|
||||||
if (input.equalsIgnoreCase("black")) {
|
if (input.equalsIgnoreCase("black")) return CardRulesPredicates.Presets.IS_BLACK;
|
||||||
return CardRulesPredicates.Presets.IS_BLACK;
|
if (input.equalsIgnoreCase("blue")) return CardRulesPredicates.Presets.IS_BLUE;
|
||||||
} else if (input.equalsIgnoreCase("blue")) {
|
if (input.equalsIgnoreCase("green")) return CardRulesPredicates.Presets.IS_GREEN;
|
||||||
return CardRulesPredicates.Presets.IS_BLUE;
|
if (input.equalsIgnoreCase("red")) return CardRulesPredicates.Presets.IS_RED;
|
||||||
} else if (input.equalsIgnoreCase("colorless")) {
|
if (input.equalsIgnoreCase("white")) return CardRulesPredicates.Presets.IS_WHITE;
|
||||||
return CardRulesPredicates.Presets.IS_COLORLESS;
|
if (input.equalsIgnoreCase("colorless")) return CardRulesPredicates.Presets.IS_COLORLESS;
|
||||||
} else if (input.equalsIgnoreCase("green")) {
|
if (input.equalsIgnoreCase("multicolor")) return CardRulesPredicates.Presets.IS_MULTICOLOR;
|
||||||
return CardRulesPredicates.Presets.IS_GREEN;
|
|
||||||
} else if (input.equalsIgnoreCase("multicolor")) {
|
if (input.equalsIgnoreCase("land")) return CardRulesPredicates.Presets.IS_LAND;
|
||||||
return CardRulesPredicates.Presets.IS_MULTICOLOR;
|
if (input.equalsIgnoreCase("creature")) return CardRulesPredicates.Presets.IS_CREATURE;
|
||||||
} else if (input.equalsIgnoreCase("red")) {
|
if (input.equalsIgnoreCase("artifact")) return CardRulesPredicates.Presets.IS_ARTIFACT;
|
||||||
return CardRulesPredicates.Presets.IS_RED;
|
if (input.equalsIgnoreCase("planeswalker")) return CardRulesPredicates.Presets.IS_PLANESWALKER;
|
||||||
} else if (input.equalsIgnoreCase("white")) {
|
if (input.equalsIgnoreCase("instant")) return CardRulesPredicates.Presets.IS_INSTANT;
|
||||||
return CardRulesPredicates.Presets.IS_WHITE;
|
if (input.equalsIgnoreCase("sorcery")) return CardRulesPredicates.Presets.IS_SORCERY;
|
||||||
} else if (input.equalsIgnoreCase("land")) {
|
if (input.equalsIgnoreCase("enchantment")) return CardRulesPredicates.Presets.IS_ENCHANTMENT;
|
||||||
return CardRulesPredicates.Presets.IS_LAND;
|
|
||||||
} else if (input.equalsIgnoreCase("creature")) {
|
|
||||||
return CardRulesPredicates.Presets.IS_CREATURE;
|
|
||||||
} else if (input.equalsIgnoreCase("artifact")) {
|
|
||||||
return CardRulesPredicates.Presets.IS_ARTIFACT;
|
|
||||||
} else if (input.equalsIgnoreCase("planeswalker")) {
|
|
||||||
return CardRulesPredicates.Presets.IS_PLANESWALKER;
|
|
||||||
} else if (input.equalsIgnoreCase("instant")) {
|
|
||||||
return CardRulesPredicates.Presets.IS_INSTANT;
|
|
||||||
} else if (input.equalsIgnoreCase("sorcery")) {
|
|
||||||
return CardRulesPredicates.Presets.IS_SORCERY;
|
|
||||||
} else if (input.equalsIgnoreCase("enchantment")) {
|
|
||||||
return CardRulesPredicates.Presets.IS_ENCHANTMENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException("No CardRules limitations could be parsed from: " + input);
|
throw new IllegalArgumentException("No CardRules limitations could be parsed from: " + input);
|
||||||
}
|
}
|
||||||
@@ -226,24 +213,27 @@ public final class BoosterUtils {
|
|||||||
String[] temp = s.split(" ");
|
String[] temp = s.split(" ");
|
||||||
List<InventoryItem> rewards = new ArrayList<InventoryItem>();
|
List<InventoryItem> rewards = new ArrayList<InventoryItem>();
|
||||||
|
|
||||||
if ((temp.length > 2 && (temp[2].equalsIgnoreCase("rare") || temp[2].equalsIgnoreCase("rares")))
|
// last word starts with 'rare' ignore case
|
||||||
|| (temp.length > 1 && (temp[1].equalsIgnoreCase("rare") || temp[1].equalsIgnoreCase("rares")))) {
|
if (temp.length > 1 && temp[temp.length-1].regionMatches(true, 0, "rare", 0, 4)) {
|
||||||
// Type 1: 'n (color) rares'
|
// Type 1: 'n [color] rares'
|
||||||
final int qty = Integer.parseInt(temp[0]);
|
final int qty = Integer.parseInt(temp[0]);
|
||||||
// Determine rarity
|
|
||||||
final Predicate<CardPrinted> rar = IPaperCard.Predicates.Presets.IS_RARE_OR_MYTHIC;
|
|
||||||
|
|
||||||
// Determine color ("random" defaults to null color)
|
List<Predicate<CardPrinted>> preds = new ArrayList<Predicate<CardPrinted>>();
|
||||||
Predicate<CardRules> col = parseRulesLimitation(temp[1]);
|
preds.add(IPaperCard.Predicates.Presets.IS_RARE_OR_MYTHIC); // Determine rarity
|
||||||
|
|
||||||
Predicate<CardPrinted> colorPred = Predicates.compose(col, CardPrinted.FN_GET_RULES);
|
if (temp.length > 2) {
|
||||||
Predicate<CardPrinted> rarAndColor = Predicates.and(rar, colorPred);
|
Predicate<CardRules> cr = parseRulesLimitation(temp[1]);
|
||||||
|
if(Predicates.alwaysTrue() != (Object)cr) // guava has a single instance for always-const predicates
|
||||||
|
preds.add(Predicates.compose(cr, CardPrinted.FN_GET_RULES));
|
||||||
|
}
|
||||||
|
|
||||||
if (Singletons.getModel().getQuest().getFormat() != null) {
|
if (Singletons.getModel().getQuest().getFormat() != null) {
|
||||||
rarAndColor = Predicates.and(Singletons.getModel().getQuest().getFormat().getFilterPrinted(), rarAndColor);
|
preds.add(Singletons.getModel().getQuest().getFormat().getFilterPrinted());
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintSheet ps = new PrintSheet("Quest rewards");
|
PrintSheet ps = new PrintSheet("Quest rewards");
|
||||||
ps.addAll(Iterables.filter(CardDb.instance().getAllCards(), rarAndColor));
|
Predicate<CardPrinted> predicate = preds.size() == 1 ? preds.get(0) : Predicates.and(preds);
|
||||||
|
ps.addAll(Iterables.filter(CardDb.instance().getAllCards(), predicate));
|
||||||
rewards.addAll(ps.random(qty, true));
|
rewards.addAll(ps.random(qty, true));
|
||||||
} else if (temp.length == 2 && temp[0].equalsIgnoreCase("duplicate") && temp[1].equalsIgnoreCase("card")) {
|
} else if (temp.length == 2 && temp[0].equalsIgnoreCase("duplicate") && temp[1].equalsIgnoreCase("card")) {
|
||||||
// Type 2: a duplicate card of the players choice
|
// Type 2: a duplicate card of the players choice
|
||||||
|
|||||||
Reference in New Issue
Block a user