aorecomp

Anarchy Online classic in the browser

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


commit 2ebdd3875f33a8d377688b4b9ce17d82f154d812
parent ea74c05b3b5097829093740f930accae05c5e100
Author: anon <anon@example.com>
Date:   Fri,  6 Nov 2026 00:06:18 +0000

Stock early Meta-Physicist combat pet upgrades

Diffstat:
MTODO.md | 11++++++++---
Mdocs/early-shop-stock.md | 91+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Mdocs/pet-attack.md | 5+++--
Mserver/basic_shop_nanos_test.go | 32++++++++++++++++++++++++++++++--
Mserver/browser_basic_shop_nanos_test.go | 57+++++++++++++++++++++++++++++++++++++++++++++++++--------
Mserver/browser_shop_availability_test.go | 5+----
Mserver/gamedata/shop_stock.yaml | 8++++++++
Mserver/nano_learning.go | 2+-
Aserver/pet_upgrade_test.go | 132+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/pets.go | 39++++++++++++++++++++++++++++++---------
Mserver/shop_availability_test.go | 2+-
Mtools/client/test_basic_shop_nanos.mjs | 21+++++++++++++++++++--
12 files changed, 360 insertions(+), 45 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -119,7 +119,7 @@ research separately. More screenshots and test cases do not count as new gamepla Thirty-six crystal terminals now carry 19 original early nanos with complete supported contracts; all 36 pass native buy/sell, cancel, upload/cast and reconnect/cold recovery, with every row covered by server regressions. - 123 placements remain empty and visibly identify unsupported purchases while + 120 placements remain empty and visibly identify unsupported purchases while retaining loot sales. The Meta-Physicist starter Mind Pain now executes its complete damage and six-skill debuff. Its existing Lesser Anger Manifestation now accepts native attack commands, pursues enemies, takes retaliation and @@ -128,8 +128,13 @@ research separately. More screenshots and test cases do not count as new gamepla Engineer Feeble Automaton now creates a one-charge shell for four credits; using it activates an owned robot with combat, removal and recovery support. See [the original contracts and provisional robot profile](docs/engineer-robots.md). - Useful shop upgrades and other profession essentials remain open, - alongside the bounded ordinary-play affordability check. New mission offers + The three Meta-Physicist terminals now sell Inferior, Greater and Supreme + Anger Manifestation, giving level-2/6/8 combat pets under an explicit + provisional profile. Their original requirements, costs and lifetimes remain + intact; purchase/use and recovery checks are described in + [the stock ledger](docs/early-shop-stock.md#meta-physicist-pet-upgrades). + Remaining profession essentials and the bounded ordinary-play affordability + check stay open. New mission offers now pay an explicit provisional 500 credits per selected mission level; level-one completion cash covers recovery/ammunition resupply in all three factions without selling issued items. Controlled settlement/purchase checks diff --git a/docs/early-shop-stock.md b/docs/early-shop-stock.md @@ -11,9 +11,9 @@ browse/buy/use behavior. Baseline: 163 placements had no catalog rows, including all four training-ground terminals. The training terminals now each carry seven recovery/ammunition rows, leaving 159 empty placements before nano stock. The three basic weapon terminals -contain four ammunition packages and twelve weapon rows. Thirty-six profession and -general crystal terminals now stock an early subset, leaving 123 empty placements. -The three Meta-Physicist terminals still lack usable early combat stock. +contain four ammunition packages and twelve weapon rows. All 39 profession and +general crystal terminals now stock an early subset, leaving 120 empty placements. +The three Meta-Physicist terminals include the pet upgrades below. ## Mission cash and resupply @@ -319,8 +319,62 @@ Symbol Helper (29192 -> 29113) was considered for Meta-Physicist stock but rejec its Psychological Modification/Sensory Improvement requirements exceed the unbuffed level-ten checkpoint. It is crafting utility in any case, so stocking it would not resolve the missing combat essentials. The three Meta-Physicist -terminals remain empty pending useful supported content. The notice below -identifies that limitation without closing the missing profession essentials. +terminals instead supply the combat-pet upgrades below. + +## Meta-Physicist pet upgrades + +The three basic Meta-Physicist terminals now offer this fixed combat subset. +The selections are provisional stock policy; original crystal qualities, prices, +requirements and complete SpawnPetACG contracts are retained. + +| Crystal -> program | Formula | Crystal QL | Pet level | MC and TS required | Lifetime | Nano debit | Omni price | Clan/Neutral price | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | +| 43784 -> 43725 | Inferior Anger Manifestation | 1 | 2 | 19 | 600 s | 14 | 201 | 211 | +| 43789 -> 43719 | Greater Anger Manifestation | 7 | 6 | 41 | 700 s | 29 | 1490 | 1564 | +| 43769 -> 43745 | Supreme Anger Manifestation | 7 | 8 | 52 | 700 s | 37 | 1518 | 1593 | + +Nano debits assume no cost modifiers; prices precede Computer Literacy discounts. +The crystal and summon records are in `server/gamedata/items/items_002.yaml` and +`items_167.yaml`. The formula's display quality is not its pet level or the +crystal quality. Admission checks the entire original PT50 effect, including its +raw tail. Other pet formulas remain unsupported. + +The existing PT50 body 96195 and single right fist 120637/120638 are retained. +**Health 17 per pet level and MA/evade/Nano Resist ratings 5 per level are explicit +provisional alpha balance.** This gives health 34/102/136 and ratings 10/30/40. +The weapon is interpolated at the authored pet level through the existing NPC +weapon path, improving on the starter pet's ordinary hit. Initiative remains 0, +AggDef 75 and nano 25. No recovered original server template establishes those +resources, ratings or the PT50-to-weapon binding; see [pet combat](pet-attack.md). +Follow/wait/attack, owner loot rights, expiry, death/removal and recovery use the +shared pet system. These upgrades do not add another pet slot or a heal pet. + +`TestBasicShopNanosPurchaseLearnCastAndRecover` buys and uses every new row at +all three terminals at the level-ten skill checkpoint, verifies exact prices and +consumption, and performs full cold startup including pet ownership and weapon +quality. `pet_upgrade_test.go` checks strict MC/TS boundaries, increasing combat +strength, original expiry and refusal of altered spawn contracts. This fixture +caps trained skills at the native level-ten maximum; it does not claim earned IP +or ordinary-play affordability. + +`TestBrowserMPShopNanos` uses real native input to open each terminal, buy every +new row, sell loot, cancel/retry, upload/cast, command a pet attack and reconnect. +The controlled level-one Leet has 16 health to keep this a short shop integration +check. Its death grants the owner loot rights, but correctly grants no XP to the +level-ten owner. Cold startup checks the same pet, kill, ownership and costs. +This is a controlled behavior check, not earned-progression evidence. + +All nine native crystal/faction combinations pass in 225.78 seconds. Artifacts +are under `local/alpha-nanos/20261105-160022/`, grouped by terminal and crystal; +the log is `local/alpha-mp-upgrades/browser-final.log`. Catalog and cast captures +were inspected. The focused server batch passes 58 test roots and 484 results, +including the existing pet/Engineer lifecycle, all 66 crystal purchases, atomic +shop failures and all 190 catalog notices (`regressions.log` in the same log +directory). `go vet ./server/...`, JavaScript syntax and diff checks pass. + +The three formerly empty profession terminals are usable; broader pet catalogs +and the ordinary-play affordability check remain outside this completed stock +subset. ## Empty terminal feedback @@ -333,17 +387,28 @@ limitation notice. Empty ShopUpdate packets remain omitted to avoid the native GM warning. `TestEarlyShopCatalogAvailabilityFeedback` covers all 190 scoped placements: -123 empty terminals emit exactly one named notice, 67 stocked terminals emit +120 empty terminals emit exactly one named notice, 70 stocked terminals emit their catalog without that notice, and replayed Use leaves both unchanged. -The initial regression reproduced all 123 missing notices. Existing admission, +The initial regression reproduced all 123 then-missing notices. Existing admission, sale cancellation, purchase and rejected-write/retry checks also pass. -`TestBrowserShopAvailability` and `tools/client/test_shop_availability.mjs` visit -the three empty Meta-Physicist terminals with real right-click/E input. Each +`TestBrowserShopAvailability` and `tools/client/test_shop_availability.mjs` originally visited +the three then-empty Meta-Physicist terminals with real right-click/E input. Each shows the notice, cancels an offered item, sells it on retry, reconnects and reopens with the notice again. Exact cash and ownership survive cold recovery. Screenshots confirm the native notice is visible. This is UI and sale evidence, -not support for missing Meta-Physicist purchases or combat. +not evidence of the later Meta-Physicist purchase/combat implementation above. +The maintained scenario now uses the three still-empty Basic Bookstores. + +The Bookstore rerun passes all three factions in 51.94 seconds. Captures are +under `local/alpha-shop-availability/20261105-160509/` with placement directories +`c008049f`, `c02a049c` and `c01504a2`; the visible notice was inspected after +reconnect. The log is `local/alpha-mp-upgrades/bookstores-final.log`. The preceding +combined run passed all nine pet scenarios before the Bookstore fixture's old +Omni crystal-terminal payout assertion failed. All three Bookstores use original +template 155599's sale modifier 4, so this sale correctly leaves 584 credits in +every faction. Correcting that expectation required no transaction behavior +change. Test servers and Chromium processes were closed after both runs. Passing browser artifacts are under `local/alpha-shop-availability/`: `20261105-134424/c013049f` (Omni), `20261105-134424/c014049c` (Clan), and @@ -382,7 +447,7 @@ essentials and ordinary-reward affordability. | 1180 | `0xc011049c` | 90576 | Basic Clan Fixer Crystals | 1 | 217.00, 5.01, 203.00 | | 1180 | `0xc012049c` | 90574 | Basic Clan General Crystals | 8 | 209.00, 5.01, 193.00 | | 1180 | `0xc013049c` | 90571 | Basic Clan Martial Artist Crystals | 1 | 217.00, 5.01, 195.00 | -| 1180 | `0xc014049c` | 90569 | Basic Clan Meta-Physicist Crystals | 0 | 213.00, 5.01, 193.00 | +| 1180 | `0xc014049c` | 90569 | Basic Clan Meta-Physicist Crystals | 3 | 213.00, 5.01, 193.00 | | 1180 | `0xc015049c` | 90567 | Basic Clan Nanotechnician Crystals | 1 | 217.00, 5.01, 199.00 | | 1180 | `0xc016049c` | 90564 | Basic Clan Soldier Crystals | 1 | 197.00, 5.01, 199.00 | | 1180 | `0xc017049c` | 90562 | Basic Clan Trader Crystals | 1 | 197.00, 5.01, 203.00 | @@ -436,7 +501,7 @@ essentials and ordinary-reward affordability. | 1183 | `0xc010049f` | 90575 | Basic Omni-Tek Fixer Crystals | 1 | 202.80, 5.00, 165.00 | | 1183 | `0xc011049f` | 90573 | Basic Omni-Tek General Crystals | 8 | 195.00, 5.00, 155.20 | | 1183 | `0xc012049f` | 90570 | Basic Omni-Tek Martial Artist Crystals | 1 | 202.80, 5.00, 157.00 | -| 1183 | `0xc013049f` | 90568 | Basic Omni-Tek Meta-Physicist Crystals | 0 | 199.00, 5.00, 155.20 | +| 1183 | `0xc013049f` | 90568 | Basic Omni-Tek Meta-Physicist Crystals | 3 | 199.00, 5.00, 155.20 | | 1183 | `0xc014049f` | 90565 | Basic Omni-Tek Nanotechnician Crystals | 1 | 202.80, 5.00, 161.00 | | 1183 | `0xc015049f` | 90563 | Basic Omni-Tek Soldier Crystals | 1 | 183.20, 5.00, 161.00 | | 1183 | `0xc016049f` | 90561 | Basic Omni-Tek Trader Crystals | 1 | 183.20, 5.00, 165.00 | @@ -502,7 +567,7 @@ essentials and ordinary-reward affordability. | 1186 | `0xc00604a2` | 43571 | Basic Fixer Crystals | 1 | 191.00, 5.00, 157.00 | | 1186 | `0xc00704a2` | 43569 | Basic General Crystals | 8 | 183.00, 5.00, 147.00 | | 1186 | `0xc00804a2` | 43575 | Basic Martial Artist Crystals | 1 | 191.00, 5.00, 149.00 | -| 1186 | `0xc00904a2` | 43574 | Basic Meta-Physicist Crystals | 0 | 187.00, 5.00, 147.00 | +| 1186 | `0xc00904a2` | 43574 | Basic Meta-Physicist Crystals | 3 | 187.00, 5.00, 147.00 | | 1186 | `0xc00a04a2` | 43573 | Basic Nanotechnician Crystals | 1 | 191.00, 5.00, 153.00 | | 1186 | `0xc00b04a2` | 43572 | Basic Soldier Crystals | 1 | 171.00, 5.00, 153.00 | | 1186 | `0xc00c04a2` | 43570 | Basic Trader Crystals | 1 | 171.00, 5.00, 157.00 | diff --git a/docs/pet-attack.md b/docs/pet-attack.md @@ -48,8 +48,9 @@ entity and ownership for retry. This dissolution policy is provisional. Cold recovery restores the weapon profile and ownership, while combat commands remain transient. Existing idle NPC regeneration supplies recovery between -fights. This change adds no new pet levels, healing commands, guard/hunt modes, -Engineer robots or shop upgrades. +fights. [Engineer robots](engineer-robots.md) and the bounded +[Meta-Physicist shop upgrades](early-shop-stock.md#meta-physicist-pet-upgrades) +also use this combat path. Healing commands and guard/hunt modes remain unsupported. ## Focused checks diff --git a/server/basic_shop_nanos_test.go b/server/basic_shop_nanos_test.go @@ -58,11 +58,20 @@ func trainBasicShopNanoFixture(player *character, profession uint32) { player.health, player.nano = 20, player.maximumNano() } +func mpShopNanoFixtures() []basicShopNanoFixture { + return []basicShopNanoFixture{ + {[2]uint32{201, 211}, 12, [3]uint32{0xc013049f, 0xc014049c, 0xc00904a2}, 43784, 43725, 1, 0, 0, 0, 0, false}, + {[2]uint32{1490, 1564}, 12, [3]uint32{0xc013049f, 0xc014049c, 0xc00904a2}, 43789, 43719, 7, 0, 0, 0, 0, false}, + {[2]uint32{1518, 1593}, 12, [3]uint32{0xc013049f, 0xc014049c, 0xc00904a2}, 43769, 43745, 7, 0, 0, 0, 0, false}, + } +} + func TestBasicShopNanosPurchaseLearnCastAndRecover(t *testing.T) { - for _, fixture := range basicShopNanoFixtures() { + for _, fixture := range append(basicShopNanoFixtures(), mpShopNanoFixtures()...) { for _, machineID := range fixture.machines { t.Run(fmt.Sprintf("%x/%d", machineID, fixture.crystal), func(t *testing.T) { world, _ := newPurchaseWorld(t) + world.nextNPC = 1000001 player, client, target := world.characters[1], world.clients[1], world.characters[1000000] machine := gamedata.ShopMachines[machineID] player.playfield, player.position = machine.Playfield, machine.Position @@ -146,7 +155,26 @@ func TestBasicShopNanosPurchaseLearnCastAndRecover(t *testing.T) { } // Credits, consumed crystal, learned program and effects survive restart. - cold := newTestInventoryServer(t).characters[1] + var coldWorld *server + if fixture.profession == 12 { + coldWorld = newServerForTest(t) + } else { + coldWorld = newTestInventoryServer(t) + } + cold := coldWorld.characters[1] + if fixture.profession == 12 { + level := map[uint32]uint16{43725: 2, 43719: 6, 43745: 8}[fixture.program] + for _, current := range []*server{world, coldWorld} { + if len(current.characters[1].pets) != 1 { + t.Fatal("purchased summon lost pet ownership") + } + for _, pet := range current.characters[1].pets { + if pet.level != level || pet.health != 17*uint32(level) || pet.pet.program != fixture.program || pet.attackWeapon().Quality == nil || *pet.attackWeapon().Quality != uint32(level) { + t.Fatal("purchased pet lost its level, resources or weapon", pet) + } + } + } + } if !reflect.DeepEqual(cold.inventory, player.inventory) || cold.inventory.Credits != credits || world.nextItem != 2 || cold.nano != player.nano { t.Fatal("purchase/upload/cast changed during cold recovery") } diff --git a/server/browser_basic_shop_nanos_test.go b/server/browser_basic_shop_nanos_test.go @@ -19,17 +19,24 @@ import ( ) func TestBrowserBasicShopNanos(t *testing.T) { + // General weapon proficiencies have all-row server coverage. + testBrowserBasicShopNanos(t, basicShopNanoFixtures()[:12]) +} + +func TestBrowserMPShopNanos(t *testing.T) { + testBrowserBasicShopNanos(t, mpShopNanoFixtures()) +} + +func testBrowserBasicShopNanos(t *testing.T, fixtures []basicShopNanoFixture) { if os.Getenv("AO_GAME_TEST") != "1" { t.Skip("set AO_GAME_TEST=1 for the basic crystal terminals") } _, source, _, _ := runtime.Caller(0) root := filepath.Dir(filepath.Dir(source)) output := filepath.Join(root, "local/alpha-nanos", time.Now().Format("20060102-150405")) - // Every terminal is visited; the general terminal uses its healing row here. - // The server regression purchases and casts every general weapon proficiency. - for _, fixture := range basicShopNanoFixtures()[:12] { + for _, fixture := range fixtures { for _, identity := range fixture.machines { - t.Run(fmt.Sprintf("%x", identity), func(t *testing.T) { + t.Run(fmt.Sprintf("%x/%d", identity, fixture.crystal), func(t *testing.T) { world := newTestServer(t) machine := gamedata.ShopMachines[identity] player := world.newCharacter() @@ -64,6 +71,10 @@ func TestBrowserBasicShopNanos(t *testing.T) { target.playfield, target.position, target.health = player.playfield, player.position, 1000 target.position[0] -= 1.5 * forward[0] target.position[2] -= 1.5 * forward[2] + petLevel := map[uint32]uint16{43725: 2, 43719: 6, 43745: 8}[fixture.program] + if petLevel != 0 { + target.health = 16 + } world.combatRoll = landedCombatRoll creditsAfterPurchase := uint32(10000 - fixture.prices[0] + 605) if machine.Playfield != 1183 { @@ -89,14 +100,22 @@ func TestBrowserBasicShopNanos(t *testing.T) { for _, effect := range recipient.activeNanos { effects = append(effects, effect.program) } + var petID, looter uint32 + if target.corpse != nil { + looter = target.corpse.looter + } + for id := range player.pets { + petID = id + } json.NewEncoder(w).Encode(map[string]any{"machine": identity, "playfield": machine.Playfield, - "creditsAfterPurchase": creditsAfterPurchase, "rows": len(gamedata.ShopStock[machine.Template]), "crystal": fixture.crystal, "program": fixture.program, "quality": fixture.quality, + "creditsAfterPurchase": creditsAfterPurchase, "rows": len(gamedata.ShopStock[machine.Template]), "crystal": fixture.crystal, "row": slices.Index(gamedata.ShopStock[machine.Template], gamedata.ShopItem{Template: fixture.crystal, Quality: fixture.quality}), "petLevel": petLevel, "pet": petID, "enemy": target.id, "experience": player.experience, "enemyHealth": target.health, "looter": looter, "program": fixture.program, "quality": fixture.quality, "stat": fixture.stat, "bonus": fixture.bonus, "minimum": fixture.minimum, "maximum": fixture.maximum, "hostile": fixture.hostile, "open": open, "purchases": purchases, "sales": sales, "inventory": player.inventory, "target": recipient.id, "health": recipient.health, "nano": player.nano, "reserved": player.nanoReserved, "effects": effects, "appliedBonus": player.nanoBonus(fixture.stat), "rooted": target.movementRestricted()}) }) host := httptest.NewServer(mux) defer host.Close() + closeTestBrowserStreams(t, world) ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) stopped := make(chan struct{}) go func() { @@ -108,20 +127,42 @@ func TestBrowserBasicShopNanos(t *testing.T) { case now := <-clock.C: world.advancePlayerMovement(now) world.advanceNanos(now) + if petLevel != 0 { + world.advanceCombat(now) + } case <-ctx.Done(): return } } }() defer func() { cancel(); <-stopped }() - command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_basic_shop_nanos.mjs"), host.URL, filepath.Join(output, fmt.Sprintf("%x", identity))) + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_basic_shop_nanos.mjs"), host.URL, filepath.Join(output, fmt.Sprintf("%x/%d", identity, fixture.crystal))) command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr err := command.Run() - t.Logf("Browser artifacts: %s", filepath.Join(output, fmt.Sprintf("%x", identity))) + t.Logf("Browser artifacts: %s", filepath.Join(output, fmt.Sprintf("%x/%d", identity, fixture.crystal))) if err != nil { t.Fatal(err) } - cold := newTestInventoryServer(t).characters[1] + cancel() + <-stopped + var coldWorld *server + if petLevel != 0 { + coldWorld = newServerForTest(t) + } else { + coldWorld = newTestInventoryServer(t) + } + cold := coldWorld.characters[1] + if petLevel != 0 { + target = coldWorld.characters[target.id] + if len(cold.pets) != 1 || cold.experience != 0 || target.health != 0 || target.corpse == nil || target.corpse.looter != player.id { + t.Fatal("purchased pet or reward did not survive restart") + } + for _, pet := range cold.pets { + if pet.level != petLevel || pet.pet.program != fixture.program { + t.Fatal("cold pet lost upgrade") + } + } + } if cold.inventory.Credits != creditsAfterPurchase || cold.inventory.LastID != 2 || len(cold.inventory.Items) != 0 || !slices.Equal(cold.inventory.LearnedNanos, []uint32{fixture.program}) || fixture.stat != 0 && cold.nanoBonus(fixture.stat) != fixture.bonus { t.Fatal("purchased nano changed during cold recovery", cold.inventory, cold.activeNanos) diff --git a/server/browser_shop_availability_test.go b/server/browser_shop_availability_test.go @@ -24,7 +24,7 @@ func TestBrowserShopAvailability(t *testing.T) { _, source, _, _ := runtime.Caller(0) root := filepath.Dir(filepath.Dir(source)) output := filepath.Join(root, "local/alpha-shop-availability", time.Now().Format("20060102-150405")) - for _, id := range []uint32{0xc013049f, 0xc014049c, 0xc00904a2} { + for _, id := range []uint32{0xc008049f, 0xc02a049c, 0xc01504a2} { t.Run(fmt.Sprintf("%x", id), func(t *testing.T) { world := newTestServer(t) machine := gamedata.ShopMachines[id] @@ -47,9 +47,6 @@ func TestBrowserShopAvailability(t *testing.T) { t.Fatal(err) } creditsAfterSale := uint32(584) - if machine.Playfield == 1183 { - creditsAfterSale = 705 - } mux := http.NewServeMux() mux.Handle("/", world.httpHandler()) mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) { diff --git a/server/gamedata/shop_stock.yaml b/server/gamedata/shop_stock.yaml @@ -183,3 +183,11 @@ - {template: 26481, quality: 4} 90574: *basic_general_nanos 43569: *basic_general_nanos + +# Meta-Physicist combat upgrades within the alpha's level-ten skill checkpoint. +90568: &basic_meta_physicist_nanos + - {template: 43784, quality: 1} + - {template: 43789, quality: 7} + - {template: 43769, quality: 7} +90569: *basic_meta_physicist_nanos +43574: *basic_meta_physicist_nanos diff --git a/server/nano_learning.go b/server/nano_learning.go @@ -42,7 +42,7 @@ func nanoCrystalProgram(template uint32) uint32 { return 0 } program = uint32(*function.Arguments[0].Integer) - if !engineerShellNano(program) && !statBuffNano(program) && directDamageNano(program) == nil && directHealingNano(program) == nil && healingOverTimeNano(program) == nil && damageOverTimeNano(program) == nil && controlNano(program) == nil { + if !petSummonNano(program) && !engineerShellNano(program) && !statBuffNano(program) && directDamageNano(program) == nil && directHealingNano(program) == nil && healingOverTimeNano(program) == nil && damageOverTimeNano(program) == nil && controlNano(program) == nil { return 0 } } diff --git a/server/pet_upgrade_test.go b/server/pet_upgrade_test.go @@ -0,0 +1,132 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "fmt" + "testing" + "time" +) + +func TestPetUpgradesRespectOriginalSkillBoundaries(t *testing.T) { + for _, fixture := range []struct{ program, threshold uint32 }{{43725, 18}, {43719, 40}, {43745, 51}} { + for _, stat := range []uint32{130, 131} { + t.Run(fmt.Sprintf("%d/%d", fixture.program, stat), func(t *testing.T) { + world, _ := newPetSummonWorld(t) + player, client := world.characters[1], world.clients[1] + trainBasicShopNanoFixture(player, 12) + player.inventory.LearnedNanos = []uint32{fixture.program} + actual, _ := player.effectiveStat(stat) + if stat == 130 { + player.stats.NanoAiding.MatterCreation -= uint16(actual) - uint16(fixture.threshold) + } else { + player.stats.NanoAiding.TimeAndSpace -= uint16(actual) - uint16(fixture.threshold) + } + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + before := player.nano + request := characterActionPacket(1, [5]uint32{19, 0, 0, 53019, fixture.program})[20:] + + world.handleNanoCast(client, request) + + if client.nanoCast != nil || player.nano != before || len(player.pets) != 0 { + t.Fatal("strict authored skill threshold was relaxed") + } + if stat == 130 { + player.stats.NanoAiding.MatterCreation++ + } else { + player.stats.NanoAiding.TimeAndSpace++ + } + if err := world.handleNanoCast(client, request); err != nil || client.nanoCast == nil { + t.Fatal("first valid skill point did not admit summon", err) + } + }) + } + } +} + +func TestPetUpgradesImproveCombatAndRetainOriginalLifetime(t *testing.T) { + for _, fixture := range []struct { + program, health, rating, debit uint32 + level uint16 + lifetime time.Duration + }{ + {43725, 34, 10, 14, 2, 600 * time.Second}, + {43719, 102, 30, 29, 6, 700 * time.Second}, + {43745, 136, 40, 37, 8, 700 * time.Second}, + } { + t.Run(fmt.Sprint(fixture.program), func(t *testing.T) { + world, _ := newPetSummonWorld(t) + player, client, target := world.characters[1], world.clients[1], world.characters[1000000] + trainBasicShopNanoFixture(player, 12) + player.inventory.LearnedNanos = []uint32{fixture.program} + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + before := player.nano + request := characterActionPacket(1, [5]uint32{19, 0, 0, 53019, fixture.program})[20:] + world.handleNanoCast(client, request) + if client.nanoCast == nil { + t.Fatal("upgrade could not cast") + } + completed := client.nanoCast.readyAt.Add(time.Nanosecond) + + world.advanceNanos(completed) + pet := player.pets[1000001] + if pet == nil || pet.level != fixture.level || pet.health != fixture.health || pet.attackRating() != int32(fixture.rating) || + player.nano != before-fixture.debit || !pet.pet.expiresAt.Equal(completed.Add(fixture.lifetime)) { + t.Fatal("upgrade profile/cost/lifetime changed", pet) + } + client.selectedTarget = [2]uint32{50000, target.id} + world.handlePetCommand(client, petAttackRequest()) + world.advanceCombat(pet.nextAttack) + if target.health >= 84 { + t.Fatal("upgrade did not improve on the starter's 16-damage hit", target.health) + } + + // Wait cancels combat; expiry removes this exact higher-level entity once. + wait := petFollowRequest(1)[20:] + binary.BigEndian.PutUint32(wait[16:], 4) + world.handlePetCommand(client, wait) + world.advanceNanos(pet.pet.expiresAt.Add(-time.Nanosecond)) + if len(player.pets) != 1 { + t.Fatal("upgrade expired early") + } + world.advanceNanos(pet.pet.expiresAt) + if len(player.pets) != 0 || world.characters[pet.id] != nil { + t.Fatal("upgrade ignored authored expiry") + } + }) + } +} + +func TestPetUpgradeRejectsIncompleteSpawnContract(t *testing.T) { + for _, fixture := range mpShopNanoFixtures() { + for _, field := range []string{"level", "lifetime", "tail"} { + t.Run(fmt.Sprintf("%d/%s", fixture.program, field), func(t *testing.T) { + original := gamedata.NanoTemplates[fixture.program] + clone := *original + clone.Sections = append([]gamedata.ItemSection(nil), original.Sections...) + functions := append([]gamedata.ItemFunction(nil), (*original.Sections[2].Functions)...) + functions[0].Arguments = append([]gamedata.ItemArgument(nil), functions[0].Arguments...) + clone.Sections[2].Functions = &functions + wrong, tail := int32(999), "00000000" + switch field { + case "level": + functions[0].Arguments[1].Integer = &wrong + case "lifetime": + functions[0].Arguments[2].Integer = &wrong + case "tail": + functions[0].Arguments[3].BytesHex = &tail + } + gamedata.NanoTemplates[fixture.program] = &clone + t.Cleanup(func() { gamedata.NanoTemplates[fixture.program] = original }) + + if nanoCrystalProgram(fixture.crystal) != 0 { + t.Fatal("incomplete pet contract remained uploadable") + } + }) + } + } +} diff --git a/server/pets.go b/server/pets.go @@ -21,20 +21,34 @@ func (pet *ownedPet) expired(now time.Time) bool { return !pet.expiresAt.IsZero() && !now.Before(pet.expiresAt) } -func petCombatProfile(program uint32) *gamedata.NPCCombatProfile { +func petCombatProfile(program uint32, level uint16) *gamedata.NPCCombatProfile { if program == 43325 { // Provisional PT01 resources and ratings, with the original Engineer fist. return &gamedata.NPCCombatProfile{Health: 40, Weapon: [2]uint32{120652, 120653}, AggDef: 75, Skills: map[uint32]int32{100: 5, 153: 5, 154: 5, 155: 5, 168: 5}} } // Explicit single-fist PT50 alpha policy; original binding is unresolved. - return &gamedata.NPCCombatProfile{Health: 17, Weapon: [2]uint32{120637, 120638}, AggDef: 75, - Skills: map[uint32]int32{100: 5, 153: 5, 154: 5, 155: 5, 168: 5}} + return &gamedata.NPCCombatProfile{Health: 17 * uint32(level), Weapon: [2]uint32{120637, 120638}, AggDef: 75, + Skills: map[uint32]int32{100: 5 * int32(level), 153: 5 * int32(level), 154: 5 * int32(level), 155: 5 * int32(level), 168: 5 * int32(level)}} } func petSummonNano(program uint32) bool { + var level, lifetime int32 + var tail string + switch program { + case 43324: + level, lifetime, tail = 1, 600, "0000000002000000000000000000000000000000a186010001000000830000008200000000000000070000000700000000000000" + case 43725: + level, lifetime, tail = 2, 600, "0000000002000000000000000000000000000000a186010001000000830000008200000000000000120000001200000000000000" + case 43719: + level, lifetime, tail = 6, 700, "0000000002000000000000000000000000000000a186010001000000830000008200000000000000280000002800000000000000" + case 43745: + level, lifetime, tail = 8, 700, "0000000002000000000000000000000000000000a186010001000000830000008200000000000000330000003300000000000000" + default: + return false + } definition := gamedata.NanoTemplates[program] - if program != 43324 || definition == nil || definition.RecordType != 1040005 || definition.Undecoded != nil || len(definition.Sections) != 4 { + if definition == nil || definition.RecordType != 1040005 || definition.Undecoded != nil || len(definition.Sections) != 4 { return false } section := definition.Sections[2] @@ -48,9 +62,9 @@ func petSummonNano(program uint32) bool { } // The complete admitted PT50 contract includes its still-unnamed numeric fields. return spawn.Arguments[0].Code != nil && *spawn.Arguments[0].Code == "PT50" && - spawn.Arguments[1].Integer != nil && *spawn.Arguments[1].Integer == 1 && - spawn.Arguments[2].Integer != nil && *spawn.Arguments[2].Integer == 600 && - spawn.Arguments[3].BytesHex != nil && *spawn.Arguments[3].BytesHex == "0000000002000000000000000000000000000000a186010001000000830000008200000000000000070000000700000000000000" + spawn.Arguments[1].Integer != nil && *spawn.Arguments[1].Integer == level && + spawn.Arguments[2].Integer != nil && *spawn.Arguments[2].Integer == lifetime && + spawn.Arguments[3].BytesHex != nil && *spawn.Arguments[3].BytesHex == tail } func petIdentityPacket(code, owner, pet uint32) []byte { @@ -94,8 +108,15 @@ func (server *server) createPet_locked(caster *character, program uint32, now ti if program == 43325 { pet.name, pet.monsterData, pet.npcDefinitionID = "Feeble Automaton", 17649, "pet/PT01" pet.pet.program, pet.pet.expiresAt = program, time.Time{} + } else { + spawn := (*gamedata.NanoTemplates[program].Sections[2].Functions)[0] + pet.level = uint16(*spawn.Arguments[1].Integer) + pet.pet.program, pet.pet.expiresAt = program, now.Add(time.Duration(*spawn.Arguments[2].Integer)*time.Second) + if program != 43324 { + pet.name = gamedata.NanoTemplates[program].Name + } } - pet.combatProfile = petCombatProfile(program) + pet.combatProfile = petCombatProfile(program, pet.level) pet.health, pet.nano = pet.maximumHealth(), pet.maximumNano() store, err := server.itemStore_locked(caster, caster.inventory) if err != nil { @@ -135,7 +156,7 @@ func (server *server) loadPets() error { } entity, owner := server.characters[id], server.characters[pet.owner] entity.pet = pet - entity.combatProfile = petCombatProfile(pet.program) + entity.combatProfile = petCombatProfile(pet.program, entity.level) server.petExpiry = append(server.petExpiry, entity) if owner.pets == nil { owner.pets = make(map[uint32]*character) diff --git a/server/shop_availability_test.go b/server/shop_availability_test.go @@ -68,7 +68,7 @@ func TestEarlyShopCatalogAvailabilityFeedback(t *testing.T) { } }) } - if visited != 190 || empty != 123 { + if visited != 190 || empty != 120 { t.Fatalf("finite terminal inventory changed: visited %d, empty %d", visited, empty) } } diff --git a/tools/client/test_basic_shop_nanos.mjs b/tools/client/test_basic_shop_nanos.mjs @@ -36,7 +36,7 @@ try { }; await open(false); await game.save(output + '/catalog'); - await click(cell(111, 0)); + await click(cell(111, initial.row)); await waitServer('crystal in purchase basket', state => state.purchases === 1); await click(cell(104, 48)); await game.wait('sale loot picked', state => state.dragged[0] === 104); @@ -52,7 +52,7 @@ try { // Cancel and reopen the same terminal before consuming the exact purchase. await open(true); - await click(cell(111, 0)); + await click(cell(111, initial.row)); await waitServer('cancel basket selected', state => state.purchases === 1); await game.click(945, 475); await waitServer('cancel completed', state => !state.open); @@ -100,6 +100,17 @@ try { await game.wait('native health agrees with server result', state => state.actors.find(actor => actor.type === 50000 && actor.id === initial.target)?.stats[27] === cast.health); } + if (initial.petLevel) { + await game.wait('purchased pet appears', state => state.actors.some(actor => actor.id === cast.pet && actor.stats[54] === initial.petLevel)); + await game.key('Tab'); + await game.wait('native enemy selection', state => state.selected[0] === 50000 && state.selected[1] === initial.enemy); + await game.key('Enter'); + await page.keyboard.type('/pet attack'); + await game.key('Enter'); + await waitServer('purchased pet kills target with owner loot rights', state => state.enemyHealth === 0 && state.looter === 1); + assert.equal((await server()).experience, 0, 'level-ten owner receives no XP from this level-one fixture'); + evidence.petKill = await server(); + } await game.save(output + '/cast'); await page.reload(); await game.ready(); @@ -109,6 +120,12 @@ try { assert.equal(evidence.reconnected.appliedBonus, initial.bonus); if (nativeArmor !== null) assert.equal(game.local().effectiveArmor[initial.stat - 90], nativeArmor + initial.bonus); } + if (initial.petLevel) { + await game.wait('upgraded pet reappears after reconnect', state => state.actors.some(actor => actor.id === cast.pet && actor.stats[54] === initial.petLevel)); + assert.equal(evidence.reconnected.experience, 0); + assert.equal(evidence.reconnected.enemyHealth, 0); + assert.equal(evidence.reconnected.looter, 1); + } assert.equal(game.local().stats[61], cast.inventory.Credits); assert.deepEqual(game.errors, []); console.log('PASS:', initial.machine, 'crystal', initial.crystal, 'native buy/sell, cancel, learn/cast and reconnect');