From ee61f7b3ac465e9c87c3323cb0543a95b645a6fc Mon Sep 17 00:00:00 2001 From: Kevin Cathcart Date: Fri, 5 Jan 2018 02:02:58 -0500 Subject: [PATCH] Handle turtle rock big key chest key-for-a-key --- Rules.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Rules.py b/Rules.py index d0a31981..bd20dcd6 100644 --- a/Rules.py +++ b/Rules.py @@ -506,18 +506,21 @@ def set_trock_key_rules(world): set_rule(world.get_entrance('Turtle Rock (Chain Chomp Room) (North)'), lambda state: state.has('Small Key (Turtle Rock)', 3)) # the most complicated one - # if we have back entrance access, we could waste all keys before touching this - # if we don't, we have access to all chests by the time we can waste a key on trinexx door - # in that case, if it contains the big key, we can also not waste a key on the roller switch door - # however in keysanity being able to reach all other chests while only having three keys does not imply this contains - # a key, so we again need all four keys unless it contains the big key - if can_reach_back: - set_rule(world.get_location('Turtle Rock - Big Key Chest'), lambda state: state.has('Small Key (Turtle Rock)', 4) or (item_name(state.world.get_location('Turtle Rock - Big Key Chest')) in ['Small Key (Turtle Rock)'])) - elif world.keysanity: - set_rule(world.get_location('Turtle Rock - Big Key Chest'), lambda state: state.has('Small Key (Turtle Rock)', 2) if (item_name(state.world.get_location('Turtle Rock - Big Key Chest')) in ['Big Key (Turtle Rock)']) else state.has('Small Key (Turtle Rock)', 4) or (item_name(state.world.get_location('Turtle Rock - Big Key Chest')) in ['Small Key (Turtle Rock)'])) - else: - set_rule(world.get_location('Turtle Rock - Big Key Chest'), lambda state: state.has('Small Key (Turtle Rock)', 2) if (item_name(state.world.get_location('Turtle Rock - Big Key Chest')) in ['Big Key (Turtle Rock)']) else state.has('Small Key (Turtle Rock)', 3) or (item_name(state.world.get_location('Turtle Rock - Big Key Chest')) in ['Small Key (Turtle Rock)'])) - # TODO add key-for-key logic to the above mess via always_allow rules. Ugh! + def tr_big_key_chest_keys_needed(state): + item = item_name(state.world.get_location('Turtle Rock - Big Key Chest')) + # handle key for a key situation in the usual way (by letting us logically open the door using the key locked inside it) + if item in ['Small Key (Turtle Rock)']: + return 3 + # if we lack backdoor access and cannot reach the back before opening this chest because it contains the big key + # then that means there are two doors left that we cannot have spent a key on, (crystalroller and trinexx) so we only need + # two keys + if item in ['Big Key (Turtle Rock)'] and not can_reach_back: + return 2 + # otherwise we could potentially have opened every other door already, so we need all 4 keys. + return 4 + + set_rule(world.get_location('Turtle Rock - Big Key Chest'), lambda state: state.has('Small Key (Turtle Rock)', tr_big_key_chest_keys_needed(state))) + set_always_allow(world.get_location('Turtle Rock - Big Key Chest'), lambda state, item: item.name == 'Small Key (Turtle Rock)' and state.has('Small Key (Turtle Rock)', 3)) # set big key restrictions non_big_key_locations = ['Turtle Rock - Big Chest', 'Turtle Rock - Trinexx']