When the boss is generated (door opened), the treasure is selected too. Here's a rough order of how things happen (assuming that OnPuzzleActivate() is calling GetItemRewardDesc() + GetMoneyBagDesc() and they're not called separately).
- The boss is spawned alongside the spinning wheel and minions.
- The server counts the number of players in the party. If there's more than 8 (?!) it only counts as 8.
- The server generates 8 chests and puts gold in them. It picks a min of 13000 and a max of 26000, and then... multiplies those by 0.16. Dungeons are set up to have different gold multipliers (decimators really) according to party count, but for Alby Advanced Hardmode it's unchanged (all the multipliers are 0.16 here). Strangely, the non-HM version is set up for higher gold rewards.
- The server runs a loop to generate "junk" items for the chests. Magic powder, NPC equipment with slightly-different stats, low-level potions, etc. Puts one result in each chest if I'm reading this correctly. Too lazy to list the items and probabilities 'cause it's all NPC or low-level crap.
- The server next checks for some features (if special upgrades and extra enchants are enabled) and then sets up stuff to generate the robe and upgrade stone. The following assumes that these features are enabled.
- The server runs the following loop once per player count in the party.
6a - Generate a random number to 1000.
6b - If this number is less than or equal to 40, put a Hebona Robe in chest x (x being the loop count+1).
6c - Generate a random number to 1000.
6d - If this number is less than or equal to 30, put a Blue Upgrade Stone in chest x (x being the loop count+1).
- Generate a random number up to 100, once.
If it's less than 30, give the Warrior enchant scroll in chest 1.
If it's 30-54, give a Lute with the Lucky enchant in chest 1.
If it's 55-84, give the Lethal enchant scroll in chest 1.
Otherwise, give the Precise enchant scroll in chest 1.
- Set up the stuff to be run when the boss is gone, such as giving the keys, checking and assigning journal progress.
So there's a few things of interest here.
A - Enchants only show up in chest 1, so you can only get one of them. This is likely what players refer to as a "primary" dungeon reward. The other dungeon scripts would have to be examined for else statements outside of loops to see what else (maybe skill books?) might be a "primary" reward where you can only get one item from that category no matter the chests opened.
B - Chest numbers higher than the party count can't contain a Hebona Robe. So if the chests in the room are always in a specific layout (1 is somewhere, 2 is somewhere else), that means you can figure out which chests cannot have a robe in it because they were not reached in the loop. This could help people save on yarn keys and get effectively higher chances per total chests opened if they can disregard chests that cannot have a robe.
Unfortunately I have not yet figured out if there's a pattern to which chest is which because getting people to cooperate in Mabi and not open chests until I say it's okay is proving quite difficult.
C - The server accounts for more than 8 players in a party, and this was well before Raid parties. It also accounts for less than 1 player, so either this is a failsafe (there's a failsafe gold multiplier too), or it accounts for GM trickery.