diff options
Diffstat (limited to 'apworld/tracker.py')
-rw-r--r-- | apworld/tracker.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/apworld/tracker.py b/apworld/tracker.py new file mode 100644 index 0000000..721e9b3 --- /dev/null +++ b/apworld/tracker.py | |||
@@ -0,0 +1,67 @@ | |||
1 | from BaseClasses import MultiWorld, CollectionState, ItemClassification | ||
2 | from NetUtils import NetworkItem | ||
3 | from . import Lingo2World, Lingo2Item | ||
4 | from .regions import connect_ports_from_ut | ||
5 | from .options import Lingo2Options | ||
6 | |||
7 | PLAYER_NUM = 1 | ||
8 | |||
9 | |||
10 | class Tracker: | ||
11 | multiworld: MultiWorld | ||
12 | |||
13 | collected_items: dict[int, int] | ||
14 | checked_locations: set[int] | ||
15 | accessible_locations: set[int] | ||
16 | |||
17 | state: CollectionState | ||
18 | |||
19 | def __init__(self): | ||
20 | self.collected_items = {} | ||
21 | self.checked_locations = set() | ||
22 | self.accessible_locations = set() | ||
23 | |||
24 | def setup_slot(self, slot_data): | ||
25 | self.multiworld = MultiWorld(players=PLAYER_NUM) | ||
26 | world = Lingo2World(self.multiworld, PLAYER_NUM) | ||
27 | self.multiworld.worlds[1] = world | ||
28 | world.options = Lingo2Options(**{k: t(slot_data.get(k, t.default)) | ||
29 | for k, t in Lingo2Options.type_hints.items()}) | ||
30 | |||
31 | world.generate_early() | ||
32 | world.create_regions() | ||
33 | |||
34 | if world.options.shuffle_worldports: | ||
35 | port_pairings = {int(fp): int(tp) for fp, tp in slot_data["port_pairings"].items()} | ||
36 | connect_ports_from_ut(port_pairings, world) | ||
37 | |||
38 | self.state = CollectionState(self.multiworld) | ||
39 | |||
40 | def set_checked_locations(self, checked_locations: set[int]): | ||
41 | self.checked_locations = checked_locations.copy() | ||
42 | |||
43 | def set_collected_items(self, network_items: list[NetworkItem]): | ||
44 | self.collected_items = {} | ||
45 | |||
46 | for item in network_items: | ||
47 | self.collected_items[item.item] = self.collected_items.get(item.item, 0) + 1 | ||
48 | |||
49 | self.refresh_state() | ||
50 | |||
51 | def refresh_state(self): | ||
52 | self.state = CollectionState(self.multiworld) | ||
53 | |||
54 | for item_id, item_amount in self.collected_items.items(): | ||
55 | for i in range(item_amount): | ||
56 | self.state.collect(Lingo2Item(Lingo2World.static_logic.item_id_to_name.get(item_id), | ||
57 | ItemClassification.progression, item_id, PLAYER_NUM), prevent_sweep=True) | ||
58 | |||
59 | self.state.sweep_for_advancements() | ||
60 | |||
61 | self.accessible_locations = set() | ||
62 | |||
63 | for region in self.state.reachable_regions[PLAYER_NUM]: | ||
64 | for location in region.locations: | ||
65 | if location.address not in self.checked_locations and location.access_rule(self.state): | ||
66 | if location.address is not None: | ||
67 | self.accessible_locations.add(location.address) | ||