BlueGit

timfa questward

Strict dual-channel tint and full fairy mob presentation.

RGB blend only when the winning channel has equal secondaries; fairies use their own bloom sprite with random hair/shirt/skirt tints, soft light, and per-swing elemental melee.

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
952d65833d6edbfacf81d871622bad99b4c71431
Parent
3697a6d3
10 files changed +137 −55
client/assets/mobs/fairy/fairy-bloom.png added Binary file +0 −0

The contents of this binary file are not shown.

client/assets/mobs/fairy/fairy.png added Binary file +0 −0

The contents of this binary file are not shown.

client/src/render/worldView.js +50 −17
@@ -164,7 +164,8 @@ const TINT_LIT_SPRITE_FRAG = [
164 164 ].join("\n");
165 165
166 166 /** Dual/triple-channel tint: red = shaft, blue = tip, green = coat; then darkness.
167 * Equal non-dominant channels lighten the assigned tint toward white. */
167 * Only when the primary channel is highest and the other two are equal;
168 * equal non-zero secondaries lighten the assigned tint toward white. */
168 169 const DUAL_TINT_LIT_SPRITE_FRAG = [
169 170 "precision mediump float;",
170 171 "varying vec2 v_texCoord;",
@@ -178,12 +179,13 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
178 179 "uniform vec3 u_tipTint;",
179 180 "uniform vec3 u_coatTint;",
180 181 "uniform float u_hasCoat;",
181 "vec3 channelTint(float L, float o1, float o2, vec3 tint) {",
182 "vec3 channelTint(float L, float secondary, vec3 tint) {",
183 " float blend = L > 0.0 ? clamp(secondary / L, 0.0, 1.0) : 0.0;",
184 " return mix(tint, vec3(1.0), blend) * L;",
185 "}",
186 "float channelMask(float primary, float o1, float o2) {",
182 187 " float equal = step(abs(o1 - o2), 0.04);",
183 " float blend = L > 0.0 ? clamp(mix(min(o1, o2), o1, equal) / L, 0.0, 1.0) : 0.0;",
184 " float tintLuma = dot(tint, vec3(0.2126, 0.7152, 0.0722));",
185 " vec3 toward = mix(vec3(tintLuma), vec3(1.0), equal);",
186 " return mix(tint, toward, blend) * L;",
188 " return clamp((primary - max(o1, o2)) * 1.75, 0.0, 1.0) * equal;",
187 189 "}",
188 190 "void main() {",
189 191 " vec4 color = texture2D(u_texture, v_texCoord);",
@@ -192,20 +194,20 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
192 194 " if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
193 195 " vec3 rgb = color.rgb;",
194 196 " if (u_hasCoat > 0.5) {",
195 " float coatMask = clamp((color.g - max(color.r, color.b)) * 1.75, 0.0, 1.0);",
197 " float coatMask = channelMask(color.g, color.r, color.b);",
196 198 " if (coatMask > 0.0) {",
197 " vec3 coatCol = channelTint(color.g, color.r, color.b, u_coatTint);",
199 " vec3 coatCol = channelTint(color.g, color.r, u_coatTint);",
198 200 " rgb = mix(rgb, coatCol, coatMask);",
199 201 " }",
200 202 " }",
201 " float tipMask = clamp((color.b - max(color.r, color.g)) * 1.75, 0.0, 1.0);",
203 " float tipMask = channelMask(color.b, color.r, color.g);",
202 204 " if (tipMask > 0.0) {",
203 " vec3 tipCol = channelTint(color.b, color.r, color.g, u_tipTint);",
205 " vec3 tipCol = channelTint(color.b, color.r, u_tipTint);",
204 206 " rgb = mix(rgb, tipCol, tipMask);",
205 207 " }",
206 " float shaftMask = clamp((color.r - max(color.g, color.b)) * 1.75, 0.0, 1.0);",
208 " float shaftMask = channelMask(color.r, color.g, color.b);",
207 209 " if (shaftMask > 0.0) {",
208 " vec3 shaftCol = channelTint(color.r, color.g, color.b, u_shaftTint);",
210 " vec3 shaftCol = channelTint(color.r, color.g, u_shaftTint);",
209 211 " rgb = mix(rgb, shaftCol, shaftMask);",
210 212 " }",
211 213 " if (u_wade > 0.5 && fromBottom < 5.0) {",
@@ -2368,6 +2370,15 @@ export class WorldView
2368 2370 this.#startIdleAnimation(entity.object);
2369 2371 }
2370 2372 entity.bodyTint = layers[0]?.tint ? normalizeRgb(layers[0].tint) : null;
2373 entity.bodyDualTint = layers[0]?.dualTint
2374 ? {
2375 shaft: normalizeRgb(layers[0].dualTint.shaft),
2376 tip: normalizeRgb(layers[0].dualTint.tip),
2377 ...(layers[0].dualTint.coat
2378 ? { coat: normalizeRgb(layers[0].dualTint.coat) }
2379 : {})
2380 }
2381 : null;
2371 2382 entity.bloomBody = !!layers[0]?.bloomBody;
2372 2383 for (const overlay of entity.overlays ?? [])
2373 2384 { overlay.destroy(); }
@@ -2379,6 +2390,7 @@ export class WorldView
2379 2390 entity.overlayTightFit = [];
2380 2391 entity.bloomOverlays = [];
2381 2392 entity.bloomOverlayTints = [];
2393 entity.bloomOverlayDualTints = [];
2382 2394 if (entity.bloomBody && this.game.images[base])
2383 2395 {
2384 2396 const bloomName = bloomCompanionName(base);
@@ -2391,6 +2403,7 @@ export class WorldView
2391 2403 this.scene.addObject(bloom);
2392 2404 entity.bloomOverlays.push(bloom);
2393 2405 entity.bloomOverlayTints.push(entity.bodyTint);
2406 entity.bloomOverlayDualTints.push(entity.bodyDualTint);
2394 2407 }
2395 2408 }
2396 2409 for (const layer of layers.slice(1))
@@ -2452,7 +2465,21 @@ export class WorldView
2452 2465 const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);
2453 2466
2454 2467 entity.object.transform.rotation = walkTilt;
2455 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null, flashColor);
2468 if (entity.bodyDualTint)
2469 {
2470 this.#syncDualTintLitSprite(
2471 entity.object,
2472 tileShade,
2473 entity.bodyDualTint,
2474 flashStrength,
2475 wade,
2476 flashColor
2477 );
2478 }
2479 else
2480 {
2481 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null, flashColor);
2482 }
2456 2483 const flight = !!entity.freeFlight;
2457 2484 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1, flight);
2458 2485 for (let index = 0; index < (entity.overlays ?? []).length; index++)
@@ -2496,8 +2523,11 @@ export class WorldView
2496 2523 overlay.renderer.subImage = entity.object.renderer.subImage | 0;
2497 2524 }
2498 2525 overlay.transform.rotation = walkTilt;
2526 const bloomDual = entity.bloomOverlayDualTints?.[index] ?? null;
2499 2527 const bloomTint = entity.bloomOverlayTints?.[index] ?? entity.bodyTint ?? null;
2500 if (bloomTint)
2528 if (bloomDual)
2529 { this.#syncDualTintLitSprite(overlay, 0, bloomDual); }
2530 else if (bloomTint)
2501 2531 { this.#syncUnlitTintSprite(overlay, bloomTint); }
2502 2532 else
2503 2533 { this.#syncLitSprite(overlay, tileShade, flashStrength, wade, null, flashColor); }
@@ -2648,13 +2678,16 @@ export class WorldView
2648 2678
2649 2679 #syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false, flashColor = null)
2650 2680 {
2651 if (!object?.renderer || object._lit === false || !dualTint)
2681 if (!object?.renderer || !dualTint)
2652 2682 { return; }
2653 object._lit = true;
2654 2683 const shaft = normalizeRgb(dualTint.shaft);
2655 2684 const tip = normalizeRgb(dualTint.tip);
2656 2685 const coat = dualTint.coat ? normalizeRgb(dualTint.coat) : null;
2657 const dark = Math.min(1, Math.max(0, darkness ?? 0));
2686 const dark = object._lit === false
2687 ? 0
2688 : Math.min(1, Math.max(0, darkness ?? 0));
2689 if (object._lit !== false)
2690 { object._lit = true; }
2658 2691 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
2659 2692 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
2660 2693 object.renderer.shader = getDualTintLitSpriteShader();
@@ -164,7 +164,8 @@ const TINT_LIT_SPRITE_FRAG = [
164].join("\n");
164].join("\n");
165
165
166/** Dual/triple-channel tint: red = shaft, blue = tip, green = coat; then darkness.
166/** Dual/triple-channel tint: red = shaft, blue = tip, green = coat; then darkness.
167 * Equal non-dominant channels lighten the assigned tint toward white. */
167 * Only when the primary channel is highest and the other two are equal;
168 * equal non-zero secondaries lighten the assigned tint toward white. */
168const DUAL_TINT_LIT_SPRITE_FRAG = [
169const DUAL_TINT_LIT_SPRITE_FRAG = [
169 "precision mediump float;",
170 "precision mediump float;",
170 "varying vec2 v_texCoord;",
171 "varying vec2 v_texCoord;",
@@ -178,12 +179,13 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
178 "uniform vec3 u_tipTint;",
179 "uniform vec3 u_tipTint;",
179 "uniform vec3 u_coatTint;",
180 "uniform vec3 u_coatTint;",
180 "uniform float u_hasCoat;",
181 "uniform float u_hasCoat;",
181 "vec3 channelTint(float L, float o1, float o2, vec3 tint) {",
182 "vec3 channelTint(float L, float secondary, vec3 tint) {",
183 " float blend = L > 0.0 ? clamp(secondary / L, 0.0, 1.0) : 0.0;",
184 " return mix(tint, vec3(1.0), blend) * L;",
185 "}",
186 "float channelMask(float primary, float o1, float o2) {",
182 " float equal = step(abs(o1 - o2), 0.04);",
187 " float equal = step(abs(o1 - o2), 0.04);",
183 " float blend = L > 0.0 ? clamp(mix(min(o1, o2), o1, equal) / L, 0.0, 1.0) : 0.0;",
188 " return clamp((primary - max(o1, o2)) * 1.75, 0.0, 1.0) * equal;",
184 " float tintLuma = dot(tint, vec3(0.2126, 0.7152, 0.0722));",
185 " vec3 toward = mix(vec3(tintLuma), vec3(1.0), equal);",
186 " return mix(tint, toward, blend) * L;",
187 "}",
189 "}",
188 "void main() {",
190 "void main() {",
189 " vec4 color = texture2D(u_texture, v_texCoord);",
191 " vec4 color = texture2D(u_texture, v_texCoord);",
@@ -192,20 +194,20 @@ const DUAL_TINT_LIT_SPRITE_FRAG = [
192 " if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
194 " if (u_wade > 0.5 && fromBottom < 4.0) { discard; }",
193 " vec3 rgb = color.rgb;",
195 " vec3 rgb = color.rgb;",
194 " if (u_hasCoat > 0.5) {",
196 " if (u_hasCoat > 0.5) {",
195 " float coatMask = clamp((color.g - max(color.r, color.b)) * 1.75, 0.0, 1.0);",
197 " float coatMask = channelMask(color.g, color.r, color.b);",
196 " if (coatMask > 0.0) {",
198 " if (coatMask > 0.0) {",
197 " vec3 coatCol = channelTint(color.g, color.r, color.b, u_coatTint);",
199 " vec3 coatCol = channelTint(color.g, color.r, u_coatTint);",
198 " rgb = mix(rgb, coatCol, coatMask);",
200 " rgb = mix(rgb, coatCol, coatMask);",
199 " }",
201 " }",
200 " }",
202 " }",
201 " float tipMask = clamp((color.b - max(color.r, color.g)) * 1.75, 0.0, 1.0);",
203 " float tipMask = channelMask(color.b, color.r, color.g);",
202 " if (tipMask > 0.0) {",
204 " if (tipMask > 0.0) {",
203 " vec3 tipCol = channelTint(color.b, color.r, color.g, u_tipTint);",
205 " vec3 tipCol = channelTint(color.b, color.r, u_tipTint);",
204 " rgb = mix(rgb, tipCol, tipMask);",
206 " rgb = mix(rgb, tipCol, tipMask);",
205 " }",
207 " }",
206 " float shaftMask = clamp((color.r - max(color.g, color.b)) * 1.75, 0.0, 1.0);",
208 " float shaftMask = channelMask(color.r, color.g, color.b);",
207 " if (shaftMask > 0.0) {",
209 " if (shaftMask > 0.0) {",
208 " vec3 shaftCol = channelTint(color.r, color.g, color.b, u_shaftTint);",
210 " vec3 shaftCol = channelTint(color.r, color.g, u_shaftTint);",
209 " rgb = mix(rgb, shaftCol, shaftMask);",
211 " rgb = mix(rgb, shaftCol, shaftMask);",
210 " }",
212 " }",
211 " if (u_wade > 0.5 && fromBottom < 5.0) {",
213 " if (u_wade > 0.5 && fromBottom < 5.0) {",
@@ -2368,6 +2370,15 @@ export class WorldView
2368 this.#startIdleAnimation(entity.object);
2370 this.#startIdleAnimation(entity.object);
2369 }
2371 }
2370 entity.bodyTint = layers[0]?.tint ? normalizeRgb(layers[0].tint) : null;
2372 entity.bodyTint = layers[0]?.tint ? normalizeRgb(layers[0].tint) : null;
2373 entity.bodyDualTint = layers[0]?.dualTint
2374 ? {
2375 shaft: normalizeRgb(layers[0].dualTint.shaft),
2376 tip: normalizeRgb(layers[0].dualTint.tip),
2377 ...(layers[0].dualTint.coat
2378 ? { coat: normalizeRgb(layers[0].dualTint.coat) }
2379 : {})
2380 }
2381 : null;
2371 entity.bloomBody = !!layers[0]?.bloomBody;
2382 entity.bloomBody = !!layers[0]?.bloomBody;
2372 for (const overlay of entity.overlays ?? [])
2383 for (const overlay of entity.overlays ?? [])
2373 { overlay.destroy(); }
2384 { overlay.destroy(); }
@@ -2379,6 +2390,7 @@ export class WorldView
2379 entity.overlayTightFit = [];
2390 entity.overlayTightFit = [];
2380 entity.bloomOverlays = [];
2391 entity.bloomOverlays = [];
2381 entity.bloomOverlayTints = [];
2392 entity.bloomOverlayTints = [];
2393 entity.bloomOverlayDualTints = [];
2382 if (entity.bloomBody && this.game.images[base])
2394 if (entity.bloomBody && this.game.images[base])
2383 {
2395 {
2384 const bloomName = bloomCompanionName(base);
2396 const bloomName = bloomCompanionName(base);
@@ -2391,6 +2403,7 @@ export class WorldView
2391 this.scene.addObject(bloom);
2403 this.scene.addObject(bloom);
2392 entity.bloomOverlays.push(bloom);
2404 entity.bloomOverlays.push(bloom);
2393 entity.bloomOverlayTints.push(entity.bodyTint);
2405 entity.bloomOverlayTints.push(entity.bodyTint);
2406 entity.bloomOverlayDualTints.push(entity.bodyDualTint);
2394 }
2407 }
2395 }
2408 }
2396 for (const layer of layers.slice(1))
2409 for (const layer of layers.slice(1))
@@ -2452,7 +2465,21 @@ export class WorldView
2452 const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);
2465 const wade = isWadeGroundInSeason(this.#groundTypeAt(entity.tileX, entity.tileY), this.worldSeason);
2453
2466
2454 entity.object.transform.rotation = walkTilt;
2467 entity.object.transform.rotation = walkTilt;
2455 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null, flashColor);
2468 if (entity.bodyDualTint)
2469 {
2470 this.#syncDualTintLitSprite(
2471 entity.object,
2472 tileShade,
2473 entity.bodyDualTint,
2474 flashStrength,
2475 wade,
2476 flashColor
2477 );
2478 }
2479 else
2480 {
2481 this.#syncLitSprite(entity.object, tileShade, flashStrength, wade, entity.bodyTint ?? null, flashColor);
2482 }
2456 const flight = !!entity.freeFlight;
2483 const flight = !!entity.freeFlight;
2457 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1, flight);
2484 this.#placePivoted(entity.object, pivotX, pivotY, pivotY, SORT_ENTITY, entity.visualScale ?? 1, flight);
2458 for (let index = 0; index < (entity.overlays ?? []).length; index++)
2485 for (let index = 0; index < (entity.overlays ?? []).length; index++)
@@ -2496,8 +2523,11 @@ export class WorldView
2496 overlay.renderer.subImage = entity.object.renderer.subImage | 0;
2523 overlay.renderer.subImage = entity.object.renderer.subImage | 0;
2497 }
2524 }
2498 overlay.transform.rotation = walkTilt;
2525 overlay.transform.rotation = walkTilt;
2526 const bloomDual = entity.bloomOverlayDualTints?.[index] ?? null;
2499 const bloomTint = entity.bloomOverlayTints?.[index] ?? entity.bodyTint ?? null;
2527 const bloomTint = entity.bloomOverlayTints?.[index] ?? entity.bodyTint ?? null;
2500 if (bloomTint)
2528 if (bloomDual)
2529 { this.#syncDualTintLitSprite(overlay, 0, bloomDual); }
2530 else if (bloomTint)
2501 { this.#syncUnlitTintSprite(overlay, bloomTint); }
2531 { this.#syncUnlitTintSprite(overlay, bloomTint); }
2502 else
2532 else
2503 { this.#syncLitSprite(overlay, tileShade, flashStrength, wade, null, flashColor); }
2533 { this.#syncLitSprite(overlay, tileShade, flashStrength, wade, null, flashColor); }
@@ -2648,13 +2678,16 @@ export class WorldView
2648
2678
2649 #syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false, flashColor = null)
2679 #syncDualTintLitSprite (object, darkness, dualTint, flashStrength = 0, wade = false, flashColor = null)
2650 {
2680 {
2651 if (!object?.renderer || object._lit === false || !dualTint)
2681 if (!object?.renderer || !dualTint)
2652 { return; }
2682 { return; }
2653 object._lit = true;
2654 const shaft = normalizeRgb(dualTint.shaft);
2683 const shaft = normalizeRgb(dualTint.shaft);
2655 const tip = normalizeRgb(dualTint.tip);
2684 const tip = normalizeRgb(dualTint.tip);
2656 const coat = dualTint.coat ? normalizeRgb(dualTint.coat) : null;
2685 const coat = dualTint.coat ? normalizeRgb(dualTint.coat) : null;
2657 const dark = Math.min(1, Math.max(0, darkness ?? 0));
2686 const dark = object._lit === false
2687 ? 0
2688 : Math.min(1, Math.max(0, darkness ?? 0));
2689 if (object._lit !== false)
2690 { object._lit = true; }
2658 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
2691 const flash = Math.min(1, Math.max(0, flashStrength ?? 0));
2659 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
2692 const height = object.renderer.sprite?.height ?? SPRITE_SIZE_PX;
2660 object.renderer.shader = getDualTintLitSpriteShader();
2693 object.renderer.shader = getDualTintLitSpriteShader();
server/src/combat/service.js +17 −6
@@ -14,7 +14,7 @@ import
14 14 import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";
15 15 import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
16 16 import { mobDamageAffinities } from "../../../shared/combat/magic.js";
17 import { AttackType } from "../../../shared/definitions/attackTypes.js";
17 import { AttackType, MAGIC_ELEMENT_ORDER } from "../../../shared/definitions/attackTypes.js";
18 18 import
19 19 {
20 20 effectiveHitSkillInDarkness,
@@ -324,14 +324,25 @@ function arrowStackInOffhand (equipment)
324 324 return stack;
325 325 }
326 326
327 /** Physical attack type, or tipped-arrow magic element when present. */
327 /** Physical attack type, tipped-arrow element, or per-swing random fairy element. */
328 328 function resolveAttackDamageType (ecs, attackerHandle, profile)
329 329 {
330 if (attackerHandle != null && profile?.mode === "ranged")
330 if (attackerHandle != null)
331 331 {
332 const stack = arrowStackInOffhand(ecs.get(attackerHandle, Component.equipment));
333 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
334 { return stack.instance.element; }
332 const creature = ecs.get(attackerHandle, Component.creature);
333 const def = creature ? mobDefinition(creature.mobTypeId) : null;
334 if (def?.randomElementMelee)
335 {
336 return MAGIC_ELEMENT_ORDER[
337 Math.floor(Math.random() * MAGIC_ELEMENT_ORDER.length)
338 ];
339 }
340 if (profile?.mode === "ranged")
341 {
342 const stack = arrowStackInOffhand(ecs.get(attackerHandle, Component.equipment));
343 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
344 { return stack.instance.element; }
345 }
335 346 }
336 347 return profile?.attackType ?? AttackType.blunt;
337 348 }
@@ -14,7 +14,7 @@ import
14import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";
14import { spellDefinition, spellMinMagicLevel } from "../../../shared/definitions/spells.js";
15import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
15import { resolvePhysicalAttack } from "../../../shared/combat/rolls.js";
16import { mobDamageAffinities } from "../../../shared/combat/magic.js";
16import { mobDamageAffinities } from "../../../shared/combat/magic.js";
17import { AttackType } from "../../../shared/definitions/attackTypes.js";
17import { AttackType, MAGIC_ELEMENT_ORDER } from "../../../shared/definitions/attackTypes.js";
18import
18import
19 {
19 {
20 effectiveHitSkillInDarkness,
20 effectiveHitSkillInDarkness,
@@ -324,14 +324,25 @@ function arrowStackInOffhand (equipment)
324 return stack;
324 return stack;
325}
325}
326
326
327/** Physical attack type, or tipped-arrow magic element when present. */
327/** Physical attack type, tipped-arrow element, or per-swing random fairy element. */
328function resolveAttackDamageType (ecs, attackerHandle, profile)
328function resolveAttackDamageType (ecs, attackerHandle, profile)
329{
329{
330 if (attackerHandle != null && profile?.mode === "ranged")
330 if (attackerHandle != null)
331 {
331 {
332 const stack = arrowStackInOffhand(ecs.get(attackerHandle, Component.equipment));
332 const creature = ecs.get(attackerHandle, Component.creature);
333 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
333 const def = creature ? mobDefinition(creature.mobTypeId) : null;
334 { return stack.instance.element; }
334 if (def?.randomElementMelee)
335 {
336 return MAGIC_ELEMENT_ORDER[
337 Math.floor(Math.random() * MAGIC_ELEMENT_ORDER.length)
338 ];
339 }
340 if (profile?.mode === "ranged")
341 {
342 const stack = arrowStackInOffhand(ecs.get(attackerHandle, Component.equipment));
343 if (stack?.instance?.kind === "tipped-arrow" && stack.instance.element)
344 { return stack.instance.element; }
345 }
335 }
346 }
336 return profile?.attackType ?? AttackType.blunt;
347 return profile?.attackType ?? AttackType.blunt;
337}
348}
server/src/simulation/spawners.js +14 −1
@@ -24,7 +24,7 @@ import { LeatherItemId } from "../../../shared/definitions/leatherItems.js";
24 24 import { CENTRAL_EXCHANGE_STAFF } from "../../../shared/market/exchange.js";
25 25 import { emptyEquipment } from "../../../shared/items/inventory.js";
26 26 import { itemDefinition } from "../../../shared/definitions/items.js";
27 import { appearanceHairFields, hairFromNameSeed } from "../../../shared/appearance/hair.js";
27 import { appearanceHairFields, hairFromNameSeed, randomNpcHairColor, randomBrightOrPastelColor } from "../../../shared/appearance/hair.js";
28 28 import { npcDefaultEquipment } from "../../../shared/appearance/npcEquipment.js";
29 29 import { Component } from "../ecs/components.js";
30 30 import { tileToChunk, tileToRegion, parseChunkKey } from "../world/coordinates.js";
@@ -241,6 +241,19 @@ export function mobComponents (request)
241 241 { appearance.sprite = sprite; }
242 242 }
243 243
244 if (def.dualChannelAppearance || def.mobTypeId === MobId.fairy)
245 {
246 appearance.dualTint = {
247 /** Red channel — shirt. */
248 shaft: randomBrightOrPastelColor(),
249 /** Blue channel — skirt. */
250 tip: randomBrightOrPastelColor(),
251 /** Green channel — hair. */
252 coat: randomNpcHairColor()
253 };
254 appearance.bloomBody = !!def.bloomBody;
255 }
256
244 257 let element = request.element ?? null;
245 258 if ((def.randomElementOnSpawn || def.mobTypeId === MobId.sprite) && !element)
246 259 {
@@ -24,7 +24,7 @@ import { LeatherItemId } from "../../../shared/definitions/leatherItems.js";
24import { CENTRAL_EXCHANGE_STAFF } from "../../../shared/market/exchange.js";
24import { CENTRAL_EXCHANGE_STAFF } from "../../../shared/market/exchange.js";
25import { emptyEquipment } from "../../../shared/items/inventory.js";
25import { emptyEquipment } from "../../../shared/items/inventory.js";
26import { itemDefinition } from "../../../shared/definitions/items.js";
26import { itemDefinition } from "../../../shared/definitions/items.js";
27import { appearanceHairFields, hairFromNameSeed } from "../../../shared/appearance/hair.js";
27import { appearanceHairFields, hairFromNameSeed, randomNpcHairColor, randomBrightOrPastelColor } from "../../../shared/appearance/hair.js";
28import { npcDefaultEquipment } from "../../../shared/appearance/npcEquipment.js";
28import { npcDefaultEquipment } from "../../../shared/appearance/npcEquipment.js";
29import { Component } from "../ecs/components.js";
29import { Component } from "../ecs/components.js";
30import { tileToChunk, tileToRegion, parseChunkKey } from "../world/coordinates.js";
30import { tileToChunk, tileToRegion, parseChunkKey } from "../world/coordinates.js";
@@ -241,6 +241,19 @@ export function mobComponents (request)
241 { appearance.sprite = sprite; }
241 { appearance.sprite = sprite; }
242 }
242 }
243
243
244 if (def.dualChannelAppearance || def.mobTypeId === MobId.fairy)
245 {
246 appearance.dualTint = {
247 /** Red channel — shirt. */
248 shaft: randomBrightOrPastelColor(),
249 /** Blue channel — skirt. */
250 tip: randomBrightOrPastelColor(),
251 /** Green channel — hair. */
252 coat: randomNpcHairColor()
253 };
254 appearance.bloomBody = !!def.bloomBody;
255 }
256
244 let element = request.element ?? null;
257 let element = request.element ?? null;
245 if ((def.randomElementOnSpawn || def.mobTypeId === MobId.sprite) && !element)
258 if ((def.randomElementOnSpawn || def.mobTypeId === MobId.sprite) && !element)
246 {
259 {
server/tests/shearing.test.js +8 −3
@@ -111,11 +111,16 @@ test("sheep and cashmere goat are shearable with fleece/shorn sprites", () =>
111 111 assert.equal(mobSpriteName(MobId.cashmereGoat, "fleece"), "mob:cashmere-goat:fleece");
112 112 });
113 113
114 test("fairy reuses sprite art and drops fairy silk", () =>
114 test("fairy uses own sprites, dual-channel kit, and random-element melee", () =>
115 115 {
116 116 const fairy = mobDefinition(MobId.fairy);
117 assert.equal(fairy.spriteKey, "sprite");
118 assert.equal(mobSpriteName(MobId.fairy), "mob:sprite:sprite");
117 assert.equal(fairy.spriteKey, undefined);
118 assert.equal(mobSpriteName(MobId.fairy), "mob:fairy:fairy");
119 assert.equal(fairy.bloomBody, true);
120 assert.equal(fairy.dualChannelAppearance, true);
121 assert.equal(fairy.randomElementMelee, true);
122 assert.equal(fairy.lightRadiusTiles, 1);
123 assert.equal(fairy.frames, 2);
119 124 assert.equal(fairy.drops.length, 1);
120 125 assert.equal(fairy.drops[0].itemId, ClothItemId.fairySilk);
121 126 assert.equal(fairy.drops[0].chance, 0.7);
@@ -111,11 +111,16 @@ test("sheep and cashmere goat are shearable with fleece/shorn sprites", () =>
111 assert.equal(mobSpriteName(MobId.cashmereGoat, "fleece"), "mob:cashmere-goat:fleece");
111 assert.equal(mobSpriteName(MobId.cashmereGoat, "fleece"), "mob:cashmere-goat:fleece");
112});
112});
113
113
114test("fairy reuses sprite art and drops fairy silk", () =>
114test("fairy uses own sprites, dual-channel kit, and random-element melee", () =>
115{
115{
116 const fairy = mobDefinition(MobId.fairy);
116 const fairy = mobDefinition(MobId.fairy);
117 assert.equal(fairy.spriteKey, "sprite");
117 assert.equal(fairy.spriteKey, undefined);
118 assert.equal(mobSpriteName(MobId.fairy), "mob:sprite:sprite");
118 assert.equal(mobSpriteName(MobId.fairy), "mob:fairy:fairy");
119 assert.equal(fairy.bloomBody, true);
120 assert.equal(fairy.dualChannelAppearance, true);
121 assert.equal(fairy.randomElementMelee, true);
122 assert.equal(fairy.lightRadiusTiles, 1);
123 assert.equal(fairy.frames, 2);
119 assert.equal(fairy.drops.length, 1);
124 assert.equal(fairy.drops.length, 1);
120 assert.equal(fairy.drops[0].itemId, ClothItemId.fairySilk);
125 assert.equal(fairy.drops[0].itemId, ClothItemId.fairySilk);
121 assert.equal(fairy.drops[0].chance, 0.7);
126 assert.equal(fairy.drops[0].chance, 0.7);
server/tests/tint.test.js +5 −0
@@ -86,6 +86,11 @@ test("dual-channel arrow tints shaft red and tip blue, leaves white fletching",
86 86 assert.equal(white.r, 1);
87 87 assert.equal(white.g, 1);
88 88 assert.equal(white.b, 1);
89 const unequal = dualChannelTintedRgb(0.9, 0.4, 0.1, pine, bronze);
90 assert.equal(unequal.r, 0.9);
91 assert.equal(unequal.g, 0.4);
92 assert.equal(unequal.b, 0.1);
93 assert.equal(channelDominanceMask(0.9, 0.4, 0.1, "shaft"), 0);
89 94 const dual = resolveItemDualTint({ itemId: RangedItemId.bronzeArrow });
90 95 assert.ok(dual?.shaft);
91 96 assert.ok(dual?.tip);
@@ -86,6 +86,11 @@ test("dual-channel arrow tints shaft red and tip blue, leaves white fletching",
86 assert.equal(white.r, 1);
86 assert.equal(white.r, 1);
87 assert.equal(white.g, 1);
87 assert.equal(white.g, 1);
88 assert.equal(white.b, 1);
88 assert.equal(white.b, 1);
89 const unequal = dualChannelTintedRgb(0.9, 0.4, 0.1, pine, bronze);
90 assert.equal(unequal.r, 0.9);
91 assert.equal(unequal.g, 0.4);
92 assert.equal(unequal.b, 0.1);
93 assert.equal(channelDominanceMask(0.9, 0.4, 0.1, "shaft"), 0);
89 const dual = resolveItemDualTint({ itemId: RangedItemId.bronzeArrow });
94 const dual = resolveItemDualTint({ itemId: RangedItemId.bronzeArrow });
90 assert.ok(dual?.shaft);
95 assert.ok(dual?.shaft);
91 assert.ok(dual?.tip);
96 assert.ok(dual?.tip);
shared/appearance/hair.js +21 −0
@@ -66,6 +66,26 @@ export function hairFromNameSeed (displayName, sex)
66 66 return { style, color, sex: resolvedSex };
67 67 }
68 68
69 /** Random NPC hair palette colour (fairies, etc.). */
70 export function randomNpcHairColor (rng = Math.random)
71 {
72 const index = Math.floor(rng() * NPC_HAIR_COLORS.length) % NPC_HAIR_COLORS.length;
73 return normalizeRgb(NPC_HAIR_COLORS[index]);
74 }
75
76 /**
77 * Bright or pastel clothing colour for dual-channel fairy kits.
78 * @returns {{ r: number, g: number, b: number }}
79 */
80 export function randomBrightOrPastelColor (rng = Math.random)
81 {
82 const hue = rng() * 360;
83 const pastel = rng() < 0.5;
84 if (pastel)
85 { return hslToRgb(hue, 0.42 + rng() * 0.38, 0.70 + rng() * 0.2); }
86 return hslToRgb(hue, 0.72 + rng() * 0.28, 0.42 + rng() * 0.28);
87 }
88
69 89 export function bodySpriteName (sex)
70 90 {
71 91 const key = sex === "female" ? "player-body-female" : "player-body-male";
@@ -220,6 +240,7 @@ export function composeAppearanceLayers (appearance, equipmentSlots)
220 240 const layers = [{
221 241 sprite: appearance?.sprite ?? bodySpriteName(sex),
222 242 ...(appearance?.tint ? { tint: appearance.tint } : {}),
243 ...(appearance?.dualTint ? { dualTint: appearance.dualTint } : {}),
223 244 ...(appearance?.bloomBody ? { bloomBody: true } : {})
224 245 }];
225 246 const slots = equipmentSlots ?? {};
@@ -66,6 +66,26 @@ export function hairFromNameSeed (displayName, sex)
66 return { style, color, sex: resolvedSex };
66 return { style, color, sex: resolvedSex };
67}
67}
68
68
69/** Random NPC hair palette colour (fairies, etc.). */
70export function randomNpcHairColor (rng = Math.random)
71{
72 const index = Math.floor(rng() * NPC_HAIR_COLORS.length) % NPC_HAIR_COLORS.length;
73 return normalizeRgb(NPC_HAIR_COLORS[index]);
74}
75
76/**
77 * Bright or pastel clothing colour for dual-channel fairy kits.
78 * @returns {{ r: number, g: number, b: number }}
79 */
80export function randomBrightOrPastelColor (rng = Math.random)
81{
82 const hue = rng() * 360;
83 const pastel = rng() < 0.5;
84 if (pastel)
85 { return hslToRgb(hue, 0.42 + rng() * 0.38, 0.70 + rng() * 0.2); }
86 return hslToRgb(hue, 0.72 + rng() * 0.28, 0.42 + rng() * 0.28);
87}
88
69export function bodySpriteName (sex)
89export function bodySpriteName (sex)
70{
90{
71 const key = sex === "female" ? "player-body-female" : "player-body-male";
91 const key = sex === "female" ? "player-body-female" : "player-body-male";
@@ -220,6 +240,7 @@ export function composeAppearanceLayers (appearance, equipmentSlots)
220 const layers = [{
240 const layers = [{
221 sprite: appearance?.sprite ?? bodySpriteName(sex),
241 sprite: appearance?.sprite ?? bodySpriteName(sex),
222 ...(appearance?.tint ? { tint: appearance.tint } : {}),
242 ...(appearance?.tint ? { tint: appearance.tint } : {}),
243 ...(appearance?.dualTint ? { dualTint: appearance.dualTint } : {}),
223 ...(appearance?.bloomBody ? { bloomBody: true } : {})
244 ...(appearance?.bloomBody ? { bloomBody: true } : {})
224 }];
245 }];
225 const slots = equipmentSlots ?? {};
246 const slots = equipmentSlots ?? {};
shared/definitions/mobs.js +6 −3
@@ -307,16 +307,19 @@ export const MOB_DEFINITIONS = Object.freeze({
307 307 untargetable: false,
308 308 aggressive: true,
309 309 aggroRangeTiles: 5,
310 /** Dimmer than elemental sprites (radius 2). */
310 311 lightRadiusTiles: 1,
311 312 bloomBody: true,
312 /** Temp art until dedicated fairy sprites exist. */
313 spriteKey: "sprite",
313 /** Shirt/skirt/hair use dual-channel body tints rolled on spawn. */
314 dualChannelAppearance: true,
315 /** Melee hits roll a fresh magic element each swing. */
316 randomElementMelee: true,
314 317 gait: "walk",
315 318 sex: "female",
316 319 frames: 2,
317 320 framesPerRow: 2,
318 321 animationSpeed: 0.45,
319 defaultState: "sprite"
322 defaultState: "fairy"
320 323 }),
321 324 [MobId.humanoid]: Object.freeze({
322 325 mobTypeId: MobId.humanoid,
@@ -307,16 +307,19 @@ export const MOB_DEFINITIONS = Object.freeze({
307 untargetable: false,
307 untargetable: false,
308 aggressive: true,
308 aggressive: true,
309 aggroRangeTiles: 5,
309 aggroRangeTiles: 5,
310 /** Dimmer than elemental sprites (radius 2). */
310 lightRadiusTiles: 1,
311 lightRadiusTiles: 1,
311 bloomBody: true,
312 bloomBody: true,
312 /** Temp art until dedicated fairy sprites exist. */
313 /** Shirt/skirt/hair use dual-channel body tints rolled on spawn. */
313 spriteKey: "sprite",
314 dualChannelAppearance: true,
315 /** Melee hits roll a fresh magic element each swing. */
316 randomElementMelee: true,
314 gait: "walk",
317 gait: "walk",
315 sex: "female",
318 sex: "female",
316 frames: 2,
319 frames: 2,
317 framesPerRow: 2,
320 framesPerRow: 2,
318 animationSpeed: 0.45,
321 animationSpeed: 0.45,
319 defaultState: "sprite"
322 defaultState: "fairy"
320 }),
323 }),
321 [MobId.humanoid]: Object.freeze({
324 [MobId.humanoid]: Object.freeze({
322 mobTypeId: MobId.humanoid,
325 mobTypeId: MobId.humanoid,
shared/render/tint.js +16 −25
@@ -12,20 +12,22 @@ import { magicElementTint } from "../definitions/attackTypes.js";
12 12 * - Otherwise leave RGB as-is. World shaders apply darkness after this pass.
13 13 *
14 14 * Dual / triple channel ({@link applyDualChannelTintToImageData}):
15 * - Dominant red (R > G,B): shaft / wood / metal blade; lightness = R.
16 * - Dominant blue (B > R,G): tip / leather / string; lightness = B.
17 * - Dominant green (G > R,B): coating (tipped arrows); lightness = G.
18 * - When one channel is highest and the other two are equal and non-zero,
19 * that is a lighter tint of the assigned colour (blend toward white) —
20 * not a mix of multiple assigned colours.
15 * - Dominant red (R > G,B) with G ≈ B: shaft; lightness = R.
16 * - Dominant blue (B > R,G) with R ≈ G: tip; lightness = B.
17 * - Dominant green (G > R,B) with R ≈ B: coat; lightness = G.
18 * - Equal non-zero secondaries lighten the assigned tint toward white.
19 * - If the primary wins but the other two channels differ, leave the pixel as-is.
21 20 * - Neutral / white (fletching): neither channel dominates — RGB unchanged.
22 21 */
23 22
24 23 const SECONDARY_EQUAL_TOL = 0.04;
25 24
26 /** Mask strength when a paint channel dominates (matches world dual-tint shader). */
25 /** Mask strength when a paint channel dominates with equal secondaries (matches world dual-tint shader). */
27 26 export function channelDominanceMask (r, g, b, channel)
28 27 {
28 const [o1, o2] = channelSecondaries(r, g, b, channel);
29 if (Math.abs(o1 - o2) > SECONDARY_EQUAL_TOL)
30 { return 0; }
29 31 if (channel === "shaft")
30 32 { return clamp01((r - Math.max(g, b)) * 1.75); }
31 33 if (channel === "coat")
@@ -52,9 +54,8 @@ function channelSecondaries (r, g, b, channel)
52 54 }
53 55
54 56 /**
55 * Tint pixels where `channel` dominates, preserving channel lightness.
56 * Equal non-dominant channels → blend assigned tint toward white.
57 * Unequal → keep legacy soft desat via the lesser secondary (compat with dual art).
57 * Tint pixels where `channel` dominates with equal secondaries, preserving lightness.
58 * Equal non-zero secondaries → blend assigned tint toward white.
58 59 */
59 60 export function channelTintedRgb (r, g, b, channel, tintRgb)
60 61 {
@@ -62,23 +63,13 @@ export function channelTintedRgb (r, g, b, channel, tintRgb)
62 63 if (mask <= 0)
63 64 { return null; }
64 65 const L = channelLightness(r, g, b, channel);
65 const [o1, o2] = channelSecondaries(r, g, b, channel);
66 const equalSeconds = Math.abs(o1 - o2) <= SECONDARY_EQUAL_TOL;
67 const whiteBlend = L > 0 && equalSeconds
68 ? Math.min(1, Math.max(0, o1 / L))
69 : (L > 0 ? Math.min(1, Math.max(0, Math.min(o1, o2) / L)) : 0);
66 const [o1] = channelSecondaries(r, g, b, channel);
67 const whiteBlend = L > 0 ? Math.min(1, Math.max(0, o1 / L)) : 0;
70 68 const tint = normalizeRgb(tintRgb);
71 const toward = equalSeconds
72 ? { r: 1, g: 1, b: 1 }
73 : (() =>
74 {
75 const tintLuma = luminance(tint.r, tint.g, tint.b);
76 return { r: tintLuma, g: tintLuma, b: tintLuma };
77 })();
78 69 return {
79 r: clamp01(mix(tint.r, toward.r, whiteBlend) * L),
80 g: clamp01(mix(tint.g, toward.g, whiteBlend) * L),
81 b: clamp01(mix(tint.b, toward.b, whiteBlend) * L),
70 r: clamp01(mix(tint.r, 1, whiteBlend) * L),
71 g: clamp01(mix(tint.g, 1, whiteBlend) * L),
72 b: clamp01(mix(tint.b, 1, whiteBlend) * L),
82 73 mask
83 74 };
84 75 }
@@ -12,20 +12,22 @@ import { magicElementTint } from "../definitions/attackTypes.js";
12 * - Otherwise leave RGB as-is. World shaders apply darkness after this pass.
12 * - Otherwise leave RGB as-is. World shaders apply darkness after this pass.
13 *
13 *
14 * Dual / triple channel ({@link applyDualChannelTintToImageData}):
14 * Dual / triple channel ({@link applyDualChannelTintToImageData}):
15 * - Dominant red (R > G,B): shaft / wood / metal blade; lightness = R.
15 * - Dominant red (R > G,B) with G ≈ B: shaft; lightness = R.
16 * - Dominant blue (B > R,G): tip / leather / string; lightness = B.
16 * - Dominant blue (B > R,G) with R ≈ G: tip; lightness = B.
17 * - Dominant green (G > R,B): coating (tipped arrows); lightness = G.
17 * - Dominant green (G > R,B) with R ≈ B: coat; lightness = G.
18 * - When one channel is highest and the other two are equal and non-zero,
18 * - Equal non-zero secondaries lighten the assigned tint toward white.
19 * that is a lighter tint of the assigned colour (blend toward white) —
19 * - If the primary wins but the other two channels differ, leave the pixel as-is.
20 * not a mix of multiple assigned colours.
21 * - Neutral / white (fletching): neither channel dominates — RGB unchanged.
20 * - Neutral / white (fletching): neither channel dominates — RGB unchanged.
22 */
21 */
23
22
24const SECONDARY_EQUAL_TOL = 0.04;
23const SECONDARY_EQUAL_TOL = 0.04;
25
24
26/** Mask strength when a paint channel dominates (matches world dual-tint shader). */
25/** Mask strength when a paint channel dominates with equal secondaries (matches world dual-tint shader). */
27export function channelDominanceMask (r, g, b, channel)
26export function channelDominanceMask (r, g, b, channel)
28{
27{
28 const [o1, o2] = channelSecondaries(r, g, b, channel);
29 if (Math.abs(o1 - o2) > SECONDARY_EQUAL_TOL)
30 { return 0; }
29 if (channel === "shaft")
31 if (channel === "shaft")
30 { return clamp01((r - Math.max(g, b)) * 1.75); }
32 { return clamp01((r - Math.max(g, b)) * 1.75); }
31 if (channel === "coat")
33 if (channel === "coat")
@@ -52,9 +54,8 @@ function channelSecondaries (r, g, b, channel)
52}
54}
53
55
54/**
56/**
55 * Tint pixels where `channel` dominates, preserving channel lightness.
57 * Tint pixels where `channel` dominates with equal secondaries, preserving lightness.
56 * Equal non-dominant channels → blend assigned tint toward white.
58 * Equal non-zero secondaries → blend assigned tint toward white.
57 * Unequal → keep legacy soft desat via the lesser secondary (compat with dual art).
58 */
59 */
59export function channelTintedRgb (r, g, b, channel, tintRgb)
60export function channelTintedRgb (r, g, b, channel, tintRgb)
60{
61{
@@ -62,23 +63,13 @@ export function channelTintedRgb (r, g, b, channel, tintRgb)
62 if (mask <= 0)
63 if (mask <= 0)
63 { return null; }
64 { return null; }
64 const L = channelLightness(r, g, b, channel);
65 const L = channelLightness(r, g, b, channel);
65 const [o1, o2] = channelSecondaries(r, g, b, channel);
66 const [o1] = channelSecondaries(r, g, b, channel);
66 const equalSeconds = Math.abs(o1 - o2) <= SECONDARY_EQUAL_TOL;
67 const whiteBlend = L > 0 ? Math.min(1, Math.max(0, o1 / L)) : 0;
67 const whiteBlend = L > 0 && equalSeconds
68 ? Math.min(1, Math.max(0, o1 / L))
69 : (L > 0 ? Math.min(1, Math.max(0, Math.min(o1, o2) / L)) : 0);
70 const tint = normalizeRgb(tintRgb);
68 const tint = normalizeRgb(tintRgb);
71 const toward = equalSeconds
72 ? { r: 1, g: 1, b: 1 }
73 : (() =>
74 {
75 const tintLuma = luminance(tint.r, tint.g, tint.b);
76 return { r: tintLuma, g: tintLuma, b: tintLuma };
77 })();
78 return {
69 return {
79 r: clamp01(mix(tint.r, toward.r, whiteBlend) * L),
70 r: clamp01(mix(tint.r, 1, whiteBlend) * L),
80 g: clamp01(mix(tint.g, toward.g, whiteBlend) * L),
71 g: clamp01(mix(tint.g, 1, whiteBlend) * L),
81 b: clamp01(mix(tint.b, toward.b, whiteBlend) * L),
72 b: clamp01(mix(tint.b, 1, whiteBlend) * L),
82 mask
73 mask
83 };
74 };
84}
75}