Skip to content

Commit

Permalink
Added a setting which allows players to provide a large champion pool…
Browse files Browse the repository at this point in the history
… and have generation choose a subset
  • Loading branch information
gaithern committed Feb 18, 2024
1 parent 20b9dcb commit c12a58a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
14 changes: 12 additions & 2 deletions worlds/lol/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RequiredLPPercentage(Range):

class Champions(OptionSet):
"""
Which champions are included in the item pool?
Which champions are possibly included in the item pool?
"""
display_name = "Champions"
valid_keys = [champions[champion_id]["name"] for champion_id in champions]
Expand Down Expand Up @@ -68,6 +68,15 @@ class StartingChampions(Range):
range_end = 5
display_name = "Starting Champions"

class ChampionSubsetCount(Range):
"""
Number of champions to randomly select for the item pool of those listed provided.
"""
default = 20
range_start = 1
range_end = 200
display_name = "Champion Subset Count"

@dataclass
class LOLOptions(PerGameCommonOptions):
champions: Champions
Expand All @@ -76,4 +85,5 @@ class LOLOptions(PerGameCommonOptions):
required_kills: RequiredKills
required_assists: RequiredAssists
required_lp: RequiredLPPercentage
starting_champions: StartingChampions
starting_champions: StartingChampions
champion_subset_count: ChampionSubsetCount
6 changes: 3 additions & 3 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, options):
def create_regions(multiworld: MultiWorld, player: int, options, possible_champions):
regions: Dict[str, LOLRegionData] = {
"Menu": LOLRegionData(None, ["Match"]),
"Match": LOLRegionData([], []),
Expand All @@ -20,7 +20,7 @@ def create_regions(multiworld: MultiWorld, player: int, options):

for champion_id in champions:
champion_name = champions[champion_id]["name"]
if champion_name in options.champions.value:
if champion_name in possible_champions:
regions["Match"].locations.append("Assist Taking Dragon as " + champion_name)
regions["Match"].locations.append("Assist Taking Rift Herald as " + champion_name)
regions["Match"].locations.append("Assist Taking Baron as " + champion_name)
Expand All @@ -32,7 +32,7 @@ def create_regions(multiworld: MultiWorld, player: int, options):
if "Support" not in champions[champion_id]["tags"]:
regions["Match"].locations.append("Get X Kills as " + champion_name)
regions["Match"].locations.append("Get X Creep Score as " + champion_name)
for i in range(min(options.starting_champions, len(options.champions.value))):
for i in range(min(options.starting_champions, len(possible_champions))):
regions["Match"].locations.append("Starting Champion " + str(i+1))

# Set up the regions correctly.
Expand Down
4 changes: 2 additions & 2 deletions worlds/lol/Rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def has_item(state: CollectionState, player: int, item) -> bool:
def has_at_least(state: CollectionState, player: int, item_name, item_qty_required) -> bool:
return state.count(item_name, player) >= item_qty_required

def set_rules(multiworld: MultiWorld, player: int, options, required_lp):
def set_rules(multiworld: MultiWorld, player: int, options, required_lp, possible_champions):
for champion_id in champions:
champion_name = champions[champion_id]["name"]
if champion_name in options.champions.value:
if champion_name in possible_champions:
multiworld.get_location("Assist Taking Dragon as " + champion_name, player).access_rule = lambda state, champion_name = champion_name: has_item(state, player, champion_name)
multiworld.get_location("Assist Taking Rift Herald as " + champion_name, player).access_rule = lambda state, champion_name = champion_name: has_item(state, player, champion_name)
multiworld.get_location("Assist Taking Baron as " + champion_name, player).access_rule = lambda state, champion_name = champion_name: has_item(state, player, champion_name)
Expand Down
29 changes: 18 additions & 11 deletions worlds/lol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from .Rules import set_rules
from .Data import champions
from worlds.LauncherComponents import Component, components, Type, launch_subprocess
import random



Expand Down Expand Up @@ -43,23 +42,20 @@ class LOLWorld(World):
required_client_version = (0, 3, 5)
web = LOLWeb()
added_lp = 0
possible_champions = []

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()}

def create_items(self):
item_pool: List[LOLItem] = []
possible_champions = []
for champion_id in champions:
champion_name = champions[champion_id]["name"]
if champion_name in self.options.champions.value:
possible_champions.append(champion_name)
starting_champions = random.sample(possible_champions, min(self.options.starting_champions, len(self.options.champions.value)))
self.choose_possible_champions()
starting_champions = self.random.sample(self.possible_champions, min(self.options.starting_champions, len(self.possible_champions)))
for i in range(len(starting_champions)):
self.multiworld.get_location("Starting Champion " + str(i+1), self.player).place_locked_item(self.create_item(starting_champions[i]))
total_locations = len(self.multiworld.get_unfilled_locations(self.player))
for name, data in item_table.items():
if name in possible_champions and name not in starting_champions:
if name in self.possible_champions and name not in starting_champions:
item_pool += [self.create_item(name) for _ in range(0, 1)]
while len(item_pool) < total_locations:
item_pool.append(self.create_item("LP"))
Expand All @@ -71,15 +67,26 @@ def create_item(self, name: str) -> LOLItem:
return LOLItem(name, data.classification, data.code, self.player)

def set_rules(self):
set_rules(self.multiworld, self.player, self.options, int(self.added_lp * (self.options.required_lp / 100)))
self.choose_possible_champions()
set_rules(self.multiworld, self.player, self.options, int(self.added_lp * (self.options.required_lp / 100)), self.possible_champions)

def create_regions(self):
create_regions(self.multiworld, self.player, self.options)
self.choose_possible_champions()
create_regions(self.multiworld, self.player, self.options, self.possible_champions)

def fill_slot_data(self) -> dict:
slot_data = {"Required CS": int(self.options.required_creep_score)
,"Required VS": int(self.options.required_vision_score)
,"Required Kills": int(self.options.required_kills)
,"Required Assists": int(self.options.required_assists)
,"Required LP": int(self.added_lp * (self.options.required_lp / 100))}
return slot_data
return slot_data

def choose_possible_champions(self):
if len(self.possible_champions) == 0:
for champion_id in champions:
champion_name = champions[champion_id]["name"]
if champion_name in self.options.champions.value:
self.possible_champions.append(champion_name)
if len(self.possible_champions) > self.options.champion_subset_count:
self.possible_champions = self.random.sample(self.possible_champions, self.options.champion_subset_count)

0 comments on commit c12a58a

Please sign in to comment.