TLOZ: update to new options API (#2714)

This commit is contained in:
t3hf1gm3nt 2024-01-14 22:47:32 -05:00 committed by GitHub
parent 5b93db121f
commit 6d393fe42b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 28 deletions

View File

@ -94,17 +94,17 @@ def get_pool_core(world):
# Starting Weapon
start_weapon_locations = starting_weapon_locations.copy()
final_starting_weapons = [weapon for weapon in starting_weapons
if weapon not in world.multiworld.non_local_items[world.player]]
if weapon not in world.options.non_local_items]
if not final_starting_weapons:
final_starting_weapons = starting_weapons
starting_weapon = random.choice(final_starting_weapons)
if world.multiworld.StartingPosition[world.player] == StartingPosition.option_safe:
if world.options.StartingPosition == StartingPosition.option_safe:
placed_items[start_weapon_locations[0]] = starting_weapon
elif world.multiworld.StartingPosition[world.player] in \
elif world.options.StartingPosition in \
[StartingPosition.option_unsafe, StartingPosition.option_dangerous]:
if world.multiworld.StartingPosition[world.player] == StartingPosition.option_dangerous:
if world.options.StartingPosition == StartingPosition.option_dangerous:
for location in dangerous_weapon_locations:
if world.multiworld.ExpandedPool[world.player] or "Drop" not in location:
if world.options.ExpandedPool or "Drop" not in location:
start_weapon_locations.append(location)
placed_items[random.choice(start_weapon_locations)] = starting_weapon
else:
@ -115,7 +115,7 @@ def get_pool_core(world):
# Triforce Fragments
fragment = "Triforce Fragment"
if world.multiworld.ExpandedPool[world.player]:
if world.options.ExpandedPool:
possible_level_locations = [location for location in all_level_locations
if location not in level_locations[8]]
else:
@ -125,15 +125,15 @@ def get_pool_core(world):
if location in possible_level_locations:
possible_level_locations.remove(location)
for level in range(1, 9):
if world.multiworld.TriforceLocations[world.player] == TriforceLocations.option_vanilla:
if world.options.TriforceLocations == TriforceLocations.option_vanilla:
placed_items[f"Level {level} Triforce"] = fragment
elif world.multiworld.TriforceLocations[world.player] == TriforceLocations.option_dungeons:
elif world.options.TriforceLocations == TriforceLocations.option_dungeons:
placed_items[possible_level_locations.pop(random.randint(0, len(possible_level_locations) - 1))] = fragment
else:
pool.append(fragment)
# Level 9 junk fill
if world.multiworld.ExpandedPool[world.player] > 0:
if world.options.ExpandedPool > 0:
spots = random.sample(level_locations[8], len(level_locations[8]) // 2)
for spot in spots:
junk = random.choice(list(minor_items.keys()))
@ -142,7 +142,7 @@ def get_pool_core(world):
# Finish Pool
final_pool = basic_pool
if world.multiworld.ExpandedPool[world.player]:
if world.options.ExpandedPool:
final_pool = {
item: basic_pool.get(item, 0) + minor_items.get(item, 0) + take_any_items.get(item, 0)
for item in set(basic_pool) | set(minor_items) | set(take_any_items)

View File

@ -1,5 +1,6 @@
import typing
from Options import Option, DefaultOnToggle, Choice
from dataclasses import dataclass
from Options import Option, DefaultOnToggle, Choice, PerGameCommonOptions
class ExpandedPool(DefaultOnToggle):
@ -32,9 +33,8 @@ class StartingPosition(Choice):
option_dangerous = 2
option_very_dangerous = 3
tloz_options: typing.Dict[str, type(Option)] = {
"ExpandedPool": ExpandedPool,
"TriforceLocations": TriforceLocations,
"StartingPosition": StartingPosition
}
@dataclass
class TlozOptions(PerGameCommonOptions):
ExpandedPool: ExpandedPool
TriforceLocations: TriforceLocations
StartingPosition: StartingPosition

View File

@ -11,6 +11,7 @@ if TYPE_CHECKING:
def set_rules(tloz_world: "TLoZWorld"):
player = tloz_world.player
world = tloz_world.multiworld
options = tloz_world.options
# Boss events for a nicer spoiler log play through
for level in range(1, 9):
@ -23,7 +24,7 @@ def set_rules(tloz_world: "TLoZWorld"):
# No dungeons without weapons except for the dangerous weapon locations if we're dangerous, no unsafe dungeons
for i, level in enumerate(tloz_world.levels[1:10]):
for location in level.locations:
if world.StartingPosition[player] < StartingPosition.option_dangerous \
if options.StartingPosition < StartingPosition.option_dangerous \
or location.name not in dangerous_weapon_locations:
add_rule(world.get_location(location.name, player),
lambda state: state.has_group("weapons", player))
@ -66,7 +67,7 @@ def set_rules(tloz_world: "TLoZWorld"):
lambda state: state.has("Recorder", player))
add_rule(world.get_location("Level 7 Boss", player),
lambda state: state.has("Recorder", player))
if world.ExpandedPool[player]:
if options.ExpandedPool:
add_rule(world.get_location("Level 7 Key Drop (Stalfos)", player),
lambda state: state.has("Recorder", player))
add_rule(world.get_location("Level 7 Bomb Drop (Digdogger)", player),
@ -75,13 +76,13 @@ def set_rules(tloz_world: "TLoZWorld"):
lambda state: state.has("Recorder", player))
for location in food_locations:
if world.ExpandedPool[player] or "Drop" not in location:
if options.ExpandedPool or "Drop" not in location:
add_rule(world.get_location(location, player),
lambda state: state.has("Food", player))
add_rule(world.get_location("Level 8 Item (Magical Key)", player),
lambda state: state.has("Bow", player) and state.has_group("arrows", player))
if world.ExpandedPool[player]:
if options.ExpandedPool:
add_rule(world.get_location("Level 8 Bomb Drop (Darknuts North)", player),
lambda state: state.has("Bow", player) and state.has_group("arrows", player))
@ -106,13 +107,13 @@ def set_rules(tloz_world: "TLoZWorld"):
for location in stepladder_locations:
add_rule(world.get_location(location, player),
lambda state: state.has("Stepladder", player))
if world.ExpandedPool[player]:
if options.ExpandedPool:
for location in stepladder_locations_expanded:
add_rule(world.get_location(location, player),
lambda state: state.has("Stepladder", player))
# Don't allow Take Any Items until we can actually get in one
if world.ExpandedPool[player]:
if options.ExpandedPool:
add_rule(world.get_location("Take Any Item Left", player),
lambda state: state.has_group("candles", player) or
state.has("Raft", player))

View File

@ -13,7 +13,7 @@ from .ItemPool import generate_itempool, starting_weapons, dangerous_weapon_loca
from .Items import item_table, item_prices, item_game_ids
from .Locations import location_table, level_locations, major_locations, shop_locations, all_level_locations, \
standard_level_locations, shop_price_location_ids, secret_money_ids, location_ids, food_locations
from .Options import tloz_options
from .Options import TlozOptions
from .Rom import TLoZDeltaPatch, get_base_rom_path, first_quest_dungeon_items_early, first_quest_dungeon_items_late
from .Rules import set_rules
from worlds.AutoWorld import World, WebWorld
@ -63,7 +63,8 @@ class TLoZWorld(World):
This randomizer shuffles all the items in the game around, leading to a new adventure
every time.
"""
option_definitions = tloz_options
options_dataclass = TlozOptions
options = TlozOptions
settings: typing.ClassVar[TLoZSettings]
game = "The Legend of Zelda"
topology_present = False
@ -132,7 +133,7 @@ class TLoZWorld(World):
for i, level in enumerate(level_locations):
for location in level:
if self.multiworld.ExpandedPool[self.player] or "Drop" not in location:
if self.options.ExpandedPool or "Drop" not in location:
self.levels[i + 1].locations.append(
self.create_location(location, self.location_name_to_id[location], self.levels[i + 1]))
@ -144,7 +145,7 @@ class TLoZWorld(World):
self.levels[level].locations.append(boss_event)
for location in major_locations:
if self.multiworld.ExpandedPool[self.player] or "Take Any" not in location:
if self.options.ExpandedPool or "Take Any" not in location:
overworld.locations.append(
self.create_location(location, self.location_name_to_id[location], overworld))
@ -311,7 +312,7 @@ class TLoZWorld(World):
return self.multiworld.random.choice(self.filler_items)
def fill_slot_data(self) -> Dict[str, Any]:
if self.multiworld.ExpandedPool[self.player]:
if self.options.ExpandedPool:
take_any_left = self.multiworld.get_location("Take Any Item Left", self.player).item
take_any_middle = self.multiworld.get_location("Take Any Item Middle", self.player).item
take_any_right = self.multiworld.get_location("Take Any Item Right", self.player).item