From 51c771848dab8e9440a17e4a6be7c6c9eba78b7e Mon Sep 17 00:00:00 2001 From: pfirpfel Date: Tue, 6 Oct 2020 11:45:59 +0200 Subject: [PATCH 1/2] Adding BoosterReplaceSlotFromPrintSheet logic --- .../src/main/java/forge/card/CardEdition.java | 3 + .../item/generation/BoosterGenerator.java | 81 +++++++++++++++---- 2 files changed, 67 insertions(+), 17 deletions(-) diff --git a/forge-core/src/main/java/forge/card/CardEdition.java b/forge-core/src/main/java/forge/card/CardEdition.java index 13d2ad422cf..c69b165d995 100644 --- a/forge-core/src/main/java/forge/card/CardEdition.java +++ b/forge-core/src/main/java/forge/card/CardEdition.java @@ -123,6 +123,7 @@ public final class CardEdition implements Comparable { // 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 tokenNormalized; @@ -193,6 +194,7 @@ public final class CardEdition implements Comparable { // 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 { // 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; } diff --git a/forge-core/src/main/java/forge/item/generation/BoosterGenerator.java b/forge-core/src/main/java/forge/item/generation/BoosterGenerator.java index 8f5d18715d6..6610e94aee9 100644 --- a/forge-core/src/main/java/forge/item/generation/BoosterGenerator.java +++ b/forge-core/src/main/java/forge/item/generation/BoosterGenerator.java @@ -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 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 booster, PaperCard toAdd) { + Predicate 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 dest, String printSheetKey) { PrintSheet extraSheet = getPrintSheet(printSheetKey); From 52547345bec9942c1dae50b1dc60ad8a1069d477 Mon Sep 17 00:00:00 2001 From: pfirpfel Date: Tue, 6 Oct 2020 15:14:25 +0200 Subject: [PATCH 2/2] Adding ZNR DFC printsheet, changing ZNR booster composition --- forge-gui/res/blockdata/printsheets.txt | 38 ++++++++++++++++++++++ forge-gui/res/editions/Zendikar Rising.txt | 3 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/forge-gui/res/blockdata/printsheets.txt b/forge-gui/res/blockdata/printsheets.txt index 65bea9ea298..29e25bd4641 100644 --- a/forge-gui/res/blockdata/printsheets.txt +++ b/forge-gui/res/blockdata/printsheets.txt @@ -6130,3 +6130,41 @@ Bloodchief's Thirst|ZNR|2 Roil Eruption|ZNR|2 Roiling Regrowth|ZNR|2 Kargan Warleader|ZNR|2 + +[ZNRModalDoubleFaceCards] +1 Agadeem's Awakening|ZNR +1 Emeria's Call|ZNR +1 Sea Gate Restoration|ZNR +1 Shatterskull Smashing|ZNR +1 Turntimber Symbiosis|ZNR +2 Branchloft Pathway|ZNR +2 Brightclimb Pathway|ZNR +2 Clearwater Pathway|ZNR +2 Cragcrown Pathway|ZNR +2 Glasspool Mimic|ZNR +2 Hagra Mauling|ZNR +2 Kazandu Mammoth|ZNR +2 Needleverge Pathway|ZNR +2 Ondu Inversion|ZNR +2 Riverglide Pathway|ZNR +2 Valakut Awakening|ZNR +6 Akoum Warrior|ZNR +6 Bala Ged Recovery|ZNR +6 Beyeen Veil|ZNR +6 Blackbloom Rogue|ZNR +6 Jwari Disruption|ZNR +6 Kabira Takedown|ZNR +6 Kazuul's Fury|ZNR +6 Khalni Ambush|ZNR +6 Makindi Stampede|ZNR +6 Malakir Rebirth|ZNR +6 Pelakka Predation|ZNR +6 Sejiri Shelter|ZNR +6 Silundi Vision|ZNR +6 Skyclave Cleric|ZNR +6 Song-Mad Treachery|ZNR +6 Spikefield Hazard|ZNR +6 Tangled Florahedron|ZNR +6 Umara Wizard|ZNR +6 Vastwood Fortification|ZNR +6 Zof Consumption|ZNR diff --git a/forge-gui/res/editions/Zendikar Rising.txt b/forge-gui/res/editions/Zendikar Rising.txt index ae4db3b9168..be26549a4c0 100644 --- a/forge-gui/res/editions/Zendikar Rising.txt +++ b/forge-gui/res/editions/Zendikar Rising.txt @@ -6,7 +6,8 @@ Code2=ZNR MciCode=znr Type=Expansion BoosterCovers=3 -Booster=9 Common:!dfc:!fromSheet("ZNR Secret Cards"), 3 Uncommon:!dfc:!fromSheet("ZNR Secret Cards"), 1 RareMythic:!dfc:!fromSheet("ZNR Secret Cards"), 1 dfc:!fromSheet("ZNR Secret Cards"), 1 BasicLand +Booster=10 Common:!dfc:!fromSheet("ZNR Secret Cards"), 3 Uncommon:!dfc:!fromSheet("ZNR Secret Cards"), 1 RareMythic:!dfc:!fromSheet("ZNR Secret Cards"), 1 BasicLand +BoosterReplaceSlotFromPrintSheet=ZNRModalDoubleFaceCards Prerelease=6 Boosters, 1 RareMythic+ [cards]