* Fixed generation of double faced cards of SOI boosters (fixes #1810).

This commit is contained in:
LevelX2 2016-05-01 12:50:47 +02:00
parent 8f38daa117
commit 993e1aaebf
2 changed files with 161 additions and 68 deletions

View file

@ -27,8 +27,16 @@
*/
package mage.sets;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.GregorianCalendar;
import java.util.List;
import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.Rarity;
import mage.constants.SetType;
/**
@ -43,6 +51,8 @@ public class ShadowsOverInnistrad extends ExpansionSet {
return fINSTANCE;
}
protected final EnumMap<Rarity, List<CardInfo>> savedDoubleFacedCards;
private ShadowsOverInnistrad() {
super("Shadows over Innistrad", "SOI", "mage.sets.shadowsoverinnistrad", new GregorianCalendar(2016, 3, 8).getTime(), SetType.EXPANSION);
this.blockName = "Shadows over Innistrad";
@ -53,5 +63,55 @@ public class ShadowsOverInnistrad extends ExpansionSet {
this.numBoosterRare = 1;
this.ratioBoosterMythic = 8;
this.numBoosterDoubleFaced = 1;
savedDoubleFacedCards = new EnumMap<>(Rarity.class);
}
/* add double faced card for SOI booster
* add only common or uncommon
*/
@Override
public void addDoubleFace(List<Card> booster) {
for (int i = 0; i < numBoosterDoubleFaced; i++) {
List<CardInfo> doubleFacedCards;
if (rnd.nextInt(15) < 10) {
doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.COMMON);
} else {
doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.UNCOMMON);
}
addToBooster(booster, doubleFacedCards);
}
}
public List<CardInfo> getDoubleFacedCardsByRarity(Rarity rarity) {
List<CardInfo> savedCardsInfos = savedDoubleFacedCards.get(rarity);
if (savedCardsInfos == null) {
CardCriteria criteria = new CardCriteria();
criteria.setCodes(getCode());
criteria.rarities(rarity);
criteria.doubleFaced(true);
savedCardsInfos = CardRepository.instance.findCards(criteria);
savedDoubleFacedCards.put(rarity, savedCardsInfos);
}
// Return a copy of the saved cards information, as not to let modify the original.
return new ArrayList<>(savedCardsInfos);
}
@Override
public int getNumberOfSpecialCommons() {
// Then about an eighth of the packs will have a second double-faced card, which will be a rare or mythic rare.
return rnd.nextInt(8) == 0 ? 1 : 0;
}
@Override
public void addSpecialCommon(List<Card> booster, int number) {
// number is here always 1
List<CardInfo> doubleFacedCards;
if (rnd.nextInt(8) > 0) {
doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.RARE);
} else {
doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.MYTHIC);
}
addToBooster(booster, doubleFacedCards);
}
}

View file

@ -163,14 +163,23 @@ public abstract class ExpansionSet implements Serializable {
}
}
}
int numSpecialCommons = getNumberOfSpecialCommons();
int numCommonsToGenerate = numBoosterCommon - numSpecialCommons;
List<CardInfo> commons = getCardsByRarity(Rarity.COMMON);
for (int i = 0; i < numBoosterCommon; i++) {
for (int i = 0; i < numCommonsToGenerate; i++) {
addToBooster(booster, commons);
}
if (numSpecialCommons > 0) { // e.g. used to conditionaly replace common cards in the booster
addSpecialCommon(booster, numSpecialCommons);
}
List<CardInfo> uncommons = getCardsByRarity(Rarity.UNCOMMON);
for (int i = 0; i < numBoosterUncommon; i++) {
addToBooster(booster, uncommons);
}
List<CardInfo> rares = getCardsByRarity(Rarity.RARE);
List<CardInfo> mythics = getCardsByRarity(Rarity.MYTHIC);
for (int i = 0; i < numBoosterRare; i++) {
@ -182,75 +191,11 @@ public abstract class ExpansionSet implements Serializable {
}
if (numBoosterDoubleFaced > 0) {
this.addDoubleFace(booster);
addDoubleFace(booster);
}
if (numBoosterSpecial > 0) {
int specialCards = 0;
List<CardInfo> specialBonus = getSpecialBonus();
if (specialBonus != null) {
specialCards += specialBonus.size();
}
List<CardInfo> specialMythic = getSpecialMythic();
if (specialMythic != null) {
specialCards += specialMythic.size();
}
List<CardInfo> specialRare = getSpecialRare();
if (specialRare != null) {
specialCards += specialRare.size();
}
List<CardInfo> specialUncommon = getSpecialUncommon();
if (specialUncommon != null) {
specialCards += specialUncommon.size();
}
List<CardInfo> specialCommon = getSpecialCommon();
if (specialCommon != null) {
specialCards += specialCommon.size();
}
if (specialCards > 0) {
for (int i = 0; i < numBoosterSpecial; i++) {
if (rnd.nextInt(15) < 10) {
if (specialCommon != null && !specialCommon.isEmpty()) {
addToBooster(booster, specialCommon);
} else {
i--;
}
continue;
}
if (rnd.nextInt(4) < 3) {
if (specialUncommon != null && !specialUncommon.isEmpty()) {
addToBooster(booster, specialUncommon);
} else {
i--;
}
continue;
}
if (rnd.nextInt(8) < 7) {
if (specialRare != null && !specialRare.isEmpty()) {
addToBooster(booster, specialRare);
} else {
i--;
}
continue;
}
if (specialMythic != null && !specialMythic.isEmpty()) {
if (specialBonus != null && !specialBonus.isEmpty()) {
if (rnd.nextInt(3) < 2) {
addToBooster(booster, specialMythic);
continue;
}
} else {
addToBooster(booster, specialMythic);
continue;
}
} else {
i--;
}
if (specialBonus != null && !specialBonus.isEmpty()) {
addToBooster(booster, specialBonus);
}
}
}
addSpecial(booster);
}
return booster;
@ -259,7 +204,7 @@ public abstract class ExpansionSet implements Serializable {
/* add double faced card for Innistrad booster
* rarity near as the normal distribution
*/
private void addDoubleFace(List<Card> booster) {
public void addDoubleFace(List<Card> booster) {
for (int i = 0; i < numBoosterDoubleFaced; i++) {
CardCriteria criteria = new CardCriteria();
criteria.setCodes(this.code).doubleFaced(true);
@ -277,6 +222,93 @@ public abstract class ExpansionSet implements Serializable {
}
}
/**
* Can be overwritten if sometimes special cards will be generated instead
* of common slots
*
* @return
*/
public int getNumberOfSpecialCommons() {
return 0;
}
/**
* Can be overwritten to add a replacement for common card in boosters
*
* @param booster
*/
public void addSpecialCommon(List<Card> booster, int number) {
}
private void addSpecial(List<Card> booster) {
int specialCards = 0;
List<CardInfo> specialBonus = getSpecialBonus();
if (specialBonus != null) {
specialCards += specialBonus.size();
}
List<CardInfo> specialMythic = getSpecialMythic();
if (specialMythic != null) {
specialCards += specialMythic.size();
}
List<CardInfo> specialRare = getSpecialRare();
if (specialRare != null) {
specialCards += specialRare.size();
}
List<CardInfo> specialUncommon = getSpecialUncommon();
if (specialUncommon != null) {
specialCards += specialUncommon.size();
}
List<CardInfo> specialCommon = getSpecialCommon();
if (specialCommon != null) {
specialCards += specialCommon.size();
}
if (specialCards > 0) {
for (int i = 0; i < numBoosterSpecial; i++) {
if (rnd.nextInt(15) < 10) {
if (specialCommon != null && !specialCommon.isEmpty()) {
addToBooster(booster, specialCommon);
} else {
i--;
}
continue;
}
if (rnd.nextInt(4) < 3) {
if (specialUncommon != null && !specialUncommon.isEmpty()) {
addToBooster(booster, specialUncommon);
} else {
i--;
}
continue;
}
if (rnd.nextInt(8) < 7) {
if (specialRare != null && !specialRare.isEmpty()) {
addToBooster(booster, specialRare);
} else {
i--;
}
continue;
}
if (specialMythic != null && !specialMythic.isEmpty()) {
if (specialBonus != null && !specialBonus.isEmpty()) {
if (rnd.nextInt(3) < 2) {
addToBooster(booster, specialMythic);
continue;
}
} else {
addToBooster(booster, specialMythic);
continue;
}
} else {
i--;
}
if (specialBonus != null && !specialBonus.isEmpty()) {
addToBooster(booster, specialBonus);
}
}
}
}
public boolean hasBoosters() {
return hasBoosters;
}
@ -335,4 +367,5 @@ public abstract class ExpansionSet implements Serializable {
public void removeSavedCards() {
savedCards.clear();
}
}