Move unclaimed logic to a common function
This commit is contained in:
parent
1106585f58
commit
f221a5dffe
6 changed files with 41 additions and 19 deletions
|
@ -40,7 +40,7 @@ export default class Reroll extends ButtonEvent {
|
|||
return;
|
||||
}
|
||||
|
||||
const randomCard = GetCardsHelper.GetRandomCard();
|
||||
const randomCard = await GetCardsHelper.FetchCard(interaction.user.id);
|
||||
|
||||
if (!randomCard) {
|
||||
await interaction.reply("Unable to fetch card, please try again.");
|
||||
|
|
|
@ -10,9 +10,6 @@ import AppLogger from "../client/appLogger";
|
|||
import User from "../database/entities/app/User";
|
||||
import CardConstants from "../constants/CardConstants";
|
||||
import ErrorMessages from "../constants/ErrorMessages";
|
||||
import { DropResult } from "../contracts/SeriesMetadata";
|
||||
import EffectHelper from "../helpers/EffectHelper";
|
||||
import GetUnclaimedCardsHelper from "../helpers/DropHelpers/GetUnclaimedCardsHelper";
|
||||
import GetCardsHelper from "../helpers/DropHelpers/GetCardsHelper";
|
||||
import DropEmbedHelper from "../helpers/DropHelpers/DropEmbedHelper";
|
||||
|
||||
|
@ -51,15 +48,7 @@ export default class Drop extends Command {
|
|||
return;
|
||||
}
|
||||
|
||||
let randomCard: DropResult | undefined;
|
||||
|
||||
const hasChanceUpEffect = await EffectHelper.HasEffect(interaction.user.id, "unclaimed");
|
||||
|
||||
if (hasChanceUpEffect && Math.random() <= CardConstants.UnusedChanceUpChance) {
|
||||
randomCard = await GetUnclaimedCardsHelper.GetRandomCardUnclaimed(interaction.user.id);
|
||||
} else {
|
||||
randomCard = GetCardsHelper.GetRandomCard();
|
||||
}
|
||||
const randomCard = await GetCardsHelper.FetchCard(interaction.user.id);
|
||||
|
||||
if (!randomCard) {
|
||||
AppLogger.LogWarn("Commands/Drop", ErrorMessages.UnableToFetchCard);
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
import AppLogger from "../../client/appLogger";
|
||||
import { CoreClient } from "../../client/client";
|
||||
import CardConstants from "../../constants/CardConstants";
|
||||
import { CardRarity } from "../../constants/CardRarity";
|
||||
import CardRarityChances from "../../constants/CardRarityChances";
|
||||
import { DropResult } from "../../contracts/SeriesMetadata";
|
||||
import EffectHelper from "../EffectHelper";
|
||||
import GetUnclaimedCardsHelper from "./GetUnclaimedCardsHelper";
|
||||
|
||||
export default class GetCardsHelper {
|
||||
public static async FetchCard(userId: string): Promise<DropResult | undefined> {
|
||||
const hasChanceUpEffect = await EffectHelper.HasEffect(userId, "unclaimed");
|
||||
|
||||
if (hasChanceUpEffect && Math.random() <= CardConstants.UnusedChanceUpChance) {
|
||||
return await GetUnclaimedCardsHelper.GetRandomCardUnclaimed(userId);
|
||||
}
|
||||
|
||||
return this.GetRandomCard();
|
||||
}
|
||||
|
||||
public static GetRandomCard(): DropResult | undefined {
|
||||
const randomRarity = Math.random() * 100;
|
||||
|
||||
|
|
|
@ -25,14 +25,10 @@ export default class GetUnclaimedCardsHelper {
|
|||
|
||||
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) {
|
||||
|
@ -59,8 +55,6 @@ export default class GetUnclaimedCardsHelper {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
AppLogger.LogSilly("CardDropHelperMetadata/GetRandomCardByRarityUnclaimed", `Random card: ${card.id} ${card.name}`);
|
||||
|
||||
return {
|
||||
series: series,
|
||||
card: card,
|
||||
|
|
7
tests/helpers/DropHelpers/GetCardsHelper.test.ts
Normal file
7
tests/helpers/DropHelpers/GetCardsHelper.test.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
describe("FetchCard", () => {
|
||||
test.todo("GIVEN user has the unclaimed effect AND unused chance is within constraint, EXPECT unclaimed card returned");
|
||||
|
||||
test.todo("GIVEN user has unclaimed effect AND unused chance is NOT within constraint, EXPECT random card returned");
|
||||
|
||||
test.todo("GIVEN user does NOT have unclaimed effect, EXPECT random card returned");
|
||||
});
|
19
tests/helpers/DropHelpers/GetUnclaimedCardsHelper.test.ts
Normal file
19
tests/helpers/DropHelpers/GetUnclaimedCardsHelper.test.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
describe("GetRandomCardUnclaimed", () => {
|
||||
test.todo("GIVEN chance is within bronze chance, EXPECT bronze card returned");
|
||||
|
||||
test.todo("GIVEN chance is within silver chance, EXPECT silver card");
|
||||
|
||||
test.todo("GIVEN chance is within gold chance, EXPECT gold card returned");
|
||||
|
||||
test.todo("GIVEN chance is within manga chance, EXPECT manga card returned");
|
||||
});
|
||||
|
||||
describe("GetRandomCardByRarityUnclaimed", () => {
|
||||
test.todo("GIVEN user has no claimed cards, EXPECT random card returned");
|
||||
|
||||
test.todo("GIVEN no cards are found in memory, EXPECT undefined returned");
|
||||
|
||||
test.todo("GIVEN no series metadata is found for random card, EXPECT undefined returned");
|
||||
|
||||
test.todo("GIVEN user has claimed cards, EXPECT random card to NOT be this card");
|
||||
});
|
Loading…
Reference in a new issue