Skip to content

Chest shop suffle by world#136

Open
JackQuincy wants to merge 3 commits into
ff6wc:mainfrom
JackQuincy:chest-shop-suffle-by-world
Open

Chest shop suffle by world#136
JackQuincy wants to merge 3 commits into
ff6wc:mainfrom
JackQuincy:chest-shop-suffle-by-world

Conversation

@JackQuincy

Copy link
Copy Markdown
  • 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

@wrjones104

Copy link
Copy Markdown
Collaborator

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread data/chests.py
Comment on lines +200 to +206
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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)

Comment thread data/shops.py
Comment on lines +166 to +183
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants