Compare commits
2 commits
afd76e01f7
...
00b6c7f8e2
Author | SHA1 | Date | |
---|---|---|---|
00b6c7f8e2 | |||
4260b120e7 |
2 changed files with 561 additions and 540 deletions
|
@ -1,6 +1,5 @@
|
||||||
import { CardRarity } from "../constants/CardRarity";
|
import { CardRarity } from "../constants/CardRarity";
|
||||||
import Card from "../database/entities/card/Card";
|
import Card from "../database/entities/card/Card";
|
||||||
import Series from "../database/entities/card/Series";
|
|
||||||
|
|
||||||
export default class CardDropHelper {
|
export default class CardDropHelper {
|
||||||
public static async GetRandomCard(): Promise<Card> {
|
public static async GetRandomCard(): Promise<Card> {
|
||||||
|
@ -17,18 +16,7 @@ export default class CardDropHelper {
|
||||||
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
|
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
|
||||||
else cardRarity = CardRarity.Legendary;
|
else cardRarity = CardRarity.Legendary;
|
||||||
|
|
||||||
const allSeries = await Series.FetchAll(Series, [ "Cards", "Cards.Series" ]);
|
const randomCard = await this.GetRandomCardByRarity(cardRarity);
|
||||||
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;
|
return randomCard;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue