Adding BoosterReplaceSlotFromPrintSheet logic

This commit is contained in:
pfirpfel
2020-10-06 11:45:59 +02:00
parent fb16232c9f
commit 51c771848d
2 changed files with 67 additions and 17 deletions

View File

@@ -123,6 +123,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
private String additionalUnlockSet = "";
private boolean smallSetOverride = false;
private String boosterMustContain = "";
private String boosterReplaceSlotFromPrintSheet = "";
private boolean doublePickToStartRound = false;
private final CardInSet[] cards;
private final Map<String, Integer> tokenNormalized;
@@ -193,6 +194,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
public boolean getSmallSetOverride() { return smallSetOverride; }
public boolean getDoublePickToStartRound() { return doublePickToStartRound; }
public String getBoosterMustContain() { return boosterMustContain; }
public String getBoosterReplaceSlotFromPrintSheet() { return boosterReplaceSlotFromPrintSheet; }
public CardInSet[] getCards() { return cards; }
public boolean isModern() { return getDate().after(parseDate("2003-07-27")); } //8ED and above are modern except some promo cards and others
@@ -382,6 +384,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
res.doublePickToStartRound = section.getBoolean("DoublePick", false); // for "small" sets with over 200 cards (e.g. Eldritch Moon)
res.boosterMustContain = section.get("BoosterMustContain", ""); // e.g. Dominaria guaranteed legendary creature
res.boosterReplaceSlotFromPrintSheet = section.get("BoosterReplaceSlotFromPrintSheet", ""); // e.g. Zendikar Rising guaranteed double-faced card
return res;
}

View File

@@ -339,6 +339,11 @@ public class BoosterGenerator {
if (!boosterMustContain.isEmpty()) {
ensureGuaranteedCardInBooster(result, template, boosterMustContain);
}
String boosterReplaceSlotFromPrintSheet = edition.getBoosterReplaceSlotFromPrintSheet();
if(!boosterReplaceSlotFromPrintSheet.isEmpty()) {
replaceCardFromExtraSheet(result, boosterReplaceSlotFromPrintSheet);
}
}
return result;
@@ -390,24 +395,66 @@ public class BoosterGenerator {
if (!possibleCards.isEmpty()) {
PaperCard toAdd = Aggregates.random(possibleCards);
PaperCard toRepl = null;
CardRarity tgtRarity = toAdd.getRarity();
BoosterGenerator.replaceCard(result, toAdd);
}
}
}
// remove the first card of the same rarity, replace it with toAdd. Keep the foil state.
for (PaperCard repl : result) {
if (repl.getRarity() == tgtRarity) {
toRepl = repl;
/**
* Replaces an already present card in the booster with a card from the supplied print sheet.
* Nothing is replaced if there is no matching rarity found.
* @param booster in which a card gets replaced
* @param printSheetKey
*/
public static void replaceCardFromExtraSheet(List<PaperCard> booster, String printSheetKey) {
PrintSheet replacementSheet = StaticData.instance().getPrintSheets().get(printSheetKey);
PaperCard toAdd = replacementSheet.random(1, false).get(0);
BoosterGenerator.replaceCard(booster, toAdd);
}
/**
* Replaces an already present card with the supplied card of the same (or similar in case or rare/mythic)
* rarity in the supplied booster. Nothing is replaced if there is no matching rarity found.
* @param booster in which a card gets replaced
* @param toAdd new card which replaces a card in the booster
*/
public static void replaceCard(List<PaperCard> booster, PaperCard toAdd) {
Predicate<PaperCard> rarityPredicate = null;
switch(toAdd.getRarity()){
case BasicLand:
rarityPredicate = Presets.IS_BASIC_LAND;
break;
case Common:
rarityPredicate = Presets.IS_COMMON;
break;
case Uncommon:
rarityPredicate = Presets.IS_UNCOMMON;
break;
case Rare:
case MythicRare:
rarityPredicate = Presets.IS_RARE_OR_MYTHIC;
break;
default:
rarityPredicate = Presets.IS_SPECIAL;
}
PaperCard toReplace = null;
// Find first card in booster that matches the rarity
for (PaperCard card : booster) {
if(rarityPredicate.apply(card)) {
toReplace = card;
break;
}
}
if (toRepl != null) {
if (toRepl.isFoil()) {
// Replace card if match is found
if (toReplace != null) {
// Keep the foil state
if (toReplace.isFoil()) {
toAdd = StaticData.instance().getCommonCards().getFoiled(toAdd);
}
result.remove(toRepl);
result.add(toAdd);
}
}
booster.remove(toReplace);
booster.add(toAdd);
}
}