From 0a9d61eb993a13285a610d6729738907ce4d84fd Mon Sep 17 00:00:00 2001 From: Fenhl Date: Wed, 8 Nov 2023 04:19:20 +0000 Subject: [PATCH 1/5] Fix logic for Kak Granny Buy Blue Potion --- data/World/Overworld.json | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/data/World/Overworld.json b/data/World/Overworld.json index 96ca25f86..84570d227 100644 --- a/data/World/Overworld.json +++ b/data/World/Overworld.json @@ -1789,12 +1789,11 @@ "locations": { "Kak Granny Trade Odd Mushroom": "'Odd Potion Access'", # Granny will not sell her item without turning in odd mushroom - # If the adult trade item(s) in the world are all after odd mushroom, - # allow any of the later sequence items to satisfy logic. The patcher - # sets the flag needed for her to sell stuff if odd mushroom can't be obtained. - "Kak Granny Buy Blue Potion": "Progressive_Wallet and is_adult and - (Odd_Mushroom or ((Odd_Potion or Poachers_Saw or Broken_Sword or - Prescription or Eyeball_Frog or Eyedrops or Claim_Check) and not adult_trade_shuffle))" + "Kak Granny Buy Blue Potion": "Progressive_Wallet and is_adult and ('Odd Potion Access' or + ((selected_adult_trade_item == 'Odd Potion' or selected_adult_trade_item == 'Poachers Saw' or + selected_adult_trade_item == 'Broken Sword' or selected_adult_trade_item == 'Prescription' or + selected_adult_trade_item == 'Eyeball Frog' or selected_adult_trade_item == 'Eyedrops' or + selected_adult_trade_item == 'Claim Check') and not adult_trade_shuffle))" }, "exits": { "Kak Backyard": "True" From 9f99cfa737f6a706e78a06065ef3e7c87ef80a89 Mon Sep 17 00:00:00 2001 From: mracsys Date: Tue, 7 Nov 2023 23:50:28 -0500 Subject: [PATCH 2/5] plando fix for adult trade item --- Plandomizer.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Plandomizer.py b/Plandomizer.py index b035f0afc..a866e328b 100644 --- a/Plandomizer.py +++ b/Plandomizer.py @@ -843,6 +843,13 @@ def fill(self, worlds: list[World], location_pools: list[list[Location]], item_p if self.locations: locations = {loc: self.locations[loc] for loc in random.sample(sorted(self.locations), len(self.locations))} used_items = [] + # Override the adult trade item used to control trade quest flags during patching. + # This has to run before placing other items because the selected trade + # item impacts logic for buying a blue potion from Granny's Potion shop. + adult_trade_matcher = self.pattern_matcher("#AdultTrade") + plando_adult_trade = list(filter(lambda location_record_pair: adult_trade_matcher(location_record_pair[1].item), self.pattern_dict_items(locations))) + if plando_adult_trade and not world.settings.adult_trade_shuffle and world.settings.adult_trade_start: + world.selected_adult_trade_item = plando_adult_trade[0][1].item # ugly but functional, see the loop below for how this is indexed record: LocationRecord for (location_name, record) in self.pattern_dict_items(locations): if record.item is None: @@ -892,11 +899,6 @@ def fill(self, worlds: list[World], location_pools: list[list[Location]], item_p if record.item == '#Junk' and location.type == 'Song' and world.settings.shuffle_song_items == 'song' and not any(name in song_list and r.count for name, r in world.settings.starting_items.items()): record.item = '#JunkSong' - adult_trade_matcher = self.pattern_matcher("#AdultTrade") - if adult_trade_matcher(record.item) and not world.settings.adult_trade_shuffle and world.settings.adult_trade_start: - # Override the adult trade item used to control trade quest flags during patching - world.selected_adult_trade_item = record.item - ignore_pools = None is_invert = self.pattern_matcher(record.item)('!') if is_invert and location.type != 'Song' and world.settings.shuffle_song_items == 'song': From 900463f114bbee61246285716c9b18dbe78cb2c6 Mon Sep 17 00:00:00 2001 From: Fenhl Date: Wed, 8 Nov 2023 05:23:22 +0000 Subject: [PATCH 3/5] Calculate selected adult trade item on world construction --- ItemPool.py | 4 +--- Plandomizer.py | 7 ------- World.py | 11 ++++++++++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ItemPool.py b/ItemPool.py index c0869dd6d..32ff5e3fb 100644 --- a/ItemPool.py +++ b/ItemPool.py @@ -647,9 +647,7 @@ def get_pool_core(world: World) -> tuple[list[str], dict[str, Item]]: elif location.vanilla_item in trade_items: if not world.settings.adult_trade_shuffle: if location.vanilla_item == 'Pocket Egg' and world.settings.adult_trade_start: - potential_trade_items = world.settings.adult_trade_start - item = random.choice(potential_trade_items) - world.selected_adult_trade_item = item + item = world.selected_adult_trade_item shuffle_item = True else: shuffle_item = False diff --git a/Plandomizer.py b/Plandomizer.py index a866e328b..51b58249f 100644 --- a/Plandomizer.py +++ b/Plandomizer.py @@ -843,13 +843,6 @@ def fill(self, worlds: list[World], location_pools: list[list[Location]], item_p if self.locations: locations = {loc: self.locations[loc] for loc in random.sample(sorted(self.locations), len(self.locations))} used_items = [] - # Override the adult trade item used to control trade quest flags during patching. - # This has to run before placing other items because the selected trade - # item impacts logic for buying a blue potion from Granny's Potion shop. - adult_trade_matcher = self.pattern_matcher("#AdultTrade") - plando_adult_trade = list(filter(lambda location_record_pair: adult_trade_matcher(location_record_pair[1].item), self.pattern_dict_items(locations))) - if plando_adult_trade and not world.settings.adult_trade_shuffle and world.settings.adult_trade_start: - world.selected_adult_trade_item = plando_adult_trade[0][1].item # ugly but functional, see the loop below for how this is indexed record: LocationRecord for (location_name, record) in self.pattern_dict_items(locations): if record.item is None: diff --git a/World.py b/World.py index c06c20746..c0ae29345 100644 --- a/World.py +++ b/World.py @@ -78,7 +78,16 @@ def __init__(self, world_id: int, settings: Settings, resolve_randomized_setting self.disable_trade_revert: bool = self.shuffle_interior_entrances or settings.shuffle_overworld_entrances or settings.adult_trade_shuffle self.skip_child_zelda: bool = 'Zeldas Letter' not in settings.shuffle_child_trade and \ 'Zeldas Letter' in self.distribution.starting_items - self.selected_adult_trade_item: str = '' + self.selected_adult_trade_item: str = random.choice(settings.adult_trade_start) if settings.adult_trade_start else None + # Override the adult trade item used to control trade quest flags during patching if any are placed in plando. + # This has to run here because the rule parser caches world attributes and this attribute impacts logic for buying a blue potion from Granny's Potion shop. + locations = {} + if self.distribution.locations: + locations = {loc: self.distribution.locations[loc] for loc in random.sample(sorted(self.distribution.locations), len(self.distribution.locations))} + adult_trade_matcher = self.distribution.pattern_matcher("#AdultTrade") + plando_adult_trade = list(filter(lambda location_record_pair: adult_trade_matcher(location_record_pair[1].item), self.distribution.pattern_dict_items(locations))) + if plando_adult_trade and not settings.adult_trade_shuffle and settings.adult_trade_start: + self.selected_adult_trade_item = plando_adult_trade[0][1].item # ugly but functional, see the loop in Plandomizer.WorldDistribution.fill for how this is indexed self.adult_trade_starting_inventory: str = '' if (settings.open_forest == 'closed' From 6622b72eadf37b177e94602df49ced8761869dbd Mon Sep 17 00:00:00 2001 From: Fenhl Date: Wed, 8 Nov 2023 05:58:40 +0000 Subject: [PATCH 4/5] Address review comments --- World.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/World.py b/World.py index c0ae29345..d00d34614 100644 --- a/World.py +++ b/World.py @@ -78,16 +78,14 @@ def __init__(self, world_id: int, settings: Settings, resolve_randomized_setting self.disable_trade_revert: bool = self.shuffle_interior_entrances or settings.shuffle_overworld_entrances or settings.adult_trade_shuffle self.skip_child_zelda: bool = 'Zeldas Letter' not in settings.shuffle_child_trade and \ 'Zeldas Letter' in self.distribution.starting_items - self.selected_adult_trade_item: str = random.choice(settings.adult_trade_start) if settings.adult_trade_start else None - # Override the adult trade item used to control trade quest flags during patching if any are placed in plando. - # This has to run here because the rule parser caches world attributes and this attribute impacts logic for buying a blue potion from Granny's Potion shop. - locations = {} - if self.distribution.locations: - locations = {loc: self.distribution.locations[loc] for loc in random.sample(sorted(self.distribution.locations), len(self.distribution.locations))} - adult_trade_matcher = self.distribution.pattern_matcher("#AdultTrade") - plando_adult_trade = list(filter(lambda location_record_pair: adult_trade_matcher(location_record_pair[1].item), self.distribution.pattern_dict_items(locations))) - if plando_adult_trade and not settings.adult_trade_shuffle and settings.adult_trade_start: - self.selected_adult_trade_item = plando_adult_trade[0][1].item # ugly but functional, see the loop in Plandomizer.WorldDistribution.fill for how this is indexed + if not settings.adult_trade_shuffle and settings.adult_trade_start: + self.selected_adult_trade_item: str = random.choice(settings.adult_trade_start) + # Override the adult trade item used to control trade quest flags during patching if any are placed in plando. + # This has to run here because the rule parser caches world attributes and this attribute impacts logic for buying a blue potion from Granny's Potion shop. + adult_trade_matcher = self.distribution.pattern_matcher("#AdultTrade") + plando_adult_trade = list(filter(lambda location_record_pair: adult_trade_matcher(location_record_pair[1].item), self.distribution.pattern_dict_items(self.distribution.locations))) + if plando_adult_trade: + self.selected_adult_trade_item = plando_adult_trade[0][1].item # ugly but functional, see the loop in Plandomizer.WorldDistribution.fill for how this is indexed self.adult_trade_starting_inventory: str = '' if (settings.open_forest == 'closed' From f5cb80877b7c0bd4caeb1afd39fbd7cbc1793a20 Mon Sep 17 00:00:00 2001 From: Fenhl Date: Wed, 8 Nov 2023 06:23:30 +0000 Subject: [PATCH 5/5] Always define World.selected_adult_trade_item --- World.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/World.py b/World.py index d00d34614..26ad793b8 100644 --- a/World.py +++ b/World.py @@ -78,8 +78,9 @@ def __init__(self, world_id: int, settings: Settings, resolve_randomized_setting self.disable_trade_revert: bool = self.shuffle_interior_entrances or settings.shuffle_overworld_entrances or settings.adult_trade_shuffle self.skip_child_zelda: bool = 'Zeldas Letter' not in settings.shuffle_child_trade and \ 'Zeldas Letter' in self.distribution.starting_items + self.selected_adult_trade_item: str = None if not settings.adult_trade_shuffle and settings.adult_trade_start: - self.selected_adult_trade_item: str = random.choice(settings.adult_trade_start) + self.selected_adult_trade_item = random.choice(settings.adult_trade_start) # Override the adult trade item used to control trade quest flags during patching if any are placed in plando. # This has to run here because the rule parser caches world attributes and this attribute impacts logic for buying a blue potion from Granny's Potion shop. adult_trade_matcher = self.distribution.pattern_matcher("#AdultTrade")