mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Adding BoosterReplaceSlotFromPrintSheet logic
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,27 +395,69 @@ public class BoosterGenerator {
|
||||
|
||||
if (!possibleCards.isEmpty()) {
|
||||
PaperCard toAdd = Aggregates.random(possibleCards);
|
||||
PaperCard toRepl = null;
|
||||
CardRarity tgtRarity = toAdd.getRarity();
|
||||
|
||||
// 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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (toRepl != null) {
|
||||
if (toRepl.isFoil()) {
|
||||
toAdd = StaticData.instance().getCommonCards().getFoiled(toAdd);
|
||||
}
|
||||
result.remove(toRepl);
|
||||
result.add(toAdd);
|
||||
}
|
||||
BoosterGenerator.replaceCard(result, toAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
// Replace card if match is found
|
||||
if (toReplace != null) {
|
||||
// Keep the foil state
|
||||
if (toReplace.isFoil()) {
|
||||
toAdd = StaticData.instance().getCommonCards().getFoiled(toAdd);
|
||||
}
|
||||
booster.remove(toReplace);
|
||||
booster.add(toAdd);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addCardsFromExtraSheet(List<PaperCard> dest, String printSheetKey) {
|
||||
PrintSheet extraSheet = getPrintSheet(printSheetKey);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user