BlueGit

timfa questward

Rebuild lightmaps for Dark spell and apply it to combat accuracy.

Lightmap cache keys ignored spell darkness, so ground stayed lit after Dark appear/remove; combat tile light now subtracts spell dark (and adds spell light) the same way night darkness penalizes hit/aggro.

timfa Tim Falken · pushed by timfa

Authored 2026-08-31 · 2 months ago

Hash
17bf8615b0dc61ff9156b997df719da1b7b98aec
Parent
c8fde696
4 files changed +115 −11
client/src/render/worldView.js +44 −6
@@ -1661,11 +1661,19 @@ export class WorldView
1661 1661 range: payload.rangeTiles ?? 6,
1662 1662 intensity: payload.intensity ?? 0.88
1663 1663 });
1664 this.#invalidateNeighborLightmapCaches(
1665 Math.floor(payload.tileX / CHUNK_SIZE),
1666 Math.floor(payload.tileY / CHUNK_SIZE)
1667 );
1664 1668 }
1665 1669
1666 1670 removeSpellLight (payload)
1667 1671 {
1668 1672 this.spellLights.delete(`${payload.tileX},${payload.tileY}`);
1673 this.#invalidateNeighborLightmapCaches(
1674 Math.floor(payload.tileX / CHUNK_SIZE),
1675 Math.floor(payload.tileY / CHUNK_SIZE)
1676 );
1669 1677 }
1670 1678
1671 1679 setSpellDark (payload)
@@ -1678,11 +1686,19 @@ export class WorldView
1678 1686 range: payload.rangeTiles ?? 6,
1679 1687 intensity: payload.intensity ?? 0.88
1680 1688 });
1689 this.#invalidateNeighborLightmapCaches(
1690 Math.floor(payload.tileX / CHUNK_SIZE),
1691 Math.floor(payload.tileY / CHUNK_SIZE)
1692 );
1681 1693 }
1682 1694
1683 1695 removeSpellDark (payload)
1684 1696 {
1685 1697 this.spellDarks.delete(`${payload.tileX},${payload.tileY}`);
1698 this.#invalidateNeighborLightmapCaches(
1699 Math.floor(payload.tileX / CHUNK_SIZE),
1700 Math.floor(payload.tileY / CHUNK_SIZE)
1701 );
1686 1702 }
1687 1703
1688 1704 #spellProjectileImage (baseSprite, frameIndex)
@@ -3729,7 +3745,14 @@ export class WorldView
3729 3745 for (const key of [...this.spellLights.keys()])
3730 3746 {
3731 3747 if (this.spellLights.get(key).until <= now)
3732 { this.spellLights.delete(key); }
3748 {
3749 const expired = this.spellLights.get(key);
3750 this.spellLights.delete(key);
3751 this.#invalidateNeighborLightmapCaches(
3752 Math.floor(expired.tileX / CHUNK_SIZE),
3753 Math.floor(expired.tileY / CHUNK_SIZE)
3754 );
3755 }
3733 3756 }
3734 3757 const activeDarks = [];
3735 3758 for (const dark of this.spellDarks.values())
@@ -3746,7 +3769,14 @@ export class WorldView
3746 3769 for (const key of [...this.spellDarks.keys()])
3747 3770 {
3748 3771 if (this.spellDarks.get(key).until <= now)
3749 { this.spellDarks.delete(key); }
3772 {
3773 const expired = this.spellDarks.get(key);
3774 this.spellDarks.delete(key);
3775 this.#invalidateNeighborLightmapCaches(
3776 Math.floor(expired.tileX / CHUNK_SIZE),
3777 Math.floor(expired.tileY / CHUNK_SIZE)
3778 );
3779 }
3750 3780 }
3751 3781 this._activeSpellDarks = activeDarks;
3752 3782 const tileSize = this.tileSize();
@@ -3990,17 +4020,25 @@ export class WorldView
3990 4020 { return null; }
3991 4021 const bakedHash = this.#hashUint8Array(snapshot.light);
3992 4022 const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, activeLights);
3993 if (!lights.length)
3994 { return `i:${bakedHash}`; }
4023 const darks = this._activeSpellDarks ?? [];
3995 4024 const mode = this.lightingMode === "simple" ? "s" : "f";
3996 4025 let lightsKey = "";
3997 4026 for (const light of lights)
3998 4027 {
3999 4028 if (!this.#lightAffectsChunkBounds(light, baked.chunkX, baked.chunkY))
4000 4029 { continue; }
4001 lightsKey += `${light.tileX},${light.tileY},${light.range},${light.intensity ?? 1};`;
4030 lightsKey += `l${light.tileX},${light.tileY},${light.range},${light.intensity ?? 1};`;
4002 4031 }
4003 return `a:${mode}:${bakedHash}:${lightsKey}`;
4032 let darksKey = "";
4033 for (const dark of darks)
4034 {
4035 if (!this.#lightAffectsChunkBounds(dark, baked.chunkX, baked.chunkY))
4036 { continue; }
4037 darksKey += `d${dark.tileX},${dark.tileY},${dark.range},${dark.intensity ?? 1};`;
4038 }
4039 if (!lightsKey && !darksKey)
4040 { return `i:${bakedHash}`; }
4041 return `a:${mode}:${bakedHash}:${lightsKey}|${darksKey}`;
4004 4042 }
4005 4043
4006 4044 #invalidateNeighborLightmapCaches (chunkX, chunkY)
@@ -1661,11 +1661,19 @@ export class WorldView
1661 range: payload.rangeTiles ?? 6,
1661 range: payload.rangeTiles ?? 6,
1662 intensity: payload.intensity ?? 0.88
1662 intensity: payload.intensity ?? 0.88
1663 });
1663 });
1664 this.#invalidateNeighborLightmapCaches(
1665 Math.floor(payload.tileX / CHUNK_SIZE),
1666 Math.floor(payload.tileY / CHUNK_SIZE)
1667 );
1664 }
1668 }
1665
1669
1666 removeSpellLight (payload)
1670 removeSpellLight (payload)
1667 {
1671 {
1668 this.spellLights.delete(`${payload.tileX},${payload.tileY}`);
1672 this.spellLights.delete(`${payload.tileX},${payload.tileY}`);
1673 this.#invalidateNeighborLightmapCaches(
1674 Math.floor(payload.tileX / CHUNK_SIZE),
1675 Math.floor(payload.tileY / CHUNK_SIZE)
1676 );
1669 }
1677 }
1670
1678
1671 setSpellDark (payload)
1679 setSpellDark (payload)
@@ -1678,11 +1686,19 @@ export class WorldView
1678 range: payload.rangeTiles ?? 6,
1686 range: payload.rangeTiles ?? 6,
1679 intensity: payload.intensity ?? 0.88
1687 intensity: payload.intensity ?? 0.88
1680 });
1688 });
1689 this.#invalidateNeighborLightmapCaches(
1690 Math.floor(payload.tileX / CHUNK_SIZE),
1691 Math.floor(payload.tileY / CHUNK_SIZE)
1692 );
1681 }
1693 }
1682
1694
1683 removeSpellDark (payload)
1695 removeSpellDark (payload)
1684 {
1696 {
1685 this.spellDarks.delete(`${payload.tileX},${payload.tileY}`);
1697 this.spellDarks.delete(`${payload.tileX},${payload.tileY}`);
1698 this.#invalidateNeighborLightmapCaches(
1699 Math.floor(payload.tileX / CHUNK_SIZE),
1700 Math.floor(payload.tileY / CHUNK_SIZE)
1701 );
1686 }
1702 }
1687
1703
1688 #spellProjectileImage (baseSprite, frameIndex)
1704 #spellProjectileImage (baseSprite, frameIndex)
@@ -3729,7 +3745,14 @@ export class WorldView
3729 for (const key of [...this.spellLights.keys()])
3745 for (const key of [...this.spellLights.keys()])
3730 {
3746 {
3731 if (this.spellLights.get(key).until <= now)
3747 if (this.spellLights.get(key).until <= now)
3732 { this.spellLights.delete(key); }
3748 {
3749 const expired = this.spellLights.get(key);
3750 this.spellLights.delete(key);
3751 this.#invalidateNeighborLightmapCaches(
3752 Math.floor(expired.tileX / CHUNK_SIZE),
3753 Math.floor(expired.tileY / CHUNK_SIZE)
3754 );
3755 }
3733 }
3756 }
3734 const activeDarks = [];
3757 const activeDarks = [];
3735 for (const dark of this.spellDarks.values())
3758 for (const dark of this.spellDarks.values())
@@ -3746,7 +3769,14 @@ export class WorldView
3746 for (const key of [...this.spellDarks.keys()])
3769 for (const key of [...this.spellDarks.keys()])
3747 {
3770 {
3748 if (this.spellDarks.get(key).until <= now)
3771 if (this.spellDarks.get(key).until <= now)
3749 { this.spellDarks.delete(key); }
3772 {
3773 const expired = this.spellDarks.get(key);
3774 this.spellDarks.delete(key);
3775 this.#invalidateNeighborLightmapCaches(
3776 Math.floor(expired.tileX / CHUNK_SIZE),
3777 Math.floor(expired.tileY / CHUNK_SIZE)
3778 );
3779 }
3750 }
3780 }
3751 this._activeSpellDarks = activeDarks;
3781 this._activeSpellDarks = activeDarks;
3752 const tileSize = this.tileSize();
3782 const tileSize = this.tileSize();
@@ -3990,17 +4020,25 @@ export class WorldView
3990 { return null; }
4020 { return null; }
3991 const bakedHash = this.#hashUint8Array(snapshot.light);
4021 const bakedHash = this.#hashUint8Array(snapshot.light);
3992 const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, activeLights);
4022 const lights = this.#dynamicLightsForChunk(baked.chunkX, baked.chunkY, activeLights);
3993 if (!lights.length)
4023 const darks = this._activeSpellDarks ?? [];
3994 { return `i:${bakedHash}`; }
3995 const mode = this.lightingMode === "simple" ? "s" : "f";
4024 const mode = this.lightingMode === "simple" ? "s" : "f";
3996 let lightsKey = "";
4025 let lightsKey = "";
3997 for (const light of lights)
4026 for (const light of lights)
3998 {
4027 {
3999 if (!this.#lightAffectsChunkBounds(light, baked.chunkX, baked.chunkY))
4028 if (!this.#lightAffectsChunkBounds(light, baked.chunkX, baked.chunkY))
4000 { continue; }
4029 { continue; }
4001 lightsKey += `${light.tileX},${light.tileY},${light.range},${light.intensity ?? 1};`;
4030 lightsKey += `l${light.tileX},${light.tileY},${light.range},${light.intensity ?? 1};`;
4002 }
4031 }
4003 return `a:${mode}:${bakedHash}:${lightsKey}`;
4032 let darksKey = "";
4033 for (const dark of darks)
4034 {
4035 if (!this.#lightAffectsChunkBounds(dark, baked.chunkX, baked.chunkY))
4036 { continue; }
4037 darksKey += `d${dark.tileX},${dark.tileY},${dark.range},${dark.intensity ?? 1};`;
4038 }
4039 if (!lightsKey && !darksKey)
4040 { return `i:${bakedHash}`; }
4041 return `a:${mode}:${bakedHash}:${lightsKey}|${darksKey}`;
4004 }
4042 }
4005
4043
4006 #invalidateNeighborLightmapCaches (chunkX, chunkY)
4044 #invalidateNeighborLightmapCaches (chunkX, chunkY)
server/src/combat/service.js +25 −3
@@ -27,6 +27,10 @@ import
27 27 tileCombatLight01,
28 28 tileIndexLocal
29 29 } from "../../../shared/lighting/combatLight.js";
30 import { dynamicDarknessAtTile, dynamicLightAtTile, rayReaches } from "../../../shared/lighting/raycast.js";
31 import { LightOcclusion } from "../../../shared/definitions/tiles.js";
32 import { tileLightOcclusionAt } from "../../../shared/lighting/chunkOcclusion.js";
33 import { spellLightsForDynamicLighting } from "../spells/lights.js";
30 34 import { skillLevel, SkillId, UNARMED_ATTACK } from "../../../shared/definitions/skills.js";
31 35 import
32 36 {
@@ -38,8 +42,7 @@ import { COMBAT_RANGE_TILES, RANGED_PROJECTILE_MS, SPELL_COOLDOWN_MS } from "../
38 42 import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
39 43 import { chunkBoundsAround, findPath } from "../navigation/astar.js";
40 44 import { findPathToNearestGoal } from "../../../shared/navigation/bfs.js";
41 import { VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";
42 import { rayReaches } from "../../../shared/lighting/raycast.js";
45 import { CHUNK_SIZE, VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";
43 46 import { tileToChunk } from "../world/coordinates.js";
44 47 import { stackQuantity } from "../../../shared/items/inventory.js";
45 48 import { addGroundItem, publicGroundItem } from "../items/bags.js";
@@ -225,17 +228,36 @@ export function hasCombatLineOfSight (world, fromX, fromY, toX, toY)
225 228 return rayReaches(fromX, fromY, toX, toY, isClear);
226 229 }
227 230
228 /** Target-tile lighting 0–1 (baked + entity lights + time of day). */
231 function lightOcclusionAtWorld (world, x, y)
232 {
233 const data = world.chunkData?.(tileToChunk(x), tileToChunk(y));
234 if (!data)
235 { return LightOcclusion.clear; }
236 const index = tileIndexLocal(x, y);
237 if (Array.isArray(data.occlusion) && data.occlusion.length > index)
238 { return data.occlusion[index] | 0; }
239 const localX = ((x % CHUNK_SIZE) + CHUNK_SIZE) % CHUNK_SIZE;
240 const localY = ((y % CHUNK_SIZE) + CHUNK_SIZE) % CHUNK_SIZE;
241 return tileLightOcclusionAt(data.grounds, data.blocks, localX, localY);
242 }
243
244 /** Target-tile lighting 0–1 (baked + entity/spell lights − spell dark + time of day). */
229 245 export function tileLightAt (world, tileX, tileY, now = Date.now())
230 246 {
231 247 const data = world.chunkData?.(tileToChunk(tileX), tileToChunk(tileY));
232 248 const index = tileIndexLocal(tileX, tileY);
233 249 const baked = bakedTileLight01(data?.light, index);
234 250 const entity = entityLightAtTile(world.ecs, Component, tileX, tileY, now);
251 const { lights, darks } = spellLightsForDynamicLighting(world.spellLights, now);
252 const occlusionAt = (x, y) => lightOcclusionAtWorld(world, x, y);
253 const spellLight = dynamicLightAtTile(tileX, tileY, lights, occlusionAt);
254 const spellDark = dynamicDarknessAtTile(tileX, tileY, darks, occlusionAt);
235 255 const worldTime = world.worldTime?.(now);
236 256 return tileCombatLight01({
237 257 bakedLight01: baked,
238 258 entityLight01: entity,
259 spellLight01: spellLight,
260 spellDark01: spellDark,
239 261 worldHour: worldTime?.hour ?? 12,
240 262 nightDarkness: world.settings?.nightDarkness ?? 0.72
241 263 });
@@ -27,6 +27,10 @@ import
27 tileCombatLight01,
27 tileCombatLight01,
28 tileIndexLocal
28 tileIndexLocal
29 } from "../../../shared/lighting/combatLight.js";
29 } from "../../../shared/lighting/combatLight.js";
30import { dynamicDarknessAtTile, dynamicLightAtTile, rayReaches } from "../../../shared/lighting/raycast.js";
31import { LightOcclusion } from "../../../shared/definitions/tiles.js";
32import { tileLightOcclusionAt } from "../../../shared/lighting/chunkOcclusion.js";
33import { spellLightsForDynamicLighting } from "../spells/lights.js";
30import { skillLevel, SkillId, UNARMED_ATTACK } from "../../../shared/definitions/skills.js";
34import { skillLevel, SkillId, UNARMED_ATTACK } from "../../../shared/definitions/skills.js";
31import
35import
32 {
36 {
@@ -38,8 +42,7 @@ import { COMBAT_RANGE_TILES, RANGED_PROJECTILE_MS, SPELL_COOLDOWN_MS } from "../
38import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
42import { awardCombatHitXp, awardCombatAvoidanceXp, awardDamageHealthXp, syncPlayerHealth } from "../skills/service.js";
39import { chunkBoundsAround, findPath } from "../navigation/astar.js";
43import { chunkBoundsAround, findPath } from "../navigation/astar.js";
40import { findPathToNearestGoal } from "../../../shared/navigation/bfs.js";
44import { findPathToNearestGoal } from "../../../shared/navigation/bfs.js";
41import { VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";
45import { CHUNK_SIZE, VISIBLE_CHUNK_RADIUS } from "../../../shared/protocol/constants.js";
42import { rayReaches } from "../../../shared/lighting/raycast.js";
43import { tileToChunk } from "../world/coordinates.js";
46import { tileToChunk } from "../world/coordinates.js";
44import { stackQuantity } from "../../../shared/items/inventory.js";
47import { stackQuantity } from "../../../shared/items/inventory.js";
45import { addGroundItem, publicGroundItem } from "../items/bags.js";
48import { addGroundItem, publicGroundItem } from "../items/bags.js";
@@ -225,17 +228,36 @@ export function hasCombatLineOfSight (world, fromX, fromY, toX, toY)
225 return rayReaches(fromX, fromY, toX, toY, isClear);
228 return rayReaches(fromX, fromY, toX, toY, isClear);
226}
229}
227
230
228/** Target-tile lighting 0–1 (baked + entity lights + time of day). */
231function lightOcclusionAtWorld (world, x, y)
232{
233 const data = world.chunkData?.(tileToChunk(x), tileToChunk(y));
234 if (!data)
235 { return LightOcclusion.clear; }
236 const index = tileIndexLocal(x, y);
237 if (Array.isArray(data.occlusion) && data.occlusion.length > index)
238 { return data.occlusion[index] | 0; }
239 const localX = ((x % CHUNK_SIZE) + CHUNK_SIZE) % CHUNK_SIZE;
240 const localY = ((y % CHUNK_SIZE) + CHUNK_SIZE) % CHUNK_SIZE;
241 return tileLightOcclusionAt(data.grounds, data.blocks, localX, localY);
242}
243
244/** Target-tile lighting 0–1 (baked + entity/spell lights − spell dark + time of day). */
229export function tileLightAt (world, tileX, tileY, now = Date.now())
245export function tileLightAt (world, tileX, tileY, now = Date.now())
230{
246{
231 const data = world.chunkData?.(tileToChunk(tileX), tileToChunk(tileY));
247 const data = world.chunkData?.(tileToChunk(tileX), tileToChunk(tileY));
232 const index = tileIndexLocal(tileX, tileY);
248 const index = tileIndexLocal(tileX, tileY);
233 const baked = bakedTileLight01(data?.light, index);
249 const baked = bakedTileLight01(data?.light, index);
234 const entity = entityLightAtTile(world.ecs, Component, tileX, tileY, now);
250 const entity = entityLightAtTile(world.ecs, Component, tileX, tileY, now);
251 const { lights, darks } = spellLightsForDynamicLighting(world.spellLights, now);
252 const occlusionAt = (x, y) => lightOcclusionAtWorld(world, x, y);
253 const spellLight = dynamicLightAtTile(tileX, tileY, lights, occlusionAt);
254 const spellDark = dynamicDarknessAtTile(tileX, tileY, darks, occlusionAt);
235 const worldTime = world.worldTime?.(now);
255 const worldTime = world.worldTime?.(now);
236 return tileCombatLight01({
256 return tileCombatLight01({
237 bakedLight01: baked,
257 bakedLight01: baked,
238 entityLight01: entity,
258 entityLight01: entity,
259 spellLight01: spellLight,
260 spellDark01: spellDark,
239 worldHour: worldTime?.hour ?? 12,
261 worldHour: worldTime?.hour ?? 12,
240 nightDarkness: world.settings?.nightDarkness ?? 0.72
262 nightDarkness: world.settings?.nightDarkness ?? 0.72
241 });
263 });
server/tests/darkness.test.js +35 −0
@@ -5,6 +5,7 @@ import {
5 5 effectiveHitSkillInDarkness,
6 6 aggroDistanceMultiplier
7 7 } from "../../shared/combat/darkness.js";
8 import { tileCombatLight01 } from "../../shared/lighting/combatLight.js";
8 9
9 10 test("toHitDarknessPenalty scales quadratically with darkness", () =>
10 11 {
@@ -26,3 +27,37 @@ test("aggroDistanceMultiplier lengthens effective distance in dark", () =>
26 27 assert.equal(aggroDistanceMultiplier(0.5), 1.5);
27 28 assert.equal(aggroDistanceMultiplier(0), 2);
28 29 });
30
31 test("spell dark reduces combat light like missing local light at night", () =>
32 {
33 const nightLit = tileCombatLight01({
34 bakedLight01: 1,
35 worldHour: 0,
36 nightDarkness: 0.72
37 });
38 const nightDarkSpell = tileCombatLight01({
39 bakedLight01: 1,
40 spellDark01: 1,
41 worldHour: 0,
42 nightDarkness: 0.72
43 });
44 assert.equal(nightLit, 1);
45 assert.equal(nightDarkSpell, 1 - 0.72);
46 assert.ok(toHitDarknessPenalty(nightDarkSpell) > toHitDarknessPenalty(nightLit));
47 });
48
49 test("spell light restores combat light against spell dark at night", () =>
50 {
51 const withLight = tileCombatLight01({
52 spellLight01: 0.88,
53 spellDark01: 0.4,
54 worldHour: 0,
55 nightDarkness: 0.72
56 });
57 const darkOnly = tileCombatLight01({
58 spellDark01: 0.4,
59 worldHour: 0,
60 nightDarkness: 0.72
61 });
62 assert.ok(withLight > darkOnly);
63 });
@@ -5,6 +5,7 @@ import {
5 effectiveHitSkillInDarkness,
5 effectiveHitSkillInDarkness,
6 aggroDistanceMultiplier
6 aggroDistanceMultiplier
7} from "../../shared/combat/darkness.js";
7} from "../../shared/combat/darkness.js";
8import { tileCombatLight01 } from "../../shared/lighting/combatLight.js";
8
9
9test("toHitDarknessPenalty scales quadratically with darkness", () =>
10test("toHitDarknessPenalty scales quadratically with darkness", () =>
10{
11{
@@ -26,3 +27,37 @@ test("aggroDistanceMultiplier lengthens effective distance in dark", () =>
26 assert.equal(aggroDistanceMultiplier(0.5), 1.5);
27 assert.equal(aggroDistanceMultiplier(0.5), 1.5);
27 assert.equal(aggroDistanceMultiplier(0), 2);
28 assert.equal(aggroDistanceMultiplier(0), 2);
28});
29});
30
31test("spell dark reduces combat light like missing local light at night", () =>
32{
33 const nightLit = tileCombatLight01({
34 bakedLight01: 1,
35 worldHour: 0,
36 nightDarkness: 0.72
37 });
38 const nightDarkSpell = tileCombatLight01({
39 bakedLight01: 1,
40 spellDark01: 1,
41 worldHour: 0,
42 nightDarkness: 0.72
43 });
44 assert.equal(nightLit, 1);
45 assert.equal(nightDarkSpell, 1 - 0.72);
46 assert.ok(toHitDarknessPenalty(nightDarkSpell) > toHitDarknessPenalty(nightLit));
47});
48
49test("spell light restores combat light against spell dark at night", () =>
50{
51 const withLight = tileCombatLight01({
52 spellLight01: 0.88,
53 spellDark01: 0.4,
54 worldHour: 0,
55 nightDarkness: 0.72
56 });
57 const darkOnly = tileCombatLight01({
58 spellDark01: 0.4,
59 worldHour: 0,
60 nightDarkness: 0.72
61 });
62 assert.ok(withLight > darkOnly);
63});
shared/lighting/combatLight.js +11 −2
@@ -35,15 +35,24 @@ export function bakedTileLight01 (lightArray, index)
35 35 return lightIntensity(lightArray[index] ?? 0);
36 36 }
37 37
38 /** Combined target-tile lighting 0–1 for combat (static + entity lights + time of day). */
38 /**
39 * Combined target-tile lighting 0–1 for combat
40 * (static + entity/spell lights − spell darkness + time of day).
41 * Matches client shade: ambientDark × (1 − max(0, max(lights) − dark)).
42 */
39 43 export function tileCombatLight01 ({
40 44 bakedLight01 = 0,
41 45 entityLight01 = 0,
46 spellLight01 = 0,
47 spellDark01 = 0,
42 48 worldHour = 12,
43 49 nightDarkness = 0.72
44 50 } = {})
45 51 {
46 const localLit = Math.min(1, Math.max(bakedLight01, entityLight01));
52 const localLit = Math.max(
53 0,
54 Math.min(1, Math.max(bakedLight01, entityLight01, spellLight01) - (Number(spellDark01) || 0))
55 );
47 56 const ambientDark = nightFactor(worldHour, nightDarkness);
48 57 return 1 - ambientDark * (1 - localLit);
49 58 }
@@ -35,15 +35,24 @@ export function bakedTileLight01 (lightArray, index)
35 return lightIntensity(lightArray[index] ?? 0);
35 return lightIntensity(lightArray[index] ?? 0);
36}
36}
37
37
38/** Combined target-tile lighting 0–1 for combat (static + entity lights + time of day). */
38/**
39 * Combined target-tile lighting 0–1 for combat
40 * (static + entity/spell lights − spell darkness + time of day).
41 * Matches client shade: ambientDark × (1 − max(0, max(lights) − dark)).
42 */
39export function tileCombatLight01 ({
43export function tileCombatLight01 ({
40 bakedLight01 = 0,
44 bakedLight01 = 0,
41 entityLight01 = 0,
45 entityLight01 = 0,
46 spellLight01 = 0,
47 spellDark01 = 0,
42 worldHour = 12,
48 worldHour = 12,
43 nightDarkness = 0.72
49 nightDarkness = 0.72
44} = {})
50} = {})
45{
51{
46 const localLit = Math.min(1, Math.max(bakedLight01, entityLight01));
52 const localLit = Math.max(
53 0,
54 Math.min(1, Math.max(bakedLight01, entityLight01, spellLight01) - (Number(spellDark01) || 0))
55 );
47 const ambientDark = nightFactor(worldHour, nightDarkness);
56 const ambientDark = nightFactor(worldHour, nightDarkness);
48 return 1 - ambientDark * (1 - localLit);
57 return 1 - ambientDark * (1 - localLit);
49}
58}