From 3b5ae8712bccabb43c0b4dbae4534a0b88bb22f5 Mon Sep 17 00:00:00 2001 From: Scipio Wright Date: Mon, 20 May 2024 21:38:51 -0400 Subject: [PATCH] Clean up a bunch of rules that no longer need to be multi-lined since the functions are shorter --- worlds/tunic/er_rules.py | 44 +++++++++++++------------------- worlds/tunic/rules.py | 54 +++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 58 deletions(-) diff --git a/worlds/tunic/er_rules.py b/worlds/tunic/er_rules.py index ef2063e3e44a..d6d58bf26514 100644 --- a/worlds/tunic/er_rules.py +++ b/worlds/tunic/er_rules.py @@ -397,8 +397,7 @@ def set_er_region_rules(world: "TunicWorld", regions: Dict[str, Region], portal_ regions["East Forest"].connect( connecting_region=regions["Lower Forest"], rule=lambda state: has_ladder("Ladders to Lower Forest", state, player) - or (state.has_all({grapple, fire_wand, ice_dagger}, player) # do ice slime, then go to the lower hook - and has_ability(icebolt, state, player))) + or (state.has_all({grapple, fire_wand, ice_dagger}, player) and has_ability(icebolt, state, player))) regions["Lower Forest"].connect( connecting_region=regions["East Forest"], rule=lambda state: has_ladder("Ladders to Lower Forest", state, player)) @@ -440,7 +439,6 @@ def set_er_region_rules(world: "TunicWorld", regions: Dict[str, Region], portal_ connecting_region=regions["Forest Grave Path by Grave"]) # Beneath the Well and Dark Tomb - # don't need the ladder when entering at the ladder spot regions["Beneath the Well Ladder Exit"].connect( connecting_region=regions["Beneath the Well Front"], rule=lambda state: has_ladder("Ladders in Well", state, player)) @@ -603,8 +601,8 @@ def set_er_region_rules(world: "TunicWorld", regions: Dict[str, Region], portal_ regions["Library Exterior Ladder Region"].connect( connecting_region=regions["Library Exterior Tree Region"], rule=lambda state: has_ability(prayer, state, player) - and (state.has(grapple, player) or (state.has(laurels, player) - and has_ladder("Ladders in Library", state, player)))) + and ((state.has(laurels, player) and has_ladder("Ladders in Library", state, player)) + or state.has(grapple, player))) regions["Library Hall Bookshelf"].connect( connecting_region=regions["Library Hall"], @@ -822,8 +820,7 @@ def set_er_region_rules(world: "TunicWorld", regions: Dict[str, Region], portal_ # nmg: use ice grapple to get from the beginning of Quarry to the door without really needing mask only with ER on regions["Quarry"].connect( connecting_region=regions["Lower Quarry Zig Door"], - rule=lambda state: has_ice_grapple_logic(True, state, player) - and options.entrance_rando) + rule=lambda state: has_ice_grapple_logic(True, state, player) and options.entrance_rando) regions["Monastery Front"].connect( connecting_region=regions["Monastery Back"]) @@ -860,8 +857,7 @@ def set_er_region_rules(world: "TunicWorld", regions: Dict[str, Region], portal_ # nmg: can ice grapple on the voidlings to the double admin fight, still need to pray at the fuse regions["Rooted Ziggurat Lower Back"].connect( connecting_region=regions["Rooted Ziggurat Lower Front"], - rule=lambda state: ((state.has(laurels, player) - or has_ice_grapple_logic(True, state, player)) + rule=lambda state: ((state.has(laurels, player) or has_ice_grapple_logic(True, state, player)) and has_ability(prayer, state, player) and has_sword(state, player)) or can_ladder_storage(state, player)) @@ -897,8 +893,7 @@ def set_er_region_rules(world: "TunicWorld", regions: Dict[str, Region], portal_ # nmg: ice grapple through cathedral door, can do it both ways regions["Swamp Mid"].connect( connecting_region=regions["Swamp to Cathedral Main Entrance Region"], - rule=lambda state: (has_ability(prayer, state, player) - and state.has(laurels, player)) + rule=lambda state: (has_ability(prayer, state, player) and state.has(laurels, player)) or has_ice_grapple_logic(False, state, player)) regions["Swamp to Cathedral Main Entrance Region"].connect( connecting_region=regions["Swamp Mid"], @@ -1252,8 +1247,7 @@ def get_portal_info(portal_sd: str) -> Tuple[str, str]: regions[region_name].connect( regions[paired_region], name=portal_name + " (LS) " + region_name, - rule=lambda state: has_stick(state, player) - and state.has_any(ladders, player) + rule=lambda state: has_stick(state, player) and state.has_any(ladders, player) and state.has_any({"Ladder in Dark Tomb", "Ladders to West Bell"}, player)) # soft locked if you can't get past garden knight backwards or up the belltower ladders elif portal_name == "West Garden Entrance near Belltower" and not options.entrance_rando: @@ -1267,23 +1261,20 @@ def get_portal_info(portal_sd: str) -> Tuple[str, str]: regions[region_name].connect( regions[paired_region], name=portal_name + " (LS) " + region_name, - rule=lambda state: has_stick(state, player) - and state.has("Ladder to Beneath the Vault", player) + rule=lambda state: has_stick(state, player) and state.has("Ladder to Beneath the Vault", player) and has_lantern(state, player)) elif portal_name == "Atoll Lower Entrance" and not options.entrance_rando: regions[region_name].connect( regions[paired_region], name=portal_name + " (LS) " + region_name, - rule=lambda state: has_stick(state, player) - and state.has_any(ladders, player) + rule=lambda state: has_stick(state, player) and state.has_any(ladders, player) and (state.has_any({"Ladders in Overworld Town", grapple}, player) or has_ice_grapple_logic(True, state, player))) elif portal_name == "Atoll Upper Entrance" and not options.entrance_rando: regions[region_name].connect( regions[paired_region], name=portal_name + " (LS) " + region_name, - rule=lambda state: has_stick(state, player) - and state.has_any(ladders, player) + rule=lambda state: has_stick(state, player) and state.has_any(ladders, player) and state.has(grapple, player) or has_ability(prayer, state, player)) # soft lock potential elif portal_name in {"Special Shop Entrance", "Stairs to Top of the Mountain", "Swamp Upper Entrance", @@ -1316,15 +1307,13 @@ def get_portal_info(portal_sd: str) -> Tuple[str, str]: regions[region_name].connect( regions[paired_region], name=portal_name + " (LS) " + region_name, - rule=lambda state: has_stick(state, player) - and state.has(ladder, player)) + rule=lambda state: has_stick(state, player) and state.has(ladder, player)) # if multiple ladders can be used else: regions[region_name].connect( regions[paired_region], name=portal_name + " (LS) " + region_name, - rule=lambda state: has_stick(state, player) - and state.has_any(ladders, player)) + rule=lambda state: has_stick(state, player) and state.has_any(ladders, player)) def set_er_location_rules(world: "TunicWorld") -> None: @@ -1407,8 +1396,10 @@ def set_er_location_rules(world: "TunicWorld") -> None: lambda state: state.has(fairies, player, 10)) set_rule(multiworld.get_location("Secret Gathering Place - 20 Fairy Reward", player), lambda state: state.has(fairies, player, 20)) - set_rule(multiworld.get_location("Coins in the Well - 3 Coins", player), lambda state: state.has(coins, player, 3)) - set_rule(multiworld.get_location("Coins in the Well - 6 Coins", player), lambda state: state.has(coins, player, 6)) + set_rule(multiworld.get_location("Coins in the Well - 3 Coins", player), + lambda state: state.has(coins, player, 3)) + set_rule(multiworld.get_location("Coins in the Well - 6 Coins", player), + lambda state: state.has(coins, player, 6)) set_rule(multiworld.get_location("Coins in the Well - 10 Coins", player), lambda state: state.has(coins, player, 10)) set_rule(multiworld.get_location("Coins in the Well - 15 Coins", player), @@ -1420,8 +1411,7 @@ def set_er_location_rules(world: "TunicWorld") -> None: set_rule(multiworld.get_location("East Forest - Lower Dash Chest", player), lambda state: state.has_all({grapple, laurels}, player)) set_rule(multiworld.get_location("East Forest - Ice Rod Grapple Chest", player), lambda state: ( - state.has_all({grapple, ice_dagger, fire_wand}, player) and - has_ability(icebolt, state, player))) + state.has_all({grapple, ice_dagger, fire_wand}, player) and has_ability(icebolt, state, player))) # West Garden set_rule(multiworld.get_location("West Garden - [North] Across From Page Pickup", player), diff --git a/worlds/tunic/rules.py b/worlds/tunic/rules.py index 8f3e420bea12..a8e7fa96c17b 100644 --- a/worlds/tunic/rules.py +++ b/worlds/tunic/rules.py @@ -58,7 +58,8 @@ def has_ability(ability: str, state: CollectionState, player: int) -> bool: # a check to see if you can whack things in melee at all def has_stick(state: CollectionState, player: int) -> bool: - return state.has("Stick", player) or state.has("Sword Upgrade", player, 1) or state.has("Sword", player) + return (state.has("Stick", player) or state.has("Sword Upgrade", player, 1) + or state.has("Sword", player)) def has_sword(state: CollectionState, player: int) -> bool: @@ -72,8 +73,7 @@ def has_ice_grapple_logic(long_range: bool, state: CollectionState, player: int) if not long_range: return state.has_all({ice_dagger, grapple}, player) else: - return state.has_all({ice_dagger, fire_wand, grapple}, player) and \ - has_ability(icebolt, state, player) + return state.has_all({ice_dagger, fire_wand, grapple}, player) and has_ability(icebolt, state, player) def can_ladder_storage(state: CollectionState, player: int) -> bool: @@ -120,11 +120,9 @@ def set_region_rules(world: "TunicWorld") -> None: or can_ladder_storage(state, player) # using laurels or ls to get in is covered by the -> Eastern Vault Fortress rules multiworld.get_entrance("Overworld -> Beneath the Vault", player).access_rule = \ - lambda state: has_lantern(state, player) and \ - has_ability(prayer, state, player) + lambda state: has_lantern(state, player) and has_ability(prayer, state, player) multiworld.get_entrance("Ruined Atoll -> Library", player).access_rule = \ - lambda state: state.has_any({grapple, laurels}, player) and \ - has_ability(prayer, state, player) + lambda state: state.has_any({grapple, laurels}, player) and has_ability(prayer, state, player) multiworld.get_entrance("Overworld -> Quarry", player).access_rule = \ lambda state: (has_sword(state, player) or state.has(fire_wand, player)) \ and (state.has_any({grapple, laurels}, player) or can_ladder_storage(state, player)) @@ -140,8 +138,7 @@ def set_region_rules(world: "TunicWorld") -> None: multiworld.get_entrance("Overworld -> Spirit Arena", player).access_rule = \ lambda state: (state.has(gold_hexagon, player, options.hexagon_goal.value) if options.hexagon_quest.value else state.has_all({red_hexagon, green_hexagon, blue_hexagon}, player)) and \ - has_ability(prayer, state, player) and has_sword(state, player) and \ - state.has_any({lantern, laurels}, player) + has_ability(prayer, state, player) and has_sword(state, player) and state.has_any({lantern, laurels}, player) def set_location_rules(world: "TunicWorld") -> None: @@ -155,15 +152,14 @@ def set_location_rules(world: "TunicWorld") -> None: set_rule(multiworld.get_location("Far Shore - Page Pickup", player), lambda state: has_ability(prayer, state, player)) set_rule(multiworld.get_location("Fortress Courtyard - Chest Near Cave", player), - lambda state: has_ability(prayer, state, player) or state.has(laurels, player) + lambda state: has_ability(prayer, state, player) + or state.has(laurels, player) or can_ladder_storage(state, player) - or (has_ice_grapple_logic(True, state, player) - and has_lantern(state, player))) + or (has_ice_grapple_logic(True, state, player) and has_lantern(state, player))) set_rule(multiworld.get_location("Fortress Courtyard - Page Near Cave", player), lambda state: has_ability(prayer, state, player) or state.has(laurels, player) or can_ladder_storage(state, player) - or (has_ice_grapple_logic(True, state, player) - and has_lantern(state, player))) + or (has_ice_grapple_logic(True, state, player) and has_lantern(state, player))) set_rule(multiworld.get_location("East Forest - Dancing Fox Spirit Holy Cross", player), lambda state: has_ability(holy_cross, state, player)) set_rule(multiworld.get_location("Forest Grave Path - Holy Cross Code by Grave", player), @@ -201,10 +197,10 @@ def set_location_rules(world: "TunicWorld") -> None: or has_ice_grapple_logic(False, state, player) or (state.has(laurels, player) and options.logic_rules)) set_rule(multiworld.get_location("Old House - Holy Cross Chest", player), - lambda state: has_ability(holy_cross, state, player) and - (state.has(house_key, player) - or has_ice_grapple_logic(False, state, player) - or (state.has(laurels, player) and options.logic_rules))) + lambda state: has_ability(holy_cross, state, player) and ( + state.has(house_key, player) + or has_ice_grapple_logic(False, state, player) + or (state.has(laurels, player) and options.logic_rules))) set_rule(multiworld.get_location("Old House - Shield Pickup", player), lambda state: state.has(house_key, player) or has_ice_grapple_logic(False, state, player) @@ -224,11 +220,10 @@ def set_location_rules(world: "TunicWorld") -> None: set_rule(multiworld.get_location("Special Shop - Secret Page Pickup", player), lambda state: state.has(laurels, player)) set_rule(multiworld.get_location("Sealed Temple - Holy Cross Chest", player), - lambda state: has_ability(holy_cross, state, player) and - (state.has(laurels, player) - or (has_lantern(state, player) and - (has_sword(state, player) or state.has(fire_wand, player))) - or has_ice_grapple_logic(False, state, player))) + lambda state: has_ability(holy_cross, state, player) + and (state.has(laurels, player) or (has_lantern(state, player) and (has_sword(state, player) + or state.has(fire_wand, player))) + or has_ice_grapple_logic(False, state, player))) set_rule(multiworld.get_location("Sealed Temple - Page Pickup", player), lambda state: state.has(laurels, player) or (has_lantern(state, player) and (has_sword(state, player) or state.has(fire_wand, player))) @@ -264,8 +259,7 @@ def set_location_rules(world: "TunicWorld") -> None: set_rule(multiworld.get_location("West Garden - [West] In Flooded Walkway", player), lambda state: state.has(laurels, player)) set_rule(multiworld.get_location("West Garden - [West Lowlands] Tree Holy Cross Chest", player), - lambda state: state.has(laurels, player) - and has_ability(holy_cross, state, player)) + lambda state: state.has(laurels, player) and has_ability(holy_cross, state, player)) set_rule(multiworld.get_location("West Garden - [East Lowlands] Page Behind Ice Dagger House", player), lambda state: (state.has(laurels, player) and has_ability(prayer, state, player)) or has_ice_grapple_logic(True, state, player)) @@ -298,13 +292,11 @@ def set_location_rules(world: "TunicWorld") -> None: set_rule(multiworld.get_location("Fortress Leaf Piles - Secret Chest", player), lambda state: state.has(laurels, player)) set_rule(multiworld.get_location("Fortress Arena - Siege Engine/Vault Key Pickup", player), - lambda state: has_sword(state, player) and - (has_ability(prayer, state, player) - or has_ice_grapple_logic(False, state, player))) + lambda state: has_sword(state, player) + and (has_ability(prayer, state, player) or has_ice_grapple_logic(False, state, player))) set_rule(multiworld.get_location("Fortress Arena - Hexagon Red", player), - lambda state: state.has(vault_key, player) and - (has_ability(prayer, state, player) - or has_ice_grapple_logic(False, state, player))) + lambda state: state.has(vault_key, player) + and (has_ability(prayer, state, player) or has_ice_grapple_logic(False, state, player))) # Beneath the Vault set_rule(multiworld.get_location("Beneath the Fortress - Bridge", player),