mirror of
https://github.com/magefree/mage.git
synced 2026-01-10 04:42:07 -08:00
updated sets and added booster packs - commented out planechase set
This commit is contained in:
parent
ad83ccabf4
commit
5acf46bb60
21 changed files with 379 additions and 151 deletions
|
|
@ -34,15 +34,20 @@ import java.io.Serializable;
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.Constants.Rarity;
|
||||
import mage.util.Logging;
|
||||
|
||||
/**
|
||||
|
|
@ -53,16 +58,32 @@ public abstract class ExpansionSet implements Serializable {
|
|||
|
||||
private final static Logger logger = Logging.getLogger(ExpansionSet.class.getName());
|
||||
|
||||
protected static Random rnd = new Random();
|
||||
|
||||
protected String name;
|
||||
protected String code;
|
||||
protected String symbolCode;
|
||||
protected Date releaseDate;
|
||||
protected ExpansionSet parentSet;
|
||||
protected List<Class> cards;
|
||||
protected boolean core;
|
||||
protected Map<Rarity, List<Class>> rarities;
|
||||
|
||||
public ExpansionSet(String name, String code, String symbolCode, String packageName) {
|
||||
protected String blockName;
|
||||
protected int numBoosterLands;
|
||||
protected int numBoosterCommon;
|
||||
protected int numBoosterUncommon;
|
||||
protected int numBoosterRare;
|
||||
protected int ratioBoosterMythic;
|
||||
|
||||
public ExpansionSet(String name, String code, String symbolCode, String packageName, Date releaseDate, boolean core) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
this.symbolCode = symbolCode;
|
||||
this.releaseDate = releaseDate;
|
||||
this.core = core;
|
||||
this.cards = getCardClassesForPackage(packageName);
|
||||
this.rarities = getCardsByRarity();
|
||||
}
|
||||
|
||||
public List<Class> getCards() {
|
||||
|
|
@ -81,6 +102,14 @@ public abstract class ExpansionSet implements Serializable {
|
|||
return symbolCode;
|
||||
}
|
||||
|
||||
public Date getReleaseDate() {
|
||||
return releaseDate;
|
||||
}
|
||||
|
||||
public boolean isCore() {
|
||||
return core;
|
||||
}
|
||||
|
||||
public Card createCard(Class clazz) {
|
||||
try {
|
||||
Constructor<?> con = clazz.getConstructor(new Class[]{UUID.class});
|
||||
|
|
@ -143,4 +172,53 @@ public abstract class ExpansionSet implements Serializable {
|
|||
return classes;
|
||||
}
|
||||
|
||||
private Map<Rarity, List<Class>> getCardsByRarity() {
|
||||
Map<Rarity, List<Class>> cardsByRarity = new HashMap<Rarity, List<Class>>();
|
||||
|
||||
for (Class clazz: cards) {
|
||||
Card card = createCard(clazz);
|
||||
if (!cardsByRarity.containsKey(card.getRarity()))
|
||||
cardsByRarity.put(card.getRarity(), new ArrayList<Class>());
|
||||
cardsByRarity.get(card.getRarity()).add(clazz);
|
||||
}
|
||||
|
||||
return cardsByRarity;
|
||||
}
|
||||
|
||||
public List<Card> createBooster() {
|
||||
List<Card> booster = new ArrayList<Card>();
|
||||
|
||||
if (parentSet != null) {
|
||||
parentSet.getRandom(Rarity.LAND);
|
||||
}
|
||||
else {
|
||||
booster.add(getRandom(Rarity.LAND));
|
||||
}
|
||||
for (int i = 0; i < numBoosterCommon; i++) {
|
||||
booster.add(getRandom(Rarity.COMMON));
|
||||
}
|
||||
for (int i = 0; i < numBoosterUncommon; i++) {
|
||||
booster.add(getRandom(Rarity.UNCOMMON));
|
||||
}
|
||||
for (int i = 0; i < numBoosterRare; i++) {
|
||||
if (rnd.nextInt(ratioBoosterMythic) == 1) {
|
||||
booster.add(getRandom(Rarity.MYTHIC));
|
||||
}
|
||||
else {
|
||||
booster.add(getRandom(Rarity.RARE));
|
||||
}
|
||||
}
|
||||
|
||||
return booster;
|
||||
}
|
||||
|
||||
protected Card getRandom(Rarity rarity) {
|
||||
if (!rarities.containsKey(rarity))
|
||||
return null;
|
||||
int size = rarities.get(rarity).size();
|
||||
if (size > 0) {
|
||||
return createCard(rarities.get(rarity).get(rnd.nextInt(size)));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import mage.cards.*;
|
|||
import java.io.Serializable;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import mage.game.GameException;
|
||||
|
||||
public class Deck implements Serializable {
|
||||
|
||||
|
|
@ -39,14 +40,22 @@ public class Deck implements Serializable {
|
|||
private Set<Card> cards = new LinkedHashSet<Card>();
|
||||
private Set<Card> sideboard = new LinkedHashSet<Card>();
|
||||
|
||||
public static Deck load(DeckCardLists deckCardLists) {
|
||||
public static Deck load(DeckCardLists deckCardLists) throws GameException {
|
||||
Deck deck = new Deck();
|
||||
deck.setName(deckCardLists.getName());
|
||||
for (String cardName: deckCardLists.getCards()) {
|
||||
deck.cards.add(CardImpl.createCard(cardName));
|
||||
Card card = CardImpl.createCard(cardName);
|
||||
if (card != null)
|
||||
deck.cards.add(CardImpl.createCard(cardName));
|
||||
else
|
||||
throw new GameException("Error loading card - " + cardName + " for deck - " + deck.getName());
|
||||
}
|
||||
for (String cardName: deckCardLists.getSideboard()) {
|
||||
deck.sideboard.add(CardImpl.createCard(cardName));
|
||||
Card card = CardImpl.createCard(cardName);
|
||||
if (card != null)
|
||||
deck.sideboard.add(CardImpl.createCard(cardName));
|
||||
else
|
||||
throw new GameException("Error loading card - " + cardName + " for deck - " + deck.getName());
|
||||
}
|
||||
|
||||
return deck;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue