mirror of
https://github.com/correl/mage.git
synced 2025-03-17 09:16:26 -09:00
Updated booster generation for ISD.
(Double-faced cards instead of "C" common).
This commit is contained in:
parent
e949d046df
commit
28d887dff2
2 changed files with 378 additions and 313 deletions
|
@ -34,7 +34,6 @@ import mage.cards.ExpansionSet;
|
|||
import java.util.GregorianCalendar;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Innistrad extends ExpansionSet {
|
||||
|
@ -50,10 +49,11 @@ public class Innistrad extends ExpansionSet {
|
|||
this.blockName = "Innistrad";
|
||||
this.hasBoosters = true;
|
||||
this.numBoosterLands = 1;
|
||||
this.numBoosterCommon = 10;
|
||||
this.numBoosterCommon = 9;
|
||||
this.numBoosterUncommon = 3;
|
||||
this.numBoosterRare = 1;
|
||||
this.ratioBoosterMythic = 8;
|
||||
this.numBoosterDoubleFaced = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,14 +28,11 @@
|
|||
|
||||
package mage.cards;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import mage.Constants.Rarity;
|
||||
import mage.Constants.SetType;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
@ -43,7 +40,6 @@ import java.net.URLDecoder;
|
|||
import java.util.*;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -69,6 +65,7 @@ public abstract class ExpansionSet implements Serializable {
|
|||
protected int numBoosterCommon;
|
||||
protected int numBoosterUncommon;
|
||||
protected int numBoosterRare;
|
||||
protected int numBoosterDoubleFaced;
|
||||
protected int ratioBoosterMythic;
|
||||
|
||||
public ExpansionSet(String name, String code, String symbolCode, String packageName, Date releaseDate, SetType setType) {
|
||||
|
@ -330,6 +327,9 @@ public abstract class ExpansionSet implements Serializable {
|
|||
addToBooster(booster, this, Rarity.RARE);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < numBoosterDoubleFaced; i++) {
|
||||
addToBoosterDoubleFaced(booster, this);
|
||||
}
|
||||
|
||||
return booster;
|
||||
}
|
||||
|
@ -337,6 +337,34 @@ public abstract class ExpansionSet implements Serializable {
|
|||
protected void addToBooster(List<Card> booster, ExpansionSet set, Rarity rarity) {
|
||||
Card card = set.getRandom(rarity);
|
||||
if (card != null) {
|
||||
card = checkNotDoubleFaced(card, set, rarity);
|
||||
card = checkNotDuplicate(card, booster, set, rarity);
|
||||
Card newCard = card.copy();
|
||||
newCard.assignNewId();
|
||||
booster.add(newCard);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addToBoosterDoubleFaced(List<Card> booster, ExpansionSet set) {
|
||||
Card card = set.getRandomDoubleFaced();
|
||||
if (card != null) {
|
||||
Card newCard = card.copy();
|
||||
newCard.assignNewId();
|
||||
booster.add(newCard);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that card doesn't already exist in the booster. If so, tries to generate new one several times.
|
||||
*
|
||||
* @param cardToCheck
|
||||
* @param booster
|
||||
* @param set
|
||||
* @param rarity
|
||||
* @return
|
||||
*/
|
||||
private Card checkNotDuplicate(Card cardToCheck, List<Card> booster, ExpansionSet set, Rarity rarity) {
|
||||
Card card = cardToCheck;
|
||||
boolean duplicate = true;
|
||||
int retryCount = 5;
|
||||
while (duplicate && retryCount > 0) {
|
||||
|
@ -352,10 +380,29 @@ public abstract class ExpansionSet implements Serializable {
|
|||
}
|
||||
retryCount--;
|
||||
}
|
||||
Card newCard = card.copy();
|
||||
newCard.assignNewId();
|
||||
booster.add(newCard);
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that card is not double faced. If so, tries to generate new one several times.
|
||||
*
|
||||
* @param cardToCheck
|
||||
* @param set
|
||||
* @param rarity
|
||||
* @return
|
||||
*/
|
||||
private Card checkNotDoubleFaced(Card cardToCheck, ExpansionSet set, Rarity rarity) {
|
||||
int retryCount = 100;
|
||||
Card card = cardToCheck;
|
||||
while (card.canTransform()) {
|
||||
card = set.getRandom(rarity);
|
||||
retryCount--;
|
||||
if (retryCount <= 0) {
|
||||
logger.warn("Couldn't find non double faced card");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
protected boolean hasCardByName(List<Card> booster, String name) {
|
||||
|
@ -376,4 +423,22 @@ public abstract class ExpansionSet implements Serializable {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Card getRandomDoubleFaced() {
|
||||
int size = cards.size();
|
||||
if (size > 0) {
|
||||
Card card = cards.get(rnd.nextInt(size));
|
||||
int retryCount = 1000;
|
||||
while (!card.canTransform()) {
|
||||
card = cards.get(rnd.nextInt(size));
|
||||
retryCount--;
|
||||
if (retryCount <= 0) {
|
||||
logger.warn("Couldn't find double-faced card.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return card;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue