Add chance effect function

This commit is contained in:
Ethan Lane 2024-12-23 16:18:40 +00:00
parent dd1f259170
commit 9a2835a0eb
3 changed files with 73 additions and 1 deletions

View file

@ -11,6 +11,8 @@ import AppLogger from "../client/appLogger";
import User from "../database/entities/app/User"; import User from "../database/entities/app/User";
import CardConstants from "../constants/CardConstants"; import CardConstants from "../constants/CardConstants";
import ErrorMessages from "../constants/ErrorMessages"; import ErrorMessages from "../constants/ErrorMessages";
import { DropResult } from "../contracts/SeriesMetadata";
import EffectHelper from "../helpers/EffectHelper";
export default class Drop extends Command { export default class Drop extends Command {
constructor() { constructor() {
@ -47,7 +49,15 @@ export default class Drop extends Command {
return; return;
} }
const randomCard = CardDropHelperMetadata.GetRandomCard(); let randomCard: DropResult | undefined;
const hasChanceUpEffect = await EffectHelper.HasEffect(interaction.user.id, "unclaimed");
if (hasChanceUpEffect && Math.random() <= CardConstants.UnusedChanceUpChance) {
randomCard = await CardDropHelperMetadata.GetRandomCardUnclaimed(interaction.user.id);
} else {
randomCard = CardDropHelperMetadata.GetRandomCard();
}
if (!randomCard) { if (!randomCard) {
AppLogger.LogWarn("Commands/Drop", ErrorMessages.UnableToFetchCard); AppLogger.LogWarn("Commands/Drop", ErrorMessages.UnableToFetchCard);

View file

@ -7,4 +7,7 @@ export default class CardConstants {
// Multidrop // Multidrop
public static readonly MultidropCost = this.ClaimCost * 10; public static readonly MultidropCost = this.ClaimCost * 10;
public static readonly MultidropQuantity = 11; public static readonly MultidropQuantity = 11;
// Effects
public static readonly UnusedChanceUpChance = 1;
} }

View file

@ -6,6 +6,7 @@ import { CoreClient } from "../client/client";
import AppLogger from "../client/appLogger"; import AppLogger from "../client/appLogger";
import CardConstants from "../constants/CardConstants"; import CardConstants from "../constants/CardConstants";
import StringTools from "./StringTools"; import StringTools from "./StringTools";
import Inventory from "../database/entities/app/Inventory";
export default class CardDropHelperMetadata { export default class CardDropHelperMetadata {
public static GetRandomCard(): DropResult | undefined { public static GetRandomCard(): DropResult | undefined {
@ -58,6 +59,64 @@ export default class CardDropHelperMetadata {
}; };
} }
public static async GetRandomCardUnclaimed(userId: string): Promise<DropResult | undefined> {
const randomRarity = Math.random() * 100;
let cardRarity: CardRarity;
const bronzeChance = CardRarityChances.Bronze;
const silverChance = bronzeChance + CardRarityChances.Silver;
const goldChance = silverChance + CardRarityChances.Gold;
const mangaChance = goldChance + CardRarityChances.Manga;
if (randomRarity < bronzeChance) cardRarity = CardRarity.Bronze;
else if (randomRarity < silverChance) cardRarity = CardRarity.Silver;
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
else if (randomRarity < mangaChance) cardRarity = CardRarity.Manga;
else cardRarity = CardRarity.Legendary;
const randomCard = await this.GetRandomCardByRarityUnclaimed(cardRarity, userId);
AppLogger.LogSilly("CardDropHelperMetadata/GetRandomCardUnclaimed", `Random card: ${randomCard?.card.id} ${randomCard?.card.name}`);
return randomCard;
}
public static async GetRandomCardByRarityUnclaimed(rarity: CardRarity, userId: string): Promise<DropResult | undefined> {
AppLogger.LogSilly("CardDropHelperMetadata/GetRandomCardByRarityUnclaimed", `Parameters: rarity=${rarity}, userId=${userId}`);
const claimedCards = await Inventory.FetchAllByUserId(userId);
if (!claimedCards) {
// They don't have any cards, so safe to get any random card
return this.GetRandomCardByRarity(rarity);
}
const allCards = CoreClient.Cards
.flatMap(x => x.cards)
.filter(x => x.type == rarity)
.filter(x => !claimedCards.find(y => y.CardNumber == x.id));
const randomCardIndex = Math.floor(Math.random() * allCards.length);
const card = allCards[randomCardIndex];
const series = CoreClient.Cards
.find(x => x.cards.includes(card));
if (!series) {
AppLogger.LogWarn("CardDropHelperMetadata/GetRandomCardByRarityUnclaimed", `Series not found for card ${card.id}`);
return undefined;
}
AppLogger.LogSilly("CardDropHelperMetadata/GetRandomCardByRarityUnclaimed", `Random card: ${card.id} ${card.name}`);
return {
series: series,
card: card,
};
}
public static GetCardByCardNumber(cardNumber: string): DropResult | undefined { public static GetCardByCardNumber(cardNumber: string): DropResult | undefined {
AppLogger.LogSilly("CardDropHelperMetadata/GetCardByCardNumber", `Parameters: cardNumber=${cardNumber}`); AppLogger.LogSilly("CardDropHelperMetadata/GetCardByCardNumber", `Parameters: cardNumber=${cardNumber}`);