fix light spell
@@ -1,13 +1,14 @@
1
1
import { Component } from "../ecs/components.js";
2
2
import { tileKey } from "../world/coordinates.js";
3
import {
4
LIGHT_FADE_MS,
5
LIGHT_MAX_DURATION_MS,
6
LIGHT_OWNER_DISTANCE_CAP_MS,
7
SPELL_LIGHT_INTENSITY,
8
SPELL_LIGHT_RANGE_TILES,
9
COMBAT_RANGE_TILES
10
} from "../../../shared/spells/constants.js";
3
import
4
{
5
LIGHT_FADE_MS,
6
LIGHT_MAX_DURATION_MS,
7
LIGHT_OWNER_DISTANCE_CAP_MS,
8
SPELL_LIGHT_INTENSITY,
9
SPELL_LIGHT_RANGE_TILES,
10
COMBAT_RANGE_TILES
11
} from "../../../shared/spells/constants.js";
11
12
12
13
/**
13
14
* Authoritative temporary spell lights keyed by tile.
@@ -23,7 +24,7 @@ import {
23
24
24
25
export class SpellLightRegistry
25
26
{
26
constructor ()
27
constructor()
27
28
{
28
29
/** @type {Map<string, SpellLight>} */
29
30
this.byTile = new Map();
@@ -41,11 +42,13 @@ export class SpellLightRegistry
41
42
tileY,
42
43
ownerEntityId,
43
44
durationMs,
45
baseRange = SPELL_LIGHT_RANGE_TILES,
44
46
now = Date.now()
45
47
})
46
48
{
47
49
const key = tileKey(tileX, tileY);
48
50
const addMs = Math.max(0, Math.min(LIGHT_MAX_DURATION_MS, durationMs | 0));
51
const range = Math.max(0, Number(baseRange) || SPELL_LIGHT_RANGE_TILES);
49
52
const existing = this.byTile.get(key);
50
53
if (existing)
51
54
{
@@ -54,6 +57,7 @@ export class SpellLightRegistry
54
57
existing.expiresAt = now + next;
55
58
existing.maxDurationMs = Math.max(existing.maxDurationMs, next);
56
59
existing.ownerEntityId = ownerEntityId;
60
existing.baseRange = Math.max(existing.baseRange ?? 0, range);
57
61
return { light: existing, extended: true };
58
62
}
59
63
const light = {
@@ -63,7 +67,7 @@ export class SpellLightRegistry
63
67
ownerEntityId,
64
68
expiresAt: now + addMs,
65
69
maxDurationMs: addMs,
66
baseRange: SPELL_LIGHT_RANGE_TILES,
70
baseRange: range,
67
71
baseIntensity: SPELL_LIGHT_INTENSITY
68
72
};
69
73
this.byTile.set(key, light);
@@ -103,7 +107,7 @@ export class SpellLightRegistry
103
107
if (dist > COMBAT_RANGE_TILES)
104
108
{
105
109
const remaining = light.expiresAt - now;
106
const capped = Math.min( remaining, LIGHT_OWNER_DISTANCE_CAP_MS);
110
const capped = Math.min(remaining, LIGHT_OWNER_DISTANCE_CAP_MS);
107
111
if (capped !== remaining)
108
112
{
109
113
light.expiresAt = now + capped;
@@ -1,13 +1,14 @@1
import { Component } from "../ecs/components.js";1
import { Component } from "../ecs/components.js";2
import { tileKey } from "../world/coordinates.js";2
import { tileKey } from "../world/coordinates.js";3
import {3
import4
LIGHT_FADE_MS,4
{5
LIGHT_MAX_DURATION_MS,5
LIGHT_FADE_MS,6
LIGHT_OWNER_DISTANCE_CAP_MS,6
LIGHT_MAX_DURATION_MS,7
SPELL_LIGHT_INTENSITY,7
LIGHT_OWNER_DISTANCE_CAP_MS,8
SPELL_LIGHT_RANGE_TILES,8
SPELL_LIGHT_INTENSITY,9
COMBAT_RANGE_TILES9
SPELL_LIGHT_RANGE_TILES,10
} from "../../../shared/spells/constants.js";10
COMBAT_RANGE_TILES11
} from "../../../shared/spells/constants.js";11
12
12
/**13
/**13
* Authoritative temporary spell lights keyed by tile.14
* Authoritative temporary spell lights keyed by tile.@@ -23,7 +24,7 @@ import {23
24
24
export class SpellLightRegistry25
export class SpellLightRegistry25
{26
{26
constructor ()27
constructor()27
{28
{28
/** @type {Map<string, SpellLight>} */29
/** @type {Map<string, SpellLight>} */29
this.byTile = new Map();30
this.byTile = new Map();@@ -41,11 +42,13 @@ export class SpellLightRegistry41
tileY,42
tileY,42
ownerEntityId,43
ownerEntityId,43
durationMs,44
durationMs,45
baseRange = SPELL_LIGHT_RANGE_TILES,44
now = Date.now()46
now = Date.now()45
})47
})46
{48
{47
const key = tileKey(tileX, tileY);49
const key = tileKey(tileX, tileY);48
const addMs = Math.max(0, Math.min(LIGHT_MAX_DURATION_MS, durationMs | 0));50
const addMs = Math.max(0, Math.min(LIGHT_MAX_DURATION_MS, durationMs | 0));51
const range = Math.max(0, Number(baseRange) || SPELL_LIGHT_RANGE_TILES);49
const existing = this.byTile.get(key);52
const existing = this.byTile.get(key);50
if (existing)53
if (existing)51
{54
{@@ -54,6 +57,7 @@ export class SpellLightRegistry54
existing.expiresAt = now + next;57
existing.expiresAt = now + next;55
existing.maxDurationMs = Math.max(existing.maxDurationMs, next);58
existing.maxDurationMs = Math.max(existing.maxDurationMs, next);56
existing.ownerEntityId = ownerEntityId;59
existing.ownerEntityId = ownerEntityId;60
existing.baseRange = Math.max(existing.baseRange ?? 0, range);57
return { light: existing, extended: true };61
return { light: existing, extended: true };58
}62
}59
const light = {63
const light = {@@ -63,7 +67,7 @@ export class SpellLightRegistry63
ownerEntityId,67
ownerEntityId,64
expiresAt: now + addMs,68
expiresAt: now + addMs,65
maxDurationMs: addMs,69
maxDurationMs: addMs,66
baseRange: SPELL_LIGHT_RANGE_TILES,70
baseRange: range,67
baseIntensity: SPELL_LIGHT_INTENSITY71
baseIntensity: SPELL_LIGHT_INTENSITY68
};72
};69
this.byTile.set(key, light);73
this.byTile.set(key, light);@@ -103,7 +107,7 @@ export class SpellLightRegistry103
if (dist > COMBAT_RANGE_TILES)107
if (dist > COMBAT_RANGE_TILES)104
{108
{105
const remaining = light.expiresAt - now;109
const remaining = light.expiresAt - now;106
const capped = Math.min( remaining, LIGHT_OWNER_DISTANCE_CAP_MS);110
const capped = Math.min(remaining, LIGHT_OWNER_DISTANCE_CAP_MS);107
if (capped !== remaining)111
if (capped !== remaining)108
{112
{109
light.expiresAt = now + capped;113
light.expiresAt = now + capped;@@ -1,7 +1,8 @@
1
1
import { Component } from "../ecs/components.js";
2
2
import { SkillId, skillLevel } from "../../../shared/definitions/skills.js";
3
3
import { SpellId, spellDefinition, spellDifficulty } from "../../../shared/definitions/spells.js";
4
import {
4
import
5
{
5
6
canCastSpell,
6
7
defaultPlayerSpells,
7
8
normalizePlayerSpells,
@@ -10,15 +11,18 @@ import {
10
11
toggleFavorite,
11
12
learnSpell
12
13
} from "../../../shared/spells/state.js";
13
import {
14
import
15
{
14
16
CAST_FLASH_MS,
15
17
COMBAT_RANGE_TILES,
16
18
LIGHT_DURATION_MS_PER_MIND,
17
19
SPELL_COOLDOWN_MS,
20
SPELL_LIGHT_RANGE_TILES,
18
21
SPELL_PROJECTILE_MS,
19
22
castFlashRadiusTiles
20
23
} from "../../../shared/spells/constants.js";
21
import {
24
import
25
{
22
26
mobElementAffinities,
23
27
ElementMultiplier,
24
28
resolveMagicAttack,
@@ -29,7 +33,8 @@ import { mobDefinition } from "../../../shared/definitions/mobs.js";
29
33
import { awardCombatHitXp, awardDamageHealthXp, awardSpellCastXp, syncPlayerHealth } from "../skills/service.js";
30
34
import { equipmentBonusesFromSlots, effectiveSkillLevel } from "../../../shared/equipment/stats.js";
31
35
import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";
32
import {
36
import
37
{
33
38
chebyshev,
34
39
hasCombatLineOfSight,
35
40
queueStandInRangeApproach,
@@ -504,12 +509,17 @@ function applySpellImpact (world, impact, now)
504
509
{
505
510
world.spellLights = world.spellLights ?? new SpellLightRegistry();
506
511
const mindRoll = resolveSpellPotency({ mindSkillLevel: impact.levels.mind }).mindRoll;
507
const durationMs = mindRoll * LIGHT_DURATION_MS_PER_MIND;
512
// Mind 0: still a brief light, but at half range. Mind 1+ → roll × 5s at full range.
513
const durationMs = Math.max(1, mindRoll) * LIGHT_DURATION_MS_PER_MIND;
514
const baseRange = mindRoll === 0
515
? SPELL_LIGHT_RANGE_TILES * 0.5
516
: SPELL_LIGHT_RANGE_TILES;
508
517
const { light, extended } = world.spellLights.placeOrExtend({
509
518
tileX: impact.targetTileX,
510
519
tileY: impact.targetTileY,
511
520
ownerEntityId: impact.casterEntityId,
512
521
durationMs,
522
baseRange,
513
523
now
514
524
});
515
525
events.push({
@@ -1,7 +1,8 @@1
import { Component } from "../ecs/components.js";1
import { Component } from "../ecs/components.js";2
import { SkillId, skillLevel } from "../../../shared/definitions/skills.js";2
import { SkillId, skillLevel } from "../../../shared/definitions/skills.js";3
import { SpellId, spellDefinition, spellDifficulty } from "../../../shared/definitions/spells.js";3
import { SpellId, spellDefinition, spellDifficulty } from "../../../shared/definitions/spells.js";4
import {4
import5
{5
canCastSpell,6
canCastSpell,6
defaultPlayerSpells,7
defaultPlayerSpells,7
normalizePlayerSpells,8
normalizePlayerSpells,@@ -10,15 +11,18 @@ import {10
toggleFavorite,11
toggleFavorite,11
learnSpell12
learnSpell12
} from "../../../shared/spells/state.js";13
} from "../../../shared/spells/state.js";13
import {14
import15
{14
CAST_FLASH_MS,16
CAST_FLASH_MS,15
COMBAT_RANGE_TILES,17
COMBAT_RANGE_TILES,16
LIGHT_DURATION_MS_PER_MIND,18
LIGHT_DURATION_MS_PER_MIND,17
SPELL_COOLDOWN_MS,19
SPELL_COOLDOWN_MS,20
SPELL_LIGHT_RANGE_TILES,18
SPELL_PROJECTILE_MS,21
SPELL_PROJECTILE_MS,19
castFlashRadiusTiles22
castFlashRadiusTiles20
} from "../../../shared/spells/constants.js";23
} from "../../../shared/spells/constants.js";21
import {24
import25
{22
mobElementAffinities,26
mobElementAffinities,23
ElementMultiplier,27
ElementMultiplier,24
resolveMagicAttack,28
resolveMagicAttack,@@ -29,7 +33,8 @@ import { mobDefinition } from "../../../shared/definitions/mobs.js";29
import { awardCombatHitXp, awardDamageHealthXp, awardSpellCastXp, syncPlayerHealth } from "../skills/service.js";33
import { awardCombatHitXp, awardDamageHealthXp, awardSpellCastXp, syncPlayerHealth } from "../skills/service.js";30
import { equipmentBonusesFromSlots, effectiveSkillLevel } from "../../../shared/equipment/stats.js";34
import { equipmentBonusesFromSlots, effectiveSkillLevel } from "../../../shared/equipment/stats.js";31
import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";35
import { statusSkillBonuses } from "../../../shared/statusEffects/rules.js";32
import {36
import37
{33
chebyshev,38
chebyshev,34
hasCombatLineOfSight,39
hasCombatLineOfSight,35
queueStandInRangeApproach,40
queueStandInRangeApproach,@@ -504,12 +509,17 @@ function applySpellImpact (world, impact, now)504
{509
{505
world.spellLights = world.spellLights ?? new SpellLightRegistry();510
world.spellLights = world.spellLights ?? new SpellLightRegistry();506
const mindRoll = resolveSpellPotency({ mindSkillLevel: impact.levels.mind }).mindRoll;511
const mindRoll = resolveSpellPotency({ mindSkillLevel: impact.levels.mind }).mindRoll;507
const durationMs = mindRoll * LIGHT_DURATION_MS_PER_MIND;512
// Mind 0: still a brief light, but at half range. Mind 1+ → roll × 5s at full range.513
const durationMs = Math.max(1, mindRoll) * LIGHT_DURATION_MS_PER_MIND;514
const baseRange = mindRoll === 0515
? SPELL_LIGHT_RANGE_TILES * 0.5516
: SPELL_LIGHT_RANGE_TILES;508
const { light, extended } = world.spellLights.placeOrExtend({517
const { light, extended } = world.spellLights.placeOrExtend({509
tileX: impact.targetTileX,518
tileX: impact.targetTileX,510
tileY: impact.targetTileY,519
tileY: impact.targetTileY,511
ownerEntityId: impact.casterEntityId,520
ownerEntityId: impact.casterEntityId,512
durationMs,521
durationMs,522
baseRange,513
now523
now514
});524
});515
events.push({525
events.push({