Compare commits

..

1 commit

Author SHA1 Message Date
8f47898523 Update dependency typescript to v5.2.2
Some checks failed
continuous-integration/drone/push Build is failing
2023-09-28 10:43:19 +00:00

View file

@ -1,5 +1,6 @@
import { CardRarity } from "../constants/CardRarity";
import Card from "../database/entities/card/Card";
import Series from "../database/entities/card/Series";
export default class CardDropHelper {
public static async GetRandomCard(): Promise<Card> {
@ -16,7 +17,18 @@ export default class CardDropHelper {
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
else cardRarity = CardRarity.Legendary;
const randomCard = await this.GetRandomCardByRarity(cardRarity);
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);
const randomCard = allCards[randomCardIndex];
return randomCard;
}