commit 66167a92a1641f9616321eca7259db41f94ad879
parent 761f9070ea91aa83d0f780a30e12f10f1d089359
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 21:57:54 +0000
Admit audited regular Kevlar quality families
Diffstat:
9 files changed, 743 insertions(+), 0 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -447,6 +447,15 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
both sleeves, QL100/101 refusal/training, exact sale and page/fresh-server
recovery. Historical acquisition remains open; see
[Omni-Pol contracts](docs/omni-pol-armor.md).
+ Six audited regular Kevlar pairs now admit QL1..200 through shared data,
+ fixing qualified QL2 glove refusal. Complete original descriptors distinguish
+ Vest/Body Armor and preserve strict Agility/Strength gates, all eight ACs,
+ selected values, both sleeve slots and both stored anchors. Controlled pickup,
+ wear/removal, sale and cold ownership use the existing consumers. Historical
+ regular-Kevlar acquisition remains open. A short controlled two-client WASM
+ fixture verifies both body styles, all six worn pieces, independent sleeves,
+ QL100/101 native training, cancelled/accepted sale and nine retained identities
+ across page/cold recovery; see [Kevlar contracts](docs/kevlar-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/kevlar-armor.md b/docs/kevlar-armor.md
@@ -0,0 +1,104 @@
+# Regular Kevlar armor
+
+Six complete original endpoint pairs now admit QL1..200 through the shared item
+quality, requirement, AC, native-delivery and sale consumers. Previously a
+qualified QL2 pair of gloves was refused because only its shipped endpoints
+were supported. The failing public-handler check is retained in
+`local/kevlar/baseline.log`.
+
+| Piece | QL1 template | QL200 template | Worn slot |
+| --- | --- | --- | --- |
+| Pants | 85516 | 22301 | 27 |
+| Gloves | 85598 | 22178 | 24 |
+| Boots | 85641 | 22116 | 30 |
+| Vest | 85691 | 22004 | 21 |
+| Body Armor | 85692 | 22026 | 21 |
+| Sleeves | 85745 | 21929 | 23 or25 |
+
+These pairs cover the original Inferior/Flawless Kevlar descriptors, including
+both body styles. They do not admit Kirch Kevlar, Notum Infused Kevlar,
+Professor Jones's vest, balaclavas, armbands or shoulderpads.
+
+## Original contracts
+
+Fresh reads from the original14.9.1 database match every catalog field for all
+12 records, including payload hashes and record offsets. Each record is
+type1000020 with header `[51022, 4, 15, 23]`, text header `[21, 33]`, no undecoded
+data and exactly two sections. The complete sections contain eight unconditional
+OnWear Modify53045 AC functions and the strict wear requirements for Agility17
+and Strength16. There is no faction requirement or unimplemented companion
+effect. Normalizing the section byte offsets, the two strict threshold amounts
+and eight AC amounts makes each pair's complete sections identical.
+
+The original descriptions, other stats and complete section structure match
+within each pair. Stat differences are limited to stats1/2, QL54 and
+value74. Names differ between Inferior and Flawless. The shared native nearer
+endpoint rule preserves those nonnumeric properties; no Kevlar-specific code
+or stat interpolation was introduced.
+
+The source index SHA256 is
+`46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`.
+The twelve original payloads, complete normalized audit and per-record hashes
+are retained in `local/kevlar/original/`.
+
+All pieces share the same strict thresholds:
+
+| QL | Agility must exceed | Strength must exceed |
+| --- | --- | --- |
+| 1 | 8 | 8 |
+| 2 | 11 | 10 |
+| 100 | 265 | 240 |
+| 101 | 268 | 243 |
+| 200 | 525 | 475 |
+
+Glove values at QL2/100/101/200 are358/82704/84376/333102. QL100 glove ACs in
+stat90..97 order are `[125,125,109,78,25,78,78,25]`; QL101 gives
+`[126,126,110,79,26,79,79,26]`. Vest and Body Armor have different AC contracts,
+despite using the same slot and ability thresholds, and retain their respective
+original appearance properties.
+
+## Acquisition limits
+
+Production loot, mission rewards and shop stock are unchanged. The bounded
+period search did not establish regular-Kevlar acquisition or its quality
+distribution. A contemporary August8,2003
+[player trade guide](https://forum.paticik.com/topic/230531-trade-icin-gecerli-olan-itemlar/)
+describes Kirch Kevlar separately; its reported availability cannot establish
+regular Kevlar membership. Local Fandom results are retained in
+`local/kevlar/fandom.json` as later secondary evidence. Controlled loot and native
+fixture items verify their consumers, not historical acquisition or earned
+progression.
+
+## Verification
+
+Public-handler checks cover both stored anchors, representative QL1/2/20/100/
+101/199/200 boundaries, every piece and both sleeves. They check strict equality
+refusal without item loss, the exact selected endpoint/QL wear packet, all eight
+ACs, original value, removal and cold recovery. A controlled generated QL100
+glove retains its identity through corpse pickup and repeated requests. Cancelled
+and accepted sales retain the selected value and exactly-once ownership.
+
+The final Go invocation passes four server roots/74 results and the reviewed
+family table's203 results,277 total. Vet and both Node syntax checks pass. No
+runtime Go or client behavior branch changed for this admission.
+
+The accepted two-client WASM fixture is `local/kevlar/20261103-135432/`:
+warm43.84seconds, cold31.42seconds,15 clean traces with no dropped events or
+page exceptions. Six initially worn pieces are individually removed/re-worn;
+left and right sleeves retain their own slots. A separate native switch wears
+the vest, verifies its distinct ACs and observer appearance, then restores the
+body armor. The observer receives each exact endpoint/QL wear packet.
+
+A QL100 glove stored against its high endpoint wears at the arranged268Agility/
+243Strength; QL101 refuses at equality. Native ability training to269/244 costs
+1022 of the fixture's2000 IP and permits that same QL101 instance. QL200 still
+refuses without an inventory request. The original Omni armor machine cancels,
+then accepts the QL100 sale for4962 credits, leaving5062 from the arranged100.
+Page and fresh-server native recovery retain nine exact instances, correct
+slots/endpoints and all selected properties. Cold ACs are
+`[149,149,132,98,33,98,98,33]`; the other client remains empty and uncharged.
+
+Visual review confirms both body styles on a visible observer replica and the
+cold owner's equipment/AC display. These are controlled contract fixtures,
+not earned-progression evidence. Full source, packet, UI and conservation checks
+are recorded in `local/kevlar/verification.json`.
diff --git a/server/browser_kevlar_test.go b/server/browser_kevlar_test.go
@@ -0,0 +1,140 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "reflect"
+ "runtime"
+ "testing"
+ "time"
+)
+
+func TestBrowserKevlarArmorQualities(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for the focused native Kevlar check")
+ }
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/kevlar", time.Now().Format("20060102-150405"))
+ t.Chdir(t.TempDir())
+ world := newServerForTest(t)
+ owner := world.newCharacter()
+ owner.name, owner.level, owner.appearance = "Kevlarowner", 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.Agility, owner.stats.Abilities.Strength = 268, 243
+ owner.stats.ImprovementPoints, owner.inventory.Credits = 2000, 100
+ owner.health, owner.nano = owner.maximumHealth(), owner.maximumNano()
+ owner.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("kevlar-owner")))
+ watcher := world.newCharacter()
+ watcher.name, watcher.playfield, watcher.position = "Kevlarwatch", 1183, [3]float32{186, 5.11, 134.5}
+ watcher.rotation = [4]float32{0, 0.18910752, 0, 0.98195636}
+ watcher.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("kevlar-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 }{
+ {85516, 2, 27}, {85641, 2, 30}, {85745, 2, 23}, {85745, 2, 25},
+ {85598, 2, 24}, {85692, 2, 21}, {85691, 2, 67},
+ {22178, 100, 64}, {85598, 101, 65}, {85598, 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_kevlar_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 != 5062 || owner.stats.ImprovementPoints != 978 ||
+ owner.stats.Abilities.Agility != 269 || owner.stats.Abilities.Strength != 244 || 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{149, 149, 132, 98, 33, 98, 98, 33} {
+ 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_kevlar_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
@@ -125,3 +125,10 @@
- [85735, 21955]
# Carry-only Carbonrich Rock: complete original descriptors; docs/resource-pickup.md.
- [150274, 150273]
+# Regular Kevlar armor: complete original descriptor audit; docs/kevlar-armor.md.
+- [85516, 22301]
+- [85598, 22178]
+- [85641, 22116]
+- [85691, 22004]
+- [85692, 22026]
+- [85745, 21929]
diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go
@@ -46,6 +46,8 @@ func TestReviewedItemFamilyQualityRanges(t *testing.T) {
{85505, 22331, 1, 200}, {85552, 22246, 1, 200}, {85591, 22196, 1, 200},
{85631, 22142, 1, 200}, {85679, 22064, 1, 200}, {85735, 21955, 1, 200},
{150274, 150273, 1, 255},
+ {85516, 22301, 1, 200}, {85598, 22178, 1, 200}, {85641, 22116, 1, 200},
+ {85691, 22004, 1, 200}, {85692, 22026, 1, 200}, {85745, 21929, 1, 200},
} {
for _, template := range [2]uint32{family.lowTemplate, family.highTemplate} {
t.Run(fmt.Sprint(template), func(t *testing.T) {
diff --git a/server/kevlar_armor_test.go b/server/kevlar_armor_test.go
@@ -0,0 +1,25 @@
+package main
+
+import "testing"
+
+func TestKevlarIntermediateQualityCanBeWorn(t *testing.T) {
+ world, _ := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Abilities.Agility, player.stats.Abilities.Strength = 12, 11
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if granted, err := world.grantItem_locked(player, 85598); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ player.inventory.Items[1].Quality = 2
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+
+ err := world.handleInventory(client, inventoryMovePacket(1, 65, 24)[20:])
+
+ if err != nil || client.equipment == nil {
+ t.Fatal("qualified Kevlar QL2 gloves did not start wear", err)
+ }
+}
diff --git a/server/kevlar_contracts_test.go b/server/kevlar_contracts_test.go
@@ -0,0 +1,219 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "bytes"
+ "encoding/binary"
+ "fmt"
+ "slices"
+ "testing"
+)
+
+func TestKevlarGeneratedPickupKeepsSelectedQuality(t *testing.T) {
+ world, output := newKillExperienceWorld(t, "unarmed")
+ player, client := world.characters[1], world.clients[1]
+
+ player.stats.Abilities.Agility, player.stats.Abilities.Strength = 266, 241
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ // Controlled membership tests delivery, not historical Kevlar creature drops.
+ profile := *world.characters[1000000].combatProfile
+ profile.Loot = []gamedata.NPCLoot{{Template: 22178, 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, 85598, 22178, 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: 22178, 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 TestKevlarArmorQualitiesWearRemoveAndRecover(t *testing.T) {
+ for _, scenario := range []struct {
+ low, high, slot, quality, value uint32
+ agility, strength uint16
+ armor [8]int32
+ }{
+ {85516, 22301, 27, 1, 875, 8, 8, [8]int32{3, 3, 3, 3, 1, 3, 3, 1}},
+ {85516, 22301, 27, 2, 896, 11, 10, [8]int32{6, 6, 6, 5, 2, 5, 5, 2}},
+ {85516, 22301, 27, 20, 8458, 57, 53, [8]int32{62, 62, 55, 40, 13, 40, 40, 13}},
+ {85516, 22301, 27, 100, 206760, 265, 240, [8]int32{312, 312, 273, 196, 63, 196, 196, 63}},
+ {85516, 22301, 27, 200, 832757, 525, 475, [8]int32{625, 625, 546, 390, 125, 390, 390, 125}},
+ {85598, 22178, 24, 1, 350, 8, 8, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {85598, 22178, 24, 2, 358, 11, 10, [8]int32{2, 2, 2, 2, 1, 2, 2, 1}},
+ {85598, 22178, 24, 20, 3383, 57, 53, [8]int32{25, 25, 22, 16, 6, 16, 16, 6}},
+ {85598, 22178, 24, 100, 82704, 265, 240, [8]int32{125, 125, 109, 78, 25, 78, 78, 25}},
+ {85598, 22178, 24, 101, 84376, 268, 243, [8]int32{126, 126, 110, 79, 26, 79, 79, 26}},
+ {85598, 22178, 24, 199, 329766, 522, 473, [8]int32{249, 249, 217, 155, 50, 155, 155, 50}},
+ {85598, 22178, 24, 200, 333102, 525, 475, [8]int32{250, 250, 218, 156, 50, 156, 156, 50}},
+ {85641, 22116, 30, 1, 525, 8, 8, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {85641, 22116, 30, 2, 537, 11, 10, [8]int32{3, 3, 3, 2, 1, 2, 2, 1}},
+ {85641, 22116, 30, 20, 5075, 57, 53, [8]int32{37, 37, 32, 23, 8, 23, 23, 8}},
+ {85641, 22116, 30, 100, 124055, 265, 240, [8]int32{187, 187, 164, 117, 38, 117, 117, 38}},
+ {85641, 22116, 30, 200, 499654, 525, 475, [8]int32{375, 375, 328, 234, 75, 234, 234, 75}},
+ {85691, 22004, 21, 1, 1400, 8, 8, [8]int32{5, 5, 5, 5, 1, 5, 5, 1}},
+ {85691, 22004, 21, 2, 1433, 11, 10, [8]int32{9, 9, 9, 7, 2, 7, 7, 2}},
+ {85691, 22004, 21, 20, 13533, 57, 53, [8]int32{88, 88, 76, 52, 18, 52, 52, 18}},
+ {85691, 22004, 21, 100, 330816, 265, 240, [8]int32{438, 438, 376, 251, 88, 251, 251, 88}},
+ {85691, 22004, 21, 200, 1332411, 525, 475, [8]int32{875, 875, 750, 500, 175, 500, 500, 175}},
+ {85692, 22026, 21, 1, 1400, 8, 8, [8]int32{5, 5, 5, 5, 1, 5, 5, 1}},
+ {85692, 22026, 21, 2, 1433, 11, 10, [8]int32{10, 10, 9, 8, 2, 8, 8, 2}},
+ {85692, 22026, 21, 20, 13533, 57, 53, [8]int32{100, 100, 88, 64, 20, 64, 64, 20}},
+ {85692, 22026, 21, 100, 330816, 265, 240, [8]int32{500, 500, 438, 313, 100, 313, 313, 100}},
+ {85692, 22026, 21, 200, 1332411, 525, 475, [8]int32{1000, 1000, 875, 625, 200, 625, 625, 200}},
+ {85745, 21929, 25, 1, 350, 8, 8, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}},
+ {85745, 21929, 25, 2, 358, 11, 10, [8]int32{2, 2, 2, 2, 1, 2, 2, 1}},
+ {85745, 21929, 23, 2, 358, 11, 10, [8]int32{2, 2, 2, 2, 1, 2, 2, 1}},
+ {85745, 21929, 25, 20, 3383, 57, 53, [8]int32{25, 25, 22, 16, 6, 16, 16, 6}},
+ {85745, 21929, 25, 100, 82704, 265, 240, [8]int32{125, 125, 109, 78, 25, 78, 78, 25}},
+ {85745, 21929, 25, 200, 333102, 525, 475, [8]int32{250, 250, 218, 156, 50, 156, 156, 50}},
+ } {
+ 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.Agility, player.stats.Abilities.Strength = scenario.agility+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.Agility, &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 TestKevlarSaleCancellationAndReplayKeepSelectedQuality(t *testing.T) {
+ for _, scenario := range []struct{ quality, sale uint32 }{
+ {2, 17}, {100, 4135}, {101, 4218}, {200, 16655},
+ } {
+ 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, 85598); 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_kevlar_armor.mjs b/tools/client/test_kevlar_armor.mjs
@@ -0,0 +1,185 @@
+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 ['kevlar-owner', 'kevlar-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();
+ await page.waitForFunction(() => touchRegion(500, 400)?.world === true);
+ await game.snapshot();
+ }
+ const [owner, observer] = games;
+ if (!observer.state.camera.firstPerson) await observer.key('F8');
+ await observer.wait('armor wearer is visible to the observer', state => state.actors.some(actor => actor.id === 1 &&
+ actor.screenPosition?.[0] > 0 && actor.screenPosition[0] < 1024 && actor.screenPosition[1] > 0 &&
+ actor.screenPosition[1] < 748 && actor.screenPosition[2] >= 0 && actor.screenPosition[2] <= 1));
+ 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, [25, 25, 24, 21, 8, 21, 21, 8]);
+ 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, 27, 927, 262, [6, 6, 6, 5, 2, 5, 5, 2]],
+ [2, 30, 927, 316, [3, 3, 3, 2, 1, 2, 2, 1]],
+ [3, 23, 867, 206, [2, 2, 2, 2, 1, 2, 2, 1]],
+ [4, 25, 987, 206, [2, 2, 2, 2, 1, 2, 2, 1]],
+ [5, 24, 927, 206, [2, 2, 2, 2, 1, 2, 2, 1]],
+ [6, 21, 927, 148, [10, 10, 9, 8, 2, 8, 8, 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]));
+ 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 alternate vest must retain its distinct appearance and AC contract.
+ await owner.click(927, 148, 'right');
+ await owner.wait('body armor retained', state => owner.local(state).inventory.some(item => item.id === 6 && item.slot >= 48));
+ const vestSequence = observer.sequence;
+ await bagClick(owner, 7);
+ await owner.wait('alternate vest worn', state => owner.local(state).inventory.some(item => item.id === 7 && item.slot === 21));
+ await observer.wait('observer receives alternate vest', () => observer.events.some(event => {
+ if (event.sequence <= vestSequence || event.direction !== 'framereceived' || event.opcode !== '35505644') return false;
+ const packet = Buffer.from(event.hex, 'hex');
+ return packet.readUInt32BE(29) === 85691 && packet.readUInt32BE(45) === 6 && packet.readUInt32BE(53) === 21;
+ }));
+ assert.deepEqual((await state()).armor, [24, 24, 24, 20, 8, 20, 20, 8]);
+ await owner.save(output + '/vest-style');
+ await observer.save(output + '/observer-vest-style');
+ await owner.click(927, 148, 'right');
+ await owner.wait('alternate vest retained', state => owner.local(state).inventory.some(item => item.id === 7 && item.slot >= 48));
+ await bagClick(owner, 6);
+ await owner.wait('body armor restored', state => owner.local(state).inventory.some(item => item.id === 6 && item.slot === 21));
+ assert.deepEqual((await state()).armor, baseline.armor);
+
+ // 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 === 5 && 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, [148, 148, 131, 97, 32, 97, 97, 32]);
+ 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 Agility 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, 196);
+ await owner.click(445, 622);
+ await owner.wait('trained strict thresholds', state => owner.local(state).stats[16] === 244 &&
+ owner.local(state).stats[17] === 269 && owner.local(state).stats[53] === 978);
+ 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, [149, 149, 132, 98, 33, 98, 98, 33]);
+ 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] === 5062);
+ const final = await state();
+ const slots = {1: 27, 2: 30, 3: 23, 4: 25, 5: 68, 6: 21, 7: 67, 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 = {85691: [85691, 22004], 85516: [85516, 22301], 85641: [85641, 22116],
+ 85745: [85745, 21929], 85598: [85598, 22178], 85692: [85692, 22026]};
+ 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: Kevlar 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_kevlar_cold.mjs b/tools/client/test_kevlar_cold.mjs
@@ -0,0 +1,52 @@
+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 ['kevlar-owner', 'kevlar-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();
+ await page.waitForFunction(() => touchRegion(500, 400)?.world === true);
+ await game.snapshot();
+ }
+ const [owner, observer] = games;
+ if (!observer.state.camera.firstPerson) await observer.key('F8');
+ await observer.wait('retained armor wearer is visible', state => state.actors.some(actor => actor.id === 1 &&
+ actor.screenPosition?.[0] > 0 && actor.screenPosition[0] < 1024 && actor.screenPosition[1] > 0 &&
+ actor.screenPosition[1] < 748 && actor.screenPosition[2] >= 0 && actor.screenPosition[2] <= 1));
+ 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, 27, 2, 85516, 22301, 1], [2, 30, 2, 85641, 22116, 1],
+ [3, 23, 2, 85745, 21929, 1], [4, 25, 2, 85745, 21929, 1],
+ [5, 52, 2, 85598, 22178, 1], [6, 21, 2, 85692, 22026, 1],
+ [7, 51, 2, 85691, 22004, 1], [9, 24, 101, 85598, 22178, 1],
+ [10, 50, 200, 22178, 22178, 1],
+ ]);
+ assert.equal(owner.local().stats[16], 244);
+ assert.equal(owner.local().stats[17], 269);
+ assert.equal(owner.local().stats[53], 978);
+ assert.equal(owner.local().stats[61], 5062);
+ 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 Kevlar 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(); }
+}