BlueGit

timfa questward

Files

questward / shared / navigation / chunkPresence.js

chunkPresence.js

chunkPresence.js 1.2 KiB Download Raw
1import { OVERWORLD_ID } from "../world/dimensions.js";
2import { CHUNK_AGGRO_PEACE_MS } from "../combat/combatLevel.js";
3
4export { CHUNK_AGGRO_PEACE_MS };
5
6/** @returns {object} New or updated chunk-presence record. */
7export function updateChunkPresence (presence, tileX, tileY, dimensionId, now, tileToChunk)
8{
9 const chunkX = tileToChunk(tileX);
10 const chunkY = tileToChunk(tileY);
11 const dim = dimensionId ?? OVERWORLD_ID;
12 if (!presence)
13 {
14 return { chunkX, chunkY, dimensionId: dim, sinceMs: now };
15 }
16 if (
17 presence.chunkX !== chunkX
18 || presence.chunkY !== chunkY
19 || (presence.dimensionId ?? OVERWORLD_ID) !== dim
20 )
21 {
22 presence.chunkX = chunkX;
23 presence.chunkY = chunkY;
24 presence.dimensionId = dim;
25 presence.sinceMs = now;
26 }
27 return presence;
28}
29
30/** True when the player has stayed in the current chunk long enough to ignore auto-aggro. */
31export function chunkPeaceAggressionImmunity (presence, tileX, tileY, dimensionId, now, tileToChunk)
32{
33 if (!presence || now - presence.sinceMs < CHUNK_AGGRO_PEACE_MS)
34 { return false; }
35 const dim = dimensionId ?? OVERWORLD_ID;
36 return presence.chunkX === tileToChunk(tileX)
37 && presence.chunkY === tileToChunk(tileY)
38 && (presence.dimensionId ?? OVERWORLD_ID) === dim;
39}