Add booster generator for Battlebond packs

This commit is contained in:
Chatziargyriou Eleftheria 2018-06-22 18:57:13 +03:00 committed by GitHub
parent 01cf9614d6
commit d754410934
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) {