aorecomp

Anarchy Online classic in the browser

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


commit 3d422e6750eb2423e1cc1f1553c667f0b18894c5
parent 53c7795b407be2095ce1d247c61ac90865fe0ed5
Author: anon <anon@example.com>
Date:   Wed, 28 Oct 2026 23:56:00 +0000

Add the complete Low-Tech armor set to early shops

Diffstat:
MTODO.md | 28+++++++++++++++++++++++++---
Mdocs/early-armor.md | 124++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
Mserver/gamedata/item_families.yaml | 9++++++++-
Mserver/gamedata/item_quality_test.go | 3++-
Mserver/gamedata/shop_stock.yaml | 30++++++++++++++++++++++++++----
Mserver/low_tech_armor_test.go | 2+-
Aserver/low_tech_set_test.go | 265+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/shop_quality_test.go | 9++++++++-
8 files changed, 449 insertions(+), 21 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -260,13 +260,23 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). low/high template delivery at low, intermediate and boundary QLs. Include pickup, rejected wear, equip/remove, sale and cold recovery of the same instance. Metaplast and one reviewed QL1..11 Rusty pistol family now use the shared QL - path. Reviewed Low-Tech gloves now add QL1/2 basic-shop upgrades through the - same consumers, with an ordinary earned sale-funded purchase and wear now - verified. A QL2 Advanced Baseballbat now also passes ordinary mission earning, + path. The reviewed complete Low-Tech set adds QL1/2 basic-shop upgrades through + the same consumers, with ordinary earned purchases and wear of gloves and a + sleeve verified. A QL2 Advanced Baseballbat also passes ordinary mission earning, rejected wear, earned IP training, equip/remove, a full-health kill, canceled sale and cold retention. Useful creature equipment pools and wider early families remain. See [early armor](docs/early-armor.md) and [early melee](docs/early-melee.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 + provisional QL1/2 subset. Original payload audits, both stored anchors, + requirements, price/AC boundaries, full-set exact balances, cold ownership + and whole-basket rollback/retry pass. Native earned income bought and wore a + sleeve; a separate controlled visitor verified all seven pieces, both styles, + rejected wear, distinct sleeve slots and cold retention of all nine instances. + Source-icon and green-skin limitations remain separate TODOs. See + [complete early armor](docs/early-armor.md#complete-set). - [x] Verify one intermediate-quality weapon family through shared consumers. Check: Rusty pistol endpoints 123742/123743 at QL1,2,5,6,10,11 preserve selected damage, criticals, strict requirements, OE, delays, ammo, price and native @@ -1156,6 +1166,10 @@ introduction and starting-item gameplay remain open below. bare skin, both sleeve instances and skirt/trousers on owner and observer, including cold bootstrap. Captures are in `local/early-shop/runtime/`; do not infer complete visual fidelity from successful wear notifications alone. + The complete Low-Tech set also exposes green neck/arm/leg regions despite + correct independent sleeve slots and native AC totals. Compare shared skin + compositing and original color-key behavior before adding item-specific fixes. + Captures: `local/low-tech-set/fixture/`. - [ ] [P1] Reconstruct the original Arrival Hall and training-ground introduction. Check all three factions' entry/exit flow, authored tutorial NPC identities, dialogues, starter instructions and camera state. Replace training NPC @@ -2857,6 +2871,14 @@ and server restarts. Turn every reproduced bug into a focused regression test. after reconnect and restart. The rejected-drag defect below is reproduced and fixed; continue auditing other paths rather than treating that one fix or passing Go tests as proof that the entire earlier report is resolved. +- [ ] [P2] Review nearly invisible original item icons separately from ownership + loss. Low-Tech sleeves 70561/85744 reference icon 1010008/13228: the original + 14.9.1 PNG is almost entirely chroma-key green, with only a tiny shoulder in + its upper-right corner. The native inventory/shop therefore looks nearly + empty despite a valid tooltip, quote and retained instance. Check whether + period-supported corrected artwork exists before replacing the original; + do not treat this matching source image as a WASM renderer defect. Evidence: + `local/low-tech-set/icon-1010008-13228.bin` and native purchase captures. - [x] Extend equipment conservation checks across placement rollback, retry and lost replies. Both wear/removal now cover failed and ignored location deletes and inserts, failed COMMIT, unchanged unrelated items, cold ownership and no diff --git a/docs/early-armor.md b/docs/early-armor.md @@ -1,13 +1,15 @@ # Low-Tech starter armor -Basic Omni, Clan and neutral armor terminals now offer Low-Tech gloves at QL1 -and QL2 alongside the existing QL5 Metaplast subset. Original template 70562 -(Battered) and 85597 (Enhanced) form one reviewed QL1..200 family. The existing -item-quality, requirements, armor, price, native delivery and transaction code -supplies all behavior; there is no Low-Tech-specific Go branch. +Basic Omni, Clan and neutral armor terminals offer the complete Low-Tech set +at QL1 and QL2 alongside the QL5 Metaplast subset. Eight explicit original +endpoint pairs cover QL1..200, including alternate body and leg styles. The +existing item-quality, requirements, armor, price, native delivery and +transaction code supplies all behavior; there is no Low-Tech-specific Go branch. ## Original item evidence +The glove pair provides the following worked interpolation example. + Both complete 14.9.1 records have type 51022, ItemType 2, CanWear, gloves slot mask 256, one texture descriptor and eight unconditional armor modifiers. Their section/action/function layouts match. The only variable scalar properties are @@ -40,16 +42,44 @@ scalar, effect and criterion are retained in `local/early-armor-research/audit.j These records establish item behavior, not a universal pairing heuristic or original shop stock generation. +## Complete set + +All eight pairs have matching complete section layouts, unconditional armor +effects and strict Agility/Strength requirements. At QL1 both abilities must +exceed 7; at QL2 both must exceed 9. The alternate body and leg records retain +their distinct original visual descriptors. They do not add an inferred sex +restriction. Each sleeve can occupy either authored arm slot, and two sleeves +are separate instances. + +| Piece | Original QL1/200 pair | Logical wear slot | Base value QL1/2 | AC90..97 at QL2 | +| --- | --- | --- | --- | --- | +| Boots | 70558/85640 | 30 | 142/146 | 5/5/2/1/1/1/1/1 | +| Body | 70559/85689 | 21 | 500/512 | 9/9/9/2/2/2/2/2 | +| Female Body | 70560/85688 | 21 | 500/512 | 9/9/9/2/2/2/2/2 | +| Sleeves | 70561/85744 | 23 or 25 | 125/127 | 4/4/2/1/1/1/1/1 | +| Gloves | 70562/85597 | 24 | 125/127 | 4/4/2/1/1/1/1/1 | +| Helmet | 70563/85558 | 18 | 375/384 | 6/6/6/2/2/2/2/2 | +| Pants | 70564/85515 | 27 | 312/319 | 6/6/5/1/1/1/1/1 | +| Shorts | 70565/85514 | 27 | 312/319 | 6/6/5/1/1/1/1/1 | + +The independent source-payload comparison in `local/low-tech-set/audit.json` +checks all 16 records against the decoded catalog, retains their byte slices, +offsets and hashes, and rejects undecoded tails. The original index SHA-256 is +`46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`. +Only stats 54, 1, 74 and 2, eight armor amounts, and the two requirement thresholds +differ within each pair. All other sections match after those numeric changes +are normalized. The hand-reviewed pairs are added directly to the shared table. + ## Purchase policy and progression boundary -The two fixed rows in basic armor templates 99383/99502/99570 are reconstruction -policy. Original terminal descriptions establish the basic armor category, -without enumerating membership or refresh probabilities. No advanced, superior +The sixteen fixed Low-Tech rows in basic armor templates 99383/99502/99570 are +reconstruction policy. Original terminal descriptions establish the basic armor +category, without enumerating membership or refresh probabilities. No advanced, superior or training-terminal stock is inferred from this subset. No creature acquires an equipment drop from this change. -At effective Computer Literacy 40, QL1/2 cost 124/126 credits in Omni basic armor -and 130/132 in Clan/neutral. At a starter's lower literacy the Omni prices are +For gloves and sleeves at effective Computer Literacy 40, QL1/2 cost 124/126 +credits in Omni basic armor and 130/132 in Clan/neutral. At a starter's lower literacy the Omni prices are 125/127. This preserves original values and vendor modifiers. QL1 can be worn with two abilities at 8, while QL2 requires 10; ordinary IP and breed/level caps still apply. These are cheaper low-level upgrades, not proof that the current @@ -61,6 +91,14 @@ the 125-credit purchase, with the original reward, bought instance, effects and [earned armor purchase](starter-progression.md#earned-loot-sales-and-an-armor-purchase). Broader loot/recovery economics and other starter breeds remain open. +A seven-piece set uses one body, one pants/shorts record, boots, gloves, helmet +and two sleeves. With low Computer Literacy, QL1/2 cost 1704/1742 credits at the +Omni basic terminal, or 1787/1826 at Clan/neutral terminals. Its combined +AC90..97 is 23/23/15/7/7/7/7/7 at QL1 and 38/38/28/9/9/9/9/9 at QL2. Removing +one sleeve subtracts exactly that instance's contribution. These prices retain +the original item values and vendor modifiers; they do not establish that +starter loot suitably funds a complete suit. + ## Verification Public inventory handlers test both stored anchors at QL1,2,100,101,199,200, @@ -71,6 +109,23 @@ required balance, wear/remove and sell once despite a repeated acceptance. Failed item inserts, ignored placement and deferred commit failures retain cash, items and identity counters; the same purchase can retry successfully. +The full-set extension checks both stored endpoints of each new family at +QL1, 2, 100 and 200, including each strict requirement, all eight ACs, selected +native endpoints, authored prices, removal and cold identity retention. +Seven-item baskets purchase and wear independent sleeves at both low qualities +in all three factions using the exact required balance. A failed item write, +ignored location write or failed COMMIT on the second sleeve rolls back the +whole basket and retries without charging twice or skipping identities. + +The original sleeve icon 1010008/13228 is a 48x48 RGB PNG containing almost only +chroma-key green and a tiny shoulder in its upper-right corner. Its SHA-256 is +`96f502c15fc7275f2a018ca808a61be2900cb11438c91285809a6fceae537cc0`. +The native shop/inventory image matches this nearly empty source asset. Its +tooltip, quote, wear action and instance remain usable. This is distinct from +an instance disappearing or the WASM renderer dropping a valid icon. A separate +TODO asks for period-supported corrected artwork rather than silently replacing +the original. + The armor/shop regression selection passed 111 roots / 1,200 results; the new lifecycle selection passed 3 roots / 24 results under the race detector. Vet and the development-server build passed. These checks exercise the existing shared @@ -99,3 +154,52 @@ sold QL1 instance 14 remained absent. No page exception or adapter abort occurre ordinary resource 404 console entries are retained separately. Only the owned fixture account and remaining purchased item are cleaned up; unrelated rows and SQLite integrity are checked before restoring the single HTTPS preview. + +## Complete-set native check + +The retained ordinary level-3 Enforcer walked from Backyard 1 through Omni +Entertainment to basic shop 1183 without admin location, skill or cash edits. +It bought QL1 sleeve 125 for 125 earned credits, leaving 31. Native wear selected +left arm 25 and raised AC90..97 from 3/13/1/1/1/1/1/1 to 6/16/2/2/2/2/2/2. +Removal restored the baseline; re-wear and reconnect retained all 18 owned +instances, their quantities and placements. All prior item records, wallet +metadata, XP, IP, stats and mission/death facts remained unchanged apart from +the intended cash debit and ordinary travel fields. + +A separate isolated visitor used controlled funds, location and abilities to +check the whole QL2 suit. Seven pieces cost 1742 from 5000. At abilities 9, the +native client displayed both required values 10, rejected wear and retained all +seven items. Raising only the fixture's two abilities to 10 allowed wear. The +second sleeve's right-click targeted the occupied left arm; the server's +correction retained it. Explicit pickup/place into right arm 23 completed the +set, with native AC 38/38/28/9/9/9/9/9 and two separate sleeve identities. + +The fixture then bought the alternate Female Body and Shorts for 831, leaving +2427. It removed the original body/pants and wore both alternatives. All nine +instances survived reconnect; the replaced pieces remained in ordinary +inventory and the combined AC stayed unchanged. This exercises the original +style descriptors and shared wear path, not normal-play affordability of a +complete suit. The earned character's 18 items and 31 credits were unchanged by +the controlled fixture. + +Both browsers closed before the sole default-port preview restarted with the +same binary. SQLite retained all 59 item records and placements, both players, +and the earned mission/death history. Fresh native clients restored all 18 +earned and all nine fixture identities, counts, qualities and wear positions, +their wallets and the same armor totals. All four native sessions used the +GPU/OpenGL renderer. Evidence, GPU metadata, wire streams, +read-only native probes and database snapshots live in `local/low-tech-set/`. + +Visual fidelity remains incomplete: exposed neck/arm/leg regions can render +green, as already recorded for Omni-Med clothing. The native full-set screenshot +retains this defect rather than claiming a complete visual pass. The almost +empty original sleeve icon is a separate source-asset issue. Page exceptions +and adapter-abort diagnostics were absent in the controlled set/style run. + +The complete maintained Go run passes 1676 root tests / 16515 results with no +skipped tests. The new armor and purchase selection passes 96 results in seven +roots under the race detector; the related normal runs and all 43 family-range +results also pass. Vet passes for the maintained server and export packages. +The initial full-set fixture expected allocation in click order; its six failed +cases are retained separately. Correcting that expectation to the existing +catalog order required no runtime change. The subsequent full suite is clean. diff --git a/server/gamedata/item_families.yaml b/server/gamedata/item_families.yaml @@ -17,8 +17,15 @@ - [122691, 122692] # Monster Parts: complete original descriptor audit; docs/npc-loot.md. - [42640, 42641] -# Low-Tech gloves: complete original descriptor audit; docs/early-armor.md. +# Low-Tech armor: complete original descriptor audits; docs/early-armor.md. +- [70558, 85640] +- [70559, 85689] +- [70560, 85688] +- [70561, 85744] - [70562, 85597] +- [70563, 85558] +- [70564, 85515] +- [70565, 85514] # Regular recovery supplies, QL1..200: docs/medical-quality.md. - [25812, 25811] - [85366, 85367] diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go @@ -13,7 +13,8 @@ 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}, - {70562, 85597, 1, 200}, + {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}, {25812, 25811, 1, 200}, {85366, 85367, 1, 200}, {25820, 25821, 1, 200}, } { for _, template := range [2]uint32{family.lowTemplate, family.highTemplate} { diff --git a/server/gamedata/shop_stock.yaml b/server/gamedata/shop_stock.yaml @@ -55,7 +55,29 @@ # Basic armor: a fixed QL5 Metaplast subset of the original basic-armor family. # This is reconstruction policy; complete membership and rotation remain open. # See docs/shops.md for the stock and authored-value evidence boundary. -# The cheaper Low-Tech QL1/2 glove subset uses the same policy; docs/early-armor.md. -99383: [{template: 85596, quality: 5}, {template: 85742, quality: 5}, {template: 85638, quality: 5}, {template: 85512, quality: 5}, {template: 85557, quality: 5}, {template: 85686, quality: 5}, {template: 70562, quality: 1}, {template: 70562, quality: 2}] -99502: [{template: 85596, quality: 5}, {template: 85742, quality: 5}, {template: 85638, quality: 5}, {template: 85512, quality: 5}, {template: 85557, quality: 5}, {template: 85686, quality: 5}, {template: 70562, quality: 1}, {template: 70562, quality: 2}] -99570: [{template: 85596, quality: 5}, {template: 85742, quality: 5}, {template: 85638, quality: 5}, {template: 85512, quality: 5}, {template: 85557, quality: 5}, {template: 85686, quality: 5}, {template: 70562, quality: 1}, {template: 70562, quality: 2}] +# The cheaper Low-Tech QL1/2 set uses the same policy; docs/early-armor.md. +99383: &basic_armor + - {template: 85596, quality: 5} + - {template: 85742, quality: 5} + - {template: 85638, quality: 5} + - {template: 85512, quality: 5} + - {template: 85557, quality: 5} + - {template: 85686, quality: 5} + - {template: 70562, quality: 1} + - {template: 70562, quality: 2} + - {template: 70558, quality: 1} + - {template: 70558, quality: 2} + - {template: 70559, quality: 1} + - {template: 70559, quality: 2} + - {template: 70560, quality: 1} + - {template: 70560, quality: 2} + - {template: 70561, quality: 1} + - {template: 70561, quality: 2} + - {template: 70563, quality: 1} + - {template: 70563, quality: 2} + - {template: 70564, quality: 1} + - {template: 70564, quality: 2} + - {template: 70565, quality: 1} + - {template: 70565, quality: 2} +99502: *basic_armor +99570: *basic_armor diff --git a/server/low_tech_armor_test.go b/server/low_tech_armor_test.go @@ -126,7 +126,7 @@ func TestLowTechBasicArmorPurchaseWearAndSale(t *testing.T) { if err := world.handleShopUse(client, request); err != nil { t.Fatal(err) } - if client.shop == nil || len(client.shop.stock) != 8 || client.shop.stock[6+row] != (gamedata.ShopItem{Template: 70562, Quality: quality}) { + if client.shop == nil || len(client.shop.stock) != 22 || client.shop.stock[6+row] != (gamedata.ShopItem{Template: 70562, Quality: quality}) { t.Fatal("basic armor lacks its low-quality glove selection") } for _, request := range [][]byte{ diff --git a/server/low_tech_set_test.go b/server/low_tech_set_test.go @@ -0,0 +1,265 @@ +package main + +import ( + "ao/server/gamedata" + "bytes" + "encoding/binary" + "fmt" + "slices" + "testing" +) + +func TestLowTechArmorQualityFamiliesWearAndRecover(t *testing.T) { + for _, scenario := range []struct { + low, high, slot, quality, value uint32 + strength, agility uint16 + armor [8]int32 + }{ + {70558, 85640, 30, 1, 142, 7, 7, [8]int32{3, 3, 1, 1, 1, 1, 1, 1}}, + {70558, 85640, 30, 2, 146, 9, 9, [8]int32{5, 5, 2, 1, 1, 1, 1, 1}}, + {70558, 85640, 30, 100, 44270, 227, 252, [8]int32{165, 165, 140, 28, 28, 28, 28, 28}}, + {70558, 85640, 30, 200, 178447, 450, 500, [8]int32{328, 328, 281, 56, 56, 56, 56, 56}}, + {70559, 85689, 21, 1, 500, 7, 7, [8]int32{5, 5, 5, 1, 1, 1, 1, 1}}, + {70559, 85689, 21, 2, 512, 9, 9, [8]int32{9, 9, 9, 2, 2, 2, 2, 2}}, + {70559, 85689, 21, 100, 118148, 227, 252, [8]int32{438, 438, 376, 75, 75, 75, 75, 75}}, + {70559, 85689, 21, 200, 475861, 450, 500, [8]int32{875, 875, 750, 150, 150, 150, 150, 150}}, + {70560, 85688, 21, 1, 500, 7, 7, [8]int32{5, 5, 5, 1, 1, 1, 1, 1}}, + {70560, 85688, 21, 2, 512, 9, 9, [8]int32{9, 9, 9, 2, 2, 2, 2, 2}}, + {70560, 85688, 21, 100, 118148, 227, 252, [8]int32{438, 438, 376, 75, 75, 75, 75, 75}}, + {70560, 85688, 21, 200, 475861, 450, 500, [8]int32{875, 875, 750, 150, 150, 150, 150, 150}}, + {70561, 85744, 23, 1, 125, 7, 7, [8]int32{3, 3, 1, 1, 1, 1, 1, 1}}, + {70561, 85744, 23, 2, 127, 9, 9, [8]int32{4, 4, 2, 1, 1, 1, 1, 1}}, + {70561, 85744, 23, 100, 29536, 227, 252, [8]int32{110, 110, 94, 19, 19, 19, 19, 19}}, + {70561, 85744, 23, 200, 118965, 450, 500, [8]int32{218, 218, 187, 37, 37, 37, 37, 37}}, + {70563, 85558, 18, 1, 375, 7, 7, [8]int32{3, 3, 3, 1, 1, 1, 1, 1}}, + {70563, 85558, 18, 2, 384, 9, 9, [8]int32{6, 6, 6, 2, 2, 2, 2, 2}}, + {70563, 85558, 18, 100, 88611, 227, 252, [8]int32{328, 328, 281, 56, 56, 56, 56, 56}}, + {70563, 85558, 18, 200, 356895, 450, 500, [8]int32{656, 656, 562, 112, 112, 112, 112, 112}}, + {70564, 85515, 27, 1, 312, 7, 7, [8]int32{3, 3, 3, 1, 1, 1, 1, 1}}, + {70564, 85515, 27, 2, 319, 9, 9, [8]int32{6, 6, 5, 1, 1, 1, 1, 1}}, + {70564, 85515, 27, 100, 73842, 227, 252, [8]int32{273, 273, 234, 47, 47, 47, 47, 47}}, + {70564, 85515, 27, 200, 297413, 450, 500, [8]int32{546, 546, 468, 93, 93, 93, 93, 93}}, + {70565, 85514, 27, 1, 312, 7, 7, [8]int32{3, 3, 3, 1, 1, 1, 1, 1}}, + {70565, 85514, 27, 2, 319, 9, 9, [8]int32{6, 6, 5, 1, 1, 1, 1, 1}}, + {70565, 85514, 27, 100, 73842, 227, 252, [8]int32{273, 273, 234, 47, 47, 47, 47, 47}}, + {70565, 85514, 27, 200, 297413, 450, 500, [8]int32{546, 546, 468, 93, 93, 93, 93, 93}}, + } { + for _, anchor := range []uint32{scenario.low, scenario.high} { + t.Run(fmt.Sprintf("%d/QL%d", anchor, scenario.quality), func(t *testing.T) { + world, output := newEquipmentWorld(t) + t.Cleanup(func() { world.db.Close() }) + player, client := world.characters[1], world.clients[1] + player.stats.Abilities.Strength, player.stats.Abilities.Agility = scenario.strength+1, scenario.agility+1 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, anchor); err != nil || !granted { + t.Fatal("grant armor", granted, err) + } + player.inventory.Items[1].Quality = scenario.quality + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + weapon := player.inventory.Items[0] + + for _, ability := range []*uint16{&player.stats.Abilities.Strength, &player.stats.Abilities.Agility} { + *ability -= 1 + if err := world.handleInventory(client, inventoryMovePacket(1, 65, scenario.slot)[20:]); err != nil || client.equipment != nil || player.inventory.Items[1].Slot != 65 { + t.Fatal("threshold equality equipped or lost the armor", err) + } + *ability += 1 + } + output.packets = nil + if err := world.handleInventory(client, inventoryMovePacket(1, 65, scenario.slot)[20:]); err != nil || client.equipment == nil { + t.Fatal("qualified armor did not start wear", err) + } + world.advanceEquipment(client.equipment.readyAt) + worn := newTestInventoryServer(t) + low, high := scenario.low, scenario.high + if scenario.quality == 1 { + high = low + } else if scenario.quality == 200 { + low = high + } + var action []byte + for _, word := range []uint32{low, high, scenario.quality, 1, 6, 102, scenario.slot, 0, 0} { + action = binary.BigEndian.AppendUint32(action, word) + } + if len(output.packets) != 2 || !bytes.Equal(output.packets[1][29:65], action) { + t.Fatal("native wear lost the selected quality or endpoint pair") + } + if err := world.handleInventory(client, itemMovePacket(1, scenario.slot, 111)[20:]); err != nil || client.equipment == nil { + t.Fatal("armor did not start removal", err) + } + world.advanceEquipment(client.equipment.readyAt) + removed := newTestInventoryServer(t) + + expected := ownedItem{ID: 2, Type: 51022, Template: anchor, Quality: scenario.quality, Slot: scenario.slot, Count: 1} + if !slices.Equal(worn.characters[1].inventory.Items, []ownedItem{weapon, expected}) || worn.characters[1].inventory.Items[1].shopPrice() != scenario.value { + t.Fatal("cold armor identity, quality, value or unrelated item changed") + } + expected.Slot = 65 + if !slices.Equal(removed.characters[1].inventory.Items, []ownedItem{weapon, expected}) || removed.nextItem != 2 { + t.Fatal("removal lost or replaced an instance") + } + for index, bonus := range scenario.armor { + if worn.characters[1].equipmentBonus(90+uint32(index)) != bonus || removed.characters[1].equipmentBonus(90+uint32(index)) != 0 { + t.Fatal("selected armor effects or their removal changed", index) + } + } + }) + } + } +} + +func TestLowTechCompleteShopSetKeepsBothSleevesAndExactPrice(t *testing.T) { + for _, terminal := range []struct { + id uint32 + side uint16 + prices [2]uint32 + }{ + {3221226655, 2, [2]uint32{1704, 1742}}, + {3223389340, 1, [2]uint32{1787, 1826}}, + {3222078626, 0, [2]uint32{1787, 1826}}, + } { + for row, quality := range []uint32{1, 2} { + t.Run(fmt.Sprintf("%d/QL%d", terminal.id, quality), func(t *testing.T) { + world, _ := newPurchaseWorld(t) + t.Cleanup(func() { world.db.Close() }) + player, client := world.characters[1], world.clients[1] + machine := gamedata.ShopMachines[terminal.id] + player.playfield, player.position, player.appearance = machine.Playfield, machine.Position, 0x115|terminal.side<<9 + player.stats.Abilities.Strength, player.stats.Abilities.Agility = 10, 10 + player.stats.TradeRepair.ComputerLiteracy = 5 + player.inventory.Credits = terminal.prices[row] + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.savePosition_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + weapon := player.inventory.Items[0] + request := shopUseRequest(2) + binary.BigEndian.PutUint32(request[44:48], terminal.id) + + if err := world.handleShopUse(client, request); err != nil { + t.Fatal(err) + } + for _, index := range []uint32{8, 10, 14, 14, 6, 16, 18} { + if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, terminal.id}, [2]uint32{111, index + uint32(row)})[20:]); err != nil { + t.Fatal(err) + } + } + if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]); err != nil { + t.Fatal(err) + } + // Purchased instances materialize in catalog order, not selection order. + for index, slot := range []uint32{24, 30, 21, 23, 25, 18, 27} { + if err := world.handleInventory(client, inventoryMovePacket(1, 65+uint32(index), slot)[20:]); err != nil || client.equipment == nil { + t.Fatal("set piece did not start wear", index, err) + } + world.advanceEquipment(client.equipment.readyAt) + } + worn := newTestInventoryServer(t) + if err := world.handleInventory(client, itemMovePacket(1, 25, 111)[20:]); err != nil || client.equipment == nil { + t.Fatal("left sleeve did not start removal", err) + } + world.advanceEquipment(client.equipment.readyAt) + removed := newTestInventoryServer(t) + + expected := []ownedItem{weapon, + {ID: 2, Type: 51022, Template: 70562, Quality: quality, Slot: 24, Count: 1}, + {ID: 3, Type: 51022, Template: 70558, Quality: quality, Slot: 30, Count: 1}, + {ID: 4, Type: 51022, Template: 70559, Quality: quality, Slot: 21, Count: 1}, + {ID: 5, Type: 51022, Template: 70561, Quality: quality, Slot: 23, Count: 1}, + {ID: 6, Type: 51022, Template: 70561, Quality: quality, Slot: 25, Count: 1}, + {ID: 7, Type: 51022, Template: 70563, Quality: quality, Slot: 18, Count: 1}, + {ID: 8, Type: 51022, Template: 70564, Quality: quality, Slot: 27, Count: 1}, + } + if !slices.Equal(worn.characters[1].inventory.Items, expected) || worn.characters[1].inventory.Credits != 0 { + t.Fatal("complete set lost an instance or charged the wrong price", worn.characters[1].inventory) + } + expected[5].Slot = 65 + if !slices.Equal(removed.characters[1].inventory.Items, expected) || removed.nextItem != 8 { + t.Fatal("removing one sleeve changed its partner or another item") + } + fullArmor := [][8]int32{{23, 23, 15, 7, 7, 7, 7, 7}, {38, 38, 28, 9, 9, 9, 9, 9}}[row] + oneSleeve := [][8]int32{{20, 20, 14, 6, 6, 6, 6, 6}, {34, 34, 26, 8, 8, 8, 8, 8}}[row] + for index := range fullArmor { + if worn.characters[1].equipmentBonus(90+uint32(index)) != fullArmor[index] || removed.characters[1].equipmentBonus(90+uint32(index)) != oneSleeve[index] { + t.Fatal("complete-set bonuses or single-sleeve removal changed", index) + } + } + }) + } + } +} + +func TestLowTechSetSecondSleeveFailureRollsBackTheWholeBasket(t *testing.T) { + for _, failure := range []struct{ name, sql string }{ + {"item", "CREATE TRIGGER reject_set BEFORE INSERT ON items WHEN NEW.id=6 BEGIN SELECT RAISE(FAIL,'second sleeve'); END"}, + {"ignored placement", "CREATE TRIGGER reject_set BEFORE INSERT ON item_locations WHEN NEW.item_id=6 BEGIN SELECT RAISE(IGNORE); END"}, + {"commit", "CREATE TABLE set_commit_failure (id INTEGER REFERENCES items(id) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER reject_set AFTER INSERT ON items WHEN NEW.id=6 BEGIN INSERT INTO set_commit_failure VALUES(9999); END"}, + } { + t.Run(failure.name, func(t *testing.T) { + world, output := newPurchaseWorld(t) + t.Cleanup(func() { world.db.Close() }) + player, client := world.characters[1], world.clients[1] + player.position = gamedata.ShopMachines[3221226655].Position + player.stats.TradeRepair.ComputerLiteracy = 5 + player.inventory.Credits = 5000 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + request := shopUseRequest(2) + binary.BigEndian.PutUint32(request[44:48], 3221226655) + if err := world.handleShopUse(client, request); err != nil { + t.Fatal(err) + } + for _, index := range []uint32{6, 8, 10, 14, 14, 16, 18} { + if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221226655}, [2]uint32{111, index})[20:]); err != nil { + t.Fatal(err) + } + } + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + if _, err := world.db.Exec(failure.sql); err != nil { + t.Fatal(err) + } + output.packets = nil + accept := shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:] + + failed := world.handleTrade(client, accept) + after, err := readTestItemStore(world) + cold := newTestInventoryServer(t) + + if failed == nil || err != nil || !bytes.Equal(before, after) || len(output.packets) != 0 || + player.inventory.Credits != 5000 || len(player.inventory.Items) != 1 || world.nextItem != 1 || + cold.characters[1].inventory.Credits != 5000 || len(cold.characters[1].inventory.Items) != 1 || cold.nextItem != 1 { + t.Fatal("partial set purchase spent credits, leaked an instance or announced success", failed, err) + } + + if _, err := world.db.Exec("DROP TRIGGER reject_set"); err != nil { + t.Fatal(err) + } + if err := world.handleTrade(client, accept); err != nil { + t.Fatal(err) + } + retried := newTestInventoryServer(t) + + if retried.characters[1].inventory.Credits != 3296 || retried.nextItem != 8 || len(retried.characters[1].inventory.Items) != 8 || + retried.characters[1].inventory.Items[4] != (ownedItem{ID: 5, Type: 51022, Template: 70561, Quality: 1, Slot: 68, Count: 1}) || + retried.characters[1].inventory.Items[5] != (ownedItem{ID: 6, Type: 51022, Template: 70561, Quality: 1, Slot: 69, Count: 1}) { + t.Fatal("whole-basket retry lost a sleeve, changed its identity or charged twice") + } + }) + } +} diff --git a/server/shop_quality_test.go b/server/shop_quality_test.go @@ -30,7 +30,14 @@ func TestShopBasicArmorProductionQualityPurchase(t *testing.T) { t.Fatal(err) } - if client.shop == nil || !reflect.DeepEqual(client.shop.stock, []gamedata.ShopItem{{Template: 85596, Quality: 5}, {Template: 85742, Quality: 5}, {Template: 85638, Quality: 5}, {Template: 85512, Quality: 5}, {Template: 85557, Quality: 5}, {Template: 85686, Quality: 5}, {Template: 70562, Quality: 1}, {Template: 70562, Quality: 2}}) { + if client.shop == nil || !reflect.DeepEqual(client.shop.stock, []gamedata.ShopItem{ + {Template: 85596, Quality: 5}, {Template: 85742, Quality: 5}, {Template: 85638, Quality: 5}, + {Template: 85512, Quality: 5}, {Template: 85557, Quality: 5}, {Template: 85686, Quality: 5}, + {Template: 70562, Quality: 1}, {Template: 70562, Quality: 2}, {Template: 70558, Quality: 1}, {Template: 70558, Quality: 2}, + {Template: 70559, Quality: 1}, {Template: 70559, Quality: 2}, {Template: 70560, Quality: 1}, {Template: 70560, Quality: 2}, + {Template: 70561, Quality: 1}, {Template: 70561, Quality: 2}, {Template: 70563, Quality: 1}, {Template: 70563, Quality: 2}, + {Template: 70564, Quality: 1}, {Template: 70564, Quality: 2}, {Template: 70565, Quality: 1}, {Template: 70565, Quality: 2}, + }) { t.Fatal("basic armor lost its explicit selected-quality subset") }