mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
move art index tracking from pack superclasses to booster pack classes
This commit is contained in:
1
.project
1
.project
@@ -34,7 +34,6 @@
|
|||||||
<natures>
|
<natures>
|
||||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
<nature>org.eclipse.pde.PluginNature</nature>
|
|
||||||
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
|
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public class BoosterData extends PackData {
|
|||||||
private final int nSpecial;
|
private final int nSpecial;
|
||||||
private final int nDoubleFaced;
|
private final int nDoubleFaced;
|
||||||
private final int foilRate;
|
private final int foilRate;
|
||||||
|
private final int artIndices;
|
||||||
private static final int CARDS_PER_BOOSTER = 15;
|
private static final int CARDS_PER_BOOSTER = 15;
|
||||||
|
|
||||||
public BoosterData(String edition, String editionLand, int nC, int nU, int nR, int nS, int nDF, int artIndices) {
|
public BoosterData(String edition, String editionLand, int nC, int nU, int nR, int nS, int nDF, int artIndices) {
|
||||||
@@ -23,18 +24,15 @@ public class BoosterData extends PackData {
|
|||||||
(nC + nR + nU + nS + nDF) > 10 ? BoosterData.CARDS_PER_BOOSTER - nC - nR - nU - nS - nDF : 0, 68);
|
(nC + nR + nU + nS + nDF) > 10 ? BoosterData.CARDS_PER_BOOSTER - nC - nR - nU - nS - nDF : 0, 68);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BoosterData(String edition, String editionLand, int nC, int nU, int nR, int nS, int nDF, int artIndices, int nL, int oneFoilPer) {
|
public BoosterData(String edition, String editionLand, int nC, int nU, int nR, int nS, int nDF, int artIndices0, int nL, int oneFoilPer) {
|
||||||
super(edition, editionLand, nL > 0 ? nL : 0, artIndices);
|
super(edition, editionLand, nL > 0 ? nL : 0);
|
||||||
this.nCommon = nC;
|
this.nCommon = nC;
|
||||||
this.nUncommon = nU;
|
this.nUncommon = nU;
|
||||||
this.nRare = nR;
|
this.nRare = nR;
|
||||||
this.nSpecial = nS;
|
this.nSpecial = nS;
|
||||||
this.nDoubleFaced = nDF;
|
this.nDoubleFaced = nDF;
|
||||||
this.foilRate = oneFoilPer;
|
this.foilRate = oneFoilPer;
|
||||||
}
|
artIndices = artIndices0;
|
||||||
|
|
||||||
public final int getCommon() {
|
|
||||||
return this.nCommon;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Predicate<CardPrinted> getEditionFilter() {
|
public final Predicate<CardPrinted> getEditionFilter() {
|
||||||
@@ -45,6 +43,10 @@ public class BoosterData extends PackData {
|
|||||||
return IPaperCard.Predicates.printedInSets(getLandEdition());
|
return IPaperCard.Predicates.printedInSets(getLandEdition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int getCommon() {
|
||||||
|
return this.nCommon;
|
||||||
|
}
|
||||||
|
|
||||||
public final int getUncommon() {
|
public final int getUncommon() {
|
||||||
return this.nUncommon;
|
return this.nUncommon;
|
||||||
}
|
}
|
||||||
@@ -69,6 +71,10 @@ public class BoosterData extends PackData {
|
|||||||
return this.foilRate;
|
return this.foilRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getArtIndices() {
|
||||||
|
return artIndices;
|
||||||
|
}
|
||||||
|
|
||||||
private void _append(StringBuilder s, int val, String name) {
|
private void _append(StringBuilder s, int val, String name) {
|
||||||
if (0 >= val) {
|
if (0 >= val) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class FatPackData extends PackData {
|
|||||||
|
|
||||||
public FatPackData(String edition0, String landEdition0, int nBoosters, int nBasicLands)
|
public FatPackData(String edition0, String landEdition0, int nBoosters, int nBasicLands)
|
||||||
{
|
{
|
||||||
super(edition0, landEdition0, nBasicLands, 1);
|
super(edition0, landEdition0, nBasicLands);
|
||||||
cntBoosters = nBoosters;
|
cntBoosters = nBoosters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ public class PackData {
|
|||||||
private final String edition;
|
private final String edition;
|
||||||
private final String landEdition;
|
private final String landEdition;
|
||||||
private final int cntLands;
|
private final int cntLands;
|
||||||
private final int artIndices;
|
|
||||||
|
|
||||||
public final String getEdition() {
|
public final String getEdition() {
|
||||||
return edition;
|
return edition;
|
||||||
@@ -40,17 +39,12 @@ public class PackData {
|
|||||||
return cntLands;
|
return cntLands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getArtIndices() {
|
public PackData(String edition0, String landEdition0, int nBasicLands)
|
||||||
return artIndices;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PackData(String edition0, String landEdition0, int nBasicLands, int artIndices0)
|
|
||||||
{
|
{
|
||||||
if (null == edition0) { throw new NullArgumentException("edition0"); }
|
if (null == edition0) { throw new NullArgumentException("edition0"); }
|
||||||
edition = edition0;
|
edition = edition0;
|
||||||
landEdition = landEdition0;
|
landEdition = landEdition0;
|
||||||
cntLands = nBasicLands;
|
cntLands = nBasicLands;
|
||||||
artIndices = artIndices0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Function<? super PackData, String> FN_GET_CODE = new Function<PackData, String>() {
|
public static final Function<? super PackData, String> FN_GET_CODE = new Function<PackData, String>() {
|
||||||
@@ -61,7 +55,7 @@ public class PackData {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -76,7 +70,7 @@ public class PackData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int hashCode() {
|
public int hashCode() {
|
||||||
return edition.hashCode();
|
return edition.hashCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,12 @@ import com.google.common.base.Function;
|
|||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.BoosterData;
|
import forge.card.BoosterData;
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
|
import forge.util.MyRandom;
|
||||||
|
|
||||||
public class BoosterPack extends OpenablePack {
|
public class BoosterPack extends OpenablePack {
|
||||||
|
private final int artIndex;
|
||||||
|
private final int hash;
|
||||||
|
|
||||||
public static final Function<CardEdition, BoosterPack> FN_FROM_SET = new Function<CardEdition, BoosterPack>() {
|
public static final Function<CardEdition, BoosterPack> FN_FROM_SET = new Function<CardEdition, BoosterPack>() {
|
||||||
@Override
|
@Override
|
||||||
public BoosterPack apply(final CardEdition arg1) {
|
public BoosterPack apply(final CardEdition arg1) {
|
||||||
@@ -35,6 +39,12 @@ public class BoosterPack extends OpenablePack {
|
|||||||
|
|
||||||
public BoosterPack(final String name0, final BoosterData boosterData) {
|
public BoosterPack(final String name0, final BoosterData boosterData) {
|
||||||
super(name0, boosterData);
|
super(name0, boosterData);
|
||||||
|
artIndex = MyRandom.getRandom().nextInt(boosterData.getArtIndices()) + 1;
|
||||||
|
hash = super.hashCode() ^ artIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int getArtIndex() {
|
||||||
|
return artIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -50,4 +60,21 @@ public class BoosterPack extends OpenablePack {
|
|||||||
public BoosterData getBoosterData() {
|
public BoosterData getBoosterData() {
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!super.equals(obj)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
BoosterPack other = (BoosterPack)obj;
|
||||||
|
return artIndex == other.artIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int hashCode() {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,10 @@ import forge.card.BoosterData;
|
|||||||
import forge.card.BoosterGenerator;
|
import forge.card.BoosterGenerator;
|
||||||
import forge.card.CardRulesPredicates;
|
import forge.card.CardRulesPredicates;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
import forge.util.MyRandom;
|
|
||||||
|
|
||||||
public abstract class OpenablePack implements InventoryItemFromSet {
|
public abstract class OpenablePack implements InventoryItemFromSet {
|
||||||
protected final BoosterData contents;
|
protected final BoosterData contents;
|
||||||
protected final String name;
|
protected final String name;
|
||||||
private final int artIndex;
|
|
||||||
private final int hash;
|
private final int hash;
|
||||||
private List<CardPrinted> cards = null;
|
private List<CardPrinted> cards = null;
|
||||||
private BoosterGenerator generator = null;
|
private BoosterGenerator generator = null;
|
||||||
@@ -45,8 +43,7 @@ public abstract class OpenablePack implements InventoryItemFromSet {
|
|||||||
if (null == boosterData) { throw new NullArgumentException("boosterData"); }
|
if (null == boosterData) { throw new NullArgumentException("boosterData"); }
|
||||||
contents = boosterData;
|
contents = boosterData;
|
||||||
name = name0;
|
name = name0;
|
||||||
artIndex = MyRandom.getRandom().nextInt(boosterData.getArtIndices()) + 1;
|
hash = name.hashCode() ^ getClass().hashCode() ^ contents.hashCode();
|
||||||
hash = name.hashCode() ^ getClass().hashCode() ^ contents.hashCode() ^ artIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,10 +60,6 @@ public abstract class OpenablePack implements InventoryItemFromSet {
|
|||||||
return contents.getEdition();
|
return contents.getEdition();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getArtIndex() {
|
|
||||||
return artIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public final List<CardPrinted> getCards() {
|
public final List<CardPrinted> getCards() {
|
||||||
if (null == cards) {
|
if (null == cards) {
|
||||||
cards = generate();
|
cards = generate();
|
||||||
@@ -80,7 +73,7 @@ public abstract class OpenablePack implements InventoryItemFromSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -91,12 +84,11 @@ public abstract class OpenablePack implements InventoryItemFromSet {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
OpenablePack other = (OpenablePack)obj;
|
OpenablePack other = (OpenablePack)obj;
|
||||||
return name.equals(other.name) && contents.equals(other.contents) && artIndex == other.artIndex;
|
return name.equals(other.name) && contents.equals(other.contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int hashCode() {
|
public int hashCode() {
|
||||||
System.out.println(String.format("returning hash: %d for edition=%s; idx=%d", hash, getEdition(), getArtIndex()));
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user