Chest shop suffle by world#136
Conversation
JackQuincy
commented
May 5, 2026
- Adding a flag -ccswr which makes chest shuffle in separate pools for World of Balance and World of Ruin based on the chests location, with a % chance to place a truly random item in the box instead
- This includes monster in a boxes
- Chest locations that can be accessed from the World of Balance or World of Ruin are placed into the World of Balance pool.
- Adding a flag -siswr which shuffles shop contents in separate pools for World of Balance and World of Ruin based on the location of the Shop. With a % chance to place a truly random item in the shop slot instead
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces new features to shuffle chest contents and shop inventories within their respective worlds (World of Balance and World of Ruin) with a configurable randomization percentage. While the implementation successfully integrates these options into the CLI and menus, two critical issues were identified in the shuffling logic. First, in data/chests.py, the chest indices must be filtered to exclude special or duplicate chests that are not in the active randomizer pool to prevent breaking game logic. Second, in data/shops.py, empty or inaccessible shops must be filtered out before gathering items to avoid item-to-shop capacity mismatches that can lead to runtime errors during shuffling.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| def shuffle_indices(self, types, indices): | ||
| import copy | ||
| chests_shuffle = list() | ||
| for index in indices: | ||
| chest = copy.deepcopy(self.all_chests[index]) | ||
| if chest.type in types: | ||
| chests_shuffle.append(chest) |
There was a problem hiding this comment.
The indices list contains raw chest IDs from area_chests, which includes special chests (such as the Lone Wolf chest and the Gem Box chest) and duplicate chests that are explicitly excluded from the randomizer pool (self.chests). Shuffling these can break game logic or duplicate/lose items. We should filter indices to only include chest IDs present in self.chests.
| def shuffle_indices(self, types, indices): | |
| import copy | |
| chests_shuffle = list() | |
| for index in indices: | |
| chest = copy.deepcopy(self.all_chests[index]) | |
| if chest.type in types: | |
| chests_shuffle.append(chest) | |
| def shuffle_indices(self, types, indices): | |
| import copy | |
| valid_chest_ids = {chest.id for chest in self.chests} | |
| indices = [index for index in indices if index in valid_chest_ids] | |
| chests_shuffle = list() | |
| for index in indices: | |
| chest = copy.deepcopy(self.all_chests[index]) | |
| if chest.type in types: | |
| chests_shuffle.append(chest) |
| shops_to_shuffle = list() | ||
| for shop_index in indices: | ||
| shops_to_shuffle.append(self.all_shops[shop_index]) | ||
|
|
||
| type_items = {Shop.WEAPON : [], Shop.ARMOR : [], Shop.ITEM : [], Shop.RELIC : [], Shop.VENDOR : []} | ||
| for shop in shops_to_shuffle: | ||
| for item_index in range(shop.item_count): | ||
| type_items[shop.type].append(shop.items[item_index]) | ||
|
|
||
| # shuffle vendor shops with item shops | ||
| # add vendor shops to list of item shops and vendor shop inventories to list of items in item shops | ||
| type_shops = {Shop.WEAPON : [], Shop.ARMOR : [], Shop.ITEM : [], Shop.RELIC : [], Shop.VENDOR : []} | ||
| for shop in shops_to_shuffle: | ||
| # exclude shops that are inaccesible from shops and type_shops lists | ||
| if shop.type != Shop.EMPTY and shop.accessible(): | ||
| type_shops[shop.type].append(shop) | ||
| type_items[Shop.ITEM].extend(type_items[Shop.VENDOR]) | ||
| self.shuffle_by_type(type_items, type_shops) |
There was a problem hiding this comment.
The indices list contains raw shop indices, some of which might be empty or inaccessible. If we collect items from all shops in indices (including empty/inaccessible ones) but only collect the shops themselves into type_shops if they are accessible and non-empty, we will have a mismatch between the number of items and the total capacity of the shops. This will cause shuffle_by_type to raise an IndexError when shop_indices becomes empty before all items are distributed, or a KeyError if shop.type is Shop.EMPTY. We should filter shops_to_shuffle to only include accessible and non-empty shops right at the start.
| shops_to_shuffle = list() | |
| for shop_index in indices: | |
| shops_to_shuffle.append(self.all_shops[shop_index]) | |
| type_items = {Shop.WEAPON : [], Shop.ARMOR : [], Shop.ITEM : [], Shop.RELIC : [], Shop.VENDOR : []} | |
| for shop in shops_to_shuffle: | |
| for item_index in range(shop.item_count): | |
| type_items[shop.type].append(shop.items[item_index]) | |
| # shuffle vendor shops with item shops | |
| # add vendor shops to list of item shops and vendor shop inventories to list of items in item shops | |
| type_shops = {Shop.WEAPON : [], Shop.ARMOR : [], Shop.ITEM : [], Shop.RELIC : [], Shop.VENDOR : []} | |
| for shop in shops_to_shuffle: | |
| # exclude shops that are inaccesible from shops and type_shops lists | |
| if shop.type != Shop.EMPTY and shop.accessible(): | |
| type_shops[shop.type].append(shop) | |
| type_items[Shop.ITEM].extend(type_items[Shop.VENDOR]) | |
| self.shuffle_by_type(type_items, type_shops) | |
| shops_to_shuffle = list() | |
| for shop_index in indices: | |
| shop = self.all_shops[shop_index] | |
| if shop.type != Shop.EMPTY and shop.accessible(): | |
| shops_to_shuffle.append(shop) | |
| type_items = {Shop.WEAPON : [], Shop.ARMOR : [], Shop.ITEM : [], Shop.RELIC : [], Shop.VENDOR : []} | |
| for shop in shops_to_shuffle: | |
| for item_index in range(shop.item_count): | |
| type_items[shop.type].append(shop.items[item_index]) | |
| # shuffle vendor shops with item shops | |
| # add vendor shops to list of item shops and vendor shop inventories to list of items in item shops | |
| type_shops = {Shop.WEAPON : [], Shop.ARMOR : [], Shop.ITEM : [], Shop.RELIC : [], Shop.VENDOR : []} | |
| for shop in shops_to_shuffle: | |
| type_shops[shop.type].append(shop) | |
| type_items[Shop.ITEM].extend(type_items[Shop.VENDOR]) | |
| self.shuffle_by_type(type_items, type_shops) |