Vendor stock and gambling
Purpose
Section titled “Purpose”When a player opens a vendor’s trade window, the server builds that vendor’s stock if it has none: a list of normal, superior and magic items, plus the vendor’s permanent items, at a stock level derived from the opener’s character level, the difficulty and the act. When a player opens a gamble window, the server builds a 14-item gamble window for that player at that NPC. Both draw every choice (counts, normal quality, the upgrade to an exceptional or elite base, the gamble level, the gamble base and the gamble quality) from one store seed per game. Each item is then created through the ordinary item creation of uniques-sets, affixes and properties, seeded from the game seed exactly as a drop is. This spec gives when stock is built and rebuilt, the stock build and the gamble build as pseudocode with their draw order, and the hand-off to item creation. Prices, the buy/sell multipliers and repair costs are specified in items/economy (§ I).
Vendor stock and gambling never reach the treasure-class resolver. Names of functions, structs and fields are ours.
Notation. S is the store seed, NpcStoreCtl+0x08 (Game+0x1D24 → +0x08). “Game seed” is Game+0xD0, “item
seed” the item data’s seed. Step, Range are the primitives of
rng: R(s, n) is Range(s, n), 0 with no draw when n < 1 (signed), else one draw
and low mod n (unsigned). RandLoHi(s, lo, hi) is lo + R(s, hi − lo) when hi > lo (signed), else lo with no
draw. clvl is the opener’s character level (stat 12). The vendor index v is the column group of the item tables:
0 Akara, 1 Gheed, 2 Charsi, 3 Fara, 4 Lysander, 5 Drognan, 6 Hratli (Hralti in the table headers), 7 Alkor,
8 Ormus, 9 Elzix, 10 Asheara, 11 Cain, 12 Halbu, 13 Jamella, 14 Malah, 15 Larzuk, 16 Drehya (Anya).
Entry points
Section titled “Entry points”| When | Function | Tag |
|---|---|---|
| Game creation: the store records and the store seed | GameCreate → NPCSTORE_CtlCreate |
[C] |
| Item tables loaded: the 17 candidate lists, once per process | VENDOR_BuildAllLists → VENDOR_BuildList |
[C] |
| NPC menu packet: action 1 trade, 2 gamble, 3 hire | NPC_MenuAction → NPC_TradeOpen → NPC_OpenStore |
[C] |
| A player leaves a town level (level or act change) | TownLevelLeave → NPCSTORE_ActStale |
[C] |
| A player leaves the game from a town of Acts I–IV | TownPlayerRemove → NPCSTORE_ActStale |
[C] |
| The gamble window closes (cancel packet) | NpcInteractRemove → GambleInvFree |
[C] |
| A player unit is freed while its NPC interaction is open | UnitFree → PlayerInteractEnd → NpcStorePlayerLeave, vend 2 |
[C] |
- [C]
NPC_MenuAction(action, npcId, arg)handles a 13-byte client packet. Action 1 (trade) is accepted for exactly the NPC classes 147, 148, 154, 177, 178, 199, 202, 252–255, 257, 405 and 511–513, and action 2 (gamble) for exactly 147, 199, 254, 405, 512 and 514: both class tests were run for every class 0..799. The trade list is the slot table’s store-flag set without 514, the gamble list the setNPCSTORE_CtlCreatemarks as gamblers, and all 419 logged trade opens carried that gambler flag. Classes are MonStats rows. (NPC_MenuAction,NPCSTORE_CtlCreate,g_NpcStoreTable, vend 3) - [I] Action 3 opens the hire list; the other actions are quest services (imbue, socketing, personalisation, travel), outside this spec.
- [C]
VENDOR_BuildStockhas three call sites only, andNPCSTORE_Resettwo. The direct-call walk from the 265 callbacks that the 37 quest init functions store never reachesVENDOR_BuildStock. It reachesNPCSTORE_Resetby one chain only: Baal’s death → a save of every client, in game types 1 and 2 only → its callee → a client dropped after three failed sends →ClientRemove→TownPlayerRemove→NPCSTORE_ActStale. So, by direct calls, quest code resets a store only through that client drop, never in single player. (VENDOR_BuildStock,NPCSTORE_Reset,A5Q6_BaalDeath, vend 4) - [I] The walk follows direct calls only: the 825 indirect call sites under those callbacks are not followed.
(
VENDOR_BuildStock, vend 4) - [C] Which free reaches
NpcStorePlayerLeave.PlayerInteractEndhas one call site, inUnitFree; all 8 logged entries return to the same site. It callsNpcStorePlayerLeavewhen the player is still interacting with an NPC: in the two-client run’s kept logs, 2 of the 7 host-side entries, the joiner’s leaves while it was talking to Kashya (class 150) and to Akara, are followed by that call. In the second vendors run’s single-player Save and Exit, the trade window’s cancel had already cleared the interaction (NpcInteractRemove, thenPlayerClearInteract, and no new interaction after), and noNpcStorePlayerLeavecall followed. With one player, every window close and menu Escape of the run sent the cancel first. (PlayerInteractEnd,UnitFree,NpcStorePlayerLeave, vend 2) - [I] The call site is
UnitFree’s case for unit type 0 (the jump table), and the test between the two outcomes is the player’s interaction flag+0x6Cwith interaction type 1: the two logged outcomes fit it. So the path is reached only when a client leaves with an interaction open.PlayerSetInteract(called byNpcInteractStartwith type 1 and the NPC’s id) writes the interaction only while+0x6Cis 0;PlayerClearInteractclears it. (UnitFree,PlayerSetInteract,PlayerClearInteract, vend 2)
Inputs
Section titled “Inputs”Tables
Section titled “Tables”| Anchor | Used for |
|---|---|
Weapons.txt:CharsiMin, <V>Max, <V>MagicMin, <V>MagicMax, <V>MagicLvl (+0x146 + v, +0x157 + v, +0x168 + v, +0x179 + v, +0x18A + v, u8) |
the candidate entry of base and vendor v (§ B); the same columns in Armor.txt:CharsiMin and Misc.txt:AkaraMin |
Weapons.txt:PermStoreItem (+0x1A4), Misc.txt:PermStoreItem |
the permanent list (§ B) |
Weapons.txt:spawnable (+0x133) |
listing filter (§ B) |
Weapons.txt:level (+0xFD), Weapons.txt:version (+0xF6), Weapons.txt:code (+0x80) |
the base level gate, the classic skip, the code (§ D, § G) |
Weapons.txt:bitfield1 bit 0 (+0xDC) |
the base may have magic stock (§ D) |
Weapons.txt:ubercode (+0x88), Weapons.txt:ultracode (+0x8C) |
the exceptional and elite bases of the stock upgrade (§ E) and the gamble upgrade (§ G) |
Weapons.txt:NightmareUpgrade (+0x19C), Weapons.txt:HellUpgrade (+0x1A0) |
the stock replacement base in Nightmare and Hell, xxx = none (§ E) |
ItemTypes.txt:StorePage (+0x22), a row index of StorePage.txt:Code |
the stock tab (§ E) |
Gamble.txt:code |
the gamble base list (§ G) |
DifficultyLevels.txt:GambleRare, GambleSet, GambleUnique, GambleUber, GambleUltra (+0x44..+0x54) |
the gamble quality and upgrade (§ G) |
MonStats.txt:interact (+0x0D bit 1) |
which NPC classes get a store record (§ A) |
Npc.txt:npc and the multiplier columns |
prices only; not read on the creation path (§ I) |
Runtime state
Section titled “Runtime state”| State | Type | Source |
|---|---|---|
store seed S |
Seed | NpcStoreCtl+0x08, seeded once at game creation (§ A); NpcStoreCtl+0x08 |
| game seed | Seed | Game+0xD0; every created item’s unit and item seeds (§ F) |
clvl |
i32 | the opener’s stat 12, read at each stock build and each gamble build |
difficulty |
u8 | Game+0x6D: 0 Normal, 1 Nightmare, 2 Hell |
expansion |
bool | the game’s expansion flag (Game+0x70) |
itemVersion |
u16 | Game+0x78: < 100 in a classic game |
| store record | NpcStoreRec, 0x44 bytes |
per NPC class: act, hasStore, isGambler, opened, built, stale (+0x27), buildTick, the entries and permanent codes, the per-player gamble inventories; NpcStoreRec+0x27 |
now |
u32 | GetTickCount() milliseconds, unsigned |
- [C] The stock and gamble builds read
clvl,difficulty, the act and the expansion flag as inputs. The runs’ characters were tool-built saves loaded on stock data (expansion clvl 30 and 75, classic clvl 30; expansion clvl 1 and 30 in Normal, 19 in Nightmare, 99 in Hell). They are neutral inputs: they back the code that reads these values, nothing about how a character reaches that state. The clvl-30 save of the later run, one experience point under clvl 32’s threshold, is not a state a character reaches by play (§ C).
Constants
Section titled “Constants”| Name | Value | Anchor | Tag |
|---|---|---|---|
STORE_INIT_HIGH |
666 (the Init high word) |
NPCSTORE_CtlCreate |
[C] |
NORMAL_CAP[act] |
12, 20, 28, 36, 45 for Acts I–V | VENDOR_StockLevel |
[C] |
NO_NORMAL_FROM |
25: no normal copies, magic extra 1 or 2, from this stock level | — | [C] |
UPGRADE_MIN_CLVL |
26: the stock upgrade draw needs clvl > 25 |
— | [C] |
STALE_MS |
240 000 (0x3A980) |
NPCSTORE_ActStale |
[C] |
MAX_FAILS |
32: a test that finds more than 32 failed creations (after a normal copy or a permanent item) ends the whole build at once; never reached (§ D) | VENDOR_BuildStock |
[I] |
GAMBLE_SLOTS |
14 | GAMBLE_BuildInv |
[C] |
CRACKED_TRIES |
5 | VENDOR_CreateStockItem |
[I] |
| store record count | 64 records of 0x44 bytes: NPCSTORE_FindRec walks i = 0..0x3F at recs + 0x44·i, NPCSTORE_CtlCreate allocates 0x1100 bytes |
NPCSTORE_FindRec, NPCSTORE_CtlCreate, vend 7 |
[C] |
| NPC slot table | 43 entries of 8 bytes (acts 0–4: 8, 14, 8, 6, 7 entries; 17 with the store flag): class +0x0, store flag +0x4, act +0x5, flag +0x6, the only stride-8 reads being NPCSTORE_CtlCreate’s |
g_NpcStoreTable, vend 8 |
[C] |
Algorithm
Section titled “Algorithm”A. Store records and the store seed (game creation)
Section titled “A. Store records and the store seed (game creation)”A1. Step(game.seed) [C] draw (game seed) S ← Init(game.seed.low) ; S = {low, 666}A2. for cls in 0 ..< nMonStats: [C] if MonStats[cls].interact = 0: continue rec ← next of the 64 records; rec.classId ← cls; rec.inventory ← new slot ← g_NpcStoreTable entry with class cls; if none: continue [I] no-slot case rec.act ← slot.act; rec.hasStore ← slot.hasStore if rec.hasStore ≠ 1: no lists; continue rec.entries, rec.permCodes ← copy of VendorList[VENDOR_INDEX[cls]] rec.isGambler ← cls ∈ {147, 199, 254, 405, 512, 514}Step notes:
-
A1. [C]
NPCSTORE_CtlCreateruns once per game fromGameCreate, after the monster-region and object-region builds that draw on the game seed too. Every logged store seed of the 7 games is{low, 666}after one game-seed step, and the store seed at the entry of each of the 435 logged builds (stock, gamble, hireling) is the model’s: nothing outside the builds of this spec and the hireling oracle draws onS. -
A1. [C] The store seed is game-seed draw 3 from
Init(N)(N the game’s seed,{N, 666}atGAME_InitSeeds): after the monster-region build (draw 1) and the object-region build (draw 2), each one step. The code steps the game seed once and seedsSfrom the new low word; in each of the 7 games (seeds 3201–3207) the logged game seed at that step’s entry (VSC0) is two steps past the one logged atGAME_InitSeeds, andS(VSC1) isInitof the third step’s low word. -
A2. [C] The records follow MonStats row order of the
interactrows, and each record’s act and store flag are its class’s slot-table entry: all 419 logged trade opens show the record’s act and store flag equal to the slot table’s, and the 32 loggedNPCSTORE_ActStalerecord lists are in ascending class order.NPCSTORE_FindRecfinds a record by class over all 64 slots (Constants). (NPCSTORE_CtlCreate,NPCSTORE_FindRec,MonStats.txt:interact, vend 7, 9) -
A2. [I] One stock per NPC class per game, shared by every player; gambling keeps one inventory per player and NPC (§ H).
-
A2. [C] The stock is shared with a second player: in the two-client run each store the host built was the one the joiner’s open of the same NPC found, with no second build (12 opens, C1). Scope: two players, the trade stock; per-player gambling was not run with two players.
VENDOR_INDEX (NPC class → vendor index):
| Class | NPC | v | Class | NPC | v |
|---|---|---|---|---|---|
| 148 | Akara | 0 | 255 | Ormus | 8 |
| 147 | Gheed | 1 | 199 | Elzix | 9 |
| 154 | Charsi | 2 | 252 | Asheara | 10 |
| 178 | Fara | 3 | 257 | Halbu | 12 |
| 202 | Lysander | 4 | 405 | Jamella | 13 |
| 177 | Drognan | 5 | 513 | Malah | 14 |
| 253 | Hratli | 6 | 511 | Larzuk | 15 |
| 254 | Alkor | 7 | 512 | Drehya (Anya) | 16 |
-
[C] The record filler’s switch and the list builder’s switch agree on these 16 classes (a second code path), and the model’s lists built from this map equal, byte for byte, the record each of the 94 logged builds read.
-
[C] Class 514 (Nihlathak) gets list 15 (Larzuk’s) and the gambler mark in his record, while the list builder maps him to 16; the two switches agree on the 16 trade classes, and neither gives any class index 11 (Cain). He is not in the trade menu’s class list (action 1, above), so his record’s list is never built into stock; he only gambles. (
VENDOR_BuildAllLists,NPC_MenuAction, vend 11) -
[I] The Npc table’s
npccolumn is not read for this map.
B. The candidate lists (VENDOR_BuildList)
Section titled “B. The candidate lists (VENDOR_BuildList)”B1. for v in 0 ..< 17, once per process: [C] entries[v] ← []; perm[v] ← [] for i in 0 ..< nItems: ; weapons, then armor, then misc, record index order b ← items[i] if b.spawnable = 0: continue if b.Max[v] = 0 and b.MagicMax[v] = 0: continue if b.PermStoreItem ≠ 0: append b.code to perm[v] else: append {Min: u8, Max: u8, MagicMin: u8, MagicMax: u8, code, MagicLvl: u8} to entries[v]-
B1. [C]
Minplays no part in the listing: a base whoseMaxandMagicMaxare both 0 is never stocked by that vendor. A permanent base is made once per build whatever its counts. A per-index byte atg_VendorListBuiltmakes each list build once; the lists live atg_VendorLists. The logged record of all 16 used lists equals the model’s. -
[C] prints each group’s listed bases from the tables prints the 17 lists in build order.
C. When stock is built, reset and marked stale
Section titled “C. When stock is built, reset and marked stale”C0. on each interaction start of a player with an NPC [C] before any menu action (the call is unconditional): HIRE_SendList(npc): if npc.class ∉ {150, 198, 252, 515}: return ; the sellers (hirelings spec) if rec.hirelingsBuilt = 0: HIRE_BuildStock(rec); rec.hirelingsBuilt ← 1 ; draws on S: hirelings specC1. on trade open (action 1) of NPC npc by player p: [C] rec ← NPCSTORE_FindRec(npc.class); rec.opened ← 1 if rec.hasStore: if rec.built = 0: VENDOR_BuildStock(npc, p) (§ D); rec.built ← 1 if rec.hirelingsBuilt = 0: [I] never true with the stock client: C0 ran first if npc.class ∈ {150, 515, 198, 252}: HIRE_BuildStock(rec) rec.hirelingsBuilt ← 1 if npc.class ∈ {150, 515, 198}: return ; hire-only NPCs if sole and rec.stale: ; sole: the NPC's interaction list has exactly one live entry rec.stale ← 0; NPCSTORE_Reset(rec, npc) ; stock destroyed, built ← 0 VENDOR_BuildStock(npc, p); rec.built ← 1 send the stockC2. on any level change of a player whose old level is a town [C] (levels 1, 40, 75, 103, 109 → act 0..4): count ← players still in that level NPCSTORE_ActStale(act, townEmpty: count = 0)C3. NPCSTORE_ActStale(act, townEmpty): [C] for rec with rec.act = act, hasStore = 1, opened = 1, built = 1: if not townEmpty: if now > rec.buildTick + 240000: ; u32, unsigned compare rec.stale ← 1; rec.buildTick ← now else: u ← the unit rec.npcUnitId if u is gone or u.class ≠ rec.classId: clear rec: built ← 0, buildTick ← 0, new inventory ; no NPCSTORE_Reset call else if NpcInteractCount(u) = 0: NPCSTORE_Reset(rec, u) ; built ← 0, stock destroyed else: rec.stale ← 1Step notes:
-
C1. [C] Every one of the 94 logged trade opens built: 81 first opens (
built= 0), 6 opens after a reset and 7 opens of a stale store by the sole interactor (NPCSTORE_Reset, then the build), each predicted from the record’s state at the open. -
C1. [C] An open of a built, non-stale store keeps the stock. In the two-client run each store the host built at its first open was kept, with no build, at the joiner’s open of the same NPC (12 opens). Scope: the second open by another player.
-
C1. [C] The same player opening the window again rebuilds nothing either. In the second vendors run, 7 trade opens found the store built and not stale (Charsi 1, Drognan 3, Larzuk 3): no build before the next open, and the stock’s item ids at each open were those left by the build, less the items bought since (one, Charsi’s
lax). (NPC_TradeOpen,NPC_OpenStore, vend 12) -
C1. [I]
soleis computed byNPC_MenuActionbefore the call from the NPC’s interaction list (MonsterData+0x30). -
C1. [C] With two players interacting, a stale store is not rebuilt and keeps its stock. In the two-client run, Akara’s store, marked stale 266.5 s after its build by the joiner’s town leave, was opened by the host while the joiner was talking to her:
sole0, no reset and no build. Once the joiner’s talk ended, the host’s next open hadsole1, a reset, then a build. -
C0–C1. [C] Asheara’s hirelings come before her stock, whatever the menu choice. Her hire table (252, a store and hirelings) is built once, by
HIRE_SendListcalled fromNpcInteractStart, at the first click on her and before her first menu action. In the second vendors run four hire-list actions and then the trade open followed it, withhirelingsBuilt1 andbuilt0 at the open, and the stock build that followed called noHIRE_BuildStock; in the first vendors run’s 5 games with Asheara her first trade open likewise foundhirelingsBuiltat 1, the hireling build logged before her first menu action (6 of 6 with the later run’s). SoNPC_OpenStore’s call was never taken in the runs.HIRE_BuildStockwas a boundary oracle of the first run; its draws onSare specified in hirelings, which a reimplementation runs in its place. (HIRE_SendList,HIRE_BuildStock,NpcInteractStart,NPC_OpenStore, vend 14) -
C1. [I] The trade-first order is never taken by the stock client, beyond the runs:
+0x21(hirelingsBuilt) is cleared only, andHIRE_BuildStockfollows at once;NPCSTORE_Resetwrites+0x20(built) alone, so a store reset, including the two-player stale branch, leaves the hire table built. (NPCSTORE_Reset, vend 14) -
C1. [C] In the run the oracle was entered 16 times, each with the
Sthe model predicted, and its exitSwas taken from the log. -
C2. [C] In single player, a waypoint to another act reaches
NPCSTORE_ActStalewithtownEmpty0 (the leaving player still counted in the town; 26 of 26 calls), so the old act’s stores are only marked stale, and only those built more than 240 000 ms before. A waypoint to a level of the same act givestownEmpty1 (6 of 6 calls), so every built store of the act is destroyed at once (byNPCSTORE_Reset, or by the clear path when the NPC unit is gone) and rebuilt at the next trade open from the opener’s current level. -
C2. [C] Walking out of a town takes the same
TownLevelLeavecall as a waypoint within the act. In the second vendors run the walk from the Rogue Encampment into the Blood Moor (levels 1 → 2) called it from the per-frame room check (the call, return), andNPCSTORE_ActStalegottownEmpty1 and reset Akara’s and Charsi’s stores at once. The waypoints within an act took the same call site withtownEmpty1 (Harrogath → the Frigid Highlands once, Lut Gholein → the Sewers Level 2 six times: Larzuk’s and Fara’s stores reset), and every act change came fromPlayerChangeLevel(the call, return ; the 14 from a town all withtownEmpty0). (TownLevelLeave,NPCSTORE_ActStale, vend 15) -
C2. [I] Why an act change counts the leaving player.
TownLevelLeavecounts the players whose current room’s level is the old level. For a target in another act,PlayerChangeLevelcalls it beforePlayerChangeAct, while the player’s unit is still in its town room, so the count includes it andtownEmptyis 0. A change within the act goes through the per-frame room check, which calls it only after it has found the player’s room in a new level, so the player is no longer counted. A walk out of town takes the per-frame path. This matches the run’s counts (0 on the 6 in-act changes, 1 on the 26 act changes). -
C2. [I]
TownPlayerRemove(a player leaving the game) does the same withcount − 1 = 0, for the towns of Acts I–IV only: Harrogath (109) is missing from its switch. -
C2. [C] A player leaving the game, with two players. In the two-client run the joiner left from the Rogue Encampment (a) with the host in town:
townEmpty0, and only Gheed’s store (built 351.6 s earlier) was marked stale, Akara’s and Charsi’s kept; (b) with the host in the Blood Moor:townEmpty1, and the three built stores were reset. A leave from Harrogath, in two sessions, logged noNPCSTORE_ActStalecall fromTownPlayerRemove(no stale line with the return). Scope: the leaves of (a) and (b) were connection drops (the joiner’s process stopped) and Harrogath’s were Save and Exit; whether both paths take the same removal call is not logged. -
C3. [C] The 240 000 ms test: the code compares
nowwithbuildTick + 0x3A980unsigned; in the run 7 stores were marked, at 252.5–375.7 s after their build, and none sooner.buildTickis written at the start of each build and by the stale mark. -
C3. [C] The multiplayer case with a player left in town (stale only after 240 s, rebuilt at the next trade open by a sole interactor) is C2’s (a) and C1’s two-player open.
-
C3. [I] The stale branch with
townEmpty1 and someone still interacting: the run’s one such leave (the joiner alone in town with Akara’s trade open, its connection dropped) logged the stale call before the interaction ended and no reset, the branch with an interactor, but the logged record list was empty there, so the stale byte itself was not seen. -
[C] What rebuilds nothing: a town entry, a reopen and a level-up. In the second vendors run Drognan’s store, built at clvl 30 in Lut Gholein, was opened again; the player took the waypoint to the Frigid Highlands (an act change,
townEmpty0, the store kept), levelled up there, came back by waypoint (a town entry: noNPCSTORE_ActStalecall) and opened the store twice more. None of the three later opens built, each showed the same 57 item ids, and the model predicted the record’s state (built, not stale) each time. The level-up was one event of two levels (30 → 32): the tool-built save held clvl 30 one experience point under clvl 32’s threshold, a state not reached by play, andNpcStoreLevelUpNotewas entered once from the level-up’s call. (NpcStoreLevelUpNote,NPC_TradeOpen, vend 18) -
[I] A quest event rebuilds nothing either (none in the runs). Why a level-up changes nothing: the level-up calls
NpcStoreLevelUpNote, which queues a note on each built store without reading the level gained; the queue’s consumerNpcStorePendingDeadhas no caller, nor doesStockRebuildDead. So the stock keeps the level of the build until a reset or stale rebuild.
D. The stock build (VENDOR_BuildStock)
Section titled “D. The stock build (VENDOR_BuildStock)”D1. rec.buildTick ← now [C]D2. clvl: i32 ← stat 12 of the opener [C] ilvl: i32 ← VENDOR_StockLevel(clvl + 5) VENDOR_StockLevel(x): if difficulty = 0 and act < 5: return min(x, NORMAL_CAP[act]) else return x ; no clamp to 99D3. fails: i32 ← 0 [C] for e in rec.entries, in order: b ← base of e.code if b.level > ilvl: continue ; no draw if ilvl < 25: n: i32 ← RandLoHi(S, e.Min, e.Max + 1) ; draw (none when Max + 1 ≤ Min) else: n ← 0 if b.version ≥ 100 and itemVersion < 100: continue ; classic: after the count draw repeat n times: q: i32 ← VENDOR_PickNormalQuality(S, ilvl) ; draw if not VENDOR_CreateStockItem(e.code, q, ilvl, clvl): fails ← fails + 1 (§ E) if fails > 32: return [I] never reached if b.bitfield1 & 1 and e.MagicLvl ≤ ilvl: ; MagicLvl read as u8 if ilvl ≥ 25: x: i32 ← RandLoHi(S, 1, 3) + 1 ; draw: 2 or 3 else: x ← 1 m: i32 ← RandLoHi(S, e.MagicMin, e.MagicMax + x) ; draw (none when MagicMax + x ≤ MagicMin) repeat m times: if not VENDOR_CreateStockItem(e.code, 4, ilvl, clvl): fails ← fails + 1 (§ E); no limit test hereD4. for c in rec.permCodes, in order: [C] it ← VENDOR_CreateStockItem(c, 2, ilvl, clvl) (§ E) if it = none: fails ← fails + 1 else if c ∈ {aqv, cqv}: it.quantity (stat 70) ← its maximum stack if fails > 32: return [I] never reachedD5. VENDOR_PickNormalQuality(S, ilvl) → i32: [C] Step(S); r: u32 ← S.low mod 100 ; draw, always if ilvl < 5: return 1 if r > 90 else 2 if ilvl < 10: return 3 if r > 85 else 2 return 3 if r ≥ 75 else 2Step notes:
-
D2. [C] The Normal caps bind for every act (Acts I–V at clvl 30 and 75); Nightmare and Hell take
clvl + 5with no cap, up to 104.ITEMS_CreateForStoreonly raises anilvlbelow 1 to 1. -
D3. [C] Counts: normal stock is
Min..Maxinclusive whileilvl < 25and none from 25 on; magic stock isMagicMin..MagicMaxbelow 25, andMagicMin..MagicMax + 1orMagicMin..MagicMax + 2from 25 on, after a draw that picks which. An entry withMax= 0 andMin= 0 still makes its count draw (RandLoHi(S, 0, 1)=R(S, 1), one draw, result 0). -
D3. [C]
MagicLvlis a minimum stock level, not an affix level. The byte is compared withilvl(movzx,jg skip), so 0 is no gate and 255 means the vendor never stocks a magic copy of that base. The affix level of a magic stock item comes from the ordinary alvl rule with the item’silvl. In the run Charsi at Normal Act I (ilvl12) made no magichla(MagicLvl15),stu(20) orrng(255), no 255 base ever got a magic copy, and 4097 of 4375 affix picks on magic stock items have analvlabove their entry’sMagicLvl. -
D3. [C] Hratli’s
MagicLvlis 0 on every weapon and armor base (the table headerHratliMagicLvlis not the compiler’s column name, so the absent-column default 0 is stored), so his magic stock has no level gate. -
D3. [C] Classic. An expansion base (
version≥ 100) is skipped after its count draw and before any quality draw, so a classic game consumes the count draw of each expansion entry whileilvl < 25(32 such skips in the run). -
D1. [C] The
buildTickeach of the 83 logged builds left (read at the next trade open or stale test) is ordered as the builds are in the log and lies between theGetTickCountvalues of the stale marks before and after it (7 marks, 0 out of order); the 240 000 ms test of those marks counts from it. (VENDOR_BuildStock, vend 19) -
D3–D4. [C] The 32-failure limit was never reached: no build of the first vendors run passed 20 failures (94 builds; 348 stock items found no room on their tab, § E), and none of the second vendors run’s 17 passed 27 (Larzuk in Hell at
ilvl104, five builds in three games: 26, 12, 13, 27 and 17; Fara in Nightmare atilvl24, the most normal copies, 9 to 20; Asheara at 104, 8; Anya and Malah at 104, none). reproduces every build with the limit modelled. (VENDOR_BuildStock, vend 5) -
D3–D4. [I] Where the limit is tested. The count is tested after each normal copy (
cmp [ebp-4], 0x20; jg) and after each permanent item, never in the magic loop. Bothjggo to the function’s epilogue (ret 8), so the first test that finds a 33rd failure ends the whole build at once: no further entry, copy or permanent item is made. From stock level 25 (no normal copies) the limit can end a build only in the permanent loop, after its first item. (VENDOR_BuildStock, vend 5) -
D5. [C] Stock is normal, superior or magic, never low, rare, set or unique: the 4 656 logged stock items of the first vendors run are quality 2 ×848, 3 ×131 and 4 ×3 677. Since
clvl ≥ 1givesilvl ≥ 6(D2), the low-quality branch (ilvl < 5) is unreachable. A normal entry is superior with 14 chances in 100 belowilvl10 and 25 in 100 from 10 on (the code’s bounds; not a frequency claim). (VENDOR_BuildStock, vend 20)
Draw order on S per entry [C] (7513 stock-build draws reproduced):
E. One stock item (VENDOR_CreateStockItem)
Section titled “E. One stock item (VENDOR_CreateStockItem)”E1. b ← base of code; want ← code [C] if difficulty > 0 and clvl > 25: u: u32 ← Range(S, 100000) ; draw (RNG_RangeB) if difficulty = 1: ; Nightmare; no expansion test if u < ilvl·64 + 4000 and valid(b.ubercode): want ← b.ubercode else if b.NightmareUpgrade ≠ "xxx": want ← b.NightmareUpgrade else: ; Hell if expansion and u < ilvl·16 + 1000 and valid(b.ultracode): want ← b.ultracode else if u < ilvl·128 + 5000 and valid(b.ubercode): want ← b.ubercode if b.HellUpgrade ≠ "xxx": want ← b.HellUpgrade ; overrides either resultE2. for pass in 0 ..< 2: [C] for t in 1 ... 5: it ← ITEMS_CreateForStore(npc, index of want, kind 4, q, ilvl) (§ F) if it is low quality named "Cracked": destroy it; it ← none; continue [I] never reached break if it = none: return none [I] after 5 Cracked tries if code(it) = want: break destroy it; q ← 2 [I] made again once with quality 2E3. page ← the StorePage of it's item type [C] if page = −1: destroy it; return none [I] no case place it on tab page; if that fails and page = 1: try tab 2 ; the cell search [I] if that fails: park the item; return none ; counts as a failure in § D return itStep notes:
- E1. [C]
valid(c)isc ≠ 0andcnot four spaces; the upgrade columns usexxxfor none. Both thresholds use the stockilvl; the gate usesclvl. The NightmareNightmareUpgradeapplies only after a failed uber test; the HellHellUpgradereplaces whatever the tests gave. In the run every branch was taken (Nightmare:ubercode78,NightmareUpgrade851, none 603; Hell, expansion:ultracode25,ubercode128,HellUpgradealone 452, none 584; 2721 upgrade draws). - E1. [C] Every
NightmareUpgradeandHellUpgradetarget is a normal-tier base (a step up the same type,wnd→ywn→bwn), not the exceptional or elite code; the exceptional and elite bases come only from theubercode/ultracodetests. - E1. [C] A classic Nightmare or Hell store never creates an expansion base: every
ubercode,NightmareUpgradeandHellUpgradeof every base a classic game can stock names a classic (version0) base (972 cells), and 28 classic Nightmare stock items took theirubercodeand reproduced. With modified data such an upgrade would reach a fatal assert (creation returns no item in a classic game, andITEMS_GetCode(NULL)asserts). - E2. [C] Neither retry was reached in the run: stock is never low quality (D5), and the first pass returned the
chosen code for all 4 656 stock items (no
CRK, noCMM). (vend 20, 21) - E3. [C] The tab is the item type’s
StorePagebyte, byte+0x22of theitemtypes.binrecord, compiled to the StorePage row index of its code (0armo, 1weap, 2mag, 3misc; 0xFF for the 28 blank cells), asItemStorePagereads it. No item type namesmag(blank 28,armo12,misc45,weap18), so tab 2 holds only the overflow of tab 1. (ItemStorePage,ItemTypes.txt:StorePage,StorePage.txt:Code, vend 22, 24) - E3. [C] The tab and the placement. For all 1 086 stock items of the second vendors run,
ItemStorePagereturned the StorePage byte of the item’s type (the type at items+0x11E). Placed: tab 0 277, tab 1 314, tab 2 171, tab 3 139; parked 185. Each placed item lies on the tab it was placed on, inside the 10 × 10 grid, overlapping no other (901 cells). Tab 2 received only items whose tab-1 try had failed (171), and a tab-1 item that also failed on tab 2, or an item of another tab that failed once, was parked: these are the builds’ failures. (ItemStorePage,InvPlaceItem, vend 22) - E3. [I] The cell search is not modelled. A first fit in column-major order (x outer, y inner) over the tab, in
creation order, gives 841 of the 901 logged cells, and row-major order 384: the search is close to column-major but
is not that alone. (
InvPlaceItem, vend 22) - E3. [I]
0xFFor an out-of-range type gives −1 (no stock case). Nothing readsstorepage.binat run time. (ItemStorePage,StorePage.txt:Code, vend 24) - E3. [C] A stock item that finds no room is still created (its seeds and draws are consumed) and then counted as a failure: 348 such items in the run, each reproduced.
- [I] Before placement fills durability, throwable stacks and charges to their maximum.
- [C] That fill makes no draw. The walk under
ItemRepairAll(487 functions), with its broken-item branchItemRepairBrokenleft out (a new stock item is never broken), reaches no LCG site and no RNG call; and the store seed and the game seed continue unchanged across every stock item of the 94 builds of the first vendors run. (ItemRepairAll, vend 25)
F. The creation record (ITEMS_CreateForStore) and the item seeds
Section titled “F. The creation record (ITEMS_CreateForStore) and the item seeds”F1. rec: ItemCreateRec ← zeroed 0x84 bytes [C] rec.source ← npc; rec.ilvl ← max(1, ilvl); rec.itemIndex ← index; rec+0x18 ← 4 ; kind (drops use 3) rec+0x28 ← 1; rec+0x2A ← itemVersion; rec.quality ← q; rec+0x80 ← 0x02 ; no seed fields setF2. item ← ItemCreate(rec) [C] Step(game.seed) ; the unit seed (SUnitCreate) Step(game.seed); start: u32 ← game.seed.low ; ItemSeedInit item seed ← Init(start) ; {start, 666} then ItemCreateByQuality as for a dropF3. mark the item identified (flag 0x10) [C]-
F1. [C] At
ItemCreate(the record logged after each store creation), all 9 206 stock and gamble records of the first vendors run have+0x80= 2, row 0, no restore, the quality andmax(1, ilvl)passed, and the game’s item version; all 1 646 of the second vendors run (from the calls) have+0x18= 4,+0x28= 1 and+0x80= 2 atItemCreateByQuality’s entry. (ITEMS_CreateForStore,ItemCreateRec+0x80, vend 26, vend 26) -
F1. [C] Not every
ITEMS_CreateForStorecall is a store item.DropGoldAmountcalls it too (return) for a gold pile (class 523), outside any build: 4 such calls in the second vendors run, none in the first vendors run. Why those piles dropped is not part of this spec. -
F3. [C] All 4 656 stock and 4 550 gamble items have the identified flag
0x10whenITEMS_CreateForStorereturns. (ITEMS_CreateForStore, vend 27) -
F2. [C] Two game-seed steps per creation, the item’s start seed the second step’s low word: 9206 creations, each predicted from the game seed at
ITEMS_CreateForStore. Other units draw on the game seed between builds, so a reimplementation of a live game must keep every game-seed consumer in call order. -
F2. [C] The creation-side quality roll (
ItemRollQualityCreate) returns the record’s quality with no draw (quality and item version are non-zero), so the stock or gamble quality enters the builders of uniques-sets and affixes unchanged, with their usual fallbacks (7 → 6 → 4, 5 → 4). 8787 creations reproduced through the item chain (uniques → affixes → properties) and 419 through the property chain. -
F1. [C] Bit
0x02ofrec+0x80skips the ethereal roll’s draw: vendor and gamble items are never ethereal. Normal and superior items still go through the socket roll on the item seed.
G. Gambling (GAMBLE_BuildInv)
Section titled “G. Gambling (GAMBLE_BuildInv)”The gamble list (GAMBLE_LoadTable, once at load):
-
[C] The list is the 125 rows’ item indices sorted by base level, and
countUpTo[n]forn= 1..99 is the index of the first entry withlevel > n, or the row count: the dumped list (the same in all 7 games) is that order,countUpTo[1..99]equals the count of rows with level ≤n, and the 325 gamble windows reproduce from it. (GAMBLE_LoadTable,g_GambleList,Gamble.txt:code, vend 28) -
[I] How it is built: each
gamblerecord gets the baselevel(u32 at+0x04) and the item index ofcode(+0x08) in place; an unknown code is fatal. The array is sorted in place bylevelwith the CRTqsort(unsigned level; equal levels compare equal), and a separate index array copies each sorted record’s item index. -
[C] The order of equal-level rows is the order
qsortleaves, not Gamble.txt’s. A reimplementation takes it as data: the table below, dumped in all 7 games of the run (one order), withcountUpTo[1..99]equal to the count of rows with base level ≤ n computed from the tables.
Gamble list order (stock data). first is the list index of the first row of that level, so a pick index k
names the k − first-th code of its row (0-based). countUpTo[n] = the first of the next listed level (125 after
level 52). [C]
The window:
G1. D ← DifficultyLevels[difficulty] [C] total: i32 ← D.GambleRare + D.GambleSet + D.GambleUnique inv ← new gamble inventory for player p at this NPC clvl: i32 ← stat 12 of p slot: i32 ← 0G2. while slot < 14: [C] Step(S); lvl: i32 ← (i32)(S.low mod 10) + clvl − 5 ; draw; unsigned mod lvl ← 5 if lvl ≤ 5, 99 if lvl ≥ 99, else lvl item ← list[R(S, countUpTo[lvl])] ; draw (none when countUpTo[lvl] < 1) if not expansion: if item has no record: return [I] ends the build; no stock case if item.version ≥ 100: continue ; redraw this slot if slot = 0: item ← rin else if slot = 1: item ← amu ; after their two draws if expansion: item ← GAMBLE_Upgrade(lvl, item, D.GambleUber, D.GambleUltra) (G3) q: i32 ← 4 if total > 0: Step(S); r: u32 ← S.low mod 100000 ; draw if r < total: if r < D.GambleUnique: q ← 7 else if r ≥ D.GambleSet + D.GambleUnique: q ← 6 else: q ← 5 slot ← slot + 1 it ← ITEMS_CreateForStore(npc, item, kind 4, q, ilvl: lvl) (§ F) if it = none: continue [I] the slot stays empty; no stock case place it in inv (page 0); if that fails: destroy it; return ; the failure branch [I], no stock caseG3. GAMBLE_Upgrade(lvl, item, uber, ultra) → item: [C] B ← base record of item if B.ubercode is blank, 0 or unknown: return item ; no draw c: i32 ← (lvl − level(B.ubercode))·uber + 1 if c ≤ 0: return item ; no draw, no ultra test if R(S, 10000) < c: return base of B.ubercode ; draw; signed compare if B.ultracode is blank, 0 or unknown: return item c2: i32 ← (lvl − level(B.ultracode))·ultra + 1 if c2 ≤ 0: return item ; no draw if R(S, 10000) < c2: return base of B.ultracode ; draw return itemStep notes:
-
G1. [C] Every gamble open of the runs built a window: the 325 of the first vendors run and the 40 of the second vendors run, each after the previous window’s close had freed the inventory (§ H). (
GambleEnsure, vend 29) -
G1. [I] A gamble open builds only for an NPC whose record has
isGambler(the six classes of § A), and only when the player has no gamble inventory at that NPC:GambleEnsureskips the build when its id scan finds the player’s id. The inventory is keyed by the player’s unit id, so each player in a game has their own window. The no-build branch needs a second interactor on the NPC, and has no single-player case:NpcInteractRemovefrees the inventory only when its removal empties the NPC’s interaction list (cmp [edx], 0; jneskipsGambleInvFree); with one player every close and menu Escape sends the cancel, and the client sends the gamble action only from the NPC menu. A second player talking to the NPC keeps the list non-empty. (GambleEnsure,NPC_OpenStore, vend 29) -
G2. [C] The gamble level
lvllies inclvl − 5 .. clvl + 4; it filters the base (uniform among the list rows with baselevel ≤ lvl), is the item’s creationilvl, and is the upgrade level. At clvl 30 and 75 every value of that range occurred, and every affix pick of the 4550 gambled items reproduced from thatilvlby the general alvl rule: there is no separate affix window around the character’s level. -
G2. [C] The clamp to 5..99. In the second vendors run, of 560
lvldraws, 26 at clvl 1 fell below 5 (−4 to 4) and were taken as 5, and 232 at clvl 99 rose above 99 (100 to 103) and were taken as 99; every window reproduces from the clamped value (the pick’s boundcountUpTo[lvl], the upgrade level and the creationilvl). (GAMBLE_BuildInv, vend 30) -
G2. [C] Rings and amulets. Slot 0 is always a ring and slot 1 always an amulet; their
lvland pick draws are made and discarded, butlvlis still theirilvl.rinandamucan also come up in slots 2–13 as list rows. -
G2. [C] Classic redraw. In a classic game an expansion base repeats the slot’s
lvland pick draws without advancing the slot (94 redraws in the run). The upgrade is skipped in a classic game with no draw. -
G2. [C] The quality. One draw per slot (when
total > 0), tested cumulatively in the order unique, set, rare out of 100 000. With stock DifficultyLevels (GambleUnique50,GambleSet100,GambleRare10 000 in all three difficulties) the code’s shares are 50 unique, 100 set, 10 000 rare and 89 850 magic in 100 000. The code reads the columns, so other data changes them. A unique or set that item creation cannot build falls back as for any item. 4550 quality draws reproduced. -
G2. [I] A creation that returns no item leaves its slot empty (the slot counter already advanced); a placement failure ends the build. Neither happened in the run.
-
G3. [C] The uber test
R(S, 10000) < (lvl − qlvl)·GambleUber + 1gives(lvl − qlvl)·0.9 % + 0.01 %with the stockGambleUber90: the constant is 1 in 10 000, and atlvl = qlvlthe bound is 1. The ultra test (stockGambleUltra33) is made only after a failed uber draw and uses the elite base’s own level. A base with noubercode, or whose bound is ≤ 0, keeps its code with no draw. 2292 tests (1669 uber, 623 ultra) and 1966 no-draw bounds reproduced. -
[C] The gambled item is decided at the build. The server creates the window’s items with their upgraded base and quality already set; what a purchase does with them is § H.
-
[I] A gambled unique enters the made-uniques set at the build. Quality 7 reaches the same
ITEMS_BuildUniqueas a drop, whose oneITEMS_UniqueMarkMadecall marks the row, so a unique shown in the window marks its row made whether or not it is bought, and a later pick of that row fails and falls back.
Draw order on S per slot [C] (16 130 gamble-build draws reproduced): lvl (1), the pick (1, or 0 when countUpTo[lvl] < 1), in an expansion game the uber test (0–1) and the ultra test (0–1, only after a failed uber draw), the quality (1); then the item’s creation on the game seed and its item seed.
H. Gamble refresh and purchases
Section titled “H. Gamble refresh and purchases”- [C] Closing the gamble window sends the cancel packet:
NpcInteractRemoveremoves the player from the NPC’s interaction list, and when the list empties the player’s gamble inventory there is freed; the next Gamble builds a new window. Each of the 325 windows of the run was built this way. - [C] In the second vendors run all 77 logged
GambleInvFreecalls came fromNpcInteractRemove(return : the cancel). The interaction end that frees throughNpcStorePlayerLeave(§ Entry points) was met only at the joiner’s leaves at Kashya and Akara in the two-client run, neither a gambler. (GambleInvFree,NpcInteractRemove, vend 32) - [I] The inventory is also freed when a player unit is freed with its interaction open
(
PlayerInteractEnd→NpcStorePlayerLeave) and byNPCSTORE_ClearRecon a full reset of the NPC’s record. Opening the gamble window twice within one interaction shows the same items. Both need a second interactor on the NPC and have no single-player case: the free byNpcStorePlayerLeaveneeds a client leaving with a gamble window open, and a second open within one interaction is G1’s no-build branch, which needs the NPC’s interaction list non-empty at a close. (PlayerInteractEnd,NpcStorePlayerLeave,NPCSTORE_ClearRec, vend 32) - [C] A purchase copies the shown item and creates no replacement. In the second vendors run two gamble
purchases (Gheed’s
smlat clvl 1, Anya’scapat clvl 99) wentNPC_BuyItem→ItemCopyof the shown item (a new unit with the same class, quality and file index), thenStoreItemSold’s gamble branch, with noITEMS_CreateForStore,GAMBLE_BuildInvorVENDOR_BuildStockcall inside the purchase; the player’s gamble inventory afterwards was the one before less the bought item. (NPC_BuyItem,ItemCopy,StoreItemSold, vend 33) - [C] A bought stock item is removed from the store unless
VENDOR_IsPermanentholds; a sold item is copied in unless refused. Purchases in the second vendors run: Akara’stsc(permanent: no removal call, the stock unchanged), Akara’swnd, Charsi’slaxand Malah’sbwn(not permanent: the removal call, the stock less the item). Sales (NPC_SellItem’s decision): ahp5to Akara in Normal and acapto Malah in Hell copied and placed; atscto Akara refused by the permanent test (her permanent list); ahp5to Malah in Hell refused by the permanent test, wherehp5is in no vendor’s permanent list, so the clause outside Normal refused it, against the Normalhp5copied; acapsold in Gheed’s gamble window refused by the gamble view, with no copy. With the second economy run’s refusals by the flags bit 22 (ethereal) and0x100and bycarry1. (VENDOR_IsPermanent,StoreItemSold,NPC_SellItem, vend 34) - [I] The rest of the two tests, not reached:
VENDOR_IsPermanent’s clause outside Normal forhp4,mp4andmp5, and the sale refusals of aCrackedlow-quality item, base type 7, item flag0x1000000. (VENDOR_IsPermanent,NPC_SellItem, vend 34)
I. Prices and repair
Section titled “I. Prices and repair”- [C] Buy, sell and gamble prices go through
ItemTradePrice(player, item, difficulty, questRecord, npcClass, mode), with the NPC’s Npc.txt row found byNpcGetByClass; repair goes throughNpcRepairandRepairCost. They are specified in items/economy: the price core in § B–§ D, the gamble price in § E, buy, sell and repair in § F.
Outputs
Section titled “Outputs”- A stock build leaves the NPC’s store inventory holding, in creation order, the normal and superior copies (below
stock level 25), the magic copies and one normal copy of each permanent code, each placed on its tab; and
Sand the game seed advanced by every draw above. [C] - A gamble build leaves the player’s gamble inventory at that NPC holding up to 14 items: slot 0 a ring, slot 1 an
amulet, each with
ilvl= its slot’slvl, quality 4–7 (after item creation’s fallbacks), never ethereal. [C] - Each item is a finished item unit from uniques-sets → affixes → properties, identified. [C]
Worked example
Section titled “Worked example”Both examples are recomputed from the run’s logs (read-only), which reproduces them with 0 mismatches. Seeds are low:high in hex.
Stock: Akara, expansion Normal, Act I, clvl 30 (game 3201)
Section titled “Stock: Akara, expansion Normal, Act I, clvl 30 (game 3201)”Inputs: S = 3145eef6:54d70515 at the build, game seed 218ddad6:1552df2f, clvl 30, so
ilvl = min(35, 12) = 12 (Normal, Act I). Akara’s list: 5 entries and 10 permanent codes. All five entries are
level ≤ 12; MagicLvl is 1 on each.
| Entry | Min..Max | MagicMin..MagicMax |
|---|---|---|
wnd |
4..6 | 7..9 |
ywn |
1..2 | 1..1 |
scp |
2..4 | 2..4 |
sst |
5..9 | 5..9 |
lst |
2..3 | 1..2 |
The first eleven draws on S (low after the step, then the value):
| # | Draw | low |
Result |
|---|---|---|---|
| 1 | wnd count RandLoHi(4, 7) |
44564863 |
4 + 1 = 5 normal copies |
| 2–6 | quality, low mod 100 |
2e3c9115 … 08107a2d |
37, 95, 75, 80, 81 → 2, 3, 3, 3, 3 |
| 7 | wnd magic RandLoHi(7, 10) |
e16fda46 |
7 + 0 = 7 magic copies (no draw per copy in Normal) |
| 8 | ywn count RandLoHi(1, 3) |
375b6bc2 |
1 |
| 9 | quality | 100a38aa |
22 → 2 |
| 10 | ywn magic RandLoHi(1, 2) = 1 + R(S, 1) |
66500574 |
1 (a draw, though the range has one value) |
| 11 | scp count RandLoHi(2, 5) |
050e1eb4 |
3 |
The build continues the same way (scp 3 + 4, sst 6 + 6, lst 2 + 1) for 27 draws in all, ending at
S = a59b06dc:57c891ff, then makes the 10 permanent items (vps yps wms tbk ibk tsc isc key hp1 mp1, quality 2)
with no draw on S: 46 items. The first item (wnd, quality 2) steps the game seed twice: unit seed
9018a5dd:…, then 9930b65e:…, so its item seed is 9930b65e:0000029a ({start, 666}).
Gamble: Jamella, expansion Hell, clvl 75 (game 3203)
Section titled “Gamble: Jamella, expansion Hell, clvl 75 (game 3203)”Inputs: S = fa9e0110:4ba2ec0d, clvl 75, DifficultyLevels Hell GambleRare 10 000, GambleSet 100,
GambleUnique 50, GambleUber 90, GambleUltra 33; countUpTo[lvl] = 125 for every lvl ≥ 52.
| Slot | lvl |
pick (of 125) | uber test r / bound | ultra test r / bound | base | quality r → q |
|---|---|---|---|---|---|---|
| 0 | 79 | 45 hlm |
— | — | rin (slot 0) |
85041 → 4 |
| 1 | 77 | 40 2hs |
— | — | amu (slot 1) |
99141 → 4 |
| 2 | 72 | 38 wrb |
6916 / 3601 | 9157 / 331 | wrb |
30736 → 4 |
| 3 | 76 | 30 vgl |
3235 / 3331 | — | xvg |
92408 → 4 |
| 4 | 78 | 58 mxb |
2591 / 3421 | — | 8mx |
17273 → 4 |
| 5 | 76 | 41 spk |
1288 / 3061 | — | xpk |
33537 → 4 |
| 6 | 72 | 106 hgl |
899 / 1621 | — | xhg |
17665 → 4 |
| 7 | 76 | 103 wsd |
894 / 2431 | — | 9wd |
1219 → 6 |
| 8 | 72 | 124 ci1 |
409 / 181 | bound ≤ 0, no draw | ci1 |
7812 → 6 |
| 9 | 77 | 78 spt |
9491 / 2971 | bound ≤ 0, no draw | spt |
4142 → 6 |
| 10 | 78 | 71 clw |
5556 / 2971 | 2218 / 1 | clw |
32551 → 4 |
| 11 | 77 | 62 kit |
8503 / 2881 | 7312 / 166 | kit |
67585 → 4 |
| 12 | 79 | 56 2ax |
9392 / 3601 | 3271 / 298 | 2ax |
6087 → 6 |
| 13 | 71 | 78 spt |
1483 / 2431 | — | 9st |
63915 → 4 |
Slot 0 in detail: Step(S) → low 7a32bd5d, mod 10 = 9, lvl = 9 + 75 − 5 = 79; Step(S) → f405d8f0,
mod 125 = 45, list index 45 = hlm (level 11 starts at 41: spk crs vou rng hlm), discarded for rin, which has no
ubercode (no upgrade draw); Step(S) → 6f1ebb71, mod 100000 = 85041 ≥ 10 150, so magic. Slot 6: hgl’s
exceptional xhg has level 54, bound (72 − 54)·90 + 1 = 1621, and 899 < 1621 gives xhg. Slot 10: clw’s elite
base has level 78 = lvl, so its bound is 1 and only r = 0 would pass. Slots 8 and 9 fail their uber test and
make no ultra draw, because the elite bases (ci3 level 85, 7st level 83) are above lvl. The window takes 3 draws
on each of slots 0 and 1, 4 on each of the eight slots with one upgrade draw, and 5 on each of the four with two:
58 draws, ending at S = d06de8ab:51260e38; the 14 creations step the game seed twice each.
[C]
Reimplementation notes
Section titled “Reimplementation notes”-
A one-value range still draws.
RandLoHi(S, 1, 2)is1 + R(S, 1), andR(S, 1)stepsS(onlyn < 1skips the step). Akara’sywnmagic count above consumes a draw for a fixed result; so does aMin=Max= 0 count. Onlyhi ≤ loskips the draw. [C] -
The classic count draw. An expansion entry in a classic game still makes its count draw (below stock level 25) before it is skipped. [C]
-
Ring and amulet slots discard two draws. Slots 0 and 1 draw
lvland a pick, then replace the pick; theirlvlis kept. [C] -
Equal-level gamble order is data. Do not sort Gamble.txt with a stable sort; use the table in § G. [C]
-
Two seeds interleave. Every choice of § D, § E and § G is on
S; every item’s unit and item seed comes from the game seed, which other units also step between builds.HIRE_BuildStocksharesSand must run in its place: at a seller’s first interaction start, before any menu action, so Asheara’s hirelings come before her first stock build (C0). [C] (HIRE_BuildStock,NpcInteractStart, vend 14) -
The upgrade draw comes before the creation of each stock item, after its quality draw (normal copies) or after the magic count (magic copies); permanent items make it too in Nightmare and Hell. [C]
-
Stock level is not clamped to 99 in Nightmare and Hell (
clvl99 gives 104), while the gamblelvlis clamped to 5..99: 8 Hell builds at clvl 99 (Larzuk 5, Anya, Malah, Asheara) tookilvl104 and reproduce from it (the level gate, the upgrade bounds104·16 + 1000and104·128 + 5000, the creations’ilvl), while the same games’ gamblelvlwas clamped to 99. [C] (VENDOR_StockLevel,GAMBLE_BuildInv, vend 36) -
A 33rd failure ends the whole build, permanent items included, at the next limit test (after a normal copy or a permanent item; none in the magic loop). No stock build reaches it. [I] (vend 5)
-
MagicLvlis a gate, not a cap: do not clamp the affix level to it. [C] -
An act change by waypoint does not reset the old act’s stores in single player; it only marks those older than 240 s stale. A waypoint within the act resets them at once. [C]
Evidence
Section titled “Evidence”- Tables: Weapons § Vendor columns, Armor § Vendor columns, Misc § Vendor columns, Gamble, StorePage, Npc, DifficultyLevels § Gamble columns.
- Upstream specs: rng, rng/seeds, quality, uniques-sets, affixes, properties.
- Plan: 0031.