- Simplify foil chance calculations, use double to represent chance.

This commit is contained in:
Agetian
2014-02-10 08:17:34 +00:00
parent 9957c12ff8
commit 30fda0e7a8
2 changed files with 5 additions and 4 deletions

View File

@@ -61,7 +61,7 @@ public class BoosterGenerator {
List<PrintSheet> sheetsUsed = new ArrayList<PrintSheet>(); List<PrintSheet> sheetsUsed = new ArrayList<PrintSheet>();
CardEdition edition = StaticData.instance().getEditions().get(template.getEdition()); CardEdition edition = StaticData.instance().getEditions().get(template.getEdition());
boolean hasFoil = edition != null && MyRandom.getRandom().nextInt(10000) <= edition.getFoilChanceInBooster() && edition.getFoilType() != FoilType.NOT_SUPPORTED; // FoilChanceInBooster is given with 1/10000th precision for a closer 21.43% approximation. boolean hasFoil = edition != null && MyRandom.getRandom().nextDouble() < edition.getFoilChanceInBooster() && edition.getFoilType() != FoilType.NOT_SUPPORTED;
boolean commonSlotFoil = !hasFoil ? false : edition.getFoilAlwaysInCommonSlot(); boolean commonSlotFoil = !hasFoil ? false : edition.getFoilAlwaysInCommonSlot();
String foilSlot = !hasFoil ? null : edition.getFoilAlwaysInCommonSlot() ? BoosterSlots.COMMON : Aggregates.random(template.getSlots()).getKey(); String foilSlot = !hasFoil ? null : edition.getFoilAlwaysInCommonSlot() ? BoosterSlots.COMMON : Aggregates.random(template.getSlots()).getKey();

View File

@@ -99,7 +99,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
private String alias = null; private String alias = null;
private boolean whiteBorder = false; private boolean whiteBorder = false;
private FoilType foilType = FoilType.NOT_SUPPORTED; private FoilType foilType = FoilType.NOT_SUPPORTED;
private int foilChanceInBooster = 0; private double foilChanceInBooster = 0;
private boolean foilAlwaysInCommonSlot = false; private boolean foilAlwaysInCommonSlot = false;
private final CardInSet[] cards; private final CardInSet[] cards;
@@ -151,7 +151,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
public String getName() { return name; } public String getName() { return name; }
public String getAlias() { return alias; } public String getAlias() { return alias; }
public FoilType getFoilType() { return foilType; } public FoilType getFoilType() { return foilType; }
public int getFoilChanceInBooster() { return foilChanceInBooster; } public double getFoilChanceInBooster() { return foilChanceInBooster; }
public boolean getFoilAlwaysInCommonSlot() { return foilAlwaysInCommonSlot; } public boolean getFoilAlwaysInCommonSlot() { return foilAlwaysInCommonSlot; }
public CardInSet[] getCards() { return cards; } public CardInSet[] getCards() { return cards; }
@@ -286,7 +286,8 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
res.foilType = FoilType.NOT_SUPPORTED; res.foilType = FoilType.NOT_SUPPORTED;
break; break;
} }
res.foilChanceInBooster = section.getInt("FoilChanceInBooster", 2143); // uses 1:10000 precision, 21.43% is roughly every 70th card foiled res.foilChanceInBooster = section.getInt("FoilChanceInBooster", 2143) / 10000.0F;
System.out.println("chance = " + res.foilChanceInBooster);
res.foilAlwaysInCommonSlot = section.getBoolean("FoilAlwaysInCommonSlot", false); res.foilAlwaysInCommonSlot = section.getBoolean("FoilAlwaysInCommonSlot", false);
return res; return res;