commit e73d1afdad573662c8bf22962fab97fede5d91ee
parent b79414d8c8f1209dacb00ad90464ad0e7d8b26cc
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 19:16:45 +0000
Admit reviewed Graft and Organic armor qualities
Diffstat:
9 files changed, 954 insertions(+), 1 deletion(-)
diff --git a/TODO.md b/TODO.md
@@ -433,6 +433,13 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
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).
+ Twelve audited regular Graft/Organic pairs now admit QL1..200, fixing
+ qualified selected-quality refusal. Shared handlers verify each set's strict
+ Stamina/Strength gates, AC/value, sleeves, pickup, sale and cold ownership.
+ Short two-client fixtures render both sets and verify native glove wear,
+ QL100/101 training, exact sale and page/fresh-server recovery. These controlled
+ qualities do not establish historical acquisition or a minimum obtainable QL;
+ see [Graft/Organic contracts](docs/graft-organic-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,
@@ -1913,7 +1920,9 @@ introduction and starting-item gameplay remain open below.
the original training grounds. Funcom's
[14.7.10 notes](https://worthplaying.com/article/2003/2/26/news/8473-anarchy-online-update-patch-available-now/)
introduced this vendor while moving some stock out of the newbie terminal.
- Original shop template 209286 selects category 105 and requires level > 1.
+ Original shop template 209286 requires level > 1. Its stat427 value105 is a
+ buy-price percentage, not a recovered stock category; see
+ [original buy quotes](docs/shops.md#catalog-and-transaction-protocol).
Recover its placement, NPC interaction/dialogue and dated stock membership;
reuse current quote, inventory and atomic purchase/sale rules. Test native
opening, cancellation, ownership, range/lifecycle revalidation, insufficient
diff --git a/docs/graft-organic-armor.md b/docs/graft-organic-armor.md
@@ -0,0 +1,92 @@
+# Graft and Organic armor qualities
+
+Twelve reviewed original pairs admit QL1..200 through shared equipment,
+requirements, modifiers, pricing and native delivery. Before admission,
+qualified QL2 gloves from both sets stayed carried. The production change
+adds explicit family rows, with no armor-specific server branch.
+
+## Original contracts
+
+All24 complete resource1000020 payloads independently reparse from the shipped
+14.9.1 database to the maintained catalog, including hashes, file offsets,
+headers, text, functions, appearance resources and requirements. The index
+SHA256 is `46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`.
+Raw bytes, individual hashes, complete records and comparisons are under
+`local/graft-organic-armor/original/`.
+
+| Piece | Graft QL1 / QL200 | Organic QL1 / QL200 | Native slot |
+| --- | --- | --- | --- |
+| Pants | 120579 / 142679 | 120585 / 142680 | 27 |
+| Helmet | 120565 / 142681 | 120586 / 142682 | 18 |
+| Gloves | 120581 / 142683 | 120587 / 142684 | 24 |
+| Boots | 120582 / 142685 | 120588 / 142686 | 30 |
+| Body armor | 120583 / 142687 | 120589 / 142688 | 21 |
+| Sleeves | 120584 / 142689 | 120590 / 142690 | 23 or25 |
+
+Within each pair, only scalar stats1/2/54/74, eight Modify53045 AC amounts
+and the two strict wear thresholds vary. The remaining section structure,
+function arguments and appearance contracts match exactly. Names change from
+Inferior to Flawless, selected from the nearer endpoint; text length accounts
+for section-offset changes. No unsupported or opaque effect is discarded.
+Symbio-Grafts and Grafted Bau Charger armor are separate contracts.
+
+Both sets require Stamina18 and Strength16 strictly above the selected
+thresholds. Graft and Organic retain different thresholds and AC distributions:
+
+| QL | Graft Stamina / Strength thresholds | Organic Stamina / Strength thresholds |
+| --- | --- | --- |
+| 1 | 9 /9 | 9 /9 |
+| 2 | 12 /11 | 12 /11 |
+| 100 | 276 /251 | 271 /246 |
+| 101 | 278 /253 | 273 /248 |
+| 200 | 545 /495 | 535 /485 |
+
+Exact endpoint qualities send the same ID twice. Intermediate qualities
+retain the reviewed pair regardless of the stored anchor. The existing
+quadratic value rule, rather than an endpoint price, drives each selected QL.
+
+The local mirror's Graft and Organic pages were touched in December2007; its
+CAS recipe and armor overview are later still. They corroborate names and
+equipment categories without establishing14.9.1 drop or shop membership.
+The Graft page includes an explicitly tentative minimum-QL50 comment.
+The shipped QL1 endpoint establishes an interpolation contract, not that
+QL1..49 pieces were ordinarily obtainable. Bounded web searches did not
+recover a target-period acquisition rule. Production shops, missions and
+creature selections remain unchanged; controlled low-QL items verify the
+contract, not earned early-game acquisition. Source notes are retained in
+`local/graft-organic-armor/fandom.json` and the original audit.
+
+## Focused verification
+
+Both QL2 glove regressions fail before admission with "qualified armor did
+not start wear". Public inventory handlers cover every pair and both stored
+anchors at QL1/2/20/100/200, glove101/199 boundaries and independent sleeves.
+They verify each strict equality refusal, qualified wear, native endpoints,
+all eight ACs, selected value, removal and cold identity. Controlled generated
+QL100 gloves follow actual kill/loot/pickup handlers, repeated pickup,
+wear/remove and cold ownership. Sales cover cancellation, acceptance and
+duplicate acceptance. Catalog tests reject extrapolation.
+
+`TestBrowserGraftAndOrganicArmorQualities` runs each set in its own disposable
+database with two clients. The complete controlled QL2 set renders before
+native glove removal/wear, QL100 wear, QL101 equality refusal, ordinary ability
+training and QL101 wear. QL200 remains rejected and owned. The other pieces'
+wear boundaries have handler checks; native initial and cold snapshots retain
+all seven worn pieces and both sleeve slots. These are cap-valid controlled
+fixtures, not earned-progression evidence.
+
+Graft trains Strength253 ->254 and Stamina278 ->279 for1062 IP, retaining938.
+Its QL100 glove sells for6202 at the original armor machine, leaving6302
+credits. Organic trains Strength248 ->249 and Stamina273 ->274 for1042 IP,
+retaining958; its QL100 glove sells for5493, leaving5593 credits. Each sale is
+canceled first. Both phases must retain all nine other physical identities,
+the selected endpoints, exact slots, abilities and wallet through page replay
+and fresh server/two-client recovery.
+
+The accepted run is `local/graft-organic-armor/20261103-111234/`:Graft warm/cold
+33.61s/17.81s and Organic38.88s/27.19s,124.31s total/132.052s including Go.
+Reviewed captures show both original appearances. Independent checks match
+all24 original hashes, both refusal baselines,18 exact page/cold item records,
+distinct trained abilities/ACs/wallets and26 complete clean traces. The report
+is `local/graft-organic-armor/verification.json`. All146 focused Go and209
+catalog results, both native script syntax checks and vet pass.
diff --git a/server/browser_graft_organic_test.go b/server/browser_graft_organic_test.go
@@ -0,0 +1,158 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "reflect"
+ "runtime"
+ "testing"
+ "time"
+)
+
+func TestBrowserGraftAndOrganicArmorQualities(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for Graft and Organic native armor checks")
+ }
+ stamp := time.Now().Format("20060102-150405")
+ for _, family := range []struct {
+ name string
+ pairs [6][2]uint32
+ stamina, strength uint16
+ ip, wallet uint32
+ armor [8]int32
+ }{
+ {name: "graft", pairs: [6][2]uint32{{120579, 142679}, {120565, 142681}, {120581, 142683}, {120582, 142685}, {120583, 142687}, {120584, 142689}}, stamina: 278, strength: 253, ip: 938, wallet: 6302, armor: [8]int32{138, 156, 156, 120, 103, 35, 138, 138}},
+ {name: "organic", pairs: [6][2]uint32{{120585, 142680}, {120586, 142682}, {120587, 142684}, {120588, 142686}, {120589, 142688}, {120590, 142690}}, stamina: 273, strength: 248, ip: 958, wallet: 5593, armor: [8]int32{138, 156, 156, 120, 35, 35, 138, 138}},
+ } {
+ t.Run(family.name, func(t *testing.T) {
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/graft-organic-armor", stamp, family.name)
+ t.Chdir(t.TempDir())
+ world := newServerForTest(t)
+ owner := world.newCharacter()
+ owner.name, owner.level, owner.appearance = family.name+"owner", 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 = family.stamina, family.strength
+ owner.stats.ImprovementPoints, owner.inventory.Credits = 2000, 100
+ owner.health, owner.nano = owner.maximumHealth(), owner.maximumNano()
+ owner.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("armor-owner")))
+ watcher := world.newCharacter()
+ watcher.name, watcher.playfield, watcher.position = family.name+"watch", 1183, [3]float32{186, 5.11, 134.5}
+ watcher.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("armor-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 }{
+ {family.pairs[1][0], 2, 18}, {family.pairs[0][0], 2, 27}, {family.pairs[3][0], 2, 30},
+ {family.pairs[5][0], 2, 23}, {family.pairs[5][0], 2, 25}, {family.pairs[2][0], 2, 24}, {family.pairs[4][0], 2, 21},
+ {family.pairs[2][1], 100, 64}, {family.pairs[2][0], 101, 65}, {family.pairs[2][0], 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{"family": family.name, "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_graft_organic_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 != family.wallet || owner.stats.ImprovementPoints != family.ip ||
+ owner.stats.Abilities.Stamina != family.stamina+1 || owner.stats.Abilities.Strength != family.strength+1 || 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 family.armor {
+ if cold.characters[owner.id].equipmentBonus(90+uint32(index)) != armor {
+ t.Fatal("cold armor or independent sleeves changed", index)
+ }
+ }
+ mux := http.NewServeMux()
+ mux.Handle("/", cold.httpHandler())
+ mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) {
+ json.NewEncoder(w).Encode(map[string]string{"family": family.name})
+ })
+ host := httptest.NewServer(mux)
+ 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_graft_organic_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
@@ -103,3 +103,16 @@
- [85633, 85632]
- [85681, 85680]
- [85737, 85736]
+# Graft and Organic armor: original descriptor audits; docs/graft-organic-armor.md.
+- [120579, 142679]
+- [120565, 142681]
+- [120581, 142683]
+- [120582, 142685]
+- [120583, 142687]
+- [120584, 142689]
+- [120585, 142680]
+- [120586, 142682]
+- [120587, 142684]
+- [120588, 142686]
+- [120589, 142688]
+- [120590, 142690]
diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go
@@ -39,6 +39,10 @@ func TestReviewedItemFamilyQualityRanges(t *testing.T) {
{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},
+ {120579, 142679, 1, 200}, {120565, 142681, 1, 200}, {120581, 142683, 1, 200},
+ {120582, 142685, 1, 200}, {120583, 142687, 1, 200}, {120584, 142689, 1, 200},
+ {120585, 142680, 1, 200}, {120586, 142682, 1, 200}, {120587, 142684, 1, 200},
+ {120588, 142686, 1, 200}, {120589, 142688, 1, 200}, {120590, 142690, 1, 200},
} {
for _, template := range [2]uint32{family.lowTemplate, family.highTemplate} {
t.Run(fmt.Sprint(template), func(t *testing.T) {
diff --git a/server/graft_armor_test.go b/server/graft_armor_test.go
@@ -0,0 +1,217 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "slices"
+ "testing"
+)
+
+func TestGraftGeneratedPickupKeepsSelectedQuality(t *testing.T) {
+ world, output := newKillExperienceWorld(t, "unarmed")
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Abilities.Stamina, player.stats.Abilities.Strength = 277, 252
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ // Controlled membership tests delivery, not historical Graft creature drops.
+ profile := *world.characters[1000000].combatProfile
+ profile.Loot = []gamedata.NPCLoot{{Template: 142683, 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, 120581, 142683, 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: 142683, 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 TestGraftArmorQualitiesWearRemoveAndRecover(t *testing.T) {
+ for _, scenario := range []struct {
+ low, high, slot, quality, value uint32
+ stamina, strength uint16
+ armor [8]int32
+ }{
+ {120579, 142679, 27, 1, 1093, 9, 9, [8]int32{3, 3, 3, 3, 3, 1, 3, 3}},
+ {120579, 142679, 27, 2, 1119, 12, 11, [8]int32{6, 6, 6, 5, 5, 2, 6, 6}},
+ {120579, 142679, 27, 20, 10572, 60, 55, [8]int32{55, 62, 62, 47, 40, 13, 55, 55}},
+ {120579, 142679, 27, 100, 258450, 276, 251, [8]int32{273, 312, 312, 234, 196, 63, 273, 273}},
+ {120579, 142679, 27, 200, 1040946, 545, 495, [8]int32{546, 625, 625, 468, 390, 125, 546, 546}},
+ {120565, 142681, 18, 1, 1312, 9, 9, [8]int32{3, 3, 3, 3, 3, 1, 3, 3}},
+ {120565, 142681, 18, 2, 1343, 12, 11, [8]int32{6, 7, 7, 6, 5, 2, 6, 6}},
+ {120565, 142681, 18, 20, 12687, 60, 55, [8]int32{65, 74, 74, 56, 47, 15, 65, 65}},
+ {120565, 142681, 18, 100, 310140, 276, 251, [8]int32{328, 375, 375, 281, 234, 75, 328, 328}},
+ {120565, 142681, 18, 200, 1249135, 545, 495, [8]int32{656, 750, 750, 562, 468, 150, 656, 656}},
+ {120581, 142683, 24, 1, 437, 9, 9, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {120581, 142683, 24, 2, 447, 12, 11, [8]int32{2, 2, 2, 2, 2, 1, 2, 2}},
+ {120581, 142683, 24, 20, 4228, 60, 55, [8]int32{22, 25, 25, 19, 16, 6, 22, 22}},
+ {120581, 142683, 24, 100, 103379, 276, 251, [8]int32{109, 125, 125, 94, 78, 25, 109, 109}},
+ {120581, 142683, 24, 101, 105470, 278, 253, [8]int32{110, 126, 126, 94, 79, 26, 110, 110}},
+ {120581, 142683, 24, 199, 412208, 542, 493, [8]int32{217, 249, 249, 186, 155, 50, 217, 217}},
+ {120581, 142683, 24, 200, 416378, 545, 495, [8]int32{218, 250, 250, 187, 156, 50, 218, 218}},
+ {120582, 142685, 30, 1, 656, 9, 9, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {120582, 142685, 30, 2, 671, 12, 11, [8]int32{3, 3, 3, 2, 2, 1, 3, 3}},
+ {120582, 142685, 30, 20, 6343, 60, 55, [8]int32{32, 37, 37, 28, 23, 8, 32, 32}},
+ {120582, 142685, 30, 100, 155070, 276, 251, [8]int32{164, 187, 187, 140, 117, 38, 164, 164}},
+ {120582, 142685, 30, 200, 624567, 545, 495, [8]int32{328, 375, 375, 281, 234, 75, 328, 328}},
+ {120583, 142687, 21, 1, 1750, 9, 9, [8]int32{5, 5, 5, 5, 5, 1, 5, 5}},
+ {120583, 142687, 21, 2, 1792, 12, 11, [8]int32{9, 10, 10, 9, 8, 2, 9, 9}},
+ {120583, 142687, 21, 20, 16916, 60, 55, [8]int32{83, 100, 100, 76, 64, 20, 83, 83}},
+ {120583, 142687, 21, 100, 413521, 276, 251, [8]int32{413, 500, 500, 376, 313, 100, 413, 413}},
+ {120583, 142687, 21, 200, 1665514, 545, 495, [8]int32{825, 1000, 1000, 750, 625, 200, 825, 825}},
+ {120584, 142689, 25, 1, 437, 9, 9, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {120584, 142689, 25, 2, 447, 12, 11, [8]int32{2, 2, 2, 2, 2, 1, 2, 2}},
+ {120584, 142689, 23, 2, 447, 12, 11, [8]int32{2, 2, 2, 2, 2, 1, 2, 2}},
+ {120584, 142689, 25, 20, 4228, 60, 55, [8]int32{22, 25, 25, 19, 16, 6, 22, 22}},
+ {120584, 142689, 25, 100, 103379, 276, 251, [8]int32{109, 125, 125, 94, 78, 25, 109, 109}},
+ {120584, 142689, 25, 200, 416378, 545, 495, [8]int32{218, 250, 250, 187, 156, 50, 218, 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 TestGraftSaleCancellationAndReplayKeepSelectedQuality(t *testing.T) {
+ for _, scenario := range []struct{ quality, sale uint32 }{
+ {2, 22}, {100, 5168}, {101, 5273}, {200, 20818},
+ } {
+ 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, 120581); 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/server/organic_armor_test.go b/server/organic_armor_test.go
@@ -0,0 +1,217 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "slices"
+ "testing"
+)
+
+func TestOrganicGeneratedPickupKeepsSelectedQuality(t *testing.T) {
+ world, output := newKillExperienceWorld(t, "unarmed")
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Abilities.Stamina, player.stats.Abilities.Strength = 272, 247
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ // Controlled membership tests delivery, not historical Organic creature drops.
+ profile := *world.characters[1000000].combatProfile
+ profile.Loot = []gamedata.NPCLoot{{Template: 142684, 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, 120587, 142684, 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: 142684, 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 TestOrganicArmorQualitiesWearRemoveAndRecover(t *testing.T) {
+ for _, scenario := range []struct {
+ low, high, slot, quality, value uint32
+ stamina, strength uint16
+ armor [8]int32
+ }{
+ {120585, 142680, 27, 1, 968, 9, 9, [8]int32{3, 3, 3, 3, 1, 1, 3, 3}},
+ {120585, 142680, 27, 2, 991, 12, 11, [8]int32{6, 6, 6, 5, 2, 2, 6, 6}},
+ {120585, 142680, 27, 20, 9363, 59, 54, [8]int32{55, 62, 62, 47, 13, 13, 55, 55}},
+ {120585, 142680, 27, 100, 228912, 271, 246, [8]int32{273, 312, 312, 234, 63, 63, 273, 273}},
+ {120585, 142680, 27, 200, 921981, 535, 485, [8]int32{546, 625, 625, 468, 125, 125, 546, 546}},
+ {120586, 142682, 18, 1, 1162, 9, 9, [8]int32{3, 3, 3, 3, 1, 1, 3, 3}},
+ {120586, 142682, 18, 2, 1189, 12, 11, [8]int32{6, 7, 7, 6, 2, 2, 6, 6}},
+ {120586, 142682, 18, 20, 11237, 59, 54, [8]int32{65, 74, 74, 56, 15, 15, 65, 65}},
+ {120586, 142682, 18, 100, 274696, 271, 246, [8]int32{328, 375, 375, 281, 75, 75, 328, 328}},
+ {120586, 142682, 18, 200, 1106377, 535, 485, [8]int32{656, 750, 750, 562, 150, 150, 656, 656}},
+ {120587, 142684, 24, 1, 387, 9, 9, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {120587, 142684, 24, 2, 396, 12, 11, [8]int32{2, 2, 2, 2, 1, 1, 2, 2}},
+ {120587, 142684, 24, 20, 3745, 59, 54, [8]int32{22, 25, 25, 19, 6, 6, 22, 22}},
+ {120587, 142684, 24, 100, 91565, 271, 246, [8]int32{109, 125, 125, 94, 25, 25, 109, 109}},
+ {120587, 142684, 24, 101, 93416, 273, 248, [8]int32{110, 126, 126, 94, 26, 26, 110, 110}},
+ {120587, 142684, 24, 199, 365099, 532, 483, [8]int32{217, 249, 249, 186, 50, 50, 217, 217}},
+ {120587, 142684, 24, 200, 368792, 535, 485, [8]int32{218, 250, 250, 187, 50, 50, 218, 218}},
+ {120588, 142686, 30, 1, 581, 9, 9, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {120588, 142686, 30, 2, 594, 12, 11, [8]int32{3, 3, 3, 2, 1, 1, 3, 3}},
+ {120588, 142686, 30, 20, 5618, 59, 54, [8]int32{32, 37, 37, 28, 8, 8, 32, 32}},
+ {120588, 142686, 30, 100, 137347, 271, 246, [8]int32{164, 187, 187, 140, 38, 38, 164, 164}},
+ {120588, 142686, 30, 200, 553188, 535, 485, [8]int32{328, 375, 375, 281, 75, 75, 328, 328}},
+ {120589, 142688, 21, 1, 1550, 9, 9, [8]int32{5, 5, 5, 5, 1, 1, 5, 5}},
+ {120589, 142688, 21, 2, 1587, 12, 11, [8]int32{9, 10, 10, 9, 2, 2, 9, 9}},
+ {120589, 142688, 21, 20, 14983, 59, 54, [8]int32{88, 100, 100, 76, 20, 20, 88, 88}},
+ {120589, 142688, 21, 100, 366261, 271, 246, [8]int32{438, 500, 500, 376, 100, 100, 438, 438}},
+ {120589, 142688, 21, 200, 1475169, 535, 485, [8]int32{875, 1000, 1000, 750, 200, 200, 875, 875}},
+ {120590, 142690, 25, 1, 387, 9, 9, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {120590, 142690, 25, 2, 396, 12, 11, [8]int32{2, 2, 2, 2, 1, 1, 2, 2}},
+ {120590, 142690, 23, 2, 396, 12, 11, [8]int32{2, 2, 2, 2, 1, 1, 2, 2}},
+ {120590, 142690, 25, 20, 3745, 59, 54, [8]int32{22, 25, 25, 19, 6, 6, 22, 22}},
+ {120590, 142690, 25, 100, 91565, 271, 246, [8]int32{109, 125, 125, 94, 25, 25, 109, 109}},
+ {120590, 142690, 25, 200, 368792, 535, 485, [8]int32{218, 250, 250, 187, 50, 50, 218, 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 TestOrganicSaleCancellationAndReplayKeepSelectedQuality(t *testing.T) {
+ for _, scenario := range []struct{ quality, sale uint32 }{
+ {2, 19}, {100, 4578}, {101, 4670}, {200, 18439},
+ } {
+ 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, 120587); 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_graft_organic_armor.mjs b/tools/client/test_graft_organic_armor.mjs
@@ -0,0 +1,172 @@
+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 specs = {
+ graft: {
+ pairs: {120579: [120579, 142679], 120565: [120565, 142681], 120581: [120581, 142683], 120582: [120582, 142685], 120583: [120583, 142687], 120584: [120584, 142689]},
+ stamina: 278, strength: 253, ip: 938, wallet: 6302,
+ baseline: [30, 32, 32, 28, 26, 10, 30, 30],
+ glove2: [2, 2, 2, 2, 2, 1, 2, 2],
+ q100: [137, 155, 155, 120, 102, 34, 137, 137],
+ q101: [138, 156, 156, 120, 103, 35, 138, 138],
+ },
+ organic: {
+ pairs: {120585: [120585, 142680], 120586: [120586, 142682], 120587: [120587, 142684], 120588: [120588, 142686], 120589: [120589, 142688], 120590: [120590, 142690]},
+ stamina: 273, strength: 248, ip: 958, wallet: 5593,
+ baseline: [30, 32, 32, 28, 10, 10, 30, 30],
+ glove2: [2, 2, 2, 2, 1, 1, 2, 2],
+ q100: [137, 155, 155, 120, 34, 34, 137, 137],
+ q101: [138, 156, 156, 120, 35, 35, 138, 138],
+ },
+};
+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 ['armor-owner', 'armor-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();
+ const spec = specs[baseline.family];
+ assert.equal(baseline.inventory.Items.length, 10);
+ assert.deepEqual(baseline.armor, spec.baseline);
+ 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');
+
+ // The complete set renders; selected gloves exercise the native wear path.
+ for (const [id, slot, x, y, armor] of [
+ [6, 24, 927, 206, spec.glove2],
+ ]) {
+ 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, spec.q100);
+ 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] === spec.strength + 1 &&
+ owner.local(state).stats[18] === spec.stamina + 1 && owner.local(state).stats[53] === spec.ip);
+ 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, spec.q101);
+ 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] === spec.wallet);
+ 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 = spec.pairs;
+ 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: original armor set, 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_graft_organic_cold.mjs b/tools/client/test_graft_organic_cold.mjs
@@ -0,0 +1,71 @@
+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 specs = {
+ graft: {
+ stamina: 278, strength: 253, ip: 938, wallet: 6302,
+ items: [
+ [1, 18, 2, 120565, 142681, 1],
+ [2, 27, 2, 120579, 142679, 1],
+ [3, 30, 2, 120582, 142685, 1],
+ [4, 23, 2, 120584, 142689, 1],
+ [5, 25, 2, 120584, 142689, 1],
+ [6, 51, 2, 120581, 142683, 1],
+ [7, 21, 2, 120583, 142687, 1],
+ [9, 24, 101, 120581, 142683, 1],
+ [10, 50, 200, 142683, 142683, 1],
+ ],
+ },
+ organic: {
+ stamina: 273, strength: 248, ip: 958, wallet: 5593,
+ items: [
+ [1, 18, 2, 120586, 142682, 1],
+ [2, 27, 2, 120585, 142680, 1],
+ [3, 30, 2, 120588, 142686, 1],
+ [4, 23, 2, 120590, 142690, 1],
+ [5, 25, 2, 120590, 142690, 1],
+ [6, 51, 2, 120587, 142684, 1],
+ [7, 21, 2, 120589, 142688, 1],
+ [9, 24, 101, 120587, 142684, 1],
+ [10, 50, 200, 142684, 142684, 1],
+ ],
+ },
+};
+const games = [];
+try {
+ for (const token of ['armor-owner', 'armor-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 spec = specs[(await (await owner.page.request.get(url + "/test-state")).json()).family];
+ assert.deepEqual(owner.local().inventory.map(item =>
+ [item.id, item.slot, item.quality, ...item.templates, item.count]).sort((a, b) => a[0] - b[0]), spec.items);
+ assert.equal(owner.local().stats[16], spec.strength + 1);
+ assert.equal(owner.local().stats[18], spec.stamina + 1);
+ assert.equal(owner.local().stats[53], spec.ip);
+ assert.equal(owner.local().stats[61], spec.wallet);
+ 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 armor 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(); }
+}