aorecomp

Anarchy Online classic in the browser

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


commit fe7f121dfd0c6dc60e340037189c3a461504156e
parent b9377d715f889d3ea81c055442fd33922161276f
Author: anon <anon@example.com>
Date:   Sun, 25 Oct 2026 00:48:13 +0000

Support passive regeneration modifiers and delta implants

Diffstat:
MTODO.md | 17+++++++++++++++--
Mdocs/combat-regeneration.md | 34++++++++++++++++++++++++++++++++--
Mdocs/implants.md | 29++++++++++++++++++++++++++---
Mserver/implant_catalog_test.go | 4++--
Mserver/implants.go | 2+-
Mserver/regeneration.go | 7++++---
Aserver/regeneration_delta_test.go | 240+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 320 insertions(+), 13 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -136,9 +136,14 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). qualities and rounding boundaries, including after equip/remove and restart. - [x] Equip one implant. Check: its slot, treatment/ability requirements and bonuses work independently of armor and weapon slots. -- [ ] Complete the remaining 8,604 implant contracts before admitting them. +- [x] Verify passive HealDelta343/NanoDelta364 equipment recovery against the + real WASM client. Check stacked and mixed implants, posture, unchanged tick + timing, caps, failed installation, removal, cold restore and checkpoint cadence. + Supporting both consumers adds 1,596 complete authored contracts; 244 delta + implants with other unsupported effects still reject as whole items. +- [ ] Complete the remaining 7,008 implant contracts before admitting them. Implement consumers for absorption226/227/228/229/230/231/233/234 and stats - 277/318/343/364/381/383; establish each original rule before naming unknown + 277/318/381/383; establish each original rule before naming unknown stats. Support conditional OnWear130263, Notum Splice204649's complete usable effect, and the unclassified sections of six additional dungeon implants. Do not grant partial effects. Complete records and rejected fixtures are in @@ -587,6 +592,14 @@ introduction and starting-item gameplay remain open below. All six basic ability Boosts and Augment Strength share catalog-driven crystal uploads, casting, stat/NCU contributions and durable add/remove state. See [temporary nanos](docs/nano-buffs.md) for verification and policy limits. +- [ ] Audit and admit complete passive regeneration nano programs, beginning + with Regeneration27144 and Nano Restoration27118. The original catalog audit + retains13 delta programs in `local/regeneration-delta-research/catalog/`. + Check full casting requirements, cost, NCU/strain, duration, cancellation, + expiry, death and cold restore, plus additive equipment contributions. + The343/364 consumers are implemented; these programs remain uncastable until + their complete contracts qualify. Keep passive delta modifiers distinct from + periodic heal-over-time functions. - [x] Enforce NCU capacity. Check: a buff fitting the available NCU succeeds and one exceeding it is rejected without charging resources incorrectly. Native checks cover exact fit at 8/8, rejecting a 9-NCU replacement without diff --git a/docs/combat-regeneration.md b/docs/combat-regeneration.md @@ -95,8 +95,8 @@ health_interval = max(1, trunc((30 - Stamina * float32(1/30)) * percent * float3 nano_interval = max(1, trunc((30 - Psychic * float32(1/30)) * percent * float32(.01))) & ~1 rest = 25 sitting, otherwise 100 if sitting and health_interval > 1: health_interval >>= 1 -health_gain = effective_BodyDevelopment / rest + breed_HealDelta -nano_gain = effective_BodyDevelopment / rest + breed_NanoDelta +health_gain = effective_BodyDevelopment / rest + breed_HealDelta + equipment343 + nano343 +nano_gain = effective_BodyDevelopment / rest + breed_NanoDelta + equipment364 + nano364 ``` Integer division truncates. Health recovery requires the counter to be divisible @@ -105,6 +105,36 @@ rounded interval is zero. Maximums clamp both resources. In this client the nano gain uses Body Development too; substituting Nano Pool changes the result. Exact sources and breed coefficients are in [client stats](combat-client-stats.md). +HealDelta343 and NanoDelta364 modifiers stack after the integer division. +Sitting does not multiply those bonuses, and the deltas do not change the +intervals. Equipment changes affect the next eligible check without resetting +the counter. Health requires an injured actor; nano also permits a negative +final NanoDelta at maximum nano. Nano changes clamp to zero and the effective +maximum. Authored delta implants are all positive; signed synthetic fixtures +cover the negative consumer independently of catalog admission. + +The complete implant audit adds 1,596 definitions whose remaining consumers +are these two deltas. Implants with another unsupported effect still reject +as whole items. Original Regeneration27144 and Nano Restoration27118 provide +active-effect fixtures for the shared nano modifier calculation; this does +not add them to the list of castable programs. See [implants](implants.md). +Recovery stays in memory until a vitals checkpoint; equipping or removing +these implants persists placement immediately without forcing unrelated vitals +updates when the resource caps are unchanged. + +Actual GPU WASM checks used a Solitus fixture with Stamina/Psychic780 +and effective Body Development199. Its standing intervals were3: health +recovered every third two-second check and nano every check after rounding +the interval down to2. Baseline gains4/4 became12/11 with the three implants +listed in [implants](implants.md), and seated gains became18/17. Removing the +mixed implant reduced seated gains to15/15. The same instances and12/11 +standing gains survived server restart. Both resources clamped at their caps; +all four test items survived removal and rejection of the unsupported179201 +implant. Browser errors were empty. Native stats, authoritative wire windows, +SQLite snapshots and the checked report are retained in +`local/regeneration-delta-smoke/verification.json`; native evidence identity +and getter semantics are in `local/regeneration-delta-research/native/`. + For the old default Solitus stats, standing recovery is 3 HP at counter 58, and 3 nano at counters 28 and 56. Sitting halves the health interval from 29 to 14. Attacking recalculates intervals to 59, with health at counter 118 and diff --git a/docs/implants.md b/docs/implants.md @@ -3,17 +3,40 @@ Implants use native type 51022, ItemType 76=3 and Wear bit 4 in Can30. Admission requires the exact authored quality, a valid anatomical mask and a complete implemented effect contract. The decoded catalog contains 44,356 implant -definitions; 35,752 currently qualify. Authored qualities are 1, 200, 201 and +definitions; 37,348 currently qualify. Authored qualities are 1, 200, 201 and 300; no QL400 implants exist. Intermediate qualities are not inferred from matching names. Every admitted function is unconditional OnWear14 Modify53045, target2, one tick and zero interval, with two integer arguments. Supported consumers cover abilities, all trained skills, AC, health/nano maxima, NCU, offense, damage, -XP, weapon range and SkillLockModifier382. Blank implants also qualify. +XP, weapon range, SkillLockModifier382 and HealDelta343/NanoDelta364. +Blank implants also qualify. Conditional/repeating effects, unsupported stat consumers, other use effects, unparsed data and unknown section contracts reject the complete item. The -remaining 8,604 definitions are unavailable until their full behavior is modeled. +remaining 7,008 definitions are unavailable until their full behavior is modeled. + +## Passive regeneration modifiers + +The original catalog has 1,840 delta-bearing implants at authored qualities +1/200/201/300. Supporting343/364 admits 1,596 complete definitions, 399 at +each quality; the other 244 also need an unsupported consumer. Examples179201, +176962 and193040 combine a delta with318,381 or383 and remain unavailable. +The complete original records, hashes and admission audit are retained in +`local/regeneration-delta-research/catalog/`. + +| Complete QL1 fixture | Slot | HealDelta343 | NanoDelta364 | +| --- | --- | ---: | ---: | +|178548|Left arm38|5|0| +|166365|Right wrist39|0|5| +|191531|Feet45|3|2| + +These three stack to +8 health and +7 nano per eligible recovery check. +Each requires Treatment>10, its authored ability>15 and TitleLevel>2, plus +surgery access. Installed deltas retain their full value after an ability +drops below its installation threshold. They change recovery amount, with +the existing native counter, intervals and posture rules documented in +[regeneration](combat-regeneration.md). ## Slots and installation diff --git a/server/implant_catalog_test.go b/server/implant_catalog_test.go @@ -49,7 +49,7 @@ func TestImplantCatalogAdmissionMatchesCompleteAuthoredContracts(t *testing.T) { } } - if total != 44356 || !reflect.DeepEqual(accepted, map[uint32]int{1: 9006, 200: 9003, 201: 8871, 300: 8872}) { + if total != 44356 || !reflect.DeepEqual(accepted, map[uint32]int{1: 9405, 200: 9402, 201: 9270, 300: 9271}) { t.Fatal("implant admission diverged from the original complete-effect audit", total, accepted) } } @@ -179,7 +179,7 @@ func TestImplantSurgeryRevalidatesOutsideChestSlot(t *testing.T) { func TestCatalogImplantsRejectIncompleteEffectsAsWholeItems(t *testing.T) { for _, template := range []uint32{ 130263, 204649, 181297, 181846, 181321, 182584, 179455, 182822, 180292, 183214, - 172245, 173249, 178548, 166365, 176593, 177719, 204613, 204614, 204647, 204650, 204651, 206246, + 172245, 173249, 176593, 177719, 179201, 176962, 193040, 204613, 204614, 204647, 204650, 204651, 206246, } { t.Run(fmt.Sprint(template), func(t *testing.T) { world, conn := newCatalogImplantWorld(t, template) diff --git a/server/implants.go b/server/implants.go @@ -144,7 +144,7 @@ func (item ownedItem) isImplant() bool { continue } switch stat { - case 1, 181, 221, 276, 278, 279, 280, 281, 282, 311, 316, 317, 319, 380, 382: + case 1, 181, 221, 276, 278, 279, 280, 281, 282, 311, 316, 317, 319, 343, 364, 380, 382: default: return false } diff --git a/server/regeneration.go b/server/regeneration.go @@ -61,11 +61,12 @@ func (server *server) advanceRegeneration(now time.Time) { bodyDevelopment := player.effectiveSkill(152, stats.Body.BodyDevelopment, [6]uint32{0, 0, 100, 0, 0, 0}) breed := player.appearance >> 4 & 7 if int32(player.health) < int32(player.maximumHealth()) && client.regenerationSeconds%healthInterval == 0 { - gain := bodyDevelopment/rest + [8]int32{2, 3, 3, 2, 4, 6, 2, 2}[breed] + gain := bodyDevelopment/rest + [8]int32{2, 3, 3, 2, 4, 6, 2, 2}[breed] + player.equipmentBonus(343) + player.nanoBonus(343) player.health = uint32(max(0, min(int32(player.maximumHealth()), int32(player.health)+gain))) } - if int32(player.nano) < int32(player.maximumNano()) && (nanoInterval == 0 || client.regenerationSeconds%nanoInterval == 0) { - gain := bodyDevelopment/rest + [8]int32{2, 3, 3, 4, 2, 1, 2, 2}[breed] + nanoDelta := [8]int32{2, 3, 3, 4, 2, 1, 2, 2}[breed] + player.equipmentBonus(364) + player.nanoBonus(364) + if (int32(player.nano) < int32(player.maximumNano()) || nanoDelta < 0) && (nanoInterval == 0 || client.regenerationSeconds%nanoInterval == 0) { + gain := bodyDevelopment/rest + nanoDelta player.nano = uint32(max(0, min(int32(player.maximumNano()), int32(player.nano)+gain))) } diff --git a/server/regeneration_delta_test.go b/server/regeneration_delta_test.go @@ -0,0 +1,240 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "reflect" + "slices" + "testing" + "time" +) + +func TestRegenerationUsesSignedDeltasAndNativeFullResourceGates(t *testing.T) { + for _, scenario := range []struct { + name string + health, nano uint32 + wantHealth, wantNano uint32 + }{ + {"injured", 20, 10, 14, 4}, + {"full health skips negative delta", 37, 35, 37, 29}, + {"nano drains to zero", 20, 1, 14, 0}, + } { + t.Run(scenario.name, func(t *testing.T) { + // All authored delta implants are positive; this fixture checks signed arithmetic. + original := gamedata.ItemTemplates[191531] + definition := *original + definition.Sections = slices.Clone(original.Sections) + functions := slices.Clone(*definition.Sections[0].Functions) + for index := range functions { + functions[index].Arguments = slices.Clone(functions[index].Arguments) + functions[index].Arguments[1].Integer = new(int32(-9)) + } + definition.Sections[0].Functions = &functions + gamedata.ItemTemplates[191531] = &definition + t.Cleanup(func() { gamedata.ItemTemplates[191531] = original }) + world, _, start := newRegenerationWorld() + player := world.characters[1] + player.inventory.Items = []ownedItem{{Type: 51022, Template: 191531, Quality: 1, Slot: 45}} + player.health, player.nano = scenario.health, scenario.nano + world.clients[1].regenerationSeconds = 810 + + world.advanceRegeneration(start.Add(2 * time.Second)) + + if player.health != scenario.wantHealth || player.nano != scenario.wantNano { + t.Fatal("signed recovery or the full-resource gate diverged", player.health, player.nano) + } + }) + } +} + +func TestRegenerationAddsAuthoredEquipmentAndNanoDeltas(t *testing.T) { + for _, source := range []struct { + name string + items []ownedItem + nanos []activeNano + heal, nano uint32 + }{ + {name: "breed only"}, + {name: "heal implant", items: []ownedItem{{Type: 51022, Template: 178548, Quality: 1, Slot: 38}}, heal: 5}, + {name: "nano implant", items: []ownedItem{{Type: 51022, Template: 166365, Quality: 1, Slot: 39}}, nano: 5}, + {name: "both deltas", items: []ownedItem{{Type: 51022, Template: 191531, Quality: 1, Slot: 45}}, heal: 3, nano: 2}, + {name: "stacked implants", items: []ownedItem{ + {Type: 51022, Template: 178548, Quality: 1, Slot: 38}, + {Type: 51022, Template: 166365, Quality: 1, Slot: 39}, + {Type: 51022, Template: 191531, Quality: 1, Slot: 45}, + }, heal: 8, nano: 7}, + // These original programs are active-effect fixtures, not newly admitted casts. + {name: "implants and nanos", items: []ownedItem{ + {Type: 51022, Template: 178548, Quality: 1, Slot: 38}, + {Type: 51022, Template: 166365, Quality: 1, Slot: 39}, + {Type: 51022, Template: 191531, Quality: 1, Slot: 45}, + }, nanos: []activeNano{{program: 27144}, {program: 27118}}, heal: 11, nano: 9}, + {name: "carried implants", items: []ownedItem{ + {Type: 51022, Template: 178548, Quality: 1, Slot: 64}, + {Type: 51022, Template: 166365, Quality: 1, Slot: 65}, + }}, + } { + for _, posture := range []struct { + name string + sitting, fighting bool + counter, health, nano uint32 + interval uint32 + }{ + {"standing", false, false, 812, 25, 5, 29}, + {"sitting", true, false, 28, 31, 11, 29}, + {"attacking", false, true, 3422, 25, 5, 59}, + } { + t.Run(source.name+"/"+posture.name, func(t *testing.T) { + world, conn, start := newRegenerationWorld() + player := world.characters[1] + player.level, player.stats.Body.BodyDevelopment = 50, 198 + player.inventory.Items, player.activeNanos = source.items, source.nanos + player.sitting = posture.sitting + if posture.fighting { + player.fighting = 1000000 + } + world.clients[1].regenerationSeconds = posture.counter - 2 + + world.advanceRegeneration(start.Add(2 * time.Second)) + healthInterval, nanoInterval := player.regenerationIntervals() + + if player.health != posture.health+source.heal || player.nano != posture.nano+source.nano || + healthInterval != posture.interval || nanoInterval != posture.interval { + t.Fatal("deltas changed timing or were divided by posture", player.health, player.nano, healthInterval, nanoInterval) + } + last := conn.packets[len(conn.packets)-1] + if binary.BigEndian.Uint32(last[29:33]) != 214 || binary.BigEndian.Uint32(last[33:37]) != player.nano { + t.Fatal("recovery did not publish authoritative nano", last) + } + }) + } + } +} + +func TestRegenerationDeltasClampWithoutRevivingOrChangingSkippedActors(t *testing.T) { + for _, scenario := range []string{"below cap", "at cap", "dead", "loading", "offline", "not ready"} { + t.Run(scenario, func(t *testing.T) { + world, _, start := newRegenerationWorld() + player := world.characters[1] + player.inventory.Items = []ownedItem{{Type: 51022, Template: 191531, Quality: 1, Slot: 45}} + player.health, player.nano = 36, 34 + world.clients[1].regenerationSeconds = 810 + switch scenario { + case "at cap": + player.health, player.nano = 37, 35 + case "dead": + player.health = 0 + case "loading": + world.clients[1].loading = true + case "offline": + delete(world.clients, 1) + case "not ready": + world.clients[1].ready = false + } + health, nano := player.health, player.nano + + world.advanceRegeneration(start.Add(2 * time.Second)) + + if scenario == "below cap" || scenario == "at cap" { + if player.health != 37 || player.nano != 35 { + t.Fatal("delta overflowed the resource cap", player.health, player.nano) + } + } else if player.health != health || player.nano != nano { + t.Fatal("delta bypassed the actor recovery gate", player.health, player.nano) + } + }) + } +} + +func TestRegenerationImplantMovesPersistAndTicksWaitForCheckpoint(t *testing.T) { + world, _ := newCatalogImplantWorld(t, 178548) + player, client := world.characters[1], world.clients[1] + player.level = 50 + player.stats.Abilities.Strength, player.stats.Abilities.Agility, player.stats.Abilities.Sense = 16, 16, 16 + player.appearance, player.health, player.nano = 1<<4, 20, 0 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + for _, template := range []uint32{166365, 191531} { + if granted, err := world.grantItem_locked(player, template); err != nil || !granted { + t.Fatal(granted, err) + } + } + before := slices.Clone(player.inventory.Items) + + for _, move := range [][2]uint32{{66, 38}, {67, 39}, {68, 45}} { + if err := world.handleInventory(client, inventoryMovePacket(1, move[0], move[1])[20:]); err != nil || client.equipment == nil { + t.Fatal("valid regeneration implant did not start installation", move, err) + } + world.advanceEquipment(client.equipment.readyAt) + } + restarted := newTestInventoryServer(t).characters[1] + if restarted.equipmentBonus(343) != 8 || restarted.equipmentBonus(364) != 7 || len(restarted.inventory.Items) != len(before) { + t.Fatal("cold load lost installed deltas or items", restarted.inventory.Items) + } + auditCheckpointWrites(t, world) + start := time.Unix(100, 0) + client.regenerationAt, client.regenerationSeconds = start, 810 + world.advanceRegeneration(start.Add(2 * time.Second)) + + if player.health != 31 || player.nano != 10 || checkpointWrites(t, world)["characters/UPDATE"] != 0 { + t.Fatal("recovery lost deltas or wrote its low-significance tick to SQLite", player.health, player.nano, checkpointWrites(t, world)) + } + if cold := newTestInventoryServer(t).characters[1]; cold.health != 20 || cold.nano != 0 { + t.Fatal("recovery persisted before checkpoint", cold.health, cold.nano) + } + + // Remove equipment through the same public move path without forcing a vitals checkpoint. + if err := world.handleInventory(client, itemMovePacket(1, 45, 111)[20:]); err != nil || client.equipment == nil { + t.Fatal("regeneration implant did not start removal", err) + } + world.advanceEquipment(client.equipment.readyAt) + restarted = newTestInventoryServer(t).characters[1] + if restarted.health != 20 || restarted.nano != 0 || restarted.equipmentBonus(343) != 5 || restarted.equipmentBonus(364) != 5 || + len(restarted.inventory.Items) != len(before) || restarted.inventory.Items[4].ID != before[4].ID || restarted.inventory.Items[4].Slot != 66 { + t.Fatal("removal lost vitals, identity, placement or remaining deltas", restarted.inventory.Items) + } + client.regenerationSeconds = 1622 + world.advanceRegeneration(start.Add(4 * time.Second)) + if player.health != 39 || player.nano != 18 || client.regenerationSeconds != 1624 { + t.Fatal("removing a delta did not change the next gain exactly once", player.health, player.nano) + } + if err := world.flushWorld(); err != nil { + t.Fatal(err) + } + if cold := newTestInventoryServer(t).characters[1]; cold.health != 39 || cold.nano != 18 { + t.Fatal("world flush lost accumulated recovery", cold.health, cold.nano) + } +} + +func TestRegenerationDeltaInstallFailurePreservesItemsAndRecovery(t *testing.T) { + for _, scenario := range []string{"ability equality", "title equality", "failed save"} { + t.Run(scenario, func(t *testing.T) { + world, conn := newCatalogImplantWorld(t, 191531) + player, client := world.characters[1], world.clients[1] + player.level, player.stats.Abilities.Strength = 50, 16 + if scenario == "ability equality" { + player.stats.Abilities.Strength = 15 + } else if scenario == "title equality" { + player.level = 49 + } + before := slices.Clone(player.inventory.Items) + stored, _ := readTestItemStore(world) + + err := world.handleInventory(client, inventoryMovePacket(1, 66, 45)[20:]) + if scenario == "failed save" { + if client.equipment == nil { + t.Fatal("valid delta installation did not start") + } + failDatabaseWrites(t, world) + world.advanceEquipment(client.equipment.readyAt) + } + after, _ := readTestItemStore(world) + + if err != nil || client.equipment != nil || !reflect.DeepEqual(player.inventory.Items, before) || !slices.Equal(stored, after) || + player.equipmentBonus(343) != 0 || player.equipmentBonus(364) != 0 { + t.Fatal("rejected delta install changed ownership or recovery", err, conn.packets) + } + }) + } +}