Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows for additional cards to be added to worlds.txt in quest mode. #6175

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,10 @@ private static Predicate<PaperCard> buildExtraPredicate(List<String> operators)
List<Predicate<PaperCard>> conditions = new ArrayList<>();

Iterator<String> itOp = operators.iterator();

//needed to find additional cards in boosters generated on quest mode
List<PaperCard> additionalCards = null;

while (itOp.hasNext()) {
String operator = itOp.next();
if (StringUtils.isEmpty(operator)) {
Expand All @@ -676,6 +680,7 @@ private static Predicate<PaperCard> buildExtraPredicate(List<String> operators)
boolean invert = operator.charAt(0) == '!';
if (invert) { operator = operator.substring(1); }

boolean extra = false;
Predicate<PaperCard> toAdd = null;
if (operator.equalsIgnoreCase(BoosterSlots.DUAL_FACED_CARD)) {
toAdd = Predicates.compose(
Expand All @@ -694,9 +699,16 @@ private static Predicate<PaperCard> buildExtraPredicate(List<String> operators)
} else if (operator.equalsIgnoreCase(BoosterSlots.UNCOMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_UNCOMMON;
} else if (operator.equalsIgnoreCase(BoosterSlots.COMMON)) { toAdd = IPaperCard.Predicates.Presets.IS_COMMON;
} else if (operator.startsWith("name(")) {
//cardname@set
additionalCards = new ArrayList<>();
operator = StringUtils.strip(operator.substring(4), "() ");
String[] cardNames = TextUtil.splitWithParenthesis(operator, ',', '"', '"');
toAdd = IPaperCard.Predicates.names(Lists.newArrayList(cardNames));
for(String card : cardNames){
String[] split = card.split("@");
additionalCards.add(StaticData.instance().getCommonCards().getCard(split[0], split[1]));
}
itOp.remove();
continue;
} else if (operator.startsWith("color(")) {
operator = StringUtils.strip(operator.substring("color(".length() + 1), "()\" ");
switch (operator.toLowerCase()) {
Expand All @@ -722,7 +734,16 @@ private static Predicate<PaperCard> buildExtraPredicate(List<String> operators)
} else if (operator.startsWith("fromSets(")) {
operator = StringUtils.strip(operator.substring("fromSets(".length() + 1), "()\" ");
String[] sets = operator.split(",");
toAdd = IPaperCard.Predicates.printedInSets(sets);
//looks up for if there are additional cards in the format to place them toguether with the set cards
if(additionalCards == null){
toAdd = IPaperCard.Predicates.printedInSets(sets);
}else{
toAdd = Predicates.or(
IPaperCard.Predicates.printedInSets(sets),
IPaperCard.Predicates.cards(additionalCards)
);
additionalCards = null;
}
} else if (operator.startsWith("fromSheet(") && invert) {
String sheetName = StringUtils.strip(operator.substring(9), "()\" ");
Iterable<PaperCard> cards = StaticData.instance().getPrintSheets().get(sheetName).toFlatList();
Expand All @@ -740,6 +761,10 @@ private static Predicate<PaperCard> buildExtraPredicate(List<String> operators)
}
conditions.add(toAdd);
}
//if no sets were present, creates the predicate with only the additional cards
if(additionalCards != null){
conditions.add(IPaperCard.Predicates.cards(additionalCards));
}

if (conditions.isEmpty()) {
return Predicates.alwaysTrue();
Expand Down
123 changes: 102 additions & 21 deletions forge-game/src/main/java/forge/game/GameFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.StaticData;
import forge.card.CardDb;
Expand Down Expand Up @@ -92,11 +93,11 @@ public enum FormatSubType {

private final int index;

public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) {
this(fName, parseDate(DEFAULTDATE), sets, bannedCards, null, false, null, null, 0, FormatType.CUSTOM, FormatSubType.CUSTOM);
public GameFormat(final String fName, final Iterable<String> sets, final List<String> additionalCards, final List<String> bannedCards) {
this(fName, parseDate(DEFAULTDATE), sets, bannedCards, null, false, additionalCards, null, 0, FormatType.CUSTOM, FormatSubType.CUSTOM);
}
public static final GameFormat NoFormat = new GameFormat("(none)", parseDate(DEFAULTDATE) , null, null, null, false

public static final GameFormat NoFormat = new GameFormat("(none)", parseDate(DEFAULTDATE), null, null, null, false
, null, null, Integer.MAX_VALUE, FormatType.CUSTOM, FormatSubType.CUSTOM);

public GameFormat(final String fName, final Date effectiveDate, final Iterable<String> sets, final List<String> bannedCards,
Expand Down Expand Up @@ -146,21 +147,59 @@ protected Predicate<PaperCard> buildFilter(boolean printed) {
p = Predicates.and(p, Predicates.not(IPaperCard.Predicates.Presets.IS_REBALANCED));
}

//creates a predicate for additional cards
Predicate<PaperCard> additionalPred = null;
if (!this.getAdditionalCards().isEmpty()) {
List<String> cardNames = Lists.newArrayList();
List<PaperCard> cards = Lists.newArrayList();
for(String card : this.getAdditionalCards()){
String[] cardSplit = card.split("\\|");
PaperCard pCard = null;
if(cardSplit.length == 2){
pCard = StaticData.instance().getCommonCards().getCard(cardSplit[0], cardSplit[1]);
if(pCard != null){
cards.add(pCard);
cardNames.add(cardSplit[0]);
}
}else{
pCard = StaticData.instance().getCommonCards().getUniqueByName(cardSplit[0]);
if(pCard != null){
cards.add(pCard);
cardNames.add(pCard.getName());
}
}
}

additionalPred = IPaperCard.Predicates.cards(cards);
}

//in case allowed set codes are not empty and there are additional cards, it'll set the predicate to account for both
if (!this.getAllowedSetCodes().isEmpty()) {
p = Predicates.and(p, printed ?
IPaperCard.Predicates.printedInSets(this.getAllowedSetCodes(), printed) :
StaticData.instance().getCommonCards().wasPrintedInSets(this.getAllowedSetCodes()));
Predicate<PaperCard> setsPred = null;
if(printed){
setsPred = IPaperCard.Predicates.printedInSets(this.getAllowedSetCodes(), printed);
}else{
setsPred = (Predicate<PaperCard>) StaticData.instance().getCommonCards().wasPrintedInSets(this.getAllowedSetCodes());
}
if(additionalPred != null)
{
p = Predicates.and(p, Predicates.or(setsPred, additionalPred));
}else{
p = Predicates.and(p, setsPred);
}
}
//if allowed set codes are empty, the whole format will only be additional cards (if there are any)
else if(additionalPred != null){
p = Predicates.and(p, additionalPred);
}

if (!this.getAllowedRarities().isEmpty()) {
List<Predicate<? super PaperCard>> crp = Lists.newArrayList();
for (CardRarity cr: this.getAllowedRarities()) {
crp.add(StaticData.instance().getCommonCards().wasPrintedAtRarity(cr));
}
p = Predicates.and(p, Predicates.or(crp));
}
if (!this.getAdditionalCards().isEmpty()) {
p = Predicates.or(p, IPaperCard.Predicates.names(this.getAdditionalCards()));
}
return p;
}

Expand Down Expand Up @@ -221,18 +260,59 @@ public List<CardRarity> getAllowedRarities() {
}

public List<PaperCard> getAllCards() {

return Lists.newArrayList(Iterables.filter(StaticData.instance().getCommonCards().getAllCards(), getFilterPrinted()));


//List<PaperCard> cards = new ArrayList<>();
//CardDb commonCards = StaticData.instance().getCommonCards();


//for (String setCode : allowedSetCodes_ro) {
// CardEdition edition = StaticData.instance().getEditions().get(setCode);
// if (edition != null) {
// for (CardInSet card : edition.getAllCardsInSet()) {
// if (!bannedCardNames_ro.contains(card.name)) {
// PaperCard pc = commonCards.getCard(card.name, setCode, card.collectorNumber);
// if (pc != null) {
// cards.add(pc);
// }
// }
// }
// }
//}
//adds extra cards to the pool
//for(String extraCard : additionalCardNames_ro){
// String[] split = extraCard.split("@");
// if(split.length == 2){
// PaperCard pc = commonCards.getCard(split[0], split[1]);
// if(pc != null){
// cards.add(pc);
// }
// }else{
// PaperCard pc = commonCards.getCard(extraCard);
// if(pc != null){
// cards.add(pc);
// }
// }
//}
//return cards;
}
public List<PaperCard> getAllExtraCards(){
List<PaperCard> cards = new ArrayList<>();
CardDb commonCards = StaticData.instance().getCommonCards();
for (String setCode : allowedSetCodes_ro) {
CardEdition edition = StaticData.instance().getEditions().get(setCode);
if (edition != null) {
for (CardInSet card : edition.getAllCardsInSet()) {
if (!bannedCardNames_ro.contains(card.name)) {
PaperCard pc = commonCards.getCard(card.name, setCode, card.collectorNumber);
if (pc != null) {
cards.add(pc);
}
}
//adds extra cards to the pool
for(String extraCard : additionalCardNames_ro){
String[] split = extraCard.split("@");
if(split.length == 2){
PaperCard pc = commonCards.getCard(split[0], split[1]);
if(pc != null){
cards.add(pc);
}
}else{
PaperCard pc = commonCards.getCard(extraCard);
if(pc != null){
cards.add(pc);
}
}
}
Expand All @@ -247,8 +327,9 @@ public Predicate<PaperCard> getFilterPrinted() {
return this.filterPrinted;
}

//if there arent additional cards nor allowed sets, it will return false
public boolean isSetLegal(final String setCode) {
return this.getAllowedSetCodes().isEmpty() || this.getAllowedSetCodes().contains(setCode);
return (this.getAllowedSetCodes().isEmpty() && this.getAdditionalCards().isEmpty()) || this.getAllowedSetCodes().contains(setCode);
}

private boolean isPoolLegal(final CardPool allCards) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean merge(final ItemFilter<?> filter) {
allBannedCards.addAll(bannedCards);
}
this.formats.clear();
this.formats.add(new GameFormat(null, this.sets, allBannedCards));
this.formats.add(new GameFormat(null, this.sets, null, allBannedCards));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class CardSetFilter extends CardFormatFilter {
public CardSetFilter(ItemManager<? super PaperCard> itemManager0, Collection<String> sets0, boolean allowReprints0) {
super(itemManager0);
this.sets.addAll(sets0);
this.formats.add(new GameFormat(null, this.sets, null));
this.formats.add(new GameFormat(null, this.sets, null, null));
this.allowReprints = allowReprints0;
}

Expand Down Expand Up @@ -54,7 +54,7 @@ public boolean merge(ItemFilter<?> filter) {
this.limitedSets.addAll(cardSetFilter.limitedSets);
this.allowReprints = cardSetFilter.allowReprints;
this.formats.clear();
this.formats.add(new GameFormat(null, this.sets, null));
this.formats.add(new GameFormat(null, this.sets, null, null));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean merge(final ItemFilter<?> filter) {
allBannedCards.addAll(bannedCards);
}
this.formats.clear();
this.formats.add(new GameFormat(null, this.sets, allBannedCards));
this.formats.add(new GameFormat(null, this.sets, null, allBannedCards));
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DeckSetFilter extends DeckFormatFilter {
public DeckSetFilter(ItemManager<? super DeckProxy> itemManager0, Collection<String> sets0, boolean allowReprints0) {
super(itemManager0);
this.sets.addAll(sets0);
this.formats.add(new GameFormat(null, this.sets, null));
this.formats.add(new GameFormat(null, this.sets, null, null));
this.allowReprints = allowReprints0;
}

Expand Down Expand Up @@ -53,7 +53,7 @@ public boolean merge(ItemFilter<?> filter) {
this.limitedSets.addAll(cardSetFilter.limitedSets);
this.allowReprints = cardSetFilter.allowReprints;
this.formats.clear();
this.formats.add(new GameFormat(null, this.sets, null));
this.formats.add(new GameFormat(null, this.sets, null, null));
return true;
}

Expand All @@ -67,7 +67,7 @@ public void edit() {
sets.addAll(dialog.getSelectedSets());
allowReprints = dialog.getWantReprints();
formats.clear();
formats.add(new GameFormat(null, sets, null));
formats.add(new GameFormat(null, sets, null, null));
itemManager.addFilter(itemFilter); // this adds/updates the current filter
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void newQuest() {
return;
}
}
fmtStartPool = customFormatCodes.isEmpty() ? null : new GameFormatQuest("Custom", customFormatCodes, null); // chosen sets and no banned cards
fmtStartPool = customFormatCodes.isEmpty() ? null : new GameFormatQuest("Custom", customFormatCodes, null, null); // chosen sets and no banned cards
break;

case DraftDeck:
Expand Down Expand Up @@ -194,7 +194,7 @@ private void newQuest() {
for(Map.Entry<PaperCard, Integer> entry : dckStartPool.getAllCardsInASinglePool()) {
sets.add(entry.getKey().getEdition());
}
fmtPrizes = new GameFormat(localizer.getMessage("lblFromDeck"), sets, null);
fmtPrizes = new GameFormat(localizer.getMessage("lblFromDeck"), sets, null, null);
}
}
else {
Expand All @@ -209,7 +209,7 @@ private void newQuest() {
return;
}
}
fmtPrizes = customPrizeFormatCodes.isEmpty() ? null : new GameFormat("Custom Prizes", customPrizeFormatCodes, null); // chosen sets and no banned cards
fmtPrizes = customPrizeFormatCodes.isEmpty() ? null : new GameFormat("Custom Prizes", customPrizeFormatCodes, null, null); // chosen sets and no banned cards
break;
case Sanctioned:
fmtPrizes = view.getPrizedRotatingFormat();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading