aorecomp

Anarchy Online classic in the browser

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


commit ffb8126e6fdfbfc32fe9f74858b76041dd36adf1
parent c4b5b2c2ea0687f129fdcbe3b50b82c3dac134db
Author: anon <anon@example.com>
Date:   Thu,  5 Nov 2026 06:55:31 +0000

Allow fifteen minutes of NPC activity for idle recovery

Diffstat:
Mdocs/npc-pursuit.md | 2+-
Mdocs/npc-regeneration.md | 2+-
Mdocs/world-state.md | 2+-
Mserver/database_test.go | 2+-
Mserver/interest.go | 4++--
Mserver/npc_activity_test.go | 8++++----
Mserver/npc_regeneration_test.go | 18++++++++++++++++++
7 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/docs/npc-pursuit.md b/docs/npc-pursuit.md @@ -45,7 +45,7 @@ original-server scheduling frequency. Return to the retained spawn is an explicit reconstruction policy. A bounded source search found no period Leet rule proving that exact destination or its timing. Motion, including returns, runs within 600 metres horizontally of a -ready player in the same playfield, and for five minutes after the last nearby +ready player in the same playfield, and for fifteen minutes after the last nearby player leaves. Loading players do not activate NPCs. Health uses the separate [recovery rule](npc-regeneration.md), including while returning. Unprofiled appearance stand-ins do not acquire combat pursuit. Proximity aggression, diff --git a/docs/npc-regeneration.md b/docs/npc-regeneration.md @@ -65,7 +65,7 @@ implementation. The server keeps one two-second phase and counter per living NPC. Recovery runs within 600 metres horizontally of a ready, non-loading player in the same -playfield and for five minutes after the last nearby player leaves. After that, +playfield and for fifteen minutes after the last nearby player leaves. After that, dormant NPCs retain their health and clock until a player returns. Starting or stopping an attack changes the applicable branch without resetting that phase or granting an additional heal. A late scheduler diff --git a/docs/world-state.md b/docs/world-state.md @@ -62,7 +62,7 @@ its counters, clock or population-initialization state change. NPC state is checked on the one-second world tick, but routine writes occur at least 20 seconds apart, with random starting phases, only for NPCs within 600 metres horizontally -of a ready, non-loading player in the same playfield, or within a five-minute +of a ready, non-loading player in the same playfield, or within a fifteen-minute grace period after the last nearby player leaves. Roaming, pursuit, returns, recovery and periodic effects use the same activity gate. Grace expiry triggers one final snapshot; an occupied zone does not activate its entire population. diff --git a/server/database_test.go b/server/database_test.go @@ -268,7 +268,7 @@ func TestNPCCheckpointsSkipDormantNPCsAndLimitRoutineWrites(t *testing.T) { seconds int present bool x float32 - }{{60, false, 53}, {61, true, 53}, {62, true, 54}, {80, true, 54}, {102, true, 54}, {103, true, 55}, {404, false, 55}, {465, false, 56}} + }{{60, false, 53}, {61, true, 53}, {62, true, 54}, {80, true, 54}, {102, true, 54}, {103, true, 55}, {1004, false, 55}, {1065, false, 56}} var counts [8]int var positions [8]float32 for index, step := range steps { diff --git a/server/interest.go b/server/interest.go @@ -3,7 +3,7 @@ package main import "time" func (server *server) npcActive_locked(npc *character, now time.Time) bool { - // Keep nearby NPCs active for five minutes after the last player leaves. + // Keep nearby NPCs active for fifteen minutes after the last player leaves. for id, client := range server.clients { if !client.ready || client.loading { continue @@ -14,7 +14,7 @@ func (server *server) npcActive_locked(npc *character, now time.Time) bool { } x, z := player.position[0]-npc.position[0], player.position[2]-npc.position[2] if x*x+z*z <= 600*600 { - npc.npcActiveUntil = now.Add(5 * time.Minute) + npc.npcActiveUntil = now.Add(15 * time.Minute) return true } } diff --git a/server/npc_activity_test.go b/server/npc_activity_test.go @@ -124,7 +124,7 @@ func TestNPCActivitySavesFinalPositionWhenGraceExpires(t *testing.T) { world.characters[1000000].position[0] = 53 world.characters[1].position[0] = 2000 - if err := world.checkpointWorld(now.Add(5 * time.Minute)); err != nil { + if err := world.checkpointWorld(now.Add(15 * time.Minute)); err != nil { t.Fatal(err) } var x float32 @@ -132,7 +132,7 @@ func TestNPCActivitySavesFinalPositionWhenGraceExpires(t *testing.T) { t.Fatal(err) } queries := world.databaseQueries.Load() - if err := world.checkpointWorld(now.Add(5*time.Minute + time.Second)); err != nil { + if err := world.checkpointWorld(now.Add(15*time.Minute + time.Second)); err != nil { t.Fatal(err) } @@ -148,12 +148,12 @@ func TestNPCActivityGracePeriodAllowsHealingThenSleeps(t *testing.T) { delete(world.clients, 1) world.advanceRegeneration(start.Add(2 * time.Second)) - world.advanceRegeneration(start.Add(5*time.Minute - time.Second)) + world.advanceRegeneration(start.Add(15*time.Minute - time.Second)) if npc.health != 22 { t.Fatal("recently observed NPC stopped healing", npc.health) } clock := npc.regenerationAt - world.advanceRegeneration(start.Add(5 * time.Minute)) + world.advanceRegeneration(start.Add(15 * time.Minute)) world.advanceRegeneration(start.Add(time.Hour)) if npc.health != 22 || npc.regenerationAt != clock { t.Fatal("dormant NPC continued healing", npc.health, npc.regenerationAt) diff --git a/server/npc_regeneration_test.go b/server/npc_regeneration_test.go @@ -290,3 +290,21 @@ func TestNPCRegenerationRespawnStartsWithFreshResourcesAndClock(t *testing.T) { t.Fatal("replacement inherited the dead life's resources or recovery phase") } } + +func TestNPCRegenerationCompletesRecoveryDuringActivityGracePeriod(t *testing.T) { + world, _, start := newNPCRegenerationWorld(t) + npc := world.characters[1000000] + // Just below the next heal-delta threshold gives the longest idle recovery. + npc.combatProfile = &gamedata.NPCCombatProfile{Health: 239} + npc.health = 1 + world.advanceRegeneration(start) + delete(world.clients, 1) + + for second := 2; second <= 476; second += 2 { + world.advanceRegeneration(start.Add(time.Duration(second) * time.Second)) + } + + if npc.health != 239 { + t.Fatal("NPC went dormant before finishing idle recovery", npc.health) + } +}