aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit dd406a93bf95fc52a007d3698de23b761b4d438c
parent fbce36b27bb17f7b9de34de7d116ccea7a7ac9f4
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 21:01:34 +0000

Admit original Omni-Pol armor quality families

Diffstat:
MTODO.md | 7+++++++
Adocs/omni-pol-armor.md | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/browser_omni_pol_test.go | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/gamedata/item_families.yaml | 7+++++++
Mserver/gamedata/item_quality_test.go | 2++
Aserver/omni_pol_armor_test.go | 26++++++++++++++++++++++++++
Aserver/omni_pol_contracts_test.go | 226+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_omni_pol_armor.mjs | 166+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_omni_pol_cold.mjs | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 711 insertions(+), 0 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -440,6 +440,13 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). 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). + Six audited regular Omni-Pol pairs now admit QL1..200, fixing qualified QL2 + glove refusal. Shared handlers retain the original Omni-only gate, both + strict ability thresholds, selected AC/value, pickup, wear/remove, sale and + cold ownership. A controlled two-client WASM fixture verifies every piece, + 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). 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/omni-pol-armor.md b/docs/omni-pol-armor.md @@ -0,0 +1,85 @@ +# Omni-Pol armor qualities + +Six reviewed regular Omni-Pol pairs now admit QL1..200 through the shared +equipment path. Previously, qualified QL2 gloves stayed carried. The fix adds +explicit family data; faction/ability requirements, AC, value, appearance and +native endpoint delivery continue through existing consumers. + +## Original contracts + +All twelve complete resource1000020 payloads freshly reparse from the original +14.9.1 database to the maintained catalog, including hashes, file offsets, +headers, text, functions, appearance and requirements. The index SHA256 is +`46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`. +Raw payloads, full descriptors and comparisons are retained in +`local/omni-pol/original/audit.json` and its adjacent binaries. + +| Piece | QL1 / QL200 templates | Native slot | QL2 base value | +| --- | --- | --- | ---: | +| Pants | 85505 / 22331 | 27 | 1055 | +| Helmet | 85552 / 22246 | 18 | 1266 | +| Gloves | 85591 / 22196 | 24 | 421 | +| Boots | 85631 / 22142 | 30 | 632 | +| Body armor | 85679 / 22064 | 21 | 1689 | +| Sleeves | 85735 / 21955 | 23 or 25 | 421 | + +Within each pair, only stats1/2/54/74, eight Modify53045 AC amounts and two +strict wear thresholds differ. Text changes from Recruit-Issue to Assault-Issue; +text length changes section offsets. All other complete section structures, +requirements and function arguments match. In particular Side33 must equal2 +at both endpoints. Names located candidates; complete contracts establish +pairing. Elite, Forest, Desert and Trooper variants remain separate items. + +Stamina18 and Strength16 must be strictly greater than9/9 at QL1 and540/490 at +QL200. Shared rounding gives thresholds12/11 at QL2,273/248 at QL100 and276/251 +at QL101. QL100 gloves have base value97472, QL101 value99443 and QL200 +value392585. The QL100 eight-AC vector, ordered by stats90..97, is +`[125,125,125,109,109,31,94,31]`. Exact endpoint qualities send the selected +endpoint twice; intermediate qualities retain both reviewed IDs, including +when the stored anchor is numerically smaller than the low-QL template. + +## Acquisition boundary + +The local Fandom mirror's Biomare page lists the same six QL60 armor parts and +credits AoStratics. Its last-touched date is2015, and the linked original guide +could not be retrieved. This is an acquisition lead, without a verified +target-period publication date, exact NPC binding or drop distribution. The +retained text and lookup results are in `local/omni-pol/biomare.txt` and +`fandom.json`. No minimum obtainable QL is established by these fixtures. + +Production shop stock, mission selections and loot membership are unchanged. +The controlled generated pickup verifies selected-quality delivery and retained +ownership, without asserting that the test creature historically dropped this +armor. The separate bounded loot-quality follow-up records remaining evidence +gaps in `local/loot-quality-research/20261103-followup.md`. + +## Focused checks + +The qualified QL2 glove regression fails before the family-data change. Public +handler tests cover both stored anchors at low, intermediate and boundary +qualities; both strict ability equalities; Neutral/Clan refusals; every piece +and both sleeves; all eight ACs and value; native endpoints; generated pickup; +wear/removal; cancelled, accepted and repeated sales; and cold identity recovery. +Four roots and74 results pass in18.577 seconds. The reviewed-family range check +passes189 results in7.563 seconds, and adjacent bag/deletion, loot, reclaim and +pending-wear transaction checks pass four roots/eight results in9.026 seconds. + +The two-client native fixture starts with a complete QL2 set and controlled +level100/abilities/funds. Real clicks remove and re-wear every piece, including +both sleeves, while server AC and observer wear packets are checked. Original +native QL101 equality refuses without a move request; one Strength/Stamina +purchase qualifies it. QL200 remains refused. Native sale cancellation retains +the exact QL100 glove; acceptance sells that instance for5848 credits at the +original Omni armor machine's six-percent rate, leaving5948 credits. +All nine remaining IDs, endpoints, slots,946 IP and the trained252/277 abilities +survive page replay and a fresh-server two-client recovery. The fixture is not +earned-progression or historical-acquisition evidence. + +The accepted native run takes78.23 seconds, with44.73 warm and30.24 cold phases, +and retains13 clean traces under `local/omni-pol/20261103-125823/`. The observer +uses the original F8 first-person control from an explicitly aimed fixture; +both warm and cold checkpoints require the wearer inside its camera. Saved +renders visibly show the complete armor and the5848-credit sale offer. The +combined source/protocol/ownership audit is `local/omni-pol/verification.json`; +vet and both Node syntax checks pass. Earlier fixture identity/quote mistakes +and an interrupted whole-catalog audit are excluded from that verification. diff --git a/server/browser_omni_pol_test.go b/server/browser_omni_pol_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 TestBrowserOmniPolArmorQualities(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for the focused native OmniPol check") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/omni-pol", time.Now().Format("20060102-150405")) + t.Chdir(t.TempDir()) + world := newServerForTest(t) + owner := world.newCharacter() + owner.name, owner.level, owner.appearance = "OmniPolowner", 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 = 276, 251 + owner.stats.ImprovementPoints, owner.inventory.Credits = 2000, 100 + owner.health, owner.nano = owner.maximumHealth(), owner.maximumNano() + owner.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("omni-pol-owner"))) + watcher := world.newCharacter() + watcher.name, watcher.playfield, watcher.position = "OmniPolwatch", 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("omni-pol-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 }{ + {85552, 2, 18}, {85505, 2, 27}, {85631, 2, 30}, + {85735, 2, 23}, {85735, 2, 25}, {85591, 2, 24}, {85679, 2, 21}, + {22196, 100, 64}, {85591, 101, 65}, {85591, 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_omni_pol_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 != 5948 || owner.stats.ImprovementPoints != 946 || + owner.stats.Abilities.Stamina != 277 || owner.stats.Abilities.Strength != 252 || len(watcher.inventory.Items) != 0 { + t.Fatal("native armor contract lost ownership, selected-quality price or trained abilities") + } + }) + if t.Failed() { + return + } + t.Run("cold", func(t *testing.T) { + cold := newServerForTest(t) + for _, player := range []*character{owner, watcher} { + // Loaded inventory views share the world's last allocated item identity. + expected := player.inventory + expected.LastID = 10 + if !reflect.DeepEqual(expected, cold.characters[player.id].inventory) || player.stats != cold.characters[player.id].stats { + t.Fatal("completed armor contract changed on cold loading", player.id) + } + } + for index, armor := range [8]int32{156, 156, 156, 138, 138, 41, 120, 41} { + 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_omni_pol_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 @@ -116,3 +116,10 @@ - [120588, 142686] - [120589, 142688] - [120590, 142690] +# Omni-Pol armor: complete original descriptor audit; docs/omni-pol-armor.md. +- [85505, 22331] +- [85552, 22246] +- [85591, 22196] +- [85631, 22142] +- [85679, 22064] +- [85735, 21955] diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go @@ -43,6 +43,8 @@ func TestReviewedItemFamilyQualityRanges(t *testing.T) { {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}, + {85505, 22331, 1, 200}, {85552, 22246, 1, 200}, {85591, 22196, 1, 200}, + {85631, 22142, 1, 200}, {85679, 22064, 1, 200}, {85735, 21955, 1, 200}, } { for _, template := range [2]uint32{family.lowTemplate, family.highTemplate} { t.Run(fmt.Sprint(template), func(t *testing.T) { diff --git a/server/omni_pol_armor_test.go b/server/omni_pol_armor_test.go @@ -0,0 +1,26 @@ +package main + +import "testing" + +func TestOmniPolIntermediateQualityCanBeWorn(t *testing.T) { + world, _ := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + player.appearance = 0x515 + player.stats.Abilities.Stamina, player.stats.Abilities.Strength = 13, 12 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, 85591); 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 Omni-Pol QL2 gloves did not start wear", err) + } +} diff --git a/server/omni_pol_contracts_test.go b/server/omni_pol_contracts_test.go @@ -0,0 +1,226 @@ +package main + +import ( + "ao/server/gamedata" + "bytes" + "encoding/binary" + "fmt" + "slices" + "testing" +) + +func TestOmniPolGeneratedPickupKeepsSelectedQuality(t *testing.T) { + world, output := newKillExperienceWorld(t, "unarmed") + player, client := world.characters[1], world.clients[1] + player.appearance = 0x515 + player.stats.Abilities.Stamina, player.stats.Abilities.Strength = 274, 249 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + // Controlled membership tests delivery, not historical OmniPol creature drops. + profile := *world.characters[1000000].combatProfile + profile.Loot = []gamedata.NPCLoot{{Template: 22196, 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, 85591, 22196, 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: 22196, 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 TestOmniPolArmorQualitiesWearRemoveAndRecover(t *testing.T) { + for _, scenario := range []struct { + low, high, slot, quality, value uint32 + stamina, strength uint16 + armor [8]int32 + }{ + {85505, 22331, 27, 1, 1031, 9, 9, [8]int32{3, 3, 3, 3, 3, 1, 3, 1}}, + {85505, 22331, 27, 2, 1055, 12, 11, [8]int32{6, 6, 6, 6, 6, 2, 5, 2}}, + {85505, 22331, 27, 20, 9968, 60, 55, [8]int32{62, 62, 62, 55, 55, 16, 47, 16}}, + {85505, 22331, 27, 100, 243682, 273, 248, [8]int32{312, 312, 312, 273, 273, 78, 234, 78}}, + {85505, 22331, 27, 200, 981463, 540, 490, [8]int32{625, 625, 625, 546, 546, 156, 468, 156}}, + {85552, 22246, 18, 1, 1237, 9, 9, [8]int32{3, 3, 3, 3, 3, 1, 3, 1}}, + {85552, 22246, 18, 2, 1266, 12, 11, [8]int32{7, 7, 7, 6, 6, 2, 6, 2}}, + {85552, 22246, 18, 20, 11962, 60, 55, [8]int32{74, 74, 74, 65, 65, 19, 56, 19}}, + {85552, 22246, 18, 100, 292417, 273, 248, [8]int32{375, 375, 375, 328, 328, 94, 281, 94}}, + {85552, 22246, 18, 200, 1177756, 540, 490, [8]int32{750, 750, 750, 656, 656, 187, 562, 187}}, + {85591, 22196, 24, 1, 412, 9, 9, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}}, + {85591, 22196, 24, 2, 421, 12, 11, [8]int32{2, 2, 2, 2, 2, 1, 2, 1}}, + {85591, 22196, 24, 20, 3987, 60, 55, [8]int32{25, 25, 25, 22, 22, 7, 19, 7}}, + {85591, 22196, 24, 100, 97472, 273, 248, [8]int32{125, 125, 125, 109, 109, 31, 94, 31}}, + {85591, 22196, 24, 101, 99443, 276, 251, [8]int32{126, 126, 126, 110, 110, 32, 94, 32}}, + {85591, 22196, 24, 199, 388652, 537, 488, [8]int32{249, 249, 249, 217, 217, 62, 186, 62}}, + {85591, 22196, 24, 200, 392585, 540, 490, [8]int32{250, 250, 250, 218, 218, 62, 187, 62}}, + {85631, 22142, 30, 1, 618, 9, 9, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}}, + {85631, 22142, 30, 2, 632, 12, 11, [8]int32{3, 3, 3, 3, 3, 1, 2, 1}}, + {85631, 22142, 30, 20, 5980, 60, 55, [8]int32{37, 37, 37, 32, 32, 10, 28, 10}}, + {85631, 22142, 30, 100, 146208, 273, 248, [8]int32{187, 187, 187, 164, 164, 47, 140, 47}}, + {85631, 22142, 30, 200, 588878, 540, 490, [8]int32{375, 375, 375, 328, 328, 93, 281, 93}}, + {85679, 22064, 21, 1, 1650, 9, 9, [8]int32{5, 5, 5, 5, 5, 1, 5, 1}}, + {85679, 22064, 21, 2, 1689, 12, 11, [8]int32{10, 10, 10, 9, 9, 2, 9, 2}}, + {85679, 22064, 21, 20, 15950, 60, 55, [8]int32{100, 100, 100, 88, 88, 25, 76, 25}}, + {85679, 22064, 21, 100, 389891, 273, 248, [8]int32{500, 500, 500, 438, 438, 125, 376, 125}}, + {85679, 22064, 21, 200, 1570342, 540, 490, [8]int32{1000, 1000, 1000, 875, 875, 250, 750, 250}}, + {85735, 21955, 25, 1, 412, 9, 9, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}}, + {85735, 21955, 25, 2, 421, 12, 11, [8]int32{2, 2, 2, 2, 2, 1, 2, 1}}, + {85735, 21955, 23, 2, 421, 12, 11, [8]int32{2, 2, 2, 2, 2, 1, 2, 1}}, + {85735, 21955, 25, 20, 3987, 60, 55, [8]int32{25, 25, 25, 22, 22, 7, 19, 7}}, + {85735, 21955, 25, 100, 97472, 273, 248, [8]int32{125, 125, 125, 109, 109, 31, 94, 31}}, + {85735, 21955, 25, 200, 392585, 540, 490, [8]int32{250, 250, 250, 218, 218, 62, 187, 62}}, + } { + 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.appearance = 0x515 + 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 + } + for _, side := range []uint16{0, 1} { + player.appearance = 0x115 | side<<9 + if err := world.handleInventory(client, inventoryMovePacket(1, 65, scenario.slot)[20:]); err != nil || client.equipment != nil || player.inventory.Items[1].Slot != 65 { + t.Fatal("non-Omni character equipped or lost faction armor", side, err) + } + } + player.appearance = 0x515 + 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 TestOmniPolSaleCancellationAndReplayKeepSelectedQuality(t *testing.T) { + for _, scenario := range []struct{ quality, sale uint32 }{ + {2, 21}, {100, 4873}, {101, 4972}, {200, 19629}, + } { + 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, 85591); 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_omni_pol_armor.mjs b/tools/client/test_omni_pol_armor.mjs @@ -0,0 +1,166 @@ +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 ['omni-pol-owner', 'omni-pol-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, [32, 32, 32, 30, 30, 10, 28, 10]); + await owner.key('KeyI'); + await owner.page.keyboard.press('Control+1'); + await owner.click(953, 53); + await owner.page.keyboard.press('Control+9'); + await owner.save(output + '/initial'); + + // Every piece uses native removal and wear, with explicit left-arm placement. + for (const [id, slot, x, y, armor] of [ + [1, 18, 927, 94, [7, 7, 7, 6, 6, 2, 6, 2]], + [2, 27, 927, 262, [6, 6, 6, 6, 6, 2, 5, 2]], + [3, 30, 927, 316, [3, 3, 3, 3, 3, 1, 2, 1]], + [4, 23, 867, 206, [2, 2, 2, 2, 2, 1, 2, 1]], + [5, 25, 987, 206, [2, 2, 2, 2, 2, 1, 2, 1]], + [6, 24, 927, 206, [2, 2, 2, 2, 2, 1, 2, 1]], + [7, 21, 927, 148, [10, 10, 10, 9, 9, 2, 9, 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 high stored endpoint must still deliver the selected QL100 contract. + await owner.click(927, 206, 'right'); + await owner.wait('QL2 gloves retained', state => owner.local(state).inventory.some(item => item.id === 6 && item.slot >= 48)); + await bagClick(owner, 8); + await owner.wait('QL100 gloves worn', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot === 24)); + assert.deepEqual((await state()).armor, [155, 155, 155, 137, 137, 40, 120, 40]); + 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] === 252 && + owner.local(state).stats[18] === 277 && owner.local(state).stats[53] === 946); + await bagClick(owner, 9); + await owner.wait('QL101 gloves worn', state => owner.local(state).inventory.some(item => item.id === 9 && item.slot === 24)); + assert.deepEqual((await state()).armor, [156, 156, 156, 138, 138, 41, 120, 41]); + 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] === 5948); + 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 = {85552: [85552, 22246], 85505: [85505, 22331], 85631: [85631, 22142], + 85735: [85735, 21955], 85591: [85591, 22196], 85679: [85679, 22064]}; + 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: OmniPol 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_omni_pol_cold.mjs b/tools/client/test_omni_pol_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 ['omni-pol-owner', 'omni-pol-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, 18, 2, 85552, 22246, 1], [2, 27, 2, 85505, 22331, 1], + [3, 30, 2, 85631, 22142, 1], [4, 23, 2, 85735, 21955, 1], + [5, 25, 2, 85735, 21955, 1], [6, 51, 2, 85591, 22196, 1], + [7, 21, 2, 85679, 22064, 1], [9, 24, 101, 85591, 22196, 1], + [10, 50, 200, 22196, 22196, 1], + ]); + assert.equal(owner.local().stats[16], 252); + assert.equal(owner.local().stats[18], 277); + assert.equal(owner.local().stats[53], 946); + assert.equal(owner.local().stats[61], 5948); + 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 OmniPol 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(); } +}