-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path__init__.py
405 lines (343 loc) · 15.6 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
from .ItemPool import generate_item_pool, generate_start_inventory
from .PrimeUtils import setup_lib_path
setup_lib_path() # NOTE: This MUST be called before importing any other metroidprime modules (other than PrimeUtils)
# Setup local dependencies if running in an apworld
import typing
import os
from Options import NumericOption
from typing import Any, Dict, List, Optional, TextIO, Union, cast
from logging import info
from .data.RoomNames import RoomName
from .data.PhazonMines import PhazonMinesAreaData
from .data.PhendranaDrifts import PhendranaDriftsAreaData
from .data.MagmoorCaverns import MagmoorCavernsAreaData
from .data.ChozoRuins import ChozoRuinsAreaData
from .data.TallonOverworld import TallonOverworldAreaData
from .BlastShieldRando import (
WorldBlastShieldMapping,
apply_blast_shield_mapping,
get_world_blast_shield_mapping,
)
from .data.RoomData import AreaData
from .data.AreaNames import MetroidPrimeArea
from .DoorRando import (
WorldDoorColorMapping,
get_world_door_mapping,
remap_doors_to_power_beam_if_necessary,
)
from worlds.LauncherComponents import Component, SuffixIdentifier, Type, components, launch_subprocess # type: ignore
import settings
from worlds.AutoWorld import World, WebWorld
from .data.Transports import (
ELEVATOR_USEFUL_NAMES,
default_elevator_mappings,
get_random_elevator_mapping,
)
from .Config import make_config
from .Regions import create_regions
from .Locations import every_location
from .PrimeOptions import (
BlastShieldRandomization,
MetroidPrimeOptions,
prime_option_groups,
)
from .Items import (
MetroidPrimeItem,
SuitUpgrade,
artifact_table,
item_table,
)
from .data.StartRoomData import (
StartRoomData,
init_starting_beam,
init_starting_loadout,
init_starting_room_data,
)
from .Container import MetroidPrimeContainer
from BaseClasses import MultiWorld, Tutorial, ItemClassification
class MultiworldWithPassthrough(MultiWorld):
re_gen_passthrough: Dict[str, Dict[str, Any]] = {}
def run_client(*args: Any):
from .MetroidPrimeClient import launch
launch_subprocess(launch, name="MetroidPrimeClient")
components.append(
Component(
"Metroid Prime Client",
func=run_client,
component_type=Type.CLIENT,
file_identifier=SuffixIdentifier(".apmp1"),
)
)
class MetroidPrimeSettings(settings.Group):
class RomFile(settings.UserFilePath):
"""File name of the Metroid Prime ISO"""
description = "Metroid Prime GC ISO file"
copy_to = "Metroid_Prime.iso"
class RomStart(str):
"""
Set this to false to never autostart a rom (such as after patching),
Set it to true to have the operating system default program open the iso
Alternatively, set it to a path to a program to open the .iso file with (like Dolplhin)
"""
rom_file: RomFile = RomFile(RomFile.copy_to)
rom_start: typing.Union[RomStart, bool] = False
class MetroidPrimeWeb(WebWorld):
tutorials = [
Tutorial(
"Multiworld Setup Guide",
"A guide to setting up Metroid Prime for Archipelago",
"English",
"setup.md",
"setup/en",
["hesto2", "Electro15"],
)
]
option_groups = prime_option_groups
class MetroidPrimeWorld(World):
"""
Metroid Prime is a first-person action-adventure game originally for the Gamecube. Play as
the bounty hunter Samus Aran as she traverses the planet Tallon IV and uncovers the plans
of the Space Pirates.
"""
game = "Metroid Prime"
web = MetroidPrimeWeb()
required_client_version = (0, 5, 0)
options_dataclass = MetroidPrimeOptions
options: MetroidPrimeOptions # type: ignore
topology_present = True
item_name_to_id = {name: data.code for name, data in item_table.items()}
location_name_to_id = every_location
settings: MetroidPrimeSettings # type: ignore
item_name_groups = {"Artifacts": set(artifact_table.keys())}
starting_room_data: StartRoomData
prefilled_item_map: Dict[str, str] = {} # Dict of location name to item name
elevator_mapping: Dict[str, Dict[str, str]] = default_elevator_mappings
door_color_mapping: Optional[WorldDoorColorMapping] = None
blast_shield_mapping: Optional[WorldBlastShieldMapping] = None
game_region_data: Dict[MetroidPrimeArea, AreaData]
has_generated_bomb_doors: bool = False
def __init__(self, multiworld: MultiWorld, player: int):
super().__init__(multiworld, player)
self.game_region_data = {
MetroidPrimeArea.Tallon_Overworld: TallonOverworldAreaData(),
MetroidPrimeArea.Chozo_Ruins: ChozoRuinsAreaData(),
MetroidPrimeArea.Magmoor_Caverns: MagmoorCavernsAreaData(),
MetroidPrimeArea.Phendrana_Drifts: PhendranaDriftsAreaData(),
MetroidPrimeArea.Phazon_Mines: PhazonMinesAreaData(),
}
def get_filler_item_name(self) -> str:
return SuitUpgrade.Missile_Expansion.value
def init_tracker_data(self):
# Universal tracker stuff, shouldn't do anything in standard gen
tracker_multiworld = cast(MultiworldWithPassthrough, self.multiworld)
if self.game in tracker_multiworld.re_gen_passthrough:
info("Setting data for tracker")
passthrough = tracker_multiworld.re_gen_passthrough[self.game]
# Need to re initialize the game region data
self.game_region_data = {
MetroidPrimeArea.Tallon_Overworld: TallonOverworldAreaData(),
MetroidPrimeArea.Chozo_Ruins: ChozoRuinsAreaData(),
MetroidPrimeArea.Magmoor_Caverns: MagmoorCavernsAreaData(),
MetroidPrimeArea.Phendrana_Drifts: PhendranaDriftsAreaData(),
MetroidPrimeArea.Phazon_Mines: PhazonMinesAreaData(),
}
for key, value in passthrough.items():
option = getattr(self.options, key, None)
if option is not None:
# These get interpreted as lists but the tracker expects them to be sets
if key in [
"non_local_items",
"local_items",
"local_early_items",
"priority_locations",
"exclude_locations",
]:
option.value = set(value)
else:
option.value = value
def generate_early(self) -> None:
if hasattr(self.multiworld, "re_gen_passthrough"):
self.init_tracker_data()
# Select Start Room
init_starting_room_data(self)
# Randomize Door Colors
if self.options.door_color_mapping:
self.door_color_mapping = WorldDoorColorMapping.from_option_value(
self.options.door_color_mapping.value
)
elif self.options.door_color_randomization != "none":
self.door_color_mapping = get_world_door_mapping(self)
self.options.door_color_mapping.value = (
self.door_color_mapping.to_option_value()
)
init_starting_beam(self)
# Reconcile starting beam with door color mapping, if applicable
remap_doors_to_power_beam_if_necessary(self)
# Set starting loadout
init_starting_loadout(self)
# Randomize Blast Shields
if self.options.blast_shield_mapping:
self.blast_shield_mapping = WorldBlastShieldMapping.from_option_value(
self.options.blast_shield_mapping.value
)
elif (
cast(str, self.options.blast_shield_randomization.value)
!= BlastShieldRandomization.option_none
or self.options.locked_door_count > 0
):
self.blast_shield_mapping = get_world_blast_shield_mapping(self)
self.options.blast_shield_mapping.value = (
self.blast_shield_mapping.to_option_value()
)
if self.blast_shield_mapping:
apply_blast_shield_mapping(self)
# Randomize Elevators
if self.options.elevator_mapping:
self.elevator_mapping = self.options.elevator_mapping.value
elif self.options.elevator_randomization.value:
self.elevator_mapping = get_random_elevator_mapping(self)
self.options.elevator_mapping.value = self.elevator_mapping
# Init starting inventory
starting_items = generate_start_inventory(self)
for item in starting_items:
self.multiworld.push_precollected(
self.create_item(item, ItemClassification.progression)
)
def create_regions(self) -> None:
boss_selection = int(self.options.final_bosses)
create_regions(self, boss_selection)
def create_item(
self, name: str, override: Optional[ItemClassification] = None
) -> "MetroidPrimeItem":
createdthing = item_table[name]
if override:
return MetroidPrimeItem(name, override, createdthing.code, self.player)
return MetroidPrimeItem(
name, createdthing.classification, createdthing.code, self.player
)
def create_items(self) -> None:
item_pool = generate_item_pool(self)
self.multiworld.itempool += item_pool
def pre_fill(self) -> None:
for location_name, item_name in self.prefilled_item_map.items():
location = self.get_location(location_name)
item = self.create_item(item_name, ItemClassification.progression)
location.place_locked_item(item)
def set_rules(self) -> None:
self.multiworld.completion_condition[self.player] = lambda state: (
state.can_reach("Mission Complete", "Region", self.player)
)
def post_fill(self) -> None:
if self.options.artifact_hints.value:
start_hints: typing.Set[str] = self.options.start_hints.value
for i in artifact_table:
start_hints.add(i)
def generate_output(self, output_directory: str) -> None:
if self.options.randomize_suit_colors:
options: List[NumericOption] = [
self.options.power_suit_color,
self.options.varia_suit_color,
self.options.gravity_suit_color,
self.options.phazon_suit_color,
]
# Select a random valid suit color index
for option in options:
if option.value == 0:
option.value = self.random.randint(1, 35) * 10
import json
configjson = make_config(self)
configjsons = json.dumps(configjson, indent=4)
if os.environ.get("DEBUG") == "True":
with open("test_config.json", "w") as f:
f.write(configjsons)
options_dict: Dict[str, Union[int, str]] = {
"progressive_beam_upgrades": self.options.progressive_beam_upgrades.value,
"player_name": self.player_name,
}
options_json = json.dumps(options_dict, indent=4)
outfile_name = self.multiworld.get_out_file_name_base(self.player)
apmp1 = MetroidPrimeContainer(
configjsons,
options_json,
outfile_name,
output_directory,
player=self.player,
player_name=self.multiworld.get_player_name(self.player),
)
apmp1.write()
def fill_slot_data(self) -> Dict[str, Any]:
exclude_options = [
"fusion_suit",
"as_dict",
"artifact_hints",
"staggered_suit_damage",
"start_hints",
]
non_cosmetic_options = [
o
for o in dir(self.options)
if "suit_color" not in o
and o not in exclude_options
and not o.startswith("__")
]
slot_data: Dict[str, Any] = self.options.as_dict(*non_cosmetic_options)
return slot_data
# for the universal tracker, doesn't get called in standard gen
@staticmethod
def interpret_slot_data(slot_data: Dict[str, Any]) -> Dict[str, Any]:
# returning slot_data so it regens, giving it back in multiworld.re_gen_passthrough
info("Regenerating world for tracker")
return slot_data
def write_spoiler(self, spoiler_handle: TextIO):
player_name = self.multiworld.get_player_name(self.player)
if self.options.elevator_randomization:
spoiler_handle.write(f"\n\nElevator Mapping({player_name}):\n")
for area, mapping in self.elevator_mapping.items():
spoiler_handle.write(f"{area}:\n")
for source, target in mapping.items():
spoiler_handle.write(
f" {ELEVATOR_USEFUL_NAMES[source]} -> {ELEVATOR_USEFUL_NAMES[target]}\n"
)
if self.options.door_color_randomization == "regional":
assert self.door_color_mapping is not None
spoiler_handle.write(f"\n\nDoor Color Mapping({player_name}):\n")
for area, mapping in self.door_color_mapping.items():
spoiler_handle.write(f"{area}:\n")
for door, color in mapping.type_mapping.items():
spoiler_handle.write(f" {door} -> {color}\n")
elif self.options.door_color_randomization == "global":
assert self.door_color_mapping is not None
spoiler_handle.write(f"\n\nDoor Color Mapping({player_name}):\n")
for door, color in self.door_color_mapping[
MetroidPrimeArea.Tallon_Overworld.value
].type_mapping.items():
spoiler_handle.write(f" {door} -> {color}\n")
if (
cast(str, self.options.blast_shield_randomization.value)
!= BlastShieldRandomization.option_none
or self.options.locked_door_count > 0
):
assert self.blast_shield_mapping is not None
spoiler_handle.write(f"\n\nBlast Shield Mapping({player_name}):\n")
written_mappings: List[List[str]] = []
for area, mapping in self.blast_shield_mapping.items():
spoiler_handle.write(f"{area}:\n")
if len(mapping.type_mapping) == 0:
spoiler_handle.write(f" None\n")
for room, doors in mapping.type_mapping.items():
for door in doors.keys():
source_room = self.game_region_data[
MetroidPrimeArea(area)
].rooms[RoomName(room)]
# Use the door_data blast shield since it may have been overridden by the door on the other side
door_data = source_room.doors[door]
assert door_data.default_destination is not None
assert door_data.blast_shield is not None
destination = door_data.default_destination.value
# Don't double write mappings since each door is paired
if [destination, room] in written_mappings:
continue
spoiler_handle.write(
f" {room} <--> {destination}: {door_data.blast_shield.value}\n"
)
written_mappings.append([room, destination])