import { hashString } from "./hair.js"; import { sweaterItemId, shirtItemId, shortsItemId, skirtItemId, trousersItemId } from "../definitions/clothItems.js"; import { CLOTH_TIER_ORDER } from "../definitions/materialTiers.js"; import { LeatherItemId } from "../definitions/leatherItems.js"; import { normalizeRgb } from "../render/tint.js"; /** Minimum byte channel when rolling random NPC cloth dyes (avoids near-black). */ export const NPC_CLOTH_DYE_BYTE_MIN = 40; /** * Deterministic dye from a display name (+ optional salt). * @returns {{ r: number, g: number, b: number }} linear RGB 0–1 */ export function npcClothDyeFromSeed (displayName, salt = 0) { const seed = hashString(`${String(displayName ?? "").trim().toLowerCase() || "npc"}:${salt}`); const span = 256 - NPC_CLOTH_DYE_BYTE_MIN; const r = NPC_CLOTH_DYE_BYTE_MIN + (seed % span); const g = NPC_CLOTH_DYE_BYTE_MIN + ((seed >>> 8) % span); const b = NPC_CLOTH_DYE_BYTE_MIN + ((seed >>> 16) % span); return normalizeRgb({ r: r / 255, g: g / 255, b: b / 255 }); } /** * Default humanoid spawner clothing when a slot is left empty. * Chest/legs use random dyes; boots are soft-leather shoes (tier tint). * * @returns {Partial>} */ export function npcDefaultEquipment (displayName, sex = "male") { const name = String(displayName ?? "").trim().toLowerCase() || "npc"; const seed = hashString(name); const wantsSweater = (seed >>> 12) % 5 === 0; const chestTier = CLOTH_TIER_ORDER[(seed >>> 6) % CLOTH_TIER_ORDER.length]; const chestItemId = wantsSweater ? sweaterItemId(chestTier) : shirtItemId(chestTier); const legsTier = CLOTH_TIER_ORDER[(seed >>> 18) % CLOTH_TIER_ORDER.length]; const legsRoll = seed % 3; const legsItemId = legsRoll === 0 ? shortsItemId(legsTier) : legsRoll === 1 ? skirtItemId(legsTier) : trousersItemId(legsTier); return { chest: { itemId: chestItemId, dyeColor: npcClothDyeFromSeed(name, 1) }, legs: { itemId: legsItemId, dyeColor: npcClothDyeFromSeed(name, 2) }, boots: { itemId: LeatherItemId.leatherShoes, dyeColor: null } }; }