aorecomp

Anarchy Online classic in the browser

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


commit 5e78d9d57b72745ddf0774ec9064a29003e48f80
parent 654c84774b5c9d636034f7e886f2a2a0165ae2cd
Author: anon <anon@example.com>
Date:   Sat,  7 Nov 2026 03:30:13 +0000

Preserve control removals and authored facing across periodic recovery

Diffstat:
Mserver/nano_health_payment_test.go | 33++++++++++++++++++++++++++++-----
Mserver/nano_periodic.go | 6+++---
Mserver/npc_facing_test.go | 11+++++------
Mserver/npc_shared_pursuit_test.go | 14+++-----------
Mserver/world_store.go | 4++--
5 files changed, 41 insertions(+), 27 deletions(-)

diff --git a/server/nano_health_payment_test.go b/server/nano_health_payment_test.go @@ -112,8 +112,8 @@ func TestHealthPaymentDebtTicksAndBlocksRecastUntilExpiry(t *testing.T) { } world.advanceNanos(at.Add(2 * time.Second)) cold := newTestInventoryServer(t).characters[1] - if player.health != health-10 || cold.health != player.health || cold.activeNanos[0].ticksLeft != 4 { - t.Fatal("debt tick or durable progress differs", player.health, cold.activeNanos) + if player.health != health-10 || cold.health != health || cold.activeNanos[0].ticksLeft != 5 { + t.Fatal("debt tick did not stay in memory until its checkpoint", player.health, cold.activeNanos) } world.handleNanoRemoval(client, characterActionPacket(1, [5]uint32{65, 0, 0, 53019, 43372})[20:]) world.advanceNanos(at.Add(10 * time.Second)) @@ -128,6 +128,10 @@ func TestHealthPaymentDebtTicksAndBlocksRecastUntilExpiry(t *testing.T) { t.Fatal("recast restriction expired before 15 seconds") } world.advanceNanos(at.Add(15 * time.Second)) + cold = newTestInventoryServer(t).characters[1] + if cold.health != health-50 || len(cold.activeNanos) != 0 { + t.Fatal("debt expiry did not persist accumulated damage with effect removal", cold.health, cold.activeNanos) + } world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, 43374})[20:]) if len(player.activeNanos) != 0 || client.nanoCast == nil { t.Fatal("debt did not expire or a new cast stayed blocked") @@ -235,7 +239,7 @@ func TestHealthPaymentRejectsIncompleteLinkedEffects(t *testing.T) { } } -func TestHealthPaymentFailedDebtTickRetriesWithoutLosingProgress(t *testing.T) { +func TestHealthPaymentFailedPersistenceRetainsDebtProgressAndRetries(t *testing.T) { for _, failure := range []string{"health", "ignored health", "ticks", "ignored ticks", "death"} { t.Run(failure, func(t *testing.T) { world := newHealthPaymentWorld(t) @@ -262,16 +266,35 @@ func TestHealthPaymentFailedDebtTickRetriesWithoutLosingProgress(t *testing.T) { } world.advanceNanos(at) + if failure != "death" { + player.nextPositionSave = at + if err := world.flushPositions(at); err == nil { + t.Fatal("failed checkpoint accepted debt progress") + } + } cold := newTestInventoryServer(t).characters[1] - if player.health != before || cold.health != before || player.activeNanos[0].ticksLeft != 5 || cold.activeNanos[0].ticksLeft != 5 { - t.Fatal("failed debt tick changed HP or consumed progress") + wantHealth, wantTicks := before, uint32(5) + if failure != "death" { + wantHealth, wantTicks = before-10, 4 + } + if player.health != wantHealth || player.activeNanos[0].ticksLeft != wantTicks || cold.health != before || cold.activeNanos[0].ticksLeft != 5 { + t.Fatal("failed persistence changed the saved debt or lost live progress") } if _, err := world.db.Exec("DROP TRIGGER fail_debt"); err != nil { t.Fatal(err) } world.advanceNanos(at) world.advanceNanos(at) + if failure != "death" { + if err := world.flushPositions(at); err != nil { + t.Fatal(err) + } + cold = newTestInventoryServer(t).characters[1] + if cold.health != before-10 || cold.activeNanos[0].ticksLeft != 4 { + t.Fatal("checkpoint retry did not persist exactly one debt tick") + } + } if failure == "death" { if player.health != 0 || len(player.activeNanos) != 0 { t.Fatal("lethal debt retry did not settle death") diff --git a/server/nano_periodic.go b/server/nano_periodic.go @@ -51,10 +51,10 @@ func (server *server) advancePeriodicNanos_locked(now time.Time, affected []*cha } candidate.updateMovementPermission(target, now) - // Ordinary damage and tick progress share the next checkpoint. Death - // must commit its contribution, corpse and rewards before publication. + // Ordinary damage and tick progress share the next checkpoint. Death and + // control removal commit their complete outcome before publication. var award *experienceAward - if candidate.health == 0 { + if candidate.health == 0 || len(candidate.activeNanos) != len(target.activeNanos) { var err error award, err = server.saveDamageOutcome_locked(&candidate, now) if err != nil { diff --git a/server/npc_facing_test.go b/server/npc_facing_test.go @@ -64,16 +64,15 @@ func TestFixedNPCRespawnRestoresAuthoredFacingAndReloadPreservesIt(t *testing.T) } } -func TestNPCReloadUsesAuthoredFacingOnlyForStationaryActors(t *testing.T) { +func TestLivingNPCReloadRestoresAuthoredFacing(t *testing.T) { for _, scenario := range []struct { name string placement string appearance string - rotation [4]float32 }{ - {"stationary", "fixed_point", "placeholder_creature", [4]float32{0, 0.70710677, 0, 0.70710677}}, - {"roaming", "authored_point", "placeholder_creature", [4]float32{0, 0, 0, 1}}, - {"combat", "fixed_point", "inferred_species", [4]float32{0, 0, 0, 1}}, + {"stationary", "fixed_point", "placeholder_creature"}, + {"roaming", "authored_point", "placeholder_creature"}, + {"combat", "fixed_point", "inferred_species"}, } { t.Run(scenario.name, func(t *testing.T) { data := testNPCData() @@ -93,7 +92,7 @@ func TestNPCReloadUsesAuthoredFacingOnlyForStationaryActors(t *testing.T) { cold := newTestInventoryServer(t) - if cold.characters[1000000].rotation != scenario.rotation { + if cold.characters[1000000].rotation != [4]float32{0, 0.70710677, 0, 0.70710677} { t.Fatalf("%s actor loaded rotation %v", scenario.name, cold.characters[1000000].rotation) } }) diff --git a/server/npc_shared_pursuit_test.go b/server/npc_shared_pursuit_test.go @@ -120,7 +120,7 @@ func TestFixedNPCPursuitRespectsRootAndSnare(t *testing.T) { } } -func TestFixedNPCColdLoadReturnsWithoutRestoringCombat(t *testing.T) { +func TestFixedNPCColdLoadRestoresHomeAndHealthWithoutCombat(t *testing.T) { for _, state := range []string{"pursuit", "return", "rooted", "home"} { t.Run(state, func(t *testing.T) { world, _ := newFixedBossPursuitWorld(t) @@ -140,7 +140,6 @@ func TestFixedNPCColdLoadReturnsWithoutRestoringCombat(t *testing.T) { if err := world.flushWorld(); err != nil { t.Fatal(err) } - before := npc.position cold := newTestInventoryServer(t) cold.characters[1].playfield = npc.playfield @@ -150,16 +149,9 @@ func TestFixedNPCColdLoadReturnsWithoutRestoringCombat(t *testing.T) { cold.advanceNPCs(cold.lastNPCUpdate.Add(250 * time.Millisecond)) restored := cold.characters[npc.id] - want := float32(5.2) - if state == "home" { - want = 1 - } - if state == "rooted" { - want = 5.5 - } if restored.motion == nil || restored.motion.roaming || restored.motion.home != [3]float32{1, 0, 0} || restored.fighting != 0 || - math.Abs(float64(restored.position[0]-want)) > .0001 || restored.position[1] != 0 || restored.position[2] != 0 || restored.health != 50 || restored.motion.returning != (before != restored.motion.home) || len(cold.mobileNPCs[952]) != 1 { - t.Fatal("cold fixed encounter lost home, moved through a root or resumed stale combat", restored.position, restored.motion, restored.fighting) + restored.position != [3]float32{1, 0, 0} || restored.health != 50 || restored.motion.returning || restored.motion.moving || restored.movementRestricted() != (state == "rooted") || len(cold.mobileNPCs[952]) != 1 { + t.Fatal("cold fixed encounter lost home, health or control state, or resumed stale combat", restored.position, restored.motion, restored.fighting) } }) } diff --git a/server/world_store.go b/server/world_store.go @@ -93,7 +93,7 @@ func (npc *character) worldState(present bool, respawnAt time.Time) npcState { // disposable; corpses and pets retain their actual location. if npc.motion != nil && npc.pet == nil && npc.corpse == nil && npc.health != 0 && npc.npcDefinitionID != "" { state.Character.Position.Position = npc.motion.home - state.Character.Position.Rotation = [4]float32{0, 0, 0, 1} + state.Character.Position.Rotation = npcSpawnRotation(gamedata.NPCGroups[npc.npcDefinitionID]) state.Motion = motionState{Home: npc.motion.home, Destination: npc.motion.home} } if npc.corpse != nil { @@ -317,7 +317,7 @@ func (server *server) loadNPCs() (bool, error) { npc.motion.returning = npc.position != npc.motion.home } } - // Stationary living actors use their authored facing; mobile actors keep live rotation. + // Stationary living actors also take their facing from the definition. if group := gamedata.NPCGroups[npc.npcDefinitionID]; npc.motion == nil && npc.health != 0 && !state.HasCorpse && group != nil && group.FixedSource != nil { npc.rotation = npcSpawnRotation(group) }