Add killMobFromSpawner quest condition and stamp more dimensionIds.
New condition kind filters kills by mob type + spawner id (editor combobox with red blink for unknown ids). Also stamp dimensionId on mob-killed, replication spawn/move, and courier despawns so other-dim interest stays correct.
@@ -137,6 +137,14 @@ export function renderConditionSet (when, onChange, ctx = {})
137
137
bump(false);
138
138
}));
139
139
}
140
else if (cond.kind === ConditionKind.killMobFromSpawner)
141
{
142
row.append(killMobFromSpawnerConditionFields(cond, ctx, () =>
143
{
144
set.all[index].condition = cond;
145
bump(false);
146
}));
147
}
140
148
else if (cond.kind === ConditionKind.atTile)
141
149
{
142
150
row.append(atTileConditionFields(cond, ctx, () =>
@@ -488,6 +496,90 @@ function killCountConditionFields (cond, onChanged)
488
496
return wrap;
489
497
}
490
498
499
/** Mob + spawner combobox + count for killMobFromSpawner conditions. */
500
function killMobFromSpawnerConditionFields (cond, ctx, onChanged)
501
{
502
const wrap = document.createElement("div");
503
wrap.className = "quest-condition-pair";
504
const mobSelect = document.createElement("select");
505
for (const def of listSpawnableMobTypes())
506
{
507
const opt = document.createElement("option");
508
opt.value = def.mobTypeId;
509
opt.textContent = def.displayName ?? def.mobTypeId;
510
if (def.mobTypeId === cond.mobTypeId)
511
{ opt.selected = true; }
512
mobSelect.append(opt);
513
}
514
if (cond.mobTypeId && ![...mobSelect.options].some((o) => o.value === cond.mobTypeId))
515
{
516
const missing = document.createElement("option");
517
missing.value = cond.mobTypeId;
518
missing.textContent = `${cond.mobTypeId} (missing)`;
519
missing.selected = true;
520
mobSelect.append(missing);
521
}
522
if (!cond.mobTypeId && mobSelect.options.length)
523
{
524
cond.mobTypeId = mobSelect.options[0].value;
525
mobSelect.options[0].selected = true;
526
}
527
528
const spawnerRoot = document.createElement("div");
529
spawnerRoot.style.minWidth = "10rem";
530
const combo = createDimensionCombobox({
531
root: spawnerRoot,
532
allowCreate: false,
533
allowUnknown: true,
534
placeholder: "Spawner id…",
535
emptyLabel: "No spawners for this mob",
536
onSelect (id)
537
{
538
cond.spawnerId = id || "";
539
onChanged();
540
}
541
});
542
543
function refreshSpawnerOptions ()
544
{
545
const rows = typeof ctx.getSpawnerOptions === "function"
546
? (ctx.getSpawnerOptions(cond.mobTypeId) ?? [])
547
: [];
548
combo.setOptions(rows.map((row) => ({
549
id: row.spawnerId,
550
label: row.spawnerId,
551
hint: row.mobTypeId
552
? `${row.mobTypeId} @ ${row.tileX},${row.tileY}`
553
: `${row.tileX},${row.tileY}`
554
})));
555
combo.setValue(cond.spawnerId || null);
556
}
557
558
const qty = document.createElement("input");
559
qty.type = "number";
560
qty.min = "1";
561
qty.step = "1";
562
qty.style.width = "5rem";
563
qty.value = String(Math.max(1, Number(cond.count) || 1));
564
qty.title = "Kill count";
565
566
mobSelect.addEventListener("change", () =>
567
{
568
cond.mobTypeId = mobSelect.value || undefined;
569
refreshSpawnerOptions();
570
onChanged();
571
});
572
qty.addEventListener("input", () =>
573
{
574
cond.count = Math.max(1, Number(qty.value) || 1);
575
onChanged();
576
});
577
578
refreshSpawnerOptions();
579
wrap.append(mobSelect, spawnerRoot, qty);
580
return wrap;
581
}
582
491
583
/** Dialogue picker + step-id dropdown from that tree. */
492
584
function dialogueHeardConditionFields (cond, dialogueList, onChanged)
493
585
{
@@ -778,6 +870,8 @@ function defaultCondition (kind)
778
870
return { kind, dialogueId: "", trigger: "" };
779
871
case ConditionKind.killCount:
780
872
return { kind, mobTypeId: "deer", count: 1 };
873
case ConditionKind.killMobFromSpawner:
874
return { kind, mobTypeId: "deer", spawnerId: "", count: 1 };
781
875
case ConditionKind.atTile:
782
876
case ConditionKind.nearTile:
783
877
return { kind, dimensionId: OVERWORLD_ID, tileX: 0, tileY: 0, ...(kind === ConditionKind.nearTile ? { range: 1 } : {}) };
@@ -137,6 +137,14 @@ export function renderConditionSet (when, onChange, ctx = {})137
bump(false);137
bump(false);138
}));138
}));139
}139
}140
else if (cond.kind === ConditionKind.killMobFromSpawner)141
{142
row.append(killMobFromSpawnerConditionFields(cond, ctx, () =>143
{144
set.all[index].condition = cond;145
bump(false);146
}));147
}140
else if (cond.kind === ConditionKind.atTile)148
else if (cond.kind === ConditionKind.atTile)141
{149
{142
row.append(atTileConditionFields(cond, ctx, () =>150
row.append(atTileConditionFields(cond, ctx, () =>@@ -488,6 +496,90 @@ function killCountConditionFields (cond, onChanged)488
return wrap;496
return wrap;489
}497
}490
498
499
/** Mob + spawner combobox + count for killMobFromSpawner conditions. */500
function killMobFromSpawnerConditionFields (cond, ctx, onChanged)501
{502
const wrap = document.createElement("div");503
wrap.className = "quest-condition-pair";504
const mobSelect = document.createElement("select");505
for (const def of listSpawnableMobTypes())506
{507
const opt = document.createElement("option");508
opt.value = def.mobTypeId;509
opt.textContent = def.displayName ?? def.mobTypeId;510
if (def.mobTypeId === cond.mobTypeId)511
{ opt.selected = true; }512
mobSelect.append(opt);513
}514
if (cond.mobTypeId && ![...mobSelect.options].some((o) => o.value === cond.mobTypeId))515
{516
const missing = document.createElement("option");517
missing.value = cond.mobTypeId;518
missing.textContent = `${cond.mobTypeId} (missing)`;519
missing.selected = true;520
mobSelect.append(missing);521
}522
if (!cond.mobTypeId && mobSelect.options.length)523
{524
cond.mobTypeId = mobSelect.options[0].value;525
mobSelect.options[0].selected = true;526
}527
528
const spawnerRoot = document.createElement("div");529
spawnerRoot.style.minWidth = "10rem";530
const combo = createDimensionCombobox({531
root: spawnerRoot,532
allowCreate: false,533
allowUnknown: true,534
placeholder: "Spawner id…",535
emptyLabel: "No spawners for this mob",536
onSelect (id)537
{538
cond.spawnerId = id || "";539
onChanged();540
}541
});542
543
function refreshSpawnerOptions ()544
{545
const rows = typeof ctx.getSpawnerOptions === "function"546
? (ctx.getSpawnerOptions(cond.mobTypeId) ?? [])547
: [];548
combo.setOptions(rows.map((row) => ({549
id: row.spawnerId,550
label: row.spawnerId,551
hint: row.mobTypeId552
? `${row.mobTypeId} @ ${row.tileX},${row.tileY}`553
: `${row.tileX},${row.tileY}`554
})));555
combo.setValue(cond.spawnerId || null);556
}557
558
const qty = document.createElement("input");559
qty.type = "number";560
qty.min = "1";561
qty.step = "1";562
qty.style.width = "5rem";563
qty.value = String(Math.max(1, Number(cond.count) || 1));564
qty.title = "Kill count";565
566
mobSelect.addEventListener("change", () =>567
{568
cond.mobTypeId = mobSelect.value || undefined;569
refreshSpawnerOptions();570
onChanged();571
});572
qty.addEventListener("input", () =>573
{574
cond.count = Math.max(1, Number(qty.value) || 1);575
onChanged();576
});577
578
refreshSpawnerOptions();579
wrap.append(mobSelect, spawnerRoot, qty);580
return wrap;581
}582
491
/** Dialogue picker + step-id dropdown from that tree. */583
/** Dialogue picker + step-id dropdown from that tree. */492
function dialogueHeardConditionFields (cond, dialogueList, onChanged)584
function dialogueHeardConditionFields (cond, dialogueList, onChanged)493
{585
{@@ -778,6 +870,8 @@ function defaultCondition (kind)778
return { kind, dialogueId: "", trigger: "" };870
return { kind, dialogueId: "", trigger: "" };779
case ConditionKind.killCount:871
case ConditionKind.killCount:780
return { kind, mobTypeId: "deer", count: 1 };872
return { kind, mobTypeId: "deer", count: 1 };873
case ConditionKind.killMobFromSpawner:874
return { kind, mobTypeId: "deer", spawnerId: "", count: 1 };781
case ConditionKind.atTile:875
case ConditionKind.atTile:782
case ConditionKind.nearTile:876
case ConditionKind.nearTile:783
return { kind, dimensionId: OVERWORLD_ID, tileX: 0, tileY: 0, ...(kind === ConditionKind.nearTile ? { range: 1 } : {}) };877
return { kind, dimensionId: OVERWORLD_ID, tileX: 0, tileY: 0, ...(kind === ConditionKind.nearTile ? { range: 1 } : {}) };@@ -15,7 +15,8 @@ export function initDialoguesModal ({
15
15
MessageType,
16
16
describeWorldTile = null,
17
17
centerEditorOnTile = null,
18
getDimensionOptions = null
18
getDimensionOptions = null,
19
getSpawnerOptions = null
19
20
})
20
21
{
21
22
const backdrop = document.getElementById("dialogues-backdrop");
@@ -70,7 +71,8 @@ export function initDialoguesModal ({
70
71
dialogues,
71
72
describeWorldTile,
72
73
centerEditorOnTile,
73
getDimensionOptions
74
getDimensionOptions,
75
getSpawnerOptions
74
76
};
75
77
}
76
78
@@ -15,7 +15,8 @@ export function initDialoguesModal ({15
MessageType,15
MessageType,16
describeWorldTile = null,16
describeWorldTile = null,17
centerEditorOnTile = null,17
centerEditorOnTile = null,18
getDimensionOptions = null18
getDimensionOptions = null,19
getSpawnerOptions = null19
})20
})20
{21
{21
const backdrop = document.getElementById("dialogues-backdrop");22
const backdrop = document.getElementById("dialogues-backdrop");@@ -70,7 +71,8 @@ export function initDialoguesModal ({70
dialogues,71
dialogues,71
describeWorldTile,72
describeWorldTile,72
centerEditorOnTile,73
centerEditorOnTile,73
getDimensionOptions74
getDimensionOptions,75
getSpawnerOptions74
};76
};75
}77
}76
78
@@ -5,7 +5,9 @@
5
5
export function createDimensionCombobox ({
6
6
root,
7
7
allowCreate = false,
8
allowUnknown = false,
8
9
placeholder = "Dimension…",
10
emptyLabel = "No matches",
9
11
onSelect,
10
12
onCreate
11
13
})
@@ -41,6 +43,25 @@ export function createDimensionCombobox ({
41
43
let selectedId = null;
42
44
let open = false;
43
45
46
function isKnownId (id)
47
{
48
return !!id && options.some((opt) => opt.id === id);
49
}
50
51
function updateValidity ()
52
{
53
const invalid = allowUnknown && !!selectedId && !isKnownId(selectedId);
54
root.classList.toggle("dim-combo-invalid", invalid);
55
if (invalid)
56
{
57
root.classList.remove("dim-combo-invalid-pulse");
58
void root.offsetWidth;
59
root.classList.add("dim-combo-invalid-pulse");
60
}
61
else
62
{ root.classList.remove("dim-combo-invalid-pulse"); }
63
}
64
44
65
function selectedOption ()
45
66
{
46
67
return options.find((opt) => opt.id === selectedId) ?? null;
@@ -147,7 +168,7 @@ export function createDimensionCombobox ({
147
168
{
148
169
const empty = document.createElement("li");
149
170
empty.className = "dim-combo-empty";
150
empty.textContent = "No dimensions";
171
empty.textContent = emptyLabel;
151
172
list.append(empty);
152
173
}
153
174
}
@@ -156,6 +177,7 @@ export function createDimensionCombobox ({
156
177
{
157
178
selectedId = id;
158
179
syncInputFromSelection();
180
updateValidity();
159
181
setOpen(false);
160
182
onSelect?.(id);
161
183
}
@@ -225,13 +247,45 @@ export function createDimensionCombobox ({
225
247
}
226
248
}
227
249
});
250
input.addEventListener("input", () =>
251
{
252
if (!allowUnknown)
253
{ return; }
254
const typed = input.value.trim();
255
const exact = exactMatchId(typed);
256
selectedId = exact ?? (typed || null);
257
updateValidity();
258
onSelect?.(selectedId);
259
});
228
260
input.addEventListener("blur", () =>
229
261
{
230
262
window.setTimeout(() =>
231
263
{
232
264
if (!root.contains(document.activeElement))
233
265
{
234
syncInputFromSelection();
266
if (allowUnknown)
267
{
268
const typed = input.value.trim();
269
const exact = exactMatchId(typed);
270
if (exact)
271
{ choose(exact); }
272
else if (typed)
273
{
274
selectedId = typed;
275
input.value = typed;
276
updateValidity();
277
onSelect?.(typed);
278
}
279
else
280
{
281
selectedId = null;
282
input.value = "";
283
updateValidity();
284
onSelect?.(null);
285
}
286
}
287
else
288
{ syncInputFromSelection(); }
235
289
setOpen(false);
236
290
}
237
291
}, 0);
@@ -241,9 +295,10 @@ export function createDimensionCombobox ({
241
295
setOptions (nextOptions)
242
296
{
243
297
options = Array.isArray(nextOptions) ? nextOptions.slice() : [];
244
if (selectedId && !options.some((opt) => opt.id === selectedId))
298
if (selectedId && !options.some((opt) => opt.id === selectedId) && !allowUnknown)
245
299
{ selectedId = options[0]?.id ?? null; }
246
300
syncInputFromSelection();
301
updateValidity();
247
302
if (open)
248
303
{ renderList(); }
249
304
},
@@ -251,6 +306,7 @@ export function createDimensionCombobox ({
251
306
{
252
307
selectedId = id;
253
308
syncInputFromSelection();
309
updateValidity();
254
310
if (open)
255
311
{ renderList(); }
256
312
},
@@ -5,7 +5,9 @@5
export function createDimensionCombobox ({5
export function createDimensionCombobox ({6
root,6
root,7
allowCreate = false,7
allowCreate = false,8
allowUnknown = false,8
placeholder = "Dimension…",9
placeholder = "Dimension…",10
emptyLabel = "No matches",9
onSelect,11
onSelect,10
onCreate12
onCreate11
})13
})@@ -41,6 +43,25 @@ export function createDimensionCombobox ({41
let selectedId = null;43
let selectedId = null;42
let open = false;44
let open = false;43
45
46
function isKnownId (id)47
{48
return !!id && options.some((opt) => opt.id === id);49
}50
51
function updateValidity ()52
{53
const invalid = allowUnknown && !!selectedId && !isKnownId(selectedId);54
root.classList.toggle("dim-combo-invalid", invalid);55
if (invalid)56
{57
root.classList.remove("dim-combo-invalid-pulse");58
void root.offsetWidth;59
root.classList.add("dim-combo-invalid-pulse");60
}61
else62
{ root.classList.remove("dim-combo-invalid-pulse"); }63
}64
44
function selectedOption ()65
function selectedOption ()45
{66
{46
return options.find((opt) => opt.id === selectedId) ?? null;67
return options.find((opt) => opt.id === selectedId) ?? null;@@ -147,7 +168,7 @@ export function createDimensionCombobox ({147
{168
{148
const empty = document.createElement("li");169
const empty = document.createElement("li");149
empty.className = "dim-combo-empty";170
empty.className = "dim-combo-empty";150
empty.textContent = "No dimensions";171
empty.textContent = emptyLabel;151
list.append(empty);172
list.append(empty);152
}173
}153
}174
}@@ -156,6 +177,7 @@ export function createDimensionCombobox ({156
{177
{157
selectedId = id;178
selectedId = id;158
syncInputFromSelection();179
syncInputFromSelection();180
updateValidity();159
setOpen(false);181
setOpen(false);160
onSelect?.(id);182
onSelect?.(id);161
}183
}@@ -225,13 +247,45 @@ export function createDimensionCombobox ({225
}247
}226
}248
}227
});249
});250
input.addEventListener("input", () =>251
{252
if (!allowUnknown)253
{ return; }254
const typed = input.value.trim();255
const exact = exactMatchId(typed);256
selectedId = exact ?? (typed || null);257
updateValidity();258
onSelect?.(selectedId);259
});228
input.addEventListener("blur", () =>260
input.addEventListener("blur", () =>229
{261
{230
window.setTimeout(() =>262
window.setTimeout(() =>231
{263
{232
if (!root.contains(document.activeElement))264
if (!root.contains(document.activeElement))233
{265
{234
syncInputFromSelection();266
if (allowUnknown)267
{268
const typed = input.value.trim();269
const exact = exactMatchId(typed);270
if (exact)271
{ choose(exact); }272
else if (typed)273
{274
selectedId = typed;275
input.value = typed;276
updateValidity();277
onSelect?.(typed);278
}279
else280
{281
selectedId = null;282
input.value = "";283
updateValidity();284
onSelect?.(null);285
}286
}287
else288
{ syncInputFromSelection(); }235
setOpen(false);289
setOpen(false);236
}290
}237
}, 0);291
}, 0);@@ -241,9 +295,10 @@ export function createDimensionCombobox ({241
setOptions (nextOptions)295
setOptions (nextOptions)242
{296
{243
options = Array.isArray(nextOptions) ? nextOptions.slice() : [];297
options = Array.isArray(nextOptions) ? nextOptions.slice() : [];244
if (selectedId && !options.some((opt) => opt.id === selectedId))298
if (selectedId && !options.some((opt) => opt.id === selectedId) && !allowUnknown)245
{ selectedId = options[0]?.id ?? null; }299
{ selectedId = options[0]?.id ?? null; }246
syncInputFromSelection();300
syncInputFromSelection();301
updateValidity();247
if (open)302
if (open)248
{ renderList(); }303
{ renderList(); }249
},304
},@@ -251,6 +306,7 @@ export function createDimensionCombobox ({251
{306
{252
selectedId = id;307
selectedId = id;253
syncInputFromSelection();308
syncInputFromSelection();309
updateValidity();254
if (open)310
if (open)255
{ renderList(); }311
{ renderList(); }256
},312
},@@ -1934,6 +1934,58 @@ async function main ()
1934
1934
getDimensionRecord: (id) => dimensionsById.get(id) ?? null,
1935
1935
isOverworld
1936
1936
});
1937
1938
function collectEditorSpawners ()
1939
{
1940
const byId = new Map();
1941
function add (row)
1942
{
1943
const id = String(row?.spawnerId ?? "").trim();
1944
if (!id)
1945
{ return; }
1946
byId.set(id, {
1947
spawnerId: id,
1948
mobTypeId: row.mobTypeId ?? null,
1949
dimensionId: row.dimensionId ?? OVERWORLD_ID,
1950
tileX: row.tileX | 0,
1951
tileY: row.tileY | 0
1952
});
1953
}
1954
for (const row of questsModal?.getServerSpawners?.() ?? [])
1955
{ add(row); }
1956
function addChunk (cx, cy, dim, spawners)
1957
{
1958
for (const entry of spawners ?? [])
1959
{
1960
const config = normalizeSpawnerConfig(entry.config, entry.config?.spawnerId);
1961
add({
1962
spawnerId: config.spawnerId,
1963
mobTypeId: config.mobTypeId,
1964
dimensionId: dim,
1965
tileX: cx * CHUNK_SIZE + (entry.localX | 0),
1966
tileY: cy * CHUNK_SIZE + (entry.localY | 0)
1967
});
1968
}
1969
}
1970
if (draft)
1971
{ addChunk(chunkX, chunkY, selectedDimensionId, draft.spawners); }
1972
for (const [key, data] of dirtyNeighborChunks)
1973
{
1974
const [cx, cy] = key.split(",").map(Number);
1975
if (!Number.isFinite(cx) || !Number.isFinite(cy))
1976
{ continue; }
1977
addChunk(cx, cy, selectedDimensionId, data.spawners);
1978
}
1979
for (const [key, spawners] of neighborSpawnersByChunk)
1980
{
1981
const [cx, cy] = key.split(",").map(Number);
1982
if (!Number.isFinite(cx) || !Number.isFinite(cy))
1983
{ continue; }
1984
addChunk(cx, cy, selectedDimensionId, spawners);
1985
}
1986
return [...byId.values()].sort((a, b) => a.spawnerId.localeCompare(b.spawnerId));
1987
}
1988
1937
1989
questsModal = initQuestsModal({
1938
1990
socket,
1939
1991
MessageType,
@@ -1944,7 +1996,10 @@ async function main ()
1944
1996
label: dim.displayName || dim.dimensionId,
1945
1997
disabled: dim.deletedAt != null,
1946
1998
hint: dim.deletedAt != null ? "soft-deleted" : null
1947
}))
1999
})),
2000
getSpawnerOptions: (mobTypeId) => collectEditorSpawners().filter((row) =>
2001
!mobTypeId || String(row.mobTypeId) === String(mobTypeId)
2002
)
1948
2003
});
1949
2004
dialoguesModal = initDialoguesModal({
1950
2005
socket,
@@ -1956,7 +2011,10 @@ async function main ()
1956
2011
label: dim.displayName || dim.dimensionId,
1957
2012
disabled: dim.deletedAt != null,
1958
2013
hint: dim.deletedAt != null ? "soft-deleted" : null
1959
}))
2014
})),
2015
getSpawnerOptions: (mobTypeId) => collectEditorSpawners().filter((row) =>
2016
!mobTypeId || String(row.mobTypeId) === String(mobTypeId)
2017
)
1960
2018
});
1961
2019
giftsModal = initGiftsModal({ socket, MessageType });
1962
2020
initSidePanelTabs();
@@ -1934,6 +1934,58 @@ async function main ()1934
getDimensionRecord: (id) => dimensionsById.get(id) ?? null,1934
getDimensionRecord: (id) => dimensionsById.get(id) ?? null,1935
isOverworld1935
isOverworld1936
});1936
});1937
1938
function collectEditorSpawners ()1939
{1940
const byId = new Map();1941
function add (row)1942
{1943
const id = String(row?.spawnerId ?? "").trim();1944
if (!id)1945
{ return; }1946
byId.set(id, {1947
spawnerId: id,1948
mobTypeId: row.mobTypeId ?? null,1949
dimensionId: row.dimensionId ?? OVERWORLD_ID,1950
tileX: row.tileX | 0,1951
tileY: row.tileY | 01952
});1953
}1954
for (const row of questsModal?.getServerSpawners?.() ?? [])1955
{ add(row); }1956
function addChunk (cx, cy, dim, spawners)1957
{1958
for (const entry of spawners ?? [])1959
{1960
const config = normalizeSpawnerConfig(entry.config, entry.config?.spawnerId);1961
add({1962
spawnerId: config.spawnerId,1963
mobTypeId: config.mobTypeId,1964
dimensionId: dim,1965
tileX: cx * CHUNK_SIZE + (entry.localX | 0),1966
tileY: cy * CHUNK_SIZE + (entry.localY | 0)1967
});1968
}1969
}1970
if (draft)1971
{ addChunk(chunkX, chunkY, selectedDimensionId, draft.spawners); }1972
for (const [key, data] of dirtyNeighborChunks)1973
{1974
const [cx, cy] = key.split(",").map(Number);1975
if (!Number.isFinite(cx) || !Number.isFinite(cy))1976
{ continue; }1977
addChunk(cx, cy, selectedDimensionId, data.spawners);1978
}1979
for (const [key, spawners] of neighborSpawnersByChunk)1980
{1981
const [cx, cy] = key.split(",").map(Number);1982
if (!Number.isFinite(cx) || !Number.isFinite(cy))1983
{ continue; }1984
addChunk(cx, cy, selectedDimensionId, spawners);1985
}1986
return [...byId.values()].sort((a, b) => a.spawnerId.localeCompare(b.spawnerId));1987
}1988
1937
questsModal = initQuestsModal({1989
questsModal = initQuestsModal({1938
socket,1990
socket,1939
MessageType,1991
MessageType,@@ -1944,7 +1996,10 @@ async function main ()1944
label: dim.displayName || dim.dimensionId,1996
label: dim.displayName || dim.dimensionId,1945
disabled: dim.deletedAt != null,1997
disabled: dim.deletedAt != null,1946
hint: dim.deletedAt != null ? "soft-deleted" : null1998
hint: dim.deletedAt != null ? "soft-deleted" : null1947
}))1999
})),2000
getSpawnerOptions: (mobTypeId) => collectEditorSpawners().filter((row) =>2001
!mobTypeId || String(row.mobTypeId) === String(mobTypeId)2002
)1948
});2003
});1949
dialoguesModal = initDialoguesModal({2004
dialoguesModal = initDialoguesModal({1950
socket,2005
socket,@@ -1956,7 +2011,10 @@ async function main ()1956
label: dim.displayName || dim.dimensionId,2011
label: dim.displayName || dim.dimensionId,1957
disabled: dim.deletedAt != null,2012
disabled: dim.deletedAt != null,1958
hint: dim.deletedAt != null ? "soft-deleted" : null2013
hint: dim.deletedAt != null ? "soft-deleted" : null1959
}))2014
})),2015
getSpawnerOptions: (mobTypeId) => collectEditorSpawners().filter((row) =>2016
!mobTypeId || String(row.mobTypeId) === String(mobTypeId)2017
)1960
});2018
});1961
giftsModal = initGiftsModal({ socket, MessageType });2019
giftsModal = initGiftsModal({ socket, MessageType });1962
initSidePanelTabs();2020
initSidePanelTabs();@@ -9,7 +9,8 @@ export function initQuestsModal ({
9
9
MessageType,
10
10
describeWorldTile = null,
11
11
centerEditorOnTile = null,
12
getDimensionOptions = null
12
getDimensionOptions = null,
13
getSpawnerOptions = null
13
14
})
14
15
{
15
16
const backdrop = document.getElementById("quests-backdrop");
@@ -24,6 +25,8 @@ export function initQuestsModal ({
24
25
let quests = [];
25
26
/** @type {ReturnType<typeof normalizeDialogueTree>[]} */
26
27
let dialogues = [];
28
/** @type {{ spawnerId: string, mobTypeId?: string, dimensionId?: string, tileX?: number, tileY?: number }[]} */
29
let serverSpawners = [];
27
30
/** @type {ReturnType<typeof normalizeQuestDef>|null} */
28
31
let draft = null;
29
32
let selectedId = null;
@@ -260,7 +263,12 @@ export function initQuestsModal ({
260
263
obj.when = next;
261
264
if (remount)
262
265
{ renderEditor(); }
263
}, { quests, dialogues, describeWorldTile, centerEditorOnTile, getDimensionOptions }));
266
}, { quests, dialogues, describeWorldTile, centerEditorOnTile, getDimensionOptions, getSpawnerOptions: (mobTypeId) =>
267
{
268
if (typeof getSpawnerOptions === "function")
269
{ return getSpawnerOptions(mobTypeId) ?? []; }
270
return serverSpawners.filter((row) => !mobTypeId || String(row.mobTypeId) === String(mobTypeId));
271
} }));
264
272
box.append(objBox);
265
273
});
266
274
editorEl.append(box);
@@ -496,6 +504,7 @@ export function initQuestsModal ({
496
504
return {
497
505
isOpen: () => open,
498
506
getQuests: () => quests,
507
getServerSpawners: () => serverSpawners.slice(),
499
508
handleMessage (message)
500
509
{
501
510
if (message.type === MessageType.editorDialogues)
@@ -508,6 +517,7 @@ export function initQuestsModal ({
508
517
if (message.type !== MessageType.editorQuests)
509
518
{ return; }
510
519
quests = (message.quests ?? []).map((q) => normalizeQuestDef(q));
520
serverSpawners = Array.isArray(message.spawners) ? message.spawners.slice() : [];
511
521
changelog = message.changelog ?? [];
512
522
if (draft)
513
523
{
@@ -9,7 +9,8 @@ export function initQuestsModal ({9
MessageType,9
MessageType,10
describeWorldTile = null,10
describeWorldTile = null,11
centerEditorOnTile = null,11
centerEditorOnTile = null,12
getDimensionOptions = null12
getDimensionOptions = null,13
getSpawnerOptions = null13
})14
})14
{15
{15
const backdrop = document.getElementById("quests-backdrop");16
const backdrop = document.getElementById("quests-backdrop");@@ -24,6 +25,8 @@ export function initQuestsModal ({24
let quests = [];25
let quests = [];25
/** @type {ReturnType<typeof normalizeDialogueTree>[]} */26
/** @type {ReturnType<typeof normalizeDialogueTree>[]} */26
let dialogues = [];27
let dialogues = [];28
/** @type {{ spawnerId: string, mobTypeId?: string, dimensionId?: string, tileX?: number, tileY?: number }[]} */29
let serverSpawners = [];27
/** @type {ReturnType<typeof normalizeQuestDef>|null} */30
/** @type {ReturnType<typeof normalizeQuestDef>|null} */28
let draft = null;31
let draft = null;29
let selectedId = null;32
let selectedId = null;@@ -260,7 +263,12 @@ export function initQuestsModal ({260
obj.when = next;263
obj.when = next;261
if (remount)264
if (remount)262
{ renderEditor(); }265
{ renderEditor(); }263
}, { quests, dialogues, describeWorldTile, centerEditorOnTile, getDimensionOptions }));266
}, { quests, dialogues, describeWorldTile, centerEditorOnTile, getDimensionOptions, getSpawnerOptions: (mobTypeId) =>267
{268
if (typeof getSpawnerOptions === "function")269
{ return getSpawnerOptions(mobTypeId) ?? []; }270
return serverSpawners.filter((row) => !mobTypeId || String(row.mobTypeId) === String(mobTypeId));271
} }));264
box.append(objBox);272
box.append(objBox);265
});273
});266
editorEl.append(box);274
editorEl.append(box);@@ -496,6 +504,7 @@ export function initQuestsModal ({496
return {504
return {497
isOpen: () => open,505
isOpen: () => open,498
getQuests: () => quests,506
getQuests: () => quests,507
getServerSpawners: () => serverSpawners.slice(),499
handleMessage (message)508
handleMessage (message)500
{509
{501
if (message.type === MessageType.editorDialogues)510
if (message.type === MessageType.editorDialogues)@@ -508,6 +517,7 @@ export function initQuestsModal ({508
if (message.type !== MessageType.editorQuests)517
if (message.type !== MessageType.editorQuests)509
{ return; }518
{ return; }510
quests = (message.quests ?? []).map((q) => normalizeQuestDef(q));519
quests = (message.quests ?? []).map((q) => normalizeQuestDef(q));520
serverSpawners = Array.isArray(message.spawners) ? message.spawners.slice() : [];511
changelog = message.changelog ?? [];521
changelog = message.changelog ?? [];512
if (draft)522
if (draft)513
{523
{@@ -365,6 +365,20 @@ body>aside {
365
365
color: #9aa3b2;
366
366
}
367
367
368
.dim-combo-invalid .dim-combo-input,
369
.dim-combo-invalid .dim-combo-toggle {
370
border-color: #c62828;
371
}
372
373
.dim-combo-invalid-pulse .dim-combo-input {
374
animation: dim-combo-invalid-blink 0.85s ease-in-out 2;
375
}
376
377
@keyframes dim-combo-invalid-blink {
378
0%, 100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0); }
379
50% { box-shadow: 0 0 0 2px rgba(198, 40, 40, 0.85); }
380
}
381
368
382
.dimension-settings {
369
383
display: flex;
370
384
flex-direction: column;
@@ -365,6 +365,20 @@ body>aside {365
color: #9aa3b2;365
color: #9aa3b2;366
}366
}367
367
368
.dim-combo-invalid .dim-combo-input,369
.dim-combo-invalid .dim-combo-toggle {370
border-color: #c62828;371
}372
373
.dim-combo-invalid-pulse .dim-combo-input {374
animation: dim-combo-invalid-blink 0.85s ease-in-out 2;375
}376
377
@keyframes dim-combo-invalid-blink {378
0%, 100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0); }379
50% { box-shadow: 0 0 0 2px rgba(198, 40, 40, 0.85); }380
}381
368
.dimension-settings {382
.dimension-settings {369
display: flex;383
display: flex;370
flex-direction: column;384
flex-direction: column;@@ -2517,6 +2517,8 @@ export function finalizeMobKill (world, attackerId, targetId, targetHandle, tile
2517
2517
const origin = world.ecs.get(handle, Component.spawnOrigin);
2518
2518
const appearance = world.ecs.get(handle, Component.appearance);
2519
2519
const summon = world.ecs.get(handle, Component.summon);
2520
const position = world.ecs.get(handle, Component.position);
2521
const dimensionId = normalizeDimensionId(position?.dimensionId ?? OVERWORLD_ID);
2520
2522
if (summon?.kind === "jadeite-fairy")
2521
2523
{
2522
2524
const respawnAt = now + JADEITE_FAIRY_RESPAWN_MS;
@@ -2549,7 +2551,8 @@ export function finalizeMobKill (world, attackerId, targetId, targetHandle, tile
2549
2551
townGuard: !!origin?.townGuard,
2550
2552
displayName: appearance?.firstName ?? null,
2551
2553
tileX,
2552
tileY
2554
tileY,
2555
dimensionId
2553
2556
});
2554
2557
if (origin?.spawnerId)
2555
2558
{
@@ -2517,6 +2517,8 @@ export function finalizeMobKill (world, attackerId, targetId, targetHandle, tile2517
const origin = world.ecs.get(handle, Component.spawnOrigin);2517
const origin = world.ecs.get(handle, Component.spawnOrigin);2518
const appearance = world.ecs.get(handle, Component.appearance);2518
const appearance = world.ecs.get(handle, Component.appearance);2519
const summon = world.ecs.get(handle, Component.summon);2519
const summon = world.ecs.get(handle, Component.summon);2520
const position = world.ecs.get(handle, Component.position);2521
const dimensionId = normalizeDimensionId(position?.dimensionId ?? OVERWORLD_ID);2520
if (summon?.kind === "jadeite-fairy")2522
if (summon?.kind === "jadeite-fairy")2521
{2523
{2522
const respawnAt = now + JADEITE_FAIRY_RESPAWN_MS;2524
const respawnAt = now + JADEITE_FAIRY_RESPAWN_MS;@@ -2549,7 +2551,8 @@ export function finalizeMobKill (world, attackerId, targetId, targetHandle, tile2549
townGuard: !!origin?.townGuard,2551
townGuard: !!origin?.townGuard,2550
displayName: appearance?.firstName ?? null,2552
displayName: appearance?.firstName ?? null,2551
tileX,2553
tileX,2552
tileY2554
tileY,2555
dimensionId2553
});2556
});2554
if (origin?.spawnerId)2557
if (origin?.spawnerId)2555
{2558
{@@ -436,7 +436,13 @@ export class CourierService
436
436
if (transit.entityId)
437
437
{
438
438
this.simulation.despawnEntity(transit.entityId);
439
events.push({ type: "entity-despawn", entityId: transit.entityId, tileX, tileY });
439
events.push({
440
type: "entity-despawn",
441
entityId: transit.entityId,
442
tileX,
443
tileY,
444
dimensionId: OVERWORLD_ID
445
});
440
446
transit.entityId = null;
441
447
}
442
448
return events;
@@ -486,7 +492,13 @@ export class CourierService
486
492
if (moved?.despawned)
487
493
{
488
494
transit.entityId = null;
489
events.push({ type: "entity-despawn", entityId: moved.entityId, tileX, tileY });
495
events.push({
496
type: "entity-despawn",
497
entityId: moved.entityId,
498
tileX,
499
tileY,
500
dimensionId: OVERWORLD_ID
501
});
490
502
}
491
503
else if (moved?.event)
492
504
{ events.push(moved.event); }
@@ -503,7 +515,8 @@ export class CourierService
503
515
type: "entity-despawn",
504
516
entityId: transit.entityId,
505
517
tileX: Math.floor(transit.destX),
506
tileY: Math.floor(transit.destY)
518
tileY: Math.floor(transit.destY),
519
dimensionId: OVERWORLD_ID
507
520
});
508
521
transit.entityId = null;
509
522
}
@@ -436,7 +436,13 @@ export class CourierService436
if (transit.entityId)436
if (transit.entityId)437
{437
{438
this.simulation.despawnEntity(transit.entityId);438
this.simulation.despawnEntity(transit.entityId);439
events.push({ type: "entity-despawn", entityId: transit.entityId, tileX, tileY });439
events.push({440
type: "entity-despawn",441
entityId: transit.entityId,442
tileX,443
tileY,444
dimensionId: OVERWORLD_ID445
});440
transit.entityId = null;446
transit.entityId = null;441
}447
}442
return events;448
return events;@@ -486,7 +492,13 @@ export class CourierService486
if (moved?.despawned)492
if (moved?.despawned)487
{493
{488
transit.entityId = null;494
transit.entityId = null;489
events.push({ type: "entity-despawn", entityId: moved.entityId, tileX, tileY });495
events.push({496
type: "entity-despawn",497
entityId: moved.entityId,498
tileX,499
tileY,500
dimensionId: OVERWORLD_ID501
});490
}502
}491
else if (moved?.event)503
else if (moved?.event)492
{ events.push(moved.event); }504
{ events.push(moved.event); }@@ -503,7 +515,8 @@ export class CourierService503
type: "entity-despawn",515
type: "entity-despawn",504
entityId: transit.entityId,516
entityId: transit.entityId,505
tileX: Math.floor(transit.destX),517
tileX: Math.floor(transit.destX),506
tileY: Math.floor(transit.destY)518
tileY: Math.floor(transit.destY),519
dimensionId: OVERWORLD_ID507
});520
});508
transit.entityId = null;521
transit.entityId = null;509
}522
}@@ -155,6 +155,7 @@ export function replicationSpawn (view)
155
155
accountId: view.accountId ?? null,
156
156
tileX: view.tileX,
157
157
tileY: view.tileY,
158
dimensionId: view.dimensionId,
158
159
worldX: view.worldX,
159
160
worldY: view.worldY,
160
161
gait: view.gait,
@@ -191,6 +192,7 @@ export function replicationMove (view, fromTileX, fromTileY)
191
192
entityId: view.entityId,
192
193
tileX: view.tileX,
193
194
tileY: view.tileY,
195
dimensionId: view.dimensionId,
194
196
worldX: view.worldX,
195
197
worldY: view.worldY,
196
198
gait: view.gait,
@@ -155,6 +155,7 @@ export function replicationSpawn (view)155
accountId: view.accountId ?? null,155
accountId: view.accountId ?? null,156
tileX: view.tileX,156
tileX: view.tileX,157
tileY: view.tileY,157
tileY: view.tileY,158
dimensionId: view.dimensionId,158
worldX: view.worldX,159
worldX: view.worldX,159
worldY: view.worldY,160
worldY: view.worldY,160
gait: view.gait,161
gait: view.gait,@@ -191,6 +192,7 @@ export function replicationMove (view, fromTileX, fromTileY)191
entityId: view.entityId,192
entityId: view.entityId,192
tileX: view.tileX,193
tileX: view.tileX,193
tileY: view.tileY,194
tileY: view.tileY,195
dimensionId: view.dimensionId,194
worldX: view.worldX,196
worldX: view.worldX,195
worldY: view.worldY,197
worldY: view.worldY,196
gait: view.gait,198
gait: view.gait,@@ -447,6 +447,41 @@ export class EditorService
447
447
};
448
448
}
449
449
450
451
/** Flat list of authored spawners across all editor-revision chunks. */
452
listSpawners ()
453
{
454
const revisionId = this.worldDb.getEditorRevisionId();
455
const settings = this.worldDb.getLiveSettings();
456
const out = [];
457
const seen = new Set();
458
for (const { chunk_x: cx, chunk_y: cy, dimension_id: dimensionId } of this.worldDb.listChunkCoords(revisionId))
459
{
460
const dim = normalizeDimensionId(dimensionId ?? OVERWORLD_ID);
461
const row = this.worldDb.getChunkVersion(cx, cy, revisionId, dim);
462
if (!row)
463
{ continue; }
464
const data = decodeChunkBlob(row.data_blob, settings.defaultGroundTypeId, cx, cy);
465
for (const entry of data.spawners ?? [])
466
{
467
const config = entry?.config;
468
const spawnerId = String(config?.spawnerId ?? "").trim();
469
if (!spawnerId || seen.has(spawnerId))
470
{ continue; }
471
seen.add(spawnerId);
472
out.push({
473
spawnerId,
474
mobTypeId: config.mobTypeId ?? null,
475
dimensionId: dim,
476
tileX: localToTile(cx, entry.localX),
477
tileY: localToTile(cy, entry.localY)
478
});
479
}
480
}
481
out.sort((a, b) => String(a.spawnerId).localeCompare(String(b.spawnerId)));
482
return out;
483
}
484
450
485
loadQuests ()
451
486
{
452
487
const revisionId = this.worldDb.getEditorRevisionId();
@@ -456,6 +491,7 @@ export class EditorService
456
491
pendingRevisionId: this.worldDb.getPendingRevisionId(),
457
492
activeRevisionId: this.worldDb.getActiveRevisionId(),
458
493
quests,
494
spawners: this.listSpawners(),
459
495
changelog: this.#enrichChangelog(this.worldDb.listQuestChangelog())
460
496
};
461
497
}
@@ -447,6 +447,41 @@ export class EditorService447
};447
};448
}448
}449
449
450
451
/** Flat list of authored spawners across all editor-revision chunks. */452
listSpawners ()453
{454
const revisionId = this.worldDb.getEditorRevisionId();455
const settings = this.worldDb.getLiveSettings();456
const out = [];457
const seen = new Set();458
for (const { chunk_x: cx, chunk_y: cy, dimension_id: dimensionId } of this.worldDb.listChunkCoords(revisionId))459
{460
const dim = normalizeDimensionId(dimensionId ?? OVERWORLD_ID);461
const row = this.worldDb.getChunkVersion(cx, cy, revisionId, dim);462
if (!row)463
{ continue; }464
const data = decodeChunkBlob(row.data_blob, settings.defaultGroundTypeId, cx, cy);465
for (const entry of data.spawners ?? [])466
{467
const config = entry?.config;468
const spawnerId = String(config?.spawnerId ?? "").trim();469
if (!spawnerId || seen.has(spawnerId))470
{ continue; }471
seen.add(spawnerId);472
out.push({473
spawnerId,474
mobTypeId: config.mobTypeId ?? null,475
dimensionId: dim,476
tileX: localToTile(cx, entry.localX),477
tileY: localToTile(cy, entry.localY)478
});479
}480
}481
out.sort((a, b) => String(a.spawnerId).localeCompare(String(b.spawnerId)));482
return out;483
}484
450
loadQuests ()485
loadQuests ()451
{486
{452
const revisionId = this.worldDb.getEditorRevisionId();487
const revisionId = this.worldDb.getEditorRevisionId();@@ -456,6 +491,7 @@ export class EditorService456
pendingRevisionId: this.worldDb.getPendingRevisionId(),491
pendingRevisionId: this.worldDb.getPendingRevisionId(),457
activeRevisionId: this.worldDb.getActiveRevisionId(),492
activeRevisionId: this.worldDb.getActiveRevisionId(),458
quests,493
quests,494
spawners: this.listSpawners(),459
changelog: this.#enrichChangelog(this.worldDb.listQuestChangelog())495
changelog: this.#enrichChangelog(this.worldDb.listQuestChangelog())460
};496
};461
}497
}@@ -957,11 +957,7 @@ export class QuestRuntime
957
957
for (const clause of obj.when?.all ?? [])
958
958
{
959
959
const c = clause.condition;
960
if (c?.kind !== "killCount")
961
{ continue; }
962
const matchMob = c.mobTypeId != null && String(c.mobTypeId) === String(mobTypeId);
963
const matchSpawner = c.spawnerId != null && String(c.spawnerId) === String(spawnerId);
964
if (!matchMob && !matchSpawner)
960
if (!matchesKillCondition(c, mobTypeId, spawnerId))
965
961
{ continue; }
966
962
const key = killKey(c);
967
963
counters[key] = (counters[key] | 0) + 1;
@@ -991,6 +987,28 @@ function journalPublic (row)
991
987
};
992
988
}
993
989
990
991
function matchesKillCondition (condition, mobTypeId, spawnerId)
992
{
993
if (!condition || typeof condition !== "object")
994
{ return false; }
995
if (condition.kind === "killMobFromSpawner")
996
{
997
if (condition.mobTypeId == null || condition.spawnerId == null || spawnerId == null)
998
{ return false; }
999
return String(condition.mobTypeId) === String(mobTypeId)
1000
&& String(condition.spawnerId) === String(spawnerId);
1001
}
1002
if (condition.kind === "killCount")
1003
{
1004
// Mob-type kills: match type. Legacy JSON may also use spawnerId alone.
1005
const matchMob = condition.mobTypeId != null && String(condition.mobTypeId) === String(mobTypeId);
1006
const matchSpawner = condition.spawnerId != null && String(condition.spawnerId) === String(spawnerId);
1007
return matchMob || matchSpawner;
1008
}
1009
return false;
1010
}
1011
994
1012
function killKey (condition)
995
1013
{
996
1014
if (condition.spawnerId)
@@ -957,11 +957,7 @@ export class QuestRuntime957
for (const clause of obj.when?.all ?? [])957
for (const clause of obj.when?.all ?? [])958
{958
{959
const c = clause.condition;959
const c = clause.condition;960
if (c?.kind !== "killCount")960
if (!matchesKillCondition(c, mobTypeId, spawnerId))961
{ continue; }962
const matchMob = c.mobTypeId != null && String(c.mobTypeId) === String(mobTypeId);963
const matchSpawner = c.spawnerId != null && String(c.spawnerId) === String(spawnerId);964
if (!matchMob && !matchSpawner)965
{ continue; }961
{ continue; }966
const key = killKey(c);962
const key = killKey(c);967
counters[key] = (counters[key] | 0) + 1;963
counters[key] = (counters[key] | 0) + 1;@@ -991,6 +987,28 @@ function journalPublic (row)991
};987
};992
}988
}993
989
990
991
function matchesKillCondition (condition, mobTypeId, spawnerId)992
{993
if (!condition || typeof condition !== "object")994
{ return false; }995
if (condition.kind === "killMobFromSpawner")996
{997
if (condition.mobTypeId == null || condition.spawnerId == null || spawnerId == null)998
{ return false; }999
return String(condition.mobTypeId) === String(mobTypeId)1000
&& String(condition.spawnerId) === String(spawnerId);1001
}1002
if (condition.kind === "killCount")1003
{1004
// Mob-type kills: match type. Legacy JSON may also use spawnerId alone.1005
const matchMob = condition.mobTypeId != null && String(condition.mobTypeId) === String(mobTypeId);1006
const matchSpawner = condition.spawnerId != null && String(condition.spawnerId) === String(spawnerId);1007
return matchMob || matchSpawner;1008
}1009
return false;1010
}1011
994
function killKey (condition)1012
function killKey (condition)995
{1013
{996
if (condition.spawnerId)1014
if (condition.spawnerId)@@ -162,7 +162,14 @@ export function shadeSummonComponents ({ tileX, tileY, level, ownerEntityId, exp
162
162
return components;
163
163
}
164
164
165
export function publicSummonDespawn (entityId)
165
export function publicSummonDespawn (entityId, view = null)
166
166
{
167
return { type: "entity-despawn", entityId };
167
const event = { type: "entity-despawn", entityId };
168
if (view)
169
{
170
event.tileX = view.tileX;
171
event.tileY = view.tileY;
172
event.dimensionId = view.dimensionId;
173
}
174
return event;
168
175
}
@@ -162,7 +162,14 @@ export function shadeSummonComponents ({ tileX, tileY, level, ownerEntityId, exp162
return components;162
return components;163
}163
}164
164
165
export function publicSummonDespawn (entityId)165
export function publicSummonDespawn (entityId, view = null)166
{166
{167
return { type: "entity-despawn", entityId };167
const event = { type: "entity-despawn", entityId };168
if (view)169
{170
event.tileX = view.tileX;171
event.tileY = view.tileY;172
event.dimensionId = view.dimensionId;173
}174
return event;168
}175
}@@ -0,0 +1,90 @@
1
import test from "node:test";
2
import assert from "node:assert/strict";
3
import { MobId } from "../../shared/definitions/mobs.js";
4
import { normalizeQuestDef } from "../../shared/quests/normalize.js";
5
import { ConditionKind } from "../../shared/quests/conditions.js";
6
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";
7
import { mobComponents } from "../src/simulation/spawners.js";
8
import { applyDamageAndKill } from "../src/combat/service.js";
9
import { Component } from "../src/ecs/components.js";
10
11
function saveQuest (harness, raw)
12
{
13
const revisionId = harness.worldDb.getActiveRevisionId();
14
const quest = normalizeQuestDef(raw);
15
const pending = harness.worldDb.ensurePendingRevision(1);
16
harness.worldDb.saveQuestDef(pending, quest);
17
harness.worldDb.promotePendingRevision();
18
harness.simulation.questContent.reload();
19
return quest;
20
}
21
22
test("killMobFromSpawner counts only matching spawner kills", () =>
23
{
24
const harness = makeSimulation({ workerCount: 1 });
25
try
26
{
27
saveQuest(harness, {
28
questId: "spawner-rats",
29
title: "Spawner rats",
30
steps: [{
31
stepId: "step-1",
32
title: "Hunt",
33
objectives: [{
34
objectiveId: "obj-1",
35
text: "Kill 2 from rats-a",
36
when: {
37
all: [{
38
condition: {
39
kind: ConditionKind.killMobFromSpawner,
40
mobTypeId: MobId.rat,
41
spawnerId: "rats-a",
42
count: 2
43
}
44
}]
45
}
46
}],
47
completionJournalText: "Done."
48
}]
49
});
50
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });
51
const playerId = harness.simulation.spawnCharacter(1, character);
52
harness.simulation.quests.startQuest(character.character_id, "spawner-rats", null, []);
53
54
function killRat (spawnerId)
55
{
56
const ratId = harness.simulation.spawnEntity(mobComponents({
57
tileX: 9,
58
tileY: 8,
59
mobTypeId: MobId.rat,
60
spawnerId
61
}));
62
const worker = harness.simulation.workers[
63
harness.simulation.entityRecord(ratId).workerId
64
];
65
worker.world.ecs.get(worker.world.ecs.handleOf(ratId), Component.health).current = 1;
66
const events = applyDamageAndKill(worker.world, playerId, ratId, 1, harness.now());
67
const killed = events.find((event) => event.type === "mob-killed");
68
harness.simulation.quests.noteKill(character.character_id, {
69
mobTypeId: killed.mobTypeId,
70
spawnerId: killed.spawnerId
71
});
72
}
73
74
killRat("rats-b");
75
assert.equal(
76
harness.stateDb.getQuestState(character.character_id, "spawner-rats").progress?.counters?.["spawner:rats-a"] ?? 0,
77
0
78
);
79
killRat("rats-a");
80
assert.equal(
81
harness.stateDb.getQuestState(character.character_id, "spawner-rats").progress?.counters?.["spawner:rats-a"],
82
1
83
);
84
const snap = harness.simulation.quests.questSnapshot(character.character_id);
85
assert.equal(snap.quests[0].step.objectives[0].current, 1);
86
assert.equal(snap.quests[0].step.objectives[0].required, 2);
87
}
88
finally
89
{ harness.close(); }
90
});
@@ -0,0 +1,90 @@1
import test from "node:test";2
import assert from "node:assert/strict";3
import { MobId } from "../../shared/definitions/mobs.js";4
import { normalizeQuestDef } from "../../shared/quests/normalize.js";5
import { ConditionKind } from "../../shared/quests/conditions.js";6
import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js";7
import { mobComponents } from "../src/simulation/spawners.js";8
import { applyDamageAndKill } from "../src/combat/service.js";9
import { Component } from "../src/ecs/components.js";10
11
function saveQuest (harness, raw)12
{13
const revisionId = harness.worldDb.getActiveRevisionId();14
const quest = normalizeQuestDef(raw);15
const pending = harness.worldDb.ensurePendingRevision(1);16
harness.worldDb.saveQuestDef(pending, quest);17
harness.worldDb.promotePendingRevision();18
harness.simulation.questContent.reload();19
return quest;20
}21
22
test("killMobFromSpawner counts only matching spawner kills", () =>23
{24
const harness = makeSimulation({ workerCount: 1 });25
try26
{27
saveQuest(harness, {28
questId: "spawner-rats",29
title: "Spawner rats",30
steps: [{31
stepId: "step-1",32
title: "Hunt",33
objectives: [{34
objectiveId: "obj-1",35
text: "Kill 2 from rats-a",36
when: {37
all: [{38
condition: {39
kind: ConditionKind.killMobFromSpawner,40
mobTypeId: MobId.rat,41
spawnerId: "rats-a",42
count: 243
}44
}]45
}46
}],47
completionJournalText: "Done."48
}]49
});50
const character = makeCharacter(harness.stateDb, { tileX: 8, tileY: 8 });51
const playerId = harness.simulation.spawnCharacter(1, character);52
harness.simulation.quests.startQuest(character.character_id, "spawner-rats", null, []);53
54
function killRat (spawnerId)55
{56
const ratId = harness.simulation.spawnEntity(mobComponents({57
tileX: 9,58
tileY: 8,59
mobTypeId: MobId.rat,60
spawnerId61
}));62
const worker = harness.simulation.workers[63
harness.simulation.entityRecord(ratId).workerId64
];65
worker.world.ecs.get(worker.world.ecs.handleOf(ratId), Component.health).current = 1;66
const events = applyDamageAndKill(worker.world, playerId, ratId, 1, harness.now());67
const killed = events.find((event) => event.type === "mob-killed");68
harness.simulation.quests.noteKill(character.character_id, {69
mobTypeId: killed.mobTypeId,70
spawnerId: killed.spawnerId71
});72
}73
74
killRat("rats-b");75
assert.equal(76
harness.stateDb.getQuestState(character.character_id, "spawner-rats").progress?.counters?.["spawner:rats-a"] ?? 0,77
078
);79
killRat("rats-a");80
assert.equal(81
harness.stateDb.getQuestState(character.character_id, "spawner-rats").progress?.counters?.["spawner:rats-a"],82
183
);84
const snap = harness.simulation.quests.questSnapshot(character.character_id);85
assert.equal(snap.quests[0].step.objectives[0].current, 1);86
assert.equal(snap.quests[0].step.objectives[0].required, 2);87
}88
finally89
{ harness.close(); }90
});@@ -159,6 +159,22 @@ test("countable objective progress for hasItem killCount and skillLevelAtLeast",
159
159
{ current: 2, required: 3 }
160
160
);
161
161
162
const fromSpawner = normalizeConditionSet({
163
all: [{ condition: { kind: ConditionKind.killMobFromSpawner, mobTypeId: "rat", spawnerId: "rats-1", count: 4 } }]
164
});
165
assert.deepEqual(
166
countableObjectiveProgress(fromSpawner, {
167
killCount: (c) => (c.kind === ConditionKind.killMobFromSpawner && c.spawnerId === "rats-1" ? 1 : 0)
168
}),
169
{ current: 1, required: 4 }
170
);
171
assert.equal(
172
evaluateConditionSet(fromSpawner, {
173
killCount: (c) => (c.spawnerId === "rats-1" ? 4 : 0)
174
}),
175
true
176
);
177
162
178
const skill = normalizeConditionSet({
163
179
all: [{ condition: { kind: ConditionKind.skillLevelAtLeast, skillId: "woodcutting", level: 20 } }]
164
180
});
@@ -159,6 +159,22 @@ test("countable objective progress for hasItem killCount and skillLevelAtLeast",159
{ current: 2, required: 3 }159
{ current: 2, required: 3 }160
);160
);161
161
162
const fromSpawner = normalizeConditionSet({163
all: [{ condition: { kind: ConditionKind.killMobFromSpawner, mobTypeId: "rat", spawnerId: "rats-1", count: 4 } }]164
});165
assert.deepEqual(166
countableObjectiveProgress(fromSpawner, {167
killCount: (c) => (c.kind === ConditionKind.killMobFromSpawner && c.spawnerId === "rats-1" ? 1 : 0)168
}),169
{ current: 1, required: 4 }170
);171
assert.equal(172
evaluateConditionSet(fromSpawner, {173
killCount: (c) => (c.spawnerId === "rats-1" ? 4 : 0)174
}),175
true176
);177
162
const skill = normalizeConditionSet({178
const skill = normalizeConditionSet({163
all: [{ condition: { kind: ConditionKind.skillLevelAtLeast, skillId: "woodcutting", level: 20 } }]179
all: [{ condition: { kind: ConditionKind.skillLevelAtLeast, skillId: "woodcutting", level: 20 } }]164
});180
});