diff --git a/Mage.Sets/src/mage/sets/ShadowsOverInnistrad.java b/Mage.Sets/src/mage/sets/ShadowsOverInnistrad.java index 2eac9006d24..c09a17e4511 100644 --- a/Mage.Sets/src/mage/sets/ShadowsOverInnistrad.java +++ b/Mage.Sets/src/mage/sets/ShadowsOverInnistrad.java @@ -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> 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 booster) { + for (int i = 0; i < numBoosterDoubleFaced; i++) { + List doubleFacedCards; + if (rnd.nextInt(15) < 10) { + doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.COMMON); + } else { + doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.UNCOMMON); + } + addToBooster(booster, doubleFacedCards); + } + } + + public List getDoubleFacedCardsByRarity(Rarity rarity) { + List 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 booster, int number) { + // number is here always 1 + List doubleFacedCards; + if (rnd.nextInt(8) > 0) { + doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.RARE); + } else { + doubleFacedCards = getDoubleFacedCardsByRarity(Rarity.MYTHIC); + } + addToBooster(booster, doubleFacedCards); + } + } diff --git a/Mage/src/main/java/mage/cards/ExpansionSet.java b/Mage/src/main/java/mage/cards/ExpansionSet.java index eb1666bdafd..a81f82ce04b 100644 --- a/Mage/src/main/java/mage/cards/ExpansionSet.java +++ b/Mage/src/main/java/mage/cards/ExpansionSet.java @@ -163,14 +163,23 @@ public abstract class ExpansionSet implements Serializable { } } } + int numSpecialCommons = getNumberOfSpecialCommons(); + int numCommonsToGenerate = numBoosterCommon - numSpecialCommons; + List 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 uncommons = getCardsByRarity(Rarity.UNCOMMON); for (int i = 0; i < numBoosterUncommon; i++) { addToBooster(booster, uncommons); } + List rares = getCardsByRarity(Rarity.RARE); List 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 specialBonus = getSpecialBonus(); - if (specialBonus != null) { - specialCards += specialBonus.size(); - } - List specialMythic = getSpecialMythic(); - if (specialMythic != null) { - specialCards += specialMythic.size(); - } - List specialRare = getSpecialRare(); - if (specialRare != null) { - specialCards += specialRare.size(); - } - List specialUncommon = getSpecialUncommon(); - if (specialUncommon != null) { - specialCards += specialUncommon.size(); - } - List 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 booster) { + public void addDoubleFace(List 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 booster, int number) { + + } + + private void addSpecial(List booster) { + int specialCards = 0; + List specialBonus = getSpecialBonus(); + if (specialBonus != null) { + specialCards += specialBonus.size(); + } + List specialMythic = getSpecialMythic(); + if (specialMythic != null) { + specialCards += specialMythic.size(); + } + List specialRare = getSpecialRare(); + if (specialRare != null) { + specialCards += specialRare.size(); + } + List specialUncommon = getSpecialUncommon(); + if (specialUncommon != null) { + specialCards += specialUncommon.size(); + } + List 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(); } + }