Compare commits
16 Commits
e303373441
...
feature/ru
| Author | SHA1 | Date | |
|---|---|---|---|
| 102cbfeaad | |||
| 377a533466 | |||
| e3f90ca545 | |||
|
|
d504008030 | ||
| 79b9e448b7 | |||
|
|
50873e6989 | ||
|
|
ec0de5b0b8 | ||
| aea00d31e8 | |||
| fdaa2e3135 | |||
|
|
4dde4bff99 | ||
| 67453df51e | |||
| cff5f786a0 | |||
|
|
39703ce6b0 | ||
|
|
1ff20723ec | ||
|
|
120e144b3f | ||
|
|
6bf48df74c |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ dist/
|
||||
*.tsbuildinfo
|
||||
vite.config.js
|
||||
vite.config.d.ts
|
||||
Notes/rendered-pages/
|
||||
|
||||
452
package-lock.json
generated
452
package-lock.json
generated
@@ -18,7 +18,8 @@
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"@vitejs/plugin-react": "^4.4.1",
|
||||
"typescript": "^5.8.2",
|
||||
"vite": "^6.2.0"
|
||||
"vite": "^6.2.0",
|
||||
"vitest": "^3.0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/code-frame": {
|
||||
@@ -1197,6 +1198,24 @@
|
||||
"@babel/types": "^7.28.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/chai": {
|
||||
"version": "5.2.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz",
|
||||
"integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/deep-eql": "*",
|
||||
"assertion-error": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/deep-eql": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz",
|
||||
"integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/estree": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
|
||||
@@ -1255,6 +1274,131 @@
|
||||
"vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/expect": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.2.4.tgz",
|
||||
"integrity": "sha512-Io0yyORnB6sikFlt8QW5K7slY4OjqNX9jmJQ02QDda8lyM6B5oNgVWoSoKPac8/kgnCUzuHQKrSLtu/uOqqrig==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/chai": "^5.2.2",
|
||||
"@vitest/spy": "3.2.4",
|
||||
"@vitest/utils": "3.2.4",
|
||||
"chai": "^5.2.0",
|
||||
"tinyrainbow": "^2.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/mocker": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-3.2.4.tgz",
|
||||
"integrity": "sha512-46ryTE9RZO/rfDd7pEqFl7etuyzekzEhUbTW3BvmeO/BcCMEgq59BKhek3dXDWgAj4oMK6OZi+vRr1wPW6qjEQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/spy": "3.2.4",
|
||||
"estree-walker": "^3.0.3",
|
||||
"magic-string": "^0.30.17"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"msw": "^2.4.9",
|
||||
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"msw": {
|
||||
"optional": true
|
||||
},
|
||||
"vite": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/pretty-format": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.2.4.tgz",
|
||||
"integrity": "sha512-IVNZik8IVRJRTr9fxlitMKeJeXFFFN0JaB9PHPGQ8NKQbGpfjlTx9zO4RefN8gp7eqjNy8nyK3NZmBzOPeIxtA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tinyrainbow": "^2.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/runner": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-3.2.4.tgz",
|
||||
"integrity": "sha512-oukfKT9Mk41LreEW09vt45f8wx7DordoWUZMYdY/cyAk7w5TWkTRCNZYF7sX7n2wB7jyGAl74OxgwhPgKaqDMQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/utils": "3.2.4",
|
||||
"pathe": "^2.0.3",
|
||||
"strip-literal": "^3.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/snapshot": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-3.2.4.tgz",
|
||||
"integrity": "sha512-dEYtS7qQP2CjU27QBC5oUOxLE/v5eLkGqPE0ZKEIDGMs4vKWe7IjgLOeauHsR0D5YuuycGRO5oSRXnwnmA78fQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/pretty-format": "3.2.4",
|
||||
"magic-string": "^0.30.17",
|
||||
"pathe": "^2.0.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/spy": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-3.2.4.tgz",
|
||||
"integrity": "sha512-vAfasCOe6AIK70iP5UD11Ac4siNUNJ9i/9PZ3NKx07sG6sUxeag1LWdNrMWeKKYBLlzuK+Gn65Yd5nyL6ds+nw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tinyspy": "^4.0.3"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/utils": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-3.2.4.tgz",
|
||||
"integrity": "sha512-fB2V0JFrQSMsCo9HiSq3Ezpdv4iYaXRG1Sx8edX3MwxfyNn83mKiGzOcH+Fkxt4MHxr3y42fQi1oeAInqgX2QA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@vitest/pretty-format": "3.2.4",
|
||||
"loupe": "^3.1.4",
|
||||
"tinyrainbow": "^2.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/assertion-error": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz",
|
||||
"integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/baseline-browser-mapping": {
|
||||
"version": "2.10.8",
|
||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.8.tgz",
|
||||
@@ -1302,6 +1446,16 @@
|
||||
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
|
||||
}
|
||||
},
|
||||
"node_modules/cac": {
|
||||
"version": "6.7.14",
|
||||
"resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz",
|
||||
"integrity": "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/caniuse-lite": {
|
||||
"version": "1.0.30001779",
|
||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001779.tgz",
|
||||
@@ -1323,6 +1477,33 @@
|
||||
],
|
||||
"license": "CC-BY-4.0"
|
||||
},
|
||||
"node_modules/chai": {
|
||||
"version": "5.3.3",
|
||||
"resolved": "https://registry.npmjs.org/chai/-/chai-5.3.3.tgz",
|
||||
"integrity": "sha512-4zNhdJD/iOjSH0A05ea+Ke6MU5mmpQcbQsSOkgdaUMJ9zTlDTD/GYlwohmIE2u0gaxHYiVHEn1Fw9mZ/ktJWgw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"assertion-error": "^2.0.1",
|
||||
"check-error": "^2.1.1",
|
||||
"deep-eql": "^5.0.1",
|
||||
"loupe": "^3.1.0",
|
||||
"pathval": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/check-error": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.3.tgz",
|
||||
"integrity": "sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 16"
|
||||
}
|
||||
},
|
||||
"node_modules/convert-source-map": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
|
||||
@@ -1355,6 +1536,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/deep-eql": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz",
|
||||
"integrity": "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/electron-to-chromium": {
|
||||
"version": "1.5.313",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.313.tgz",
|
||||
@@ -1362,6 +1553,13 @@
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/es-module-lexer": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz",
|
||||
"integrity": "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.25.12",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.12.tgz",
|
||||
@@ -1414,6 +1612,26 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/estree-walker": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz",
|
||||
"integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/estree": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/expect-type": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.3.0.tgz",
|
||||
"integrity": "sha512-knvyeauYhqjOYvQ66MznSMs83wmHrCycNEN6Ao+2AeYEfxUIkuiVxdEa1qlGEPK+We3n0THiDciYSsCcgW/DoA==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fdir": {
|
||||
"version": "6.5.0",
|
||||
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
|
||||
@@ -1490,6 +1708,13 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/loupe": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/loupe/-/loupe-3.2.1.tgz",
|
||||
"integrity": "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lru-cache": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
|
||||
@@ -1500,6 +1725,16 @@
|
||||
"yallist": "^3.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/magic-string": {
|
||||
"version": "0.30.21",
|
||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz",
|
||||
"integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/sourcemap-codec": "^1.5.5"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.1.3",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||
@@ -1533,6 +1768,23 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/pathe": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",
|
||||
"integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/pathval": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.1.tgz",
|
||||
"integrity": "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 14.16"
|
||||
}
|
||||
},
|
||||
"node_modules/picocolors": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
|
||||
@@ -1674,6 +1926,13 @@
|
||||
"semver": "bin/semver.js"
|
||||
}
|
||||
},
|
||||
"node_modules/siginfo": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz",
|
||||
"integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==",
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/source-map-js": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
||||
@@ -1684,6 +1943,54 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/stackback": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",
|
||||
"integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/std-env": {
|
||||
"version": "3.10.0",
|
||||
"resolved": "https://registry.npmjs.org/std-env/-/std-env-3.10.0.tgz",
|
||||
"integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/strip-literal": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-3.1.0.tgz",
|
||||
"integrity": "sha512-8r3mkIM/2+PpjHoOtiAW8Rg3jJLHaV7xPwG+YRGrv6FP0wwk/toTpATxWYOW0BKdWwl82VT2tFYi5DlROa0Mxg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"js-tokens": "^9.0.1"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/antfu"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-literal/node_modules/js-tokens": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-9.0.1.tgz",
|
||||
"integrity": "sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tinybench": {
|
||||
"version": "2.9.0",
|
||||
"resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz",
|
||||
"integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tinyexec": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.2.tgz",
|
||||
"integrity": "sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tinyglobby": {
|
||||
"version": "0.2.15",
|
||||
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz",
|
||||
@@ -1701,6 +2008,36 @@
|
||||
"url": "https://github.com/sponsors/SuperchupuDev"
|
||||
}
|
||||
},
|
||||
"node_modules/tinypool": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/tinypool/-/tinypool-1.1.1.tgz",
|
||||
"integrity": "sha512-Zba82s87IFq9A9XmjiX5uZA/ARWDrB03OHlq+Vw1fSdt0I+4/Kutwy8BP4Y/y/aORMo61FQ0vIb5j44vSo5Pkg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^18.0.0 || >=20.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyrainbow": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-2.0.0.tgz",
|
||||
"integrity": "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tinyspy": {
|
||||
"version": "4.0.4",
|
||||
"resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-4.0.4.tgz",
|
||||
"integrity": "sha512-azl+t0z7pw/z958Gy9svOTuzqIk6xq+NSheJzn5MMWtWTFywIacg2wUlzKFGtt3cthx0r2SxMK0yzJOR0IES7Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.9.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||
@@ -1828,6 +2165,119 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/vite-node": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/vite-node/-/vite-node-3.2.4.tgz",
|
||||
"integrity": "sha512-EbKSKh+bh1E1IFxeO0pg1n4dvoOTt0UDiXMd/qn++r98+jPO1xtJilvXldeuQ8giIB5IkpjCgMleHMNEsGH6pg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cac": "^6.7.14",
|
||||
"debug": "^4.4.1",
|
||||
"es-module-lexer": "^1.7.0",
|
||||
"pathe": "^2.0.3",
|
||||
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0"
|
||||
},
|
||||
"bin": {
|
||||
"vite-node": "vite-node.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.0.0 || ^20.0.0 || >=22.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
}
|
||||
},
|
||||
"node_modules/vitest": {
|
||||
"version": "3.2.4",
|
||||
"resolved": "https://registry.npmjs.org/vitest/-/vitest-3.2.4.tgz",
|
||||
"integrity": "sha512-LUCP5ev3GURDysTWiP47wRRUpLKMOfPh+yKTx3kVIEiu5KOMeqzpnYNsKyOoVrULivR8tLcks4+lga33Whn90A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/chai": "^5.2.2",
|
||||
"@vitest/expect": "3.2.4",
|
||||
"@vitest/mocker": "3.2.4",
|
||||
"@vitest/pretty-format": "^3.2.4",
|
||||
"@vitest/runner": "3.2.4",
|
||||
"@vitest/snapshot": "3.2.4",
|
||||
"@vitest/spy": "3.2.4",
|
||||
"@vitest/utils": "3.2.4",
|
||||
"chai": "^5.2.0",
|
||||
"debug": "^4.4.1",
|
||||
"expect-type": "^1.2.1",
|
||||
"magic-string": "^0.30.17",
|
||||
"pathe": "^2.0.3",
|
||||
"picomatch": "^4.0.2",
|
||||
"std-env": "^3.9.0",
|
||||
"tinybench": "^2.9.0",
|
||||
"tinyexec": "^0.3.2",
|
||||
"tinyglobby": "^0.2.14",
|
||||
"tinypool": "^1.1.1",
|
||||
"tinyrainbow": "^2.0.0",
|
||||
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0",
|
||||
"vite-node": "3.2.4",
|
||||
"why-is-node-running": "^2.3.0"
|
||||
},
|
||||
"bin": {
|
||||
"vitest": "vitest.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^18.0.0 || ^20.0.0 || >=22.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@edge-runtime/vm": "*",
|
||||
"@types/debug": "^4.1.12",
|
||||
"@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0",
|
||||
"@vitest/browser": "3.2.4",
|
||||
"@vitest/ui": "3.2.4",
|
||||
"happy-dom": "*",
|
||||
"jsdom": "*"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@edge-runtime/vm": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/debug": {
|
||||
"optional": true
|
||||
},
|
||||
"@types/node": {
|
||||
"optional": true
|
||||
},
|
||||
"@vitest/browser": {
|
||||
"optional": true
|
||||
},
|
||||
"@vitest/ui": {
|
||||
"optional": true
|
||||
},
|
||||
"happy-dom": {
|
||||
"optional": true
|
||||
},
|
||||
"jsdom": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/why-is-node-running": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz",
|
||||
"integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"siginfo": "^2.0.0",
|
||||
"stackback": "0.0.2"
|
||||
},
|
||||
"bin": {
|
||||
"why-is-node-running": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/yallist": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
"dev": "vite",
|
||||
"build": "npm run check && vite build",
|
||||
"preview": "vite preview",
|
||||
"check": "tsc --noEmit -p tsconfig.app.json && tsc --noEmit -p tsconfig.node.json"
|
||||
"check": "tsc --noEmit -p tsconfig.app.json && tsc --noEmit -p tsconfig.node.json",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.0.0",
|
||||
@@ -20,6 +21,7 @@
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"@vitejs/plugin-react": "^4.4.1",
|
||||
"typescript": "^5.8.2",
|
||||
"vite": "^6.2.0"
|
||||
"vite": "^6.2.0",
|
||||
"vitest": "^3.0.8"
|
||||
}
|
||||
}
|
||||
|
||||
60
src/data/contentHelpers.test.ts
Normal file
60
src/data/contentHelpers.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { lookupTable } from "@/rules/tables";
|
||||
|
||||
import {
|
||||
findCreatureByName,
|
||||
findRoomTemplateForLookup,
|
||||
findTableByCode,
|
||||
} from "./contentHelpers";
|
||||
import { sampleContentPack } from "./sampleContentPack";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
describe("level 1 content helpers", () => {
|
||||
it("finds encoded level 1 encounter tables by code", () => {
|
||||
const table = findTableByCode(sampleContentPack, "L1A");
|
||||
|
||||
expect(table.name).toBe("Level 1 Animals");
|
||||
expect(table.entries).toHaveLength(6);
|
||||
});
|
||||
|
||||
it("resolves a small room template from a table lookup", () => {
|
||||
const lookup = lookupTable(findTableByCode(sampleContentPack, "L1SR"), {
|
||||
roller: createSequenceRoller([3, 4]),
|
||||
});
|
||||
|
||||
const roomTemplate = findRoomTemplateForLookup(sampleContentPack, lookup);
|
||||
|
||||
expect(lookup.roll.total).toBe(7);
|
||||
expect(roomTemplate.title).toBe("Murtayne Effigy");
|
||||
expect(roomTemplate.roomClass).toBe("small");
|
||||
});
|
||||
|
||||
it("resolves a large room template from a table lookup", () => {
|
||||
const lookup = lookupTable(findTableByCode(sampleContentPack, "L1LR"), {
|
||||
roller: createSequenceRoller([5, 5]),
|
||||
});
|
||||
|
||||
const roomTemplate = findRoomTemplateForLookup(sampleContentPack, lookup);
|
||||
|
||||
expect(lookup.roll.total).toBe(10);
|
||||
expect(roomTemplate.title).toBe("Slate Shrine");
|
||||
expect(roomTemplate.roomClass).toBe("large");
|
||||
});
|
||||
|
||||
it("finds a creature definition by display name", () => {
|
||||
const creature = findCreatureByName(sampleContentPack, "Guard");
|
||||
|
||||
expect(creature.id).toBe("creature.level1.guard");
|
||||
expect(creature.hp).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
63
src/data/contentHelpers.ts
Normal file
63
src/data/contentHelpers.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import type {
|
||||
ContentPack,
|
||||
CreatureDefinition,
|
||||
RoomTemplate,
|
||||
TableDefinition,
|
||||
} from "@/types/content";
|
||||
import type { TableLookupResult } from "@/rules/tables";
|
||||
|
||||
export function findTableByCode(content: ContentPack, code: string): TableDefinition {
|
||||
const table = content.tables.find((entry) => entry.code === code);
|
||||
|
||||
if (!table) {
|
||||
throw new Error(`Unknown table code: ${code}`);
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
export function findRoomTemplateById(
|
||||
content: ContentPack,
|
||||
roomTemplateId: string,
|
||||
): RoomTemplate {
|
||||
const roomTemplate = content.roomTemplates.find((entry) => entry.id === roomTemplateId);
|
||||
|
||||
if (!roomTemplate) {
|
||||
throw new Error(`Unknown room template id: ${roomTemplateId}`);
|
||||
}
|
||||
|
||||
return roomTemplate;
|
||||
}
|
||||
|
||||
export function findRoomTemplateForLookup(
|
||||
content: ContentPack,
|
||||
lookup: TableLookupResult,
|
||||
): RoomTemplate {
|
||||
const roomReference = lookup.entry.references?.find((reference) => reference.type === "room");
|
||||
|
||||
if (!roomReference) {
|
||||
throw new Error(`Lookup result ${lookup.tableId}:${lookup.entryKey} does not point to a room.`);
|
||||
}
|
||||
|
||||
return findRoomTemplateById(content, roomReference.id);
|
||||
}
|
||||
|
||||
function normalizeName(value: string) {
|
||||
return value.trim().toLowerCase().replace(/\s+/g, " ");
|
||||
}
|
||||
|
||||
export function findCreatureByName(
|
||||
content: ContentPack,
|
||||
creatureName: string,
|
||||
): CreatureDefinition {
|
||||
const normalizedTarget = normalizeName(creatureName);
|
||||
const creature = content.creatures.find(
|
||||
(entry) => normalizeName(entry.name) === normalizedTarget,
|
||||
);
|
||||
|
||||
if (!creature) {
|
||||
throw new Error(`Unknown creature name: ${creatureName}`);
|
||||
}
|
||||
|
||||
return creature;
|
||||
}
|
||||
649
src/data/level1Rooms.ts
Normal file
649
src/data/level1Rooms.ts
Normal file
@@ -0,0 +1,649 @@
|
||||
import type { RoomTemplate } from "@/types/content";
|
||||
|
||||
export const level1RoomTemplates: RoomTemplate[] = [
|
||||
{
|
||||
id: "room.level1.normal.empty-room",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "2",
|
||||
title: "Empty Room",
|
||||
text: "A bare chamber with little more than dust and stone.",
|
||||
encounterText: "Nothing here.",
|
||||
exitHint: "Archways only.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "empty"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.abandoned-guard-post",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "3",
|
||||
title: "Abandoned Guard Post",
|
||||
text: "A disused guard station with ruined furnishings and signs of looting.",
|
||||
encounterText: "Search debris for wooden objects beneath collapsed furniture.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "search"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.guard-post",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "4",
|
||||
title: "Guard Post",
|
||||
text: "A still-used guard room with a table, benches, and simple fixtures.",
|
||||
encounterText: "If occupied, use the martial encounter table.",
|
||||
exitHint: "Reinforced wooden doors.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "guards"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.storage-area",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "5",
|
||||
title: "Storage Area",
|
||||
text: "Crates and barrels fill the walls, with spoiled goods hidden among them.",
|
||||
encounterText: "Roll for food, drink, or crate events while searching.",
|
||||
exitHint: "Archways.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "loot"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.meeting-room",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "6",
|
||||
title: "Meeting Room",
|
||||
text: "Simple tables and chairs suggest an old gathering place.",
|
||||
encounterText: "Workers or a crazed preacher may be present depending on the table roll.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "social"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.blacksmith-space",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "7",
|
||||
title: "Blacksmith Space",
|
||||
text: "An anvil and cold forge remain in a soot-darkened workshop.",
|
||||
encounterText: "Roll for weapon loot or a worker-themed encounter.",
|
||||
exitHint: "Archways.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "craft"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.holding-cell",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "8",
|
||||
title: "Holding Cell",
|
||||
text: "A grim cell with chains, a chamber pot, and signs of former prisoners.",
|
||||
encounterText: "Check whether the cell is empty or contains a prisoner.",
|
||||
exitHint: "Reinforced doors.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "cell"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.wash-room",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "9",
|
||||
title: "Wash Room",
|
||||
text: "Buckets, basins, and cloths suggest a communal cleaning room.",
|
||||
encounterText: "May contain slimy or fungal threats and hidden salvage.",
|
||||
exitHint: "Random roll for exits.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "utility"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.kennel",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "10",
|
||||
title: "Kennel",
|
||||
text: "A low room littered with straw and the stink of animals.",
|
||||
encounterText: "Use the level 1 dogs table if occupied.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "animals"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.snake-pit",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "11",
|
||||
title: "Snake Pit",
|
||||
text: "A dusty pit cut into the floor houses a nest of snakes.",
|
||||
encounterText: "Open the chest only if you survive the pit's occupants.",
|
||||
exitHint: "Random roll for exits.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "animals", "hazard"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.weapon-dump",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P1",
|
||||
tableEntryKey: "12",
|
||||
title: "Weapon Dump",
|
||||
text: "Broken weapons and shields spill from a long-past discard pile.",
|
||||
encounterText: "Roll for random weapons and possible fungal attackers.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "loot", "weapons"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.guard-room",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "2",
|
||||
title: "Guard Room",
|
||||
text: "A stone room with table, chairs, and signs of routine occupation.",
|
||||
encounterText: "Use the guards encounter table if occupied.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "guards"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.pool-room",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "3",
|
||||
title: "Pool Room",
|
||||
text: "A raised stone pool dominates the center of this damp chamber.",
|
||||
encounterText: "Investigating the pool may trigger a slimy or animal threat.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "water"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.storage-area-2",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "4",
|
||||
title: "Storage Area",
|
||||
text: "Ropes, cloth, and supplies are stacked among the dust.",
|
||||
encounterText: "Arms and empty chests invite a guarded search.",
|
||||
exitHint: "Archways.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "loot"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.canteen",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "5",
|
||||
title: "Canteen",
|
||||
text: "Rough tables and stools fill an old communal eating space.",
|
||||
encounterText: "Labourers or workers may still be here.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "social"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.mourning-quarters",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "6",
|
||||
title: "Mourning Quarters",
|
||||
text: "An eerie chamber of candles, a shrouded bier, and stale grief.",
|
||||
encounterText: "A corpse may be present and can trigger a level 1 corpse interaction.",
|
||||
exitHint: "Random roll for exits.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "ritual"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.holding-cell-2",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "7",
|
||||
title: "Holding Cell",
|
||||
text: "A bare cell cut off from the rest of the room by bars.",
|
||||
encounterText: "Check for a prisoner before searching further.",
|
||||
exitHint: "Reinforced doors.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "cell"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.training-room",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "8",
|
||||
title: "Training Room",
|
||||
text: "Mannequins, target poles, and old practice gear fill the space.",
|
||||
encounterText: "Armour and weapons training prompts a follow-up armour or item roll.",
|
||||
exitHint: "Random roll for exits.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "training"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.dorm",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "9",
|
||||
title: "Dorm",
|
||||
text: "Hammocks and scattered belongings suggest a once-lived-in barracks room.",
|
||||
encounterText: "Use the people table if the dorm is occupied.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "sleeping"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.apothecary",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "10",
|
||||
title: "Apothecary",
|
||||
text: "Shelves of jars and bottles crowd a room thick with old herbs.",
|
||||
encounterText: "Medicine or potion finds compete with apothecary occupants.",
|
||||
exitHint: "Random roll for exits.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "alchemy"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.damp-space",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "11",
|
||||
title: "Damp Space",
|
||||
text: "Moist stone and fungus overrun this clammy side room.",
|
||||
encounterText: "A fungal encounter may attack when the fungus is disturbed.",
|
||||
exitHint: "Reinforced doors.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "fungal"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.normal.chapel",
|
||||
level: 1,
|
||||
sourcePage: 43,
|
||||
roomClass: "normal",
|
||||
tableCode: "L1R-P2",
|
||||
tableEntryKey: "12",
|
||||
title: "Chapel",
|
||||
text: "Candles, benches, and a central altar mark a room of devotion.",
|
||||
encounterText: "Dark clergy or a corpse event can emerge here after the altar is examined.",
|
||||
exitHint: "Curtains.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "religious"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.stone-workshop",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "2",
|
||||
title: "Stone Workshop",
|
||||
text: "Large tables, stone shelves, and an oversized work area dominate the room.",
|
||||
encounterText: "No built-in encounter.",
|
||||
exitHint: "Wooden doors.",
|
||||
tags: ["human-ancestry", "large", "craft"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.marble-hall",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "3",
|
||||
title: "Marble Hall",
|
||||
text: "A ceremonial hall lined with pillars and a raised seating platform.",
|
||||
encounterText: "No built-in encounter.",
|
||||
exitHint: "Archways.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "large", "hall"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.old-mess-hall",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "4",
|
||||
title: "Old Mess Hall",
|
||||
text: "Long tables and benches suggest a once-busy common dining area.",
|
||||
encounterText: "No built-in encounter.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "large", "social"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.penitentiary",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "5",
|
||||
title: "Penitentiary",
|
||||
text: "A chained whipping post and harsh punishments define this grim chamber.",
|
||||
encounterText: "No built-in encounter.",
|
||||
exitHint: "Reinforced doors.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "large", "punishment"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.fountain-room",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "6",
|
||||
title: "Fountain Room",
|
||||
text: "A circular fountain and polished floor lend this chamber a sacred tone.",
|
||||
encounterText: "No built-in encounter.",
|
||||
exitHint: "Archways.",
|
||||
tags: ["human-ancestry", "large", "water"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.temple",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "7",
|
||||
title: "Temple",
|
||||
text: "Benches and chandeliers frame a formal place of worship.",
|
||||
encounterText: "No built-in encounter.",
|
||||
exitHint: "Archways.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "large", "religious"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.sparring-chamber",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "8",
|
||||
title: "Sparring Chamber",
|
||||
text: "Sand, markings, and weapons racks show this room was used for training.",
|
||||
encounterText: "A warrior can appear here.",
|
||||
exitHint: "Wooden doors.",
|
||||
tags: ["human-ancestry", "large", "training"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.crate-store",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "9",
|
||||
title: "Crate Store",
|
||||
text: "Crates and stacked stone create shadows and possible hidden spaces.",
|
||||
encounterText: "No built-in encounter.",
|
||||
exitHint: "Archways.",
|
||||
tags: ["human-ancestry", "large", "loot"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.slate-shrine",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "10",
|
||||
title: "Slate Shrine",
|
||||
text: "A central slate monolith marks a room of devotion and offering.",
|
||||
encounterText: "No built-in encounter.",
|
||||
exitHint: "Archways.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "large", "religious"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.dormitory",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "11",
|
||||
title: "Dormitory",
|
||||
text: "Rows of bunks and sparse belongings line the walls.",
|
||||
encounterText: "No built-in encounter.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "large", "sleeping"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.large.library",
|
||||
level: 1,
|
||||
sourcePage: 40,
|
||||
roomClass: "large",
|
||||
tableCode: "L1LR",
|
||||
tableEntryKey: "12",
|
||||
title: "Library",
|
||||
text: "Towering bookshelves and guarded knowledge define this vast archive.",
|
||||
encounterText: "Two guards can be found here.",
|
||||
exitHint: "Wooden doors.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "large", "books"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.empty-space",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "2",
|
||||
title: "Empty Space",
|
||||
text: "A bare side space with nothing of note.",
|
||||
encounterText: "Nothing here.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "small", "empty"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.strange-text",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "3",
|
||||
title: "Strange Text",
|
||||
text: "An old message linking the corridor to ancient hunger and warning.",
|
||||
encounterText: "No encounter.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "small", "lore"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.grazada-mural",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "4",
|
||||
title: "Grazada Mural",
|
||||
text: "A tiled image of the goddess of sacrifice fills the wall.",
|
||||
encounterText: "A possible favour interaction.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "small", "religious"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.intuneric-mosaic",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "5",
|
||||
title: "Intuneric Mosaic",
|
||||
text: "A shrine mosaic to the god of influence and gifts.",
|
||||
encounterText: "A possible favour interaction.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "small", "religious"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.maduva-statue",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "6",
|
||||
title: "Maduva Statue",
|
||||
text: "A twisted statue of Maduva stands watch in the niche.",
|
||||
encounterText: "A possible favour interaction.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "small", "religious"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.murtayne-effigy",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "7",
|
||||
title: "Murtayne Effigy",
|
||||
text: "A rotting fleshy effigy marks a place linked to disease and corruption.",
|
||||
encounterText: "A possible favour interaction.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "small", "religious"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.nevzator-doll",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "8",
|
||||
title: "Nevzator Doll",
|
||||
text: "A rope doll symbolizes hidden dealings and quiet bargains.",
|
||||
encounterText: "A possible favour interaction.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "small", "religious"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.radacina-tapestry",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "9",
|
||||
title: "Radacina Tapestry",
|
||||
text: "A tapestry of Radacina, deity of teaching, hangs in the space.",
|
||||
encounterText: "A possible favour interaction.",
|
||||
unique: true,
|
||||
tags: ["human-ancestry", "small", "religious"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.heated-space",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "10",
|
||||
title: "Heated Space",
|
||||
text: "Warmth and wavering shadows suggest hidden heat behind the walls.",
|
||||
encounterText: "No encounter.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "small", "atmosphere"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.wall-shrine",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "11",
|
||||
title: "Wall Shrine",
|
||||
text: "A small offering niche waits at the wall's edge.",
|
||||
encounterText: "A possible favour interaction.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "small", "religious"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "room.level1.small.banner-arms",
|
||||
level: 1,
|
||||
sourcePage: 46,
|
||||
roomClass: "small",
|
||||
tableCode: "L1SR",
|
||||
tableEntryKey: "12",
|
||||
title: "Banner Arms",
|
||||
text: "Crossed spears and an old shield suggest a ceremonial martial display.",
|
||||
encounterText: "No encounter.",
|
||||
unique: false,
|
||||
tags: ["human-ancestry", "small", "martial"],
|
||||
mvp: true,
|
||||
},
|
||||
];
|
||||
224
src/data/level1Tables.ts
Normal file
224
src/data/level1Tables.ts
Normal file
@@ -0,0 +1,224 @@
|
||||
import type { TableDefinition } from "@/types/content";
|
||||
|
||||
export const level1EncounterTables: TableDefinition[] = [
|
||||
{
|
||||
id: "table.level1.animals",
|
||||
code: "L1A",
|
||||
name: "Level 1 Animals",
|
||||
category: "level",
|
||||
level: 1,
|
||||
page: 38,
|
||||
diceKind: "d6",
|
||||
entries: [
|
||||
{ key: "1", exact: 1, label: "Giant Rat" },
|
||||
{ key: "2", exact: 2, label: "Huge Rat" },
|
||||
{ key: "3", exact: 3, label: "Work Dog" },
|
||||
{ key: "4", exact: 4, label: "Guard Dog" },
|
||||
{ key: "5", exact: 5, label: "Shard Rock Python" },
|
||||
{ key: "6", exact: 6, label: "Giant Horned Anaconda" },
|
||||
],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "table.level1.martial",
|
||||
code: "L1M",
|
||||
name: "Level 1 Martial",
|
||||
category: "level",
|
||||
level: 1,
|
||||
page: 38,
|
||||
diceKind: "d6",
|
||||
entries: [
|
||||
{ key: "1", exact: 1, label: "Guard" },
|
||||
{ key: "2", exact: 2, label: "Guard" },
|
||||
{ key: "3", exact: 3, label: "Warrior" },
|
||||
{ key: "4", exact: 4, label: "Veteran" },
|
||||
{ key: "5", exact: 5, label: "Veteran" },
|
||||
{ key: "6", exact: 6, label: "Guard and Guard" },
|
||||
],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "table.level1.dogs",
|
||||
code: "L1D",
|
||||
name: "Level 1 Dogs",
|
||||
category: "level",
|
||||
level: 1,
|
||||
page: 38,
|
||||
diceKind: "d6",
|
||||
entries: [
|
||||
{ key: "1", exact: 1, label: "Work Dog" },
|
||||
{ key: "2", exact: 2, label: "Guard Dog" },
|
||||
{ key: "3", exact: 3, label: "Guard Dog" },
|
||||
{ key: "4", exact: 4, label: "Guard Hound" },
|
||||
{ key: "5", exact: 5, label: "War Hound" },
|
||||
{ key: "6", exact: 6, label: "Guard and Work Dog" },
|
||||
],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "table.level1.people",
|
||||
code: "L1P",
|
||||
name: "Level 1 People",
|
||||
category: "level",
|
||||
level: 1,
|
||||
page: 38,
|
||||
diceKind: "d6",
|
||||
entries: [
|
||||
{ key: "1", exact: 1, label: "Labourer" },
|
||||
{ key: "2", exact: 2, label: "Crazed Preacher" },
|
||||
{ key: "3", exact: 3, label: "Thug" },
|
||||
{ key: "4", exact: 4, label: "Guard" },
|
||||
{ key: "5", exact: 5, label: "Guard and Guard Dog" },
|
||||
{ key: "6", exact: 6, label: "Labourer and Guard Dog" },
|
||||
],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "table.level1.fungal",
|
||||
code: "L1F",
|
||||
name: "Level 1 Fungal",
|
||||
category: "level",
|
||||
level: 1,
|
||||
page: 38,
|
||||
diceKind: "d6",
|
||||
entries: [
|
||||
{ key: "1", exact: 1, label: "Fungal Geist" },
|
||||
{ key: "2", exact: 2, label: "Fungal Geist" },
|
||||
{ key: "3", exact: 3, label: "Musty Bloater" },
|
||||
{ key: "4", exact: 4, label: "Musty Bloater" },
|
||||
{ key: "5", exact: 5, label: "Musty Bloater" },
|
||||
{ key: "6", exact: 6, label: "Slimy Gorger" },
|
||||
],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "table.level1.guards",
|
||||
code: "L1G",
|
||||
name: "Level 1 Guards",
|
||||
category: "level",
|
||||
level: 1,
|
||||
page: 38,
|
||||
diceKind: "d6",
|
||||
entries: [
|
||||
{ key: "1", exact: 1, label: "Thug" },
|
||||
{ key: "2", exact: 2, label: "Thug" },
|
||||
{ key: "3", exact: 3, label: "Guard" },
|
||||
{ key: "4", exact: 4, label: "Guard" },
|
||||
{ key: "5", exact: 5, label: "Guard" },
|
||||
{ key: "6", exact: 6, label: "Guard and Warrior" },
|
||||
],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "table.level1.workers",
|
||||
code: "L1W",
|
||||
name: "Level 1 Workers",
|
||||
category: "level",
|
||||
level: 1,
|
||||
page: 38,
|
||||
diceKind: "d6",
|
||||
entries: [
|
||||
{ key: "1", exact: 1, label: "Thug" },
|
||||
{ key: "2", exact: 2, label: "Thug" },
|
||||
{ key: "3", exact: 3, label: "Labourer" },
|
||||
{ key: "4", exact: 4, label: "Artisan" },
|
||||
{ key: "5", exact: 5, label: "Blacksmith" },
|
||||
{ key: "6", exact: 6, label: "Artisan and Medic" },
|
||||
],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "table.level1.crate",
|
||||
code: "L1CE",
|
||||
name: "Level 1 Crate",
|
||||
category: "level",
|
||||
level: 1,
|
||||
page: 38,
|
||||
diceKind: "d6",
|
||||
entries: [
|
||||
{
|
||||
key: "1",
|
||||
exact: 1,
|
||||
label: "Slimy Gorger Ambush",
|
||||
text: "A slimy gorger drops from above and attacks immediately.",
|
||||
},
|
||||
{
|
||||
key: "2",
|
||||
exact: 2,
|
||||
label: "Giant Rat Pair",
|
||||
text: "A pair of giant rats attacks while the room is being searched.",
|
||||
},
|
||||
{
|
||||
key: "3",
|
||||
exact: 3,
|
||||
label: "Huge Rat Ambush",
|
||||
text: "A huge rat leaps from under the crate and attacks.",
|
||||
},
|
||||
{
|
||||
key: "4",
|
||||
exact: 4,
|
||||
label: "Insect Swarm",
|
||||
text: "Scuttling insects spill out from beneath a corpse during the search.",
|
||||
},
|
||||
{
|
||||
key: "5",
|
||||
exact: 5,
|
||||
label: "Corpse Trap",
|
||||
text: "Searching the fallen body triggers a level 1 corpse-interaction event.",
|
||||
},
|
||||
{
|
||||
key: "6",
|
||||
exact: 6,
|
||||
label: "Hooked Bag",
|
||||
text: "A bag fixed near the ceiling calls for a follow-up item table roll.",
|
||||
},
|
||||
],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "table.level1.large-rooms",
|
||||
code: "L1LR",
|
||||
name: "Level 1 Large Rooms",
|
||||
category: "room",
|
||||
level: 1,
|
||||
page: 40,
|
||||
diceKind: "2d6",
|
||||
entries: [
|
||||
{ key: "2", exact: 2, label: "Stone Workshop", references: [{ type: "room", id: "room.level1.large.stone-workshop" }] },
|
||||
{ key: "3", exact: 3, label: "Marble Hall", references: [{ type: "room", id: "room.level1.large.marble-hall" }] },
|
||||
{ key: "4", exact: 4, label: "Old Mess Hall", references: [{ type: "room", id: "room.level1.large.old-mess-hall" }] },
|
||||
{ key: "5", exact: 5, label: "Penitentiary", references: [{ type: "room", id: "room.level1.large.penitentiary" }] },
|
||||
{ key: "6", exact: 6, label: "Fountain Room", references: [{ type: "room", id: "room.level1.large.fountain-room" }] },
|
||||
{ key: "7", exact: 7, label: "Temple", references: [{ type: "room", id: "room.level1.large.temple" }] },
|
||||
{ key: "8", exact: 8, label: "Sparring Chamber", references: [{ type: "room", id: "room.level1.large.sparring-chamber" }] },
|
||||
{ key: "9", exact: 9, label: "Crate Store", references: [{ type: "room", id: "room.level1.large.crate-store" }] },
|
||||
{ key: "10", exact: 10, label: "Slate Shrine", references: [{ type: "room", id: "room.level1.large.slate-shrine" }] },
|
||||
{ key: "11", exact: 11, label: "Dormitory", references: [{ type: "room", id: "room.level1.large.dormitory" }] },
|
||||
{ key: "12", exact: 12, label: "Library", references: [{ type: "room", id: "room.level1.large.library" }] },
|
||||
],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "table.level1.small-rooms",
|
||||
code: "L1SR",
|
||||
name: "Level 1 Small Rooms",
|
||||
category: "room",
|
||||
level: 1,
|
||||
page: 46,
|
||||
diceKind: "2d6",
|
||||
entries: [
|
||||
{ key: "2", exact: 2, label: "Empty Space", references: [{ type: "room", id: "room.level1.small.empty-space" }] },
|
||||
{ key: "3", exact: 3, label: "Strange Text", references: [{ type: "room", id: "room.level1.small.strange-text" }] },
|
||||
{ key: "4", exact: 4, label: "Grazada Mural", references: [{ type: "room", id: "room.level1.small.grazada-mural" }] },
|
||||
{ key: "5", exact: 5, label: "Intuneric Mosaic", references: [{ type: "room", id: "room.level1.small.intuneric-mosaic" }] },
|
||||
{ key: "6", exact: 6, label: "Maduva Statue", references: [{ type: "room", id: "room.level1.small.maduva-statue" }] },
|
||||
{ key: "7", exact: 7, label: "Murtayne Effigy", references: [{ type: "room", id: "room.level1.small.murtayne-effigy" }] },
|
||||
{ key: "8", exact: 8, label: "Nevzator Doll", references: [{ type: "room", id: "room.level1.small.nevzator-doll" }] },
|
||||
{ key: "9", exact: 9, label: "Radacina Tapestry", references: [{ type: "room", id: "room.level1.small.radacina-tapestry" }] },
|
||||
{ key: "10", exact: 10, label: "Heated Space", references: [{ type: "room", id: "room.level1.small.heated-space" }] },
|
||||
{ key: "11", exact: 11, label: "Wall Shrine", references: [{ type: "room", id: "room.level1.small.wall-shrine" }] },
|
||||
{ key: "12", exact: 12, label: "Banner Arms", references: [{ type: "room", id: "room.level1.small.banner-arms" }] },
|
||||
],
|
||||
mvp: true,
|
||||
},
|
||||
];
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { ContentPack } from "@/types/content";
|
||||
|
||||
import { contentPackSchema } from "@/schemas/content";
|
||||
import { level1RoomTemplates } from "./level1Rooms";
|
||||
import { level1EncounterTables } from "./level1Tables";
|
||||
|
||||
const samplePack = {
|
||||
version: "0.1.0",
|
||||
@@ -10,6 +12,7 @@ const samplePack = {
|
||||
"Source/2D6 Dungeon - Play Sheet.pdf",
|
||||
],
|
||||
tables: [
|
||||
...level1EncounterTables,
|
||||
{
|
||||
id: "table.weapon-manoeuvres-1",
|
||||
code: "WMT1",
|
||||
@@ -72,6 +75,14 @@ const samplePack = {
|
||||
},
|
||||
],
|
||||
items: [
|
||||
{
|
||||
id: "item.flint-and-steel",
|
||||
name: "Flint and Steel",
|
||||
itemType: "gear",
|
||||
stackable: false,
|
||||
consumable: false,
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "item.ration",
|
||||
name: "Ration",
|
||||
@@ -88,6 +99,30 @@ const samplePack = {
|
||||
consumable: false,
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "item.pouch",
|
||||
name: "Pouch",
|
||||
itemType: "gear",
|
||||
stackable: false,
|
||||
consumable: false,
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "item.wax-sealing-kit",
|
||||
name: "Wax Sealing Kit",
|
||||
itemType: "gear",
|
||||
stackable: false,
|
||||
consumable: false,
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "item.backpack",
|
||||
name: "Backpack",
|
||||
itemType: "gear",
|
||||
stackable: false,
|
||||
consumable: false,
|
||||
mvp: true,
|
||||
},
|
||||
],
|
||||
potions: [
|
||||
{
|
||||
@@ -132,11 +167,98 @@ const samplePack = {
|
||||
traits: ["level-1", "sample"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "creature.level1.guard",
|
||||
name: "Guard",
|
||||
level: 1,
|
||||
category: "humanoid",
|
||||
hp: 4,
|
||||
attackProfile: {
|
||||
discipline: 1,
|
||||
precision: 1,
|
||||
damage: 1,
|
||||
},
|
||||
defenceProfile: {
|
||||
armour: 1,
|
||||
},
|
||||
xpReward: 2,
|
||||
sourcePage: 102,
|
||||
traits: ["level-1", "martial"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "creature.level1.warrior",
|
||||
name: "Warrior",
|
||||
level: 1,
|
||||
category: "humanoid",
|
||||
hp: 5,
|
||||
attackProfile: {
|
||||
discipline: 2,
|
||||
precision: 1,
|
||||
damage: 2,
|
||||
},
|
||||
defenceProfile: {
|
||||
armour: 1,
|
||||
},
|
||||
xpReward: 3,
|
||||
sourcePage: 102,
|
||||
traits: ["level-1", "martial"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "creature.level1.thug",
|
||||
name: "Thug",
|
||||
level: 1,
|
||||
category: "humanoid",
|
||||
hp: 3,
|
||||
attackProfile: {
|
||||
discipline: 0,
|
||||
precision: 1,
|
||||
damage: 1,
|
||||
},
|
||||
xpReward: 1,
|
||||
sourcePage: 102,
|
||||
traits: ["level-1", "martial"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "creature.level1.work-dog",
|
||||
name: "Work Dog",
|
||||
level: 1,
|
||||
category: "beast",
|
||||
hp: 3,
|
||||
attackProfile: {
|
||||
discipline: 0,
|
||||
precision: 1,
|
||||
damage: 1,
|
||||
},
|
||||
xpReward: 1,
|
||||
sourcePage: 102,
|
||||
traits: ["level-1", "beast"],
|
||||
mvp: true,
|
||||
},
|
||||
{
|
||||
id: "creature.level1.guard-dog",
|
||||
name: "Guard Dog",
|
||||
level: 1,
|
||||
category: "beast",
|
||||
hp: 4,
|
||||
attackProfile: {
|
||||
discipline: 1,
|
||||
precision: 1,
|
||||
damage: 1,
|
||||
},
|
||||
xpReward: 2,
|
||||
sourcePage: 102,
|
||||
traits: ["level-1", "beast"],
|
||||
mvp: true,
|
||||
},
|
||||
],
|
||||
roomTemplates: [
|
||||
{
|
||||
id: "room.level1.entry",
|
||||
level: 1,
|
||||
sourcePage: 42,
|
||||
roomClass: "start",
|
||||
tableCode: "L1R",
|
||||
tableEntryKey: "entry",
|
||||
@@ -150,6 +272,7 @@ const samplePack = {
|
||||
tags: ["starter", "entry"],
|
||||
mvp: true,
|
||||
},
|
||||
...level1RoomTemplates,
|
||||
],
|
||||
townServices: [
|
||||
{
|
||||
|
||||
50
src/rules/character.test.ts
Normal file
50
src/rules/character.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
||||
|
||||
import { createStartingAdventurer, getCharacterCreationOptions } from "./character";
|
||||
|
||||
describe("character creation", () => {
|
||||
it("exposes legal starting options from the content pack", () => {
|
||||
const options = getCharacterCreationOptions(sampleContentPack);
|
||||
|
||||
expect(options.weapons).toHaveLength(1);
|
||||
expect(options.armour).toHaveLength(1);
|
||||
expect(options.scrolls).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("builds a valid starting adventurer from legal choices", () => {
|
||||
const adventurer = createStartingAdventurer(sampleContentPack, {
|
||||
name: "Mira",
|
||||
weaponId: "weapon.short-sword",
|
||||
armourId: "armour.leather-vest",
|
||||
scrollId: "scroll.lesser-heal",
|
||||
});
|
||||
|
||||
expect(adventurer.name).toBe("Mira");
|
||||
expect(adventurer.level).toBe(1);
|
||||
expect(adventurer.stats.shift).toBe(2);
|
||||
expect(adventurer.manoeuvreIds).toEqual([
|
||||
"manoeuvre.exact-strike",
|
||||
"manoeuvre.guard-break",
|
||||
]);
|
||||
expect(adventurer.inventory.rationCount).toBe(3);
|
||||
expect(adventurer.inventory.carried).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ definitionId: "potion.healing", quantity: 1 }),
|
||||
expect.objectContaining({ definitionId: "scroll.lesser-heal", quantity: 1 }),
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects an empty adventurer name", () => {
|
||||
expect(() =>
|
||||
createStartingAdventurer(sampleContentPack, {
|
||||
name: " ",
|
||||
weaponId: "weapon.short-sword",
|
||||
armourId: "armour.leather-vest",
|
||||
scrollId: "scroll.lesser-heal",
|
||||
}),
|
||||
).toThrow("Adventurer name is required.");
|
||||
});
|
||||
});
|
||||
128
src/rules/character.ts
Normal file
128
src/rules/character.ts
Normal file
@@ -0,0 +1,128 @@
|
||||
import type { ContentPack } from "@/types/content";
|
||||
import type { AdventurerState, InventoryEntry } from "@/types/state";
|
||||
|
||||
export type CharacterCreationChoiceSet = {
|
||||
name: string;
|
||||
weaponId: string;
|
||||
armourId: string;
|
||||
scrollId: string;
|
||||
};
|
||||
|
||||
const DEFAULT_STARTING_ITEM_IDS = [
|
||||
"item.flint-and-steel",
|
||||
"item.lantern",
|
||||
"item.ration",
|
||||
"item.pouch",
|
||||
"item.wax-sealing-kit",
|
||||
"item.backpack",
|
||||
];
|
||||
|
||||
function requireDefinition<T extends { id: string }>(
|
||||
entries: T[],
|
||||
id: string,
|
||||
label: string,
|
||||
) {
|
||||
const entry = entries.find((candidate) => candidate.id === id);
|
||||
|
||||
if (!entry) {
|
||||
throw new Error(`Unknown ${label} id: ${id}`);
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
function makeInventoryEntry(definitionId: string, quantity = 1): InventoryEntry {
|
||||
return {
|
||||
definitionId,
|
||||
quantity,
|
||||
};
|
||||
}
|
||||
|
||||
export function getCharacterCreationOptions(content: ContentPack) {
|
||||
return {
|
||||
weapons: content.weapons.filter((weapon) => weapon.startingOption),
|
||||
armour: content.armour.filter((armour) => armour.startingOption),
|
||||
scrolls: content.scrolls.filter((scroll) => scroll.startingOption),
|
||||
};
|
||||
}
|
||||
|
||||
export function createStartingAdventurer(
|
||||
content: ContentPack,
|
||||
choices: CharacterCreationChoiceSet,
|
||||
): AdventurerState {
|
||||
const trimmedName = choices.name.trim();
|
||||
|
||||
if (trimmedName.length === 0) {
|
||||
throw new Error("Adventurer name is required.");
|
||||
}
|
||||
|
||||
const selectedWeapon = requireDefinition(content.weapons, choices.weaponId, "weapon");
|
||||
const selectedArmour = requireDefinition(content.armour, choices.armourId, "armour");
|
||||
const selectedScroll = requireDefinition(content.scrolls, choices.scrollId, "scroll");
|
||||
|
||||
if (!selectedWeapon.startingOption) {
|
||||
throw new Error(`Weapon ${selectedWeapon.id} is not a legal starting option.`);
|
||||
}
|
||||
|
||||
if (!selectedArmour.startingOption) {
|
||||
throw new Error(`Armour ${selectedArmour.id} is not a legal starting option.`);
|
||||
}
|
||||
|
||||
if (!selectedScroll.startingOption) {
|
||||
throw new Error(`Scroll ${selectedScroll.id} is not a legal starting option.`);
|
||||
}
|
||||
|
||||
const allowedManoeuvreIds = selectedWeapon.allowedManoeuvreIds;
|
||||
|
||||
if (allowedManoeuvreIds.length === 0) {
|
||||
throw new Error(`Weapon ${selectedWeapon.id} does not define starting manoeuvres.`);
|
||||
}
|
||||
|
||||
DEFAULT_STARTING_ITEM_IDS.forEach((itemId) => requireDefinition(content.items, itemId, "item"));
|
||||
requireDefinition(content.potions, "potion.healing", "potion");
|
||||
|
||||
return {
|
||||
id: "adventurer.new",
|
||||
name: trimmedName,
|
||||
level: 1,
|
||||
xp: 0,
|
||||
hp: {
|
||||
current: 10,
|
||||
max: 10,
|
||||
base: 10,
|
||||
},
|
||||
stats: {
|
||||
shift: 2,
|
||||
discipline: 1,
|
||||
precision: 0,
|
||||
},
|
||||
weaponId: selectedWeapon.id,
|
||||
manoeuvreIds: allowedManoeuvreIds,
|
||||
armourId: selectedArmour.id,
|
||||
favour: {},
|
||||
statuses: [],
|
||||
inventory: {
|
||||
carried: [
|
||||
makeInventoryEntry("item.flint-and-steel"),
|
||||
makeInventoryEntry("item.lantern"),
|
||||
makeInventoryEntry("item.ration", 3),
|
||||
makeInventoryEntry("item.pouch"),
|
||||
makeInventoryEntry("item.wax-sealing-kit"),
|
||||
makeInventoryEntry("item.backpack"),
|
||||
makeInventoryEntry(selectedScroll.id),
|
||||
makeInventoryEntry("potion.healing"),
|
||||
],
|
||||
equipped: [
|
||||
makeInventoryEntry(selectedWeapon.id),
|
||||
makeInventoryEntry(selectedArmour.id),
|
||||
],
|
||||
stored: [],
|
||||
currency: {
|
||||
gold: 0,
|
||||
},
|
||||
rationCount: 3,
|
||||
lightSources: [makeInventoryEntry("item.lantern")],
|
||||
},
|
||||
progressionFlags: [],
|
||||
};
|
||||
}
|
||||
111
src/rules/combat.test.ts
Normal file
111
src/rules/combat.test.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
||||
|
||||
import { createStartingAdventurer } from "./character";
|
||||
import { startCombatFromRoom } from "./combat";
|
||||
import { createRoomStateFromTemplate } from "./rooms";
|
||||
|
||||
describe("combat bootstrap", () => {
|
||||
it("creates a combat state from a resolved guard encounter", () => {
|
||||
const adventurer = createStartingAdventurer(sampleContentPack, {
|
||||
name: "Aster",
|
||||
weaponId: "weapon.short-sword",
|
||||
armourId: "armour.leather-vest",
|
||||
scrollId: "scroll.lesser-heal",
|
||||
});
|
||||
const room = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.guard-room",
|
||||
1,
|
||||
"room.level1.normal.guard-room",
|
||||
);
|
||||
room.encounter = {
|
||||
id: `${room.id}.encounter`,
|
||||
sourceTableCode: "L1G",
|
||||
creatureIds: ["a", "b"],
|
||||
creatureNames: ["Guard", "Warrior"],
|
||||
resultLabel: "Guard and Warrior",
|
||||
resolved: true,
|
||||
};
|
||||
|
||||
const result = startCombatFromRoom({
|
||||
content: sampleContentPack,
|
||||
adventurer,
|
||||
room,
|
||||
at: "2026-03-15T13:00:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.combat.id).toBe("room.level1.guard-room.combat");
|
||||
expect(result.combat.actingSide).toBe("player");
|
||||
expect(result.combat.player.name).toBe("Aster");
|
||||
expect(result.combat.enemies.map((enemy) => enemy.name)).toEqual(["Guard", "Warrior"]);
|
||||
expect(result.combat.enemies[0]?.armourValue).toBe(1);
|
||||
expect(result.room.encounter?.rewardPending).toBe(true);
|
||||
expect(result.logEntries[0]?.text).toContain("Guard and Warrior");
|
||||
});
|
||||
|
||||
it("supports single-creature combat from a crate encounter", () => {
|
||||
const adventurer = createStartingAdventurer(sampleContentPack, {
|
||||
name: "Bryn",
|
||||
weaponId: "weapon.short-sword",
|
||||
armourId: "armour.leather-vest",
|
||||
scrollId: "scroll.lesser-heal",
|
||||
});
|
||||
const room = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.storage-area",
|
||||
1,
|
||||
"room.level1.normal.storage-area",
|
||||
);
|
||||
room.encounter = {
|
||||
id: `${room.id}.encounter`,
|
||||
sourceTableCode: "L1CE",
|
||||
creatureIds: ["a"],
|
||||
creatureNames: ["Giant Rat"],
|
||||
resultLabel: "Giant Rat Pair",
|
||||
resolved: true,
|
||||
};
|
||||
|
||||
const result = startCombatFromRoom({
|
||||
content: sampleContentPack,
|
||||
adventurer,
|
||||
room,
|
||||
at: "2026-03-15T13:05:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.combat.enemies).toHaveLength(1);
|
||||
expect(result.combat.enemies[0]?.sourceDefinitionId).toBe("creature.level1.giant-rat");
|
||||
expect(result.combat.player.hpCurrent).toBe(10);
|
||||
});
|
||||
|
||||
it("rejects rooms without combat-ready encounter names", () => {
|
||||
const adventurer = createStartingAdventurer(sampleContentPack, {
|
||||
name: "Cyra",
|
||||
weaponId: "weapon.short-sword",
|
||||
armourId: "armour.leather-vest",
|
||||
scrollId: "scroll.lesser-heal",
|
||||
});
|
||||
const room = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.small.empty",
|
||||
1,
|
||||
"room.level1.small.empty-space",
|
||||
);
|
||||
room.encounter = {
|
||||
id: `${room.id}.encounter`,
|
||||
creatureIds: [],
|
||||
creatureNames: [],
|
||||
resultLabel: "No encounter",
|
||||
resolved: true,
|
||||
};
|
||||
|
||||
expect(() =>
|
||||
startCombatFromRoom({
|
||||
content: sampleContentPack,
|
||||
adventurer,
|
||||
room,
|
||||
}),
|
||||
).toThrow("combat-ready encounter");
|
||||
});
|
||||
});
|
||||
124
src/rules/combat.ts
Normal file
124
src/rules/combat.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
import { findCreatureByName } from "@/data/contentHelpers";
|
||||
import type { ContentPack, CreatureDefinition } from "@/types/content";
|
||||
import type { AdventurerState, CombatState, CombatantState, RoomState } from "@/types/state";
|
||||
import type { LogEntry } from "@/types/rules";
|
||||
|
||||
export type StartCombatOptions = {
|
||||
content: ContentPack;
|
||||
adventurer: AdventurerState;
|
||||
room: RoomState;
|
||||
at?: string;
|
||||
};
|
||||
|
||||
export type StartCombatResult = {
|
||||
combat: CombatState;
|
||||
room: RoomState;
|
||||
logEntries: LogEntry[];
|
||||
};
|
||||
|
||||
function createLogEntry(
|
||||
id: string,
|
||||
at: string,
|
||||
type: LogEntry["type"],
|
||||
text: string,
|
||||
relatedIds: string[],
|
||||
): LogEntry {
|
||||
return {
|
||||
id,
|
||||
at,
|
||||
type,
|
||||
text,
|
||||
relatedIds,
|
||||
};
|
||||
}
|
||||
|
||||
function createPlayerCombatant(adventurer: AdventurerState): CombatantState {
|
||||
return {
|
||||
id: adventurer.id,
|
||||
name: adventurer.name,
|
||||
hpCurrent: adventurer.hp.current,
|
||||
hpMax: adventurer.hp.max,
|
||||
shift: adventurer.stats.shift,
|
||||
discipline: adventurer.stats.discipline,
|
||||
precision: adventurer.stats.precision,
|
||||
statuses: [...adventurer.statuses],
|
||||
traits: ["player"],
|
||||
};
|
||||
}
|
||||
|
||||
function createEnemyCombatant(
|
||||
room: RoomState,
|
||||
creature: CreatureDefinition,
|
||||
index: number,
|
||||
): CombatantState {
|
||||
return {
|
||||
id: `${room.id}.enemy.${index + 1}`,
|
||||
name: creature.name,
|
||||
sourceDefinitionId: creature.id,
|
||||
hpCurrent: creature.hp,
|
||||
hpMax: creature.hp,
|
||||
shift: 0,
|
||||
discipline: creature.attackProfile.discipline,
|
||||
precision: creature.attackProfile.precision,
|
||||
armourValue: creature.defenceProfile?.armour,
|
||||
statuses: [],
|
||||
traits: creature.traits ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
function requireEncounterNames(room: RoomState) {
|
||||
const creatureNames = room.encounter?.creatureNames?.filter(Boolean);
|
||||
|
||||
if (!room.encounter?.resolved || !creatureNames || creatureNames.length === 0) {
|
||||
throw new Error(`Room ${room.id} does not have a combat-ready encounter.`);
|
||||
}
|
||||
|
||||
return creatureNames;
|
||||
}
|
||||
|
||||
export function startCombatFromRoom(
|
||||
options: StartCombatOptions,
|
||||
): StartCombatResult {
|
||||
const at = options.at ?? new Date().toISOString();
|
||||
const creatureNames = requireEncounterNames(options.room);
|
||||
const enemies = creatureNames.map((creatureName, index) =>
|
||||
createEnemyCombatant(
|
||||
options.room,
|
||||
findCreatureByName(options.content, creatureName),
|
||||
index,
|
||||
),
|
||||
);
|
||||
|
||||
const combat: CombatState = {
|
||||
id: `${options.room.id}.combat`,
|
||||
round: 1,
|
||||
actingSide: "player",
|
||||
player: createPlayerCombatant(options.adventurer),
|
||||
enemies,
|
||||
combatLog: [
|
||||
createLogEntry(
|
||||
`${options.room.id}.combat.start`,
|
||||
at,
|
||||
"combat",
|
||||
`Combat begins in ${options.room.id} against ${creatureNames.join(" and ")}.`,
|
||||
[options.room.id, ...enemies.map((enemy) => enemy.id)],
|
||||
),
|
||||
],
|
||||
};
|
||||
|
||||
const room: RoomState = {
|
||||
...options.room,
|
||||
encounter: options.room.encounter
|
||||
? {
|
||||
...options.room.encounter,
|
||||
rewardPending: true,
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
|
||||
return {
|
||||
combat,
|
||||
room,
|
||||
logEntries: [...combat.combatLog],
|
||||
};
|
||||
}
|
||||
132
src/rules/combatTurns.test.ts
Normal file
132
src/rules/combatTurns.test.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
||||
|
||||
import { createStartingAdventurer } from "./character";
|
||||
import { startCombatFromRoom } from "./combat";
|
||||
import { resolveEnemyTurn, resolvePlayerAttack } from "./combatTurns";
|
||||
import { createRoomStateFromTemplate } from "./rooms";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
function createGuardCombat() {
|
||||
const adventurer = createStartingAdventurer(sampleContentPack, {
|
||||
name: "Aster",
|
||||
weaponId: "weapon.short-sword",
|
||||
armourId: "armour.leather-vest",
|
||||
scrollId: "scroll.lesser-heal",
|
||||
});
|
||||
const room = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.guard-room",
|
||||
1,
|
||||
"room.level1.normal.guard-room",
|
||||
);
|
||||
room.encounter = {
|
||||
id: `${room.id}.encounter`,
|
||||
sourceTableCode: "L1G",
|
||||
creatureIds: ["a", "b"],
|
||||
creatureNames: ["Guard", "Warrior"],
|
||||
resultLabel: "Guard and Warrior",
|
||||
resolved: true,
|
||||
};
|
||||
|
||||
return {
|
||||
adventurer,
|
||||
...startCombatFromRoom({
|
||||
content: sampleContentPack,
|
||||
adventurer,
|
||||
room,
|
||||
at: "2026-03-15T13:00:00.000Z",
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
describe("combat turns", () => {
|
||||
it("lets the player hit an enemy and pass initiative", () => {
|
||||
const { adventurer, combat } = createGuardCombat();
|
||||
const targetId = combat.enemies[0]!.id;
|
||||
|
||||
const result = resolvePlayerAttack({
|
||||
content: sampleContentPack,
|
||||
combat,
|
||||
adventurer,
|
||||
manoeuvreId: "manoeuvre.exact-strike",
|
||||
targetEnemyId: targetId,
|
||||
roller: createSequenceRoller([6, 6]),
|
||||
at: "2026-03-15T13:01:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.combat.actingSide).toBe("enemy");
|
||||
expect(result.combat.selectedManoeuvreId).toBe("manoeuvre.exact-strike");
|
||||
expect(result.combat.enemies[0]?.hpCurrent).toBeLessThan(result.combat.enemies[0]!.hpMax);
|
||||
expect(result.logEntries[0]?.text).toContain("deals");
|
||||
});
|
||||
|
||||
it("marks an enemy defeated when the player deals lethal damage", () => {
|
||||
const { adventurer, combat } = createGuardCombat();
|
||||
combat.enemies[0]!.hpCurrent = 1;
|
||||
|
||||
const result = resolvePlayerAttack({
|
||||
content: sampleContentPack,
|
||||
combat,
|
||||
adventurer,
|
||||
manoeuvreId: "manoeuvre.guard-break",
|
||||
targetEnemyId: combat.enemies[0]!.id,
|
||||
roller: createSequenceRoller([6, 5]),
|
||||
at: "2026-03-15T13:02:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.defeatedEnemyIds).toEqual([combat.enemies[0]!.id]);
|
||||
expect(result.logEntries.map((entry) => entry.text)).toContain("Guard is defeated.");
|
||||
});
|
||||
|
||||
it("lets an enemy attack the player and advances the round", () => {
|
||||
const { adventurer, combat } = createGuardCombat();
|
||||
const afterPlayer = resolvePlayerAttack({
|
||||
content: sampleContentPack,
|
||||
combat,
|
||||
adventurer,
|
||||
manoeuvreId: "manoeuvre.exact-strike",
|
||||
targetEnemyId: combat.enemies[0]!.id,
|
||||
roller: createSequenceRoller([4, 4]),
|
||||
at: "2026-03-15T13:03:00.000Z",
|
||||
});
|
||||
|
||||
const result = resolveEnemyTurn({
|
||||
content: sampleContentPack,
|
||||
combat: afterPlayer.combat,
|
||||
adventurer,
|
||||
roller: createSequenceRoller([6, 6]),
|
||||
at: "2026-03-15T13:04:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.combat.round).toBe(2);
|
||||
expect(result.combat.actingSide).toBe("player");
|
||||
expect(result.combat.player.hpCurrent).toBeLessThan(result.combat.player.hpMax);
|
||||
expect(result.logEntries[0]?.text).toContain("attacks");
|
||||
});
|
||||
|
||||
it("rejects player turns that target a defeated enemy", () => {
|
||||
const { adventurer, combat } = createGuardCombat();
|
||||
combat.enemies[0]!.hpCurrent = 0;
|
||||
|
||||
expect(() =>
|
||||
resolvePlayerAttack({
|
||||
content: sampleContentPack,
|
||||
combat,
|
||||
adventurer,
|
||||
manoeuvreId: "manoeuvre.exact-strike",
|
||||
targetEnemyId: combat.enemies[0]!.id,
|
||||
}),
|
||||
).toThrow("Unknown or defeated target");
|
||||
});
|
||||
});
|
||||
255
src/rules/combatTurns.ts
Normal file
255
src/rules/combatTurns.ts
Normal file
@@ -0,0 +1,255 @@
|
||||
import type {
|
||||
ArmourDefinition,
|
||||
ContentPack,
|
||||
ManoeuvreDefinition,
|
||||
WeaponDefinition,
|
||||
} from "@/types/content";
|
||||
import type { AdventurerState, CombatState, CombatantState } from "@/types/state";
|
||||
import type { LogEntry } from "@/types/rules";
|
||||
|
||||
import { roll2D6, type DiceRoller } from "./dice";
|
||||
|
||||
export type ResolvePlayerAttackOptions = {
|
||||
content: ContentPack;
|
||||
combat: CombatState;
|
||||
adventurer: AdventurerState;
|
||||
manoeuvreId: string;
|
||||
targetEnemyId: string;
|
||||
roller?: DiceRoller;
|
||||
at?: string;
|
||||
};
|
||||
|
||||
export type ResolveEnemyTurnOptions = {
|
||||
content: ContentPack;
|
||||
combat: CombatState;
|
||||
adventurer: AdventurerState;
|
||||
roller?: DiceRoller;
|
||||
at?: string;
|
||||
};
|
||||
|
||||
export type CombatTurnResult = {
|
||||
combat: CombatState;
|
||||
logEntries: LogEntry[];
|
||||
defeatedEnemyIds: string[];
|
||||
combatEnded: boolean;
|
||||
};
|
||||
|
||||
const BASE_TARGET_NUMBER = 7;
|
||||
|
||||
function requireWeapon(content: ContentPack, weaponId: string): WeaponDefinition {
|
||||
const weapon = content.weapons.find((entry) => entry.id === weaponId);
|
||||
|
||||
if (!weapon) {
|
||||
throw new Error(`Unknown weapon id: ${weaponId}`);
|
||||
}
|
||||
|
||||
return weapon;
|
||||
}
|
||||
|
||||
function requireManoeuvre(content: ContentPack, manoeuvreId: string): ManoeuvreDefinition {
|
||||
const manoeuvre = content.manoeuvres.find((entry) => entry.id === manoeuvreId);
|
||||
|
||||
if (!manoeuvre) {
|
||||
throw new Error(`Unknown manoeuvre id: ${manoeuvreId}`);
|
||||
}
|
||||
|
||||
return manoeuvre;
|
||||
}
|
||||
|
||||
function findArmour(content: ContentPack, armourId?: string): ArmourDefinition | undefined {
|
||||
if (!armourId) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return content.armour.find((entry) => entry.id === armourId);
|
||||
}
|
||||
|
||||
function cloneCombatant(combatant: CombatantState): CombatantState {
|
||||
return {
|
||||
...combatant,
|
||||
statuses: [...combatant.statuses],
|
||||
traits: [...combatant.traits],
|
||||
};
|
||||
}
|
||||
|
||||
function cloneCombat(combat: CombatState): CombatState {
|
||||
return {
|
||||
...combat,
|
||||
player: cloneCombatant(combat.player),
|
||||
enemies: combat.enemies.map(cloneCombatant),
|
||||
combatLog: combat.combatLog.map((entry) => ({
|
||||
...entry,
|
||||
relatedIds: entry.relatedIds ? [...entry.relatedIds] : undefined,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
function createLogEntry(
|
||||
id: string,
|
||||
at: string,
|
||||
text: string,
|
||||
relatedIds: string[],
|
||||
): LogEntry {
|
||||
return {
|
||||
id,
|
||||
at,
|
||||
type: "combat",
|
||||
text,
|
||||
relatedIds,
|
||||
};
|
||||
}
|
||||
|
||||
function getPlayerArmourValue(content: ContentPack, adventurer: AdventurerState) {
|
||||
return findArmour(content, adventurer.armourId)?.armourValue ?? 0;
|
||||
}
|
||||
|
||||
function isAlive(combatant: CombatantState) {
|
||||
return combatant.hpCurrent > 0;
|
||||
}
|
||||
|
||||
function getLivingEnemies(combat: CombatState) {
|
||||
return combat.enemies.filter(isAlive);
|
||||
}
|
||||
|
||||
export function resolvePlayerAttack(
|
||||
options: ResolvePlayerAttackOptions,
|
||||
): CombatTurnResult {
|
||||
if (options.combat.actingSide !== "player") {
|
||||
throw new Error("It is not currently the player's turn.");
|
||||
}
|
||||
|
||||
const combat = cloneCombat(options.combat);
|
||||
const at = options.at ?? new Date().toISOString();
|
||||
const weapon = requireWeapon(options.content, options.adventurer.weaponId);
|
||||
const manoeuvre = requireManoeuvre(options.content, options.manoeuvreId);
|
||||
|
||||
if (!options.adventurer.manoeuvreIds.includes(manoeuvre.id)) {
|
||||
throw new Error(`Adventurer cannot use manoeuvre ${manoeuvre.id}.`);
|
||||
}
|
||||
|
||||
if (!manoeuvre.weaponCategories.includes(weapon.category)) {
|
||||
throw new Error(`Manoeuvre ${manoeuvre.id} is not compatible with ${weapon.id}.`);
|
||||
}
|
||||
|
||||
const target = combat.enemies.find((enemy) => enemy.id === options.targetEnemyId);
|
||||
|
||||
if (!target || !isAlive(target)) {
|
||||
throw new Error(`Unknown or defeated target enemy: ${options.targetEnemyId}`);
|
||||
}
|
||||
|
||||
const roll = roll2D6(options.roller);
|
||||
const accuracy =
|
||||
(roll.total ?? 0) +
|
||||
combat.player.precision +
|
||||
(manoeuvre.precisionModifier ?? 0);
|
||||
const targetNumber = BASE_TARGET_NUMBER + (target.armourValue ?? 0);
|
||||
const hit = accuracy >= targetNumber;
|
||||
const rawDamage = hit
|
||||
? weapon.baseDamage +
|
||||
Math.max(0, combat.player.discipline + (manoeuvre.damageModifier ?? 0))
|
||||
: 0;
|
||||
const damage = hit ? Math.max(1, rawDamage) : 0;
|
||||
|
||||
if (hit) {
|
||||
target.hpCurrent = Math.max(0, target.hpCurrent - damage);
|
||||
}
|
||||
|
||||
combat.selectedManoeuvreId = manoeuvre.id;
|
||||
combat.lastRoll = roll;
|
||||
combat.actingSide = getLivingEnemies(combat).length === 0 ? "player" : "enemy";
|
||||
|
||||
const logEntries: LogEntry[] = [
|
||||
createLogEntry(
|
||||
`${combat.id}.player.${combat.combatLog.length + 1}`,
|
||||
at,
|
||||
hit
|
||||
? `${combat.player.name} uses ${manoeuvre.name} on ${target.name}, rolls ${roll.total}, and deals ${damage} damage.`
|
||||
: `${combat.player.name} uses ${manoeuvre.name} on ${target.name}, rolls ${roll.total}, and misses.`,
|
||||
[combat.player.id, target.id],
|
||||
),
|
||||
];
|
||||
|
||||
const defeatedEnemyIds = !isAlive(target) ? [target.id] : [];
|
||||
|
||||
if (defeatedEnemyIds.length > 0) {
|
||||
logEntries.push(
|
||||
createLogEntry(
|
||||
`${combat.id}.player.${combat.combatLog.length + 2}`,
|
||||
at,
|
||||
`${target.name} is defeated.`,
|
||||
[target.id],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
combat.combatLog.push(...logEntries);
|
||||
|
||||
return {
|
||||
combat,
|
||||
logEntries,
|
||||
defeatedEnemyIds,
|
||||
combatEnded: getLivingEnemies(combat).length === 0,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveEnemyTurn(
|
||||
options: ResolveEnemyTurnOptions,
|
||||
): CombatTurnResult {
|
||||
if (options.combat.actingSide !== "enemy") {
|
||||
throw new Error("It is not currently the enemy's turn.");
|
||||
}
|
||||
|
||||
const combat = cloneCombat(options.combat);
|
||||
const at = options.at ?? new Date().toISOString();
|
||||
const attacker = getLivingEnemies(combat)[0];
|
||||
|
||||
if (!attacker) {
|
||||
throw new Error("No living enemies are available to act.");
|
||||
}
|
||||
|
||||
const roll = roll2D6(options.roller);
|
||||
const armourValue = getPlayerArmourValue(options.content, options.adventurer);
|
||||
const accuracy = (roll.total ?? 0) + attacker.precision;
|
||||
const targetNumber = BASE_TARGET_NUMBER + armourValue;
|
||||
const hit = accuracy >= targetNumber;
|
||||
const rawDamage = hit ? Math.max(1, 1 + attacker.discipline) : 0;
|
||||
|
||||
if (hit) {
|
||||
combat.player.hpCurrent = Math.max(0, combat.player.hpCurrent - rawDamage);
|
||||
}
|
||||
|
||||
combat.lastRoll = roll;
|
||||
combat.actingSide = combat.player.hpCurrent > 0 ? "player" : "enemy";
|
||||
combat.round += 1;
|
||||
|
||||
const logEntries: LogEntry[] = [
|
||||
createLogEntry(
|
||||
`${combat.id}.enemy.${combat.combatLog.length + 1}`,
|
||||
at,
|
||||
hit
|
||||
? `${attacker.name} attacks ${combat.player.name}, rolls ${roll.total}, and deals ${rawDamage} damage.`
|
||||
: `${attacker.name} attacks ${combat.player.name}, rolls ${roll.total}, and misses.`,
|
||||
[attacker.id, combat.player.id],
|
||||
),
|
||||
];
|
||||
|
||||
if (combat.player.hpCurrent === 0) {
|
||||
logEntries.push(
|
||||
createLogEntry(
|
||||
`${combat.id}.enemy.${combat.combatLog.length + 2}`,
|
||||
at,
|
||||
`${combat.player.name} is defeated.`,
|
||||
[combat.player.id],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
combat.combatLog.push(...logEntries);
|
||||
|
||||
return {
|
||||
combat,
|
||||
logEntries,
|
||||
defeatedEnemyIds: [],
|
||||
combatEnded: combat.player.hpCurrent === 0,
|
||||
};
|
||||
}
|
||||
46
src/rules/dice.test.ts
Normal file
46
src/rules/dice.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { applyRollModifier, roll2D6, rollD3, rollD66, rollDice } from "./dice";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
describe("dice rules", () => {
|
||||
it("maps d3 rolls from a d6 source", () => {
|
||||
const result = rollD3(createSequenceRoller([5]));
|
||||
|
||||
expect(result.rolls).toEqual([5]);
|
||||
expect(result.total).toBe(3);
|
||||
expect(result.modifiedTotal).toBe(3);
|
||||
});
|
||||
|
||||
it("preserves primary and secondary dice for d66", () => {
|
||||
const result = rollD66(createSequenceRoller([4, 2]));
|
||||
|
||||
expect(result.primary).toBe(4);
|
||||
expect(result.secondary).toBe(2);
|
||||
expect(result.total).toBe(42);
|
||||
});
|
||||
|
||||
it("applies modifiers with clamping when limits are provided", () => {
|
||||
const roll = roll2D6(createSequenceRoller([6, 6]));
|
||||
const modified = applyRollModifier(roll, 3, { min: 2, max: 12 });
|
||||
|
||||
expect(modified.modifiedTotal).toBe(12);
|
||||
expect(modified.clamped).toBe(true);
|
||||
});
|
||||
|
||||
it("routes dice kinds through the shared roller", () => {
|
||||
const result = rollDice("d6", createSequenceRoller([2]));
|
||||
|
||||
expect(result.total).toBe(2);
|
||||
expect(result.diceKind).toBe("d6");
|
||||
});
|
||||
});
|
||||
113
src/rules/dice.ts
Normal file
113
src/rules/dice.ts
Normal file
@@ -0,0 +1,113 @@
|
||||
import type { DiceKind, RollResult } from "@/types/rules";
|
||||
|
||||
export type DiceRoller = (sides: number) => number;
|
||||
|
||||
const defaultDiceRoller: DiceRoller = (sides) =>
|
||||
Math.floor(Math.random() * sides) + 1;
|
||||
|
||||
function assertRollInRange(value: number, sides: number) {
|
||||
if (!Number.isInteger(value) || value < 1 || value > sides) {
|
||||
throw new Error(`Dice roller returned invalid value ${value} for d${sides}.`);
|
||||
}
|
||||
}
|
||||
|
||||
function clampTotal(total: number, min: number, max: number) {
|
||||
return Math.max(min, Math.min(max, total));
|
||||
}
|
||||
|
||||
export function rollD3(roller: DiceRoller = defaultDiceRoller): RollResult {
|
||||
const value = roller(6);
|
||||
assertRollInRange(value, 6);
|
||||
const total = Math.ceil(value / 2);
|
||||
|
||||
return {
|
||||
diceKind: "d3",
|
||||
rolls: [value],
|
||||
total,
|
||||
modifiedTotal: total,
|
||||
};
|
||||
}
|
||||
|
||||
export function rollD6(roller: DiceRoller = defaultDiceRoller): RollResult {
|
||||
const value = roller(6);
|
||||
assertRollInRange(value, 6);
|
||||
|
||||
return {
|
||||
diceKind: "d6",
|
||||
rolls: [value],
|
||||
total: value,
|
||||
modifiedTotal: value,
|
||||
};
|
||||
}
|
||||
|
||||
export function roll2D6(roller: DiceRoller = defaultDiceRoller): RollResult {
|
||||
const first = roller(6);
|
||||
const second = roller(6);
|
||||
assertRollInRange(first, 6);
|
||||
assertRollInRange(second, 6);
|
||||
const total = first + second;
|
||||
|
||||
return {
|
||||
diceKind: "2d6",
|
||||
rolls: [first, second],
|
||||
primary: first,
|
||||
secondary: second,
|
||||
total,
|
||||
modifiedTotal: total,
|
||||
};
|
||||
}
|
||||
|
||||
export function rollD66(roller: DiceRoller = defaultDiceRoller): RollResult {
|
||||
const primary = roller(6);
|
||||
const secondary = roller(6);
|
||||
assertRollInRange(primary, 6);
|
||||
assertRollInRange(secondary, 6);
|
||||
const total = primary * 10 + secondary;
|
||||
|
||||
return {
|
||||
diceKind: "d66",
|
||||
rolls: [primary, secondary],
|
||||
primary,
|
||||
secondary,
|
||||
total,
|
||||
modifiedTotal: total,
|
||||
};
|
||||
}
|
||||
|
||||
export function applyRollModifier(
|
||||
roll: RollResult,
|
||||
modifier = 0,
|
||||
limits?: { min: number; max: number },
|
||||
): RollResult {
|
||||
if (roll.total === undefined) {
|
||||
throw new Error("Cannot apply a modifier to a roll without a total.");
|
||||
}
|
||||
|
||||
const nextTotal = roll.total + modifier;
|
||||
const boundedTotal = limits
|
||||
? clampTotal(nextTotal, limits.min, limits.max)
|
||||
: nextTotal;
|
||||
|
||||
return {
|
||||
...roll,
|
||||
modifier,
|
||||
modifiedTotal: boundedTotal,
|
||||
clamped: limits ? boundedTotal !== nextTotal : false,
|
||||
};
|
||||
}
|
||||
|
||||
export function rollDice(
|
||||
diceKind: DiceKind,
|
||||
roller: DiceRoller = defaultDiceRoller,
|
||||
): RollResult {
|
||||
switch (diceKind) {
|
||||
case "d3":
|
||||
return rollD3(roller);
|
||||
case "d6":
|
||||
return rollD6(roller);
|
||||
case "2d6":
|
||||
return roll2D6(roller);
|
||||
case "d66":
|
||||
return rollD66(roller);
|
||||
}
|
||||
}
|
||||
87
src/rules/dungeon.test.ts
Normal file
87
src/rules/dungeon.test.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
||||
|
||||
import {
|
||||
expandLevelFromExit,
|
||||
getUnresolvedExits,
|
||||
initializeDungeonLevel,
|
||||
} from "./dungeon";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
describe("dungeon state", () => {
|
||||
it("initializes level 1 with a generated start room", () => {
|
||||
const levelState = initializeDungeonLevel({ content: sampleContentPack });
|
||||
|
||||
expect(levelState.level).toBe(1);
|
||||
expect(levelState.discoveredRoomOrder).toEqual(["room.level1.start"]);
|
||||
expect(levelState.rooms["room.level1.start"]?.roomClass).toBe("start");
|
||||
});
|
||||
|
||||
it("lists unresolved traversable exits in discovery order", () => {
|
||||
const levelState = initializeDungeonLevel({ content: sampleContentPack });
|
||||
|
||||
expect(getUnresolvedExits(levelState)).toEqual([
|
||||
expect.objectContaining({
|
||||
roomId: "room.level1.start",
|
||||
direction: "north",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("expands the dungeon from a chosen exit and links both rooms", () => {
|
||||
const levelState = initializeDungeonLevel({ content: sampleContentPack });
|
||||
const result = expandLevelFromExit({
|
||||
content: sampleContentPack,
|
||||
levelState,
|
||||
fromRoomId: "room.level1.start",
|
||||
exitDirection: "north",
|
||||
roomTableCode: "L1SR",
|
||||
roller: createSequenceRoller([3, 3]),
|
||||
});
|
||||
|
||||
expect(result.createdRoom.position).toEqual({ x: 0, y: -1 });
|
||||
expect(result.levelState.discoveredRoomOrder).toEqual([
|
||||
"room.level1.start",
|
||||
"room.level1.small.002",
|
||||
]);
|
||||
expect(result.fromRoom.exits[0]?.leadsToRoomId).toBe("room.level1.small.002");
|
||||
expect(result.createdRoom.exits.some((exit) => exit.leadsToRoomId === "room.level1.start")).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects placement into an occupied coordinate", () => {
|
||||
const levelState = initializeDungeonLevel({ content: sampleContentPack });
|
||||
const expanded = expandLevelFromExit({
|
||||
content: sampleContentPack,
|
||||
levelState,
|
||||
fromRoomId: "room.level1.start",
|
||||
exitDirection: "north",
|
||||
roomTableCode: "L1SR",
|
||||
roomId: "room.level1.small.a",
|
||||
roller: createSequenceRoller([3, 3]),
|
||||
});
|
||||
|
||||
expect(() =>
|
||||
expandLevelFromExit({
|
||||
content: sampleContentPack,
|
||||
levelState: expanded.levelState,
|
||||
fromRoomId: "room.level1.start",
|
||||
exitDirection: "north",
|
||||
roomTableCode: "L1SR",
|
||||
roomId: "room.level1.small.b",
|
||||
roller: createSequenceRoller([4, 4]),
|
||||
}),
|
||||
).toThrow("already connected");
|
||||
});
|
||||
});
|
||||
219
src/rules/dungeon.ts
Normal file
219
src/rules/dungeon.ts
Normal file
@@ -0,0 +1,219 @@
|
||||
import type { ContentPack } from "@/types/content";
|
||||
import type { DungeonLevelState, RoomExitState, RoomState } from "@/types/state";
|
||||
|
||||
import { createLevelShell, generateLevel1StartRoom, generateRoomFromTable } from "./rooms";
|
||||
import type { DiceRoller } from "./dice";
|
||||
|
||||
type CardinalDirection = "north" | "east" | "south" | "west";
|
||||
|
||||
export type InitializeLevelOptions = {
|
||||
content: ContentPack;
|
||||
level?: number;
|
||||
startRoomId?: string;
|
||||
};
|
||||
|
||||
export type ExpandFromExitOptions = {
|
||||
content: ContentPack;
|
||||
levelState: DungeonLevelState;
|
||||
fromRoomId: string;
|
||||
exitDirection: CardinalDirection;
|
||||
roomTableCode: string;
|
||||
roomId?: string;
|
||||
roller?: DiceRoller;
|
||||
};
|
||||
|
||||
export type ExpansionResult = {
|
||||
levelState: DungeonLevelState;
|
||||
createdRoom: RoomState;
|
||||
fromRoom: RoomState;
|
||||
};
|
||||
|
||||
const DIRECTION_VECTORS: Record<CardinalDirection, { x: number; y: number }> = {
|
||||
north: { x: 0, y: -1 },
|
||||
east: { x: 1, y: 0 },
|
||||
south: { x: 0, y: 1 },
|
||||
west: { x: -1, y: 0 },
|
||||
};
|
||||
|
||||
const OPPOSITE_DIRECTION: Record<CardinalDirection, CardinalDirection> = {
|
||||
north: "south",
|
||||
east: "west",
|
||||
south: "north",
|
||||
west: "east",
|
||||
};
|
||||
|
||||
function cloneRoom(room: RoomState): RoomState {
|
||||
return {
|
||||
...room,
|
||||
position: { ...room.position },
|
||||
dimensions: { ...room.dimensions },
|
||||
exits: room.exits.map((exit) => ({ ...exit })),
|
||||
discovery: { ...room.discovery },
|
||||
encounter: room.encounter
|
||||
? {
|
||||
...room.encounter,
|
||||
creatureIds: [...room.encounter.creatureIds],
|
||||
creatureNames: room.encounter.creatureNames
|
||||
? [...room.encounter.creatureNames]
|
||||
: undefined,
|
||||
}
|
||||
: undefined,
|
||||
objects: room.objects.map((object) => ({
|
||||
...object,
|
||||
effects: object.effects ? [...object.effects] : undefined,
|
||||
})),
|
||||
notes: [...room.notes],
|
||||
flags: [...room.flags],
|
||||
};
|
||||
}
|
||||
|
||||
function cloneLevel(levelState: DungeonLevelState): DungeonLevelState {
|
||||
return {
|
||||
...levelState,
|
||||
rooms: Object.fromEntries(
|
||||
Object.entries(levelState.rooms).map(([roomId, room]) => [roomId, cloneRoom(room)]),
|
||||
),
|
||||
discoveredRoomOrder: [...levelState.discoveredRoomOrder],
|
||||
};
|
||||
}
|
||||
|
||||
function findExit(room: RoomState, direction: CardinalDirection): RoomExitState {
|
||||
const exit = room.exits.find((candidate) => candidate.direction === direction);
|
||||
|
||||
if (!exit) {
|
||||
throw new Error(`Room ${room.id} does not have an exit facing ${direction}.`);
|
||||
}
|
||||
|
||||
return exit;
|
||||
}
|
||||
|
||||
function computeNextPosition(room: RoomState, direction: CardinalDirection) {
|
||||
const offset = DIRECTION_VECTORS[direction];
|
||||
|
||||
return {
|
||||
x: room.position.x + offset.x,
|
||||
y: room.position.y + offset.y,
|
||||
};
|
||||
}
|
||||
|
||||
function connectRooms(
|
||||
fromRoom: RoomState,
|
||||
toRoom: RoomState,
|
||||
direction: CardinalDirection,
|
||||
) {
|
||||
const fromExit = findExit(fromRoom, direction);
|
||||
fromExit.leadsToRoomId = toRoom.id;
|
||||
fromExit.discovered = true;
|
||||
|
||||
const oppositeDirection = OPPOSITE_DIRECTION[direction];
|
||||
const returnExit =
|
||||
toRoom.exits.find((candidate) => candidate.direction === oppositeDirection) ?? toRoom.exits[0];
|
||||
|
||||
if (!returnExit) {
|
||||
throw new Error(`Generated room ${toRoom.id} does not have an available return exit.`);
|
||||
}
|
||||
|
||||
returnExit.direction = oppositeDirection;
|
||||
returnExit.leadsToRoomId = fromRoom.id;
|
||||
returnExit.discovered = true;
|
||||
}
|
||||
|
||||
function getNextRoomId(levelState: DungeonLevelState, roomClass: string) {
|
||||
const sequence = levelState.discoveredRoomOrder.length + 1;
|
||||
return `room.level${levelState.level}.${roomClass}.${String(sequence).padStart(3, "0")}`;
|
||||
}
|
||||
|
||||
function assertCoordinateAvailable(levelState: DungeonLevelState, position: { x: number; y: number }) {
|
||||
const occupiedRoom = Object.values(levelState.rooms).find(
|
||||
(room) => room.position.x === position.x && room.position.y === position.y,
|
||||
);
|
||||
|
||||
if (occupiedRoom) {
|
||||
throw new Error(
|
||||
`Cannot place a new room at (${position.x}, ${position.y}); ${occupiedRoom.id} already occupies that position.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function initializeDungeonLevel(
|
||||
options: InitializeLevelOptions,
|
||||
): DungeonLevelState {
|
||||
const level = options.level ?? 1;
|
||||
|
||||
if (level !== 1) {
|
||||
throw new Error("Only Level 1 initialization is currently implemented.");
|
||||
}
|
||||
|
||||
const levelState = createLevelShell(level);
|
||||
const startResult = generateLevel1StartRoom(
|
||||
options.content,
|
||||
options.startRoomId ?? `room.level${level}.start`,
|
||||
);
|
||||
|
||||
levelState.rooms[startResult.room.id] = startResult.room;
|
||||
levelState.discoveredRoomOrder.push(startResult.room.id);
|
||||
|
||||
return levelState;
|
||||
}
|
||||
|
||||
export function getUnresolvedExits(levelState: DungeonLevelState) {
|
||||
return levelState.discoveredRoomOrder.flatMap((roomId) => {
|
||||
const room = levelState.rooms[roomId];
|
||||
|
||||
return room.exits
|
||||
.filter((exit) => !exit.leadsToRoomId && exit.traversable)
|
||||
.map((exit) => ({
|
||||
roomId,
|
||||
exitId: exit.id,
|
||||
direction: exit.direction,
|
||||
exitType: exit.exitType,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
export function expandLevelFromExit(
|
||||
options: ExpandFromExitOptions,
|
||||
): ExpansionResult {
|
||||
const levelState = cloneLevel(options.levelState);
|
||||
const fromRoom = levelState.rooms[options.fromRoomId];
|
||||
|
||||
if (!fromRoom) {
|
||||
throw new Error(`Unknown source room id: ${options.fromRoomId}`);
|
||||
}
|
||||
|
||||
const sourceExit = findExit(fromRoom, options.exitDirection);
|
||||
|
||||
if (sourceExit.leadsToRoomId) {
|
||||
throw new Error(`Exit ${sourceExit.id} is already connected to ${sourceExit.leadsToRoomId}.`);
|
||||
}
|
||||
|
||||
if (!sourceExit.traversable) {
|
||||
throw new Error(`Exit ${sourceExit.id} is not traversable.`);
|
||||
}
|
||||
|
||||
const position = computeNextPosition(fromRoom, options.exitDirection);
|
||||
assertCoordinateAvailable(levelState, position);
|
||||
|
||||
const provisionalRoomId =
|
||||
options.roomId ?? getNextRoomId(levelState, options.roomTableCode === "L1SR" ? "small" : "room");
|
||||
const result = generateRoomFromTable({
|
||||
content: options.content,
|
||||
roomId: provisionalRoomId,
|
||||
level: levelState.level,
|
||||
roomTableCode: options.roomTableCode,
|
||||
position,
|
||||
roller: options.roller,
|
||||
});
|
||||
|
||||
connectRooms(fromRoom, result.room, options.exitDirection);
|
||||
|
||||
levelState.rooms[fromRoom.id] = fromRoom;
|
||||
levelState.rooms[result.room.id] = result.room;
|
||||
levelState.discoveredRoomOrder.push(result.room.id);
|
||||
|
||||
return {
|
||||
levelState,
|
||||
createdRoom: result.room,
|
||||
fromRoom,
|
||||
};
|
||||
}
|
||||
73
src/rules/encounters.test.ts
Normal file
73
src/rules/encounters.test.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
||||
|
||||
import { createRoomStateFromTemplate } from "./rooms";
|
||||
import { resolveRoomEncounter } from "./encounters";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
describe("encounter resolution", () => {
|
||||
it("marks explicitly empty rooms as having no encounter", () => {
|
||||
const room = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.small.empty",
|
||||
1,
|
||||
"room.level1.small.empty-space",
|
||||
);
|
||||
room.notes.push("Nothing here.");
|
||||
|
||||
const result = resolveRoomEncounter(sampleContentPack, room);
|
||||
|
||||
expect(result.encounter?.creatureIds).toEqual([]);
|
||||
expect(result.encounter?.resultLabel).toBe("No encounter");
|
||||
});
|
||||
|
||||
it("uses room context to resolve a guard encounter table", () => {
|
||||
const room = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.guard-room",
|
||||
1,
|
||||
"room.level1.normal.guard-room",
|
||||
);
|
||||
room.notes.push("Use the guards encounter table if occupied.");
|
||||
|
||||
const result = resolveRoomEncounter(
|
||||
sampleContentPack,
|
||||
room,
|
||||
createSequenceRoller([6]),
|
||||
);
|
||||
|
||||
expect(result.lookup?.entry.label).toBe("Guard and Warrior");
|
||||
expect(result.encounter?.sourceTableCode).toBe("L1G");
|
||||
expect(result.encounter?.creatureNames).toEqual(["Guard", "Warrior"]);
|
||||
});
|
||||
|
||||
it("resolves crate events from room context when the room hints at crate rolls", () => {
|
||||
const room = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.storage-area",
|
||||
1,
|
||||
"room.level1.normal.storage-area",
|
||||
);
|
||||
room.notes.push("Roll for food, drink, or crate events while searching.");
|
||||
|
||||
const result = resolveRoomEncounter(
|
||||
sampleContentPack,
|
||||
room,
|
||||
createSequenceRoller([2]),
|
||||
);
|
||||
|
||||
expect(result.lookup?.entry.label).toBe("Giant Rat Pair");
|
||||
expect(result.encounter?.sourceTableCode).toBe("L1CE");
|
||||
expect(result.encounter?.creatureNames).toEqual(["Giant Rat Pair"]);
|
||||
});
|
||||
});
|
||||
110
src/rules/encounters.ts
Normal file
110
src/rules/encounters.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { findTableByCode } from "@/data/contentHelpers";
|
||||
import type { ContentPack } from "@/types/content";
|
||||
import type { EncounterState, RoomState } from "@/types/state";
|
||||
|
||||
import { lookupTable, type TableLookupResult } from "./tables";
|
||||
import type { DiceRoller } from "./dice";
|
||||
|
||||
export type EncounterResolutionResult = {
|
||||
room: RoomState;
|
||||
encounter?: EncounterState;
|
||||
lookup?: TableLookupResult;
|
||||
};
|
||||
|
||||
const ROOM_HINT_TO_TABLE: Array<{ pattern: RegExp; tableCode: string }> = [
|
||||
{ pattern: /\bdogs?\b/i, tableCode: "L1D" },
|
||||
{ pattern: /\bguards?\b/i, tableCode: "L1G" },
|
||||
{ pattern: /\bmartial\b/i, tableCode: "L1M" },
|
||||
{ pattern: /\bworkers?\b/i, tableCode: "L1W" },
|
||||
{ pattern: /\blabourers?\b/i, tableCode: "L1P" },
|
||||
{ pattern: /\bpreacher\b/i, tableCode: "L1P" },
|
||||
{ pattern: /\banimals?\b/i, tableCode: "L1A" },
|
||||
{ pattern: /\bsnakes?\b/i, tableCode: "L1A" },
|
||||
{ pattern: /\bfungal\b/i, tableCode: "L1F" },
|
||||
{ pattern: /\bslimy\b/i, tableCode: "L1F" },
|
||||
{ pattern: /\bcrate\b/i, tableCode: "L1CE" },
|
||||
];
|
||||
|
||||
function splitEncounterLabel(label: string) {
|
||||
return label
|
||||
.split(/\sand\s/i)
|
||||
.map((part) => part.trim())
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
function inferEncounterTableCode(room: RoomState) {
|
||||
const noteText = room.notes.join(" ");
|
||||
const flagText = room.flags.join(" ");
|
||||
const combinedText = `${noteText} ${flagText}`;
|
||||
|
||||
for (const mapping of ROOM_HINT_TO_TABLE) {
|
||||
if (mapping.pattern.test(combinedText)) {
|
||||
return mapping.tableCode;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isNonEncounterRoom(room: RoomState) {
|
||||
const noteText = room.notes.join(" ").toLowerCase();
|
||||
return noteText.includes("nothing here") || noteText.includes("no encounter");
|
||||
}
|
||||
|
||||
export function resolveRoomEncounter(
|
||||
content: ContentPack,
|
||||
room: RoomState,
|
||||
roller?: DiceRoller,
|
||||
): EncounterResolutionResult {
|
||||
if (room.encounter?.resolved) {
|
||||
return {
|
||||
room,
|
||||
encounter: room.encounter,
|
||||
};
|
||||
}
|
||||
|
||||
if (isNonEncounterRoom(room)) {
|
||||
const emptyEncounter: EncounterState = {
|
||||
id: `${room.id}.encounter`,
|
||||
creatureIds: [],
|
||||
creatureNames: [],
|
||||
resultLabel: "No encounter",
|
||||
resolved: true,
|
||||
};
|
||||
|
||||
return {
|
||||
room: {
|
||||
...room,
|
||||
encounter: emptyEncounter,
|
||||
},
|
||||
encounter: emptyEncounter,
|
||||
};
|
||||
}
|
||||
|
||||
const tableCode = inferEncounterTableCode(room);
|
||||
|
||||
if (!tableCode) {
|
||||
return { room };
|
||||
}
|
||||
|
||||
const table = findTableByCode(content, tableCode);
|
||||
const lookup = lookupTable(table, { roller });
|
||||
const creatureNames = splitEncounterLabel(lookup.entry.label);
|
||||
const encounter: EncounterState = {
|
||||
id: `${room.id}.encounter`,
|
||||
sourceTableCode: tableCode,
|
||||
creatureIds: creatureNames.map((_, index) => `${room.id}.creature.${index + 1}`),
|
||||
creatureNames,
|
||||
resultLabel: lookup.entry.label,
|
||||
resolved: true,
|
||||
};
|
||||
|
||||
return {
|
||||
room: {
|
||||
...room,
|
||||
encounter,
|
||||
},
|
||||
encounter,
|
||||
lookup,
|
||||
};
|
||||
}
|
||||
115
src/rules/roomEntry.test.ts
Normal file
115
src/rules/roomEntry.test.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
||||
|
||||
import { expandLevelFromExit, initializeDungeonLevel } from "./dungeon";
|
||||
import { createRoomStateFromTemplate } from "./rooms";
|
||||
import { enterRoom } from "./roomEntry";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
describe("room entry flow", () => {
|
||||
it("marks a newly generated room as entered and resolves an empty encounter", () => {
|
||||
const levelState = initializeDungeonLevel({ content: sampleContentPack });
|
||||
const expanded = expandLevelFromExit({
|
||||
content: sampleContentPack,
|
||||
levelState,
|
||||
fromRoomId: "room.level1.start",
|
||||
exitDirection: "north",
|
||||
roomTableCode: "L1SR",
|
||||
roller: createSequenceRoller([1, 1]),
|
||||
});
|
||||
|
||||
const result = enterRoom({
|
||||
content: sampleContentPack,
|
||||
levelState: expanded.levelState,
|
||||
roomId: expanded.createdRoom.id,
|
||||
at: "2026-03-15T12:00:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.firstEntry).toBe(true);
|
||||
expect(result.encounterResolved).toBe(true);
|
||||
expect(result.room.discovery.entered).toBe(true);
|
||||
expect(result.room.discovery.cleared).toBe(true);
|
||||
expect(result.room.encounter?.resultLabel).toBe("No encounter");
|
||||
expect(result.logEntries.map((entry) => entry.text)).toEqual([
|
||||
"Entered Empty Space.",
|
||||
"Empty Space is quiet.",
|
||||
]);
|
||||
});
|
||||
|
||||
it("resolves a guard encounter once and records the lookup roll", () => {
|
||||
const levelState = initializeDungeonLevel({ content: sampleContentPack });
|
||||
const guardRoom = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.guard-room",
|
||||
1,
|
||||
"room.level1.normal.guard-room",
|
||||
{ x: 0, y: -1 },
|
||||
);
|
||||
|
||||
levelState.rooms[guardRoom.id] = guardRoom;
|
||||
levelState.discoveredRoomOrder.push(guardRoom.id);
|
||||
|
||||
const result = enterRoom({
|
||||
content: sampleContentPack,
|
||||
levelState,
|
||||
roomId: guardRoom.id,
|
||||
roller: createSequenceRoller([6]),
|
||||
at: "2026-03-15T12:00:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.room.templateId).toBe("room.level1.normal.guard-room");
|
||||
expect(result.lookup?.entry.label).toBe("Guard and Warrior");
|
||||
expect(result.room.encounter?.creatureNames).toEqual(["Guard", "Warrior"]);
|
||||
expect(result.room.discovery.cleared).toBe(false);
|
||||
expect(result.logEntries.map((entry) => entry.type)).toEqual(["room", "roll", "room"]);
|
||||
expect(result.logEntries[1]?.text).toContain("Guard and Warrior");
|
||||
});
|
||||
|
||||
it("does not reroll an encounter when re-entering a room", () => {
|
||||
const levelState = initializeDungeonLevel({ content: sampleContentPack });
|
||||
const guardRoom = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.guard-room",
|
||||
1,
|
||||
"room.level1.normal.guard-room",
|
||||
{ x: 0, y: -1 },
|
||||
);
|
||||
|
||||
levelState.rooms[guardRoom.id] = guardRoom;
|
||||
levelState.discoveredRoomOrder.push(guardRoom.id);
|
||||
|
||||
const firstEntry = enterRoom({
|
||||
content: sampleContentPack,
|
||||
levelState,
|
||||
roomId: guardRoom.id,
|
||||
roller: createSequenceRoller([4]),
|
||||
at: "2026-03-15T12:00:00.000Z",
|
||||
});
|
||||
const secondEntry = enterRoom({
|
||||
content: sampleContentPack,
|
||||
levelState: firstEntry.levelState,
|
||||
roomId: guardRoom.id,
|
||||
roller: createSequenceRoller([6]),
|
||||
at: "2026-03-15T12:05:00.000Z",
|
||||
});
|
||||
|
||||
expect(firstEntry.room.encounter?.resultLabel).toBe("Guard");
|
||||
expect(secondEntry.room.encounter?.resultLabel).toBe("Guard");
|
||||
expect(secondEntry.lookup).toBeUndefined();
|
||||
expect(secondEntry.firstEntry).toBe(false);
|
||||
expect(secondEntry.logEntries.map((entry) => entry.text)).toEqual([
|
||||
"Re-entered Guard Room.",
|
||||
"Encounter in Guard Room: Guard.",
|
||||
]);
|
||||
});
|
||||
});
|
||||
164
src/rules/roomEntry.ts
Normal file
164
src/rules/roomEntry.ts
Normal file
@@ -0,0 +1,164 @@
|
||||
import { findRoomTemplateById } from "@/data/contentHelpers";
|
||||
import type { ContentPack } from "@/types/content";
|
||||
import type { DungeonLevelState, RoomState } from "@/types/state";
|
||||
import type { LogEntry } from "@/types/rules";
|
||||
|
||||
import type { DiceRoller } from "./dice";
|
||||
import { resolveRoomEncounter } from "./encounters";
|
||||
import type { TableLookupResult } from "./tables";
|
||||
|
||||
export type EnterRoomOptions = {
|
||||
content: ContentPack;
|
||||
levelState: DungeonLevelState;
|
||||
roomId: string;
|
||||
roller?: DiceRoller;
|
||||
at?: string;
|
||||
};
|
||||
|
||||
export type EnterRoomResult = {
|
||||
levelState: DungeonLevelState;
|
||||
room: RoomState;
|
||||
logEntries: LogEntry[];
|
||||
lookup?: TableLookupResult;
|
||||
firstEntry: boolean;
|
||||
encounterResolved: boolean;
|
||||
};
|
||||
|
||||
function cloneRoom(room: RoomState): RoomState {
|
||||
return {
|
||||
...room,
|
||||
position: { ...room.position },
|
||||
dimensions: { ...room.dimensions },
|
||||
exits: room.exits.map((exit) => ({ ...exit })),
|
||||
discovery: { ...room.discovery },
|
||||
encounter: room.encounter
|
||||
? {
|
||||
...room.encounter,
|
||||
creatureIds: [...room.encounter.creatureIds],
|
||||
creatureNames: room.encounter.creatureNames
|
||||
? [...room.encounter.creatureNames]
|
||||
: undefined,
|
||||
}
|
||||
: undefined,
|
||||
objects: room.objects.map((object) => ({
|
||||
...object,
|
||||
effects: object.effects ? [...object.effects] : undefined,
|
||||
})),
|
||||
notes: [...room.notes],
|
||||
flags: [...room.flags],
|
||||
};
|
||||
}
|
||||
|
||||
function cloneLevel(levelState: DungeonLevelState): DungeonLevelState {
|
||||
return {
|
||||
...levelState,
|
||||
rooms: Object.fromEntries(
|
||||
Object.entries(levelState.rooms).map(([roomId, room]) => [roomId, cloneRoom(room)]),
|
||||
),
|
||||
discoveredRoomOrder: [...levelState.discoveredRoomOrder],
|
||||
};
|
||||
}
|
||||
|
||||
function getRoomLabel(content: ContentPack, room: RoomState) {
|
||||
if (room.templateId) {
|
||||
return findRoomTemplateById(content, room.templateId).title;
|
||||
}
|
||||
|
||||
return room.notes[0] ?? room.id;
|
||||
}
|
||||
|
||||
function createLogEntry(
|
||||
id: string,
|
||||
at: string,
|
||||
type: LogEntry["type"],
|
||||
text: string,
|
||||
relatedIds: string[],
|
||||
): LogEntry {
|
||||
return {
|
||||
id,
|
||||
at,
|
||||
type,
|
||||
text,
|
||||
relatedIds,
|
||||
};
|
||||
}
|
||||
|
||||
function formatRollText(lookup: TableLookupResult) {
|
||||
const total = lookup.roll.modifiedTotal ?? lookup.roll.total;
|
||||
const rolledValues = lookup.roll.rolls.join(", ");
|
||||
|
||||
return `Rolled ${lookup.roll.diceKind} [${rolledValues}] on ${lookup.tableId} for ${total}: ${lookup.entry.label}.`;
|
||||
}
|
||||
|
||||
export function enterRoom(options: EnterRoomOptions): EnterRoomResult {
|
||||
const levelState = cloneLevel(options.levelState);
|
||||
const room = levelState.rooms[options.roomId];
|
||||
|
||||
if (!room) {
|
||||
throw new Error(`Unknown room id: ${options.roomId}`);
|
||||
}
|
||||
|
||||
const at = options.at ?? new Date().toISOString();
|
||||
const roomLabel = getRoomLabel(options.content, room);
|
||||
const firstEntry = !room.discovery.entered;
|
||||
room.discovery.entered = true;
|
||||
|
||||
const resolution = resolveRoomEncounter(options.content, room, options.roller);
|
||||
const nextRoom = resolution.room;
|
||||
const encounterResolved = Boolean(resolution.encounter);
|
||||
|
||||
if (resolution.encounter && resolution.encounter.creatureIds.length === 0) {
|
||||
nextRoom.discovery.cleared = true;
|
||||
}
|
||||
|
||||
levelState.rooms[nextRoom.id] = nextRoom;
|
||||
|
||||
const entryVerb = firstEntry ? "Entered" : "Re-entered";
|
||||
const logEntries: LogEntry[] = [
|
||||
createLogEntry(
|
||||
`${nextRoom.id}.entry.${firstEntry ? "first" : "repeat"}`,
|
||||
at,
|
||||
"room",
|
||||
`${entryVerb} ${roomLabel}.`,
|
||||
[nextRoom.id],
|
||||
),
|
||||
];
|
||||
|
||||
if (resolution.lookup) {
|
||||
logEntries.push(
|
||||
createLogEntry(
|
||||
`${nextRoom.id}.entry.roll`,
|
||||
at,
|
||||
"roll",
|
||||
formatRollText(resolution.lookup),
|
||||
[nextRoom.id, resolution.lookup.tableId],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (resolution.encounter) {
|
||||
const encounterText =
|
||||
resolution.encounter.creatureIds.length === 0
|
||||
? `${roomLabel} is quiet.`
|
||||
: `Encounter in ${roomLabel}: ${resolution.encounter.resultLabel ?? "Unknown threat"}.`;
|
||||
|
||||
logEntries.push(
|
||||
createLogEntry(
|
||||
`${nextRoom.id}.entry.encounter`,
|
||||
at,
|
||||
"room",
|
||||
encounterText,
|
||||
[nextRoom.id, resolution.encounter.id],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
levelState,
|
||||
room: nextRoom,
|
||||
logEntries,
|
||||
lookup: resolution.lookup,
|
||||
firstEntry,
|
||||
encounterResolved,
|
||||
};
|
||||
}
|
||||
91
src/rules/rooms.test.ts
Normal file
91
src/rules/rooms.test.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
||||
|
||||
import {
|
||||
createLevelShell,
|
||||
createRoomStateFromTemplate,
|
||||
generateLevel1StartRoom,
|
||||
generateRoomFromTable,
|
||||
} from "./rooms";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
describe("room generation", () => {
|
||||
it("creates the level 1 start room from its template", () => {
|
||||
const result = generateLevel1StartRoom(sampleContentPack);
|
||||
|
||||
expect(result.templateSource).toBe("direct-template");
|
||||
expect(result.room.roomClass).toBe("start");
|
||||
expect(result.room.position).toEqual({ x: 0, y: 0 });
|
||||
expect(result.room.exits).toHaveLength(1);
|
||||
expect(result.room.exits[0]?.direction).toBe("north");
|
||||
});
|
||||
|
||||
it("generates a small room from the encoded small-room table", () => {
|
||||
const result = generateRoomFromTable({
|
||||
content: sampleContentPack,
|
||||
roomId: "room.level1.small.001",
|
||||
level: 1,
|
||||
roomTableCode: "L1SR",
|
||||
position: { x: 2, y: 1 },
|
||||
roller: createSequenceRoller([5, 5]),
|
||||
});
|
||||
|
||||
expect(result.lookup?.roll.total).toBe(10);
|
||||
expect(result.room.templateId).toBe("room.level1.small.heated-space");
|
||||
expect(result.room.dimensions).toEqual({ width: 2, height: 3 });
|
||||
expect(result.room.exits).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("generates a large room from the encoded large-room table", () => {
|
||||
const result = generateRoomFromTable({
|
||||
content: sampleContentPack,
|
||||
roomId: "room.level1.large.001",
|
||||
level: 1,
|
||||
roomTableCode: "L1LR",
|
||||
position: { x: 4, y: 3 },
|
||||
roller: createSequenceRoller([4, 4]),
|
||||
});
|
||||
|
||||
expect(result.lookup?.roll.total).toBe(8);
|
||||
expect(result.room.templateId).toBe("room.level1.large.sparring-chamber");
|
||||
expect(result.room.dimensions).toEqual({ width: 6, height: 6 });
|
||||
expect(result.room.exits).toHaveLength(3);
|
||||
expect(result.room.flags).toContain("large");
|
||||
});
|
||||
|
||||
it("respects explicit template exits when they are defined", () => {
|
||||
const room = createRoomStateFromTemplate(
|
||||
sampleContentPack,
|
||||
"room.level1.custom.start",
|
||||
1,
|
||||
"room.level1.entry",
|
||||
{ x: 0, y: 0 },
|
||||
);
|
||||
|
||||
expect(room.exits).toEqual([
|
||||
expect.objectContaining({
|
||||
direction: "north",
|
||||
exitType: "door",
|
||||
discovered: true,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("creates a clean level shell for future dungeon state", () => {
|
||||
const level = createLevelShell(1);
|
||||
|
||||
expect(level.themeName).toBe("The Entry");
|
||||
expect(level.rooms).toEqual({});
|
||||
expect(level.discoveredRoomOrder).toEqual([]);
|
||||
});
|
||||
});
|
||||
200
src/rules/rooms.ts
Normal file
200
src/rules/rooms.ts
Normal file
@@ -0,0 +1,200 @@
|
||||
import {
|
||||
findRoomTemplateById,
|
||||
findRoomTemplateForLookup,
|
||||
findTableByCode,
|
||||
} from "@/data/contentHelpers";
|
||||
import type { ContentPack, ExitType, RoomClass } from "@/types/content";
|
||||
import type { DungeonLevelState, RoomExitState, RoomState } from "@/types/state";
|
||||
|
||||
import { lookupTable, type TableLookupResult } from "./tables";
|
||||
import type { DiceRoller } from "./dice";
|
||||
|
||||
export type RoomGenerationOptions = {
|
||||
content: ContentPack;
|
||||
roomId: string;
|
||||
level: number;
|
||||
roomTemplateId?: string;
|
||||
roomTableCode?: string;
|
||||
roomClass?: RoomClass;
|
||||
position?: {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
roller?: DiceRoller;
|
||||
};
|
||||
|
||||
export type RoomGenerationResult = {
|
||||
room: RoomState;
|
||||
lookup?: TableLookupResult;
|
||||
templateSource: "direct-template" | "table-lookup";
|
||||
};
|
||||
|
||||
const DEFAULT_ROOM_DIMENSIONS: Record<RoomClass, { width: number; height: number }> = {
|
||||
start: { width: 4, height: 4 },
|
||||
normal: { width: 4, height: 4 },
|
||||
small: { width: 2, height: 3 },
|
||||
large: { width: 6, height: 6 },
|
||||
special: { width: 4, height: 4 },
|
||||
stairs: { width: 4, height: 4 },
|
||||
};
|
||||
|
||||
const DEFAULT_DIRECTIONS = ["north", "east", "south", "west"] as const;
|
||||
|
||||
function inferExitType(exitHint?: string): ExitType {
|
||||
const normalized = exitHint?.toLowerCase() ?? "";
|
||||
|
||||
if (normalized.includes("reinforced")) {
|
||||
return "locked";
|
||||
}
|
||||
|
||||
if (normalized.includes("curtain")) {
|
||||
return "open";
|
||||
}
|
||||
|
||||
if (normalized.includes("archway")) {
|
||||
return "open";
|
||||
}
|
||||
|
||||
if (normalized.includes("wooden")) {
|
||||
return "door";
|
||||
}
|
||||
|
||||
return "door";
|
||||
}
|
||||
|
||||
function inferExitCount(roomClass: RoomClass, exitHint?: string) {
|
||||
const normalized = exitHint?.toLowerCase() ?? "";
|
||||
|
||||
if (normalized.includes("random")) {
|
||||
return roomClass === "large" ? 3 : 2;
|
||||
}
|
||||
|
||||
if (normalized.includes("archway")) {
|
||||
return roomClass === "large" ? 3 : 2;
|
||||
}
|
||||
|
||||
if (roomClass === "small") {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (roomClass === "large") {
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
function createExits(
|
||||
roomId: string,
|
||||
roomClass: RoomClass,
|
||||
exitHint?: string,
|
||||
): RoomExitState[] {
|
||||
const exitCount = inferExitCount(roomClass, exitHint);
|
||||
const exitType = inferExitType(exitHint);
|
||||
|
||||
return DEFAULT_DIRECTIONS.slice(0, exitCount).map((direction, index) => ({
|
||||
id: `${roomId}.exit.${index + 1}`,
|
||||
direction,
|
||||
exitType,
|
||||
discovered: roomClass === "start",
|
||||
traversable: true,
|
||||
}));
|
||||
}
|
||||
|
||||
export function createRoomStateFromTemplate(
|
||||
content: ContentPack,
|
||||
roomId: string,
|
||||
level: number,
|
||||
roomTemplateId: string,
|
||||
position = { x: 0, y: 0 },
|
||||
): RoomState {
|
||||
const template = findRoomTemplateById(content, roomTemplateId);
|
||||
const dimensions = template.dimensions ?? DEFAULT_ROOM_DIMENSIONS[template.roomClass];
|
||||
const exits =
|
||||
template.exits?.map((exit, index) => ({
|
||||
id: `${roomId}.exit.${index + 1}`,
|
||||
direction: exit.direction ?? DEFAULT_DIRECTIONS[index] ?? "north",
|
||||
exitType: exit.exitType,
|
||||
discovered: template.roomClass === "start",
|
||||
traversable: exit.exitType !== "locked",
|
||||
destinationLevel: exit.destinationLevel,
|
||||
})) ?? createExits(roomId, template.roomClass, template.exitHint);
|
||||
|
||||
return {
|
||||
id: roomId,
|
||||
level,
|
||||
templateId: template.id,
|
||||
position,
|
||||
dimensions,
|
||||
roomClass: template.roomClass,
|
||||
exits,
|
||||
discovery: {
|
||||
generated: true,
|
||||
entered: template.roomClass === "start",
|
||||
cleared: false,
|
||||
searched: false,
|
||||
},
|
||||
encounter: undefined,
|
||||
objects: [],
|
||||
notes: [template.text ?? template.title, template.encounterText].filter(
|
||||
(note): note is string => Boolean(note),
|
||||
),
|
||||
flags: [
|
||||
`table:${template.tableCode}`,
|
||||
`entry:${template.tableEntryKey}`,
|
||||
...(template.unique ? ["unique"] : []),
|
||||
...template.tags,
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export function generateRoomFromTable(
|
||||
options: RoomGenerationOptions,
|
||||
): RoomGenerationResult {
|
||||
if (!options.roomTableCode) {
|
||||
throw new Error("Room table code is required for table-based room generation.");
|
||||
}
|
||||
|
||||
const table = findTableByCode(options.content, options.roomTableCode);
|
||||
const lookup = lookupTable(table, { roller: options.roller });
|
||||
const template = findRoomTemplateForLookup(options.content, lookup);
|
||||
const room = createRoomStateFromTemplate(
|
||||
options.content,
|
||||
options.roomId,
|
||||
options.level,
|
||||
template.id,
|
||||
options.position,
|
||||
);
|
||||
|
||||
return {
|
||||
room,
|
||||
lookup,
|
||||
templateSource: "table-lookup",
|
||||
};
|
||||
}
|
||||
|
||||
export function generateLevel1StartRoom(
|
||||
content: ContentPack,
|
||||
roomId = "room.level1.start",
|
||||
): RoomGenerationResult {
|
||||
const room = createRoomStateFromTemplate(content, roomId, 1, "room.level1.entry", {
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
|
||||
return {
|
||||
room,
|
||||
templateSource: "direct-template",
|
||||
};
|
||||
}
|
||||
|
||||
export function createLevelShell(level: number): DungeonLevelState {
|
||||
return {
|
||||
level,
|
||||
themeName: level === 1 ? "The Entry" : undefined,
|
||||
rooms: {},
|
||||
discoveredRoomOrder: [],
|
||||
secretDoorUsed: false,
|
||||
exhaustedExitSearch: false,
|
||||
};
|
||||
}
|
||||
186
src/rules/runState.test.ts
Normal file
186
src/rules/runState.test.ts
Normal file
@@ -0,0 +1,186 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { sampleContentPack } from "@/data/sampleContentPack";
|
||||
|
||||
import { createStartingAdventurer } from "./character";
|
||||
import {
|
||||
createRunState,
|
||||
enterCurrentRoom,
|
||||
resolveRunEnemyTurn,
|
||||
resolveRunPlayerTurn,
|
||||
startCombatInCurrentRoom,
|
||||
} from "./runState";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
function createAdventurer() {
|
||||
return createStartingAdventurer(sampleContentPack, {
|
||||
name: "Aster",
|
||||
weaponId: "weapon.short-sword",
|
||||
armourId: "armour.leather-vest",
|
||||
scrollId: "scroll.lesser-heal",
|
||||
});
|
||||
}
|
||||
|
||||
describe("run state flow", () => {
|
||||
it("creates a run anchored in the start room", () => {
|
||||
const run = createRunState({
|
||||
content: sampleContentPack,
|
||||
campaignId: "campaign.1",
|
||||
adventurer: createAdventurer(),
|
||||
at: "2026-03-15T14:00:00.000Z",
|
||||
});
|
||||
|
||||
expect(run.currentLevel).toBe(1);
|
||||
expect(run.currentRoomId).toBe("room.level1.start");
|
||||
expect(run.dungeon.levels["1"]?.rooms["room.level1.start"]).toBeDefined();
|
||||
});
|
||||
|
||||
it("enters the current room and appends room logs", () => {
|
||||
const run = createRunState({
|
||||
content: sampleContentPack,
|
||||
campaignId: "campaign.1",
|
||||
adventurer: createAdventurer(),
|
||||
at: "2026-03-15T14:00:00.000Z",
|
||||
});
|
||||
|
||||
const result = enterCurrentRoom({
|
||||
content: sampleContentPack,
|
||||
run,
|
||||
at: "2026-03-15T14:01:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.run.log).toHaveLength(1);
|
||||
expect(result.run.log[0]?.text).toContain("Re-entered Entry Chamber");
|
||||
});
|
||||
|
||||
it("starts combat from the current room and stores the active combat state", () => {
|
||||
const run = createRunState({
|
||||
content: sampleContentPack,
|
||||
campaignId: "campaign.1",
|
||||
adventurer: createAdventurer(),
|
||||
at: "2026-03-15T14:00:00.000Z",
|
||||
});
|
||||
const levelState = run.dungeon.levels["1"]!;
|
||||
const room = levelState.rooms["room.level1.start"]!;
|
||||
|
||||
room.encounter = {
|
||||
id: `${room.id}.encounter`,
|
||||
sourceTableCode: "L1G",
|
||||
creatureIds: ["a", "b"],
|
||||
creatureNames: ["Guard", "Warrior"],
|
||||
resultLabel: "Guard and Warrior",
|
||||
resolved: true,
|
||||
};
|
||||
|
||||
const result = startCombatInCurrentRoom({
|
||||
content: sampleContentPack,
|
||||
run,
|
||||
at: "2026-03-15T14:02:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.run.activeCombat?.enemies).toHaveLength(2);
|
||||
expect(result.run.log.at(-1)?.text).toContain("Combat begins");
|
||||
});
|
||||
|
||||
it("resolves player and enemy turns through run state", () => {
|
||||
const run = createRunState({
|
||||
content: sampleContentPack,
|
||||
campaignId: "campaign.1",
|
||||
adventurer: createAdventurer(),
|
||||
at: "2026-03-15T14:00:00.000Z",
|
||||
});
|
||||
const levelState = run.dungeon.levels["1"]!;
|
||||
const room = levelState.rooms["room.level1.start"]!;
|
||||
|
||||
room.encounter = {
|
||||
id: `${room.id}.encounter`,
|
||||
sourceTableCode: "L1G",
|
||||
creatureIds: ["a", "b"],
|
||||
creatureNames: ["Guard", "Warrior"],
|
||||
resultLabel: "Guard and Warrior",
|
||||
resolved: true,
|
||||
};
|
||||
|
||||
const withCombat = startCombatInCurrentRoom({
|
||||
content: sampleContentPack,
|
||||
run,
|
||||
at: "2026-03-15T14:02:00.000Z",
|
||||
}).run;
|
||||
const targetEnemyId = withCombat.activeCombat!.enemies[0]!.id;
|
||||
|
||||
const afterPlayer = resolveRunPlayerTurn({
|
||||
content: sampleContentPack,
|
||||
run: withCombat,
|
||||
manoeuvreId: "manoeuvre.exact-strike",
|
||||
targetEnemyId,
|
||||
roller: createSequenceRoller([6, 6]),
|
||||
at: "2026-03-15T14:03:00.000Z",
|
||||
}).run;
|
||||
|
||||
expect(afterPlayer.activeCombat?.actingSide).toBe("enemy");
|
||||
expect(afterPlayer.log.at(-1)?.text).toContain("deals");
|
||||
|
||||
const afterEnemy = resolveRunEnemyTurn({
|
||||
content: sampleContentPack,
|
||||
run: afterPlayer,
|
||||
roller: createSequenceRoller([6, 6]),
|
||||
at: "2026-03-15T14:04:00.000Z",
|
||||
}).run;
|
||||
|
||||
expect(afterEnemy.activeCombat?.actingSide).toBe("player");
|
||||
expect(afterEnemy.adventurerSnapshot.hp.current).toBeLessThan(
|
||||
createAdventurer().hp.current,
|
||||
);
|
||||
});
|
||||
|
||||
it("clears the room and ends active combat when the last enemy falls", () => {
|
||||
const run = createRunState({
|
||||
content: sampleContentPack,
|
||||
campaignId: "campaign.1",
|
||||
adventurer: createAdventurer(),
|
||||
at: "2026-03-15T14:00:00.000Z",
|
||||
});
|
||||
const room = run.dungeon.levels["1"]!.rooms["room.level1.start"]!;
|
||||
|
||||
room.encounter = {
|
||||
id: `${room.id}.encounter`,
|
||||
sourceTableCode: "L1G",
|
||||
creatureIds: ["a"],
|
||||
creatureNames: ["Guard"],
|
||||
resultLabel: "Guard",
|
||||
resolved: true,
|
||||
};
|
||||
|
||||
const withCombat = startCombatInCurrentRoom({
|
||||
content: sampleContentPack,
|
||||
run,
|
||||
at: "2026-03-15T14:02:00.000Z",
|
||||
}).run;
|
||||
|
||||
withCombat.activeCombat!.enemies[0]!.hpCurrent = 1;
|
||||
|
||||
const result = resolveRunPlayerTurn({
|
||||
content: sampleContentPack,
|
||||
run: withCombat,
|
||||
manoeuvreId: "manoeuvre.guard-break",
|
||||
targetEnemyId: withCombat.activeCombat!.enemies[0]!.id,
|
||||
roller: createSequenceRoller([6, 6]),
|
||||
at: "2026-03-15T14:03:00.000Z",
|
||||
});
|
||||
|
||||
expect(result.run.activeCombat).toBeUndefined();
|
||||
expect(result.run.dungeon.levels["1"]!.rooms["room.level1.start"]!.discovery.cleared).toBe(true);
|
||||
expect(result.run.dungeon.levels["1"]!.rooms["room.level1.start"]!.encounter?.rewardPending).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
335
src/rules/runState.ts
Normal file
335
src/rules/runState.ts
Normal file
@@ -0,0 +1,335 @@
|
||||
import type { ContentPack } from "@/types/content";
|
||||
import type {
|
||||
AdventurerState,
|
||||
CombatState,
|
||||
DungeonState,
|
||||
RunState,
|
||||
} from "@/types/state";
|
||||
import type { LogEntry } from "@/types/rules";
|
||||
|
||||
import { startCombatFromRoom } from "./combat";
|
||||
import {
|
||||
resolveEnemyTurn,
|
||||
resolvePlayerAttack,
|
||||
type ResolveEnemyTurnOptions,
|
||||
type ResolvePlayerAttackOptions,
|
||||
} from "./combatTurns";
|
||||
import { initializeDungeonLevel } from "./dungeon";
|
||||
import type { DiceRoller } from "./dice";
|
||||
import { enterRoom } from "./roomEntry";
|
||||
|
||||
export type CreateRunOptions = {
|
||||
content: ContentPack;
|
||||
campaignId: string;
|
||||
adventurer: AdventurerState;
|
||||
runId?: string;
|
||||
at?: string;
|
||||
};
|
||||
|
||||
export type EnterCurrentRoomOptions = {
|
||||
content: ContentPack;
|
||||
run: RunState;
|
||||
roller?: DiceRoller;
|
||||
at?: string;
|
||||
};
|
||||
|
||||
export type StartCurrentCombatOptions = {
|
||||
content: ContentPack;
|
||||
run: RunState;
|
||||
at?: string;
|
||||
};
|
||||
|
||||
export type ResolveRunPlayerTurnOptions = {
|
||||
content: ContentPack;
|
||||
run: RunState;
|
||||
manoeuvreId: string;
|
||||
targetEnemyId: string;
|
||||
roller?: DiceRoller;
|
||||
at?: string;
|
||||
};
|
||||
|
||||
export type ResolveRunEnemyTurnOptions = {
|
||||
content: ContentPack;
|
||||
run: RunState;
|
||||
roller?: DiceRoller;
|
||||
at?: string;
|
||||
};
|
||||
|
||||
export type RunTransitionResult = {
|
||||
run: RunState;
|
||||
logEntries: LogEntry[];
|
||||
};
|
||||
|
||||
function cloneCombat(combat: CombatState): CombatState {
|
||||
return {
|
||||
...combat,
|
||||
player: {
|
||||
...combat.player,
|
||||
statuses: [...combat.player.statuses],
|
||||
traits: [...combat.player.traits],
|
||||
},
|
||||
enemies: combat.enemies.map((enemy) => ({
|
||||
...enemy,
|
||||
statuses: [...enemy.statuses],
|
||||
traits: [...enemy.traits],
|
||||
})),
|
||||
combatLog: combat.combatLog.map((entry) => ({
|
||||
...entry,
|
||||
relatedIds: entry.relatedIds ? [...entry.relatedIds] : undefined,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
function cloneRun(run: RunState): RunState {
|
||||
return {
|
||||
...run,
|
||||
adventurerSnapshot: {
|
||||
...run.adventurerSnapshot,
|
||||
hp: { ...run.adventurerSnapshot.hp },
|
||||
stats: { ...run.adventurerSnapshot.stats },
|
||||
favour: { ...run.adventurerSnapshot.favour },
|
||||
statuses: run.adventurerSnapshot.statuses.map((status) => ({ ...status })),
|
||||
inventory: {
|
||||
...run.adventurerSnapshot.inventory,
|
||||
carried: run.adventurerSnapshot.inventory.carried.map((entry) => ({ ...entry })),
|
||||
equipped: run.adventurerSnapshot.inventory.equipped.map((entry) => ({ ...entry })),
|
||||
stored: run.adventurerSnapshot.inventory.stored.map((entry) => ({ ...entry })),
|
||||
currency: { ...run.adventurerSnapshot.inventory.currency },
|
||||
lightSources: run.adventurerSnapshot.inventory.lightSources.map((entry) => ({ ...entry })),
|
||||
},
|
||||
progressionFlags: [...run.adventurerSnapshot.progressionFlags],
|
||||
manoeuvreIds: [...run.adventurerSnapshot.manoeuvreIds],
|
||||
},
|
||||
dungeon: {
|
||||
levels: Object.fromEntries(
|
||||
Object.entries(run.dungeon.levels).map(([level, levelState]) => [
|
||||
level,
|
||||
{
|
||||
...levelState,
|
||||
rooms: Object.fromEntries(
|
||||
Object.entries(levelState.rooms).map(([roomId, room]) => [
|
||||
roomId,
|
||||
{
|
||||
...room,
|
||||
position: { ...room.position },
|
||||
dimensions: { ...room.dimensions },
|
||||
exits: room.exits.map((exit) => ({ ...exit })),
|
||||
discovery: { ...room.discovery },
|
||||
encounter: room.encounter
|
||||
? {
|
||||
...room.encounter,
|
||||
creatureIds: [...room.encounter.creatureIds],
|
||||
creatureNames: room.encounter.creatureNames
|
||||
? [...room.encounter.creatureNames]
|
||||
: undefined,
|
||||
}
|
||||
: undefined,
|
||||
objects: room.objects.map((object) => ({
|
||||
...object,
|
||||
effects: object.effects ? [...object.effects] : undefined,
|
||||
})),
|
||||
notes: [...room.notes],
|
||||
flags: [...room.flags],
|
||||
},
|
||||
]),
|
||||
),
|
||||
discoveredRoomOrder: [...levelState.discoveredRoomOrder],
|
||||
},
|
||||
]),
|
||||
) as DungeonState["levels"],
|
||||
revealedPercentByLevel: { ...run.dungeon.revealedPercentByLevel },
|
||||
globalFlags: [...run.dungeon.globalFlags],
|
||||
},
|
||||
activeCombat: run.activeCombat ? cloneCombat(run.activeCombat) : undefined,
|
||||
log: run.log.map((entry) => ({
|
||||
...entry,
|
||||
relatedIds: entry.relatedIds ? [...entry.relatedIds] : undefined,
|
||||
})),
|
||||
pendingEffects: run.pendingEffects.map((effect) => ({ ...effect })),
|
||||
};
|
||||
}
|
||||
|
||||
function requireCurrentLevel(run: RunState) {
|
||||
const levelState = run.dungeon.levels[run.currentLevel];
|
||||
|
||||
if (!levelState) {
|
||||
throw new Error(`Run is missing level ${run.currentLevel}.`);
|
||||
}
|
||||
|
||||
return levelState;
|
||||
}
|
||||
|
||||
function requireCurrentRoomId(run: RunState) {
|
||||
if (!run.currentRoomId) {
|
||||
throw new Error("Run does not have a current room.");
|
||||
}
|
||||
|
||||
return run.currentRoomId;
|
||||
}
|
||||
|
||||
function syncPlayerToAdventurer(run: RunState) {
|
||||
if (!run.activeCombat) {
|
||||
return;
|
||||
}
|
||||
|
||||
run.adventurerSnapshot.hp.current = run.activeCombat.player.hpCurrent;
|
||||
run.adventurerSnapshot.statuses = run.activeCombat.player.statuses.map((status) => ({ ...status }));
|
||||
}
|
||||
|
||||
function appendLogs(run: RunState, logEntries: LogEntry[]) {
|
||||
run.log.push(...logEntries);
|
||||
}
|
||||
|
||||
export function createRunState(options: CreateRunOptions): RunState {
|
||||
const at = options.at ?? new Date().toISOString();
|
||||
const levelState = initializeDungeonLevel({
|
||||
content: options.content,
|
||||
level: 1,
|
||||
});
|
||||
|
||||
return {
|
||||
id: options.runId ?? "run.active",
|
||||
campaignId: options.campaignId,
|
||||
status: "active",
|
||||
startedAt: at,
|
||||
currentLevel: 1,
|
||||
currentRoomId: "room.level1.start",
|
||||
dungeon: {
|
||||
levels: {
|
||||
1: levelState,
|
||||
},
|
||||
revealedPercentByLevel: {
|
||||
1: 0,
|
||||
},
|
||||
globalFlags: [],
|
||||
},
|
||||
adventurerSnapshot: options.adventurer,
|
||||
log: [],
|
||||
pendingEffects: [],
|
||||
};
|
||||
}
|
||||
|
||||
export function enterCurrentRoom(
|
||||
options: EnterCurrentRoomOptions,
|
||||
): RunTransitionResult {
|
||||
const run = cloneRun(options.run);
|
||||
const levelState = requireCurrentLevel(run);
|
||||
const roomId = requireCurrentRoomId(run);
|
||||
const entry = enterRoom({
|
||||
content: options.content,
|
||||
levelState,
|
||||
roomId,
|
||||
roller: options.roller,
|
||||
at: options.at,
|
||||
});
|
||||
|
||||
run.dungeon.levels[run.currentLevel] = entry.levelState;
|
||||
appendLogs(run, entry.logEntries);
|
||||
|
||||
return {
|
||||
run,
|
||||
logEntries: entry.logEntries,
|
||||
};
|
||||
}
|
||||
|
||||
export function startCombatInCurrentRoom(
|
||||
options: StartCurrentCombatOptions,
|
||||
): RunTransitionResult {
|
||||
const run = cloneRun(options.run);
|
||||
const levelState = requireCurrentLevel(run);
|
||||
const roomId = requireCurrentRoomId(run);
|
||||
const room = levelState.rooms[roomId];
|
||||
|
||||
if (!room) {
|
||||
throw new Error(`Unknown room id: ${roomId}`);
|
||||
}
|
||||
|
||||
const started = startCombatFromRoom({
|
||||
content: options.content,
|
||||
adventurer: run.adventurerSnapshot,
|
||||
room,
|
||||
at: options.at,
|
||||
});
|
||||
|
||||
levelState.rooms[roomId] = started.room;
|
||||
run.activeCombat = started.combat;
|
||||
appendLogs(run, started.logEntries);
|
||||
|
||||
return {
|
||||
run,
|
||||
logEntries: started.logEntries,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveRunPlayerTurn(
|
||||
options: ResolveRunPlayerTurnOptions,
|
||||
): RunTransitionResult {
|
||||
const run = cloneRun(options.run);
|
||||
|
||||
if (!run.activeCombat) {
|
||||
throw new Error("Run does not have an active combat.");
|
||||
}
|
||||
|
||||
const result = resolvePlayerAttack({
|
||||
content: options.content,
|
||||
combat: run.activeCombat,
|
||||
adventurer: run.adventurerSnapshot,
|
||||
manoeuvreId: options.manoeuvreId,
|
||||
targetEnemyId: options.targetEnemyId,
|
||||
roller: options.roller,
|
||||
at: options.at,
|
||||
} satisfies ResolvePlayerAttackOptions);
|
||||
|
||||
run.activeCombat = result.combat;
|
||||
syncPlayerToAdventurer(run);
|
||||
appendLogs(run, result.logEntries);
|
||||
|
||||
if (result.combatEnded) {
|
||||
const levelState = requireCurrentLevel(run);
|
||||
const roomId = requireCurrentRoomId(run);
|
||||
const room = levelState.rooms[roomId];
|
||||
|
||||
if (room?.encounter) {
|
||||
room.encounter.rewardPending = false;
|
||||
room.discovery.cleared = true;
|
||||
}
|
||||
|
||||
run.activeCombat = undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
run,
|
||||
logEntries: result.logEntries,
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveRunEnemyTurn(
|
||||
options: ResolveRunEnemyTurnOptions,
|
||||
): RunTransitionResult {
|
||||
const run = cloneRun(options.run);
|
||||
|
||||
if (!run.activeCombat) {
|
||||
throw new Error("Run does not have an active combat.");
|
||||
}
|
||||
|
||||
const result = resolveEnemyTurn({
|
||||
content: options.content,
|
||||
combat: run.activeCombat,
|
||||
adventurer: run.adventurerSnapshot,
|
||||
roller: options.roller,
|
||||
at: options.at,
|
||||
} satisfies ResolveEnemyTurnOptions);
|
||||
|
||||
run.activeCombat = result.combat;
|
||||
syncPlayerToAdventurer(run);
|
||||
appendLogs(run, result.logEntries);
|
||||
|
||||
if (result.combatEnded) {
|
||||
run.status = "failed";
|
||||
}
|
||||
|
||||
return {
|
||||
run,
|
||||
logEntries: result.logEntries,
|
||||
};
|
||||
}
|
||||
62
src/rules/tables.test.ts
Normal file
62
src/rules/tables.test.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { TableDefinition } from "@/types/content";
|
||||
|
||||
import { lookupTable, resolveTableEntry } from "./tables";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
const d6Table: TableDefinition = {
|
||||
id: "table.sample",
|
||||
code: "SAMPLE1",
|
||||
name: "Sample Table",
|
||||
category: "generic",
|
||||
page: 1,
|
||||
diceKind: "d6",
|
||||
usesModifiedRangesRule: true,
|
||||
entries: [
|
||||
{ key: "1", exact: 1, label: "One" },
|
||||
{ key: "2-5", min: 2, max: 5, label: "Two to Five" },
|
||||
{ key: "6", exact: 6, label: "Six" },
|
||||
],
|
||||
mvp: true,
|
||||
};
|
||||
|
||||
describe("table lookup rules", () => {
|
||||
it("finds a matching exact entry", () => {
|
||||
const result = lookupTable(d6Table, { roller: createSequenceRoller([6]) });
|
||||
|
||||
expect(result.entry.label).toBe("Six");
|
||||
expect(result.roll.total).toBe(6);
|
||||
});
|
||||
|
||||
it("clamps modified results when the table uses modified ranges", () => {
|
||||
const result = lookupTable(d6Table, {
|
||||
roller: createSequenceRoller([6]),
|
||||
modifier: 3,
|
||||
});
|
||||
|
||||
expect(result.entry.label).toBe("Six");
|
||||
expect(result.roll.modifiedTotal).toBe(6);
|
||||
expect(result.roll.clamped).toBe(true);
|
||||
});
|
||||
|
||||
it("falls back to the nearest numeric entry for direct resolution", () => {
|
||||
const result = resolveTableEntry(d6Table, {
|
||||
diceKind: "d6",
|
||||
rolls: [0],
|
||||
total: 4,
|
||||
modifiedTotal: 7,
|
||||
});
|
||||
|
||||
expect(result.entry.label).toBe("Six");
|
||||
});
|
||||
});
|
||||
110
src/rules/tables.ts
Normal file
110
src/rules/tables.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import type { TableDefinition, TableEntry } from "@/types/content";
|
||||
import type { RollResult } from "@/types/rules";
|
||||
|
||||
import { applyRollModifier, rollDice, type DiceRoller } from "./dice";
|
||||
|
||||
export type TableLookupResult = {
|
||||
tableId: string;
|
||||
entryKey: string;
|
||||
roll: RollResult;
|
||||
entry: TableEntry;
|
||||
};
|
||||
|
||||
function getNumericEntryValue(entry: TableEntry) {
|
||||
if (entry.d66 !== undefined) {
|
||||
return entry.d66;
|
||||
}
|
||||
|
||||
if (entry.exact !== undefined) {
|
||||
return entry.exact;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getEntryBounds(entries: TableEntry[]) {
|
||||
const values = entries
|
||||
.flatMap((entry) => {
|
||||
if (entry.min !== undefined && entry.max !== undefined) {
|
||||
return [entry.min, entry.max];
|
||||
}
|
||||
|
||||
const exactValue = getNumericEntryValue(entry);
|
||||
return exactValue !== undefined ? [exactValue] : [];
|
||||
})
|
||||
.sort((a, b) => a - b);
|
||||
|
||||
if (values.length === 0) {
|
||||
throw new Error("Cannot compute table bounds for an empty numeric table.");
|
||||
}
|
||||
|
||||
return { min: values[0], max: values[values.length - 1] };
|
||||
}
|
||||
|
||||
function matchesEntry(entry: TableEntry, lookupValue: number) {
|
||||
if (entry.min !== undefined && entry.max !== undefined) {
|
||||
return lookupValue >= entry.min && lookupValue <= entry.max;
|
||||
}
|
||||
|
||||
const exactValue = getNumericEntryValue(entry);
|
||||
return exactValue === lookupValue;
|
||||
}
|
||||
|
||||
function findNearestEntry(entries: TableEntry[], lookupValue: number) {
|
||||
return entries
|
||||
.map((entry) => ({ entry, value: getNumericEntryValue(entry) }))
|
||||
.filter((candidate): candidate is { entry: TableEntry; value: number } => {
|
||||
return candidate.value !== undefined;
|
||||
})
|
||||
.sort((left, right) => {
|
||||
const distanceDelta =
|
||||
Math.abs(left.value - lookupValue) - Math.abs(right.value - lookupValue);
|
||||
|
||||
return distanceDelta !== 0 ? distanceDelta : left.value - right.value;
|
||||
})[0]?.entry;
|
||||
}
|
||||
|
||||
export function resolveTableEntry(
|
||||
table: TableDefinition,
|
||||
roll: RollResult,
|
||||
): TableLookupResult {
|
||||
const lookupValue = roll.modifiedTotal ?? roll.total;
|
||||
|
||||
if (lookupValue === undefined) {
|
||||
throw new Error(`Cannot resolve table ${table.code} without a roll total.`);
|
||||
}
|
||||
|
||||
const matchingEntry = table.entries.find((entry) => matchesEntry(entry, lookupValue));
|
||||
const fallbackEntry = matchingEntry ?? findNearestEntry(table.entries, lookupValue);
|
||||
|
||||
if (!fallbackEntry) {
|
||||
throw new Error(`No table entry found for ${table.code} with value ${lookupValue}.`);
|
||||
}
|
||||
|
||||
return {
|
||||
tableId: table.id,
|
||||
entryKey: fallbackEntry.key,
|
||||
roll,
|
||||
entry: fallbackEntry,
|
||||
};
|
||||
}
|
||||
|
||||
export function lookupTable(
|
||||
table: TableDefinition,
|
||||
options?: {
|
||||
modifier?: number;
|
||||
roller?: DiceRoller;
|
||||
},
|
||||
): TableLookupResult {
|
||||
const rawRoll = rollDice(table.diceKind, options?.roller);
|
||||
const roll =
|
||||
options?.modifier !== undefined
|
||||
? applyRollModifier(
|
||||
rawRoll,
|
||||
options.modifier,
|
||||
table.usesModifiedRangesRule ? getEntryBounds(table.entries) : undefined,
|
||||
)
|
||||
: rawRoll;
|
||||
|
||||
return resolveTableEntry(table, roll);
|
||||
}
|
||||
@@ -159,11 +159,15 @@ export const exitTemplateSchema = z.object({
|
||||
export const roomTemplateSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
level: z.number().int().positive(),
|
||||
sourcePage: z.number().int().positive().optional(),
|
||||
roomClass: z.enum(["normal", "small", "large", "special", "start", "stairs"]),
|
||||
tableCode: z.string().min(1),
|
||||
tableEntryKey: z.string().min(1),
|
||||
title: z.string().min(1),
|
||||
text: z.string().optional(),
|
||||
encounterText: z.string().optional(),
|
||||
exitHint: z.string().optional(),
|
||||
unique: z.boolean().optional(),
|
||||
dimensions: z
|
||||
.object({
|
||||
width: z.number().int().positive(),
|
||||
|
||||
@@ -110,6 +110,8 @@ export const encounterStateSchema = z.object({
|
||||
id: z.string().min(1),
|
||||
sourceTableCode: z.string().optional(),
|
||||
creatureIds: z.array(z.string()),
|
||||
creatureNames: z.array(z.string()).optional(),
|
||||
resultLabel: z.string().optional(),
|
||||
resolved: z.boolean(),
|
||||
surprise: z.boolean().optional(),
|
||||
rewardPending: z.boolean().optional(),
|
||||
|
||||
@@ -165,11 +165,15 @@ export type RoomClass = "normal" | "small" | "large" | "special" | "start" | "st
|
||||
export type RoomTemplate = {
|
||||
id: string;
|
||||
level: number;
|
||||
sourcePage?: number;
|
||||
roomClass: RoomClass;
|
||||
tableCode: string;
|
||||
tableEntryKey: string;
|
||||
title: string;
|
||||
text?: string;
|
||||
encounterText?: string;
|
||||
exitHint?: string;
|
||||
unique?: boolean;
|
||||
dimensions?: {
|
||||
width: number;
|
||||
height: number;
|
||||
|
||||
@@ -111,6 +111,8 @@ export type EncounterState = {
|
||||
id: string;
|
||||
sourceTableCode?: string;
|
||||
creatureIds: string[];
|
||||
creatureNames?: string[];
|
||||
resultLabel?: string;
|
||||
resolved: boolean;
|
||||
surprise?: boolean;
|
||||
rewardPending?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user