aorecomp

Anarchy Online classic in the browser

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


commit d678d798b5f9c6e6a989d5cd07b566679f8a7651
parent 33da05bad6eabe4910239457b66e28940fa3ab61
Author: anon <anon@example.com>
Date:   Wed, 28 Oct 2026 02:03:17 +0000

Select corpse loot quality from validated profile intervals

Diffstat:
MTODO.md | 23+++++++++++++++++------
Adocs/loot-quality-ranges.md | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/npc-loot.md | 33++++++++++++++++++---------------
Mserver/gamedata/item_families.yaml | 2++
Mserver/gamedata/item_quality_test.go | 4++--
Mserver/gamedata/load.go | 3++-
Mserver/gamedata/npc_combat.yaml | 10+++++-----
Mserver/gamedata/types.go | 6+++---
Mserver/npc_loot.go | 6+++++-
Mserver/npc_loot_progression_test.go | 2+-
Mserver/npc_loot_quality_test.go | 6+++---
Aserver/npc_loot_range_test.go | 230+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/npc_loot_test.go | 8++++----
Mserver/starter_boss_test.go | 2+-
Mserver/weapon_quality_lifecycle_test.go | 2+-
15 files changed, 374 insertions(+), 43 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -837,10 +837,10 @@ are recorded in [reclaim](docs/reclaim.md). equip or sell, matching requirements, stable instance identity, repeat/restart behavior and atomic rejection with full inventory. Record the evidence and any provisional chances/cash values separately; reuse shared reward/item rules. - The first production profile now rolls QL 1 Monster Parts independently at a - provisional 50% chance and 1..5 cash. Useful equipment, broader levels/species, - original distributions/quality selection and the complete native pickup/equip/ - sale route remain open. The mirrored Leets page names Monster Parts but dates + The production level-1/2 Leet profiles roll Monster Parts independently at a + provisional 50% chance and 1..5 cash. Level 1 selects QL1; level 2 selects + uniformly from QL1..3. Useful equipment, broader levels/species and original + distributions remain open. The mirrored Leets page names Monster Parts but dates to 2010; neither it nor the dated newbie gathering accounts establish 14.9.1 drop chances or cash formulas. See [NPC loot](docs/npc-loot.md). - [x] Connect selected-quality regular equipment to an authored training boss. @@ -869,13 +869,24 @@ are recorded in [reclaim](docs/reclaim.md). QL or extrapolate past its reviewed interval. Test different enemy levels, low/high boundaries, empty rolls, full inventory, transaction failure/retry, repeated pickup and restart. Label provisional selection rules explicitly. +- [x] Select loot qualities from explicit validated inclusive intervals. Successful + membership rolls sample the configured interval; fixed and empty drops consume + no quality draw. The selected instance commits atomically with the death and + survives pickup, rejected wear, canceled/accepted sale and cold recovery. Tests + cover all direct killing actions, different levels, interval boundaries and + SQL failure/ignored-write/commit rollback and retry. Regular Monster Parts now + share reviewed QL1..400 endpoints. The level-2 Leet QL1..3 interval is explicitly + provisional; recovering period distributions remains P0 above. A hardware + WASM level-2 Leet kill generated a QL1 part, 100 XP and five credits; native + pickup/reconnect retained its identity. Controlled caster skills/health verify + delivery, not starting-character balance. See [loot quality ranges](docs/loot-quality-ranges.md). - [x] Deliver an explicitly selected supported QL through shared death outcomes. Reviewed endpoint pairs now live in one data table; loot rows require a valid QL instead of inheriting a shipped endpoint's QL. Controlled profiles verify intermediate armor through all direct attacks, periodic damage, native packet endpoints, pickup, rejected wear, equip/remove, full inventory, cold recovery - and two-item SQL failure/retry. Both real Leet profiles still select QL1 Monster - Parts; historical distributions and useful equipment membership remain above. + and two-item SQL failure/retry. Historical distributions and useful equipment + membership remain above. - [x] Follow generated loot through equipment and sale consumers. Check: a controlled weapon drop survives pickup, cold load, rejected wear below its requirements, skill-training requests and wear/remove/wear with one stable identity. diff --git a/docs/loot-quality-ranges.md b/docs/loot-quality-ranges.md @@ -0,0 +1,80 @@ +# Loot quality intervals + +NPC loot keeps membership and quality selection separate. Each row supplies +`template`, `quality: [low, high]` and its independent chance. A successful row +samples uniformly and inclusively within that interval, using the existing +reward roll source. `[q, q]` preserves a fixed QL without another random draw; +an empty membership roll never samples a quality. The selected QL, physical +instance, corpse placement, cash and XP commit through the existing death +transaction. Failed or ignored writes and failed commit publish none of them. +Reconnect and checkpoints restore the committed selection rather than reroll it. + +Startup rejects zero, reversed and unsupported bounds. A range must fit the +reviewed family addressed by its template; it is never clamped or extrapolated. +Fixed-QL exceptions use their one authored QL. Endpoint membership remains in +`server/gamedata/item_families.yaml`, not name matching or per-item Go branches. +Shops, missions, pricing, requirements, equipment and native serialization retain +the shared interpolation implementation. + +Production selections currently remain deliberately small: + +| Admitted encounter | Drop | Selected QL | +| --- | --- | --- | +| Level 1 Leet | Monster Parts | 1 | +| Level 2 Leet | Monster Parts | 1..3 | +| Authored level-4 Clan training boss | Metaplast gloves / Rusty pistol | 4 / 4 | + +The level-2 interval and uniform distribution are reconstruction policy. The +existing membership chances, cash and reward baselines remain provisional. +This does not claim a universal original `loot QL = creature level` rule or +scale outdoor NPCs to a visiting player's level. Broader species, useful equipment +pools, mission generation and historical distributions remain open P0 work. + +## Regular Monster Parts + +Complete original records 1000020/42640 and 42641 have matching type 51005 headers, +flags, carry capability, strings and empty effect sections. They differ only in +QL stat 54 (1/400), icon stat 79 (144704/144701) and value stat 74 (100/10000). The original payload +hashes match the decoded catalog. Full records, offsets, index digest and the +two 126-byte payload slices are in `local/loot-quality-research/monster-parts-audit.json`. +This admits one explicit family; it does not establish a creature distribution. + +The existing native-derived rule curves value stat 74 after rounded interpolation, +while choosing nonnumeric properties from the nearer endpoint. The native WASM +inventory shows the low icon at QL200 and the high icon at QL201. Its information +window shows intermediate and endpoint QLs, including 2, 200 and 400. The native +training shop quotes 128 credits for QL200, 129 for QL201 and 500 for QL400 at the +controlled fixture's literacy. Cancelling preserves the exact instance; accepting +the QL200 sale removes that instance and credits 128 once. Cold recovery retains +the five other selected qualities and the 128-credit balance. These GM-provisioned +items verify interpolation and ownership, not an earned-income progression gate. + +A [November 2002 firsthand crafting guide](https://www.paradisesgarage.com/arcanum/armor_fleshhood.html) +corroborates variable-quality regular Monster Parts, without specifying drop +ranges. The searchable guide text was available but a subsequent direct fetch +failed. Much later [player accounts](https://forums.funcom.com/t/seeking-info-on-finding-ql-item-to-the-correct-dyna-boss-level-range/227584) +disagree about fixed-level and percentage ranges; they do not establish 14.9.1 +selection rules. Bounded source notes and access limitations are retained in +`local/loot-quality-research/selection-evidence.md`. + +The hardware WASM run also killed an unchanged full-health level-2 Tir County +Leet through seven normal Winter's Bite casts. It awarded 100 XP and five credits +and generated physical instance 13, a QL1 Monster Part. Native corpse pickup, +page reconnect and a saved SQLite read retained that exact instance and reward +accounting. The caster had controlled skills and health; this verifies the +production reward path, not ordinary starting-character balance. This random +sample rolled QL1; QL2/3 production selections are covered by controlled tests. + +## Verification + +Public attack-handler tests exercise fixed, low, middle, high and empty results, +all six direct killing actions, cold recovery, full inventory, repeated pickup, +rejected wear, cancelled/accepted sale and SQL failure/ignored-write/deferred +commit rollback and retry. Actual package-startup overlays reject zero, reversed +and out-of-family intervals. Existing typed loot, armor/weapon quality, boss and +sale regressions pass with explicit fixed intervals. + +The focused selection passed 51 roots/261 results. The race selection passed 14 +roots/34 results; `go vet` and the server build passed. Headed hardware WASM +captures, raw inventory rows, item accounting, cold snapshots and wire evidence +are retained in `local/loot-quality-research/`. No native adapter edit was needed. diff --git a/docs/npc-loot.md b/docs/npc-loot.md @@ -4,21 +4,22 @@ Normal deaths generate rewards from the admitted species/level combat profile. Species evidence in the stable definition is required; a matching placeholder body alone does not qualify. See [profile eligibility](npc-profile-eligibility.md). The current production profiles are level 1 and level 2 Leets. Each configured loot row rolls -independently, creates one item at its explicitly configured quality, and +independently, selects a quality from its explicit inclusive interval, and places it in a free corpse slot. Cash is selected inclusively from the configured range. Unprofiled creatures do not inherit a universal loot table. -Both explicit levels currently select the same provisional rewards below. -The level-2 weapon curve does not establish a loot-quality curve, larger cash -award or XP scaling formula. Its Monster Part therefore remains fixed QL1. +Level 1 selects fixed QL1 Monster Parts; level 2 selects uniformly from QL1..3. +These are explicit reconstruction selections, not a recovered loot-quality +curve. The level-2 weapon curve does not establish a larger cash award or XP +scaling formula. See [quality ranges](loot-quality-ranges.md). The [profile report](combat-npc-balance.md#explicit-leet-profiles) separates those choices from the recovered weapon values and population identities. The first table uses original Monster Parts 42640, QL 1, with a **provisional 50% chance and 1..5 credits**. Those probabilities and cash amounts are reconstruction values, not recovered 14.9.1 formulas. The independent-row/uniform-cash policy is -also provisional. No equipment drop, variable quantity or interpolated loot -quality is inferred from a creature's name or level. Useful equipment loot, +also provisional. No equipment drop, variable quantity or universal loot-quality +formula is inferred from a creature's name or level. Useful equipment loot, broader species/levels and original reward distributions remain open in TODO. ## Evidence boundary @@ -74,12 +75,14 @@ Typed fixture coverage does not establish those items as historical Leet drops. ## Selected item qualities -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 nine reviewed endpoint pairs: -six Metaplast pieces, Backpack of Survival, NCU Hacker Interface and the QL1..11 -Rusty OT M-10 Flechette Pistol. +Each loot row requires `template`, inclusive `quality: [low, high]` and `chance`. +Startup rejects missing/zero or reversed bounds, unknown templates and intervals +outside the template's reviewed family. Fixed-QL items accept only their authored +quality as both bounds. Quality is sampled after successful membership; fixed +and empty drops do not consume a quality roll. The shared +`server/gamedata/item_families.yaml` lists ten reviewed endpoint pairs: +six Metaplast pieces, Backpack of Survival, NCU Hacker Interface, the QL1..11 +Rusty OT M-10 Flechette Pistol and regular QL1..400 Monster Parts. Either endpoint identifies a family. No name or neighboring-ID heuristic pairs additional definitions, and listing a pair does not implement its effects. @@ -92,9 +95,9 @@ rejected rather than clamped or substituted with a shipped endpoint's QL. This separates quality delivery from selecting the historical quality distribution. The explicit species/level profiles can choose different supported -qualities without a universal `item QL = NPC level` rule. Both production Leet -profiles still choose QL1 Monster Parts. Wider item families, level-relative -selection, useful equipment drop membership and mission rewards remain open. +qualities without a universal `item QL = NPC level` rule. Level 1 Leets retain +QL1 parts and level 2 uses the explicitly provisional QL1..3 interval. Wider item families, historical quality distributions, useful equipment +drop membership and broader mission rewards remain open. The shipped `cd_image/text/help/How do I play this Game Alone.txt` recommends armor around character QL and a weapon at least at character QL for solo play. diff --git a/server/gamedata/item_families.yaml b/server/gamedata/item_families.yaml @@ -13,3 +13,5 @@ - [158416, 158417] # Rusty OT M-10 Flechette Pistol: docs/catalog-weapons.md. - [123742, 123743] +# Monster Parts: complete original descriptor audit; docs/npc-loot.md. +- [42640, 42641] diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go @@ -12,7 +12,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}, - {206730, 206731, 50, 150}, {158416, 158417, 1, 200}, {123742, 123743, 1, 11}, + {42640, 42641, 1, 400}, {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) { @@ -38,7 +38,7 @@ func TestUnreviewedItemQualityRemainsExact(t *testing.T) { for _, entry := range []struct { template, quality uint32 supported bool - }{{42640, 1, true}, {42640, 2, false}, {209283, 1, true}, {209283, 2, false}, {85557, 0, false}, {4294967295, 1, false}} { + }{{209283, 1, true}, {209283, 2, false}, {85557, 0, 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/gamedata/load.go b/server/gamedata/load.go @@ -245,7 +245,8 @@ func init() { panic(fmt.Errorf("NPC combat profile %d/%d has invalid corpse cash", monster, level)) } for _, drop := range profile.Loot { - if drop.Chance > 100 || !ItemQualitySupported(drop.Template, drop.Quality) { + if drop.Chance > 100 || drop.Quality[0] > drop.Quality[1] || + !ItemQualitySupported(drop.Template, drop.Quality[0]) || !ItemQualitySupported(drop.Template, drop.Quality[1]) { panic(fmt.Errorf("NPC combat profile %d/%d has invalid loot %d", monster, level, drop.Template)) } } diff --git a/server/gamedata/npc_combat.yaml b/server/gamedata/npc_combat.yaml @@ -21,7 +21,7 @@ credits: [1, 5] loot: - template: 42640 - quality: 1 + quality: [1, 1] chance: 50 2: # Retained prototype health and the same provisional solo reward, not a scaling formula. @@ -34,11 +34,11 @@ agg_def: 75 respawn_seconds: 100 corpse_seconds: 180 - # Fixed QL1 Monster Parts and cash policy remain provisional; no QL curve is inferred. + # Provisional nearby QL1..3 Monster Parts; this is not a recovered loot curve. credits: [1, 5] loot: - template: 42640 - quality: 1 + quality: [1, 3] chance: 50 30354: @@ -60,8 +60,8 @@ # See docs/starter-boss.md for original placement, item facts and evidence limits. loot: - template: 85596 - quality: 4 + quality: [4, 4] chance: 50 - template: 123742 - quality: 4 + quality: [4, 4] chance: 25 diff --git a/server/gamedata/types.go b/server/gamedata/types.go @@ -74,9 +74,9 @@ type NPCCombatProfile struct { } type NPCLoot struct { - Template uint32 `yaml:"template"` - Quality uint32 `yaml:"quality"` - Chance uint32 `yaml:"chance"` + Template uint32 `yaml:"template"` + Quality [2]uint32 `yaml:"quality,flow"` + Chance uint32 `yaml:"chance"` } type NPCPlayfield struct { diff --git a/server/npc_loot.go b/server/npc_loot.go @@ -34,9 +34,13 @@ func (server *server) rollCorpseLoot_locked(target *character) ([]ownedItem, err for slices.ContainsFunc(target.corpse.items, func(item ownedItem) bool { return item.Slot == slot }) { slot++ } + quality := drop.Quality[0] + if drop.Quality[1] > quality { + quality += roll(drop.Quality[1] - quality + 1) + } next++ definition := gamedata.ItemTemplates[drop.Template] - item := ownedItem{ID: next, Type: definition.HeaderWords[0], Template: definition.ID, Quality: drop.Quality, Slot: slot, Count: 1} + item := ownedItem{ID: next, Type: definition.HeaderWords[0], Template: definition.ID, Quality: quality, Slot: slot, Count: 1} drops = append(drops, item) target.corpse.items = append(target.corpse.items, item) slot++ diff --git a/server/npc_loot_progression_test.go b/server/npc_loot_progression_test.go @@ -15,7 +15,7 @@ func TestNPCLootWeaponRetainsInstanceAcrossRejectedWearTrainingAndReequip(t *tes } // This controlled table tests weapon delivery, not historical Leet membership. profile := *world.characters[1000000].combatProfile - profile.Loot = []gamedata.NPCLoot{{Template: 209283, Quality: 1, Chance: 100}} + profile.Loot = []gamedata.NPCLoot{{Template: 209283, Quality: [2]uint32{1, 1}, Chance: 100}} world.characters[1000000].combatProfile = &profile world.combatRoll = func(uint32) uint32 { return 0 } identity := world.nextItem + 1 diff --git a/server/npc_loot_quality_test.go b/server/npc_loot_quality_test.go @@ -15,7 +15,7 @@ func TestNPCDeathGeneratesSelectedArmorQualityAcrossAttackPaths(t *testing.T) { t.Run(attack, func(t *testing.T) { world, _ := newKillExperienceWorld(t, attack) profile := *world.characters[1000000].combatProfile - profile.Loot = []gamedata.NPCLoot{{Template: 85557, Quality: 101, Chance: 100}} + profile.Loot = []gamedata.NPCLoot{{Template: 85557, Quality: [2]uint32{101, 101}, Chance: 100}} world.characters[1000000].combatProfile = &profile world.combatRoll = func(uint32) uint32 { return 0 } identity := world.nextItem + 1 @@ -48,7 +48,7 @@ func TestNPCLootSelectedArmorQualitySurvivesPickupAndWear(t *testing.T) { player, client := world.characters[1], world.clients[1] player.stats.Abilities.Strength, player.stats.Abilities.Agility = 0, 0 profile := *world.characters[1000000].combatProfile - profile.Loot = []gamedata.NPCLoot{{Template: template, Quality: entry.quality, Chance: 100}} + profile.Loot = []gamedata.NPCLoot{{Template: template, Quality: [2]uint32{entry.quality, entry.quality}, Chance: 100}} world.characters[1000000].combatProfile = &profile world.combatRoll = func(uint32) uint32 { return 0 } identity := world.nextItem + 1 @@ -125,7 +125,7 @@ func TestNPCLootSelectedQualityFailureRollsBackTheWholeDeath(t *testing.T) { t.Run(fault.name, func(t *testing.T) { world, _ := newKillExperienceWorld(t, "unarmed") profile := *world.characters[1000000].combatProfile - profile.Loot = []gamedata.NPCLoot{{Template: 85557, Quality: 2, Chance: 100}, {Template: 85556, Quality: 101, Chance: 100}} + profile.Loot = []gamedata.NPCLoot{{Template: 85557, Quality: [2]uint32{2, 2}, Chance: 100}, {Template: 85556, Quality: [2]uint32{101, 101}, Chance: 100}} world.characters[1000000].combatProfile = &profile world.combatRoll = func(uint32) uint32 { return 0 } before := world.nextItem diff --git a/server/npc_loot_range_test.go b/server/npc_loot_range_test.go @@ -0,0 +1,230 @@ +package main + +import ( + "ao/server/gamedata" + "fmt" + "slices" + "testing" + "time" +) + +func TestRangedEquipmentLootAcrossKillingActions(t *testing.T) { + for _, attack := range []string{"unarmed", "axe", "pistol", "fling", "fast", "nano"} { + t.Run(attack, func(t *testing.T) { + world, _ := newKillExperienceWorld(t, attack) + profile := *world.characters[1000000].combatProfile + profile.Loot = []gamedata.NPCLoot{{Template: 85596, Quality: [2]uint32{3, 5}, Chance: 100}} + world.characters[1000000].combatProfile = &profile + world.combatRoll = func(limit uint32) uint32 { + if limit == 3 { + return 1 + } + return 0 + } + identity := world.nextItem + 1 + + attackForExperience(t, world, attack) + world.advanceCombat(time.Now().Add(time.Hour)) + world.advanceNanos(time.Now().Add(time.Hour)) + cold := newTestInventoryServer(t) + + if !slices.Equal(cold.characters[1000000].corpse.items, []ownedItem{{ID: identity, Type: 51022, Template: 85596, Quality: 4, Count: 1}}) || cold.nextItem != identity || cold.characters[1].experience != 100 { + t.Fatal("killing action lost or repeated its selected range quality") + } + }) + } +} + +func TestProductionLootQualityRangeBoundaries(t *testing.T) { + for _, scenario := range []struct { + level uint16 + qualityRoll uint32 + empty bool + quality uint32 + lastBounds []uint32 + }{ + {1, 0, false, 1, []uint32{5, 100}}, + {2, 0, false, 1, []uint32{5, 100, 3}}, + {2, 1, false, 2, []uint32{5, 100, 3}}, + {2, 2, false, 3, []uint32{5, 100, 3}}, + {2, 2, true, 0, []uint32{5, 100}}, + } { + t.Run(fmt.Sprintf("%d/%d/empty=%t", scenario.level, scenario.qualityRoll, scenario.empty), func(t *testing.T) { + world, _ := newKillExperienceWorld(t, "unarmed") + target := world.characters[1000000] + target.level, target.combatProfile = scenario.level, gamedata.NPCCombatProfiles[17655][scenario.level] + var bounds []uint32 + world.combatRoll = func(limit uint32) uint32 { + bounds = append(bounds, limit) + if limit == 3 { + return scenario.qualityRoll + } + if scenario.empty && limit == 100 { + return 50 + } + return 0 + } + identity := world.nextItem + 1 + + attackForExperience(t, world, "unarmed") + world.advanceCombat(world.characters[1].nextAttack) + cold := newTestInventoryServer(t) + + if len(bounds) < len(scenario.lastBounds) || !slices.Equal(bounds[len(bounds)-len(scenario.lastBounds):], scenario.lastBounds) { + t.Fatal("fixed or empty drop consumed a quality roll, or range endpoints changed", bounds) + } + for _, current := range []*server{world, cold} { + corpse := current.characters[1000000].corpse + if corpse == nil || corpse.credits != 1 || current.characters[1].experience != 100 { + t.Fatal("quality selection changed the ordinary kill outcome") + } + if scenario.empty { + if len(corpse.items) != 0 || current.nextItem != identity-1 { + t.Fatal("empty roll allocated an item") + } + } else if !slices.Equal(corpse.items, []ownedItem{{ID: identity, Type: 51005, Template: 42640, Quality: scenario.quality, Count: 1}}) || current.nextItem != identity { + t.Fatal("quality range did not persist its selected instance", corpse.items) + } + } + }) + } +} + +func TestRangedLootRollbackAndRetry(t *testing.T) { + for _, failure := range []struct{ name, sql string }{ + {"item", "CREATE TRIGGER reject_range BEFORE INSERT ON items BEGIN SELECT RAISE(FAIL,'range'); END"}, + {"ignored placement", "CREATE TRIGGER reject_range BEFORE INSERT ON item_locations BEGIN SELECT RAISE(IGNORE); END"}, + {"commit", "CREATE TABLE range_commit_failure (id INTEGER REFERENCES items(id) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER reject_range AFTER INSERT ON items BEGIN INSERT INTO range_commit_failure VALUES(9999); END"}, + } { + t.Run(failure.name, func(t *testing.T) { + world, _ := newKillExperienceWorld(t, "unarmed") + target := world.characters[1000000] + target.level, target.combatProfile = 2, gamedata.NPCCombatProfiles[17655][2] + world.combatRoll = func(limit uint32) uint32 { + if limit == 3 { + return 2 + } + return 0 + } + before := world.nextItem + if _, err := world.db.Exec(failure.sql); err != nil { + t.Fatal(err) + } + + attackForExperience(t, world, "unarmed") + cold := newTestInventoryServer(t) + if target.health != 1 || target.corpse != nil || world.nextItem != before || cold.characters[1000000].health != 1 || cold.characters[1000000].corpse != nil || cold.nextItem != before || cold.characters[1].experience != 0 || len(cold.items) != 0 { + t.Fatal("failed ranged reward leaked a death, quality or identity") + } + if _, err := world.db.Exec("DROP TRIGGER reject_range"); err != nil { + t.Fatal(err) + } + attackForExperience(t, world, "unarmed") + cold = newTestInventoryServer(t) + + if !slices.Equal(cold.characters[1000000].corpse.items, []ownedItem{{ID: before + 1, Type: 51005, Template: 42640, Quality: 3, Count: 1}}) || cold.nextItem != before+1 || cold.characters[1].experience != 100 { + t.Fatal("retry lost the selected range quality or allocated twice") + } + }) + } +} + +func TestRangedMonsterPartFullInventoryColdPickupAndSale(t *testing.T) { + world, _ := newKillExperienceWorld(t, "unarmed") + player, client := world.characters[1], world.clients[1] + player.appearance = 0x515 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + inventory := player.inventory + for slot := uint32(64); slot < 94; slot++ { + inventory.LastID++ + inventory.Items = append(inventory.Items, ownedItem{ID: inventory.LastID, Type: 51005, Template: 121567, Quality: 1, Count: 1, Slot: slot}) + } + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(err) + } + profile := *world.characters[1000000].combatProfile + profile.Loot = []gamedata.NPCLoot{{Template: 42641, Quality: [2]uint32{1, 400}, Chance: 100}} + world.characters[1000000].combatProfile = &profile + world.combatRoll = func(limit uint32) uint32 { + if limit == 400 { + return 199 + } + return 0 + } + identity := world.nextItem + 1 + + // Collect cash, then reject pickup while every inventory slot is occupied. + attackForExperience(t, world, "unarmed") + if err := world.handleLootUse(client, lootUseRequest(1)); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, lootTakeRequest()); err != nil { + t.Fatal(err) + } + if len(player.inventory.Items) != 30 || !slices.Equal(world.characters[1000000].corpse.items, []ownedItem{{ID: identity, Type: 51005, Template: 42641, Quality: 200, Count: 1}}) { + t.Fatal("full inventory changed the selected corpse instance") + } + + // Free one slot and recover the same selected instance after a cold load. + if err := world.handleInventory(client, inventoryDeletePacket(1, 64)[20:]); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, lootTakeRequest()); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, 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 + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil { + t.Fatal(err) + } + item := slices.IndexFunc(player.inventory.Items, func(item ownedItem) bool { return item.ID == identity }) + if item < 0 || player.inventory.Items[item].Quality != 200 || player.inventory.Items[item].shopPrice() != 2563 || client.equipment != nil { + t.Fatal("cold pickup or rejected wear changed the interpolated part") + } + + // Cancel a sale before accepting it, preserving every unrelated item. + player.position = [3]float32{60, 14.75, 53} + 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) + } + cancelled := newTestInventoryServer(t) + if cancelled.items[identity].Quality != 200 || cancelled.characters[1].inventory.Credits != 1 { + t.Fatal("cancelled sale changed the selected part or balance") + } + if err := world.handleShopUse(client, shopUseRequest(2)); 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) + + if cold.characters[1].inventory.Credits != 129 || len(cold.characters[1].inventory.Items) != 29 || cold.nextItem != identity || len(cold.characters[1000000].corpse.items) != 0 { + t.Fatal("interpolated sale lost other items or repeated rewards", cold.characters[1].inventory) + } + if _, exists := cold.items[identity]; exists { + t.Fatal("sold selected-quality part survived cold recovery") + } +} diff --git a/server/npc_loot_test.go b/server/npc_loot_test.go @@ -172,7 +172,7 @@ func TestNPCLootDoesNotDependOnSoloExperienceEligibility(t *testing.T) { func TestNPCLootUsesSharedTypedItemRecords(t *testing.T) { world, _ := newKillExperienceWorld(t, "unarmed") profile := *world.characters[1000000].combatProfile - profile.Loot = []gamedata.NPCLoot{{Template: 42640, Quality: 1, Chance: 100}, {Template: 123742, Quality: 1, Chance: 100}, {Template: 143832, Quality: 1, Chance: 100}} + profile.Loot = []gamedata.NPCLoot{{Template: 42640, Quality: [2]uint32{1, 1}, Chance: 100}, {Template: 123742, Quality: [2]uint32{1, 1}, Chance: 100}, {Template: 143832, Quality: [2]uint32{1, 1}, Chance: 100}} world.characters[1000000].combatProfile = &profile world.combatRoll = func(uint32) uint32 { return 0 } before := world.nextItem @@ -196,7 +196,7 @@ func TestNPCLootPeriodicKillingTickCommitsOnce(t *testing.T) { target := world.characters[1000000] target.health, target.monsterData, target.level = 1, 17655, 1 profile := *gamedata.NPCCombatProfiles[17655][1] - profile.Loot = []gamedata.NPCLoot{{Template: 85557, Quality: 101, Chance: 100}} + profile.Loot = []gamedata.NPCLoot{{Template: 85557, Quality: [2]uint32{101, 101}, Chance: 100}} target.combatProfile = &profile before := world.nextItem at := castPeriodicNano(t, world, 43376) @@ -231,7 +231,7 @@ func TestNPCLootIdentityExhaustionRejectsOnlyAnActualDrop(t *testing.T) { world, _ := newKillExperienceWorld(t, "unarmed") world.combatRoll = func(uint32) uint32 { return 0 } profile := *world.characters[1000000].combatProfile - profile.Loot = []gamedata.NPCLoot{{Template: 42640, Quality: 1, Chance: chance}} + profile.Loot = []gamedata.NPCLoot{{Template: 42640, Quality: [2]uint32{1, 1}, Chance: chance}} world.characters[1000000].combatProfile = &profile world.nextItem = 4294967295 if _, err := world.db.Exec("UPDATE world SET last_item_id=4294967295 WHERE id=1"); err != nil { @@ -280,7 +280,7 @@ func TestNPCLootRespawnAndCheckpointDoNotRegenerateOldRewards(t *testing.T) { func TestNPCLootFullInventoryRetainsGeneratedItem(t *testing.T) { world, _ := newKillExperienceWorld(t, "unarmed") profile := *world.characters[1000000].combatProfile - profile.Loot = []gamedata.NPCLoot{{Template: 85557, Quality: 101, Chance: 100}} + profile.Loot = []gamedata.NPCLoot{{Template: 85557, Quality: [2]uint32{101, 101}, Chance: 100}} world.characters[1000000].combatProfile = &profile world.combatRoll = func(uint32) uint32 { return 0 } for range 30 { diff --git a/server/starter_boss_test.go b/server/starter_boss_test.go @@ -23,7 +23,7 @@ func TestStarterBossAuthoredSpawnHasUsefulSelectedQualityLoot(t *testing.T) { if spawn.monsterData != 30354 || spawn.level != 4 || spawn.position != [3]float32{186.06424, 13.7, 182.79846} || spawn.combatProfile == nil || spawn.combatProfile.Health != 100 || spawn.combatProfile.Experience != 100 || spawn.combatProfile.Weapon != [2]uint32{121063, 121064} || - !reflect.DeepEqual(spawn.combatProfile.Loot, []gamedata.NPCLoot{{Template: 85596, Quality: 4, Chance: 50}, {Template: 123742, Quality: 4, Chance: 25}}) { + !reflect.DeepEqual(spawn.combatProfile.Loot, []gamedata.NPCLoot{{Template: 85596, Quality: [2]uint32{4, 4}, Chance: 50}, {Template: 123742, Quality: [2]uint32{4, 4}, Chance: 25}}) { t.Fatal("authored starter boss has no isolated, level-appropriate equipment profile", spawn.combatProfile) } return diff --git a/server/weapon_quality_lifecycle_test.go b/server/weapon_quality_lifecycle_test.go @@ -15,7 +15,7 @@ func TestWeaponQualityGeneratedPickupEquipRemoveAndSale(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}} + profile.Loot = []gamedata.NPCLoot{{Template: template, Quality: [2]uint32{5, 5}, Chance: 100}} world.characters[1000000].combatProfile = &profile world.combatRoll = func(uint32) uint32 { return 0 } identity := world.nextItem + 1