Make force rarity configurable
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
1a4d4b4e23
commit
ada907e2a4
7 changed files with 31 additions and 2 deletions
|
@ -16,7 +16,11 @@ export default class Drop extends Command {
|
|||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction) {
|
||||
const randomCard = await CardDropHelper.GetRandomCard();
|
||||
let randomCard = await CardDropHelper.GetRandomCard();
|
||||
|
||||
if (process.env.DROP_RARITY && Number(process.env.DROP_RARITY) > 0) {
|
||||
randomCard = await CardDropHelper.GetRandomCardByRarity(Number(process.env.DROP_RARITY));
|
||||
}
|
||||
|
||||
const image = readFileSync(randomCard.Path);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Column, Entity, ManyToOne } from "typeorm";
|
|||
import CardBaseEntity from "../../../contracts/CardBaseEntity";
|
||||
import { CardRarity } from "../../../constants/CardRarity";
|
||||
import Series from "./Series";
|
||||
import CardDataSource from "../../dataSources/cardDataSource";
|
||||
|
||||
@Entity()
|
||||
export default class Card extends CardBaseEntity {
|
||||
|
@ -33,4 +34,12 @@ export default class Card extends CardBaseEntity {
|
|||
|
||||
@ManyToOne(() => Series, x => x.Cards)
|
||||
Series: Series;
|
||||
|
||||
public static async FetchAllByRarity(rarity: CardRarity, relations?: string[]): Promise<Card[]> {
|
||||
const repository = CardDataSource.getRepository(Card);
|
||||
|
||||
const all = await repository.find({ where: { Rarity: rarity }, relations: relations || [] });
|
||||
|
||||
return all;
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ export default class CardDropHelper {
|
|||
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
|
||||
else cardRarity = CardRarity.Legendary;
|
||||
|
||||
const allCards = randomSeries.Cards.filter(x => x.Rarity == cardRarity && x.Path && x.FileName && x.Rarity == CardRarity.Legendary);
|
||||
const allCards = randomSeries.Cards.filter(x => x.Rarity == cardRarity && x.Path && x.FileName);
|
||||
|
||||
const randomCardIndex = Math.floor(Math.random() * allCards.length);
|
||||
|
||||
|
@ -32,4 +32,14 @@ export default class CardDropHelper {
|
|||
|
||||
return randomCard;
|
||||
}
|
||||
|
||||
public static async GetRandomCardByRarity(rarity: CardRarity): Promise<Card> {
|
||||
const allCards = await Card.FetchAllByRarity(rarity, [ "Series" ]);
|
||||
|
||||
const randomCardIndex = Math.floor(Math.random() * allCards.length);
|
||||
|
||||
const card = allCards[randomCardIndex];
|
||||
|
||||
return card;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue