BlueGit

timfa questward

Award combat XP from damage dealt; tier-family items and distinct tree sprites.

Physical hits grant XP equal to damage to hit and damage skills with no kill bonus. Magic cast XP scales from spell difficulty for when spells are wired. Items and recipes migrate to tier families; combat rolls drop baseDamage in favour of stat rolls.

timfa Tim Falken · pushed by timfa

Authored 2026-08-26 · 2 months ago

Hash
42cbd8a1a78d277522b910d2dce96b4cc31a47c5
Parent
79408345
79 files changed +1669 −988
client/assets/blocks/birch-tree/fall-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/birch-tree/fall.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/birch-tree/summer-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/birch-tree/summer.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/birch-tree/winter-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/birch-tree/winter.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/ebony-tree/fall-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/ebony-tree/fall.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/ebony-tree/summer-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/ebony-tree/summer.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/ebony-tree/winter-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/ebony-tree/winter.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/elder-tree/fall-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/elder-tree/fall.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/elder-tree/summer-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/elder-tree/summer.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/elder-tree/winter-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/elder-tree/winter.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/heartwood-tree/fall-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/heartwood-tree/fall.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/heartwood-tree/summer-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/heartwood-tree/summer.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/heartwood-tree/winter-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/heartwood-tree/winter.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/lignum-tree/fall-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/lignum-tree/fall.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/lignum-tree/summer-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/lignum-tree/summer.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/lignum-tree/winter-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/lignum-tree/winter.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/oak-tree/fall-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/oak-tree/fall.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/oak-tree/summer-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/oak-tree/summer.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/oak-tree/winter-stump.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/blocks/oak-tree/winter.png Binary file +0 −0

The contents of this binary file are not shown.

client/assets/fx/projectile/arrow.png Binary file +0 −0

The contents of this binary file are not shown.

client/scripts/generate-tier-tree-sprites.mjs added +42 −0
@@ -0,0 +1,42 @@
1 #!/usr/bin/env node
2 /**
3 * Generate distinct 32×48 tree sprites per wood tier (summer/fall/winter + stumps).
4 *
5 * node client/scripts/generate-tier-tree-sprites.mjs
6 * node client/scripts/generate-tier-tree-sprites.mjs birch oak
7 *
8 * Each tier shape lives in tree-sprites/shapes/{tier}.mjs — edit those for silhouette changes.
9 */
10 import { WoodTier } from "../../shared/definitions/materialTiers.js";
11 import { writeTierTrees } from "./tree-sprites/common.mjs";
12 import { drawBirchCanopy } from "./tree-sprites/shapes/birch.mjs";
13 import { drawOakCanopy } from "./tree-sprites/shapes/oak.mjs";
14 import { drawEbonyCanopy } from "./tree-sprites/shapes/ebony.mjs";
15 import { drawLignumCanopy } from "./tree-sprites/shapes/lignum.mjs";
16 import { drawHeartwoodCanopy } from "./tree-sprites/shapes/heartwood.mjs";
17 import { drawElderCanopy } from "./tree-sprites/shapes/elder.mjs";
18
19 const SHAPES = Object.freeze({
20 [WoodTier.birch]: drawBirchCanopy,
21 [WoodTier.oak]: drawOakCanopy,
22 [WoodTier.ebony]: drawEbonyCanopy,
23 [WoodTier.lignum]: drawLignumCanopy,
24 [WoodTier.heartwood]: drawHeartwoodCanopy,
25 [WoodTier.elder]: drawElderCanopy
26 });
27
28 const requested = process.argv.slice(2);
29 const tiers = requested.length ? requested : Object.keys(SHAPES);
30
31 for (const tier of tiers)
32 {
33 const draw = SHAPES[tier];
34 if (!draw)
35 {
36 console.error(`Unknown tier: ${tier}`);
37 process.exitCode = 1;
38 continue;
39 }
40 writeTierTrees(tier, draw);
41 console.log(`Wrote ${tier}-tree (6 PNGs)`);
42 }
@@ -0,0 +1,42 @@
1#!/usr/bin/env node
2/**
3 * Generate distinct 32×48 tree sprites per wood tier (summer/fall/winter + stumps).
4 *
5 * node client/scripts/generate-tier-tree-sprites.mjs
6 * node client/scripts/generate-tier-tree-sprites.mjs birch oak
7 *
8 * Each tier shape lives in tree-sprites/shapes/{tier}.mjs — edit those for silhouette changes.
9 */
10import { WoodTier } from "../../shared/definitions/materialTiers.js";
11import { writeTierTrees } from "./tree-sprites/common.mjs";
12import { drawBirchCanopy } from "./tree-sprites/shapes/birch.mjs";
13import { drawOakCanopy } from "./tree-sprites/shapes/oak.mjs";
14import { drawEbonyCanopy } from "./tree-sprites/shapes/ebony.mjs";
15import { drawLignumCanopy } from "./tree-sprites/shapes/lignum.mjs";
16import { drawHeartwoodCanopy } from "./tree-sprites/shapes/heartwood.mjs";
17import { drawElderCanopy } from "./tree-sprites/shapes/elder.mjs";
18
19const SHAPES = Object.freeze({
20 [WoodTier.birch]: drawBirchCanopy,
21 [WoodTier.oak]: drawOakCanopy,
22 [WoodTier.ebony]: drawEbonyCanopy,
23 [WoodTier.lignum]: drawLignumCanopy,
24 [WoodTier.heartwood]: drawHeartwoodCanopy,
25 [WoodTier.elder]: drawElderCanopy
26});
27
28const requested = process.argv.slice(2);
29const tiers = requested.length ? requested : Object.keys(SHAPES);
30
31for (const tier of tiers)
32{
33 const draw = SHAPES[tier];
34 if (!draw)
35 {
36 console.error(`Unknown tier: ${tier}`);
37 process.exitCode = 1;
38 continue;
39 }
40 writeTierTrees(tier, draw);
41 console.log(`Wrote ${tier}-tree (6 PNGs)`);
42}
client/scripts/tree-sprites/common.mjs added +131 −0
@@ -0,0 +1,131 @@
1 /**
2 * Shared helpers for tier tree sprite generation (32×48 px, bottom-centred trunk).
3 * Run via: node client/scripts/generate-tier-tree-sprites.mjs [tier...]
4 */
5 import { join, dirname } from "node:path";
6 import { fileURLToPath } from "node:url";
7 import { writeRgbaPng, makeRgba, fillRect } from "../../../server/src/assets/placeholderPng.js";
8 import { MATERIAL_TINT_HEX, WoodTier } from "../../../shared/definitions/materialTiers.js";
9
10 export { fillRect };
11
12 export const TREE_W = 32;
13 export const TREE_H = 48;
14 export const ASSETS_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "blocks");
15
16 /** @typedef {"summer"|"fall"|"winter"} TreeSeason */
17
18 const TRUNK = Object.freeze([92, 58, 34, 255]);
19 const STUMP = Object.freeze([78, 48, 28, 255]);
20
21 const SEASON_FOLIAGE = Object.freeze({
22 summer: (tier) => foliageFromWood(tier, 1),
23 fall: () => [210, 110, 42, 255],
24 winter: () => [148, 158, 148, 255]
25 });
26
27 const SEASON_SNOW = Object.freeze([235, 240, 248, 255]);
28
29 function foliageFromWood (tier, strength = 1)
30 {
31 const hex = MATERIAL_TINT_HEX[tier] ?? MATERIAL_TINT_HEX[WoodTier.pine];
32 const greenBoost = 0.55 + strength * 0.35;
33 return [
34 Math.round(hex.r * 255 * 0.35 + 40 * greenBoost),
35 Math.round(hex.g * 255 * 0.55 + 90 * greenBoost),
36 Math.round(hex.b * 255 * 0.25 + 24),
37 255
38 ];
39 }
40
41 export function createTreeImage ()
42 {
43 return makeRgba(TREE_W, TREE_H, [0, 0, 0, 0]);
44 }
45
46 export function setPixel (image, x, y, rgba)
47 {
48 if (x < 0 || y < 0 || x >= image.width || y >= image.height)
49 { return; }
50 image.pixels.set(rgba, (y * image.width + x) * 4);
51 }
52
53 export function fillCircle (image, cx, cy, radius, rgba)
54 {
55 const r2 = radius * radius;
56 for (let y = Math.floor(cy - radius); y <= Math.ceil(cy + radius); y++)
57 {
58 for (let x = Math.floor(cx - radius); x <= Math.ceil(cx + radius); x++)
59 {
60 const dx = x - cx;
61 const dy = y - cy;
62 if (dx * dx + dy * dy <= r2)
63 { setPixel(image, x, y, rgba); }
64 }
65 }
66 }
67
68 export function fillEllipse (image, cx, cy, rx, ry, rgba)
69 {
70 for (let y = Math.floor(cy - ry); y <= Math.ceil(cy + ry); y++)
71 {
72 for (let x = Math.floor(cx - rx); x <= Math.ceil(cx + rx); x++)
73 {
74 const nx = (x - cx) / Math.max(1, rx);
75 const ny = (y - cy) / Math.max(1, ry);
76 if (nx * nx + ny * ny <= 1)
77 { setPixel(image, x, y, rgba); }
78 }
79 }
80 }
81
82 export function drawTrunk (image, x, y0, y1, width = 3)
83 {
84 fillRect(image, x - Math.floor(width / 2), y0, width, y1 - y0 + 1, TRUNK);
85 }
86
87 export function drawStump (image, cx = 16, topY = 38)
88 {
89 fillRect(image, cx - 4, topY, 8, 10, STUMP);
90 fillRect(image, cx - 3, topY - 1, 6, 2, [68, 42, 24, 255]);
91 }
92
93 /**
94 * @param {TreeSeason} season
95 * @param {boolean} stump
96 * @param {(image: ReturnType<typeof makeRgba>, season: TreeSeason, stump: boolean) => void} drawCanopy
97 */
98 export function renderTree (tier, season, stump, drawCanopy)
99 {
100 const image = createTreeImage();
101 const foliage = SEASON_FOLIAGE[season](tier);
102 if (stump)
103 {
104 drawStump(image);
105 writeTreePng(tier, season, stump, image);
106 return;
107 }
108 drawCanopy(image, season, stump, foliage);
109 if (season === "winter")
110 {
111 fillEllipse(image, 16, 16, 11, 7, SEASON_SNOW);
112 fillRect(image, 10, 8, 12, 3, SEASON_SNOW);
113 }
114 writeTreePng(tier, season, stump, image);
115 }
116
117 function writeTreePng (tier, season, stump, image)
118 {
119 const folder = join(ASSETS_ROOT, `${tier}-tree`);
120 const name = stump ? `${season}-stump` : season;
121 writeRgbaPng(join(folder, `${name}.png`), TREE_W, TREE_H, image.pixels);
122 }
123
124 export function writeTierTrees (tier, drawCanopy)
125 {
126 for (const season of ["summer", "fall", "winter"])
127 {
128 renderTree(tier, season, false, drawCanopy);
129 renderTree(tier, season, true, drawCanopy);
130 }
131 }
@@ -0,0 +1,131 @@
1/**
2 * Shared helpers for tier tree sprite generation (32×48 px, bottom-centred trunk).
3 * Run via: node client/scripts/generate-tier-tree-sprites.mjs [tier...]
4 */
5import { join, dirname } from "node:path";
6import { fileURLToPath } from "node:url";
7import { writeRgbaPng, makeRgba, fillRect } from "../../../server/src/assets/placeholderPng.js";
8import { MATERIAL_TINT_HEX, WoodTier } from "../../../shared/definitions/materialTiers.js";
9
10export { fillRect };
11
12export const TREE_W = 32;
13export const TREE_H = 48;
14export const ASSETS_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "blocks");
15
16/** @typedef {"summer"|"fall"|"winter"} TreeSeason */
17
18const TRUNK = Object.freeze([92, 58, 34, 255]);
19const STUMP = Object.freeze([78, 48, 28, 255]);
20
21const SEASON_FOLIAGE = Object.freeze({
22 summer: (tier) => foliageFromWood(tier, 1),
23 fall: () => [210, 110, 42, 255],
24 winter: () => [148, 158, 148, 255]
25});
26
27const SEASON_SNOW = Object.freeze([235, 240, 248, 255]);
28
29function foliageFromWood (tier, strength = 1)
30{
31 const hex = MATERIAL_TINT_HEX[tier] ?? MATERIAL_TINT_HEX[WoodTier.pine];
32 const greenBoost = 0.55 + strength * 0.35;
33 return [
34 Math.round(hex.r * 255 * 0.35 + 40 * greenBoost),
35 Math.round(hex.g * 255 * 0.55 + 90 * greenBoost),
36 Math.round(hex.b * 255 * 0.25 + 24),
37 255
38 ];
39}
40
41export function createTreeImage ()
42{
43 return makeRgba(TREE_W, TREE_H, [0, 0, 0, 0]);
44}
45
46export function setPixel (image, x, y, rgba)
47{
48 if (x < 0 || y < 0 || x >= image.width || y >= image.height)
49 { return; }
50 image.pixels.set(rgba, (y * image.width + x) * 4);
51}
52
53export function fillCircle (image, cx, cy, radius, rgba)
54{
55 const r2 = radius * radius;
56 for (let y = Math.floor(cy - radius); y <= Math.ceil(cy + radius); y++)
57 {
58 for (let x = Math.floor(cx - radius); x <= Math.ceil(cx + radius); x++)
59 {
60 const dx = x - cx;
61 const dy = y - cy;
62 if (dx * dx + dy * dy <= r2)
63 { setPixel(image, x, y, rgba); }
64 }
65 }
66}
67
68export function fillEllipse (image, cx, cy, rx, ry, rgba)
69{
70 for (let y = Math.floor(cy - ry); y <= Math.ceil(cy + ry); y++)
71 {
72 for (let x = Math.floor(cx - rx); x <= Math.ceil(cx + rx); x++)
73 {
74 const nx = (x - cx) / Math.max(1, rx);
75 const ny = (y - cy) / Math.max(1, ry);
76 if (nx * nx + ny * ny <= 1)
77 { setPixel(image, x, y, rgba); }
78 }
79 }
80}
81
82export function drawTrunk (image, x, y0, y1, width = 3)
83{
84 fillRect(image, x - Math.floor(width / 2), y0, width, y1 - y0 + 1, TRUNK);
85}
86
87export function drawStump (image, cx = 16, topY = 38)
88{
89 fillRect(image, cx - 4, topY, 8, 10, STUMP);
90 fillRect(image, cx - 3, topY - 1, 6, 2, [68, 42, 24, 255]);
91}
92
93/**
94 * @param {TreeSeason} season
95 * @param {boolean} stump
96 * @param {(image: ReturnType<typeof makeRgba>, season: TreeSeason, stump: boolean) => void} drawCanopy
97 */
98export function renderTree (tier, season, stump, drawCanopy)
99{
100 const image = createTreeImage();
101 const foliage = SEASON_FOLIAGE[season](tier);
102 if (stump)
103 {
104 drawStump(image);
105 writeTreePng(tier, season, stump, image);
106 return;
107 }
108 drawCanopy(image, season, stump, foliage);
109 if (season === "winter")
110 {
111 fillEllipse(image, 16, 16, 11, 7, SEASON_SNOW);
112 fillRect(image, 10, 8, 12, 3, SEASON_SNOW);
113 }
114 writeTreePng(tier, season, stump, image);
115}
116
117function writeTreePng (tier, season, stump, image)
118{
119 const folder = join(ASSETS_ROOT, `${tier}-tree`);
120 const name = stump ? `${season}-stump` : season;
121 writeRgbaPng(join(folder, `${name}.png`), TREE_W, TREE_H, image.pixels);
122}
123
124export function writeTierTrees (tier, drawCanopy)
125{
126 for (const season of ["summer", "fall", "winter"])
127 {
128 renderTree(tier, season, false, drawCanopy);
129 renderTree(tier, season, true, drawCanopy);
130 }
131}
client/scripts/tree-sprites/shapes/birch.mjs added +23 −0
@@ -0,0 +1,23 @@
1 import { drawTrunk, fillEllipse, fillRect, setPixel } from "../common.mjs";
2
3 const BARK = Object.freeze([210, 198, 168, 255]);
4 const BARK_STREAK = Object.freeze([238, 234, 222, 255]);
5 const BARK_MARK = Object.freeze([72, 58, 46, 255]);
6
7 /** Tall pale birch — narrow oval crown, white bark streak. */
8 export function drawBirchCanopy (image, season, stump, foliage)
9 {
10 drawTrunk(image, 16, 26, 44, 2);
11 fillRect(image, 15, 26, 2, 18, BARK);
12 fillRect(image, 15, 28, 1, 14, BARK_STREAK);
13 for (const y of [31, 35, 39])
14 {
15 setPixel(image, 15, y, BARK_MARK);
16 setPixel(image, 16, y, BARK_MARK);
17 }
18
19 fillEllipse(image, 16, 13, 5, 12, foliage);
20 fillEllipse(image, 16, 5, 3, 4, foliage);
21 fillEllipse(image, 11, 15, 2, 5, foliage);
22 fillEllipse(image, 21, 15, 2, 5, foliage);
23 }
@@ -0,0 +1,23 @@
1import { drawTrunk, fillEllipse, fillRect, setPixel } from "../common.mjs";
2
3const BARK = Object.freeze([210, 198, 168, 255]);
4const BARK_STREAK = Object.freeze([238, 234, 222, 255]);
5const BARK_MARK = Object.freeze([72, 58, 46, 255]);
6
7/** Tall pale birch — narrow oval crown, white bark streak. */
8export function drawBirchCanopy (image, season, stump, foliage)
9{
10 drawTrunk(image, 16, 26, 44, 2);
11 fillRect(image, 15, 26, 2, 18, BARK);
12 fillRect(image, 15, 28, 1, 14, BARK_STREAK);
13 for (const y of [31, 35, 39])
14 {
15 setPixel(image, 15, y, BARK_MARK);
16 setPixel(image, 16, y, BARK_MARK);
17 }
18
19 fillEllipse(image, 16, 13, 5, 12, foliage);
20 fillEllipse(image, 16, 5, 3, 4, foliage);
21 fillEllipse(image, 11, 15, 2, 5, foliage);
22 fillEllipse(image, 21, 15, 2, 5, foliage);
23}
client/scripts/tree-sprites/shapes/ebony.mjs added +23 −0
@@ -0,0 +1,23 @@
1 import { drawTrunk, fillEllipse, fillRect, setPixel } from "../common.mjs";
2
3 /** Ebony — flat umbrella crown, slender dark trunk. */
4 export function drawEbonyCanopy (image, season, stump, foliage)
5 {
6 const shade = [
7 Math.max(0, foliage[0] - 32),
8 Math.max(0, foliage[1] - 32),
9 Math.max(0, foliage[2] - 24),
10 255
11 ];
12
13 drawTrunk(image, 16, 28, 44, 2);
14
15 fillRect(image, 3, 11, 26, 2, foliage);
16 fillEllipse(image, 16, 14, 15, 4, foliage);
17 fillEllipse(image, 16, 16, 14, 2, foliage);
18
19 fillEllipse(image, 16, 12, 7, 2, foliage);
20 setPixel(image, 2, 15, foliage);
21 setPixel(image, 29, 15, foliage);
22 fillRect(image, 4, 16, 24, 1, shade);
23 }
@@ -0,0 +1,23 @@
1import { drawTrunk, fillEllipse, fillRect, setPixel } from "../common.mjs";
2
3/** Ebony — flat umbrella crown, slender dark trunk. */
4export function drawEbonyCanopy (image, season, stump, foliage)
5{
6 const shade = [
7 Math.max(0, foliage[0] - 32),
8 Math.max(0, foliage[1] - 32),
9 Math.max(0, foliage[2] - 24),
10 255
11 ];
12
13 drawTrunk(image, 16, 28, 44, 2);
14
15 fillRect(image, 3, 11, 26, 2, foliage);
16 fillEllipse(image, 16, 14, 15, 4, foliage);
17 fillEllipse(image, 16, 16, 14, 2, foliage);
18
19 fillEllipse(image, 16, 12, 7, 2, foliage);
20 setPixel(image, 2, 15, foliage);
21 setPixel(image, 29, 15, foliage);
22 fillRect(image, 4, 16, 24, 1, shade);
23}
client/scripts/tree-sprites/shapes/elder.mjs added +71 −0
@@ -0,0 +1,71 @@
1 import { drawTrunk, fillCircle, fillEllipse, setPixel } from "../common.mjs";
2
3 const BARK = Object.freeze([68, 44, 28, 255]);
4 const BARK_SHADOW = Object.freeze([48, 30, 20, 255]);
5
6 function mysticGlow (foliage)
7 {
8 return [
9 Math.min(255, foliage[0] + 36),
10 Math.min(255, foliage[1] + 48),
11 Math.min(255, foliage[2] + 28),
12 255
13 ];
14 }
15
16 function drawLine (image, x0, y0, x1, y1, rgba)
17 {
18 const steps = Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0), 1);
19 for (let i = 0; i <= steps; i++)
20 {
21 const t = i / steps;
22 setPixel(image, Math.round(x0 + (x1 - x0) * t), Math.round(y0 + (y1 - y0) * t), rgba);
23 }
24 }
25
26 function drawGnarledBranch (image, points, rgba = BARK)
27 {
28 for (let i = 0; i < points.length - 1; i++)
29 {
30 const [x0, y0] = points[i];
31 const [x1, y1] = points[i + 1];
32 drawLine(image, x0, y0, x1, y1, rgba);
33 if (i > 0 && i < points.length - 1)
34 { setPixel(image, x0, y0, BARK_SHADOW); }
35 }
36 }
37
38 function leafCluster (image, x, y, foliage, radius = 2)
39 {
40 fillCircle(image, x, y, radius, foliage);
41 fillCircle(image, x, y, Math.max(1, radius - 1), mysticGlow(foliage));
42 }
43
44 /** Elder — gnarled sparse branches, small clusters, mystical ancient silhouette. */
45 export function drawElderCanopy (image, season, stump, foliage)
46 {
47 drawTrunk(image, 16, 34, 44, 3);
48 drawTrunk(image, 15, 28, 35, 2);
49 setPixel(image, 17, 30, BARK_SHADOW);
50 setPixel(image, 14, 33, BARK_SHADOW);
51
52 drawGnarledBranch(image, [[16, 30], [14, 26], [11, 21], [9, 16], [7, 11]]);
53 drawGnarledBranch(image, [[16, 29], [18, 24], [21, 19], [23, 14], [25, 9]]);
54 drawGnarledBranch(image, [[15, 32], [10, 28], [7, 23], [5, 18], [4, 13]]);
55 drawGnarledBranch(image, [[17, 31], [22, 27], [26, 22], [28, 17], [29, 12]]);
56 drawGnarledBranch(image, [[16, 28], [16, 22], [15, 16], [16, 10], [16, 6]]);
57
58 drawGnarledBranch(image, [[11, 21], [13, 19], [15, 17]], BARK_SHADOW);
59 drawGnarledBranch(image, [[21, 19], [19, 17], [17, 15]], BARK_SHADOW);
60
61 leafCluster(image, 7, 11, foliage, 2);
62 leafCluster(image, 25, 9, foliage, 2);
63 leafCluster(image, 4, 13, foliage, 2);
64 leafCluster(image, 29, 12, foliage, 2);
65 leafCluster(image, 16, 6, foliage, 3);
66 leafCluster(image, 15, 17, foliage, 2);
67 leafCluster(image, 17, 15, foliage, 2);
68 leafCluster(image, 9, 16, foliage, 2);
69
70 fillEllipse(image, 16, 4, 2, 1, mysticGlow(foliage));
71 }
@@ -0,0 +1,71 @@
1import { drawTrunk, fillCircle, fillEllipse, setPixel } from "../common.mjs";
2
3const BARK = Object.freeze([68, 44, 28, 255]);
4const BARK_SHADOW = Object.freeze([48, 30, 20, 255]);
5
6function mysticGlow (foliage)
7{
8 return [
9 Math.min(255, foliage[0] + 36),
10 Math.min(255, foliage[1] + 48),
11 Math.min(255, foliage[2] + 28),
12 255
13 ];
14}
15
16function drawLine (image, x0, y0, x1, y1, rgba)
17{
18 const steps = Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0), 1);
19 for (let i = 0; i <= steps; i++)
20 {
21 const t = i / steps;
22 setPixel(image, Math.round(x0 + (x1 - x0) * t), Math.round(y0 + (y1 - y0) * t), rgba);
23 }
24}
25
26function drawGnarledBranch (image, points, rgba = BARK)
27{
28 for (let i = 0; i < points.length - 1; i++)
29 {
30 const [x0, y0] = points[i];
31 const [x1, y1] = points[i + 1];
32 drawLine(image, x0, y0, x1, y1, rgba);
33 if (i > 0 && i < points.length - 1)
34 { setPixel(image, x0, y0, BARK_SHADOW); }
35 }
36}
37
38function leafCluster (image, x, y, foliage, radius = 2)
39{
40 fillCircle(image, x, y, radius, foliage);
41 fillCircle(image, x, y, Math.max(1, radius - 1), mysticGlow(foliage));
42}
43
44/** Elder — gnarled sparse branches, small clusters, mystical ancient silhouette. */
45export function drawElderCanopy (image, season, stump, foliage)
46{
47 drawTrunk(image, 16, 34, 44, 3);
48 drawTrunk(image, 15, 28, 35, 2);
49 setPixel(image, 17, 30, BARK_SHADOW);
50 setPixel(image, 14, 33, BARK_SHADOW);
51
52 drawGnarledBranch(image, [[16, 30], [14, 26], [11, 21], [9, 16], [7, 11]]);
53 drawGnarledBranch(image, [[16, 29], [18, 24], [21, 19], [23, 14], [25, 9]]);
54 drawGnarledBranch(image, [[15, 32], [10, 28], [7, 23], [5, 18], [4, 13]]);
55 drawGnarledBranch(image, [[17, 31], [22, 27], [26, 22], [28, 17], [29, 12]]);
56 drawGnarledBranch(image, [[16, 28], [16, 22], [15, 16], [16, 10], [16, 6]]);
57
58 drawGnarledBranch(image, [[11, 21], [13, 19], [15, 17]], BARK_SHADOW);
59 drawGnarledBranch(image, [[21, 19], [19, 17], [17, 15]], BARK_SHADOW);
60
61 leafCluster(image, 7, 11, foliage, 2);
62 leafCluster(image, 25, 9, foliage, 2);
63 leafCluster(image, 4, 13, foliage, 2);
64 leafCluster(image, 29, 12, foliage, 2);
65 leafCluster(image, 16, 6, foliage, 3);
66 leafCluster(image, 15, 17, foliage, 2);
67 leafCluster(image, 17, 15, foliage, 2);
68 leafCluster(image, 9, 16, foliage, 2);
69
70 fillEllipse(image, 16, 4, 2, 1, mysticGlow(foliage));
71}
client/scripts/tree-sprites/shapes/heartwood.mjs added +12 −0
@@ -0,0 +1,12 @@
1 import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";
2
3 /** Heartwood — twin-lobed heart-shaped crown. */
4 export function drawHeartwoodCanopy (image, season, stump, foliage)
5 {
6 drawTrunk(image, 16, 33, 44, 3);
7 fillCircle(image, 8, 14, 7, foliage);
8 fillCircle(image, 24, 14, 7, foliage);
9 fillEllipse(image, 16, 21, 10, 6, foliage);
10 fillEllipse(image, 16, 26, 6, 5, foliage);
11 fillCircle(image, 16, 30, 2, foliage);
12 }
@@ -0,0 +1,12 @@
1import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";
2
3/** Heartwood — twin-lobed heart-shaped crown. */
4export function drawHeartwoodCanopy (image, season, stump, foliage)
5{
6 drawTrunk(image, 16, 33, 44, 3);
7 fillCircle(image, 8, 14, 7, foliage);
8 fillCircle(image, 24, 14, 7, foliage);
9 fillEllipse(image, 16, 21, 10, 6, foliage);
10 fillEllipse(image, 16, 26, 6, 5, foliage);
11 fillCircle(image, 16, 30, 2, foliage);
12}
client/scripts/tree-sprites/shapes/lignum.mjs added +14 −0
@@ -0,0 +1,14 @@
1 import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";
2
3 /** Lignum — irregular layered canopy, slightly leaning. */
4 export function drawLignumCanopy (image, season, stump, foliage)
5 {
6 drawTrunk(image, 17, 31, 44, 3);
7 fillEllipse(image, 11, 25, 9, 6, foliage);
8 fillEllipse(image, 19, 27, 7, 5, foliage);
9 fillEllipse(image, 21, 20, 8, 7, foliage);
10 fillEllipse(image, 13, 21, 6, 5, foliage);
11 fillCircle(image, 9, 17, 4, foliage);
12 fillCircle(image, 20, 15, 5, foliage);
13 fillCircle(image, 15, 11, 3, foliage);
14 }
@@ -0,0 +1,14 @@
1import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";
2
3/** Lignum — irregular layered canopy, slightly leaning. */
4export function drawLignumCanopy (image, season, stump, foliage)
5{
6 drawTrunk(image, 17, 31, 44, 3);
7 fillEllipse(image, 11, 25, 9, 6, foliage);
8 fillEllipse(image, 19, 27, 7, 5, foliage);
9 fillEllipse(image, 21, 20, 8, 7, foliage);
10 fillEllipse(image, 13, 21, 6, 5, foliage);
11 fillCircle(image, 9, 17, 4, foliage);
12 fillCircle(image, 20, 15, 5, foliage);
13 fillCircle(image, 15, 11, 3, foliage);
14}
client/scripts/tree-sprites/shapes/oak.mjs added +13 −0
@@ -0,0 +1,13 @@
1 import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";
2
3 /** Broad round oak — wide low canopy, thick trunk. */
4 export function drawOakCanopy (image, season, stump, foliage)
5 {
6 drawTrunk(image, 16, 36, 44, 5);
7 fillEllipse(image, 16, 23, 14, 10, foliage);
8 fillCircle(image, 8, 22, 5, foliage);
9 fillCircle(image, 24, 22, 5, foliage);
10 fillCircle(image, 16, 15, 7, foliage);
11 fillCircle(image, 11, 18, 5, foliage);
12 fillCircle(image, 21, 18, 5, foliage);
13 }
@@ -0,0 +1,13 @@
1import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";
2
3/** Broad round oak — wide low canopy, thick trunk. */
4export function drawOakCanopy (image, season, stump, foliage)
5{
6 drawTrunk(image, 16, 36, 44, 5);
7 fillEllipse(image, 16, 23, 14, 10, foliage);
8 fillCircle(image, 8, 22, 5, foliage);
9 fillCircle(image, 24, 22, 5, foliage);
10 fillCircle(image, 16, 15, 7, foliage);
11 fillCircle(image, 11, 18, 5, foliage);
12 fillCircle(image, 21, 18, 5, foliage);
13}
client/scripts/write-arrow-projectile-template.mjs added +40 −0
@@ -0,0 +1,40 @@
1 #!/usr/bin/env node
2 /**
3 * Dual-channel arrow projectile template for client/assets/fx/projectile/arrow.png
4 *
5 * Channel convention (same as items/arrow/full-arrow.png):
6 * - Dominant RED → shaft mask (lightness = R); tinted with wood tier at runtime
7 * - Dominant BLUE → tip mask (lightness = B); tinted with metal tier at runtime
8 * - Neutral WHITE → fletching / bindings; left unchanged
9 *
10 * Regenerate after hand-editing the layout:
11 * node client/scripts/write-arrow-projectile-template.mjs
12 *
13 * Runtime: WorldView.spawnPhysicalProjectileFx uses DUAL_TINT_LIT_SPRITE shader when
14 * combat-projectile carries shaftTint + tipTint from the server.
15 */
16 import { join, dirname } from "node:path";
17 import { fileURLToPath } from "node:url";
18 import { writeRgbaPng, makeRgba, fillRect } from "../../server/src/assets/placeholderPng.js";
19
20 const W = 24;
21 const H = 8;
22 const out = join(dirname(fileURLToPath(import.meta.url)), "..", "assets", "fx", "projectile", "arrow.png");
23
24 const image = makeRgba(W, H, [0, 0, 0, 0]);
25
26 // Shaft — pure red channel (wood tint applied in shader)
27 for (let x = 4; x < 16; x++)
28 { fillRect(image, x, 3, 1, 2, [220, 0, 0, 255]); }
29
30 // Tip — pure blue channel (metal tint applied in shader)
31 fillRect(image, 16, 2, 4, 4, [0, 0, 220, 255]);
32 fillRect(image, 20, 3, 2, 2, [0, 0, 255, 255]);
33
34 // Fletching — white, untouched by dual tint
35 fillRect(image, 0, 2, 3, 4, [245, 245, 245, 255]);
36 fillRect(image, 1, 1, 2, 1, [255, 255, 255, 255]);
37 fillRect(image, 1, 6, 2, 1, [255, 255, 255, 255]);
38
39 writeRgbaPng(out, W, H, image.pixels);
40 console.log(`Wrote dual-channel projectile template: ${out} (${W}×${H})`);
@@ -0,0 +1,40 @@
1#!/usr/bin/env node
2/**
3 * Dual-channel arrow projectile template for client/assets/fx/projectile/arrow.png
4 *
5 * Channel convention (same as items/arrow/full-arrow.png):
6 * - Dominant RED → shaft mask (lightness = R); tinted with wood tier at runtime
7 * - Dominant BLUE → tip mask (lightness = B); tinted with metal tier at runtime
8 * - Neutral WHITE → fletching / bindings; left unchanged
9 *
10 * Regenerate after hand-editing the layout:
11 * node client/scripts/write-arrow-projectile-template.mjs
12 *
13 * Runtime: WorldView.spawnPhysicalProjectileFx uses DUAL_TINT_LIT_SPRITE shader when
14 * combat-projectile carries shaftTint + tipTint from the server.
15 */
16import { join, dirname } from "node:path";
17import { fileURLToPath } from "node:url";
18import { writeRgbaPng, makeRgba, fillRect } from "../../server/src/assets/placeholderPng.js";
19
20const W = 24;
21const H = 8;
22const out = join(dirname(fileURLToPath(import.meta.url)), "..", "assets", "fx", "projectile", "arrow.png");
23
24const image = makeRgba(W, H, [0, 0, 0, 0]);
25
26// Shaft — pure red channel (wood tint applied in shader)
27for (let x = 4; x < 16; x++)
28{ fillRect(image, x, 3, 1, 2, [220, 0, 0, 255]); }
29
30// Tip — pure blue channel (metal tint applied in shader)
31fillRect(image, 16, 2, 4, 4, [0, 0, 220, 255]);
32fillRect(image, 20, 3, 2, 2, [0, 0, 255, 255]);
33
34// Fletching — white, untouched by dual tint
35fillRect(image, 0, 2, 3, 4, [245, 245, 245, 255]);
36fillRect(image, 1, 1, 2, 1, [255, 255, 255, 255]);
37fillRect(image, 1, 6, 2, 1, [255, 255, 255, 255]);
38
39writeRgbaPng(out, W, H, image.pixels);
40console.log(`Wrote dual-channel projectile template: ${out} (${W}×${H})`);
client/src/render/potionIcon.js +38 −2
@@ -2,8 +2,10 @@ import { ItemId, itemDefinition, itemAssetPathForStack } from "/shared/definitio
2 2 import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
3 3 import {
4 4 applyMagentaTintToImageData,
5 applyDualChannelTintToImageData,
5 6 normalizeRgb,
6 resolveItemTint
7 resolveItemTint,
8 resolveItemDualTint
7 9 } from "/shared/render/tint.js";
8 10
9 11 const bottleCache = new Map();
@@ -97,6 +99,27 @@ export async function tintedItemIconDataUrl (assetPath, tint)
97 99 return url;
98 100 }
99 101
102 /** Dual-channel arrow icon (red shaft + blue tip masks). */
103 export async function dualTintedItemIconDataUrl (assetPath, dualTint)
104 {
105 const key = `dual|${assetPath}|${colorKey(dualTint.shaft)}|${colorKey(dualTint.tip)}`;
106 if (urlCache.has(key))
107 { return urlCache.get(key); }
108 const img = await loadImage(assetPath);
109 const canvas = document.createElement("canvas");
110 canvas.width = img.width || SPRITE_SIZE_PX;
111 canvas.height = img.height || SPRITE_SIZE_PX;
112 const ctx = canvas.getContext("2d");
113 ctx.clearRect(0, 0, canvas.width, canvas.height);
114 ctx.drawImage(img, 0, 0);
115 const image = ctx.getImageData(0, 0, canvas.width, canvas.height);
116 applyDualChannelTintToImageData(image, dualTint);
117 ctx.putImageData(image, 0, 0);
118 const url = canvas.toDataURL("image/png");
119 urlCache.set(key, url);
120 return url;
121 }
122
100 123 export function isPotionStack (stack)
101 124 {
102 125 return (stack?.itemId === ItemId.potion && stack.instance?.kind === "potion")
@@ -109,7 +132,20 @@ export function applyItemIcon (img, stack, fallbackPath)
109 132 if (!img)
110 133 { return; }
111 134 img.src = fallbackPath;
112 const tint = resolveItemTint(stack, itemDefinition(stack?.itemId));
135 const def = itemDefinition(stack?.itemId);
136 const dualTint = resolveItemDualTint(stack, def);
137 if (dualTint)
138 {
139 dualTintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), dualTint).then((url) =>
140 {
141 img.src = url;
142 }).catch(() =>
143 {
144 img.src = fallbackPath;
145 });
146 return;
147 }
148 const tint = resolveItemTint(stack, def);
113 149 if (!tint)
114 150 { return; }
115 151 const work = isPotionStack(stack)
@@ -2,8 +2,10 @@ import { ItemId, itemDefinition, itemAssetPathForStack } from "/shared/definitio
2import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
2import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
3import {
3import {
4 applyMagentaTintToImageData,
4 applyMagentaTintToImageData,
5 applyDualChannelTintToImageData,
5 normalizeRgb,
6 normalizeRgb,
6 resolveItemTint
7 resolveItemTint,
8 resolveItemDualTint
7} from "/shared/render/tint.js";
9} from "/shared/render/tint.js";
8
10
9const bottleCache = new Map();
11const bottleCache = new Map();
@@ -97,6 +99,27 @@ export async function tintedItemIconDataUrl (assetPath, tint)
97 return url;
99 return url;
98}
100}
99
101
102/** Dual-channel arrow icon (red shaft + blue tip masks). */
103export async function dualTintedItemIconDataUrl (assetPath, dualTint)
104{
105 const key = `dual|${assetPath}|${colorKey(dualTint.shaft)}|${colorKey(dualTint.tip)}`;
106 if (urlCache.has(key))
107 { return urlCache.get(key); }
108 const img = await loadImage(assetPath);
109 const canvas = document.createElement("canvas");
110 canvas.width = img.width || SPRITE_SIZE_PX;
111 canvas.height = img.height || SPRITE_SIZE_PX;
112 const ctx = canvas.getContext("2d");
113 ctx.clearRect(0, 0, canvas.width, canvas.height);
114 ctx.drawImage(img, 0, 0);
115 const image = ctx.getImageData(0, 0, canvas.width, canvas.height);
116 applyDualChannelTintToImageData(image, dualTint);
117 ctx.putImageData(image, 0, 0);
118 const url = canvas.toDataURL("image/png");
119 urlCache.set(key, url);
120 return url;
121}
122
100export function isPotionStack (stack)
123export function isPotionStack (stack)
101{
124{
102 return (stack?.itemId === ItemId.potion && stack.instance?.kind === "potion")
125 return (stack?.itemId === ItemId.potion && stack.instance?.kind === "potion")
@@ -109,7 +132,20 @@ export function applyItemIcon (img, stack, fallbackPath)
109 if (!img)
132 if (!img)
110 { return; }
133 { return; }
111 img.src = fallbackPath;
134 img.src = fallbackPath;
112 const tint = resolveItemTint(stack, itemDefinition(stack?.itemId));
135 const def = itemDefinition(stack?.itemId);
136 const dualTint = resolveItemDualTint(stack, def);
137 if (dualTint)
138 {
139 dualTintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), dualTint).then((url) =>
140 {
141 img.src = url;
142 }).catch(() =>
143 {
144 img.src = fallbackPath;
145 });
146 return;
147 }
148 const tint = resolveItemTint(stack, def);
113 if (!tint)
149 if (!tint)
114 { return; }
150 { return; }
115 const work = isPotionStack(stack)
151 const work = isPotionStack(stack)
client/src/render/worldView.js +103 −7
@@ -3,7 +3,7 @@ import { dynamicLightAtTile, lightIntensity } from "/shared/lighting/raycast.js"
3 3 import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
4 4 import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
5 5 import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
6 import { resolveItemTint, resolveEquipTint, normalizeRgb } from "/shared/render/tint.js";
6 import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";
7 7 import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight } from "/shared/definitions/tiles.js";
8 8 import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";
9 9 import { bakeChunkAtlases } from "./chunkBake.js";
@@ -135,6 +135,48 @@ const TINT_LIT_SPRITE_FRAG = [
135 135 "}"
136 136 ].join("\n");
137 137
138 /** Dual-channel arrow tint: red = shaft, blue = tip, white unchanged; then darkness. */
139 const DUAL_TINT_LIT_SPRITE_FRAG = [
140 "precision mediump float;",
141 "varying vec2 v_texCoord;",
142 "uniform sampler2D u_texture;",
143 "uniform float u_darkness;",
144 "uniform float u_strength;",
145 "uniform float u_wade;",
146 "uniform float u_spriteHeight;",
147 "uniform vec3 u_shaftTint;",
148 "uniform vec3 u_tipTint;",
149 "void main() {",
150 " vec4 color = texture2D(u_texture, v_texCoord);",
151 " if (color.a <= 0.0) { discard; }",
152 " float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);",
153 " if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
154 " vec3 rgb = color.rgb;",
155 " float tipMask = clamp((color.b - max(color.r, color.g)) * 1.75, 0.0, 1.0);",
156 " if (tipMask > 0.0) {",
157 " float L = color.b;",
158 " float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;",
159 " float tipLuma = dot(u_tipTint, vec3(0.2126, 0.7152, 0.0722));",
160 " vec3 tipCol = mix(u_tipTint, vec3(tipLuma), gBlend) * L;",
161 " rgb = mix(rgb, tipCol, tipMask);",
162 " }",
163 " float shaftMask = clamp((color.r - max(color.g, color.b)) * 1.75, 0.0, 1.0);",
164 " if (shaftMask > 0.0) {",
165 " float L = color.r;",
166 " float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;",
167 " float shaftLuma = dot(u_shaftTint, vec3(0.2126, 0.7152, 0.0722));",
168 " vec3 shaftCol = mix(u_shaftTint, vec3(shaftLuma), gBlend) * L;",
169 " rgb = mix(rgb, shaftCol, shaftMask);",
170 " }",
171 " if (u_wade > 0.5 && fromBottom < 5.0) {",
172 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
173 " }",
174 " rgb = mix(rgb, vec3(0.0), u_darkness);",
175 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
176 " gl_FragColor = vec4(rgb, color.a);",
177 "}"
178 ].join("\n");
179
138 180 const ATLAS_LIGHTING_FRAG = [
139 181 "precision mediump float;",
140 182 "varying vec2 v_texCoord;",
@@ -160,6 +202,7 @@ let spriteLightingShader = null;
160 202 let atlasLightingShader = null;
161 203 let waterGroundShader = null;
162 204 let tintLitSpriteShader = null;
205 let dualTintLitSpriteShader = null;
163 206
164 207 function getSpriteLightingShader ()
165 208 {
@@ -189,6 +232,13 @@ function getTintLitSpriteShader ()
189 232 return tintLitSpriteShader;
190 233 }
191 234
235 function getDualTintLitSpriteShader ()
236 {
237 if (!dualTintLitSpriteShader)
238 { dualTintLitSpriteShader = Shader.fragment(DUAL_TINT_LIT_SPRITE_FRAG); }
239 return dualTintLitSpriteShader;
240 }
241
192 242 export class WorldView
193 243 {
194 244 constructor (game, scene, catalog = { grounds: {}, blocks: {} })
@@ -517,7 +567,8 @@ export class WorldView
517 567 item.sprite = spriteName;
518 568 item.instance = payload.instance ?? null;
519 569 const stack = { itemId: payload.itemId, instance: payload.instance ?? null };
520 item.tintColor = resolveItemTint(stack, itemDefinition(payload.itemId));
570 item.dualTint = resolveItemDualTint(stack, itemDefinition(payload.itemId));
571 item.tintColor = item.dualTint ? null : resolveItemTint(stack, itemDefinition(payload.itemId));
521 572 this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK);
522 573 this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0);
523 574 }
@@ -860,6 +911,7 @@ export class WorldView
860 911 const image = this.game.images[spriteName];
861 912 if (!image)
862 913 { return; }
914 const dualTint = this.#dualTintFromPayload(payload);
863 915 const fromPivot = tilePivot(payload.fromTileX, payload.fromTileY, this.tileSize());
864 916 const toPivot = tilePivot(payload.tileX, payload.tileY, this.tileSize());
865 917 const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02;
@@ -874,7 +926,8 @@ export class WorldView
874 926 payload.fromTileX,
875 927 payload.fromTileY,
876 928 payload.tileX,
877 payload.tileY
929 payload.tileY,
930 dualTint
878 931 );
879 932 const started = performance.now();
880 933 const durationMs = payload.durationMs ?? 400;
@@ -884,6 +937,7 @@ export class WorldView
884 937 started,
885 938 durationMs,
886 939 lerp: true,
940 dualTint,
887 941 fromTileX: payload.fromTileX,
888 942 fromTileY: payload.fromTileY,
889 943 tileX: payload.tileX,
@@ -1414,8 +1468,35 @@ export class WorldView
1414 1468 object.renderer.secondaryMap = null;
1415 1469 }
1416 1470
1471 #syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false)
1472 {
1473 if (!object?.renderer || object._lit === false || !dualTint)
1474 { return; }
1475 object._lit = true;
1476 const shaft = normalizeRgb(dualTint.shaft);
1477 const tip = normalizeRgb(dualTint.tip);
1478 const dark = Math.min(1, Math.max(0, darkness ?? 0));
1479 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
1480 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
1481 object.renderer.shader = getDualTintLitSpriteShader();
1482 object.renderer.shaderUniforms = {
1483 u_darkness: dark,
1484 u_strength: flash,
1485 u_wade: wade ? 1 : 0,
1486 u_spriteHeight: height,
1487 u_shaftTint: [shaft.r, shaft.g, shaft.b],
1488 u_tipTint: [tip.r, tip.g, tip.b]
1489 };
1490 object.renderer.secondaryMap = null;
1491 }
1492
1417 1493 #syncGroundItemSprite (item, darkness)
1418 1494 {
1495 if (item?.dualTint)
1496 {
1497 this.#syncDualTintLitSprite(item.object, darkness, item.dualTint);
1498 return;
1499 }
1419 1500 this.#syncLitSprite(item?.object, darkness, 0, false, item?.tintColor ?? null);
1420 1501 }
1421 1502
@@ -1544,11 +1625,24 @@ export class WorldView
1544 1625 };
1545 1626 }
1546 1627
1547 #applyPhysicalCombatFxDarkness (object, fromTileX, fromTileY, tileX, tileY)
1628 #applyPhysicalCombatFxDarkness (object, fromTileX, fromTileY, tileX, tileY, dualTint = null)
1548 1629 {
1549 1630 const fromAlpha = this.tiles.get(`${fromTileX},${fromTileY}`)?.shadeAlpha ?? 0;
1550 1631 const toAlpha = this.tiles.get(`${tileX},${tileY}`)?.shadeAlpha ?? 0;
1551 this.#syncLitSprite(object, (fromAlpha + toAlpha) / 2);
1632 const dark = (fromAlpha + toAlpha) / 2;
1633 if (dualTint)
1634 {
1635 this.#syncDualTintLitSprite(object, dark, dualTint);
1636 return;
1637 }
1638 this.#syncLitSprite(object, dark);
1639 }
1640
1641 #dualTintFromPayload (payload)
1642 {
1643 if (!payload?.shaftTint || !payload?.tipTint)
1644 { return null; }
1645 return { shaft: payload.shaftTint, tip: payload.tipTint };
1552 1646 }
1553 1647
1554 1648 #syncHpBar (entity)
@@ -2324,7 +2418,8 @@ export class WorldView
2324 2418 swipe.fromTileX,
2325 2419 swipe.fromTileY,
2326 2420 swipe.tileX,
2327 swipe.tileY
2421 swipe.tileY,
2422 swipe.dualTint ?? null
2328 2423 );
2329 2424 }
2330 2425 else if (swipe.fromTileX != null)
@@ -2334,7 +2429,8 @@ export class WorldView
2334 2429 swipe.fromTileX,
2335 2430 swipe.fromTileY,
2336 2431 swipe.tileX,
2337 swipe.tileY
2432 swipe.tileY,
2433 swipe.dualTint ?? null
2338 2434 );
2339 2435 }
2340 2436 if (swipe.until > now)
@@ -3,7 +3,7 @@ import { dynamicLightAtTile, lightIntensity } from "/shared/lighting/raycast.js"
3import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
3import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
4import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
4import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
5import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
5import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
6import { resolveItemTint, resolveEquipTint, normalizeRgb } from "/shared/render/tint.js";
6import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";
7import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight } from "/shared/definitions/tiles.js";
7import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight } from "/shared/definitions/tiles.js";
8import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";
8import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";
9import { bakeChunkAtlases } from "./chunkBake.js";
9import { bakeChunkAtlases } from "./chunkBake.js";
@@ -135,6 +135,48 @@ const TINT_LIT_SPRITE_FRAG = [
135 "}"
135 "}"
136].join("\n");
136].join("\n");
137
137
138/** Dual-channel arrow tint: red = shaft, blue = tip, white unchanged; then darkness. */
139const DUAL_TINT_LIT_SPRITE_FRAG = [
140 "precision mediump float;",
141 "varying vec2 v_texCoord;",
142 "uniform sampler2D u_texture;",
143 "uniform float u_darkness;",
144 "uniform float u_strength;",
145 "uniform float u_wade;",
146 "uniform float u_spriteHeight;",
147 "uniform vec3 u_shaftTint;",
148 "uniform vec3 u_tipTint;",
149 "void main() {",
150 " vec4 color = texture2D(u_texture, v_texCoord);",
151 " if (color.a <= 0.0) { discard; }",
152 " float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);",
153 " if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
154 " vec3 rgb = color.rgb;",
155 " float tipMask = clamp((color.b - max(color.r, color.g)) * 1.75, 0.0, 1.0);",
156 " if (tipMask > 0.0) {",
157 " float L = color.b;",
158 " float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;",
159 " float tipLuma = dot(u_tipTint, vec3(0.2126, 0.7152, 0.0722));",
160 " vec3 tipCol = mix(u_tipTint, vec3(tipLuma), gBlend) * L;",
161 " rgb = mix(rgb, tipCol, tipMask);",
162 " }",
163 " float shaftMask = clamp((color.r - max(color.g, color.b)) * 1.75, 0.0, 1.0);",
164 " if (shaftMask > 0.0) {",
165 " float L = color.r;",
166 " float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;",
167 " float shaftLuma = dot(u_shaftTint, vec3(0.2126, 0.7152, 0.0722));",
168 " vec3 shaftCol = mix(u_shaftTint, vec3(shaftLuma), gBlend) * L;",
169 " rgb = mix(rgb, shaftCol, shaftMask);",
170 " }",
171 " if (u_wade > 0.5 && fromBottom < 5.0) {",
172 " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
173 " }",
174 " rgb = mix(rgb, vec3(0.0), u_darkness);",
175 " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
176 " gl_FragColor = vec4(rgb, color.a);",
177 "}"
178].join("\n");
179
138const ATLAS_LIGHTING_FRAG = [
180const ATLAS_LIGHTING_FRAG = [
139 "precision mediump float;",
181 "precision mediump float;",
140 "varying vec2 v_texCoord;",
182 "varying vec2 v_texCoord;",
@@ -160,6 +202,7 @@ let spriteLightingShader = null;
160let atlasLightingShader = null;
202let atlasLightingShader = null;
161let waterGroundShader = null;
203let waterGroundShader = null;
162let tintLitSpriteShader = null;
204let tintLitSpriteShader = null;
205let dualTintLitSpriteShader = null;
163
206
164function getSpriteLightingShader ()
207function getSpriteLightingShader ()
165{
208{
@@ -189,6 +232,13 @@ function getTintLitSpriteShader ()
189 return tintLitSpriteShader;
232 return tintLitSpriteShader;
190}
233}
191
234
235function getDualTintLitSpriteShader ()
236{
237 if (!dualTintLitSpriteShader)
238 { dualTintLitSpriteShader = Shader.fragment(DUAL_TINT_LIT_SPRITE_FRAG); }
239 return dualTintLitSpriteShader;
240}
241
192export class WorldView
242export class WorldView
193{
243{
194 constructor (game, scene, catalog = { grounds: {}, blocks: {} })
244 constructor (game, scene, catalog = { grounds: {}, blocks: {} })
@@ -517,7 +567,8 @@ export class WorldView
517 item.sprite = spriteName;
567 item.sprite = spriteName;
518 item.instance = payload.instance ?? null;
568 item.instance = payload.instance ?? null;
519 const stack = { itemId: payload.itemId, instance: payload.instance ?? null };
569 const stack = { itemId: payload.itemId, instance: payload.instance ?? null };
520 item.tintColor = resolveItemTint(stack, itemDefinition(payload.itemId));
570 item.dualTint = resolveItemDualTint(stack, itemDefinition(payload.itemId));
571 item.tintColor = item.dualTint ? null : resolveItemTint(stack, itemDefinition(payload.itemId));
521 this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK);
572 this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK);
522 this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0);
573 this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0);
523 }
574 }
@@ -860,6 +911,7 @@ export class WorldView
860 const image = this.game.images[spriteName];
911 const image = this.game.images[spriteName];
861 if (!image)
912 if (!image)
862 { return; }
913 { return; }
914 const dualTint = this.#dualTintFromPayload(payload);
863 const fromPivot = tilePivot(payload.fromTileX, payload.fromTileY, this.tileSize());
915 const fromPivot = tilePivot(payload.fromTileX, payload.fromTileY, this.tileSize());
864 const toPivot = tilePivot(payload.tileX, payload.tileY, this.tileSize());
916 const toPivot = tilePivot(payload.tileX, payload.tileY, this.tileSize());
865 const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02;
917 const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02;
@@ -874,7 +926,8 @@ export class WorldView
874 payload.fromTileX,
926 payload.fromTileX,
875 payload.fromTileY,
927 payload.fromTileY,
876 payload.tileX,
928 payload.tileX,
877 payload.tileY
929 payload.tileY,
930 dualTint
878 );
931 );
879 const started = performance.now();
932 const started = performance.now();
880 const durationMs = payload.durationMs ?? 400;
933 const durationMs = payload.durationMs ?? 400;
@@ -884,6 +937,7 @@ export class WorldView
884 started,
937 started,
885 durationMs,
938 durationMs,
886 lerp: true,
939 lerp: true,
940 dualTint,
887 fromTileX: payload.fromTileX,
941 fromTileX: payload.fromTileX,
888 fromTileY: payload.fromTileY,
942 fromTileY: payload.fromTileY,
889 tileX: payload.tileX,
943 tileX: payload.tileX,
@@ -1414,8 +1468,35 @@ export class WorldView
1414 object.renderer.secondaryMap = null;
1468 object.renderer.secondaryMap = null;
1415 }
1469 }
1416
1470
1471 #syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false)
1472 {
1473 if (!object?.renderer || object._lit === false || !dualTint)
1474 { return; }
1475 object._lit = true;
1476 const shaft = normalizeRgb(dualTint.shaft);
1477 const tip = normalizeRgb(dualTint.tip);
1478 const dark = Math.min(1, Math.max(0, darkness ?? 0));
1479 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
1480 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
1481 object.renderer.shader = getDualTintLitSpriteShader();
1482 object.renderer.shaderUniforms = {
1483 u_darkness: dark,
1484 u_strength: flash,
1485 u_wade: wade ? 1 : 0,
1486 u_spriteHeight: height,
1487 u_shaftTint: [shaft.r, shaft.g, shaft.b],
1488 u_tipTint: [tip.r, tip.g, tip.b]
1489 };
1490 object.renderer.secondaryMap = null;
1491 }
1492
1417 #syncGroundItemSprite (item, darkness)
1493 #syncGroundItemSprite (item, darkness)
1418 {
1494 {
1495 if (item?.dualTint)
1496 {
1497 this.#syncDualTintLitSprite(item.object, darkness, item.dualTint);
1498 return;
1499 }
1419 this.#syncLitSprite(item?.object, darkness, 0, false, item?.tintColor ?? null);
1500 this.#syncLitSprite(item?.object, darkness, 0, false, item?.tintColor ?? null);
1420 }
1501 }
1421
1502
@@ -1544,11 +1625,24 @@ export class WorldView
1544 };
1625 };
1545 }
1626 }
1546
1627
1547 #applyPhysicalCombatFxDarkness (object, fromTileX, fromTileY, tileX, tileY)
1628 #applyPhysicalCombatFxDarkness (object, fromTileX, fromTileY, tileX, tileY, dualTint = null)
1548 {
1629 {
1549 const fromAlpha = this.tiles.get(`${fromTileX},${fromTileY}`)?.shadeAlpha ?? 0;
1630 const fromAlpha = this.tiles.get(`${fromTileX},${fromTileY}`)?.shadeAlpha ?? 0;
1550 const toAlpha = this.tiles.get(`${tileX},${tileY}`)?.shadeAlpha ?? 0;
1631 const toAlpha = this.tiles.get(`${tileX},${tileY}`)?.shadeAlpha ?? 0;
1551 this.#syncLitSprite(object, (fromAlpha + toAlpha) / 2);
1632 const dark = (fromAlpha + toAlpha) / 2;
1633 if (dualTint)
1634 {
1635 this.#syncDualTintLitSprite(object, dark, dualTint);
1636 return;
1637 }
1638 this.#syncLitSprite(object, dark);
1639 }
1640
1641 #dualTintFromPayload (payload)
1642 {
1643 if (!payload?.shaftTint || !payload?.tipTint)
1644 { return null; }
1645 return { shaft: payload.shaftTint, tip: payload.tipTint };
1552 }
1646 }
1553
1647
1554 #syncHpBar (entity)
1648 #syncHpBar (entity)
@@ -2324,7 +2418,8 @@ export class WorldView
2324 swipe.fromTileX,
2418 swipe.fromTileX,
2325 swipe.fromTileY,
2419 swipe.fromTileY,
2326 swipe.tileX,
2420 swipe.tileX,
2327 swipe.tileY
2421 swipe.tileY,
2422 swipe.dualTint ?? null
2328 );
2423 );
2329 }
2424 }
2330 else if (swipe.fromTileX != null)
2425 else if (swipe.fromTileX != null)
@@ -2334,7 +2429,8 @@ export class WorldView
2334 swipe.fromTileX,
2429 swipe.fromTileX,
2335 swipe.fromTileY,
2430 swipe.fromTileY,
2336 swipe.tileX,
2431 swipe.tileX,
2337 swipe.tileY
2432 swipe.tileY,
2433 swipe.dualTint ?? null
2338 );
2434 );
2339 }
2435 }
2340 if (swipe.until > now)
2436 if (swipe.until > now)
server/src/combat/service.js +35 −29
@@ -24,8 +24,6 @@ import {
24 24 effectiveSkillLevel,
25 25 equipmentBonusesFromSlots
26 26 } from "../../../shared/equipment/stats.js";
27 import { tierStatBonus } from "../../../shared/definitions/materialTiers.js";
28 import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";
29 27 import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";
30 28 import { awardCombatHitXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
31 29 import { chunkBoundsAround, findPath } from "../navigation/astar.js";
@@ -34,6 +32,7 @@ import { rayReaches } from "../../../shared/lighting/raycast.js";
34 32 import { tileToChunk } from "../world/coordinates.js";
35 33 import { stackQuantity } from "../../../shared/items/inventory.js";
36 34 import { addGroundItem, publicGroundItem } from "../items/bags.js";
35 import { resolveItemDualTint } from "../../../shared/render/tint.js";
37 36
38 37 export function chebyshev (ax, ay, bx, by)
39 38 {
@@ -98,26 +97,9 @@ function playerCombatLevels (ecs, handle, profile)
98 97 bonuses[SkillId.strength] = (bonuses[SkillId.strength] ?? 0) + (status.strength ?? 0);
99 98 bonuses[SkillId.mind] = (bonuses[SkillId.mind] ?? 0) + (status.mind ?? 0);
100 99
101 if (profile.mode === "ranged")
102 {
103 const weapon = equipment?.slots?.weapon;
104 const offhand = equipment?.slots?.offhand;
105 const bowDef = weapon ? itemDefinition(weapon.itemId) : null;
106 const arrowDef = offhand ? itemDefinition(offhand.itemId) : null;
107 const bowTier = bowDef?.equipment?.tier;
108 const arrowTier = arrowDef?.equipment?.tier;
109 return {
110 hitLevel: skillLevel(skills, SkillId.archery) + (bowTier ? tierStatBonus(bowTier) : 0),
111 damageLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses)
112 + (arrowTier ? tierStatBonus(arrowTier) : 0),
113 agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses),
114 defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses)
115 };
116 }
117
118 100 return {
119 hitLevel: skillLevel(skills, profile.hitSkillId),
120 damageLevel: effectiveSkillLevel(skills, profile.damageSkillId, bonuses),
101 hitLevel: skillLevel(skills, profile.hitSkillId ?? SkillId.unarmed),
102 damageLevel: effectiveSkillLevel(skills, profile.damageSkillId ?? SkillId.strength, bonuses),
121 103 agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses),
122 104 defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses)
123 105 };
@@ -239,6 +221,25 @@ function spawnMobDrops (world, targetHandle, tileX, tileY, now)
239 221 return events;
240 222 }
241 223
224 function projectileDualTintFromAttacker (ecs, handle)
225 {
226 const equipment = ecs.get(handle, Component.equipment);
227 const stack = arrowStackInOffhand(equipment);
228 if (!stack)
229 { return null; }
230 return resolveItemDualTint(stack, itemDefinition(stack.itemId));
231 }
232
233 function publicDualTint (dualTint)
234 {
235 if (!dualTint)
236 { return null; }
237 return {
238 shaftTint: dualTint.shaft,
239 tipTint: dualTint.tip
240 };
241 }
242
242 243 function missProjectileTile (targetTileX, targetTileY, rng = Math.random)
243 244 {
244 245 const angle = rng() * Math.PI * 2;
@@ -624,7 +625,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
624 625 tileX: snapshot.tileX,
625 626 tileY: snapshot.tileY,
626 627 fromTileX: from.tileX,
627 fromTileY: from.tileY
628 fromTileY: from.tileY,
629 ...(publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {})
628 630 });
629 631 return events;
630 632 }
@@ -666,7 +668,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
666 668 fromTileY: from.tileY,
667 669 tileX: endX,
668 670 tileY: endY,
669 durationMs: 400
671 durationMs: 400,
672 ...publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {}
670 673 });
671 674 return events.concat(hitEvents);
672 675 }
@@ -824,7 +827,9 @@ export function applyRemoteRangedShot (world, payload)
824 827 fromTileY: payload.fromTileY,
825 828 tileX: endX,
826 829 tileY: endY,
827 durationMs: 400
830 durationMs: 400,
831 shaftTint: payload.shaftTint ?? null,
832 tipTint: payload.tipTint ?? null
828 833 }, ...hitEvents];
829 834
830 835 const forwards = [];
@@ -834,7 +839,8 @@ export function applyRemoteRangedShot (world, payload)
834 839 forwards.push({
835 840 type: "forward-combat-xp",
836 841 entityId: payload.attackerId,
837 profile: payload.profile
842 profile: payload.profile,
843 damage: hitEvent.damage
838 844 });
839 845 }
840 846 return { events, forwards };
@@ -870,7 +876,8 @@ export function applyRemoteMeleeSwing (world, payload)
870 876 forwards.push({
871 877 type: "forward-combat-xp",
872 878 entityId: payload.attackerId,
873 profile: payload.profile
879 profile: payload.profile,
880 damage: hitEvent.damage
874 881 });
875 882 }
876 883 return { events, forwards };
@@ -942,8 +949,7 @@ function applyLocalMeleeHit (
942 949 ),
943 950 agilitySkillLevel: agilityLevel,
944 951 damageSkillLevel: attackerLevels.damageLevel,
945 defenceSkillLevel: defenceLevel,
946 baseDamage: profile.baseDamage ?? 1
952 defenceSkillLevel: defenceLevel
947 953 });
948 954
949 955 if (resolved.outcome === "miss")
@@ -1017,7 +1023,7 @@ function applyLocalMeleeHit (
1017 1023 const attackerCharacter = world.ecs.get(attackerHandle, Component.character);
1018 1024 if (attackerCharacter)
1019 1025 {
1020 const xpAward = awardCombatHitXp(world.ecs, attackerHandle, profile);
1026 const xpAward = awardCombatHitXp(world.ecs, attackerHandle, profile, damage);
1021 1027 if (xpAward)
1022 1028 {
1023 1029 events.push({
@@ -24,8 +24,6 @@ import {
24 effectiveSkillLevel,
24 effectiveSkillLevel,
25 equipmentBonusesFromSlots
25 equipmentBonusesFromSlots
26} from "../../../shared/equipment/stats.js";
26} from "../../../shared/equipment/stats.js";
27import { tierStatBonus } from "../../../shared/definitions/materialTiers.js";
28import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";
29import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";
27import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";
30import { awardCombatHitXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
28import { awardCombatHitXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
31import { chunkBoundsAround, findPath } from "../navigation/astar.js";
29import { chunkBoundsAround, findPath } from "../navigation/astar.js";
@@ -34,6 +32,7 @@ import { rayReaches } from "../../../shared/lighting/raycast.js";
34import { tileToChunk } from "../world/coordinates.js";
32import { tileToChunk } from "../world/coordinates.js";
35import { stackQuantity } from "../../../shared/items/inventory.js";
33import { stackQuantity } from "../../../shared/items/inventory.js";
36import { addGroundItem, publicGroundItem } from "../items/bags.js";
34import { addGroundItem, publicGroundItem } from "../items/bags.js";
35import { resolveItemDualTint } from "../../../shared/render/tint.js";
37
36
38export function chebyshev (ax, ay, bx, by)
37export function chebyshev (ax, ay, bx, by)
39{
38{
@@ -98,26 +97,9 @@ function playerCombatLevels (ecs, handle, profile)
98 bonuses[SkillId.strength] = (bonuses[SkillId.strength] ?? 0) + (status.strength ?? 0);
97 bonuses[SkillId.strength] = (bonuses[SkillId.strength] ?? 0) + (status.strength ?? 0);
99 bonuses[SkillId.mind] = (bonuses[SkillId.mind] ?? 0) + (status.mind ?? 0);
98 bonuses[SkillId.mind] = (bonuses[SkillId.mind] ?? 0) + (status.mind ?? 0);
100
99
101 if (profile.mode === "ranged")
102 {
103 const weapon = equipment?.slots?.weapon;
104 const offhand = equipment?.slots?.offhand;
105 const bowDef = weapon ? itemDefinition(weapon.itemId) : null;
106 const arrowDef = offhand ? itemDefinition(offhand.itemId) : null;
107 const bowTier = bowDef?.equipment?.tier;
108 const arrowTier = arrowDef?.equipment?.tier;
109 return {
110 hitLevel: skillLevel(skills, SkillId.archery) + (bowTier ? tierStatBonus(bowTier) : 0),
111 damageLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses)
112 + (arrowTier ? tierStatBonus(arrowTier) : 0),
113 agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses),
114 defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses)
115 };
116 }
117
118 return {
100 return {
119 hitLevel: skillLevel(skills, profile.hitSkillId),
101 hitLevel: skillLevel(skills, profile.hitSkillId ?? SkillId.unarmed),
120 damageLevel: effectiveSkillLevel(skills, profile.damageSkillId, bonuses),
102 damageLevel: effectiveSkillLevel(skills, profile.damageSkillId ?? SkillId.strength, bonuses),
121 agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses),
103 agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses),
122 defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses)
104 defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses)
123 };
105 };
@@ -239,6 +221,25 @@ function spawnMobDrops (world, targetHandle, tileX, tileY, now)
239 return events;
221 return events;
240}
222}
241
223
224function projectileDualTintFromAttacker (ecs, handle)
225{
226 const equipment = ecs.get(handle, Component.equipment);
227 const stack = arrowStackInOffhand(equipment);
228 if (!stack)
229 { return null; }
230 return resolveItemDualTint(stack, itemDefinition(stack.itemId));
231}
232
233function publicDualTint (dualTint)
234{
235 if (!dualTint)
236 { return null; }
237 return {
238 shaftTint: dualTint.shaft,
239 tipTint: dualTint.tip
240 };
241}
242
242function missProjectileTile (targetTileX, targetTileY, rng = Math.random)
243function missProjectileTile (targetTileX, targetTileY, rng = Math.random)
243{
244{
244 const angle = rng() * Math.PI * 2;
245 const angle = rng() * Math.PI * 2;
@@ -624,7 +625,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
624 tileX: snapshot.tileX,
625 tileX: snapshot.tileX,
625 tileY: snapshot.tileY,
626 tileY: snapshot.tileY,
626 fromTileX: from.tileX,
627 fromTileX: from.tileX,
627 fromTileY: from.tileY
628 fromTileY: from.tileY,
629 ...(publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {})
628 });
630 });
629 return events;
631 return events;
630 }
632 }
@@ -666,7 +668,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
666 fromTileY: from.tileY,
668 fromTileY: from.tileY,
667 tileX: endX,
669 tileX: endX,
668 tileY: endY,
670 tileY: endY,
669 durationMs: 400
671 durationMs: 400,
672 ...publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {}
670 });
673 });
671 return events.concat(hitEvents);
674 return events.concat(hitEvents);
672}
675}
@@ -824,7 +827,9 @@ export function applyRemoteRangedShot (world, payload)
824 fromTileY: payload.fromTileY,
827 fromTileY: payload.fromTileY,
825 tileX: endX,
828 tileX: endX,
826 tileY: endY,
829 tileY: endY,
827 durationMs: 400
830 durationMs: 400,
831 shaftTint: payload.shaftTint ?? null,
832 tipTint: payload.tipTint ?? null
828 }, ...hitEvents];
833 }, ...hitEvents];
829
834
830 const forwards = [];
835 const forwards = [];
@@ -834,7 +839,8 @@ export function applyRemoteRangedShot (world, payload)
834 forwards.push({
839 forwards.push({
835 type: "forward-combat-xp",
840 type: "forward-combat-xp",
836 entityId: payload.attackerId,
841 entityId: payload.attackerId,
837 profile: payload.profile
842 profile: payload.profile,
843 damage: hitEvent.damage
838 });
844 });
839 }
845 }
840 return { events, forwards };
846 return { events, forwards };
@@ -870,7 +876,8 @@ export function applyRemoteMeleeSwing (world, payload)
870 forwards.push({
876 forwards.push({
871 type: "forward-combat-xp",
877 type: "forward-combat-xp",
872 entityId: payload.attackerId,
878 entityId: payload.attackerId,
873 profile: payload.profile
879 profile: payload.profile,
880 damage: hitEvent.damage
874 });
881 });
875 }
882 }
876 return { events, forwards };
883 return { events, forwards };
@@ -942,8 +949,7 @@ function applyLocalMeleeHit (
942 ),
949 ),
943 agilitySkillLevel: agilityLevel,
950 agilitySkillLevel: agilityLevel,
944 damageSkillLevel: attackerLevels.damageLevel,
951 damageSkillLevel: attackerLevels.damageLevel,
945 defenceSkillLevel: defenceLevel,
952 defenceSkillLevel: defenceLevel
946 baseDamage: profile.baseDamage ?? 1
947 });
953 });
948
954
949 if (resolved.outcome === "miss")
955 if (resolved.outcome === "miss")
@@ -1017,7 +1023,7 @@ function applyLocalMeleeHit (
1017 const attackerCharacter = world.ecs.get(attackerHandle, Component.character);
1023 const attackerCharacter = world.ecs.get(attackerHandle, Component.character);
1018 if (attackerCharacter)
1024 if (attackerCharacter)
1019 {
1025 {
1020 const xpAward = awardCombatHitXp(world.ecs, attackerHandle, profile);
1026 const xpAward = awardCombatHitXp(world.ecs, attackerHandle, profile, damage);
1021 if (xpAward)
1027 if (xpAward)
1022 {
1028 {
1023 events.push({
1029 events.push({
server/src/gateway/websocket.js +3 −1
@@ -1355,7 +1355,9 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1355 1355 fromTileY: event.fromTileY,
1356 1356 tileX: event.tileX,
1357 1357 tileY: event.tileY,
1358 durationMs: event.durationMs ?? 400
1358 durationMs: event.durationMs ?? 400,
1359 shaftTint: event.shaftTint ?? null,
1360 tipTint: event.tipTint ?? null
1359 1361 });
1360 1362 continue;
1361 1363 }
@@ -1355,7 +1355,9 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
1355 fromTileY: event.fromTileY,
1355 fromTileY: event.fromTileY,
1356 tileX: event.tileX,
1356 tileX: event.tileX,
1357 tileY: event.tileY,
1357 tileY: event.tileY,
1358 durationMs: event.durationMs ?? 400
1358 durationMs: event.durationMs ?? 400,
1359 shaftTint: event.shaftTint ?? null,
1360 tipTint: event.tipTint ?? null
1359 });
1361 });
1360 continue;
1362 continue;
1361 }
1363 }
server/src/simulation/simulation.js +4 −2
@@ -1059,7 +1059,8 @@ export class Simulation
1059 1059 const xpResult = this.workers[attackerRecord.workerId].call({
1060 1060 type: WorkerMessage.applyCombatHitXp,
1061 1061 entityId: forward.entityId,
1062 profile: forward.profile
1062 profile: forward.profile,
1063 damage: forward.damage
1063 1064 });
1064 1065 for (const xpEvent of xpResult?.events ?? [])
1065 1066 {
@@ -1114,7 +1115,8 @@ export class Simulation
1114 1115 const xpResult = this.workers[attackerRecord.workerId].call({
1115 1116 type: WorkerMessage.applyCombatHitXp,
1116 1117 entityId: forward.entityId,
1117 profile: forward.profile
1118 profile: forward.profile,
1119 damage: forward.damage
1118 1120 });
1119 1121 for (const xpEvent of xpResult?.events ?? [])
1120 1122 {
@@ -1059,7 +1059,8 @@ export class Simulation
1059 const xpResult = this.workers[attackerRecord.workerId].call({
1059 const xpResult = this.workers[attackerRecord.workerId].call({
1060 type: WorkerMessage.applyCombatHitXp,
1060 type: WorkerMessage.applyCombatHitXp,
1061 entityId: forward.entityId,
1061 entityId: forward.entityId,
1062 profile: forward.profile
1062 profile: forward.profile,
1063 damage: forward.damage
1063 });
1064 });
1064 for (const xpEvent of xpResult?.events ?? [])
1065 for (const xpEvent of xpResult?.events ?? [])
1065 {
1066 {
@@ -1114,7 +1115,8 @@ export class Simulation
1114 const xpResult = this.workers[attackerRecord.workerId].call({
1115 const xpResult = this.workers[attackerRecord.workerId].call({
1115 type: WorkerMessage.applyCombatHitXp,
1116 type: WorkerMessage.applyCombatHitXp,
1116 entityId: forward.entityId,
1117 entityId: forward.entityId,
1117 profile: forward.profile
1118 profile: forward.profile,
1119 damage: forward.damage
1118 });
1120 });
1119 for (const xpEvent of xpResult?.events ?? [])
1121 for (const xpEvent of xpResult?.events ?? [])
1120 {
1122 {
server/src/simulation/workerWorld.js +2 −2
@@ -727,7 +727,7 @@ export class WorkerWorld
727 727 return applyRemoteRangedShot(this, payload);
728 728 }
729 729
730 #applyCombatHitXp ({ entityId, profile })
730 #applyCombatHitXp ({ entityId, profile, damage })
731 731 {
732 732 const handle = this.ecs.handleOf(entityId);
733 733 if (handle == null)
@@ -735,7 +735,7 @@ export class WorkerWorld
735 735 const character = this.ecs.get(handle, Component.character);
736 736 if (!character)
737 737 { return { events: [] }; }
738 const xpAward = awardCombatHitXp(this.ecs, handle, profile);
738 const xpAward = awardCombatHitXp(this.ecs, handle, profile, damage);
739 739 if (!xpAward)
740 740 { return { events: [] }; }
741 741 return {
@@ -727,7 +727,7 @@ export class WorkerWorld
727 return applyRemoteRangedShot(this, payload);
727 return applyRemoteRangedShot(this, payload);
728 }
728 }
729
729
730 #applyCombatHitXp ({ entityId, profile })
730 #applyCombatHitXp ({ entityId, profile, damage })
731 {
731 {
732 const handle = this.ecs.handleOf(entityId);
732 const handle = this.ecs.handleOf(entityId);
733 if (handle == null)
733 if (handle == null)
@@ -735,7 +735,7 @@ export class WorkerWorld
735 const character = this.ecs.get(handle, Component.character);
735 const character = this.ecs.get(handle, Component.character);
736 if (!character)
736 if (!character)
737 { return { events: [] }; }
737 { return { events: [] }; }
738 const xpAward = awardCombatHitXp(this.ecs, handle, profile);
738 const xpAward = awardCombatHitXp(this.ecs, handle, profile, damage);
739 if (!xpAward)
739 if (!xpAward)
740 { return { events: [] }; }
740 { return { events: [] }; }
741 return {
741 return {
server/src/skills/service.js +29 −8
@@ -1,6 +1,6 @@
1 1 import { Component } from "../ecs/components.js";
2 2 import { SkillId, playerMaxHealth, playerMaxStamina } from "../../../shared/definitions/skills.js";
3 import { combatHitXpPerSkill } from "../../../shared/skills/progression.js";
3 import { combatDamageXp, spellCastXpFromDifficulty } from "../../../shared/skills/progression.js";
4 4 import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
5 5
6 6 export function syncPlayerHealth (ecs, handle)
@@ -31,20 +31,22 @@ export function syncPlayerStamina (ecs, handle)
31 31 stamina.current = Math.min(Number(stamina.current) || 0, max);
32 32 }
33 33
34 export function awardCombatHitXp (ecs, attackerHandle, profile)
34 export function awardCombatHitXp (ecs, attackerHandle, profile, damage)
35 35 {
36 const amount = combatDamageXp(damage);
37 if (!amount)
38 { return null; }
36 39 const skills = ecs.get(attackerHandle, Component.skills);
37 40 if (!skills?.xp)
38 41 { return null; }
39 const perSkill = combatHitXpPerSkill();
40 42 const levelUps = [];
41 const hit = applySkillXp(skills, profile.hitSkillId, perSkill);
43 const hit = applySkillXp(skills, profile.hitSkillId, amount);
42 44 if (hit.levelUp)
43 45 { levelUps.push(hit.levelUp); }
44 const damage = applySkillXp(skills, profile.damageSkillId, perSkill);
45 if (damage.levelUp)
46 { levelUps.push(damage.levelUp); }
47 if (!hit.changed && !damage.changed)
46 const damageSkill = applySkillXp(skills, profile.damageSkillId, amount);
47 if (damageSkill.levelUp)
48 { levelUps.push(damageSkill.levelUp); }
49 if (!hit.changed && !damageSkill.changed)
48 50 { return null; }
49 51 return {
50 52 view: publicSkillsView(skills),
@@ -53,6 +55,25 @@ export function awardCombatHitXp (ecs, attackerHandle, profile)
53 55 };
54 56 }
55 57
58 /** Magic XP on a successful cast; damage XP uses {@link awardCombatHitXp} when the spell lands. */
59 export function awardSpellCastXp (ecs, casterHandle, spellDifficulty)
60 {
61 const amount = spellCastXpFromDifficulty(spellDifficulty);
62 const skills = ecs.get(casterHandle, Component.skills);
63 if (!skills?.xp)
64 { return null; }
65 const result = applySkillXp(skills, SkillId.magic, amount);
66 if (!result.changed)
67 { return null; }
68 const character = ecs.get(casterHandle, Component.character);
69 return {
70 characterId: character?.characterId ?? null,
71 view: publicSkillsView(skills),
72 stored: storedSkillXp(skills),
73 levelUps: result.levelUp ? [result.levelUp] : []
74 };
75 }
76
56 77 export function awardDamageHealthXp (ecs, targetHandle, damage)
57 78 {
58 79 const amount = Math.max(0, Math.floor(Number(damage) || 0));
@@ -1,6 +1,6 @@
1import { Component } from "../ecs/components.js";
1import { Component } from "../ecs/components.js";
2import { SkillId, playerMaxHealth, playerMaxStamina } from "../../../shared/definitions/skills.js";
2import { SkillId, playerMaxHealth, playerMaxStamina } from "../../../shared/definitions/skills.js";
3import { combatHitXpPerSkill } from "../../../shared/skills/progression.js";
3import { combatDamageXp, spellCastXpFromDifficulty } from "../../../shared/skills/progression.js";
4import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
4import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
5
5
6export function syncPlayerHealth (ecs, handle)
6export function syncPlayerHealth (ecs, handle)
@@ -31,20 +31,22 @@ export function syncPlayerStamina (ecs, handle)
31 stamina.current = Math.min(Number(stamina.current) || 0, max);
31 stamina.current = Math.min(Number(stamina.current) || 0, max);
32}
32}
33
33
34export function awardCombatHitXp (ecs, attackerHandle, profile)
34export function awardCombatHitXp (ecs, attackerHandle, profile, damage)
35{
35{
36 const amount = combatDamageXp(damage);
37 if (!amount)
38 { return null; }
36 const skills = ecs.get(attackerHandle, Component.skills);
39 const skills = ecs.get(attackerHandle, Component.skills);
37 if (!skills?.xp)
40 if (!skills?.xp)
38 { return null; }
41 { return null; }
39 const perSkill = combatHitXpPerSkill();
40 const levelUps = [];
42 const levelUps = [];
41 const hit = applySkillXp(skills, profile.hitSkillId, perSkill);
43 const hit = applySkillXp(skills, profile.hitSkillId, amount);
42 if (hit.levelUp)
44 if (hit.levelUp)
43 { levelUps.push(hit.levelUp); }
45 { levelUps.push(hit.levelUp); }
44 const damage = applySkillXp(skills, profile.damageSkillId, perSkill);
46 const damageSkill = applySkillXp(skills, profile.damageSkillId, amount);
45 if (damage.levelUp)
47 if (damageSkill.levelUp)
46 { levelUps.push(damage.levelUp); }
48 { levelUps.push(damageSkill.levelUp); }
47 if (!hit.changed && !damage.changed)
49 if (!hit.changed && !damageSkill.changed)
48 { return null; }
50 { return null; }
49 return {
51 return {
50 view: publicSkillsView(skills),
52 view: publicSkillsView(skills),
@@ -53,6 +55,25 @@ export function awardCombatHitXp (ecs, attackerHandle, profile)
53 };
55 };
54}
56}
55
57
58/** Magic XP on a successful cast; damage XP uses {@link awardCombatHitXp} when the spell lands. */
59export function awardSpellCastXp (ecs, casterHandle, spellDifficulty)
60{
61 const amount = spellCastXpFromDifficulty(spellDifficulty);
62 const skills = ecs.get(casterHandle, Component.skills);
63 if (!skills?.xp)
64 { return null; }
65 const result = applySkillXp(skills, SkillId.magic, amount);
66 if (!result.changed)
67 { return null; }
68 const character = ecs.get(casterHandle, Component.character);
69 return {
70 characterId: character?.characterId ?? null,
71 view: publicSkillsView(skills),
72 stored: storedSkillXp(skills),
73 levelUps: result.levelUp ? [result.levelUp] : []
74 };
75}
76
56export function awardDamageHealthXp (ecs, targetHandle, damage)
77export function awardDamageHealthXp (ecs, targetHandle, damage)
57{
78{
58 const amount = Math.max(0, Math.floor(Number(damage) || 0));
79 const amount = Math.max(0, Math.floor(Number(damage) || 0));
server/tests/combatRolls.test.js +18 −6
@@ -32,7 +32,6 @@ test("physical attack miss when agility roll beats hit roll", () =>
32 32 agilitySkillLevel: 10,
33 33 damageSkillLevel: 10,
34 34 defenceSkillLevel: 1,
35 baseDamage: 2,
36 35 rng
37 36 });
38 37 assert.equal(result.outcome, "miss");
@@ -50,7 +49,6 @@ test("equal hit and agility rolls count as a hit", () =>
50 49 agilitySkillLevel: 5,
51 50 damageSkillLevel: 5,
52 51 defenceSkillLevel: 1,
53 baseDamage: 1,
54 52 rng
55 53 });
56 54 assert.equal(result.toHitRoll, result.agilityRoll);
@@ -67,7 +65,6 @@ test("physical attack block prevents damage after winning the hit contest", () =
67 65 agilitySkillLevel: 3,
68 66 damageSkillLevel: 8,
69 67 defenceSkillLevel: 10,
70 baseDamage: 1,
71 68 rng
72 69 });
73 70 assert.equal(result.outcome, "block");
@@ -85,11 +82,27 @@ test("physical attack hit applies rolled damage when not blocked", () =>
85 82 agilitySkillLevel: 1,
86 83 damageSkillLevel: 5,
87 84 defenceSkillLevel: 1,
88 baseDamage: 2,
89 85 rng
90 86 });
91 87 assert.equal(result.outcome, "hit");
92 assert.equal(result.damage, 2);
88 assert.equal(result.damage, 1);
89 });
90
91 test("physical damage is the damage skill roll only", () =>
92 {
93 let i = 0;
94 const rolls = [0.5, 0, 0.4, 0];
95 const rng = () => rolls[i++];
96 const result = resolvePhysicalAttack({
97 hitSkillLevel: 10,
98 agilitySkillLevel: 1,
99 damageSkillLevel: 5,
100 defenceSkillLevel: 1,
101 rng
102 });
103 assert.equal(result.outcome, "hit");
104 assert.equal(result.damageRoll, 3);
105 assert.equal(result.damage, 3);
93 106 });
94 107
95 108 test("skill level 1 contest can still land a hit on equal agility", () =>
@@ -99,7 +112,6 @@ test("skill level 1 contest can still land a hit on equal agility", () =>
99 112 agilitySkillLevel: 1,
100 113 damageSkillLevel: 1,
101 114 defenceSkillLevel: 1,
102 baseDamage: 1,
103 115 rng: () => 0
104 116 });
105 117 assert.equal(result.outcome, "hit");
@@ -32,7 +32,6 @@ test("physical attack miss when agility roll beats hit roll", () =>
32 agilitySkillLevel: 10,
32 agilitySkillLevel: 10,
33 damageSkillLevel: 10,
33 damageSkillLevel: 10,
34 defenceSkillLevel: 1,
34 defenceSkillLevel: 1,
35 baseDamage: 2,
36 rng
35 rng
37 });
36 });
38 assert.equal(result.outcome, "miss");
37 assert.equal(result.outcome, "miss");
@@ -50,7 +49,6 @@ test("equal hit and agility rolls count as a hit", () =>
50 agilitySkillLevel: 5,
49 agilitySkillLevel: 5,
51 damageSkillLevel: 5,
50 damageSkillLevel: 5,
52 defenceSkillLevel: 1,
51 defenceSkillLevel: 1,
53 baseDamage: 1,
54 rng
52 rng
55 });
53 });
56 assert.equal(result.toHitRoll, result.agilityRoll);
54 assert.equal(result.toHitRoll, result.agilityRoll);
@@ -67,7 +65,6 @@ test("physical attack block prevents damage after winning the hit contest", () =
67 agilitySkillLevel: 3,
65 agilitySkillLevel: 3,
68 damageSkillLevel: 8,
66 damageSkillLevel: 8,
69 defenceSkillLevel: 10,
67 defenceSkillLevel: 10,
70 baseDamage: 1,
71 rng
68 rng
72 });
69 });
73 assert.equal(result.outcome, "block");
70 assert.equal(result.outcome, "block");
@@ -85,11 +82,27 @@ test("physical attack hit applies rolled damage when not blocked", () =>
85 agilitySkillLevel: 1,
82 agilitySkillLevel: 1,
86 damageSkillLevel: 5,
83 damageSkillLevel: 5,
87 defenceSkillLevel: 1,
84 defenceSkillLevel: 1,
88 baseDamage: 2,
89 rng
85 rng
90 });
86 });
91 assert.equal(result.outcome, "hit");
87 assert.equal(result.outcome, "hit");
92 assert.equal(result.damage, 2);
88 assert.equal(result.damage, 1);
89});
90
91test("physical damage is the damage skill roll only", () =>
92{
93 let i = 0;
94 const rolls = [0.5, 0, 0.4, 0];
95 const rng = () => rolls[i++];
96 const result = resolvePhysicalAttack({
97 hitSkillLevel: 10,
98 agilitySkillLevel: 1,
99 damageSkillLevel: 5,
100 defenceSkillLevel: 1,
101 rng
102 });
103 assert.equal(result.outcome, "hit");
104 assert.equal(result.damageRoll, 3);
105 assert.equal(result.damage, 3);
93});
106});
94
107
95test("skill level 1 contest can still land a hit on equal agility", () =>
108test("skill level 1 contest can still land a hit on equal agility", () =>
@@ -99,7 +112,6 @@ test("skill level 1 contest can still land a hit on equal agility", () =>
99 agilitySkillLevel: 1,
112 agilitySkillLevel: 1,
100 damageSkillLevel: 1,
113 damageSkillLevel: 1,
101 defenceSkillLevel: 1,
114 defenceSkillLevel: 1,
102 baseDamage: 1,
103 rng: () => 0
115 rng: () => 0
104 });
116 });
105 assert.equal(result.outcome, "hit");
117 assert.equal(result.outcome, "hit");
server/tests/magic.test.js +3 −3
@@ -30,7 +30,7 @@ test("fizzled magic attack deals no damage", () =>
30 30 magicSkillLevel: 3,
31 31 spellDifficulty: 10,
32 32 mindSkillLevel: 10,
33 baseDamage: 5,
33 mindBonus: 5,
34 34 element: "fire",
35 35 rng
36 36 });
@@ -46,7 +46,7 @@ test("successful magic attack rolls mind damage and elemental multiplier", () =>
46 46 magicSkillLevel: 10,
47 47 spellDifficulty: 1,
48 48 mindSkillLevel: 5,
49 baseDamage: 2,
49 mindBonus: 2,
50 50 element: "fire",
51 51 targetAffinities: {},
52 52 rng
@@ -60,7 +60,7 @@ test("successful magic attack rolls mind damage and elemental multiplier", () =>
60 60 magicSkillLevel: 10,
61 61 spellDifficulty: 1,
62 62 mindSkillLevel: 5,
63 baseDamage: 2,
63 mindBonus: 2,
64 64 element: "fire",
65 65 targetAffinities: { fire: "weak" },
66 66 rng: rngWeak
@@ -30,7 +30,7 @@ test("fizzled magic attack deals no damage", () =>
30 magicSkillLevel: 3,
30 magicSkillLevel: 3,
31 spellDifficulty: 10,
31 spellDifficulty: 10,
32 mindSkillLevel: 10,
32 mindSkillLevel: 10,
33 baseDamage: 5,
33 mindBonus: 5,
34 element: "fire",
34 element: "fire",
35 rng
35 rng
36 });
36 });
@@ -46,7 +46,7 @@ test("successful magic attack rolls mind damage and elemental multiplier", () =>
46 magicSkillLevel: 10,
46 magicSkillLevel: 10,
47 spellDifficulty: 1,
47 spellDifficulty: 1,
48 mindSkillLevel: 5,
48 mindSkillLevel: 5,
49 baseDamage: 2,
49 mindBonus: 2,
50 element: "fire",
50 element: "fire",
51 targetAffinities: {},
51 targetAffinities: {},
52 rng
52 rng
@@ -60,7 +60,7 @@ test("successful magic attack rolls mind damage and elemental multiplier", () =>
60 magicSkillLevel: 10,
60 magicSkillLevel: 10,
61 spellDifficulty: 1,
61 spellDifficulty: 1,
62 mindSkillLevel: 5,
62 mindSkillLevel: 5,
63 baseDamage: 2,
63 mindBonus: 2,
64 element: "fire",
64 element: "fire",
65 targetAffinities: { fire: "weak" },
65 targetAffinities: { fire: "weak" },
66 rng: rngWeak
66 rng: rngWeak
server/tests/mobCombat.test.js +1 −1
@@ -14,5 +14,5 @@ test("mob attack profile uses one attackSkill for hit and damage rolls", () =>
14 14 {
15 15 const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat));
16 16 assert.equal(profile.mobAttackSkill, 3);
17 assert.equal(profile.baseDamage, 2);
17 assert.equal(profile.baseDamage, undefined);
18 18 });
@@ -14,5 +14,5 @@ test("mob attack profile uses one attackSkill for hit and damage rolls", () =>
14{
14{
15 const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat));
15 const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat));
16 assert.equal(profile.mobAttackSkill, 3);
16 assert.equal(profile.mobAttackSkill, 3);
17 assert.equal(profile.baseDamage, 2);
17 assert.equal(profile.baseDamage, undefined);
18});
18});
server/tests/ranged.test.js +2 −1
@@ -16,7 +16,8 @@ test("ranged items: bow is ranged weapon, arrows stack in offhand", () =>
16 16
17 17 const arrow = itemDefinition(RangedItemId.bronzeArrow);
18 18 assert.equal(arrow?.equipment?.kind, EquipmentKind.arrowAmmo);
19 assert.equal(arrow?.equipment?.slot, "offhand");
19 assert.equal(arrow?.defaultState, "full-arrow");
20 assert.equal(arrow?.dualTintFromTier, true);
20 21 assert.equal(arrow?.maxStackSize, 999);
21 22 assert.equal(arrow?.equipment?.hideEquipSprite, true);
22 23 });
@@ -16,7 +16,8 @@ test("ranged items: bow is ranged weapon, arrows stack in offhand", () =>
16
16
17 const arrow = itemDefinition(RangedItemId.bronzeArrow);
17 const arrow = itemDefinition(RangedItemId.bronzeArrow);
18 assert.equal(arrow?.equipment?.kind, EquipmentKind.arrowAmmo);
18 assert.equal(arrow?.equipment?.kind, EquipmentKind.arrowAmmo);
19 assert.equal(arrow?.equipment?.slot, "offhand");
19 assert.equal(arrow?.defaultState, "full-arrow");
20 assert.equal(arrow?.dualTintFromTier, true);
20 assert.equal(arrow?.maxStackSize, 999);
21 assert.equal(arrow?.maxStackSize, 999);
21 assert.equal(arrow?.equipment?.hideEquipSprite, true);
22 assert.equal(arrow?.equipment?.hideEquipSprite, true);
22});
23});
server/tests/skills.test.js +12 −6
@@ -6,7 +6,8 @@ import {
6 6 totalXpForLevel,
7 7 xpProgress,
8 8 levelFromTotalXp,
9 combatHitXpPerSkill
9 combatDamageXp,
10 spellCastXpFromDifficulty
10 11 } from "../../shared/skills/progression.js";
11 12 import {
12 13 normalizeSkillXp,
@@ -168,12 +169,14 @@ test("applySkillXp reports a level-up when XP crosses a threshold", () =>
168 169 assert.match(result.levelUp?.icon, /strength\.svg$/);
169 170 });
170 171
171 test("combat hit xp is split equally", () =>
172 test("combat xp equals damage dealt to hit and damage skills", () =>
172 173 {
173 assert.equal(combatHitXpPerSkill(), 5);
174 assert.equal(combatDamageXp(7), 7);
175 assert.equal(combatDamageXp(0), 0);
176 assert.equal(spellCastXpFromDifficulty(4), 8);
174 177 });
175 178
176 test("successful player melee hits award split xp", () =>
179 test("successful player melee hits award xp equal to damage", () =>
177 180 {
178 181 const harness = makeSimulation({ workerCount: 1 });
179 182 const random = Math.random;
@@ -190,10 +193,13 @@ test("successful player melee hits award split xp", () =>
190 193 const worker = harness.simulation.workers[0];
191 194 const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(playerId));
192 195 const events = resolveMeleeSwing(worker.world, playerId, ratId, profile, Date.now());
196 const hit = events.find((event) => event.type === "combat-hit");
193 197 const updated = events.find((event) => event.type === "skills-updated");
198 assert.ok(hit);
194 199 assert.ok(updated);
195 assert.equal(updated.stored[profile.hitSkillId], combatHitXpPerSkill());
196 assert.equal(updated.stored[profile.damageSkillId], combatHitXpPerSkill());
200 const xp = combatDamageXp(hit.damage);
201 assert.equal(updated.stored[profile.hitSkillId], xp);
202 assert.equal(updated.stored[profile.damageSkillId], xp);
197 203 }
198 204 finally
199 205 {
@@ -6,7 +6,8 @@ import {
6 totalXpForLevel,
6 totalXpForLevel,
7 xpProgress,
7 xpProgress,
8 levelFromTotalXp,
8 levelFromTotalXp,
9 combatHitXpPerSkill
9 combatDamageXp,
10 spellCastXpFromDifficulty
10} from "../../shared/skills/progression.js";
11} from "../../shared/skills/progression.js";
11import {
12import {
12 normalizeSkillXp,
13 normalizeSkillXp,
@@ -168,12 +169,14 @@ test("applySkillXp reports a level-up when XP crosses a threshold", () =>
168 assert.match(result.levelUp?.icon, /strength\.svg$/);
169 assert.match(result.levelUp?.icon, /strength\.svg$/);
169});
170});
170
171
171test("combat hit xp is split equally", () =>
172test("combat xp equals damage dealt to hit and damage skills", () =>
172{
173{
173 assert.equal(combatHitXpPerSkill(), 5);
174 assert.equal(combatDamageXp(7), 7);
175 assert.equal(combatDamageXp(0), 0);
176 assert.equal(spellCastXpFromDifficulty(4), 8);
174});
177});
175
178
176test("successful player melee hits award split xp", () =>
179test("successful player melee hits award xp equal to damage", () =>
177{
180{
178 const harness = makeSimulation({ workerCount: 1 });
181 const harness = makeSimulation({ workerCount: 1 });
179 const random = Math.random;
182 const random = Math.random;
@@ -190,10 +193,13 @@ test("successful player melee hits award split xp", () =>
190 const worker = harness.simulation.workers[0];
193 const worker = harness.simulation.workers[0];
191 const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(playerId));
194 const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(playerId));
192 const events = resolveMeleeSwing(worker.world, playerId, ratId, profile, Date.now());
195 const events = resolveMeleeSwing(worker.world, playerId, ratId, profile, Date.now());
196 const hit = events.find((event) => event.type === "combat-hit");
193 const updated = events.find((event) => event.type === "skills-updated");
197 const updated = events.find((event) => event.type === "skills-updated");
198 assert.ok(hit);
194 assert.ok(updated);
199 assert.ok(updated);
195 assert.equal(updated.stored[profile.hitSkillId], combatHitXpPerSkill());
200 const xp = combatDamageXp(hit.damage);
196 assert.equal(updated.stored[profile.damageSkillId], combatHitXpPerSkill());
201 assert.equal(updated.stored[profile.hitSkillId], xp);
202 assert.equal(updated.stored[profile.damageSkillId], xp);
197 }
203 }
198 finally
204 finally
199 {
205 {
server/tests/tierFamilies.test.js added +58 −0
@@ -0,0 +1,58 @@
1 import test from "node:test";
2 import assert from "node:assert/strict";
3 import { ItemId, itemDefinition } from "../../shared/definitions/items.js";
4 import { WoodTier, MaterialTier, statBoostPerTier } from "../../shared/definitions/materialTiers.js";
5 import { ItemFamilyId } from "../../shared/definitions/tierFamilies.js";
6 import { CraftingItemId } from "../../shared/definitions/craftingItems.js";
7 import { RangedItemId } from "../../shared/definitions/rangedItems.js";
8 import { recipeDefinition } from "../../shared/crafting/stationRecipes.js";
9 import { CraftingStationId } from "../../shared/definitions/craftingStations.js";
10
11 test("handle family builds per-tier defs with stable ids", () =>
12 {
13 const handle = itemDefinition(ItemId.birchHandle);
14 assert.equal(handle.familyId, ItemFamilyId.handle);
15 assert.equal(handle.tier, WoodTier.birch);
16 assert.equal(handle.displayName, "Birch handle");
17 assert.equal(handle.tintFromTier, true);
18 });
19
20 test("ore family builds metal tier defs", () =>
21 {
22 const ore = itemDefinition(ItemId.ironOre);
23 assert.equal(ore.familyId, ItemFamilyId.ore);
24 assert.equal(ore.tier, MaterialTier.iron);
25 assert.equal(ore.defaultState, "ore");
26 });
27
28 test("statBoostPerTier aliases tierStatBonus", () =>
29 {
30 assert.equal(statBoostPerTier(MaterialTier.steel), 4);
31 });
32
33 test("pickaxe tool family includes bronze tier with equipment", () =>
34 {
35 const pickaxe = itemDefinition(CraftingItemId.bronzePickaxe);
36 assert.equal(pickaxe.familyId, ItemFamilyId.pickaxe);
37 assert.equal(pickaxe.equipment?.kind, "pickaxeTool");
38 });
39
40 test("bow family exposes ranged attack profile without base damage", () =>
41 {
42 const bow = itemDefinition(RangedItemId.pineBow);
43 assert.equal(bow.familyId, ItemFamilyId.bow);
44 assert.equal(bow.equipment?.attack?.hitSkillId, "archery");
45 assert.equal(bow.equipment?.attack?.baseDamage, undefined);
46 });
47
48 test("tier family recipes resolve through family item ids", () =>
49 {
50 const handle = recipeDefinition("handle-pine");
51 assert.equal(handle.output.itemId, ItemId.pineHandle);
52 const pickaxe = recipeDefinition("pickaxe-bronze");
53 assert.equal(pickaxe.output.itemId, CraftingItemId.bronzePickaxe);
54 assert.equal(pickaxe.inputs.length, 2);
55 const arrow = recipeDefinition("arrow-bronze");
56 assert.equal(arrow.output.itemId, RangedItemId.bronzeArrow);
57 assert.equal(arrow.stationId, CraftingStationId.craftingBench);
58 });
@@ -0,0 +1,58 @@
1import test from "node:test";
2import assert from "node:assert/strict";
3import { ItemId, itemDefinition } from "../../shared/definitions/items.js";
4import { WoodTier, MaterialTier, statBoostPerTier } from "../../shared/definitions/materialTiers.js";
5import { ItemFamilyId } from "../../shared/definitions/tierFamilies.js";
6import { CraftingItemId } from "../../shared/definitions/craftingItems.js";
7import { RangedItemId } from "../../shared/definitions/rangedItems.js";
8import { recipeDefinition } from "../../shared/crafting/stationRecipes.js";
9import { CraftingStationId } from "../../shared/definitions/craftingStations.js";
10
11test("handle family builds per-tier defs with stable ids", () =>
12{
13 const handle = itemDefinition(ItemId.birchHandle);
14 assert.equal(handle.familyId, ItemFamilyId.handle);
15 assert.equal(handle.tier, WoodTier.birch);
16 assert.equal(handle.displayName, "Birch handle");
17 assert.equal(handle.tintFromTier, true);
18});
19
20test("ore family builds metal tier defs", () =>
21{
22 const ore = itemDefinition(ItemId.ironOre);
23 assert.equal(ore.familyId, ItemFamilyId.ore);
24 assert.equal(ore.tier, MaterialTier.iron);
25 assert.equal(ore.defaultState, "ore");
26});
27
28test("statBoostPerTier aliases tierStatBonus", () =>
29{
30 assert.equal(statBoostPerTier(MaterialTier.steel), 4);
31});
32
33test("pickaxe tool family includes bronze tier with equipment", () =>
34{
35 const pickaxe = itemDefinition(CraftingItemId.bronzePickaxe);
36 assert.equal(pickaxe.familyId, ItemFamilyId.pickaxe);
37 assert.equal(pickaxe.equipment?.kind, "pickaxeTool");
38});
39
40test("bow family exposes ranged attack profile without base damage", () =>
41{
42 const bow = itemDefinition(RangedItemId.pineBow);
43 assert.equal(bow.familyId, ItemFamilyId.bow);
44 assert.equal(bow.equipment?.attack?.hitSkillId, "archery");
45 assert.equal(bow.equipment?.attack?.baseDamage, undefined);
46});
47
48test("tier family recipes resolve through family item ids", () =>
49{
50 const handle = recipeDefinition("handle-pine");
51 assert.equal(handle.output.itemId, ItemId.pineHandle);
52 const pickaxe = recipeDefinition("pickaxe-bronze");
53 assert.equal(pickaxe.output.itemId, CraftingItemId.bronzePickaxe);
54 assert.equal(pickaxe.inputs.length, 2);
55 const arrow = recipeDefinition("arrow-bronze");
56 assert.equal(arrow.output.itemId, RangedItemId.bronzeArrow);
57 assert.equal(arrow.stationId, CraftingStationId.craftingBench);
58});
server/tests/tint.test.js +28 −1
@@ -3,11 +3,15 @@ import assert from "node:assert/strict";
3 3 import {
4 4 isMagentaTintable,
5 5 magentaTintedRgb,
6 channelDominanceMask,
7 dualChannelTintedRgb,
6 8 tierTintColor,
7 resolveItemTint
9 resolveItemTint,
10 resolveItemDualTint
8 11 } from "../../shared/render/tint.js";
9 12 import { MaterialTier, GatherMaterialId, hexToRgb01, MATERIAL_TINT_HEX, rgb } from "../../shared/definitions/materialTiers.js";
10 13 import { ItemId } from "../../shared/definitions/items.js";
14 import { RangedItemId } from "../../shared/definitions/rangedItems.js";
11 15
12 16 test("magenta tintable when R==B and G < R", () =>
13 17 {
@@ -64,6 +68,29 @@ test("resolveItemTint uses potion instance color and tier tints", () =>
64 68 assert.deepEqual(resolveItemTint({ itemId: ItemId.ironBar }), iron);
65 69 });
66 70
71 test("dual-channel arrow tints shaft red and tip blue, leaves white fletching", () =>
72 {
73 assert.ok(channelDominanceMask(1, 0, 0, "shaft") > 0.9);
74 assert.ok(channelDominanceMask(0, 0, 1, "tip") > 0.9);
75 assert.equal(channelDominanceMask(1, 1, 1, "shaft"), 0);
76 assert.equal(channelDominanceMask(1, 1, 1, "tip"), 0);
77 const bronze = tierTintColor(MaterialTier.bronze);
78 const pine = tierTintColor("pine");
79 const shaftOnly = dualChannelTintedRgb(0.8, 0, 0, pine, bronze);
80 assert.ok(shaftOnly.r > 0.1);
81 assert.ok(shaftOnly.r > shaftOnly.b);
82 const tipOnly = dualChannelTintedRgb(0, 0, 0.8, pine, bronze);
83 assert.ok(tipOnly.b > tipOnly.r || tipOnly.b > 0.05);
84 const white = dualChannelTintedRgb(1, 1, 1, pine, bronze);
85 assert.equal(white.r, 1);
86 assert.equal(white.g, 1);
87 assert.equal(white.b, 1);
88 const dual = resolveItemDualTint({ itemId: RangedItemId.bronzeArrow });
89 assert.ok(dual?.shaft);
90 assert.ok(dual?.tip);
91 assert.equal(resolveItemTint({ itemId: RangedItemId.bronzeArrow }), null);
92 });
93
67 94 test("material tint hex converts to 0-1 rgb at load", () =>
68 95 {
69 96 assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.bronze], rgb(184, 122, 71));
@@ -3,11 +3,15 @@ import assert from "node:assert/strict";
3import {
3import {
4 isMagentaTintable,
4 isMagentaTintable,
5 magentaTintedRgb,
5 magentaTintedRgb,
6 channelDominanceMask,
7 dualChannelTintedRgb,
6 tierTintColor,
8 tierTintColor,
7 resolveItemTint
9 resolveItemTint,
10 resolveItemDualTint
8} from "../../shared/render/tint.js";
11} from "../../shared/render/tint.js";
9import { MaterialTier, GatherMaterialId, hexToRgb01, MATERIAL_TINT_HEX, rgb } from "../../shared/definitions/materialTiers.js";
12import { MaterialTier, GatherMaterialId, hexToRgb01, MATERIAL_TINT_HEX, rgb } from "../../shared/definitions/materialTiers.js";
10import { ItemId } from "../../shared/definitions/items.js";
13import { ItemId } from "../../shared/definitions/items.js";
14import { RangedItemId } from "../../shared/definitions/rangedItems.js";
11
15
12test("magenta tintable when R==B and G < R", () =>
16test("magenta tintable when R==B and G < R", () =>
13{
17{
@@ -64,6 +68,29 @@ test("resolveItemTint uses potion instance color and tier tints", () =>
64 assert.deepEqual(resolveItemTint({ itemId: ItemId.ironBar }), iron);
68 assert.deepEqual(resolveItemTint({ itemId: ItemId.ironBar }), iron);
65});
69});
66
70
71test("dual-channel arrow tints shaft red and tip blue, leaves white fletching", () =>
72{
73 assert.ok(channelDominanceMask(1, 0, 0, "shaft") > 0.9);
74 assert.ok(channelDominanceMask(0, 0, 1, "tip") > 0.9);
75 assert.equal(channelDominanceMask(1, 1, 1, "shaft"), 0);
76 assert.equal(channelDominanceMask(1, 1, 1, "tip"), 0);
77 const bronze = tierTintColor(MaterialTier.bronze);
78 const pine = tierTintColor("pine");
79 const shaftOnly = dualChannelTintedRgb(0.8, 0, 0, pine, bronze);
80 assert.ok(shaftOnly.r > 0.1);
81 assert.ok(shaftOnly.r > shaftOnly.b);
82 const tipOnly = dualChannelTintedRgb(0, 0, 0.8, pine, bronze);
83 assert.ok(tipOnly.b > tipOnly.r || tipOnly.b > 0.05);
84 const white = dualChannelTintedRgb(1, 1, 1, pine, bronze);
85 assert.equal(white.r, 1);
86 assert.equal(white.g, 1);
87 assert.equal(white.b, 1);
88 const dual = resolveItemDualTint({ itemId: RangedItemId.bronzeArrow });
89 assert.ok(dual?.shaft);
90 assert.ok(dual?.tip);
91 assert.equal(resolveItemTint({ itemId: RangedItemId.bronzeArrow }), null);
92});
93
67test("material tint hex converts to 0-1 rgb at load", () =>
94test("material tint hex converts to 0-1 rgb at load", () =>
68{
95{
69 assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.bronze], rgb(184, 122, 71));
96 assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.bronze], rgb(184, 122, 71));
shared/combat/magic.js +3 −3
@@ -55,7 +55,7 @@ function elementalMultiplier (element, targetAffinities = {})
55 55 * @param {number} params.magicSkillLevel
56 56 * @param {number} params.spellDifficulty
57 57 * @param {number} params.mindSkillLevel
58 * @param {number} [params.baseDamage]
58 * @param {number} [params.mindBonus]
59 59 * @param {SpellElement} [params.element]
60 60 * @param {Partial<Record<SpellElement, "weak"|"resistant"|"neutral">>} [params.targetAffinities]
61 61 * @param {() => number} [params.rng]
@@ -64,7 +64,7 @@ export function resolveMagicAttack ({
64 64 magicSkillLevel,
65 65 spellDifficulty,
66 66 mindSkillLevel,
67 baseDamage = 1,
67 mindBonus = 0,
68 68 element = "none",
69 69 targetAffinities = {},
70 70 rng = Math.random
@@ -83,7 +83,7 @@ export function resolveMagicAttack ({
83 83 }
84 84
85 85 const mindRoll = rollSkill(mindSkillLevel, rng);
86 const rawDamage = Math.max(1, (baseDamage | 0) + mindRoll - 1);
86 const rawDamage = Math.max(1, (mindBonus | 0) + mindRoll - (mindBonus ? 1 : 0));
87 87 const multiplier = elementalMultiplier(element, targetAffinities);
88 88 const damage = Math.max(1, Math.floor(rawDamage * multiplier));
89 89
@@ -55,7 +55,7 @@ function elementalMultiplier (element, targetAffinities = {})
55 * @param {number} params.magicSkillLevel
55 * @param {number} params.magicSkillLevel
56 * @param {number} params.spellDifficulty
56 * @param {number} params.spellDifficulty
57 * @param {number} params.mindSkillLevel
57 * @param {number} params.mindSkillLevel
58 * @param {number} [params.baseDamage]
58 * @param {number} [params.mindBonus]
59 * @param {SpellElement} [params.element]
59 * @param {SpellElement} [params.element]
60 * @param {Partial<Record<SpellElement, "weak"|"resistant"|"neutral">>} [params.targetAffinities]
60 * @param {Partial<Record<SpellElement, "weak"|"resistant"|"neutral">>} [params.targetAffinities]
61 * @param {() => number} [params.rng]
61 * @param {() => number} [params.rng]
@@ -64,7 +64,7 @@ export function resolveMagicAttack ({
64 magicSkillLevel,
64 magicSkillLevel,
65 spellDifficulty,
65 spellDifficulty,
66 mindSkillLevel,
66 mindSkillLevel,
67 baseDamage = 1,
67 mindBonus = 0,
68 element = "none",
68 element = "none",
69 targetAffinities = {},
69 targetAffinities = {},
70 rng = Math.random
70 rng = Math.random
@@ -83,7 +83,7 @@ export function resolveMagicAttack ({
83 }
83 }
84
84
85 const mindRoll = rollSkill(mindSkillLevel, rng);
85 const mindRoll = rollSkill(mindSkillLevel, rng);
86 const rawDamage = Math.max(1, (baseDamage | 0) + mindRoll - 1);
86 const rawDamage = Math.max(1, (mindBonus | 0) + mindRoll - (mindBonus ? 1 : 0));
87 const multiplier = elementalMultiplier(element, targetAffinities);
87 const multiplier = elementalMultiplier(element, targetAffinities);
88 const damage = Math.max(1, Math.floor(rawDamage * multiplier));
88 const damage = Math.max(1, Math.floor(rawDamage * multiplier));
89
89
shared/combat/rolls.js +1 −2
@@ -17,7 +17,6 @@ export function resolvePhysicalAttack ({
17 17 agilitySkillLevel,
18 18 damageSkillLevel,
19 19 defenceSkillLevel,
20 baseDamage = 1,
21 20 rng = Math.random
22 21 })
23 22 {
@@ -35,7 +34,7 @@ export function resolvePhysicalAttack ({
35 34 }
36 35
37 36 const damageRoll = rollSkill(damageSkillLevel, rng);
38 const damage = Math.max(1, (baseDamage | 0) + damageRoll - 1);
37 const damage = damageRoll;
39 38 const defenceRoll = rollSkill(defenceSkillLevel, rng);
40 39 if (defenceRoll > toHitRoll)
41 40 {
@@ -17,7 +17,6 @@ export function resolvePhysicalAttack ({
17 agilitySkillLevel,
17 agilitySkillLevel,
18 damageSkillLevel,
18 damageSkillLevel,
19 defenceSkillLevel,
19 defenceSkillLevel,
20 baseDamage = 1,
21 rng = Math.random
20 rng = Math.random
22})
21})
23{
22{
@@ -35,7 +34,7 @@ export function resolvePhysicalAttack ({
35 }
34 }
36
35
37 const damageRoll = rollSkill(damageSkillLevel, rng);
36 const damageRoll = rollSkill(damageSkillLevel, rng);
38 const damage = Math.max(1, (baseDamage | 0) + damageRoll - 1);
37 const damage = damageRoll;
39 const defenceRoll = rollSkill(defenceSkillLevel, rng);
38 const defenceRoll = rollSkill(defenceSkillLevel, rng);
40 if (defenceRoll > toHitRoll)
39 if (defenceRoll > toHitRoll)
41 {
40 {
shared/crafting/stationRecipes.js +3 −218
@@ -1,46 +1,21 @@
1 1 import { CraftingStationId } from "../definitions/craftingStations.js";
2 2 import { ItemId } from "../definitions/items.js";
3 3 import { CraftingItemId } from "../definitions/craftingItems.js";
4 import { MetalItemId } from "../definitions/metalItems.js";
4 5 import {
5 MetalItemId,
6 PICKAXE_HEAD_ITEM_BY_METAL,
7 PICKAXE_ITEM_BY_METAL,
8 AXE_HEAD_ITEM_BY_METAL,
9 AXE_ITEM_BY_METAL,
10 PLANT_CLIPPERS_ITEM_BY_METAL
11 } from "../definitions/metalItems.js";
12 import {
13 WOOD_TIER_ORDER,
14 6 MaterialTier,
15 7 GatherMaterialId,
16 MATERIAL_TIER_ORDER,
17 8 CLOTH_TIER_ORDER,
18 woodTierForMetal,
19 9 tierSmeltSkillLevel,
20 10 tierCraftSkillLevel
21 11 } from "../definitions/materialTiers.js";
22 import {
23 logItemIdForWood,
24 handleItemIdForWood
25 } from "../definitions/woodItems.js";
26 import {
27 ARMOUR_CRAFT_PIECES,
28 armourItemIdForTier
29 } from "../definitions/armourItems.js";
30 12 import {
31 13 rawClothItemId,
32 14 yarnItemId,
33 15 wovenClothItemId,
34 16 CLOTHING_TEMPLATES
35 17 } from "../definitions/clothItems.js";
36 import {
37 arrowShaftRecipe,
38 arrowTipRecipe,
39 arrowAssembleRecipe,
40 unstrungBowRecipe,
41 bowstringRecipe,
42 bowAssembleRecipe
43 } from "../definitions/rangedItems.js";
18 import { TIER_FAMILY_RECIPES } from "./tierRecipes.js";
44 19
45 20 /**
46 21 * Craft recipe schema (shared client + server):
@@ -67,184 +42,6 @@ function smelt (tier, recipeId, inputs, outputItemId)
67 42 });
68 43 }
69 44
70 function handleRecipe (woodTier)
71 {
72 const logId = logItemIdForWood(woodTier);
73 const handleId = handleItemIdForWood(woodTier);
74 return Object.freeze({
75 recipeId: `handle-${woodTier}`,
76 craftGroup: "tool-handle",
77 craftGroupLabel: "Tool handle",
78 stationId: CraftingStationId.woodworkingBench,
79 output: { itemId: handleId, quantity: 1 },
80 inputs: [{ itemId: logId, quantity: 1 }],
81 minSkillLevel: tierCraftSkillLevel(woodTier),
82 skillId: "crafting",
83 xpMaterial: woodTier
84 });
85 }
86
87 function pickaxeHeadRecipe (metalTier, barItemId, headItemId)
88 {
89 return Object.freeze({
90 recipeId: `pickaxe-head-${metalTier}`,
91 craftGroup: "pickaxe-head",
92 craftGroupLabel: "Pickaxe head",
93 stationId: CraftingStationId.anvil,
94 output: { itemId: headItemId, quantity: 1 },
95 inputs: [{ itemId: barItemId, quantity: 1 }],
96 minSkillLevel: tierSmeltSkillLevel(metalTier),
97 skillId: "smithing",
98 xpMaterial: metalTier
99 });
100 }
101
102 function pickaxeAssembleRecipe (metalTier, handleItemId, headItemId, pickaxeItemId)
103 {
104 return Object.freeze({
105 recipeId: `pickaxe-${metalTier}`,
106 stationId: CraftingStationId.craftingBench,
107 output: { itemId: pickaxeItemId, quantity: 1 },
108 inputs: [
109 { itemId: handleItemId, quantity: 1 },
110 { itemId: headItemId, quantity: 1 }
111 ],
112 minSkillLevel: tierCraftSkillLevel(metalTier),
113 skillId: "crafting",
114 xpMaterial: metalTier
115 });
116 }
117
118 function axeHeadRecipe (metalTier, barItemId, headItemId)
119 {
120 return Object.freeze({
121 recipeId: `axe-head-${metalTier}`,
122 craftGroup: "axe-head",
123 craftGroupLabel: "Axe head",
124 stationId: CraftingStationId.anvil,
125 output: { itemId: headItemId, quantity: 1 },
126 inputs: [{ itemId: barItemId, quantity: 1 }],
127 minSkillLevel: tierSmeltSkillLevel(metalTier),
128 skillId: "smithing",
129 xpMaterial: metalTier
130 });
131 }
132
133 function axeAssembleRecipe (metalTier, handleItemId, headItemId, axeItemId)
134 {
135 return Object.freeze({
136 recipeId: `axe-${metalTier}`,
137 stationId: CraftingStationId.craftingBench,
138 output: { itemId: axeItemId, quantity: 1 },
139 inputs: [
140 { itemId: handleItemId, quantity: 1 },
141 { itemId: headItemId, quantity: 1 }
142 ],
143 minSkillLevel: tierCraftSkillLevel(metalTier),
144 skillId: "crafting",
145 xpMaterial: metalTier
146 });
147 }
148
149 function armourRecipe (metalTier, piece)
150 {
151 const outputItemId = armourItemIdForTier(metalTier, piece.idKey);
152 const inputs = [{ itemId: BAR_BY_METAL[metalTier], quantity: piece.ingots }];
153 if (piece.needsBone)
154 { inputs.push({ itemId: ItemId.bones, quantity: 1 }); }
155 const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1);
156 return Object.freeze({
157 recipeId: `armour-${piece.suffix}-${metalTier}`,
158 craftGroup: `armour-${piece.suffix}`,
159 craftGroupLabel: label,
160 stationId: CraftingStationId.anvil,
161 output: { itemId: outputItemId, quantity: 1 },
162 inputs,
163 minSkillLevel: tierSmeltSkillLevel(metalTier),
164 skillId: "smithing",
165 xpMaterial: metalTier
166 });
167 }
168
169 function plantClippersRecipe (metalTier, barItemId, clippersItemId)
170 {
171 return Object.freeze({
172 recipeId: `plant-clippers-${metalTier}`,
173 craftGroup: "plant-clippers",
174 craftGroupLabel: "Plant clippers",
175 stationId: CraftingStationId.anvil,
176 output: { itemId: clippersItemId, quantity: 1 },
177 inputs: [{ itemId: barItemId, quantity: 1 }],
178 minSkillLevel: tierSmeltSkillLevel(metalTier),
179 skillId: "smithing",
180 xpMaterial: metalTier
181 });
182 }
183
184 const BAR_BY_METAL = Object.freeze({
185 [MaterialTier.bronze]: CraftingItemId.bronzeBar,
186 [MaterialTier.iron]: MetalItemId.ironBar,
187 [MaterialTier.steel]: MetalItemId.steelBar,
188 [MaterialTier.mithril]: MetalItemId.mithrilBar,
189 [MaterialTier.adamantium]: MetalItemId.adamantiumBar,
190 [MaterialTier.orichalcum]: MetalItemId.orichalcumBar,
191 [MaterialTier.dragon]: MetalItemId.dragonBar
192 });
193
194 const PICKAXE_BY_METAL = Object.freeze({
195 [MaterialTier.bronze]: CraftingItemId.bronzePickaxe,
196 ...PICKAXE_ITEM_BY_METAL
197 });
198
199 const AXE_BY_METAL = Object.freeze({
200 [MaterialTier.bronze]: CraftingItemId.bronzeAxe,
201 ...AXE_ITEM_BY_METAL
202 });
203
204 const WOOD_HANDLE_RECIPES = WOOD_TIER_ORDER.map((tier) => handleRecipe(tier));
205
206 const PICKAXE_HEAD_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
207 pickaxeHeadRecipe(tier, BAR_BY_METAL[tier], PICKAXE_HEAD_ITEM_BY_METAL[tier]));
208
209 const PICKAXE_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
210 {
211 const wood = woodTierForMetal(tier);
212 return pickaxeAssembleRecipe(
213 tier,
214 handleItemIdForWood(wood),
215 PICKAXE_HEAD_ITEM_BY_METAL[tier],
216 PICKAXE_BY_METAL[tier]
217 );
218 });
219
220 const AXE_HEAD_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
221 axeHeadRecipe(tier, BAR_BY_METAL[tier], AXE_HEAD_ITEM_BY_METAL[tier]));
222
223 const AXE_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
224 {
225 const wood = woodTierForMetal(tier);
226 return axeAssembleRecipe(
227 tier,
228 handleItemIdForWood(wood),
229 AXE_HEAD_ITEM_BY_METAL[tier],
230 AXE_BY_METAL[tier]
231 );
232 });
233
234 const ARMOUR_RECIPES = MATERIAL_TIER_ORDER.flatMap((tier) =>
235 ARMOUR_CRAFT_PIECES.map((piece) => armourRecipe(tier, piece)));
236
237 const PLANT_CLIPPERS_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
238 plantClippersRecipe(tier, BAR_BY_METAL[tier], PLANT_CLIPPERS_ITEM_BY_METAL[tier]));
239
240 const ARROW_SHAFT_RECIPES = WOOD_TIER_ORDER.map((tier) => arrowShaftRecipe(tier));
241 const ARROW_TIP_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
242 arrowTipRecipe(tier, BAR_BY_METAL[tier]));
243 const ARROW_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) => arrowAssembleRecipe(tier));
244 const UNSTRUNG_BOW_RECIPES = WOOD_TIER_ORDER.map((tier) => unstrungBowRecipe(tier));
245 const BOWSTRING_RECIPES = CLOTH_TIER_ORDER.map((tier) => bowstringRecipe(tier));
246 const BOW_ASSEMBLE_RECIPES = WOOD_TIER_ORDER.map((tier) => bowAssembleRecipe(tier));
247
248 45 function yarnSpinRecipe (clothTier)
249 46 {
250 47 return Object.freeze({
@@ -336,19 +133,7 @@ export const CRAFT_RECIPES = Object.freeze([
336 133 { itemId: MetalItemId.coal, quantity: 5 }
337 134 ], MetalItemId.dragonBar),
338 135
339 ...WOOD_HANDLE_RECIPES,
340 ...PICKAXE_HEAD_RECIPES,
341 ...PICKAXE_ASSEMBLE_RECIPES,
342 ...AXE_HEAD_RECIPES,
343 ...AXE_ASSEMBLE_RECIPES,
344 ...ARMOUR_RECIPES,
345 ...PLANT_CLIPPERS_RECIPES,
346 ...ARROW_SHAFT_RECIPES,
347 ...UNSTRUNG_BOW_RECIPES,
348 ...ARROW_TIP_RECIPES,
349 ...BOWSTRING_RECIPES,
350 ...ARROW_ASSEMBLE_RECIPES,
351 ...BOW_ASSEMBLE_RECIPES,
136 ...TIER_FAMILY_RECIPES,
352 137 ...YARN_SPIN_RECIPES,
353 138 ...CLOTH_WEAVE_RECIPES,
354 139 ...TAILOR_TEMPLATE_RECIPES
@@ -1,46 +1,21 @@
1import { CraftingStationId } from "../definitions/craftingStations.js";
1import { CraftingStationId } from "../definitions/craftingStations.js";
2import { ItemId } from "../definitions/items.js";
2import { ItemId } from "../definitions/items.js";
3import { CraftingItemId } from "../definitions/craftingItems.js";
3import { CraftingItemId } from "../definitions/craftingItems.js";
4import { MetalItemId } from "../definitions/metalItems.js";
4import {
5import {
5 MetalItemId,
6 PICKAXE_HEAD_ITEM_BY_METAL,
7 PICKAXE_ITEM_BY_METAL,
8 AXE_HEAD_ITEM_BY_METAL,
9 AXE_ITEM_BY_METAL,
10 PLANT_CLIPPERS_ITEM_BY_METAL
11} from "../definitions/metalItems.js";
12import {
13 WOOD_TIER_ORDER,
14 MaterialTier,
6 MaterialTier,
15 GatherMaterialId,
7 GatherMaterialId,
16 MATERIAL_TIER_ORDER,
17 CLOTH_TIER_ORDER,
8 CLOTH_TIER_ORDER,
18 woodTierForMetal,
19 tierSmeltSkillLevel,
9 tierSmeltSkillLevel,
20 tierCraftSkillLevel
10 tierCraftSkillLevel
21} from "../definitions/materialTiers.js";
11} from "../definitions/materialTiers.js";
22import {
23 logItemIdForWood,
24 handleItemIdForWood
25} from "../definitions/woodItems.js";
26import {
27 ARMOUR_CRAFT_PIECES,
28 armourItemIdForTier
29} from "../definitions/armourItems.js";
30import {
12import {
31 rawClothItemId,
13 rawClothItemId,
32 yarnItemId,
14 yarnItemId,
33 wovenClothItemId,
15 wovenClothItemId,
34 CLOTHING_TEMPLATES
16 CLOTHING_TEMPLATES
35} from "../definitions/clothItems.js";
17} from "../definitions/clothItems.js";
36import {
18import { TIER_FAMILY_RECIPES } from "./tierRecipes.js";
37 arrowShaftRecipe,
38 arrowTipRecipe,
39 arrowAssembleRecipe,
40 unstrungBowRecipe,
41 bowstringRecipe,
42 bowAssembleRecipe
43} from "../definitions/rangedItems.js";
44
19
45/**
20/**
46 * Craft recipe schema (shared client + server):
21 * Craft recipe schema (shared client + server):
@@ -67,184 +42,6 @@ function smelt (tier, recipeId, inputs, outputItemId)
67 });
42 });
68}
43}
69
44
70function handleRecipe (woodTier)
71{
72 const logId = logItemIdForWood(woodTier);
73 const handleId = handleItemIdForWood(woodTier);
74 return Object.freeze({
75 recipeId: `handle-${woodTier}`,
76 craftGroup: "tool-handle",
77 craftGroupLabel: "Tool handle",
78 stationId: CraftingStationId.woodworkingBench,
79 output: { itemId: handleId, quantity: 1 },
80 inputs: [{ itemId: logId, quantity: 1 }],
81 minSkillLevel: tierCraftSkillLevel(woodTier),
82 skillId: "crafting",
83 xpMaterial: woodTier
84 });
85}
86
87function pickaxeHeadRecipe (metalTier, barItemId, headItemId)
88{
89 return Object.freeze({
90 recipeId: `pickaxe-head-${metalTier}`,
91 craftGroup: "pickaxe-head",
92 craftGroupLabel: "Pickaxe head",
93 stationId: CraftingStationId.anvil,
94 output: { itemId: headItemId, quantity: 1 },
95 inputs: [{ itemId: barItemId, quantity: 1 }],
96 minSkillLevel: tierSmeltSkillLevel(metalTier),
97 skillId: "smithing",
98 xpMaterial: metalTier
99 });
100}
101
102function pickaxeAssembleRecipe (metalTier, handleItemId, headItemId, pickaxeItemId)
103{
104 return Object.freeze({
105 recipeId: `pickaxe-${metalTier}`,
106 stationId: CraftingStationId.craftingBench,
107 output: { itemId: pickaxeItemId, quantity: 1 },
108 inputs: [
109 { itemId: handleItemId, quantity: 1 },
110 { itemId: headItemId, quantity: 1 }
111 ],
112 minSkillLevel: tierCraftSkillLevel(metalTier),
113 skillId: "crafting",
114 xpMaterial: metalTier
115 });
116}
117
118function axeHeadRecipe (metalTier, barItemId, headItemId)
119{
120 return Object.freeze({
121 recipeId: `axe-head-${metalTier}`,
122 craftGroup: "axe-head",
123 craftGroupLabel: "Axe head",
124 stationId: CraftingStationId.anvil,
125 output: { itemId: headItemId, quantity: 1 },
126 inputs: [{ itemId: barItemId, quantity: 1 }],
127 minSkillLevel: tierSmeltSkillLevel(metalTier),
128 skillId: "smithing",
129 xpMaterial: metalTier
130 });
131}
132
133function axeAssembleRecipe (metalTier, handleItemId, headItemId, axeItemId)
134{
135 return Object.freeze({
136 recipeId: `axe-${metalTier}`,
137 stationId: CraftingStationId.craftingBench,
138 output: { itemId: axeItemId, quantity: 1 },
139 inputs: [
140 { itemId: handleItemId, quantity: 1 },
141 { itemId: headItemId, quantity: 1 }
142 ],
143 minSkillLevel: tierCraftSkillLevel(metalTier),
144 skillId: "crafting",
145 xpMaterial: metalTier
146 });
147}
148
149function armourRecipe (metalTier, piece)
150{
151 const outputItemId = armourItemIdForTier(metalTier, piece.idKey);
152 const inputs = [{ itemId: BAR_BY_METAL[metalTier], quantity: piece.ingots }];
153 if (piece.needsBone)
154 { inputs.push({ itemId: ItemId.bones, quantity: 1 }); }
155 const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1);
156 return Object.freeze({
157 recipeId: `armour-${piece.suffix}-${metalTier}`,
158 craftGroup: `armour-${piece.suffix}`,
159 craftGroupLabel: label,
160 stationId: CraftingStationId.anvil,
161 output: { itemId: outputItemId, quantity: 1 },
162 inputs,
163 minSkillLevel: tierSmeltSkillLevel(metalTier),
164 skillId: "smithing",
165 xpMaterial: metalTier
166 });
167}
168
169function plantClippersRecipe (metalTier, barItemId, clippersItemId)
170{
171 return Object.freeze({
172 recipeId: `plant-clippers-${metalTier}`,
173 craftGroup: "plant-clippers",
174 craftGroupLabel: "Plant clippers",
175 stationId: CraftingStationId.anvil,
176 output: { itemId: clippersItemId, quantity: 1 },
177 inputs: [{ itemId: barItemId, quantity: 1 }],
178 minSkillLevel: tierSmeltSkillLevel(metalTier),
179 skillId: "smithing",
180 xpMaterial: metalTier
181 });
182}
183
184const BAR_BY_METAL = Object.freeze({
185 [MaterialTier.bronze]: CraftingItemId.bronzeBar,
186 [MaterialTier.iron]: MetalItemId.ironBar,
187 [MaterialTier.steel]: MetalItemId.steelBar,
188 [MaterialTier.mithril]: MetalItemId.mithrilBar,
189 [MaterialTier.adamantium]: MetalItemId.adamantiumBar,
190 [MaterialTier.orichalcum]: MetalItemId.orichalcumBar,
191 [MaterialTier.dragon]: MetalItemId.dragonBar
192});
193
194const PICKAXE_BY_METAL = Object.freeze({
195 [MaterialTier.bronze]: CraftingItemId.bronzePickaxe,
196 ...PICKAXE_ITEM_BY_METAL
197});
198
199const AXE_BY_METAL = Object.freeze({
200 [MaterialTier.bronze]: CraftingItemId.bronzeAxe,
201 ...AXE_ITEM_BY_METAL
202});
203
204const WOOD_HANDLE_RECIPES = WOOD_TIER_ORDER.map((tier) => handleRecipe(tier));
205
206const PICKAXE_HEAD_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
207 pickaxeHeadRecipe(tier, BAR_BY_METAL[tier], PICKAXE_HEAD_ITEM_BY_METAL[tier]));
208
209const PICKAXE_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
210{
211 const wood = woodTierForMetal(tier);
212 return pickaxeAssembleRecipe(
213 tier,
214 handleItemIdForWood(wood),
215 PICKAXE_HEAD_ITEM_BY_METAL[tier],
216 PICKAXE_BY_METAL[tier]
217 );
218});
219
220const AXE_HEAD_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
221 axeHeadRecipe(tier, BAR_BY_METAL[tier], AXE_HEAD_ITEM_BY_METAL[tier]));
222
223const AXE_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
224{
225 const wood = woodTierForMetal(tier);
226 return axeAssembleRecipe(
227 tier,
228 handleItemIdForWood(wood),
229 AXE_HEAD_ITEM_BY_METAL[tier],
230 AXE_BY_METAL[tier]
231 );
232});
233
234const ARMOUR_RECIPES = MATERIAL_TIER_ORDER.flatMap((tier) =>
235 ARMOUR_CRAFT_PIECES.map((piece) => armourRecipe(tier, piece)));
236
237const PLANT_CLIPPERS_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
238 plantClippersRecipe(tier, BAR_BY_METAL[tier], PLANT_CLIPPERS_ITEM_BY_METAL[tier]));
239
240const ARROW_SHAFT_RECIPES = WOOD_TIER_ORDER.map((tier) => arrowShaftRecipe(tier));
241const ARROW_TIP_RECIPES = MATERIAL_TIER_ORDER.map((tier) =>
242 arrowTipRecipe(tier, BAR_BY_METAL[tier]));
243const ARROW_ASSEMBLE_RECIPES = MATERIAL_TIER_ORDER.map((tier) => arrowAssembleRecipe(tier));
244const UNSTRUNG_BOW_RECIPES = WOOD_TIER_ORDER.map((tier) => unstrungBowRecipe(tier));
245const BOWSTRING_RECIPES = CLOTH_TIER_ORDER.map((tier) => bowstringRecipe(tier));
246const BOW_ASSEMBLE_RECIPES = WOOD_TIER_ORDER.map((tier) => bowAssembleRecipe(tier));
247
248function yarnSpinRecipe (clothTier)
45function yarnSpinRecipe (clothTier)
249{
46{
250 return Object.freeze({
47 return Object.freeze({
@@ -336,19 +133,7 @@ export const CRAFT_RECIPES = Object.freeze([
336 { itemId: MetalItemId.coal, quantity: 5 }
133 { itemId: MetalItemId.coal, quantity: 5 }
337 ], MetalItemId.dragonBar),
134 ], MetalItemId.dragonBar),
338
135
339 ...WOOD_HANDLE_RECIPES,
136 ...TIER_FAMILY_RECIPES,
340 ...PICKAXE_HEAD_RECIPES,
341 ...PICKAXE_ASSEMBLE_RECIPES,
342 ...AXE_HEAD_RECIPES,
343 ...AXE_ASSEMBLE_RECIPES,
344 ...ARMOUR_RECIPES,
345 ...PLANT_CLIPPERS_RECIPES,
346 ...ARROW_SHAFT_RECIPES,
347 ...UNSTRUNG_BOW_RECIPES,
348 ...ARROW_TIP_RECIPES,
349 ...BOWSTRING_RECIPES,
350 ...ARROW_ASSEMBLE_RECIPES,
351 ...BOW_ASSEMBLE_RECIPES,
352 ...YARN_SPIN_RECIPES,
137 ...YARN_SPIN_RECIPES,
353 ...CLOTH_WEAVE_RECIPES,
138 ...CLOTH_WEAVE_RECIPES,
354 ...TAILOR_TEMPLATE_RECIPES
139 ...TAILOR_TEMPLATE_RECIPES
shared/crafting/tierRecipes.js added +314 −0
@@ -0,0 +1,314 @@
1 import { CraftingStationId } from "../definitions/craftingStations.js";
2 import { ItemId } from "../definitions/items.js";
3 import { ItemFamilyId } from "../definitions/tierFamilies.js";
4 import { familyItemId } from "../definitions/familyItemIds.js";
5 import {
6 WOOD_TIER_ORDER,
7 MATERIAL_TIER_ORDER,
8 CLOTH_TIER_ORDER,
9 MATERIAL_DISPLAY_NAME,
10 woodTierForMetal,
11 clothTierForWood,
12 tierSmeltSkillLevel,
13 tierCraftSkillLevel,
14 tierMinSkillLevel
15 } from "../definitions/materialTiers.js";
16 import {
17 ARMOUR_CRAFT_PIECES,
18 armourItemIdForTier
19 } from "../definitions/armourItems.js";
20 import { RangedItemId } from "../definitions/rangedItems.js";
21 import { yarnItemId } from "../definitions/clothItems.js";
22
23 /**
24 * Tier-scaled craft recipes generated from {@link ItemFamilyId} templates.
25 * Adding a tier to materialTiers + item id maps extends every matching recipe chain.
26 */
27
28 function tierRecipe ({
29 recipeId,
30 stationId,
31 outputFamily,
32 outputTier,
33 outputQty = 1,
34 inputs,
35 minSkillLevel,
36 skillId,
37 xpMaterial,
38 craftGroup,
39 craftGroupLabel
40 })
41 {
42 const outputItemId = familyItemId(outputFamily, outputTier);
43 if (!outputItemId)
44 { throw new Error(`Missing output item for ${outputFamily}@${outputTier}`); }
45 return Object.freeze({
46 recipeId,
47 stationId,
48 output: { itemId: outputItemId, quantity: outputQty },
49 inputs,
50 minSkillLevel,
51 skillId,
52 xpMaterial,
53 ...(craftGroup ? { craftGroup, craftGroupLabel } : {})
54 });
55 }
56
57 function handleRecipes ()
58 {
59 return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({
60 recipeId: `handle-${woodTier}`,
61 craftGroup: "tool-handle",
62 craftGroupLabel: "Tool handle",
63 stationId: CraftingStationId.woodworkingBench,
64 outputFamily: ItemFamilyId.handle,
65 outputTier: woodTier,
66 inputs: [{ itemId: familyItemId(ItemFamilyId.log, woodTier), quantity: 1 }],
67 minSkillLevel: tierCraftSkillLevel(woodTier),
68 skillId: "crafting",
69 xpMaterial: woodTier
70 }));
71 }
72
73 function pickaxeHeadRecipes ()
74 {
75 return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({
76 recipeId: `pickaxe-head-${metalTier}`,
77 craftGroup: "pickaxe-head",
78 craftGroupLabel: "Pickaxe head",
79 stationId: CraftingStationId.anvil,
80 outputFamily: ItemFamilyId.pickaxeHead,
81 outputTier: metalTier,
82 inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }],
83 minSkillLevel: tierSmeltSkillLevel(metalTier),
84 skillId: "smithing",
85 xpMaterial: metalTier
86 }));
87 }
88
89 function pickaxeAssembleRecipes ()
90 {
91 return MATERIAL_TIER_ORDER.map((metalTier) =>
92 {
93 const woodTier = woodTierForMetal(metalTier);
94 return tierRecipe({
95 recipeId: `pickaxe-${metalTier}`,
96 stationId: CraftingStationId.craftingBench,
97 outputFamily: ItemFamilyId.pickaxe,
98 outputTier: metalTier,
99 inputs: [
100 { itemId: familyItemId(ItemFamilyId.handle, woodTier), quantity: 1 },
101 { itemId: familyItemId(ItemFamilyId.pickaxeHead, metalTier), quantity: 1 }
102 ],
103 minSkillLevel: tierCraftSkillLevel(metalTier),
104 skillId: "crafting",
105 xpMaterial: metalTier
106 });
107 });
108 }
109
110 function axeHeadRecipes ()
111 {
112 return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({
113 recipeId: `axe-head-${metalTier}`,
114 craftGroup: "axe-head",
115 craftGroupLabel: "Axe head",
116 stationId: CraftingStationId.anvil,
117 outputFamily: ItemFamilyId.axeHead,
118 outputTier: metalTier,
119 inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }],
120 minSkillLevel: tierSmeltSkillLevel(metalTier),
121 skillId: "smithing",
122 xpMaterial: metalTier
123 }));
124 }
125
126 function axeAssembleRecipes ()
127 {
128 return MATERIAL_TIER_ORDER.map((metalTier) =>
129 {
130 const woodTier = woodTierForMetal(metalTier);
131 return tierRecipe({
132 recipeId: `axe-${metalTier}`,
133 stationId: CraftingStationId.craftingBench,
134 outputFamily: ItemFamilyId.axe,
135 outputTier: metalTier,
136 inputs: [
137 { itemId: familyItemId(ItemFamilyId.handle, woodTier), quantity: 1 },
138 { itemId: familyItemId(ItemFamilyId.axeHead, metalTier), quantity: 1 }
139 ],
140 minSkillLevel: tierCraftSkillLevel(metalTier),
141 skillId: "crafting",
142 xpMaterial: metalTier
143 });
144 });
145 }
146
147 function plantClippersRecipes ()
148 {
149 return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({
150 recipeId: `plant-clippers-${metalTier}`,
151 craftGroup: "plant-clippers",
152 craftGroupLabel: "Plant clippers",
153 stationId: CraftingStationId.anvil,
154 outputFamily: ItemFamilyId.plantClippers,
155 outputTier: metalTier,
156 inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }],
157 minSkillLevel: tierSmeltSkillLevel(metalTier),
158 skillId: "smithing",
159 xpMaterial: metalTier
160 }));
161 }
162
163 function arrowShaftRecipes ()
164 {
165 return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({
166 recipeId: `arrow-shafts-${woodTier}`,
167 craftGroup: "arrow-shafts",
168 craftGroupLabel: "Arrow shafts",
169 stationId: CraftingStationId.woodworkingBench,
170 outputFamily: ItemFamilyId.arrowShaft,
171 outputTier: woodTier,
172 outputQty: 15,
173 inputs: [{ itemId: familyItemId(ItemFamilyId.log, woodTier), quantity: 1 }],
174 minSkillLevel: tierMinSkillLevel(woodTier),
175 skillId: "crafting",
176 xpMaterial: woodTier
177 }));
178 }
179
180 function arrowTipRecipes ()
181 {
182 return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({
183 recipeId: `arrow-tips-${metalTier}`,
184 craftGroup: "arrow-tips",
185 craftGroupLabel: "Arrow tips",
186 stationId: CraftingStationId.anvil,
187 outputFamily: ItemFamilyId.arrowTip,
188 outputTier: metalTier,
189 outputQty: 15,
190 inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }],
191 minSkillLevel: tierMinSkillLevel(metalTier),
192 skillId: "smithing",
193 xpMaterial: metalTier
194 }));
195 }
196
197 function arrowAssembleRecipes ()
198 {
199 return MATERIAL_TIER_ORDER.map((metalTier) =>
200 {
201 const woodTier = woodTierForMetal(metalTier);
202 return tierRecipe({
203 recipeId: `arrow-${metalTier}`,
204 craftGroup: `arrow-${metalTier}`,
205 craftGroupLabel: `${MATERIAL_DISPLAY_NAME[metalTier] ?? metalTier} arrow`,
206 stationId: CraftingStationId.craftingBench,
207 outputFamily: ItemFamilyId.arrow,
208 outputTier: metalTier,
209 inputs: [
210 { itemId: RangedItemId.feather, quantity: 1 },
211 { itemId: familyItemId(ItemFamilyId.arrowShaft, woodTier), quantity: 1 },
212 { itemId: familyItemId(ItemFamilyId.arrowTip, metalTier), quantity: 1 }
213 ],
214 minSkillLevel: tierMinSkillLevel(metalTier),
215 skillId: "crafting",
216 xpMaterial: metalTier
217 });
218 });
219 }
220
221 function unstrungBowRecipes ()
222 {
223 return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({
224 recipeId: `unstrung-bow-${woodTier}`,
225 craftGroup: "unstrung-bow",
226 craftGroupLabel: "Unstrung bow",
227 stationId: CraftingStationId.woodworkingBench,
228 outputFamily: ItemFamilyId.unstrungBow,
229 outputTier: woodTier,
230 inputs: [{ itemId: familyItemId(ItemFamilyId.log, woodTier), quantity: 1 }],
231 minSkillLevel: tierMinSkillLevel(woodTier),
232 skillId: "crafting",
233 xpMaterial: woodTier
234 }));
235 }
236
237 function bowstringRecipes ()
238 {
239 return CLOTH_TIER_ORDER.map((clothTier) => tierRecipe({
240 recipeId: `bowstring-${clothTier}`,
241 craftGroup: "bowstring",
242 craftGroupLabel: "Bowstring",
243 stationId: CraftingStationId.spinningWheel,
244 outputFamily: ItemFamilyId.bowstring,
245 outputTier: clothTier,
246 inputs: [{ itemId: yarnItemId(clothTier), quantity: 1 }],
247 minSkillLevel: tierMinSkillLevel(clothTier),
248 skillId: "tailoring",
249 xpMaterial: clothTier
250 }));
251 }
252
253 function bowAssembleRecipes ()
254 {
255 return WOOD_TIER_ORDER.map((woodTier) =>
256 {
257 const clothTier = clothTierForWood(woodTier);
258 return tierRecipe({
259 recipeId: `bow-${woodTier}`,
260 craftGroup: `bow-${woodTier}`,
261 craftGroupLabel: `${MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier} bow`,
262 stationId: CraftingStationId.craftingBench,
263 outputFamily: ItemFamilyId.bow,
264 outputTier: woodTier,
265 inputs: [
266 { itemId: familyItemId(ItemFamilyId.unstrungBow, woodTier), quantity: 1 },
267 { itemId: familyItemId(ItemFamilyId.bowstring, clothTier), quantity: 1 }
268 ],
269 minSkillLevel: tierMinSkillLevel(woodTier),
270 skillId: "crafting",
271 xpMaterial: woodTier
272 });
273 });
274 }
275
276 function armourRecipes ()
277 {
278 return MATERIAL_TIER_ORDER.flatMap((metalTier) =>
279 ARMOUR_CRAFT_PIECES.map((piece) =>
280 {
281 const inputs = [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: piece.ingots }];
282 if (piece.needsBone)
283 { inputs.push({ itemId: ItemId.bones, quantity: 1 }); }
284 const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1);
285 return Object.freeze({
286 recipeId: `armour-${piece.suffix}-${metalTier}`,
287 craftGroup: `armour-${piece.suffix}`,
288 craftGroupLabel: label,
289 stationId: CraftingStationId.anvil,
290 output: { itemId: armourItemIdForTier(metalTier, piece.idKey), quantity: 1 },
291 inputs,
292 minSkillLevel: tierSmeltSkillLevel(metalTier),
293 skillId: "smithing",
294 xpMaterial: metalTier
295 });
296 }));
297 }
298
299 /** All recipes driven by tier families (tools, wood/metal intermediates, ranged). */
300 export const TIER_FAMILY_RECIPES = Object.freeze([
301 ...handleRecipes(),
302 ...pickaxeHeadRecipes(),
303 ...pickaxeAssembleRecipes(),
304 ...axeHeadRecipes(),
305 ...axeAssembleRecipes(),
306 ...plantClippersRecipes(),
307 ...arrowShaftRecipes(),
308 ...arrowTipRecipes(),
309 ...arrowAssembleRecipes(),
310 ...unstrungBowRecipes(),
311 ...bowstringRecipes(),
312 ...bowAssembleRecipes(),
313 ...armourRecipes()
314 ]);
@@ -0,0 +1,314 @@
1import { CraftingStationId } from "../definitions/craftingStations.js";
2import { ItemId } from "../definitions/items.js";
3import { ItemFamilyId } from "../definitions/tierFamilies.js";
4import { familyItemId } from "../definitions/familyItemIds.js";
5import {
6 WOOD_TIER_ORDER,
7 MATERIAL_TIER_ORDER,
8 CLOTH_TIER_ORDER,
9 MATERIAL_DISPLAY_NAME,
10 woodTierForMetal,
11 clothTierForWood,
12 tierSmeltSkillLevel,
13 tierCraftSkillLevel,
14 tierMinSkillLevel
15} from "../definitions/materialTiers.js";
16import {
17 ARMOUR_CRAFT_PIECES,
18 armourItemIdForTier
19} from "../definitions/armourItems.js";
20import { RangedItemId } from "../definitions/rangedItems.js";
21import { yarnItemId } from "../definitions/clothItems.js";
22
23/**
24 * Tier-scaled craft recipes generated from {@link ItemFamilyId} templates.
25 * Adding a tier to materialTiers + item id maps extends every matching recipe chain.
26 */
27
28function tierRecipe ({
29 recipeId,
30 stationId,
31 outputFamily,
32 outputTier,
33 outputQty = 1,
34 inputs,
35 minSkillLevel,
36 skillId,
37 xpMaterial,
38 craftGroup,
39 craftGroupLabel
40})
41{
42 const outputItemId = familyItemId(outputFamily, outputTier);
43 if (!outputItemId)
44 { throw new Error(`Missing output item for ${outputFamily}@${outputTier}`); }
45 return Object.freeze({
46 recipeId,
47 stationId,
48 output: { itemId: outputItemId, quantity: outputQty },
49 inputs,
50 minSkillLevel,
51 skillId,
52 xpMaterial,
53 ...(craftGroup ? { craftGroup, craftGroupLabel } : {})
54 });
55}
56
57function handleRecipes ()
58{
59 return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({
60 recipeId: `handle-${woodTier}`,
61 craftGroup: "tool-handle",
62 craftGroupLabel: "Tool handle",
63 stationId: CraftingStationId.woodworkingBench,
64 outputFamily: ItemFamilyId.handle,
65 outputTier: woodTier,
66 inputs: [{ itemId: familyItemId(ItemFamilyId.log, woodTier), quantity: 1 }],
67 minSkillLevel: tierCraftSkillLevel(woodTier),
68 skillId: "crafting",
69 xpMaterial: woodTier
70 }));
71}
72
73function pickaxeHeadRecipes ()
74{
75 return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({
76 recipeId: `pickaxe-head-${metalTier}`,
77 craftGroup: "pickaxe-head",
78 craftGroupLabel: "Pickaxe head",
79 stationId: CraftingStationId.anvil,
80 outputFamily: ItemFamilyId.pickaxeHead,
81 outputTier: metalTier,
82 inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }],
83 minSkillLevel: tierSmeltSkillLevel(metalTier),
84 skillId: "smithing",
85 xpMaterial: metalTier
86 }));
87}
88
89function pickaxeAssembleRecipes ()
90{
91 return MATERIAL_TIER_ORDER.map((metalTier) =>
92 {
93 const woodTier = woodTierForMetal(metalTier);
94 return tierRecipe({
95 recipeId: `pickaxe-${metalTier}`,
96 stationId: CraftingStationId.craftingBench,
97 outputFamily: ItemFamilyId.pickaxe,
98 outputTier: metalTier,
99 inputs: [
100 { itemId: familyItemId(ItemFamilyId.handle, woodTier), quantity: 1 },
101 { itemId: familyItemId(ItemFamilyId.pickaxeHead, metalTier), quantity: 1 }
102 ],
103 minSkillLevel: tierCraftSkillLevel(metalTier),
104 skillId: "crafting",
105 xpMaterial: metalTier
106 });
107 });
108}
109
110function axeHeadRecipes ()
111{
112 return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({
113 recipeId: `axe-head-${metalTier}`,
114 craftGroup: "axe-head",
115 craftGroupLabel: "Axe head",
116 stationId: CraftingStationId.anvil,
117 outputFamily: ItemFamilyId.axeHead,
118 outputTier: metalTier,
119 inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }],
120 minSkillLevel: tierSmeltSkillLevel(metalTier),
121 skillId: "smithing",
122 xpMaterial: metalTier
123 }));
124}
125
126function axeAssembleRecipes ()
127{
128 return MATERIAL_TIER_ORDER.map((metalTier) =>
129 {
130 const woodTier = woodTierForMetal(metalTier);
131 return tierRecipe({
132 recipeId: `axe-${metalTier}`,
133 stationId: CraftingStationId.craftingBench,
134 outputFamily: ItemFamilyId.axe,
135 outputTier: metalTier,
136 inputs: [
137 { itemId: familyItemId(ItemFamilyId.handle, woodTier), quantity: 1 },
138 { itemId: familyItemId(ItemFamilyId.axeHead, metalTier), quantity: 1 }
139 ],
140 minSkillLevel: tierCraftSkillLevel(metalTier),
141 skillId: "crafting",
142 xpMaterial: metalTier
143 });
144 });
145}
146
147function plantClippersRecipes ()
148{
149 return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({
150 recipeId: `plant-clippers-${metalTier}`,
151 craftGroup: "plant-clippers",
152 craftGroupLabel: "Plant clippers",
153 stationId: CraftingStationId.anvil,
154 outputFamily: ItemFamilyId.plantClippers,
155 outputTier: metalTier,
156 inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }],
157 minSkillLevel: tierSmeltSkillLevel(metalTier),
158 skillId: "smithing",
159 xpMaterial: metalTier
160 }));
161}
162
163function arrowShaftRecipes ()
164{
165 return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({
166 recipeId: `arrow-shafts-${woodTier}`,
167 craftGroup: "arrow-shafts",
168 craftGroupLabel: "Arrow shafts",
169 stationId: CraftingStationId.woodworkingBench,
170 outputFamily: ItemFamilyId.arrowShaft,
171 outputTier: woodTier,
172 outputQty: 15,
173 inputs: [{ itemId: familyItemId(ItemFamilyId.log, woodTier), quantity: 1 }],
174 minSkillLevel: tierMinSkillLevel(woodTier),
175 skillId: "crafting",
176 xpMaterial: woodTier
177 }));
178}
179
180function arrowTipRecipes ()
181{
182 return MATERIAL_TIER_ORDER.map((metalTier) => tierRecipe({
183 recipeId: `arrow-tips-${metalTier}`,
184 craftGroup: "arrow-tips",
185 craftGroupLabel: "Arrow tips",
186 stationId: CraftingStationId.anvil,
187 outputFamily: ItemFamilyId.arrowTip,
188 outputTier: metalTier,
189 outputQty: 15,
190 inputs: [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: 1 }],
191 minSkillLevel: tierMinSkillLevel(metalTier),
192 skillId: "smithing",
193 xpMaterial: metalTier
194 }));
195}
196
197function arrowAssembleRecipes ()
198{
199 return MATERIAL_TIER_ORDER.map((metalTier) =>
200 {
201 const woodTier = woodTierForMetal(metalTier);
202 return tierRecipe({
203 recipeId: `arrow-${metalTier}`,
204 craftGroup: `arrow-${metalTier}`,
205 craftGroupLabel: `${MATERIAL_DISPLAY_NAME[metalTier] ?? metalTier} arrow`,
206 stationId: CraftingStationId.craftingBench,
207 outputFamily: ItemFamilyId.arrow,
208 outputTier: metalTier,
209 inputs: [
210 { itemId: RangedItemId.feather, quantity: 1 },
211 { itemId: familyItemId(ItemFamilyId.arrowShaft, woodTier), quantity: 1 },
212 { itemId: familyItemId(ItemFamilyId.arrowTip, metalTier), quantity: 1 }
213 ],
214 minSkillLevel: tierMinSkillLevel(metalTier),
215 skillId: "crafting",
216 xpMaterial: metalTier
217 });
218 });
219}
220
221function unstrungBowRecipes ()
222{
223 return WOOD_TIER_ORDER.map((woodTier) => tierRecipe({
224 recipeId: `unstrung-bow-${woodTier}`,
225 craftGroup: "unstrung-bow",
226 craftGroupLabel: "Unstrung bow",
227 stationId: CraftingStationId.woodworkingBench,
228 outputFamily: ItemFamilyId.unstrungBow,
229 outputTier: woodTier,
230 inputs: [{ itemId: familyItemId(ItemFamilyId.log, woodTier), quantity: 1 }],
231 minSkillLevel: tierMinSkillLevel(woodTier),
232 skillId: "crafting",
233 xpMaterial: woodTier
234 }));
235}
236
237function bowstringRecipes ()
238{
239 return CLOTH_TIER_ORDER.map((clothTier) => tierRecipe({
240 recipeId: `bowstring-${clothTier}`,
241 craftGroup: "bowstring",
242 craftGroupLabel: "Bowstring",
243 stationId: CraftingStationId.spinningWheel,
244 outputFamily: ItemFamilyId.bowstring,
245 outputTier: clothTier,
246 inputs: [{ itemId: yarnItemId(clothTier), quantity: 1 }],
247 minSkillLevel: tierMinSkillLevel(clothTier),
248 skillId: "tailoring",
249 xpMaterial: clothTier
250 }));
251}
252
253function bowAssembleRecipes ()
254{
255 return WOOD_TIER_ORDER.map((woodTier) =>
256 {
257 const clothTier = clothTierForWood(woodTier);
258 return tierRecipe({
259 recipeId: `bow-${woodTier}`,
260 craftGroup: `bow-${woodTier}`,
261 craftGroupLabel: `${MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier} bow`,
262 stationId: CraftingStationId.craftingBench,
263 outputFamily: ItemFamilyId.bow,
264 outputTier: woodTier,
265 inputs: [
266 { itemId: familyItemId(ItemFamilyId.unstrungBow, woodTier), quantity: 1 },
267 { itemId: familyItemId(ItemFamilyId.bowstring, clothTier), quantity: 1 }
268 ],
269 minSkillLevel: tierMinSkillLevel(woodTier),
270 skillId: "crafting",
271 xpMaterial: woodTier
272 });
273 });
274}
275
276function armourRecipes ()
277{
278 return MATERIAL_TIER_ORDER.flatMap((metalTier) =>
279 ARMOUR_CRAFT_PIECES.map((piece) =>
280 {
281 const inputs = [{ itemId: familyItemId(ItemFamilyId.bar, metalTier), quantity: piece.ingots }];
282 if (piece.needsBone)
283 { inputs.push({ itemId: ItemId.bones, quantity: 1 }); }
284 const label = piece.label.charAt(0).toUpperCase() + piece.label.slice(1);
285 return Object.freeze({
286 recipeId: `armour-${piece.suffix}-${metalTier}`,
287 craftGroup: `armour-${piece.suffix}`,
288 craftGroupLabel: label,
289 stationId: CraftingStationId.anvil,
290 output: { itemId: armourItemIdForTier(metalTier, piece.idKey), quantity: 1 },
291 inputs,
292 minSkillLevel: tierSmeltSkillLevel(metalTier),
293 skillId: "smithing",
294 xpMaterial: metalTier
295 });
296 }));
297}
298
299/** All recipes driven by tier families (tools, wood/metal intermediates, ranged). */
300export const TIER_FAMILY_RECIPES = Object.freeze([
301 ...handleRecipes(),
302 ...pickaxeHeadRecipes(),
303 ...pickaxeAssembleRecipes(),
304 ...axeHeadRecipes(),
305 ...axeAssembleRecipes(),
306 ...plantClippersRecipes(),
307 ...arrowShaftRecipes(),
308 ...arrowTipRecipes(),
309 ...arrowAssembleRecipes(),
310 ...unstrungBowRecipes(),
311 ...bowstringRecipes(),
312 ...bowAssembleRecipes(),
313 ...armourRecipes()
314]);
shared/definitions/craftingItems.js +0 −39
@@ -1,6 +1,5 @@
1 1 import { ItemCategory } from "./itemCategories.js";
2 2 import { MaterialTier, GatherMaterialId } from "./materialTiers.js";
3 import { EquipmentKind } from "./equipmentKinds.js";
4 3
5 4 const DEFAULT_STACK = 99;
6 5
@@ -105,44 +104,6 @@ export const CRAFTING_ITEM_STUBS = Object.freeze({
105 104 [CraftingItemId.leather]: stub(CraftingItemId.leather, "leather", "Leather", ItemCategory.ingredient, {
106 105 description: "Cured hide, stout enough for armour and straps."
107 106 }),
108 [CraftingItemId.bronzeAxe]: Object.freeze({
109 itemId: CraftingItemId.bronzeAxe,
110 key: "bronze-axe",
111 displayName: "Bronze axe",
112 description: "A bronze axe for felling trees.",
113 seedValue: 8,
114 stackable: false,
115 maxStackSize: 1,
116 uniqueInstance: false,
117 category: ItemCategory.tool,
118 iconKey: "axe",
119 defaultState: "axe",
120 tintFromTier: true,
121 equipment: Object.freeze({
122 slot: "weapon",
123 tier: MaterialTier.bronze,
124 kind: EquipmentKind.axeTool
125 })
126 }),
127 [CraftingItemId.bronzePickaxe]: Object.freeze({
128 itemId: CraftingItemId.bronzePickaxe,
129 key: "bronze-pickaxe",
130 displayName: "Bronze pickaxe",
131 description: "A bronze pickaxe for breaking stone and ore.",
132 seedValue: 8,
133 stackable: false,
134 maxStackSize: 1,
135 uniqueInstance: false,
136 category: ItemCategory.tool,
137 iconKey: "pickaxe",
138 defaultState: "pickaxe",
139 tintFromTier: true,
140 equipment: Object.freeze({
141 slot: "weapon",
142 tier: MaterialTier.bronze,
143 kind: EquipmentKind.pickaxeTool
144 })
145 }),
146 107 [CraftingItemId.fishingRod]: stub(CraftingItemId.fishingRod, "fishing-rod", "Fishing rod", ItemCategory.tool, {
147 108 stackable: false,
148 109 maxStackSize: 1,
@@ -1,6 +1,5 @@
1import { ItemCategory } from "./itemCategories.js";
1import { ItemCategory } from "./itemCategories.js";
2import { MaterialTier, GatherMaterialId } from "./materialTiers.js";
2import { MaterialTier, GatherMaterialId } from "./materialTiers.js";
3import { EquipmentKind } from "./equipmentKinds.js";
4
3
5const DEFAULT_STACK = 99;
4const DEFAULT_STACK = 99;
6
5
@@ -105,44 +104,6 @@ export const CRAFTING_ITEM_STUBS = Object.freeze({
105 [CraftingItemId.leather]: stub(CraftingItemId.leather, "leather", "Leather", ItemCategory.ingredient, {
104 [CraftingItemId.leather]: stub(CraftingItemId.leather, "leather", "Leather", ItemCategory.ingredient, {
106 description: "Cured hide, stout enough for armour and straps."
105 description: "Cured hide, stout enough for armour and straps."
107 }),
106 }),
108 [CraftingItemId.bronzeAxe]: Object.freeze({
109 itemId: CraftingItemId.bronzeAxe,
110 key: "bronze-axe",
111 displayName: "Bronze axe",
112 description: "A bronze axe for felling trees.",
113 seedValue: 8,
114 stackable: false,
115 maxStackSize: 1,
116 uniqueInstance: false,
117 category: ItemCategory.tool,
118 iconKey: "axe",
119 defaultState: "axe",
120 tintFromTier: true,
121 equipment: Object.freeze({
122 slot: "weapon",
123 tier: MaterialTier.bronze,
124 kind: EquipmentKind.axeTool
125 })
126 }),
127 [CraftingItemId.bronzePickaxe]: Object.freeze({
128 itemId: CraftingItemId.bronzePickaxe,
129 key: "bronze-pickaxe",
130 displayName: "Bronze pickaxe",
131 description: "A bronze pickaxe for breaking stone and ore.",
132 seedValue: 8,
133 stackable: false,
134 maxStackSize: 1,
135 uniqueInstance: false,
136 category: ItemCategory.tool,
137 iconKey: "pickaxe",
138 defaultState: "pickaxe",
139 tintFromTier: true,
140 equipment: Object.freeze({
141 slot: "weapon",
142 tier: MaterialTier.bronze,
143 kind: EquipmentKind.pickaxeTool
144 })
145 }),
146 [CraftingItemId.fishingRod]: stub(CraftingItemId.fishingRod, "fishing-rod", "Fishing rod", ItemCategory.tool, {
107 [CraftingItemId.fishingRod]: stub(CraftingItemId.fishingRod, "fishing-rod", "Fishing rod", ItemCategory.tool, {
147 stackable: false,
108 stackable: false,
148 maxStackSize: 1,
109 maxStackSize: 1,
shared/definitions/familyItemIds.js added +41 −0
@@ -0,0 +1,41 @@
1 import { ItemFamilyId, itemIdForFamilyTier } from "./tierFamilies.js";
2 import { LOG_ITEM_BY_WOOD, HANDLE_ITEM_BY_WOOD } from "./woodItems.js";
3 import {
4 BAR_ITEM_BY_METAL,
5 PICKAXE_HEAD_ITEM_BY_METAL,
6 AXE_HEAD_ITEM_BY_METAL,
7 PICKAXE_ITEM_BY_METAL,
8 AXE_ITEM_BY_METAL,
9 PLANT_CLIPPERS_ITEM_BY_METAL
10 } from "./metalItems.js";
11 import {
12 ARROW_SHAFT_BY_WOOD,
13 ARROW_TIP_BY_METAL,
14 ARROW_BY_METAL,
15 UNSTRUNG_BOW_BY_WOOD,
16 BOWSTRING_BY_CLOTH,
17 BOW_BY_WOOD
18 } from "./rangedItems.js";
19
20 /** Tier → itemId lookup tables keyed by {@link ItemFamilyId}. */
21 export const FAMILY_ITEM_IDS = Object.freeze({
22 [ItemFamilyId.log]: LOG_ITEM_BY_WOOD,
23 [ItemFamilyId.handle]: HANDLE_ITEM_BY_WOOD,
24 [ItemFamilyId.bar]: BAR_ITEM_BY_METAL,
25 [ItemFamilyId.pickaxeHead]: PICKAXE_HEAD_ITEM_BY_METAL,
26 [ItemFamilyId.axeHead]: AXE_HEAD_ITEM_BY_METAL,
27 [ItemFamilyId.pickaxe]: PICKAXE_ITEM_BY_METAL,
28 [ItemFamilyId.axe]: AXE_ITEM_BY_METAL,
29 [ItemFamilyId.plantClippers]: PLANT_CLIPPERS_ITEM_BY_METAL,
30 [ItemFamilyId.arrowShaft]: ARROW_SHAFT_BY_WOOD,
31 [ItemFamilyId.arrowTip]: ARROW_TIP_BY_METAL,
32 [ItemFamilyId.arrow]: ARROW_BY_METAL,
33 [ItemFamilyId.unstrungBow]: UNSTRUNG_BOW_BY_WOOD,
34 [ItemFamilyId.bowstring]: BOWSTRING_BY_CLOTH,
35 [ItemFamilyId.bow]: BOW_BY_WOOD
36 });
37
38 export function familyItemId (familyId, tier)
39 {
40 return itemIdForFamilyTier(FAMILY_ITEM_IDS[familyId], tier);
41 }
@@ -0,0 +1,41 @@
1import { ItemFamilyId, itemIdForFamilyTier } from "./tierFamilies.js";
2import { LOG_ITEM_BY_WOOD, HANDLE_ITEM_BY_WOOD } from "./woodItems.js";
3import {
4 BAR_ITEM_BY_METAL,
5 PICKAXE_HEAD_ITEM_BY_METAL,
6 AXE_HEAD_ITEM_BY_METAL,
7 PICKAXE_ITEM_BY_METAL,
8 AXE_ITEM_BY_METAL,
9 PLANT_CLIPPERS_ITEM_BY_METAL
10} from "./metalItems.js";
11import {
12 ARROW_SHAFT_BY_WOOD,
13 ARROW_TIP_BY_METAL,
14 ARROW_BY_METAL,
15 UNSTRUNG_BOW_BY_WOOD,
16 BOWSTRING_BY_CLOTH,
17 BOW_BY_WOOD
18} from "./rangedItems.js";
19
20/** Tier → itemId lookup tables keyed by {@link ItemFamilyId}. */
21export const FAMILY_ITEM_IDS = Object.freeze({
22 [ItemFamilyId.log]: LOG_ITEM_BY_WOOD,
23 [ItemFamilyId.handle]: HANDLE_ITEM_BY_WOOD,
24 [ItemFamilyId.bar]: BAR_ITEM_BY_METAL,
25 [ItemFamilyId.pickaxeHead]: PICKAXE_HEAD_ITEM_BY_METAL,
26 [ItemFamilyId.axeHead]: AXE_HEAD_ITEM_BY_METAL,
27 [ItemFamilyId.pickaxe]: PICKAXE_ITEM_BY_METAL,
28 [ItemFamilyId.axe]: AXE_ITEM_BY_METAL,
29 [ItemFamilyId.plantClippers]: PLANT_CLIPPERS_ITEM_BY_METAL,
30 [ItemFamilyId.arrowShaft]: ARROW_SHAFT_BY_WOOD,
31 [ItemFamilyId.arrowTip]: ARROW_TIP_BY_METAL,
32 [ItemFamilyId.arrow]: ARROW_BY_METAL,
33 [ItemFamilyId.unstrungBow]: UNSTRUNG_BOW_BY_WOOD,
34 [ItemFamilyId.bowstring]: BOWSTRING_BY_CLOTH,
35 [ItemFamilyId.bow]: BOW_BY_WOOD
36});
37
38export function familyItemId (familyId, tier)
39{
40 return itemIdForFamilyTier(FAMILY_ITEM_IDS[familyId], tier);
41}
shared/definitions/items.js +1 −2
@@ -127,8 +127,7 @@ export const ITEM_DEFINITIONS = Object.freeze({
127 127 hitSkillId: SkillId.clubfighting,
128 128 damageSkillId: SkillId.strength,
129 129 attackType: AttackType.blunt,
130 cooldownMs: 700,
131 baseDamage: 2
130 cooldownMs: 700
132 131 })
133 132 })
134 133 }),
@@ -127,8 +127,7 @@ export const ITEM_DEFINITIONS = Object.freeze({
127 hitSkillId: SkillId.clubfighting,
127 hitSkillId: SkillId.clubfighting,
128 damageSkillId: SkillId.strength,
128 damageSkillId: SkillId.strength,
129 attackType: AttackType.blunt,
129 attackType: AttackType.blunt,
130 cooldownMs: 700,
130 cooldownMs: 700
131 baseDamage: 2
132 })
131 })
133 })
132 })
134 }),
133 }),
shared/definitions/materialTiers.js +3 −0
@@ -378,6 +378,9 @@ export function tierStatBonus (tier)
378 378 return TIER_STAT_BONUS[tier] ?? TIER_STAT_BONUS[MaterialTier.bronze];
379 379 }
380 380
381 /** Alias for equipment combat boosts derived from material tier. */
382 export const statBoostPerTier = tierStatBonus;
383
381 384 export function tierMinSkillLevel (tier)
382 385 {
383 386 return TIER_MIN_SKILL_LEVEL[tier] ?? TIER_MIN_SKILL_LEVEL[MaterialTier.bronze];
@@ -378,6 +378,9 @@ export function tierStatBonus (tier)
378 return TIER_STAT_BONUS[tier] ?? TIER_STAT_BONUS[MaterialTier.bronze];
378 return TIER_STAT_BONUS[tier] ?? TIER_STAT_BONUS[MaterialTier.bronze];
379}
379}
380
380
381/** Alias for equipment combat boosts derived from material tier. */
382export const statBoostPerTier = tierStatBonus;
383
381export function tierMinSkillLevel (tier)
384export function tierMinSkillLevel (tier)
382{
385{
383 return TIER_MIN_SKILL_LEVEL[tier] ?? TIER_MIN_SKILL_LEVEL[MaterialTier.bronze];
386 return TIER_MIN_SKILL_LEVEL[tier] ?? TIER_MIN_SKILL_LEVEL[MaterialTier.bronze];
shared/definitions/metalItems.js +66 −266
@@ -1,10 +1,13 @@
1 1 import { ItemCategory } from "./itemCategories.js";
2 2 import {
3 3 MaterialTier,
4 GatherMaterialId,
5 MATERIAL_DISPLAY_NAME
4 GatherMaterialId
6 5 } from "./materialTiers.js";
7 import { EquipmentKind } from "./equipmentKinds.js";
6 import { CraftingItemId } from "./craftingItems.js";
7 import {
8 ItemFamilyId,
9 buildFamilyDefinitionMap
10 } from "./tierFamilies.js";
8 11
9 12 /**
10 13 * Metal ores, bars, pickaxes/axes, and coal.
@@ -65,262 +68,31 @@ export const MetalItemId = Object.freeze({
65 68
66 69 const DEFAULT_STACK = 99;
67 70
68 function oreDef (itemId, tier, key)
69 {
70 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
71 return Object.freeze({
72 itemId,
73 key,
74 displayName: `${name} ore`,
75 description: `Mined ${name.toLowerCase()} ore. Smelt at a furnace.`,
76 seedValue: 2,
77 stackable: true,
78 maxStackSize: DEFAULT_STACK,
79 uniqueInstance: false,
80 category: ItemCategory.ingredient,
81 iconKey: "metal",
82 defaultState: "ore",
83 tier,
84 tintFromTier: true
85 });
86 }
87
88 function barDef (itemId, tier, key)
89 {
90 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
91 return Object.freeze({
92 itemId,
93 key,
94 displayName: `${name} bar`,
95 description: `Smelted ${name.toLowerCase()}. Smith at an anvil.`,
96 seedValue: 4,
97 stackable: true,
98 maxStackSize: DEFAULT_STACK,
99 uniqueInstance: false,
100 category: ItemCategory.intermediate,
101 iconKey: "metal",
102 defaultState: "bar",
103 tier,
104 tintFromTier: true
105 });
106 }
107
108 function pickaxeHeadDef (itemId, tier, key)
109 {
110 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
111 return Object.freeze({
112 itemId,
113 key,
114 displayName: `${name} pickaxe head`,
115 description: `Smithed ${name.toLowerCase()} head. Attach a matching handle at a crafting bench.`,
116 seedValue: 5,
117 stackable: true,
118 maxStackSize: DEFAULT_STACK,
119 uniqueInstance: false,
120 category: ItemCategory.intermediate,
121 iconKey: "pickaxe",
122 defaultState: "pickaxe-head",
123 tier,
124 tintFromTier: true
125 });
126 }
127
128 function pickaxeDef (itemId, tier, key)
129 {
130 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
131 return Object.freeze({
132 itemId,
133 key,
134 displayName: `${name} pickaxe`,
135 description: `A ${name.toLowerCase()} pickaxe for breaking stone and ore.`,
136 seedValue: 8,
137 stackable: false,
138 maxStackSize: 1,
139 uniqueInstance: false,
140 category: ItemCategory.tool,
141 iconKey: "pickaxe",
142 defaultState: "pickaxe",
143 tintFromTier: true,
144 equipment: Object.freeze({
145 slot: "weapon",
146 tier,
147 kind: EquipmentKind.pickaxeTool
148 })
149 });
150 }
151
152 function axeHeadDef (itemId, tier, key)
153 {
154 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
155 return Object.freeze({
156 itemId,
157 key,
158 displayName: `${name} axe head`,
159 description: `Smithed ${name.toLowerCase()} head. Attach a matching handle at a crafting bench.`,
160 seedValue: 5,
161 stackable: true,
162 maxStackSize: DEFAULT_STACK,
163 uniqueInstance: false,
164 category: ItemCategory.intermediate,
165 iconKey: "axe",
166 defaultState: "axe-head",
167 tier,
168 tintFromTier: true
169 });
170 }
171
172 function axeDef (itemId, tier, key)
173 {
174 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
175 return Object.freeze({
176 itemId,
177 key,
178 displayName: `${name} axe`,
179 description: `A ${name.toLowerCase()} axe for felling trees.`,
180 seedValue: 8,
181 stackable: false,
182 maxStackSize: 1,
183 uniqueInstance: false,
184 category: ItemCategory.tool,
185 iconKey: "axe",
186 defaultState: "axe",
187 tintFromTier: true,
188 equipment: Object.freeze({
189 slot: "weapon",
190 tier,
191 kind: EquipmentKind.axeTool
192 })
193 });
194 }
71 const ORE_BY_TIER = Object.freeze({
72 [MaterialTier.iron]: MetalItemId.ironOre,
73 [MaterialTier.mithril]: MetalItemId.mithrilOre,
74 [MaterialTier.adamantium]: MetalItemId.adamantiumOre,
75 [MaterialTier.orichalcum]: MetalItemId.orichalcumOre,
76 [MaterialTier.dragon]: MetalItemId.dragonOre,
77 [GatherMaterialId.gold]: MetalItemId.goldOre,
78 [GatherMaterialId.silver]: MetalItemId.silverOre
79 });
195 80
196 function plantClippersDef (itemId, tier, key)
197 {
198 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
199 return Object.freeze({
200 itemId,
201 key,
202 displayName: `${name} plant clippers`,
203 description: "Fine shears for cutting herbs and blooms.",
204 seedValue: 10,
205 stackable: false,
206 maxStackSize: 1,
207 uniqueInstance: false,
208 category: ItemCategory.tool,
209 npcShopAllowed: true,
210 /** Shared magenta art under items/bronze-plant-clippers (tinted per tier). */
211 iconKey: "bronze-plant-clippers",
212 defaultState: "bronze-plant-clippers",
213 tintFromTier: true,
214 equipment: Object.freeze({
215 slot: "weapon",
216 tier,
217 kind: EquipmentKind.plantClippers,
218 tintFromTier: true
219 })
220 });
221 }
81 /** Smelted bars used in smithing recipes (bronze bar lives on CraftingItemId). */
82 export const BAR_ITEM_BY_METAL = Object.freeze({
83 [MaterialTier.bronze]: CraftingItemId.bronzeBar,
84 [MaterialTier.iron]: MetalItemId.ironBar,
85 [MaterialTier.steel]: MetalItemId.steelBar,
86 [MaterialTier.mithril]: MetalItemId.mithrilBar,
87 [MaterialTier.adamantium]: MetalItemId.adamantiumBar,
88 [MaterialTier.orichalcum]: MetalItemId.orichalcumBar,
89 [MaterialTier.dragon]: MetalItemId.dragonBar
90 });
222 91
223 /** Full defs for metal family (merged into ITEM_DEFINITIONS). */
224 export const METAL_ITEM_DEFINITIONS = Object.freeze({
225 [MetalItemId.coal]: Object.freeze({
226 itemId: MetalItemId.coal,
227 key: "coal",
228 displayName: "Coal",
229 description: "Dark coal, hot enough to harden steel.",
230 seedValue: 2,
231 stackable: true,
232 maxStackSize: DEFAULT_STACK,
233 uniqueInstance: false,
234 category: ItemCategory.ingredient,
235 iconKey: "metal",
236 defaultState: "ore",
237 tier: GatherMaterialId.coal,
238 tintFromTier: true
239 }),
240 [MetalItemId.bronzePickaxeHead]: pickaxeHeadDef(
241 MetalItemId.bronzePickaxeHead,
242 MaterialTier.bronze,
243 "bronze-pickaxe-head"
244 ),
245 [MetalItemId.bronzeAxeHead]: axeHeadDef(
246 MetalItemId.bronzeAxeHead,
247 MaterialTier.bronze,
248 "bronze-axe-head"
249 ),
250 [MetalItemId.ironOre]: oreDef(MetalItemId.ironOre, MaterialTier.iron, "iron-ore"),
251 [MetalItemId.ironBar]: barDef(MetalItemId.ironBar, MaterialTier.iron, "iron-bar"),
252 [MetalItemId.ironPickaxe]: pickaxeDef(MetalItemId.ironPickaxe, MaterialTier.iron, "iron-pickaxe"),
253 [MetalItemId.ironPickaxeHead]: pickaxeHeadDef(MetalItemId.ironPickaxeHead, MaterialTier.iron, "iron-pickaxe-head"),
254 [MetalItemId.ironAxe]: axeDef(MetalItemId.ironAxe, MaterialTier.iron, "iron-axe"),
255 [MetalItemId.ironAxeHead]: axeHeadDef(MetalItemId.ironAxeHead, MaterialTier.iron, "iron-axe-head"),
256 [MetalItemId.goldOre]: oreDef(MetalItemId.goldOre, GatherMaterialId.gold, "gold-ore"),
257 [MetalItemId.goldBar]: barDef(MetalItemId.goldBar, GatherMaterialId.gold, "gold-bar"),
258 [MetalItemId.silverOre]: oreDef(MetalItemId.silverOre, GatherMaterialId.silver, "silver-ore"),
259 [MetalItemId.silverBar]: barDef(MetalItemId.silverBar, GatherMaterialId.silver, "silver-bar"),
260 [MetalItemId.steelBar]: barDef(MetalItemId.steelBar, MaterialTier.steel, "steel-bar"),
261 [MetalItemId.steelPickaxe]: pickaxeDef(MetalItemId.steelPickaxe, MaterialTier.steel, "steel-pickaxe"),
262 [MetalItemId.steelPickaxeHead]: pickaxeHeadDef(MetalItemId.steelPickaxeHead, MaterialTier.steel, "steel-pickaxe-head"),
263 [MetalItemId.steelAxe]: axeDef(MetalItemId.steelAxe, MaterialTier.steel, "steel-axe"),
264 [MetalItemId.steelAxeHead]: axeHeadDef(MetalItemId.steelAxeHead, MaterialTier.steel, "steel-axe-head"),
265 [MetalItemId.mithrilOre]: oreDef(MetalItemId.mithrilOre, MaterialTier.mithril, "mithril-ore"),
266 [MetalItemId.mithrilBar]: barDef(MetalItemId.mithrilBar, MaterialTier.mithril, "mithril-bar"),
267 [MetalItemId.mithrilPickaxe]: pickaxeDef(MetalItemId.mithrilPickaxe, MaterialTier.mithril, "mithril-pickaxe"),
268 [MetalItemId.mithrilPickaxeHead]: pickaxeHeadDef(MetalItemId.mithrilPickaxeHead, MaterialTier.mithril, "mithril-pickaxe-head"),
269 [MetalItemId.mithrilAxe]: axeDef(MetalItemId.mithrilAxe, MaterialTier.mithril, "mithril-axe"),
270 [MetalItemId.mithrilAxeHead]: axeHeadDef(MetalItemId.mithrilAxeHead, MaterialTier.mithril, "mithril-axe-head"),
271 [MetalItemId.adamantiumOre]: oreDef(MetalItemId.adamantiumOre, MaterialTier.adamantium, "adamantium-ore"),
272 [MetalItemId.adamantiumBar]: barDef(MetalItemId.adamantiumBar, MaterialTier.adamantium, "adamantium-bar"),
273 [MetalItemId.adamantiumPickaxe]: pickaxeDef(MetalItemId.adamantiumPickaxe, MaterialTier.adamantium, "adamantium-pickaxe"),
274 [MetalItemId.adamantiumPickaxeHead]: pickaxeHeadDef(MetalItemId.adamantiumPickaxeHead, MaterialTier.adamantium, "adamantium-pickaxe-head"),
275 [MetalItemId.adamantiumAxe]: axeDef(MetalItemId.adamantiumAxe, MaterialTier.adamantium, "adamantium-axe"),
276 [MetalItemId.adamantiumAxeHead]: axeHeadDef(MetalItemId.adamantiumAxeHead, MaterialTier.adamantium, "adamantium-axe-head"),
277 [MetalItemId.orichalcumOre]: oreDef(MetalItemId.orichalcumOre, MaterialTier.orichalcum, "orichalcum-ore"),
278 [MetalItemId.orichalcumBar]: barDef(MetalItemId.orichalcumBar, MaterialTier.orichalcum, "orichalcum-bar"),
279 [MetalItemId.orichalcumPickaxe]: pickaxeDef(MetalItemId.orichalcumPickaxe, MaterialTier.orichalcum, "orichalcum-pickaxe"),
280 [MetalItemId.orichalcumPickaxeHead]: pickaxeHeadDef(MetalItemId.orichalcumPickaxeHead, MaterialTier.orichalcum, "orichalcum-pickaxe-head"),
281 [MetalItemId.orichalcumAxe]: axeDef(MetalItemId.orichalcumAxe, MaterialTier.orichalcum, "orichalcum-axe"),
282 [MetalItemId.orichalcumAxeHead]: axeHeadDef(MetalItemId.orichalcumAxeHead, MaterialTier.orichalcum, "orichalcum-axe-head"),
283 [MetalItemId.dragonOre]: oreDef(MetalItemId.dragonOre, MaterialTier.dragon, "dragon-ore"),
284 [MetalItemId.dragonBar]: barDef(MetalItemId.dragonBar, MaterialTier.dragon, "dragon-bar"),
285 [MetalItemId.dragonPickaxe]: pickaxeDef(MetalItemId.dragonPickaxe, MaterialTier.dragon, "dragon-pickaxe"),
286 [MetalItemId.dragonPickaxeHead]: pickaxeHeadDef(MetalItemId.dragonPickaxeHead, MaterialTier.dragon, "dragon-pickaxe-head"),
287 [MetalItemId.dragonAxe]: axeDef(MetalItemId.dragonAxe, MaterialTier.dragon, "dragon-axe"),
288 [MetalItemId.dragonAxeHead]: axeHeadDef(MetalItemId.dragonAxeHead, MaterialTier.dragon, "dragon-axe-head"),
289 [MetalItemId.bronzePlantClippers]: plantClippersDef(
290 MetalItemId.bronzePlantClippers,
291 MaterialTier.bronze,
292 "bronze-plant-clippers"
293 ),
294 [MetalItemId.ironPlantClippers]: plantClippersDef(
295 MetalItemId.ironPlantClippers,
296 MaterialTier.iron,
297 "iron-plant-clippers"
298 ),
299 [MetalItemId.steelPlantClippers]: plantClippersDef(
300 MetalItemId.steelPlantClippers,
301 MaterialTier.steel,
302 "steel-plant-clippers"
303 ),
304 [MetalItemId.mithrilPlantClippers]: plantClippersDef(
305 MetalItemId.mithrilPlantClippers,
306 MaterialTier.mithril,
307 "mithril-plant-clippers"
308 ),
309 [MetalItemId.adamantiumPlantClippers]: plantClippersDef(
310 MetalItemId.adamantiumPlantClippers,
311 MaterialTier.adamantium,
312 "adamantium-plant-clippers"
313 ),
314 [MetalItemId.orichalcumPlantClippers]: plantClippersDef(
315 MetalItemId.orichalcumPlantClippers,
316 MaterialTier.orichalcum,
317 "orichalcum-plant-clippers"
318 ),
319 [MetalItemId.dragonPlantClippers]: plantClippersDef(
320 MetalItemId.dragonPlantClippers,
321 MaterialTier.dragon,
322 "dragon-plant-clippers"
323 )
92 const BAR_BY_TIER = Object.freeze({
93 ...BAR_ITEM_BY_METAL,
94 [GatherMaterialId.gold]: MetalItemId.goldBar,
95 [GatherMaterialId.silver]: MetalItemId.silverBar
324 96 });
325 97
326 98 /** Pickaxe head item id by metal tier. */
@@ -334,15 +106,6 @@ export const PICKAXE_HEAD_ITEM_BY_METAL = Object.freeze({
334 106 [MaterialTier.dragon]: MetalItemId.dragonPickaxeHead
335 107 });
336 108
337 export const PICKAXE_ITEM_BY_METAL = Object.freeze({
338 [MaterialTier.iron]: MetalItemId.ironPickaxe,
339 [MaterialTier.steel]: MetalItemId.steelPickaxe,
340 [MaterialTier.mithril]: MetalItemId.mithrilPickaxe,
341 [MaterialTier.adamantium]: MetalItemId.adamantiumPickaxe,
342 [MaterialTier.orichalcum]: MetalItemId.orichalcumPickaxe,
343 [MaterialTier.dragon]: MetalItemId.dragonPickaxe
344 });
345
346 109 /** Axe head item id by metal tier. */
347 110 export const AXE_HEAD_ITEM_BY_METAL = Object.freeze({
348 111 [MaterialTier.bronze]: MetalItemId.bronzeAxeHead,
@@ -354,7 +117,18 @@ export const AXE_HEAD_ITEM_BY_METAL = Object.freeze({
354 117 [MaterialTier.dragon]: MetalItemId.dragonAxeHead
355 118 });
356 119
120 export const PICKAXE_ITEM_BY_METAL = Object.freeze({
121 [MaterialTier.bronze]: CraftingItemId.bronzePickaxe,
122 [MaterialTier.iron]: MetalItemId.ironPickaxe,
123 [MaterialTier.steel]: MetalItemId.steelPickaxe,
124 [MaterialTier.mithril]: MetalItemId.mithrilPickaxe,
125 [MaterialTier.adamantium]: MetalItemId.adamantiumPickaxe,
126 [MaterialTier.orichalcum]: MetalItemId.orichalcumPickaxe,
127 [MaterialTier.dragon]: MetalItemId.dragonPickaxe
128 });
129
357 130 export const AXE_ITEM_BY_METAL = Object.freeze({
131 [MaterialTier.bronze]: CraftingItemId.bronzeAxe,
358 132 [MaterialTier.iron]: MetalItemId.ironAxe,
359 133 [MaterialTier.steel]: MetalItemId.steelAxe,
360 134 [MaterialTier.mithril]: MetalItemId.mithrilAxe,
@@ -373,3 +147,29 @@ export const PLANT_CLIPPERS_ITEM_BY_METAL = Object.freeze({
373 147 [MaterialTier.orichalcum]: MetalItemId.orichalcumPlantClippers,
374 148 [MaterialTier.dragon]: MetalItemId.dragonPlantClippers
375 149 });
150
151 /** Full defs for metal family (merged into ITEM_DEFINITIONS). */
152 export const METAL_ITEM_DEFINITIONS = Object.freeze({
153 ...buildFamilyDefinitionMap(ItemFamilyId.ore, ORE_BY_TIER),
154 ...buildFamilyDefinitionMap(ItemFamilyId.bar, BAR_BY_TIER),
155 ...buildFamilyDefinitionMap(ItemFamilyId.pickaxeHead, PICKAXE_HEAD_ITEM_BY_METAL),
156 ...buildFamilyDefinitionMap(ItemFamilyId.axeHead, AXE_HEAD_ITEM_BY_METAL),
157 ...buildFamilyDefinitionMap(ItemFamilyId.pickaxe, PICKAXE_ITEM_BY_METAL),
158 ...buildFamilyDefinitionMap(ItemFamilyId.axe, AXE_ITEM_BY_METAL),
159 ...buildFamilyDefinitionMap(ItemFamilyId.plantClippers, PLANT_CLIPPERS_ITEM_BY_METAL),
160 [MetalItemId.coal]: Object.freeze({
161 itemId: MetalItemId.coal,
162 key: "coal",
163 displayName: "Coal",
164 description: "Dark coal, hot enough to harden steel.",
165 seedValue: 2,
166 stackable: true,
167 maxStackSize: DEFAULT_STACK,
168 uniqueInstance: false,
169 category: ItemCategory.ingredient,
170 iconKey: "metal",
171 defaultState: "ore",
172 tier: GatherMaterialId.coal,
173 tintFromTier: true
174 })
175 });
@@ -1,10 +1,13 @@
1import { ItemCategory } from "./itemCategories.js";
1import { ItemCategory } from "./itemCategories.js";
2import {
2import {
3 MaterialTier,
3 MaterialTier,
4 GatherMaterialId,
4 GatherMaterialId
5 MATERIAL_DISPLAY_NAME
6} from "./materialTiers.js";
5} from "./materialTiers.js";
7import { EquipmentKind } from "./equipmentKinds.js";
6import { CraftingItemId } from "./craftingItems.js";
7import {
8 ItemFamilyId,
9 buildFamilyDefinitionMap
10} from "./tierFamilies.js";
8
11
9/**
12/**
10 * Metal ores, bars, pickaxes/axes, and coal.
13 * Metal ores, bars, pickaxes/axes, and coal.
@@ -65,262 +68,31 @@ export const MetalItemId = Object.freeze({
65
68
66const DEFAULT_STACK = 99;
69const DEFAULT_STACK = 99;
67
70
68function oreDef (itemId, tier, key)
71const ORE_BY_TIER = Object.freeze({
69{
72 [MaterialTier.iron]: MetalItemId.ironOre,
70 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
73 [MaterialTier.mithril]: MetalItemId.mithrilOre,
71 return Object.freeze({
74 [MaterialTier.adamantium]: MetalItemId.adamantiumOre,
72 itemId,
75 [MaterialTier.orichalcum]: MetalItemId.orichalcumOre,
73 key,
76 [MaterialTier.dragon]: MetalItemId.dragonOre,
74 displayName: `${name} ore`,
77 [GatherMaterialId.gold]: MetalItemId.goldOre,
75 description: `Mined ${name.toLowerCase()} ore. Smelt at a furnace.`,
78 [GatherMaterialId.silver]: MetalItemId.silverOre
76 seedValue: 2,
79});
77 stackable: true,
78 maxStackSize: DEFAULT_STACK,
79 uniqueInstance: false,
80 category: ItemCategory.ingredient,
81 iconKey: "metal",
82 defaultState: "ore",
83 tier,
84 tintFromTier: true
85 });
86}
87
88function barDef (itemId, tier, key)
89{
90 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
91 return Object.freeze({
92 itemId,
93 key,
94 displayName: `${name} bar`,
95 description: `Smelted ${name.toLowerCase()}. Smith at an anvil.`,
96 seedValue: 4,
97 stackable: true,
98 maxStackSize: DEFAULT_STACK,
99 uniqueInstance: false,
100 category: ItemCategory.intermediate,
101 iconKey: "metal",
102 defaultState: "bar",
103 tier,
104 tintFromTier: true
105 });
106}
107
108function pickaxeHeadDef (itemId, tier, key)
109{
110 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
111 return Object.freeze({
112 itemId,
113 key,
114 displayName: `${name} pickaxe head`,
115 description: `Smithed ${name.toLowerCase()} head. Attach a matching handle at a crafting bench.`,
116 seedValue: 5,
117 stackable: true,
118 maxStackSize: DEFAULT_STACK,
119 uniqueInstance: false,
120 category: ItemCategory.intermediate,
121 iconKey: "pickaxe",
122 defaultState: "pickaxe-head",
123 tier,
124 tintFromTier: true
125 });
126}
127
128function pickaxeDef (itemId, tier, key)
129{
130 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
131 return Object.freeze({
132 itemId,
133 key,
134 displayName: `${name} pickaxe`,
135 description: `A ${name.toLowerCase()} pickaxe for breaking stone and ore.`,
136 seedValue: 8,
137 stackable: false,
138 maxStackSize: 1,
139 uniqueInstance: false,
140 category: ItemCategory.tool,
141 iconKey: "pickaxe",
142 defaultState: "pickaxe",
143 tintFromTier: true,
144 equipment: Object.freeze({
145 slot: "weapon",
146 tier,
147 kind: EquipmentKind.pickaxeTool
148 })
149 });
150}
151
152function axeHeadDef (itemId, tier, key)
153{
154 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
155 return Object.freeze({
156 itemId,
157 key,
158 displayName: `${name} axe head`,
159 description: `Smithed ${name.toLowerCase()} head. Attach a matching handle at a crafting bench.`,
160 seedValue: 5,
161 stackable: true,
162 maxStackSize: DEFAULT_STACK,
163 uniqueInstance: false,
164 category: ItemCategory.intermediate,
165 iconKey: "axe",
166 defaultState: "axe-head",
167 tier,
168 tintFromTier: true
169 });
170}
171
172function axeDef (itemId, tier, key)
173{
174 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
175 return Object.freeze({
176 itemId,
177 key,
178 displayName: `${name} axe`,
179 description: `A ${name.toLowerCase()} axe for felling trees.`,
180 seedValue: 8,
181 stackable: false,
182 maxStackSize: 1,
183 uniqueInstance: false,
184 category: ItemCategory.tool,
185 iconKey: "axe",
186 defaultState: "axe",
187 tintFromTier: true,
188 equipment: Object.freeze({
189 slot: "weapon",
190 tier,
191 kind: EquipmentKind.axeTool
192 })
193 });
194}
195
80
196function plantClippersDef (itemId, tier, key)
81/** Smelted bars used in smithing recipes (bronze bar lives on CraftingItemId). */
197{
82export const BAR_ITEM_BY_METAL = Object.freeze({
198 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
83 [MaterialTier.bronze]: CraftingItemId.bronzeBar,
199 return Object.freeze({
84 [MaterialTier.iron]: MetalItemId.ironBar,
200 itemId,
85 [MaterialTier.steel]: MetalItemId.steelBar,
201 key,
86 [MaterialTier.mithril]: MetalItemId.mithrilBar,
202 displayName: `${name} plant clippers`,
87 [MaterialTier.adamantium]: MetalItemId.adamantiumBar,
203 description: "Fine shears for cutting herbs and blooms.",
88 [MaterialTier.orichalcum]: MetalItemId.orichalcumBar,
204 seedValue: 10,
89 [MaterialTier.dragon]: MetalItemId.dragonBar
205 stackable: false,
90});
206 maxStackSize: 1,
207 uniqueInstance: false,
208 category: ItemCategory.tool,
209 npcShopAllowed: true,
210 /** Shared magenta art under items/bronze-plant-clippers (tinted per tier). */
211 iconKey: "bronze-plant-clippers",
212 defaultState: "bronze-plant-clippers",
213 tintFromTier: true,
214 equipment: Object.freeze({
215 slot: "weapon",
216 tier,
217 kind: EquipmentKind.plantClippers,
218 tintFromTier: true
219 })
220 });
221}
222
91
223/** Full defs for metal family (merged into ITEM_DEFINITIONS). */
92const BAR_BY_TIER = Object.freeze({
224export const METAL_ITEM_DEFINITIONS = Object.freeze({
93 ...BAR_ITEM_BY_METAL,
225 [MetalItemId.coal]: Object.freeze({
94 [GatherMaterialId.gold]: MetalItemId.goldBar,
226 itemId: MetalItemId.coal,
95 [GatherMaterialId.silver]: MetalItemId.silverBar
227 key: "coal",
228 displayName: "Coal",
229 description: "Dark coal, hot enough to harden steel.",
230 seedValue: 2,
231 stackable: true,
232 maxStackSize: DEFAULT_STACK,
233 uniqueInstance: false,
234 category: ItemCategory.ingredient,
235 iconKey: "metal",
236 defaultState: "ore",
237 tier: GatherMaterialId.coal,
238 tintFromTier: true
239 }),
240 [MetalItemId.bronzePickaxeHead]: pickaxeHeadDef(
241 MetalItemId.bronzePickaxeHead,
242 MaterialTier.bronze,
243 "bronze-pickaxe-head"
244 ),
245 [MetalItemId.bronzeAxeHead]: axeHeadDef(
246 MetalItemId.bronzeAxeHead,
247 MaterialTier.bronze,
248 "bronze-axe-head"
249 ),
250 [MetalItemId.ironOre]: oreDef(MetalItemId.ironOre, MaterialTier.iron, "iron-ore"),
251 [MetalItemId.ironBar]: barDef(MetalItemId.ironBar, MaterialTier.iron, "iron-bar"),
252 [MetalItemId.ironPickaxe]: pickaxeDef(MetalItemId.ironPickaxe, MaterialTier.iron, "iron-pickaxe"),
253 [MetalItemId.ironPickaxeHead]: pickaxeHeadDef(MetalItemId.ironPickaxeHead, MaterialTier.iron, "iron-pickaxe-head"),
254 [MetalItemId.ironAxe]: axeDef(MetalItemId.ironAxe, MaterialTier.iron, "iron-axe"),
255 [MetalItemId.ironAxeHead]: axeHeadDef(MetalItemId.ironAxeHead, MaterialTier.iron, "iron-axe-head"),
256 [MetalItemId.goldOre]: oreDef(MetalItemId.goldOre, GatherMaterialId.gold, "gold-ore"),
257 [MetalItemId.goldBar]: barDef(MetalItemId.goldBar, GatherMaterialId.gold, "gold-bar"),
258 [MetalItemId.silverOre]: oreDef(MetalItemId.silverOre, GatherMaterialId.silver, "silver-ore"),
259 [MetalItemId.silverBar]: barDef(MetalItemId.silverBar, GatherMaterialId.silver, "silver-bar"),
260 [MetalItemId.steelBar]: barDef(MetalItemId.steelBar, MaterialTier.steel, "steel-bar"),
261 [MetalItemId.steelPickaxe]: pickaxeDef(MetalItemId.steelPickaxe, MaterialTier.steel, "steel-pickaxe"),
262 [MetalItemId.steelPickaxeHead]: pickaxeHeadDef(MetalItemId.steelPickaxeHead, MaterialTier.steel, "steel-pickaxe-head"),
263 [MetalItemId.steelAxe]: axeDef(MetalItemId.steelAxe, MaterialTier.steel, "steel-axe"),
264 [MetalItemId.steelAxeHead]: axeHeadDef(MetalItemId.steelAxeHead, MaterialTier.steel, "steel-axe-head"),
265 [MetalItemId.mithrilOre]: oreDef(MetalItemId.mithrilOre, MaterialTier.mithril, "mithril-ore"),
266 [MetalItemId.mithrilBar]: barDef(MetalItemId.mithrilBar, MaterialTier.mithril, "mithril-bar"),
267 [MetalItemId.mithrilPickaxe]: pickaxeDef(MetalItemId.mithrilPickaxe, MaterialTier.mithril, "mithril-pickaxe"),
268 [MetalItemId.mithrilPickaxeHead]: pickaxeHeadDef(MetalItemId.mithrilPickaxeHead, MaterialTier.mithril, "mithril-pickaxe-head"),
269 [MetalItemId.mithrilAxe]: axeDef(MetalItemId.mithrilAxe, MaterialTier.mithril, "mithril-axe"),
270 [MetalItemId.mithrilAxeHead]: axeHeadDef(MetalItemId.mithrilAxeHead, MaterialTier.mithril, "mithril-axe-head"),
271 [MetalItemId.adamantiumOre]: oreDef(MetalItemId.adamantiumOre, MaterialTier.adamantium, "adamantium-ore"),
272 [MetalItemId.adamantiumBar]: barDef(MetalItemId.adamantiumBar, MaterialTier.adamantium, "adamantium-bar"),
273 [MetalItemId.adamantiumPickaxe]: pickaxeDef(MetalItemId.adamantiumPickaxe, MaterialTier.adamantium, "adamantium-pickaxe"),
274 [MetalItemId.adamantiumPickaxeHead]: pickaxeHeadDef(MetalItemId.adamantiumPickaxeHead, MaterialTier.adamantium, "adamantium-pickaxe-head"),
275 [MetalItemId.adamantiumAxe]: axeDef(MetalItemId.adamantiumAxe, MaterialTier.adamantium, "adamantium-axe"),
276 [MetalItemId.adamantiumAxeHead]: axeHeadDef(MetalItemId.adamantiumAxeHead, MaterialTier.adamantium, "adamantium-axe-head"),
277 [MetalItemId.orichalcumOre]: oreDef(MetalItemId.orichalcumOre, MaterialTier.orichalcum, "orichalcum-ore"),
278 [MetalItemId.orichalcumBar]: barDef(MetalItemId.orichalcumBar, MaterialTier.orichalcum, "orichalcum-bar"),
279 [MetalItemId.orichalcumPickaxe]: pickaxeDef(MetalItemId.orichalcumPickaxe, MaterialTier.orichalcum, "orichalcum-pickaxe"),
280 [MetalItemId.orichalcumPickaxeHead]: pickaxeHeadDef(MetalItemId.orichalcumPickaxeHead, MaterialTier.orichalcum, "orichalcum-pickaxe-head"),
281 [MetalItemId.orichalcumAxe]: axeDef(MetalItemId.orichalcumAxe, MaterialTier.orichalcum, "orichalcum-axe"),
282 [MetalItemId.orichalcumAxeHead]: axeHeadDef(MetalItemId.orichalcumAxeHead, MaterialTier.orichalcum, "orichalcum-axe-head"),
283 [MetalItemId.dragonOre]: oreDef(MetalItemId.dragonOre, MaterialTier.dragon, "dragon-ore"),
284 [MetalItemId.dragonBar]: barDef(MetalItemId.dragonBar, MaterialTier.dragon, "dragon-bar"),
285 [MetalItemId.dragonPickaxe]: pickaxeDef(MetalItemId.dragonPickaxe, MaterialTier.dragon, "dragon-pickaxe"),
286 [MetalItemId.dragonPickaxeHead]: pickaxeHeadDef(MetalItemId.dragonPickaxeHead, MaterialTier.dragon, "dragon-pickaxe-head"),
287 [MetalItemId.dragonAxe]: axeDef(MetalItemId.dragonAxe, MaterialTier.dragon, "dragon-axe"),
288 [MetalItemId.dragonAxeHead]: axeHeadDef(MetalItemId.dragonAxeHead, MaterialTier.dragon, "dragon-axe-head"),
289 [MetalItemId.bronzePlantClippers]: plantClippersDef(
290 MetalItemId.bronzePlantClippers,
291 MaterialTier.bronze,
292 "bronze-plant-clippers"
293 ),
294 [MetalItemId.ironPlantClippers]: plantClippersDef(
295 MetalItemId.ironPlantClippers,
296 MaterialTier.iron,
297 "iron-plant-clippers"
298 ),
299 [MetalItemId.steelPlantClippers]: plantClippersDef(
300 MetalItemId.steelPlantClippers,
301 MaterialTier.steel,
302 "steel-plant-clippers"
303 ),
304 [MetalItemId.mithrilPlantClippers]: plantClippersDef(
305 MetalItemId.mithrilPlantClippers,
306 MaterialTier.mithril,
307 "mithril-plant-clippers"
308 ),
309 [MetalItemId.adamantiumPlantClippers]: plantClippersDef(
310 MetalItemId.adamantiumPlantClippers,
311 MaterialTier.adamantium,
312 "adamantium-plant-clippers"
313 ),
314 [MetalItemId.orichalcumPlantClippers]: plantClippersDef(
315 MetalItemId.orichalcumPlantClippers,
316 MaterialTier.orichalcum,
317 "orichalcum-plant-clippers"
318 ),
319 [MetalItemId.dragonPlantClippers]: plantClippersDef(
320 MetalItemId.dragonPlantClippers,
321 MaterialTier.dragon,
322 "dragon-plant-clippers"
323 )
324});
96});
325
97
326/** Pickaxe head item id by metal tier. */
98/** Pickaxe head item id by metal tier. */
@@ -334,15 +106,6 @@ export const PICKAXE_HEAD_ITEM_BY_METAL = Object.freeze({
334 [MaterialTier.dragon]: MetalItemId.dragonPickaxeHead
106 [MaterialTier.dragon]: MetalItemId.dragonPickaxeHead
335});
107});
336
108
337export const PICKAXE_ITEM_BY_METAL = Object.freeze({
338 [MaterialTier.iron]: MetalItemId.ironPickaxe,
339 [MaterialTier.steel]: MetalItemId.steelPickaxe,
340 [MaterialTier.mithril]: MetalItemId.mithrilPickaxe,
341 [MaterialTier.adamantium]: MetalItemId.adamantiumPickaxe,
342 [MaterialTier.orichalcum]: MetalItemId.orichalcumPickaxe,
343 [MaterialTier.dragon]: MetalItemId.dragonPickaxe
344});
345
346/** Axe head item id by metal tier. */
109/** Axe head item id by metal tier. */
347export const AXE_HEAD_ITEM_BY_METAL = Object.freeze({
110export const AXE_HEAD_ITEM_BY_METAL = Object.freeze({
348 [MaterialTier.bronze]: MetalItemId.bronzeAxeHead,
111 [MaterialTier.bronze]: MetalItemId.bronzeAxeHead,
@@ -354,7 +117,18 @@ export const AXE_HEAD_ITEM_BY_METAL = Object.freeze({
354 [MaterialTier.dragon]: MetalItemId.dragonAxeHead
117 [MaterialTier.dragon]: MetalItemId.dragonAxeHead
355});
118});
356
119
120export const PICKAXE_ITEM_BY_METAL = Object.freeze({
121 [MaterialTier.bronze]: CraftingItemId.bronzePickaxe,
122 [MaterialTier.iron]: MetalItemId.ironPickaxe,
123 [MaterialTier.steel]: MetalItemId.steelPickaxe,
124 [MaterialTier.mithril]: MetalItemId.mithrilPickaxe,
125 [MaterialTier.adamantium]: MetalItemId.adamantiumPickaxe,
126 [MaterialTier.orichalcum]: MetalItemId.orichalcumPickaxe,
127 [MaterialTier.dragon]: MetalItemId.dragonPickaxe
128});
129
357export const AXE_ITEM_BY_METAL = Object.freeze({
130export const AXE_ITEM_BY_METAL = Object.freeze({
131 [MaterialTier.bronze]: CraftingItemId.bronzeAxe,
358 [MaterialTier.iron]: MetalItemId.ironAxe,
132 [MaterialTier.iron]: MetalItemId.ironAxe,
359 [MaterialTier.steel]: MetalItemId.steelAxe,
133 [MaterialTier.steel]: MetalItemId.steelAxe,
360 [MaterialTier.mithril]: MetalItemId.mithrilAxe,
134 [MaterialTier.mithril]: MetalItemId.mithrilAxe,
@@ -373,3 +147,29 @@ export const PLANT_CLIPPERS_ITEM_BY_METAL = Object.freeze({
373 [MaterialTier.orichalcum]: MetalItemId.orichalcumPlantClippers,
147 [MaterialTier.orichalcum]: MetalItemId.orichalcumPlantClippers,
374 [MaterialTier.dragon]: MetalItemId.dragonPlantClippers
148 [MaterialTier.dragon]: MetalItemId.dragonPlantClippers
375});
149});
150
151/** Full defs for metal family (merged into ITEM_DEFINITIONS). */
152export const METAL_ITEM_DEFINITIONS = Object.freeze({
153 ...buildFamilyDefinitionMap(ItemFamilyId.ore, ORE_BY_TIER),
154 ...buildFamilyDefinitionMap(ItemFamilyId.bar, BAR_BY_TIER),
155 ...buildFamilyDefinitionMap(ItemFamilyId.pickaxeHead, PICKAXE_HEAD_ITEM_BY_METAL),
156 ...buildFamilyDefinitionMap(ItemFamilyId.axeHead, AXE_HEAD_ITEM_BY_METAL),
157 ...buildFamilyDefinitionMap(ItemFamilyId.pickaxe, PICKAXE_ITEM_BY_METAL),
158 ...buildFamilyDefinitionMap(ItemFamilyId.axe, AXE_ITEM_BY_METAL),
159 ...buildFamilyDefinitionMap(ItemFamilyId.plantClippers, PLANT_CLIPPERS_ITEM_BY_METAL),
160 [MetalItemId.coal]: Object.freeze({
161 itemId: MetalItemId.coal,
162 key: "coal",
163 displayName: "Coal",
164 description: "Dark coal, hot enough to harden steel.",
165 seedValue: 2,
166 stackable: true,
167 maxStackSize: DEFAULT_STACK,
168 uniqueInstance: false,
169 category: ItemCategory.ingredient,
170 iconKey: "metal",
171 defaultState: "ore",
172 tier: GatherMaterialId.coal,
173 tintFromTier: true
174 })
175});
shared/definitions/mobCombat.js +0 −1
@@ -39,7 +39,6 @@ export function mobMeleeAttackProfile (def)
39 39 hitSkillId: SkillId.unarmed,
40 40 damageSkillId: SkillId.unarmed,
41 41 cooldownMs: def?.attackCooldownMs ?? 900,
42 baseDamage: def?.baseDamage ?? 1,
43 42 mobAttackSkill: attackSkill
44 43 };
45 44 }
@@ -39,7 +39,6 @@ export function mobMeleeAttackProfile (def)
39 hitSkillId: SkillId.unarmed,
39 hitSkillId: SkillId.unarmed,
40 damageSkillId: SkillId.unarmed,
40 damageSkillId: SkillId.unarmed,
41 cooldownMs: def?.attackCooldownMs ?? 900,
41 cooldownMs: def?.attackCooldownMs ?? 900,
42 baseDamage: def?.baseDamage ?? 1,
43 mobAttackSkill: attackSkill
42 mobAttackSkill: attackSkill
44 };
43 };
45}
44}
shared/definitions/mobs.js +0 −3
@@ -36,7 +36,6 @@ export const MOB_DEFINITIONS = Object.freeze({
36 36 maxHealth: 8,
37 37 attackSkill: 2,
38 38 attackCooldownMs: 1000,
39 baseDamage: 1,
40 39 drops: Object.freeze([]),
41 40 sells: Object.freeze([]),
42 41 dialogue: Object.freeze([]),
@@ -88,7 +87,6 @@ export const MOB_DEFINITIONS = Object.freeze({
88 87 maxHealth: 12,
89 88 attackSkill: 3,
90 89 attackCooldownMs: 900,
91 baseDamage: 2,
92 90 drops: Object.freeze([]),
93 91 sells: Object.freeze([]),
94 92 dialogue: Object.freeze([]),
@@ -116,7 +114,6 @@ export const MOB_DEFINITIONS = Object.freeze({
116 114 maxHealth: 5,
117 115 attackSkill: 1,
118 116 attackCooldownMs: 1200,
119 baseDamage: 1,
120 117 drops: Object.freeze([
121 118 { itemId: RangedItemId.feather, chance: 1 }
122 119 ]),
@@ -36,7 +36,6 @@ export const MOB_DEFINITIONS = Object.freeze({
36 maxHealth: 8,
36 maxHealth: 8,
37 attackSkill: 2,
37 attackSkill: 2,
38 attackCooldownMs: 1000,
38 attackCooldownMs: 1000,
39 baseDamage: 1,
40 drops: Object.freeze([]),
39 drops: Object.freeze([]),
41 sells: Object.freeze([]),
40 sells: Object.freeze([]),
42 dialogue: Object.freeze([]),
41 dialogue: Object.freeze([]),
@@ -88,7 +87,6 @@ export const MOB_DEFINITIONS = Object.freeze({
88 maxHealth: 12,
87 maxHealth: 12,
89 attackSkill: 3,
88 attackSkill: 3,
90 attackCooldownMs: 900,
89 attackCooldownMs: 900,
91 baseDamage: 2,
92 drops: Object.freeze([]),
90 drops: Object.freeze([]),
93 sells: Object.freeze([]),
91 sells: Object.freeze([]),
94 dialogue: Object.freeze([]),
92 dialogue: Object.freeze([]),
@@ -116,7 +114,6 @@ export const MOB_DEFINITIONS = Object.freeze({
116 maxHealth: 5,
114 maxHealth: 5,
117 attackSkill: 1,
115 attackSkill: 1,
118 attackCooldownMs: 1200,
116 attackCooldownMs: 1200,
119 baseDamage: 1,
120 drops: Object.freeze([
117 drops: Object.freeze([
121 { itemId: RangedItemId.feather, chance: 1 }
118 { itemId: RangedItemId.feather, chance: 1 }
122 ]),
119 ]),
shared/definitions/rangedItems.js +29 −316
@@ -1,23 +1,14 @@
1 1 import { ItemCategory } from "./itemCategories.js";
2 2 import {
3 3 MaterialTier,
4 MATERIAL_TIER_ORDER,
5 MATERIAL_DISPLAY_NAME,
6 4 WOOD_TIER_ORDER,
7 5 WoodTier,
8 CLOTH_TIER_ORDER,
9 ClothTier,
10 CLOTH_DISPLAY_NAME,
11 clothTierForWood,
12 metalTierForWood,
13 tierMinSkillLevel
6 ClothTier
14 7 } from "./materialTiers.js";
15 import { EquipmentKind } from "./equipmentKinds.js";
16 import { AttackType } from "./attackTypes.js";
17 import { SkillId } from "./skills.js";
18 import { CraftingStationId } from "./craftingStations.js";
19 import { logItemIdForWood } from "./woodItems.js";
20 import { yarnItemId } from "./clothItems.js";
8 import {
9 ItemFamilyId,
10 buildFamilyDefinitionMap
11 } from "./tierFamilies.js";
21 12
22 13 /** @typedef {typeof MaterialTier[keyof typeof MaterialTier]} MetalTierId */
23 14
@@ -68,9 +59,8 @@ export const RangedItemId = Object.freeze({
68 59 });
69 60
70 61 const DEFAULT_STACK = 99;
71 const ARROW_MAX_STACK = 999;
72 62
73 const ARROW_SHAFT_BY_WOOD = Object.freeze({
63 export const ARROW_SHAFT_BY_WOOD = Object.freeze({
74 64 [WoodTier.pine]: RangedItemId.pineArrowShaft,
75 65 [WoodTier.birch]: RangedItemId.birchArrowShaft,
76 66 [WoodTier.oak]: RangedItemId.oakArrowShaft,
@@ -80,7 +70,7 @@ const ARROW_SHAFT_BY_WOOD = Object.freeze({
80 70 [WoodTier.elder]: RangedItemId.elderArrowShaft
81 71 });
82 72
83 const ARROW_TIP_BY_METAL = Object.freeze({
73 export const ARROW_TIP_BY_METAL = Object.freeze({
84 74 [MaterialTier.bronze]: RangedItemId.bronzeArrowTip,
85 75 [MaterialTier.iron]: RangedItemId.ironArrowTip,
86 76 [MaterialTier.steel]: RangedItemId.steelArrowTip,
@@ -90,7 +80,7 @@ const ARROW_TIP_BY_METAL = Object.freeze({
90 80 [MaterialTier.dragon]: RangedItemId.dragonArrowTip
91 81 });
92 82
93 const ARROW_BY_METAL = Object.freeze({
83 export const ARROW_BY_METAL = Object.freeze({
94 84 [MaterialTier.bronze]: RangedItemId.bronzeArrow,
95 85 [MaterialTier.iron]: RangedItemId.ironArrow,
96 86 [MaterialTier.steel]: RangedItemId.steelArrow,
@@ -100,7 +90,7 @@ const ARROW_BY_METAL = Object.freeze({
100 90 [MaterialTier.dragon]: RangedItemId.dragonArrow
101 91 });
102 92
103 const UNSTRUNG_BOW_BY_WOOD = Object.freeze({
93 export const UNSTRUNG_BOW_BY_WOOD = Object.freeze({
104 94 [WoodTier.pine]: RangedItemId.pineUnstrungBow,
105 95 [WoodTier.birch]: RangedItemId.birchUnstrungBow,
106 96 [WoodTier.oak]: RangedItemId.oakUnstrungBow,
@@ -110,7 +100,7 @@ const UNSTRUNG_BOW_BY_WOOD = Object.freeze({
110 100 [WoodTier.elder]: RangedItemId.elderUnstrungBow
111 101 });
112 102
113 const BOWSTRING_BY_CLOTH = Object.freeze({
103 export const BOWSTRING_BY_CLOTH = Object.freeze({
114 104 [ClothTier.cotton]: RangedItemId.cottonBowstring,
115 105 [ClothTier.wool]: RangedItemId.woolBowstring,
116 106 [ClothTier.linen]: RangedItemId.linenBowstring,
@@ -120,7 +110,7 @@ const BOWSTRING_BY_CLOTH = Object.freeze({
120 110 [ClothTier.dragonweave]: RangedItemId.dragonweaveBowstring
121 111 });
122 112
123 const BOW_BY_WOOD = Object.freeze({
113 export const BOW_BY_WOOD = Object.freeze({
124 114 [WoodTier.pine]: RangedItemId.pineBow,
125 115 [WoodTier.birch]: RangedItemId.birchBow,
126 116 [WoodTier.oak]: RangedItemId.oakBow,
@@ -160,302 +150,25 @@ export function bowItemId (woodTier)
160 150 return BOW_BY_WOOD[woodTier] ?? null;
161 151 }
162 152
163 export {
164 ARROW_SHAFT_BY_WOOD,
165 ARROW_TIP_BY_METAL,
166 ARROW_BY_METAL,
167 UNSTRUNG_BOW_BY_WOOD,
168 BOWSTRING_BY_CLOTH,
169 BOW_BY_WOOD
170 };
171
172 function shaftDef (itemId, woodTier)
173 {
174 const woodName = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
175 return Object.freeze({
176 itemId,
177 key: `${woodTier}-arrow-shaft`,
178 displayName: `${woodName} arrow shaft`,
179 description: "A straight wooden shaft, ready for fletching.",
153 /** Full defs for ranged family (merged into ITEM_DEFINITIONS). */
154 export const RANGED_ITEM_DEFINITIONS = Object.freeze({
155 ...buildFamilyDefinitionMap(ItemFamilyId.arrowShaft, ARROW_SHAFT_BY_WOOD),
156 ...buildFamilyDefinitionMap(ItemFamilyId.arrowTip, ARROW_TIP_BY_METAL),
157 ...buildFamilyDefinitionMap(ItemFamilyId.arrow, ARROW_BY_METAL),
158 ...buildFamilyDefinitionMap(ItemFamilyId.unstrungBow, UNSTRUNG_BOW_BY_WOOD),
159 ...buildFamilyDefinitionMap(ItemFamilyId.bowstring, BOWSTRING_BY_CLOTH),
160 ...buildFamilyDefinitionMap(ItemFamilyId.bow, BOW_BY_WOOD),
161 [RangedItemId.feather]: Object.freeze({
162 itemId: RangedItemId.feather,
163 key: "feather",
164 displayName: "Feather",
165 description: "A soft plume for fletching arrows.",
180 166 seedValue: 1,
181 167 stackable: true,
182 168 maxStackSize: DEFAULT_STACK,
183 169 uniqueInstance: false,
184 category: ItemCategory.intermediate,
185 iconKey: "wood",
186 defaultState: "handle",
187 tier: woodTier,
188 tintFromTier: true
189 });
190 }
191
192 function tipDef (itemId, metalTier)
193 {
194 const name = MATERIAL_DISPLAY_NAME[metalTier] ?? metalTier;
195 return Object.freeze({
196 itemId,
197 key: `${metalTier}-arrow-tip`,
198 displayName: `${name} arrow tip`,
199 description: `A smithed ${name.toLowerCase()} point for arrows.`,
200 seedValue: 1,
201 stackable: true,
202 maxStackSize: DEFAULT_STACK,
203 uniqueInstance: false,
204 category: ItemCategory.intermediate,
205 iconKey: "metal",
206 defaultState: "bar",
207 tier: metalTier,
208 tintFromTier: true
209 });
210 }
211
212 function arrowDef (itemId, metalTier)
213 {
214 const name = MATERIAL_DISPLAY_NAME[metalTier] ?? metalTier;
215 const woodTier = metalTierForWood(metalTier);
216 return Object.freeze({
217 itemId,
218 key: `${metalTier}-arrow`,
219 displayName: `${name} arrow`,
220 description: "A fletched arrow with matching shaft and head.",
221 seedValue: 2,
222 stackable: true,
223 maxStackSize: ARROW_MAX_STACK,
224 uniqueInstance: false,
225 category: ItemCategory.finished,
226 iconKey: "arrow",
227 defaultState: "arrow",
228 tier: metalTier,
229 woodTier,
230 tintFromTier: true,
231 equipment: Object.freeze({
232 slot: "offhand",
233 tier: metalTier,
234 kind: EquipmentKind.arrowAmmo,
235 hideEquipSprite: true
236 })
237 });
238 }
239
240 function unstrungBowDef (itemId, woodTier)
241 {
242 const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
243 return Object.freeze({
244 itemId,
245 key: `${woodTier}-unstrung-bow`,
246 displayName: `${name} unstrung bow`,
247 description: "A carved bow frame awaiting a string.",
248 seedValue: 6,
249 stackable: false,
250 maxStackSize: 1,
251 uniqueInstance: false,
252 category: ItemCategory.intermediate,
253 iconKey: "bow",
254 defaultState: "bow",
255 tier: woodTier,
256 tintFromTier: true
257 });
258 }
259
260 function bowstringDef (itemId, clothTier)
261 {
262 const name = CLOTH_DISPLAY_NAME[clothTier] ?? clothTier;
263 return Object.freeze({
264 itemId,
265 key: `${clothTier}-bowstring`,
266 displayName: `${name} bowstring`,
267 description: "Twisted yarn spun tight for a bow.",
268 seedValue: 2,
269 stackable: true,
270 maxStackSize: DEFAULT_STACK,
271 uniqueInstance: false,
272 category: ItemCategory.intermediate,
273 iconKey: "cloth",
274 defaultState: "yarn",
275 tier: clothTier,
276 tintFromTier: true
277 });
278 }
279
280 function bowDef (itemId, woodTier)
281 {
282 const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
283 const clothTier = clothTierForWood(woodTier);
284 return Object.freeze({
285 itemId,
286 key: `${woodTier}-bow`,
287 displayName: `${name} bow`,
288 description: `A ${name.toLowerCase()} bow strung with matching yarn.`,
289 seedValue: 12,
290 stackable: false,
291 maxStackSize: 1,
292 uniqueInstance: false,
293 category: ItemCategory.finished,
294 iconKey: "bow",
295 defaultState: "bow",
296 tier: woodTier,
297 clothTier,
298 tintFromTier: true,
299 equipment: Object.freeze({
300 slot: "weapon",
301 tier: woodTier,
302 kind: EquipmentKind.bow,
303 tintFromTier: true,
304 attack: Object.freeze({
305 mode: "ranged",
306 rangeTiles: 8,
307 hitSkillId: SkillId.archery,
308 damageSkillId: SkillId.dexterity,
309 attackType: AttackType.piercing,
310 cooldownMs: 1200,
311 baseDamage: 2
312 })
313 })
314 });
315 }
316
317 function buildRangedDefinitions ()
318 {
319 const defs = {
320 [RangedItemId.feather]: Object.freeze({
321 itemId: RangedItemId.feather,
322 key: "feather",
323 displayName: "Feather",
324 description: "A soft plume for fletching arrows.",
325 seedValue: 1,
326 stackable: true,
327 maxStackSize: DEFAULT_STACK,
328 uniqueInstance: false,
329 category: ItemCategory.ingredient,
330 iconKey: "feather",
331 defaultState: "feather"
332 })
333 };
334 for (const wood of WOOD_TIER_ORDER)
335 {
336 defs[arrowShaftItemId(wood)] = shaftDef(arrowShaftItemId(wood), wood);
337 defs[unstrungBowItemId(wood)] = unstrungBowDef(unstrungBowItemId(wood), wood);
338 defs[bowItemId(wood)] = bowDef(bowItemId(wood), wood);
339 }
340 for (const metal of MATERIAL_TIER_ORDER)
341 {
342 defs[arrowTipItemId(metal)] = tipDef(arrowTipItemId(metal), metal);
343 defs[arrowItemId(metal)] = arrowDef(arrowItemId(metal), metal);
344 }
345 for (const cloth of CLOTH_TIER_ORDER)
346 {
347 defs[bowstringItemId(cloth)] = bowstringDef(bowstringItemId(cloth), cloth);
348 }
349 return Object.freeze(defs);
350 }
351
352 export const RANGED_ITEM_DEFINITIONS = buildRangedDefinitions();
353
354 export function arrowCraftInputs (metalTier)
355 {
356 const woodTier = metalTierForWood(metalTier);
357 return Object.freeze([
358 { itemId: RangedItemId.feather, quantity: 1 },
359 { itemId: arrowShaftItemId(woodTier), quantity: 1 },
360 { itemId: arrowTipItemId(metalTier), quantity: 1 }
361 ]);
362 }
363
364 export function bowCraftInputs (woodTier)
365 {
366 const clothTier = clothTierForWood(woodTier);
367 return Object.freeze([
368 { itemId: unstrungBowItemId(woodTier), quantity: 1 },
369 { itemId: bowstringItemId(clothTier), quantity: 1 }
370 ]);
371 }
372
373 export function arrowShaftRecipe (woodTier)
374 {
375 return Object.freeze({
376 recipeId: `arrow-shafts-${woodTier}`,
377 craftGroup: "arrow-shafts",
378 craftGroupLabel: "Arrow shafts",
379 stationId: CraftingStationId.woodworkingBench,
380 output: { itemId: arrowShaftItemId(woodTier), quantity: 15 },
381 inputs: [{ itemId: logItemIdForWood(woodTier), quantity: 1 }],
382 minSkillLevel: tierMinSkillLevel(woodTier),
383 skillId: "crafting",
384 xpMaterial: woodTier
385 });
386 }
387
388 export function arrowTipRecipe (metalTier, barItemId)
389 {
390 return Object.freeze({
391 recipeId: `arrow-tips-${metalTier}`,
392 craftGroup: "arrow-tips",
393 craftGroupLabel: "Arrow tips",
394 stationId: CraftingStationId.anvil,
395 output: { itemId: arrowTipItemId(metalTier), quantity: 15 },
396 inputs: [{ itemId: barItemId, quantity: 1 }],
397 minSkillLevel: tierMinSkillLevel(metalTier),
398 skillId: "smithing",
399 xpMaterial: metalTier
400 });
401 }
402
403 export function arrowAssembleRecipe (metalTier)
404 {
405 return Object.freeze({
406 recipeId: `arrow-${metalTier}`,
407 craftGroup: `arrow-${metalTier}`,
408 craftGroupLabel: `${MATERIAL_DISPLAY_NAME[metalTier] ?? metalTier} arrow`,
409 stationId: CraftingStationId.craftingBench,
410 output: { itemId: arrowItemId(metalTier), quantity: 1 },
411 inputs: arrowCraftInputs(metalTier),
412 minSkillLevel: tierMinSkillLevel(metalTier),
413 skillId: "crafting",
414 xpMaterial: metalTier
415 });
416 }
417
418 export function unstrungBowRecipe (woodTier)
419 {
420 return Object.freeze({
421 recipeId: `unstrung-bow-${woodTier}`,
422 craftGroup: "unstrung-bow",
423 craftGroupLabel: "Unstrung bow",
424 stationId: CraftingStationId.woodworkingBench,
425 output: { itemId: unstrungBowItemId(woodTier), quantity: 1 },
426 inputs: [{ itemId: logItemIdForWood(woodTier), quantity: 1 }],
427 minSkillLevel: tierMinSkillLevel(woodTier),
428 skillId: "crafting",
429 xpMaterial: woodTier
430 });
431 }
432
433 export function bowstringRecipe (clothTier)
434 {
435 return Object.freeze({
436 recipeId: `bowstring-${clothTier}`,
437 craftGroup: "bowstring",
438 craftGroupLabel: "Bowstring",
439 stationId: CraftingStationId.spinningWheel,
440 output: { itemId: bowstringItemId(clothTier), quantity: 1 },
441 inputs: [{ itemId: yarnItemId(clothTier), quantity: 1 }],
442 minSkillLevel: tierMinSkillLevel(clothTier),
443 skillId: "tailoring",
444 xpMaterial: clothTier
445 });
446 }
447
448 export function bowAssembleRecipe (woodTier)
449 {
450 return Object.freeze({
451 recipeId: `bow-${woodTier}`,
452 craftGroup: `bow-${woodTier}`,
453 craftGroupLabel: `${MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier} bow`,
454 stationId: CraftingStationId.craftingBench,
455 output: { itemId: bowItemId(woodTier), quantity: 1 },
456 inputs: bowCraftInputs(woodTier),
457 minSkillLevel: tierMinSkillLevel(woodTier),
458 skillId: "crafting",
459 xpMaterial: woodTier
460 });
461 }
170 category: ItemCategory.ingredient,
171 iconKey: "feather",
172 defaultState: "feather"
173 })
174 });
@@ -1,23 +1,14 @@
1import { ItemCategory } from "./itemCategories.js";
1import { ItemCategory } from "./itemCategories.js";
2import {
2import {
3 MaterialTier,
3 MaterialTier,
4 MATERIAL_TIER_ORDER,
5 MATERIAL_DISPLAY_NAME,
6 WOOD_TIER_ORDER,
4 WOOD_TIER_ORDER,
7 WoodTier,
5 WoodTier,
8 CLOTH_TIER_ORDER,
6 ClothTier
9 ClothTier,
10 CLOTH_DISPLAY_NAME,
11 clothTierForWood,
12 metalTierForWood,
13 tierMinSkillLevel
14} from "./materialTiers.js";
7} from "./materialTiers.js";
15import { EquipmentKind } from "./equipmentKinds.js";
8import {
16import { AttackType } from "./attackTypes.js";
9 ItemFamilyId,
17import { SkillId } from "./skills.js";
10 buildFamilyDefinitionMap
18import { CraftingStationId } from "./craftingStations.js";
11} from "./tierFamilies.js";
19import { logItemIdForWood } from "./woodItems.js";
20import { yarnItemId } from "./clothItems.js";
21
12
22/** @typedef {typeof MaterialTier[keyof typeof MaterialTier]} MetalTierId */
13/** @typedef {typeof MaterialTier[keyof typeof MaterialTier]} MetalTierId */
23
14
@@ -68,9 +59,8 @@ export const RangedItemId = Object.freeze({
68});
59});
69
60
70const DEFAULT_STACK = 99;
61const DEFAULT_STACK = 99;
71const ARROW_MAX_STACK = 999;
72
62
73const ARROW_SHAFT_BY_WOOD = Object.freeze({
63export const ARROW_SHAFT_BY_WOOD = Object.freeze({
74 [WoodTier.pine]: RangedItemId.pineArrowShaft,
64 [WoodTier.pine]: RangedItemId.pineArrowShaft,
75 [WoodTier.birch]: RangedItemId.birchArrowShaft,
65 [WoodTier.birch]: RangedItemId.birchArrowShaft,
76 [WoodTier.oak]: RangedItemId.oakArrowShaft,
66 [WoodTier.oak]: RangedItemId.oakArrowShaft,
@@ -80,7 +70,7 @@ const ARROW_SHAFT_BY_WOOD = Object.freeze({
80 [WoodTier.elder]: RangedItemId.elderArrowShaft
70 [WoodTier.elder]: RangedItemId.elderArrowShaft
81});
71});
82
72
83const ARROW_TIP_BY_METAL = Object.freeze({
73export const ARROW_TIP_BY_METAL = Object.freeze({
84 [MaterialTier.bronze]: RangedItemId.bronzeArrowTip,
74 [MaterialTier.bronze]: RangedItemId.bronzeArrowTip,
85 [MaterialTier.iron]: RangedItemId.ironArrowTip,
75 [MaterialTier.iron]: RangedItemId.ironArrowTip,
86 [MaterialTier.steel]: RangedItemId.steelArrowTip,
76 [MaterialTier.steel]: RangedItemId.steelArrowTip,
@@ -90,7 +80,7 @@ const ARROW_TIP_BY_METAL = Object.freeze({
90 [MaterialTier.dragon]: RangedItemId.dragonArrowTip
80 [MaterialTier.dragon]: RangedItemId.dragonArrowTip
91});
81});
92
82
93const ARROW_BY_METAL = Object.freeze({
83export const ARROW_BY_METAL = Object.freeze({
94 [MaterialTier.bronze]: RangedItemId.bronzeArrow,
84 [MaterialTier.bronze]: RangedItemId.bronzeArrow,
95 [MaterialTier.iron]: RangedItemId.ironArrow,
85 [MaterialTier.iron]: RangedItemId.ironArrow,
96 [MaterialTier.steel]: RangedItemId.steelArrow,
86 [MaterialTier.steel]: RangedItemId.steelArrow,
@@ -100,7 +90,7 @@ const ARROW_BY_METAL = Object.freeze({
100 [MaterialTier.dragon]: RangedItemId.dragonArrow
90 [MaterialTier.dragon]: RangedItemId.dragonArrow
101});
91});
102
92
103const UNSTRUNG_BOW_BY_WOOD = Object.freeze({
93export const UNSTRUNG_BOW_BY_WOOD = Object.freeze({
104 [WoodTier.pine]: RangedItemId.pineUnstrungBow,
94 [WoodTier.pine]: RangedItemId.pineUnstrungBow,
105 [WoodTier.birch]: RangedItemId.birchUnstrungBow,
95 [WoodTier.birch]: RangedItemId.birchUnstrungBow,
106 [WoodTier.oak]: RangedItemId.oakUnstrungBow,
96 [WoodTier.oak]: RangedItemId.oakUnstrungBow,
@@ -110,7 +100,7 @@ const UNSTRUNG_BOW_BY_WOOD = Object.freeze({
110 [WoodTier.elder]: RangedItemId.elderUnstrungBow
100 [WoodTier.elder]: RangedItemId.elderUnstrungBow
111});
101});
112
102
113const BOWSTRING_BY_CLOTH = Object.freeze({
103export const BOWSTRING_BY_CLOTH = Object.freeze({
114 [ClothTier.cotton]: RangedItemId.cottonBowstring,
104 [ClothTier.cotton]: RangedItemId.cottonBowstring,
115 [ClothTier.wool]: RangedItemId.woolBowstring,
105 [ClothTier.wool]: RangedItemId.woolBowstring,
116 [ClothTier.linen]: RangedItemId.linenBowstring,
106 [ClothTier.linen]: RangedItemId.linenBowstring,
@@ -120,7 +110,7 @@ const BOWSTRING_BY_CLOTH = Object.freeze({
120 [ClothTier.dragonweave]: RangedItemId.dragonweaveBowstring
110 [ClothTier.dragonweave]: RangedItemId.dragonweaveBowstring
121});
111});
122
112
123const BOW_BY_WOOD = Object.freeze({
113export const BOW_BY_WOOD = Object.freeze({
124 [WoodTier.pine]: RangedItemId.pineBow,
114 [WoodTier.pine]: RangedItemId.pineBow,
125 [WoodTier.birch]: RangedItemId.birchBow,
115 [WoodTier.birch]: RangedItemId.birchBow,
126 [WoodTier.oak]: RangedItemId.oakBow,
116 [WoodTier.oak]: RangedItemId.oakBow,
@@ -160,302 +150,25 @@ export function bowItemId (woodTier)
160 return BOW_BY_WOOD[woodTier] ?? null;
150 return BOW_BY_WOOD[woodTier] ?? null;
161}
151}
162
152
163export {
153/** Full defs for ranged family (merged into ITEM_DEFINITIONS). */
164 ARROW_SHAFT_BY_WOOD,
154export const RANGED_ITEM_DEFINITIONS = Object.freeze({
165 ARROW_TIP_BY_METAL,
155 ...buildFamilyDefinitionMap(ItemFamilyId.arrowShaft, ARROW_SHAFT_BY_WOOD),
166 ARROW_BY_METAL,
156 ...buildFamilyDefinitionMap(ItemFamilyId.arrowTip, ARROW_TIP_BY_METAL),
167 UNSTRUNG_BOW_BY_WOOD,
157 ...buildFamilyDefinitionMap(ItemFamilyId.arrow, ARROW_BY_METAL),
168 BOWSTRING_BY_CLOTH,
158 ...buildFamilyDefinitionMap(ItemFamilyId.unstrungBow, UNSTRUNG_BOW_BY_WOOD),
169 BOW_BY_WOOD
159 ...buildFamilyDefinitionMap(ItemFamilyId.bowstring, BOWSTRING_BY_CLOTH),
170};
160 ...buildFamilyDefinitionMap(ItemFamilyId.bow, BOW_BY_WOOD),
171
161 [RangedItemId.feather]: Object.freeze({
172function shaftDef (itemId, woodTier)
162 itemId: RangedItemId.feather,
173{
163 key: "feather",
174 const woodName = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
164 displayName: "Feather",
175 return Object.freeze({
165 description: "A soft plume for fletching arrows.",
176 itemId,
177 key: `${woodTier}-arrow-shaft`,
178 displayName: `${woodName} arrow shaft`,
179 description: "A straight wooden shaft, ready for fletching.",
180 seedValue: 1,
166 seedValue: 1,
181 stackable: true,
167 stackable: true,
182 maxStackSize: DEFAULT_STACK,
168 maxStackSize: DEFAULT_STACK,
183 uniqueInstance: false,
169 uniqueInstance: false,
184 category: ItemCategory.intermediate,
170 category: ItemCategory.ingredient,
185 iconKey: "wood",
171 iconKey: "feather",
186 defaultState: "handle",
172 defaultState: "feather"
187 tier: woodTier,
173 })
188 tintFromTier: true
174});
189 });
190}
191
192function tipDef (itemId, metalTier)
193{
194 const name = MATERIAL_DISPLAY_NAME[metalTier] ?? metalTier;
195 return Object.freeze({
196 itemId,
197 key: `${metalTier}-arrow-tip`,
198 displayName: `${name} arrow tip`,
199 description: `A smithed ${name.toLowerCase()} point for arrows.`,
200 seedValue: 1,
201 stackable: true,
202 maxStackSize: DEFAULT_STACK,
203 uniqueInstance: false,
204 category: ItemCategory.intermediate,
205 iconKey: "metal",
206 defaultState: "bar",
207 tier: metalTier,
208 tintFromTier: true
209 });
210}
211
212function arrowDef (itemId, metalTier)
213{
214 const name = MATERIAL_DISPLAY_NAME[metalTier] ?? metalTier;
215 const woodTier = metalTierForWood(metalTier);
216 return Object.freeze({
217 itemId,
218 key: `${metalTier}-arrow`,
219 displayName: `${name} arrow`,
220 description: "A fletched arrow with matching shaft and head.",
221 seedValue: 2,
222 stackable: true,
223 maxStackSize: ARROW_MAX_STACK,
224 uniqueInstance: false,
225 category: ItemCategory.finished,
226 iconKey: "arrow",
227 defaultState: "arrow",
228 tier: metalTier,
229 woodTier,
230 tintFromTier: true,
231 equipment: Object.freeze({
232 slot: "offhand",
233 tier: metalTier,
234 kind: EquipmentKind.arrowAmmo,
235 hideEquipSprite: true
236 })
237 });
238}
239
240function unstrungBowDef (itemId, woodTier)
241{
242 const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
243 return Object.freeze({
244 itemId,
245 key: `${woodTier}-unstrung-bow`,
246 displayName: `${name} unstrung bow`,
247 description: "A carved bow frame awaiting a string.",
248 seedValue: 6,
249 stackable: false,
250 maxStackSize: 1,
251 uniqueInstance: false,
252 category: ItemCategory.intermediate,
253 iconKey: "bow",
254 defaultState: "bow",
255 tier: woodTier,
256 tintFromTier: true
257 });
258}
259
260function bowstringDef (itemId, clothTier)
261{
262 const name = CLOTH_DISPLAY_NAME[clothTier] ?? clothTier;
263 return Object.freeze({
264 itemId,
265 key: `${clothTier}-bowstring`,
266 displayName: `${name} bowstring`,
267 description: "Twisted yarn spun tight for a bow.",
268 seedValue: 2,
269 stackable: true,
270 maxStackSize: DEFAULT_STACK,
271 uniqueInstance: false,
272 category: ItemCategory.intermediate,
273 iconKey: "cloth",
274 defaultState: "yarn",
275 tier: clothTier,
276 tintFromTier: true
277 });
278}
279
280function bowDef (itemId, woodTier)
281{
282 const name = MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier;
283 const clothTier = clothTierForWood(woodTier);
284 return Object.freeze({
285 itemId,
286 key: `${woodTier}-bow`,
287 displayName: `${name} bow`,
288 description: `A ${name.toLowerCase()} bow strung with matching yarn.`,
289 seedValue: 12,
290 stackable: false,
291 maxStackSize: 1,
292 uniqueInstance: false,
293 category: ItemCategory.finished,
294 iconKey: "bow",
295 defaultState: "bow",
296 tier: woodTier,
297 clothTier,
298 tintFromTier: true,
299 equipment: Object.freeze({
300 slot: "weapon",
301 tier: woodTier,
302 kind: EquipmentKind.bow,
303 tintFromTier: true,
304 attack: Object.freeze({
305 mode: "ranged",
306 rangeTiles: 8,
307 hitSkillId: SkillId.archery,
308 damageSkillId: SkillId.dexterity,
309 attackType: AttackType.piercing,
310 cooldownMs: 1200,
311 baseDamage: 2
312 })
313 })
314 });
315}
316
317function buildRangedDefinitions ()
318{
319 const defs = {
320 [RangedItemId.feather]: Object.freeze({
321 itemId: RangedItemId.feather,
322 key: "feather",
323 displayName: "Feather",
324 description: "A soft plume for fletching arrows.",
325 seedValue: 1,
326 stackable: true,
327 maxStackSize: DEFAULT_STACK,
328 uniqueInstance: false,
329 category: ItemCategory.ingredient,
330 iconKey: "feather",
331 defaultState: "feather"
332 })
333 };
334 for (const wood of WOOD_TIER_ORDER)
335 {
336 defs[arrowShaftItemId(wood)] = shaftDef(arrowShaftItemId(wood), wood);
337 defs[unstrungBowItemId(wood)] = unstrungBowDef(unstrungBowItemId(wood), wood);
338 defs[bowItemId(wood)] = bowDef(bowItemId(wood), wood);
339 }
340 for (const metal of MATERIAL_TIER_ORDER)
341 {
342 defs[arrowTipItemId(metal)] = tipDef(arrowTipItemId(metal), metal);
343 defs[arrowItemId(metal)] = arrowDef(arrowItemId(metal), metal);
344 }
345 for (const cloth of CLOTH_TIER_ORDER)
346 {
347 defs[bowstringItemId(cloth)] = bowstringDef(bowstringItemId(cloth), cloth);
348 }
349 return Object.freeze(defs);
350}
351
352export const RANGED_ITEM_DEFINITIONS = buildRangedDefinitions();
353
354export function arrowCraftInputs (metalTier)
355{
356 const woodTier = metalTierForWood(metalTier);
357 return Object.freeze([
358 { itemId: RangedItemId.feather, quantity: 1 },
359 { itemId: arrowShaftItemId(woodTier), quantity: 1 },
360 { itemId: arrowTipItemId(metalTier), quantity: 1 }
361 ]);
362}
363
364export function bowCraftInputs (woodTier)
365{
366 const clothTier = clothTierForWood(woodTier);
367 return Object.freeze([
368 { itemId: unstrungBowItemId(woodTier), quantity: 1 },
369 { itemId: bowstringItemId(clothTier), quantity: 1 }
370 ]);
371}
372
373export function arrowShaftRecipe (woodTier)
374{
375 return Object.freeze({
376 recipeId: `arrow-shafts-${woodTier}`,
377 craftGroup: "arrow-shafts",
378 craftGroupLabel: "Arrow shafts",
379 stationId: CraftingStationId.woodworkingBench,
380 output: { itemId: arrowShaftItemId(woodTier), quantity: 15 },
381 inputs: [{ itemId: logItemIdForWood(woodTier), quantity: 1 }],
382 minSkillLevel: tierMinSkillLevel(woodTier),
383 skillId: "crafting",
384 xpMaterial: woodTier
385 });
386}
387
388export function arrowTipRecipe (metalTier, barItemId)
389{
390 return Object.freeze({
391 recipeId: `arrow-tips-${metalTier}`,
392 craftGroup: "arrow-tips",
393 craftGroupLabel: "Arrow tips",
394 stationId: CraftingStationId.anvil,
395 output: { itemId: arrowTipItemId(metalTier), quantity: 15 },
396 inputs: [{ itemId: barItemId, quantity: 1 }],
397 minSkillLevel: tierMinSkillLevel(metalTier),
398 skillId: "smithing",
399 xpMaterial: metalTier
400 });
401}
402
403export function arrowAssembleRecipe (metalTier)
404{
405 return Object.freeze({
406 recipeId: `arrow-${metalTier}`,
407 craftGroup: `arrow-${metalTier}`,
408 craftGroupLabel: `${MATERIAL_DISPLAY_NAME[metalTier] ?? metalTier} arrow`,
409 stationId: CraftingStationId.craftingBench,
410 output: { itemId: arrowItemId(metalTier), quantity: 1 },
411 inputs: arrowCraftInputs(metalTier),
412 minSkillLevel: tierMinSkillLevel(metalTier),
413 skillId: "crafting",
414 xpMaterial: metalTier
415 });
416}
417
418export function unstrungBowRecipe (woodTier)
419{
420 return Object.freeze({
421 recipeId: `unstrung-bow-${woodTier}`,
422 craftGroup: "unstrung-bow",
423 craftGroupLabel: "Unstrung bow",
424 stationId: CraftingStationId.woodworkingBench,
425 output: { itemId: unstrungBowItemId(woodTier), quantity: 1 },
426 inputs: [{ itemId: logItemIdForWood(woodTier), quantity: 1 }],
427 minSkillLevel: tierMinSkillLevel(woodTier),
428 skillId: "crafting",
429 xpMaterial: woodTier
430 });
431}
432
433export function bowstringRecipe (clothTier)
434{
435 return Object.freeze({
436 recipeId: `bowstring-${clothTier}`,
437 craftGroup: "bowstring",
438 craftGroupLabel: "Bowstring",
439 stationId: CraftingStationId.spinningWheel,
440 output: { itemId: bowstringItemId(clothTier), quantity: 1 },
441 inputs: [{ itemId: yarnItemId(clothTier), quantity: 1 }],
442 minSkillLevel: tierMinSkillLevel(clothTier),
443 skillId: "tailoring",
444 xpMaterial: clothTier
445 });
446}
447
448export function bowAssembleRecipe (woodTier)
449{
450 return Object.freeze({
451 recipeId: `bow-${woodTier}`,
452 craftGroup: `bow-${woodTier}`,
453 craftGroupLabel: `${MATERIAL_DISPLAY_NAME[woodTier] ?? woodTier} bow`,
454 stationId: CraftingStationId.craftingBench,
455 output: { itemId: bowItemId(woodTier), quantity: 1 },
456 inputs: bowCraftInputs(woodTier),
457 minSkillLevel: tierMinSkillLevel(woodTier),
458 skillId: "crafting",
459 xpMaterial: woodTier
460 });
461}
shared/definitions/skills.js +1 −2
@@ -90,8 +90,7 @@ export const UNARMED_ATTACK = Object.freeze({
90 90 rangeTiles: 1,
91 91 hitSkillId: SkillId.unarmed,
92 92 damageSkillId: SkillId.strength,
93 cooldownMs: 800,
94 baseDamage: 1
93 cooldownMs: 800
95 94 });
96 95
97 96 import { levelFromTotalXp, MAX_SKILL_LEVEL } from "../skills/progression.js";
@@ -90,8 +90,7 @@ export const UNARMED_ATTACK = Object.freeze({
90 rangeTiles: 1,
90 rangeTiles: 1,
91 hitSkillId: SkillId.unarmed,
91 hitSkillId: SkillId.unarmed,
92 damageSkillId: SkillId.strength,
92 damageSkillId: SkillId.strength,
93 cooldownMs: 800,
93 cooldownMs: 800
94 baseDamage: 1
95});
94});
96
95
97import { levelFromTotalXp, MAX_SKILL_LEVEL } from "../skills/progression.js";
96import { levelFromTotalXp, MAX_SKILL_LEVEL } from "../skills/progression.js";
shared/definitions/spells.js +2 −2
@@ -5,7 +5,7 @@
5 5 * @property {string} spellId
6 6 * @property {string} displayName
7 7 * @property {number} difficulty Roll contest die size (1..difficulty) rolled against Magic
8 * @property {number} [baseDamage]
8 * @property {number} [mindBonus] Added to the Mind damage roll on a successful cast
9 9 * @property {import("../combat/magic.js").SpellElement} [element]
10 10 * @property {string|null} [effectId] Non-damage spells apply this when cast succeeds
11 11 * @property {number} [rangeTiles]
@@ -22,7 +22,7 @@ export const SPELL_DEFINITIONS = Object.freeze({
22 22 spellId: SpellId.spark,
23 23 displayName: "Spark",
24 24 difficulty: 4,
25 baseDamage: 2,
25 mindBonus: 2,
26 26 element: "fire",
27 27 effectId: null,
28 28 rangeTiles: 4,
@@ -5,7 +5,7 @@
5 * @property {string} spellId
5 * @property {string} spellId
6 * @property {string} displayName
6 * @property {string} displayName
7 * @property {number} difficulty Roll contest die size (1..difficulty) rolled against Magic
7 * @property {number} difficulty Roll contest die size (1..difficulty) rolled against Magic
8 * @property {number} [baseDamage]
8 * @property {number} [mindBonus] Added to the Mind damage roll on a successful cast
9 * @property {import("../combat/magic.js").SpellElement} [element]
9 * @property {import("../combat/magic.js").SpellElement} [element]
10 * @property {string|null} [effectId] Non-damage spells apply this when cast succeeds
10 * @property {string|null} [effectId] Non-damage spells apply this when cast succeeds
11 * @property {number} [rangeTiles]
11 * @property {number} [rangeTiles]
@@ -22,7 +22,7 @@ export const SPELL_DEFINITIONS = Object.freeze({
22 spellId: SpellId.spark,
22 spellId: SpellId.spark,
23 displayName: "Spark",
23 displayName: "Spark",
24 difficulty: 4,
24 difficulty: 4,
25 baseDamage: 2,
25 mindBonus: 2,
26 element: "fire",
26 element: "fire",
27 effectId: null,
27 effectId: null,
28 rangeTiles: 4,
28 rangeTiles: 4,
shared/definitions/tierFamilies.js added +375 −0
@@ -0,0 +1,375 @@
1 import { ItemCategory } from "./itemCategories.js";
2 import {
3 WoodTier,
4 MATERIAL_DISPLAY_NAME,
5 WOOD_TIER_ORDER,
6 MATERIAL_TIER_ORDER,
7 CLOTH_TIER_ORDER,
8 CLOTH_DISPLAY_NAME,
9 metalTierForWood,
10 clothTierForWood
11 } from "./materialTiers.js";
12 import { EquipmentKind } from "./equipmentKinds.js";
13 import { AttackType } from "./attackTypes.js";
14 import { SkillId } from "./skills.js";
15
16 /** Which tier list drives a family (`wood` → pine…elder, `metal` → bronze…dragon). */
17 export const TierAxis = Object.freeze({
18 wood: "wood",
19 metal: "metal",
20 cloth: "cloth"
21 });
22
23 /** Stable family ids — one template per intermediate / gather product shape. */
24 export const ItemFamilyId = Object.freeze({
25 log: "log",
26 handle: "handle",
27 ore: "ore",
28 bar: "bar",
29 pickaxeHead: "pickaxeHead",
30 axeHead: "axeHead",
31 pickaxe: "pickaxe",
32 axe: "axe",
33 plantClippers: "plantClippers",
34 arrowShaft: "arrowShaft",
35 arrowTip: "arrowTip",
36 arrow: "arrow",
37 unstrungBow: "unstrungBow",
38 bow: "bow",
39 bowstring: "bowstring"
40 });
41
42 const DEFAULT_STACK = 99;
43
44 /**
45 * Family templates: display suffix, sprite, stacking, and tier axis.
46 * Per-tier itemIds stay in woodItems / metalItems / rangedItems; defs are built here.
47 */
48 export const ITEM_FAMILIES = Object.freeze({
49 [ItemFamilyId.log]: Object.freeze({
50 familyId: ItemFamilyId.log,
51 axis: TierAxis.wood,
52 label: "log",
53 description: (name) => `A sturdy ${name.toLowerCase()} log.`,
54 category: ItemCategory.ingredient,
55 iconKey: "wood",
56 defaultState: "log",
57 stackable: true,
58 maxStackSize: DEFAULT_STACK,
59 seedValue: (tier) => (tier === WoodTier.pine ? 5 : 2),
60 tintFromTier: true,
61 npcShopAllowed: true
62 }),
63 [ItemFamilyId.handle]: Object.freeze({
64 familyId: ItemFamilyId.handle,
65 axis: TierAxis.wood,
66 label: "handle",
67 description: (name) => `Shaped ${name.toLowerCase()} haft. Combine with a matching toolhead.`,
68 category: ItemCategory.intermediate,
69 iconKey: "wood",
70 defaultState: "handle",
71 stackable: true,
72 maxStackSize: DEFAULT_STACK,
73 seedValue: 3,
74 tintFromTier: true
75 }),
76 [ItemFamilyId.ore]: Object.freeze({
77 familyId: ItemFamilyId.ore,
78 axis: TierAxis.metal,
79 label: "ore",
80 description: (name) => `Mined ${name.toLowerCase()} ore. Smelt at a furnace.`,
81 category: ItemCategory.ingredient,
82 iconKey: "metal",
83 defaultState: "ore",
84 stackable: true,
85 maxStackSize: DEFAULT_STACK,
86 seedValue: 2,
87 tintFromTier: true
88 }),
89 [ItemFamilyId.bar]: Object.freeze({
90 familyId: ItemFamilyId.bar,
91 axis: TierAxis.metal,
92 label: "bar",
93 description: (name) => `Smelted ${name.toLowerCase()}. Smith at an anvil.`,
94 category: ItemCategory.intermediate,
95 iconKey: "metal",
96 defaultState: "bar",
97 stackable: true,
98 maxStackSize: DEFAULT_STACK,
99 seedValue: 4,
100 tintFromTier: true
101 }),
102 [ItemFamilyId.pickaxeHead]: Object.freeze({
103 familyId: ItemFamilyId.pickaxeHead,
104 axis: TierAxis.metal,
105 label: "pickaxe head",
106 description: (name) => `Smithed ${name.toLowerCase()} head. Attach a matching handle at a crafting bench.`,
107 category: ItemCategory.intermediate,
108 iconKey: "pickaxe",
109 defaultState: "pickaxe-head",
110 stackable: true,
111 maxStackSize: DEFAULT_STACK,
112 seedValue: 5,
113 tintFromTier: true
114 }),
115 [ItemFamilyId.axeHead]: Object.freeze({
116 familyId: ItemFamilyId.axeHead,
117 axis: TierAxis.metal,
118 label: "axe head",
119 description: (name) => `Smithed ${name.toLowerCase()} head. Attach a matching handle at a crafting bench.`,
120 category: ItemCategory.intermediate,
121 iconKey: "axe",
122 defaultState: "axe-head",
123 stackable: true,
124 maxStackSize: DEFAULT_STACK,
125 seedValue: 5,
126 tintFromTier: true
127 }),
128 [ItemFamilyId.arrowShaft]: Object.freeze({
129 familyId: ItemFamilyId.arrowShaft,
130 axis: TierAxis.wood,
131 label: "arrow shaft",
132 description: () => "A straight wooden shaft, ready for fletching.",
133 category: ItemCategory.intermediate,
134 iconKey: "arrow",
135 defaultState: "shaft",
136 stackable: true,
137 maxStackSize: DEFAULT_STACK,
138 seedValue: 1,
139 tintFromTier: true
140 }),
141 [ItemFamilyId.arrowTip]: Object.freeze({
142 familyId: ItemFamilyId.arrowTip,
143 axis: TierAxis.metal,
144 label: "arrow tip",
145 description: (name) => `A smithed ${name.toLowerCase()} point for arrows.`,
146 category: ItemCategory.intermediate,
147 iconKey: "arrow",
148 defaultState: "tip",
149 stackable: true,
150 maxStackSize: DEFAULT_STACK,
151 seedValue: 1,
152 tintFromTier: true
153 }),
154 [ItemFamilyId.pickaxe]: Object.freeze({
155 familyId: ItemFamilyId.pickaxe,
156 axis: TierAxis.metal,
157 label: "pickaxe",
158 description: (name) => `A ${name.toLowerCase()} pickaxe for breaking stone and ore.`,
159 category: ItemCategory.tool,
160 iconKey: "pickaxe",
161 defaultState: "pickaxe",
162 stackable: false,
163 maxStackSize: 1,
164 seedValue: 8,
165 tintFromTier: true,
166 equipmentKind: EquipmentKind.pickaxeTool
167 }),
168 [ItemFamilyId.axe]: Object.freeze({
169 familyId: ItemFamilyId.axe,
170 axis: TierAxis.metal,
171 label: "axe",
172 description: (name) => `A ${name.toLowerCase()} axe for felling trees.`,
173 category: ItemCategory.tool,
174 iconKey: "axe",
175 defaultState: "axe",
176 stackable: false,
177 maxStackSize: 1,
178 seedValue: 8,
179 tintFromTier: true,
180 equipmentKind: EquipmentKind.axeTool
181 }),
182 [ItemFamilyId.plantClippers]: Object.freeze({
183 familyId: ItemFamilyId.plantClippers,
184 axis: TierAxis.metal,
185 label: "plant clippers",
186 description: () => "Fine shears for cutting herbs and blooms.",
187 category: ItemCategory.tool,
188 iconKey: "bronze-plant-clippers",
189 defaultState: "bronze-plant-clippers",
190 stackable: false,
191 maxStackSize: 1,
192 seedValue: 10,
193 tintFromTier: true,
194 npcShopAllowed: true,
195 equipmentKind: EquipmentKind.plantClippers,
196 equipmentTintFromTier: true
197 }),
198 [ItemFamilyId.arrow]: Object.freeze({
199 familyId: ItemFamilyId.arrow,
200 axis: TierAxis.metal,
201 label: "arrow",
202 description: () => "A fletched arrow with matching shaft and head.",
203 category: ItemCategory.finished,
204 iconKey: "arrow",
205 defaultState: "full-arrow",
206 stackable: true,
207 maxStackSize: 999,
208 seedValue: 2,
209 dualTintFromTier: true,
210 woodTierFromMetal: true,
211 equipmentKind: EquipmentKind.arrowAmmo,
212 equipmentSlot: "offhand",
213 hideEquipSprite: true
214 }),
215 [ItemFamilyId.unstrungBow]: Object.freeze({
216 familyId: ItemFamilyId.unstrungBow,
217 axis: TierAxis.wood,
218 label: "unstrung bow",
219 description: () => "A carved bow frame awaiting a string.",
220 category: ItemCategory.intermediate,
221 iconKey: "bow",
222 defaultState: "bow",
223 stackable: false,
224 maxStackSize: 1,
225 seedValue: 6,
226 tintFromTier: true
227 }),
228 [ItemFamilyId.bow]: Object.freeze({
229 familyId: ItemFamilyId.bow,
230 axis: TierAxis.wood,
231 label: "bow",
232 description: (name) => `A ${name.toLowerCase()} bow strung with matching yarn.`,
233 category: ItemCategory.finished,
234 iconKey: "bow",
235 defaultState: "bow",
236 stackable: false,
237 maxStackSize: 1,
238 seedValue: 12,
239 tintFromTier: true,
240 clothTierFromWood: true,
241 equipmentKind: EquipmentKind.bow,
242 equipmentTintFromTier: true,
243 equipmentAttack: Object.freeze({
244 mode: "ranged",
245 rangeTiles: 8,
246 hitSkillId: SkillId.archery,
247 damageSkillId: SkillId.dexterity,
248 attackType: AttackType.piercing,
249 cooldownMs: 1200
250 })
251 }),
252 [ItemFamilyId.bowstring]: Object.freeze({
253 familyId: ItemFamilyId.bowstring,
254 axis: TierAxis.cloth,
255 label: "bowstring",
256 description: () => "Twisted yarn spun tight for a bow.",
257 category: ItemCategory.intermediate,
258 iconKey: "cloth",
259 defaultState: "yarn",
260 stackable: true,
261 maxStackSize: DEFAULT_STACK,
262 seedValue: 2,
263 tintFromTier: true
264 })
265 });
266
267 export function tierOrderForAxis (axis)
268 {
269 if (axis === TierAxis.wood)
270 { return WOOD_TIER_ORDER; }
271 if (axis === TierAxis.metal)
272 { return MATERIAL_TIER_ORDER; }
273 if (axis === TierAxis.cloth)
274 { return CLOTH_TIER_ORDER; }
275 return [];
276 }
277
278 function buildFamilyEquipment (family, tier)
279 {
280 if (!family.equipmentKind)
281 { return null; }
282 const equipment = {
283 slot: family.equipmentSlot ?? "weapon",
284 tier,
285 kind: family.equipmentKind
286 };
287 if (family.equipmentTintFromTier)
288 { equipment.tintFromTier = true; }
289 if (family.hideEquipSprite)
290 { equipment.hideEquipSprite = true; }
291 if (family.equipmentAttack)
292 { equipment.attack = family.equipmentAttack; }
293 return Object.freeze(equipment);
294 }
295
296 export function familyDefinition (familyId)
297 {
298 return ITEM_FAMILIES[familyId] ?? null;
299 }
300
301 /**
302 * Build one tiered item definition from a family template.
303 * @param {string} familyId
304 * @param {string} tier
305 * @param {number} itemId stable numeric id (inventory / saves)
306 * @param {object} [extra] per-tier overrides (key, seedValue, description, …)
307 */
308 export function buildTierItemDef (familyId, tier, itemId, extra = {})
309 {
310 const family = familyDefinition(familyId);
311 if (!family)
312 { throw new Error(`Unknown item family: ${familyId}`); }
313 const name = family.axis === TierAxis.cloth
314 ? (CLOTH_DISPLAY_NAME[tier] ?? tier)
315 : (MATERIAL_DISPLAY_NAME[tier] ?? tier);
316 const key = extra.key ?? `${tier}-${family.label.replace(/ /g, "-")}`;
317 const seedValue = extra.seedValue ?? (
318 typeof family.seedValue === "function" ? family.seedValue(tier) : family.seedValue
319 );
320 const description = extra.description ?? family.description(name);
321 const equipment = extra.equipment ?? buildFamilyEquipment(family, tier);
322 return Object.freeze({
323 itemId,
324 familyId,
325 key,
326 displayName: extra.displayName ?? `${name} ${family.label}`,
327 description,
328 seedValue,
329 stackable: extra.stackable ?? family.stackable,
330 maxStackSize: extra.maxStackSize ?? family.maxStackSize,
331 uniqueInstance: false,
332 category: extra.category ?? family.category,
333 iconKey: extra.iconKey ?? family.iconKey,
334 defaultState: extra.defaultState ?? family.defaultState,
335 tier,
336 ...(family.tintFromTier ? { tintFromTier: true } : {}),
337 ...(family.npcShopAllowed ? { npcShopAllowed: true } : {}),
338 ...(family.woodTierFromMetal ? { woodTier: metalTierForWood(tier), dualTintFromTier: true } : {}),
339 ...(family.dualTintFromTier && !family.woodTierFromMetal ? { dualTintFromTier: true } : {}),
340 ...(family.clothTierFromWood ? { clothTier: clothTierForWood(tier) } : {}),
341 ...(equipment ? { equipment } : {})
342 });
343 }
344
345 /** Build `{ [itemId]: def }` from a tier → itemId map. */
346 export function buildFamilyDefinitionMap (familyId, tierToItemId, extraByTier = {})
347 {
348 const defs = {};
349 for (const [tier, id] of Object.entries(tierToItemId))
350 {
351 const itemId = id | 0;
352 if (!itemId)
353 { continue; }
354 defs[itemId] = buildTierItemDef(familyId, tier, itemId, extraByTier[tier] ?? {});
355 }
356 return defs;
357 }
358
359 /** Resolve itemId for a family tier from a lookup table. */
360 export function itemIdForFamilyTier (familyTierMap, tier)
361 {
362 return familyTierMap[tier] ?? null;
363 }
364
365 /** Reverse lookup: tier for an item id within a family map, or null. */
366 export function tierForFamilyItemId (familyTierMap, itemId)
367 {
368 const want = itemId | 0;
369 for (const [tier, id] of Object.entries(familyTierMap))
370 {
371 if ((id | 0) === want)
372 { return tier; }
373 }
374 return null;
375 }
@@ -0,0 +1,375 @@
1import { ItemCategory } from "./itemCategories.js";
2import {
3 WoodTier,
4 MATERIAL_DISPLAY_NAME,
5 WOOD_TIER_ORDER,
6 MATERIAL_TIER_ORDER,
7 CLOTH_TIER_ORDER,
8 CLOTH_DISPLAY_NAME,
9 metalTierForWood,
10 clothTierForWood
11} from "./materialTiers.js";
12import { EquipmentKind } from "./equipmentKinds.js";
13import { AttackType } from "./attackTypes.js";
14import { SkillId } from "./skills.js";
15
16/** Which tier list drives a family (`wood` → pine…elder, `metal` → bronze…dragon). */
17export const TierAxis = Object.freeze({
18 wood: "wood",
19 metal: "metal",
20 cloth: "cloth"
21});
22
23/** Stable family ids — one template per intermediate / gather product shape. */
24export const ItemFamilyId = Object.freeze({
25 log: "log",
26 handle: "handle",
27 ore: "ore",
28 bar: "bar",
29 pickaxeHead: "pickaxeHead",
30 axeHead: "axeHead",
31 pickaxe: "pickaxe",
32 axe: "axe",
33 plantClippers: "plantClippers",
34 arrowShaft: "arrowShaft",
35 arrowTip: "arrowTip",
36 arrow: "arrow",
37 unstrungBow: "unstrungBow",
38 bow: "bow",
39 bowstring: "bowstring"
40});
41
42const DEFAULT_STACK = 99;
43
44/**
45 * Family templates: display suffix, sprite, stacking, and tier axis.
46 * Per-tier itemIds stay in woodItems / metalItems / rangedItems; defs are built here.
47 */
48export const ITEM_FAMILIES = Object.freeze({
49 [ItemFamilyId.log]: Object.freeze({
50 familyId: ItemFamilyId.log,
51 axis: TierAxis.wood,
52 label: "log",
53 description: (name) => `A sturdy ${name.toLowerCase()} log.`,
54 category: ItemCategory.ingredient,
55 iconKey: "wood",
56 defaultState: "log",
57 stackable: true,
58 maxStackSize: DEFAULT_STACK,
59 seedValue: (tier) => (tier === WoodTier.pine ? 5 : 2),
60 tintFromTier: true,
61 npcShopAllowed: true
62 }),
63 [ItemFamilyId.handle]: Object.freeze({
64 familyId: ItemFamilyId.handle,
65 axis: TierAxis.wood,
66 label: "handle",
67 description: (name) => `Shaped ${name.toLowerCase()} haft. Combine with a matching toolhead.`,
68 category: ItemCategory.intermediate,
69 iconKey: "wood",
70 defaultState: "handle",
71 stackable: true,
72 maxStackSize: DEFAULT_STACK,
73 seedValue: 3,
74 tintFromTier: true
75 }),
76 [ItemFamilyId.ore]: Object.freeze({
77 familyId: ItemFamilyId.ore,
78 axis: TierAxis.metal,
79 label: "ore",
80 description: (name) => `Mined ${name.toLowerCase()} ore. Smelt at a furnace.`,
81 category: ItemCategory.ingredient,
82 iconKey: "metal",
83 defaultState: "ore",
84 stackable: true,
85 maxStackSize: DEFAULT_STACK,
86 seedValue: 2,
87 tintFromTier: true
88 }),
89 [ItemFamilyId.bar]: Object.freeze({
90 familyId: ItemFamilyId.bar,
91 axis: TierAxis.metal,
92 label: "bar",
93 description: (name) => `Smelted ${name.toLowerCase()}. Smith at an anvil.`,
94 category: ItemCategory.intermediate,
95 iconKey: "metal",
96 defaultState: "bar",
97 stackable: true,
98 maxStackSize: DEFAULT_STACK,
99 seedValue: 4,
100 tintFromTier: true
101 }),
102 [ItemFamilyId.pickaxeHead]: Object.freeze({
103 familyId: ItemFamilyId.pickaxeHead,
104 axis: TierAxis.metal,
105 label: "pickaxe head",
106 description: (name) => `Smithed ${name.toLowerCase()} head. Attach a matching handle at a crafting bench.`,
107 category: ItemCategory.intermediate,
108 iconKey: "pickaxe",
109 defaultState: "pickaxe-head",
110 stackable: true,
111 maxStackSize: DEFAULT_STACK,
112 seedValue: 5,
113 tintFromTier: true
114 }),
115 [ItemFamilyId.axeHead]: Object.freeze({
116 familyId: ItemFamilyId.axeHead,
117 axis: TierAxis.metal,
118 label: "axe head",
119 description: (name) => `Smithed ${name.toLowerCase()} head. Attach a matching handle at a crafting bench.`,
120 category: ItemCategory.intermediate,
121 iconKey: "axe",
122 defaultState: "axe-head",
123 stackable: true,
124 maxStackSize: DEFAULT_STACK,
125 seedValue: 5,
126 tintFromTier: true
127 }),
128 [ItemFamilyId.arrowShaft]: Object.freeze({
129 familyId: ItemFamilyId.arrowShaft,
130 axis: TierAxis.wood,
131 label: "arrow shaft",
132 description: () => "A straight wooden shaft, ready for fletching.",
133 category: ItemCategory.intermediate,
134 iconKey: "arrow",
135 defaultState: "shaft",
136 stackable: true,
137 maxStackSize: DEFAULT_STACK,
138 seedValue: 1,
139 tintFromTier: true
140 }),
141 [ItemFamilyId.arrowTip]: Object.freeze({
142 familyId: ItemFamilyId.arrowTip,
143 axis: TierAxis.metal,
144 label: "arrow tip",
145 description: (name) => `A smithed ${name.toLowerCase()} point for arrows.`,
146 category: ItemCategory.intermediate,
147 iconKey: "arrow",
148 defaultState: "tip",
149 stackable: true,
150 maxStackSize: DEFAULT_STACK,
151 seedValue: 1,
152 tintFromTier: true
153 }),
154 [ItemFamilyId.pickaxe]: Object.freeze({
155 familyId: ItemFamilyId.pickaxe,
156 axis: TierAxis.metal,
157 label: "pickaxe",
158 description: (name) => `A ${name.toLowerCase()} pickaxe for breaking stone and ore.`,
159 category: ItemCategory.tool,
160 iconKey: "pickaxe",
161 defaultState: "pickaxe",
162 stackable: false,
163 maxStackSize: 1,
164 seedValue: 8,
165 tintFromTier: true,
166 equipmentKind: EquipmentKind.pickaxeTool
167 }),
168 [ItemFamilyId.axe]: Object.freeze({
169 familyId: ItemFamilyId.axe,
170 axis: TierAxis.metal,
171 label: "axe",
172 description: (name) => `A ${name.toLowerCase()} axe for felling trees.`,
173 category: ItemCategory.tool,
174 iconKey: "axe",
175 defaultState: "axe",
176 stackable: false,
177 maxStackSize: 1,
178 seedValue: 8,
179 tintFromTier: true,
180 equipmentKind: EquipmentKind.axeTool
181 }),
182 [ItemFamilyId.plantClippers]: Object.freeze({
183 familyId: ItemFamilyId.plantClippers,
184 axis: TierAxis.metal,
185 label: "plant clippers",
186 description: () => "Fine shears for cutting herbs and blooms.",
187 category: ItemCategory.tool,
188 iconKey: "bronze-plant-clippers",
189 defaultState: "bronze-plant-clippers",
190 stackable: false,
191 maxStackSize: 1,
192 seedValue: 10,
193 tintFromTier: true,
194 npcShopAllowed: true,
195 equipmentKind: EquipmentKind.plantClippers,
196 equipmentTintFromTier: true
197 }),
198 [ItemFamilyId.arrow]: Object.freeze({
199 familyId: ItemFamilyId.arrow,
200 axis: TierAxis.metal,
201 label: "arrow",
202 description: () => "A fletched arrow with matching shaft and head.",
203 category: ItemCategory.finished,
204 iconKey: "arrow",
205 defaultState: "full-arrow",
206 stackable: true,
207 maxStackSize: 999,
208 seedValue: 2,
209 dualTintFromTier: true,
210 woodTierFromMetal: true,
211 equipmentKind: EquipmentKind.arrowAmmo,
212 equipmentSlot: "offhand",
213 hideEquipSprite: true
214 }),
215 [ItemFamilyId.unstrungBow]: Object.freeze({
216 familyId: ItemFamilyId.unstrungBow,
217 axis: TierAxis.wood,
218 label: "unstrung bow",
219 description: () => "A carved bow frame awaiting a string.",
220 category: ItemCategory.intermediate,
221 iconKey: "bow",
222 defaultState: "bow",
223 stackable: false,
224 maxStackSize: 1,
225 seedValue: 6,
226 tintFromTier: true
227 }),
228 [ItemFamilyId.bow]: Object.freeze({
229 familyId: ItemFamilyId.bow,
230 axis: TierAxis.wood,
231 label: "bow",
232 description: (name) => `A ${name.toLowerCase()} bow strung with matching yarn.`,
233 category: ItemCategory.finished,
234 iconKey: "bow",
235 defaultState: "bow",
236 stackable: false,
237 maxStackSize: 1,
238 seedValue: 12,
239 tintFromTier: true,
240 clothTierFromWood: true,
241 equipmentKind: EquipmentKind.bow,
242 equipmentTintFromTier: true,
243 equipmentAttack: Object.freeze({
244 mode: "ranged",
245 rangeTiles: 8,
246 hitSkillId: SkillId.archery,
247 damageSkillId: SkillId.dexterity,
248 attackType: AttackType.piercing,
249 cooldownMs: 1200
250 })
251 }),
252 [ItemFamilyId.bowstring]: Object.freeze({
253 familyId: ItemFamilyId.bowstring,
254 axis: TierAxis.cloth,
255 label: "bowstring",
256 description: () => "Twisted yarn spun tight for a bow.",
257 category: ItemCategory.intermediate,
258 iconKey: "cloth",
259 defaultState: "yarn",
260 stackable: true,
261 maxStackSize: DEFAULT_STACK,
262 seedValue: 2,
263 tintFromTier: true
264 })
265});
266
267export function tierOrderForAxis (axis)
268{
269 if (axis === TierAxis.wood)
270 { return WOOD_TIER_ORDER; }
271 if (axis === TierAxis.metal)
272 { return MATERIAL_TIER_ORDER; }
273 if (axis === TierAxis.cloth)
274 { return CLOTH_TIER_ORDER; }
275 return [];
276}
277
278function buildFamilyEquipment (family, tier)
279{
280 if (!family.equipmentKind)
281 { return null; }
282 const equipment = {
283 slot: family.equipmentSlot ?? "weapon",
284 tier,
285 kind: family.equipmentKind
286 };
287 if (family.equipmentTintFromTier)
288 { equipment.tintFromTier = true; }
289 if (family.hideEquipSprite)
290 { equipment.hideEquipSprite = true; }
291 if (family.equipmentAttack)
292 { equipment.attack = family.equipmentAttack; }
293 return Object.freeze(equipment);
294}
295
296export function familyDefinition (familyId)
297{
298 return ITEM_FAMILIES[familyId] ?? null;
299}
300
301/**
302 * Build one tiered item definition from a family template.
303 * @param {string} familyId
304 * @param {string} tier
305 * @param {number} itemId stable numeric id (inventory / saves)
306 * @param {object} [extra] per-tier overrides (key, seedValue, description, …)
307 */
308export function buildTierItemDef (familyId, tier, itemId, extra = {})
309{
310 const family = familyDefinition(familyId);
311 if (!family)
312 { throw new Error(`Unknown item family: ${familyId}`); }
313 const name = family.axis === TierAxis.cloth
314 ? (CLOTH_DISPLAY_NAME[tier] ?? tier)
315 : (MATERIAL_DISPLAY_NAME[tier] ?? tier);
316 const key = extra.key ?? `${tier}-${family.label.replace(/ /g, "-")}`;
317 const seedValue = extra.seedValue ?? (
318 typeof family.seedValue === "function" ? family.seedValue(tier) : family.seedValue
319 );
320 const description = extra.description ?? family.description(name);
321 const equipment = extra.equipment ?? buildFamilyEquipment(family, tier);
322 return Object.freeze({
323 itemId,
324 familyId,
325 key,
326 displayName: extra.displayName ?? `${name} ${family.label}`,
327 description,
328 seedValue,
329 stackable: extra.stackable ?? family.stackable,
330 maxStackSize: extra.maxStackSize ?? family.maxStackSize,
331 uniqueInstance: false,
332 category: extra.category ?? family.category,
333 iconKey: extra.iconKey ?? family.iconKey,
334 defaultState: extra.defaultState ?? family.defaultState,
335 tier,
336 ...(family.tintFromTier ? { tintFromTier: true } : {}),
337 ...(family.npcShopAllowed ? { npcShopAllowed: true } : {}),
338 ...(family.woodTierFromMetal ? { woodTier: metalTierForWood(tier), dualTintFromTier: true } : {}),
339 ...(family.dualTintFromTier && !family.woodTierFromMetal ? { dualTintFromTier: true } : {}),
340 ...(family.clothTierFromWood ? { clothTier: clothTierForWood(tier) } : {}),
341 ...(equipment ? { equipment } : {})
342 });
343}
344
345/** Build `{ [itemId]: def }` from a tier → itemId map. */
346export function buildFamilyDefinitionMap (familyId, tierToItemId, extraByTier = {})
347{
348 const defs = {};
349 for (const [tier, id] of Object.entries(tierToItemId))
350 {
351 const itemId = id | 0;
352 if (!itemId)
353 { continue; }
354 defs[itemId] = buildTierItemDef(familyId, tier, itemId, extraByTier[tier] ?? {});
355 }
356 return defs;
357}
358
359/** Resolve itemId for a family tier from a lookup table. */
360export function itemIdForFamilyTier (familyTierMap, tier)
361{
362 return familyTierMap[tier] ?? null;
363}
364
365/** Reverse lookup: tier for an item id within a family map, or null. */
366export function tierForFamilyItemId (familyTierMap, itemId)
367{
368 const want = itemId | 0;
369 for (const [tier, id] of Object.entries(familyTierMap))
370 {
371 if ((id | 0) === want)
372 { return tier; }
373 }
374 return null;
375}
shared/definitions/woodItems.js +12 −59
@@ -1,9 +1,12 @@
1 import { ItemCategory } from "./itemCategories.js";
2 1 import {
3 2 WoodTier,
4 WOOD_TIER_ORDER,
5 MATERIAL_DISPLAY_NAME
3 WOOD_TIER_ORDER
6 4 } from "./materialTiers.js";
5 import {
6 ItemFamilyId,
7 buildFamilyDefinitionMap,
8 itemIdForFamilyTier
9 } from "./tierFamilies.js";
7 10
8 11 /**
9 12 * Wood logs and handles.
@@ -27,8 +30,6 @@ export const WoodItemId = Object.freeze({
27 30 elderHandle: 66
28 31 });
29 32
30 const DEFAULT_STACK = 99;
31
32 33 const LOG_IDS = Object.freeze({
33 34 [WoodTier.pine]: WoodItemId.pineLog,
34 35 [WoodTier.birch]: WoodItemId.birchLog,
@@ -49,69 +50,21 @@ const HANDLE_IDS = Object.freeze({
49 50 [WoodTier.elder]: WoodItemId.elderHandle
50 51 });
51 52
52 function logDef (itemId, tier)
53 {
54 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
55 return Object.freeze({
56 itemId,
57 key: `${tier}-log`,
58 displayName: `${name} log`,
59 description: `A sturdy ${name.toLowerCase()} log.`,
60 seedValue: tier === WoodTier.pine ? 5 : 2,
61 stackable: true,
62 maxStackSize: DEFAULT_STACK,
63 uniqueInstance: false,
64 category: ItemCategory.ingredient,
65 iconKey: "wood",
66 defaultState: "log",
67 tier,
68 tintFromTier: true,
69 npcShopAllowed: true
70 });
71 }
72
73 function handleDef (itemId, tier)
74 {
75 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
76 return Object.freeze({
77 itemId,
78 key: `${tier}-handle`,
79 displayName: `${name} handle`,
80 description: `Shaped ${name.toLowerCase()} haft. Combine with a matching toolhead.`,
81 seedValue: 3,
82 stackable: true,
83 maxStackSize: DEFAULT_STACK,
84 uniqueInstance: false,
85 category: ItemCategory.intermediate,
86 iconKey: "wood",
87 defaultState: "handle",
88 tier,
89 tintFromTier: true
90 });
91 }
92
93 53 export const LOG_ITEM_BY_WOOD = LOG_IDS;
94 54 export const HANDLE_ITEM_BY_WOOD = HANDLE_IDS;
95 55
96 56 export function logItemIdForWood (woodTier)
97 57 {
98 return LOG_IDS[woodTier] ?? null;
58 return itemIdForFamilyTier(LOG_IDS, woodTier);
99 59 }
100 60
101 61 export function handleItemIdForWood (woodTier)
102 62 {
103 return HANDLE_IDS[woodTier] ?? null;
63 return itemIdForFamilyTier(HANDLE_IDS, woodTier);
104 64 }
105 65
106 66 /** Full defs for wood family (merged into ITEM_DEFINITIONS). */
107 export const WOOD_ITEM_DEFINITIONS = Object.freeze(Object.fromEntries(
108 WOOD_TIER_ORDER.flatMap((tier) =>
109 {
110 const logId = LOG_IDS[tier];
111 const handleId = HANDLE_IDS[tier];
112 return [
113 [logId, logDef(logId, tier)],
114 [handleId, handleDef(handleId, tier)]
115 ];
116 })
117 ));
67 export const WOOD_ITEM_DEFINITIONS = Object.freeze({
68 ...buildFamilyDefinitionMap(ItemFamilyId.log, LOG_IDS),
69 ...buildFamilyDefinitionMap(ItemFamilyId.handle, HANDLE_IDS)
70 });
@@ -1,9 +1,12 @@
1import { ItemCategory } from "./itemCategories.js";
2import {
1import {
3 WoodTier,
2 WoodTier,
4 WOOD_TIER_ORDER,
3 WOOD_TIER_ORDER
5 MATERIAL_DISPLAY_NAME
6} from "./materialTiers.js";
4} from "./materialTiers.js";
5import {
6 ItemFamilyId,
7 buildFamilyDefinitionMap,
8 itemIdForFamilyTier
9} from "./tierFamilies.js";
7
10
8/**
11/**
9 * Wood logs and handles.
12 * Wood logs and handles.
@@ -27,8 +30,6 @@ export const WoodItemId = Object.freeze({
27 elderHandle: 66
30 elderHandle: 66
28});
31});
29
32
30const DEFAULT_STACK = 99;
31
32const LOG_IDS = Object.freeze({
33const LOG_IDS = Object.freeze({
33 [WoodTier.pine]: WoodItemId.pineLog,
34 [WoodTier.pine]: WoodItemId.pineLog,
34 [WoodTier.birch]: WoodItemId.birchLog,
35 [WoodTier.birch]: WoodItemId.birchLog,
@@ -49,69 +50,21 @@ const HANDLE_IDS = Object.freeze({
49 [WoodTier.elder]: WoodItemId.elderHandle
50 [WoodTier.elder]: WoodItemId.elderHandle
50});
51});
51
52
52function logDef (itemId, tier)
53{
54 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
55 return Object.freeze({
56 itemId,
57 key: `${tier}-log`,
58 displayName: `${name} log`,
59 description: `A sturdy ${name.toLowerCase()} log.`,
60 seedValue: tier === WoodTier.pine ? 5 : 2,
61 stackable: true,
62 maxStackSize: DEFAULT_STACK,
63 uniqueInstance: false,
64 category: ItemCategory.ingredient,
65 iconKey: "wood",
66 defaultState: "log",
67 tier,
68 tintFromTier: true,
69 npcShopAllowed: true
70 });
71}
72
73function handleDef (itemId, tier)
74{
75 const name = MATERIAL_DISPLAY_NAME[tier] ?? tier;
76 return Object.freeze({
77 itemId,
78 key: `${tier}-handle`,
79 displayName: `${name} handle`,
80 description: `Shaped ${name.toLowerCase()} haft. Combine with a matching toolhead.`,
81 seedValue: 3,
82 stackable: true,
83 maxStackSize: DEFAULT_STACK,
84 uniqueInstance: false,
85 category: ItemCategory.intermediate,
86 iconKey: "wood",
87 defaultState: "handle",
88 tier,
89 tintFromTier: true
90 });
91}
92
93export const LOG_ITEM_BY_WOOD = LOG_IDS;
53export const LOG_ITEM_BY_WOOD = LOG_IDS;
94export const HANDLE_ITEM_BY_WOOD = HANDLE_IDS;
54export const HANDLE_ITEM_BY_WOOD = HANDLE_IDS;
95
55
96export function logItemIdForWood (woodTier)
56export function logItemIdForWood (woodTier)
97{
57{
98 return LOG_IDS[woodTier] ?? null;
58 return itemIdForFamilyTier(LOG_IDS, woodTier);
99}
59}
100
60
101export function handleItemIdForWood (woodTier)
61export function handleItemIdForWood (woodTier)
102{
62{
103 return HANDLE_IDS[woodTier] ?? null;
63 return itemIdForFamilyTier(HANDLE_IDS, woodTier);
104}
64}
105
65
106/** Full defs for wood family (merged into ITEM_DEFINITIONS). */
66/** Full defs for wood family (merged into ITEM_DEFINITIONS). */
107export const WOOD_ITEM_DEFINITIONS = Object.freeze(Object.fromEntries(
67export const WOOD_ITEM_DEFINITIONS = Object.freeze({
108 WOOD_TIER_ORDER.flatMap((tier) =>
68 ...buildFamilyDefinitionMap(ItemFamilyId.log, LOG_IDS),
109 {
69 ...buildFamilyDefinitionMap(ItemFamilyId.handle, HANDLE_IDS)
110 const logId = LOG_IDS[tier];
70});
111 const handleId = HANDLE_IDS[tier];
112 return [
113 [logId, logDef(logId, tier)],
114 [handleId, handleDef(handleId, tier)]
115 ];
116 })
117));
shared/equipment/stats.js +3 −1
@@ -9,12 +9,14 @@ export { EquipmentKind } from "../definitions/equipmentKinds.js";
9 9 const BONUS_STAT_BY_KIND = Object.freeze({
10 10 [EquipmentKind.metalWeapon]: SkillId.strength,
11 11 [EquipmentKind.clubWeapon]: SkillId.strength,
12 [EquipmentKind.bow]: SkillId.dexterity,
13 [EquipmentKind.arrowAmmo]: SkillId.dexterity,
12 14 [EquipmentKind.metalArmour]: SkillId.defence,
13 15 [EquipmentKind.leatherArmour]: SkillId.dexterity,
14 16 [EquipmentKind.clothArmour]: SkillId.defence,
15 17 [EquipmentKind.wizardCloth]: SkillId.magic,
16 18 [EquipmentKind.shield]: SkillId.defence,
17 [EquipmentKind.staff]: SkillId.mind
19 [EquipmentKind.staff]: SkillId.magic
18 20 });
19 21
20 22 export function equipMinSkillId (equipmentDef)
@@ -9,12 +9,14 @@ export { EquipmentKind } from "../definitions/equipmentKinds.js";
9const BONUS_STAT_BY_KIND = Object.freeze({
9const BONUS_STAT_BY_KIND = Object.freeze({
10 [EquipmentKind.metalWeapon]: SkillId.strength,
10 [EquipmentKind.metalWeapon]: SkillId.strength,
11 [EquipmentKind.clubWeapon]: SkillId.strength,
11 [EquipmentKind.clubWeapon]: SkillId.strength,
12 [EquipmentKind.bow]: SkillId.dexterity,
13 [EquipmentKind.arrowAmmo]: SkillId.dexterity,
12 [EquipmentKind.metalArmour]: SkillId.defence,
14 [EquipmentKind.metalArmour]: SkillId.defence,
13 [EquipmentKind.leatherArmour]: SkillId.dexterity,
15 [EquipmentKind.leatherArmour]: SkillId.dexterity,
14 [EquipmentKind.clothArmour]: SkillId.defence,
16 [EquipmentKind.clothArmour]: SkillId.defence,
15 [EquipmentKind.wizardCloth]: SkillId.magic,
17 [EquipmentKind.wizardCloth]: SkillId.magic,
16 [EquipmentKind.shield]: SkillId.defence,
18 [EquipmentKind.shield]: SkillId.defence,
17 [EquipmentKind.staff]: SkillId.mind
19 [EquipmentKind.staff]: SkillId.magic
18});
20});
19
21
20export function equipMinSkillId (equipmentDef)
22export function equipMinSkillId (equipmentDef)
shared/render/tint.js +99 −1
@@ -1,4 +1,4 @@
1 import { MATERIAL_TIER_ORDER, materialTintColor, GatherMaterialId } from "../definitions/materialTiers.js";
1 import { MATERIAL_TIER_ORDER, materialTintColor, GatherMaterialId, metalTierForWood } from "../definitions/materialTiers.js";
2 2 import { itemDefinition } from "../definitions/items.js";
3 3
4 4 /**
@@ -9,8 +9,104 @@ import { itemDefinition } from "../definitions/items.js";
9 9 * - G > 0 (still G < R) desaturates toward the tint's own gray (not white),
10 10 * so dark target colours stay dark: mix(tint, vec3(luma(tint)), G/R) * L.
11 11 * - Otherwise leave RGB as-is. World shaders apply darkness after this pass.
12 *
13 * Dual-channel arrows ({@link applyDualChannelTintToImageData}):
14 * - Dominant red (R > G,B): shaft mask; lightness = R; tint with shaft colour.
15 * - Dominant blue (B > R,G): tip mask; lightness = B; tint with tip colour.
16 * - Neutral / white (fletching): neither channel dominates — RGB unchanged.
12 17 */
13 18
19 /** Mask strength when a paint channel dominates (matches world dual-tint shader). */
20 export function channelDominanceMask (r, g, b, channel)
21 {
22 if (channel === "shaft")
23 { return clamp01((r - Math.max(g, b)) * 1.75); }
24 return clamp01((b - Math.max(r, g)) * 1.75);
25 }
26
27 /** Tint pixels where `channel` dominates, preserving channel lightness. */
28 export function channelTintedRgb (r, g, b, channel, tintRgb)
29 {
30 const mask = channelDominanceMask(r, g, b, channel);
31 if (mask <= 0)
32 { return null; }
33 const L = channel === "shaft" ? r : b;
34 const gBlend = L > 0 ? Math.min(1, Math.max(0, g / L)) : 0;
35 const tint = normalizeRgb(tintRgb);
36 const tintLuma = luminance(tint.r, tint.g, tint.b);
37 return {
38 r: clamp01(mix(tint.r, tintLuma, gBlend) * L),
39 g: clamp01(mix(tint.g, tintLuma, gBlend) * L),
40 b: clamp01(mix(tint.b, tintLuma, gBlend) * L),
41 mask
42 };
43 }
44
45 /** Shaft + tip channel tints for full-arrow sprites. */
46 export function dualChannelTintedRgb (r, g, b, shaftTint, tipTint)
47 {
48 let rgb = { r, g, b };
49 const tip = channelTintedRgb(r, g, b, "tip", tipTint);
50 if (tip)
51 {
52 rgb = {
53 r: mix(r, tip.r, tip.mask),
54 g: mix(g, tip.g, tip.mask),
55 b: mix(b, tip.b, tip.mask)
56 };
57 }
58 const shaft = channelTintedRgb(r, g, b, "shaft", shaftTint);
59 if (shaft)
60 {
61 rgb = {
62 r: mix(rgb.r, shaft.r, shaft.mask),
63 g: mix(rgb.g, shaft.g, shaft.mask),
64 b: mix(rgb.b, shaft.b, shaft.mask)
65 };
66 }
67 return rgb;
68 }
69
70 /** Mutate ImageData: red channel = shaft, blue = tip, white unchanged. */
71 export function applyDualChannelTintToImageData (imageData, { shaft, tip })
72 {
73 const data = imageData.data;
74 const shaftTint = normalizeRgb(shaft);
75 const tipTint = normalizeRgb(tip);
76 for (let i = 0; i < data.length; i += 4)
77 {
78 if (data[i + 3] < 8)
79 { continue; }
80 const r = data[i] / 255;
81 const g = data[i + 1] / 255;
82 const b = data[i + 2] / 255;
83 const next = dualChannelTintedRgb(r, g, b, shaftTint, tipTint);
84 data[i] = Math.round(next.r * 255);
85 data[i + 1] = Math.round(next.g * 255);
86 data[i + 2] = Math.round(next.b * 255);
87 }
88 return imageData;
89 }
90
91 /** Dual shaft/tip tier tints for assembled arrows (`dualTintFromTier` on item def). */
92 export function resolveItemDualTint (stackOrDef, def = null)
93 {
94 const stack = stackOrDef?.itemId != null ? stackOrDef : null;
95 const definition = def
96 ?? (stack ? itemDefinition(stack.itemId) : stackOrDef)
97 ?? null;
98 if (!definition?.dualTintFromTier)
99 { return null; }
100 const metalTier = definition.tier ?? definition.equipment?.tier ?? null;
101 const woodTier = definition.woodTier ?? (metalTier ? metalTierForWood(metalTier) : null);
102 if (!metalTier || !woodTier)
103 { return null; }
104 return {
105 shaft: tierTintColor(woodTier),
106 tip: tierTintColor(metalTier)
107 };
108 }
109
14 110 /** Max |R − B| in 0–255 channel units for near-magenta pixels. */
15 111 export const MAGENTA_CHANNEL_TOLERANCE = 2;
16 112
@@ -56,6 +152,8 @@ export function resolveItemTint (stackOrDef, def = null)
56 152 { return normalizeRgb(stack.instance.dyeColor); }
57 153 if (definition?.tint)
58 154 { return normalizeRgb(definition.tint); }
155 if (definition?.dualTintFromTier)
156 { return null; }
59 157 const tier = resolveTintTier(definition);
60 158 if (tier)
61 159 { return tierTintColor(tier, { ore: isOreItemDefinition(definition) }); }
@@ -1,4 +1,4 @@
1import { MATERIAL_TIER_ORDER, materialTintColor, GatherMaterialId } from "../definitions/materialTiers.js";
1import { MATERIAL_TIER_ORDER, materialTintColor, GatherMaterialId, metalTierForWood } from "../definitions/materialTiers.js";
2import { itemDefinition } from "../definitions/items.js";
2import { itemDefinition } from "../definitions/items.js";
3
3
4/**
4/**
@@ -9,8 +9,104 @@ import { itemDefinition } from "../definitions/items.js";
9 * - G > 0 (still G < R) desaturates toward the tint's own gray (not white),
9 * - G > 0 (still G < R) desaturates toward the tint's own gray (not white),
10 * so dark target colours stay dark: mix(tint, vec3(luma(tint)), G/R) * L.
10 * so dark target colours stay dark: mix(tint, vec3(luma(tint)), G/R) * L.
11 * - Otherwise leave RGB as-is. World shaders apply darkness after this pass.
11 * - Otherwise leave RGB as-is. World shaders apply darkness after this pass.
12 *
13 * Dual-channel arrows ({@link applyDualChannelTintToImageData}):
14 * - Dominant red (R > G,B): shaft mask; lightness = R; tint with shaft colour.
15 * - Dominant blue (B > R,G): tip mask; lightness = B; tint with tip colour.
16 * - Neutral / white (fletching): neither channel dominates — RGB unchanged.
12 */
17 */
13
18
19/** Mask strength when a paint channel dominates (matches world dual-tint shader). */
20export function channelDominanceMask (r, g, b, channel)
21{
22 if (channel === "shaft")
23 { return clamp01((r - Math.max(g, b)) * 1.75); }
24 return clamp01((b - Math.max(r, g)) * 1.75);
25}
26
27/** Tint pixels where `channel` dominates, preserving channel lightness. */
28export function channelTintedRgb (r, g, b, channel, tintRgb)
29{
30 const mask = channelDominanceMask(r, g, b, channel);
31 if (mask <= 0)
32 { return null; }
33 const L = channel === "shaft" ? r : b;
34 const gBlend = L > 0 ? Math.min(1, Math.max(0, g / L)) : 0;
35 const tint = normalizeRgb(tintRgb);
36 const tintLuma = luminance(tint.r, tint.g, tint.b);
37 return {
38 r: clamp01(mix(tint.r, tintLuma, gBlend) * L),
39 g: clamp01(mix(tint.g, tintLuma, gBlend) * L),
40 b: clamp01(mix(tint.b, tintLuma, gBlend) * L),
41 mask
42 };
43}
44
45/** Shaft + tip channel tints for full-arrow sprites. */
46export function dualChannelTintedRgb (r, g, b, shaftTint, tipTint)
47{
48 let rgb = { r, g, b };
49 const tip = channelTintedRgb(r, g, b, "tip", tipTint);
50 if (tip)
51 {
52 rgb = {
53 r: mix(r, tip.r, tip.mask),
54 g: mix(g, tip.g, tip.mask),
55 b: mix(b, tip.b, tip.mask)
56 };
57 }
58 const shaft = channelTintedRgb(r, g, b, "shaft", shaftTint);
59 if (shaft)
60 {
61 rgb = {
62 r: mix(rgb.r, shaft.r, shaft.mask),
63 g: mix(rgb.g, shaft.g, shaft.mask),
64 b: mix(rgb.b, shaft.b, shaft.mask)
65 };
66 }
67 return rgb;
68}
69
70/** Mutate ImageData: red channel = shaft, blue = tip, white unchanged. */
71export function applyDualChannelTintToImageData (imageData, { shaft, tip })
72{
73 const data = imageData.data;
74 const shaftTint = normalizeRgb(shaft);
75 const tipTint = normalizeRgb(tip);
76 for (let i = 0; i < data.length; i += 4)
77 {
78 if (data[i + 3] < 8)
79 { continue; }
80 const r = data[i] / 255;
81 const g = data[i + 1] / 255;
82 const b = data[i + 2] / 255;
83 const next = dualChannelTintedRgb(r, g, b, shaftTint, tipTint);
84 data[i] = Math.round(next.r * 255);
85 data[i + 1] = Math.round(next.g * 255);
86 data[i + 2] = Math.round(next.b * 255);
87 }
88 return imageData;
89}
90
91/** Dual shaft/tip tier tints for assembled arrows (`dualTintFromTier` on item def). */
92export function resolveItemDualTint (stackOrDef, def = null)
93{
94 const stack = stackOrDef?.itemId != null ? stackOrDef : null;
95 const definition = def
96 ?? (stack ? itemDefinition(stack.itemId) : stackOrDef)
97 ?? null;
98 if (!definition?.dualTintFromTier)
99 { return null; }
100 const metalTier = definition.tier ?? definition.equipment?.tier ?? null;
101 const woodTier = definition.woodTier ?? (metalTier ? metalTierForWood(metalTier) : null);
102 if (!metalTier || !woodTier)
103 { return null; }
104 return {
105 shaft: tierTintColor(woodTier),
106 tip: tierTintColor(metalTier)
107 };
108}
109
14/** Max |R − B| in 0–255 channel units for near-magenta pixels. */
110/** Max |R − B| in 0–255 channel units for near-magenta pixels. */
15export const MAGENTA_CHANNEL_TOLERANCE = 2;
111export const MAGENTA_CHANNEL_TOLERANCE = 2;
16
112
@@ -56,6 +152,8 @@ export function resolveItemTint (stackOrDef, def = null)
56 { return normalizeRgb(stack.instance.dyeColor); }
152 { return normalizeRgb(stack.instance.dyeColor); }
57 if (definition?.tint)
153 if (definition?.tint)
58 { return normalizeRgb(definition.tint); }
154 { return normalizeRgb(definition.tint); }
155 if (definition?.dualTintFromTier)
156 { return null; }
59 const tier = resolveTintTier(definition);
157 const tier = resolveTintTier(definition);
60 if (tier)
158 if (tier)
61 { return tierTintColor(tier, { ore: isOreItemDefinition(definition) }); }
159 { return tierTintColor(tier, { ore: isOreItemDefinition(definition) }); }
shared/skills/progression.js +11 −4
@@ -59,10 +59,17 @@ export function levelFromTotalXp (totalXp)
59 59 return xpProgress(totalXp).level;
60 60 }
61 61
62 /** Split combat hit XP equally between hit and damage skills. */
63 export const COMBAT_HIT_XP_TOTAL = 10;
62 /** XP from damage dealt — applied to each related combat skill on a hit. */
63 export function combatDamageXp (damage)
64 {
65 return Math.max(0, Math.floor(Number(damage) || 0));
66 }
64 67
65 export function combatHitXpPerSkill ()
68 /**
69 * XP for a successful spell cast (Magic skill).
70 * Scales with spell difficulty die size.
71 */
72 export function spellCastXpFromDifficulty (difficulty)
66 73 {
67 return COMBAT_HIT_XP_TOTAL / 2;
74 return Math.max(1, Math.floor(Number(difficulty) || 1) * 2);
68 75 }
@@ -59,10 +59,17 @@ export function levelFromTotalXp (totalXp)
59 return xpProgress(totalXp).level;
59 return xpProgress(totalXp).level;
60}
60}
61
61
62/** Split combat hit XP equally between hit and damage skills. */
62/** XP from damage dealt — applied to each related combat skill on a hit. */
63export const COMBAT_HIT_XP_TOTAL = 10;
63export function combatDamageXp (damage)
64{
65 return Math.max(0, Math.floor(Number(damage) || 0));
66}
64
67
65export function combatHitXpPerSkill ()
68/**
69 * XP for a successful spell cast (Magic skill).
70 * Scales with spell difficulty die size.
71 */
72export function spellCastXpFromDifficulty (difficulty)
66{
73{
67 return COMBAT_HIT_XP_TOTAL / 2;
74 return Math.max(1, Math.floor(Number(difficulty) || 1) * 2);
68}
75}