BlueGit

timfa questward

Files

questward / shared / combat / darkness.js

darkness.js

darkness.js 922 B Download Raw
1/**
2 * Combat modifiers from target tile lighting (0 = dark, 1 = fully lit).
3 * Penalty scales quadratically: 0% lit → 50% to-hit penalty, 50% lit → 12.5%.
4 */
5
6/** Fraction subtracted from effective hit skill (0–0.5). */
7export function toHitDarknessPenalty (light01)
8{
9 const lit = Math.min(1, Math.max(0, Number(light01) || 0));
10 return 0.5 * (1 - lit) ** 2;
11}
12
13/** Effective hit skill after darkness penalty on the target tile. */
14export function effectiveHitSkillInDarkness (hitSkillLevel, light01)
15{
16 const penalty = toHitDarknessPenalty(light01);
17 return Math.max(1, Math.floor((hitSkillLevel | 0) * (1 - penalty)));
18}
19
20/**
21 * Multiplier applied to Chebyshev aggro distance (1 = normal, 2 = target in full dark).
22 * Linear: 0 lit → 2×, 0.5 lit → 1.5×, 1 lit → 1×.
23 */
24export function aggroDistanceMultiplier (light01)
25{
26 const lit = Math.min(1, Math.max(0, Number(light01) || 0));
27 return 2 - lit;
28}