commit b79414d8c8f1209dacb00ad90464ad0e7d8b26cc
parent e768452357b2f9aff18f91b46a99d0eb8a78af29
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 19:03:46 +0000
Admit reviewed Nomad armor qualities
Diffstat:
8 files changed, 655 insertions(+), 0 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -427,6 +427,12 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
gates, AC/value, native endpoints, pickup, wear/removal, sale and cold ownership.
Acquisition remains open; see
[Steel-Ribbed contracts](docs/steel-ribbed-armor.md).
+ Six audited Nomad pairs now admit QL1..200 through the shared path, fixing
+ qualified QL2 glove refusal. Public handlers cover strict Stamina/Strength
+ gates, selected AC/value, both sleeves, pickup, wear/remove, sale and cold
+ ownership. Two controlled WASM clients verify every piece, QL100/101 native
+ refusal/training and exact page/fresh-server recovery. Acquisition remains
+ open; see [Nomad contracts](docs/nomad-armor.md).
The reviewed Dull Katana pair now admits QL1..20 through the shared path,
fixing qualified QL2 wear rejection. Original descriptor audits and focused
public-handler checks cover all three strict skill gates, both anchors,
diff --git a/docs/nomad-armor.md b/docs/nomad-armor.md
@@ -0,0 +1,78 @@
+# Nomad armor qualities
+
+Six reviewed Nomad pairs admit QL1..200 through the shared equipment path.
+Previously qualified QL2 gloves stayed carried despite satisfying both strict
+ability gates. The fix adds explicit family data; requirements, AC, value,
+appearance and native endpoint delivery retain their shared consumers.
+
+## Original contracts
+
+All twelve complete resource1000020 payloads independently reparse from the
+original14.9.1 database to the maintained catalog, including hashes, file
+offsets, headers, text, functions, resources and requirements. The index SHA256
+is `46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`.
+Raw payloads, individual hashes, complete descriptors and comparisons are in
+`local/nomad-armor/original/`.
+
+| Piece | QL1 / QL200 templates | Native slot | QL2 base value |
+| --- | --- | --- | ---: |
+| Pants | 85507 / 85506 | 27 | 863 |
+| Helmet | 85554 / 85553 | 18 | 1036 |
+| Gloves | 85593 / 85592 | 24 | 345 |
+| Boots | 85633 / 85632 | 30 | 518 |
+| Body armor | 85681 / 85680 | 21 | 1382 |
+| Sleeves | 85737 / 85736 | 23 or 25 | 345 |
+
+Within each pair, only stats1/2/54/74, eight Modify53045 AC amounts and the
+two strict wear thresholds differ. Names change from Battered to Enhanced;
+the selected nearest endpoint supplies that text. Text lengths account for
+section-offset differences. All other section structures and function arguments
+match, including the appearance contracts; no opaque effects are discarded.
+Names identified candidates for inspection; full descriptors establish pairing.
+Later Desert Nomad variants are separate items.
+
+Stamina18 and Strength16 must be strictly greater than8/8 at QL1 and520/470
+at QL200. Shared rounding gives thresholds11/10 at QL2,57/52 at QL20,
+263/238 at QL100 and265/240 at QL101. The existing quadratic value rule gives
+QL100 gloves a base value79749; QL200 retains321206. Exact endpoint qualities
+send that endpoint twice. Intermediate qualities retain both reviewed IDs,
+regardless of the stored anchor.
+
+The local Fandom mirror yielded no Nomad title or "Nomad Armor" full-text
+match. A later [armor list](https://wiki.aodb.us/wiki/Armorsets) classifies
+ordinary Nomad under Strength/Stamina, separately from later Desert Nomad
+armor. It does not establish14.9.1 acquisition, minimum obtainable QL, stock
+membership or a drop distribution. Bounded web searches did not recover those
+rules. Production shops, missions and creature membership remain unchanged.
+
+## Focused verification
+
+The QL2 glove public-handler regression fails before admission with
+"qualified armor did not start wear". With the six family rows, public handlers
+cover both stored anchors at QL1/2/20/100/200, glove101/199 boundaries and both
+sleeve slots. Checks include each strict equality refusal, qualified wear,
+all eight ACs, selected value, native endpoints, removal and cold identity.
+A controlled generated QL100 glove follows normal kill/loot/pickup handlers,
+repeated pickup, cold replay and wear/remove. Sale checks cover cancellation,
+acceptance and duplicate acceptance. Catalog range tests reject extrapolation.
+
+`TestBrowserNomadArmorQualities` supplies ten controlled items and cap-valid
+abilities before two native clients connect. Real input removes/re-wears all
+seven worn pieces, explicitly keeps sleeves in different arms, wears QL100
+gloves stored at the high endpoint and rejects QL101 at equality. Native
+training raises Strength240 ->241 and Stamina265 ->266 for1010 IP; that same
+QL101 glove then wears. QL200 remains rejected and owned. These fixtures verify
+contracts and ownership, not earned progression or historical acquisition.
+
+The native armor machine quotes4784 for the QL100 glove at the fixture's
+Computer Literacy6. Canceling retains it; acceptance leaves4884 credits and
+nine other identities. Final AC totals are156/156/138/41/41/138/41/138.
+Page replay and two fresh clients after the warm server closes must retain
+the exact IDs, endpoints, slots, qualities, trained abilities and wallet.
+
+The accepted run is `local/nomad-armor/20261103-110158/`:41.26s warm and19.67s
+cold,65.03s native/72.594s including Go. Reviewed captures show the original
+armor and separate sleeve slots. Independent checks match all twelve original
+hashes, the refusal baseline, exact page/cold inventory and13 complete clean
+traces. The report is `local/nomad-armor/verification.json`. All73 focused Go
+and185 catalog results, both native script syntax checks and vet pass.
diff --git a/server/browser_nomad_test.go b/server/browser_nomad_test.go
@@ -0,0 +1,139 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "reflect"
+ "runtime"
+ "testing"
+ "time"
+)
+
+func TestBrowserNomadArmorQualities(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for the focused native Nomad check")
+ }
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/nomad-armor", time.Now().Format("20060102-150405"))
+ t.Chdir(t.TempDir())
+ world := newServerForTest(t)
+ owner := world.newCharacter()
+ owner.name, owner.level, owner.appearance = "Nomadowner", 100, 0x515
+ owner.playfield, owner.position = 1183, [3]float32{188, 5.11, 139.5}
+ owner.rotation = [4]float32{0, 0.70710677, 0, 0.70710677}
+ owner.stats.Abilities.Stamina, owner.stats.Abilities.Strength = 265, 240
+ owner.stats.ImprovementPoints, owner.inventory.Credits = 2000, 100
+ owner.health, owner.nano = owner.maximumHealth(), owner.maximumNano()
+ owner.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("nomad-owner")))
+ watcher := world.newCharacter()
+ watcher.name, watcher.playfield, watcher.position = "Nomadwatch", 1183, [3]float32{186, 5.11, 134.5}
+ watcher.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("nomad-watch")))
+ for _, player := range []*character{owner, watcher} {
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ }
+ // Controlled contracts isolate selected qualities without earning levels or gear.
+ for _, item := range []struct{ template, quality, slot uint32 }{
+ {85554, 2, 18}, {85507, 2, 27}, {85633, 2, 30},
+ {85737, 2, 23}, {85737, 2, 25}, {85593, 2, 24}, {85681, 2, 21},
+ {85592, 100, 64}, {85593, 101, 65}, {85593, 200, 66},
+ } {
+ 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[len(owner.inventory.Items)-1].Slot = item.slot
+ }
+ if err := world.saveInventory_locked(owner, owner.inventory); err != nil {
+ t.Fatal(err)
+ }
+
+ // Each phase drains browser sessions before its database closes.
+ t.Run("warm", func(t *testing.T) {
+ registerTestDatabaseCleanup(t, world)
+ 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()
+ armor := [8]int32{}
+ for index := range armor {
+ armor[index] = owner.equipmentBonus(90 + uint32(index))
+ }
+ json.NewEncoder(w).Encode(map[string]any{"inventory": owner.inventory, "stats": owner.stats,
+ "armor": armor, "observer": watcher.inventory, "pending": world.clients[owner.id].equipment != nil})
+ })
+ host := httptest.NewServer(mux)
+ t.Cleanup(host.Close)
+ closeTestBrowserStreams(t, world)
+ ctx, cancel := context.WithTimeout(context.Background(), 4*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)
+ case <-ctx.Done():
+ return
+ }
+ }
+ }()
+ defer func() { cancel(); <-stopped }()
+
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_nomad_armor.mjs"), host.URL, output)
+ 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)
+ }
+ if len(owner.inventory.Items) != 9 || owner.inventory.Credits != 4884 || owner.stats.ImprovementPoints != 990 ||
+ owner.stats.Abilities.Stamina != 266 || owner.stats.Abilities.Strength != 241 || len(watcher.inventory.Items) != 0 {
+ t.Fatal("native armor contract lost ownership, selected-quality price or trained abilities")
+ }
+ })
+ if t.Failed() {
+ return
+ }
+ t.Run("cold", func(t *testing.T) {
+ cold := newServerForTest(t)
+ for _, player := range []*character{owner, watcher} {
+ // Loaded inventory views share the world's last allocated item identity.
+ expected := player.inventory
+ expected.LastID = 10
+ if !reflect.DeepEqual(expected, cold.characters[player.id].inventory) || player.stats != cold.characters[player.id].stats {
+ t.Fatal("completed armor contract changed on cold loading", player.id)
+ }
+ }
+ for index, armor := range [8]int32{156, 156, 138, 41, 41, 138, 41, 138} {
+ if cold.characters[owner.id].equipmentBonus(90+uint32(index)) != armor {
+ t.Fatal("cold armor or independent sleeves changed", index)
+ }
+ }
+ host := httptest.NewServer(cold.httpHandler())
+ t.Cleanup(host.Close)
+ closeTestBrowserStreams(t, cold)
+ ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
+ defer cancel()
+
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_nomad_cold.mjs"), host.URL, filepath.Join(output, "cold"))
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ if err := command.Run(); err != nil {
+ t.Fatal(err)
+ }
+ })
+}
diff --git a/server/gamedata/item_families.yaml b/server/gamedata/item_families.yaml
@@ -96,3 +96,10 @@
- [85620, 22158]
- [85668, 22080]
- [85724, 21971]
+# Nomad armor: complete original descriptor audit; docs/nomad-armor.md.
+- [85507, 85506]
+- [85554, 85553]
+- [85593, 85592]
+- [85633, 85632]
+- [85681, 85680]
+- [85737, 85736]
diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go
@@ -37,6 +37,8 @@ func TestReviewedItemFamilyQualityRanges(t *testing.T) {
{25812, 25811, 1, 200}, {85366, 85367, 1, 200}, {25820, 25821, 1, 200},
{85494, 22347, 1, 200}, {85541, 22262, 1, 200}, {85580, 22212, 1, 200},
{85620, 22158, 1, 200}, {85668, 22080, 1, 200}, {85724, 21971, 1, 200},
+ {85507, 85506, 1, 200}, {85554, 85553, 1, 200}, {85593, 85592, 1, 200},
+ {85633, 85632, 1, 200}, {85681, 85680, 1, 200}, {85737, 85736, 1, 200},
} {
for _, template := range [2]uint32{family.lowTemplate, family.highTemplate} {
t.Run(fmt.Sprint(template), func(t *testing.T) {
diff --git a/server/nomad_armor_test.go b/server/nomad_armor_test.go
@@ -0,0 +1,217 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "slices"
+ "testing"
+)
+
+func TestNomadGeneratedPickupKeepsSelectedQuality(t *testing.T) {
+ world, output := newKillExperienceWorld(t, "unarmed")
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Abilities.Stamina, player.stats.Abilities.Strength = 264, 239
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ // Controlled membership tests delivery, not historical Nomad creature drops.
+ profile := *world.characters[1000000].combatProfile
+ profile.Loot = []gamedata.NPCLoot{{Template: 85592, Quality: [2]uint32{100, 100}, Chance: 100}}
+ world.characters[1000000].combatProfile = &profile
+ world.combatRoll = func(uint32) uint32 { return 0 }
+ identity := world.nextItem + 1
+ var wire []byte
+ for _, value := range []uint32{identity, 85593, 85592, 100, 0} {
+ wire = binary.BigEndian.AppendUint32(wire, value)
+ }
+
+ attackForExperience(t, world, "unarmed")
+ if err := world.handleLootUse(client, lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ shown := slices.ContainsFunc(output.packets, func(packet []byte) bool { return bytes.Contains(packet, wire) })
+ for range 2 {
+ if err := world.handleInventory(client, lootTakeRequest()); err != nil {
+ t.Fatal(err)
+ }
+ }
+ world = newTestInventoryServer(t)
+ client = &worldClient{id: 1, conn: output, target: true, ready: true}
+ world.clients[1] = client
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 24)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("picked-up gloves did not start wear", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ worn := newTestInventoryServer(t)
+ if err := world.handleInventory(client, itemMovePacket(1, 24, 64)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("picked-up gloves did not start removal", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ removed := newTestInventoryServer(t)
+
+ expected := ownedItem{ID: identity, Type: 51022, Template: 85592, Quality: 100, Slot: 24, Count: 1}
+ if !shown || !slices.Equal(worn.characters[1].inventory.Items, []ownedItem{expected}) || worn.characters[1].equipmentBonus(91) != 125 {
+ t.Fatal("generated pickup lost its native endpoints, identity, selected quality or worn AC")
+ }
+ expected.Slot = 64
+ if !slices.Equal(removed.characters[1].inventory.Items, []ownedItem{expected}) || removed.characters[1].equipmentBonus(91) != 0 ||
+ len(removed.characters[1000000].corpse.items) != 0 || removed.nextItem != identity {
+ t.Fatal("duplicate pickup, removal or cold recovery lost or duplicated the gloves")
+ }
+}
+
+func TestNomadArmorQualitiesWearRemoveAndRecover(t *testing.T) {
+ for _, scenario := range []struct {
+ low, high, slot, quality, value uint32
+ stamina, strength uint16
+ armor [8]int32
+ }{
+ {85507, 85506, 27, 1, 843, 8, 8, [8]int32{3, 3, 3, 1, 1, 3, 1, 3}},
+ {85507, 85506, 27, 2, 863, 11, 10, [8]int32{6, 6, 6, 2, 2, 6, 2, 6}},
+ {85507, 85506, 27, 20, 8155, 57, 52, [8]int32{62, 62, 55, 16, 16, 55, 16, 55}},
+ {85507, 85506, 27, 100, 199375, 263, 238, [8]int32{312, 312, 273, 78, 78, 273, 78, 273}},
+ {85507, 85506, 27, 200, 803015, 520, 470, [8]int32{625, 625, 546, 156, 156, 546, 156, 546}},
+ {85554, 85553, 18, 1, 1012, 8, 8, [8]int32{3, 3, 3, 1, 1, 3, 1, 3}},
+ {85554, 85553, 18, 2, 1036, 11, 10, [8]int32{7, 7, 6, 2, 2, 6, 2, 6}},
+ {85554, 85553, 18, 20, 9787, 57, 52, [8]int32{74, 74, 65, 19, 19, 65, 19, 65}},
+ {85554, 85553, 18, 100, 239251, 263, 238, [8]int32{375, 375, 328, 94, 94, 328, 94, 328}},
+ {85554, 85553, 18, 200, 963619, 520, 470, [8]int32{750, 750, 656, 187, 187, 656, 187, 656}},
+ {85593, 85592, 24, 1, 337, 8, 8, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {85593, 85592, 24, 2, 345, 11, 10, [8]int32{2, 2, 2, 1, 1, 2, 1, 2}},
+ {85593, 85592, 24, 20, 3262, 57, 52, [8]int32{25, 25, 22, 7, 7, 22, 7, 22}},
+ {85593, 85592, 24, 100, 79749, 263, 238, [8]int32{125, 125, 109, 31, 31, 109, 31, 109}},
+ {85593, 85592, 24, 101, 81362, 265, 240, [8]int32{126, 126, 110, 32, 32, 110, 32, 110}},
+ {85593, 85592, 24, 199, 317990, 517, 468, [8]int32{249, 249, 217, 62, 62, 217, 62, 217}},
+ {85593, 85592, 24, 200, 321206, 520, 470, [8]int32{250, 250, 218, 62, 62, 218, 62, 218}},
+ {85633, 85632, 30, 1, 506, 8, 8, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {85633, 85632, 30, 2, 518, 11, 10, [8]int32{3, 3, 3, 1, 1, 3, 1, 3}},
+ {85633, 85632, 30, 20, 4893, 57, 52, [8]int32{37, 37, 32, 10, 10, 32, 10, 32}},
+ {85633, 85632, 30, 100, 119625, 263, 238, [8]int32{187, 187, 164, 47, 47, 164, 47, 164}},
+ {85633, 85632, 30, 200, 481809, 520, 470, [8]int32{375, 375, 328, 93, 93, 328, 93, 328}},
+ {85681, 85680, 21, 1, 1350, 8, 8, [8]int32{5, 5, 5, 1, 1, 5, 1, 5}},
+ {85681, 85680, 21, 2, 1382, 11, 10, [8]int32{10, 10, 9, 2, 2, 9, 2, 9}},
+ {85681, 85680, 21, 20, 13050, 57, 52, [8]int32{100, 100, 88, 25, 25, 88, 25, 88}},
+ {85681, 85680, 21, 100, 319002, 263, 238, [8]int32{500, 500, 438, 125, 125, 438, 125, 438}},
+ {85681, 85680, 21, 200, 1284825, 520, 470, [8]int32{1000, 1000, 875, 250, 250, 875, 250, 875}},
+ {85737, 85736, 25, 1, 337, 8, 8, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {85737, 85736, 25, 2, 345, 11, 10, [8]int32{2, 2, 2, 1, 1, 2, 1, 2}},
+ {85737, 85736, 23, 2, 345, 11, 10, [8]int32{2, 2, 2, 1, 1, 2, 1, 2}},
+ {85737, 85736, 25, 20, 3262, 57, 52, [8]int32{25, 25, 22, 7, 7, 22, 7, 22}},
+ {85737, 85736, 25, 100, 79749, 263, 238, [8]int32{125, 125, 109, 31, 31, 109, 31, 109}},
+ {85737, 85736, 25, 200, 321206, 520, 470, [8]int32{250, 250, 218, 62, 62, 218, 62, 218}},
+ } {
+ for _, anchor := range []uint32{scenario.low, scenario.high} {
+ t.Run(fmt.Sprintf("%d/QL%d/slot%d", anchor, scenario.quality, scenario.slot), func(t *testing.T) {
+ world, output := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Abilities.Stamina, player.stats.Abilities.Strength = scenario.stamina+1, scenario.strength+1
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if granted, err := world.grantItem_locked(player, anchor); err != nil || !granted {
+ t.Fatal("grant armor", granted, err)
+ }
+ player.inventory.Items[1].Quality = scenario.quality
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ weapon := player.inventory.Items[0]
+
+ for _, ability := range []*uint16{&player.stats.Abilities.Stamina, &player.stats.Abilities.Strength} {
+ *ability -= 1
+ if err := world.handleInventory(client, inventoryMovePacket(1, 65, scenario.slot)[20:]); err != nil || client.equipment != nil || player.inventory.Items[1].Slot != 65 {
+ t.Fatal("threshold equality equipped or lost the armor", err)
+ }
+ *ability += 1
+ }
+ output.packets = nil
+ if err := world.handleInventory(client, inventoryMovePacket(1, 65, scenario.slot)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("qualified armor did not start wear", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ worn := newTestInventoryServer(t)
+ low, high := scenario.low, scenario.high
+ if scenario.quality == 1 {
+ high = low
+ } else if scenario.quality == 200 {
+ low = high
+ }
+ var action []byte
+ for _, word := range []uint32{low, high, scenario.quality, 1, 6, 102, scenario.slot, 0, 0} {
+ action = binary.BigEndian.AppendUint32(action, word)
+ }
+ if len(output.packets) != 2 || !bytes.Equal(output.packets[1][29:65], action) {
+ t.Fatal("native wear lost the selected quality or endpoint pair")
+ }
+ if err := world.handleInventory(client, itemMovePacket(1, scenario.slot, 111)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("armor did not start removal", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ removed := newTestInventoryServer(t)
+
+ expected := ownedItem{ID: 2, Type: 51022, Template: anchor, Quality: scenario.quality, Slot: scenario.slot, Count: 1}
+ if !slices.Equal(worn.characters[1].inventory.Items, []ownedItem{weapon, expected}) || worn.characters[1].inventory.Items[1].shopPrice() != scenario.value {
+ t.Fatal("cold armor identity, quality, value or unrelated item changed")
+ }
+ expected.Slot = 65
+ if !slices.Equal(removed.characters[1].inventory.Items, []ownedItem{weapon, expected}) || removed.nextItem != 2 {
+ t.Fatal("removal lost or replaced an instance")
+ }
+ for index, bonus := range scenario.armor {
+ if worn.characters[1].equipmentBonus(90+uint32(index)) != bonus || removed.characters[1].equipmentBonus(90+uint32(index)) != 0 {
+ t.Fatal("selected armor effects or their removal changed", index)
+ }
+ }
+ })
+ }
+ }
+}
+
+func TestNomadSaleCancellationAndReplayKeepSelectedQuality(t *testing.T) {
+ for _, scenario := range []struct{ quality, sale uint32 }{
+ {2, 17}, {100, 3987}, {101, 4068}, {200, 16060},
+ } {
+ t.Run(fmt.Sprint(scenario.quality), func(t *testing.T) {
+ world, _ := newShopWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ if granted, err := world.grantItem_locked(player, 85593); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ player.inventory.Items[1].Quality = scenario.quality
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ before := append([]ownedItem(nil), player.inventory.Items...)
+ offer := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{50000, 1}, [2]uint32{104, 65})[20:]
+
+ if err := world.handleTrade(client, offer); 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)
+ }
+ cancelled := newTestInventoryServer(t).characters[1].inventory
+ if err := world.handleShopUse(client, shopUseRequest(2)); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleTrade(client, offer); 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)
+ }
+ }
+ sold := newTestInventoryServer(t).characters[1].inventory
+
+ if !slices.Equal(cancelled.Items, before) || cancelled.Credits != 100 {
+ t.Fatal("cancelled sale changed the selected instance or wallet", cancelled)
+ }
+ if !slices.Equal(sold.Items, before[:1]) || sold.Credits != 100+scenario.sale {
+ t.Fatal("accepted or repeated sale changed another item or its selected-quality price", sold)
+ }
+ })
+ }
+}
diff --git a/tools/client/test_nomad_armor.mjs b/tools/client/test_nomad_armor.mjs
@@ -0,0 +1,160 @@
+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 = [];
+async function bagClick(game, id) {
+ await game.wait('inventory actions finish', 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, 'right');
+}
+try {
+ for (const token of ['nomad-owner', 'nomad-watch']) {
+ const context = await browser.newContext({viewport: {width: 1024, height: 768}});
+ await context.addCookies([{name: 'ao_client', value: token, 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 state = async () => (await owner.page.request.get(url + '/test-state')).json();
+ const baseline = await state();
+ assert.equal(baseline.inventory.Items.length, 10);
+ assert.deepEqual(baseline.armor, [32, 32, 30, 10, 10, 30, 10, 30]);
+ await owner.key('KeyI');
+ await owner.page.keyboard.press('Control+1');
+ await owner.click(953, 53);
+ await owner.page.keyboard.press('Control+9');
+ await owner.save(output + '/initial');
+
+ // Every piece uses native removal and wear, with explicit left-arm placement.
+ for (const [id, slot, x, y, armor] of [
+ [1, 18, 927, 94, [7, 7, 6, 2, 2, 6, 2, 6]],
+ [2, 27, 927, 262, [6, 6, 6, 2, 2, 6, 2, 6]],
+ [3, 30, 927, 316, [3, 3, 3, 1, 1, 3, 1, 3]],
+ [4, 23, 867, 206, [2, 2, 2, 1, 1, 2, 1, 2]],
+ [5, 25, 987, 206, [2, 2, 2, 1, 1, 2, 1, 2]],
+ [6, 24, 927, 206, [2, 2, 2, 1, 1, 2, 1, 2]],
+ [7, 21, 927, 148, [10, 10, 9, 2, 2, 9, 2, 9]],
+ ]) {
+ const sequence = observer.sequence;
+ await owner.click(x, y, 'right');
+ await owner.wait('exact piece removed', state => owner.local(state).inventory.some(item => item.id === id && item.slot >= 48));
+ assert.deepEqual((await state()).armor, baseline.armor.map((value, index) => value - armor[index]));
+ if (slot === 23) {
+ await owner.wait('arm action finishes', state => !owner.local(state).actions.includes(3));
+ const cell = owner.local().inventory.find(item => item.id === id).slot - 48;
+ await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54);
+ await owner.click(x, y);
+ } else await bagClick(owner, id);
+ await owner.wait('exact piece worn', state => owner.local(state).inventory.some(item => item.id === id && item.slot === slot));
+ await observer.wait('observer receives wear', () => observer.events.some(event => {
+ if (event.sequence <= sequence || event.direction !== 'framereceived' || event.opcode !== '35505644' || event.actor[1] !== 1) return false;
+ const packet = Buffer.from(event.hex, 'hex');
+ return packet.readUInt32BE(45) === 6 && packet.readUInt32BE(53) === slot;
+ }));
+ assert.deepEqual((await state()).armor, baseline.armor);
+ }
+ await owner.save(output + '/all-pieces');
+ await observer.save(output + '/observer-all-pieces');
+
+ // The high stored endpoint must still deliver the selected QL100 contract.
+ await owner.click(927, 206, 'right');
+ await owner.wait('QL2 gloves retained', state => owner.local(state).inventory.some(item => item.id === 6 && item.slot >= 48));
+ await bagClick(owner, 8);
+ await owner.wait('QL100 gloves worn', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot === 24));
+ assert.deepEqual((await state()).armor, [155, 155, 137, 40, 40, 137, 40, 137]);
+ await owner.save(output + '/quality-100');
+ await owner.click(927, 206, 'right');
+ await owner.wait('QL100 gloves retained', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot >= 48));
+ const before = await state(), sequence = owner.sequence;
+ await bagClick(owner, 9);
+ await owner.save(output + '/quality-101-rejected');
+ assert(!owner.events.some(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24'));
+ assert.deepEqual((await state()).inventory, before.inventory);
+ assert.equal((await state()).pending, false);
+
+ // Train one Strength and Stamina point through the original ability form.
+ await owner.page.keyboard.press('Control+1');
+ await owner.page.keyboard.press('Control+9');
+ await owner.key('KeyU');
+ await owner.click(334, 256);
+ await owner.click(835, 166);
+ await owner.click(835, 226);
+ await owner.click(445, 622);
+ await owner.wait('trained strict thresholds', state => owner.local(state).stats[16] === 241 &&
+ owner.local(state).stats[18] === 266 && owner.local(state).stats[53] === 990);
+ await bagClick(owner, 9);
+ await owner.wait('QL101 gloves worn', state => owner.local(state).inventory.some(item => item.id === 9 && item.slot === 24));
+ assert.deepEqual((await state()).armor, [156, 156, 138, 41, 41, 138, 41, 138]);
+ const high = await state(), highSequence = owner.sequence;
+ await bagClick(owner, 10);
+ await owner.save(output + '/quality-200-rejected');
+ assert(!owner.events.some(event => event.sequence > highSequence && event.direction === 'framesent' && event.opcode === '47537a24'));
+ assert.deepEqual((await state()).inventory, high.inventory);
+
+ // Cancel, then accept one selected-quality sale at the original armor machine.
+ if (!owner.state.camera.firstPerson) await owner.key('F8');
+ let offered = await state();
+ for (let attempt = 0; attempt < 2; ++attempt) {
+ const [x, y] = await owner.pick(51035, 3221226655);
+ await owner.click(x, y, 'right');
+ await owner.wait('armor machine open', state => state.regions.some(([left, top, right, bottom]) =>
+ left === 832 && top === 0 && right === 1024 && bottom === 494));
+ const cell = owner.local().inventory.find(item => item.id === 8).slot - 48;
+ await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54);
+ const sequence = owner.sequence;
+ await owner.click(864, 416);
+ await owner.wait('sale offered', () => owner.events.some(event => event.sequence > sequence &&
+ event.direction === 'framesent' && event.opcode === '36284f6e'));
+ assert.deepEqual((await state()).inventory, offered.inventory);
+ await owner.save(output + '/sale-offer-' + attempt);
+ if (attempt === 0) {
+ await owner.click(945, 475);
+ await owner.wait('cancelled glove restored', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot === 48));
+ assert.deepEqual((await state()).inventory, offered.inventory);
+ offered = await state();
+ }
+ }
+ await owner.click(874, 475);
+ await owner.wait('exact selected-quality sale', state => owner.local(state).stats[61] === 4884);
+ const final = await state();
+ const slots = {1: 18, 2: 27, 3: 30, 4: 23, 5: 25, 6: 67, 7: 21, 9: 24, 10: 66};
+ const expected = baseline.inventory.Items.filter(item => item.ID !== 8).map(item => ({...item, Slot: slots[item.ID]}));
+ assert.deepEqual(final.inventory.Items, expected);
+ assert.deepEqual(final.observer, baseline.observer);
+ await fs.writeFile(output + '/ledger.json', JSON.stringify(final, null, 2));
+ await owner.page.reload();
+ await owner.ready();
+ await owner.page.waitForFunction(() => touchRegion(500, 400)?.world === true);
+ await owner.snapshot();
+ const pairs = {85554: [85554, 85553], 85507: [85507, 85506], 85633: [85633, 85632],
+ 85737: [85737, 85736], 85593: [85593, 85592], 85681: [85681, 85680]};
+ for (const item of expected) {
+ const pair = pairs[item.Template];
+ assert.deepEqual(owner.local().inventory.find(actual => actual.id === item.ID), {
+ slot: item.Slot >= 64 ? item.Slot - 16 : item.Slot, type: item.Type, id: item.ID,
+ quality: item.Quality, templates: item.Quality === 200 ? [pair[1], pair[1]] : pair, count: 1});
+ }
+ await owner.key('KeyI');
+ await owner.page.keyboard.press('Control+1');
+ await owner.click(953, 53);
+ await owner.page.keyboard.press('Control+9');
+ await owner.save(output + '/reconnected');
+ assert(games.every(game => game.errors.length === 0));
+ console.log('PASS: Nomad pieces, both sleeves, QL100/101 native gates/training, exact sale and page recovery');
+} finally {
+ try { await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); }
+ finally { await browser.close(); }
+}
diff --git a/tools/client/test_nomad_cold.mjs b/tools/client/test_nomad_cold.mjs
@@ -0,0 +1,46 @@
+import assert from 'node:assert/strict';
+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 = [];
+try {
+ for (const token of ['nomad-owner', 'nomad-watch']) {
+ const context = await browser.newContext({viewport: {width: 1024, height: 768}});
+ await context.addCookies([{name: 'ao_client', value: token, 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;
+ 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, 18, 2, 85554, 85553, 1], [2, 27, 2, 85507, 85506, 1],
+ [3, 30, 2, 85633, 85632, 1], [4, 23, 2, 85737, 85736, 1],
+ [5, 25, 2, 85737, 85736, 1], [6, 51, 2, 85593, 85592, 1],
+ [7, 21, 2, 85681, 85680, 1], [9, 24, 101, 85593, 85592, 1],
+ [10, 50, 200, 85592, 85592, 1],
+ ]);
+ assert.equal(owner.local().stats[16], 241);
+ assert.equal(owner.local().stats[18], 266);
+ assert.equal(owner.local().stats[53], 990);
+ assert.equal(owner.local().stats[61], 4884);
+ assert.deepEqual(observer.local().inventory, []);
+ await owner.page.waitForFunction(() => touchRegion(500, 400)?.world === true);
+ await owner.snapshot();
+ await owner.key('KeyI');
+ await owner.page.keyboard.press('Control+1');
+ await owner.click(953, 53);
+ await owner.page.keyboard.press('Control+9');
+ assert(games.every(game => game.errors.length === 0));
+ console.log('PASS: all nine exact Nomad identities, endpoints, slots, training and sale wallet after cold startup');
+} finally {
+ try { await Promise.all(games.map((game, index) => game.save(output + '/' + index))); }
+ finally { await browser.close(); }
+}