aorecomp

Anarchy Online classic in the browser

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


commit 6b4b0f35ba90f1162905dc7e5b32ae19e6fbd5f9
parent a2c7f0331d85d5ec3f022b831f3d32f7d738f5e0
Author: anon <anon@example.com>
Date:   Mon,  2 Nov 2026 21:39:51 +0000

Support selected qualities for early M-10 pistol tiers

Diffstat:
MTODO.md | 5+++++
Mdocs/catalog-weapons.md | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Aserver/browser_m10_test.go | 143+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/gamedata/item_families.yaml | 4+++-
Mserver/gamedata/item_quality_test.go | 1+
Mserver/weapon_quality_lifecycle_test.go | 28++++++++++++++++++++++------
Mserver/weapon_quality_test.go | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Atools/client/test_m10.mjs | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 414 insertions(+), 41 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -364,6 +364,11 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). one energy shot, rejected QL125 wear, exactly-once LIZARD effects and fresh-server recovery. Fixed QL180 DRAGON stays separate; historical acquisition remains open. See [Vektor contracts](docs/vektor-shotguns.md). + Two further audited M-10 pistol pairs now admit QL12..21 and QL22..37, + fixing qualified QL13 rejection through the shared path. Public-handler and + short two-client native checks cover strict Pistol/Fling gates, selected + damage/timing, Bullets, pickup, wear/removal, sale and exact cold ownership. + Acquisition remains open; see [M-10 contracts](docs/catalog-weapons.md#reviewed-shortened-and-regular-m-10-qualities). Six regular Steel-Ribbed pairs now use the shared QL1..200 path after complete original descriptor audits, fixing qualified selected-quality wear rejection. Public-handler and short two-client WASM checks cover strict Sense/Agility diff --git a/docs/catalog-weapons.md b/docs/catalog-weapons.md @@ -11,7 +11,7 @@ profession, breed, sex, side and race. Other predicate forms remain open. The existing combat calculations read damage, protection type, range, attack skill weights, initiative, attack/recharge delay and overequipping thresholds from the quality-adjusted instance. This enables the original Baseballbat, Oak -Bo, Meta Shield and five solar guns, plus the reviewed Rusty pistol family below. +Bo, Meta Shield and five solar guns, plus the reviewed M-10 pistol intervals below. Left-hand scheduling, dual wield, wider endpoint families, original critical/hit selection and unimplemented item functions remain separate work; [critical outcomes](critical-hits.md) now have a provisional shared path. @@ -49,7 +49,7 @@ The original lifetime evidence is retained in Rusty OT M-10 Flechette Pistol uses explicit endpoints 123742 (QL1) and 123743 (QL11). Either stored endpoint accepts QL1..11; QL0 and QL12 are rejected. No -name or adjacent-ID inference admits the Shortened or higher pistol tiers. +name or adjacent-ID inference admits an unreviewed higher pistol tier. The original payload audit fully decodes both records, including all sections, requirements and presentation descriptors. All layouts align; only quality, value, MultiRanged, maximum damage, critical bonus and two wear thresholds vary. @@ -170,6 +170,75 @@ Fling keeps its [pre-15.5.5 special prototype](fling-shot.md), with no round consumption and a persistent shared lock. Other advertised specials still need their own rules and outcomes. +## Reviewed Shortened and regular M-10 qualities + +Two additional explicit endpoint pairs extend the shared pistol path: +123744/123745 (Shortened, QL12..21) and 123746/123747 (regular, QL22..37). +Before admission, qualified QL13 wear failed at the public inventory handler; +the retained failing regression is in `local/m10-quality/red-qualified-wear.log`. +The production change consists of two rows in `item_families.yaml`. Later M-10.3 +and Nano tiers retain their separate, unreviewed intervals. + +An independent read of all six original resource payloads, including Rusty, +matches the exported records and retains their hashes. Complete within-pair +headers, scalar membership, sections, requirements and presentation functions +align. Only audited numeric properties and Pistol/Fling thresholds differ. +This supports the explicit pairing; it is not a recovered server family table. +The [current AO Index](https://www.aoindex.com/items/page/62) independently lists +these intervals but does not establish period values or acquisition. + +| Interval / QL | Damage | Critical | Attack/recharge (cs) | Minimum Pistol/Fling | Value | +| --- | --- | ---: | ---: | --- | ---: | +| Shortened / 12 | 3-21 | 16 | 125 | 56 / 31 | 3853 | +| Shortened / 13 | 3-22 | 16 | 125 | 61 / 33 | 3894 | +| Shortened / 16 | 3-25 | 17 | 125 | 74 / 40 | 4512 | +| Shortened / 17 | 4-25 | 18 | 124 | 79 / 42 | 4884 | +| Shortened / 21 | 4-29 | 19 | 124 | 97 / 51 | 7195 | +| Regular / 22 | 4-30 | 19 | 124 | 102 / 54 | 7683 | +| Regular / 23 | 4-31 | 19 | 124 | 107 / 56 | 7727 | +| Regular / 29 | 4-36 | 21 | 124 | 134 / 70 | 9881 | +| Regular / 30 | 4-36 | 22 | 124 | 138 / 72 | 10554 | +| Regular / 37 | 4-42 | 24 | 124 | 170 / 88 | 17780 | + +All retain a 20-Bullet magazine, Projectile damage, 22m range, 150cs equip delay, +Pistol attack, Dodge Ranged defense and Ranged Initiative. Minimum skills include +the strict greater-than rule. Existing quality interpolation preserves both +selected properties and the native nearer-endpoint override packet. No new +OnWear, OnHit or Use gameplay function is introduced. + +The expanded existing weapon tests cover both stored anchors at the interval +ends, neighbors and rounding/midpoint boundaries. Public handlers check strict +skill rejection, exact selected stats, immutable catalog data, owner/observer +packets, attack/recharge cadence, normal/Fling damage, ammunition and reloads. +Controlled QL13/30 drops follow their exact instances through pickup, rejected +wear, wear/remove/rewear, cancelled/accepted/repeated sales and cold ownership. +At the fixture's shop skills, final wallets are 195 and 528 credits respectively. + +`TestBrowserM10Qualities` uses a controlled level-100 Adventurer and two real +WASM clients. Its abilities 200 contribute 49 effective skill points through the +existing float32 calculation: raw Pistol 351/Fling 23 give effective 400/72. +Native inventory input wears/removes QL13 and QL17, then wears QL30 and refuses +QL37 with the displayed minimum Fling 88. An actual ammo-on-weapon request loads +20 Bullets; one normal shot deals 72 Projectile damage, leaving 19 loaded and 80 +carried rounds. Both clients show the same target HP 9928 from a controlled 10000 HP +checkpoint. All five exact item identities, slots, QLs and ammunition survive +page replay and two fresh clients after the warm server closes. This verifies +item contracts, not earned progression or original creature balance. + +The native check passes in 98.16s (warm 63.37s, cold 34.78s); both clients' final +traces contain no errors. The independent verifier compares all six original +payload hashes and exact native/durable page/cold ledgers. Reports and reviewed +screenshots: `local/m10-quality/20261102-133343/`. The focused normal Go checks +pass in 26.742s (server) and 7.634s (gamedata); the expanded race selection +passes in 174.372s/97.482s, and vet passes. The published client is unchanged. + +Historical shop, mission-reward and creature-drop membership remain unverified; +these selections are unchanged. A self-dated +[February 2002 pistol guide](https://www.geocities.ws/cratpistol/) names the Grand +Master line but supplies no Shortened/regular acquisition contract. Direct Auno +QL13/23 pages were inaccessible during the bounded follow-up. Original audits, +literal expectations and test reports are under `local/m10-quality/`. + ## Verification `server/starter_weapons_test.go` covers all eight starter definitions, every diff --git a/server/browser_m10_test.go b/server/browser_m10_test.go @@ -0,0 +1,143 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "reflect" + "runtime" + "testing" + "time" +) + +func TestBrowserM10Qualities(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for the focused native M-10 check") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/m10-quality", time.Now().Format("20060102-150405")) + t.Chdir(t.TempDir()) + for _, phase := range []string{"warm", "cold"} { + t.Run(phase, func(t *testing.T) { + world := newServer() + t.Cleanup(func() { world.db.Close() }) + var target *character + for _, actor := range world.characters { + if actor.npc && actor.playfield == 950 && actor.monsterData == 17655 && actor.level == 1 && actor.combatProfile != nil && (target == nil || actor.id < target.id) { + target = actor + } + } + if target == nil { + t.Fatal("no Leet for the controlled shot") + } + if phase == "warm" { + for index := 0; index < 2; index++ { + player := world.newCharacter() + player.name = fmt.Sprint("M10", index) + player.position = target.position + player.position[0] -= float32(index * 3) + player.position[2] -= 2 + player.rotation = [4]float32{0, 0, 0, 1} + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint("m10-", index)))) + if index == 0 { + player.level, player.profession, player.appearance, player.aggDef = 100, 6, 0x515, 75 + player.stats.Abilities = characterAbilitiesStats{200, 200, 200, 200, 200, 200} + player.stats.Ranged.Pistol, player.stats.Ranged.FlingShot = 351, 23 + if player.trainingMaximum(112) < 351 || player.trainingMaximum(150) < 23 { + t.Fatal("controlled skills exceed native training caps") + } + pistol, _ := player.effectiveStat(112) + fling, _ := player.effectiveStat(150) + if pistol != 400 || fling != 72 { + t.Fatal("controlled effective Pistol/Fling values differ", pistol, fling) + } + } + player.health, player.nano = player.maximumHealth(), player.maximumNano() + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + } + // Controlled contracts and target HP isolate delivery, not earned progression. + owner := world.characters[1] + for _, item := range []struct{ template, quality uint32 }{ + {123744, 13}, {123745, 17}, {123747, 30}, {123746, 37}, {21605, 1}, + } { + 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[4].Count = 100 + if err := world.saveInventory_locked(owner, owner.inventory); err != nil { + t.Fatal(err) + } + profile := *target.combatProfile + profile.Health = 10000 + target.combatProfile, target.health = &profile, 10000 + world.combatRoll = landedCombatRoll + } + owner, watcher := world.characters[1], world.characters[2] + 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() + json.NewEncoder(w).Encode(map[string]any{"inventory": owner.inventory, "observer": watcher.inventory, + "target": target.id, "health": target.health, "fighting": owner.fighting}) + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 3*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) + world.advanceCombat(now) + case <-ctx.Done(): + return + } + } + }() + defer func() { cancel(); <-stopped }() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_m10.mjs"), host.URL, filepath.Join(output, phase)) + 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) + } + world.mutex.Lock() + defer world.mutex.Unlock() + expected := []ownedItem{ + {ID: 1, Type: 51018, Template: 123744, Quality: 13, Slot: 64, Count: 1}, + {ID: 2, Type: 51018, Template: 123745, Quality: 17, Slot: 65, Count: 1}, + {ID: 3, Type: 51018, Template: 123747, Quality: 30, Slot: 6, Count: 1, Ammo: 19}, + {ID: 4, Type: 51018, Template: 123746, Quality: 37, Slot: 67, Count: 1}, + {ID: 5, Type: 51005, Template: 21605, Quality: 1, Slot: 68, Count: 80}, + } + if !reflect.DeepEqual(owner.inventory.Items, expected) || owner.inventory.Credits != 0 || + len(watcher.inventory.Items) != 0 || watcher.inventory.Credits != 0 || world.nextItem != 5 { + t.Fatal("native wear, shot or cold recovery lost an instance, round or cash") + } + }) + if t.Failed() { + return + } + } +} diff --git a/server/gamedata/item_families.yaml b/server/gamedata/item_families.yaml @@ -11,8 +11,10 @@ - [206730, 206731] # NCU Hacker Interface: docs/tradeskills.md. - [158416, 158417] -# Rusty OT M-10 Flechette Pistol: docs/catalog-weapons.md. +# OT M-10 Flechette pistols: original descriptor audits; docs/catalog-weapons.md. - [123742, 123743] +- [123744, 123745] +- [123746, 123747] # Vektor ND shotguns: original descriptor audits; docs/vektor-shotguns.md. - [124256, 124257] - [124258, 124259] diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go @@ -13,6 +13,7 @@ func TestReviewedItemFamilyQualityRanges(t *testing.T) { {85512, 85511, 1, 200}, {85557, 85556, 1, 200}, {85596, 85595, 1, 200}, {85638, 85637, 1, 200}, {85686, 85685, 1, 200}, {85742, 85741, 1, 200}, {42640, 42641, 1, 400}, {206730, 206731, 50, 150}, {158416, 158417, 1, 200}, {123742, 123743, 1, 11}, + {123744, 123745, 12, 21}, {123746, 123747, 22, 37}, {124256, 124257, 1, 4}, {124258, 124259, 5, 69}, {124260, 124261, 70, 179}, {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}, diff --git a/server/weapon_quality_lifecycle_test.go b/server/weapon_quality_lifecycle_test.go @@ -10,12 +10,20 @@ import ( ) func TestWeaponQualityGeneratedPickupEquipRemoveAndSale(t *testing.T) { - for _, template := range []uint32{123742, 123743} { - t.Run(fmt.Sprint(template), func(t *testing.T) { + for _, scenario := range []struct { + template, quality uint32 + pistol, fling uint16 + credits uint32 + }{ + {123742, 5, 24, 15, 127}, {123743, 5, 24, 15, 127}, + {123744, 13, 61, 33, 195}, {123745, 13, 61, 33, 195}, + {123746, 30, 138, 72, 528}, {123747, 30, 138, 72, 528}, + } { + t.Run(fmt.Sprintf("%d/QL%d", scenario.template, scenario.quality), func(t *testing.T) { world, _ := newKillExperienceWorld(t, "unarmed") // Controlled membership tests delivery, not historical Leet equipment drops. profile := *world.characters[1000000].combatProfile - profile.Loot = []gamedata.NPCLoot{{Template: template, Quality: [2]uint32{5, 5}, Chance: 100}} + profile.Loot = []gamedata.NPCLoot{{Template: scenario.template, Quality: [2]uint32{scenario.quality, scenario.quality}, Chance: 100}} world.characters[1000000].combatProfile = &profile world.combatRoll = func(uint32) uint32 { return 0 } identity := world.nextItem + 1 @@ -34,7 +42,15 @@ func TestWeaponQualityGeneratedPickupEquipRemoveAndSale(t *testing.T) { client := &worldClient{id: 1, conn: &combatTestConn{}, target: true, ready: true} world.clients[1] = client player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} - player.stats.Ranged.Pistol, player.stats.Ranged.FlingShot = 24, 15 + player.stats.Ranged.Pistol, player.stats.Ranged.FlingShot = scenario.pistol-1, scenario.fling + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment != nil || + len(player.inventory.Items) != 1 || player.inventory.Items[0].ID != identity || player.inventory.Items[0].Slot != 64 { + t.Fatal("rejected wear lost the picked-up instance", err) + } + player.stats.Ranged.Pistol++ if err := world.saveUser_locked(player); err != nil { t.Fatal(err) } @@ -48,7 +64,7 @@ func TestWeaponQualityGeneratedPickupEquipRemoveAndSale(t *testing.T) { } world.advanceEquipment(client.equipment.readyAt) cold := newTestInventoryServer(t) - expected := []ownedItem{{ID: identity, Type: 51018, Template: template, Quality: 5, Slot: move[1], Count: 1}} + expected := []ownedItem{{ID: identity, Type: 51018, Template: scenario.template, Quality: scenario.quality, Slot: move[1], Count: 1}} if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) || len(cold.characters[1000000].corpse.items) != 0 || cold.characters[1].inventory.Credits != 1 || cold.nextItem != identity { t.Fatal("pickup, repeated wear or cold recovery lost or duplicated the weapon") @@ -95,7 +111,7 @@ func TestWeaponQualityGeneratedPickupEquipRemoveAndSale(t *testing.T) { cold = newTestInventoryServer(t) for _, current := range []*server{world, cold} { - if len(current.characters[1].inventory.Items) != 0 || current.characters[1].inventory.Credits != 127 || + if len(current.characters[1].inventory.Items) != 0 || current.characters[1].inventory.Credits != scenario.credits || current.characters[1].experience != 100 || current.nextItem != identity { t.Fatal("selected-quality sale lost or repeated value, rewards or an instance", current.characters[1].inventory) } diff --git a/server/weapon_quality_test.go b/server/weapon_quality_test.go @@ -12,18 +12,30 @@ import ( ) func TestWeaponQualityEquipRequiresInterpolatedSkillsAndRecovers(t *testing.T) { - for _, template := range []uint32{123742, 123743} { - for _, scenario := range []struct { - quality, maximum, critical, value, multi uint32 - pistol, fling uint16 - }{ - {1, 12, 12, 2321, 26, 6, 6}, - {2, 13, 12, 2333, 29, 11, 8}, - {5, 15, 13, 2525, 36, 24, 15}, - {6, 16, 14, 2640, 39, 29, 18}, - {10, 19, 15, 3354, 49, 47, 27}, - {11, 20, 15, 3598, 51, 52, 29}, - } { + for _, scenario := range []struct { + low, high, quality, minimum, maximum, critical, delay, value, multi, definition uint32 + pistol, fling uint16 + }{ + {123742, 123743, 1, 3, 12, 12, 125, 2321, 26, 123742, 6, 6}, + {123742, 123743, 2, 3, 13, 12, 125, 2333, 29, 123742, 11, 8}, + {123742, 123743, 5, 3, 15, 13, 125, 2525, 36, 123742, 24, 15}, + {123742, 123743, 6, 3, 16, 14, 125, 2640, 39, 123743, 29, 18}, + {123742, 123743, 10, 3, 19, 15, 125, 3354, 49, 123743, 47, 27}, + {123742, 123743, 11, 3, 20, 15, 125, 3598, 51, 123743, 52, 29}, + {123744, 123745, 12, 3, 21, 16, 125, 3853, 53, 123744, 56, 31}, + {123744, 123745, 13, 3, 22, 16, 125, 3894, 55, 123744, 61, 33}, + {123744, 123745, 16, 3, 25, 17, 125, 4512, 63, 123744, 74, 40}, + {123744, 123745, 17, 4, 25, 18, 124, 4884, 65, 123745, 79, 42}, + {123744, 123745, 20, 4, 28, 19, 124, 6494, 73, 123745, 92, 49}, + {123744, 123745, 21, 4, 29, 19, 124, 7195, 75, 123745, 97, 51}, + {123746, 123747, 22, 4, 30, 19, 124, 7683, 78, 123746, 102, 54}, + {123746, 123747, 23, 4, 31, 19, 124, 7727, 81, 123746, 107, 56}, + {123746, 123747, 29, 4, 36, 21, 124, 9881, 96, 123746, 134, 70}, + {123746, 123747, 30, 4, 36, 22, 124, 10554, 98, 123747, 138, 72}, + {123746, 123747, 36, 4, 41, 24, 124, 16478, 113, 123747, 165, 86}, + {123746, 123747, 37, 4, 42, 24, 124, 17780, 116, 123747, 170, 88}, + } { + for _, template := range [2]uint32{scenario.low, scenario.high} { t.Run(fmt.Sprintf("%d/QL%d", template, scenario.quality), func(t *testing.T) { world, owner := newEquipmentWorld(t) t.Cleanup(func() { world.db.Close() }) @@ -41,7 +53,7 @@ func TestWeaponQualityEquipRequiresInterpolatedSkillsAndRecovers(t *testing.T) { if err != nil { t.Fatal(err) } - catalog, err := json.Marshal([]*gamedata.Item{gamedata.ItemTemplates[123742], gamedata.ItemTemplates[123743]}) + catalog, err := json.Marshal([]*gamedata.Item{gamedata.ItemTemplates[scenario.low], gamedata.ItemTemplates[scenario.high]}) if err != nil { t.Fatal(err) } @@ -73,7 +85,7 @@ func TestWeaponQualityEquipRequiresInterpolatedSkillsAndRecovers(t *testing.T) { world.advanceEquipment(finish) restored := newTestInventoryServer(t).characters[1] weapon := restored.attackWeapon() - afterCatalog, err := json.Marshal([]*gamedata.Item{gamedata.ItemTemplates[123742], gamedata.ItemTemplates[123743]}) + afterCatalog, err := json.Marshal([]*gamedata.Item{gamedata.ItemTemplates[scenario.low], gamedata.ItemTemplates[scenario.high]}) if err != nil { t.Fatal(err) } @@ -81,14 +93,16 @@ func TestWeaponQualityEquipRequiresInterpolatedSkillsAndRecovers(t *testing.T) { if finish.Before(started.Add(1500*time.Millisecond)) || finish.After(started.Add(1550*time.Millisecond)) || !reflect.DeepEqual(restored.inventory.Items, []ownedItem{{ID: 1, Type: 51018, Template: template, Quality: scenario.quality, Slot: 6, Count: 1}}) || weapon == nil || *weapon.Quality != scenario.quality || itemStat(weapon, 285) != scenario.maximum || - itemStat(weapon, 284) != scenario.critical || restored.inventory.Items[0].shopPrice() != scenario.value || + itemStat(weapon, 284) != scenario.critical || itemStat(weapon, 286) != scenario.minimum || + itemStat(weapon, 294) != scenario.delay || itemStat(weapon, 210) != scenario.delay || + restored.inventory.Items[0].shopPrice() != scenario.value || !bytes.Equal(catalog, afterCatalog) { t.Fatalf("selected quality, timing, price, persistence or catalog changed: weapon=%+v items=%+v", weapon, restored.inventory.Items) } - low, high := uint32(123742), uint32(123743) - if scenario.quality == 1 { + low, high := scenario.low, scenario.high + if scenario.quality == *gamedata.ItemTemplates[low].Quality { high = low - } else if scenario.quality == 11 { + } else if scenario.quality == *gamedata.ItemTemplates[high].Quality { low = high } var delivered []byte @@ -109,14 +123,11 @@ func TestWeaponQualityEquipRequiresInterpolatedSkillsAndRecovers(t *testing.T) { for offset := 59; offset < int(binary.BigEndian.Uint16(delivered[6:8]))-4; offset += 8 { stats[binary.BigEndian.Uint32(delivered[offset:])] = binary.BigEndian.Uint32(delivered[offset+4:]) } - definition := uint32(123742) - if scenario.quality >= 6 { - definition = 123743 - } + definition := scenario.definition if stats[23] != definition || binary.BigEndian.Uint32(delivered[55:59]) != uint32(len(stats)+1)*1009 { t.Fatal("remote weapon template or encoded stat count differs", stats) } - for stat, expected := range map[uint32]uint32{74: scenario.value, 134: scenario.multi, 284: scenario.critical, 285: scenario.maximum, 26: 0, 212: 20} { + for stat, expected := range map[uint32]uint32{74: scenario.value, 134: scenario.multi, 284: scenario.critical, 285: scenario.maximum, 286: scenario.minimum, 294: scenario.delay, 210: scenario.delay, 26: 0, 212: 20} { actual, overridden := stats[stat] if !overridden { actual = itemStat(gamedata.ItemTemplates[stats[23]], stat) @@ -131,19 +142,36 @@ func TestWeaponQualityEquipRequiresInterpolatedSkillsAndRecovers(t *testing.T) { } func TestWeaponQualityNormalAndFlingDamageAmmoAndReloadRecover(t *testing.T) { - for _, template := range []uint32{123742, 123743} { - for _, scenario := range []struct { - quality, normal, critical uint32 - }{ - {1, 24, 48}, {2, 26, 50}, {5, 30, 56}, - {6, 32, 60}, {10, 38, 68}, {11, 40, 70}, - } { + for _, scenario := range []struct { + low, high, quality, normal, critical, delay uint32 + }{ + {123742, 123743, 1, 24, 48, 125}, + {123742, 123743, 2, 26, 50, 125}, + {123742, 123743, 5, 30, 56, 125}, + {123742, 123743, 6, 32, 60, 125}, + {123742, 123743, 10, 38, 68, 125}, + {123742, 123743, 11, 40, 70, 125}, + {123744, 123745, 12, 42, 74, 125}, + {123744, 123745, 13, 44, 76, 125}, + {123744, 123745, 16, 50, 84, 125}, + {123744, 123745, 17, 50, 86, 124}, + {123744, 123745, 20, 56, 94, 124}, + {123744, 123745, 21, 58, 96, 124}, + {123746, 123747, 22, 60, 98, 124}, + {123746, 123747, 23, 62, 100, 124}, + {123746, 123747, 29, 72, 114, 124}, + {123746, 123747, 30, 72, 116, 124}, + {123746, 123747, 36, 82, 130, 124}, + {123746, 123747, 37, 84, 132, 124}, + } { + for _, template := range [2]uint32{scenario.low, scenario.high} { for _, critical := range []bool{false, true} { t.Run(fmt.Sprintf("%d/QL%d/critical%v", template, scenario.quality, critical), func(t *testing.T) { world, owner := newRangedWorld(t) player, target, client := world.characters[1], world.characters[1000000], world.clients[1] player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} player.stats.Ranged.Pistol, player.stats.Ranged.FlingShot = 400, 100 + player.stats.Speed.RangedInitiative, player.aggDef = 0, 75 player.inventory.Items[0].Template, player.inventory.Items[0].Quality = template, scenario.quality if err := world.saveUser_locked(player); err != nil { t.Fatal(err) @@ -168,7 +196,12 @@ func TestWeaponQualityNormalAndFlingDamageAmmoAndReloadRecover(t *testing.T) { if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil { t.Fatal(err) } - world.advanceCombat(player.nextAttack) + shotAt := player.nextAttack + world.advanceCombat(shotAt) + if player.rechargeUntil.Sub(shotAt) != time.Duration(scenario.delay)*10*time.Millisecond || + player.nextAttack.Sub(shotAt) != time.Duration(scenario.delay)*20*time.Millisecond { + t.Fatal("selected-quality attack/recharge cadence differs") + } if err := world.handleWeaponSpecial(client, flingShotRequest(1, target.id)[20:]); err != nil { t.Fatal(err) } @@ -202,7 +235,7 @@ func TestWeaponQualityNormalAndFlingDamageAmmoAndReloadRecover(t *testing.T) { reloaded.inventory.Items[0].Ammo != 20 || reloaded.inventory.Items[1].Count != 82 || reloaded.inventory.Items[0].Template != template || reloaded.inventory.Items[0].Quality != scenario.quality || !reloaded.skillLocks[150].Equal(player.skillLocks[150]) || - client.reloadUntil.Before(started.Add(1250*time.Millisecond)) || client.reloadUntil.After(started.Add(1300*time.Millisecond)) { + client.reloadUntil.Before(started.Add(time.Duration(scenario.delay)*10*time.Millisecond)) || client.reloadUntil.After(started.Add(time.Duration(scenario.delay)*10*time.Millisecond+50*time.Millisecond)) { t.Fatalf("selected-quality combat/reload recovery: normal=%d fling=%d HP=%d items=%+v", normal, fling, target.health, reloaded.inventory.Items) } }) diff --git a/tools/client/test_m10.mjs b/tools/client/test_m10.mjs @@ -0,0 +1,104 @@ +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 = [], evidence = {}; +async function bagClick(game, id, button = 'right') { + await game.wait('native equipment action finishes', 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, button); +} +try { + for (const index of [0, 1]) { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'm10-' + index, url}]); + const page = await context.newPage(); + const game = await GameTest.attach(page); + games.push(game); + await page.goto(url); + await game.ready(); + } + const [owner, observer] = games; + const server = async () => (await owner.page.request.get(url + '/test-state')).json(); + evidence.initial = await server(); + if (evidence.initial.inventory.Items[2].Ammo === 0) { + assert.equal(owner.local().stats[112], 351); + assert.equal(owner.local().stats[150], 23); + await owner.key('KeyI'); + await owner.page.keyboard.press('Control+1'); + for (const id of [1, 2, 3]) { + const sequence = observer.sequence; + await bagClick(owner, id); + await owner.wait('selected M-10 worn', state => owner.local(state).inventory.some(item => item.id === id && item.slot === 6)); + await observer.wait('observer receives selected M-10', () => observer.events.some(event => + event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '3b1d2268' && + event.actor[0] === 51018 && event.actor[1] === id)); + evidence['worn' + id] = {native: owner.local().inventory, server: await server()}; + await owner.save(output + '/worn-' + id); + if (id !== 3) { + await owner.click(867, 206, 'right'); + await owner.wait('same M-10 removed', state => owner.local(state).inventory.some(item => item.id === id && item.slot >= 48)); + } + } + const rejected = await server(); + const sequence = owner.sequence; + await bagClick(owner, 4); + await owner.save(output + '/rejected-37'); + assert(!owner.events.some(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24')); + assert.deepEqual((await server()).inventory, rejected.inventory); + + // The actual native ammunition-on-weapon request loads twenty Bullets. + await bagClick(owner, 5, 'left'); + await owner.click(867, 206, 'right'); + await owner.wait('bullet stack debited', state => owner.local(state).inventory.some(item => item.id === 5 && item.count === 80)); + assert.equal((await server()).inventory.Items[2].Ammo, 20); + await owner.wait('native reload completes', state => !owner.local(state).actions.includes(5)); + const before = await server(); + const deadline = Date.now() + 10000; + while (owner.state.selected[0] !== 50000 || owner.state.selected[1] !== before.target) { + assert(Date.now() < deadline, 'Native Tab did not select the controlled Leet'); + const selected = owner.state.selected; + await owner.key('Tab'); + await owner.wait('native target cycle advances', state => state.selected[0] !== selected[0] || state.selected[1] !== selected[1]); + } + const attack = owner.sequence; + await owner.key('KeyQ'); + await owner.wait('one real selected-quality shot', () => owner.events.some(event => event.sequence > attack && + event.direction === 'framereceived' && event.opcode === '46002f16' && event.actor[1] === owner.local().id)); + await owner.key('KeyQ'); + await Promise.all(games.map(game => game.wait('native selected-quality impact', state => + state.actors.some(actor => actor.id === before.target && actor.stats[27] === 9928)))); + evidence.shot = await server(); + assert.equal(evidence.shot.health, 9928); + assert.equal(evidence.shot.inventory.Items[2].Ammo, 19); + assert.equal(evidence.shot.fighting, 0); + await owner.save(output + '/shot'); + await observer.save(output + '/observer-shot'); + await owner.page.reload(); + await owner.ready(); + } + 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, 48, 13, 123744, 123745, 1], [2, 49, 17, 123744, 123745, 1], + [3, 6, 30, 123746, 123747, 1], [4, 51, 37, 123747, 123747, 1], + [5, 52, 1, 21605, 21605, 80], + ]); + assert.equal((await server()).inventory.Items[2].Ammo, 19); + assert.deepEqual(observer.local().inventory, []); + evidence.final = {native: owner.local().inventory, server: await server()}; + assert(games.every(game => game.errors.length === 0)); + console.log('PASS: native M-10 selected qualities, wear/removal, Fling gate, bullet reload, shot and page/cold ownership'); +} finally { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2)); + try { await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); } + finally { await browser.close(); } +}