Add humanoid Aggressive flag and level-based spell cast chance.
@@ -9,6 +9,7 @@ import {
9
9
isCentralExchangeSpawner,
10
10
spawnerEquipmentSlot
11
11
} from "/shared/definitions/mobs.js";
12
import { mobSpellCastChancePercent } from "/shared/definitions/mobCombat.js";
12
13
import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";
13
14
import { centralExchangeStaffCount } from "/shared/market/exchange.js";
14
15
import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing } from "/shared/definitions/items.js";
@@ -410,6 +411,20 @@ export function initTileConfigModal ({ onSave, onRemove })
410
411
);
411
412
}
412
413
414
const aggressiveLabel = document.createElement("label");
415
aggressiveLabel.className = "spawner-buys-row";
416
const aggressive = document.createElement("input");
417
aggressive.type = "checkbox";
418
aggressive.name = "aggressive";
419
aggressive.checked = !!config.aggressive;
420
aggressive.addEventListener("change", () => syncBountyForAggressive());
421
aggressiveLabel.append(aggressive, document.createTextNode(" Aggressive (attacks players in range)"));
422
wrap.append(aggressiveLabel);
423
const aggressiveHint = document.createElement("p");
424
aggressiveHint.className = "hint";
425
aggressiveHint.textContent = "When Aggressive is on, Bounty is forced to 0.";
426
wrap.append(aggressiveHint);
427
413
428
const equipHeader = document.createElement("div");
414
429
equipHeader.className = "spawner-sells-header";
415
430
const equipTitle = document.createElement("strong");
@@ -525,7 +540,7 @@ export function initTileConfigModal ({ onSave, onRemove })
525
540
!spellsDraft.some((line) => line.spellId === def.spellId));
526
541
if (!available)
527
542
{ return; }
528
spellsDraft.push({ spellId: available.spellId, chance: 100 });
543
spellsDraft.push({ spellId: available.spellId });
529
544
renderSpellsList();
530
545
});
531
546
header.append(titleEl, addBtn);
@@ -538,14 +553,13 @@ export function initTileConfigModal ({ onSave, onRemove })
538
553
539
554
const hint = document.createElement("p");
540
555
hint.className = "hint";
541
hint.textContent = "Chance is the % roll when the mob picks that spell to cast. Only Attack (entity) spells are used in combat. Mobs only learn spells their Level can cast.";
556
hint.textContent = "Cast chance is derived from the mob Level (shown as a label). Only Attack (entity) spells are used in combat. Mobs only learn spells their Level can cast.";
542
557
wrap.append(hint);
543
558
544
559
if (!Array.isArray(spellsDraft) || !spellsDraft.length)
545
560
{
546
561
spellsDraft = (config?.spells ?? []).map((line) => ({
547
spellId: String(line.spellId ?? ""),
548
chance: Math.max(0, Math.min(100, Number(line.chance) || 0)) | 0
562
spellId: String(line.spellId ?? "")
549
563
})).filter((line) => line.spellId);
550
564
}
551
565
queueMicrotask(() => renderSpellsList());
@@ -567,6 +581,7 @@ export function initTileConfigModal ({ onSave, onRemove })
567
581
return;
568
582
}
569
583
const level = Math.max(1, Number(form.querySelector('[name="level"]')?.value) || 1) | 0;
584
const castChance = mobSpellCastChancePercent(level);
570
585
for (let index = 0; index < spellsDraft.length; index++)
571
586
{
572
587
const line = spellsDraft[index];
@@ -591,21 +606,13 @@ export function initTileConfigModal ({ onSave, onRemove })
591
606
renderSpellsList();
592
607
});
593
608
594
const chance = document.createElement("input");
595
chance.type = "number";
596
chance.min = "0";
597
chance.max = "100";
598
chance.value = String(line.chance);
599
chance.title = "Cast chance %";
600
chance.addEventListener("change", () =>
601
{
602
spellsDraft[index].chance = Math.max(0, Math.min(100, Number(chance.value) || 0)) | 0;
603
});
604
605
609
const minLv = def?.minMagicLevel | 0 || 1;
606
const status = document.createElement("span");
607
status.className = "hint";
608
status.textContent = level < minLv ? `needs Lv.${minLv}` : `${line.chance}%`;
610
const chanceLabel = document.createElement("span");
611
chanceLabel.className = "hint";
612
chanceLabel.title = "Cast chance from mob Level";
613
chanceLabel.textContent = level < minLv
614
? `needs Lv.${minLv}`
615
: `cast ${castChance}%`;
609
616
610
617
const remove = document.createElement("button");
611
618
remove.type = "button";
@@ -616,11 +623,27 @@ export function initTileConfigModal ({ onSave, onRemove })
616
623
renderSpellsList();
617
624
});
618
625
619
row.append(select, chance, status, remove);
626
row.append(select, chanceLabel, remove);
620
627
list.append(row);
621
628
}
622
629
}
623
630
631
function syncBountyForAggressive ()
632
{
633
const bountyInput = form.querySelector('[name="bounty"]');
634
const aggressiveInput = form.querySelector('[name="aggressive"]');
635
if (!bountyInput)
636
{ return; }
637
const aggressive = !!aggressiveInput?.checked;
638
if (aggressive)
639
{
640
bountyInput.value = "0";
641
bountyInput.disabled = true;
642
}
643
else
644
{ bountyInput.disabled = false; }
645
}
646
624
647
function openSpawner (ctx)
625
648
{
626
649
context = { kind: "spawner", ...ctx };
@@ -661,13 +684,14 @@ export function initTileConfigModal ({ onSave, onRemove })
661
684
syncWanderMin();
662
685
syncHumanoidSection(defaults);
663
686
syncSpellsSection(defaults);
687
syncBountyForAggressive();
664
688
});
665
689
spellsDraft = (config.spells ?? []).map((line) => ({
666
spellId: String(line.spellId ?? ""),
667
chance: Math.max(0, Math.min(100, Number(line.chance) || 0)) | 0
690
spellId: String(line.spellId ?? "")
668
691
})).filter((line) => line.spellId);
669
692
syncHumanoidSection(config);
670
693
syncSpellsSection(config);
694
syncBountyForAggressive();
671
695
show(true);
672
696
}
673
697
@@ -711,6 +735,7 @@ export function initTileConfigModal ({ onSave, onRemove })
711
735
maxWanderRangeTiles: Number(data.get("maxWanderRangeTiles") || 4),
712
736
level: Number(data.get("level") || 1),
713
737
bounty: Number(data.get("bounty") || 0),
738
aggressive: data.get("aggressive") === "on",
714
739
spawnerId: String(data.get("spawnerId") || context.config.spawnerId),
715
740
sex: String(data.get("sex") || "male"),
716
741
displayName: String(data.get("displayName") || ""),
@@ -9,6 +9,7 @@ import {9
isCentralExchangeSpawner,9
isCentralExchangeSpawner,10
spawnerEquipmentSlot10
spawnerEquipmentSlot11
} from "/shared/definitions/mobs.js";11
} from "/shared/definitions/mobs.js";12
import { mobSpellCastChancePercent } from "/shared/definitions/mobCombat.js";12
import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";13
import { SPELL_DEFINITIONS } from "/shared/definitions/spells.js";13
import { centralExchangeStaffCount } from "/shared/market/exchange.js";14
import { centralExchangeStaffCount } from "/shared/market/exchange.js";14
import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing } from "/shared/definitions/items.js";15
import { ITEM_DEFINITIONS, itemDefinition, isDyeableClothing } from "/shared/definitions/items.js";@@ -410,6 +411,20 @@ export function initTileConfigModal ({ onSave, onRemove })410
);411
);411
}412
}412
413
414
const aggressiveLabel = document.createElement("label");415
aggressiveLabel.className = "spawner-buys-row";416
const aggressive = document.createElement("input");417
aggressive.type = "checkbox";418
aggressive.name = "aggressive";419
aggressive.checked = !!config.aggressive;420
aggressive.addEventListener("change", () => syncBountyForAggressive());421
aggressiveLabel.append(aggressive, document.createTextNode(" Aggressive (attacks players in range)"));422
wrap.append(aggressiveLabel);423
const aggressiveHint = document.createElement("p");424
aggressiveHint.className = "hint";425
aggressiveHint.textContent = "When Aggressive is on, Bounty is forced to 0.";426
wrap.append(aggressiveHint);427
413
const equipHeader = document.createElement("div");428
const equipHeader = document.createElement("div");414
equipHeader.className = "spawner-sells-header";429
equipHeader.className = "spawner-sells-header";415
const equipTitle = document.createElement("strong");430
const equipTitle = document.createElement("strong");@@ -525,7 +540,7 @@ export function initTileConfigModal ({ onSave, onRemove })525
!spellsDraft.some((line) => line.spellId === def.spellId));540
!spellsDraft.some((line) => line.spellId === def.spellId));526
if (!available)541
if (!available)527
{ return; }542
{ return; }528
spellsDraft.push({ spellId: available.spellId, chance: 100 });543
spellsDraft.push({ spellId: available.spellId });529
renderSpellsList();544
renderSpellsList();530
});545
});531
header.append(titleEl, addBtn);546
header.append(titleEl, addBtn);@@ -538,14 +553,13 @@ export function initTileConfigModal ({ onSave, onRemove })538
553
539
const hint = document.createElement("p");554
const hint = document.createElement("p");540
hint.className = "hint";555
hint.className = "hint";541
hint.textContent = "Chance is the % roll when the mob picks that spell to cast. Only Attack (entity) spells are used in combat. Mobs only learn spells their Level can cast.";556
hint.textContent = "Cast chance is derived from the mob Level (shown as a label). Only Attack (entity) spells are used in combat. Mobs only learn spells their Level can cast.";542
wrap.append(hint);557
wrap.append(hint);543
558
544
if (!Array.isArray(spellsDraft) || !spellsDraft.length)559
if (!Array.isArray(spellsDraft) || !spellsDraft.length)545
{560
{546
spellsDraft = (config?.spells ?? []).map((line) => ({561
spellsDraft = (config?.spells ?? []).map((line) => ({547
spellId: String(line.spellId ?? ""),562
spellId: String(line.spellId ?? "")548
chance: Math.max(0, Math.min(100, Number(line.chance) || 0)) | 0549
})).filter((line) => line.spellId);563
})).filter((line) => line.spellId);550
}564
}551
queueMicrotask(() => renderSpellsList());565
queueMicrotask(() => renderSpellsList());@@ -567,6 +581,7 @@ export function initTileConfigModal ({ onSave, onRemove })567
return;581
return;568
}582
}569
const level = Math.max(1, Number(form.querySelector('[name="level"]')?.value) || 1) | 0;583
const level = Math.max(1, Number(form.querySelector('[name="level"]')?.value) || 1) | 0;584
const castChance = mobSpellCastChancePercent(level);570
for (let index = 0; index < spellsDraft.length; index++)585
for (let index = 0; index < spellsDraft.length; index++)571
{586
{572
const line = spellsDraft[index];587
const line = spellsDraft[index];@@ -591,21 +606,13 @@ export function initTileConfigModal ({ onSave, onRemove })591
renderSpellsList();606
renderSpellsList();592
});607
});593
608
594
const chance = document.createElement("input");595
chance.type = "number";596
chance.min = "0";597
chance.max = "100";598
chance.value = String(line.chance);599
chance.title = "Cast chance %";600
chance.addEventListener("change", () =>601
{602
spellsDraft[index].chance = Math.max(0, Math.min(100, Number(chance.value) || 0)) | 0;603
});604
605
const minLv = def?.minMagicLevel | 0 || 1;609
const minLv = def?.minMagicLevel | 0 || 1;606
const status = document.createElement("span");610
const chanceLabel = document.createElement("span");607
status.className = "hint";611
chanceLabel.className = "hint";608
status.textContent = level < minLv ? `needs Lv.${minLv}` : `${line.chance}%`;612
chanceLabel.title = "Cast chance from mob Level";613
chanceLabel.textContent = level < minLv614
? `needs Lv.${minLv}`615
: `cast ${castChance}%`;609
616
610
const remove = document.createElement("button");617
const remove = document.createElement("button");611
remove.type = "button";618
remove.type = "button";@@ -616,11 +623,27 @@ export function initTileConfigModal ({ onSave, onRemove })616
renderSpellsList();623
renderSpellsList();617
});624
});618
625
619
row.append(select, chance, status, remove);626
row.append(select, chanceLabel, remove);620
list.append(row);627
list.append(row);621
}628
}622
}629
}623
630
631
function syncBountyForAggressive ()632
{633
const bountyInput = form.querySelector('[name="bounty"]');634
const aggressiveInput = form.querySelector('[name="aggressive"]');635
if (!bountyInput)636
{ return; }637
const aggressive = !!aggressiveInput?.checked;638
if (aggressive)639
{640
bountyInput.value = "0";641
bountyInput.disabled = true;642
}643
else644
{ bountyInput.disabled = false; }645
}646
624
function openSpawner (ctx)647
function openSpawner (ctx)625
{648
{626
context = { kind: "spawner", ...ctx };649
context = { kind: "spawner", ...ctx };@@ -661,13 +684,14 @@ export function initTileConfigModal ({ onSave, onRemove })661
syncWanderMin();684
syncWanderMin();662
syncHumanoidSection(defaults);685
syncHumanoidSection(defaults);663
syncSpellsSection(defaults);686
syncSpellsSection(defaults);687
syncBountyForAggressive();664
});688
});665
spellsDraft = (config.spells ?? []).map((line) => ({689
spellsDraft = (config.spells ?? []).map((line) => ({666
spellId: String(line.spellId ?? ""),690
spellId: String(line.spellId ?? "")667
chance: Math.max(0, Math.min(100, Number(line.chance) || 0)) | 0668
})).filter((line) => line.spellId);691
})).filter((line) => line.spellId);669
syncHumanoidSection(config);692
syncHumanoidSection(config);670
syncSpellsSection(config);693
syncSpellsSection(config);694
syncBountyForAggressive();671
show(true);695
show(true);672
}696
}673
697
@@ -711,6 +735,7 @@ export function initTileConfigModal ({ onSave, onRemove })711
maxWanderRangeTiles: Number(data.get("maxWanderRangeTiles") || 4),735
maxWanderRangeTiles: Number(data.get("maxWanderRangeTiles") || 4),712
level: Number(data.get("level") || 1),736
level: Number(data.get("level") || 1),713
bounty: Number(data.get("bounty") || 0),737
bounty: Number(data.get("bounty") || 0),738
aggressive: data.get("aggressive") === "on",714
spawnerId: String(data.get("spawnerId") || context.config.spawnerId),739
spawnerId: String(data.get("spawnerId") || context.config.spawnerId),715
sex: String(data.get("sex") || "male"),740
sex: String(data.get("sex") || "male"),716
displayName: String(data.get("displayName") || ""),741
displayName: String(data.get("displayName") || ""),@@ -184,8 +184,8 @@ Each entry is a short note on behaviour and where the code lives. Update this fi
184
184
## Spawners
185
185
186
186
**Status:** full
187
**Spec:** Authored chunk spawners (`data.spawners[]`) with mob type, max alive, spawn range, and **max wander range** (≥ spawn range). Legacy `BlockType.spawner` tiles migrate into this array on decode. They fire only in open, simulating chunks. When a chunk first becomes simulating, spawners **pre-heat** and place up to `maxAlive` immediately so the area looks populated. Spawned mobs get `SpawnOrigin` (origin tile + wander range); idle wander goals must stay inside max wander range, while combat chase / approach may leave the area. Persistence follows the mob definition (deer are not persistent). In play, spawners are invisible and non-blocking; players may place real blocks on the same tile. Wildlife options include deer and rats; the editor lists every mob definition as a placeable spawner. Hovering a spawner in the world editor highlights spawn range (cyan) and wander range (amber). Pigeons are not ambient wildlife. Living mobs (deer, rats, etc.) can always fight back when attacked (retaliate on first swing); **rats are aggressive** and auto-engage players within 5 tiles with line of sight.; courier pigeons cannot.
188
**Code:** `server/src/simulation/spawners.js`, `server/src/simulation/workerWorld.js`, `server/src/world/chunkData.js`, `shared/definitions/mobs.js`, `shared/definitions/mobCombat.js`, `client/assets/mobs/deer/`, `client/assets/mobs/rat/`
187
**Spec:** Authored chunk spawners (`data.spawners[]`) with mob type, max alive, spawn range, and **max wander range** (≥ spawn range). Legacy `BlockType.spawner` tiles migrate into this array on decode. They fire only in open, simulating chunks. When a chunk first becomes simulating, spawners **pre-heat** and place up to `maxAlive` immediately so the area looks populated. Spawned mobs get `SpawnOrigin` (origin tile + wander range); idle wander goals must stay inside max wander range, while combat chase / approach may leave the area. Persistence follows the mob definition (deer are not persistent). In play, spawners are invisible and non-blocking; players may place real blocks on the same tile. Wildlife options include deer and rats; the editor lists every mob definition as a placeable spawner. Hovering a spawner in the world editor highlights spawn range (cyan) and wander range (amber). Pigeons are not ambient wildlife. Living mobs (deer, rats, etc.) can always fight back when attacked (retaliate on first swing); **rats are aggressive** and auto-engage players within 5 tiles with line of sight. **Humanoid** spawners (incl. town guards / exchange) have an editor **Aggressive** flag for the same in-range aggro; Aggressive forces **Bounty** to 0. Spawner **Level** sets skills/HP and **spell cast chance %** (= level, capped 1–100; shown as a label, not editable).; courier pigeons cannot.
188
**Code:** `server/src/simulation/spawners.js`, `server/src/simulation/workerWorld.js`, `server/src/world/chunkData.js`, `shared/definitions/mobs.js`, `shared/definitions/mobCombat.js`, `client/src/editor/tileConfigModal.js`, `client/assets/mobs/deer/`, `client/assets/mobs/rat/`
189
189
190
190
## Mob definitions (content schema)
191
191
@@ -184,8 +184,8 @@ Each entry is a short note on behaviour and where the code lives. Update this fi184
## Spawners184
## Spawners185
185
186
**Status:** full 186
**Status:** full 187
**Spec:** Authored chunk spawners (`data.spawners[]`) with mob type, max alive, spawn range, and **max wander range** (≥ spawn range). Legacy `BlockType.spawner` tiles migrate into this array on decode. They fire only in open, simulating chunks. When a chunk first becomes simulating, spawners **pre-heat** and place up to `maxAlive` immediately so the area looks populated. Spawned mobs get `SpawnOrigin` (origin tile + wander range); idle wander goals must stay inside max wander range, while combat chase / approach may leave the area. Persistence follows the mob definition (deer are not persistent). In play, spawners are invisible and non-blocking; players may place real blocks on the same tile. Wildlife options include deer and rats; the editor lists every mob definition as a placeable spawner. Hovering a spawner in the world editor highlights spawn range (cyan) and wander range (amber). Pigeons are not ambient wildlife. Living mobs (deer, rats, etc.) can always fight back when attacked (retaliate on first swing); **rats are aggressive** and auto-engage players within 5 tiles with line of sight.; courier pigeons cannot. 187
**Spec:** Authored chunk spawners (`data.spawners[]`) with mob type, max alive, spawn range, and **max wander range** (≥ spawn range). Legacy `BlockType.spawner` tiles migrate into this array on decode. They fire only in open, simulating chunks. When a chunk first becomes simulating, spawners **pre-heat** and place up to `maxAlive` immediately so the area looks populated. Spawned mobs get `SpawnOrigin` (origin tile + wander range); idle wander goals must stay inside max wander range, while combat chase / approach may leave the area. Persistence follows the mob definition (deer are not persistent). In play, spawners are invisible and non-blocking; players may place real blocks on the same tile. Wildlife options include deer and rats; the editor lists every mob definition as a placeable spawner. Hovering a spawner in the world editor highlights spawn range (cyan) and wander range (amber). Pigeons are not ambient wildlife. Living mobs (deer, rats, etc.) can always fight back when attacked (retaliate on first swing); **rats are aggressive** and auto-engage players within 5 tiles with line of sight. **Humanoid** spawners (incl. town guards / exchange) have an editor **Aggressive** flag for the same in-range aggro; Aggressive forces **Bounty** to 0. Spawner **Level** sets skills/HP and **spell cast chance %** (= level, capped 1–100; shown as a label, not editable).; courier pigeons cannot. 188
**Code:** `server/src/simulation/spawners.js`, `server/src/simulation/workerWorld.js`, `server/src/world/chunkData.js`, `shared/definitions/mobs.js`, `shared/definitions/mobCombat.js`, `client/assets/mobs/deer/`, `client/assets/mobs/rat/`188
**Code:** `server/src/simulation/spawners.js`, `server/src/simulation/workerWorld.js`, `server/src/world/chunkData.js`, `shared/definitions/mobs.js`, `shared/definitions/mobCombat.js`, `client/src/editor/tileConfigModal.js`, `client/assets/mobs/deer/`, `client/assets/mobs/rat/`189
189
190
## Mob definitions (content schema)190
## Mob definitions (content schema)191
191
@@ -4,6 +4,7 @@ import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";
4
4
import { mobDefinition } from "../../../shared/definitions/mobs.js";
5
5
import {
6
6
mobCanFightType,
7
mobCanFight,
7
8
mobMeleeAttackProfile,
8
9
mobSkillLevels,
9
10
mobIsAggressive,
@@ -298,7 +299,11 @@ export function stepAggression (world, now = Date.now())
298
299
if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))
299
300
{ continue; }
300
301
const def = mobDefinition(entity.creature.mobTypeId);
301
if (!mobIsAggressive(def))
302
const origin = world.ecs.get(entity.handle, Component.spawnOrigin);
303
const aggressive = origin
304
? !!origin.aggressive
305
: mobIsAggressive(def);
306
if (!aggressive || !mobCanFight(def))
302
307
{ continue; }
303
308
if (world.ecs.has(entity.handle, Component.dead))
304
309
{ continue; }
@@ -4,6 +4,7 @@ import { EquipmentKind } from "../../../shared/definitions/equipmentKinds.js";4
import { mobDefinition } from "../../../shared/definitions/mobs.js";4
import { mobDefinition } from "../../../shared/definitions/mobs.js";5
import {5
import {6
mobCanFightType,6
mobCanFightType,7
mobCanFight,7
mobMeleeAttackProfile,8
mobMeleeAttackProfile,8
mobSkillLevels,9
mobSkillLevels,9
mobIsAggressive,10
mobIsAggressive,@@ -298,7 +299,11 @@ export function stepAggression (world, now = Date.now())298
if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))299
if (!world.chunkIsSimulating?.(entity.position.tileX, entity.position.tileY))299
{ continue; }300
{ continue; }300
const def = mobDefinition(entity.creature.mobTypeId);301
const def = mobDefinition(entity.creature.mobTypeId);301
if (!mobIsAggressive(def))302
const origin = world.ecs.get(entity.handle, Component.spawnOrigin);303
const aggressive = origin304
? !!origin.aggressive305
: mobIsAggressive(def);306
if (!aggressive || !mobCanFight(def))302
{ continue; }307
{ continue; }303
if (world.ecs.has(entity.handle, Component.dead))308
if (world.ecs.has(entity.handle, Component.dead))304
{ continue; }309
{ continue; }@@ -1,5 +1,10 @@
1
1
import { GAIT, CHUNK_SIZE } from "../../../shared/protocol/constants.js";
2
import { mobCanFight, mobSkillLevels, mobHealthForLevel } from "../../../shared/definitions/mobCombat.js";
2
import {
3
mobCanFight,
4
mobSkillLevels,
5
mobHealthForLevel,
6
mobSpellCastChancePercent
7
} from "../../../shared/definitions/mobCombat.js";
3
8
import {
4
9
normalizeSpawnerConfig,
5
10
listAmbientMobTypes,
@@ -7,7 +12,8 @@ import {
7
12
mobSpriteName,
8
13
MobId,
9
14
spawnerEquipmentSlot,
10
isTownGuardMob
15
isTownGuardMob,
16
isHumanoidMob
11
17
} from "../../../shared/definitions/mobs.js";
12
18
import { spellDefinition } from "../../../shared/definitions/spells.js";
13
19
import { LeatherItemId } from "../../../shared/definitions/leatherItems.js";
@@ -68,6 +74,7 @@ export function collectSpawnRequests (world)
68
74
wanderRangeTiles: config.maxWanderRangeTiles,
69
75
level: config.level,
70
76
bounty: config.bounty,
77
aggressive: !!config.aggressive,
71
78
spells: config.spells,
72
79
persistent,
73
80
sex: staff.sex,
@@ -99,6 +106,9 @@ export function collectSpawnRequests (world)
99
106
wanderRangeTiles: config.maxWanderRangeTiles,
100
107
level: config.level,
101
108
bounty: config.bounty,
109
aggressive: isHumanoidMob(config.mobTypeId) || config.townGuard
110
? !!config.aggressive
111
: undefined,
102
112
spells: config.spells,
103
113
persistent,
104
114
sex: config.sex,
@@ -153,13 +163,21 @@ export function mobComponents (request)
153
163
};
154
164
if (request.spawnerId)
155
165
{
166
const aggressive = request.aggressive != null
167
? !!request.aggressive
168
: !!def.aggressive;
169
// Humanoid Aggressive flag forces bounty 0; wildlife can be aggressive and still pay kill bounty.
170
const bounty = request.aggressive === true
171
? 0
172
: (Math.max(0, Number(request.bounty) || 0) | 0);
156
173
components.spawnOrigin = {
157
174
spawnerId: request.spawnerId,
158
175
originTileX: request.originTileX ?? request.tileX,
159
176
originTileY: request.originTileY ?? request.tileY,
160
177
wanderRangeTiles: request.wanderRangeTiles ?? 4,
161
bounty: Math.max(0, Number(request.bounty) || 0) | 0,
178
bounty,
162
179
level,
180
aggressive,
163
181
centralExchange: !!request.centralExchange,
164
182
townGuard: !!request.townGuard || isTownGuardMob(def.mobTypeId),
165
183
stationTileX: null,
@@ -189,11 +207,12 @@ export function mobComponents (request)
189
207
const knownSpells = normalizeMobSpells(request.spells, level);
190
208
if (knownSpells.length)
191
209
{
210
const castChance = mobSpellCastChancePercent(level);
192
211
components.spells = {
193
212
known: knownSpells.map((entry) => entry.spellId),
194
213
favorites: [],
195
214
autoCast: false,
196
castChances: Object.fromEntries(knownSpells.map((entry) => [entry.spellId, entry.chance]))
215
castChances: Object.fromEntries(knownSpells.map((entry) => [entry.spellId, castChance]))
197
216
};
198
217
components.spellcasting = {
199
218
armedSpellId: null,
@@ -280,10 +299,7 @@ function normalizeMobSpells (raw, level)
280
299
if (lv < minLevel)
281
300
{ continue; }
282
301
seen.add(spellId);
283
out.push({
284
spellId,
285
chance: Math.max(0, Math.min(100, Number(entry.chance) || 0)) | 0
286
});
302
out.push({ spellId });
287
303
}
288
304
return out;
289
305
}
@@ -1,5 +1,10 @@1
import { GAIT, CHUNK_SIZE } from "../../../shared/protocol/constants.js";1
import { GAIT, CHUNK_SIZE } from "../../../shared/protocol/constants.js";2
import { mobCanFight, mobSkillLevels, mobHealthForLevel } from "../../../shared/definitions/mobCombat.js";2
import {3
mobCanFight,4
mobSkillLevels,5
mobHealthForLevel,6
mobSpellCastChancePercent7
} from "../../../shared/definitions/mobCombat.js";3
import {8
import {4
normalizeSpawnerConfig,9
normalizeSpawnerConfig,5
listAmbientMobTypes,10
listAmbientMobTypes,@@ -7,7 +12,8 @@ import {7
mobSpriteName,12
mobSpriteName,8
MobId,13
MobId,9
spawnerEquipmentSlot,14
spawnerEquipmentSlot,10
isTownGuardMob15
isTownGuardMob,16
isHumanoidMob11
} from "../../../shared/definitions/mobs.js";17
} from "../../../shared/definitions/mobs.js";12
import { spellDefinition } from "../../../shared/definitions/spells.js";18
import { spellDefinition } from "../../../shared/definitions/spells.js";13
import { LeatherItemId } from "../../../shared/definitions/leatherItems.js";19
import { LeatherItemId } from "../../../shared/definitions/leatherItems.js";@@ -68,6 +74,7 @@ export function collectSpawnRequests (world)68
wanderRangeTiles: config.maxWanderRangeTiles,74
wanderRangeTiles: config.maxWanderRangeTiles,69
level: config.level,75
level: config.level,70
bounty: config.bounty,76
bounty: config.bounty,77
aggressive: !!config.aggressive,71
spells: config.spells,78
spells: config.spells,72
persistent,79
persistent,73
sex: staff.sex,80
sex: staff.sex,@@ -99,6 +106,9 @@ export function collectSpawnRequests (world)99
wanderRangeTiles: config.maxWanderRangeTiles,106
wanderRangeTiles: config.maxWanderRangeTiles,100
level: config.level,107
level: config.level,101
bounty: config.bounty,108
bounty: config.bounty,109
aggressive: isHumanoidMob(config.mobTypeId) || config.townGuard110
? !!config.aggressive111
: undefined,102
spells: config.spells,112
spells: config.spells,103
persistent,113
persistent,104
sex: config.sex,114
sex: config.sex,@@ -153,13 +163,21 @@ export function mobComponents (request)153
};163
};154
if (request.spawnerId)164
if (request.spawnerId)155
{165
{166
const aggressive = request.aggressive != null167
? !!request.aggressive168
: !!def.aggressive;169
// Humanoid Aggressive flag forces bounty 0; wildlife can be aggressive and still pay kill bounty.170
const bounty = request.aggressive === true171
? 0172
: (Math.max(0, Number(request.bounty) || 0) | 0);156
components.spawnOrigin = {173
components.spawnOrigin = {157
spawnerId: request.spawnerId,174
spawnerId: request.spawnerId,158
originTileX: request.originTileX ?? request.tileX,175
originTileX: request.originTileX ?? request.tileX,159
originTileY: request.originTileY ?? request.tileY,176
originTileY: request.originTileY ?? request.tileY,160
wanderRangeTiles: request.wanderRangeTiles ?? 4,177
wanderRangeTiles: request.wanderRangeTiles ?? 4,161
bounty: Math.max(0, Number(request.bounty) || 0) | 0,178
bounty,162
level,179
level,180
aggressive,163
centralExchange: !!request.centralExchange,181
centralExchange: !!request.centralExchange,164
townGuard: !!request.townGuard || isTownGuardMob(def.mobTypeId),182
townGuard: !!request.townGuard || isTownGuardMob(def.mobTypeId),165
stationTileX: null,183
stationTileX: null,@@ -189,11 +207,12 @@ export function mobComponents (request)189
const knownSpells = normalizeMobSpells(request.spells, level);207
const knownSpells = normalizeMobSpells(request.spells, level);190
if (knownSpells.length)208
if (knownSpells.length)191
{209
{210
const castChance = mobSpellCastChancePercent(level);192
components.spells = {211
components.spells = {193
known: knownSpells.map((entry) => entry.spellId),212
known: knownSpells.map((entry) => entry.spellId),194
favorites: [],213
favorites: [],195
autoCast: false,214
autoCast: false,196
castChances: Object.fromEntries(knownSpells.map((entry) => [entry.spellId, entry.chance]))215
castChances: Object.fromEntries(knownSpells.map((entry) => [entry.spellId, castChance]))197
};216
};198
components.spellcasting = {217
components.spellcasting = {199
armedSpellId: null,218
armedSpellId: null,@@ -280,10 +299,7 @@ function normalizeMobSpells (raw, level)280
if (lv < minLevel)299
if (lv < minLevel)281
{ continue; }300
{ continue; }282
seen.add(spellId);301
seen.add(spellId);283
out.push({302
out.push({ spellId });284
spellId,285
chance: Math.max(0, Math.min(100, Number(entry.chance) || 0)) | 0286
});287
}303
}288
return out;304
return out;289
}305
}@@ -7,7 +7,7 @@ import {
7
7
mobLevelDisplayName,
8
8
mobDefinition
9
9
} from "../../shared/definitions/mobs.js";
10
import { mobCanFight } from "../../shared/definitions/mobCombat.js";
10
import { mobCanFight, mobSpellCastChancePercent } from "../../shared/definitions/mobCombat.js";
11
11
import { SpellId } from "../../shared/definitions/spells.js";
12
12
import { SkillId } from "../../shared/definitions/skills.js";
13
13
import { mobComponents } from "../src/simulation/spawners.js";
@@ -39,8 +39,19 @@ test("spawner config keeps bounty, level, and spells", () =>
39
39
assert.equal(config.bounty, 25);
40
40
assert.equal(config.spells.length, 2);
41
41
assert.equal(config.spells[0].spellId, SpellId.spark);
42
assert.equal(config.spells[0].chance, 75);
43
assert.equal(config.spells[1].chance, 0);
42
assert.equal(config.spells[0].chance, undefined);
43
assert.equal(config.spells[1].spellId, SpellId.light);
44
});
45
46
test("humanoid aggressive forces bounty to 0", () =>
47
{
48
const config = normalizeSpawnerConfig({
49
mobTypeId: MobId.humanoid,
50
bounty: 50,
51
aggressive: true
52
}, "aggro-1");
53
assert.equal(config.aggressive, true);
54
assert.equal(config.bounty, 0);
44
55
});
45
56
46
57
test("town guard is a fightable humanoid body mob", () =>
@@ -70,8 +81,8 @@ test("mob components use spawner level for skills, HP, bounty origin, and spells
70
81
displayName: "Captain",
71
82
sex: "male",
72
83
spells: [
73
{ spellId: SpellId.spark, chance: 50 },
74
{ spellId: SpellId.light, chance: 100 }
84
{ spellId: SpellId.spark },
85
{ spellId: SpellId.light }
75
86
]
76
87
});
77
88
assert.equal(components.creature.level, 4);
@@ -83,7 +94,8 @@ test("mob components use spawner level for skills, HP, bounty origin, and spells
83
94
assert.equal(components.spawnOrigin.townGuard, true);
84
95
assert.ok(components.spells.known.includes(SpellId.spark));
85
96
assert.ok(components.spells.known.includes(SpellId.light));
86
assert.equal(components.spells.castChances[SpellId.spark], 50);
97
assert.equal(components.spells.castChances[SpellId.spark], mobSpellCastChancePercent(4));
98
assert.equal(components.spells.castChances[SpellId.light], mobSpellCastChancePercent(4));
87
99
});
88
100
89
101
test("mobs below spell minMagicLevel do not learn the spell", () =>
@@ -94,11 +106,28 @@ test("mobs below spell minMagicLevel do not learn the spell", () =>
94
106
mobTypeId: MobId.rat,
95
107
spawnerId: "0:0:4",
96
108
level: 1,
97
spells: [{ spellId: SpellId.spark, chance: 100 }]
109
spells: [{ spellId: SpellId.spark }]
98
110
});
99
111
assert.equal(components.spells, undefined);
100
112
});
101
113
114
test("aggressive humanoid stores aggro flag and zero bounty", () =>
115
{
116
const components = mobComponents({
117
tileX: 8,
118
tileY: 8,
119
mobTypeId: MobId.humanoid,
120
spawnerId: "aggro-npc",
121
level: 3,
122
bounty: 99,
123
aggressive: true,
124
displayName: "Bandit",
125
sex: "male"
126
});
127
assert.equal(components.spawnOrigin.aggressive, true);
128
assert.equal(components.spawnOrigin.bounty, 0);
129
});
130
102
131
test("killing a bounty mob awards player bounty and can wake town guards", () =>
103
132
{
104
133
const harness = makeSimulation({ workerCount: 1 });
@@ -7,7 +7,7 @@ import {7
mobLevelDisplayName,7
mobLevelDisplayName,8
mobDefinition8
mobDefinition9
} from "../../shared/definitions/mobs.js";9
} from "../../shared/definitions/mobs.js";10
import { mobCanFight } from "../../shared/definitions/mobCombat.js";10
import { mobCanFight, mobSpellCastChancePercent } from "../../shared/definitions/mobCombat.js";11
import { SpellId } from "../../shared/definitions/spells.js";11
import { SpellId } from "../../shared/definitions/spells.js";12
import { SkillId } from "../../shared/definitions/skills.js";12
import { SkillId } from "../../shared/definitions/skills.js";13
import { mobComponents } from "../src/simulation/spawners.js";13
import { mobComponents } from "../src/simulation/spawners.js";@@ -39,8 +39,19 @@ test("spawner config keeps bounty, level, and spells", () =>39
assert.equal(config.bounty, 25);39
assert.equal(config.bounty, 25);40
assert.equal(config.spells.length, 2);40
assert.equal(config.spells.length, 2);41
assert.equal(config.spells[0].spellId, SpellId.spark);41
assert.equal(config.spells[0].spellId, SpellId.spark);42
assert.equal(config.spells[0].chance, 75);42
assert.equal(config.spells[0].chance, undefined);43
assert.equal(config.spells[1].chance, 0);43
assert.equal(config.spells[1].spellId, SpellId.light);44
});45
46
test("humanoid aggressive forces bounty to 0", () =>47
{48
const config = normalizeSpawnerConfig({49
mobTypeId: MobId.humanoid,50
bounty: 50,51
aggressive: true52
}, "aggro-1");53
assert.equal(config.aggressive, true);54
assert.equal(config.bounty, 0);44
});55
});45
56
46
test("town guard is a fightable humanoid body mob", () =>57
test("town guard is a fightable humanoid body mob", () =>@@ -70,8 +81,8 @@ test("mob components use spawner level for skills, HP, bounty origin, and spells70
displayName: "Captain",81
displayName: "Captain",71
sex: "male",82
sex: "male",72
spells: [83
spells: [73
{ spellId: SpellId.spark, chance: 50 },84
{ spellId: SpellId.spark },74
{ spellId: SpellId.light, chance: 100 }85
{ spellId: SpellId.light }75
]86
]76
});87
});77
assert.equal(components.creature.level, 4);88
assert.equal(components.creature.level, 4);@@ -83,7 +94,8 @@ test("mob components use spawner level for skills, HP, bounty origin, and spells83
assert.equal(components.spawnOrigin.townGuard, true);94
assert.equal(components.spawnOrigin.townGuard, true);84
assert.ok(components.spells.known.includes(SpellId.spark));95
assert.ok(components.spells.known.includes(SpellId.spark));85
assert.ok(components.spells.known.includes(SpellId.light));96
assert.ok(components.spells.known.includes(SpellId.light));86
assert.equal(components.spells.castChances[SpellId.spark], 50);97
assert.equal(components.spells.castChances[SpellId.spark], mobSpellCastChancePercent(4));98
assert.equal(components.spells.castChances[SpellId.light], mobSpellCastChancePercent(4));87
});99
});88
100
89
test("mobs below spell minMagicLevel do not learn the spell", () =>101
test("mobs below spell minMagicLevel do not learn the spell", () =>@@ -94,11 +106,28 @@ test("mobs below spell minMagicLevel do not learn the spell", () =>94
mobTypeId: MobId.rat,106
mobTypeId: MobId.rat,95
spawnerId: "0:0:4",107
spawnerId: "0:0:4",96
level: 1,108
level: 1,97
spells: [{ spellId: SpellId.spark, chance: 100 }]109
spells: [{ spellId: SpellId.spark }]98
});110
});99
assert.equal(components.spells, undefined);111
assert.equal(components.spells, undefined);100
});112
});101
113
114
test("aggressive humanoid stores aggro flag and zero bounty", () =>115
{116
const components = mobComponents({117
tileX: 8,118
tileY: 8,119
mobTypeId: MobId.humanoid,120
spawnerId: "aggro-npc",121
level: 3,122
bounty: 99,123
aggressive: true,124
displayName: "Bandit",125
sex: "male"126
});127
assert.equal(components.spawnOrigin.aggressive, true);128
assert.equal(components.spawnOrigin.bounty, 0);129
});130
102
test("killing a bounty mob awards player bounty and can wake town guards", () =>131
test("killing a bounty mob awards player bounty and can wake town guards", () =>103
{132
{104
const harness = makeSimulation({ workerCount: 1 });133
const harness = makeSimulation({ workerCount: 1 });