commit 451633dfcf21ac8f91ec4de5a66edf7512427add
parent 6211b76b5d9f4ff4a6f679f31c8370a37baacc3d
Author: anon <anon@example.com>
Date: Sat, 31 Oct 2026 10:34:19 +0000
Support reviewed Leather armor qualities and native lifecycle
Diffstat:
10 files changed, 752 insertions(+), 6 deletions(-)
diff --git a/DEVELOPERS.md b/DEVELOPERS.md
@@ -502,6 +502,15 @@ training exit to Backyard1. It checks the distinct booth56001, entrance56006 and
scene-door51005 identities sharing a numeric ID, then uses the actual booth and
cancels its window without changing inventory, cash or progression.
+`AO_GAME_TEST=1 go test ./server -run '^TestBrowserLeatherArmorQualities$' -count=1 -timeout=12m -v`
+runs a controlled two-client item-contract fixture. It seeds the characters and
+eleven Leather instances before connecting, then uses normal native input for
+all seven worn pieces, both arm slots, QL100/101 thresholds, ability training,
+the alternate vest, cancelled/accepted sale and page reconnect. It checks exact
+ownership and all eight server AC totals, preserving screenshots, wire events
+and the stopped database. This fixture does not establish earned acquisition
+or original stock membership; see [Leather armor](docs/leather-armor.md).
+
For a new scenario, attach before navigation so protocol capture includes the
initial stream handshake:
@@ -562,7 +571,10 @@ and corpses. Actor fields include global position, rotation, playfield, deletion
and combat state. Characters expose the 1024 raw stat values by native stat ID; these
are the dictionary values, not a reconstruction of all effective modifiers.
The local character includes inventory/equipment proxies with native slots,
-instance identities, QL, template endpoints and counts. Inventory slots 48..77
+instance identities, QL, template endpoints and counts, plus an `actions` array
+of active native action types. Inventory admission checks types3 and6; wait for
+their absence before testing a new placement rather than guessing a delay.
+Inventory slots 48..77
correspond to server slots 64..93. Snapshots are copied on the game thread and
published synchronously before C frees their buffers. Missing actors during
zoning or removal are not proof of death or success.
diff --git a/TODO.md b/TODO.md
@@ -306,10 +306,13 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
[earned creature upgrades](docs/earned-creature-upgrade.md),
[early armor](docs/early-armor.md) and
[early melee](docs/early-melee.md).
- An independent original-DB audit also matches all fourteen records of seven
- regular Leather candidate pairs at QL1/200, including appearance, AC and
- strict Sense/Agility criteria. Intermediate quality, native use and acquisition
- remain unverified; see `local/todo-progression-play/leather-audit/audit.json`.
+ Seven regular Leather pairs now use the same QL1..200 path after complete
+ original-DB audits. Public-handler checks cover both anchors, strict ability
+ equality, all eight ACs, value boundaries, removal, sale and cold recovery.
+ A controlled two-client WASM fixture verifies all seven worn pieces, independent
+ sleeve slots, QL100/101 wear/training, the distinct vest, exact cancelled/accepted
+ sale and reconnect. Historical acquisition remains unverified; production stock
+ and mission selections are unchanged. See [Leather contracts](docs/leather-armor.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
@@ -1313,6 +1316,11 @@ introduction and starting-item gameplay remain open below.
correct independent sleeve slots and native AC totals. Compare shared skin
compositing and original color-key behavior before adding item-specific fixes.
Captures: `local/low-tech-set/fixture/`.
+ The controlled regular Leather lifecycle also shows green skin regions beside
+ correct changing armor totals and distinct body/vest styles. Include its owner,
+ observer and cold captures in the shared investigation. Compare the owner's
+ visible helmet with the observer's apparently uncovered head as well; see
+ [Leather verification](docs/leather-armor.md#verification-scope).
- [ ] [P1] Reconstruct the original Arrival Hall and training-ground introduction.
Check all three factions' entry/exit flow, authored tutorial NPC identities,
dialogues, starter instructions and camera state. Replace training NPC
diff --git a/client/runtime/browser_testing.c b/client/runtime/browser_testing.c
@@ -100,7 +100,19 @@ static void actor(FILE *output, uint32_t object, uint32_t type, uint32_t id, int
}
fputc(']', output);
if (local) {
- fputs(",\"inventory\":", output);
+ /* kkr.dll/lifted-0026.c::sub_36052A20 / sub_36052790 enumerate action types. */
+ uint32_t actions = MEM32(object + 0x184);
+ fputs(",\"actions\":[", output);
+ unsigned count = 0;
+ if (actions) {
+ for (int i = 0; i < (int)MEM32(actions + 4); ++i) {
+ uint32_t action = MEM32(MEM32(MEM32(actions + 8) + 4) + i * 4);
+ if (!action) continue;
+ if (count++) fputc(',', output);
+ fprintf(output, "%d", (int32_t)MEM32(action + 0x18));
+ }
+ }
+ fputs("],\"inventory\":", output);
inventory(output, object);
}
}
diff --git a/client/tests/browser_testing.c b/client/tests/browser_testing.c
@@ -79,6 +79,7 @@ static void snapshot_copies_native_state_without_changing_guest_registers(void)
assert(strstr(snapshot, "\"hover\":[51050,99]"));
assert(strstr(snapshot, "\"pick\":null"));
assert(strstr(snapshot, "\"selected\":[50000,9]"));
+ assert(strstr(snapshot, "\"actions\":[]"));
assert(strstr(snapshot, "\"slot\":48,\"type\":51005,\"id\":25,\"quality\":1,\"templates\":[25812,25812],\"count\":3"));
assert(g_eax == 123 && g_esp == 456);
}
@@ -127,12 +128,34 @@ static void snapshots_observe_directory_clear_and_new_frames(void)
assert(strstr(snapshot, "\"pick\":null"));
}
+static void snapshots_observe_active_local_actions_without_mutation(void)
+{
+ MEM32(0x50000304) = 0x50000500;
+ MEM32(0x50001184) = 0x5000d800;
+ MEM32(0x5000d804) = 4;
+ MEM32(0x5000d808) = 0x5000d900;
+ MEM32(0x5000d904) = 0x5000da00;
+ memcpy((void *)ADDR(0x5000da00), (uint32_t[]){0x5000db00, 0, 0x5000dc00, 0x5000dd00}, 16);
+ MEM32(0x5000db18) = 6;
+ MEM32(0x5000dc18) = 3;
+ MEM32(0x5000dd18) = 12;
+
+ browser_test_request();
+ browser_test_frame();
+
+ assert(strstr(snapshot, "\"actions\":[6,3,12]"));
+ assert(MEM32(0x5000d804) == 4 && MEM32(0x5000db18) == 6);
+ assert(MEM32(0x5000dc18) == 3 && MEM32(0x5000dd18) == 12);
+ assert(g_eax == 123 && g_esp == 456);
+}
+
int main(void)
{
snapshot_copies_native_state_without_changing_guest_registers();
completed_picks_record_the_query_pixel_and_result();
snapshots_do_not_advance_the_pick_generation();
snapshots_observe_directory_clear_and_new_frames();
+ snapshots_observe_active_local_actions_without_mutation();
free(snapshot);
puts("PASS: frame snapshots, native inventory, directory clearing and guest state preservation");
}
diff --git a/docs/leather-armor.md b/docs/leather-armor.md
@@ -0,0 +1,116 @@
+# Leather armor quality contracts
+
+Seven reviewed regular Leather pairs use the shared selected-quality equipment,
+requirements, price and native-delivery paths at QL1..200. No family-specific
+gameplay branch is needed. These item contracts do not establish original shop,
+mission or creature-drop membership; acquisition remains separate research.
+
+## Original records
+
+All fourteen complete records are independently decoded from the selected
+14.9.1 resource database and compared against the maintained catalog. Raw bytes,
+offsets, payload hashes and the original index hash are retained in
+`local/todo-progression-play/leather-audit/audit.json`. The index SHA-256 is
+`46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`.
+
+| Piece | QL1 / QL200 templates | Wear slot | Base value QL1 / QL2 | AC90..97 at QL2 |
+| --- | --- | --- | --- | --- |
+| Vest | 85481 / 85690 | 21 | 1000 / 1024 | 9/10/2/2/9/9/2/6 |
+| Pants | 85521 / 85520 | 27 | 625 / 640 | 6/6/1/1/6/6/1/1 |
+| Helmet | 85562 / 85561 | 18 | 750 / 768 | 6/7/2/2/6/6/2/2 |
+| Gloves | 85602 / 85601 | 24 | 250 / 255 | 2/2/1/1/2/2/1/1 |
+| Boots | 85645 / 85644 | 30 | 375 / 384 | 3/3/1/1/3/3/1/1 |
+| Body armor | 85697 / 85696 | 21 | 1000 / 1024 | 9/10/2/2/9/9/2/2 |
+| Sleeves | 85750 / 85749 | 23 or 25 | 250 / 255 | 2/2/1/1/2/2/1/1 |
+
+Each pair has identical remaining descriptors after normalizing scalar
+properties1/2/54/74, the eight armor amounts and the two wear thresholds.
+QL1 requires Sense and Agility each greater than 7; QL200 requires them
+greater than 510 and 460. The selected criteria retain their strict comparisons:
+QL2 needs Sense 11/Agility 10, QL100 needs 258/233 and QL101 needs 261/236.
+The native-derived shared interpolation retains its rounding and quadratic
+price curve. Either stored anchor resolves the same selected contract.
+
+Vest and body armor are distinct original styles. The vest has PoisonAC97=5
+at QL1 and6 at QL2; body armor has1 and2. Their other armor amounts match.
+Both sleeves retain independent identities and either authored arm slot.
+
+The local fandom page3383, touched2007-12-25, corroborates the regular set's
+later QL200 totals. A later [Apocalypse crafting guide](https://wiki.aodb.us/wiki/Apocalypse_Leather_Armor)
+lists ordinary Leather as shop, chest and mission material, but its dated
+2005/2007 contributions do not recover14.9.1 membership or probabilities.
+Bounded period searches found no precise stock or loot table. The current
+production shop and mission selections are unchanged.
+
+## Verification scope
+
+Public inventory-handler cases cover both anchors, all seven pieces, the two
+arm slots, strict equality rejection, exact native endpoint delivery, all eight
+ACs, original values, removal and cold ownership. The glove matrix additionally
+checks QL5/100/101/199 rounding boundaries. Sale cases use the original startup
+terminal's five-percent modifier, covering cancelled offers, accepted sales,
+duplicate acceptance and cold recovery of unrelated ownership.
+An explicitly controlled creature-drop case also checks original endpoint
+presentation, repeated pickup, wear/removal and cold retention of the same
+QL100 glove stored at the high anchor. Its injected membership establishes no
+historical Leather drop table.
+
+`TestBrowserLeatherArmorQualities` starts a controlled level100 Opifex with
+eleven physical instances before either WASM client connects. Actual browser
+input removes and re-wears all seven pieces, keeping both sleeve identities.
+Right-click chooses the original default arm25; an occupied-arm rejection keeps
+the other sleeve, which can be picked up and explicitly placed in arm23 after
+the native action gate clears. Read-only snapshots expose the original action
+types3/6 used by `kkr.dll`'s inventory admission gate; no timer or guest mutation
+is used to bypass it. Placement uses click-to-pick-up/click-to-place.
+
+QL100 gloves stored at the high anchor wear at Sense 260/Agility 235. QL101
+rejects locally with the original Sense 261/Agility 236 messages and sends no
+wear packet. The native skill window spends 495 IP for those two points,
+reducing 2000 to 1505, after which the exact QL101 instance wears. QL200 still
+rejects and remains owned. The separate public-handler matrix establishes the
+same server-side criteria even when a client submits an unqualified request.
+
+The basic armor machine uses its original six-percent sale modifier: the
+QL100 glove's 59074 base value returns 3544 credits. Cancellation restores that
+same instance to the first free inventory cell, without changing the wallet;
+retrying and accepting leaves 3644 credits and ten exact remaining instances.
+The original body instance remains in inventory when the distinct vest wears.
+Owner and observer state, native template endpoints and selected qualities are
+checked through page reconnect and cold database loading.
+
+Rendered Stats show Projectile/Melee/Energy AC 137/155/27 with QL100 gloves and
+138/156/27 after QL101 training. Read-only server totals include all eight ACs:
+the final vest set is 138/156/27/27/138/138/27/31. Native raw stats90..97 are
+separate dictionary values; they must not be mistaken for the effective armor.
+Screenshots retain the existing green-skin compositing limitation on the owner;
+the observer's worn-body capture also shows an apparently uncovered head beside
+the owner's visible helmet. Compare the head/appearance updates in the complete
+appearance audit, which remains open in TODO.md. Successful wear packets
+and correct totals do not establish full visual fidelity.
+
+Controlled fixture checks establish item behavior, not earned acquisition.
+
+The maintained run `local/game-tests/leather-20261031-024054/` passes in 36.07s.
+Its independently checked stopped `world.sqlite` matches every physical item,
+slot, count, quality, wallet and trained stat. A separate two-client fresh WASM
+startup from that unchanged database passes in 14.95s at
+`local/game-tests/leather-cold-20261031-024246/`. All ten item records and
+locations, both player records and all non-pose character columns remain
+identical. Native positions differ from the saved values by 0.014863m and
+quaternion dots exceed 0.9999999; neither client reports a runtime error.
+Final page and cold Stats retain 138/156/27. The native action-gate procedure
+evidence is retained in
+`local/todo-progression-play/leather-native-actions-evidence.json` beside the
+original resource audit and independent ownership reports.
+
+The four focused Go test roots produce 128 passing test/subtest results under
+the race detector, including generated pickup and both stored anchors. The
+frame-snapshot C check and all 126 JavaScript harness tests also pass. The
+published WASM bundle includes the matching read-only action snapshot change.
+The full `go test ./server/... -count=1 -timeout=1h` run also passes: 16959
+test/subtest results across 1728 passing roots, with the four browser-gated
+roots skipped in that run. The server package takes 2657.123s; game data takes
+7.779s. `go vet ./server/...` passes. Full and focused race JSON logs remain in
+`local/todo-progression-play/leather-go-full-verified.json` and
+`local/todo-progression-play/leather-go-race-verified.json`.
diff --git a/server/browser_leather_test.go b/server/browser_leather_test.go
@@ -0,0 +1,138 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "reflect"
+ "runtime"
+ "testing"
+ "time"
+)
+
+func TestBrowserLeatherArmorQualities(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 to run the real WASM client in Chromium")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local", "game-tests", "leather-"+time.Now().Format("20060102-150405"))
+ t.Chdir(t.TempDir())
+ world := newServer()
+ t.Cleanup(func() { world.db.Close() })
+ owner := world.newCharacter()
+ owner.name, owner.level, owner.appearance = "Leatherowner", 100, 0x525
+ owner.playfield, owner.position = 1183, [3]float32{188, 5.011, 139.5}
+ owner.rotation = [4]float32{0, 0.70710677, 0, 0.70710677}
+ owner.stats.Abilities.Sense, owner.stats.Abilities.Agility = 260, 235
+ owner.stats.ImprovementPoints, owner.inventory.Credits = 2000, 100
+ owner.health, owner.nano = owner.maximumHealth(), owner.maximumNano()
+ owner.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("leather-owner")))
+ watcher := world.newCharacter()
+ watcher.name, watcher.playfield, watcher.position = "Leatherwatch", 1183, [3]float32{186, 5.011, 134.5}
+ watcher.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("leather-watch")))
+ for _, player := range []*character{owner, watcher} {
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.savePosition_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ // Seed a controlled item-contract fixture before either native client connects.
+ for _, item := range []struct{ template, quality, slot uint32 }{
+ {85562, 2, 18}, {85521, 2, 27}, {85645, 2, 30},
+ {85750, 2, 23}, {85750, 2, 25}, {85602, 2, 24}, {85697, 2, 21},
+ {85481, 2, 64}, {85601, 100, 65}, {85602, 101, 66}, {85602, 200, 67},
+ } {
+ 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)
+ }
+ 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)
+ defer host.Close()
+ closeTestBrowserStreams(t, world)
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
+ defer cancel()
+ stopped := make(chan struct{})
+ go func() {
+ defer close(stopped)
+ ticker := time.NewTicker(50 * 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_leather_armor.mjs"), host.URL, output)
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ err := command.Run()
+ cancel()
+ <-stopped
+ t.Logf("Browser artifacts: %s", output)
+ if failure := world.flushPositions(time.Now().Add(20 * time.Second)); failure != nil {
+ t.Fatal(failure)
+ }
+ if failure := world.flushWorld(); failure != nil {
+ t.Fatal(failure)
+ }
+ if failure := os.MkdirAll(output, 0755); failure != nil {
+ t.Fatal(failure)
+ }
+ if _, failure := world.db.Exec("VACUUM INTO ?", filepath.Join(output, "world.sqlite")); failure != nil {
+ t.Fatal(failure)
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ cold := newServer()
+ defer cold.db.Close()
+
+ for _, player := range []*character{owner, watcher} {
+ restored := cold.characters[player.id]
+ if !reflect.DeepEqual(player.inventory.Items, restored.inventory.Items) || player.inventory.Credits != restored.inventory.Credits || player.stats != restored.stats ||
+ player.position != restored.position || player.rotation != restored.rotation {
+ t.Fatal("native armor outcome changed across cold loading", player.id)
+ }
+ }
+ if len(owner.inventory.Items) != 10 || owner.inventory.Credits != 3644 || owner.stats.ImprovementPoints != 1505 ||
+ owner.stats.Abilities.Sense != 261 || owner.stats.Abilities.Agility != 236 || len(watcher.inventory.Items) != 0 {
+ t.Fatal("native armor fixture lost ownership, selected-quality sale or ability training")
+ }
+ for index, armor := range [8]int32{138, 156, 27, 27, 138, 138, 27, 31} {
+ if owner.equipmentBonus(90+uint32(index)) != armor || cold.characters[owner.id].equipmentBonus(90+uint32(index)) != armor {
+ t.Fatal("native worn armor or independent sleeves changed", index)
+ }
+ }
+}
diff --git a/server/gamedata/item_families.yaml b/server/gamedata/item_families.yaml
@@ -26,6 +26,14 @@
- [70563, 85558]
- [70564, 85515]
- [70565, 85514]
+# Leather armor: complete original descriptor audits; docs/leather-armor.md.
+- [85481, 85690]
+- [85521, 85520]
+- [85562, 85561]
+- [85602, 85601]
+- [85645, 85644]
+- [85697, 85696]
+- [85750, 85749]
# Regular recovery supplies, QL1..200: docs/medical-quality.md.
- [25812, 25811]
- [85366, 85367]
diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go
@@ -15,6 +15,8 @@ func TestReviewedItemFamilyQualityRanges(t *testing.T) {
{42640, 42641, 1, 400}, {206730, 206731, 50, 150}, {158416, 158417, 1, 200}, {123742, 123743, 1, 11},
{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},
+ {85481, 85690, 1, 200}, {85521, 85520, 1, 200}, {85562, 85561, 1, 200}, {85602, 85601, 1, 200},
+ {85645, 85644, 1, 200}, {85697, 85696, 1, 200}, {85750, 85749, 1, 200},
{25812, 25811, 1, 200}, {85366, 85367, 1, 200}, {25820, 25821, 1, 200},
} {
for _, template := range [2]uint32{family.lowTemplate, family.highTemplate} {
diff --git a/server/leather_armor_test.go b/server/leather_armor_test.go
@@ -0,0 +1,217 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "slices"
+ "testing"
+)
+
+func TestLeatherGeneratedPickupKeepsSelectedQuality(t *testing.T) {
+ world, output := newKillExperienceWorld(t, "unarmed")
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Abilities.Sense, player.stats.Abilities.Agility = 258, 233
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ // Controlled membership tests delivery, not historical Leather creature drops.
+ profile := *world.characters[1000000].combatProfile
+ profile.Loot = []gamedata.NPCLoot{{Template: 85601, 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, 85602, 85601, 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: 85601, 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 TestLeatherArmorQualitiesWearRemoveAndRecover(t *testing.T) {
+ for _, scenario := range []struct {
+ low, high, slot, quality, value uint32
+ sense, agility uint16
+ armor [8]int32
+ }{
+ {85481, 85690, 21, 1, 1000, 7, 7, [8]int32{5, 5, 1, 1, 5, 5, 1, 5}},
+ {85481, 85690, 21, 2, 1024, 10, 9, [8]int32{9, 10, 2, 2, 9, 9, 2, 6}},
+ {85481, 85690, 21, 100, 236297, 257, 232, [8]int32{438, 500, 75, 75, 438, 438, 75, 77}},
+ {85481, 85690, 21, 200, 951722, 510, 460, [8]int32{875, 1000, 150, 150, 875, 875, 150, 150}},
+ {85521, 85520, 27, 1, 625, 7, 7, [8]int32{3, 3, 1, 1, 3, 3, 1, 1}},
+ {85521, 85520, 27, 2, 640, 10, 9, [8]int32{6, 6, 1, 1, 6, 6, 1, 1}},
+ {85521, 85520, 27, 100, 147686, 257, 232, [8]int32{273, 312, 47, 47, 273, 273, 47, 47}},
+ {85521, 85520, 27, 200, 594826, 510, 460, [8]int32{546, 625, 93, 93, 546, 546, 93, 93}},
+ {85562, 85561, 18, 1, 750, 7, 7, [8]int32{3, 3, 1, 1, 3, 3, 1, 1}},
+ {85562, 85561, 18, 2, 768, 10, 9, [8]int32{6, 7, 2, 2, 6, 6, 2, 2}},
+ {85562, 85561, 18, 100, 177223, 257, 232, [8]int32{328, 375, 56, 56, 328, 328, 56, 56}},
+ {85562, 85561, 18, 200, 713791, 510, 460, [8]int32{656, 750, 112, 112, 656, 656, 112, 112}},
+ {85602, 85601, 24, 1, 250, 7, 7, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {85602, 85601, 24, 2, 255, 10, 9, [8]int32{2, 2, 1, 1, 2, 2, 1, 1}},
+ {85602, 85601, 24, 5, 346, 17, 16, [8]int32{5, 6, 2, 2, 5, 5, 2, 2}},
+ {85602, 85601, 24, 100, 59074, 257, 232, [8]int32{109, 125, 19, 19, 109, 109, 19, 19}},
+ {85602, 85601, 24, 101, 60268, 260, 235, [8]int32{110, 126, 19, 19, 110, 110, 19, 19}},
+ {85602, 85601, 24, 199, 235547, 507, 458, [8]int32{217, 249, 37, 37, 217, 217, 37, 37}},
+ {85602, 85601, 24, 200, 237930, 510, 460, [8]int32{218, 250, 37, 37, 218, 218, 37, 37}},
+ {85645, 85644, 30, 1, 375, 7, 7, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {85645, 85644, 30, 2, 384, 10, 9, [8]int32{3, 3, 1, 1, 3, 3, 1, 1}},
+ {85645, 85644, 30, 100, 88611, 257, 232, [8]int32{164, 187, 28, 28, 164, 164, 28, 28}},
+ {85645, 85644, 30, 200, 356895, 510, 460, [8]int32{328, 375, 56, 56, 328, 328, 56, 56}},
+ {85697, 85696, 21, 1, 1000, 7, 7, [8]int32{5, 5, 1, 1, 5, 5, 1, 1}},
+ {85697, 85696, 21, 2, 1024, 10, 9, [8]int32{9, 10, 2, 2, 9, 9, 2, 2}},
+ {85697, 85696, 21, 100, 236297, 257, 232, [8]int32{438, 500, 75, 75, 438, 438, 75, 75}},
+ {85697, 85696, 21, 200, 951722, 510, 460, [8]int32{875, 1000, 150, 150, 875, 875, 150, 150}},
+ {85750, 85749, 25, 1, 250, 7, 7, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {85750, 85749, 25, 2, 255, 10, 9, [8]int32{2, 2, 1, 1, 2, 2, 1, 1}},
+ {85750, 85749, 23, 2, 255, 10, 9, [8]int32{2, 2, 1, 1, 2, 2, 1, 1}},
+ {85750, 85749, 25, 100, 59074, 257, 232, [8]int32{109, 125, 19, 19, 109, 109, 19, 19}},
+ {85750, 85749, 25, 200, 237930, 510, 460, [8]int32{218, 250, 37, 37, 218, 218, 37, 37}},
+ } {
+ 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)
+ t.Cleanup(func() { world.db.Close() })
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Abilities.Sense, player.stats.Abilities.Agility = scenario.sense+1, scenario.agility+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.Sense, &player.stats.Abilities.Agility} {
+ *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 TestLeatherSaleCancellationAndReplayKeepSelectedQuality(t *testing.T) {
+ for _, scenario := range []struct{ quality, sale uint32 }{
+ {2, 12}, {100, 2953}, {101, 3013}, {200, 11896},
+ } {
+ 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, 85602); 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_leather_armor.mjs b/tools/client/test_leather_armor.mjs
@@ -0,0 +1,210 @@
+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);
+assert(url && output, 'Run through TestBrowserLeatherArmorQualities');
+const browser = await chromium.launch({executablePath: '/usr/bin/chromium',
+ 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('native 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, 'Fixture item is outside its visible inventory cells');
+ const cell = item.slot - 48;
+ await game.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54, 'right');
+}
+
+try {
+ for (const token of ['leather-owner', 'leather-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.equal(owner.local().id, 1);
+ assert.equal(observer.local().id, 2);
+ const state = async () => (await owner.page.request.get(url + '/test-state')).json();
+ const baseline = await state();
+ const watched = observer.local().inventory;
+ assert.equal(baseline.inventory.Items.length, 11);
+ assert.deepEqual(baseline.armor, [30, 32, 9, 9, 30, 30, 9, 9]);
+ 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.wait('native armor stats window', state => state.regions.some(
+ ([left, top, right, bottom]) => left === 832 && top === 380 && right === 1024 && bottom === 606));
+ await owner.save(output + '/initial-set');
+ await observer.save(output + '/observer-initial-set');
+
+ // Remove and re-wear every initial piece, retaining each sleeve independently.
+ for (const [id, slot, x, y, armor] of [
+ [1, 18, 927, 94, [6, 7, 2, 2, 6, 6, 2, 2]],
+ [2, 27, 927, 262, [6, 6, 1, 1, 6, 6, 1, 1]],
+ [3, 30, 927, 316, [3, 3, 1, 1, 3, 3, 1, 1]],
+ [4, 23, 867, 206, [2, 2, 1, 1, 2, 2, 1, 1]],
+ [5, 25, 987, 206, [2, 2, 1, 1, 2, 2, 1, 1]],
+ [6, 24, 927, 206, [2, 2, 1, 1, 2, 2, 1, 1]],
+ [7, 21, 927, 148, [9, 10, 2, 2, 9, 9, 2, 2]],
+ ]) {
+ 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]));
+ await owner.save(output + '/removed-' + id);
+ if (slot === 23) {
+ // Native right-click chooses default slot25; explicitly place the other sleeve.
+ const attempt = owner.sequence;
+ await bagClick(owner, id);
+ await owner.wait('occupied default arm correction', () => owner.events.filter(event =>
+ event.sequence > attempt && event.direction === 'framereceived' && event.opcode === '47537a24').length >= 2);
+ await owner.save(output + '/default-arm-rejected');
+ await owner.wait('native inventory actions finish', state =>
+ !owner.local(state).actions.includes(3) && !owner.local(state).actions.includes(6));
+ const item = owner.local().inventory.find(item => item.id === id);
+ const cell = item.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 re-worn', state => owner.local(state).inventory.some(item => item.id === id && item.slot === slot));
+ await observer.wait('observer receives worn piece', () => 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 + '/worn-' + id);
+ await observer.save(output + '/observer-worn-' + id);
+ }
+ console.log('PASS: all seven worn pieces remove/re-wear, with independent sleeves');
+
+ // Wear an intermediate quality stored at the high endpoint, then reject equality at QL101.
+ await owner.click(927, 206, 'right');
+ await owner.wait('QL2 gloves retained in inventory', state => owner.local(state).inventory.some(item => item.id === 6 && item.slot >= 48));
+ await bagClick(owner, 9);
+ await owner.wait('QL100 gloves worn', state => owner.local(state).inventory.some(item => item.id === 9 && item.slot === 24));
+ assert.deepEqual((await state()).armor, [137, 155, 27, 27, 137, 137, 27, 27]);
+ await owner.save(output + '/quality-100');
+ await owner.click(927, 206, 'right');
+ await owner.wait('QL100 gloves retained in inventory', state => owner.local(state).inventory.some(item => item.id === 9 && item.slot >= 48));
+ const untrained = await state();
+ const untrainedAttempt = owner.sequence;
+ await bagClick(owner, 10);
+ await owner.save(output + '/quality-101-rejected');
+ assert(!owner.events.some(event => event.sequence > untrainedAttempt &&
+ event.direction === 'framesent' && event.opcode === '47537a24'), 'Native requirements admitted unqualified gloves');
+ const rejected = await state();
+ assert.deepEqual(rejected.inventory, untrained.inventory);
+ assert.equal(rejected.pending, false);
+ assert(owner.local().inventory.some(item => item.id === 10 && item.slot >= 48));
+
+ // Train both strict ability thresholds through the original skill window.
+ await owner.page.keyboard.press('Control+1');
+ await owner.page.keyboard.press('Control+9');
+ await owner.key('KeyU');
+ await owner.click(334, 196);
+ await owner.click(835, 196);
+ await owner.click(835, 286);
+ await owner.click(445, 622);
+ await owner.wait('one trained ability point each', state => owner.local(state).stats[17] === 236 &&
+ owner.local(state).stats[20] === 261 && owner.local(state).stats[53] === 1505);
+ await bagClick(owner, 10);
+ await owner.wait('QL101 gloves worn after training', state => owner.local(state).inventory.some(item => item.id === 10 && item.slot === 24));
+ assert.deepEqual((await state()).armor, [138, 156, 27, 27, 138, 138, 27, 27]);
+ await owner.page.keyboard.press('Control+1');
+ await owner.click(953, 53);
+ await owner.page.keyboard.press('Control+9');
+ await owner.wait('trained native armor stats window', state => state.regions.some(
+ ([left, top, right, bottom]) => left === 832 && top === 380 && right === 1024 && bottom === 606));
+ await owner.save(output + '/quality-101-trained');
+ const beforeHigh = await state();
+ const highAttempt = owner.sequence;
+ await bagClick(owner, 11);
+ await owner.save(output + '/quality-200-rejected');
+ assert(!owner.events.some(event => event.sequence > highAttempt &&
+ event.direction === 'framesent' && event.opcode === '47537a24'), 'Native requirements admitted QL200 gloves');
+ assert.deepEqual((await state()).inventory, beforeHigh.inventory);
+
+ // Retain the body instance while wearing the vest's distinct Poison AC effect.
+ await owner.click(927, 148, 'right');
+ await owner.wait('original body retained', state => owner.local(state).inventory.some(item => item.id === 7 && item.slot >= 48));
+ await bagClick(owner, 8);
+ await owner.wait('alternate vest worn', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot === 21));
+ assert.deepEqual((await state()).armor, [138, 156, 27, 27, 138, 138, 27, 31]);
+ await owner.save(output + '/vest');
+
+ // Cancel and accept the exact QL100 sale through the original basic armor machine.
+ await owner.page.keyboard.press('Control+1');
+ await owner.page.keyboard.press('Control+9');
+ if (!owner.state.camera.firstPerson) await owner.key('F8');
+ let offerState = 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('original armor shop open', state => state.regions.some(
+ ([left, top, right, bottom]) => left === 832 && top === 0 && right === 1024 && bottom === 494));
+ const item = owner.local().inventory.find(item => item.id === 9);
+ const cell = item.slot - 48;
+ await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54);
+ const offered = owner.sequence;
+ await owner.click(864, 416);
+ await owner.wait('exact native sale offered', () => owner.events.some(event =>
+ event.sequence > offered && event.direction === 'framesent' && event.opcode === '36284f6e'));
+ assert.deepEqual((await state()).inventory, offerState.inventory);
+ await owner.save(output + '/sale-offer-' + attempt);
+ if (attempt === 0) {
+ await owner.click(945, 475);
+ await owner.wait('cancel restores QL100 identity in the first free cell', state => owner.local(state).inventory.some(item => item.id === 9 && item.slot === 48));
+ const cancelled = await state();
+ assert.deepEqual(cancelled.inventory, {...offerState.inventory,
+ Items: offerState.inventory.Items.map(item => item.ID === 9 ? {...item, Slot: 64} : item)});
+ offerState = cancelled;
+ await owner.save(output + '/sale-cancelled');
+ await fs.writeFile(output + '/sale-cancelled/server.json', JSON.stringify(cancelled, null, 2));
+ }
+ }
+ await owner.click(874, 475);
+ await owner.wait('selected-quality sale committed', state => owner.local(state).stats[61] === 3644);
+ const final = await state();
+ const slots = {1: 18, 2: 27, 3: 30, 4: 23, 5: 25, 6: 68, 7: 66, 8: 21, 10: 24, 11: 67};
+ const expected = baseline.inventory.Items.filter(item => item.ID !== 9).map(item => ({...item, Slot: slots[item.ID]}));
+ assert.deepEqual(final.inventory.Items, expected);
+ assert.equal(final.stats.ImprovementPoints, 1505);
+ assert.deepEqual(final.observer, baseline.observer);
+ await owner.page.reload();
+ await owner.ready();
+ assert.equal(owner.local().inventory.length, 10);
+ for (const item of expected) {
+ const pair = {85562: [85562, 85561], 85521: [85521, 85520], 85645: [85645, 85644],
+ 85750: [85750, 85749], 85602: [85602, 85601], 85697: [85697, 85696], 85481: [85481, 85690]}[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.wait('reconnected native armor stats window', state => state.regions.some(
+ ([left, top, right, bottom]) => left === 832 && top === 380 && right === 1024 && bottom === 606));
+ await owner.save(output + '/reconnected');
+ await observer.snapshot();
+ assert.deepEqual(observer.local().inventory, watched);
+ for (const game of games) assert.deepEqual(game.errors, []);
+ await fs.writeFile(output + '/ledger.json', JSON.stringify(final, null, 2));
+ console.log('PASS: QL100/101 requirements, original vest, exact sale and page ownership');
+} finally {
+ try {
+ for (const [index, game] of games.entries()) await game.save(output + '/client-' + index);
+ } finally { await browser.close(); }
+}