Files
healer-man/src/game/manastormLoot.test.ts
T
2026-09-13 13:21:27 -04:00

89 lines
3.2 KiB
TypeScript

import { beforeEach, describe, expect, it } from "vitest";
import { useCombatStore } from "./combatStore";
import { MANASTORM_ENCOUNTERS } from "./manastorm";
import {
lootCurrentManastormBoss,
openManastormRewardCache,
} from "./manastormLoot";
import { useManastormStore } from "./manastormStore";
import { useGameStore } from "./store";
describe("Manastorm corpse loot", () => {
beforeEach(() => {
useCombatStore.getState().initializeCharacter({ classId: "warrior", level: 10, inventory: [] });
useManastormStore.getState().resetRun();
});
it("guarantees Kresh's Normal card but waits for an explicit reward claim", () => {
const kresh = MANASTORM_ENCOUNTERS.find((encounter) => encounter.id === "kresh")!;
useGameStore.getState().activateDungeon(kresh.dungeonId, undefined, {
gameMode: "manastorm",
spawn: kresh.playerSpawn,
});
useManastormStore.setState({
status: "awaiting-loot",
currentEncounter: kresh,
level: 1,
});
useCombatStore.getState().registerMob(kresh.bossRuntimeId, {
name: kresh.bossName,
boss: true,
maxHealth: 1,
lootSourceId: kresh.id,
});
useCombatStore.getState().damageMob(kresh.bossRuntimeId, 1, 10_000);
const corpse = useCombatStore.getState().mobs[kresh.bossRuntimeId];
expect(corpse.pendingLoot).toEqual([]);
expect(corpse.bossCardDrop?.rarities).toContain("normal");
expect(useCombatStore.getState().inventory).toEqual([]);
expect(useCombatStore.getState().mobs[kresh.bossRuntimeId]?.looted).toBe(false);
expect(lootCurrentManastormBoss(10_100)).toBe(true);
expect(useCombatStore.getState().inventory).toEqual(corpse.pendingLoot);
expect(useCombatStore.getState().mobs[kresh.bossRuntimeId]?.looted).toBe(true);
expect(useCombatStore.getState().bossCards.counts["wow:kresh"]?.normal).toBe(1);
expect(useCombatStore.getState().bossLootRewards[0]).toMatchObject({
bossId: kresh.bossRuntimeId,
bossName: kresh.bossName,
items: corpse.pendingLoot,
});
expect(lootCurrentManastormBoss(10_101)).toBe(false);
});
it("opens a cache into concrete loot scaled to the character level", () => {
useCombatStore.getState().initializeCharacter({
classId: "priest",
level: 80,
xp: 0,
inventory: [],
});
useManastormStore.getState().startRun({
cacheMeter: 4,
random: () => 0,
});
useManastormStore.getState().enterStage();
useManastormStore.getState().observeTrash(true);
useManastormStore.getState().observeBoss(true, true);
const cache = useManastormStore.getState().rewardCache[0];
expect(cache).toBeTruthy();
useManastormStore.setState((state) => ({
level: 35,
scaling: {
...state.scaling,
bonusLootChance: 1,
},
}));
expect(openManastormRewardCache(cache.id, 12_345, () => 0.5)).toBe(true);
expect(useManastormStore.getState().rewardCache).not.toContainEqual(cache);
expect(useCombatStore.getState().inventory).toEqual([
expect.objectContaining({
itemLevel: 85,
acquiredAt: 12_345,
}),
]);
expect(openManastormRewardCache(cache.id, 12_346, () => 0)).toBe(false);
expect(useCombatStore.getState().inventory).toHaveLength(1);
});
});