aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


docs/research-notes/mission-encounter-research/integration-audit.md (17183B)


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

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:

  1. A real gamedata.NPCGroups[definition] with inferred_species status.
  2. Matching MonsterData.
  3. An exact level entry in gamedata.NPCCombatProfiles[monster][level].
  4. 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

Geometry-safe placement and movement

Existing source tests give useful fixed-layout anchors, without running them:

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

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:

  1. 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 resulting savedNPCs, independent of observed-zone cadence.
  2. 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_id references npcs with no deletion cascade: placements must be deleted before NPC/character rows. items also cannot be deleted while child placements still reference them.
  3. 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.
  4. 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.npcs and lootCorpse handles, and remove actors from characters, fighting, mobileNPCs, npcRespawns, and corpseExpiry. Remove saved NPC cache entries as part of the committed snapshot. Reuse cancelCombat_locked/stopAttack_locked semantics without mutating state before commit. Then remove geometry and publish existing evacuation packets.
  5. 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.

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. Test the selected mission respawn policy explicitly, including a deadline concurrent with respawn/corpse expiry; retired worlds must never respawn. roamNPCs currently 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.