editor fixes, spawner additions
@@ -2,14 +2,14 @@
2
2
* Right-click config modal for editor tiles that have configurable data (spawners, doorways).
3
3
*/
4
4
import
5
{
6
listSpawnableMobTypes,
7
normalizeSpawnerConfig,
8
MobId,
9
isHumanoidMob,
10
isCentralExchangeSpawner,
11
spawnerEquipmentSlot
12
} from "/shared/definitions/mobs.js";
5
{
6
listSpawnableMobTypes,
7
normalizeSpawnerConfig,
8
MobId,
9
isHumanoidMob,
10
isCentralExchangeSpawner,
11
spawnerEquipmentSlot
12
} from "/shared/definitions/mobs.js";
13
13
import { mobSpellCastChancePercent } from "/shared/definitions/mobCombat.js";
14
14
import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";
15
15
import { centralExchangeStaffCount } from "/shared/market/exchange.js";
@@ -109,13 +109,15 @@ export function initTileConfigModal ({
109
109
let context = null;
110
110
/** @type {{ itemId: number, quantity: number }[]} */
111
111
let sellsDraft = [];
112
/** @type {{ itemId: number, chancePercent: number, quantityMin: number, quantityMax: number }[]} */
113
let dropsDraft = [];
112
114
/** @type {number[]} raw fish item ids for fishing spots */
113
115
let fishesDraft = [];
114
116
/** @type {{ spellId: string, chance: number }[]} */
115
117
let spellsDraft = [];
116
118
/** @type {Record<string, { itemId: number|null, dyeColor: {r:number,g:number,b:number}|null }>} */
117
119
let equipmentDraft = {};
118
/** @type {{ kind: "sells" } | { kind: "fishes" } | { kind: "equip", slot: string } | { kind: "spells" } | null} */
120
/** @type {{ kind: "sells" } | { kind: "drops" } | { kind: "fishes" } | { kind: "equip", slot: string } | { kind: "spells" } | null} */
119
121
let itemSearchMode = null;
120
122
/** @type {string|null} */
121
123
let dyeEditSlot = null;
@@ -160,6 +162,12 @@ export function initTileConfigModal ({
160
162
openItemSearch("Add shop stock");
161
163
}
162
164
165
function openDropItemSearch ()
166
{
167
itemSearchMode = { kind: "drops" };
168
openItemSearch("Add drop");
169
}
170
163
171
function openFishItemSearch ()
164
172
{
165
173
itemSearchMode = { kind: "fishes" };
@@ -206,7 +214,9 @@ export function initTileConfigModal ({
206
214
const q = String(query ?? "").trim().toLowerCase();
207
215
const taken = itemSearchMode?.kind === "sells"
208
216
? new Set(sellsDraft.map((line) => line.itemId))
209
: null;
217
: (itemSearchMode?.kind === "drops"
218
? new Set(dropsDraft.map((line) => line.itemId))
219
: null);
210
220
return candidateItems().filter((item) =>
211
221
{
212
222
if (taken?.has(item.itemId))
@@ -279,6 +289,16 @@ export function initTileConfigModal ({
279
289
{ fishesDraft.push(item.itemId); }
280
290
renderFishesList();
281
291
}
292
else if (itemSearchMode?.kind === "drops")
293
{
294
dropsDraft.push({
295
itemId: item.itemId,
296
chancePercent: 100,
297
quantityMin: 1,
298
quantityMax: 1
299
});
300
renderDropsList();
301
}
282
302
else
283
303
{
284
304
sellsDraft.push({ itemId: item.itemId, quantity: 0 });
@@ -457,6 +477,95 @@ export function initTileConfigModal ({
457
477
}
458
478
}
459
479
480
function renderDropsList ()
481
{
482
const list = form.querySelector("[data-drops-list]");
483
if (!list)
484
{ return; }
485
list.innerHTML = "";
486
if (!dropsDraft.length)
487
{
488
const empty = document.createElement("p");
489
empty.className = "hint";
490
empty.textContent = "No drops yet. Use + to add loot.";
491
list.append(empty);
492
return;
493
}
494
for (let index = 0; index < dropsDraft.length; index++)
495
{
496
const line = dropsDraft[index];
497
const def = itemDefinition(line.itemId);
498
const row = document.createElement("div");
499
row.className = "spawner-drops-row";
500
const name = document.createElement("span");
501
name.className = "spawner-sells-name";
502
name.textContent = def?.displayName ?? `Item ${line.itemId}`;
503
504
const qtyMin = document.createElement("input");
505
qtyMin.type = "number";
506
qtyMin.min = "0";
507
qtyMin.step = "1";
508
qtyMin.value = String(line.quantityMin | 0);
509
qtyMin.title = "Minimum quantity if this drop hits";
510
qtyMin.addEventListener("input", () =>
511
{
512
const min = Math.max(0, Number(qtyMin.value) || 0) | 0;
513
dropsDraft[index].quantityMin = min;
514
if ((dropsDraft[index].quantityMax | 0) < min)
515
{
516
dropsDraft[index].quantityMax = min;
517
qtyMax.value = String(min);
518
}
519
});
520
521
const qtyMax = document.createElement("input");
522
qtyMax.type = "number";
523
qtyMax.min = "0";
524
qtyMax.step = "1";
525
qtyMax.value = String(line.quantityMax | 0);
526
qtyMax.title = "Maximum quantity if this drop hits";
527
qtyMax.addEventListener("input", () =>
528
{
529
const max = Math.max(0, Number(qtyMax.value) || 0) | 0;
530
const min = dropsDraft[index].quantityMin | 0;
531
dropsDraft[index].quantityMax = Math.max(min, max);
532
if (max < min)
533
{ qtyMax.value = String(min); }
534
});
535
536
const chanceWrap = document.createElement("label");
537
chanceWrap.className = "spawner-drops-chance";
538
const chance = document.createElement("input");
539
chance.type = "number";
540
chance.min = "0";
541
chance.max = "100";
542
chance.step = "1";
543
chance.value = String(Math.round(line.chancePercent ?? 100));
544
chance.title = "Drop chance (0–100%)";
545
chance.addEventListener("input", () =>
546
{
547
dropsDraft[index].chancePercent = Math.min(
548
100,
549
Math.max(0, Number(chance.value) || 0)
550
);
551
});
552
const suffix = document.createElement("span");
553
suffix.textContent = "%";
554
chanceWrap.append(chance, suffix);
555
556
const remove = document.createElement("button");
557
remove.type = "button";
558
remove.textContent = "Remove";
559
remove.addEventListener("click", () =>
560
{
561
dropsDraft.splice(index, 1);
562
renderDropsList();
563
});
564
row.append(name, qtyMin, qtyMax, chanceWrap, remove);
565
list.append(row);
566
}
567
}
568
460
569
function renderEquipmentRows ()
461
570
{
462
571
const list = form.querySelector("[data-equipment-list]");
@@ -565,6 +674,56 @@ export function initTileConfigModal ({
565
674
{ equipmentDraft[slot] = equipDraftFromConfig(config.equipment?.[slot]); }
566
675
queueMicrotask(() => renderEquipmentRows());
567
676
677
const dropsHeader = document.createElement("div");
678
dropsHeader.className = "spawner-sells-header";
679
const dropsTitle = document.createElement("strong");
680
dropsTitle.textContent = "Drops";
681
const dropsAddBtn = document.createElement("button");
682
dropsAddBtn.type = "button";
683
dropsAddBtn.textContent = "+";
684
dropsAddBtn.title = "Add drop";
685
dropsAddBtn.addEventListener("click", () => openDropItemSearch());
686
dropsHeader.append(dropsTitle, dropsAddBtn);
687
wrap.append(dropsHeader);
688
689
const dropsList = document.createElement("div");
690
dropsList.className = "spawner-sells-list";
691
dropsList.dataset.dropsList = "1";
692
wrap.append(dropsList);
693
694
const dropsHint = document.createElement("p");
695
dropsHint.className = "hint";
696
dropsHint.textContent = "On death each line rolls its chance; if it hits, quantity is random between min and max (inclusive).";
697
wrap.append(dropsHint);
698
699
dropsDraft = (config.drops ?? []).map((line) =>
700
{
701
if (!line || typeof line !== "object")
702
{ return null; }
703
const itemId = line.itemId | 0;
704
if (itemId <= 0)
705
{ return null; }
706
let chancePercent = Number(line.chance);
707
if (!Number.isFinite(chancePercent))
708
{ chancePercent = 100; }
709
else if (chancePercent <= 1)
710
{ chancePercent = chancePercent * 100; }
711
let quantityMin = Math.max(0, Math.floor(Number(line.quantityMin ?? line.quantity ?? 1)));
712
let quantityMax = Math.max(0, Math.floor(Number(line.quantityMax ?? quantityMin)));
713
if (!Number.isFinite(quantityMin))
714
{ quantityMin = 1; }
715
if (!Number.isFinite(quantityMax) || quantityMax < quantityMin)
716
{ quantityMax = quantityMin; }
717
return {
718
itemId,
719
chancePercent: Math.min(100, Math.max(0, chancePercent)),
720
quantityMin,
721
quantityMax
722
};
723
}).filter(Boolean);
724
725
queueMicrotask(() => renderDropsList());
726
568
727
if (!exchange)
569
728
{
570
729
wrap.append(field("Hidden discount (0–1)", numberInput("hiddenDiscount", config.hiddenDiscount ?? 0.9, 0.01, 1, 0.01)));
@@ -621,6 +780,7 @@ export function initTileConfigModal ({
621
780
if (!isHumanoidMob(mobTypeId))
622
781
{
623
782
sellsDraft = [];
783
dropsDraft = [];
624
784
equipmentDraft = {};
625
785
return;
626
786
}
@@ -783,6 +943,7 @@ export function initTileConfigModal ({
783
943
field("Level", numberInput("level", config.level ?? 1, 1, 99)),
784
944
field("Bounty", numberInput("bounty", config.bounty ?? 0, 0, 1_000_000)),
785
945
field("Max alive", numberInput("maxAlive", config.maxAlive, 1, 20)),
946
field("Respawn delay (seconds)", numberInput("respawnDelaySeconds", config.respawnDelaySeconds ?? 0, 0, 86_400)),
786
947
field("Spawn range", numberInput("spawnRangeTiles", config.spawnRangeTiles, 1, 32)),
787
948
field("Max wander range", numberInput("maxWanderRangeTiles", config.maxWanderRangeTiles, 1, 64)),
788
949
field("Spawner id", textInput("spawnerId", config.spawnerId, true))
@@ -949,6 +1110,7 @@ export function initTileConfigModal ({
949
1110
onSave?.(context, normalizeSpawnerConfig({
950
1111
mobTypeId: String(data.get("mobTypeId") || "deer"),
951
1112
maxAlive: Number(data.get("maxAlive") || 3),
1113
respawnDelaySeconds: Number(data.get("respawnDelaySeconds") || 0),
952
1114
spawnRangeTiles: Number(data.get("spawnRangeTiles") || 4),
953
1115
maxWanderRangeTiles: Number(data.get("maxWanderRangeTiles") || 4),
954
1116
level: Number(data.get("level") || 1),
@@ -959,6 +1121,20 @@ export function initTileConfigModal ({
959
1121
displayName: String(data.get("displayName") || ""),
960
1122
equipment,
961
1123
sells: sellsDraft,
1124
drops: dropsDraft.map((line) =>
1125
{
1126
const quantityMin = Math.max(0, Number(line.quantityMin) || 0) | 0;
1127
const quantityMax = Math.max(
1128
quantityMin,
1129
Math.max(0, Number(line.quantityMax) || 0) | 0
1130
);
1131
return {
1132
itemId: line.itemId,
1133
chance: Math.min(100, Math.max(0, Number(line.chancePercent) || 0)) / 100,
1134
quantityMin,
1135
quantityMax
1136
};
1137
}),
962
1138
spells: spellsDraft,
963
1139
buysItems: data.get("buysItems") === "on",
964
1140
hiddenDiscount: Number(data.get("hiddenDiscount") || 0.9),
@@ -2,14 +2,14 @@2
* Right-click config modal for editor tiles that have configurable data (spawners, doorways).2
* Right-click config modal for editor tiles that have configurable data (spawners, doorways).3
*/3
*/4
import4
import5
{5
{6
listSpawnableMobTypes,6
listSpawnableMobTypes,7
normalizeSpawnerConfig,7
normalizeSpawnerConfig,8
MobId,8
MobId,9
isHumanoidMob,9
isHumanoidMob,10
isCentralExchangeSpawner,10
isCentralExchangeSpawner,11
spawnerEquipmentSlot11
spawnerEquipmentSlot12
} from "/shared/definitions/mobs.js";12
} from "/shared/definitions/mobs.js";13
import { mobSpellCastChancePercent } from "/shared/definitions/mobCombat.js";13
import { mobSpellCastChancePercent } from "/shared/definitions/mobCombat.js";14
import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";14
import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";15
import { centralExchangeStaffCount } from "/shared/market/exchange.js";15
import { centralExchangeStaffCount } from "/shared/market/exchange.js";@@ -109,13 +109,15 @@ export function initTileConfigModal ({109
let context = null;109
let context = null;110
/** @type {{ itemId: number, quantity: number }[]} */110
/** @type {{ itemId: number, quantity: number }[]} */111
let sellsDraft = [];111
let sellsDraft = [];112
/** @type {{ itemId: number, chancePercent: number, quantityMin: number, quantityMax: number }[]} */113
let dropsDraft = [];112
/** @type {number[]} raw fish item ids for fishing spots */114
/** @type {number[]} raw fish item ids for fishing spots */113
let fishesDraft = [];115
let fishesDraft = [];114
/** @type {{ spellId: string, chance: number }[]} */116
/** @type {{ spellId: string, chance: number }[]} */115
let spellsDraft = [];117
let spellsDraft = [];116
/** @type {Record<string, { itemId: number|null, dyeColor: {r:number,g:number,b:number}|null }>} */118
/** @type {Record<string, { itemId: number|null, dyeColor: {r:number,g:number,b:number}|null }>} */117
let equipmentDraft = {};119
let equipmentDraft = {};118
/** @type {{ kind: "sells" } | { kind: "fishes" } | { kind: "equip", slot: string } | { kind: "spells" } | null} */120
/** @type {{ kind: "sells" } | { kind: "drops" } | { kind: "fishes" } | { kind: "equip", slot: string } | { kind: "spells" } | null} */119
let itemSearchMode = null;121
let itemSearchMode = null;120
/** @type {string|null} */122
/** @type {string|null} */121
let dyeEditSlot = null;123
let dyeEditSlot = null;@@ -160,6 +162,12 @@ export function initTileConfigModal ({160
openItemSearch("Add shop stock");162
openItemSearch("Add shop stock");161
}163
}162
164
165
function openDropItemSearch ()166
{167
itemSearchMode = { kind: "drops" };168
openItemSearch("Add drop");169
}170
163
function openFishItemSearch ()171
function openFishItemSearch ()164
{172
{165
itemSearchMode = { kind: "fishes" };173
itemSearchMode = { kind: "fishes" };@@ -206,7 +214,9 @@ export function initTileConfigModal ({206
const q = String(query ?? "").trim().toLowerCase();214
const q = String(query ?? "").trim().toLowerCase();207
const taken = itemSearchMode?.kind === "sells"215
const taken = itemSearchMode?.kind === "sells"208
? new Set(sellsDraft.map((line) => line.itemId))216
? new Set(sellsDraft.map((line) => line.itemId))209
: null;217
: (itemSearchMode?.kind === "drops"218
? new Set(dropsDraft.map((line) => line.itemId))219
: null);210
return candidateItems().filter((item) =>220
return candidateItems().filter((item) =>211
{221
{212
if (taken?.has(item.itemId))222
if (taken?.has(item.itemId))@@ -279,6 +289,16 @@ export function initTileConfigModal ({279
{ fishesDraft.push(item.itemId); }289
{ fishesDraft.push(item.itemId); }280
renderFishesList();290
renderFishesList();281
}291
}292
else if (itemSearchMode?.kind === "drops")293
{294
dropsDraft.push({295
itemId: item.itemId,296
chancePercent: 100,297
quantityMin: 1,298
quantityMax: 1299
});300
renderDropsList();301
}282
else302
else283
{303
{284
sellsDraft.push({ itemId: item.itemId, quantity: 0 });304
sellsDraft.push({ itemId: item.itemId, quantity: 0 });@@ -457,6 +477,95 @@ export function initTileConfigModal ({457
}477
}458
}478
}459
479
480
function renderDropsList ()481
{482
const list = form.querySelector("[data-drops-list]");483
if (!list)484
{ return; }485
list.innerHTML = "";486
if (!dropsDraft.length)487
{488
const empty = document.createElement("p");489
empty.className = "hint";490
empty.textContent = "No drops yet. Use + to add loot.";491
list.append(empty);492
return;493
}494
for (let index = 0; index < dropsDraft.length; index++)495
{496
const line = dropsDraft[index];497
const def = itemDefinition(line.itemId);498
const row = document.createElement("div");499
row.className = "spawner-drops-row";500
const name = document.createElement("span");501
name.className = "spawner-sells-name";502
name.textContent = def?.displayName ?? `Item ${line.itemId}`;503
504
const qtyMin = document.createElement("input");505
qtyMin.type = "number";506
qtyMin.min = "0";507
qtyMin.step = "1";508
qtyMin.value = String(line.quantityMin | 0);509
qtyMin.title = "Minimum quantity if this drop hits";510
qtyMin.addEventListener("input", () =>511
{512
const min = Math.max(0, Number(qtyMin.value) || 0) | 0;513
dropsDraft[index].quantityMin = min;514
if ((dropsDraft[index].quantityMax | 0) < min)515
{516
dropsDraft[index].quantityMax = min;517
qtyMax.value = String(min);518
}519
});520
521
const qtyMax = document.createElement("input");522
qtyMax.type = "number";523
qtyMax.min = "0";524
qtyMax.step = "1";525
qtyMax.value = String(line.quantityMax | 0);526
qtyMax.title = "Maximum quantity if this drop hits";527
qtyMax.addEventListener("input", () =>528
{529
const max = Math.max(0, Number(qtyMax.value) || 0) | 0;530
const min = dropsDraft[index].quantityMin | 0;531
dropsDraft[index].quantityMax = Math.max(min, max);532
if (max < min)533
{ qtyMax.value = String(min); }534
});535
536
const chanceWrap = document.createElement("label");537
chanceWrap.className = "spawner-drops-chance";538
const chance = document.createElement("input");539
chance.type = "number";540
chance.min = "0";541
chance.max = "100";542
chance.step = "1";543
chance.value = String(Math.round(line.chancePercent ?? 100));544
chance.title = "Drop chance (0–100%)";545
chance.addEventListener("input", () =>546
{547
dropsDraft[index].chancePercent = Math.min(548
100,549
Math.max(0, Number(chance.value) || 0)550
);551
});552
const suffix = document.createElement("span");553
suffix.textContent = "%";554
chanceWrap.append(chance, suffix);555
556
const remove = document.createElement("button");557
remove.type = "button";558
remove.textContent = "Remove";559
remove.addEventListener("click", () =>560
{561
dropsDraft.splice(index, 1);562
renderDropsList();563
});564
row.append(name, qtyMin, qtyMax, chanceWrap, remove);565
list.append(row);566
}567
}568
460
function renderEquipmentRows ()569
function renderEquipmentRows ()461
{570
{462
const list = form.querySelector("[data-equipment-list]");571
const list = form.querySelector("[data-equipment-list]");@@ -565,6 +674,56 @@ export function initTileConfigModal ({565
{ equipmentDraft[slot] = equipDraftFromConfig(config.equipment?.[slot]); }674
{ equipmentDraft[slot] = equipDraftFromConfig(config.equipment?.[slot]); }566
queueMicrotask(() => renderEquipmentRows());675
queueMicrotask(() => renderEquipmentRows());567
676
677
const dropsHeader = document.createElement("div");678
dropsHeader.className = "spawner-sells-header";679
const dropsTitle = document.createElement("strong");680
dropsTitle.textContent = "Drops";681
const dropsAddBtn = document.createElement("button");682
dropsAddBtn.type = "button";683
dropsAddBtn.textContent = "+";684
dropsAddBtn.title = "Add drop";685
dropsAddBtn.addEventListener("click", () => openDropItemSearch());686
dropsHeader.append(dropsTitle, dropsAddBtn);687
wrap.append(dropsHeader);688
689
const dropsList = document.createElement("div");690
dropsList.className = "spawner-sells-list";691
dropsList.dataset.dropsList = "1";692
wrap.append(dropsList);693
694
const dropsHint = document.createElement("p");695
dropsHint.className = "hint";696
dropsHint.textContent = "On death each line rolls its chance; if it hits, quantity is random between min and max (inclusive).";697
wrap.append(dropsHint);698
699
dropsDraft = (config.drops ?? []).map((line) =>700
{701
if (!line || typeof line !== "object")702
{ return null; }703
const itemId = line.itemId | 0;704
if (itemId <= 0)705
{ return null; }706
let chancePercent = Number(line.chance);707
if (!Number.isFinite(chancePercent))708
{ chancePercent = 100; }709
else if (chancePercent <= 1)710
{ chancePercent = chancePercent * 100; }711
let quantityMin = Math.max(0, Math.floor(Number(line.quantityMin ?? line.quantity ?? 1)));712
let quantityMax = Math.max(0, Math.floor(Number(line.quantityMax ?? quantityMin)));713
if (!Number.isFinite(quantityMin))714
{ quantityMin = 1; }715
if (!Number.isFinite(quantityMax) || quantityMax < quantityMin)716
{ quantityMax = quantityMin; }717
return {718
itemId,719
chancePercent: Math.min(100, Math.max(0, chancePercent)),720
quantityMin,721
quantityMax722
};723
}).filter(Boolean);724
725
queueMicrotask(() => renderDropsList());726
568
if (!exchange)727
if (!exchange)569
{728
{570
wrap.append(field("Hidden discount (0–1)", numberInput("hiddenDiscount", config.hiddenDiscount ?? 0.9, 0.01, 1, 0.01)));729
wrap.append(field("Hidden discount (0–1)", numberInput("hiddenDiscount", config.hiddenDiscount ?? 0.9, 0.01, 1, 0.01)));@@ -621,6 +780,7 @@ export function initTileConfigModal ({621
if (!isHumanoidMob(mobTypeId))780
if (!isHumanoidMob(mobTypeId))622
{781
{623
sellsDraft = [];782
sellsDraft = [];783
dropsDraft = [];624
equipmentDraft = {};784
equipmentDraft = {};625
return;785
return;626
}786
}@@ -783,6 +943,7 @@ export function initTileConfigModal ({783
field("Level", numberInput("level", config.level ?? 1, 1, 99)),943
field("Level", numberInput("level", config.level ?? 1, 1, 99)),784
field("Bounty", numberInput("bounty", config.bounty ?? 0, 0, 1_000_000)),944
field("Bounty", numberInput("bounty", config.bounty ?? 0, 0, 1_000_000)),785
field("Max alive", numberInput("maxAlive", config.maxAlive, 1, 20)),945
field("Max alive", numberInput("maxAlive", config.maxAlive, 1, 20)),946
field("Respawn delay (seconds)", numberInput("respawnDelaySeconds", config.respawnDelaySeconds ?? 0, 0, 86_400)),786
field("Spawn range", numberInput("spawnRangeTiles", config.spawnRangeTiles, 1, 32)),947
field("Spawn range", numberInput("spawnRangeTiles", config.spawnRangeTiles, 1, 32)),787
field("Max wander range", numberInput("maxWanderRangeTiles", config.maxWanderRangeTiles, 1, 64)),948
field("Max wander range", numberInput("maxWanderRangeTiles", config.maxWanderRangeTiles, 1, 64)),788
field("Spawner id", textInput("spawnerId", config.spawnerId, true))949
field("Spawner id", textInput("spawnerId", config.spawnerId, true))@@ -949,6 +1110,7 @@ export function initTileConfigModal ({949
onSave?.(context, normalizeSpawnerConfig({1110
onSave?.(context, normalizeSpawnerConfig({950
mobTypeId: String(data.get("mobTypeId") || "deer"),1111
mobTypeId: String(data.get("mobTypeId") || "deer"),951
maxAlive: Number(data.get("maxAlive") || 3),1112
maxAlive: Number(data.get("maxAlive") || 3),1113
respawnDelaySeconds: Number(data.get("respawnDelaySeconds") || 0),952
spawnRangeTiles: Number(data.get("spawnRangeTiles") || 4),1114
spawnRangeTiles: Number(data.get("spawnRangeTiles") || 4),953
maxWanderRangeTiles: Number(data.get("maxWanderRangeTiles") || 4),1115
maxWanderRangeTiles: Number(data.get("maxWanderRangeTiles") || 4),954
level: Number(data.get("level") || 1),1116
level: Number(data.get("level") || 1),@@ -959,6 +1121,20 @@ export function initTileConfigModal ({959
displayName: String(data.get("displayName") || ""),1121
displayName: String(data.get("displayName") || ""),960
equipment,1122
equipment,961
sells: sellsDraft,1123
sells: sellsDraft,1124
drops: dropsDraft.map((line) =>1125
{1126
const quantityMin = Math.max(0, Number(line.quantityMin) || 0) | 0;1127
const quantityMax = Math.max(1128
quantityMin,1129
Math.max(0, Number(line.quantityMax) || 0) | 01130
);1131
return {1132
itemId: line.itemId,1133
chance: Math.min(100, Math.max(0, Number(line.chancePercent) || 0)) / 100,1134
quantityMin,1135
quantityMax1136
};1137
}),962
spells: spellsDraft,1138
spells: spellsDraft,963
buysItems: data.get("buysItems") === "on",1139
buysItems: data.get("buysItems") === "on",964
hiddenDiscount: Number(data.get("hiddenDiscount") || 0.9),1140
hiddenDiscount: Number(data.get("hiddenDiscount") || 0.9),@@ -1095,8 +1095,8 @@ export class WorldView
1095
1095
item = { object };
1096
1096
this.groundItems.set(payload.groundItemId, item);
1097
1097
}
1098
else if (item.object && this.game.images[spriteName])
1099
{ item.object.image = this.game.images[spriteName]; }
1098
else if (item.object?.renderer && this.game.images[spriteName])
1099
{ item.object.renderer.sprite = this.game.images[spriteName]; }
1100
1100
item.groundItemId = payload.groundItemId;
1101
1101
item.tileX = payload.tileX;
1102
1102
item.tileY = payload.tileY;
@@ -2843,7 +2843,7 @@ export class WorldView
2843
2843
{
2844
2844
baked.groundCanvas = atlases.ground;
2845
2845
baked.groundImage = groundImage;
2846
baked.groundObject.image = groundImage;
2846
baked.groundObject.renderer.sprite = groundImage;
2847
2847
}
2848
2848
for (let row = 0; row < CHUNK_SIZE; row++)
2849
2849
{
@@ -2851,14 +2851,14 @@ export class WorldView
2851
2851
{
2852
2852
baked.blockCanvases[row] = atlases.blockRows[row];
2853
2853
baked.blockImages[row] = blockImages[row];
2854
baked.blockObjects[row].image = blockImages[row];
2854
baked.blockObjects[row].renderer.sprite = blockImages[row];
2855
2855
}
2856
2856
}
2857
2857
if (baked.bloomCanvas !== atlases.bloom)
2858
2858
{
2859
2859
baked.bloomCanvas = atlases.bloom;
2860
2860
baked.bloomImage = bloomImage;
2861
baked.bloomObject.image = bloomImage;
2861
baked.bloomObject.renderer.sprite = bloomImage;
2862
2862
}
2863
2863
baked.tallBlocks = atlases.tallBlocks;
2864
2864
baked.animatedGrounds = atlases.animatedGrounds;
@@ -1095,8 +1095,8 @@ export class WorldView1095
item = { object };1095
item = { object };1096
this.groundItems.set(payload.groundItemId, item);1096
this.groundItems.set(payload.groundItemId, item);1097
}1097
}1098
else if (item.object && this.game.images[spriteName])1098
else if (item.object?.renderer && this.game.images[spriteName])1099
{ item.object.image = this.game.images[spriteName]; }1099
{ item.object.renderer.sprite = this.game.images[spriteName]; }1100
item.groundItemId = payload.groundItemId;1100
item.groundItemId = payload.groundItemId;1101
item.tileX = payload.tileX;1101
item.tileX = payload.tileX;1102
item.tileY = payload.tileY;1102
item.tileY = payload.tileY;@@ -2843,7 +2843,7 @@ export class WorldView2843
{2843
{2844
baked.groundCanvas = atlases.ground;2844
baked.groundCanvas = atlases.ground;2845
baked.groundImage = groundImage;2845
baked.groundImage = groundImage;2846
baked.groundObject.image = groundImage;2846
baked.groundObject.renderer.sprite = groundImage;2847
}2847
}2848
for (let row = 0; row < CHUNK_SIZE; row++)2848
for (let row = 0; row < CHUNK_SIZE; row++)2849
{2849
{@@ -2851,14 +2851,14 @@ export class WorldView2851
{2851
{2852
baked.blockCanvases[row] = atlases.blockRows[row];2852
baked.blockCanvases[row] = atlases.blockRows[row];2853
baked.blockImages[row] = blockImages[row];2853
baked.blockImages[row] = blockImages[row];2854
baked.blockObjects[row].image = blockImages[row];2854
baked.blockObjects[row].renderer.sprite = blockImages[row];2855
}2855
}2856
}2856
}2857
if (baked.bloomCanvas !== atlases.bloom)2857
if (baked.bloomCanvas !== atlases.bloom)2858
{2858
{2859
baked.bloomCanvas = atlases.bloom;2859
baked.bloomCanvas = atlases.bloom;2860
baked.bloomImage = bloomImage;2860
baked.bloomImage = bloomImage;2861
baked.bloomObject.image = bloomImage;2861
baked.bloomObject.renderer.sprite = bloomImage;2862
}2862
}2863
baked.tallBlocks = atlases.tallBlocks;2863
baked.tallBlocks = atlases.tallBlocks;2864
baked.animatedGrounds = atlases.animatedGrounds;2864
baked.animatedGrounds = atlases.animatedGrounds;@@ -5,12 +5,13 @@
5
5
color: #e8e4d9;
6
6
}
7
7
8
html, body {
8
html,
9
body {
9
10
margin: 0;
10
11
min-height: 100%;
11
12
}
12
13
13
body > header {
14
body>header {
14
15
display: flex;
15
16
align-items: flex-start;
16
17
justify-content: space-between;
@@ -55,7 +56,7 @@ body > header {
55
56
display: none !important;
56
57
}
57
58
58
body > aside {
59
body>aside {
59
60
position: absolute;
60
61
left: 0;
61
62
top: 56px;
@@ -80,12 +81,14 @@ body > aside {
80
81
background: #1a1e26;
81
82
border-left: 1px solid #2c3340;
82
83
}
84
83
85
.side-panel-tabs {
84
86
display: flex;
85
87
gap: 0;
86
88
border-bottom: 1px solid #2c3340;
87
89
flex: 0 0 auto;
88
90
}
91
89
92
.side-panel-tab {
90
93
flex: 1 1 0;
91
94
border: 0;
@@ -95,11 +98,13 @@ body > aside {
95
98
padding: 0.55rem 0.4rem;
96
99
cursor: pointer;
97
100
}
101
98
102
.side-panel-tab.active {
99
103
color: #e8e4d9;
100
104
background: #222833;
101
105
box-shadow: inset 0 -2px 0 #6a8cbf;
102
106
}
107
103
108
.side-panel-body {
104
109
flex: 1 1 auto;
105
110
min-height: 0;
@@ -107,6 +112,7 @@ body > aside {
107
112
padding: 0.75rem;
108
113
box-sizing: border-box;
109
114
}
115
110
116
#editor-console {
111
117
margin: 0;
112
118
padding: 0.4rem;
@@ -120,15 +126,26 @@ body > aside {
120
126
border: 1px solid #2c3340;
121
127
color: #c8d0dc;
122
128
}
123
#editor-console .console-warn { color: #e0c070; }
124
#editor-console .console-error { color: #f0a0a0; }
125
#editor-console .console-debug { color: #7a8494; }
129
130
#editor-console .console-warn {
131
color: #e0c070;
132
}
133
134
#editor-console .console-error {
135
color: #f0a0a0;
136
}
137
138
#editor-console .console-debug {
139
color: #7a8494;
140
}
141
126
142
#console-clear {
127
143
margin-top: 0.5rem;
128
144
width: 100%;
129
145
}
130
146
131
.nav, .palette {
147
.nav,
148
.palette {
132
149
display: flex;
133
150
flex-direction: column;
134
151
gap: 0.35rem;
@@ -141,22 +158,26 @@ body > aside {
141
158
flex-direction: column;
142
159
gap: 0.35rem;
143
160
}
144
.dimension-picker > label,
161
162
.dimension-picker>label,
145
163
.dimension-picker-label {
146
164
font-size: 0.85rem;
147
165
color: #9aa3b2;
148
166
}
167
149
168
.dim-combo {
150
169
position: relative;
151
170
display: flex;
152
171
align-items: stretch;
153
172
}
173
154
174
.dim-combo-input {
155
175
flex: 1 1 auto;
156
176
width: 0;
157
177
min-width: 0;
158
178
box-sizing: border-box;
159
179
}
180
160
181
.dim-combo-toggle {
161
182
flex: 0 0 auto;
162
183
padding: 0 0.45rem;
@@ -166,9 +187,11 @@ body > aside {
166
187
color: #c8d0dc;
167
188
cursor: pointer;
168
189
}
190
169
191
.dim-combo-toggle:hover {
170
192
background: #243044;
171
193
}
194
172
195
.dim-combo-list {
173
196
position: absolute;
174
197
left: 0;
@@ -184,6 +207,7 @@ body > aside {
184
207
border: 1px solid #3a4250;
185
208
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
186
209
}
210
187
211
.dim-combo-option,
188
212
.dim-combo-empty {
189
213
display: flex;
@@ -192,22 +216,27 @@ body > aside {
192
216
padding: 0.35rem 0.55rem;
193
217
cursor: pointer;
194
218
}
219
195
220
.dim-combo-option:hover,
196
221
.dim-combo-option.selected {
197
222
background: #243044;
198
223
}
224
199
225
.dim-combo-option.disabled {
200
226
opacity: 0.55;
201
227
}
228
202
229
.dim-combo-option.create {
203
230
color: #b8d4a0;
204
231
border-top: 1px solid #2c3340;
205
232
}
233
206
234
.dim-combo-option-hint,
207
235
.dim-combo-empty {
208
236
font-size: 0.78rem;
209
237
color: #9aa3b2;
210
238
}
239
211
240
.dimension-settings {
212
241
display: flex;
213
242
flex-direction: column;
@@ -217,6 +246,7 @@ body > aside {
217
246
border: 1px solid #2c3340;
218
247
background: #151922;
219
248
}
249
220
250
.dimension-settings label {
221
251
display: flex;
222
252
flex-direction: column;
@@ -224,22 +254,26 @@ body > aside {
224
254
font-size: 0.85rem;
225
255
color: #9aa3b2;
226
256
}
257
227
258
.dimension-settings input,
228
259
.dimension-settings select {
229
260
width: 100%;
230
261
box-sizing: border-box;
231
262
}
263
232
264
.dimension-settings-actions {
233
265
display: flex;
234
266
flex-wrap: wrap;
235
267
gap: 0.35rem;
236
268
}
269
237
270
#dim-delete {
238
271
border-color: #8a3a3a;
239
272
color: #f0a0a0;
240
273
}
241
274
242
button, input {
275
button,
276
input {
243
277
font: inherit;
244
278
background: #101216;
245
279
color: inherit;
@@ -247,26 +281,40 @@ button, input {
247
281
padding: 0.3rem 0.5rem;
248
282
}
249
283
250
button { cursor: pointer; }
284
button {
285
cursor: pointer;
286
}
287
251
288
button:disabled {
252
289
opacity: 0.45;
253
290
cursor: not-allowed;
254
291
}
292
255
293
#save.save-dirty:not(:disabled) {
256
294
animation: save-pulse 1.1s ease-in-out infinite;
257
295
border-color: #c9a227;
258
296
box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.35);
259
297
}
298
260
299
@keyframes save-pulse {
261
0%, 100% { opacity: 1; }
262
50% { opacity: 0.55; }
300
301
0%,
302
100% {
303
opacity: 1;
304
}
305
306
50% {
307
opacity: 0.55;
308
}
263
309
}
310
264
311
#unsaved-chunk-backdrop {
265
312
position: fixed;
266
313
inset: 0;
267
314
background: rgba(0, 0, 0, 0.62);
268
315
z-index: 29;
269
316
}
317
270
318
#unsaved-chunk-modal {
271
319
position: fixed;
272
320
left: 50%;
@@ -279,21 +327,25 @@ button:disabled {
279
327
border: 1px solid #3a4250;
280
328
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
281
329
}
330
282
331
#unsaved-chunk-modal header {
283
332
margin: 0 0 0.5rem;
284
333
padding: 0;
285
334
border: 0;
286
335
}
336
287
337
#unsaved-chunk-modal h2 {
288
338
margin: 0;
289
339
font-size: 1.1rem;
290
340
}
341
291
342
#dimension-settings-backdrop {
292
343
position: fixed;
293
344
inset: 0;
294
345
background: rgba(0, 0, 0, 0.62);
295
346
z-index: 29;
296
347
}
348
297
349
#dimension-settings-modal {
298
350
position: fixed;
299
351
left: 50%;
@@ -306,6 +358,7 @@ button:disabled {
306
358
border: 1px solid #3a4250;
307
359
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
308
360
}
361
309
362
#dimension-settings-modal header {
310
363
display: flex;
311
364
align-items: center;
@@ -315,28 +368,54 @@ button:disabled {
315
368
padding: 0;
316
369
border: 0;
317
370
}
371
318
372
#dimension-settings-modal h2 {
319
373
margin: 0;
320
374
font-size: 1.1rem;
321
375
}
376
322
377
#dimension-settings-modal .dimension-settings {
323
378
margin: 0;
324
379
padding: 0;
325
380
border: 0;
326
381
background: transparent;
327
382
}
383
328
384
.unsaved-chunk-actions {
329
385
display: flex;
330
386
justify-content: flex-end;
331
387
gap: 0.5rem;
332
388
margin-top: 1rem;
333
389
}
334
#apply-status.ok { color: #b8d4a0; }
335
.error { color: #f0a0a0; }
336
.hint { color: #9aa3b2; font-size: 0.85rem; }
337
.open-toggle { display: flex; gap: 0.4rem; align-items: center; }
338
article { margin-bottom: 0.75rem; }
339
fieldset { border-color: #3a4250; margin-top: 1rem; }
390
391
#apply-status.ok {
392
color: #b8d4a0;
393
}
394
395
.error {
396
color: #f0a0a0;
397
}
398
399
.hint {
400
color: #9aa3b2;
401
font-size: 0.85rem;
402
}
403
404
.open-toggle {
405
display: flex;
406
gap: 0.4rem;
407
align-items: center;
408
}
409
410
article {
411
margin-bottom: 0.75rem;
412
}
413
414
fieldset {
415
border-color: #3a4250;
416
margin-top: 1rem;
417
}
418
340
419
#selection-border {
341
420
position: fixed;
342
421
pointer-events: none;
@@ -346,7 +425,10 @@ fieldset { border-color: #3a4250; margin-top: 1rem; }
346
425
z-index: 4;
347
426
}
348
427
349
label { display: block; margin: 0.4rem 0; }
428
label {
429
display: block;
430
margin: 0.4rem 0;
431
}
350
432
351
433
#settings-backdrop {
352
434
position: fixed;
@@ -828,9 +910,9 @@ label { display: block; margin: 0.4rem 0; }
828
910
display: none !important;
829
911
}
830
912
831
#palette-modal > header,
832
#tile-config-modal > header,
833
#tile-config-modal > footer {
913
#palette-modal>header,
914
#tile-config-modal>header,
915
#tile-config-modal>footer {
834
916
display: flex;
835
917
align-items: center;
836
918
justify-content: space-between;
@@ -839,7 +921,7 @@ label { display: block; margin: 0.4rem 0; }
839
921
border-bottom: 1px solid #2c3340;
840
922
}
841
923
842
#tile-config-modal > footer {
924
#tile-config-modal>footer {
843
925
border-bottom: 0;
844
926
border-top: 1px solid #2c3340;
845
927
}
@@ -915,12 +997,30 @@ label { display: block; margin: 0.4rem 0; }
915
997
align-items: center;
916
998
}
917
999
1000
.spawner-drops-row {
1001
display: grid;
1002
grid-template-columns: 1fr 3.5rem 3.5rem 4.5rem auto;
1003
gap: 0.4rem;
1004
align-items: center;
1005
}
1006
918
1007
.spawner-sells-name {
919
1008
overflow: hidden;
920
1009
text-overflow: ellipsis;
921
1010
white-space: nowrap;
922
1011
}
923
1012
1013
.spawner-drops-chance {
1014
display: flex;
1015
align-items: center;
1016
gap: 0.2rem;
1017
}
1018
1019
.spawner-drops-chance input {
1020
width: 100%;
1021
min-width: 0;
1022
}
1023
924
1024
.spawner-equip-list {
925
1025
display: flex;
926
1026
flex-direction: column;
@@ -982,7 +1082,7 @@ label { display: block; margin: 0.4rem 0; }
982
1082
display: none !important;
983
1083
}
984
1084
985
#equip-dye-modal > header {
1085
#equip-dye-modal>header {
986
1086
display: flex;
987
1087
align-items: center;
988
1088
justify-content: space-between;
@@ -1059,7 +1159,7 @@ label { display: block; margin: 0.4rem 0; }
1059
1159
display: none !important;
1060
1160
}
1061
1161
1062
#shop-item-search-modal > header {
1162
#shop-item-search-modal>header {
1063
1163
display: flex;
1064
1164
align-items: center;
1065
1165
justify-content: space-between;
@@ -1068,7 +1168,7 @@ label { display: block; margin: 0.4rem 0; }
1068
1168
border-bottom: 1px solid #2c3340;
1069
1169
}
1070
1170
1071
#shop-item-search-modal > .shop-item-search-body {
1171
#shop-item-search-modal>.shop-item-search-body {
1072
1172
padding: 0.75rem 1rem 1rem;
1073
1173
display: flex;
1074
1174
flex-direction: column;
@@ -1146,6 +1246,7 @@ label { display: block; margin: 0.4rem 0; }
1146
1246
font-size: 0.85rem;
1147
1247
pointer-events: none;
1148
1248
}
1249
1149
1250
#hover-status-text {
1150
1251
font-variant-numeric: tabular-nums;
1151
1252
}
@@ -1178,10 +1279,10 @@ label { display: block; margin: 0.4rem 0; }
1178
1279
display: none !important;
1179
1280
}
1180
1281
1181
#quests-modal > header,
1182
#dialogues-modal > header,
1183
#quests-modal > footer,
1184
#dialogues-modal > footer {
1282
#quests-modal>header,
1283
#dialogues-modal>header,
1284
#quests-modal>footer,
1285
#dialogues-modal>footer {
1185
1286
display: flex;
1186
1287
align-items: center;
1187
1288
justify-content: space-between;
@@ -1190,8 +1291,8 @@ label { display: block; margin: 0.4rem 0; }
1190
1291
border-bottom: 1px solid #2c3340;
1191
1292
}
1192
1293
1193
#quests-modal > footer,
1194
#dialogues-modal > footer {
1294
#quests-modal>footer,
1295
#dialogues-modal>footer {
1195
1296
border-bottom: 0;
1196
1297
border-top: 1px solid #2c3340;
1197
1298
justify-content: flex-end;
@@ -1287,4 +1388,4 @@ label { display: block; margin: 0.4rem 0; }
1287
1388
color: #8a909c;
1288
1389
font-size: 0.85rem;
1289
1390
margin: 0.25rem 0 0.5rem;
1290
}
1391
}
@@ -5,12 +5,13 @@5
color: #e8e4d9;5
color: #e8e4d9;6
}6
}7
7
8
html, body {8
html,9
body {9
margin: 0;10
margin: 0;10
min-height: 100%;11
min-height: 100%;11
}12
}12
13
13
body > header {14
body>header {14
display: flex;15
display: flex;15
align-items: flex-start;16
align-items: flex-start;16
justify-content: space-between;17
justify-content: space-between;@@ -55,7 +56,7 @@ body > header {55
display: none !important;56
display: none !important;56
}57
}57
58
58
body > aside {59
body>aside {59
position: absolute;60
position: absolute;60
left: 0;61
left: 0;61
top: 56px;62
top: 56px;@@ -80,12 +81,14 @@ body > aside {80
background: #1a1e26;81
background: #1a1e26;81
border-left: 1px solid #2c3340;82
border-left: 1px solid #2c3340;82
}83
}84
83
.side-panel-tabs {85
.side-panel-tabs {84
display: flex;86
display: flex;85
gap: 0;87
gap: 0;86
border-bottom: 1px solid #2c3340;88
border-bottom: 1px solid #2c3340;87
flex: 0 0 auto;89
flex: 0 0 auto;88
}90
}91
89
.side-panel-tab {92
.side-panel-tab {90
flex: 1 1 0;93
flex: 1 1 0;91
border: 0;94
border: 0;@@ -95,11 +98,13 @@ body > aside {95
padding: 0.55rem 0.4rem;98
padding: 0.55rem 0.4rem;96
cursor: pointer;99
cursor: pointer;97
}100
}101
98
.side-panel-tab.active {102
.side-panel-tab.active {99
color: #e8e4d9;103
color: #e8e4d9;100
background: #222833;104
background: #222833;101
box-shadow: inset 0 -2px 0 #6a8cbf;105
box-shadow: inset 0 -2px 0 #6a8cbf;102
}106
}107
103
.side-panel-body {108
.side-panel-body {104
flex: 1 1 auto;109
flex: 1 1 auto;105
min-height: 0;110
min-height: 0;@@ -107,6 +112,7 @@ body > aside {107
padding: 0.75rem;112
padding: 0.75rem;108
box-sizing: border-box;113
box-sizing: border-box;109
}114
}115
110
#editor-console {116
#editor-console {111
margin: 0;117
margin: 0;112
padding: 0.4rem;118
padding: 0.4rem;@@ -120,15 +126,26 @@ body > aside {120
border: 1px solid #2c3340;126
border: 1px solid #2c3340;121
color: #c8d0dc;127
color: #c8d0dc;122
}128
}123
#editor-console .console-warn { color: #e0c070; }129
124
#editor-console .console-error { color: #f0a0a0; }130
#editor-console .console-warn {125
#editor-console .console-debug { color: #7a8494; }131
color: #e0c070;132
}133
134
#editor-console .console-error {135
color: #f0a0a0;136
}137
138
#editor-console .console-debug {139
color: #7a8494;140
}141
126
#console-clear {142
#console-clear {127
margin-top: 0.5rem;143
margin-top: 0.5rem;128
width: 100%;144
width: 100%;129
}145
}130
146
131
.nav, .palette {147
.nav,148
.palette {132
display: flex;149
display: flex;133
flex-direction: column;150
flex-direction: column;134
gap: 0.35rem;151
gap: 0.35rem;@@ -141,22 +158,26 @@ body > aside {141
flex-direction: column;158
flex-direction: column;142
gap: 0.35rem;159
gap: 0.35rem;143
}160
}144
.dimension-picker > label,161
162
.dimension-picker>label,145
.dimension-picker-label {163
.dimension-picker-label {146
font-size: 0.85rem;164
font-size: 0.85rem;147
color: #9aa3b2;165
color: #9aa3b2;148
}166
}167
149
.dim-combo {168
.dim-combo {150
position: relative;169
position: relative;151
display: flex;170
display: flex;152
align-items: stretch;171
align-items: stretch;153
}172
}173
154
.dim-combo-input {174
.dim-combo-input {155
flex: 1 1 auto;175
flex: 1 1 auto;156
width: 0;176
width: 0;157
min-width: 0;177
min-width: 0;158
box-sizing: border-box;178
box-sizing: border-box;159
}179
}180
160
.dim-combo-toggle {181
.dim-combo-toggle {161
flex: 0 0 auto;182
flex: 0 0 auto;162
padding: 0 0.45rem;183
padding: 0 0.45rem;@@ -166,9 +187,11 @@ body > aside {166
color: #c8d0dc;187
color: #c8d0dc;167
cursor: pointer;188
cursor: pointer;168
}189
}190
169
.dim-combo-toggle:hover {191
.dim-combo-toggle:hover {170
background: #243044;192
background: #243044;171
}193
}194
172
.dim-combo-list {195
.dim-combo-list {173
position: absolute;196
position: absolute;174
left: 0;197
left: 0;@@ -184,6 +207,7 @@ body > aside {184
border: 1px solid #3a4250;207
border: 1px solid #3a4250;185
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);208
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);186
}209
}210
187
.dim-combo-option,211
.dim-combo-option,188
.dim-combo-empty {212
.dim-combo-empty {189
display: flex;213
display: flex;@@ -192,22 +216,27 @@ body > aside {192
padding: 0.35rem 0.55rem;216
padding: 0.35rem 0.55rem;193
cursor: pointer;217
cursor: pointer;194
}218
}219
195
.dim-combo-option:hover,220
.dim-combo-option:hover,196
.dim-combo-option.selected {221
.dim-combo-option.selected {197
background: #243044;222
background: #243044;198
}223
}224
199
.dim-combo-option.disabled {225
.dim-combo-option.disabled {200
opacity: 0.55;226
opacity: 0.55;201
}227
}228
202
.dim-combo-option.create {229
.dim-combo-option.create {203
color: #b8d4a0;230
color: #b8d4a0;204
border-top: 1px solid #2c3340;231
border-top: 1px solid #2c3340;205
}232
}233
206
.dim-combo-option-hint,234
.dim-combo-option-hint,207
.dim-combo-empty {235
.dim-combo-empty {208
font-size: 0.78rem;236
font-size: 0.78rem;209
color: #9aa3b2;237
color: #9aa3b2;210
}238
}239
211
.dimension-settings {240
.dimension-settings {212
display: flex;241
display: flex;213
flex-direction: column;242
flex-direction: column;@@ -217,6 +246,7 @@ body > aside {217
border: 1px solid #2c3340;246
border: 1px solid #2c3340;218
background: #151922;247
background: #151922;219
}248
}249
220
.dimension-settings label {250
.dimension-settings label {221
display: flex;251
display: flex;222
flex-direction: column;252
flex-direction: column;@@ -224,22 +254,26 @@ body > aside {224
font-size: 0.85rem;254
font-size: 0.85rem;225
color: #9aa3b2;255
color: #9aa3b2;226
}256
}257
227
.dimension-settings input,258
.dimension-settings input,228
.dimension-settings select {259
.dimension-settings select {229
width: 100%;260
width: 100%;230
box-sizing: border-box;261
box-sizing: border-box;231
}262
}263
232
.dimension-settings-actions {264
.dimension-settings-actions {233
display: flex;265
display: flex;234
flex-wrap: wrap;266
flex-wrap: wrap;235
gap: 0.35rem;267
gap: 0.35rem;236
}268
}269
237
#dim-delete {270
#dim-delete {238
border-color: #8a3a3a;271
border-color: #8a3a3a;239
color: #f0a0a0;272
color: #f0a0a0;240
}273
}241
274
242
button, input {275
button,276
input {243
font: inherit;277
font: inherit;244
background: #101216;278
background: #101216;245
color: inherit;279
color: inherit;@@ -247,26 +281,40 @@ button, input {247
padding: 0.3rem 0.5rem;281
padding: 0.3rem 0.5rem;248
}282
}249
283
250
button { cursor: pointer; }284
button {285
cursor: pointer;286
}287
251
button:disabled {288
button:disabled {252
opacity: 0.45;289
opacity: 0.45;253
cursor: not-allowed;290
cursor: not-allowed;254
}291
}292
255
#save.save-dirty:not(:disabled) {293
#save.save-dirty:not(:disabled) {256
animation: save-pulse 1.1s ease-in-out infinite;294
animation: save-pulse 1.1s ease-in-out infinite;257
border-color: #c9a227;295
border-color: #c9a227;258
box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.35);296
box-shadow: 0 0 0 1px rgba(201, 162, 39, 0.35);259
}297
}298
260
@keyframes save-pulse {299
@keyframes save-pulse {261
0%, 100% { opacity: 1; }300
262
50% { opacity: 0.55; }301
0%,302
100% {303
opacity: 1;304
}305
306
50% {307
opacity: 0.55;308
}263
}309
}310
264
#unsaved-chunk-backdrop {311
#unsaved-chunk-backdrop {265
position: fixed;312
position: fixed;266
inset: 0;313
inset: 0;267
background: rgba(0, 0, 0, 0.62);314
background: rgba(0, 0, 0, 0.62);268
z-index: 29;315
z-index: 29;269
}316
}317
270
#unsaved-chunk-modal {318
#unsaved-chunk-modal {271
position: fixed;319
position: fixed;272
left: 50%;320
left: 50%;@@ -279,21 +327,25 @@ button:disabled {279
border: 1px solid #3a4250;327
border: 1px solid #3a4250;280
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);328
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);281
}329
}330
282
#unsaved-chunk-modal header {331
#unsaved-chunk-modal header {283
margin: 0 0 0.5rem;332
margin: 0 0 0.5rem;284
padding: 0;333
padding: 0;285
border: 0;334
border: 0;286
}335
}336
287
#unsaved-chunk-modal h2 {337
#unsaved-chunk-modal h2 {288
margin: 0;338
margin: 0;289
font-size: 1.1rem;339
font-size: 1.1rem;290
}340
}341
291
#dimension-settings-backdrop {342
#dimension-settings-backdrop {292
position: fixed;343
position: fixed;293
inset: 0;344
inset: 0;294
background: rgba(0, 0, 0, 0.62);345
background: rgba(0, 0, 0, 0.62);295
z-index: 29;346
z-index: 29;296
}347
}348
297
#dimension-settings-modal {349
#dimension-settings-modal {298
position: fixed;350
position: fixed;299
left: 50%;351
left: 50%;@@ -306,6 +358,7 @@ button:disabled {306
border: 1px solid #3a4250;358
border: 1px solid #3a4250;307
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);359
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);308
}360
}361
309
#dimension-settings-modal header {362
#dimension-settings-modal header {310
display: flex;363
display: flex;311
align-items: center;364
align-items: center;@@ -315,28 +368,54 @@ button:disabled {315
padding: 0;368
padding: 0;316
border: 0;369
border: 0;317
}370
}371
318
#dimension-settings-modal h2 {372
#dimension-settings-modal h2 {319
margin: 0;373
margin: 0;320
font-size: 1.1rem;374
font-size: 1.1rem;321
}375
}376
322
#dimension-settings-modal .dimension-settings {377
#dimension-settings-modal .dimension-settings {323
margin: 0;378
margin: 0;324
padding: 0;379
padding: 0;325
border: 0;380
border: 0;326
background: transparent;381
background: transparent;327
}382
}383
328
.unsaved-chunk-actions {384
.unsaved-chunk-actions {329
display: flex;385
display: flex;330
justify-content: flex-end;386
justify-content: flex-end;331
gap: 0.5rem;387
gap: 0.5rem;332
margin-top: 1rem;388
margin-top: 1rem;333
}389
}334
#apply-status.ok { color: #b8d4a0; }390
335
.error { color: #f0a0a0; }391
#apply-status.ok {336
.hint { color: #9aa3b2; font-size: 0.85rem; }392
color: #b8d4a0;337
.open-toggle { display: flex; gap: 0.4rem; align-items: center; }393
}338
article { margin-bottom: 0.75rem; }394
339
fieldset { border-color: #3a4250; margin-top: 1rem; }395
.error {396
color: #f0a0a0;397
}398
399
.hint {400
color: #9aa3b2;401
font-size: 0.85rem;402
}403
404
.open-toggle {405
display: flex;406
gap: 0.4rem;407
align-items: center;408
}409
410
article {411
margin-bottom: 0.75rem;412
}413
414
fieldset {415
border-color: #3a4250;416
margin-top: 1rem;417
}418
340
#selection-border {419
#selection-border {341
position: fixed;420
position: fixed;342
pointer-events: none;421
pointer-events: none;@@ -346,7 +425,10 @@ fieldset { border-color: #3a4250; margin-top: 1rem; }346
z-index: 4;425
z-index: 4;347
}426
}348
427
349
label { display: block; margin: 0.4rem 0; }428
label {429
display: block;430
margin: 0.4rem 0;431
}350
432
351
#settings-backdrop {433
#settings-backdrop {352
position: fixed;434
position: fixed;@@ -828,9 +910,9 @@ label { display: block; margin: 0.4rem 0; }828
display: none !important;910
display: none !important;829
}911
}830
912
831
#palette-modal > header,913
#palette-modal>header,832
#tile-config-modal > header,914
#tile-config-modal>header,833
#tile-config-modal > footer {915
#tile-config-modal>footer {834
display: flex;916
display: flex;835
align-items: center;917
align-items: center;836
justify-content: space-between;918
justify-content: space-between;@@ -839,7 +921,7 @@ label { display: block; margin: 0.4rem 0; }839
border-bottom: 1px solid #2c3340;921
border-bottom: 1px solid #2c3340;840
}922
}841
923
842
#tile-config-modal > footer {924
#tile-config-modal>footer {843
border-bottom: 0;925
border-bottom: 0;844
border-top: 1px solid #2c3340;926
border-top: 1px solid #2c3340;845
}927
}@@ -915,12 +997,30 @@ label { display: block; margin: 0.4rem 0; }915
align-items: center;997
align-items: center;916
}998
}917
999
1000
.spawner-drops-row {1001
display: grid;1002
grid-template-columns: 1fr 3.5rem 3.5rem 4.5rem auto;1003
gap: 0.4rem;1004
align-items: center;1005
}1006
918
.spawner-sells-name {1007
.spawner-sells-name {919
overflow: hidden;1008
overflow: hidden;920
text-overflow: ellipsis;1009
text-overflow: ellipsis;921
white-space: nowrap;1010
white-space: nowrap;922
}1011
}923
1012
1013
.spawner-drops-chance {1014
display: flex;1015
align-items: center;1016
gap: 0.2rem;1017
}1018
1019
.spawner-drops-chance input {1020
width: 100%;1021
min-width: 0;1022
}1023
924
.spawner-equip-list {1024
.spawner-equip-list {925
display: flex;1025
display: flex;926
flex-direction: column;1026
flex-direction: column;@@ -982,7 +1082,7 @@ label { display: block; margin: 0.4rem 0; }982
display: none !important;1082
display: none !important;983
}1083
}984
1084
985
#equip-dye-modal > header {1085
#equip-dye-modal>header {986
display: flex;1086
display: flex;987
align-items: center;1087
align-items: center;988
justify-content: space-between;1088
justify-content: space-between;@@ -1059,7 +1159,7 @@ label { display: block; margin: 0.4rem 0; }1059
display: none !important;1159
display: none !important;1060
}1160
}1061
1161
1062
#shop-item-search-modal > header {1162
#shop-item-search-modal>header {1063
display: flex;1163
display: flex;1064
align-items: center;1164
align-items: center;1065
justify-content: space-between;1165
justify-content: space-between;@@ -1068,7 +1168,7 @@ label { display: block; margin: 0.4rem 0; }1068
border-bottom: 1px solid #2c3340;1168
border-bottom: 1px solid #2c3340;1069
}1169
}1070
1170
1071
#shop-item-search-modal > .shop-item-search-body {1171
#shop-item-search-modal>.shop-item-search-body {1072
padding: 0.75rem 1rem 1rem;1172
padding: 0.75rem 1rem 1rem;1073
display: flex;1173
display: flex;1074
flex-direction: column;1174
flex-direction: column;@@ -1146,6 +1246,7 @@ label { display: block; margin: 0.4rem 0; }1146
font-size: 0.85rem;1246
font-size: 0.85rem;1147
pointer-events: none;1247
pointer-events: none;1148
}1248
}1249
1149
#hover-status-text {1250
#hover-status-text {1150
font-variant-numeric: tabular-nums;1251
font-variant-numeric: tabular-nums;1151
}1252
}@@ -1178,10 +1279,10 @@ label { display: block; margin: 0.4rem 0; }1178
display: none !important;1279
display: none !important;1179
}1280
}1180
1281
1181
#quests-modal > header,1282
#quests-modal>header,1182
#dialogues-modal > header,1283
#dialogues-modal>header,1183
#quests-modal > footer,1284
#quests-modal>footer,1184
#dialogues-modal > footer {1285
#dialogues-modal>footer {1185
display: flex;1286
display: flex;1186
align-items: center;1287
align-items: center;1187
justify-content: space-between;1288
justify-content: space-between;@@ -1190,8 +1291,8 @@ label { display: block; margin: 0.4rem 0; }1190
border-bottom: 1px solid #2c3340;1291
border-bottom: 1px solid #2c3340;1191
}1292
}1192
1293
1193
#quests-modal > footer,1294
#quests-modal>footer,1194
#dialogues-modal > footer {1295
#dialogues-modal>footer {1195
border-bottom: 0;1296
border-bottom: 0;1196
border-top: 1px solid #2c3340;1297
border-top: 1px solid #2c3340;1197
justify-content: flex-end;1298
justify-content: flex-end;@@ -1287,4 +1388,4 @@ label { display: block; margin: 0.4rem 0; }1287
color: #8a909c;1388
color: #8a909c;1288
font-size: 0.85rem;1389
font-size: 0.85rem;1289
margin: 0.25rem 0 0.5rem;1390
margin: 0.25rem 0 0.5rem;1290
}1391
}@@ -40,6 +40,7 @@ import { addGroundItem, publicGroundItem } from "../items/bags.js";
40
40
import { resolveItemDualTint } from "../../../shared/render/tint.js";
41
41
import { castMobAttackSpell } from "../spells/mobCast.js";
42
42
import { attachOrigins, lootOrigin } from "../../../shared/items/origin.js";
43
import { scheduleSpawnerRespawn } from "../simulation/spawners.js";
43
44
44
45
export function chebyshev (ax, ay, bx, by)
45
46
{
@@ -257,7 +258,12 @@ function spawnMobDrops (world, targetHandle, tileX, tileY, now, attackerId = nul
257
258
}
258
259
const origin = lootOrigin(mobName, killerName);
259
260
const events = [];
260
for (const drop of def?.drops ?? [])
261
const spawnOrigin = world.ecs.get(targetHandle, Component.spawnOrigin);
262
const dropTable = [
263
...(def?.drops ?? []),
264
...(Array.isArray(spawnOrigin?.drops) ? spawnOrigin.drops : [])
265
];
266
for (const drop of dropTable)
261
267
{
262
268
if (Math.random() > (drop.chance ?? 1))
263
269
{ continue; }
@@ -1443,6 +1449,15 @@ export function finalizeMobKill (world, attackerId, targetId, targetHandle, tile
1443
1449
tileX,
1444
1450
tileY
1445
1451
});
1452
if (origin?.spawnerId)
1453
{
1454
scheduleSpawnerRespawn(
1455
world,
1456
origin.spawnerId,
1457
origin.respawnDelaySeconds ?? 0,
1458
now
1459
);
1460
}
1446
1461
const view = world.destroyEntity?.(targetId) ?? null;
1447
1462
if (view)
1448
1463
{
@@ -40,6 +40,7 @@ import { addGroundItem, publicGroundItem } from "../items/bags.js";40
import { resolveItemDualTint } from "../../../shared/render/tint.js";40
import { resolveItemDualTint } from "../../../shared/render/tint.js";41
import { castMobAttackSpell } from "../spells/mobCast.js";41
import { castMobAttackSpell } from "../spells/mobCast.js";42
import { attachOrigins, lootOrigin } from "../../../shared/items/origin.js";42
import { attachOrigins, lootOrigin } from "../../../shared/items/origin.js";43
import { scheduleSpawnerRespawn } from "../simulation/spawners.js";43
44
44
export function chebyshev (ax, ay, bx, by)45
export function chebyshev (ax, ay, bx, by)45
{46
{@@ -257,7 +258,12 @@ function spawnMobDrops (world, targetHandle, tileX, tileY, now, attackerId = nul257
}258
}258
const origin = lootOrigin(mobName, killerName);259
const origin = lootOrigin(mobName, killerName);259
const events = [];260
const events = [];260
for (const drop of def?.drops ?? [])261
const spawnOrigin = world.ecs.get(targetHandle, Component.spawnOrigin);262
const dropTable = [263
...(def?.drops ?? []),264
...(Array.isArray(spawnOrigin?.drops) ? spawnOrigin.drops : [])265
];266
for (const drop of dropTable)261
{267
{262
if (Math.random() > (drop.chance ?? 1))268
if (Math.random() > (drop.chance ?? 1))263
{ continue; }269
{ continue; }@@ -1443,6 +1449,15 @@ export function finalizeMobKill (world, attackerId, targetId, targetHandle, tile1443
tileX,1449
tileX,1444
tileY1450
tileY1445
});1451
});1452
if (origin?.spawnerId)1453
{1454
scheduleSpawnerRespawn(1455
world,1456
origin.spawnerId,1457
origin.respawnDelaySeconds ?? 0,1458
now1459
);1460
}1446
const view = world.destroyEntity?.(targetId) ?? null;1461
const view = world.destroyEntity?.(targetId) ?? null;1447
if (view)1462
if (view)1448
{1463
{@@ -26,12 +26,13 @@ import { Component } from "../ecs/components.js";
26
26
import { tileToChunk, tileToRegion, parseChunkKey } from "../world/coordinates.js";
27
27
import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";
28
28
29
export function collectSpawnRequests (world)
29
export function collectSpawnRequests (world, now = Date.now())
30
30
{
31
31
const requests = [];
32
32
const counts = countBySpawner(world);
33
33
const staffAlive = staffNamesBySpawner(world);
34
34
const reserved = new Set();
35
ensurePendingRespawns(world);
35
36
for (const [key, chunk] of world.chunks)
36
37
{
37
38
if (chunk.replica || !chunk.simulating || !chunk.data.open)
@@ -51,6 +52,7 @@ export function collectSpawnRequests (world)
51
52
const originX = chunkX * CHUNK_SIZE + localX;
52
53
const originY = chunkY * CHUNK_SIZE + localY;
53
54
const persistent = !!mobDefinition(config.mobTypeId)?.persistent;
55
const delayMs = Math.max(0, (config.respawnDelaySeconds | 0) * 1000);
54
56
55
57
if (config.centralExchange)
56
58
{
@@ -61,6 +63,8 @@ export function collectSpawnRequests (world)
61
63
{ continue; }
62
64
if ((counts.get(config.spawnerId) ?? 0) >= config.maxAlive)
63
65
{ break; }
66
if (!consumeSpawnSlot(world, config.spawnerId, delayMs, now))
67
{ break; }
64
68
const tile = pickSpawnTile(
65
69
world,
66
70
originX,
@@ -92,11 +96,13 @@ export function collectSpawnRequests (world)
92
96
displayName: staff.name,
93
97
equipment: config.equipment,
94
98
sells: [],
99
drops: config.drops,
95
100
buysItems: false,
96
101
hiddenDiscount: config.hiddenDiscount,
97
102
centralExchange: true,
98
103
townGuard: false,
99
dialogueId: config.dialogueId || null
104
dialogueId: config.dialogueId || null,
105
respawnDelaySeconds: config.respawnDelaySeconds
100
106
});
101
107
counts.set(config.spawnerId, (counts.get(config.spawnerId) ?? 0) + 1);
102
108
}
@@ -105,6 +111,8 @@ export function collectSpawnRequests (world)
105
111
106
112
while ((counts.get(config.spawnerId) ?? 0) < config.maxAlive)
107
113
{
114
if (!consumeSpawnSlot(world, config.spawnerId, delayMs, now))
115
{ break; }
108
116
const tile = pickSpawnTile(
109
117
world,
110
118
originX,
@@ -136,11 +144,13 @@ export function collectSpawnRequests (world)
136
144
displayName: config.displayName,
137
145
equipment: config.equipment,
138
146
sells: config.sells,
147
drops: config.drops,
139
148
buysItems: config.buysItems,
140
149
hiddenDiscount: config.hiddenDiscount,
141
150
centralExchange: false,
142
151
townGuard: !!config.townGuard || isTownGuardMob(config.mobTypeId),
143
dialogueId: config.dialogueId || null
152
dialogueId: config.dialogueId || null,
153
respawnDelaySeconds: config.respawnDelaySeconds
144
154
});
145
155
counts.set(config.spawnerId, (counts.get(config.spawnerId) ?? 0) + 1);
146
156
}
@@ -150,6 +160,58 @@ export function collectSpawnRequests (world)
150
160
return requests;
151
161
}
152
162
163
function ensurePendingRespawns (world)
164
{
165
if (!world.pendingSpawnerRespawns)
166
{ world.pendingSpawnerRespawns = new Map(); }
167
return world.pendingSpawnerRespawns;
168
}
169
170
/**
171
* Schedule a delayed refill slot after a spawned mob dies.
172
* Delay 0 means the next collect pass may refill immediately (no pending entry).
173
*/
174
export function scheduleSpawnerRespawn (world, spawnerId, respawnDelaySeconds, now = Date.now())
175
{
176
if (!spawnerId)
177
{ return; }
178
const delayMs = Math.max(0, (respawnDelaySeconds | 0) * 1000);
179
if (delayMs <= 0)
180
{ return; }
181
const pending = ensurePendingRespawns(world);
182
const list = pending.get(spawnerId) ?? [];
183
list.push(now + delayMs);
184
list.sort((a, b) => a - b);
185
pending.set(spawnerId, list);
186
}
187
188
/**
189
* Decide whether one more mob may spawn for this spawner right now.
190
* - delay 0 / empty pending: allow (initial populate + instant refill)
191
* - otherwise: only if a pending timer is due; consume one due timer
192
*/
193
function consumeSpawnSlot (world, spawnerId, delayMs, now)
194
{
195
if (delayMs <= 0)
196
{ return true; }
197
const pending = ensurePendingRespawns(world);
198
const list = pending.get(spawnerId);
199
if (!list?.length)
200
{
201
// No death timers yet — first populate / recovery after unload.
202
return true;
203
}
204
const readyIndex = list.findIndex((readyAt) => readyAt <= now);
205
if (readyIndex < 0)
206
{ return false; }
207
list.splice(readyIndex, 1);
208
if (!list.length)
209
{ pending.delete(spawnerId); }
210
else
211
{ pending.set(spawnerId, list); }
212
return true;
213
}
214
153
215
export function mobComponents (request)
154
216
{
155
217
const def = mobDefinition(request.mobTypeId) ?? mobDefinition("deer");
@@ -208,7 +270,9 @@ export function mobComponents (request)
208
270
townGuard: !!request.townGuard || isTownGuardMob(def.mobTypeId),
209
271
stationTileX: null,
210
272
stationTileY: null,
211
dialogueId: request.dialogueId ? String(request.dialogueId) : null
273
dialogueId: request.dialogueId ? String(request.dialogueId) : null,
274
drops: Array.isArray(request.drops) ? request.drops : [],
275
respawnDelaySeconds: Math.max(0, request.respawnDelaySeconds | 0)
212
276
};
213
277
}
214
278
if (def.persistent)
@@ -26,12 +26,13 @@ import { Component } from "../ecs/components.js";26
import { tileToChunk, tileToRegion, parseChunkKey } from "../world/coordinates.js";26
import { tileToChunk, tileToRegion, parseChunkKey } from "../world/coordinates.js";27
import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";27
import { OVERWORLD_ID, normalizeDimensionId } from "../../../shared/world/dimensions.js";28
28
29
export function collectSpawnRequests (world)29
export function collectSpawnRequests (world, now = Date.now())30
{30
{31
const requests = [];31
const requests = [];32
const counts = countBySpawner(world);32
const counts = countBySpawner(world);33
const staffAlive = staffNamesBySpawner(world);33
const staffAlive = staffNamesBySpawner(world);34
const reserved = new Set();34
const reserved = new Set();35
ensurePendingRespawns(world);35
for (const [key, chunk] of world.chunks)36
for (const [key, chunk] of world.chunks)36
{37
{37
if (chunk.replica || !chunk.simulating || !chunk.data.open)38
if (chunk.replica || !chunk.simulating || !chunk.data.open)@@ -51,6 +52,7 @@ export function collectSpawnRequests (world)51
const originX = chunkX * CHUNK_SIZE + localX;52
const originX = chunkX * CHUNK_SIZE + localX;52
const originY = chunkY * CHUNK_SIZE + localY;53
const originY = chunkY * CHUNK_SIZE + localY;53
const persistent = !!mobDefinition(config.mobTypeId)?.persistent;54
const persistent = !!mobDefinition(config.mobTypeId)?.persistent;55
const delayMs = Math.max(0, (config.respawnDelaySeconds | 0) * 1000);54
56
55
if (config.centralExchange)57
if (config.centralExchange)56
{58
{@@ -61,6 +63,8 @@ export function collectSpawnRequests (world)61
{ continue; }63
{ continue; }62
if ((counts.get(config.spawnerId) ?? 0) >= config.maxAlive)64
if ((counts.get(config.spawnerId) ?? 0) >= config.maxAlive)63
{ break; }65
{ break; }66
if (!consumeSpawnSlot(world, config.spawnerId, delayMs, now))67
{ break; }64
const tile = pickSpawnTile(68
const tile = pickSpawnTile(65
world,69
world,66
originX,70
originX,@@ -92,11 +96,13 @@ export function collectSpawnRequests (world)92
displayName: staff.name,96
displayName: staff.name,93
equipment: config.equipment,97
equipment: config.equipment,94
sells: [],98
sells: [],99
drops: config.drops,95
buysItems: false,100
buysItems: false,96
hiddenDiscount: config.hiddenDiscount,101
hiddenDiscount: config.hiddenDiscount,97
centralExchange: true,102
centralExchange: true,98
townGuard: false,103
townGuard: false,99
dialogueId: config.dialogueId || null104
dialogueId: config.dialogueId || null,105
respawnDelaySeconds: config.respawnDelaySeconds100
});106
});101
counts.set(config.spawnerId, (counts.get(config.spawnerId) ?? 0) + 1);107
counts.set(config.spawnerId, (counts.get(config.spawnerId) ?? 0) + 1);102
}108
}@@ -105,6 +111,8 @@ export function collectSpawnRequests (world)105
111
106
while ((counts.get(config.spawnerId) ?? 0) < config.maxAlive)112
while ((counts.get(config.spawnerId) ?? 0) < config.maxAlive)107
{113
{114
if (!consumeSpawnSlot(world, config.spawnerId, delayMs, now))115
{ break; }108
const tile = pickSpawnTile(116
const tile = pickSpawnTile(109
world,117
world,110
originX,118
originX,@@ -136,11 +144,13 @@ export function collectSpawnRequests (world)136
displayName: config.displayName,144
displayName: config.displayName,137
equipment: config.equipment,145
equipment: config.equipment,138
sells: config.sells,146
sells: config.sells,147
drops: config.drops,139
buysItems: config.buysItems,148
buysItems: config.buysItems,140
hiddenDiscount: config.hiddenDiscount,149
hiddenDiscount: config.hiddenDiscount,141
centralExchange: false,150
centralExchange: false,142
townGuard: !!config.townGuard || isTownGuardMob(config.mobTypeId),151
townGuard: !!config.townGuard || isTownGuardMob(config.mobTypeId),143
dialogueId: config.dialogueId || null152
dialogueId: config.dialogueId || null,153
respawnDelaySeconds: config.respawnDelaySeconds144
});154
});145
counts.set(config.spawnerId, (counts.get(config.spawnerId) ?? 0) + 1);155
counts.set(config.spawnerId, (counts.get(config.spawnerId) ?? 0) + 1);146
}156
}@@ -150,6 +160,58 @@ export function collectSpawnRequests (world)150
return requests;160
return requests;151
}161
}152
162
163
function ensurePendingRespawns (world)164
{165
if (!world.pendingSpawnerRespawns)166
{ world.pendingSpawnerRespawns = new Map(); }167
return world.pendingSpawnerRespawns;168
}169
170
/**171
* Schedule a delayed refill slot after a spawned mob dies.172
* Delay 0 means the next collect pass may refill immediately (no pending entry).173
*/174
export function scheduleSpawnerRespawn (world, spawnerId, respawnDelaySeconds, now = Date.now())175
{176
if (!spawnerId)177
{ return; }178
const delayMs = Math.max(0, (respawnDelaySeconds | 0) * 1000);179
if (delayMs <= 0)180
{ return; }181
const pending = ensurePendingRespawns(world);182
const list = pending.get(spawnerId) ?? [];183
list.push(now + delayMs);184
list.sort((a, b) => a - b);185
pending.set(spawnerId, list);186
}187
188
/**189
* Decide whether one more mob may spawn for this spawner right now.190
* - delay 0 / empty pending: allow (initial populate + instant refill)191
* - otherwise: only if a pending timer is due; consume one due timer192
*/193
function consumeSpawnSlot (world, spawnerId, delayMs, now)194
{195
if (delayMs <= 0)196
{ return true; }197
const pending = ensurePendingRespawns(world);198
const list = pending.get(spawnerId);199
if (!list?.length)200
{201
// No death timers yet — first populate / recovery after unload.202
return true;203
}204
const readyIndex = list.findIndex((readyAt) => readyAt <= now);205
if (readyIndex < 0)206
{ return false; }207
list.splice(readyIndex, 1);208
if (!list.length)209
{ pending.delete(spawnerId); }210
else211
{ pending.set(spawnerId, list); }212
return true;213
}214
153
export function mobComponents (request)215
export function mobComponents (request)154
{216
{155
const def = mobDefinition(request.mobTypeId) ?? mobDefinition("deer");217
const def = mobDefinition(request.mobTypeId) ?? mobDefinition("deer");@@ -208,7 +270,9 @@ export function mobComponents (request)208
townGuard: !!request.townGuard || isTownGuardMob(def.mobTypeId),270
townGuard: !!request.townGuard || isTownGuardMob(def.mobTypeId),209
stationTileX: null,271
stationTileX: null,210
stationTileY: null,272
stationTileY: null,211
dialogueId: request.dialogueId ? String(request.dialogueId) : null273
dialogueId: request.dialogueId ? String(request.dialogueId) : null,274
drops: Array.isArray(request.drops) ? request.drops : [],275
respawnDelaySeconds: Math.max(0, request.respawnDelaySeconds | 0)212
};276
};213
}277
}214
if (def.persistent)278
if (def.persistent)@@ -136,7 +136,7 @@ export class WorkerWorld
136
136
case WorkerMessage.stepSystems:
137
137
return this.#stepSystems(message.now, message.dt ?? (1 / 20));
138
138
case WorkerMessage.stepSpawners:
139
return { spawnRequests: collectSpawnRequests(this) };
139
return { spawnRequests: collectSpawnRequests(this, Date.now()) };
140
140
case WorkerMessage.setGroundItems:
141
141
setGroundItemsForRegion(this, message.regionX, message.regionY, message.items, tileToRegion);
142
142
return { ok: true };
@@ -136,7 +136,7 @@ export class WorkerWorld136
case WorkerMessage.stepSystems:136
case WorkerMessage.stepSystems:137
return this.#stepSystems(message.now, message.dt ?? (1 / 20));137
return this.#stepSystems(message.now, message.dt ?? (1 / 20));138
case WorkerMessage.stepSpawners:138
case WorkerMessage.stepSpawners:139
return { spawnRequests: collectSpawnRequests(this) };139
return { spawnRequests: collectSpawnRequests(this, Date.now()) };140
case WorkerMessage.setGroundItems:140
case WorkerMessage.setGroundItems:141
setGroundItemsForRegion(this, message.regionX, message.regionY, message.items, tileToRegion);141
setGroundItemsForRegion(this, message.regionX, message.regionY, message.items, tileToRegion);142
return { ok: true };142
return { ok: true };