mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
made a base class for quest/QuestRewardCardChooser and quest/QuestRewardCardFiltered to dump duplicate code there.
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14508,6 +14508,7 @@ src/main/java/forge/quest/QuestEventDifficulty.java -text
|
|||||||
src/main/java/forge/quest/QuestEventDuel.java svneol=native#text/plain
|
src/main/java/forge/quest/QuestEventDuel.java svneol=native#text/plain
|
||||||
src/main/java/forge/quest/QuestEventManager.java svneol=native#text/plain
|
src/main/java/forge/quest/QuestEventManager.java svneol=native#text/plain
|
||||||
src/main/java/forge/quest/QuestMode.java -text
|
src/main/java/forge/quest/QuestMode.java -text
|
||||||
|
src/main/java/forge/quest/QuestRewardCard.java -text
|
||||||
src/main/java/forge/quest/QuestRewardCardDuplicate.java -text
|
src/main/java/forge/quest/QuestRewardCardDuplicate.java -text
|
||||||
src/main/java/forge/quest/QuestRewardCardFiltered.java -text
|
src/main/java/forge/quest/QuestRewardCardFiltered.java -text
|
||||||
src/main/java/forge/quest/QuestUtil.java svneol=native#text/plain
|
src/main/java/forge/quest/QuestUtil.java svneol=native#text/plain
|
||||||
|
|||||||
134
src/main/java/forge/quest/QuestRewardCard.java
Normal file
134
src/main/java/forge/quest/QuestRewardCard.java
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
package forge.quest;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
|
||||||
|
import forge.Singletons;
|
||||||
|
import forge.card.CardRules;
|
||||||
|
import forge.item.CardPrinted;
|
||||||
|
import forge.item.IPaperCard;
|
||||||
|
import forge.item.InventoryItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Write javadoc for this type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class QuestRewardCard implements InventoryItem {
|
||||||
|
|
||||||
|
protected String buildDescription(final String [] input) {
|
||||||
|
final String defaultDescription = "a card";
|
||||||
|
if (input == null || input.length < 1) {
|
||||||
|
return defaultDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
String buildDesc = null;
|
||||||
|
|
||||||
|
for (String s : input) {
|
||||||
|
if (s.startsWith("desc:") || s.startsWith("Desc:")) {
|
||||||
|
String[] tmp = s.split(":");
|
||||||
|
if (tmp.length > 1) {
|
||||||
|
buildDesc = new String(tmp[1]);
|
||||||
|
} else {
|
||||||
|
buildDesc = new String();
|
||||||
|
}
|
||||||
|
} else if (buildDesc != null) {
|
||||||
|
if (s.contains(":")) {
|
||||||
|
return buildDesc;
|
||||||
|
} else {
|
||||||
|
buildDesc = buildDesc + " " + s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buildDesc != null) {
|
||||||
|
return buildDesc;
|
||||||
|
}
|
||||||
|
return defaultDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Predicate<CardPrinted> buildPredicates(final String [] input) {
|
||||||
|
if (input == null || input.length < 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Predicate<CardPrinted> filters = Singletons.getModel().getQuest().getFormat().getFilterPrinted();
|
||||||
|
Predicate<CardRules> filterRules = null;
|
||||||
|
Predicate<CardPrinted> filterRarity = null;
|
||||||
|
|
||||||
|
for (String s : input) {
|
||||||
|
if (s.startsWith("sets:") || s.startsWith("Sets:")) {
|
||||||
|
final String[] tmp = s.split(":");
|
||||||
|
if (tmp.length > 1) {
|
||||||
|
String [] setcodes = tmp[1].split(",");
|
||||||
|
if (setcodes.length > 0) {
|
||||||
|
List<String> sets = new ArrayList<String>();
|
||||||
|
for (String code : setcodes) {
|
||||||
|
if (Singletons.getModel().getEditions().contains(code)) {
|
||||||
|
// System.out.println("Set " + code + " was found!");
|
||||||
|
sets.add(code);
|
||||||
|
}
|
||||||
|
// else { System.out.println("Unknown set code " + code); }
|
||||||
|
}
|
||||||
|
if (sets.size() > 0) {
|
||||||
|
filters = IPaperCard.Predicates.printedInSets(sets, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (s.startsWith("rules:") || s.startsWith("Rules:")) {
|
||||||
|
final String[] tmp = s.split(":");
|
||||||
|
if (tmp.length > 1) {
|
||||||
|
String [] ruleCodes = tmp[1].split(",");
|
||||||
|
if (ruleCodes.length > 0) {
|
||||||
|
for (String rule : ruleCodes) {
|
||||||
|
final Predicate<CardRules> newRule = BoosterUtils.parseRulesLimitation(rule);
|
||||||
|
if (newRule != null) {
|
||||||
|
filterRules = (filterRules == null ? newRule : Predicates.and(filterRules, newRule));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (s.startsWith("rarity:") || s.startsWith("Rarity:")) {
|
||||||
|
final String[] tmp = s.split(":");
|
||||||
|
if (tmp.length > 1) {
|
||||||
|
String [] rarityCodes = tmp[1].split(",");
|
||||||
|
if (rarityCodes.length > 0) {
|
||||||
|
for (String rarity : rarityCodes) {
|
||||||
|
if (rarity.startsWith("C") || rarity.startsWith("c")) {
|
||||||
|
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_COMMON : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_COMMON));
|
||||||
|
} else if (rarity.startsWith("U") || rarity.startsWith("u")) {
|
||||||
|
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_UNCOMMON : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_UNCOMMON));
|
||||||
|
} else if (rarity.startsWith("R") || rarity.startsWith("r")) {
|
||||||
|
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_RARE : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_RARE));
|
||||||
|
} else if (rarity.startsWith("M") || rarity.startsWith("m")) {
|
||||||
|
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_MYTHIC_RARE : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filterRules != null) {
|
||||||
|
final Predicate<CardPrinted> rulesPrinted = Predicates.compose(filterRules, CardPrinted.FN_GET_RULES);
|
||||||
|
filters = Predicates.and(filters, rulesPrinted);
|
||||||
|
}
|
||||||
|
if (filterRarity != null) {
|
||||||
|
filters = Predicates.and(filters, filterRarity);
|
||||||
|
}
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A QuestRewardCardChooser ought to always be resolved to an actual card, hence no images.
|
||||||
|
*
|
||||||
|
* @return an empty string
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getImageFilename() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package forge.quest;
|
package forge.quest;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -12,8 +11,6 @@ import java.util.Map;
|
|||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.item.CardDb;
|
import forge.item.CardDb;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
import forge.item.IPaperCard;
|
|
||||||
import forge.card.CardRules;
|
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
import forge.item.ItemPool;
|
import forge.item.ItemPool;
|
||||||
|
|
||||||
@@ -22,7 +19,7 @@ import forge.item.ItemPool;
|
|||||||
* The initial version includes "duplicate", other type may be added later.
|
* The initial version includes "duplicate", other type may be added later.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class QuestRewardCardChooser implements InventoryItem {
|
public class QuestRewardCardChooser extends QuestRewardCard implements InventoryItem {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Possible types for this object.
|
* Possible types for this object.
|
||||||
@@ -55,110 +52,6 @@ public class QuestRewardCardChooser implements InventoryItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildDescription(final String [] input) {
|
|
||||||
final String defaultDescription = "a card";
|
|
||||||
if (input == null || input.length < 1) {
|
|
||||||
return defaultDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
String buildDesc = null;
|
|
||||||
|
|
||||||
for (String s : input) {
|
|
||||||
if (s.startsWith("desc:") || s.startsWith("Desc:")) {
|
|
||||||
String[] tmp = s.split(":");
|
|
||||||
if (tmp.length > 1) {
|
|
||||||
buildDesc = new String(tmp[1]);
|
|
||||||
} else {
|
|
||||||
buildDesc = new String();
|
|
||||||
}
|
|
||||||
} else if (buildDesc != null) {
|
|
||||||
if (s.contains(":")) {
|
|
||||||
return buildDesc;
|
|
||||||
} else {
|
|
||||||
buildDesc = buildDesc + " " + s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (buildDesc != null) {
|
|
||||||
return buildDesc;
|
|
||||||
}
|
|
||||||
return defaultDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private Predicate<CardPrinted> buildPredicates(final String [] input) {
|
|
||||||
if (input == null || input.length < 1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Predicate<CardPrinted> filters = Singletons.getModel().getQuest().getFormat().getFilterPrinted();
|
|
||||||
Predicate<CardRules> filterRules = null;
|
|
||||||
Predicate<CardPrinted> filterRarity = null;
|
|
||||||
|
|
||||||
for (String s : input) {
|
|
||||||
if (s.startsWith("sets:") || s.startsWith("Sets:")) {
|
|
||||||
final String[] tmp = s.split(":");
|
|
||||||
if (tmp.length > 1) {
|
|
||||||
String [] setcodes = tmp[1].split(",");
|
|
||||||
if (setcodes.length > 0) {
|
|
||||||
List<String> sets = new ArrayList<String>();
|
|
||||||
for (String code : setcodes) {
|
|
||||||
if (Singletons.getModel().getEditions().contains(code)) {
|
|
||||||
// System.out.println("Set " + code + " was found!");
|
|
||||||
sets.add(code);
|
|
||||||
}
|
|
||||||
// else { System.out.println("Unknown set code " + code); }
|
|
||||||
}
|
|
||||||
if (sets.size() > 0) {
|
|
||||||
filters = IPaperCard.Predicates.printedInSets(sets, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (s.startsWith("rules:") || s.startsWith("Rules:")) {
|
|
||||||
final String[] tmp = s.split(":");
|
|
||||||
if (tmp.length > 1) {
|
|
||||||
String [] ruleCodes = tmp[1].split(",");
|
|
||||||
if (ruleCodes.length > 0) {
|
|
||||||
for (String rule : ruleCodes) {
|
|
||||||
final Predicate<CardRules> newRule = BoosterUtils.parseRulesLimitation(rule);
|
|
||||||
if (newRule != null) {
|
|
||||||
filterRules = (filterRules == null ? newRule : Predicates.and(filterRules, newRule));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (s.startsWith("rarity:") || s.startsWith("Rarity:")) {
|
|
||||||
final String[] tmp = s.split(":");
|
|
||||||
if (tmp.length > 1) {
|
|
||||||
String [] rarityCodes = tmp[1].split(",");
|
|
||||||
if (rarityCodes.length > 0) {
|
|
||||||
for (String rarity : rarityCodes) {
|
|
||||||
if (rarity.startsWith("C") || rarity.startsWith("c")) {
|
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_COMMON : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_COMMON));
|
|
||||||
} else if (rarity.startsWith("U") || rarity.startsWith("u")) {
|
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_UNCOMMON : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_UNCOMMON));
|
|
||||||
} else if (rarity.startsWith("R") || rarity.startsWith("r")) {
|
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_RARE : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_RARE));
|
|
||||||
} else if (rarity.startsWith("M") || rarity.startsWith("m")) {
|
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_MYTHIC_RARE : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filterRules != null) {
|
|
||||||
final Predicate<CardPrinted> rulesPrinted = Predicates.compose(filterRules, CardPrinted.FN_GET_RULES);
|
|
||||||
filters = Predicates.and(filters, rulesPrinted);
|
|
||||||
}
|
|
||||||
if (filterRarity != null) {
|
|
||||||
filters = Predicates.and(filters, filterRarity);
|
|
||||||
}
|
|
||||||
return filters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name.
|
* The name.
|
||||||
*
|
*
|
||||||
@@ -169,16 +62,6 @@ public class QuestRewardCardChooser implements InventoryItem {
|
|||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A QuestRewardCardChooser ought to always be resolved to an actual card, hence no images.
|
|
||||||
*
|
|
||||||
* @return an empty string
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public String getImageFilename() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The item type.
|
* The item type.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -5,20 +5,16 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import forge.Singletons;
|
|
||||||
import forge.card.CardRules;
|
|
||||||
import forge.item.CardDb;
|
import forge.item.CardDb;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
import forge.item.IPaperCard;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows the player to choose a card from a predicate-filtered list of cards.
|
* Allows the player to choose a card from a predicate-filtered list of cards.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class QuestRewardCardFiltered implements IQuestRewardCard {
|
public class QuestRewardCardFiltered extends QuestRewardCard implements IQuestRewardCard {
|
||||||
|
|
||||||
private final String description;
|
private final String description;
|
||||||
private final Predicate<CardPrinted> predicates;
|
private final Predicate<CardPrinted> predicates;
|
||||||
@@ -33,109 +29,7 @@ public class QuestRewardCardFiltered implements IQuestRewardCard {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String buildDescription(final String [] input) {
|
/**
|
||||||
final String defaultDescription = "a card";
|
|
||||||
if (input == null || input.length < 1) {
|
|
||||||
return defaultDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
String buildDesc = null;
|
|
||||||
|
|
||||||
for (String s : input) {
|
|
||||||
if (s.startsWith("desc:") || s.startsWith("Desc:")) {
|
|
||||||
String[] tmp = s.split(":");
|
|
||||||
if (tmp.length > 1) {
|
|
||||||
buildDesc = new String(tmp[1]);
|
|
||||||
} else {
|
|
||||||
buildDesc = new String();
|
|
||||||
}
|
|
||||||
} else if (buildDesc != null) {
|
|
||||||
if (s.contains(":")) {
|
|
||||||
return buildDesc;
|
|
||||||
} else {
|
|
||||||
buildDesc = buildDesc + " " + s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (buildDesc != null) {
|
|
||||||
return buildDesc;
|
|
||||||
}
|
|
||||||
return defaultDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Predicate<CardPrinted> buildPredicates(final String [] input) {
|
|
||||||
if (input == null || input.length < 1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Predicate<CardPrinted> filters = Singletons.getModel().getQuest().getFormat().getFilterPrinted();
|
|
||||||
Predicate<CardRules> filterRules = null;
|
|
||||||
Predicate<CardPrinted> filterRarity = null;
|
|
||||||
|
|
||||||
for (String s : input) {
|
|
||||||
if (s.startsWith("sets:") || s.startsWith("Sets:")) {
|
|
||||||
final String[] tmp = s.split(":");
|
|
||||||
if (tmp.length > 1) {
|
|
||||||
String [] setcodes = tmp[1].split(",");
|
|
||||||
if (setcodes.length > 0) {
|
|
||||||
List<String> sets = new ArrayList<String>();
|
|
||||||
for (String code : setcodes) {
|
|
||||||
if (Singletons.getModel().getEditions().contains(code)) {
|
|
||||||
// System.out.println("Set " + code + " was found!");
|
|
||||||
sets.add(code);
|
|
||||||
}
|
|
||||||
// else { System.out.println("Unknown set code " + code); }
|
|
||||||
}
|
|
||||||
if (sets.size() > 0) {
|
|
||||||
filters = IPaperCard.Predicates.printedInSets(sets, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (s.startsWith("rules:") || s.startsWith("Rules:")) {
|
|
||||||
final String[] tmp = s.split(":");
|
|
||||||
if (tmp.length > 1) {
|
|
||||||
String [] ruleCodes = tmp[1].split(",");
|
|
||||||
if (ruleCodes.length > 0) {
|
|
||||||
for (String rule : ruleCodes) {
|
|
||||||
final Predicate<CardRules> newRule = BoosterUtils.parseRulesLimitation(rule);
|
|
||||||
if (newRule != null) {
|
|
||||||
filterRules = (filterRules == null ? newRule : Predicates.and(filterRules, newRule));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (s.startsWith("rarity:") || s.startsWith("Rarity:")) {
|
|
||||||
final String[] tmp = s.split(":");
|
|
||||||
if (tmp.length > 1) {
|
|
||||||
String [] rarityCodes = tmp[1].split(",");
|
|
||||||
if (rarityCodes.length > 0) {
|
|
||||||
for (String rarity : rarityCodes) {
|
|
||||||
if (rarity.startsWith("C") || rarity.startsWith("c")) {
|
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_COMMON : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_COMMON));
|
|
||||||
} else if (rarity.startsWith("U") || rarity.startsWith("u")) {
|
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_UNCOMMON : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_UNCOMMON));
|
|
||||||
} else if (rarity.startsWith("R") || rarity.startsWith("r")) {
|
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_RARE : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_RARE));
|
|
||||||
} else if (rarity.startsWith("M") || rarity.startsWith("m")) {
|
|
||||||
filterRarity = (filterRarity == null ? IPaperCard.Predicates.Presets.IS_MYTHIC_RARE : Predicates.or(filterRarity, IPaperCard.Predicates.Presets.IS_MYTHIC_RARE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filterRules != null) {
|
|
||||||
final Predicate<CardPrinted> rulesPrinted = Predicates.compose(filterRules, CardPrinted.FN_GET_RULES);
|
|
||||||
filters = Predicates.and(filters, rulesPrinted);
|
|
||||||
}
|
|
||||||
if (filterRarity != null) {
|
|
||||||
filters = Predicates.and(filters, filterRarity);
|
|
||||||
}
|
|
||||||
return filters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The name.
|
* The name.
|
||||||
*
|
*
|
||||||
* @return the name
|
* @return the name
|
||||||
|
|||||||
Reference in New Issue
Block a user