Skip to content

lufia2ac: improve performance of access rules #2456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions worlds/lufia2ac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from Options import PerGameCommonOptions
from Utils import __version__
from worlds.AutoWorld import WebWorld, World
from worlds.generic.Rules import add_rule, set_rule
from worlds.generic.Rules import add_rule, CollectionRule, set_rule
from .Client import L2ACSNIClient # noqa: F401
from .Items import ItemData, ItemType, l2ac_item_name_to_id, l2ac_item_table, L2ACItem, start_id as items_start_id
from .Locations import l2ac_location_name_to_id, L2ACLocation
Expand Down Expand Up @@ -117,6 +117,7 @@ def create_regions(self) -> None:
L2ACLocation(self.player, f"Chest access {i + 1}-{i + CHESTS_PER_SPHERE}", None, ancient_dungeon)
chest_access.place_locked_item(
L2ACItem("Progressive chest access", ItemClassification.progression, None, self.player))
chest_access.show_in_spoiler = False
ancient_dungeon.locations.append(chest_access)
for iris in self.item_name_groups["Iris treasures"]:
treasure_name: str = f"Iris treasure {self.item_name_to_id[iris] - self.item_name_to_id['Iris sword'] + 1}"
Expand Down Expand Up @@ -153,23 +154,23 @@ def create_items(self) -> None:
self.multiworld.itempool.append(self.create_item(item_name))

def set_rules(self) -> None:
for i in range(1, self.o.blue_chest_count):
if i % CHESTS_PER_SPHERE == 0:
set_rule(self.multiworld.get_location(f"Blue chest {i + 1}", self.player),
lambda state, j=i: state.has("Progressive chest access", self.player, j // CHESTS_PER_SPHERE))
set_rule(self.multiworld.get_location(f"Chest access {i + 1}-{i + CHESTS_PER_SPHERE}", self.player),
lambda state, j=i: state.can_reach(f"Blue chest {j}", "Location", self.player))
else:
set_rule(self.multiworld.get_location(f"Blue chest {i + 1}", self.player),
lambda state, j=i: state.can_reach(f"Blue chest {j}", "Location", self.player))

set_rule(self.multiworld.get_entrance("FinalFloorEntrance", self.player),
lambda state: state.can_reach(f"Blue chest {self.o.blue_chest_count}", "Location", self.player))
max_sphere: int = (self.o.blue_chest_count - 1) // CHESTS_PER_SPHERE + 1
rule_for_sphere: Dict[int, CollectionRule] = \
{sphere: lambda state, s=sphere: state.has("Progressive chest access", self.player, s - 1)
for sphere in range(2, max_sphere + 1)}

for i in range(CHESTS_PER_SPHERE * 2, self.o.blue_chest_count, CHESTS_PER_SPHERE):
set_rule(self.multiworld.get_location(f"Chest access {i + 1}-{i + CHESTS_PER_SPHERE}", self.player),
rule_for_sphere[i // CHESTS_PER_SPHERE])
for i in range(CHESTS_PER_SPHERE, self.o.blue_chest_count):
set_rule(self.multiworld.get_location(f"Blue chest {i + 1}", self.player),
rule_for_sphere[i // CHESTS_PER_SPHERE + 1])

set_rule(self.multiworld.get_entrance("FinalFloorEntrance", self.player), rule_for_sphere[max_sphere])
for i in range(9):
set_rule(self.multiworld.get_location(f"Iris treasure {i + 1}", self.player),
lambda state: state.can_reach(f"Blue chest {self.o.blue_chest_count}", "Location", self.player))
set_rule(self.multiworld.get_location("Boss", self.player),
lambda state: state.can_reach(f"Blue chest {self.o.blue_chest_count}", "Location", self.player))
set_rule(self.multiworld.get_location(f"Iris treasure {i + 1}", self.player), rule_for_sphere[max_sphere])
set_rule(self.multiworld.get_location("Boss", self.player), rule_for_sphere[max_sphere])

if self.o.shuffle_capsule_monsters:
add_rule(self.multiworld.get_location("Boss", self.player), lambda state: state.has("DARBI", self.player))
if self.o.shuffle_party_members:
Expand Down