| 1 | /** Skull marker: bounty + decaying kill counter. Magenta-tint color curve. */ |
| 2 | |
| 3 | export const SKULL_KILL_BONUS = 500; |
| 4 | export const SKULL_DECAY_PER_SECOND = 1; |
| 5 | /** |
| 6 | * Tint stays white at this value; above it, color lerps toward red. |
| 7 | * Town guards treat players above this as hostiles (same as aggressive mobs). |
| 8 | */ |
| 9 | export const SKULL_RED_LERP_START = 1; |
| 10 | /** Skull value at which tint is pure red. */ |
| 11 | export const SKULL_PURE_RED_VALUE = 500_000; |
| 12 | /** |
| 13 | * Past pure red, tint reaches dark red (128,0,0) at this value and clamps. |
| 14 | * Same span as white→red (500k). |
| 15 | */ |
| 16 | export const SKULL_DARK_RED_VALUE = 1_000_000; |
| 17 | |
| 18 | /** |
| 19 | * @param {number} bountyCopper |
| 20 | * @param {number} killCounter |
| 21 | */ |
| 22 | export function skullValue (bountyCopper, killCounter) |
| 23 | { |
| 24 | return Math.max(0, Math.floor(Number(bountyCopper) || 0) + Math.floor(Number(killCounter) || 0)); |
| 25 | } |
| 26 | |
| 27 | /** True once the skull tint starts lerping from white toward red. */ |
| 28 | export function skullAttractsTownGuards (value) |
| 29 | { |
| 30 | return Math.max(0, Math.floor(Number(value) || 0)) > SKULL_RED_LERP_START; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Decay kill counter by elapsed wall time (1 point / second). |
| 35 | * @returns {{ killCounter: number, consumedMs: number }} |
| 36 | */ |
| 37 | export function decayKillCounter (killCounter, elapsedMs) |
| 38 | { |
| 39 | const current = Math.max(0, Number(killCounter) || 0); |
| 40 | if (current <= 0 || !(elapsedMs > 0)) |
| 41 | { return { killCounter: current, consumedMs: 0 }; } |
| 42 | const decay = Math.min(current, Math.floor(elapsedMs / 1000) * SKULL_DECAY_PER_SECOND); |
| 43 | return { |
| 44 | killCounter: current - decay, |
| 45 | consumedMs: decay * 1000 |
| 46 | }; |
| 47 | } |
| 48 | |
| 49 | function lerp (a, b, t) |
| 50 | { |
| 51 | return a + (b - a) * t; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Magenta-tint target color for a skull value (0 = invisible / unused). |
| 56 | * 1 → white; … → pure red at 500_000; then → dark red (128,0,0) by 1_000_000. |
| 57 | * @returns {{ r: number, g: number, b: number } | null} 0–1 channels, or null if invisible |
| 58 | */ |
| 59 | export function skullTintColor (value) |
| 60 | { |
| 61 | const v = Math.max(0, Math.floor(Number(value) || 0)); |
| 62 | if (v <= 0) |
| 63 | { return null; } |
| 64 | if (v <= SKULL_RED_LERP_START) |
| 65 | { return Object.freeze({ r: 1, g: 1, b: 1 }); } |
| 66 | if (v <= SKULL_PURE_RED_VALUE) |
| 67 | { |
| 68 | const t = (v - SKULL_RED_LERP_START) / (SKULL_PURE_RED_VALUE - SKULL_RED_LERP_START); |
| 69 | return Object.freeze({ |
| 70 | r: 1, |
| 71 | g: lerp(1, 0, t), |
| 72 | b: lerp(1, 0, t) |
| 73 | }); |
| 74 | } |
| 75 | const t = Math.min(1, (v - SKULL_PURE_RED_VALUE) / (SKULL_DARK_RED_VALUE - SKULL_PURE_RED_VALUE)); |
| 76 | const dark = 128 / 255; |
| 77 | return Object.freeze({ |
| 78 | r: lerp(1, dark, t), |
| 79 | g: 0, |
| 80 | b: 0 |
| 81 | }); |
| 82 | } |