aorecomp

Anarchy Online classic in the browser

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


commit 0b4a62b1333aaf16fe99cc11a9bfef580ec8072e
parent d693c390a8229a2655a8b31ef6427c4561babf63
Author: anon <anon@example.com>
Date:   Fri, 23 Oct 2026 21:19:12 +0000

Apply native health recovery to unprofiled NPCs

Diffstat:
MTODO.md | 21+++++++++++++++------
Mdocs/fling-shot.md | 8+++++---
Mdocs/npc-regeneration.md | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Mserver/npc_regeneration.go | 6+++---
Mserver/npc_regeneration_test.go | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++--------
5 files changed, 142 insertions(+), 34 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -219,11 +219,20 @@ for exact records, protocol, tests and remaining reconstruction assumptions. checked resources and combat values rather than an assumed scaling formula. - [ ] Add a second species with different behavior or equipment. Check: changing one species' profile does not change the other species. -- [ ] Reconcile recovery for currently unprofiled creatures. Check: a damaged - Reet's native HP and server HP remain equal across idle time and reconnect, - with no phantom hits. A Fling test found server HP 87 while native clients - recovered to 94/96 and then 100; only the Leet currently has synchronized - NPC regeneration. Record species inputs before generalizing recovery. +- [x] Reconcile recovery for currently unprofiled creatures. Check: a damaged + Reet's native HP reconciles with server HP across idle time and reconnect, + with no phantom hits or cumulative drift. A Fling test found server HP 87 while + native clients recovered to 94/96 and then 100. Both retain the same recovery + inputs as the Leet; the generic native branch has no species/level gate. + Server recovery now follows that branch independently of combat profiles. + Quiet corrections reconcile the clients' distinct prediction phases, with + at most one idle recovery tick of drift in the native capture. + Species balance and modified recovery inputs remain separate work. +- [ ] Support changed NPC recovery inputs. Check: evidenced HealInterval, + HealDelta, Body Development, RestModifier, stat 519 and recovery-disable flags + affect both server recovery and native prediction consistently, including + temporary modifiers, removal, death and reconnect. Current NPC spawns retain + the checked native defaults; do not infer species balance from them. - [x] Pursue a target across open ground. Check: an engaged creature follows a moving player and resumes attacks only when in range. - [x] Return a creature home after pursuit ends. Check: it disengages, returns @@ -237,7 +246,7 @@ for exact records, protocol, tests and remaining reconstruction assumptions. - [x] Recover NPC resources outside combat. Check: one profile follows an evidenced recovery/reset policy without healing twice on disengagement. -The supported Leet uses the recovered native NPC health branch, with one +Living NPCs use the recovered native NPC health branch, with one retained recovery clock across combat transitions and quiet observer corrections. Its evidence, automated/native checks and original-server policy limits are in [NPC health recovery](docs/npc-regeneration.md). NPC nano recovery remains open. diff --git a/docs/fling-shot.md b/docs/fling-shot.md @@ -128,9 +128,11 @@ blocked use, and the native availability notification on expiry. That first target was an unprofiled Reet of Paradise. Its server HP reached 87, but after reconnect the native clients recovered independently to 94/96 and -then 100. Both native maxima were 100. The server currently synchronizes NPC -recovery only for the supported Leet; the newly recorded Reet gap prevents -claiming raw-HP agreement for that species. +then 100. Both native maxima were 100. That run exposed a server recovery gate +limited to the supported Leet. The subsequent +[NPC recovery fix](npc-regeneration.md#recovery-without-a-combat-profile) removes +the gate after checking the Reet's native inputs; these original Fling captures +alone do not establish raw-HP agreement for that species. The supported Leet then received a 12-point Fling with native HP 88 in both clients and ammunition still 20. A normal shot followed by Fling during weapon diff --git a/docs/npc-regeneration.md b/docs/npc-regeneration.md @@ -1,9 +1,9 @@ -# Leet health recovery +# NPC health recovery -The supported MonsterData 17655, level-1 Leet now recovers health on the -server. It uses the shipped 14.9.1 client's NPC prediction branch. The -unavailable original server's numeric recovery policy and scheduler are not -established by this client code. The profile's 100 maximum HP remains +Living NPCs recover health on the server, including creatures without a combat +profile. Recovery uses the shipped 14.9.1 client's generic NPC prediction branch. +The unavailable original server's numeric recovery policy and scheduler are not +established by this client code. The current 100 maximum HP remains provisional; see [NPC combat profiles](combat-npc-balance.md). ## Recovered client behavior @@ -47,17 +47,22 @@ addresses and baseline snapshots are in `local/npc-regeneration-research/`. ## Server policy and delivery -Only this exact species/level with an explicit combat profile receives this -recovery. Other NPCs and NPC nano recovery remain outside the implementation. -Its retained native inputs are fixed above; no configurable recovery system -or new stat-519 behavior is introduced. +The native recovery branch has no species, level or weapon-profile predicate. +NPC spawns currently retain the same interval, delta, Body Development, +RestModifier and stat-519 inputs, so recovery applies independently of the +combat-profile catalog. This does not establish the original server's creature +balance. NPC nano recovery and changed recovery stats remain outside the +implementation. -The server keeps one two-second phase and counter per living Leet, independent +The server keeps one two-second phase and counter per living NPC, independent of observers. Starting or stopping an attack changes the applicable branch without resetting that phase or granting an additional heal. A late scheduler visit performs one check and skips the stalled backlog, following the existing player recovery policy. A fresh respawn gets full health and a new clock; -dead remains cannot heal. Current NPC health is not persisted across restart. +dead remains cannot heal. Recovery stays in memory between periodic world +checkpoints. Restart restores checkpointed NPC HP with a fresh recovery clock; +it does not replay offline healing. Significant Fling damage outcomes commit +immediately, as described in [Fling Shot](fling-shot.md). Quiet health corrections use the existing zero-feedback HealthDamage packet. They reach only ready observers that already know the NPC in its playfield. @@ -77,7 +82,7 @@ they are not substitutes for that missing evidence. Focused tests cover idle/combat rates, the native maximum-health division boundaries, clamping, scheduler jitter/backlogs, repeated visits, disengagement ordering, incoming weapon queues, observer interest/readiness, -recovery without clients, dead/unverified-profile exclusions and fresh respawn +recovery without clients, dead/player exclusions and fresh respawn state. Player regeneration tests also exercise the shared quiet correction. `go test ./server/...` passed (server 107.905 seconds). The focused NPC and @@ -95,5 +100,52 @@ melee feedback without extra recovery messages. The 120 captured samples and 20 checked assertions are retained in `local/npc-regeneration-smoke/verification.json`. The agent-owned game pages -were unloaded after verification. The temporary server on HTTP port 18108 -remains available at the user's explicit request for manual testing. +were unloaded after verification. Current manual testing uses the single +default-port HTTPS preview. + +## Recovery without a combat profile + +Fling testing exposed an incorrect server gate: only MonsterData 17655 at +level 1 with a combat profile could recover, while native prediction also ran +for the unprofiled Reet of Paradise. Server HP remained 87 while the native +clients recovered independently. + +Fresh read-only probes of two published WASM clients reproduced that gap: +the owner saw Reet HP 92 and the observer later saw 98, while SQLite remained +87. Both Reets had NPC byte 1, flags 0, idle weapon state 1, interval 30, +delta 3, base Body Development 5, RestModifier 100 and stat 519 equal to zero, +matching the Leet. Their maximum 100 came from this development server; it +does not prove historical Reet HP. Original `FUN_1006ea50` at `1006f4b9` +branches on the NPC byte, weapon state and stat 519, with no species or level +test. The retained REA record above and its complete exported contents were +reused; no new binary session was necessary. + +Regression tests first failed on the unprofiled Reet and periodic-checkpoint +cases, then passed after removing the gate. They also cover higher levels, +including extended level 300, and verify that recovery waits for a world +checkpoint before changing stored HP. A Reet combat profile remains separate: +two distinct shipped peck weapons are leads, and neither is yet bound to RT01. +Source records, bounded historical research and native captures are retained +under `local/reet-regeneration-research/`. + +The updated full suite passed with `go test ./server/... -count=1` (server +359.062 seconds, gamedata 7.513 seconds). NPC/player recovery tests passed three +repetitions under the race detector (123.269 seconds). + +Two-client checks delivered the same seven-point special, taking the Reet from +100 to 93 HP. After the attacker's disconnect/reconnect ended retaliation, +both native heaps and the database reached 100. A separate combat capture +confirmed that clients can predict their three-point combat ticks at different +phases; this remains reconciled after combat rather than by interrupting weapon +queues with absolute HP updates. + +For idle verification the attacker moved beyond the Reet's melee range before +firing a nine-point special. Both native heaps showed 91, 92 and 93 HP, then +100 in the final idle samples. Both clients received every authoritative +one-point correction from 92 through 100 with zero damage-feedback fields. +The 28 sampled pairs stayed within one native prediction tick of the last +correction, with no cumulative drift; their recovery counters retained distinct +phases. SQLite reached 100 at its periodic checkpoint. All 192 item rows were +unchanged, including loaded ammunition 19. These browser runs reported no page +errors or unimplemented adapters, and their owned browser contexts were closed. +The checked report is `local/reet-regeneration-research/verification.json`. diff --git a/server/npc_regeneration.go b/server/npc_regeneration.go @@ -4,8 +4,7 @@ import "time" func (server *server) advanceNPCRegeneration_locked(now time.Time, updates map[*worldClient][][]byte) { for _, npc := range server.characters { - // Only the supported level-1 Leet profile has checked recovery inputs. - if !npc.npc || npc.monsterData != 17655 || npc.level != 1 || npc.combatProfile == nil || npc.health == 0 { + if !npc.npc || npc.health == 0 { continue } if npc.regenerationAt.IsZero() { @@ -21,7 +20,8 @@ func (server *server) advanceNPCRegeneration_locked(now time.Time, updates map[* npc.regenerationSeconds += 2 // kkr.dll FUN_1006ea50: NPC idle recovery replaces delta and interval. - // This profile retains native defaults: BodyDevelopment < 100, stat 519 = 0. + // NPC spawns retain native defaults: interval 30, delta 3, BodyDevelopment + // below RestModifier 100, and stat 519 = 0, independent of species/level. if npc.fighting == 0 { npc.health = min(npc.maximumHealth(), npc.health+max(1, npc.maximumHealth()/120)) } else if npc.regenerationSeconds%60 == 0 { diff --git a/server/npc_regeneration_test.go b/server/npc_regeneration_test.go @@ -39,6 +39,57 @@ func TestNPCRegenerationUsesOneIdleCheckDespiteJitterAndBacklogs(t *testing.T) { } } +func TestNPCRegenerationUsesNativeDefaultsWithoutASpeciesOrLevelGate(t *testing.T) { + for _, scenario := range []struct { + monster uint32 + level uint16 + }{{30365, 1}, {17655, 7}, {30365, 300}} { + world, _, start := newNPCRegenerationWorld() + npc := world.characters[1000000] + npc.monsterData, npc.level, npc.combatProfile = scenario.monster, scenario.level, nil + + world.advanceRegeneration(start) + world.advanceRegeneration(start.Add(2 * time.Second)) + if npc.health != 21 { + t.Fatalf("unprofiled NPC %d level %d did not recover while idle: %d", scenario.monster, scenario.level, npc.health) + } + npc.fighting = 1 + for second := 4; second <= 60; second += 2 { + world.advanceRegeneration(start.Add(time.Duration(second) * time.Second)) + } + + if npc.health != 24 || npc.nano != 0 || npc.regenerationSeconds != 60 { + t.Fatalf("unprofiled NPC %d level %d did not retain the native combat recovery phase: %+v", scenario.monster, scenario.level, npc) + } + } +} + +func TestNPCRegenerationUsesPeriodicWorldCheckpoint(t *testing.T) { + world, _ := newRangedWorld(t) + npc := world.characters[1000000] + npc.monsterData, npc.level, npc.combatProfile, npc.health = 30365, 1, nil, 87 + start := time.Now() + world.clients[1].regenerationAt = start.Add(time.Hour) + if err := world.flushWorld(); err != nil { + t.Fatal(err) + } + + world.advanceRegeneration(start) + world.advanceRegeneration(start.Add(2 * time.Second)) + var before uint32 + if err := world.db.QueryRow("SELECT health FROM characters WHERE id=1000000").Scan(&before); err != nil { + t.Fatal(err) + } + if err := world.checkpointWorld(start.Add(time.Minute)); err != nil { + t.Fatal(err) + } + restored := newTestInventoryServer(t) + + if before != 87 || npc.health != 88 || restored.characters[1000000].health != 88 { + t.Fatalf("recovery did not wait for its checkpoint: saved=%d live=%d restored=%d", before, npc.health, restored.characters[1000000].health) + } +} + func TestNPCRegenerationCombatUsesNativeDeltaAndCounter(t *testing.T) { world, conn, start := newNPCRegenerationWorld() world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:]) @@ -140,19 +191,13 @@ func TestNPCRegenerationClampsNativeIdleGainBoundaries(t *testing.T) { } } -func TestNPCRegenerationSkipsDeadAndUnverifiedProfiles(t *testing.T) { - for _, scenario := range []string{"dead", "unprofiled", "species", "level", "player"} { +func TestNPCRegenerationSkipsDeadAndPlayerCharacters(t *testing.T) { + for _, scenario := range []string{"dead", "player"} { t.Run(scenario, func(t *testing.T) { world, conn, start := newNPCRegenerationWorld() switch scenario { case "dead": world.characters[1000000].health = 0 - case "unprofiled": - world.characters[1000000].combatProfile = nil - case "species": - world.characters[1000000].monsterData = 1234 - case "level": - world.characters[1000000].level = 2 case "player": world.characters[1000000].npc = false }