1
1
from argparse import Namespace
2
2
from typing import List , Optional , Tuple , Type , Union
3
3
4
- from BaseClasses import CollectionState , MultiWorld
4
+ from BaseClasses import CollectionState , Item , ItemClassification , Location , MultiWorld , Region
5
5
from worlds .AutoWorld import World , call_all
6
6
7
7
gen_steps = ("generate_early" , "create_regions" , "create_items" , "set_rules" , "generate_basic" , "pre_fill" )
@@ -17,19 +17,21 @@ def setup_solo_multiworld(
17
17
:param steps: The gen steps that should be called on the generated multiworld before returning. Default calls
18
18
steps through pre_fill
19
19
:param seed: The seed to be used when creating this multiworld
20
+ :return: The generated multiworld
20
21
"""
21
22
return setup_multiworld (world_type , steps , seed )
22
23
23
24
24
25
def setup_multiworld (worlds : Union [List [Type [World ]], Type [World ]], steps : Tuple [str , ...] = gen_steps ,
25
- seed : Optional [int ] = None ) -> MultiWorld :
26
+ seed : Optional [int ] = None ) -> MultiWorld :
26
27
"""
27
28
Creates a multiworld with a player for each provided world type, allowing duplicates, setting default options, and
28
29
calling the provided gen steps.
29
30
30
- :param worlds: type /s of worlds to generate a multiworld for
31
- :param steps: gen steps that should be called before returning. Default calls through pre_fill
31
+ :param worlds: Type /s of worlds to generate a multiworld for
32
+ :param steps: Gen steps that should be called before returning. Default calls through pre_fill
32
33
:param seed: The seed to be used when creating this multiworld
34
+ :return: The generated multiworld
33
35
"""
34
36
if not isinstance (worlds , list ):
35
37
worlds = [worlds ]
@@ -49,3 +51,59 @@ def setup_multiworld(worlds: Union[List[Type[World]], Type[World]], steps: Tuple
49
51
for step in steps :
50
52
call_all (multiworld , step )
51
53
return multiworld
54
+
55
+
56
+ class TestWorld (World ):
57
+ game = f"Test Game"
58
+ item_name_to_id = {}
59
+ location_name_to_id = {}
60
+ hidden = True
61
+
62
+
63
+ def generate_test_multiworld (players : int = 1 ) -> MultiWorld :
64
+ """
65
+ Generates a multiworld using a special Test Case World class, and seed of 0.
66
+
67
+ :param players: Number of players to generate the multiworld for
68
+ :return: The generated test multiworld
69
+ """
70
+ multiworld = setup_multiworld ([TestWorld ] * players , seed = 0 )
71
+ multiworld .regions += [Region ("Menu" , player_id + 1 , multiworld ) for player_id in range (players )]
72
+
73
+ return multiworld
74
+
75
+
76
+ def generate_locations (count : int , player_id : int , region : Region , address : Optional [int ] = None ,
77
+ tag : str = "" ) -> List [Location ]:
78
+ """
79
+ Generates the specified amount of locations for the player and adds them to the specified region.
80
+
81
+ :param count: Number of locations to create
82
+ :param player_id: ID of the player to create the locations for
83
+ :param address: Address for the specified locations. They will all share the same address if multiple are created
84
+ :param region: Parent region to add these locations to
85
+ :param tag: Tag to add to the name of the generated locations
86
+ :return: List containing the created locations
87
+ """
88
+ prefix = f"player{ player_id } { tag } _location"
89
+
90
+ locations = [Location (player_id , f"{ prefix } { i } " , address , region ) for i in range (count )]
91
+ region .locations += locations
92
+ return locations
93
+
94
+
95
+ def generate_items (count : int , player_id : int , advancement : bool = False , code : int = None ) -> List [Item ]:
96
+ """
97
+ Generates the specified amount of items for the target player.
98
+
99
+ :param count: The amount of items to create
100
+ :param player_id: ID of the player to create the items for
101
+ :param advancement: Whether the created items should be advancement
102
+ :param code: The code the items should be created with
103
+ :return: List containing the created items
104
+ """
105
+ item_type = "prog" if advancement else ""
106
+ classification = ItemClassification .progression if advancement else ItemClassification .filler
107
+
108
+ items = [Item (f"player{ player_id } _{ item_type } item{ i } " , classification , code , player_id ) for i in range (count )]
109
+ return items
0 commit comments