Skip to content

Commit

Permalink
Allow the player to limit the number of items in their world
Browse files Browse the repository at this point in the history
  • Loading branch information
gaithern committed Dec 19, 2023
1 parent 2b9508b commit c5db479
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
12 changes: 11 additions & 1 deletion worlds/lol/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ class GameMode(Choice):
option_arena = 2
default = 0

class ItemNumber(Range):
"""
How many items/locations should be included in the pool?
"""
default = 30
range_start = 10
range_end = 60
display_name = "Number of Items"

lol_options: Dict[str, type(Option)] = {
"game_mode": GameMode
"game_mode": GameMode,
"item_num": ItemNumber,
}
11 changes: 7 additions & 4 deletions worlds/lol/Regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LOLRegionData(NamedTuple):
region_exits: Optional[List[str]]


def create_regions(multiworld: MultiWorld, player: int, game_mode: str):
def create_regions(multiworld: MultiWorld, player: int, game_mode: str, items: list[str]):
regions: Dict[str, LOLRegionData] = {
"Menu": LOLRegionData(None, ["Match"]),
"Match": LOLRegionData([], []),
Expand All @@ -20,13 +20,16 @@ def create_regions(multiworld: MultiWorld, player: int, game_mode: str):

if game_mode == "GameMode(Summoners Rift)":
for item_id in sr_items:
regions["Match"].locations.append("Win Summoners Rift with " + str(sr_items[item_id]))
if "SR " + str(sr_items[item_id]) in items or len(items) == 0:
regions["Match"].locations.append("Win Summoners Rift with " + str(sr_items[item_id]))
if game_mode == "GameMode(Aram)":
for item_id in aram_items:
regions["Match"].locations.append("Win ARAM with " + str(aram_items[item_id]))
if "ARAM " + str(aram_items[item_id]) in items or len(items) == 0:
regions["Match"].locations.append("Win ARAM with " + str(aram_items[item_id]))
if game_mode == "GameMode(Arena)":
for item_id in arena_items:
regions["Match"].locations.append("Win Arena with " + str(arena_items[item_id]))
if "ARENA " + str(arena_items[item_id]) in items or len(items) == 0:
regions["Match"].locations.append("Win Arena with " + str(arena_items[item_id]))
regions["Match"].locations.append("Starting Item 1")
regions["Match"].locations.append("Starting Item 2")
regions["Match"].locations.append("Starting Item 3")
Expand Down
11 changes: 7 additions & 4 deletions worlds/lol/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
def has_item(state: CollectionState, player: int, item) -> bool:
return state.has(item, player)

def set_rules(multiworld: MultiWorld, player: int, game_mode: str):
def set_rules(multiworld: MultiWorld, player: int, game_mode: str, items: list[str]):
if game_mode == "GameMode(Summoners Rift)":
for item_id in sr_items:
multiworld.get_location("Win Summoners Rift with " + str(sr_items[item_id]), player).access_rule = lambda state: has_item(state, player, "SR " + sr_items[item_id])
if str(sr_items[item_id]) in items or len(items) == 0:
multiworld.get_location("Win Summoners Rift with " + str(sr_items[item_id]), player).access_rule = lambda state: has_item(state, player, "SR " + sr_items[item_id])
if game_mode == "GameMode(Aram)":
for item_id in aram_items:
multiworld.get_location("Win ARAM with " + str(aram_items[item_id]), player).access_rule = lambda state: has_item(state, player, "ARAM " + aram_items[item_id])
if str(aram_items[item_id]) in items or len(items) == 0:
multiworld.get_location("Win ARAM with " + str(aram_items[item_id]), player).access_rule = lambda state: has_item(state, player, "ARAM " + aram_items[item_id])
if game_mode == "GameMode(Arena)":
for item_id in arena_items:
multiworld.get_location("Win Arena with " + str(arena_items[item_id]), player).access_rule = lambda state: has_item(state, player, "ARENA " + arena_items[item_id])
if str(arena_items[item_id]) in items or len(items) == 0:
multiworld.get_location("Win Arena with " + str(arena_items[item_id]), player).access_rule = lambda state: has_item(state, player, "ARENA " + arena_items[item_id])

# Win condition.
multiworld.completion_condition[player] = lambda state: state.has_all({"Bronze Rank", "Silver Rank", "Gold Rank", "Platinum Rank", "Emerald Rank", "Diamond Rank"}, player)
20 changes: 13 additions & 7 deletions worlds/lol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class LOLWorld(World):
data_version = 4
required_client_version = (0, 3, 5)
web = LOLWeb()
game_item_table = []

item_name_to_id = {name: data.code for name, data in item_table.items()}
location_name_to_id = {name: data.code for name, data in location_table.items()}
Expand All @@ -53,12 +54,10 @@ def fill_slot_data(self) -> dict:
return {option_name: self.get_setting(option_name).value for option_name in lol_options}

def create_items(self):
self.set_item_table()
item_pool: List[LOLItem] = []
game_item_table = get_items_by_category(str(self.get_setting("game_mode")), [])
game_item_table.update(get_items_by_category("Victory", []))
for name in game_item_table.keys():
quantity = 1
item_pool += [self.create_item(name) for _ in range(0, quantity)]
for name in self.game_item_table:
item_pool += [self.create_item(name) for _ in range(0, 1)]

self.multiworld.itempool += item_pool

Expand All @@ -78,7 +77,14 @@ def create_event(self, name: str) -> LOLItem:
return LOLItem(name, data.classification, data.code, self.player)

def set_rules(self):
set_rules(self.multiworld, self.player, str(self.get_setting("game_mode")))
set_rules(self.multiworld, self.player, str(self.get_setting("game_mode")), self.game_item_table)

def create_regions(self):
create_regions(self.multiworld, self.player, str(self.get_setting("game_mode")))
self.set_item_table()
create_regions(self.multiworld, self.player, str(self.get_setting("game_mode")), self.game_item_table)

def set_item_table(self):
if len(self.game_item_table) == 0:
self.game_item_table = get_items_by_category(str(self.get_setting("game_mode")), []).keys()
self.game_item_table = random.sample(self.game_item_table, int(self.get_setting("item_num")))
self.game_item_table = self.game_item_table + list(get_items_by_category("Victory", []).keys())

0 comments on commit c5db479

Please sign in to comment.