| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { |
| 4 | evaluateConditionSet, |
| 5 | normalizeConditionSet, |
| 6 | ConditionKind |
| 7 | } from "../../shared/quests/conditions.js"; |
| 8 | import { normalizeQuestDef, normalizeDialogueTree } from "../../shared/quests/normalize.js"; |
| 9 | |
| 10 | test("ConditionSet AND + NOT", () => |
| 11 | { |
| 12 | const set = normalizeConditionSet({ |
| 13 | all: [ |
| 14 | { condition: { kind: ConditionKind.hasItem, itemId: 1, quantity: 1 } }, |
| 15 | { not: true, condition: { kind: ConditionKind.questState, questId: "q1", state: "completed" } } |
| 16 | ] |
| 17 | }); |
| 18 | assert.equal(evaluateConditionSet(set, { |
| 19 | countItem: (id) => (id === 1 ? 2 : 0), |
| 20 | questState: () => "not-started" |
| 21 | }), true); |
| 22 | assert.equal(evaluateConditionSet(set, { |
| 23 | countItem: (id) => (id === 1 ? 2 : 0), |
| 24 | questState: () => "completed" |
| 25 | }), false); |
| 26 | }); |
| 27 | |
| 28 | test("normalize quest and dialogue", () => |
| 29 | { |
| 30 | const quest = normalizeQuestDef({ |
| 31 | questId: "Fetch Ore!", |
| 32 | title: "Fetch Ore", |
| 33 | steps: [{ |
| 34 | objectives: [{ text: "Have tin", when: { all: [{ kind: "hasItem", itemId: 10, quantity: 1 }] } }] |
| 35 | }] |
| 36 | }); |
| 37 | assert.equal(quest.questId, "fetch-ore"); |
| 38 | assert.equal(quest.steps[0].objectives[0].when.all[0].condition.kind, "hasItem"); |
| 39 | |
| 40 | const tree = normalizeDialogueTree({ |
| 41 | dialogueId: "Smith", |
| 42 | unique: true, |
| 43 | steps: [{ |
| 44 | stepId: "hi", |
| 45 | lines: [{ speaker: "npc", text: "Hello" }], |
| 46 | exit: { kind: "end" } |
| 47 | }] |
| 48 | }); |
| 49 | assert.equal(tree.dialogueId, "smith"); |
| 50 | assert.equal(tree.unique, true); |
| 51 | assert.equal(tree.steps[0].exit.kind, "end"); |
| 52 | }); |