mirror of
https://github.com/correl/mage.git
synced 2025-01-11 19:13:02 +00:00
* Rework of booster generation to reduce DB load while starting a tournament.
This commit is contained in:
parent
354daf736e
commit
b4636b2ce1
9 changed files with 174 additions and 111 deletions
|
@ -54,6 +54,8 @@ public class DragonsMaze extends ExpansionSet {
|
|||
return fINSTANCE;
|
||||
}
|
||||
|
||||
List<CardInfo> savedSpecialRares = new ArrayList<>();
|
||||
|
||||
private DragonsMaze() {
|
||||
super("Dragon's Maze", "DGM", "mage.sets.dragonsmaze", new GregorianCalendar(2013, 5, 03).getTime(), SetType.EXPANSION);
|
||||
this.blockName = "Return to Ravnica";
|
||||
|
@ -69,10 +71,23 @@ public class DragonsMaze extends ExpansionSet {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<CardInfo> getCommon() {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code).rarities(Rarity.COMMON).notTypes(CardType.LAND).doubleFaced(false);
|
||||
return CardRepository.instance.findCards(criteria);
|
||||
public List<CardInfo> getCardsByRarity(Rarity rarity) {
|
||||
if (rarity.equals(Rarity.COMMON)) {
|
||||
List<CardInfo> savedCardsInfos = savedCards.get(rarity);
|
||||
if (savedCardsInfos == null) {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code).notTypes(CardType.LAND);
|
||||
criteria.rarities(rarity).doubleFaced(false);
|
||||
if (maxCardNumberInBooster != Integer.MAX_VALUE) {
|
||||
criteria.maxCardNumber(maxCardNumberInBooster);
|
||||
}
|
||||
savedCardsInfos = CardRepository.instance.findCards(criteria);
|
||||
savedCards.put(rarity, savedCardsInfos);
|
||||
}
|
||||
return savedCardsInfos;
|
||||
} else {
|
||||
return super.getCardsByRarity(rarity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,39 +99,42 @@ public class DragonsMaze extends ExpansionSet {
|
|||
|
||||
@Override
|
||||
public List<CardInfo> getSpecialRare() {
|
||||
List<CardInfo> specialRare = new ArrayList<>();
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes("GTC").name("Breeding Pool");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("GTC").name("Godless Shrine");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("GTC").name("Sacred Foundry");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("GTC").name("Stomping Ground");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("GTC").name("Watery Grave");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
List<CardInfo> specialRares = new ArrayList<>();
|
||||
if (savedSpecialRares == null) {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes("GTC").name("Breeding Pool");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("GTC").name("Godless Shrine");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("GTC").name("Sacred Foundry");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("GTC").name("Stomping Ground");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("GTC").name("Watery Grave");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("RTR").name("Blood Crypt");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("RTR").name("Hallowed Fountain");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("RTR").name("Overgrown Tomb");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("RTR").name("Steam Vents");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("RTR").name("Temple Garden");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
return specialRare;
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("RTR").name("Blood Crypt");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("RTR").name("Hallowed Fountain");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("RTR").name("Overgrown Tomb");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("RTR").name("Steam Vents");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("RTR").name("Temple Garden");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
}
|
||||
specialRares.addAll(savedSpecialRares);
|
||||
return specialRares;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -47,6 +47,8 @@ public class FateReforged extends ExpansionSet {
|
|||
|
||||
private static final FateReforged fINSTANCE = new FateReforged();
|
||||
|
||||
List<CardInfo> savedSpecialRares = new ArrayList<>();
|
||||
|
||||
public static FateReforged getInstance() {
|
||||
return fINSTANCE;
|
||||
}
|
||||
|
@ -65,11 +67,24 @@ public class FateReforged extends ExpansionSet {
|
|||
this.ratioBoosterMythic = 8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CardInfo> getCommon() {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code).rarities(Rarity.COMMON).notTypes(CardType.LAND).doubleFaced(false);
|
||||
return CardRepository.instance.findCards(criteria);
|
||||
@Override
|
||||
public List<CardInfo> getCardsByRarity(Rarity rarity) {
|
||||
if (rarity.equals(Rarity.COMMON)) {
|
||||
List<CardInfo> savedCardsInfos = savedCards.get(rarity);
|
||||
if (savedCardsInfos == null) {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code).notTypes(CardType.LAND);
|
||||
criteria.rarities(rarity).doubleFaced(false);
|
||||
if (maxCardNumberInBooster != Integer.MAX_VALUE) {
|
||||
criteria.maxCardNumber(maxCardNumberInBooster);
|
||||
}
|
||||
savedCardsInfos = CardRepository.instance.findCards(criteria);
|
||||
savedCards.put(rarity, savedCardsInfos);
|
||||
}
|
||||
return savedCardsInfos;
|
||||
} else {
|
||||
return super.getCardsByRarity(rarity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,22 +96,25 @@ public class FateReforged extends ExpansionSet {
|
|||
|
||||
@Override
|
||||
public List<CardInfo> getSpecialRare() {
|
||||
List<CardInfo> specialRare = new ArrayList<>();
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes("KTK").name("Bloodstained Mire");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("KTK").name("Flooded Strand");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("KTK").name("Polluted Delta");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("KTK").name("Windswept Heath");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("KTK").name("Wooded Foothills");
|
||||
specialRare.addAll(CardRepository.instance.findCards(criteria));
|
||||
return specialRare;
|
||||
List<CardInfo> specialRares = new ArrayList<>();
|
||||
if (savedSpecialRares.isEmpty()) {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes("KTK").name("Bloodstained Mire");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("KTK").name("Flooded Strand");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("KTK").name("Polluted Delta");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("KTK").name("Windswept Heath");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes("KTK").name("Wooded Foothills");
|
||||
savedSpecialRares.addAll(CardRepository.instance.findCards(criteria));
|
||||
}
|
||||
specialRares.addAll(savedSpecialRares);
|
||||
return specialRares;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
|
|||
if (card != null) {
|
||||
cards.add(card);
|
||||
} else {
|
||||
// this bug seems to happen, if cause is removed, this check can also be removed
|
||||
// seems like this can happen during the cancelation of a game
|
||||
logger.error("Card not found cardId: " + cardId + " gameId: " + game.getId() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ package mage.cards;
|
|||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import mage.cards.repository.CardCriteria;
|
||||
|
@ -66,6 +67,8 @@ public abstract class ExpansionSet implements Serializable {
|
|||
protected String packageName;
|
||||
protected int maxCardNumberInBooster;
|
||||
|
||||
protected final EnumMap<Rarity, List<CardInfo>> savedCards;
|
||||
|
||||
public ExpansionSet(String name, String code, String packageName, Date releaseDate, SetType setType) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
|
@ -73,6 +76,7 @@ public abstract class ExpansionSet implements Serializable {
|
|||
this.setType = setType;
|
||||
this.packageName = packageName;
|
||||
this.maxCardNumberInBooster = Integer.MAX_VALUE;
|
||||
savedCards = new EnumMap<>(Rarity.class);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -113,50 +117,28 @@ public abstract class ExpansionSet implements Serializable {
|
|||
if (!hasBoosters) {
|
||||
return booster;
|
||||
}
|
||||
|
||||
List<CardInfo> common = getCommon();
|
||||
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code).rarities(Rarity.UNCOMMON).doubleFaced(false);
|
||||
if (maxCardNumberInBooster != Integer.MAX_VALUE) {
|
||||
criteria.maxCardNumber(maxCardNumberInBooster);
|
||||
}
|
||||
List<CardInfo> uncommon = CardRepository.instance.findCards(criteria);
|
||||
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code).rarities(Rarity.RARE).doubleFaced(false);
|
||||
if (maxCardNumberInBooster != Integer.MAX_VALUE) {
|
||||
criteria.maxCardNumber(maxCardNumberInBooster);
|
||||
}
|
||||
List<CardInfo> rare = CardRepository.instance.findCards(criteria);
|
||||
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code).rarities(Rarity.MYTHIC).doubleFaced(false);
|
||||
if (maxCardNumberInBooster != Integer.MAX_VALUE) {
|
||||
criteria.maxCardNumber(maxCardNumberInBooster);
|
||||
}
|
||||
List<CardInfo> mythic = CardRepository.instance.findCards(criteria);
|
||||
|
||||
|
||||
if (numBoosterLands > 0) {
|
||||
criteria = new CardCriteria();
|
||||
criteria.setCodes(!hasBasicLands && parentSet != null ? parentSet.code : this.code).rarities(Rarity.LAND).doubleFaced(false);
|
||||
List<CardInfo> basicLand = CardRepository.instance.findCards(criteria);
|
||||
List<CardInfo> basicLands = getCardsByRarity(Rarity.LAND);
|
||||
for (int i = 0; i < numBoosterLands; i++) {
|
||||
addToBooster(booster, basicLand);
|
||||
addToBooster(booster, basicLands);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
List<CardInfo> commons = getCardsByRarity(Rarity.COMMON);
|
||||
for (int i = 0; i < numBoosterCommon; i++) {
|
||||
addToBooster(booster, common);
|
||||
addToBooster(booster, commons);
|
||||
}
|
||||
List<CardInfo> uncommons = getCardsByRarity(Rarity.UNCOMMON);
|
||||
for (int i = 0; i < numBoosterUncommon; i++) {
|
||||
addToBooster(booster, uncommon);
|
||||
addToBooster(booster, uncommons);
|
||||
}
|
||||
List<CardInfo> rares = getCardsByRarity(Rarity.RARE);
|
||||
List<CardInfo> mythics = getCardsByRarity(Rarity.MYTHIC);
|
||||
for (int i = 0; i < numBoosterRare; i++) {
|
||||
if (ratioBoosterMythic > 0 && rnd.nextInt(ratioBoosterMythic) == 1) {
|
||||
addToBooster(booster, mythic);
|
||||
addToBooster(booster, mythics);
|
||||
} else {
|
||||
addToBooster(booster, rare);
|
||||
addToBooster(booster, rares);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,7 +171,7 @@ public abstract class ExpansionSet implements Serializable {
|
|||
if (specialCards > 0) {
|
||||
for (int i = 0; i < numBoosterSpecial; i++) {
|
||||
if (rnd.nextInt(15) < 10) {
|
||||
if (specialCommon != null) {
|
||||
if (specialCommon != null && !specialCommon.isEmpty()) {
|
||||
addToBooster(booster, specialCommon);
|
||||
} else {
|
||||
i--;
|
||||
|
@ -197,7 +179,7 @@ public abstract class ExpansionSet implements Serializable {
|
|||
continue;
|
||||
}
|
||||
if (rnd.nextInt(4) < 3) {
|
||||
if (specialUncommon != null) {
|
||||
if (specialUncommon != null && !specialUncommon.isEmpty()) {
|
||||
addToBooster(booster, specialUncommon);
|
||||
} else {
|
||||
i--;
|
||||
|
@ -205,15 +187,15 @@ public abstract class ExpansionSet implements Serializable {
|
|||
continue;
|
||||
}
|
||||
if (rnd.nextInt(8) < 7) {
|
||||
if (specialRare != null) {
|
||||
if (specialRare != null && !specialRare.isEmpty()) {
|
||||
addToBooster(booster, specialRare);
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (specialMythic != null) {
|
||||
if (specialBonus != null) {
|
||||
if (specialMythic != null && !specialMythic.isEmpty()) {
|
||||
if (specialBonus != null && !specialBonus.isEmpty()) {
|
||||
if (rnd.nextInt(3) < 2) {
|
||||
addToBooster(booster, specialMythic);
|
||||
continue;
|
||||
|
@ -225,7 +207,7 @@ public abstract class ExpansionSet implements Serializable {
|
|||
} else {
|
||||
i--;
|
||||
}
|
||||
if (specialBonus != null) {
|
||||
if (specialBonus != null && !specialBonus.isEmpty()) {
|
||||
addToBooster(booster, specialBonus);
|
||||
}
|
||||
}
|
||||
|
@ -276,13 +258,25 @@ public abstract class ExpansionSet implements Serializable {
|
|||
return hasBasicLands;
|
||||
}
|
||||
|
||||
public List<CardInfo> getCommon() {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.setCodes(this.code).rarities(Rarity.COMMON).doubleFaced(false);
|
||||
if (maxCardNumberInBooster != Integer.MAX_VALUE) {
|
||||
criteria.maxCardNumber(maxCardNumberInBooster);
|
||||
public List<CardInfo> getCardsByRarity(Rarity rarity) {
|
||||
List<CardInfo> savedCardsInfos = savedCards.get(rarity);
|
||||
if (savedCardsInfos == null) {
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
if (rarity.equals(Rarity.LAND)) {
|
||||
criteria.setCodes(!hasBasicLands && parentSet != null ? parentSet.code : this.code);
|
||||
} else {
|
||||
criteria.setCodes(this.code);
|
||||
}
|
||||
criteria.rarities(rarity).doubleFaced(false);
|
||||
if (maxCardNumberInBooster != Integer.MAX_VALUE) {
|
||||
criteria.maxCardNumber(maxCardNumberInBooster);
|
||||
}
|
||||
savedCardsInfos = CardRepository.instance.findCards(criteria);
|
||||
savedCards.put(rarity, savedCardsInfos);
|
||||
}
|
||||
return CardRepository.instance.findCards(criteria);
|
||||
List<CardInfo> cards = new ArrayList<>();
|
||||
cards.addAll(savedCardsInfos);
|
||||
return cards;
|
||||
}
|
||||
|
||||
public List<CardInfo> getSpecialCommon() {
|
||||
|
@ -304,4 +298,8 @@ public abstract class ExpansionSet implements Serializable {
|
|||
public List<CardInfo> getSpecialBonus() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeSavedCards() {
|
||||
savedCards.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ public class BoosterDraft extends DraftImpl {
|
|||
fireUpdatePlayersEvent();
|
||||
}
|
||||
}
|
||||
resetBufferedCards();
|
||||
this.fireEndDraftEvent();
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,8 @@ public interface Draft extends MageItem, Serializable {
|
|||
void addPlayerQueryEventListener(Listener<PlayerQueryEvent> listener);
|
||||
void firePickCardEvent(UUID playerId);
|
||||
|
||||
void resetBufferedCards();
|
||||
|
||||
boolean isAbort();
|
||||
void setAbort(boolean abort);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
package mage.game.draft;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -351,4 +352,17 @@ public abstract class DraftImpl implements Draft {
|
|||
started = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetBufferedCards() {
|
||||
HashSet<ExpansionSet> setsDone = new HashSet<>();
|
||||
for(ExpansionSet set: sets) {
|
||||
if (!setsDone.contains(set)) {
|
||||
set.removeSavedCards();
|
||||
setsDone.add(set);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -97,11 +97,11 @@ public class DraftPlayer {
|
|||
picking = false;
|
||||
}
|
||||
|
||||
public void openBooster(ExpansionSet set) {
|
||||
synchronized(booster) {
|
||||
booster = set.createBooster();
|
||||
}
|
||||
}
|
||||
// public void openBooster(ExpansionSet set) {
|
||||
// synchronized(booster) {
|
||||
// booster = set.createBooster();
|
||||
// }
|
||||
// }
|
||||
|
||||
public void setBooster(List<Card> booster) {
|
||||
this.booster = booster;
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
@ -399,9 +400,20 @@ public abstract class TournamentImpl implements Tournament {
|
|||
}
|
||||
}
|
||||
}
|
||||
resetBufferedCards();
|
||||
nextStep();
|
||||
}
|
||||
|
||||
public void resetBufferedCards() {
|
||||
HashSet<ExpansionSet> setsDone = new HashSet<>();
|
||||
for(ExpansionSet set: sets) {
|
||||
if (!setsDone.contains(set)) {
|
||||
set.removeSavedCards();
|
||||
setsDone.add(set);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void playMatch(TournamentPairing pair) {
|
||||
options.getMatchOptions().getPlayerTypes().clear();
|
||||
options.getMatchOptions().getPlayerTypes().add(pair.getPlayer1().getPlayerType());
|
||||
|
|
Loading…
Reference in a new issue