commit 731d8377e879260547a685646605a75b82baf7a5
parent 825c28c2b7f9e1ff553b4bb99af1638896a2c3bd
Author: anon <anon@example.com>
Date: Mon, 2 Nov 2026 18:59:43 +0000
Admit original Vektor shotgun quality intervals
Diffstat:
7 files changed, 666 insertions(+), 1 deletion(-)
diff --git a/TODO.md b/TODO.md
@@ -357,6 +357,13 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
and cold ownership. A short controlled two-client WASM run covers both sleeves,
QL100/101 training, cancellation/acceptance and fresh-server native recovery.
Original acquisition remains open; see [Bau Cyber contracts](docs/bau-cyber-armor.md).
+ Three audited Vektor pairs now admit QL1..4, 5..69 and 70..179, fixing qualified
+ QL2 wear rejection. Public-handler tests cover strict Shotgun gates, selected
+ damage/timing/value, energy-ammo reloads, Psychic bonuses, pickup, sale and cold
+ identity. A short controlled two-client WASM check verifies all three intervals,
+ 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).
- [x] Admit the complete Low-Tech armor set through shared quality and shop data.
Eight explicit original pairs cover QL1..200, including alternate body and leg
styles and independent sleeves. All three basic armor factions offer the
diff --git a/docs/vektor-shotguns.md b/docs/vektor-shotguns.md
@@ -0,0 +1,89 @@
+# Vektor ND selected qualities
+
+The P0 equipment-quality defect was a qualified QL2 Sparking Vektor refusing
+wear: its original definitions existed, but the shared reviewed-family table
+admitted only exact endpoints. Three explicit pairs now cover the original
+regular line. DRAGON remains a separate fixed-quality record.
+
+| Name | Low/high templates | QL | Shotgun requirement |
+| --- | --- | --- | --- |
+| Sparking Vektor ND Shotgun | 124256 / 124257 | 1..4 | >5 .. >19 |
+| Vektor ND Shotgun | 124258 / 124259 | 5..69 | >23 .. >319 |
+| Vektor ND LIZARD Shotgun | 124260 / 124261 | 70..179 | >324 .. >828 |
+| Vektor ND DRAGON Shotgun | 124262 / 124262 | 180 only | >833 |
+
+All use the right hand, Shotgun attack rating, Duck Exp defense, Energy AC
+damage, Ranged Initiative, a 40-round energy-ammo clip, 26m range, 3.5s equip
+and 2.5s recharge. Attack delay decreases from 2.50s to 2.32s across the line.
+There is no Fling Shot flag. LIZARD adds 15 Psychic and DRAGON adds 25; the
+smaller forms add none. The shared effect consumers apply and remove these
+bonuses and their derived resource/skill contributions.
+
+## Evidence and boundaries
+
+Each complete catalog descriptor was compared with its original type-1000020
+payload in `anarchy-vanilla-14.9.1`, including every section and function.
+Within each pair, header, text, stat keys, attack/defense weights, presentation
+functions and wear effects match. Differences are limited to QL54, value74,
+damage284/285/286, attack294 and the single action-8 strict Shotgun115 threshold.
+This establishes compatible authored endpoints, rather than pairing by name
+or numeric proximity. The original index SHA256 is
+`46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`.
+Raw payloads and the complete audit are retained in
+`local/vektor-quality/original/`.
+
+The current Auno pages independently show [QL1..4](https://auno.org/ao/db.php?id=124256&ql=2),
+[QL5..69](https://auno.org/ao/db.php?id=124258&ql=37) and
+[QL70..179](https://auno.org/ao/db.php?id=124260&ql=125), with energy ammo and
+the LIZARD Psychic bonus. These corroborate the intervals, not original server
+acquisition or later database additions. For example, Auno displays QL37 value
+30326; the native 14.9.1 value curve gives 16468.
+The existing shared interpolation follows `kkr.dll` `FUN_100eff20`,
+`FUN_100f0c80`, `FUN_100f1320` and `FUN_100894c0`; see
+[catalog weapons](catalog-weapons.md).
+
+Historical shop/mission/drop membership and level-relative distributions
+remain unresolved. This change does not add production stock, loot or reward
+rules. QL180 is not an extension of the LIZARD pair, and no QL181..200 form is
+invented.
+
+## Focused verification
+
+`TestVektorQualitiesWearRemoveAndRecover` covers both stored anchors at the
+interval endpoints, immediate neighbors and rounding/midpoint cases, plus the
+fixed DRAGON. Public inventory handlers reject strict threshold equality,
+retain the source row until the equip deadline, then deliver exact selected
+stats and endpoints to owner and observer. Repeated removal/re-wear and cold
+loading preserve identity, price and exactly-once Psychic effects without
+mutating catalog definitions.
+
+`TestVektorSelectedDamageAndEnergyReload` exercises normal and critical shots
+at QL2/37/75/125/180. Bullets and shotgun shells are rejected; energy ammo
+transfers exactly 40 rounds, saves the 2.5s deadline and loses one round on a
+successful shot. `TestVektorGeneratedPickupCancellationAndSale` covers each
+interval through controlled loot generation, repeated pickup, cancelled sale,
+accepted/replayed sale and cold ownership. The fixture is not evidence for
+historical creature drop membership.
+
+`TestBrowserVektorQualities` uses two actual WASM clients and the maintained
+`GameTest` harness. Its level-100 Trader, abilities, weapons, ammo and durable
+10000 HP Leet checkpoint are controlled fixtures, not earned progression or
+original NPC growth evidence. Native inventory clicks wear/remove QL2, QL37
+and QL75 weapons. Energy ammo loads 40 rounds from a 100-round stack. One real
+QL37 shot deals 168 energy damage, leaves 39 loaded/60 carried rounds and
+reaches HP 9832 on both clients. Native Tab selects the checkpoint; a reconnect
+ends its retaliation before removal, since active-combat equipment swapping
+remains a separate TODO.
+
+QL125 wear is rejected locally with the native requirement of Shotgun 579.
+QL75 LIZARD displays Psychic 215 from base 200; removal restores the baseline,
+re-wear adds precisely 15 again, and the native nano foundation changes by 9.
+Page reload and two fresh clients on a cold server retain all seven exact
+instances, counts, selected endpoints and the worn LIZARD. The Go cold check
+also verifies the carried QL37 weapon's 39 rounds and the 60-round energy stack.
+No adapter/page errors occurred. The complete native check took 80.82s; screenshots
+and traces are under `local/game-tests/vektor-20261102-105724/`.
+
+Focused Go regressions passed in 25.123s, with race checks in 129.887s; gamedata
+checks and `go vet` also passed. The checked-in WASM was unchanged (compressed
+SHA256 `ed91fa13f9f137db8bd3f8e21618be9f4f9c0894119d3e4bb8b6b204f9c6dce0`).
diff --git a/server/browser_vektor_test.go b/server/browser_vektor_test.go
@@ -0,0 +1,145 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "reflect"
+ "runtime"
+ "testing"
+ "time"
+)
+
+func TestBrowserVektorQualities(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for the controlled WASM Vektor regression")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/game-tests", "vektor-"+time.Now().Format("20060102-150405"))
+ world := newTestServer(t)
+ 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")
+ }
+ owner := world.newCharacter()
+ owner.name, owner.level, owner.profession, owner.appearance = "Vektorowner", 100, 7, 0x315
+ owner.position = target.position
+ owner.position[2] -= 2
+ owner.rotation = [4]float32{0, 0, 0, 1}
+ owner.stats.Abilities = characterAbilitiesStats{200, 200, 200, 200, 200, 200}
+ owner.stats.Ranged.Shotgun, owner.aggDef = 300, 75
+ owner.health, owner.nano = owner.maximumHealth(), owner.maximumNano()
+ owner.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("vektor-owner")))
+ if owner.trainingMaximum(115) < 300 {
+ t.Fatal("controlled Shotgun fixture exceeds the native training cap")
+ }
+ watcher := world.newCharacter()
+ watcher.name, watcher.position = "Vektorwatch", target.position
+ watcher.position[0] -= 3
+ watcher.position[2] -= 5
+ watcher.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("vektor-watch")))
+ for _, player := range []*character{owner, watcher} {
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.savePosition_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ // Seed legal selected-quality weapons and ammunition, not earned progression.
+ for _, item := range []struct{ template, quality uint32 }{
+ {124256, 2}, {124259, 37}, {124261, 75}, {124260, 125}, {21609, 1}, {21605, 1}, {21613, 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
+ }
+ for index := 4; index < 7; index++ {
+ owner.inventory.Items[index].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
+ 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, "psychic": owner.equipmentBonus(21),
+ "target": target.id, "health": target.health, "recharge": owner.rechargeUntil, "fighting": owner.fighting})
+ })
+ host := httptest.NewServer(mux)
+ defer 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(50 * 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_vektor.mjs"), host.URL, output, "live")
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ err := command.Run()
+ cancel()
+ <-stopped
+ t.Logf("Browser artifacts: %s", output)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := world.flushWorld(); err != nil {
+ t.Fatal(err)
+ }
+ host.Close()
+ if err := world.db.Close(); err != nil {
+ t.Fatal(err)
+ }
+ cold := newServer()
+ defer cold.db.Close()
+
+ if !reflect.DeepEqual(owner.inventory, cold.characters[owner.id].inventory) || owner.equipmentBonus(21) != 15 ||
+ cold.characters[owner.id].equipmentBonus(21) != 15 || owner.inventory.Items[1].Ammo != 39 || owner.inventory.Items[4].Count != 60 {
+ t.Fatal("cold weapon identity, loaded rounds, energy stack or Psychic bonus differs")
+ }
+ coldHost := httptest.NewServer(cold.httpHandler())
+ defer coldHost.Close()
+ closeTestBrowserStreams(t, cold)
+ coldContext, coldCancel := context.WithTimeout(context.Background(), time.Minute)
+ defer coldCancel()
+ command = exec.CommandContext(coldContext, "node", filepath.Join(root, "tools/client/test_vektor.mjs"), coldHost.URL, filepath.Join(output, "cold"), "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
@@ -13,6 +13,10 @@
- [158416, 158417]
# Rusty OT M-10 Flechette Pistol: docs/catalog-weapons.md.
- [123742, 123743]
+# Vektor ND shotguns: original descriptor audits; docs/vektor-shotguns.md.
+- [124256, 124257]
+- [124258, 124259]
+- [124260, 124261]
# Unbalanced Advanced Baseballbat: original payload audit; docs/early-melee.md.
- [122691, 122692]
# Monster Parts: complete original descriptor audit; docs/npc-loot.md.
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},
+ {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},
{85481, 85690, 1, 200}, {85521, 85520, 1, 200}, {85562, 85561, 1, 200}, {85602, 85601, 1, 200},
@@ -47,7 +48,8 @@ func TestUnreviewedItemQualityRemainsExact(t *testing.T) {
for _, entry := range []struct {
template, quality uint32
supported bool
- }{{209283, 1, true}, {209283, 2, false}, {85557, 0, false}, {161966, 200, true}, {161966, 199, false}, {4294967295, 1, false}} {
+ }{{209283, 1, true}, {209283, 2, false}, {85557, 0, false}, {161966, 200, true}, {161966, 199, false},
+ {124262, 180, true}, {124262, 179, false}, {124262, 181, false}, {4294967295, 1, false}} {
t.Run(fmt.Sprintf("%d/%d", entry.template, entry.quality), func(t *testing.T) {
got := gamedata.ItemQualitySupported(entry.template, entry.quality)
diff --git a/server/vektor_quality_test.go b/server/vektor_quality_test.go
@@ -0,0 +1,289 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "bytes"
+ "encoding/binary"
+ "encoding/json"
+ "fmt"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestVektorQualitiesWearRemoveAndRecover(t *testing.T) {
+ for _, scenario := range []struct {
+ low, high, quality uint32
+ threshold uint16
+ minimum, maximum, critical, attack uint32
+ value uint32
+ psychic int32
+ }{
+ {124256, 124257, 1, 5, 4, 15, 25, 250, 2373, 0},
+ {124256, 124257, 2, 10, 4, 17, 29, 250, 2388, 0},
+ {124256, 124257, 3, 14, 4, 19, 34, 250, 2436, 0},
+ {124256, 124257, 4, 19, 4, 21, 38, 250, 2515, 0},
+ {124258, 124259, 5, 23, 4, 23, 43, 250, 2610, 0},
+ {124258, 124259, 6, 28, 4, 25, 47, 250, 2623, 0},
+ {124258, 124259, 36, 166, 5, 87, 179, 247, 15615, 0},
+ {124258, 124259, 37, 171, 5, 90, 184, 247, 16468, 0},
+ {124258, 124259, 68, 314, 6, 154, 320, 243, 56323, 0},
+ {124258, 124259, 69, 319, 6, 156, 324, 243, 58042, 0},
+ {124260, 124261, 70, 324, 6, 158, 328, 243, 59679, 15},
+ {124260, 124261, 71, 329, 6, 160, 332, 243, 59705, 15},
+ {124260, 124261, 75, 347, 6, 168, 350, 242, 60353, 15},
+ {124260, 124261, 124, 574, 7, 270, 566, 238, 138395, 15},
+ {124260, 124261, 125, 578, 7, 272, 570, 237, 141338, 15},
+ {124260, 124261, 178, 823, 8, 382, 804, 232, 374544, 15},
+ {124260, 124261, 179, 828, 8, 384, 808, 232, 380402, 15},
+ {124262, 124262, 180, 833, 8, 386, 812, 232, 384650, 25},
+ } {
+ for _, anchor := range slices.Compact([]uint32{scenario.low, scenario.high}) {
+ t.Run(fmt.Sprintf("%d/QL%d", anchor, scenario.quality), func(t *testing.T) {
+ world, output := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: 950, health: 100}
+ world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true}
+ player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ player.stats.Ranged.Shotgun = scenario.threshold
+ player.aggDef = 75
+ player.stats.Speed.RangedInitiative = 0
+ player.inventory.Items[0].Template, player.inventory.Items[0].Quality = anchor, scenario.quality
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ catalog, err := json.Marshal([]*gamedata.Item{gamedata.ItemTemplates[scenario.low], gamedata.ItemTemplates[scenario.high]})
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment != nil {
+ t.Fatal("Shotgun threshold equality equipped", err)
+ }
+ if after, err := readTestItemStore(world); err != nil || !bytes.Equal(before, after) {
+ t.Fatal("rejected wear changed ownership", err)
+ }
+ player.stats.Ranged.Shotgun++
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ output.packets = nil
+ started := time.Now()
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("qualified selected-quality weapon did not start wear", err)
+ }
+ finish := client.equipment.readyAt
+ world.advanceEquipment(finish.Add(-time.Nanosecond))
+ if player.inventory.Items[0].Slot != 64 {
+ t.Fatal("weapon moved before its deadline")
+ }
+ world.advanceEquipment(finish)
+ worn := newTestInventoryServer(t).characters[1]
+ weapon := worn.attackWeapon()
+ var delivered, remoteDelivery []byte
+ for _, packet := range output.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x3b1d2268 {
+ delivered = packet
+ }
+ }
+ for _, packet := range observer.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x3b1d2268 {
+ remoteDelivery = packet
+ }
+ }
+
+ expected := ownedItem{ID: 1, Type: 51018, Template: anchor, Quality: scenario.quality, Slot: 6, Count: 1}
+ if finish.Before(started.Add(3500*time.Millisecond)) || finish.After(time.Now().Add(3500*time.Millisecond)) ||
+ !slices.Equal(worn.inventory.Items, []ownedItem{expected}) || weapon == nil || *weapon.Quality != scenario.quality ||
+ worn.equipmentBonus(21) != scenario.psychic || len(delivered) < 91 || len(remoteDelivery) < 91 || !bytes.Equal(delivered[16:], remoteDelivery[16:]) {
+ t.Fatal("wear timing, identity, Psychic bonus or observer delivery differs", worn.inventory.Items)
+ }
+ stats := make(map[uint32]uint32)
+ 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:])
+ }
+ low, high := expected.templateIDs()
+ if stats[701] != scenario.quality || stats[702] != low || stats[703] != high {
+ t.Fatal("native selected quality or endpoints differ", stats)
+ }
+ for stat, value := range map[uint32]uint32{286: scenario.minimum, 285: scenario.maximum, 284: scenario.critical,
+ 294: scenario.attack, 210: 250, 211: 350, 212: 40, 420: 1, 436: 92, 74: scenario.value, 30: 5} {
+ remote, overridden := stats[stat]
+ if !overridden {
+ remote = itemStat(gamedata.ItemTemplates[stats[23]], stat)
+ }
+ if itemStat(weapon, stat) != value || remote != value {
+ t.Fatalf("selected or remote stat%d differs: local%d remote%d want%d", stat, itemStat(weapon, stat), remote, value)
+ }
+ }
+ attack, recharge := player.attackDelays()
+ expectedAttack, expectedRecharge := time.Duration(scenario.attack)*10*time.Millisecond, 2500*time.Millisecond
+ if scenario.psychic == 25 {
+ // DRAGON's Psychic also contributes one point of Ranged Initiative.
+ expectedAttack, expectedRecharge = 2310*time.Millisecond, 2490*time.Millisecond
+ }
+ if attack != expectedAttack || recharge != expectedRecharge {
+ t.Fatal("selected attack/recharge differs", attack, recharge)
+ }
+
+ // Remove and re-wear the same instance; effects must neither stick nor double.
+ for _, move := range [][2]uint32{{6, 64}, {64, 6}, {6, 64}} {
+ request := inventoryMovePacket(1, move[0], move[1])
+ if move[0] == 6 {
+ request = itemMovePacket(1, 6, 64)
+ }
+ if err := world.handleInventory(client, request[20:]); err != nil || client.equipment == nil {
+ t.Fatal("retained weapon did not start moving", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ expected.Slot = move[1]
+ cold := newTestInventoryServer(t).characters[1]
+ bonus := int32(0)
+ if move[1] == 6 {
+ bonus = scenario.psychic
+ }
+ if !slices.Equal(cold.inventory.Items, []ownedItem{expected}) || cold.equipmentBonus(21) != bonus || cold.inventory.Items[0].shopPrice() != scenario.value {
+ t.Fatal("cold ownership, price or repeated Psychic bonus differs")
+ }
+ }
+ afterCatalog, err := json.Marshal([]*gamedata.Item{gamedata.ItemTemplates[scenario.low], gamedata.ItemTemplates[scenario.high]})
+ if err != nil || !bytes.Equal(catalog, afterCatalog) {
+ t.Fatal("interpolation modified the shared catalog", err)
+ }
+ })
+ }
+ }
+}
+
+func TestVektorGeneratedPickupCancellationAndSale(t *testing.T) {
+ for _, scenario := range []struct{ template, quality, credits uint32 }{
+ {124257, 2, 120}, {124259, 37, 824}, {124261, 75, 3018},
+ } {
+ t.Run(fmt.Sprint(scenario.quality), func(t *testing.T) {
+ world, _ := newKillExperienceWorld(t, "unarmed")
+ // Controlled membership verifies delivery, not historical creature drops.
+ profile := *world.characters[1000000].combatProfile
+ 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
+
+ attackForExperience(t, world, "unarmed")
+ if err := world.handleLootUse(world.clients[1], lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ for range 2 {
+ if err := world.handleInventory(world.clients[1], lootTakeRequest()); err != nil {
+ t.Fatal(err)
+ }
+ }
+ world = newTestInventoryServer(t)
+ player := world.characters[1]
+ expected := ownedItem{ID: identity, Type: 51018, Template: scenario.template, Quality: scenario.quality, Slot: 64, Count: 1}
+ if !slices.Equal(player.inventory.Items, []ownedItem{expected}) || len(world.characters[1000000].corpse.items) != 0 || world.nextItem != identity {
+ t.Fatal("pickup, replay or cold recovery changed the generated identity")
+ }
+ player.appearance, player.position = 0x515, [3]float32{60, 14.75, 53}
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.savePosition_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ client := &worldClient{id: 1, conn: &combatTestConn{}, target: true, ready: true}
+ world.clients[1] = client
+ offer := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{50000, 1}, [2]uint32{104, 64})[20:]
+ if err := world.handleShopUse(client, shopUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ 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)
+
+ if !slices.Equal(cancelled.Items, []ownedItem{expected}) || cancelled.Credits != 1 || len(sold.characters[1].inventory.Items) != 0 ||
+ sold.characters[1].inventory.Credits != scenario.credits || sold.nextItem != identity {
+ t.Fatal("cancelled/accepted/replayed sale changed the selected identity or price", sold.characters[1].inventory)
+ }
+ })
+ }
+}
+
+func TestVektorSelectedDamageAndEnergyReload(t *testing.T) {
+ for _, scenario := range []struct{ template, quality, normal, critical uint32 }{
+ {124257, 2, 59, 161}, {124258, 37, 315, 959}, {124261, 75, 588, 1813},
+ {124260, 125, 952, 2947}, {124262, 180, 1351, 4193},
+ } {
+ for _, critical := range []bool{false, true} {
+ t.Run(fmt.Sprintf("%d/QL%d/critical%v", scenario.template, scenario.quality, critical), func(t *testing.T) {
+ world, _ := 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.Shotgun = 1000
+ target.health = 10000
+ player.inventory.Items[0].Template, player.inventory.Items[0].Quality = scenario.template, scenario.quality
+ player.inventory.Items[0].Ammo = 0
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ world.combatRoll = func(limit uint32) uint32 {
+ if limit == 10000 || limit == 100 && critical {
+ return 0
+ }
+ return limit - 1
+ }
+
+ for index, wrong := range []uint32{21605, 21613} {
+ player.inventory.Items[1].Template = wrong
+ if err := world.handleReload(client, explicitReloadRequest(uint32(index+1), 64, 1)); err != nil || player.inventory.Items[0].Ammo != 0 || player.inventory.Items[1].Count != 100 {
+ t.Fatal("Vektor accepted bullets or shotgun shells", err)
+ }
+ }
+ player.inventory.Items[1].Template = 21609
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ started := time.Now()
+ if err := world.handleReload(client, explicitReloadRequest(3, 64, 1)); err != nil {
+ t.Fatal(err)
+ }
+ reloaded := newTestInventoryServer(t).characters[1]
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceCombat(player.nextAttack)
+ shot := newTestInventoryServer(t).characters[1]
+
+ damage := scenario.normal
+ if critical {
+ damage = scenario.critical
+ }
+ if reloaded.inventory.Items[0].Ammo != 40 || reloaded.inventory.Items[1].Count != 60 ||
+ reloaded.rechargeUntil.Before(started.Add(2500*time.Millisecond)) || reloaded.rechargeUntil.After(time.Now().Add(2500*time.Millisecond)) ||
+ shot.inventory.Items[0].Ammo != 39 || shot.inventory.Items[1].Count != 60 || target.health != 10000-damage {
+ t.Fatal("selected damage, energy ammunition or cold reload deadline differs", target.health, shot.inventory)
+ }
+ })
+ }
+ }
+}
diff --git a/tools/client/test_vektor.mjs b/tools/client/test_vektor.mjs
@@ -0,0 +1,129 @@
+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, phase] = process.argv.slice(2);
+const browser = await chromium.launch({executablePath: '/usr/bin/chromium',
+ args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
+ '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
+const games = [];
+
+async function bagClick(game, id, 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 token of ['vektor-owner', 'vektor-watch']) {
+ const context = await browser.newContext({viewport: {width: 1024, height: 768}});
+ await context.addCookies([{name: 'ao_client', value: token, url}]);
+ const page = await context.newPage();
+ const game = await GameTest.attach(page);
+ games.push(game);
+ await page.goto(url);
+ await game.ready();
+ }
+ const [owner, observer] = games;
+ const state = async () => (await owner.page.request.get(url + '/test-state')).json();
+ if (phase === 'live') {
+ assert.equal(owner.local().stats[115], 300);
+ assert.equal(owner.local().stats[21], 200);
+ const nanoMaximum = owner.local().stats[221];
+ await owner.key('KeyI');
+ await owner.page.keyboard.press('Control+1');
+ for (const [id, psychic] of [[1, 200], [2, 200], [3, 215]]) {
+ const sequence = observer.sequence;
+ await bagClick(owner, id);
+ await owner.wait('selected Vektor worn', snapshot => owner.local(snapshot).inventory.some(item => item.id === id && item.slot === 6));
+ await observer.wait('observer receives selected Vektor', () => observer.events.some(event => {
+ if (event.sequence <= sequence || event.direction !== 'framereceived' || event.opcode !== '3b1d2268') return false;
+ return event.actor[0] === 51018 && event.actor[1] === id;
+ }));
+ assert.equal(owner.local().stats[21], 200);
+ assert.equal(owner.local().stats[221], nanoMaximum + (id === 3 ? 9 : 0));
+ assert.equal((await state()).psychic, psychic - 200);
+ await owner.save(output + '/worn-' + id);
+
+ if (id === 2) {
+ // Ammunition-on-weapon uses actual inventory clicks and the native use request.
+ await bagClick(owner, 5, 'left');
+ await owner.click(867, 206, 'right');
+ await owner.wait('energy stack debited', snapshot => owner.local(snapshot).inventory.some(item => item.id === 5 && item.count === 60));
+ const reloaded = await state();
+ assert.equal(reloaded.inventory.Items.find(item => item.ID === 2).Ammo, 40);
+ await owner.wait('native reload completes', snapshot => !owner.local(snapshot).actions.includes(5));
+ const before = await state();
+ 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', snapshot =>
+ snapshot.selected[0] !== selected[0] || snapshot.selected[1] !== selected[1]);
+ }
+ const attack = owner.sequence;
+ await owner.key('KeyQ');
+ await owner.wait('one real 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 shot impact', snapshot =>
+ snapshot.actors.some(actor => actor.id === before.target && actor.stats[27] === 9832))));
+ const shot = await state();
+ assert.equal(shot.health, 9832);
+ assert.equal(shot.inventory.Items.find(item => item.ID === 2).Ammo, 39);
+ assert.equal(shot.inventory.Items.find(item => item.ID === 5).Count, 60);
+ assert.equal(shot.fighting, 0);
+ await owner.wait('server shot recharge completes', () => Date.now() >= Date.parse(shot.recharge));
+ await owner.save(output + '/shot');
+ await observer.save(output + '/observer-shot');
+ // Reconnect ends the fixture encounter; active-combat swaps are a separate TODO.
+ await owner.page.reload();
+ await owner.ready();
+ await owner.key('KeyI');
+ await owner.page.keyboard.press('Control+1');
+ }
+ await owner.click(867, 206, 'right');
+ await owner.wait('same Vektor removed', snapshot => owner.local(snapshot).inventory.some(item => item.id === id && item.slot >= 48));
+ assert.equal(owner.local().stats[21], 200);
+ assert.equal(owner.local().stats[221], nanoMaximum);
+ assert.equal((await state()).psychic, 0);
+ }
+
+ // QL125 fails locally; the retained QL75 bonus must apply exactly once again.
+ const before = await state();
+ const sequence = owner.sequence;
+ await bagClick(owner, 4);
+ await owner.save(output + '/rejected-125');
+ assert(!owner.events.some(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24'));
+ assert.deepEqual((await state()).inventory, before.inventory);
+ await bagClick(owner, 3);
+ await owner.wait('same LIZARD re-worn', snapshot => owner.local(snapshot).inventory.some(item => item.id === 3 && item.slot === 6));
+ assert.equal(owner.local().stats[21], 200);
+ assert.equal(owner.local().stats[221], nanoMaximum + 9);
+ assert.equal((await state()).psychic, 15);
+ await owner.key('KeyU');
+ await owner.save(output + '/psychic-bonus');
+ await owner.key('KeyU');
+ await owner.page.reload();
+ await owner.ready();
+ }
+ const inventory = owner.local().inventory;
+ assert.deepEqual(inventory.map(item => [item.id, item.quality, ...item.templates, item.count]).sort((a, b) => a[0] - b[0]), [
+ [1, 2, 124256, 124257, 1], [2, 37, 124258, 124259, 1],
+ [3, 75, 124260, 124261, 1], [4, 125, 124260, 124261, 1],
+ [5, 1, 21609, 21609, 60], [6, 1, 21605, 21605, 100], [7, 1, 21613, 21613, 100],
+ ]);
+ assert.equal(inventory.find(item => item.id === 3).slot, 6);
+ assert.equal(owner.local().stats[21], 200);
+ assert.deepEqual(observer.local().inventory, []);
+ assert(games.every(game => game.errors.length === 0));
+ console.log('PASS:', phase, 'Vektor selected qualities, exact identities and LIZARD bonus retained');
+} finally {
+ try { await Promise.all(games.map((game, id) => game.save(output + '/final-' + id))); }
+ finally { await browser.close(); }
+}