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.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
The contents of this binary file are not shown.
@@ -0,0 +1,42 @@
#!/usr/bin/env node
/**
* Generate distinct 32×48 tree sprites per wood tier (summer/fall/winter + stumps).
*
* node client/scripts/generate-tier-tree-sprites.mjs
* node client/scripts/generate-tier-tree-sprites.mjs birch oak
*
* Each tier shape lives in tree-sprites/shapes/{tier}.mjs — edit those for silhouette changes.
*/
import { WoodTier } from "../../shared/definitions/materialTiers.js";
import { writeTierTrees } from "./tree-sprites/common.mjs";
import { drawBirchCanopy } from "./tree-sprites/shapes/birch.mjs";
import { drawOakCanopy } from "./tree-sprites/shapes/oak.mjs";
import { drawEbonyCanopy } from "./tree-sprites/shapes/ebony.mjs";
import { drawLignumCanopy } from "./tree-sprites/shapes/lignum.mjs";
import { drawHeartwoodCanopy } from "./tree-sprites/shapes/heartwood.mjs";
import { drawElderCanopy } from "./tree-sprites/shapes/elder.mjs";
const SHAPES = Object.freeze({
[WoodTier.birch]: drawBirchCanopy,
[WoodTier.oak]: drawOakCanopy,
[WoodTier.ebony]: drawEbonyCanopy,
[WoodTier.lignum]: drawLignumCanopy,
[WoodTier.heartwood]: drawHeartwoodCanopy,
[WoodTier.elder]: drawElderCanopy
});
const requested = process.argv.slice(2);
const tiers = requested.length ? requested : Object.keys(SHAPES);
for (const tier of tiers)
{
const draw = SHAPES[tier];
if (!draw)
{
console.error(`Unknown tier: ${tier}`);
process.exitCode = 1;
continue;
}
writeTierTrees(tier, draw);
console.log(`Wrote ${tier}-tree (6 PNGs)`);
}
@@ -0,0 +1,42 @@#!/usr/bin/env node/** * Generate distinct 32×48 tree sprites per wood tier (summer/fall/winter + stumps). * * node client/scripts/generate-tier-tree-sprites.mjs * node client/scripts/generate-tier-tree-sprites.mjs birch oak * * Each tier shape lives in tree-sprites/shapes/{tier}.mjs — edit those for silhouette changes. */import { WoodTier } from "../../shared/definitions/materialTiers.js";import { writeTierTrees } from "./tree-sprites/common.mjs";import { drawBirchCanopy } from "./tree-sprites/shapes/birch.mjs";import { drawOakCanopy } from "./tree-sprites/shapes/oak.mjs";import { drawEbonyCanopy } from "./tree-sprites/shapes/ebony.mjs";import { drawLignumCanopy } from "./tree-sprites/shapes/lignum.mjs";import { drawHeartwoodCanopy } from "./tree-sprites/shapes/heartwood.mjs";import { drawElderCanopy } from "./tree-sprites/shapes/elder.mjs";const SHAPES = Object.freeze({ [WoodTier.birch]: drawBirchCanopy, [WoodTier.oak]: drawOakCanopy, [WoodTier.ebony]: drawEbonyCanopy, [WoodTier.lignum]: drawLignumCanopy, [WoodTier.heartwood]: drawHeartwoodCanopy, [WoodTier.elder]: drawElderCanopy});const requested = process.argv.slice(2);const tiers = requested.length ? requested : Object.keys(SHAPES);for (const tier of tiers){ const draw = SHAPES[tier]; if (!draw) { console.error(`Unknown tier: ${tier}`); process.exitCode = 1; continue; } writeTierTrees(tier, draw); console.log(`Wrote ${tier}-tree (6 PNGs)`);}@@ -0,0 +1,131 @@
/**
* Shared helpers for tier tree sprite generation (32×48 px, bottom-centred trunk).
* Run via: node client/scripts/generate-tier-tree-sprites.mjs [tier...]
*/
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { writeRgbaPng, makeRgba, fillRect } from "../../../server/src/assets/placeholderPng.js";
import { MATERIAL_TINT_HEX, WoodTier } from "../../../shared/definitions/materialTiers.js";
export { fillRect };
export const TREE_W = 32;
export const TREE_H = 48;
export const ASSETS_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "blocks");
/** @typedef {"summer"|"fall"|"winter"} TreeSeason */
const TRUNK = Object.freeze([92, 58, 34, 255]);
const STUMP = Object.freeze([78, 48, 28, 255]);
const SEASON_FOLIAGE = Object.freeze({
summer: (tier) => foliageFromWood(tier, 1),
fall: () => [210, 110, 42, 255],
winter: () => [148, 158, 148, 255]
});
const SEASON_SNOW = Object.freeze([235, 240, 248, 255]);
function foliageFromWood (tier, strength = 1)
{
const hex = MATERIAL_TINT_HEX[tier] ?? MATERIAL_TINT_HEX[WoodTier.pine];
const greenBoost = 0.55 + strength * 0.35;
return [
Math.round(hex.r * 255 * 0.35 + 40 * greenBoost),
Math.round(hex.g * 255 * 0.55 + 90 * greenBoost),
Math.round(hex.b * 255 * 0.25 + 24),
255
];
}
export function createTreeImage ()
{
return makeRgba(TREE_W, TREE_H, [0, 0, 0, 0]);
}
export function setPixel (image, x, y, rgba)
{
if (x < 0 || y < 0 || x >= image.width || y >= image.height)
{ return; }
image.pixels.set(rgba, (y * image.width + x) * 4);
}
export function fillCircle (image, cx, cy, radius, rgba)
{
const r2 = radius * radius;
for (let y = Math.floor(cy - radius); y <= Math.ceil(cy + radius); y++)
{
for (let x = Math.floor(cx - radius); x <= Math.ceil(cx + radius); x++)
{
const dx = x - cx;
const dy = y - cy;
if (dx * dx + dy * dy <= r2)
{ setPixel(image, x, y, rgba); }
}
}
}
export function fillEllipse (image, cx, cy, rx, ry, rgba)
{
for (let y = Math.floor(cy - ry); y <= Math.ceil(cy + ry); y++)
{
for (let x = Math.floor(cx - rx); x <= Math.ceil(cx + rx); x++)
{
const nx = (x - cx) / Math.max(1, rx);
const ny = (y - cy) / Math.max(1, ry);
if (nx * nx + ny * ny <= 1)
{ setPixel(image, x, y, rgba); }
}
}
}
export function drawTrunk (image, x, y0, y1, width = 3)
{
fillRect(image, x - Math.floor(width / 2), y0, width, y1 - y0 + 1, TRUNK);
}
export function drawStump (image, cx = 16, topY = 38)
{
fillRect(image, cx - 4, topY, 8, 10, STUMP);
fillRect(image, cx - 3, topY - 1, 6, 2, [68, 42, 24, 255]);
}
/**
* @param {TreeSeason} season
* @param {boolean} stump
* @param {(image: ReturnType<typeof makeRgba>, season: TreeSeason, stump: boolean) => void} drawCanopy
*/
export function renderTree (tier, season, stump, drawCanopy)
{
const image = createTreeImage();
const foliage = SEASON_FOLIAGE[season](tier);
if (stump)
{
drawStump(image);
writeTreePng(tier, season, stump, image);
return;
}
drawCanopy(image, season, stump, foliage);
if (season === "winter")
{
fillEllipse(image, 16, 16, 11, 7, SEASON_SNOW);
fillRect(image, 10, 8, 12, 3, SEASON_SNOW);
}
writeTreePng(tier, season, stump, image);
}
function writeTreePng (tier, season, stump, image)
{
const folder = join(ASSETS_ROOT, `${tier}-tree`);
const name = stump ? `${season}-stump` : season;
writeRgbaPng(join(folder, `${name}.png`), TREE_W, TREE_H, image.pixels);
}
export function writeTierTrees (tier, drawCanopy)
{
for (const season of ["summer", "fall", "winter"])
{
renderTree(tier, season, false, drawCanopy);
renderTree(tier, season, true, drawCanopy);
}
}
@@ -0,0 +1,131 @@/** * Shared helpers for tier tree sprite generation (32×48 px, bottom-centred trunk). * Run via: node client/scripts/generate-tier-tree-sprites.mjs [tier...] */import { join, dirname } from "node:path";import { fileURLToPath } from "node:url";import { writeRgbaPng, makeRgba, fillRect } from "../../../server/src/assets/placeholderPng.js";import { MATERIAL_TINT_HEX, WoodTier } from "../../../shared/definitions/materialTiers.js";export { fillRect };export const TREE_W = 32;export const TREE_H = 48;export const ASSETS_ROOT = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "assets", "blocks");/** @typedef {"summer"|"fall"|"winter"} TreeSeason */const TRUNK = Object.freeze([92, 58, 34, 255]);const STUMP = Object.freeze([78, 48, 28, 255]);const SEASON_FOLIAGE = Object.freeze({ summer: (tier) => foliageFromWood(tier, 1), fall: () => [210, 110, 42, 255], winter: () => [148, 158, 148, 255]});const SEASON_SNOW = Object.freeze([235, 240, 248, 255]);function foliageFromWood (tier, strength = 1){ const hex = MATERIAL_TINT_HEX[tier] ?? MATERIAL_TINT_HEX[WoodTier.pine]; const greenBoost = 0.55 + strength * 0.35; return [ Math.round(hex.r * 255 * 0.35 + 40 * greenBoost), Math.round(hex.g * 255 * 0.55 + 90 * greenBoost), Math.round(hex.b * 255 * 0.25 + 24), 255 ];}export function createTreeImage (){ return makeRgba(TREE_W, TREE_H, [0, 0, 0, 0]);}export function setPixel (image, x, y, rgba){ if (x < 0 || y < 0 || x >= image.width || y >= image.height) { return; } image.pixels.set(rgba, (y * image.width + x) * 4);}export function fillCircle (image, cx, cy, radius, rgba){ const r2 = radius * radius; for (let y = Math.floor(cy - radius); y <= Math.ceil(cy + radius); y++) { for (let x = Math.floor(cx - radius); x <= Math.ceil(cx + radius); x++) { const dx = x - cx; const dy = y - cy; if (dx * dx + dy * dy <= r2) { setPixel(image, x, y, rgba); } } }}export function fillEllipse (image, cx, cy, rx, ry, rgba){ for (let y = Math.floor(cy - ry); y <= Math.ceil(cy + ry); y++) { for (let x = Math.floor(cx - rx); x <= Math.ceil(cx + rx); x++) { const nx = (x - cx) / Math.max(1, rx); const ny = (y - cy) / Math.max(1, ry); if (nx * nx + ny * ny <= 1) { setPixel(image, x, y, rgba); } } }}export function drawTrunk (image, x, y0, y1, width = 3){ fillRect(image, x - Math.floor(width / 2), y0, width, y1 - y0 + 1, TRUNK);}export function drawStump (image, cx = 16, topY = 38){ fillRect(image, cx - 4, topY, 8, 10, STUMP); fillRect(image, cx - 3, topY - 1, 6, 2, [68, 42, 24, 255]);}/** * @param {TreeSeason} season * @param {boolean} stump * @param {(image: ReturnType<typeof makeRgba>, season: TreeSeason, stump: boolean) => void} drawCanopy */export function renderTree (tier, season, stump, drawCanopy){ const image = createTreeImage(); const foliage = SEASON_FOLIAGE[season](tier); if (stump) { drawStump(image); writeTreePng(tier, season, stump, image); return; } drawCanopy(image, season, stump, foliage); if (season === "winter") { fillEllipse(image, 16, 16, 11, 7, SEASON_SNOW); fillRect(image, 10, 8, 12, 3, SEASON_SNOW); } writeTreePng(tier, season, stump, image);}function writeTreePng (tier, season, stump, image){ const folder = join(ASSETS_ROOT, `${tier}-tree`); const name = stump ? `${season}-stump` : season; writeRgbaPng(join(folder, `${name}.png`), TREE_W, TREE_H, image.pixels);}export function writeTierTrees (tier, drawCanopy){ for (const season of ["summer", "fall", "winter"]) { renderTree(tier, season, false, drawCanopy); renderTree(tier, season, true, drawCanopy); }}@@ -0,0 +1,23 @@
import { drawTrunk, fillEllipse, fillRect, setPixel } from "../common.mjs";
const BARK = Object.freeze([210, 198, 168, 255]);
const BARK_STREAK = Object.freeze([238, 234, 222, 255]);
const BARK_MARK = Object.freeze([72, 58, 46, 255]);
/** Tall pale birch — narrow oval crown, white bark streak. */
export function drawBirchCanopy (image, season, stump, foliage)
{
drawTrunk(image, 16, 26, 44, 2);
fillRect(image, 15, 26, 2, 18, BARK);
fillRect(image, 15, 28, 1, 14, BARK_STREAK);
for (const y of [31, 35, 39])
{
setPixel(image, 15, y, BARK_MARK);
setPixel(image, 16, y, BARK_MARK);
}
fillEllipse(image, 16, 13, 5, 12, foliage);
fillEllipse(image, 16, 5, 3, 4, foliage);
fillEllipse(image, 11, 15, 2, 5, foliage);
fillEllipse(image, 21, 15, 2, 5, foliage);
}
@@ -0,0 +1,23 @@import { drawTrunk, fillEllipse, fillRect, setPixel } from "../common.mjs";const BARK = Object.freeze([210, 198, 168, 255]);const BARK_STREAK = Object.freeze([238, 234, 222, 255]);const BARK_MARK = Object.freeze([72, 58, 46, 255]);/** Tall pale birch — narrow oval crown, white bark streak. */export function drawBirchCanopy (image, season, stump, foliage){ drawTrunk(image, 16, 26, 44, 2); fillRect(image, 15, 26, 2, 18, BARK); fillRect(image, 15, 28, 1, 14, BARK_STREAK); for (const y of [31, 35, 39]) { setPixel(image, 15, y, BARK_MARK); setPixel(image, 16, y, BARK_MARK); } fillEllipse(image, 16, 13, 5, 12, foliage); fillEllipse(image, 16, 5, 3, 4, foliage); fillEllipse(image, 11, 15, 2, 5, foliage); fillEllipse(image, 21, 15, 2, 5, foliage);}@@ -0,0 +1,23 @@
import { drawTrunk, fillEllipse, fillRect, setPixel } from "../common.mjs";
/** Ebony — flat umbrella crown, slender dark trunk. */
export function drawEbonyCanopy (image, season, stump, foliage)
{
const shade = [
Math.max(0, foliage[0] - 32),
Math.max(0, foliage[1] - 32),
Math.max(0, foliage[2] - 24),
255
];
drawTrunk(image, 16, 28, 44, 2);
fillRect(image, 3, 11, 26, 2, foliage);
fillEllipse(image, 16, 14, 15, 4, foliage);
fillEllipse(image, 16, 16, 14, 2, foliage);
fillEllipse(image, 16, 12, 7, 2, foliage);
setPixel(image, 2, 15, foliage);
setPixel(image, 29, 15, foliage);
fillRect(image, 4, 16, 24, 1, shade);
}
@@ -0,0 +1,23 @@import { drawTrunk, fillEllipse, fillRect, setPixel } from "../common.mjs";/** Ebony — flat umbrella crown, slender dark trunk. */export function drawEbonyCanopy (image, season, stump, foliage){ const shade = [ Math.max(0, foliage[0] - 32), Math.max(0, foliage[1] - 32), Math.max(0, foliage[2] - 24), 255 ]; drawTrunk(image, 16, 28, 44, 2); fillRect(image, 3, 11, 26, 2, foliage); fillEllipse(image, 16, 14, 15, 4, foliage); fillEllipse(image, 16, 16, 14, 2, foliage); fillEllipse(image, 16, 12, 7, 2, foliage); setPixel(image, 2, 15, foliage); setPixel(image, 29, 15, foliage); fillRect(image, 4, 16, 24, 1, shade);}@@ -0,0 +1,71 @@
import { drawTrunk, fillCircle, fillEllipse, setPixel } from "../common.mjs";
const BARK = Object.freeze([68, 44, 28, 255]);
const BARK_SHADOW = Object.freeze([48, 30, 20, 255]);
function mysticGlow (foliage)
{
return [
Math.min(255, foliage[0] + 36),
Math.min(255, foliage[1] + 48),
Math.min(255, foliage[2] + 28),
255
];
}
function drawLine (image, x0, y0, x1, y1, rgba)
{
const steps = Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0), 1);
for (let i = 0; i <= steps; i++)
{
const t = i / steps;
setPixel(image, Math.round(x0 + (x1 - x0) * t), Math.round(y0 + (y1 - y0) * t), rgba);
}
}
function drawGnarledBranch (image, points, rgba = BARK)
{
for (let i = 0; i < points.length - 1; i++)
{
const [x0, y0] = points[i];
const [x1, y1] = points[i + 1];
drawLine(image, x0, y0, x1, y1, rgba);
if (i > 0 && i < points.length - 1)
{ setPixel(image, x0, y0, BARK_SHADOW); }
}
}
function leafCluster (image, x, y, foliage, radius = 2)
{
fillCircle(image, x, y, radius, foliage);
fillCircle(image, x, y, Math.max(1, radius - 1), mysticGlow(foliage));
}
/** Elder — gnarled sparse branches, small clusters, mystical ancient silhouette. */
export function drawElderCanopy (image, season, stump, foliage)
{
drawTrunk(image, 16, 34, 44, 3);
drawTrunk(image, 15, 28, 35, 2);
setPixel(image, 17, 30, BARK_SHADOW);
setPixel(image, 14, 33, BARK_SHADOW);
drawGnarledBranch(image, [[16, 30], [14, 26], [11, 21], [9, 16], [7, 11]]);
drawGnarledBranch(image, [[16, 29], [18, 24], [21, 19], [23, 14], [25, 9]]);
drawGnarledBranch(image, [[15, 32], [10, 28], [7, 23], [5, 18], [4, 13]]);
drawGnarledBranch(image, [[17, 31], [22, 27], [26, 22], [28, 17], [29, 12]]);
drawGnarledBranch(image, [[16, 28], [16, 22], [15, 16], [16, 10], [16, 6]]);
drawGnarledBranch(image, [[11, 21], [13, 19], [15, 17]], BARK_SHADOW);
drawGnarledBranch(image, [[21, 19], [19, 17], [17, 15]], BARK_SHADOW);
leafCluster(image, 7, 11, foliage, 2);
leafCluster(image, 25, 9, foliage, 2);
leafCluster(image, 4, 13, foliage, 2);
leafCluster(image, 29, 12, foliage, 2);
leafCluster(image, 16, 6, foliage, 3);
leafCluster(image, 15, 17, foliage, 2);
leafCluster(image, 17, 15, foliage, 2);
leafCluster(image, 9, 16, foliage, 2);
fillEllipse(image, 16, 4, 2, 1, mysticGlow(foliage));
}
@@ -0,0 +1,71 @@import { drawTrunk, fillCircle, fillEllipse, setPixel } from "../common.mjs";const BARK = Object.freeze([68, 44, 28, 255]);const BARK_SHADOW = Object.freeze([48, 30, 20, 255]);function mysticGlow (foliage){ return [ Math.min(255, foliage[0] + 36), Math.min(255, foliage[1] + 48), Math.min(255, foliage[2] + 28), 255 ];}function drawLine (image, x0, y0, x1, y1, rgba){ const steps = Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0), 1); for (let i = 0; i <= steps; i++) { const t = i / steps; setPixel(image, Math.round(x0 + (x1 - x0) * t), Math.round(y0 + (y1 - y0) * t), rgba); }}function drawGnarledBranch (image, points, rgba = BARK){ for (let i = 0; i < points.length - 1; i++) { const [x0, y0] = points[i]; const [x1, y1] = points[i + 1]; drawLine(image, x0, y0, x1, y1, rgba); if (i > 0 && i < points.length - 1) { setPixel(image, x0, y0, BARK_SHADOW); } }}function leafCluster (image, x, y, foliage, radius = 2){ fillCircle(image, x, y, radius, foliage); fillCircle(image, x, y, Math.max(1, radius - 1), mysticGlow(foliage));}/** Elder — gnarled sparse branches, small clusters, mystical ancient silhouette. */export function drawElderCanopy (image, season, stump, foliage){ drawTrunk(image, 16, 34, 44, 3); drawTrunk(image, 15, 28, 35, 2); setPixel(image, 17, 30, BARK_SHADOW); setPixel(image, 14, 33, BARK_SHADOW); drawGnarledBranch(image, [[16, 30], [14, 26], [11, 21], [9, 16], [7, 11]]); drawGnarledBranch(image, [[16, 29], [18, 24], [21, 19], [23, 14], [25, 9]]); drawGnarledBranch(image, [[15, 32], [10, 28], [7, 23], [5, 18], [4, 13]]); drawGnarledBranch(image, [[17, 31], [22, 27], [26, 22], [28, 17], [29, 12]]); drawGnarledBranch(image, [[16, 28], [16, 22], [15, 16], [16, 10], [16, 6]]); drawGnarledBranch(image, [[11, 21], [13, 19], [15, 17]], BARK_SHADOW); drawGnarledBranch(image, [[21, 19], [19, 17], [17, 15]], BARK_SHADOW); leafCluster(image, 7, 11, foliage, 2); leafCluster(image, 25, 9, foliage, 2); leafCluster(image, 4, 13, foliage, 2); leafCluster(image, 29, 12, foliage, 2); leafCluster(image, 16, 6, foliage, 3); leafCluster(image, 15, 17, foliage, 2); leafCluster(image, 17, 15, foliage, 2); leafCluster(image, 9, 16, foliage, 2); fillEllipse(image, 16, 4, 2, 1, mysticGlow(foliage));}@@ -0,0 +1,12 @@
import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";
/** Heartwood — twin-lobed heart-shaped crown. */
export function drawHeartwoodCanopy (image, season, stump, foliage)
{
drawTrunk(image, 16, 33, 44, 3);
fillCircle(image, 8, 14, 7, foliage);
fillCircle(image, 24, 14, 7, foliage);
fillEllipse(image, 16, 21, 10, 6, foliage);
fillEllipse(image, 16, 26, 6, 5, foliage);
fillCircle(image, 16, 30, 2, foliage);
}
@@ -0,0 +1,12 @@import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";/** Heartwood — twin-lobed heart-shaped crown. */export function drawHeartwoodCanopy (image, season, stump, foliage){ drawTrunk(image, 16, 33, 44, 3); fillCircle(image, 8, 14, 7, foliage); fillCircle(image, 24, 14, 7, foliage); fillEllipse(image, 16, 21, 10, 6, foliage); fillEllipse(image, 16, 26, 6, 5, foliage); fillCircle(image, 16, 30, 2, foliage);}@@ -0,0 +1,14 @@
import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";
/** Lignum — irregular layered canopy, slightly leaning. */
export function drawLignumCanopy (image, season, stump, foliage)
{
drawTrunk(image, 17, 31, 44, 3);
fillEllipse(image, 11, 25, 9, 6, foliage);
fillEllipse(image, 19, 27, 7, 5, foliage);
fillEllipse(image, 21, 20, 8, 7, foliage);
fillEllipse(image, 13, 21, 6, 5, foliage);
fillCircle(image, 9, 17, 4, foliage);
fillCircle(image, 20, 15, 5, foliage);
fillCircle(image, 15, 11, 3, foliage);
}
@@ -0,0 +1,14 @@import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";/** Lignum — irregular layered canopy, slightly leaning. */export function drawLignumCanopy (image, season, stump, foliage){ drawTrunk(image, 17, 31, 44, 3); fillEllipse(image, 11, 25, 9, 6, foliage); fillEllipse(image, 19, 27, 7, 5, foliage); fillEllipse(image, 21, 20, 8, 7, foliage); fillEllipse(image, 13, 21, 6, 5, foliage); fillCircle(image, 9, 17, 4, foliage); fillCircle(image, 20, 15, 5, foliage); fillCircle(image, 15, 11, 3, foliage);}@@ -0,0 +1,13 @@
import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";
/** Broad round oak — wide low canopy, thick trunk. */
export function drawOakCanopy (image, season, stump, foliage)
{
drawTrunk(image, 16, 36, 44, 5);
fillEllipse(image, 16, 23, 14, 10, foliage);
fillCircle(image, 8, 22, 5, foliage);
fillCircle(image, 24, 22, 5, foliage);
fillCircle(image, 16, 15, 7, foliage);
fillCircle(image, 11, 18, 5, foliage);
fillCircle(image, 21, 18, 5, foliage);
}
@@ -0,0 +1,13 @@import { drawTrunk, fillCircle, fillEllipse } from "../common.mjs";/** Broad round oak — wide low canopy, thick trunk. */export function drawOakCanopy (image, season, stump, foliage){ drawTrunk(image, 16, 36, 44, 5); fillEllipse(image, 16, 23, 14, 10, foliage); fillCircle(image, 8, 22, 5, foliage); fillCircle(image, 24, 22, 5, foliage); fillCircle(image, 16, 15, 7, foliage); fillCircle(image, 11, 18, 5, foliage); fillCircle(image, 21, 18, 5, foliage);}@@ -0,0 +1,40 @@
#!/usr/bin/env node
/**
* Dual-channel arrow projectile template for client/assets/fx/projectile/arrow.png
*
* Channel convention (same as items/arrow/full-arrow.png):
* - Dominant RED → shaft mask (lightness = R); tinted with wood tier at runtime
* - Dominant BLUE → tip mask (lightness = B); tinted with metal tier at runtime
* - Neutral WHITE → fletching / bindings; left unchanged
*
* Regenerate after hand-editing the layout:
* node client/scripts/write-arrow-projectile-template.mjs
*
* Runtime: WorldView.spawnPhysicalProjectileFx uses DUAL_TINT_LIT_SPRITE shader when
* combat-projectile carries shaftTint + tipTint from the server.
*/
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { writeRgbaPng, makeRgba, fillRect } from "../../server/src/assets/placeholderPng.js";
const W = 24;
const H = 8;
const out = join(dirname(fileURLToPath(import.meta.url)), "..", "assets", "fx", "projectile", "arrow.png");
const image = makeRgba(W, H, [0, 0, 0, 0]);
// Shaft — pure red channel (wood tint applied in shader)
for (let x = 4; x < 16; x++)
{ fillRect(image, x, 3, 1, 2, [220, 0, 0, 255]); }
// Tip — pure blue channel (metal tint applied in shader)
fillRect(image, 16, 2, 4, 4, [0, 0, 220, 255]);
fillRect(image, 20, 3, 2, 2, [0, 0, 255, 255]);
// Fletching — white, untouched by dual tint
fillRect(image, 0, 2, 3, 4, [245, 245, 245, 255]);
fillRect(image, 1, 1, 2, 1, [255, 255, 255, 255]);
fillRect(image, 1, 6, 2, 1, [255, 255, 255, 255]);
writeRgbaPng(out, W, H, image.pixels);
console.log(`Wrote dual-channel projectile template: ${out} (${W}×${H})`);
@@ -0,0 +1,40 @@#!/usr/bin/env node/** * Dual-channel arrow projectile template for client/assets/fx/projectile/arrow.png * * Channel convention (same as items/arrow/full-arrow.png): * - Dominant RED → shaft mask (lightness = R); tinted with wood tier at runtime * - Dominant BLUE → tip mask (lightness = B); tinted with metal tier at runtime * - Neutral WHITE → fletching / bindings; left unchanged * * Regenerate after hand-editing the layout: * node client/scripts/write-arrow-projectile-template.mjs * * Runtime: WorldView.spawnPhysicalProjectileFx uses DUAL_TINT_LIT_SPRITE shader when * combat-projectile carries shaftTint + tipTint from the server. */import { join, dirname } from "node:path";import { fileURLToPath } from "node:url";import { writeRgbaPng, makeRgba, fillRect } from "../../server/src/assets/placeholderPng.js";const W = 24;const H = 8;const out = join(dirname(fileURLToPath(import.meta.url)), "..", "assets", "fx", "projectile", "arrow.png");const image = makeRgba(W, H, [0, 0, 0, 0]);// Shaft — pure red channel (wood tint applied in shader)for (let x = 4; x < 16; x++){ fillRect(image, x, 3, 1, 2, [220, 0, 0, 255]); }// Tip — pure blue channel (metal tint applied in shader)fillRect(image, 16, 2, 4, 4, [0, 0, 220, 255]);fillRect(image, 20, 3, 2, 2, [0, 0, 255, 255]);// Fletching — white, untouched by dual tintfillRect(image, 0, 2, 3, 4, [245, 245, 245, 255]);fillRect(image, 1, 1, 2, 1, [255, 255, 255, 255]);fillRect(image, 1, 6, 2, 1, [255, 255, 255, 255]);writeRgbaPng(out, W, H, image.pixels);console.log(`Wrote dual-channel projectile template: ${out} (${W}×${H})`);@@ -2,8 +2,10 @@ import { ItemId, itemDefinition, itemAssetPathForStack } from "/shared/definitio
import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";
import {
applyMagentaTintToImageData,
applyDualChannelTintToImageData,
normalizeRgb,
resolveItemTint
resolveItemTint,
resolveItemDualTint
} from "/shared/render/tint.js";
const bottleCache = new Map();
@@ -97,6 +99,27 @@ export async function tintedItemIconDataUrl (assetPath, tint)
return url;
}
/** Dual-channel arrow icon (red shaft + blue tip masks). */
export async function dualTintedItemIconDataUrl (assetPath, dualTint)
{
const key = `dual|${assetPath}|${colorKey(dualTint.shaft)}|${colorKey(dualTint.tip)}`;
if (urlCache.has(key))
{ return urlCache.get(key); }
const img = await loadImage(assetPath);
const canvas = document.createElement("canvas");
canvas.width = img.width || SPRITE_SIZE_PX;
canvas.height = img.height || SPRITE_SIZE_PX;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img, 0, 0);
const image = ctx.getImageData(0, 0, canvas.width, canvas.height);
applyDualChannelTintToImageData(image, dualTint);
ctx.putImageData(image, 0, 0);
const url = canvas.toDataURL("image/png");
urlCache.set(key, url);
return url;
}
export function isPotionStack (stack)
{
return (stack?.itemId === ItemId.potion && stack.instance?.kind === "potion")
@@ -109,7 +132,20 @@ export function applyItemIcon (img, stack, fallbackPath)
if (!img)
{ return; }
img.src = fallbackPath;
const tint = resolveItemTint(stack, itemDefinition(stack?.itemId));
const def = itemDefinition(stack?.itemId);
const dualTint = resolveItemDualTint(stack, def);
if (dualTint)
{
dualTintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), dualTint).then((url) =>
{
img.src = url;
}).catch(() =>
{
img.src = fallbackPath;
});
return;
}
const tint = resolveItemTint(stack, def);
if (!tint)
{ return; }
const work = isPotionStack(stack)
@@ -2,8 +2,10 @@ import { ItemId, itemDefinition, itemAssetPathForStack } from "/shared/definitioimport { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";import { SPRITE_SIZE_PX } from "/shared/protocol/constants.js";import {import { applyMagentaTintToImageData, applyMagentaTintToImageData, applyDualChannelTintToImageData, normalizeRgb, normalizeRgb, resolveItemTint resolveItemTint, resolveItemDualTint} from "/shared/render/tint.js";} from "/shared/render/tint.js";const bottleCache = new Map();const bottleCache = new Map();@@ -97,6 +99,27 @@ export async function tintedItemIconDataUrl (assetPath, tint) return url; return url;}}/** Dual-channel arrow icon (red shaft + blue tip masks). */export async function dualTintedItemIconDataUrl (assetPath, dualTint){ const key = `dual|${assetPath}|${colorKey(dualTint.shaft)}|${colorKey(dualTint.tip)}`; if (urlCache.has(key)) { return urlCache.get(key); } const img = await loadImage(assetPath); const canvas = document.createElement("canvas"); canvas.width = img.width || SPRITE_SIZE_PX; canvas.height = img.height || SPRITE_SIZE_PX; const ctx = canvas.getContext("2d"); ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(img, 0, 0); const image = ctx.getImageData(0, 0, canvas.width, canvas.height); applyDualChannelTintToImageData(image, dualTint); ctx.putImageData(image, 0, 0); const url = canvas.toDataURL("image/png"); urlCache.set(key, url); return url;}export function isPotionStack (stack)export function isPotionStack (stack){{ return (stack?.itemId === ItemId.potion && stack.instance?.kind === "potion") return (stack?.itemId === ItemId.potion && stack.instance?.kind === "potion")@@ -109,7 +132,20 @@ export function applyItemIcon (img, stack, fallbackPath) if (!img) if (!img) { return; } { return; } img.src = fallbackPath; img.src = fallbackPath; const tint = resolveItemTint(stack, itemDefinition(stack?.itemId)); const def = itemDefinition(stack?.itemId); const dualTint = resolveItemDualTint(stack, def); if (dualTint) { dualTintedItemIconDataUrl(fallbackPath || itemAssetPathForStack(stack), dualTint).then((url) => { img.src = url; }).catch(() => { img.src = fallbackPath; }); return; } const tint = resolveItemTint(stack, def); if (!tint) if (!tint) { return; } { return; } const work = isPotionStack(stack) const work = isPotionStack(stack)@@ -3,7 +3,7 @@ import { dynamicLightAtTile, lightIntensity } from "/shared/lighting/raycast.js"
import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";
import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";
import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";
import { resolveItemTint, resolveEquipTint, normalizeRgb } from "/shared/render/tint.js";
import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";
import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight } from "/shared/definitions/tiles.js";
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";
import { bakeChunkAtlases } from "./chunkBake.js";
@@ -135,6 +135,48 @@ const TINT_LIT_SPRITE_FRAG = [
"}"
].join("\n");
/** Dual-channel arrow tint: red = shaft, blue = tip, white unchanged; then darkness. */
const DUAL_TINT_LIT_SPRITE_FRAG = [
"precision mediump float;",
"varying vec2 v_texCoord;",
"uniform sampler2D u_texture;",
"uniform float u_darkness;",
"uniform float u_strength;",
"uniform float u_wade;",
"uniform float u_spriteHeight;",
"uniform vec3 u_shaftTint;",
"uniform vec3 u_tipTint;",
"void main() {",
" vec4 color = texture2D(u_texture, v_texCoord);",
" if (color.a <= 0.0) { discard; }",
" float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);",
" if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
" vec3 rgb = color.rgb;",
" float tipMask = clamp((color.b - max(color.r, color.g)) * 1.75, 0.0, 1.0);",
" if (tipMask > 0.0) {",
" float L = color.b;",
" float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;",
" float tipLuma = dot(u_tipTint, vec3(0.2126, 0.7152, 0.0722));",
" vec3 tipCol = mix(u_tipTint, vec3(tipLuma), gBlend) * L;",
" rgb = mix(rgb, tipCol, tipMask);",
" }",
" float shaftMask = clamp((color.r - max(color.g, color.b)) * 1.75, 0.0, 1.0);",
" if (shaftMask > 0.0) {",
" float L = color.r;",
" float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;",
" float shaftLuma = dot(u_shaftTint, vec3(0.2126, 0.7152, 0.0722));",
" vec3 shaftCol = mix(u_shaftTint, vec3(shaftLuma), gBlend) * L;",
" rgb = mix(rgb, shaftCol, shaftMask);",
" }",
" if (u_wade > 0.5 && fromBottom < 5.0) {",
" rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);",
" }",
" rgb = mix(rgb, vec3(0.0), u_darkness);",
" rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);",
" gl_FragColor = vec4(rgb, color.a);",
"}"
].join("\n");
const ATLAS_LIGHTING_FRAG = [
"precision mediump float;",
"varying vec2 v_texCoord;",
@@ -160,6 +202,7 @@ let spriteLightingShader = null;
let atlasLightingShader = null;
let waterGroundShader = null;
let tintLitSpriteShader = null;
let dualTintLitSpriteShader = null;
function getSpriteLightingShader ()
{
@@ -189,6 +232,13 @@ function getTintLitSpriteShader ()
return tintLitSpriteShader;
}
function getDualTintLitSpriteShader ()
{
if (!dualTintLitSpriteShader)
{ dualTintLitSpriteShader = Shader.fragment(DUAL_TINT_LIT_SPRITE_FRAG); }
return dualTintLitSpriteShader;
}
export class WorldView
{
constructor (game, scene, catalog = { grounds: {}, blocks: {} })
@@ -517,7 +567,8 @@ export class WorldView
item.sprite = spriteName;
item.instance = payload.instance ?? null;
const stack = { itemId: payload.itemId, instance: payload.instance ?? null };
item.tintColor = resolveItemTint(stack, itemDefinition(payload.itemId));
item.dualTint = resolveItemDualTint(stack, itemDefinition(payload.itemId));
item.tintColor = item.dualTint ? null : resolveItemTint(stack, itemDefinition(payload.itemId));
this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK);
this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0);
}
@@ -860,6 +911,7 @@ export class WorldView
const image = this.game.images[spriteName];
if (!image)
{ return; }
const dualTint = this.#dualTintFromPayload(payload);
const fromPivot = tilePivot(payload.fromTileX, payload.fromTileY, this.tileSize());
const toPivot = tilePivot(payload.tileX, payload.tileY, this.tileSize());
const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02;
@@ -874,7 +926,8 @@ export class WorldView
payload.fromTileX,
payload.fromTileY,
payload.tileX,
payload.tileY
payload.tileY,
dualTint
);
const started = performance.now();
const durationMs = payload.durationMs ?? 400;
@@ -884,6 +937,7 @@ export class WorldView
started,
durationMs,
lerp: true,
dualTint,
fromTileX: payload.fromTileX,
fromTileY: payload.fromTileY,
tileX: payload.tileX,
@@ -1414,8 +1468,35 @@ export class WorldView
object.renderer.secondaryMap = null;
}
#syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false)
{
if (!object?.renderer || object._lit === false || !dualTint)
{ return; }
object._lit = true;
const shaft = normalizeRgb(dualTint.shaft);
const tip = normalizeRgb(dualTint.tip);
const dark = Math.min(1, Math.max(0, darkness ?? 0));
const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
object.renderer.shader = getDualTintLitSpriteShader();
object.renderer.shaderUniforms = {
u_darkness: dark,
u_strength: flash,
u_wade: wade ? 1 : 0,
u_spriteHeight: height,
u_shaftTint: [shaft.r, shaft.g, shaft.b],
u_tipTint: [tip.r, tip.g, tip.b]
};
object.renderer.secondaryMap = null;
}
#syncGroundItemSprite (item, darkness)
{
if (item?.dualTint)
{
this.#syncDualTintLitSprite(item.object, darkness, item.dualTint);
return;
}
this.#syncLitSprite(item?.object, darkness, 0, false, item?.tintColor ?? null);
}
@@ -1544,11 +1625,24 @@ export class WorldView
};
}
#applyPhysicalCombatFxDarkness (object, fromTileX, fromTileY, tileX, tileY)
#applyPhysicalCombatFxDarkness (object, fromTileX, fromTileY, tileX, tileY, dualTint = null)
{
const fromAlpha = this.tiles.get(`${fromTileX},${fromTileY}`)?.shadeAlpha ?? 0;
const toAlpha = this.tiles.get(`${tileX},${tileY}`)?.shadeAlpha ?? 0;
this.#syncLitSprite(object, (fromAlpha + toAlpha) / 2);
const dark = (fromAlpha + toAlpha) / 2;
if (dualTint)
{
this.#syncDualTintLitSprite(object, dark, dualTint);
return;
}
this.#syncLitSprite(object, dark);
}
#dualTintFromPayload (payload)
{
if (!payload?.shaftTint || !payload?.tipTint)
{ return null; }
return { shaft: payload.shaftTint, tip: payload.tipTint };
}
#syncHpBar (entity)
@@ -2324,7 +2418,8 @@ export class WorldView
swipe.fromTileX,
swipe.fromTileY,
swipe.tileX,
swipe.tileY
swipe.tileY,
swipe.dualTint ?? null
);
}
else if (swipe.fromTileX != null)
@@ -2334,7 +2429,8 @@ export class WorldView
swipe.fromTileX,
swipe.fromTileY,
swipe.tileX,
swipe.tileY
swipe.tileY,
swipe.dualTint ?? null
);
}
if (swipe.until > now)
@@ -3,7 +3,7 @@ import { dynamicLightAtTile, lightIntensity } from "/shared/lighting/raycast.js"import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";import { makeSnapshotLightOcclusion } from "/shared/lighting/tilePassable.js";import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";import { bloomCompanionName, spriteImageName } from "/shared/definitions/tileSprites.js";import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";import { EQUIPMENT_SLOT, itemEquipSprite, itemSpriteName, itemDefinition } from "/shared/definitions/items.js";import { resolveItemTint, resolveEquipTint, normalizeRgb } from "/shared/render/tint.js";import { resolveItemTint, resolveEquipTint, resolveItemDualTint, normalizeRgb } from "/shared/render/tint.js";import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight } from "/shared/definitions/tiles.js";import { normalizeGround, isWadeGroundInSeason, isWaterGround, isLiquidWaterGround, isGroundPassable, isBlockOccludingLight } from "/shared/definitions/tiles.js";import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer } from "/shared/render/pivot.js";import { bakeChunkAtlases } from "./chunkBake.js";import { bakeChunkAtlases } from "./chunkBake.js";@@ -135,6 +135,48 @@ const TINT_LIT_SPRITE_FRAG = [ "}" "}"].join("\n");].join("\n");/** Dual-channel arrow tint: red = shaft, blue = tip, white unchanged; then darkness. */const DUAL_TINT_LIT_SPRITE_FRAG = [ "precision mediump float;", "varying vec2 v_texCoord;", "uniform sampler2D u_texture;", "uniform float u_darkness;", "uniform float u_strength;", "uniform float u_wade;", "uniform float u_spriteHeight;", "uniform vec3 u_shaftTint;", "uniform vec3 u_tipTint;", "void main() {", " vec4 color = texture2D(u_texture, v_texCoord);", " if (color.a <= 0.0) { discard; }", " float fromBottom = (1.0 - v_texCoord.y) * max(u_spriteHeight, 1.0);", " if (u_wade > 0.5 && fromBottom < 4.0) { discard; }", " vec3 rgb = color.rgb;", " float tipMask = clamp((color.b - max(color.r, color.g)) * 1.75, 0.0, 1.0);", " if (tipMask > 0.0) {", " float L = color.b;", " float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;", " float tipLuma = dot(u_tipTint, vec3(0.2126, 0.7152, 0.0722));", " vec3 tipCol = mix(u_tipTint, vec3(tipLuma), gBlend) * L;", " rgb = mix(rgb, tipCol, tipMask);", " }", " float shaftMask = clamp((color.r - max(color.g, color.b)) * 1.75, 0.0, 1.0);", " if (shaftMask > 0.0) {", " float L = color.r;", " float gBlend = L > 0.0 ? clamp(color.g / L, 0.0, 1.0) : 0.0;", " float shaftLuma = dot(u_shaftTint, vec3(0.2126, 0.7152, 0.0722));", " vec3 shaftCol = mix(u_shaftTint, vec3(shaftLuma), gBlend) * L;", " rgb = mix(rgb, shaftCol, shaftMask);", " }", " if (u_wade > 0.5 && fromBottom < 5.0) {", " rgb = mix(rgb, vec3(0.55, 0.82, 0.98), 0.55);", " }", " rgb = mix(rgb, vec3(0.0), u_darkness);", " rgb = mix(rgb, vec3(1.0, 0.12, 0.12), u_strength);", " gl_FragColor = vec4(rgb, color.a);", "}"].join("\n");const ATLAS_LIGHTING_FRAG = [const ATLAS_LIGHTING_FRAG = [ "precision mediump float;", "precision mediump float;", "varying vec2 v_texCoord;", "varying vec2 v_texCoord;",@@ -160,6 +202,7 @@ let spriteLightingShader = null;let atlasLightingShader = null;let atlasLightingShader = null;let waterGroundShader = null;let waterGroundShader = null;let tintLitSpriteShader = null;let tintLitSpriteShader = null;let dualTintLitSpriteShader = null;function getSpriteLightingShader ()function getSpriteLightingShader (){{@@ -189,6 +232,13 @@ function getTintLitSpriteShader () return tintLitSpriteShader; return tintLitSpriteShader;}}function getDualTintLitSpriteShader (){ if (!dualTintLitSpriteShader) { dualTintLitSpriteShader = Shader.fragment(DUAL_TINT_LIT_SPRITE_FRAG); } return dualTintLitSpriteShader;}export class WorldViewexport class WorldView{{ constructor (game, scene, catalog = { grounds: {}, blocks: {} }) constructor (game, scene, catalog = { grounds: {}, blocks: {} })@@ -517,7 +567,8 @@ export class WorldView item.sprite = spriteName; item.sprite = spriteName; item.instance = payload.instance ?? null; item.instance = payload.instance ?? null; const stack = { itemId: payload.itemId, instance: payload.instance ?? null }; const stack = { itemId: payload.itemId, instance: payload.instance ?? null }; item.tintColor = resolveItemTint(stack, itemDefinition(payload.itemId)); item.dualTint = resolveItemDualTint(stack, itemDefinition(payload.itemId)); item.tintColor = item.dualTint ? null : resolveItemTint(stack, itemDefinition(payload.itemId)); this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK); this.#placePivoted(item.object, pivot.x, pivot.y, pivot.y - 0.01, SORT_BLOCK); this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0); this.#syncGroundItemSprite(item, this.tiles.get(`${payload.tileX},${payload.tileY}`)?.shadeAlpha ?? 0); } }@@ -860,6 +911,7 @@ export class WorldView const image = this.game.images[spriteName]; const image = this.game.images[spriteName]; if (!image) if (!image) { return; } { return; } const dualTint = this.#dualTintFromPayload(payload); const fromPivot = tilePivot(payload.fromTileX, payload.fromTileY, this.tileSize()); const fromPivot = tilePivot(payload.fromTileX, payload.fromTileY, this.tileSize()); const toPivot = tilePivot(payload.tileX, payload.tileY, this.tileSize()); const toPivot = tilePivot(payload.tileX, payload.tileY, this.tileSize()); const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02; const sortY = Math.max(fromPivot.y, toPivot.y) + 0.02;@@ -874,7 +926,8 @@ export class WorldView payload.fromTileX, payload.fromTileX, payload.fromTileY, payload.fromTileY, payload.tileX, payload.tileX, payload.tileY payload.tileY, dualTint ); ); const started = performance.now(); const started = performance.now(); const durationMs = payload.durationMs ?? 400; const durationMs = payload.durationMs ?? 400;@@ -884,6 +937,7 @@ export class WorldView started, started, durationMs, durationMs, lerp: true, lerp: true, dualTint, fromTileX: payload.fromTileX, fromTileX: payload.fromTileX, fromTileY: payload.fromTileY, fromTileY: payload.fromTileY, tileX: payload.tileX, tileX: payload.tileX,@@ -1414,8 +1468,35 @@ export class WorldView object.renderer.secondaryMap = null; object.renderer.secondaryMap = null; } } #syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false) { if (!object?.renderer || object._lit === false || !dualTint) { return; } object._lit = true; const shaft = normalizeRgb(dualTint.shaft); const tip = normalizeRgb(dualTint.tip); const dark = Math.min(1, Math.max(0, darkness ?? 0)); const flash = Math.min(1, Math.max(0, flashStrength ?? 0)); const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX; object.renderer.shader = getDualTintLitSpriteShader(); object.renderer.shaderUniforms = { u_darkness: dark, u_strength: flash, u_wade: wade ? 1 : 0, u_spriteHeight: height, u_shaftTint: [shaft.r, shaft.g, shaft.b], u_tipTint: [tip.r, tip.g, tip.b] }; object.renderer.secondaryMap = null; } #syncGroundItemSprite (item, darkness) #syncGroundItemSprite (item, darkness) { { if (item?.dualTint) { this.#syncDualTintLitSprite(item.object, darkness, item.dualTint); return; } this.#syncLitSprite(item?.object, darkness, 0, false, item?.tintColor ?? null); this.#syncLitSprite(item?.object, darkness, 0, false, item?.tintColor ?? null); } }@@ -1544,11 +1625,24 @@ export class WorldView }; }; } } #applyPhysicalCombatFxDarkness (object, fromTileX, fromTileY, tileX, tileY) #applyPhysicalCombatFxDarkness (object, fromTileX, fromTileY, tileX, tileY, dualTint = null) { { const fromAlpha = this.tiles.get(`${fromTileX},${fromTileY}`)?.shadeAlpha ?? 0; const fromAlpha = this.tiles.get(`${fromTileX},${fromTileY}`)?.shadeAlpha ?? 0; const toAlpha = this.tiles.get(`${tileX},${tileY}`)?.shadeAlpha ?? 0; const toAlpha = this.tiles.get(`${tileX},${tileY}`)?.shadeAlpha ?? 0; this.#syncLitSprite(object, (fromAlpha + toAlpha) / 2); const dark = (fromAlpha + toAlpha) / 2; if (dualTint) { this.#syncDualTintLitSprite(object, dark, dualTint); return; } this.#syncLitSprite(object, dark); } #dualTintFromPayload (payload) { if (!payload?.shaftTint || !payload?.tipTint) { return null; } return { shaft: payload.shaftTint, tip: payload.tipTint }; } } #syncHpBar (entity) #syncHpBar (entity)@@ -2324,7 +2418,8 @@ export class WorldView swipe.fromTileX, swipe.fromTileX, swipe.fromTileY, swipe.fromTileY, swipe.tileX, swipe.tileX, swipe.tileY swipe.tileY, swipe.dualTint ?? null ); ); } } else if (swipe.fromTileX != null) else if (swipe.fromTileX != null)@@ -2334,7 +2429,8 @@ export class WorldView swipe.fromTileX, swipe.fromTileX, swipe.fromTileY, swipe.fromTileY, swipe.tileX, swipe.tileX, swipe.tileY swipe.tileY, swipe.dualTint ?? null ); ); } } if (swipe.until > now) if (swipe.until > now)@@ -24,8 +24,6 @@ import {
effectiveSkillLevel,
equipmentBonusesFromSlots
} from "../../../shared/equipment/stats.js";
import { tierStatBonus } from "../../../shared/definitions/materialTiers.js";
import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";
import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";
import { awardCombatHitXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
import { chunkBoundsAround, findPath } from "../navigation/astar.js";
@@ -34,6 +32,7 @@ import { rayReaches } from "../../../shared/lighting/raycast.js";
import { tileToChunk } from "../world/coordinates.js";
import { stackQuantity } from "../../../shared/items/inventory.js";
import { addGroundItem, publicGroundItem } from "../items/bags.js";
import { resolveItemDualTint } from "../../../shared/render/tint.js";
export function chebyshev (ax, ay, bx, by)
{
@@ -98,26 +97,9 @@ function playerCombatLevels (ecs, handle, profile)
bonuses[SkillId.strength] = (bonuses[SkillId.strength] ?? 0) + (status.strength ?? 0);
bonuses[SkillId.mind] = (bonuses[SkillId.mind] ?? 0) + (status.mind ?? 0);
if (profile.mode === "ranged")
{
const weapon = equipment?.slots?.weapon;
const offhand = equipment?.slots?.offhand;
const bowDef = weapon ? itemDefinition(weapon.itemId) : null;
const arrowDef = offhand ? itemDefinition(offhand.itemId) : null;
const bowTier = bowDef?.equipment?.tier;
const arrowTier = arrowDef?.equipment?.tier;
return {
hitLevel: skillLevel(skills, SkillId.archery) + (bowTier ? tierStatBonus(bowTier) : 0),
damageLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses)
+ (arrowTier ? tierStatBonus(arrowTier) : 0),
agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses),
defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses)
};
}
return {
hitLevel: skillLevel(skills, profile.hitSkillId),
damageLevel: effectiveSkillLevel(skills, profile.damageSkillId, bonuses),
hitLevel: skillLevel(skills, profile.hitSkillId ?? SkillId.unarmed),
damageLevel: effectiveSkillLevel(skills, profile.damageSkillId ?? SkillId.strength, bonuses),
agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses),
defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses)
};
@@ -239,6 +221,25 @@ function spawnMobDrops (world, targetHandle, tileX, tileY, now)
return events;
}
function projectileDualTintFromAttacker (ecs, handle)
{
const equipment = ecs.get(handle, Component.equipment);
const stack = arrowStackInOffhand(equipment);
if (!stack)
{ return null; }
return resolveItemDualTint(stack, itemDefinition(stack.itemId));
}
function publicDualTint (dualTint)
{
if (!dualTint)
{ return null; }
return {
shaftTint: dualTint.shaft,
tipTint: dualTint.tip
};
}
function missProjectileTile (targetTileX, targetTileY, rng = Math.random)
{
const angle = rng() * Math.PI * 2;
@@ -624,7 +625,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
tileX: snapshot.tileX,
tileY: snapshot.tileY,
fromTileX: from.tileX,
fromTileY: from.tileY
fromTileY: from.tileY,
...(publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {})
});
return events;
}
@@ -666,7 +668,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
fromTileY: from.tileY,
tileX: endX,
tileY: endY,
durationMs: 400
durationMs: 400,
...publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {}
});
return events.concat(hitEvents);
}
@@ -824,7 +827,9 @@ export function applyRemoteRangedShot (world, payload)
fromTileY: payload.fromTileY,
tileX: endX,
tileY: endY,
durationMs: 400
durationMs: 400,
shaftTint: payload.shaftTint ?? null,
tipTint: payload.tipTint ?? null
}, ...hitEvents];
const forwards = [];
@@ -834,7 +839,8 @@ export function applyRemoteRangedShot (world, payload)
forwards.push({
type: "forward-combat-xp",
entityId: payload.attackerId,
profile: payload.profile
profile: payload.profile,
damage: hitEvent.damage
});
}
return { events, forwards };
@@ -870,7 +876,8 @@ export function applyRemoteMeleeSwing (world, payload)
forwards.push({
type: "forward-combat-xp",
entityId: payload.attackerId,
profile: payload.profile
profile: payload.profile,
damage: hitEvent.damage
});
}
return { events, forwards };
@@ -942,8 +949,7 @@ function applyLocalMeleeHit (
),
agilitySkillLevel: agilityLevel,
damageSkillLevel: attackerLevels.damageLevel,
defenceSkillLevel: defenceLevel,
baseDamage: profile.baseDamage ?? 1
defenceSkillLevel: defenceLevel
});
if (resolved.outcome === "miss")
@@ -1017,7 +1023,7 @@ function applyLocalMeleeHit (
const attackerCharacter = world.ecs.get(attackerHandle, Component.character);
if (attackerCharacter)
{
const xpAward = awardCombatHitXp(world.ecs, attackerHandle, profile);
const xpAward = awardCombatHitXp(world.ecs, attackerHandle, profile, damage);
if (xpAward)
{
events.push({
@@ -24,8 +24,6 @@ import { effectiveSkillLevel, effectiveSkillLevel, equipmentBonusesFromSlots equipmentBonusesFromSlots} from "../../../shared/equipment/stats.js";} from "../../../shared/equipment/stats.js";import { tierStatBonus } from "../../../shared/definitions/materialTiers.js";import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";import { awardCombatHitXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";import { awardCombatHitXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";import { chunkBoundsAround, findPath } from "../navigation/astar.js";import { chunkBoundsAround, findPath } from "../navigation/astar.js";@@ -34,6 +32,7 @@ import { rayReaches } from "../../../shared/lighting/raycast.js";import { tileToChunk } from "../world/coordinates.js";import { tileToChunk } from "../world/coordinates.js";import { stackQuantity } from "../../../shared/items/inventory.js";import { stackQuantity } from "../../../shared/items/inventory.js";import { addGroundItem, publicGroundItem } from "../items/bags.js";import { addGroundItem, publicGroundItem } from "../items/bags.js";import { resolveItemDualTint } from "../../../shared/render/tint.js";export function chebyshev (ax, ay, bx, by)export function chebyshev (ax, ay, bx, by){{@@ -98,26 +97,9 @@ function playerCombatLevels (ecs, handle, profile) bonuses[SkillId.strength] = (bonuses[SkillId.strength] ?? 0) + (status.strength ?? 0); bonuses[SkillId.strength] = (bonuses[SkillId.strength] ?? 0) + (status.strength ?? 0); bonuses[SkillId.mind] = (bonuses[SkillId.mind] ?? 0) + (status.mind ?? 0); bonuses[SkillId.mind] = (bonuses[SkillId.mind] ?? 0) + (status.mind ?? 0); if (profile.mode === "ranged") { const weapon = equipment?.slots?.weapon; const offhand = equipment?.slots?.offhand; const bowDef = weapon ? itemDefinition(weapon.itemId) : null; const arrowDef = offhand ? itemDefinition(offhand.itemId) : null; const bowTier = bowDef?.equipment?.tier; const arrowTier = arrowDef?.equipment?.tier; return { hitLevel: skillLevel(skills, SkillId.archery) + (bowTier ? tierStatBonus(bowTier) : 0), damageLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses) + (arrowTier ? tierStatBonus(arrowTier) : 0), agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses), defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses) }; } return { return { hitLevel: skillLevel(skills, profile.hitSkillId), hitLevel: skillLevel(skills, profile.hitSkillId ?? SkillId.unarmed), damageLevel: effectiveSkillLevel(skills, profile.damageSkillId, bonuses), damageLevel: effectiveSkillLevel(skills, profile.damageSkillId ?? SkillId.strength, bonuses), agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses), agilityLevel: effectiveSkillLevel(skills, SkillId.dexterity, bonuses), defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses) defenceLevel: effectiveSkillLevel(skills, SkillId.defence, bonuses) }; };@@ -239,6 +221,25 @@ function spawnMobDrops (world, targetHandle, tileX, tileY, now) return events; return events;}}function projectileDualTintFromAttacker (ecs, handle){ const equipment = ecs.get(handle, Component.equipment); const stack = arrowStackInOffhand(equipment); if (!stack) { return null; } return resolveItemDualTint(stack, itemDefinition(stack.itemId));}function publicDualTint (dualTint){ if (!dualTint) { return null; } return { shaftTint: dualTint.shaft, tipTint: dualTint.tip };}function missProjectileTile (targetTileX, targetTileY, rng = Math.random)function missProjectileTile (targetTileX, targetTileY, rng = Math.random){{ const angle = rng() * Math.PI * 2; const angle = rng() * Math.PI * 2;@@ -624,7 +625,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D tileX: snapshot.tileX, tileX: snapshot.tileX, tileY: snapshot.tileY, tileY: snapshot.tileY, fromTileX: from.tileX, fromTileX: from.tileX, fromTileY: from.tileY fromTileY: from.tileY, ...(publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {}) }); }); return events; return events; } }@@ -666,7 +668,8 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D fromTileY: from.tileY, fromTileY: from.tileY, tileX: endX, tileX: endX, tileY: endY, tileY: endY, durationMs: 400 durationMs: 400, ...publicDualTint(projectileDualTintFromAttacker(world.ecs, attackerHandle)) ?? {} }); }); return events.concat(hitEvents); return events.concat(hitEvents);}}@@ -824,7 +827,9 @@ export function applyRemoteRangedShot (world, payload) fromTileY: payload.fromTileY, fromTileY: payload.fromTileY, tileX: endX, tileX: endX, tileY: endY, tileY: endY, durationMs: 400 durationMs: 400, shaftTint: payload.shaftTint ?? null, tipTint: payload.tipTint ?? null }, ...hitEvents]; }, ...hitEvents]; const forwards = []; const forwards = [];@@ -834,7 +839,8 @@ export function applyRemoteRangedShot (world, payload) forwards.push({ forwards.push({ type: "forward-combat-xp", type: "forward-combat-xp", entityId: payload.attackerId, entityId: payload.attackerId, profile: payload.profile profile: payload.profile, damage: hitEvent.damage }); }); } } return { events, forwards }; return { events, forwards };@@ -870,7 +876,8 @@ export function applyRemoteMeleeSwing (world, payload) forwards.push({ forwards.push({ type: "forward-combat-xp", type: "forward-combat-xp", entityId: payload.attackerId, entityId: payload.attackerId, profile: payload.profile profile: payload.profile, damage: hitEvent.damage }); }); } } return { events, forwards }; return { events, forwards };@@ -942,8 +949,7 @@ function applyLocalMeleeHit ( ), ), agilitySkillLevel: agilityLevel, agilitySkillLevel: agilityLevel, damageSkillLevel: attackerLevels.damageLevel, damageSkillLevel: attackerLevels.damageLevel, defenceSkillLevel: defenceLevel, defenceSkillLevel: defenceLevel baseDamage: profile.baseDamage ?? 1 }); }); if (resolved.outcome === "miss") if (resolved.outcome === "miss")@@ -1017,7 +1023,7 @@ function applyLocalMeleeHit ( const attackerCharacter = world.ecs.get(attackerHandle, Component.character); const attackerCharacter = world.ecs.get(attackerHandle, Component.character); if (attackerCharacter) if (attackerCharacter) { { const xpAward = awardCombatHitXp(world.ecs, attackerHandle, profile); const xpAward = awardCombatHitXp(world.ecs, attackerHandle, profile, damage); if (xpAward) if (xpAward) { { events.push({ events.push({@@ -1355,7 +1355,9 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
fromTileY: event.fromTileY,
tileX: event.tileX,
tileY: event.tileY,
durationMs: event.durationMs ?? 400
durationMs: event.durationMs ?? 400,
shaftTint: event.shaftTint ?? null,
tipTint: event.tipTint ?? null
});
continue;
}
@@ -1355,7 +1355,9 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends, fromTileY: event.fromTileY, fromTileY: event.fromTileY, tileX: event.tileX, tileX: event.tileX, tileY: event.tileY, tileY: event.tileY, durationMs: event.durationMs ?? 400 durationMs: event.durationMs ?? 400, shaftTint: event.shaftTint ?? null, tipTint: event.tipTint ?? null }); }); continue; continue; } }@@ -1059,7 +1059,8 @@ export class Simulation
const xpResult = this.workers[attackerRecord.workerId].call({
type: WorkerMessage.applyCombatHitXp,
entityId: forward.entityId,
profile: forward.profile
profile: forward.profile,
damage: forward.damage
});
for (const xpEvent of xpResult?.events ?? [])
{
@@ -1114,7 +1115,8 @@ export class Simulation
const xpResult = this.workers[attackerRecord.workerId].call({
type: WorkerMessage.applyCombatHitXp,
entityId: forward.entityId,
profile: forward.profile
profile: forward.profile,
damage: forward.damage
});
for (const xpEvent of xpResult?.events ?? [])
{
@@ -1059,7 +1059,8 @@ export class Simulation const xpResult = this.workers[attackerRecord.workerId].call({ const xpResult = this.workers[attackerRecord.workerId].call({ type: WorkerMessage.applyCombatHitXp, type: WorkerMessage.applyCombatHitXp, entityId: forward.entityId, entityId: forward.entityId, profile: forward.profile profile: forward.profile, damage: forward.damage }); }); for (const xpEvent of xpResult?.events ?? []) for (const xpEvent of xpResult?.events ?? []) { {@@ -1114,7 +1115,8 @@ export class Simulation const xpResult = this.workers[attackerRecord.workerId].call({ const xpResult = this.workers[attackerRecord.workerId].call({ type: WorkerMessage.applyCombatHitXp, type: WorkerMessage.applyCombatHitXp, entityId: forward.entityId, entityId: forward.entityId, profile: forward.profile profile: forward.profile, damage: forward.damage }); }); for (const xpEvent of xpResult?.events ?? []) for (const xpEvent of xpResult?.events ?? []) { {@@ -727,7 +727,7 @@ export class WorkerWorld
return applyRemoteRangedShot(this, payload);
}
#applyCombatHitXp ({ entityId, profile })
#applyCombatHitXp ({ entityId, profile, damage })
{
const handle = this.ecs.handleOf(entityId);
if (handle == null)
@@ -735,7 +735,7 @@ export class WorkerWorld
const character = this.ecs.get(handle, Component.character);
if (!character)
{ return { events: [] }; }
const xpAward = awardCombatHitXp(this.ecs, handle, profile);
const xpAward = awardCombatHitXp(this.ecs, handle, profile, damage);
if (!xpAward)
{ return { events: [] }; }
return {
@@ -727,7 +727,7 @@ export class WorkerWorld return applyRemoteRangedShot(this, payload); return applyRemoteRangedShot(this, payload); } } #applyCombatHitXp ({ entityId, profile }) #applyCombatHitXp ({ entityId, profile, damage }) { { const handle = this.ecs.handleOf(entityId); const handle = this.ecs.handleOf(entityId); if (handle == null) if (handle == null)@@ -735,7 +735,7 @@ export class WorkerWorld const character = this.ecs.get(handle, Component.character); const character = this.ecs.get(handle, Component.character); if (!character) if (!character) { return { events: [] }; } { return { events: [] }; } const xpAward = awardCombatHitXp(this.ecs, handle, profile); const xpAward = awardCombatHitXp(this.ecs, handle, profile, damage); if (!xpAward) if (!xpAward) { return { events: [] }; } { return { events: [] }; } return { return {@@ -1,6 +1,6 @@
import { Component } from "../ecs/components.js";
import { SkillId, playerMaxHealth, playerMaxStamina } from "../../../shared/definitions/skills.js";
import { combatHitXpPerSkill } from "../../../shared/skills/progression.js";
import { combatDamageXp, spellCastXpFromDifficulty } from "../../../shared/skills/progression.js";
import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";
export function syncPlayerHealth (ecs, handle)
@@ -31,20 +31,22 @@ export function syncPlayerStamina (ecs, handle)
stamina.current = Math.min(Number(stamina.current) || 0, max);
}
export function awardCombatHitXp (ecs, attackerHandle, profile)
export function awardCombatHitXp (ecs, attackerHandle, profile, damage)
{
const amount = combatDamageXp(damage);
if (!amount)
{ return null; }
const skills = ecs.get(attackerHandle, Component.skills);
if (!skills?.xp)
{ return null; }
const perSkill = combatHitXpPerSkill();
const levelUps = [];
const hit = applySkillXp(skills, profile.hitSkillId, perSkill);
const hit = applySkillXp(skills, profile.hitSkillId, amount);
if (hit.levelUp)
{ levelUps.push(hit.levelUp); }
const damage = applySkillXp(skills, profile.damageSkillId, perSkill);
if (damage.levelUp)
{ levelUps.push(damage.levelUp); }
if (!hit.changed && !damage.changed)
const damageSkill = applySkillXp(skills, profile.damageSkillId, amount);
if (damageSkill.levelUp)
{ levelUps.push(damageSkill.levelUp); }
if (!hit.changed && !damageSkill.changed)
{ return null; }
return {
view: publicSkillsView(skills),
@@ -53,6 +55,25 @@ export function awardCombatHitXp (ecs, attackerHandle, profile)
};
}
/** Magic XP on a successful cast; damage XP uses {@link awardCombatHitXp} when the spell lands. */
export function awardSpellCastXp (ecs, casterHandle, spellDifficulty)
{
const amount = spellCastXpFromDifficulty(spellDifficulty);
const skills = ecs.get(casterHandle, Component.skills);
if (!skills?.xp)
{ return null; }
const result = applySkillXp(skills, SkillId.magic, amount);
if (!result.changed)
{ return null; }
const character = ecs.get(casterHandle, Component.character);
return {
characterId: character?.characterId ?? null,
view: publicSkillsView(skills),
stored: storedSkillXp(skills),
levelUps: result.levelUp ? [result.levelUp] : []
};
}
export function awardDamageHealthXp (ecs, targetHandle, damage)
{
const amount = Math.max(0, Math.floor(Number(damage) || 0));
@@ -1,6 +1,6 @@import { Component } from "../ecs/components.js";import { Component } from "../ecs/components.js";import { SkillId, playerMaxHealth, playerMaxStamina } from "../../../shared/definitions/skills.js";import { SkillId, playerMaxHealth, playerMaxStamina } from "../../../shared/definitions/skills.js";import { combatHitXpPerSkill } from "../../../shared/skills/progression.js";import { combatDamageXp, spellCastXpFromDifficulty } from "../../../shared/skills/progression.js";import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";import { applySkillXp, publicSkillsView, storedSkillXp } from "../../../shared/skills/state.js";export function syncPlayerHealth (ecs, handle)export function syncPlayerHealth (ecs, handle)@@ -31,20 +31,22 @@ export function syncPlayerStamina (ecs, handle) stamina.current = Math.min(Number(stamina.current) || 0, max); stamina.current = Math.min(Number(stamina.current) || 0, max);}}export function awardCombatHitXp (ecs, attackerHandle, profile)export function awardCombatHitXp (ecs, attackerHandle, profile, damage){{ const amount = combatDamageXp(damage); if (!amount) { return null; } const skills = ecs.get(attackerHandle, Component.skills); const skills = ecs.get(attackerHandle, Component.skills); if (!skills?.xp) if (!skills?.xp) { return null; } { return null; } const perSkill = combatHitXpPerSkill(); const levelUps = []; const levelUps = []; const hit = applySkillXp(skills, profile.hitSkillId, perSkill); const hit = applySkillXp(skills, profile.hitSkillId, amount); if (hit.levelUp) if (hit.levelUp) { levelUps.push(hit.levelUp); } { levelUps.push(hit.levelUp); } const damage = applySkillXp(skills, profile.damageSkillId, perSkill); const damageSkill = applySkillXp(skills, profile.damageSkillId, amount); if (damage.levelUp) if (damageSkill.levelUp) { levelUps.push(damage.levelUp); } { levelUps.push(damageSkill.levelUp); } if (!hit.changed && !damage.changed) if (!hit.changed && !damageSkill.changed) { return null; } { return null; } return { return { view: publicSkillsView(skills), view: publicSkillsView(skills),@@ -53,6 +55,25 @@ export function awardCombatHitXp (ecs, attackerHandle, profile) }; };}}/** Magic XP on a successful cast; damage XP uses {@link awardCombatHitXp} when the spell lands. */export function awardSpellCastXp (ecs, casterHandle, spellDifficulty){ const amount = spellCastXpFromDifficulty(spellDifficulty); const skills = ecs.get(casterHandle, Component.skills); if (!skills?.xp) { return null; } const result = applySkillXp(skills, SkillId.magic, amount); if (!result.changed) { return null; } const character = ecs.get(casterHandle, Component.character); return { characterId: character?.characterId ?? null, view: publicSkillsView(skills), stored: storedSkillXp(skills), levelUps: result.levelUp ? [result.levelUp] : [] };}export function awardDamageHealthXp (ecs, targetHandle, damage)export function awardDamageHealthXp (ecs, targetHandle, damage){{ const amount = Math.max(0, Math.floor(Number(damage) || 0)); const amount = Math.max(0, Math.floor(Number(damage) || 0));@@ -32,7 +32,6 @@ test("physical attack miss when agility roll beats hit roll", () =>
agilitySkillLevel: 10,
damageSkillLevel: 10,
defenceSkillLevel: 1,
baseDamage: 2,
rng
});
assert.equal(result.outcome, "miss");
@@ -50,7 +49,6 @@ test("equal hit and agility rolls count as a hit", () =>
agilitySkillLevel: 5,
damageSkillLevel: 5,
defenceSkillLevel: 1,
baseDamage: 1,
rng
});
assert.equal(result.toHitRoll, result.agilityRoll);
@@ -67,7 +65,6 @@ test("physical attack block prevents damage after winning the hit contest", () =
agilitySkillLevel: 3,
damageSkillLevel: 8,
defenceSkillLevel: 10,
baseDamage: 1,
rng
});
assert.equal(result.outcome, "block");
@@ -85,11 +82,27 @@ test("physical attack hit applies rolled damage when not blocked", () =>
agilitySkillLevel: 1,
damageSkillLevel: 5,
defenceSkillLevel: 1,
baseDamage: 2,
rng
});
assert.equal(result.outcome, "hit");
assert.equal(result.damage, 2);
assert.equal(result.damage, 1);
});
test("physical damage is the damage skill roll only", () =>
{
let i = 0;
const rolls = [0.5, 0, 0.4, 0];
const rng = () => rolls[i++];
const result = resolvePhysicalAttack({
hitSkillLevel: 10,
agilitySkillLevel: 1,
damageSkillLevel: 5,
defenceSkillLevel: 1,
rng
});
assert.equal(result.outcome, "hit");
assert.equal(result.damageRoll, 3);
assert.equal(result.damage, 3);
});
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", () =>
agilitySkillLevel: 1,
damageSkillLevel: 1,
defenceSkillLevel: 1,
baseDamage: 1,
rng: () => 0
});
assert.equal(result.outcome, "hit");
@@ -32,7 +32,6 @@ test("physical attack miss when agility roll beats hit roll", () => agilitySkillLevel: 10, agilitySkillLevel: 10, damageSkillLevel: 10, damageSkillLevel: 10, defenceSkillLevel: 1, defenceSkillLevel: 1, baseDamage: 2, rng rng }); }); assert.equal(result.outcome, "miss"); assert.equal(result.outcome, "miss");@@ -50,7 +49,6 @@ test("equal hit and agility rolls count as a hit", () => agilitySkillLevel: 5, agilitySkillLevel: 5, damageSkillLevel: 5, damageSkillLevel: 5, defenceSkillLevel: 1, defenceSkillLevel: 1, baseDamage: 1, rng rng }); }); assert.equal(result.toHitRoll, result.agilityRoll); assert.equal(result.toHitRoll, result.agilityRoll);@@ -67,7 +65,6 @@ test("physical attack block prevents damage after winning the hit contest", () = agilitySkillLevel: 3, agilitySkillLevel: 3, damageSkillLevel: 8, damageSkillLevel: 8, defenceSkillLevel: 10, defenceSkillLevel: 10, baseDamage: 1, rng rng }); }); assert.equal(result.outcome, "block"); assert.equal(result.outcome, "block");@@ -85,11 +82,27 @@ test("physical attack hit applies rolled damage when not blocked", () => agilitySkillLevel: 1, agilitySkillLevel: 1, damageSkillLevel: 5, damageSkillLevel: 5, defenceSkillLevel: 1, defenceSkillLevel: 1, baseDamage: 2, rng rng }); }); assert.equal(result.outcome, "hit"); assert.equal(result.outcome, "hit"); assert.equal(result.damage, 2); assert.equal(result.damage, 1);});test("physical damage is the damage skill roll only", () =>{ let i = 0; const rolls = [0.5, 0, 0.4, 0]; const rng = () => rolls[i++]; const result = resolvePhysicalAttack({ hitSkillLevel: 10, agilitySkillLevel: 1, damageSkillLevel: 5, defenceSkillLevel: 1, rng }); assert.equal(result.outcome, "hit"); assert.equal(result.damageRoll, 3); assert.equal(result.damage, 3);});});test("skill level 1 contest can still land a hit on equal agility", () =>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", () => agilitySkillLevel: 1, agilitySkillLevel: 1, damageSkillLevel: 1, damageSkillLevel: 1, defenceSkillLevel: 1, defenceSkillLevel: 1, baseDamage: 1, rng: () => 0 rng: () => 0 }); }); assert.equal(result.outcome, "hit"); assert.equal(result.outcome, "hit");@@ -30,7 +30,7 @@ test("fizzled magic attack deals no damage", () =>
magicSkillLevel: 3,
spellDifficulty: 10,
mindSkillLevel: 10,
baseDamage: 5,
mindBonus: 5,
element: "fire",
rng
});
@@ -46,7 +46,7 @@ test("successful magic attack rolls mind damage and elemental multiplier", () =>
magicSkillLevel: 10,
spellDifficulty: 1,
mindSkillLevel: 5,
baseDamage: 2,
mindBonus: 2,
element: "fire",
targetAffinities: {},
rng
@@ -60,7 +60,7 @@ test("successful magic attack rolls mind damage and elemental multiplier", () =>
magicSkillLevel: 10,
spellDifficulty: 1,
mindSkillLevel: 5,
baseDamage: 2,
mindBonus: 2,
element: "fire",
targetAffinities: { fire: "weak" },
rng: rngWeak
@@ -30,7 +30,7 @@ test("fizzled magic attack deals no damage", () => magicSkillLevel: 3, magicSkillLevel: 3, spellDifficulty: 10, spellDifficulty: 10, mindSkillLevel: 10, mindSkillLevel: 10, baseDamage: 5, mindBonus: 5, element: "fire", element: "fire", rng rng }); });@@ -46,7 +46,7 @@ test("successful magic attack rolls mind damage and elemental multiplier", () => magicSkillLevel: 10, magicSkillLevel: 10, spellDifficulty: 1, spellDifficulty: 1, mindSkillLevel: 5, mindSkillLevel: 5, baseDamage: 2, mindBonus: 2, element: "fire", element: "fire", targetAffinities: {}, targetAffinities: {}, rng rng@@ -60,7 +60,7 @@ test("successful magic attack rolls mind damage and elemental multiplier", () => magicSkillLevel: 10, magicSkillLevel: 10, spellDifficulty: 1, spellDifficulty: 1, mindSkillLevel: 5, mindSkillLevel: 5, baseDamage: 2, mindBonus: 2, element: "fire", element: "fire", targetAffinities: { fire: "weak" }, targetAffinities: { fire: "weak" }, rng: rngWeak rng: rngWeak@@ -14,5 +14,5 @@ test("mob attack profile uses one attackSkill for hit and damage rolls", () =>
{
const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat));
assert.equal(profile.mobAttackSkill, 3);
assert.equal(profile.baseDamage, 2);
assert.equal(profile.baseDamage, undefined);
});
@@ -14,5 +14,5 @@ test("mob attack profile uses one attackSkill for hit and damage rolls", () =>{{ const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat)); const profile = mobMeleeAttackProfile(mobDefinition(MobId.rat)); assert.equal(profile.mobAttackSkill, 3); assert.equal(profile.mobAttackSkill, 3); assert.equal(profile.baseDamage, 2); assert.equal(profile.baseDamage, undefined);});});@@ -16,7 +16,8 @@ test("ranged items: bow is ranged weapon, arrows stack in offhand", () =>
const arrow = itemDefinition(RangedItemId.bronzeArrow);
assert.equal(arrow?.equipment?.kind, EquipmentKind.arrowAmmo);
assert.equal(arrow?.equipment?.slot, "offhand");
assert.equal(arrow?.defaultState, "full-arrow");
assert.equal(arrow?.dualTintFromTier, true);
assert.equal(arrow?.maxStackSize, 999);
assert.equal(arrow?.equipment?.hideEquipSprite, true);
});
@@ -16,7 +16,8 @@ test("ranged items: bow is ranged weapon, arrows stack in offhand", () => const arrow = itemDefinition(RangedItemId.bronzeArrow); const arrow = itemDefinition(RangedItemId.bronzeArrow); assert.equal(arrow?.equipment?.kind, EquipmentKind.arrowAmmo); assert.equal(arrow?.equipment?.kind, EquipmentKind.arrowAmmo); assert.equal(arrow?.equipment?.slot, "offhand"); assert.equal(arrow?.defaultState, "full-arrow"); assert.equal(arrow?.dualTintFromTier, true); assert.equal(arrow?.maxStackSize, 999); assert.equal(arrow?.maxStackSize, 999); assert.equal(arrow?.equipment?.hideEquipSprite, true); assert.equal(arrow?.equipment?.hideEquipSprite, true);});});@@ -6,7 +6,8 @@ import {
totalXpForLevel,
xpProgress,
levelFromTotalXp,
combatHitXpPerSkill
combatDamageXp,
spellCastXpFromDifficulty
} from "../../shared/skills/progression.js";
import {
normalizeSkillXp,
@@ -168,12 +169,14 @@ test("applySkillXp reports a level-up when XP crosses a threshold", () =>
assert.match(result.levelUp?.icon, /strength\.svg$/);
});
test("combat hit xp is split equally", () =>
test("combat xp equals damage dealt to hit and damage skills", () =>
{
assert.equal(combatHitXpPerSkill(), 5);
assert.equal(combatDamageXp(7), 7);
assert.equal(combatDamageXp(0), 0);
assert.equal(spellCastXpFromDifficulty(4), 8);
});
test("successful player melee hits award split xp", () =>
test("successful player melee hits award xp equal to damage", () =>
{
const harness = makeSimulation({ workerCount: 1 });
const random = Math.random;
@@ -190,10 +193,13 @@ test("successful player melee hits award split xp", () =>
const worker = harness.simulation.workers[0];
const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(playerId));
const events = resolveMeleeSwing(worker.world, playerId, ratId, profile, Date.now());
const hit = events.find((event) => event.type === "combat-hit");
const updated = events.find((event) => event.type === "skills-updated");
assert.ok(hit);
assert.ok(updated);
assert.equal(updated.stored[profile.hitSkillId], combatHitXpPerSkill());
assert.equal(updated.stored[profile.damageSkillId], combatHitXpPerSkill());
const xp = combatDamageXp(hit.damage);
assert.equal(updated.stored[profile.hitSkillId], xp);
assert.equal(updated.stored[profile.damageSkillId], xp);
}
finally
{
@@ -6,7 +6,8 @@ import { totalXpForLevel, totalXpForLevel, xpProgress, xpProgress, levelFromTotalXp, levelFromTotalXp, combatHitXpPerSkill combatDamageXp, spellCastXpFromDifficulty} from "../../shared/skills/progression.js";} from "../../shared/skills/progression.js";import {import { normalizeSkillXp, normalizeSkillXp,@@ -168,12 +169,14 @@ test("applySkillXp reports a level-up when XP crosses a threshold", () => assert.match(result.levelUp?.icon, /strength\.svg$/); assert.match(result.levelUp?.icon, /strength\.svg$/);});});test("combat hit xp is split equally", () =>test("combat xp equals damage dealt to hit and damage skills", () =>{{ assert.equal(combatHitXpPerSkill(), 5); assert.equal(combatDamageXp(7), 7); assert.equal(combatDamageXp(0), 0); assert.equal(spellCastXpFromDifficulty(4), 8);});});test("successful player melee hits award split xp", () =>test("successful player melee hits award xp equal to damage", () =>{{ const harness = makeSimulation({ workerCount: 1 }); const harness = makeSimulation({ workerCount: 1 }); const random = Math.random; const random = Math.random;@@ -190,10 +193,13 @@ test("successful player melee hits award split xp", () => const worker = harness.simulation.workers[0]; const worker = harness.simulation.workers[0]; const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(playerId)); const profile = attackProfileOf(worker.world.ecs, worker.world.ecs.handleOf(playerId)); const events = resolveMeleeSwing(worker.world, playerId, ratId, profile, Date.now()); const events = resolveMeleeSwing(worker.world, playerId, ratId, profile, Date.now()); const hit = events.find((event) => event.type === "combat-hit"); const updated = events.find((event) => event.type === "skills-updated"); const updated = events.find((event) => event.type === "skills-updated"); assert.ok(hit); assert.ok(updated); assert.ok(updated); assert.equal(updated.stored[profile.hitSkillId], combatHitXpPerSkill()); const xp = combatDamageXp(hit.damage); assert.equal(updated.stored[profile.damageSkillId], combatHitXpPerSkill()); assert.equal(updated.stored[profile.hitSkillId], xp); assert.equal(updated.stored[profile.damageSkillId], xp); } } finally finally { {@@ -0,0 +1,58 @@
import test from "node:test";
import assert from "node:assert/strict";
import { ItemId, itemDefinition } from "../../shared/definitions/items.js";
import { WoodTier, MaterialTier, statBoostPerTier } from "../../shared/definitions/materialTiers.js";
import { ItemFamilyId } from "../../shared/definitions/tierFamilies.js";
import { CraftingItemId } from "../../shared/definitions/craftingItems.js";
import { RangedItemId } from "../../shared/definitions/rangedItems.js";
import { recipeDefinition } from "../../shared/crafting/stationRecipes.js";
import { CraftingStationId } from "../../shared/definitions/craftingStations.js";
test("handle family builds per-tier defs with stable ids", () =>
{
const handle = itemDefinition(ItemId.birchHandle);
assert.equal(handle.familyId, ItemFamilyId.handle);
assert.equal(handle.tier, WoodTier.birch);
assert.equal(handle.displayName, "Birch handle");
assert.equal(handle.tintFromTier, true);
});
test("ore family builds metal tier defs", () =>
{
const ore = itemDefinition(ItemId.ironOre);
assert.equal(ore.familyId, ItemFamilyId.ore);
assert.equal(ore.tier, MaterialTier.iron);
assert.equal(ore.defaultState, "ore");
});
test("statBoostPerTier aliases tierStatBonus", () =>
{
assert.equal(statBoostPerTier(MaterialTier.steel), 4);
});
test("pickaxe tool family includes bronze tier with equipment", () =>
{
const pickaxe = itemDefinition(CraftingItemId.bronzePickaxe);
assert.equal(pickaxe.familyId, ItemFamilyId.pickaxe);
assert.equal(pickaxe.equipment?.kind, "pickaxeTool");
});
test("bow family exposes ranged attack profile without base damage", () =>
{
const bow = itemDefinition(RangedItemId.pineBow);
assert.equal(bow.familyId, ItemFamilyId.bow);
assert.equal(bow.equipment?.attack?.hitSkillId, "archery");
assert.equal(bow.equipment?.attack?.baseDamage, undefined);
});
test("tier family recipes resolve through family item ids", () =>
{
const handle = recipeDefinition("handle-pine");
assert.equal(handle.output.itemId, ItemId.pineHandle);
const pickaxe = recipeDefinition("pickaxe-bronze");
assert.equal(pickaxe.output.itemId, CraftingItemId.bronzePickaxe);
assert.equal(pickaxe.inputs.length, 2);
const arrow = recipeDefinition("arrow-bronze");
assert.equal(arrow.output.itemId, RangedItemId.bronzeArrow);
assert.equal(arrow.stationId, CraftingStationId.craftingBench);
});
@@ -0,0 +1,58 @@import test from "node:test";import assert from "node:assert/strict";import { ItemId, itemDefinition } from "../../shared/definitions/items.js";import { WoodTier, MaterialTier, statBoostPerTier } from "../../shared/definitions/materialTiers.js";import { ItemFamilyId } from "../../shared/definitions/tierFamilies.js";import { CraftingItemId } from "../../shared/definitions/craftingItems.js";import { RangedItemId } from "../../shared/definitions/rangedItems.js";import { recipeDefinition } from "../../shared/crafting/stationRecipes.js";import { CraftingStationId } from "../../shared/definitions/craftingStations.js";test("handle family builds per-tier defs with stable ids", () =>{ const handle = itemDefinition(ItemId.birchHandle); assert.equal(handle.familyId, ItemFamilyId.handle); assert.equal(handle.tier, WoodTier.birch); assert.equal(handle.displayName, "Birch handle"); assert.equal(handle.tintFromTier, true);});test("ore family builds metal tier defs", () =>{ const ore = itemDefinition(ItemId.ironOre); assert.equal(ore.familyId, ItemFamilyId.ore); assert.equal(ore.tier, MaterialTier.iron); assert.equal(ore.defaultState, "ore");});test("statBoostPerTier aliases tierStatBonus", () =>{ assert.equal(statBoostPerTier(MaterialTier.steel), 4);});test("pickaxe tool family includes bronze tier with equipment", () =>{ const pickaxe = itemDefinition(CraftingItemId.bronzePickaxe); assert.equal(pickaxe.familyId, ItemFamilyId.pickaxe); assert.equal(pickaxe.equipment?.kind, "pickaxeTool");});test("bow family exposes ranged attack profile without base damage", () =>{ const bow = itemDefinition(RangedItemId.pineBow); assert.equal(bow.familyId, ItemFamilyId.bow); assert.equal(bow.equipment?.attack?.hitSkillId, "archery"); assert.equal(bow.equipment?.attack?.baseDamage, undefined);});test("tier family recipes resolve through family item ids", () =>{ const handle = recipeDefinition("handle-pine"); assert.equal(handle.output.itemId, ItemId.pineHandle); const pickaxe = recipeDefinition("pickaxe-bronze"); assert.equal(pickaxe.output.itemId, CraftingItemId.bronzePickaxe); assert.equal(pickaxe.inputs.length, 2); const arrow = recipeDefinition("arrow-bronze"); assert.equal(arrow.output.itemId, RangedItemId.bronzeArrow); assert.equal(arrow.stationId, CraftingStationId.craftingBench);});@@ -3,11 +3,15 @@ import assert from "node:assert/strict";
import {
isMagentaTintable,
magentaTintedRgb,
channelDominanceMask,
dualChannelTintedRgb,
tierTintColor,
resolveItemTint
resolveItemTint,
resolveItemDualTint
} from "../../shared/render/tint.js";
import { MaterialTier, GatherMaterialId, hexToRgb01, MATERIAL_TINT_HEX, rgb } from "../../shared/definitions/materialTiers.js";
import { ItemId } from "../../shared/definitions/items.js";
import { RangedItemId } from "../../shared/definitions/rangedItems.js";
test("magenta tintable when R==B and G < R", () =>
{
@@ -64,6 +68,29 @@ test("resolveItemTint uses potion instance color and tier tints", () =>
assert.deepEqual(resolveItemTint({ itemId: ItemId.ironBar }), iron);
});
test("dual-channel arrow tints shaft red and tip blue, leaves white fletching", () =>
{
assert.ok(channelDominanceMask(1, 0, 0, "shaft") > 0.9);
assert.ok(channelDominanceMask(0, 0, 1, "tip") > 0.9);
assert.equal(channelDominanceMask(1, 1, 1, "shaft"), 0);
assert.equal(channelDominanceMask(1, 1, 1, "tip"), 0);
const bronze = tierTintColor(MaterialTier.bronze);
const pine = tierTintColor("pine");
const shaftOnly = dualChannelTintedRgb(0.8, 0, 0, pine, bronze);
assert.ok(shaftOnly.r > 0.1);
assert.ok(shaftOnly.r > shaftOnly.b);
const tipOnly = dualChannelTintedRgb(0, 0, 0.8, pine, bronze);
assert.ok(tipOnly.b > tipOnly.r || tipOnly.b > 0.05);
const white = dualChannelTintedRgb(1, 1, 1, pine, bronze);
assert.equal(white.r, 1);
assert.equal(white.g, 1);
assert.equal(white.b, 1);
const dual = resolveItemDualTint({ itemId: RangedItemId.bronzeArrow });
assert.ok(dual?.shaft);
assert.ok(dual?.tip);
assert.equal(resolveItemTint({ itemId: RangedItemId.bronzeArrow }), null);
});
test("material tint hex converts to 0-1 rgb at load", () =>
{
assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.bronze], rgb(184, 122, 71));
@@ -3,11 +3,15 @@ import assert from "node:assert/strict";import {import { isMagentaTintable, isMagentaTintable, magentaTintedRgb, magentaTintedRgb, channelDominanceMask, dualChannelTintedRgb, tierTintColor, tierTintColor, resolveItemTint resolveItemTint, resolveItemDualTint} from "../../shared/render/tint.js";} from "../../shared/render/tint.js";import { MaterialTier, GatherMaterialId, hexToRgb01, MATERIAL_TINT_HEX, rgb } from "../../shared/definitions/materialTiers.js";import { MaterialTier, GatherMaterialId, hexToRgb01, MATERIAL_TINT_HEX, rgb } from "../../shared/definitions/materialTiers.js";import { ItemId } from "../../shared/definitions/items.js";import { ItemId } from "../../shared/definitions/items.js";import { RangedItemId } from "../../shared/definitions/rangedItems.js";test("magenta tintable when R==B and G < R", () =>test("magenta tintable when R==B and G < R", () =>{{@@ -64,6 +68,29 @@ test("resolveItemTint uses potion instance color and tier tints", () => assert.deepEqual(resolveItemTint({ itemId: ItemId.ironBar }), iron); assert.deepEqual(resolveItemTint({ itemId: ItemId.ironBar }), iron);});});test("dual-channel arrow tints shaft red and tip blue, leaves white fletching", () =>{ assert.ok(channelDominanceMask(1, 0, 0, "shaft") > 0.9); assert.ok(channelDominanceMask(0, 0, 1, "tip") > 0.9); assert.equal(channelDominanceMask(1, 1, 1, "shaft"), 0); assert.equal(channelDominanceMask(1, 1, 1, "tip"), 0); const bronze = tierTintColor(MaterialTier.bronze); const pine = tierTintColor("pine"); const shaftOnly = dualChannelTintedRgb(0.8, 0, 0, pine, bronze); assert.ok(shaftOnly.r > 0.1); assert.ok(shaftOnly.r > shaftOnly.b); const tipOnly = dualChannelTintedRgb(0, 0, 0.8, pine, bronze); assert.ok(tipOnly.b > tipOnly.r || tipOnly.b > 0.05); const white = dualChannelTintedRgb(1, 1, 1, pine, bronze); assert.equal(white.r, 1); assert.equal(white.g, 1); assert.equal(white.b, 1); const dual = resolveItemDualTint({ itemId: RangedItemId.bronzeArrow }); assert.ok(dual?.shaft); assert.ok(dual?.tip); assert.equal(resolveItemTint({ itemId: RangedItemId.bronzeArrow }), null);});test("material tint hex converts to 0-1 rgb at load", () =>test("material tint hex converts to 0-1 rgb at load", () =>{{ assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.bronze], rgb(184, 122, 71)); assert.deepEqual(MATERIAL_TINT_HEX[MaterialTier.bronze], rgb(184, 122, 71));