Private mission encounter integration audit
Date: 2026-10-27. Read-only inspection of current Go, SQL, YAML, and existing test source. No production edits, REA, clients, servers, builds, or tests were run. This report separates present behavior from recommended integration.
Recommendation
Populate the fixed private world with ordinary character NPCs and use the
existing combat, threat, damage outcome, XP, corpse, and loot machinery. Stage
their first creation alongside the existing first-entry objective transaction.
Use their unique playfield == acceptedMission.world to scope retirement;
there is no need for a separate mission combat or loot system.
Two gaps need explicit treatment: mission retirement currently ignores NPCs and
their lifecycle queues; NPC pursuit currently ignores mission geometry. Merely
inserting NPCs into server.characters would leave both gaps.
Current construction and admission
missions.go: acceptedMissionretains uniqueworld, immutablelayout,objective,completed, and the original absolute deadline.insertMissionallocates world IDs from the persistedlast_playfield_idcounter, starting above public 16-bit resources, in the same transaction as the key/assignment.mission_geometry.go: starterMissionLayoutis the two-room template-331 building: room0 at grid (1,3), rotation2; room37 at (1,1), rotation0.mission_entrance.go: prepareMissionWorld_lockedregisters geometry only. It is also called during validation and queries; it should not itself publish NPCs or allocate their IDs.control.go: updateUser_lockedstages a zone transition. When entering a private mission, it callsstageMissionObjective_lockedon anitemStore, then commits the store beforeapplyUser_lockedpublishes the new player. This is the smallest existing transaction boundary for first population.world_items.go: stageMissionObjective_lockedis idempotent throughmission.objective != 0; it derives an interior placement from a real portal, projects onto the floor, and verifies room membership. It setsupdatedMissionso initialization survives restart. If initial objective and encounter population are staged together, this existing durable first-entry marker can cover both; never repopulate by testing whether any living NPC remains.
All encounter initialization must commit with its IDs before publishing live
actors. A failed first-entry transaction must leave no live NPC, worker entry,
counter increment, partial objective, or player relocation. A subsequent entry
must retry exactly once. Current storage cannot stage new NPC actors without
mutating live maps: writeNPCs_locked reads those maps, so a small explicit
staged-NPC addition to itemStore/its transaction is needed. Do not temporarily
insert live actors and undo them after SQL errors.
Existing NPC content and combat coverage
npcs.go: readNPCSpawns expands gamedata.NPCs groups into ordinary actors with
name, appearance, MonsterData, level, definition ID, optional npcMotion, and
health derived from the admitted combat profile. npcCombatProfile requires:
- A real
gamedata.NPCGroups[definition]withinferred_speciesstatus. - Matching MonsterData.
- An exact level entry in
gamedata.NPCCombatProfiles[monster][level]. - A matching template code when the profile specifies one.
Current gamedata/npc_combat.yaml contains only these admitted profiles:
| Actor | Coverage | Existing behavior |
|---|---|---|
| Leet, MonsterData17655 | Levels1 and2 | 100HP, 100XP, weapon120910/120911, initiative0, AggDef75, 1-5 credits, 50% QL1 Monster Parts42640, respawn100s, corpse180s |
| Salamander boss BSML, MonsterData30354 | Level4 only | Boss-specific template-code gate, original weapon121063/121064, provisional equipment subset |
The numeric health, XP, cash, probability, and lifecycle policy are expressly provisional in that YAML; the weapon/item endpoints are existing original data. Other visible NPC species or placeholder humans do not inherit combat simply from their appearance or level.
For an immediately combat-capable level1 reconstruction, an existing LE01 Leet
group is available, for example
950/district/2/group/0/authored_point in gamedata/zones/zone_950.yaml, with
appearance229, MonsterData17655, level1, and admitted species status. Reusing its
actor/profile construction is technically possible. That outdoor group does
not establish that Leets are the canonical Surveillance Office occupants.
Mission encounter selection/placement must be labeled reconstruction policy
until supported by mission content evidence. Arbitrary humanoid guard spawns
would require new reviewed weapon/profile coverage, not a copied Leet profile.
A shared constructor extracted from the existing spawn field assembly can
accept an admitted group, level, private playfield, position, and allocated ID.
It should not copy outdoor coordinates or preserve outdoor roaming behavior by
accident. A stationary idle mission NPC still needs npcMotion{home: position}
for shared combat pursuit/returning; roaming=false avoids wandering before
engagement. Keep one content selection, not a new configurable generator.
Shared gameplay path
combat.go: handleCombat,startAttack_locked,advanceCombat, andfinishDamageEffects_lockedprovide attacks, death, threat, corpse packets, and lifecycle scheduling.npc_threat.go: selectNPCTarget_lockedhandles retaliation. No additional encounter damage or XP code is needed.npc_outcome.go: saveRangedHit_locked,saveDamageOutcome_locked, andsaveNanoOutcome_lockedstage authoritative outcomes. Death, generated loot, item identity reservation, andwriteKillReward_lockedshare their outcome transaction. Publish throughrememberNPCOutcome_lockedonly after commit.npc_loot.go: rollCorpseLoot_lockeduses the same admitted profile and ordinary item instances.loot.go: canLoot_lockedenforces known actor, identical playfield, rights, expiry, and five-metre range; item transfer uses the existing inventory transaction.finishDamageEffects_lockedschedules respawn for every admitted NPC whose shared profile has nonzeroRespawnSeconds. Both current Leet profiles therefore respawn after100s, even in a mission. Decide the mission lifecycle deliberately: canonical one-life mission encounters should be suppressed by one shared actor/world lifecycle rule, consistently in persistedwriteNPCOutcome_lockedand runtime death scheduling. Do not mutate a shared global profile or implement separate damage/loot to avoid respawning.
Geometry-safe placement and movement
Existing source tests give useful fixed-layout anchors, without running them:
TestMissionScenePlacesTheNativeTwoRoomLayout: global room anchors[14,0,20]and[20,0,40]. Anchors are not themselves proof of clear floor.TestMissionSceneFindsWalkableCellsAndVerticalBounds:[15,1,16]is in the entrance room,[15,1,35]is in the chamber; empty/outside points are rejected.TestMissionWorldRegistersOriginalPortalLinksAtEveryRotation: the north layout's inter-room portal is near[15,0,30]with paired opposing faces.TestMissionSceneQueriesOriginalWallsAndFloor: an entrance wall crosses x17.601997 near z16; treating a room rectangle as entirely navigable is unsafe.
The minimal placement policy can adapt the objective's portal-relative approach,
using missionScene.portal, roomRotate, scene.floor, and scene.roomAt,
while retaining distance from the entry arrival, objective, other actors, and
doorway. Verify an actor-sized clearance with scene.sphere or shared
sceneGeometry.sphere, not only room membership. The known chamber sample
[15,1,35] is a candidate to validate, not a newly certified spawn coordinate.
This audit did not execute geometry probes.
npc_pursuit.go: advanceNPCPursuit_locked currently moves in a straight X/Z line
and samples only server.terrain[npc.playfield]. Private mission worlds have no
outdoor terrain; the position is then accepted without wall collision or floor
projection. Idle movement in roaming.go: advanceNPCs has the same outdoor-only
policy. Consequently fixed valid initial positions alone do not prevent NPCs
chasing through walls, leaving room bounds, or crossing floors.
The repository already dispatches private worlds through
sceneGeometry.line, sphere, and floor (mission_world.go,
scene_geometry.go), and has portal links plus room validation. Add the needed
indoor motion checks in the shared NPC movement path, preserving outdoor
behavior. mission_movement.go: vetoPosition and player_collision.go show the
existing movement/room semantics, but invoking player force integration merely
for NPC steering would need careful evaluation. A collision stop is smaller
than a full navigation system, though it does not solve paths around corners.
combatInRange_locked presently checks distance only; this source inspection
did not establish a wall line-of-sight gate for shared weapon attacks. Do not
claim that blocked pursuit alone prevents attacks through walls. Native mission
eligibility/progress and canonical LOS are the parent's separate investigation.
Persistence, IDs, and startup
world_store.go: npcStatealready persists definition ID, character position, motion/home, corpse rights/cash/deadline, presence, and hidden respawn deadline.writeNPCState_lockedwrites character + NPC + contributors and reserves the next NPC identity throughworld.last_npc_id.server.nextNPCis the next free identity, unlikenextItem, which is the last allocated item. Outdoor NPCs start at1000000. Allocate from the persisted counter; never derive NPC identity from room number or reuse a killed ID. Explicitly test exhaustion before adding new mission allocation logic.world_store.go: writeNPCs_lockedcheckpoints observed NPC state on staggered roughly20-second intervals, checkpoints zones when their last observer leaves, and handles immediate corpse ownership/cash changes. Initial population and retirement are significant changes and must bypass cadence.loadNPCsrestores living actors, corpses, mobile workers, and hidden respawn sources from SQLite, reconstructing profiles throughnpcCombatProfile.state.go: newServerloads NPCs before users/missions.users.go: loadUsersloads mission records and excludes completed missions from player journals. Keep a private world's geometry available before its first NPC tick, even after restart with no currently connected occupant.
Retirement: missing behavior and minimal extension
mission_retirement.go: endMission_locked already commits bound-key removal,
world objective removal, inventory/trade cleanup, mission deletion, and all
occupant evacuation through itemStore before publishing. With completed=true
it only settles the assignment: the world record and geometry remain until the
original deadline. expireMissions_locked later retires completed worlds too.
Preserve that distinction.
Currently this method does not remove private-world NPCs, corpses, or pending
respawns. Adding NPCs without extending retirement would leave durable or live
orphans after abandon/expiry. item_database.go: persistItems_locked calls
writeNPCs_locked before it deletes the mission; that snapshot reads all live
characters and pending respawn sources. Deleting rows alone would allow a later
checkpoint to recreate them.
Recommended transaction and publication order:
- When
store.removedMission != nil, collect every NPC in its unique world, including saved/hidden respawn sources; filter them out of the checkpoint candidate map and resultingsavedNPCs, independent of observed-zone cadence. - Remove their corpse item placements and remaining items/contained items from
the staged item store. Preserve loot already transferred to a player, bank,
backpack, or another owner.
item_locations.corpse_idreferencesnpcswith no deletion cascade: placements must be deleted before NPC/character rows.itemsalso cannot be deleted while child placements still reference them. - Delete the retired NPC character rows inside the same existing transaction
as mission deletion and evacuation.
npcs, contributor rows, and character-owned effect rows use foreign-key cleanup where defined; verify all affected dependencies. Retire even a world with no online occupant. - After commit, cancel combat/casts referring to removed NPCs, close any open
corpse UI, send actor50000/corpse51050 despawns to clients that knew them,
clear those
client.npcsandlootCorpsehandles, and remove actors fromcharacters,fighting,mobileNPCs,npcRespawns, andcorpseExpiry. Remove saved NPC cache entries as part of the committed snapshot. ReusecancelCombat_locked/stopAttack_lockedsemantics without mutating state before commit. Then remove geometry and publish existing evacuation packets. - Keep the entire retirement path disabled for ordinary completion settlement; occupants, actors, corpses, and the original absolute expiry remain intact.
corpse_expiry.go: advanceCorpseExpiry is useful for packet/handle cleanup but
only removes live actors and leaves ordinary persistence to checkpoint.
respawn.go: advanceNPCRespawns can create a new life from a hidden source.
Neither alone supplies atomic mission retirement; both queues must be purged
after the retirement transaction commits.
Visibility and boundaries
interest.go: updateNPCInterest_locked requires exact playfield equality before
creating an actor or corpse, with550m entry/600m retention. Private world IDs
therefore isolate identical layouts/coordinates without a second instance flag.
combat_interest.go, queueCombat_locked, selectNPCTarget_locked, and loot
rights also check playfield or known NPC state. Keep those paths.
Entrance credentials are transferable bound key instances: missionDestination_locked
can admit another key holder to the same world. Encounter visibility should
follow actual occupancy, not be hardcoded to the mission owner. Completion
revokes keys but does not eject existing guests until the deadline. Two owners'
assignments with identical layouts must never share actor IDs or corpse rights.
Focused recommended tests
Use existing public handlers and entry transitions. Extend fixtures such as newAcceptedMissionWorld, existing mission
retirement tests, NPC outcomes, and respawn durability rather than replicating
their internals.
- First entry commits admitted level1 NPCs + objective + player world together; leave/reenter, reconnect, and SQLite restart create no duplicates. Killing all occupants does not cause first-entry repopulation.
- Inject initialization SQL failure and deferred commit failure: no counters, live actors, corpse/worker queues, objective, or player position change; retry succeeds exactly once with durable identities.
- Real shared melee/ranged/nano kill grants existing XP exactly once, produces profile loot and credits, permits rightful pickup, and rejects replayed or stale dead-actor attacks. Reload preserves damage/outcome/loot ownership.
- Two identical private worlds plus a public observer: only same-world actors, attack/death/corpse packets and loot handles are visible or actionable. A valid transferred-key guest sees the same actors; a foreign key does not.
- Placement and pursuit across the inter-room portal remain on valid floors; walls, outside bounds, disconnected rooms/floors, return-home movement, and target zone exit cannot move the NPC through geometry. Verify any intended wall LOS rule separately for attacks/casts.
- Abandon and expiry remove living fighters, visible corpses, hidden expired corpse respawn sources, active effects, open loot UIs, and unclaimed filled containers. Preserve already looted items and unrelated public/world actors.
- Retirement with no observers and with an offline owner still deletes rows immediately. Cold restart has no orphan actors, items, contributors, effects, timers, or regenerated inhabitants in the retired identity.
- Inject retirement failures at item placement, character deletion, mission deletion, and deferred commit: all NPC/player/item/queue state and outbound packets remain unchanged; a retry completes atomic cleanup.
- Completing the mission retains the occupied world and its NPC/corpse state until the original deadline; a subsequent assignment has independent actors. Deadline cleanup still works after restart or after the owner departs.
- Test the selected mission respawn policy explicitly, including a deadline
concurrent with respawn/corpse expiry; retired worlds must never respawn.
roamNPCscurrently advances mission expiry before those other workers.
No runtime validation was performed for this report. Canonical NPC selection, native progress semantics, and original encounter/respawn policy remain evidence questions rather than established facts.