import test from "node:test"; import assert from "node:assert/strict"; import { evaluateConditionSet, normalizeConditionSet, ConditionKind } from "../../shared/quests/conditions.js"; import { countableObjectiveProgress, formatObjectiveDisplayText } from "../../shared/quests/objectiveProgress.js"; import { normalizeQuestDef, normalizeDialogueTree } from "../../shared/quests/normalize.js"; import { formatDialogueRewardMessage, formatDialogueQuestRewardMessage } from "../../shared/quests/dialogueRewards.js"; test("ConditionSet AND + NOT", () => { const set = normalizeConditionSet({ all: [ { condition: { kind: ConditionKind.hasItem, itemId: 1, quantity: 1 } }, { not: true, condition: { kind: ConditionKind.questState, questId: "q1", state: "completed" } } ] }); assert.equal(evaluateConditionSet(set, { countItem: (id) => (id === 1 ? 2 : 0), questState: () => "not-started" }), true); assert.equal(evaluateConditionSet(set, { countItem: (id) => (id === 1 ? 2 : 0), questState: () => "completed" }), false); }); test("normalize quest and dialogue", () => { const quest = normalizeQuestDef({ questId: "Fetch Ore!", title: "Fetch Ore", steps: [{ objectives: [{ text: "Have tin", when: { all: [{ kind: "hasItem", itemId: 10, quantity: 1 }] } }] }] }); assert.equal(quest.questId, "fetch-ore"); assert.equal(quest.steps[0].objectives[0].when.all[0].condition.kind, "hasItem"); const tree = normalizeDialogueTree({ dialogueId: "Smith", unique: true, steps: [{ stepId: "hi", lines: [{ speaker: "npc", text: "Hello" }], itemRewards: [ { itemId: 10, quantity: 2 }, { itemId: 10, quantity: 9 }, { itemId: 0, quantity: 1 } ], exit: { kind: "end" } }] }); assert.equal(tree.dialogueId, "smith"); assert.equal(tree.unique, true); assert.equal(tree.steps[0].exit.kind, "end"); assert.deepEqual(tree.steps[0].itemRewards, [{ itemId: 10, quantity: 2 }]); assert.deepEqual(tree.steps[0].questRewards, []); }); test("dialogue reward messages bag vs bank and lists", () => { assert.equal( formatDialogueRewardMessage([{ displayName: "Tin ore", quantity: 1 }], "bag"), "Tin ore has been added to your bag." ); assert.equal( formatDialogueRewardMessage([{ displayName: "Tin ore", quantity: 3 }], "bank"), "3 Tin ore have been sent to your bank." ); assert.equal( formatDialogueRewardMessage([ { displayName: "Tin ore", quantity: 1 }, { displayName: "Copper ore", quantity: 1 } ], "bag"), "Tin ore and Copper ore have been added to your bag." ); assert.equal( formatDialogueRewardMessage([ { displayName: "A", quantity: 1 }, { displayName: "B", quantity: 1 }, { displayName: "C", quantity: 1 } ], "bag"), "A, B and C have been added to your bag." ); assert.equal( formatDialogueQuestRewardMessage(["Tin Delivery"]), "The Tin Delivery quest has been added to your journal." ); assert.equal( formatDialogueQuestRewardMessage(["Alpha", "Beta"]), "The Alpha and Beta quests have been added to your journal." ); }); test("countable objective progress for hasItem killCount and skillLevelAtLeast", () => { const hasItem = normalizeConditionSet({ all: [{ condition: { kind: ConditionKind.hasItem, itemId: 10, quantity: 30 } }] }); assert.deepEqual( countableObjectiveProgress(hasItem, { countItem: (id) => (id === 10 ? 5 : 0) }), { current: 5, required: 30 } ); assert.equal( formatObjectiveDisplayText("Collect Pine Logs", { current: 5, required: 30 }), "Collect Pine Logs (5 / 30)" ); const kills = normalizeConditionSet({ all: [{ condition: { kind: ConditionKind.killCount, mobTypeId: "rat", count: 3 } }] }); assert.deepEqual( countableObjectiveProgress(kills, { killCount: (c) => (c.mobTypeId === "rat" ? 2 : 0) }), { current: 2, required: 3 } ); const skill = normalizeConditionSet({ all: [{ condition: { kind: ConditionKind.skillLevelAtLeast, skillId: "woodcutting", level: 20 } }] }); assert.deepEqual( countableObjectiveProgress(skill, { skillLevel: (id) => (id === "woodcutting" ? 12 : 1) }), { current: 12, required: 20 } ); });