commit 909926847fbe0b1261dd1f24c8795440a1a66db0
parent 4f256e0146f6dc6113a33d6c972223827f9b8c1f
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 00:23:59 +0000
Support Original Electronicum intermediate qualities
Diffstat:
7 files changed, 697 insertions(+), 1 deletion(-)
diff --git a/TODO.md b/TODO.md
@@ -388,6 +388,15 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
wear, QL12 refusal, ordinary melee, exact cancelled/accepted sale and page/cold
ownership. Historical acquisition remains open; see
[Katana contracts](docs/katana.md).
+ The reviewed Original Electronicum pair now admits QL1..98 through shared
+ quality and modifier consumers, fixing qualified QL2 rejection. Focused
+ public-handler checks cover Pistol gates, selected damage/timing/value,
+ energy ammunition, exactly-once NanoC. Initiative/Nano Programming/NCU bonuses,
+ pickup, wear/removal, sale and cold ownership. Two WASM clients verify
+ QL2/49/50 wear, QL51 refusal, visible NCU10, an energy reload/shot and page/cold
+ retention of the five exact identities and their ammunition. Historical
+ acquisition and later tiers remain open; see
+ [Electronicum contracts](docs/electronicum.md).
- [x] Admit the complete Low-Tech armor set through shared quality and shop data.
Eight explicit original pairs cover QL1..200, including alternate body and leg
styles and independent sleeves. All three basic armor factions offer the
diff --git a/docs/electronicum.md b/docs/electronicum.md
@@ -0,0 +1,90 @@
+# Original Electronicum selected qualities
+
+The reviewed pair 160288/160289 admits The Original Electronicum QL1..98 through
+the existing item-quality, weapon, requirements, modifier, price and native
+delivery paths. Qualified QL2 wear previously failed at the public inventory
+handler. The production change is one explicit family row; later v2 intervals
+remain unreviewed and exact-QL only.
+
+## Original records
+
+Both complete 14.9.1 resources independently reparse to the maintained catalog,
+including payload hashes and original offsets. They share type51018/version8
+headers, stat membership, complete sections, attack/defense weights, presentation
+and wear predicate structure. Only numeric quality, damage, critical bonus,
+value, Multi Ranged and the strict Pistol threshold vary. This supports the
+explicit interval, not an original server family table or acquisition policy.
+
+| QL | Damage | Critical bonus | Minimum Pistol | Value | Multi Ranged |
+| --- | --- | --- | --- | --- | --- |
+| 1 | 1-33 | 26 | 5 | 2058 | 12 |
+| 2 | 1-35 | 28 | 9 | 2068 | 18 |
+| 49 | 1-120 | 103 | 220 | 26008 | 309 |
+| 50 | 1-121 | 104 | 224 | 27017 | 316 |
+| 97 | 1-206 | 179 | 435 | 97861 | 607 |
+| 98 | 1-208 | 181 | 439 | 99867 | 613 |
+
+All retain 141cs attack, 229cs recharge, 400cs equip, eighteen-metre range,
+Energy damage, Pistol attack, Dodge Ranged defense, Ranged Initiative and a
+twenty-round Energy Weapon Ammo magazine. Identical event14 functions53045
+add +3 NanoC. Initiative (149), +2 Nano Programming (160) and +2 NCU (181).
+Raw skills and modifiers remain separate. The presentation functions are
+identical; no new gameplay function is introduced.
+
+Original payload SHA-256:
+
+- 160288: `2e5eee851571cc6cb4430f008af6376d504de8a70d15eed2760970ccdaca6b94`.
+- 160289: `1e1d18c1f7eaa27263430209e54128fb9bf4db2c2756d299d720c52ff7bb72d3`.
+
+The complete audit, original bytes, index digest and independent integer
+expectations are retained under `local/electronicum-quality/original/`.
+The [current AO Galaxy record](https://www.aogalaxy.com/_items/item.php?aoid=160289)
+also lists QL1..98, the twenty-round energy magazine, delays and three modifiers.
+Its value and Multi Ranged differ from the original payload, and it lists an
+attack-cap field absent there. Those contemporary values do not replace the
+shipped data. The local Fandom
+`Engineer Guide` describes Jobe stock and later boss loot, without establishing
+the pre-Shadowlands 14.9.1 contract. Shop, mission and creature membership are
+unchanged and remain open.
+
+## Focused verification
+
+Public inventory handlers cover both stored anchors at all six qualities,
+strict Pistol equality refusal, the four-second equip deadline, immutable
+catalog data, selected stats/value, owner/observer packets and cold ownership.
+Removal/rewear checks all three modifiers and NCU capacity 8/10 without sticking
+or duplication. Controlled generated QL2/50 drops follow exact identities
+through pickup, repeated requests, rejected wear, wear/removal, cancelled and
+accepted/repeated sale and cold recovery. Fixture wallets become104/1351 credits,
+including the one pre-existing corpse credit; this does not establish drops.
+Normal/critical attacks at all six QLs check damage, cadence, energy rounds,
+229cs reload and both retained inventories after cold loading.
+
+`TestBrowserElectronicumQualities` uses two controlled WASM clients. Abilities120
+contribute29 Pistol trickle; raw195 produces effective224 inside its native
+training cap. The level200 checkpoint and stationary10000HP target isolate
+delivery without earned progression or encounter-balance claims. Native input
+wears/removes QL2/49, wears QL50 and refuses QL51's Pistol229 requirement.
+Observer weapon packets must retain selected properties and the nearer endpoint.
+The original ammo-on-weapon request loads20 energy rounds; one ordinary shot
+deals188 Energy damage and leaves19 loaded/80 carried rounds. Page and fresh
+server recovery must retain all five exact identities, qualities, slots,
+ammunition and the exactly-once modifiers, without observer ownership leaks.
+
+The native check passes in 92.57s (warm 72.17, cold 20.39), or 100.207s including
+Go. The reviewed worn screenshot shows NCU 0/10 and attack rating 224; the shot
+capture shows the 188-point hit, Pistol 229 refusal and 80 carried energy rounds.
+Cold loading retains the rendered pistol. An independent verifier checks both
+original payload hashes, selected wear phases, the single actual attack result,
+ammunition and exact page/cold ledgers. All ten retained traces have empty
+error lists and zero dropped events. Captures and evidence are under
+`local/electronicum-quality/20261102-161819/`. Earlier fixture skill snapshots
+exceeded native ability-bound training caps and failed before starting browsers;
+the final snapshot stays within the recovered cap without changing gameplay.
+
+The related normal Go selection passes eight top-level tests and 213 individual
+results: server 20.014s, gamedata 7.709s, with one opt-in browser check skipped.
+It covers the new contract, existing Vektor qualities, pending-wear rejection,
+OE and shared family boundaries. The native test above executes the skipped
+scenario separately. Vet, Node syntax, gofmt and whitespace checks pass.
+All three new Go roots also pass under the race detector: 31 results in 100.081s.
diff --git a/server/browser_electronicum_test.go b/server/browser_electronicum_test.go
@@ -0,0 +1,141 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "reflect"
+ "runtime"
+ "testing"
+ "time"
+)
+
+func TestBrowserElectronicumQualities(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for the focused native Electronicum check")
+ }
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/electronicum-quality", time.Now().Format("20060102-150405"))
+ t.Chdir(t.TempDir())
+ for _, phase := range []string{"warm", "cold"} {
+ t.Run(phase, func(t *testing.T) {
+ world := newServer()
+ t.Cleanup(func() { world.db.Close() })
+ var target *character
+ for _, actor := range world.characters {
+ if actor.npc && actor.playfield == 950 && actor.monsterData == 17655 && actor.level == 1 && actor.combatProfile != nil && (target == nil || actor.id < target.id) {
+ target = actor
+ }
+ }
+ if target == nil {
+ t.Fatal("no Leet for the controlled shot")
+ }
+ if phase == "warm" {
+ for index := 0; index < 2; index++ {
+ player := world.newCharacter()
+ player.name = fmt.Sprint("Electronicum", index)
+ player.position = target.position
+ player.position[0] -= float32(index * 3)
+ player.position[2] -= 2
+ player.rotation = [4]float32{0, 0, 0, 1}
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint("electronicum-", index))))
+ if index == 0 {
+ player.level, player.profession, player.appearance, player.aggDef = 200, 6, 0x515, 75
+ player.stats.Abilities = characterAbilitiesStats{120, 120, 120, 120, 120, 120}
+ player.stats.Ranged.Pistol = 195
+ if maximum := player.trainingMaximum(112); maximum < 195 {
+ t.Fatal("controlled Pistol exceeds native training cap", maximum)
+ }
+ if pistol, _ := player.effectiveStat(112); pistol != 224 {
+ t.Fatal("controlled effective Pistol differs", pistol)
+ }
+ }
+ player.health, player.nano = player.maximumHealth(), player.maximumNano()
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ }
+ // Controlled contracts and target HP isolate delivery, not earned progression.
+ owner := world.characters[1]
+ for _, item := range []struct{ template, quality uint32 }{
+ {160288, 2}, {160289, 49}, {160289, 50}, {160288, 51}, {21609, 1},
+ } {
+ if granted, err := world.grantItem_locked(owner, item.template); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ owner.inventory.Items[len(owner.inventory.Items)-1].Quality = item.quality
+ }
+ owner.inventory.Items[4].Count = 100
+ if err := world.saveInventory_locked(owner, owner.inventory); err != nil {
+ t.Fatal(err)
+ }
+ profile := *target.combatProfile
+ profile.Health = 10000
+ target.combatProfile, target.health = &profile, 10000
+ world.combatRoll = landedCombatRoll
+ }
+ owner, watcher := world.characters[1], world.characters[2]
+ mux := http.NewServeMux()
+ mux.Handle("/", world.httpHandler())
+ mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) {
+ world.mutex.Lock()
+ defer world.mutex.Unlock()
+ json.NewEncoder(w).Encode(map[string]any{"inventory": owner.inventory, "observer": watcher.inventory,
+ "target": target.id, "health": target.health, "fighting": owner.fighting, "nanoInitiative": owner.equipmentBonus(149), "programming": owner.equipmentBonus(160), "ncu": owner.maximumNCU()})
+ })
+ host := httptest.NewServer(mux)
+ t.Cleanup(host.Close)
+ closeTestBrowserStreams(t, world)
+ ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
+ defer cancel()
+ stopped := make(chan struct{})
+ go func() {
+ defer close(stopped)
+ ticker := time.NewTicker(20 * time.Millisecond)
+ defer ticker.Stop()
+ for {
+ select {
+ case now := <-ticker.C:
+ world.advanceEquipment(now)
+ world.advanceCombat(now)
+ case <-ctx.Done():
+ return
+ }
+ }
+ }()
+ defer func() { cancel(); <-stopped }()
+
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_electronicum.mjs"), host.URL, filepath.Join(output, phase))
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ err := command.Run()
+ t.Logf("Browser artifacts: %s", output)
+
+ if err != nil {
+ t.Fatal(err)
+ }
+ world.mutex.Lock()
+ defer world.mutex.Unlock()
+ expected := []ownedItem{
+ {ID: 1, Type: 51018, Template: 160288, Quality: 2, Slot: 64, Count: 1},
+ {ID: 2, Type: 51018, Template: 160289, Quality: 49, Slot: 65, Count: 1},
+ {ID: 3, Type: 51018, Template: 160289, Quality: 50, Slot: 6, Count: 1, Ammo: 19},
+ {ID: 4, Type: 51018, Template: 160288, Quality: 51, Slot: 67, Count: 1},
+ {ID: 5, Type: 51005, Template: 21609, Quality: 1, Slot: 68, Count: 80},
+ }
+ if !reflect.DeepEqual(owner.inventory.Items, expected) || owner.inventory.Credits != 0 ||
+ len(watcher.inventory.Items) != 0 || watcher.inventory.Credits != 0 || world.nextItem != 5 {
+ t.Fatal("native wear, shot or cold recovery lost an instance, round or cash")
+ }
+ })
+ if t.Failed() {
+ return
+ }
+ }
+}
diff --git a/server/electronicum_quality_test.go b/server/electronicum_quality_test.go
@@ -0,0 +1,319 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "bytes"
+ "encoding/binary"
+ "encoding/json"
+ "fmt"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestElectronicumQualitiesWearRemoveAndRecover(t *testing.T) {
+ for _, scenario := range []struct {
+ low, high, quality uint32
+ threshold uint16
+ maximum, critical, value, multi uint32
+ }{
+ {160288, 160289, 1, 4, 33, 26, 2058, 12},
+ {160288, 160289, 2, 8, 35, 28, 2068, 18},
+ {160288, 160289, 49, 219, 120, 103, 26008, 309},
+ {160288, 160289, 50, 223, 121, 104, 27017, 316},
+ {160288, 160289, 97, 434, 206, 179, 97861, 607},
+ {160288, 160289, 98, 438, 208, 181, 99867, 613},
+ } {
+ for _, anchor := range slices.Compact([]uint32{scenario.low, scenario.high}) {
+ t.Run(fmt.Sprintf("%d/QL%d", anchor, scenario.quality), func(t *testing.T) {
+ world, output := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: 950, health: 100}
+ world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true}
+ player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ player.stats.Ranged.Pistol = scenario.threshold
+ player.aggDef = 75
+ player.stats.Speed.RangedInitiative = 0
+ player.inventory.Items[0].Template, player.inventory.Items[0].Quality = anchor, scenario.quality
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ catalog, err := json.Marshal([]*gamedata.Item{gamedata.ItemTemplates[scenario.low], gamedata.ItemTemplates[scenario.high]})
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment != nil {
+ t.Fatal("Pistol threshold equality equipped", err)
+ }
+ if after, err := readTestItemStore(world); err != nil || !bytes.Equal(before, after) {
+ t.Fatal("rejected wear changed ownership", err)
+ }
+ player.stats.Ranged.Pistol++
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ output.packets = nil
+ started := time.Now()
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("qualified selected-quality weapon did not start wear", err)
+ }
+ finish := client.equipment.readyAt
+ world.advanceEquipment(finish.Add(-time.Nanosecond))
+ if player.inventory.Items[0].Slot != 64 {
+ t.Fatal("weapon moved before its deadline")
+ }
+ world.advanceEquipment(finish)
+ worn := newTestInventoryServer(t).characters[1]
+ weapon := worn.attackWeapon()
+ var delivered, remoteDelivery []byte
+ for _, packet := range output.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x3b1d2268 {
+ delivered = packet
+ }
+ }
+ for _, packet := range observer.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x3b1d2268 {
+ remoteDelivery = packet
+ }
+ }
+
+ expected := ownedItem{ID: 1, Type: 51018, Template: anchor, Quality: scenario.quality, Slot: 6, Count: 1}
+ if finish.Before(started.Add(4*time.Second)) || finish.After(time.Now().Add(4*time.Second)) ||
+ !slices.Equal(worn.inventory.Items, []ownedItem{expected}) || weapon == nil || *weapon.Quality != scenario.quality ||
+ worn.equipmentBonus(149) != 3 || worn.equipmentBonus(160) != 2 || worn.maximumNCU() != 10 || len(delivered) < 91 || len(remoteDelivery) < 91 || !bytes.Equal(delivered[16:], remoteDelivery[16:]) {
+ t.Fatal("wear timing, identity, skill/NCU bonuses or observer delivery differs", worn.inventory.Items)
+ }
+ stats := make(map[uint32]uint32)
+ for offset := 59; offset < int(binary.BigEndian.Uint16(delivered[6:8]))-4; offset += 8 {
+ stats[binary.BigEndian.Uint32(delivered[offset:])] = binary.BigEndian.Uint32(delivered[offset+4:])
+ }
+ low, high := expected.templateIDs()
+ if stats[701] != scenario.quality || stats[702] != low || stats[703] != high {
+ t.Fatal("native selected quality or endpoints differ", stats)
+ }
+ for stat, value := range map[uint32]uint32{286: 1, 285: scenario.maximum, 284: scenario.critical,
+ 294: 141, 210: 229, 211: 400, 212: 20, 420: 1, 436: 92, 74: scenario.value, 134: scenario.multi, 30: 5} {
+ remote, overridden := stats[stat]
+ if !overridden {
+ remote = itemStat(gamedata.ItemTemplates[stats[23]], stat)
+ }
+ if itemStat(weapon, stat) != value || remote != value {
+ t.Fatalf("selected or remote stat%d differs: local%d remote%d want%d", stat, itemStat(weapon, stat), remote, value)
+ }
+ }
+ attack, recharge := player.attackDelays()
+ expectedAttack, expectedRecharge := 1410*time.Millisecond, 2290*time.Millisecond
+ if attack != expectedAttack || recharge != expectedRecharge {
+ t.Fatal("selected attack/recharge differs", attack, recharge)
+ }
+
+ // Remove and re-wear the same instance; effects must neither stick nor double.
+ for _, move := range [][2]uint32{{6, 64}, {64, 6}, {6, 64}} {
+ request := inventoryMovePacket(1, move[0], move[1])
+ if move[0] == 6 {
+ request = itemMovePacket(1, 6, 64)
+ }
+ if err := world.handleInventory(client, request[20:]); err != nil || client.equipment == nil {
+ t.Fatal("retained weapon did not start moving", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ expected.Slot = move[1]
+ cold := newTestInventoryServer(t).characters[1]
+ initiative, programming, capacity := int32(0), int32(0), uint32(8)
+ if move[1] == 6 {
+ initiative, programming, capacity = 3, 2, 10
+ }
+ if !slices.Equal(cold.inventory.Items, []ownedItem{expected}) || cold.equipmentBonus(160) != programming || cold.maximumNCU() != capacity ||
+ cold.equipmentBonus(149) != initiative || cold.inventory.Items[0].shopPrice() != scenario.value {
+ t.Fatal("cold ownership, price or repeated skill/NCU bonuses differs")
+ }
+ }
+ afterCatalog, err := json.Marshal([]*gamedata.Item{gamedata.ItemTemplates[scenario.low], gamedata.ItemTemplates[scenario.high]})
+ if err != nil || !bytes.Equal(catalog, afterCatalog) {
+ t.Fatal("interpolation modified the shared catalog", err)
+ }
+ })
+ }
+ }
+}
+
+func TestElectronicumGeneratedPickupEquipRemoveAndSale(t *testing.T) {
+ for _, scenario := range []struct {
+ template, quality uint32
+ pistol uint16
+ credits uint32
+ }{
+ {160288, 2, 9, 104}, {160289, 2, 9, 104},
+ {160288, 50, 224, 1351}, {160289, 50, 224, 1351},
+ } {
+ t.Run(fmt.Sprintf("%d/QL%d", scenario.template, scenario.quality), func(t *testing.T) {
+ world, _ := newKillExperienceWorld(t, "unarmed")
+ // Controlled membership tests delivery, not historical Leet equipment drops.
+ profile := *world.characters[1000000].combatProfile
+ profile.Loot = []gamedata.NPCLoot{{Template: scenario.template, Quality: [2]uint32{scenario.quality, scenario.quality}, Chance: 100}}
+ world.characters[1000000].combatProfile = &profile
+ world.combatRoll = func(uint32) uint32 { return 0 }
+ identity := world.nextItem + 1
+
+ attackForExperience(t, world, "unarmed")
+ if err := world.handleLootUse(world.clients[1], lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ for range 2 {
+ if err := world.handleInventory(world.clients[1], lootTakeRequest()); err != nil {
+ t.Fatal(err)
+ }
+ }
+ world = newTestInventoryServer(t)
+ player := world.characters[1]
+ client := &worldClient{id: 1, conn: &combatTestConn{}, target: true, ready: true}
+ world.clients[1] = client
+ player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ player.stats.Ranged.Pistol = scenario.pistol - 1
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment != nil ||
+ len(player.inventory.Items) != 1 || player.inventory.Items[0].ID != identity || player.inventory.Items[0].Slot != 64 {
+ t.Fatal("rejected wear lost the picked-up instance", err)
+ }
+ player.stats.Ranged.Pistol++
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for _, move := range [][2]uint32{{64, 6}, {6, 64}, {64, 6}, {6, 64}} {
+ request := inventoryMovePacket(1, move[0], move[1])
+ if move[0] < 64 {
+ request = itemMovePacket(1, move[0], move[1])
+ }
+ if err := world.handleInventory(client, request[20:]); err != nil || client.equipment == nil {
+ t.Fatal("generated selected-quality weapon did not move", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ cold := newTestInventoryServer(t)
+ expected := []ownedItem{{ID: identity, Type: 51018, Template: scenario.template, Quality: scenario.quality, Slot: move[1], Count: 1}}
+ if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) ||
+ len(cold.characters[1000000].corpse.items) != 0 || cold.characters[1].inventory.Credits != 1 || cold.nextItem != identity {
+ t.Fatal("pickup, repeated wear or cold recovery lost or duplicated the weapon")
+ }
+ }
+
+ // Sell that same instance after cancellation and a cold reconnect.
+ player.appearance = 0x515
+ player.position = [3]float32{60, 14.75, 53}
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.savePosition_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleShopUse(client, shopUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ add := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{50000, 1}, [2]uint32{104, 64})[20:]
+ if err := world.handleTrade(client, add); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 2, [2]uint32{}, [2]uint32{})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+ if len(cold.characters[1].inventory.Items) != 1 || cold.characters[1].inventory.Credits != 1 {
+ t.Fatal("cancelled sale lost the selected-quality weapon")
+ }
+ world, player = cold, cold.characters[1]
+ client = &worldClient{id: 1, conn: &combatTestConn{}, target: true, ready: true}
+ world.clients[1] = client
+ if err := world.handleShopUse(client, shopUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleTrade(client, add); err != nil {
+ t.Fatal(err)
+ }
+ for range 2 {
+ if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ }
+ cold = newTestInventoryServer(t)
+
+ for _, current := range []*server{world, cold} {
+ if len(current.characters[1].inventory.Items) != 0 || current.characters[1].inventory.Credits != scenario.credits ||
+ current.characters[1].experience != 100 || current.nextItem != identity {
+ t.Fatal("selected-quality sale lost or repeated value, rewards or an instance", current.characters[1].inventory)
+ }
+ if _, exists := current.items[identity]; exists {
+ t.Fatal("sold weapon returned in the shared cache")
+ }
+ }
+ })
+ }
+}
+
+func TestElectronicumSelectedDamageEnergyAmmunitionAndReloadRecover(t *testing.T) {
+ for _, row := range []struct{ quality, normal, critical uint32 }{
+ {1, 66, 118}, {2, 70, 126}, {49, 240, 446}, {50, 242, 450}, {97, 412, 770}, {98, 416, 778},
+ } {
+ for _, critical := range []bool{false, true} {
+ t.Run(fmt.Sprintf("QL%d/critical%v", row.quality, critical), func(t *testing.T) {
+ world, output := newRangedWorld(t)
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ target.position = [3]float32{10, 0, 0}
+ player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ player.stats.Ranged.Pistol = 400
+ player.stats.Speed.RangedInitiative, player.aggDef = 0, 75
+ player.inventory.Items[0].Template, player.inventory.Items[0].Quality = 160288, row.quality
+ player.inventory.Items[1].Template = 21609
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ world.combatRoll = func(limit uint32) uint32 {
+ if limit == 10000 || limit == 100 && critical {
+ return 0
+ }
+ return limit - 1
+ }
+
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ hit := player.nextAttack
+ world.advanceCombat(hit)
+ if player.rechargeUntil.Sub(hit) != 2290*time.Millisecond || player.nextAttack.Sub(hit) != 3700*time.Millisecond {
+ t.Fatal("selected Electronicum attack/recharge cadence differs")
+ }
+ shot := newTestInventoryServer(t).characters[1]
+ started := time.Now()
+ if err := world.handleReload(client, explicitReloadRequest(1, 64, 1)); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t).characters[1]
+
+ damage := row.normal
+ if critical {
+ damage = row.critical
+ }
+ found := false
+ for _, packet := range output.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x46002f16 && binary.BigEndian.Uint32(packet[24:28]) == 1 {
+ found = binary.BigEndian.Uint32(packet[29:33]) == damage && binary.BigEndian.Uint32(packet[33:37]) == 2
+ }
+ }
+ if !found || target.health != 1000-damage || shot.inventory.Items[0].Ammo != 2 || shot.inventory.Items[1].Count != 100 ||
+ cold.inventory.Items[0].Ammo != 20 || cold.inventory.Items[1].Count != 82 || cold.inventory.Items[0].Quality != row.quality ||
+ client.reloadUntil.Before(started.Add(2290*time.Millisecond)) || client.reloadUntil.After(time.Now().Add(2290*time.Millisecond)) {
+ t.Fatal("selected damage, energy rounds, reload timing or cold ownership differs", target.health, cold.inventory)
+ }
+ })
+ }
+ }
+}
diff --git a/server/gamedata/item_families.yaml b/server/gamedata/item_families.yaml
@@ -16,6 +16,8 @@
- [123744, 123745]
- [123746, 123747]
- [123748, 123749]
+# Original Electronicum: original descriptor audit; docs/electronicum.md.
+- [160288, 160289]
# Vektor ND shotguns: original descriptor audits; docs/vektor-shotguns.md.
- [124256, 124257]
- [124258, 124259]
diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go
@@ -16,6 +16,7 @@ func TestReviewedItemFamilyQualityRanges(t *testing.T) {
{123744, 123745, 12, 21}, {123746, 123747, 22, 37},
{123748, 123749, 38, 119},
{121969, 121970, 1, 20},
+ {160288, 160289, 1, 98},
{124256, 124257, 1, 4}, {124258, 124259, 5, 69}, {124260, 124261, 70, 179},
{70558, 85640, 1, 200}, {70559, 85689, 1, 200}, {70560, 85688, 1, 200}, {70561, 85744, 1, 200},
{70562, 85597, 1, 200}, {70563, 85558, 1, 200}, {70564, 85515, 1, 200}, {70565, 85514, 1, 200},
@@ -55,7 +56,8 @@ func TestUnreviewedItemQualityRemainsExact(t *testing.T) {
supported bool
}{{209283, 1, true}, {209283, 2, false}, {85557, 0, false}, {161966, 200, true}, {161966, 199, false},
{160417, 1, true}, {160417, 2, false},
- {124262, 180, true}, {124262, 179, false}, {124262, 181, false}, {121971, 22, false}, {4294967295, 1, false}} {
+ {124262, 180, true}, {124262, 179, false}, {124262, 181, false}, {121971, 22, false},
+ {160290, 99, true}, {160290, 100, false}, {4294967295, 1, false}} {
t.Run(fmt.Sprintf("%d/%d", entry.template, entry.quality), func(t *testing.T) {
got := gamedata.ItemQualitySupported(entry.template, entry.quality)
diff --git a/tools/client/test_electronicum.mjs b/tools/client/test_electronicum.mjs
@@ -0,0 +1,133 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs/promises';
+import {createRequire} from 'node:module';
+import {GameTest} from './game_test.mjs';
+
+const {chromium} = createRequire(import.meta.url)('playwright');
+const [url, output] = process.argv.slice(2);
+const browser = await chromium.launch({executablePath: '/usr/bin/chromium', headless: false,
+ args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
+ '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
+const games = [], evidence = {};
+async function bagClick(game, id, button = 'right') {
+ await game.wait('native equipment action finishes', state =>
+ !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
+ const item = game.local().inventory.find(item => item.id === id);
+ assert(item && item.slot >= 48 && item.slot < 57);
+ const cell = item.slot - 48;
+ await game.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54, button);
+}
+try {
+ for (const index of [0, 1]) {
+ const context = await browser.newContext({viewport: {width: 1024, height: 768}});
+ await context.addCookies([{name: 'ao_client', value: 'electronicum-' + index, url}]);
+ const page = await context.newPage();
+ const game = await GameTest.attach(page);
+ games.push(game);
+ await page.goto(url);
+ await game.ready();
+ }
+ const [owner, observer] = games;
+ const server = async () => (await owner.page.request.get(url + '/test-state')).json();
+ evidence.initial = await server();
+ if (evidence.initial.inventory.Items[2].Ammo === 0) {
+ assert.equal(owner.local().stats[112], 195);
+ await owner.key('KeyI');
+ await owner.page.keyboard.press('Control+1');
+ for (const id of [1, 2, 3]) {
+ const sequence = observer.sequence;
+ await bagClick(owner, id);
+ await owner.wait('selected Electronicum worn', state => owner.local(state).inventory.some(item => item.id === id && item.slot === 6));
+ await observer.wait('observer receives selected Electronicum', () => observer.events.some(event =>
+ event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '3b1d2268' &&
+ event.actor[0] === 51018 && event.actor[1] === id));
+ const packet = Buffer.from(observer.events.find(event => event.sequence > sequence &&
+ event.direction === 'framereceived' && event.opcode === '3b1d2268' && event.actor[0] === 51018 && event.actor[1] === id).hex, 'hex');
+ const stats = new Map();
+ for (let offset = 59; offset < packet.readUInt16BE(6) - 4; offset += 8)
+ stats.set(packet.readUInt32BE(offset), packet.readUInt32BE(offset + 4));
+ const [quality, definition, minimum, maximum, critical, delay, value, multi] = {
+ 1: [2, 160288, 1, 35, 28, 141, 2068, 18],
+ 2: [49, 160288, 1, 120, 103, 141, 26008, 309],
+ 3: [50, 160289, 1, 121, 104, 141, 27017, 316],
+ }[id];
+ assert.equal(stats.get(23), definition);
+ const base = {
+ 160288: {74: 2058, 134: 12, 284: 26, 285: 33, 286: 1, 294: 141, 210: 229, 212: 20},
+ 160289: {74: 99867, 134: 613, 284: 181, 285: 208, 286: 1, 294: 141, 210: 229, 212: 20},
+ }[definition];
+ for (const [stat, expected] of Object.entries({74: value, 134: multi, 284: critical, 285: maximum,
+ 286: minimum, 294: delay, 210: 229, 212: 20, 26: 0, 701: quality, 702: 160288, 703: 160289}))
+ assert.equal(stats.get(Number(stat)) ?? base[stat], expected, 'selected native weapon stat ' + stat);
+ assert.equal((await server()).nanoInitiative, 3);
+ assert.equal((await server()).programming, 2);
+ assert.equal((await server()).ncu, 10);
+ evidence['worn' + id] = {native: owner.local().inventory, server: await server()};
+ await owner.page.keyboard.press('Control+9');
+ await owner.save(output + '/worn-' + id);
+ await owner.page.keyboard.press('Control+9');
+ if (id !== 3) {
+ await owner.click(867, 206, 'right');
+ await owner.wait('same Electronicum removed', state => owner.local(state).inventory.some(item => item.id === id && item.slot >= 48));
+ assert.equal((await server()).nanoInitiative, 0);
+ assert.equal((await server()).programming, 0);
+ assert.equal((await server()).ncu, 8);
+ }
+ }
+ const rejected = await server();
+ const sequence = owner.sequence;
+ await bagClick(owner, 4);
+ await owner.save(output + '/rejected-51');
+ assert(!owner.events.some(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24'));
+ assert.deepEqual((await server()).inventory, rejected.inventory);
+
+ // The actual native ammunition-on-weapon request loads twenty energy rounds.
+ await bagClick(owner, 5, 'left');
+ await owner.click(867, 206, 'right');
+ await owner.wait('energy stack debited', state => owner.local(state).inventory.some(item => item.id === 5 && item.count === 80));
+ assert.equal((await server()).inventory.Items[2].Ammo, 20);
+ await owner.wait('native reload completes', state => !owner.local(state).actions.includes(5));
+ const before = await server();
+ const deadline = Date.now() + 10000;
+ while (owner.state.selected[0] !== 50000 || owner.state.selected[1] !== before.target) {
+ assert(Date.now() < deadline, 'Native Tab did not select the controlled Leet');
+ const selected = owner.state.selected;
+ await owner.key('Tab');
+ await owner.wait('native target cycle advances', state => state.selected[0] !== selected[0] || state.selected[1] !== selected[1]);
+ }
+ const attack = owner.sequence;
+ await owner.key('KeyQ');
+ await owner.wait('one real selected-quality shot', () => owner.events.some(event => event.sequence > attack &&
+ event.direction === 'framereceived' && event.opcode === '46002f16' && event.actor[1] === owner.local().id));
+ await owner.key('KeyQ');
+ await Promise.all(games.map(game => game.wait('native selected-quality impact', state =>
+ state.actors.some(actor => actor.id === before.target && actor.stats[27] === 9812))));
+ evidence.shot = await server();
+ assert.equal(evidence.shot.health, 9812);
+ assert.equal(evidence.shot.inventory.Items[2].Ammo, 19);
+ assert.equal(evidence.shot.fighting, 0);
+ await owner.save(output + '/shot');
+ await observer.save(output + '/observer-shot');
+ await owner.page.reload();
+ await owner.ready();
+ }
+ assert.deepEqual(owner.local().inventory.map(item => [item.id, item.slot, item.quality, ...item.templates, item.count]).sort((a, b) => a[0] - b[0]), [
+ [1, 48, 2, 160288, 160289, 1], [2, 49, 49, 160288, 160289, 1],
+ [3, 6, 50, 160288, 160289, 1], [4, 51, 51, 160288, 160289, 1],
+ [5, 52, 1, 21609, 21609, 80],
+ ]);
+ assert.equal((await server()).inventory.Items[2].Ammo, 19);
+ assert.deepEqual(observer.local().inventory, []);
+ assert.equal((await server()).ncu, 10);
+ assert.equal((await server()).nanoInitiative, 3);
+ assert.equal((await server()).programming, 2);
+ evidence.final = {native: owner.local().inventory, server: await server()};
+ assert(games.every(game => game.errors.length === 0));
+ console.log('PASS: native Electronicum selected qualities, wear/removal, Pistol gate and skill/NCU bonuses, energy reload, shot and page/cold ownership');
+} finally {
+ try {
+ await fs.mkdir(output, {recursive: true});
+ await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2));
+ await Promise.all(games.map((game, index) => game.save(output + '/final-' + index)));
+ } finally { await browser.close(); }
+}