/** * readFile. * * @param file a {@link java.io.File} object. * @return a {@link java.util.HashMap} object. */ private Map<String, Integer> readFile(final String file) { final Map<String, Integer> map = new HashMap<>(); final Random r = MyRandom.getRandom(); final List<String> lines = FileUtil.readFile(file); for (final String line : lines) { if (line.trim().isEmpty()) { break; } if (line.startsWith(ReadPriceList.COMMENT)) { continue; } final String[] s = line.split("="); if (s.length < 2) { continue; } // skip line if not in correct format final String name = s[0].trim(); final String price = s[1].trim(); try { int val = Integer.parseInt(price.trim()); if (!(MagicColor.Constant.BASIC_LANDS.contains(name) || MagicColor.Constant.SNOW_LANDS.contains(name)) && !ForgeConstants.PRICES_BOOSTER_FILE.equals(file)) { float ff; if (r.nextInt(100) < 90) { ff = r.nextInt(10) * (float) .01; } else { // +/- 50% ff = r.nextInt(50) * (float) .01; } if (r.nextInt(100) < 50) { val = (int) (val * (1 - ff)); } else { // +ff% val = (int) (val * (1 + ff)); } } map.put(name, val); } catch (final NumberFormatException nfe) { Log.warn("NumberFormatException: " + nfe.getMessage()); } } return map; } // readFile()
/** * Constructor for SealedDeck. * * @param poolType a {@link java.lang.String} object. */ private SealedCardPoolGenerator(final LimitedPoolType poolType) { switch (poolType) { case Full: // Choose number of boosters if (!chooseNumberOfBoosters(new UnOpenedProduct(SealedProduct.Template.genericBooster))) { return; } landSetCode = CardEdition.Predicates.getRandomSetWithAllBasicLands(FModel.getMagicDb().getEditions()) .getCode(); break; case Block: case FantasyBlock: List<CardBlock> blocks = new ArrayList<CardBlock>(); Iterable<CardBlock> src = poolType == LimitedPoolType.Block ? FModel.getBlocks() : FModel.getFantasyBlocks(); for (CardBlock b : src) { blocks.add(b); } final CardBlock block = SGuiChoose.oneOrNone("Choose Block", blocks); if (block == null) { return; } final int nPacks = block.getCntBoostersSealed(); final Stack<String> sets = new Stack<String>(); for (CardEdition edition : block.getSets()) { sets.add(edition.getCode()); } for (String ms : block.getMetaSetNames()) { sets.push(ms); } if (sets.size() > 1) { final List<String> setCombos = getSetCombos(sets, nPacks); if (setCombos == null || setCombos.isEmpty()) { throw new RuntimeException( "Unsupported amount of packs (" + nPacks + ") in a Sealed Deck block!"); } final String p = setCombos.size() > 1 ? SGuiChoose.oneOrNone("Choose packs to play with", setCombos) : setCombos.get(0); if (p == null) { return; } for (String pz : TextUtil.split(p, ',')) { String[] pps = TextUtil.splitWithParenthesis(pz.trim(), ' '); String setCode = pps[pps.length - 1]; int nBoosters = pps.length > 1 ? Integer.parseInt(pps[0]) : 1; while (nBoosters-- > 0) { this.product.add(block.getBooster(setCode)); } } } else { IUnOpenedProduct prod = block.getBooster(sets.get(0)); for (int i = 0; i < nPacks; i++) { this.product.add(prod); } } landSetCode = block.getLandSet().getCode(); break; case Custom: String[] dList; final ArrayList<CustomLimited> customs = new ArrayList<CustomLimited>(); // get list of custom draft files final File dFolder = new File(ForgeConstants.SEALED_DIR); if (!dFolder.exists()) { throw new RuntimeException( "GenerateSealed : folder not found -- folder is " + dFolder.getAbsolutePath()); } if (!dFolder.isDirectory()) { throw new RuntimeException( "GenerateSealed : not a folder -- " + dFolder.getAbsolutePath()); } dList = dFolder.list(); for (final String element : dList) { if (element.endsWith(FILE_EXT)) { final List<String> dfData = FileUtil.readFile(ForgeConstants.SEALED_DIR + element); final CustomLimited cs = CustomLimited.parse(dfData, FModel.getDecks().getCubes()); if (cs.getSealedProductTemplate().getNumberOfCardsExpected() > 5) { // Do not allow too small cubes to be played as 'stand-alone'! customs.add(cs); } } } // present list to user if (customs.isEmpty()) { SOptionPane.showMessageDialog("No custom sealed files found."); return; } final CustomLimited draft = SGuiChoose.oneOrNone("Choose Custom Sealed Pool", customs); if (draft == null) { return; } UnOpenedProduct toAdd = new UnOpenedProduct(draft.getSealedProductTemplate(), draft.getCardPool()); toAdd.setLimitedPool(draft.isSingleton()); if (!chooseNumberOfBoosters(toAdd)) { return; } landSetCode = draft.getLandSetCode(); break; } }