mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
Add booster generator for Battlebond packs
This commit is contained in:
parent
01cf9614d6
commit
d754410934
1 changed files with 95 additions and 2 deletions
|
@ -4,6 +4,7 @@ package mage.cards;
|
|||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.abilities.Ability;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.SetType;
|
||||
import mage.util.CardUtil;
|
||||
|
@ -12,6 +13,7 @@ import mage.util.RandomUtil;
|
|||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import mage.abilities.keyword.PartnerWithAbility;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -21,6 +23,7 @@ public abstract class ExpansionSet implements Serializable {
|
|||
public final static CardGraphicInfo NON_FULL_USE_VARIOUS = new CardGraphicInfo(null, true);
|
||||
public final static CardGraphicInfo FULL_ART_BFZ_VARIOUS = new CardGraphicInfo(FrameStyle.BFZ_FULL_ART_BASIC, true);
|
||||
|
||||
|
||||
public class SetCardInfo implements Serializable {
|
||||
|
||||
private final String name;
|
||||
|
@ -96,6 +99,7 @@ public abstract class ExpansionSet implements Serializable {
|
|||
protected int numBoosterDoubleFaced; // -1 = include normally 0 = exclude 1-n = include explicit
|
||||
protected int ratioBoosterMythic;
|
||||
protected boolean needsLegends = false;
|
||||
protected boolean PartnerMechanic = false;
|
||||
|
||||
protected int maxCardNumberInBooster; // used to omit cards with collector numbers beyond the regular cards in a set for boosters
|
||||
|
||||
|
@ -172,6 +176,35 @@ public abstract class ExpansionSet implements Serializable {
|
|||
return theBooster;
|
||||
}
|
||||
|
||||
protected int PartnerCheck(List<Card> booster, boolean partnerAllowed, int max, int i){
|
||||
|
||||
for (Ability ability:booster.get(booster.size() - 1).getAbilities()){
|
||||
//Check if fetched card has the PartnerWithAbility
|
||||
if (ability instanceof PartnerWithAbility) {
|
||||
//Check if the pack already contains a partner pair
|
||||
if (partnerAllowed){
|
||||
//Added card always replaces a common card
|
||||
Card card = CardRepository.instance.findCard(((PartnerWithAbility) ability).getPartnerName()).getCard();
|
||||
if (i<max){
|
||||
booster.add(card);
|
||||
}
|
||||
else{
|
||||
booster.set(0, card);
|
||||
}
|
||||
//2 return value indicates found partner
|
||||
return 2;
|
||||
}
|
||||
|
||||
else{
|
||||
//If partner already exists, remove card and loop again
|
||||
booster.remove(booster.size() - 1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected void addToBooster(List<Card> booster, List<CardInfo> cards) {
|
||||
if (!cards.isEmpty()) {
|
||||
CardInfo cardInfo = cards.remove(RandomUtil.nextInt(cards.size()));
|
||||
|
@ -185,19 +218,79 @@ public abstract class ExpansionSet implements Serializable {
|
|||
}
|
||||
|
||||
public List<Card> createBooster() {
|
||||
|
||||
if (needsLegends) {
|
||||
for (int i = 0; i < 100000; i++) {//don't want to somehow loop forever
|
||||
List<Card> booster = tryBooster();
|
||||
for (Card card : booster) {
|
||||
if (card.isLegendary() && card.isCreature()) {// Dominaria packs must contain at least one legendary creature.
|
||||
return booster;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//Battlebond packs alway contain both partners
|
||||
if (PartnerMechanic){
|
||||
List<Card> booster = createPartnerBooster();
|
||||
return booster;
|
||||
}
|
||||
return tryBooster();
|
||||
}
|
||||
|
||||
public List<Card> createPartnerBooster(){
|
||||
|
||||
List<Card> booster = new ArrayList<>();
|
||||
|
||||
boolean partnerAllowed = true;
|
||||
|
||||
List<CardInfo> uncommons = getCardsByRarity(Rarity.UNCOMMON);
|
||||
for (int i = 0; i < numBoosterUncommon; i++) {
|
||||
while (true){
|
||||
addToBooster(booster, uncommons);
|
||||
int check = PartnerCheck(booster, partnerAllowed, numBoosterUncommon - 1, i);
|
||||
if (check == 1){break;}
|
||||
if (check == 2){
|
||||
partnerAllowed = false;
|
||||
//Be sure to account for the added card
|
||||
if (i != numBoosterUncommon - 1){i+=1;}
|
||||
break;}
|
||||
}
|
||||
}
|
||||
|
||||
int numSpecialCommons = getNumberOfSpecialCommons();
|
||||
int numCommonsToGenerate = numBoosterCommon - numSpecialCommons;
|
||||
|
||||
List<CardInfo> commons = getCardsByRarity(Rarity.COMMON);
|
||||
for (int i = 0; i < numCommonsToGenerate; i++) {
|
||||
addToBooster(booster, commons);
|
||||
}
|
||||
|
||||
|
||||
List<CardInfo> rares = getCardsByRarity(Rarity.RARE);
|
||||
List<CardInfo> mythics = getCardsByRarity(Rarity.MYTHIC);
|
||||
for (int i = 0; i < numBoosterRare; i++) {
|
||||
if (ratioBoosterMythic > 0 && RandomUtil.nextInt(ratioBoosterMythic) == 0) {
|
||||
while (true){
|
||||
addToBooster(booster, mythics);
|
||||
int check = PartnerCheck(booster, partnerAllowed, -1, 1);
|
||||
if (check == 1){break;}
|
||||
if (check == 2){partnerAllowed = false; break;}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
while (true){
|
||||
addToBooster(booster, rares);
|
||||
int check = PartnerCheck(booster, partnerAllowed, -1, 1);
|
||||
if (check == 1){break;}
|
||||
if (check == 2){partnerAllowed = false; break;}
|
||||
}
|
||||
}
|
||||
}
|
||||
return booster;
|
||||
}
|
||||
|
||||
public List<Card> tryBooster() {
|
||||
List<Card> booster = new ArrayList<>();
|
||||
if (!hasBoosters) {
|
||||
|
|
Loading…
Reference in a new issue