aorecomp

Anarchy Online classic in the browser

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


commit d5f5a5566db70c3639d4392496baf911e47dd5fa
parent 460cf6b9a26bb8b96dc3fc709ec0373b97169d14
Author: anon <anon@example.com>
Date:   Tue, 27 Oct 2026 09:08:51 +0000

Resolve reviewed weapon qualities across combat and native instances

Admit the audited QL1..11 Rusty Flechette family through shared endpoint data. Resolve numeric instance stats and wear thresholds for player/NPC combat, overequipping, timing, ammunition and pricing without mutating catalog records.

Send numeric differences from the nearer template in weapon FullUpdates: the original client interpolates local weapon construction but remote views require explicit values.

Cover boundary requirements, selected-quality damage and criticals, all OE tiers, generated pickup/wear/sale conservation, failed transactions and cold recovery. Verify both native WASM views and loaded-round persistence; retain evidence and keep production reward-quality selection open in TODO.

Diffstat:
MTODO.md | 12+++++++++++-
Mdocs/catalog-weapons.md | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Mdocs/items.md | 6++++--
Mdocs/npc-loot.md | 11++++++++---
Mserver/equipment.go | 55+++++++++++++++++++++----------------------------------
Mserver/gamedata/item_families.yaml | 2++
Mserver/gamedata/item_quality_test.go | 21+++++++++++----------
Mserver/item_quality.go | 38++++++++++++++++++++++++++++++++++++++
Mserver/ranged.go | 12++++++------
Mserver/shops.go | 14+-------------
Aserver/weapon_quality_lifecycle_test.go | 238+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/weapon_quality_test.go | 254+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/weapon_special.go | 4++--
Mserver/weapon_stats.go | 50+++++++++++++++++++++++++++++++++++++++++++++++---
14 files changed, 739 insertions(+), 81 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -221,7 +221,17 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). requirements, bonuses, damage, attack/recharge, ammunition, price and native low/high template delivery at low, intermediate and boundary QLs. Include pickup, rejected wear, equip/remove, sale and cold recovery of the same instance. - Existing Metaplast interpolation does not establish generic weapon support. + Metaplast and one reviewed QL1..11 Rusty pistol family now use the shared QL + path; useful production loot/shop membership and wider early families remain. +- [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 + endpoints. Remote FullUpdateItem includes resolved numeric differences because + the native client only interpolates locally owned weapon instances. Controlled + QL5 generation survives pickup, repeated equip/remove, cancelled/accepted sale + and cold recovery; failed wear/shot/reload preserves ownership and permits retry. + Historical drop/stock membership and level-relative + QL selection remain separate P0 work. See [catalog weapons](docs/catalog-weapons.md). - [x] Equip one implant. Check: its slot, treatment/ability requirements and bonuses work independently of armor and weapon slots. - [x] Verify passive HealDelta343/NanoDelta364 equipment recovery against the diff --git a/docs/catalog-weapons.md b/docs/catalog-weapons.md @@ -1,18 +1,20 @@ # Catalog main-hand weapons -Weapon admission uses the original type 51018 definition, exact shipped QL, -right-hand slot mask (298 bit 6) and an ordered damage range. It no longer -requires a particular template ID. Unknown stats and requirement operators +Weapon admission uses the original type 51018 definition, an exact shipped QL +or a reviewed family interval, right-hand slot mask (298 bit 6) and an ordered +damage range. It no longer requires a particular template ID. Unknown stats and +requirement operators reject equip rather than treating an unknown stat as zero. Equality and strict minimum predicates joined by AND use effective abilities/skills, level, title, 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 that definition. This enables the original Baseballbat, Oak Bo, Meta -Shield and five solar guns. Left-hand scheduling, dual wield, QL interpolation, -original critical/hit selection and unimplemented item functions remain separate -work; [critical outcomes](critical-hits.md) now have a provisional shared path. +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. +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. A reversed damage range, including template 123868, is rejected until the original interpretation is established; unsigned damage arithmetic must not turn it into an enormous hit. @@ -43,6 +45,93 @@ dynel despawn after the durable delete, including deleted bag children. The original lifetime evidence is retained in `local/starter-weapon-research/inventory-reuse/findings.md`. +## Reviewed Rusty pistol qualities + +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. +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. +The current [Auno QL5 record](https://auno.org/ao/db.php?id=123742&ql=5) +independently names this endpoint pair. It corroborates pairing, not historical +14.9.1 values or a captured original server family table. Its later Fling and +MultiRanged values differ from the original payloads, and its later attack +rating cap is absent from the original records. + +| QL | Damage | Critical bonus | MultiRanged | Minimum Pistol / Fling | Value | +| --- | --- | ---: | ---: | --- | ---: | +| 1 | 3-12 | 12 | 26 | 6 / 6 | 2321 | +| 2 | 3-13 | 12 | 29 | 11 / 8 | 2333 | +| 5 | 3-15 | 13 | 36 | 24 / 15 | 2525 | +| 6 | 3-16 | 14 | 39 | 29 / 18 | 2640 | +| 10 | 3-19 | 15 | 49 | 47 / 27 | 3354 | +| 11 | 3-20 | 15 | 51 | 52 / 29 | 3598 | + +These minimum skills include action8 operator2's strict greater-than rule. +Overequipping instead reads the interpolated raw thresholds, as in the original +consumer. Attack/recharge remain 1.25 seconds, equip delay 1.5 seconds, range 22 meters, +and a magazine of 20 Bullets. Stat436=90 selects ProjectileAC; it is not an attack +rating cap. No OnWear, OnHit or Use gameplay effect appears in this family. +Its four event10 presentation descriptors remain intact for the client. + +The shared instance-stat helper follows original `kkr.dll FUN_100f0c80`'s numeric +property whitelist. `FUN_100eff20` rounds the interpolated difference by adding +0.5 before truncation; stat74 then uses `FUN_100f1320`'s quadratic price curve. +For example, QL5's rounded linear value 2832 becomes final value 2525. Other +properties use the nearer endpoint, with the midpoint choosing high, following +`FUN_100894c0`. `FUN_100f1200` supplies the instance's selected quality. Original +module SHA-256 is recorded below; bounded evidence, payload hashes and confidence +limits are retained in `local/weapon-quality/catalog-audit.md` and +`local/weapon-quality/native-evidence.json`. + +Player and NPC combat share one immutable quality-adjusted weapon definition. +Action8 requirements are copied and interpolated for combat's OE check; equip +admission uses the same scalar rule. Normal/Fling damage, critical bonus, +special timing, equip timing, ammunition capacity/recharge and shop valuation +read the selected quality. Endpoints remain immutable catalog data. This does +not add left-hand attacks or dual-wield scheduling; MultiRanged is resolved for +native instance parity without claiming that subsystem is implemented. + +Native remote weapon construction needs an additional rule. `FUN_100b38b0` +invokes `FUN_100f1200` only when the packet parent is the local actor; +`FUN_100b2830` loads stat23's base definition and applies explicit packet stat +pairs. Consequently, FullUpdateItem now selects the nearer definition for +stat23 and includes each numerical difference from that definition. Loaded +energy26 remains the owned ammunition count and quality54 comes from stat701. +This makes both views agree without changing the original client. The initial +second-client check reproduced raw high-endpoint damage20/value3598 for QL6; +the packet regression retains that failure. Evidence is in +`local/weapon-quality/remote-native-evidence.json`. + +`server/weapon_quality_test.go` checks both stored anchors at QL1,2,5,6,10,11: +strict skill boundaries, equip deadlines, native endpoints, price, catalog +immutability, normal/critical/Fling damage, all OE tiers, ammo, reload and cold +recovery. `server/weapon_quality_lifecycle_test.go` follows a controlled QL5 drop +through death, repeated pickup, equip/remove, cancellation and one durable sale. +Skill loss during delayed equip and failed/ignored placement conserve the item; +failed shot/reload writes preserve both sides and a fresh retry succeeds. NPC +health reaches disk at its ordinary world checkpoint. These controlled drops +establish delivery and consumers, not historical Leet equipment membership, +quality selection, shop stock or mission rewards. Those remain priority work. + +Headed GPU WASM owner/observer checks agree at QL5 and the QL6 midpoint, +including damage, critical bonus, MultiRanged and curved value. One-point-below +Pistol/Fling wear retains the same item. Native reload/cold restart retains +20 rounds and 80 source bullets; a normal hit consumes one round while Fling +retains 19, and both clients receive identical damage/count results. A later +reload leaves 20 rounds and 79 bullets. Removal retires only the observer's dynel; +re-equip preserves identity and resolves the same numbers. No page exception or +adapter abort occurred. Only the two owned QA characters/items were removed; +unrelated stopped-world rows and SQLite integrity were verified. Captures, +assertions and confidence limits are indexed in `local/weapon-quality/README.md`. + +The complete server suite passes 1,421 roots/14,995 results; gamedata passes +23 roots/50 results. The affected selection passes 419 results, final race +checks pass 64 results, and `go vet` passes. Temporary endpoint-only combat and +remote-packet overlays fail the new regressions as expected. Final verification +is retained in `local/weapon-quality/verification.json`. + ## Ammunition contract Original `kkr.dll` SHA-256: diff --git a/docs/items.md b/docs/items.md @@ -109,7 +109,8 @@ A definition is not an owned item. The [initial inventory](inventory.md) persist instance identity, owner, slot and quality for individual items. Known stacks and portable containers are supported. The reviewed interpolation families are listed in `server/gamedata/item_families.yaml`: Metaplast armor, Backpack of -Survival and NCU Hacker Interface. Other interpolated families remain open. +Survival, NCU Hacker Interface and the QL1..11 Rusty OT M-10 Flechette Pistol. +Other interpolated families remain open. CellAO's `Item` constructor takes **quality, low template ID and high template ID**, and its item implementation interpolates properties between the templates. Consequently, one row per extracted ID is @@ -119,7 +120,8 @@ The catalog preserves the endpoint definitions; it does not guess template pairings from neighboring IDs or matching names. The shared family table supplies endpoint identity and quality admission to loot generation, equipment, control edits and native serialization. The six Metaplast pairs and their native interpolation rules are documented in -[armor](armor.md). Recover each additional pairing and its applicable fields +[armor](armor.md); the reviewed pistol and shared numerical stat rules are in +[catalog weapons](catalog-weapons.md). Recover each additional pairing and its applicable fields before generating arbitrary-quality equipment. The server will also need to enforce action requirements and effect behavior rather than relying on the client's displayed description. diff --git a/docs/npc-loot.md b/docs/npc-loot.md @@ -77,8 +77,9 @@ Typed fixture coverage does not establish those items as historical Leet drops. Each loot row requires `template`, `quality` and `chance`. Startup rejects a missing/zero quality, an unknown template and a quality outside the template's reviewed interval. Fixed-QL items accept only their authored quality. The shared -`server/gamedata/item_families.yaml` lists the eight previously reviewed endpoint -pairs: six Metaplast pieces, Backpack of Survival and NCU Hacker Interface. +`server/gamedata/item_families.yaml` lists nine reviewed endpoint pairs: +six Metaplast pieces, Backpack of Survival, NCU Hacker Interface and the QL1..11 +Rusty OT M-10 Flechette Pistol. Either endpoint identifies a family. No name or neighboring-ID heuristic pairs additional definitions, and listing a pair does not implement its effects. @@ -109,7 +110,11 @@ requirements and AC expectations. Two-item failures at the second insert, ignored insert and deferred commit preserve the whole living NPC/reward state; retry retains both requested qualities. Existing periodic and full-inventory checks now also exercise generated QL101 armor. These are controlled profiles, -not evidence for Metaplast drops from Leets. +not evidence for Metaplast drops from Leets. The selected-quality +[pistol tests](catalog-weapons.md#reviewed-rusty-pistol-qualities) additionally +follow a controlled QL5 weapon through pickup, repeated equip/remove, cancelled +sale and one accepted sale after cold recovery, without duplicating its identity +or credits. They do not add that weapon to the production Leet table. The shared-family/selected-quality milestone passed the complete Go suite: 1,415 server roots and 23 gamedata roots, with no failures. The focused selection diff --git a/server/equipment.go b/server/equipment.go @@ -118,34 +118,13 @@ func (character *character) canMoveEquipment(item ownedItem, destination uint32, func (character *character) attackWeapon() *gamedata.Item { if character.npc && character.combatProfile != nil { first, second := gamedata.ItemTemplates[character.combatProfile.Weapon[0]], gamedata.ItemTemplates[character.combatProfile.Weapon[1]] - if first == second || uint32(character.level) == *first.Quality { - return first - } - if uint32(character.level) == *second.Quality { - return second - } - // client/game/kkr.dll/lifted-0035.c::sub_3607B9A0 constructs at actor level. - // Keep categorical fields from the nearer endpoint, as for other item qualities. - weapon := *first - if uint32(character.level)-*first.Quality >= *second.Quality-uint32(character.level) { - weapon = *second - } - quality := uint32(character.level) - weapon.Quality, weapon.Stats = &quality, slices.Clone(weapon.Stats) - for index, stat := range weapon.Stats { - switch stat[0] { - case 54: - weapon.Stats[index][1] = quality - case 210, 284, 285, 286, 287, 294: - weapon.Stats[index][1] = uint32(interpolateItemValue(int32(itemStat(first, stat[0])), int32(itemStat(second, stat[0])), *first.Quality, *second.Quality, quality)) - } - } - return &weapon + return interpolateWeapon(first, second, uint32(character.level)) } for _, item := range character.inventory.Items { if item.Slot == 6 && item.isWieldableWeapon() { - return gamedata.ItemTemplates[item.Template] + low, high := item.templateIDs() + return interpolateWeapon(gamedata.ItemTemplates[low], gamedata.ItemTemplates[high], item.Quality) } } return nil @@ -228,9 +207,9 @@ func (server *server) beginEquipment_locked(client *worldClient, index int, dest // Leave the owned item at its source until the catalog's equip delay expires. // Beholder FUN_1008e840 defaults EquipDelay to 10 centiseconds. delay := 100 * time.Millisecond - for _, stat := range gamedata.ItemTemplates[item.Template].Stats { + for _, stat := range item.templateDefinition().Stats { if stat[0] == 211 { - delay = time.Duration(stat[1]) * 10 * time.Millisecond + delay = time.Duration(item.templateStat(211)) * 10 * time.Millisecond break } } @@ -361,17 +340,25 @@ func weaponPacket(owner, playfield uint32, item ownedItem, page uint32) []byte { body = binary.BigEndian.AppendUint32(body, value) } body = append(body, byte(page), byte(item.Slot)) - count := uint32(5 * 1009) - if item.usesAmmo() { - count = 6 * 1009 - } low, high := item.templateIDs() - for _, value := range []uint32{count, 23, item.Template, 701, item.Quality, 702, low, 703, high} { - body = binary.BigEndian.AppendUint32(body, value) + definition := item.templateDefinition() + stats := [][2]uint32{{23, definition.ID}, {701, item.Quality}, {702, low}, {703, high}} + // kkr.dll FUN_100b38b0 interpolates only the local owner's new weapon. + // Remote instances need numeric differences from stat23's base definition. + for _, stat := range definition.Stats { + if stat[0] != 26 && stat[0] != 54 { + if value := item.templateStat(stat[0]); value != stat[1] { + stats = append(stats, [2]uint32{stat[0], value}) + } + } } if item.usesAmmo() { - body = binary.BigEndian.AppendUint32(body, 26) - body = binary.BigEndian.AppendUint32(body, item.Ammo) + stats = append(stats, [2]uint32{26, item.Ammo}) + } + body = binary.BigEndian.AppendUint32(body, uint32(len(stats)+1)*1009) + for _, stat := range stats { + body = binary.BigEndian.AppendUint32(body, stat[0]) + body = binary.BigEndian.AppendUint32(body, stat[1]) } body = binary.BigEndian.AppendUint32(body, 0) return n3Packet(0x3b1d2268, item.Type, item.ID, body) diff --git a/server/gamedata/item_families.yaml b/server/gamedata/item_families.yaml @@ -11,3 +11,5 @@ - [206730, 206731] # NCU Hacker Interface: docs/tradeskills.md. - [158416, 158417] +# Rusty OT M-10 Flechette Pistol: docs/catalog-weapons.md. +- [123742, 123743] diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go @@ -7,23 +7,24 @@ import ( ) func TestReviewedItemFamilyQualityRanges(t *testing.T) { - for _, pair := range [][2]uint32{{85512, 85511}, {85557, 85556}, {85596, 85595}, {85638, 85637}, {85686, 85685}, {85742, 85741}, {206730, 206731}, {158416, 158417}} { - for _, template := range pair { + for _, family := range []struct { + lowTemplate, highTemplate, lowQuality, highQuality uint32 + }{ + {85512, 85511, 1, 200}, {85557, 85556, 1, 200}, {85596, 85595, 1, 200}, + {85638, 85637, 1, 200}, {85686, 85685, 1, 200}, {85742, 85741, 1, 200}, + {206730, 206731, 50, 150}, {158416, 158417, 1, 200}, {123742, 123743, 1, 11}, + } { + for _, template := range [2]uint32{family.lowTemplate, family.highTemplate} { t.Run(fmt.Sprint(template), func(t *testing.T) { - low, high := uint32(1), uint32(200) - if template == 206730 || template == 206731 { - low, high = 50, 150 - } - - if gamedata.ItemFamilies[template] != pair { + if gamedata.ItemFamilies[template] != [2]uint32{family.lowTemplate, family.highTemplate} { t.Fatal("endpoint does not identify its reviewed family") } - for _, quality := range []uint32{low, low + 1, (low + high) / 2, high - 1, high} { + for _, quality := range []uint32{family.lowQuality, family.lowQuality + 1, (family.lowQuality + family.highQuality) / 2, family.highQuality - 1, family.highQuality} { if !gamedata.ItemQualitySupported(template, quality) { t.Fatal("supported quality rejected", quality) } } - for _, quality := range []uint32{0, low - 1, high + 1, 4294967295} { + for _, quality := range []uint32{0, family.lowQuality - 1, family.highQuality + 1, 4294967295} { if gamedata.ItemQualitySupported(template, quality) { t.Fatal("unsupported quality admitted", quality) } diff --git a/server/item_quality.go b/server/item_quality.go @@ -27,6 +27,44 @@ func (item ownedItem) templateDefinition() *gamedata.Item { return first } +func (item ownedItem) templateStat(stat uint32) uint32 { + low, high := item.templateIDs() + return interpolateItemStat(gamedata.ItemTemplates[low], gamedata.ItemTemplates[high], item.Quality, stat) +} + +func interpolateItemStat(first, second *gamedata.Item, quality, stat uint32) uint32 { + // kkr.dll FUN_100f1200 sets the instance's own quality before interpolation. + if stat == 54 { + return quality + } + if first == second { + return itemStat(first, stat) + } + + // kkr.dll FUN_100f0c80 interpolates these numeric instance properties only. + switch stat { + case 1, 2, 26, 27, 36, 45, 73, 74, 75, 101, 134, 210, 211, 212, 236, 250, + 284, 285, 286, 287, 289, 294, 297, 299, 341, 422: + default: + if quality-*first.Quality >= *second.Quality-quality { + return itemStat(second, stat) + } + return itemStat(first, stat) + } + value := interpolateItemValue(int32(itemStat(first, stat)), int32(itemStat(second, stat)), *first.Quality, *second.Quality, quality) + if stat != 74 { + return uint32(value) + } + + // kkr.dll FUN_100f1320 curves value74 after rounded linear interpolation. + minimum, maximum := min(itemStat(first, 74), itemStat(second, 74)), max(itemStat(first, 74), itemStat(second, 74)) + if minimum == maximum || uint32(value) == minimum || uint32(value) == maximum { + return uint32(value) + } + difference := float64(value) - float64(minimum) + return uint32(float64(minimum) + difference*difference/float64(maximum-minimum)) +} + func interpolateItemValue(first, second int32, firstQuality, secondQuality, quality uint32) int32 { // kkr.dll FUN_100eff20 adds 0.5 before truncating the interpolated difference. if first == second || firstQuality == secondQuality || quality == firstQuality { diff --git a/server/ranged.go b/server/ranged.go @@ -13,13 +13,13 @@ func (item ownedItem) usesAmmo() bool { return false } // Native weapons without a finite clip retain the -1 ammunition sentinel. - clip := itemStat(gamedata.ItemTemplates[item.Template], 212) + clip := item.templateStat(212) return clip != 0 && clip != ^uint32(0) } func (item ownedItem) validAmmo() bool { if item.usesAmmo() { - return item.Ammo <= itemStat(gamedata.ItemTemplates[item.Template], 212) + return item.Ammo <= item.templateStat(212) } return item.Ammo == 0 } @@ -98,15 +98,15 @@ func (server *server) handleReload(client *worldClient, body []byte) error { if accepted { targetType, targetID := binary.BigEndian.Uint32(body[48:52]), binary.BigEndian.Uint32(body[52:56]) source := gamedata.ItemTemplates[player.inventory.Items[ammo].Template] - gun := gamedata.ItemTemplates[player.inventory.Items[weapon].Template] + gun := player.inventory.Items[weapon].templateDefinition() sourceType, sourceHasType := ammunitionType(source) gunType, gunHasType := ammunitionType(gun) accepted = (targetType == 101 && targetID == 6 || targetType == 51018 && targetID == player.inventory.Items[weapon].ID) && itemStat(source, 76) == 0 && sourceHasType && gunHasType && sourceType == gunType } - if accepted && player.inventory.Items[weapon].Ammo < itemStat(gamedata.ItemTemplates[player.inventory.Items[weapon].Template], 212) { + if accepted && player.inventory.Items[weapon].Ammo < player.inventory.Items[weapon].templateStat(212) { source, gun := player.inventory.Items[ammo], player.inventory.Items[weapon] - loaded := min(uint32(source.Count), itemStat(gamedata.ItemTemplates[gun.Template], 212)-gun.Ammo) + loaded := min(uint32(source.Count), gun.templateStat(212)-gun.Ammo) inventory := player.inventory inventory.Items = slices.Clone(inventory.Items) inventory.Items[weapon].Ammo += loaded @@ -118,7 +118,7 @@ func (server *server) handleReload(client *worldClient, body []byte) error { // Pause recharge, or restart an interrupted attack, as in native 100529a0. candidate := *player candidate.inventory = inventory - delay := time.Duration(itemStat(gamedata.ItemTemplates[gun.Template], 210)) * 10 * time.Millisecond + delay := time.Duration(gun.templateStat(210)) * 10 * time.Millisecond readyAt := now.Add(delay) if candidate.fighting != 0 && now.Before(candidate.rechargeUntil) { candidate.rechargeUntil = candidate.rechargeUntil.Add(delay) diff --git a/server/shops.go b/server/shops.go @@ -211,19 +211,7 @@ func (server *server) restoreTradeItems_locked(client *worldClient, offers map[u } func (item ownedItem) shopPrice() uint32 { - low, high := item.templateIDs() - first, second := gamedata.ItemTemplates[low], gamedata.ItemTemplates[high] - if low == high { - return itemStat(first, 74) - } - // kkr.dll FUN_100aa630 and FUN_100f1320 curve stat74 after interpolation. - price := interpolateItemValue(int32(itemStat(first, 74)), int32(itemStat(second, 74)), *first.Quality, *second.Quality, item.Quality) - minimum, maximum := min(itemStat(first, 74), itemStat(second, 74)), max(itemStat(first, 74), itemStat(second, 74)) - if minimum == maximum || uint32(price) == minimum || uint32(price) == maximum { - return uint32(price) - } - difference := float64(price) - float64(minimum) - return uint32(float64(minimum) + difference*difference/float64(maximum-minimum)) + return item.templateStat(74) } func shopSalePrice(item ownedItem, modifier uint32, computerLiteracy int32) uint64 { diff --git a/server/weapon_quality_lifecycle_test.go b/server/weapon_quality_lifecycle_test.go @@ -0,0 +1,238 @@ +package main + +import ( + "ao/server/gamedata" + "bytes" + "encoding/binary" + "fmt" + "slices" + "testing" +) + +func TestWeaponQualityGeneratedPickupEquipRemoveAndSale(t *testing.T) { + for _, template := range []uint32{123742, 123743} { + t.Run(fmt.Sprint(template), 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: 5, 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] + 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 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + for _, move := range [][2]uint32{{64, 6}, {6, 64}, {64, 6}, {6, 64}} { + request := inventoryMovePacket(1, move[0], move[1]) + if move[0] < 64 { + request = itemMovePacket(1, move[0], move[1]) + } + if err := world.handleInventory(client, request[20:]); err != nil || client.equipment == nil { + t.Fatal("generated selected-quality weapon did not move", err) + } + world.advanceEquipment(client.equipment.readyAt) + cold := newTestInventoryServer(t) + expected := []ownedItem{{ID: identity, Type: 51018, Template: template, Quality: 5, 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") + } + } + + // Sell that same instance after cancellation and a cold reconnect. + player.appearance = 0x515 + player.position = [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) + } + if err := world.handleShopUse(client, shopUseRequest(1)); err != nil { + t.Fatal(err) + } + add := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{50000, 1}, [2]uint32{104, 64})[20:] + if err := world.handleTrade(client, add); 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) + } + cold := newTestInventoryServer(t) + if len(cold.characters[1].inventory.Items) != 1 || cold.characters[1].inventory.Credits != 1 { + t.Fatal("cancelled sale lost the selected-quality weapon") + } + world, player = cold, cold.characters[1] + client = &worldClient{id: 1, conn: &combatTestConn{}, target: true, ready: true} + world.clients[1] = client + if err := world.handleShopUse(client, shopUseRequest(1)); err != nil { + t.Fatal(err) + } + if err := world.handleTrade(client, add); 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) + } + } + cold = newTestInventoryServer(t) + + for _, current := range []*server{world, cold} { + if len(current.characters[1].inventory.Items) != 0 || current.characters[1].inventory.Credits != 127 || + 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) + } + if _, exists := current.items[identity]; exists { + t.Fatal("sold weapon returned in the shared cache") + } + } + }) + } +} + +func TestWeaponQualityPendingWearRechecksSkillsAndRollsBack(t *testing.T) { + for _, scenario := range []string{"Pistol fell", "Fling fell", "failed placement", "ignored placement"} { + t.Run(scenario, 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 = characterAbilitiesStats{1, 1, 1, 1, 1, 1} + player.stats.Ranged.Pistol, player.stats.Ranged.FlingShot = 24, 15 + player.inventory.Items[0].Template, player.inventory.Items[0].Quality = 123743, 5 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil { + t.Fatal("qualified selected-quality wear did not begin", err) + } + switch scenario { + case "Pistol fell": + player.stats.Ranged.Pistol = 23 + case "Fling fell": + player.stats.Ranged.FlingShot = 14 + default: + sql := "CREATE TRIGGER fail_quality_wear BEFORE INSERT ON item_locations BEGIN SELECT RAISE(FAIL,'selected quality'); END" + if scenario == "ignored placement" { + sql = "CREATE TRIGGER fail_quality_wear BEFORE INSERT ON item_locations BEGIN SELECT RAISE(IGNORE); END" + } + if _, err := world.db.Exec(sql); err != nil { + t.Fatal(err) + } + } + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + + world.advanceEquipment(client.equipment.readyAt) + after, readErr := readTestItemStore(world) + cold := newTestInventoryServer(t) + + expected := []ownedItem{{ID: 1, Type: 51018, Template: 123743, Quality: 5, Slot: 64, Count: 1}} + if readErr != nil || !bytes.Equal(before, after) || !slices.Equal(player.inventory.Items, expected) || + !slices.Equal(cold.characters[1].inventory.Items, expected) || client.equipment != nil { + t.Fatal("interrupted selected-quality wear changed ownership or placement", readErr) + } + for _, packet := range output.packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x3b1d2268 { + t.Fatal("rejected wear published a live weapon instance") + } + } + }) + } +} + +func TestWeaponQualityFailedShotAndReloadPreserveBothSides(t *testing.T) { + for _, action := range []string{"shot", "reload"} { + t.Run(action, func(t *testing.T) { + world, output := newRangedWorld(t) + player, client := world.characters[1], world.clients[1] + player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} + player.stats.Ranged.Pistol, player.stats.Ranged.FlingShot = 400, 100 + world.combatRoll = func(limit uint32) uint32 { return limit - 1 } + player.inventory.Items[0].Quality = 5 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + if _, err := world.db.Exec("CREATE TRIGGER fail_quality_ammo BEFORE UPDATE OF ammo ON items WHEN NEW.id=1 BEGIN SELECT RAISE(FAIL,'selected-quality ammo'); END"); err != nil { + t.Fatal(err) + } + output.packets = nil + + if action == "reload" { + if err := world.handleReload(client, explicitReloadRequest(1, 64, 1)); err == nil { + t.Fatal("failed reload reported success") + } + } else { + if err := world.handleCombat(client, attackPacket(1, 1000000)[20:]); err != nil { + t.Fatal(err) + } + world.advanceCombat(player.nextAttack) + } + cold := newTestInventoryServer(t) + + for _, current := range []*server{world, cold} { + if current.characters[1].inventory.Items[0].Ammo != 3 || current.characters[1].inventory.Items[1].Count != 100 || + current.characters[1].inventory.Items[0].Quality != 5 || current.characters[1000000].health != 1000 { + t.Fatal("failed quality-aware ammo transaction changed either side") + } + } + for _, packet := range output.packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x46002f16 || binary.BigEndian.Uint32(packet[16:20]) == 0x26515e61 { + t.Fatal("failed ammo transaction published a shot or transfer") + } + } + + // Retry a fresh request after removing the fault; retain the selected quality. + if _, err := world.db.Exec("DROP TRIGGER fail_quality_ammo"); err != nil { + t.Fatal(err) + } + if action == "reload" { + if err := world.handleReload(client, explicitReloadRequest(2, 64, 1)); err != nil { + t.Fatal(err) + } + } else { + if err := world.handleCombat(client, attackPacket(1, 1000000)[20:]); err != nil { + t.Fatal(err) + } + world.advanceCombat(player.nextAttack) + } + // NPC health reaches disk at the normal world checkpoint. + if err := world.flushWorld(); err != nil { + t.Fatal(err) + } + cold = newTestInventoryServer(t) + ammo, remaining, health := uint32(2), uint16(100), uint32(970) + if action == "reload" { + ammo, remaining, health = 20, 83, 1000 + } + if cold.characters[1].inventory.Items[0].Ammo != ammo || cold.characters[1].inventory.Items[1].Count != remaining || + cold.characters[1000000].health != health || cold.characters[1].inventory.Items[0].Quality != 5 { + t.Fatal("ammo retry lost or repeated the selected-quality outcome", cold.characters[1].inventory, cold.characters[1000000].health) + } + }) + } +} diff --git a/server/weapon_quality_test.go b/server/weapon_quality_test.go @@ -0,0 +1,254 @@ +package main + +import ( + "ao/server/gamedata" + "bytes" + "encoding/binary" + "encoding/json" + "fmt" + "reflect" + "testing" + "time" +) + +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}, + } { + t.Run(fmt.Sprintf("%d/QL%d", template, scenario.quality), func(t *testing.T) { + world, owner := newEquipmentWorld(t) + t.Cleanup(func() { world.db.Close() }) + 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.Pistol, player.stats.Ranged.FlingShot = scenario.pistol-1, scenario.fling + player.inventory.Items[0].Template, player.inventory.Items[0].Quality = template, 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[123742], gamedata.ItemTemplates[123743]}) + if err != nil { + t.Fatal(err) + } + + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment != nil { + t.Fatalf("one point below the Pistol requirement equipped: %v", err) + } + player.stats.Ranged.Pistol, player.stats.Ranged.FlingShot = scenario.pistol, scenario.fling-1 + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment != nil { + t.Fatalf("one point below the Fling requirement equipped: %v", err) + } + if after, err := readTestItemStore(world); err != nil || !bytes.Equal(before, after) || player.inventory.Items[0].Slot != 64 { + t.Fatalf("rejected equip changed the stored item: %v", err) + } + player.stats.Ranged.FlingShot = scenario.fling + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + owner.packets = nil + started := time.Now() + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil { + t.Fatalf("qualified skills could not equip: %v", err) + } + finish := client.equipment.readyAt + world.advanceEquipment(finish.Add(-time.Nanosecond)) + if player.inventory.Items[0].Slot != 64 { + t.Fatal("weapon moved before the equip deadline") + } + world.advanceEquipment(finish) + restored := newTestInventoryServer(t).characters[1] + weapon := restored.attackWeapon() + afterCatalog, err := json.Marshal([]*gamedata.Item{gamedata.ItemTemplates[123742], gamedata.ItemTemplates[123743]}) + if err != nil { + t.Fatal(err) + } + + 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 || + !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 { + high = low + } else if scenario.quality == 11 { + low = high + } + var delivered []byte + for _, packet := range owner.packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x3b1d2268 { + delivered = packet + } + } + if len(delivered) < 91 || binary.BigEndian.Uint32(delivered[71:75]) != scenario.quality || + binary.BigEndian.Uint32(delivered[79:83]) != low || binary.BigEndian.Uint32(delivered[87:91]) != high { + t.Fatalf("weapon delivery lost selected QL/endpoints: %x", delivered) + } + if len(observer.packets) == 0 || !bytes.Equal(delivered[16:], observer.packets[0][16:]) { + t.Fatal("observer did not receive the same quality-adjusted weapon") + } + // Remote native items load stat23's template and then apply packet overrides. + 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:]) + } + definition := uint32(123742) + if scenario.quality >= 6 { + definition = 123743 + } + 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} { + actual, overridden := stats[stat] + if !overridden { + actual = itemStat(gamedata.ItemTemplates[stats[23]], stat) + } + if actual != expected { + t.Fatalf("remote stat%d: got%d want%d", stat, actual, expected) + } + } + }) + } + } +} + +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 _, 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.inventory.Items[0].Template, player.inventory.Items[0].Quality = template, scenario.quality + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + world.combatRoll = func(limit uint32) uint32 { + if limit == 100 && critical { + return 0 + } + return limit - 1 + } + expected := scenario.normal + if critical { + expected = scenario.critical + } + + if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil { + t.Fatal(err) + } + world.advanceCombat(player.nextAttack) + if err := world.handleWeaponSpecial(client, flingShotRequest(1, target.id)[20:]); err != nil { + t.Fatal(err) + } + shotRecovery := newTestInventoryServer(t).characters[1] + started := time.Now() + if err := world.handleReload(client, explicitReloadRequest(1, 64, 1)); err != nil { + t.Fatal(err) + } + reloaded := newTestInventoryServer(t).characters[1] + + normal, fling := 0, 0 + for _, packet := range owner.packets { + switch binary.BigEndian.Uint32(packet[16:20]) { + case 0x46002f16: + if binary.BigEndian.Uint32(packet[24:28]) != 1 { + continue + } + normal++ + if binary.BigEndian.Uint32(packet[29:33]) != expected || binary.BigEndian.Uint32(packet[33:37]) != 2 { + t.Fatalf("normal damage/ammo: %x", packet) + } + case 0x754f1115: + fling++ + if binary.BigEndian.Uint32(packet[33:37]) != expected || binary.BigEndian.Uint32(packet[37:41]) != 2 { + t.Fatalf("Fling damage/ammo: %x", packet) + } + } + } + if normal != 1 || fling != 1 || target.health != 1000-2*expected || + shotRecovery.inventory.Items[0].Ammo != 2 || shotRecovery.inventory.Items[1].Count != 100 || + 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)) { + t.Fatalf("selected-quality combat/reload recovery: normal=%d fling=%d HP=%d items=%+v", normal, fling, target.health, reloaded.inventory.Items) + } + }) + } + } + } +} + +func TestWeaponQualityOverequippingUsesInterpolatedFlingRequirement(t *testing.T) { + for _, template := range []uint32{123742, 123743} { + for _, scenario := range []struct { + fling uint16 + damage uint32 + }{ + {17, 32}, {14, 32}, {13, 24}, {10, 16}, {6, 8}, {3, 0}, + } { + t.Run(fmt.Sprintf("%d/Fling%d", template, scenario.fling), func(t *testing.T) { + world, owner := newRangedWorld(t) + player, target := world.characters[1], world.characters[1000000] + player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} + player.stats.Ranged.Pistol, player.stats.Ranged.FlingShot = 400, scenario.fling + player.inventory.Items[0].Template, player.inventory.Items[0].Quality = template, 6 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + + if err := world.handleCombat(world.clients[1], attackPacket(1, target.id)[20:]); err != nil { + t.Fatal(err) + } + world.advanceCombat(player.nextAttack) + restored := newTestInventoryServer(t).characters[1] + + shots := 0 + for _, packet := range owner.packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x46002f16 && binary.BigEndian.Uint32(packet[24:28]) == 1 { + shots++ + if binary.BigEndian.Uint32(packet[29:33]) != scenario.damage { + t.Fatalf("OE damage: got %d want %d", binary.BigEndian.Uint32(packet[29:33]), scenario.damage) + } + } + } + if shots != 1 || target.health != 1000-scenario.damage || restored.inventory.Items[0].Ammo != 2 || + restored.inventory.Items[0].Quality != 6 || restored.stats.Ranged.FlingShot != scenario.fling { + t.Fatalf("OE shot or cold recovery changed: shots=%d HP=%d items=%+v", shots, target.health, restored.inventory.Items) + } + }) + } + } +} diff --git a/server/weapon_special.go b/server/weapon_special.go @@ -51,13 +51,13 @@ func (server *server) handleWeaponSpecial(client *worldClient, body []byte) erro break } } - if item == nil || itemStat(gamedata.ItemTemplates[item.Template], 30)&capability == 0 || skill == 150 && item.usesAmmo() && item.Ammo == 0 { + if item == nil || item.templateStat(30)&capability == 0 || skill == 150 && item.usesAmmo() && item.Ammo == 0 { server.mutex.Unlock() return nil } // Prepare a detached result so a failed transaction changes no live actor. - seconds := player.weaponSpecialLockSeconds(gamedata.ItemTemplates[item.Template], skill) + seconds := player.weaponSpecialLockSeconds(player.attackWeapon(), skill) damage, _ := server.weaponHit_locked(player, target) candidate := server.prepareWeaponDamage_locked(player, target, damage, now) award, err := server.saveSpecialAttack_locked(player, &candidate, skill, now.Add(time.Duration(player.skillLockSeconds(seconds))*time.Second), now) diff --git a/server/weapon_stats.go b/server/weapon_stats.go @@ -1,12 +1,56 @@ package main -import "ao/server/gamedata" +import ( + "ao/server/gamedata" + "slices" +) func (item ownedItem) isWieldableWeapon() bool { definition := gamedata.ItemTemplates[item.Template] return item.Type == 51018 && definition != nil && definition.HeaderWords[0] == item.Type && - item.Quality == *definition.Quality && itemStat(definition, 298)&64 != 0 && - itemStat(definition, 285) >= itemStat(definition, 286) + gamedata.ItemQualitySupported(item.Template, item.Quality) && item.templateStat(298)&64 != 0 && + item.templateStat(285) >= item.templateStat(286) +} + +func interpolateWeapon(first, second *gamedata.Item, quality uint32) *gamedata.Item { + if first == second || quality == *first.Quality { + return first + } + if quality == *second.Quality { + return second + } + + // Keep categorical properties from the nearer endpoint without editing the catalog. + weapon := *first + if quality-*first.Quality >= *second.Quality-quality { + weapon = *second + } + weapon.Quality, weapon.Stats = &quality, slices.Clone(weapon.Stats) + for index, stat := range weapon.Stats { + weapon.Stats[index][1] = interpolateItemStat(first, second, quality, stat[0]) + } + + // Combat's OE checks use the same interpolated wear thresholds as equip admission. + weapon.Sections = slices.Clone(weapon.Sections) + for sectionIndex, section := range weapon.Sections { + if section.Actions == nil { + continue + } + actions := slices.Clone(*section.Actions) + for actionIndex, action := range actions { + if action.Type != 8 { + continue + } + actions[actionIndex].Requirements = slices.Clone(action.Requirements) + for index := range actions[actionIndex].Requirements { + lower := (*first.Sections[sectionIndex].Actions)[actionIndex].Requirements[index] + upper := (*second.Sections[sectionIndex].Actions)[actionIndex].Requirements[index] + actions[actionIndex].Requirements[index].Value = interpolateItemValue(lower.Value, upper.Value, *first.Quality, *second.Quality, quality) + } + } + weapon.Sections[sectionIndex].Actions = &actions + } + return &weapon } func (character *character) effectiveStat(stat uint32) (int32, bool) {