Compare commits
No commits in common. "7c47cfc70cb418ea11b6f9f711896ade693633a9" and "1106585f581342eb87f34a7dcde90133838e3c0c" have entirely different histories.
7c47cfc70c
...
1106585f58
6 changed files with 19 additions and 102 deletions
|
@ -40,7 +40,7 @@ export default class Reroll extends ButtonEvent {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const randomCard = await GetCardsHelper.FetchCard(interaction.user.id);
|
const randomCard = GetCardsHelper.GetRandomCard();
|
||||||
|
|
||||||
if (!randomCard) {
|
if (!randomCard) {
|
||||||
await interaction.reply("Unable to fetch card, please try again.");
|
await interaction.reply("Unable to fetch card, please try again.");
|
||||||
|
|
|
@ -10,6 +10,9 @@ 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";
|
||||||
|
import GetUnclaimedCardsHelper from "../helpers/DropHelpers/GetUnclaimedCardsHelper";
|
||||||
import GetCardsHelper from "../helpers/DropHelpers/GetCardsHelper";
|
import GetCardsHelper from "../helpers/DropHelpers/GetCardsHelper";
|
||||||
import DropEmbedHelper from "../helpers/DropHelpers/DropEmbedHelper";
|
import DropEmbedHelper from "../helpers/DropHelpers/DropEmbedHelper";
|
||||||
|
|
||||||
|
@ -48,7 +51,15 @@ export default class Drop extends Command {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const randomCard = await GetCardsHelper.FetchCard(interaction.user.id);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
if (!randomCard) {
|
if (!randomCard) {
|
||||||
AppLogger.LogWarn("Commands/Drop", ErrorMessages.UnableToFetchCard);
|
AppLogger.LogWarn("Commands/Drop", ErrorMessages.UnableToFetchCard);
|
||||||
|
|
|
@ -1,23 +1,10 @@
|
||||||
import AppLogger from "../../client/appLogger";
|
import AppLogger from "../../client/appLogger";
|
||||||
import { CoreClient } from "../../client/client";
|
import { CoreClient } from "../../client/client";
|
||||||
import CardConstants from "../../constants/CardConstants";
|
|
||||||
import { CardRarity } from "../../constants/CardRarity";
|
import { CardRarity } from "../../constants/CardRarity";
|
||||||
import CardRarityChances from "../../constants/CardRarityChances";
|
import CardRarityChances from "../../constants/CardRarityChances";
|
||||||
import { DropResult } from "../../contracts/SeriesMetadata";
|
import { DropResult } from "../../contracts/SeriesMetadata";
|
||||||
import EffectHelper from "../EffectHelper";
|
|
||||||
import GetUnclaimedCardsHelper from "./GetUnclaimedCardsHelper";
|
|
||||||
|
|
||||||
export default class GetCardsHelper {
|
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 {
|
public static GetRandomCard(): DropResult | undefined {
|
||||||
const randomRarity = Math.random() * 100;
|
const randomRarity = Math.random() * 100;
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,14 @@ export default class GetUnclaimedCardsHelper {
|
||||||
|
|
||||||
const randomCard = await this.GetRandomCardByRarityUnclaimed(cardRarity, userId);
|
const randomCard = await this.GetRandomCardByRarityUnclaimed(cardRarity, userId);
|
||||||
|
|
||||||
|
AppLogger.LogSilly("CardDropHelperMetadata/GetRandomCardUnclaimed", `Random card: ${randomCard?.card.id} ${randomCard?.card.name}`);
|
||||||
|
|
||||||
return randomCard;
|
return randomCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async GetRandomCardByRarityUnclaimed(rarity: CardRarity, userId: string): Promise<DropResult | undefined> {
|
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);
|
const claimedCards = await Inventory.FetchAllByUserId(userId);
|
||||||
|
|
||||||
if (!claimedCards) {
|
if (!claimedCards) {
|
||||||
|
@ -55,6 +59,8 @@ export default class GetUnclaimedCardsHelper {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppLogger.LogSilly("CardDropHelperMetadata/GetRandomCardByRarityUnclaimed", `Random card: ${card.id} ${card.name}`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
series: series,
|
series: series,
|
||||||
card: card,
|
card: card,
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
import GetCardsHelper from "../../../src/helpers/DropHelpers/GetCardsHelper";
|
|
||||||
import EffectHelper from "../../../src/helpers/EffectHelper";
|
|
||||||
import GetUnclaimedCardsHelper from "../../../src/helpers/DropHelpers/GetUnclaimedCardsHelper";
|
|
||||||
import CardConstants from "../../../src/constants/CardConstants";
|
|
||||||
|
|
||||||
jest.mock("../../../src/helpers/EffectHelper");
|
|
||||||
jest.mock("../../../src/helpers/DropHelpers/GetUnclaimedCardsHelper");
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.resetAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("FetchCard", () => {
|
|
||||||
test("GIVEN user has the unclaimed effect AND unused chance is within constraint, EXPECT unclaimed card returned", async () => {
|
|
||||||
// Arrange
|
|
||||||
(EffectHelper.HasEffect as jest.Mock).mockResolvedValue(true);
|
|
||||||
GetCardsHelper.GetRandomCard = jest.fn();
|
|
||||||
Math.random = jest.fn().mockReturnValue(CardConstants.UnusedChanceUpChance - 0.1);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await GetCardsHelper.FetchCard("userId");
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(EffectHelper.HasEffect).toHaveBeenCalledTimes(1);
|
|
||||||
expect(EffectHelper.HasEffect).toHaveBeenCalledWith("userId", "unclaimed");
|
|
||||||
|
|
||||||
expect(GetUnclaimedCardsHelper.GetRandomCardUnclaimed).toHaveBeenCalledTimes(1);
|
|
||||||
expect(GetUnclaimedCardsHelper.GetRandomCardUnclaimed).toHaveBeenCalledWith("userId");
|
|
||||||
|
|
||||||
expect(GetCardsHelper.GetRandomCard).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("GIVEN user has unclaimed effect AND unused chance is NOT within constraint, EXPECT random card returned", async () => {
|
|
||||||
// Arrange
|
|
||||||
(EffectHelper.HasEffect as jest.Mock).mockResolvedValue(true);
|
|
||||||
GetCardsHelper.GetRandomCard = jest.fn();
|
|
||||||
Math.random = jest.fn().mockReturnValue(CardConstants.UnusedChanceUpChance + 0.1);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await GetCardsHelper.FetchCard("userId");
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(EffectHelper.HasEffect).toHaveBeenCalledTimes(1);
|
|
||||||
expect(EffectHelper.HasEffect).toHaveBeenCalledWith("userId", "unclaimed");
|
|
||||||
|
|
||||||
expect(GetCardsHelper.GetRandomCard).toHaveBeenCalledTimes(1);
|
|
||||||
|
|
||||||
expect(GetUnclaimedCardsHelper.GetRandomCardUnclaimed).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("GIVEN user does NOT have unclaimed effect, EXPECT random card returned", async () => {
|
|
||||||
// Arrange
|
|
||||||
(EffectHelper.HasEffect as jest.Mock).mockResolvedValue(false);
|
|
||||||
GetCardsHelper.GetRandomCard = jest.fn();
|
|
||||||
Math.random = jest.fn().mockReturnValue(CardConstants.UnusedChanceUpChance + 0.1);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
await GetCardsHelper.FetchCard("userId");
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
expect(EffectHelper.HasEffect).toHaveBeenCalledTimes(1);
|
|
||||||
expect(EffectHelper.HasEffect).toHaveBeenCalledWith("userId", "unclaimed");
|
|
||||||
|
|
||||||
expect(GetCardsHelper.GetRandomCard).toHaveBeenCalledTimes(1);
|
|
||||||
|
|
||||||
expect(GetUnclaimedCardsHelper.GetRandomCardUnclaimed).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,19 +0,0 @@
|
||||||
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…
Add table
Reference in a new issue