From 9500b3d95141c739eeebd9943eb8feb33f746491 Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Sat, 8 Feb 2014 17:07:15 +0000 Subject: [PATCH] acquire booster edition once --- .../java/forge/card/BoosterGenerator.java | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/forge-core/src/main/java/forge/card/BoosterGenerator.java b/forge-core/src/main/java/forge/card/BoosterGenerator.java index 7f625f9af95..31f6e156046 100644 --- a/forge-core/src/main/java/forge/card/BoosterGenerator.java +++ b/forge-core/src/main/java/forge/card/BoosterGenerator.java @@ -61,39 +61,34 @@ public class BoosterGenerator { return cachedSheets.get(key); } - private static final String getFoilSlot(SealedProduct.Template booster) { - String setCode = booster.getEdition() != null ? booster.getEdition() : null; - CardEdition set = setCode != null ? StaticData.instance().getEditions().getEditionByCodeOrThrow(setCode) : null; - String foilSlot; - - if (set == null || set.getFoilType() == FoilType.NOT_SUPPORTED) { - foilSlot = null; // null == no foil is generated - } - else if (set.getFoilAlwaysInCommonSlot()) { - foilSlot = BoosterSlots.COMMON; + private static final String getFoilSlot(CardEdition edition, SealedProduct.Template booster) { + if (edition == null) { + return null; // null == no foil is generated + } else if (edition.getFoilAlwaysInCommonSlot()) { + return BoosterSlots.COMMON; } else { - foilSlot = Aggregates.random(booster.getSlots()).getKey(); + return Aggregates.random(booster.getSlots()).getKey(); } - - return foilSlot; } private static final PaperCard generateFoilCard(PrintSheet sheet) { return StaticData.instance().getCommonCards().getFoiled(sheet.random(1, true).get(0)); } - public static final List getBoosterPack(SealedProduct.Template booster) { + public static final List getBoosterPack(SealedProduct.Template template) { List result = new ArrayList(); List sheetsUsed = new ArrayList(); - String foilSlot = getFoilSlot(booster); - boolean hasFoil = MyRandom.getRandom().nextInt(100) <= StaticData.instance().getEditions().getEditionByCodeOrThrow(booster.getEdition()).getFoilChanceInBooster(); + CardEdition edition = StaticData.instance().getEditions().get(template.getEdition()); + String foilSlot = getFoilSlot(edition, template); + + boolean hasFoil = edition != null && MyRandom.getRandom().nextInt(100) <= edition.getFoilChanceInBooster() && edition.getFoilType() != FoilType.NOT_SUPPORTED; - for(Pair slot : booster.getSlots()) { + for(Pair slot : template.getSlots()) { String slotType = slot.getLeft(); // add expansion symbol here? int numCards = slot.getRight().intValue(); String[] sType = TextUtil.splitWithParenthesis(slotType, ' '); - String setCode = sType.length == 1 && booster.getEdition() != null ? booster.getEdition() : null; + String setCode = sType.length == 1 && template.getEdition() != null ? template.getEdition() : null; String sheetKey = StaticData.instance().getEditions().contains(setCode) ? slotType.trim() + " " + setCode: slotType.trim(); PrintSheet ps = getPrintSheet(sheetKey);