commit 63fd9073adacacf540b6a979385c3540fe821939
parent c3c9e1c93b9b261f529e0d6c84876a5da0e7d69d
Author: anon <anon@example.com>
Date: Tue, 27 Oct 2026 12:22:49 +0000
Retain profiled NPC combat engagement outside weapon range
Diffstat:
8 files changed, 252 insertions(+), 5 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -657,6 +657,12 @@ for exact records, protocol, tests and remaining reconstruction assumptions.
fixed and roaming profiles. Keep idle placement separate from combat movement;
do not add species-specific pursuit branches. Until this is implemented,
ranged kills of the stationary boss do not establish normal encounter balance.
+- [x] Keep admitted NPCs engaged while outside weapon range. Check fixed/roaming
+ profiles at both Leet levels and the Salamander Boss, retained swing deadlines,
+ no distant damage or repeated Attack/Stop traffic, valid-range resumption and
+ target loss. Repeated retaliation restarts had caused idle/combat recovery
+ differences and premature zero-HP displays. One shared rule now retains combat;
+ movement remains the pursuit task above. See [NPC engagement](docs/npc-engagement.md).
- [ ] [P1] Connect successive outdoor hunting areas to early progression. Use
original district/species level ranges for mutants and other encounters,
rather than scaling the outdoor world to the visiting player. Check reachable
@@ -807,6 +813,12 @@ are recorded in [reclaim](docs/reclaim.md).
defeated four full-health lives for 400 XP and collected one four-credit corpse;
three QL4 glove drops expired while still corpse-owned during interaction checks.
No native boss-drop pickup, wear or sale is claimed by this milestone.
+ Subsequent engagement/recovery fixes enabled six more confirmed native kills.
+ An earned QL4 glove now passes ordinary pickup, safe rejected wear and cold
+ inventory retention with its original identity. Native cancelled/accepted sale
+ then accounted for that instance and exactly 12 earned credits, retained after
+ reconnect. Qualified wear and the full earned-income upgrade loop remain open.
+ See [NPC engagement](docs/npc-engagement.md).
- [ ] [P0] Generate loot at suitable supported qualities. Separate item-family
membership/chance from quality selection; establish period-supported QL ranges
relative to creature level, allowing fixed-QL exceptions. Use shared endpoint
diff --git a/docs/npc-engagement.md b/docs/npc-engagement.md
@@ -0,0 +1,88 @@
+# NPC combat engagement and range
+
+Admitted NPC combat profiles retain their opponent and next attack deadline
+while outside weapon range. A due swing waits until the existing three-dimensional
+range check succeeds; waiting neither deals damage nor restarts the clock.
+Subsequent damage from the same opponent does not replay AttackIIR. Target death,
+loading, a different playfield or an unavailable connection ends engagement
+through the existing target-selection and StopFight path. Browser reconnect grace
+still determines when a temporarily closed transport becomes unavailable.
+
+This rule applies independently of species, level and idle roaming. Appearance
+stand-ins without an admitted combat profile keep their previous behavior.
+Existing level-1 Leet pursuit remains the only implemented approach/return policy.
+Fixed profiles and level-2 Leets can retain combat without acquiring new movement.
+General pursuit and the original outdoor give-up rules remain open TODOs.
+
+## Recovery and the native mismatch
+
+The original client selects NPC health recovery using weapon-controller state.
+Idle state 1 and zero stat519 use one check per two seconds with
+`max(1, maximumHP / 120)` health. Combat doubles HealInterval342 and retains
+HealDelta343; current spawn inputs give three HP at counter multiples of60.
+The original recovery source and its server-policy limits are in
+[NPC regeneration](npc-regeneration.md).
+
+Previously only the mobile level-1 Leet kept its engagement outside range.
+Other admitted NPCs repeatedly received AttackIIR after incoming damage and
+StopFight at the next out-of-range visit. The server then used idle recovery,
+while independently phased clients sometimes checked recovery during the brief
+combat state. Absolute corrections remained deferred behind incoming weapon
+queues. Those state transitions accumulated visible health differences.
+
+An ordinary Clan Training boss fight reproduced zero native HP on the owner,
+seven HP on the observer and a still-living authoritative NPC. No corpse packet
+or fifth XP award existed. Reloading ended that attempt and the NPC recovered.
+A separate pistol-only capture reproduced differing native HP without nanos;
+stopping the player reconciled the clients through the existing quiet correction.
+Native zero HP therefore cannot serve as the test's authoritative death gate.
+The updated native test waits for CorpseFullUpdate for that actual NPC identity.
+
+The fix extends the existing engagement rule to every admitted profile. It
+changes no damage, health value, recovery rate or packet format. It also avoids
+extra stop/start traffic rather than adding a new health-correction workaround.
+Healing while incoming weapon results are queued retains its separately
+[documented limitation](first-aid.md).
+
+## Verification
+
+Public combat-path regressions cover fixed and roaming level-1/2 Leets and the
+Clan Training boss. They check retained engagement/deadlines, no out-of-range
+hit, no repeated native attack/stop, one due hit after entering range, combat
+recovery and target death/loading/disconnection/playfield changes. Existing
+pursuit and recovery tests retain movement exclusions and recovery phase across
+actual disengagement. The new retention and recovery checks fail against the
+previous implementation.
+
+Five consecutive ordinary native fights after the fix each received one NPC
+AttackIIR and one authoritative corpse on both clients, earning 500 additional
+XP. The first fight took about 39 seconds; both clients retained combat state
+through the encounter. Opening and closing the first four empty corpses credited
+their cash once. The fifth generated both QL4 items, which expired before pickup;
+that result is not counted as successful acquisition.
+
+A sixth ordinary kill produced QL4 gloves. Native left-click pickup retained the
+same instance 709 in player inventory slot 67. Right-click wear reported the
+missing Agility 16 requirement and left it in inventory. A clean server restart
+retained all seventeen owned item instances, learned nanos, the player's
+1000 cumulative XP and 18 credits. Both WASM clients reconnected, and the gloves
+were visible in the native inventory. These encounters used issued equipment,
+ordinary skill training, recovery and native inputs without edited resources or
+rewards. The stationary boss still permits ranged acquisition; full pursuit,
+qualified wear and funded equipment upgrades remain separate acceptance checks.
+
+The owner then walked to the original Clan training terminal and offered those
+gloves for 12 credits. Decline restored the same instance and changed no wallet;
+accepting the second offer removed only that instance and credited exactly 12.
+After native reconnect, the inventory contained every remaining issued item,
+with 1000 XP and 30 credits. The training terminal's purchase stock is still
+unsupported; this sale does not establish a funded equipment purchase.
+
+The full Go suite passed 1460 test roots and 15097 results. The focused selection
+passed 36 roots/84 results, the race selection 25 roots/46 results, and vet passed.
+Source, binary and published-client digests matched the tested manifest. The
+WASM client was unchanged and neither client reported browser exceptions.
+
+The matching original KKR digest and retained recovery Evidence ID are checked
+under `local/npc-engagement/`, alongside baseline/fixed native captures, wire
+streams, regression logs, source/binary hashes and the final verification ledger.
diff --git a/docs/npc-regeneration.md b/docs/npc-regeneration.md
@@ -90,6 +90,14 @@ Missing or changed targets and healing/inspection during combat remain separate
ordering questions. The exact source ledger, retained records and generated
message bodies are in `local/npc-regeneration-research/native-followup/`.
+Admitted NPC profiles now retain engagement outside their weapon range, including
+fixed spawns. Repeatedly stopping and restarting a ranged target had selected
+idle recovery on the server while clients' independent phases sometimes checked
+the brief combat state, accumulating visible HP differences. The shared
+[engagement rule](npc-engagement.md) preserves the opponent and swing deadline
+without dealing an out-of-range hit or changing recovery rates. Fixed-spawn
+pursuit remains separate work.
+
A contemporary [March 2003 mission-boss discussion, post 16](https://forums-archive.anarchy-online.com/showthread.php?112679-Finding-GA-Guide-P=)
reports substantially faster boss recovery after combat ends. It provides no
numeric rate, Leet measurement, or original-server capture. Later guides and
diff --git a/docs/starter-boss.md b/docs/starter-boss.md
@@ -107,3 +107,13 @@ The complete Go suite passed 15,084 results across server and gamedata, includin
as did vet. A resolver negative control fails ordinary-salamander isolation and
changed-code cold replacement checks, demonstrating that the restriction is
required rather than merely documented.
+
+The subsequent [NPC engagement check](npc-engagement.md) corrected repeated
+retaliation restarts outside melee range. Six further ordinary kills reached
+1000 cumulative XP. A generated QL4 glove was picked up, rejected for wear below
+its Agility requirement, and retained with the same identity across a cold
+restart. Both clients reconnected and the glove remained visible. This adds
+normal acquisition and safe rejected-wear coverage. Walking to the Clan training
+terminal, cancelling a 12-credit offer, then accepting it retained every other
+item and credited exactly 12; reconnect showed 1000 XP and 30 credits. Qualified
+native wear and the complete funded upgrade loop remain open.
diff --git a/server/combat.go b/server/combat.go
@@ -392,8 +392,8 @@ func (server *server) advanceCombat(now time.Time) {
continue
}
if !server.combatInRange_locked(attacker, target, now) {
- // The supported mobile Leet retains its attack clock while pursuing.
- if attacker.roaming == nil || attacker.combatProfile == nil || attacker.monsterData != 17655 || attacker.level != 1 {
+ // Engaged creatures wait for range without restarting combat or their swing.
+ if !attacker.npc || attacker.combatProfile == nil {
server.stopAttack_locked(attacker, updates)
}
continue
diff --git a/server/npc_engagement_range_test.go b/server/npc_engagement_range_test.go
@@ -0,0 +1,123 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "encoding/binary"
+ "fmt"
+ "testing"
+ "time"
+)
+
+func TestProfiledNPCRetainsEngagementOutsideWeaponRange(t *testing.T) {
+ for _, profile := range []struct {
+ monster uint32
+ level uint16
+ rangeM float32
+ }{
+ {17655, 1, 10}, {17655, 2, 10}, {30354, 4, 12},
+ } {
+ for _, roaming := range []bool{false, true} {
+ t.Run(fmt.Sprintf("%d/%d/roaming=%t", profile.monster, profile.level, roaming), func(t *testing.T) {
+ world, conn := newRangedWorld(t)
+ player, npc := world.characters[1], world.characters[1000000]
+ npc.monsterData, npc.level, npc.health = profile.monster, profile.level, 100
+ npc.combatProfile = gamedata.NPCCombatProfiles[profile.monster][profile.level]
+ if roaming {
+ npc.roaming = &npcRoaming{home: npc.position}
+ }
+ if err := world.handleCombat(world.clients[1], attackPacket(1, npc.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ first := player.nextAttack
+ world.advanceCombat(first)
+ deadline := npc.nextAttack
+ conn.packets = nil
+
+ world.advanceCombat(first.Add(250 * time.Millisecond))
+ world.advanceCombat(first.Add(3950 * time.Millisecond))
+ world.advanceCombat(first.Add(4200 * time.Millisecond))
+
+ if npc.fighting != player.id || npc.nextAttack != deadline || player.health != 100 || world.fighting[npc.id] != npc {
+ t.Fatal("out-of-range NPC lost engagement, restarted its deadline or dealt damage", npc.fighting, npc.nextAttack, player.health)
+ }
+ for _, packet := range conn.packets {
+ key := binary.BigEndian.Uint32(packet[16:20])
+ if binary.BigEndian.Uint32(packet[24:28]) == npc.id && (key == 0x28494070 || key == 0x4a41203e) {
+ t.Fatal("another ranged hit restarted or stopped native NPC combat")
+ }
+ }
+
+ player.position[0] = npc.position[0] - profile.rangeM
+ world.advanceCombat(first.Add(4500 * time.Millisecond))
+ health := player.health
+ world.advanceCombat(first.Add(4500 * time.Millisecond))
+
+ if health >= 100 || player.health != health || npc.fighting != player.id || !npc.nextAttack.After(first.Add(4500*time.Millisecond)) {
+ t.Fatal("returning to range did not deliver exactly one due retaliation", health, player.health, npc.nextAttack)
+ }
+ })
+ }
+ }
+}
+
+func TestFixedNPCRangedEngagementUsesCombatRecovery(t *testing.T) {
+ world, _ := newRangedWorld(t)
+ player, npc := world.characters[1], world.characters[1000000]
+ npc.monsterData, npc.level, npc.health = 30354, 4, 100
+ npc.combatProfile = gamedata.NPCCombatProfiles[30354][4]
+ if err := world.handleCombat(world.clients[1], attackPacket(1, npc.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ first := player.nextAttack
+ world.advanceCombat(first)
+ world.advanceRegeneration(first)
+ damaged := npc.health
+
+ world.advanceCombat(first.Add(250 * time.Millisecond))
+ world.advanceRegeneration(first.Add(2 * time.Second))
+
+ if npc.health != damaged || npc.fighting != player.id {
+ t.Fatal("engaged fixed NPC took the idle health branch", damaged, npc.health, npc.fighting)
+ }
+
+ for seconds := 4; seconds <= 60; seconds += 2 {
+ world.advanceRegeneration(first.Add(time.Duration(seconds) * time.Second))
+ }
+
+ if npc.health != damaged+3 {
+ t.Fatal("fixed engagement did not retain the native combat recovery counter", damaged, npc.health)
+ }
+}
+
+func TestFixedNPCRangedEngagementEndsWhenTargetUnavailable(t *testing.T) {
+ for _, reason := range []string{"disconnect", "loading", "dead", "zone"} {
+ t.Run(reason, func(t *testing.T) {
+ world, conn := newRangedWorld(t)
+ player, npc := world.characters[1], world.characters[1000000]
+ npc.monsterData, npc.level, npc.health = 30354, 4, 100
+ npc.combatProfile = gamedata.NPCCombatProfiles[30354][4]
+ if err := world.handleCombat(world.clients[1], attackPacket(1, npc.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceCombat(player.nextAttack)
+ next := npc.nextAttack
+ conn.packets = nil
+ switch reason {
+ case "disconnect":
+ delete(world.clients, player.id)
+ case "loading":
+ world.clients[player.id].loading = true
+ case "dead":
+ player.health = 0
+ case "zone":
+ player.playfield = 705
+ }
+
+ world.advanceCombat(next.Add(250 * time.Millisecond))
+
+ if npc.fighting != 0 || world.fighting[npc.id] != nil || !npc.nextAttack.IsZero() {
+ t.Fatal("unavailable target retained fixed NPC combat", npc.fighting, npc.nextAttack)
+ }
+ })
+ }
+}
diff --git a/server/npc_pursuit_test.go b/server/npc_pursuit_test.go
@@ -168,15 +168,17 @@ func TestNPCPursuitJoiningObserverGetsSpawnBeforeRouteAndAttack(t *testing.T) {
}
}
-func TestNPCPursuitDoesNotChangeOtherSpeciesOrLevels(t *testing.T) {
+func TestNPCPursuitDoesNotMoveOtherSpeciesOrLevels(t *testing.T) {
for _, scenario := range []string{"species", "level", "profile"} {
t.Run(scenario, func(t *testing.T) {
world, _, start := newNPCPursuitWorld()
switch scenario {
case "species":
world.characters[1000000].monsterData = 17657
+ world.characters[1000000].combatProfile = nil
case "level":
world.characters[1000000].level = 2
+ world.characters[1000000].combatProfile = gamedata.NPCCombatProfiles[17655][2]
case "profile":
world.characters[1000000].combatProfile = nil
}
@@ -184,7 +186,11 @@ func TestNPCPursuitDoesNotChangeOtherSpeciesOrLevels(t *testing.T) {
world.advanceNPCs(start.Add(250 * time.Millisecond))
world.advanceCombat(start.Add(250 * time.Millisecond))
- if world.characters[1000000].position != [3]float32{1, 0, 0} || world.characters[1000000].fighting != 0 || world.characters[1000000].roaming.moving {
+ wantFighting := uint32(0)
+ if scenario == "level" {
+ wantFighting = 1
+ }
+ if world.characters[1000000].position != [3]float32{1, 0, 0} || world.characters[1000000].fighting != wantFighting || world.characters[1000000].roaming.moving {
t.Fatalf("unverified profile acquired pursuit: %+v", world.characters[1000000])
}
})
diff --git a/server/npc_regeneration_test.go b/server/npc_regeneration_test.go
@@ -118,7 +118,7 @@ func TestNPCRegenerationDisengagementDoesNotHealTwiceOrResetPhase(t *testing.T)
world.fighting[1000000] = world.characters[1000000]
world.advanceRegeneration(start)
world.advanceRegeneration(start.Add(2 * time.Second))
- world.characters[1].position = [3]float32{100, 0, 0}
+ world.characters[1].health = 0
conn.packets = nil
world.advanceCombat(start.Add(3 * time.Second))