diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-04-13 17:20:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-14 00:20:31 +0200 |
commit | 7a358cedc44c0892a4c369a4884a23a001535d63 (patch) | |
tree | 45e9c61d086702cc46f94986160c1ea8568f232a /rules.py | |
parent | 9c6e33c7869d28b8fa1b3349c9a59a40aa8c1526 (diff) | |
download | lingo-apworld-7a358cedc44c0892a4c369a4884a23a001535d63.tar.gz lingo-apworld-7a358cedc44c0892a4c369a4884a23a001535d63.tar.bz2 lingo-apworld-7a358cedc44c0892a4c369a4884a23a001535d63.zip |
Lingo: Remove unnecessary player_logic parameters (#3054)
A world's player_logic is accessible from the LingoWorld object, so it's not necessary to also pass the LingoPlayerLogic object through every function that uses both.
Diffstat (limited to 'rules.py')
-rw-r--r-- | rules.py | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/rules.py b/rules.py index 054c330..4e12938 100644 --- a/rules.py +++ b/rules.py | |||
@@ -2,61 +2,58 @@ from typing import TYPE_CHECKING | |||
2 | 2 | ||
3 | from BaseClasses import CollectionState | 3 | from BaseClasses import CollectionState |
4 | from .datatypes import RoomAndDoor | 4 | from .datatypes import RoomAndDoor |
5 | from .player_logic import AccessRequirements, LingoPlayerLogic, PlayerLocation | 5 | from .player_logic import AccessRequirements, PlayerLocation |
6 | from .static_logic import PROGRESSION_BY_ROOM, PROGRESSIVE_ITEMS | 6 | from .static_logic import PROGRESSION_BY_ROOM, PROGRESSIVE_ITEMS |
7 | 7 | ||
8 | if TYPE_CHECKING: | 8 | if TYPE_CHECKING: |
9 | from . import LingoWorld | 9 | from . import LingoWorld |
10 | 10 | ||
11 | 11 | ||
12 | def lingo_can_use_entrance(state: CollectionState, room: str, door: RoomAndDoor, world: "LingoWorld", | 12 | def lingo_can_use_entrance(state: CollectionState, room: str, door: RoomAndDoor, world: "LingoWorld"): |
13 | player_logic: LingoPlayerLogic): | ||
14 | if door is None: | 13 | if door is None: |
15 | return True | 14 | return True |
16 | 15 | ||
17 | effective_room = room if door.room is None else door.room | 16 | effective_room = room if door.room is None else door.room |
18 | return _lingo_can_open_door(state, effective_room, door.door, world, player_logic) | 17 | return _lingo_can_open_door(state, effective_room, door.door, world) |
19 | 18 | ||
20 | 19 | ||
21 | def lingo_can_use_location(state: CollectionState, location: PlayerLocation, world: "LingoWorld", | 20 | def lingo_can_use_location(state: CollectionState, location: PlayerLocation, world: "LingoWorld"): |
22 | player_logic: LingoPlayerLogic): | 21 | return _lingo_can_satisfy_requirements(state, location.access, world) |
23 | return _lingo_can_satisfy_requirements(state, location.access, world, player_logic) | ||
24 | 22 | ||
25 | 23 | ||
26 | def lingo_can_use_mastery_location(state: CollectionState, world: "LingoWorld", player_logic: LingoPlayerLogic): | 24 | def lingo_can_use_mastery_location(state: CollectionState, world: "LingoWorld"): |
27 | satisfied_count = 0 | 25 | satisfied_count = 0 |
28 | for access_req in player_logic.mastery_reqs: | 26 | for access_req in world.player_logic.mastery_reqs: |
29 | if _lingo_can_satisfy_requirements(state, access_req, world, player_logic): | 27 | if _lingo_can_satisfy_requirements(state, access_req, world): |
30 | satisfied_count += 1 | 28 | satisfied_count += 1 |
31 | return satisfied_count >= world.options.mastery_achievements.value | 29 | return satisfied_count >= world.options.mastery_achievements.value |
32 | 30 | ||
33 | 31 | ||
34 | def lingo_can_use_level_2_location(state: CollectionState, world: "LingoWorld", player_logic: LingoPlayerLogic): | 32 | def lingo_can_use_level_2_location(state: CollectionState, world: "LingoWorld"): |
35 | counted_panels = 0 | 33 | counted_panels = 0 |
36 | state.update_reachable_regions(world.player) | 34 | state.update_reachable_regions(world.player) |
37 | for region in state.reachable_regions[world.player]: | 35 | for region in state.reachable_regions[world.player]: |
38 | for access_req, panel_count in player_logic.counting_panel_reqs.get(region.name, []): | 36 | for access_req, panel_count in world.player_logic.counting_panel_reqs.get(region.name, []): |
39 | if _lingo_can_satisfy_requirements(state, access_req, world, player_logic): | 37 | if _lingo_can_satisfy_requirements(state, access_req, world): |
40 | counted_panels += panel_count | 38 | counted_panels += panel_count |
41 | if counted_panels >= world.options.level_2_requirement.value - 1: | 39 | if counted_panels >= world.options.level_2_requirement.value - 1: |
42 | return True | 40 | return True |
43 | # THE MASTER has to be handled separately, because it has special access rules. | 41 | # THE MASTER has to be handled separately, because it has special access rules. |
44 | if state.can_reach("Orange Tower Seventh Floor", "Region", world.player)\ | 42 | if state.can_reach("Orange Tower Seventh Floor", "Region", world.player)\ |
45 | and lingo_can_use_mastery_location(state, world, player_logic): | 43 | and lingo_can_use_mastery_location(state, world): |
46 | counted_panels += 1 | 44 | counted_panels += 1 |
47 | if counted_panels >= world.options.level_2_requirement.value - 1: | 45 | if counted_panels >= world.options.level_2_requirement.value - 1: |
48 | return True | 46 | return True |
49 | return False | 47 | return False |
50 | 48 | ||
51 | 49 | ||
52 | def _lingo_can_satisfy_requirements(state: CollectionState, access: AccessRequirements, world: "LingoWorld", | 50 | def _lingo_can_satisfy_requirements(state: CollectionState, access: AccessRequirements, world: "LingoWorld"): |
53 | player_logic: LingoPlayerLogic): | ||
54 | for req_room in access.rooms: | 51 | for req_room in access.rooms: |
55 | if not state.can_reach(req_room, "Region", world.player): | 52 | if not state.can_reach(req_room, "Region", world.player): |
56 | return False | 53 | return False |
57 | 54 | ||
58 | for req_door in access.doors: | 55 | for req_door in access.doors: |
59 | if not _lingo_can_open_door(state, req_door.room, req_door.door, world, player_logic): | 56 | if not _lingo_can_open_door(state, req_door.room, req_door.door, world): |
60 | return False | 57 | return False |
61 | 58 | ||
62 | if len(access.colors) > 0 and world.options.shuffle_colors: | 59 | if len(access.colors) > 0 and world.options.shuffle_colors: |
@@ -67,15 +64,14 @@ def _lingo_can_satisfy_requirements(state: CollectionState, access: AccessRequir | |||
67 | return True | 64 | return True |
68 | 65 | ||
69 | 66 | ||
70 | def _lingo_can_open_door(state: CollectionState, room: str, door: str, world: "LingoWorld", | 67 | def _lingo_can_open_door(state: CollectionState, room: str, door: str, world: "LingoWorld"): |
71 | player_logic: LingoPlayerLogic): | ||
72 | """ | 68 | """ |
73 | Determines whether a door can be opened | 69 | Determines whether a door can be opened |
74 | """ | 70 | """ |
75 | if door not in player_logic.item_by_door.get(room, {}): | 71 | if door not in world.player_logic.item_by_door.get(room, {}): |
76 | return _lingo_can_satisfy_requirements(state, player_logic.door_reqs[room][door], world, player_logic) | 72 | return _lingo_can_satisfy_requirements(state, world.player_logic.door_reqs[room][door], world) |
77 | 73 | ||
78 | item_name = player_logic.item_by_door[room][door] | 74 | item_name = world.player_logic.item_by_door[room][door] |
79 | if item_name in PROGRESSIVE_ITEMS: | 75 | if item_name in PROGRESSIVE_ITEMS: |
80 | progression = PROGRESSION_BY_ROOM[room][door] | 76 | progression = PROGRESSION_BY_ROOM[room][door] |
81 | return state.has(item_name, world.player, progression.index) | 77 | return state.has(item_name, world.player, progression.index) |
@@ -83,12 +79,12 @@ def _lingo_can_open_door(state: CollectionState, room: str, door: str, world: "L | |||
83 | return state.has(item_name, world.player) | 79 | return state.has(item_name, world.player) |
84 | 80 | ||
85 | 81 | ||
86 | def make_location_lambda(location: PlayerLocation, world: "LingoWorld", player_logic: LingoPlayerLogic): | 82 | def make_location_lambda(location: PlayerLocation, world: "LingoWorld"): |
87 | if location.name == player_logic.mastery_location: | 83 | if location.name == world.player_logic.mastery_location: |
88 | return lambda state: lingo_can_use_mastery_location(state, world, player_logic) | 84 | return lambda state: lingo_can_use_mastery_location(state, world) |
89 | 85 | ||
90 | if world.options.level_2_requirement > 1\ | 86 | if world.options.level_2_requirement > 1\ |
91 | and (location.name == "Second Room - ANOTHER TRY" or location.name == player_logic.level_2_location): | 87 | and (location.name == "Second Room - ANOTHER TRY" or location.name == world.player_logic.level_2_location): |
92 | return lambda state: lingo_can_use_level_2_location(state, world, player_logic) | 88 | return lambda state: lingo_can_use_level_2_location(state, world) |
93 | 89 | ||
94 | return lambda state: lingo_can_use_location(state, location, world, player_logic) | 90 | return lambda state: lingo_can_use_location(state, location, world) |