feature/5-drop-command (#17)
#5 Reviewed-on: https://gitea.vylpes.xyz/External/card-drop/pulls/17 Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
51d97bacd5
commit
58d1541e47
21 changed files with 382 additions and 48 deletions
38
src/helpers/CardDropHelper.ts
Normal file
38
src/helpers/CardDropHelper.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
import { CardRarity } from "../constants/CardRarity";
|
||||
import CardDataSource from "../database/dataSources/cardDataSource";
|
||||
import Card from "../database/entities/card/Card";
|
||||
import Series from "../database/entities/card/Series";
|
||||
|
||||
export default class CardDropHelper {
|
||||
public static async GetRandomCard(): Promise<Card> {
|
||||
const seriesRepository = CardDataSource.getRepository(Series);
|
||||
|
||||
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;
|
||||
|
||||
const bronzeChance = 62;
|
||||
const silverChance = bronzeChance + 31;
|
||||
const goldChance = silverChance + 6.4;
|
||||
|
||||
if (randomRarity < bronzeChance) cardRarity = CardRarity.Bronze;
|
||||
else if (randomRarity < silverChance) cardRarity = CardRarity.Silver;
|
||||
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
|
||||
else cardRarity = CardRarity.Legendary;
|
||||
|
||||
const allCards = randomSeries.Cards.filter(x => x.Rarity == cardRarity);
|
||||
|
||||
const randomCardIndex = Math.floor(Math.random() * allCards.length);
|
||||
|
||||
const randomCard = allCards[randomCardIndex];
|
||||
|
||||
return randomCard;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue