Skip to content

Commit

Permalink
fix: apply taboo_xp after exceptional
Browse files Browse the repository at this point in the history
  • Loading branch information
fspoettel committed Jun 14, 2024
1 parent abf1724 commit 7a0d1ae
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
42 changes: 42 additions & 0 deletions src/utils/card-utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { beforeAll, describe, expect, it } from "vitest";
import type { StoreApi } from "zustand";

import type { StoreState } from "@/store/slices";
import { getMockStore } from "@/test/get-mock-store";

import { countExperience } from "./card-utils";

describe("countExperience", () => {
let store: StoreApi<StoreState>;

beforeAll(async () => {
store = await getMockStore();
});

it("handles base case", () => {
const card = store.getState().metadata.cards["60127"];
expect(countExperience(card, 1)).toEqual(3);
});

it("handles case: chained", () => {
const card = store.getState().metadata.cards["60127"];
card.taboo_xp = -1;
expect(countExperience(card, 1)).toEqual(2);
});

it("handles myriad", () => {
const card = store.getState().metadata.cards["06328"];
expect(countExperience(card, 3)).toEqual(2);
});

it("handles exceptional: base case", () => {
const card = store.getState().metadata.cards["08053"];
expect(countExperience(card, 1)).toEqual(4);
});

it("handles exceptional: chained", () => {
const card = store.getState().metadata.cards["08053"];
card.taboo_xp = 1;
expect(countExperience(card, 1)).toEqual(5);
});
});
7 changes: 5 additions & 2 deletions src/utils/card-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ export function reversed(card: Card) {

export function countExperience(card: Card, quantity: number) {
if (card.customization_xp) return card.customization_xp;
let xp = (card.xp ?? 0) + (card.taboo_xp ?? 0);
xp = card.exceptional ? xp * 2 : xp;

let xp = card.xp ?? 0;
if (card.exceptional) xp *= 2;
if (card.taboo_xp) xp += card.taboo_xp;

return xp * (card.myriad ? 1 : quantity);
}

Expand Down

0 comments on commit 7a0d1ae

Please sign in to comment.