Merge branch 'feature/dimension-fx-hardening'
@@ -3,7 +3,7 @@ import { MessageType, GAIT, CHUNK_SIZE, STATIC_CHUNK_RADIUS } from "/shared/prot
3
3
import { validateCharacterNames } from "/shared/characters/names.js";
4
4
import { COMBAT_RANGE_TILES } from "/shared/spells/constants.js";
5
5
import { BlockType, BLOCK_DEFINITIONS, GROUND_DEFINITIONS, normalizeGround, resourceNodeDisplayName, isChopableTreeBlock, isPickablePlantBlock, plantGatherForBlock } from "/shared/definitions/tiles.js";
6
import { OVERWORLD_ID } from "/shared/world/dimensions.js";
6
import { OVERWORLD_ID, normalizeDimensionId } from "/shared/world/dimensions.js";
7
7
import { findPathToNearestGoal } from "/shared/navigation/bfs.js";
8
8
import { isAdjacentTile, canTalkOrShopNear } from "/shared/navigation/adjacency.js";
9
9
import { GameSocket, defaultSocketUrl } from "../net/socket.js";
@@ -64,6 +64,14 @@ let socket;
64
64
let session = null;
65
65
let playing = false;
66
66
let view = null;
67
68
/** True when a server visual event is for another dimension than the local view. */
69
function isForeignDimensionMessage (message)
70
{
71
if (!view || message?.dimensionId == null)
72
{ return false; }
73
return normalizeDimensionId(message.dimensionId) !== normalizeDimensionId(view.dimensionId);
74
}
67
75
let graphicsSettingsUi = null;
68
76
let scene = null;
69
77
let gait = GAIT.walk;
@@ -2281,6 +2289,8 @@ async function main ()
2281
2289
closeOpenUiIfTooFar();
2282
2290
break;
2283
2291
case MessageType.chunkDelta:
2292
if (isForeignDimensionMessage(message))
2293
{ break; }
2284
2294
for (const tile of message.tiles ?? [])
2285
2295
{
2286
2296
view?.updateAuthoredTile(
@@ -2330,6 +2340,8 @@ async function main ()
2330
2340
view?.updateEntitySkull(message.entityId, message.skullValue);
2331
2341
break;
2332
2342
case MessageType.groundItemAppear:
2343
if (isForeignDimensionMessage(message))
2344
{ break; }
2333
2345
view?.upsertGroundItem(message);
2334
2346
break;
2335
2347
case MessageType.groundItemDespawn:
@@ -2362,11 +2374,15 @@ async function main ()
2362
2374
spells?.handleSpellDisarmed();
2363
2375
break;
2364
2376
case MessageType.spellProjectile:
2377
if (isForeignDimensionMessage(message))
2378
{ break; }
2365
2379
view?.spawnSpellProjectileFx(message);
2366
2380
if (message.casterId === view?.localEntityId)
2367
2381
{ clearAutorunFocus(); }
2368
2382
break;
2369
2383
case MessageType.spellFizzle:
2384
if (isForeignDimensionMessage(message))
2385
{ break; }
2370
2386
view?.spawnSpellFizzleFx(message);
2371
2387
if (message.casterId === view?.localEntityId)
2372
2388
{
@@ -2376,21 +2392,31 @@ async function main ()
2376
2392
break;
2377
2393
case MessageType.spellCastFlash:
2378
2394
// Cast-flash dynamic lights skipped (lightmap rebake cost); Light spell uses spellLight*.
2395
if (isForeignDimensionMessage(message))
2396
{ break; }
2379
2397
if (message.casterId === view?.localEntityId)
2380
2398
{ clearAutorunFocus(); }
2381
2399
break;
2382
2400
case MessageType.spellLightAppear:
2383
2401
case MessageType.spellLightUpdate:
2402
if (isForeignDimensionMessage(message))
2403
{ break; }
2384
2404
view?.setSpellLight(message);
2385
2405
break;
2386
2406
case MessageType.spellLightRemove:
2407
if (isForeignDimensionMessage(message))
2408
{ break; }
2387
2409
view?.removeSpellLight(message);
2388
2410
break;
2389
2411
case MessageType.spellDarkAppear:
2390
2412
case MessageType.spellDarkUpdate:
2413
if (isForeignDimensionMessage(message))
2414
{ break; }
2391
2415
view?.setSpellDark(message);
2392
2416
break;
2393
2417
case MessageType.spellDarkRemove:
2418
if (isForeignDimensionMessage(message))
2419
{ break; }
2394
2420
view?.removeSpellDark(message);
2395
2421
break;
2396
2422
case MessageType.stamina:
@@ -2449,10 +2475,14 @@ async function main ()
2449
2475
social?.handleFriends(message);
2450
2476
break;
2451
2477
case MessageType.combatSwing:
2478
if (isForeignDimensionMessage(message))
2479
{ break; }
2452
2480
noteCombatWithLocal(message.attackerId, message.targetId);
2453
2481
view?.spawnCombatSwing(message);
2454
2482
break;
2455
2483
case MessageType.combatProjectile:
2484
if (isForeignDimensionMessage(message))
2485
{ break; }
2456
2486
noteCombatWithLocal(message.attackerId, message.targetId);
2457
2487
view?.spawnPhysicalProjectileFx({
2458
2488
...message,
@@ -2464,6 +2494,8 @@ async function main ()
2464
2494
break;
2465
2495
case MessageType.gatherSwing:
2466
2496
case MessageType.tileShove:
2497
if (isForeignDimensionMessage(message))
2498
{ break; }
2467
2499
view?.spawnGatherSwing(message);
2468
2500
break;
2469
2501
case MessageType.stationOpen:
@@ -2520,6 +2552,8 @@ async function main ()
2520
2552
break;
2521
2553
case MessageType.combatHit:
2522
2554
{
2555
if (isForeignDimensionMessage(message))
2556
{ break; }
2523
2557
noteCombatWithLocal(message.attackerId, message.targetId);
2524
2558
const applyHit = () =>
2525
2559
{
@@ -2540,12 +2574,16 @@ async function main ()
2540
2574
break;
2541
2575
}
2542
2576
case MessageType.combatMiss:
2577
if (isForeignDimensionMessage(message))
2578
{ break; }
2543
2579
noteCombatWithLocal(message.attackerId, message.targetId);
2544
2580
view?.spawnCombatDodge?.(message);
2545
2581
view?.markProjectileMiss?.(message);
2546
2582
break;
2547
2583
case MessageType.combatBlock:
2548
2584
{
2585
if (isForeignDimensionMessage(message))
2586
{ break; }
2549
2587
noteCombatWithLocal(message.attackerId, message.targetId);
2550
2588
const applyBlock = () =>
2551
2589
{
@@ -3,7 +3,7 @@ import { MessageType, GAIT, CHUNK_SIZE, STATIC_CHUNK_RADIUS } from "/shared/prot3
import { validateCharacterNames } from "/shared/characters/names.js";3
import { validateCharacterNames } from "/shared/characters/names.js";4
import { COMBAT_RANGE_TILES } from "/shared/spells/constants.js";4
import { COMBAT_RANGE_TILES } from "/shared/spells/constants.js";5
import { BlockType, BLOCK_DEFINITIONS, GROUND_DEFINITIONS, normalizeGround, resourceNodeDisplayName, isChopableTreeBlock, isPickablePlantBlock, plantGatherForBlock } from "/shared/definitions/tiles.js";5
import { BlockType, BLOCK_DEFINITIONS, GROUND_DEFINITIONS, normalizeGround, resourceNodeDisplayName, isChopableTreeBlock, isPickablePlantBlock, plantGatherForBlock } from "/shared/definitions/tiles.js";6
import { OVERWORLD_ID } from "/shared/world/dimensions.js";6
import { OVERWORLD_ID, normalizeDimensionId } from "/shared/world/dimensions.js";7
import { findPathToNearestGoal } from "/shared/navigation/bfs.js";7
import { findPathToNearestGoal } from "/shared/navigation/bfs.js";8
import { isAdjacentTile, canTalkOrShopNear } from "/shared/navigation/adjacency.js";8
import { isAdjacentTile, canTalkOrShopNear } from "/shared/navigation/adjacency.js";9
import { GameSocket, defaultSocketUrl } from "../net/socket.js";9
import { GameSocket, defaultSocketUrl } from "../net/socket.js";@@ -64,6 +64,14 @@ let socket;64
let session = null;64
let session = null;65
let playing = false;65
let playing = false;66
let view = null;66
let view = null;67
68
/** True when a server visual event is for another dimension than the local view. */69
function isForeignDimensionMessage (message)70
{71
if (!view || message?.dimensionId == null)72
{ return false; }73
return normalizeDimensionId(message.dimensionId) !== normalizeDimensionId(view.dimensionId);74
}67
let graphicsSettingsUi = null;75
let graphicsSettingsUi = null;68
let scene = null;76
let scene = null;69
let gait = GAIT.walk;77
let gait = GAIT.walk;@@ -2281,6 +2289,8 @@ async function main ()2281
closeOpenUiIfTooFar();2289
closeOpenUiIfTooFar();2282
break;2290
break;2283
case MessageType.chunkDelta:2291
case MessageType.chunkDelta:2292
if (isForeignDimensionMessage(message))2293
{ break; }2284
for (const tile of message.tiles ?? [])2294
for (const tile of message.tiles ?? [])2285
{2295
{2286
view?.updateAuthoredTile(2296
view?.updateAuthoredTile(@@ -2330,6 +2340,8 @@ async function main ()2330
view?.updateEntitySkull(message.entityId, message.skullValue);2340
view?.updateEntitySkull(message.entityId, message.skullValue);2331
break;2341
break;2332
case MessageType.groundItemAppear:2342
case MessageType.groundItemAppear:2343
if (isForeignDimensionMessage(message))2344
{ break; }2333
view?.upsertGroundItem(message);2345
view?.upsertGroundItem(message);2334
break;2346
break;2335
case MessageType.groundItemDespawn:2347
case MessageType.groundItemDespawn:@@ -2362,11 +2374,15 @@ async function main ()2362
spells?.handleSpellDisarmed();2374
spells?.handleSpellDisarmed();2363
break;2375
break;2364
case MessageType.spellProjectile:2376
case MessageType.spellProjectile:2377
if (isForeignDimensionMessage(message))2378
{ break; }2365
view?.spawnSpellProjectileFx(message);2379
view?.spawnSpellProjectileFx(message);2366
if (message.casterId === view?.localEntityId)2380
if (message.casterId === view?.localEntityId)2367
{ clearAutorunFocus(); }2381
{ clearAutorunFocus(); }2368
break;2382
break;2369
case MessageType.spellFizzle:2383
case MessageType.spellFizzle:2384
if (isForeignDimensionMessage(message))2385
{ break; }2370
view?.spawnSpellFizzleFx(message);2386
view?.spawnSpellFizzleFx(message);2371
if (message.casterId === view?.localEntityId)2387
if (message.casterId === view?.localEntityId)2372
{2388
{@@ -2376,21 +2392,31 @@ async function main ()2376
break;2392
break;2377
case MessageType.spellCastFlash:2393
case MessageType.spellCastFlash:2378
// Cast-flash dynamic lights skipped (lightmap rebake cost); Light spell uses spellLight*.2394
// Cast-flash dynamic lights skipped (lightmap rebake cost); Light spell uses spellLight*.2395
if (isForeignDimensionMessage(message))2396
{ break; }2379
if (message.casterId === view?.localEntityId)2397
if (message.casterId === view?.localEntityId)2380
{ clearAutorunFocus(); }2398
{ clearAutorunFocus(); }2381
break;2399
break;2382
case MessageType.spellLightAppear:2400
case MessageType.spellLightAppear:2383
case MessageType.spellLightUpdate:2401
case MessageType.spellLightUpdate:2402
if (isForeignDimensionMessage(message))2403
{ break; }2384
view?.setSpellLight(message);2404
view?.setSpellLight(message);2385
break;2405
break;2386
case MessageType.spellLightRemove:2406
case MessageType.spellLightRemove:2407
if (isForeignDimensionMessage(message))2408
{ break; }2387
view?.removeSpellLight(message);2409
view?.removeSpellLight(message);2388
break;2410
break;2389
case MessageType.spellDarkAppear:2411
case MessageType.spellDarkAppear:2390
case MessageType.spellDarkUpdate:2412
case MessageType.spellDarkUpdate:2413
if (isForeignDimensionMessage(message))2414
{ break; }2391
view?.setSpellDark(message);2415
view?.setSpellDark(message);2392
break;2416
break;2393
case MessageType.spellDarkRemove:2417
case MessageType.spellDarkRemove:2418
if (isForeignDimensionMessage(message))2419
{ break; }2394
view?.removeSpellDark(message);2420
view?.removeSpellDark(message);2395
break;2421
break;2396
case MessageType.stamina:2422
case MessageType.stamina:@@ -2449,10 +2475,14 @@ async function main ()2449
social?.handleFriends(message);2475
social?.handleFriends(message);2450
break;2476
break;2451
case MessageType.combatSwing:2477
case MessageType.combatSwing:2478
if (isForeignDimensionMessage(message))2479
{ break; }2452
noteCombatWithLocal(message.attackerId, message.targetId);2480
noteCombatWithLocal(message.attackerId, message.targetId);2453
view?.spawnCombatSwing(message);2481
view?.spawnCombatSwing(message);2454
break;2482
break;2455
case MessageType.combatProjectile:2483
case MessageType.combatProjectile:2484
if (isForeignDimensionMessage(message))2485
{ break; }2456
noteCombatWithLocal(message.attackerId, message.targetId);2486
noteCombatWithLocal(message.attackerId, message.targetId);2457
view?.spawnPhysicalProjectileFx({2487
view?.spawnPhysicalProjectileFx({2458
...message,2488
...message,@@ -2464,6 +2494,8 @@ async function main ()2464
break;2494
break;2465
case MessageType.gatherSwing:2495
case MessageType.gatherSwing:2466
case MessageType.tileShove:2496
case MessageType.tileShove:2497
if (isForeignDimensionMessage(message))2498
{ break; }2467
view?.spawnGatherSwing(message);2499
view?.spawnGatherSwing(message);2468
break;2500
break;2469
case MessageType.stationOpen:2501
case MessageType.stationOpen:@@ -2520,6 +2552,8 @@ async function main ()2520
break;2552
break;2521
case MessageType.combatHit:2553
case MessageType.combatHit:2522
{2554
{2555
if (isForeignDimensionMessage(message))2556
{ break; }2523
noteCombatWithLocal(message.attackerId, message.targetId);2557
noteCombatWithLocal(message.attackerId, message.targetId);2524
const applyHit = () =>2558
const applyHit = () =>2525
{2559
{@@ -2540,12 +2574,16 @@ async function main ()2540
break;2574
break;2541
}2575
}2542
case MessageType.combatMiss:2576
case MessageType.combatMiss:2577
if (isForeignDimensionMessage(message))2578
{ break; }2543
noteCombatWithLocal(message.attackerId, message.targetId);2579
noteCombatWithLocal(message.attackerId, message.targetId);2544
view?.spawnCombatDodge?.(message);2580
view?.spawnCombatDodge?.(message);2545
view?.markProjectileMiss?.(message);2581
view?.markProjectileMiss?.(message);2546
break;2582
break;2547
case MessageType.combatBlock:2583
case MessageType.combatBlock:2548
{2584
{2585
if (isForeignDimensionMessage(message))2586
{ break; }2549
noteCombatWithLocal(message.attackerId, message.targetId);2587
noteCombatWithLocal(message.attackerId, message.targetId);2550
const applyBlock = () =>2588
const applyBlock = () =>2551
{2589
{@@ -1209,6 +1209,12 @@ export class WorldView
1209
1209
}
1210
1210
for (const [id] of [...this.groundItems.entries()])
1211
1211
{ this.despawnGroundItem(id); }
1212
for (const swipe of this.swipes)
1213
{ swipe.object?.destroy(); }
1214
this.swipes = [];
1215
this.spellLights.clear();
1216
this.spellDarks.clear();
1217
this.dynamicLights = [];
1212
1218
}
1213
1219
1214
1220
/** Full client wipe when leaving the world (menu / disconnect). Includes the local player. */
@@ -1235,7 +1241,7 @@ export class WorldView
1235
1241
1236
1242
applySnapshot (snapshot)
1237
1243
{
1238
const snapDim = normalizeDimensionId(snapshot.dimensionId ?? OVERWORLD_ID);
1244
const snapDim = normalizeDimensionId(snapshot.dimensionId ?? this.dimensionId ?? OVERWORLD_ID);
1239
1245
if (normalizeDimensionId(this.dimensionId) !== snapDim)
1240
1246
{ return; }
1241
1247
const key = `${snapshot.chunkX},${snapshot.chunkY}`;
@@ -2029,6 +2035,9 @@ export class WorldView
2029
2035
2030
2036
upsertGroundItem (payload)
2031
2037
{
2038
if (payload?.dimensionId != null
2039
&& normalizeDimensionId(payload.dimensionId) !== normalizeDimensionId(this.dimensionId))
2040
{ return; }
2032
2041
const size = this.tileSize();
2033
2042
const pivot = tilePivot(payload.tileX, payload.tileY, size);
2034
2043
const potion = payload.instance?.kind === "potion" ? payload.instance : null;
@@ -1209,6 +1209,12 @@ export class WorldView1209
}1209
}1210
for (const [id] of [...this.groundItems.entries()])1210
for (const [id] of [...this.groundItems.entries()])1211
{ this.despawnGroundItem(id); }1211
{ this.despawnGroundItem(id); }1212
for (const swipe of this.swipes)1213
{ swipe.object?.destroy(); }1214
this.swipes = [];1215
this.spellLights.clear();1216
this.spellDarks.clear();1217
this.dynamicLights = [];1212
}1218
}1213
1219
1214
/** Full client wipe when leaving the world (menu / disconnect). Includes the local player. */1220
/** Full client wipe when leaving the world (menu / disconnect). Includes the local player. */@@ -1235,7 +1241,7 @@ export class WorldView1235
1241
1236
applySnapshot (snapshot)1242
applySnapshot (snapshot)1237
{1243
{1238
const snapDim = normalizeDimensionId(snapshot.dimensionId ?? OVERWORLD_ID);1244
const snapDim = normalizeDimensionId(snapshot.dimensionId ?? this.dimensionId ?? OVERWORLD_ID);1239
if (normalizeDimensionId(this.dimensionId) !== snapDim)1245
if (normalizeDimensionId(this.dimensionId) !== snapDim)1240
{ return; }1246
{ return; }1241
const key = `${snapshot.chunkX},${snapshot.chunkY}`;1247
const key = `${snapshot.chunkX},${snapshot.chunkY}`;@@ -2029,6 +2035,9 @@ export class WorldView2029
2035
2030
upsertGroundItem (payload)2036
upsertGroundItem (payload)2031
{2037
{2038
if (payload?.dimensionId != null2039
&& normalizeDimensionId(payload.dimensionId) !== normalizeDimensionId(this.dimensionId))2040
{ return; }2032
const size = this.tileSize();2041
const size = this.tileSize();2033
const pivot = tilePivot(payload.tileX, payload.tileY, size);2042
const pivot = tilePivot(payload.tileX, payload.tileY, size);2034
const potion = payload.instance?.kind === "potion" ? payload.instance : null;2043
const potion = payload.instance?.kind === "potion" ? payload.instance : null;@@ -624,7 +624,7 @@ export function tileLightAt (world, tileX, tileY, now = Date.now(), dimensionId
624
624
);
625
625
const blockLit = dynamicLightAtTile(tileX, tileY, blockSources, occlusionAt);
626
626
const entity = entityLightAtTile(world.ecs, Component, tileX, tileY, now);
627
const { lights, darks } = spellLightsForDynamicLighting(world.spellLights, now);
627
const { lights, darks } = spellLightsForDynamicLighting(world.spellLights, now, dim);
628
628
const spellLight = dynamicLightAtTile(tileX, tileY, lights, occlusionAt);
629
629
const spellDark = dynamicDarknessAtTile(tileX, tileY, darks, occlusionAt);
630
630
const worldTime = world.worldTime?.(now);
@@ -1926,6 +1926,7 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
1926
1926
fromTileX: from.tileX,
1927
1927
fromTileY: from.tileY,
1928
1928
sprite: arrowSprite,
1929
dimensionId: normalizeDimensionId(from.dimensionId ?? targetPos.dimensionId ?? OVERWORLD_ID),
1929
1930
...(publicDualTint(arrowTint) ?? {})
1930
1931
});
1931
1932
return events;
@@ -1971,6 +1972,7 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D
1971
1972
durationMs: RANGED_PROJECTILE_MS,
1972
1973
trackTarget: outcome?.type !== "combat-miss",
1973
1974
sprite: arrowSprite,
1975
dimensionId: normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID),
1974
1976
...(publicDualTint(arrowTint) ?? {})
1975
1977
});
1976
1978
return events.concat(hitEvents);
@@ -2087,7 +2089,8 @@ export function resolveMeleeSwing (world, attackerId, targetId, profile, now = D
2087
2089
tileX: to.tileX,
2088
2090
tileY: to.tileY,
2089
2091
fromTileX: from.tileX,
2090
fromTileY: from.tileY
2092
fromTileY: from.tileY,
2093
dimensionId: normalizeDimensionId(from.dimensionId ?? to.dimensionId ?? OVERWORLD_ID)
2091
2094
});
2092
2095
2093
2096
if (!target.local)
@@ -2102,7 +2105,8 @@ export function resolveMeleeSwing (world, attackerId, targetId, profile, now = D
2102
2105
attackerIsPlayer: !!attackerCharacter,
2103
2106
now,
2104
2107
tileX: to.tileX,
2105
tileY: to.tileY
2108
tileY: to.tileY,
2109
dimensionId: normalizeDimensionId(from.dimensionId ?? to.dimensionId ?? OVERWORLD_ID)
2106
2110
});
2107
2111
return events;
2108
2112
}
@@ -2125,9 +2129,13 @@ export function applyRemoteRangedShot (world, payload)
2125
2129
const targetHandle = world.ecs.handleOf(payload.targetId);
2126
2130
if (targetHandle == null)
2127
2131
{ return { events: [], forwards: [] }; }
2132
const targetPos = world.ecs.get(targetHandle, Component.position);
2128
2133
const snapshot = {
2129
2134
tileX: payload.tileX,
2130
tileY: payload.tileY
2135
tileY: payload.tileY,
2136
dimensionId: normalizeDimensionId(
2137
payload.dimensionId ?? targetPos?.dimensionId ?? OVERWORLD_ID
2138
)
2131
2139
};
2132
2140
2133
2141
const hitEvents = applyLocalMeleeHit(
@@ -2145,6 +2153,7 @@ export function applyRemoteRangedShot (world, payload)
2145
2153
2146
2154
const outcome = hitEvents.find((e) =>
2147
2155
e.type === "combat-hit" || e.type === "combat-miss" || e.type === "combat-block");
2156
const currentPos = world.ecs.get(targetHandle, Component.position);
2148
2157
let endX = snapshot.tileX;
2149
2158
let endY = snapshot.tileY;
2150
2159
if (outcome?.type === "combat-miss")
@@ -2153,14 +2162,10 @@ export function applyRemoteRangedShot (world, payload)
2153
2162
endX = miss.tileX;
2154
2163
endY = miss.tileY;
2155
2164
}
2156
else
2165
else if (currentPos)
2157
2166
{
2158
const currentPos = world.ecs.get(targetHandle, Component.position);
2159
if (currentPos)
2160
{
2161
endX = currentPos.tileX;
2162
endY = currentPos.tileY;
2163
}
2167
endX = currentPos.tileX;
2168
endY = currentPos.tileY;
2164
2169
}
2165
2170
2166
2171
const events = [{
@@ -2176,7 +2181,10 @@ export function applyRemoteRangedShot (world, payload)
2176
2181
sprite: payload.sprite ?? "fx:projectile:arrow",
2177
2182
shaftTint: payload.shaftTint ?? null,
2178
2183
tipTint: payload.tipTint ?? null,
2179
coatTint: payload.coatTint ?? null
2184
coatTint: payload.coatTint ?? null,
2185
dimensionId: normalizeDimensionId(
2186
payload.dimensionId ?? currentPos?.dimensionId ?? OVERWORLD_ID
2187
)
2180
2188
}, ...hitEvents];
2181
2189
2182
2190
const forwards = [];
@@ -2319,7 +2327,8 @@ function applyLocalMeleeHit (
2319
2327
attackerId,
2320
2328
targetId,
2321
2329
tileX: to.tileX,
2322
tileY: to.tileY
2330
tileY: to.tileY,
2331
dimensionId: normalizeDimensionId(to.dimensionId ?? OVERWORLD_ID)
2323
2332
});
2324
2333
const dodgeXp = awardCombatAvoidanceXp(
2325
2334
world.ecs,
@@ -2349,7 +2358,8 @@ function applyLocalMeleeHit (
2349
2358
attackerId,
2350
2359
targetId,
2351
2360
tileX: to.tileX,
2352
tileY: to.tileY
2361
tileY: to.tileY,
2362
dimensionId: normalizeDimensionId(to.dimensionId ?? OVERWORLD_ID)
2353
2363
});
2354
2364
const blockXp = awardCombatAvoidanceXp(
2355
2365
world.ecs,
@@ -2390,7 +2400,8 @@ function applyLocalMeleeHit (
2390
2400
tileX: to.tileX,
2391
2401
tileY: to.tileY,
2392
2402
health: health?.current ?? 0,
2393
maxHealth: health?.max ?? 0
2403
maxHealth: health?.max ?? 0,
2404
dimensionId: normalizeDimensionId(to.dimensionId ?? OVERWORLD_ID)
2394
2405
});
2395
2406
2396
2407
const healthXp = awardDamageHealthXp(world.ecs, targetHandle, damage);
@@ -2577,7 +2588,8 @@ export function applyDamageAndKill (world, attackerId, targetId, damage, now = D
2577
2588
tileX: to.tileX,
2578
2589
tileY: to.tileY,
2579
2590
health: health?.current ?? 0,
2580
maxHealth: health?.max ?? 0
2591
maxHealth: health?.max ?? 0,
2592
dimensionId: normalizeDimensionId(to.dimensionId ?? OVERWORLD_ID)
2581
2593
});
2582
2594
2583
2595
const attackerHandle = world.ecs.handleOf(attackerId);
@@ -624,7 +624,7 @@ export function tileLightAt (world, tileX, tileY, now = Date.now(), dimensionId624
);624
);625
const blockLit = dynamicLightAtTile(tileX, tileY, blockSources, occlusionAt);625
const blockLit = dynamicLightAtTile(tileX, tileY, blockSources, occlusionAt);626
const entity = entityLightAtTile(world.ecs, Component, tileX, tileY, now);626
const entity = entityLightAtTile(world.ecs, Component, tileX, tileY, now);627
const { lights, darks } = spellLightsForDynamicLighting(world.spellLights, now);627
const { lights, darks } = spellLightsForDynamicLighting(world.spellLights, now, dim);628
const spellLight = dynamicLightAtTile(tileX, tileY, lights, occlusionAt);628
const spellLight = dynamicLightAtTile(tileX, tileY, lights, occlusionAt);629
const spellDark = dynamicDarknessAtTile(tileX, tileY, darks, occlusionAt);629
const spellDark = dynamicDarknessAtTile(tileX, tileY, darks, occlusionAt);630
const worldTime = world.worldTime?.(now);630
const worldTime = world.worldTime?.(now);@@ -1926,6 +1926,7 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D1926
fromTileX: from.tileX,1926
fromTileX: from.tileX,1927
fromTileY: from.tileY,1927
fromTileY: from.tileY,1928
sprite: arrowSprite,1928
sprite: arrowSprite,1929
dimensionId: normalizeDimensionId(from.dimensionId ?? targetPos.dimensionId ?? OVERWORLD_ID),1929
...(publicDualTint(arrowTint) ?? {})1930
...(publicDualTint(arrowTint) ?? {})1930
});1931
});1931
return events;1932
return events;@@ -1971,6 +1972,7 @@ export function resolveRangedShot (world, attackerId, targetId, profile, now = D1971
durationMs: RANGED_PROJECTILE_MS,1972
durationMs: RANGED_PROJECTILE_MS,1972
trackTarget: outcome?.type !== "combat-miss",1973
trackTarget: outcome?.type !== "combat-miss",1973
sprite: arrowSprite,1974
sprite: arrowSprite,1975
dimensionId: normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID),1974
...(publicDualTint(arrowTint) ?? {})1976
...(publicDualTint(arrowTint) ?? {})1975
});1977
});1976
return events.concat(hitEvents);1978
return events.concat(hitEvents);@@ -2087,7 +2089,8 @@ export function resolveMeleeSwing (world, attackerId, targetId, profile, now = D2087
tileX: to.tileX,2089
tileX: to.tileX,2088
tileY: to.tileY,2090
tileY: to.tileY,2089
fromTileX: from.tileX,2091
fromTileX: from.tileX,2090
fromTileY: from.tileY2092
fromTileY: from.tileY,2093
dimensionId: normalizeDimensionId(from.dimensionId ?? to.dimensionId ?? OVERWORLD_ID)2091
});2094
});2092
2095
2093
if (!target.local)2096
if (!target.local)@@ -2102,7 +2105,8 @@ export function resolveMeleeSwing (world, attackerId, targetId, profile, now = D2102
attackerIsPlayer: !!attackerCharacter,2105
attackerIsPlayer: !!attackerCharacter,2103
now,2106
now,2104
tileX: to.tileX,2107
tileX: to.tileX,2105
tileY: to.tileY2108
tileY: to.tileY,2109
dimensionId: normalizeDimensionId(from.dimensionId ?? to.dimensionId ?? OVERWORLD_ID)2106
});2110
});2107
return events;2111
return events;2108
}2112
}@@ -2125,9 +2129,13 @@ export function applyRemoteRangedShot (world, payload)2125
const targetHandle = world.ecs.handleOf(payload.targetId);2129
const targetHandle = world.ecs.handleOf(payload.targetId);2126
if (targetHandle == null)2130
if (targetHandle == null)2127
{ return { events: [], forwards: [] }; }2131
{ return { events: [], forwards: [] }; }2132
const targetPos = world.ecs.get(targetHandle, Component.position);2128
const snapshot = {2133
const snapshot = {2129
tileX: payload.tileX,2134
tileX: payload.tileX,2130
tileY: payload.tileY2135
tileY: payload.tileY,2136
dimensionId: normalizeDimensionId(2137
payload.dimensionId ?? targetPos?.dimensionId ?? OVERWORLD_ID2138
)2131
};2139
};2132
2140
2133
const hitEvents = applyLocalMeleeHit(2141
const hitEvents = applyLocalMeleeHit(@@ -2145,6 +2153,7 @@ export function applyRemoteRangedShot (world, payload)2145
2153
2146
const outcome = hitEvents.find((e) =>2154
const outcome = hitEvents.find((e) =>2147
e.type === "combat-hit" || e.type === "combat-miss" || e.type === "combat-block");2155
e.type === "combat-hit" || e.type === "combat-miss" || e.type === "combat-block");2156
const currentPos = world.ecs.get(targetHandle, Component.position);2148
let endX = snapshot.tileX;2157
let endX = snapshot.tileX;2149
let endY = snapshot.tileY;2158
let endY = snapshot.tileY;2150
if (outcome?.type === "combat-miss")2159
if (outcome?.type === "combat-miss")@@ -2153,14 +2162,10 @@ export function applyRemoteRangedShot (world, payload)2153
endX = miss.tileX;2162
endX = miss.tileX;2154
endY = miss.tileY;2163
endY = miss.tileY;2155
}2164
}2156
else2165
else if (currentPos)2157
{2166
{2158
const currentPos = world.ecs.get(targetHandle, Component.position);2167
endX = currentPos.tileX;2159
if (currentPos)2168
endY = currentPos.tileY;2160
{2161
endX = currentPos.tileX;2162
endY = currentPos.tileY;2163
}2164
}2169
}2165
2170
2166
const events = [{2171
const events = [{@@ -2176,7 +2181,10 @@ export function applyRemoteRangedShot (world, payload)2176
sprite: payload.sprite ?? "fx:projectile:arrow",2181
sprite: payload.sprite ?? "fx:projectile:arrow",2177
shaftTint: payload.shaftTint ?? null,2182
shaftTint: payload.shaftTint ?? null,2178
tipTint: payload.tipTint ?? null,2183
tipTint: payload.tipTint ?? null,2179
coatTint: payload.coatTint ?? null2184
coatTint: payload.coatTint ?? null,2185
dimensionId: normalizeDimensionId(2186
payload.dimensionId ?? currentPos?.dimensionId ?? OVERWORLD_ID2187
)2180
}, ...hitEvents];2188
}, ...hitEvents];2181
2189
2182
const forwards = [];2190
const forwards = [];@@ -2319,7 +2327,8 @@ function applyLocalMeleeHit (2319
attackerId,2327
attackerId,2320
targetId,2328
targetId,2321
tileX: to.tileX,2329
tileX: to.tileX,2322
tileY: to.tileY2330
tileY: to.tileY,2331
dimensionId: normalizeDimensionId(to.dimensionId ?? OVERWORLD_ID)2323
});2332
});2324
const dodgeXp = awardCombatAvoidanceXp(2333
const dodgeXp = awardCombatAvoidanceXp(2325
world.ecs,2334
world.ecs,@@ -2349,7 +2358,8 @@ function applyLocalMeleeHit (2349
attackerId,2358
attackerId,2350
targetId,2359
targetId,2351
tileX: to.tileX,2360
tileX: to.tileX,2352
tileY: to.tileY2361
tileY: to.tileY,2362
dimensionId: normalizeDimensionId(to.dimensionId ?? OVERWORLD_ID)2353
});2363
});2354
const blockXp = awardCombatAvoidanceXp(2364
const blockXp = awardCombatAvoidanceXp(2355
world.ecs,2365
world.ecs,@@ -2390,7 +2400,8 @@ function applyLocalMeleeHit (2390
tileX: to.tileX,2400
tileX: to.tileX,2391
tileY: to.tileY,2401
tileY: to.tileY,2392
health: health?.current ?? 0,2402
health: health?.current ?? 0,2393
maxHealth: health?.max ?? 02403
maxHealth: health?.max ?? 0,2404
dimensionId: normalizeDimensionId(to.dimensionId ?? OVERWORLD_ID)2394
});2405
});2395
2406
2396
const healthXp = awardDamageHealthXp(world.ecs, targetHandle, damage);2407
const healthXp = awardDamageHealthXp(world.ecs, targetHandle, damage);@@ -2577,7 +2588,8 @@ export function applyDamageAndKill (world, attackerId, targetId, damage, now = D2577
tileX: to.tileX,2588
tileX: to.tileX,2578
tileY: to.tileY,2589
tileY: to.tileY,2579
health: health?.current ?? 0,2590
health: health?.current ?? 0,2580
maxHealth: health?.max ?? 02591
maxHealth: health?.max ?? 0,2592
dimensionId: normalizeDimensionId(to.dimensionId ?? OVERWORLD_ID)2581
});2593
});2582
2594
2583
const attackerHandle = world.ecs.handleOf(attackerId);2595
const attackerHandle = world.ecs.handleOf(attackerId);@@ -444,7 +444,8 @@ export function stepFirestarting (world, now)
444
444
fromTileX: position.tileX,
445
445
fromTileY: position.tileY,
446
446
toolItemId: session.toolItemId,
447
swipe: false
447
swipe: false,
448
dimensionId: normalizeDimensionId(position.dimensionId ?? OVERWORLD_ID)
448
449
});
449
450
450
451
const skills = world.ecs.get(handle, Component.skills);
@@ -444,7 +444,8 @@ export function stepFirestarting (world, now)444
fromTileX: position.tileX,444
fromTileX: position.tileX,445
fromTileY: position.tileY,445
fromTileY: position.tileY,446
toolItemId: session.toolItemId,446
toolItemId: session.toolItemId,447
swipe: false447
swipe: false,448
dimensionId: normalizeDimensionId(position.dimensionId ?? OVERWORLD_ID)448
});449
});449
450
450
const skills = world.ecs.get(handle, Component.skills);451
const skills = world.ecs.get(handle, Component.skills);@@ -0,0 +1,59 @@
1
import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";
2
import { chunkKey, tileToChunk } from "../world/coordinates.js";
3
4
/**
5
* Resolve which dimension an FX / replication event belongs to.
6
* Prefer an explicit event.dimensionId; otherwise ask the directory for any
7
* involved entity id (entity / attacker / caster / target).
8
*
9
* @param {object} event
10
* @param {(entityId: number) => string|null|undefined} resolveEntityDimensionId
11
*/
12
export function resolveEventDimensionId (event, resolveEntityDimensionId)
13
{
14
if (event?.dimensionId != null)
15
{ return normalizeDimensionId(event.dimensionId); }
16
const entityIds = [
17
event?.entityId,
18
event?.attackerId,
19
event?.casterId,
20
event?.ownerEntityId,
21
event?.targetId,
22
event?.targetEntityId
23
];
24
for (const id of entityIds)
25
{
26
if (id == null)
27
{ continue; }
28
const dim = resolveEntityDimensionId?.(id);
29
if (dim != null)
30
{ return normalizeDimensionId(dim); }
31
}
32
return OVERWORLD_ID;
33
}
34
35
/**
36
* Chunk interest keys for publishing an event to subscribed clients.
37
* @returns {{ fromKey: string|null, toKey: string|null, dimensionId: string, fromDimensionId: string }}
38
*/
39
export function eventInterestKeys (event, resolveEntityDimensionId)
40
{
41
const toDim = resolveEventDimensionId(event, resolveEntityDimensionId);
42
const fromDim = event?.fromDimensionId != null
43
? normalizeDimensionId(event.fromDimensionId)
44
: toDim;
45
const fromKey = event?.fromTileX != null && event?.fromTileY != null
46
? chunkKey(tileToChunk(event.fromTileX), tileToChunk(event.fromTileY), fromDim)
47
: null;
48
let toKey = event?.tileX != null && event?.tileY != null
49
? chunkKey(tileToChunk(event.tileX), tileToChunk(event.tileY), toDim)
50
: null;
51
if (toKey == null && event?.chunkX != null && event?.chunkY != null)
52
{ toKey = chunkKey(event.chunkX | 0, event.chunkY | 0, toDim); }
53
return {
54
fromKey,
55
toKey,
56
dimensionId: toDim,
57
fromDimensionId: fromDim
58
};
59
}
@@ -0,0 +1,59 @@1
import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";2
import { chunkKey, tileToChunk } from "../world/coordinates.js";3
4
/**5
* Resolve which dimension an FX / replication event belongs to.6
* Prefer an explicit event.dimensionId; otherwise ask the directory for any7
* involved entity id (entity / attacker / caster / target).8
*9
* @param {object} event10
* @param {(entityId: number) => string|null|undefined} resolveEntityDimensionId11
*/12
export function resolveEventDimensionId (event, resolveEntityDimensionId)13
{14
if (event?.dimensionId != null)15
{ return normalizeDimensionId(event.dimensionId); }16
const entityIds = [17
event?.entityId,18
event?.attackerId,19
event?.casterId,20
event?.ownerEntityId,21
event?.targetId,22
event?.targetEntityId23
];24
for (const id of entityIds)25
{26
if (id == null)27
{ continue; }28
const dim = resolveEntityDimensionId?.(id);29
if (dim != null)30
{ return normalizeDimensionId(dim); }31
}32
return OVERWORLD_ID;33
}34
35
/**36
* Chunk interest keys for publishing an event to subscribed clients.37
* @returns {{ fromKey: string|null, toKey: string|null, dimensionId: string, fromDimensionId: string }}38
*/39
export function eventInterestKeys (event, resolveEntityDimensionId)40
{41
const toDim = resolveEventDimensionId(event, resolveEntityDimensionId);42
const fromDim = event?.fromDimensionId != null43
? normalizeDimensionId(event.fromDimensionId)44
: toDim;45
const fromKey = event?.fromTileX != null && event?.fromTileY != null46
? chunkKey(tileToChunk(event.fromTileX), tileToChunk(event.fromTileY), fromDim)47
: null;48
let toKey = event?.tileX != null && event?.tileY != null49
? chunkKey(tileToChunk(event.tileX), tileToChunk(event.tileY), toDim)50
: null;51
if (toKey == null && event?.chunkX != null && event?.chunkY != null)52
{ toKey = chunkKey(event.chunkX | 0, event.chunkY | 0, toDim); }53
return {54
fromKey,55
toKey,56
dimensionId: toDim,57
fromDimensionId: fromDim58
};59
}@@ -10,6 +10,7 @@ import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimens
10
10
import { canCharacterSeeGroundItem } from "../../../shared/items/letters.js";
11
11
import { getConsoleSnapshot, subscribeConsole } from "../logging/consoleCapture.js";
12
12
import { resolveAccount } from "../auth/routes.js";
13
import { eventInterestKeys } from "./eventInterest.js";
13
14
14
15
let nextSessionId = 1;
15
16
@@ -2183,47 +2184,17 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2183
2184
2184
2185
function publishEntity (event)
2185
2186
{
2186
const entityIds = [
2187
event.entityId,
2188
event.attackerId,
2189
event.casterId,
2190
event.targetId,
2191
event.targetEntityId
2192
];
2193
let resolvedDim = event.dimensionId != null
2194
? normalizeDimensionId(event.dimensionId)
2195
: null;
2196
if (resolvedDim == null)
2197
{
2198
for (const id of entityIds)
2199
{
2200
if (id == null)
2201
{ continue; }
2202
const record = simulation.entityRecord(id);
2203
if (record?.dimensionId != null)
2204
{
2205
resolvedDim = normalizeDimensionId(record.dimensionId);
2206
break;
2207
}
2208
}
2209
}
2210
const toDim = resolvedDim ?? OVERWORLD_ID;
2211
const fromDim = event.fromDimensionId != null
2212
? normalizeDimensionId(event.fromDimensionId)
2213
: toDim;
2214
const fromKey = event.fromTileX != null
2215
? chunkKey(tileToChunk(event.fromTileX), tileToChunk(event.fromTileY), fromDim)
2216
: null;
2217
const toKey = event.tileX != null
2218
? chunkKey(tileToChunk(event.tileX), tileToChunk(event.tileY), toDim)
2219
: null;
2187
const { fromKey, toKey, dimensionId: toDim } = eventInterestKeys(
2188
event,
2189
(entityId) => simulation.entityRecord(entityId)?.dimensionId
2190
);
2220
2191
for (const session of sessions.values())
2221
2192
{
2222
2193
if (!session.entityId)
2223
2194
{ continue; }
2224
const seesFrom = fromKey ? session.entitySubscribed.has(fromKey) : false;
2225
const seesTo = session.entitySubscribed.has(toKey);
2226
const seesStaticTo = session.staticSubscribed.has(toKey);
2195
const seesFrom = fromKey != null && session.entitySubscribed.has(fromKey);
2196
const seesTo = toKey != null && session.entitySubscribed.has(toKey);
2197
const seesStaticTo = toKey != null && session.staticSubscribed.has(toKey);
2227
2198
if (event.type === "entity-spawn")
2228
2199
{
2229
2200
if (session.entityId === event.entityId || !seesTo)
@@ -2304,7 +2275,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2304
2275
tileX: event.tileX,
2305
2276
tileY: event.tileY,
2306
2277
fromTileX: event.fromTileX,
2307
fromTileY: event.fromTileY
2278
fromTileY: event.fromTileY,
2279
dimensionId: toDim
2308
2280
});
2309
2281
continue;
2310
2282
}
@@ -2323,7 +2295,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2323
2295
durationMs: event.durationMs ?? 400,
2324
2296
trackTarget: event.trackTarget !== false,
2325
2297
shaftTint: event.shaftTint ?? null,
2326
tipTint: event.tipTint ?? null
2298
tipTint: event.tipTint ?? null,
2299
dimensionId: toDim
2327
2300
});
2328
2301
continue;
2329
2302
}
@@ -2341,7 +2314,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2341
2314
tileX: event.tileX,
2342
2315
tileY: event.tileY,
2343
2316
durationMs: event.durationMs ?? 2000,
2344
sprite: event.sprite ?? null
2317
sprite: event.sprite ?? null,
2318
dimensionId: toDim
2345
2319
});
2346
2320
continue;
2347
2321
}
@@ -2356,7 +2330,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2356
2330
fromTileX: event.fromTileX,
2357
2331
fromTileY: event.fromTileY,
2358
2332
tileX: event.tileX,
2359
tileY: event.tileY
2333
tileY: event.tileY,
2334
dimensionId: toDim
2360
2335
});
2361
2336
continue;
2362
2337
}
@@ -2371,7 +2346,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2371
2346
tileY: event.tileY,
2372
2347
radiusTiles: event.radiusTiles ?? 1,
2373
2348
durationMs: event.durationMs ?? 500,
2374
tier: event.tier ?? 1
2349
tier: event.tier ?? 1,
2350
dimensionId: toDim
2375
2351
});
2376
2352
continue;
2377
2353
}
@@ -2393,7 +2369,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2393
2369
rangeTiles: event.rangeTiles ?? 0,
2394
2370
intensity: event.intensity ?? 0,
2395
2371
expiresAt: event.expiresAt ?? 0,
2396
kind: isDark ? "dark" : "light"
2372
kind: isDark ? "dark" : "light",
2373
dimensionId: toDim
2397
2374
});
2398
2375
continue;
2399
2376
}
@@ -2406,7 +2383,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2406
2383
? MessageType.spellDarkRemove
2407
2384
: MessageType.spellLightRemove,
2408
2385
tileX: event.tileX,
2409
tileY: event.tileY
2386
tileY: event.tileY,
2387
dimensionId: toDim
2410
2388
});
2411
2389
continue;
2412
2390
}
@@ -2435,7 +2413,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2435
2413
tileY: event.tileY,
2436
2414
fromTileX: event.fromTileX,
2437
2415
fromTileY: event.fromTileY,
2438
toolItemId: event.toolItemId ?? null
2416
toolItemId: event.toolItemId ?? null,
2417
dimensionId: toDim
2439
2418
});
2440
2419
}
2441
2420
else
@@ -2446,7 +2425,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2446
2425
tileX: event.tileX,
2447
2426
tileY: event.tileY,
2448
2427
fromTileX: event.fromTileX,
2449
fromTileY: event.fromTileY
2428
fromTileY: event.fromTileY,
2429
dimensionId: toDim
2450
2430
});
2451
2431
}
2452
2432
continue;
@@ -2475,6 +2455,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,
2475
2455
type: MessageType.chunkDelta,
2476
2456
chunkX: event.chunkX,
2477
2457
chunkY: event.chunkY,
2458
dimensionId: toDim,
2478
2459
tiles: [{
2479
2460
localX: event.localX,
2480
2461
localY: event.localY,
@@ -10,6 +10,7 @@ import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimens10
import { canCharacterSeeGroundItem } from "../../../shared/items/letters.js";10
import { canCharacterSeeGroundItem } from "../../../shared/items/letters.js";11
import { getConsoleSnapshot, subscribeConsole } from "../logging/consoleCapture.js";11
import { getConsoleSnapshot, subscribeConsole } from "../logging/consoleCapture.js";12
import { resolveAccount } from "../auth/routes.js";12
import { resolveAccount } from "../auth/routes.js";13
import { eventInterestKeys } from "./eventInterest.js";13
14
14
let nextSessionId = 1;15
let nextSessionId = 1;15
16
@@ -2183,47 +2184,17 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2183
2184
2184
function publishEntity (event)2185
function publishEntity (event)2185
{2186
{2186
const entityIds = [2187
const { fromKey, toKey, dimensionId: toDim } = eventInterestKeys(2187
event.entityId,2188
event,2188
event.attackerId,2189
(entityId) => simulation.entityRecord(entityId)?.dimensionId2189
event.casterId,2190
);2190
event.targetId,2191
event.targetEntityId2192
];2193
let resolvedDim = event.dimensionId != null2194
? normalizeDimensionId(event.dimensionId)2195
: null;2196
if (resolvedDim == null)2197
{2198
for (const id of entityIds)2199
{2200
if (id == null)2201
{ continue; }2202
const record = simulation.entityRecord(id);2203
if (record?.dimensionId != null)2204
{2205
resolvedDim = normalizeDimensionId(record.dimensionId);2206
break;2207
}2208
}2209
}2210
const toDim = resolvedDim ?? OVERWORLD_ID;2211
const fromDim = event.fromDimensionId != null2212
? normalizeDimensionId(event.fromDimensionId)2213
: toDim;2214
const fromKey = event.fromTileX != null2215
? chunkKey(tileToChunk(event.fromTileX), tileToChunk(event.fromTileY), fromDim)2216
: null;2217
const toKey = event.tileX != null2218
? chunkKey(tileToChunk(event.tileX), tileToChunk(event.tileY), toDim)2219
: null;2220
for (const session of sessions.values())2191
for (const session of sessions.values())2221
{2192
{2222
if (!session.entityId)2193
if (!session.entityId)2223
{ continue; }2194
{ continue; }2224
const seesFrom = fromKey ? session.entitySubscribed.has(fromKey) : false;2195
const seesFrom = fromKey != null && session.entitySubscribed.has(fromKey);2225
const seesTo = session.entitySubscribed.has(toKey);2196
const seesTo = toKey != null && session.entitySubscribed.has(toKey);2226
const seesStaticTo = session.staticSubscribed.has(toKey);2197
const seesStaticTo = toKey != null && session.staticSubscribed.has(toKey);2227
if (event.type === "entity-spawn")2198
if (event.type === "entity-spawn")2228
{2199
{2229
if (session.entityId === event.entityId || !seesTo)2200
if (session.entityId === event.entityId || !seesTo)@@ -2304,7 +2275,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2304
tileX: event.tileX,2275
tileX: event.tileX,2305
tileY: event.tileY,2276
tileY: event.tileY,2306
fromTileX: event.fromTileX,2277
fromTileX: event.fromTileX,2307
fromTileY: event.fromTileY2278
fromTileY: event.fromTileY,2279
dimensionId: toDim2308
});2280
});2309
continue;2281
continue;2310
}2282
}@@ -2323,7 +2295,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2323
durationMs: event.durationMs ?? 400,2295
durationMs: event.durationMs ?? 400,2324
trackTarget: event.trackTarget !== false,2296
trackTarget: event.trackTarget !== false,2325
shaftTint: event.shaftTint ?? null,2297
shaftTint: event.shaftTint ?? null,2326
tipTint: event.tipTint ?? null2298
tipTint: event.tipTint ?? null,2299
dimensionId: toDim2327
});2300
});2328
continue;2301
continue;2329
}2302
}@@ -2341,7 +2314,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2341
tileX: event.tileX,2314
tileX: event.tileX,2342
tileY: event.tileY,2315
tileY: event.tileY,2343
durationMs: event.durationMs ?? 2000,2316
durationMs: event.durationMs ?? 2000,2344
sprite: event.sprite ?? null2317
sprite: event.sprite ?? null,2318
dimensionId: toDim2345
});2319
});2346
continue;2320
continue;2347
}2321
}@@ -2356,7 +2330,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2356
fromTileX: event.fromTileX,2330
fromTileX: event.fromTileX,2357
fromTileY: event.fromTileY,2331
fromTileY: event.fromTileY,2358
tileX: event.tileX,2332
tileX: event.tileX,2359
tileY: event.tileY2333
tileY: event.tileY,2334
dimensionId: toDim2360
});2335
});2361
continue;2336
continue;2362
}2337
}@@ -2371,7 +2346,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2371
tileY: event.tileY,2346
tileY: event.tileY,2372
radiusTiles: event.radiusTiles ?? 1,2347
radiusTiles: event.radiusTiles ?? 1,2373
durationMs: event.durationMs ?? 500,2348
durationMs: event.durationMs ?? 500,2374
tier: event.tier ?? 12349
tier: event.tier ?? 1,2350
dimensionId: toDim2375
});2351
});2376
continue;2352
continue;2377
}2353
}@@ -2393,7 +2369,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2393
rangeTiles: event.rangeTiles ?? 0,2369
rangeTiles: event.rangeTiles ?? 0,2394
intensity: event.intensity ?? 0,2370
intensity: event.intensity ?? 0,2395
expiresAt: event.expiresAt ?? 0,2371
expiresAt: event.expiresAt ?? 0,2396
kind: isDark ? "dark" : "light"2372
kind: isDark ? "dark" : "light",2373
dimensionId: toDim2397
});2374
});2398
continue;2375
continue;2399
}2376
}@@ -2406,7 +2383,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2406
? MessageType.spellDarkRemove2383
? MessageType.spellDarkRemove2407
: MessageType.spellLightRemove,2384
: MessageType.spellLightRemove,2408
tileX: event.tileX,2385
tileX: event.tileX,2409
tileY: event.tileY2386
tileY: event.tileY,2387
dimensionId: toDim2410
});2388
});2411
continue;2389
continue;2412
}2390
}@@ -2435,7 +2413,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2435
tileY: event.tileY,2413
tileY: event.tileY,2436
fromTileX: event.fromTileX,2414
fromTileX: event.fromTileX,2437
fromTileY: event.fromTileY,2415
fromTileY: event.fromTileY,2438
toolItemId: event.toolItemId ?? null2416
toolItemId: event.toolItemId ?? null,2417
dimensionId: toDim2439
});2418
});2440
}2419
}2441
else2420
else@@ -2446,7 +2425,8 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2446
tileX: event.tileX,2425
tileX: event.tileX,2447
tileY: event.tileY,2426
tileY: event.tileY,2448
fromTileX: event.fromTileX,2427
fromTileX: event.fromTileX,2449
fromTileY: event.fromTileY2428
fromTileY: event.fromTileY,2429
dimensionId: toDim2450
});2430
});2451
}2431
}2452
continue;2432
continue;@@ -2475,6 +2455,7 @@ export function attachGateway ({ httpServer, auth, stateDb, characters, friends,2475
type: MessageType.chunkDelta,2455
type: MessageType.chunkDelta,2476
chunkX: event.chunkX,2456
chunkX: event.chunkX,2477
chunkY: event.chunkY,2457
chunkY: event.chunkY,2458
dimensionId: toDim,2478
tiles: [{2459
tiles: [{2479
localX: event.localX,2460
localX: event.localX,2480
localY: event.localY,2461
localY: event.localY,@@ -408,7 +408,8 @@ function beginGatherSwing (world, handle, entityId, position, gatherFields, now)
408
408
fromTileX: position.tileX,
409
409
fromTileY: position.tileY,
410
410
toolItemId: gatherFields.toolItemId ?? null,
411
swipe: false
411
swipe: false,
412
dimensionId: normalizeDimensionId(position.dimensionId ?? OVERWORLD_ID)
412
413
}]
413
414
};
414
415
}
@@ -1176,7 +1177,10 @@ export function stepGather (world, now)
1176
1177
fromTileX: position.tileX,
1177
1178
fromTileY: position.tileY,
1178
1179
toolItemId: gather.toolItemId ?? null,
1179
swipe: false
1180
swipe: false,
1181
dimensionId: normalizeDimensionId(
1182
gather.dimensionId ?? position.dimensionId ?? OVERWORLD_ID
1183
)
1180
1184
});
1181
1185
}
1182
1186
@@ -408,7 +408,8 @@ function beginGatherSwing (world, handle, entityId, position, gatherFields, now)408
fromTileX: position.tileX,408
fromTileX: position.tileX,409
fromTileY: position.tileY,409
fromTileY: position.tileY,410
toolItemId: gatherFields.toolItemId ?? null,410
toolItemId: gatherFields.toolItemId ?? null,411
swipe: false411
swipe: false,412
dimensionId: normalizeDimensionId(position.dimensionId ?? OVERWORLD_ID)412
}]413
}]413
};414
};414
}415
}@@ -1176,7 +1177,10 @@ export function stepGather (world, now)1176
fromTileX: position.tileX,1177
fromTileX: position.tileX,1177
fromTileY: position.tileY,1178
fromTileY: position.tileY,1178
toolItemId: gather.toolItemId ?? null,1179
toolItemId: gather.toolItemId ?? null,1179
swipe: false1180
swipe: false,1181
dimensionId: normalizeDimensionId(1182
gather.dimensionId ?? position.dimensionId ?? OVERWORLD_ID1183
)1180
});1184
});1181
}1185
}1182
1186
@@ -1,5 +1,6 @@
1
1
import { Component } from "../ecs/components.js";
2
2
import { tileKey } from "../world/coordinates.js";
3
import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";
3
4
import
4
5
{
5
6
LIGHT_FADE_MS,
@@ -12,10 +13,11 @@ import
12
13
} from "../../../shared/spells/constants.js";
13
14
14
15
/**
15
* Authoritative temporary spell lights / darkness keyed by tile.
16
* Authoritative temporary spell lights / darkness keyed by tile + dimension.
16
17
* @typedef {object} SpellLight
17
18
* @property {number} tileX
18
19
* @property {number} tileY
20
* @property {string} dimensionId
19
21
* @property {number} ownerEntityId
20
22
* @property {number} expiresAt
21
23
* @property {number} maxDurationMs
@@ -33,9 +35,10 @@ export class SpellLightRegistry
33
35
this.nextLightId = 1;
34
36
}
35
37
36
getAt (tileX, tileY)
38
getAt (tileX, tileY, dimensionId = OVERWORLD_ID)
37
39
{
38
return this.byTile.get(tileKey(tileX, tileY)) ?? null;
40
const dim = normalizeDimensionId(dimensionId);
41
return this.byTile.get(tileKey(tileX, tileY, dim)) ?? null;
39
42
}
40
43
41
44
/** @returns {{ light: SpellLight, extended: boolean }} */
@@ -47,10 +50,12 @@ export class SpellLightRegistry
47
50
baseRange = SPELL_LIGHT_RANGE_TILES,
48
51
baseIntensity = SPELL_LIGHT_INTENSITY,
49
52
kind = "light",
53
dimensionId = OVERWORLD_ID,
50
54
now = Date.now()
51
55
})
52
56
{
53
const key = tileKey(tileX, tileY);
57
const dim = normalizeDimensionId(dimensionId);
58
const key = tileKey(tileX, tileY, dim);
54
59
const addMs = Math.max(0, Math.min(LIGHT_MAX_DURATION_MS, durationMs | 0));
55
60
const range = Math.max(0, Number(baseRange) || SPELL_LIGHT_RANGE_TILES);
56
61
const intensity = Math.max(0, Number(baseIntensity)
@@ -71,6 +76,7 @@ export class SpellLightRegistry
71
76
lightId: this.nextLightId++,
72
77
tileX,
73
78
tileY,
79
dimensionId: dim,
74
80
ownerEntityId,
75
81
expiresAt: now + addMs,
76
82
maxDurationMs: addMs,
@@ -82,9 +88,10 @@ export class SpellLightRegistry
82
88
return { light, extended: false };
83
89
}
84
90
85
removeAt (tileX, tileY)
91
removeAt (tileX, tileY, dimensionId = OVERWORLD_ID)
86
92
{
87
const key = tileKey(tileX, tileY);
93
const dim = normalizeDimensionId(dimensionId);
94
const key = tileKey(tileX, tileY, dim);
88
95
const existing = this.byTile.get(key);
89
96
if (!existing)
90
97
{ return null; }
@@ -98,13 +105,15 @@ export class SpellLightRegistry
98
105
const events = [];
99
106
for (const [, light] of [...this.byTile.entries()])
100
107
{
108
const dim = normalizeDimensionId(light.dimensionId ?? OVERWORLD_ID);
101
109
if (now >= light.expiresAt)
102
110
{
103
this.byTile.delete(tileKey(light.tileX, light.tileY));
111
this.byTile.delete(tileKey(light.tileX, light.tileY, dim));
104
112
events.push({
105
113
type: light.kind === "dark" ? "spell-dark-remove" : "spell-light-remove",
106
114
tileX: light.tileX,
107
tileY: light.tileY
115
tileY: light.tileY,
116
dimensionId: dim
108
117
});
109
118
continue;
110
119
}
@@ -112,6 +121,9 @@ export class SpellLightRegistry
112
121
const ownerPos = ownerHandle != null ? world.ecs.get(ownerHandle, Component.position) : null;
113
122
if (ownerPos)
114
123
{
124
const ownerDim = normalizeDimensionId(ownerPos.dimensionId ?? OVERWORLD_ID);
125
if (ownerDim !== dim)
126
{ continue; }
115
127
const dist = Math.max(
116
128
Math.abs(ownerPos.tileX - light.tileX),
117
129
Math.abs(ownerPos.tileY - light.tileY)
@@ -132,11 +144,15 @@ export class SpellLightRegistry
132
144
return events;
133
145
}
134
146
135
listInBounds (minX, minY, maxX, maxY, now = Date.now())
147
listInBounds (minX, minY, maxX, maxY, now = Date.now(), dimensionId = null)
136
148
{
149
const dimFilter = dimensionId != null ? normalizeDimensionId(dimensionId) : null;
137
150
const out = [];
138
151
for (const light of this.byTile.values())
139
152
{
153
if (dimFilter != null
154
&& normalizeDimensionId(light.dimensionId ?? OVERWORLD_ID) !== dimFilter)
155
{ continue; }
140
156
if (light.tileX < minX || light.tileX > maxX || light.tileY < minY || light.tileY > maxY)
141
157
{ continue; }
142
158
if (now >= light.expiresAt)
@@ -156,6 +172,7 @@ export function publicSpellLight (light, now = Date.now())
156
172
return {
157
173
tileX: light.tileX,
158
174
tileY: light.tileY,
175
dimensionId: normalizeDimensionId(light.dimensionId ?? OVERWORLD_ID),
159
176
ownerEntityId: light.ownerEntityId,
160
177
remainingMs,
161
178
rangeTiles: range,
@@ -165,14 +182,18 @@ export function publicSpellLight (light, now = Date.now())
165
182
};
166
183
}
167
184
168
export function spellLightsForDynamicLighting (registry, now = Date.now())
185
export function spellLightsForDynamicLighting (registry, now = Date.now(), dimensionId = null)
169
186
{
170
187
const lights = [];
171
188
const darks = [];
172
189
if (!registry)
173
190
{ return { lights, darks }; }
191
const dimFilter = dimensionId != null ? normalizeDimensionId(dimensionId) : null;
174
192
for (const light of registry.byTile.values())
175
193
{
194
if (dimFilter != null
195
&& normalizeDimensionId(light.dimensionId ?? OVERWORLD_ID) !== dimFilter)
196
{ continue; }
176
197
if (now >= light.expiresAt)
177
198
{ continue; }
178
199
const pub = publicSpellLight(light, now);
@@ -1,5 +1,6 @@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 { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";3
import4
import4
{5
{5
LIGHT_FADE_MS,6
LIGHT_FADE_MS,@@ -12,10 +13,11 @@ import12
} from "../../../shared/spells/constants.js";13
} from "../../../shared/spells/constants.js";13
14
14
/**15
/**15
* Authoritative temporary spell lights / darkness keyed by tile.16
* Authoritative temporary spell lights / darkness keyed by tile + dimension.16
* @typedef {object} SpellLight17
* @typedef {object} SpellLight17
* @property {number} tileX18
* @property {number} tileX18
* @property {number} tileY19
* @property {number} tileY20
* @property {string} dimensionId19
* @property {number} ownerEntityId21
* @property {number} ownerEntityId20
* @property {number} expiresAt22
* @property {number} expiresAt21
* @property {number} maxDurationMs23
* @property {number} maxDurationMs@@ -33,9 +35,10 @@ export class SpellLightRegistry33
this.nextLightId = 1;35
this.nextLightId = 1;34
}36
}35
37
36
getAt (tileX, tileY)38
getAt (tileX, tileY, dimensionId = OVERWORLD_ID)37
{39
{38
return this.byTile.get(tileKey(tileX, tileY)) ?? null;40
const dim = normalizeDimensionId(dimensionId);41
return this.byTile.get(tileKey(tileX, tileY, dim)) ?? null;39
}42
}40
43
41
/** @returns {{ light: SpellLight, extended: boolean }} */44
/** @returns {{ light: SpellLight, extended: boolean }} */@@ -47,10 +50,12 @@ export class SpellLightRegistry47
baseRange = SPELL_LIGHT_RANGE_TILES,50
baseRange = SPELL_LIGHT_RANGE_TILES,48
baseIntensity = SPELL_LIGHT_INTENSITY,51
baseIntensity = SPELL_LIGHT_INTENSITY,49
kind = "light",52
kind = "light",53
dimensionId = OVERWORLD_ID,50
now = Date.now()54
now = Date.now()51
})55
})52
{56
{53
const key = tileKey(tileX, tileY);57
const dim = normalizeDimensionId(dimensionId);58
const key = tileKey(tileX, tileY, dim);54
const addMs = Math.max(0, Math.min(LIGHT_MAX_DURATION_MS, durationMs | 0));59
const addMs = Math.max(0, Math.min(LIGHT_MAX_DURATION_MS, durationMs | 0));55
const range = Math.max(0, Number(baseRange) || SPELL_LIGHT_RANGE_TILES);60
const range = Math.max(0, Number(baseRange) || SPELL_LIGHT_RANGE_TILES);56
const intensity = Math.max(0, Number(baseIntensity)61
const intensity = Math.max(0, Number(baseIntensity)@@ -71,6 +76,7 @@ export class SpellLightRegistry71
lightId: this.nextLightId++,76
lightId: this.nextLightId++,72
tileX,77
tileX,73
tileY,78
tileY,79
dimensionId: dim,74
ownerEntityId,80
ownerEntityId,75
expiresAt: now + addMs,81
expiresAt: now + addMs,76
maxDurationMs: addMs,82
maxDurationMs: addMs,@@ -82,9 +88,10 @@ export class SpellLightRegistry82
return { light, extended: false };88
return { light, extended: false };83
}89
}84
90
85
removeAt (tileX, tileY)91
removeAt (tileX, tileY, dimensionId = OVERWORLD_ID)86
{92
{87
const key = tileKey(tileX, tileY);93
const dim = normalizeDimensionId(dimensionId);94
const key = tileKey(tileX, tileY, dim);88
const existing = this.byTile.get(key);95
const existing = this.byTile.get(key);89
if (!existing)96
if (!existing)90
{ return null; }97
{ return null; }@@ -98,13 +105,15 @@ export class SpellLightRegistry98
const events = [];105
const events = [];99
for (const [, light] of [...this.byTile.entries()])106
for (const [, light] of [...this.byTile.entries()])100
{107
{108
const dim = normalizeDimensionId(light.dimensionId ?? OVERWORLD_ID);101
if (now >= light.expiresAt)109
if (now >= light.expiresAt)102
{110
{103
this.byTile.delete(tileKey(light.tileX, light.tileY));111
this.byTile.delete(tileKey(light.tileX, light.tileY, dim));104
events.push({112
events.push({105
type: light.kind === "dark" ? "spell-dark-remove" : "spell-light-remove",113
type: light.kind === "dark" ? "spell-dark-remove" : "spell-light-remove",106
tileX: light.tileX,114
tileX: light.tileX,107
tileY: light.tileY115
tileY: light.tileY,116
dimensionId: dim108
});117
});109
continue;118
continue;110
}119
}@@ -112,6 +121,9 @@ export class SpellLightRegistry112
const ownerPos = ownerHandle != null ? world.ecs.get(ownerHandle, Component.position) : null;121
const ownerPos = ownerHandle != null ? world.ecs.get(ownerHandle, Component.position) : null;113
if (ownerPos)122
if (ownerPos)114
{123
{124
const ownerDim = normalizeDimensionId(ownerPos.dimensionId ?? OVERWORLD_ID);125
if (ownerDim !== dim)126
{ continue; }115
const dist = Math.max(127
const dist = Math.max(116
Math.abs(ownerPos.tileX - light.tileX),128
Math.abs(ownerPos.tileX - light.tileX),117
Math.abs(ownerPos.tileY - light.tileY)129
Math.abs(ownerPos.tileY - light.tileY)@@ -132,11 +144,15 @@ export class SpellLightRegistry132
return events;144
return events;133
}145
}134
146
135
listInBounds (minX, minY, maxX, maxY, now = Date.now())147
listInBounds (minX, minY, maxX, maxY, now = Date.now(), dimensionId = null)136
{148
{149
const dimFilter = dimensionId != null ? normalizeDimensionId(dimensionId) : null;137
const out = [];150
const out = [];138
for (const light of this.byTile.values())151
for (const light of this.byTile.values())139
{152
{153
if (dimFilter != null154
&& normalizeDimensionId(light.dimensionId ?? OVERWORLD_ID) !== dimFilter)155
{ continue; }140
if (light.tileX < minX || light.tileX > maxX || light.tileY < minY || light.tileY > maxY)156
if (light.tileX < minX || light.tileX > maxX || light.tileY < minY || light.tileY > maxY)141
{ continue; }157
{ continue; }142
if (now >= light.expiresAt)158
if (now >= light.expiresAt)@@ -156,6 +172,7 @@ export function publicSpellLight (light, now = Date.now())156
return {172
return {157
tileX: light.tileX,173
tileX: light.tileX,158
tileY: light.tileY,174
tileY: light.tileY,175
dimensionId: normalizeDimensionId(light.dimensionId ?? OVERWORLD_ID),159
ownerEntityId: light.ownerEntityId,176
ownerEntityId: light.ownerEntityId,160
remainingMs,177
remainingMs,161
rangeTiles: range,178
rangeTiles: range,@@ -165,14 +182,18 @@ export function publicSpellLight (light, now = Date.now())165
};182
};166
}183
}167
184
168
export function spellLightsForDynamicLighting (registry, now = Date.now())185
export function spellLightsForDynamicLighting (registry, now = Date.now(), dimensionId = null)169
{186
{170
const lights = [];187
const lights = [];171
const darks = [];188
const darks = [];172
if (!registry)189
if (!registry)173
{ return { lights, darks }; }190
{ return { lights, darks }; }191
const dimFilter = dimensionId != null ? normalizeDimensionId(dimensionId) : null;174
for (const light of registry.byTile.values())192
for (const light of registry.byTile.values())175
{193
{194
if (dimFilter != null195
&& normalizeDimensionId(light.dimensionId ?? OVERWORLD_ID) !== dimFilter)196
{ continue; }176
if (now >= light.expiresAt)197
if (now >= light.expiresAt)177
{ continue; }198
{ continue; }178
const pub = publicSpellLight(light, now);199
const pub = publicSpellLight(light, now);@@ -67,6 +67,7 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da
67
67
}
68
68
casting.nextCastAt = now + SPELL_COOLDOWN_MS;
69
69
70
const dim = normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID);
70
71
if (!cast.success)
71
72
{
72
73
events.push({
@@ -76,7 +77,8 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da
76
77
fromTileX: from.tileX,
77
78
fromTileY: from.tileY,
78
79
tileX: targetPos.tileX,
79
tileY: targetPos.tileY
80
tileY: targetPos.tileY,
81
dimensionId: dim
80
82
});
81
83
return events;
82
84
}
@@ -88,7 +90,8 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da
88
90
tileY: from.tileY,
89
91
radiusTiles: castFlashRadiusTiles(def.tier),
90
92
durationMs: CAST_FLASH_MS,
91
tier: def.tier
93
tier: def.tier,
94
dimensionId: dim
92
95
});
93
96
94
97
world.pendingSpellImpacts = world.pendingSpellImpacts ?? [];
@@ -100,6 +103,7 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da
100
103
targetTileX: targetPos.tileX,
101
104
targetTileY: targetPos.tileY,
102
105
targetEntityId: targetId,
106
dimensionId: dim,
103
107
levels
104
108
});
105
109
@@ -113,7 +117,8 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da
113
117
tileX: targetPos.tileX,
114
118
tileY: targetPos.tileY,
115
119
durationMs: SPELL_PROJECTILE_MS,
116
sprite: def.projectileSprite
120
sprite: def.projectileSprite,
121
dimensionId: dim
117
122
});
118
123
return events;
119
124
}
@@ -67,6 +67,7 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da67
}67
}68
casting.nextCastAt = now + SPELL_COOLDOWN_MS;68
casting.nextCastAt = now + SPELL_COOLDOWN_MS;69
69
70
const dim = normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID);70
if (!cast.success)71
if (!cast.success)71
{72
{72
events.push({73
events.push({@@ -76,7 +77,8 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da76
fromTileX: from.tileX,77
fromTileX: from.tileX,77
fromTileY: from.tileY,78
fromTileY: from.tileY,78
tileX: targetPos.tileX,79
tileX: targetPos.tileX,79
tileY: targetPos.tileY80
tileY: targetPos.tileY,81
dimensionId: dim80
});82
});81
return events;83
return events;82
}84
}@@ -88,7 +90,8 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da88
tileY: from.tileY,90
tileY: from.tileY,89
radiusTiles: castFlashRadiusTiles(def.tier),91
radiusTiles: castFlashRadiusTiles(def.tier),90
durationMs: CAST_FLASH_MS,92
durationMs: CAST_FLASH_MS,91
tier: def.tier93
tier: def.tier,94
dimensionId: dim92
});95
});93
96
94
world.pendingSpellImpacts = world.pendingSpellImpacts ?? [];97
world.pendingSpellImpacts = world.pendingSpellImpacts ?? [];@@ -100,6 +103,7 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da100
targetTileX: targetPos.tileX,103
targetTileX: targetPos.tileX,101
targetTileY: targetPos.tileY,104
targetTileY: targetPos.tileY,102
targetEntityId: targetId,105
targetEntityId: targetId,106
dimensionId: dim,103
levels107
levels104
});108
});105
109
@@ -113,7 +117,8 @@ export function castMobAttackSpell (world, casterId, targetId, spellId, now = Da113
tileX: targetPos.tileX,117
tileX: targetPos.tileX,114
tileY: targetPos.tileY,118
tileY: targetPos.tileY,115
durationMs: SPELL_PROJECTILE_MS,119
durationMs: SPELL_PROJECTILE_MS,116
sprite: def.projectileSprite120
sprite: def.projectileSprite,121
dimensionId: dim117
});122
});118
return events;123
return events;119
}124
}@@ -532,7 +532,8 @@ function executeCast (world, sessionId, characterId, spellId, target, now)
532
532
fromTileX: from.tileX,
533
533
fromTileY: from.tileY,
534
534
tileX: target.tileX,
535
tileY: target.tileY
535
tileY: target.tileY,
536
dimensionId: normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID)
536
537
});
537
538
return { events };
538
539
}
@@ -559,7 +560,8 @@ function executeCast (world, sessionId, characterId, spellId, target, now)
559
560
tileY: from.tileY,
560
561
radiusTiles: flashRadius,
561
562
durationMs: CAST_FLASH_MS,
562
tier: def.tier
563
tier: def.tier,
564
dimensionId: normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID)
563
565
});
564
566
565
567
world.pendingSpellImpacts.push({
@@ -570,6 +572,7 @@ function executeCast (world, sessionId, characterId, spellId, target, now)
570
572
targetTileX: target.tileX,
571
573
targetTileY: target.tileY,
572
574
targetEntityId: target.targetEntityId,
575
dimensionId: normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID),
573
576
levels
574
577
});
575
578
@@ -583,7 +586,8 @@ function executeCast (world, sessionId, characterId, spellId, target, now)
583
586
tileX: target.tileX,
584
587
tileY: target.tileY,
585
588
durationMs: SPELL_PROJECTILE_MS,
586
sprite: def.projectileSprite
589
sprite: def.projectileSprite,
590
dimensionId: normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID)
587
591
});
588
592
589
593
return { events };
@@ -723,6 +727,13 @@ function applyLightOrDarkImpact (world, impact, def, effect, now)
723
727
? SPELL_LIGHT_RANGE_TILES * 0.5
724
728
: SPELL_LIGHT_RANGE_TILES;
725
729
const kind = effect === "dark" ? "dark" : "light";
730
const casterHandle = world.ecs.handleOf(impact.casterEntityId);
731
const casterPos = casterHandle != null
732
? world.ecs.get(casterHandle, Component.position)
733
: null;
734
const dim = normalizeDimensionId(
735
impact.dimensionId ?? casterPos?.dimensionId ?? OVERWORLD_ID
736
);
726
737
const { light, extended } = world.spellLights.placeOrExtend({
727
738
tileX: impact.targetTileX,
728
739
tileY: impact.targetTileY,
@@ -730,6 +741,7 @@ function applyLightOrDarkImpact (world, impact, def, effect, now)
730
741
durationMs,
731
742
baseRange,
732
743
kind,
744
dimensionId: dim,
733
745
now
734
746
});
735
747
const appear = kind === "dark"
@@ -921,6 +933,9 @@ function applyShadeImpact (world, impact, now)
921
933
const mindRoll = mindRollOf(impact);
922
934
const durationMs = Math.max(1000, mindRoll * 3 * 1000);
923
935
const casterHandle = world.ecs.handleOf(impact.casterEntityId);
936
const casterPos = casterHandle != null
937
? world.ecs.get(casterHandle, Component.position)
938
: null;
924
939
const mindLevel = impact.levels?.mind | 0 || 1;
925
940
const level = Math.max(1, Math.min(99, Math.floor(mindLevel * 0.75)));
926
941
return [{
@@ -931,7 +946,10 @@ function applyShadeImpact (world, impact, now)
931
946
tileY: impact.targetTileY,
932
947
level,
933
948
expiresAt: now + durationMs,
934
mobTypeId: "shade"
949
mobTypeId: "shade",
950
dimensionId: normalizeDimensionId(
951
impact.dimensionId ?? casterPos?.dimensionId ?? OVERWORLD_ID
952
)
935
953
}];
936
954
}
937
955
@@ -532,7 +532,8 @@ function executeCast (world, sessionId, characterId, spellId, target, now)532
fromTileX: from.tileX,532
fromTileX: from.tileX,533
fromTileY: from.tileY,533
fromTileY: from.tileY,534
tileX: target.tileX,534
tileX: target.tileX,535
tileY: target.tileY535
tileY: target.tileY,536
dimensionId: normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID)536
});537
});537
return { events };538
return { events };538
}539
}@@ -559,7 +560,8 @@ function executeCast (world, sessionId, characterId, spellId, target, now)559
tileY: from.tileY,560
tileY: from.tileY,560
radiusTiles: flashRadius,561
radiusTiles: flashRadius,561
durationMs: CAST_FLASH_MS,562
durationMs: CAST_FLASH_MS,562
tier: def.tier563
tier: def.tier,564
dimensionId: normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID)563
});565
});564
566
565
world.pendingSpellImpacts.push({567
world.pendingSpellImpacts.push({@@ -570,6 +572,7 @@ function executeCast (world, sessionId, characterId, spellId, target, now)570
targetTileX: target.tileX,572
targetTileX: target.tileX,571
targetTileY: target.tileY,573
targetTileY: target.tileY,572
targetEntityId: target.targetEntityId,574
targetEntityId: target.targetEntityId,575
dimensionId: normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID),573
levels576
levels574
});577
});575
578
@@ -583,7 +586,8 @@ function executeCast (world, sessionId, characterId, spellId, target, now)583
tileX: target.tileX,586
tileX: target.tileX,584
tileY: target.tileY,587
tileY: target.tileY,585
durationMs: SPELL_PROJECTILE_MS,588
durationMs: SPELL_PROJECTILE_MS,586
sprite: def.projectileSprite589
sprite: def.projectileSprite,590
dimensionId: normalizeDimensionId(from.dimensionId ?? OVERWORLD_ID)587
});591
});588
592
589
return { events };593
return { events };@@ -723,6 +727,13 @@ function applyLightOrDarkImpact (world, impact, def, effect, now)723
? SPELL_LIGHT_RANGE_TILES * 0.5727
? SPELL_LIGHT_RANGE_TILES * 0.5724
: SPELL_LIGHT_RANGE_TILES;728
: SPELL_LIGHT_RANGE_TILES;725
const kind = effect === "dark" ? "dark" : "light";729
const kind = effect === "dark" ? "dark" : "light";730
const casterHandle = world.ecs.handleOf(impact.casterEntityId);731
const casterPos = casterHandle != null732
? world.ecs.get(casterHandle, Component.position)733
: null;734
const dim = normalizeDimensionId(735
impact.dimensionId ?? casterPos?.dimensionId ?? OVERWORLD_ID736
);726
const { light, extended } = world.spellLights.placeOrExtend({737
const { light, extended } = world.spellLights.placeOrExtend({727
tileX: impact.targetTileX,738
tileX: impact.targetTileX,728
tileY: impact.targetTileY,739
tileY: impact.targetTileY,@@ -730,6 +741,7 @@ function applyLightOrDarkImpact (world, impact, def, effect, now)730
durationMs,741
durationMs,731
baseRange,742
baseRange,732
kind,743
kind,744
dimensionId: dim,733
now745
now734
});746
});735
const appear = kind === "dark"747
const appear = kind === "dark"@@ -921,6 +933,9 @@ function applyShadeImpact (world, impact, now)921
const mindRoll = mindRollOf(impact);933
const mindRoll = mindRollOf(impact);922
const durationMs = Math.max(1000, mindRoll * 3 * 1000);934
const durationMs = Math.max(1000, mindRoll * 3 * 1000);923
const casterHandle = world.ecs.handleOf(impact.casterEntityId);935
const casterHandle = world.ecs.handleOf(impact.casterEntityId);936
const casterPos = casterHandle != null937
? world.ecs.get(casterHandle, Component.position)938
: null;924
const mindLevel = impact.levels?.mind | 0 || 1;939
const mindLevel = impact.levels?.mind | 0 || 1;925
const level = Math.max(1, Math.min(99, Math.floor(mindLevel * 0.75)));940
const level = Math.max(1, Math.min(99, Math.floor(mindLevel * 0.75)));926
return [{941
return [{@@ -931,7 +946,10 @@ function applyShadeImpact (world, impact, now)931
tileY: impact.targetTileY,946
tileY: impact.targetTileY,932
level,947
level,933
expiresAt: now + durationMs,948
expiresAt: now + durationMs,934
mobTypeId: "shade"949
mobTypeId: "shade",950
dimensionId: normalizeDimensionId(951
impact.dimensionId ?? casterPos?.dimensionId ?? OVERWORLD_ID952
)935
}];953
}];936
}954
}937
955
@@ -132,11 +132,15 @@ test("melee combat ticks in a non-overworld dimension", () =>
132
132
combat.nextSwingAt = harness.now();
133
133
134
134
const events = stepCombat(world, harness.now());
135
const combatFx = events.find((event) =>
136
event.type === "combat-swing" || event.type === "combat-hit"
137
|| event.type === "combat-miss" || event.type === "combat-block"
138
);
135
139
assert.ok(
136
events.some((event) => event.type === "combat-swing" || event.type === "combat-hit"
137
|| event.type === "combat-miss" || event.type === "combat-block"),
140
combatFx,
138
141
`expected combat resolution in cave, got ${events.map((e) => e.type).join(",") || "none"}`
139
142
);
143
assert.equal(combatFx.dimensionId, CAVE_ID);
140
144
141
145
stepAggression(world, harness.now());
142
146
}
@@ -132,11 +132,15 @@ test("melee combat ticks in a non-overworld dimension", () =>132
combat.nextSwingAt = harness.now();132
combat.nextSwingAt = harness.now();133
133
134
const events = stepCombat(world, harness.now());134
const events = stepCombat(world, harness.now());135
const combatFx = events.find((event) =>136
event.type === "combat-swing" || event.type === "combat-hit"137
|| event.type === "combat-miss" || event.type === "combat-block"138
);135
assert.ok(139
assert.ok(136
events.some((event) => event.type === "combat-swing" || event.type === "combat-hit"140
combatFx,137
|| event.type === "combat-miss" || event.type === "combat-block"),138
`expected combat resolution in cave, got ${events.map((e) => e.type).join(",") || "none"}`141
`expected combat resolution in cave, got ${events.map((e) => e.type).join(",") || "none"}`139
);142
);143
assert.equal(combatFx.dimensionId, CAVE_ID);140
144
141
stepAggression(world, harness.now());145
stepAggression(world, harness.now());142
}146
}@@ -0,0 +1,70 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { OVERWORLD_ID } from "../../shared/world/dimensions.js";
4
import { chunkKey, tileToChunk } from "../src/world/coordinates.js";
5
import { eventInterestKeys, resolveEventDimensionId } from "../src/gateway/eventInterest.js";
6
7
const CAVE = "cave-fx";
8
9
test("resolveEventDimensionId prefers event.dimensionId then attacker/caster ids", () =>
10
{
11
assert.equal(
12
resolveEventDimensionId({ dimensionId: CAVE }, () => OVERWORLD_ID),
13
CAVE
14
);
15
assert.equal(
16
resolveEventDimensionId(
17
{ type: "combat-swing", attackerId: 7 },
18
(id) => (id === 7 ? CAVE : OVERWORLD_ID)
19
),
20
CAVE
21
);
22
assert.equal(
23
resolveEventDimensionId(
24
{ type: "spell-projectile", casterId: 3 },
25
(id) => (id === 3 ? CAVE : null)
26
),
27
CAVE
28
);
29
assert.equal(
30
resolveEventDimensionId({ type: "combat-swing", attackerId: 1 }, () => null),
31
OVERWORLD_ID
32
);
33
});
34
35
test("eventInterestKeys scope combat and chunk-delta to the event dimension", () =>
36
{
37
const swing = eventInterestKeys(
38
{
39
type: "combat-swing",
40
attackerId: 1,
41
fromTileX: 8,
42
fromTileY: 8,
43
tileX: 9,
44
tileY: 8,
45
dimensionId: CAVE
46
},
47
() => OVERWORLD_ID
48
);
49
assert.equal(swing.dimensionId, CAVE);
50
assert.equal(
51
swing.toKey,
52
chunkKey(tileToChunk(9), tileToChunk(8), CAVE)
53
);
54
assert.notEqual(
55
swing.toKey,
56
chunkKey(tileToChunk(9), tileToChunk(8), OVERWORLD_ID)
57
);
58
59
const delta = eventInterestKeys(
60
{
61
type: "chunk-delta",
62
chunkX: 0,
63
chunkY: 0,
64
dimensionId: CAVE
65
},
66
() => OVERWORLD_ID
67
);
68
assert.equal(delta.toKey, chunkKey(0, 0, CAVE));
69
assert.equal(delta.fromKey, null);
70
});
@@ -0,0 +1,70 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { OVERWORLD_ID } from "../../shared/world/dimensions.js";4
import { chunkKey, tileToChunk } from "../src/world/coordinates.js";5
import { eventInterestKeys, resolveEventDimensionId } from "../src/gateway/eventInterest.js";6
7
const CAVE = "cave-fx";8
9
test("resolveEventDimensionId prefers event.dimensionId then attacker/caster ids", () =>10
{11
assert.equal(12
resolveEventDimensionId({ dimensionId: CAVE }, () => OVERWORLD_ID),13
CAVE14
);15
assert.equal(16
resolveEventDimensionId(17
{ type: "combat-swing", attackerId: 7 },18
(id) => (id === 7 ? CAVE : OVERWORLD_ID)19
),20
CAVE21
);22
assert.equal(23
resolveEventDimensionId(24
{ type: "spell-projectile", casterId: 3 },25
(id) => (id === 3 ? CAVE : null)26
),27
CAVE28
);29
assert.equal(30
resolveEventDimensionId({ type: "combat-swing", attackerId: 1 }, () => null),31
OVERWORLD_ID32
);33
});34
35
test("eventInterestKeys scope combat and chunk-delta to the event dimension", () =>36
{37
const swing = eventInterestKeys(38
{39
type: "combat-swing",40
attackerId: 1,41
fromTileX: 8,42
fromTileY: 8,43
tileX: 9,44
tileY: 8,45
dimensionId: CAVE46
},47
() => OVERWORLD_ID48
);49
assert.equal(swing.dimensionId, CAVE);50
assert.equal(51
swing.toKey,52
chunkKey(tileToChunk(9), tileToChunk(8), CAVE)53
);54
assert.notEqual(55
swing.toKey,56
chunkKey(tileToChunk(9), tileToChunk(8), OVERWORLD_ID)57
);58
59
const delta = eventInterestKeys(60
{61
type: "chunk-delta",62
chunkX: 0,63
chunkY: 0,64
dimensionId: CAVE65
},66
() => OVERWORLD_ID67
);68
assert.equal(delta.toKey, chunkKey(0, 0, CAVE));69
assert.equal(delta.fromKey, null);70
});