Fix bug where the randomiser would sometimes pick a legendary that does not exist
This commit is contained in:
parent
5970a4fe2d
commit
0e839992e6
2 changed files with 7 additions and 8 deletions
|
@ -4,13 +4,6 @@ import Series from "../database/entities/card/Series";
|
|||
|
||||
export default class CardDropHelper {
|
||||
public static async GetRandomCard(): Promise<Card> {
|
||||
const allSeries = await Series.FetchAll(Series, [ "Cards", "Cards.Series" ]);
|
||||
const allSeriesWithCards = allSeries.filter(x => x.Cards.length > 0);
|
||||
|
||||
const randomSeriesIndex = Math.floor(Math.random() * allSeriesWithCards.length);
|
||||
|
||||
const randomSeries = allSeriesWithCards[randomSeriesIndex];
|
||||
|
||||
const randomRarity = Math.random() * 100;
|
||||
|
||||
let cardRarity: CardRarity;
|
||||
|
@ -24,6 +17,13 @@ export default class CardDropHelper {
|
|||
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
|
||||
else cardRarity = CardRarity.Legendary;
|
||||
|
||||
const allSeries = await Series.FetchAll(Series, [ "Cards", "Cards.Series" ]);
|
||||
const allSeriesWithCards = allSeries.filter(x => x.Cards.length > 0 && x.Cards.find(x => x.Rarity == cardRarity));
|
||||
|
||||
const randomSeriesIndex = Math.floor(Math.random() * allSeriesWithCards.length);
|
||||
|
||||
const randomSeries = allSeriesWithCards[randomSeriesIndex];
|
||||
|
||||
const allCards = randomSeries.Cards.filter(x => x.Rarity == cardRarity && x.Path && x.FileName);
|
||||
|
||||
const randomCardIndex = Math.floor(Math.random() * allCards.length);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue