Skip to content

Commit

Permalink
Added multiple game mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
gaithern committed Dec 17, 2023
1 parent 16a63e3 commit fc4bb7f
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 50 deletions.
8 changes: 4 additions & 4 deletions worlds/lol/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_collected_item_ids():
return item_ids

def send_check(item_id):
with open(os.path.join(game_communication_path, "send" + str(5660000 + int(item_id))), 'w') as f:
with open(os.path.join(game_communication_path, "send" + str(566000000 + int(item_id))), 'w') as f:
f.close()

def send_victory():
Expand Down Expand Up @@ -141,7 +141,7 @@ def _cmd_check_last_match(self):
if won_match(self.player_puuid, last_match_info):
item_ids_purchased = get_item_ids_purchased(self.player_puuid, last_match_info)
for item_id in item_ids_purchased:
if int(item_id) + 5650000 in unlocked_item_ids:
if int(item_id) + 565000000 in unlocked_item_ids:
new_locations.append(int(item_id))
else:
self.output(f"Last Match Resulted in a Loss...")
Expand All @@ -157,14 +157,14 @@ def _cmd_check_last_match(self):

def _cmd_receive_starting_items(self):
"""When you're ready to start your run, this receives your starting items"""
starting_location_ids = [566_0001, 566_0002, 566_0003, 566_0004, 566_0005, 566_0006]
starting_location_ids = [566_000001, 566_000002, 566_000003, 566_000004, 566_000005, 566_000006]
for location_id in starting_location_ids:
with open(os.path.join(game_communication_path, "send" + str(location_id)), 'w') as f:
f.close()
self.output("Items Received")

def _cmd_check_for_victory(self):
victory_item_ids = [5650001, 5650002, 5650003, 5650004, 5650005, 5650006]
victory_item_ids = [565000001, 565000002, 565000003, 565000004, 565000005, 565000006]
victory_items_collected = 0
item_ids = get_collected_item_ids()
for item_id in item_ids:
Expand Down
20 changes: 15 additions & 5 deletions worlds/lol/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
maps_url = "https://static.developer.riotgames.com/docs/lol/maps.json"
most_recent_version = requests.get(versions_url).json()[0]
items_url = "https://ddragon.leagueoflegends.com/cdn/" + str(most_recent_version) + "/data/en_US/item.json"
items = {}
sr_items = {}
aram_items = {}
arena_items = {}
for map in requests.get(maps_url).json():
if map["mapName"] == "Summoner's Rift" and map["notes"] == "Current Version":
map_id = map["mapId"]
sr_map_id = map["mapId"]
if map["mapName"] == "Howling Abyss":
aram_map_id = map["mapId"]
if map["mapName"] == "Rings of Wrath":
arena_map_id = map["mapId"]

item_data = requests.get(items_url).json()["data"]
for item_id in item_data.keys():
if "into" not in item_data[item_id].keys() and item_data[item_id]["maps"][str(map_id)] and item_data[item_id]["gold"]["purchasable"] and item_data[item_id]["gold"]["total"] > 1000:
items[item_id] = item_data[item_id]["name"]

if "into" not in item_data[item_id].keys() and item_data[item_id]["gold"]["purchasable"] and item_data[item_id]["gold"]["total"] > 1000:
if item_data[item_id]["maps"][str(sr_map_id)]:
sr_items[item_id] = item_data[item_id]["name"]
if item_data[item_id]["maps"][str(aram_map_id)]:
aram_items[item_id] = item_data[item_id]["name"]
if item_data[item_id]["maps"][str(arena_map_id)]:
arena_items[item_id] = item_data[item_id]["name"]
22 changes: 13 additions & 9 deletions worlds/lol/Items.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Dict, NamedTuple, Optional
from .Data import items
from .Data import sr_items, aram_items, arena_items

from BaseClasses import Item, ItemClassification

Expand Down Expand Up @@ -27,14 +27,18 @@ def get_items_by_category(category: str, disclude: list) -> Dict[str, LOLItemDat


item_table: Dict[str, LOLItemData] = {}
for item_id in items:
item_table[items[item_id]] = LOLItemData("Item", code = 565_0000 + int(item_id), classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Bronze Rank"] = LOLItemData("Item", code = 565_0001, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Silver Rank"] = LOLItemData("Item", code = 565_0002, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Gold Rank"] = LOLItemData("Item", code = 565_0003, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Platinum Rank"] = LOLItemData("Item", code = 565_0004, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Emerald Rank"] = LOLItemData("Item", code = 565_0005, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Diamond Rank"] = LOLItemData("Item", code = 565_0006, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
for item_id in sr_items:
item_table["SR " + sr_items[item_id]] = LOLItemData("GameMode(Summoners Rift)", code = 565_000000 + int(item_id), classification = ItemClassification.progression, max_quantity = 1, weight = 1)
for item_id in aram_items:
item_table["ARAM " + aram_items[item_id]] = LOLItemData("GameMode(Aram)", code = 565_000000 + int(item_id), classification = ItemClassification.progression, max_quantity = 1, weight = 1)
for item_id in arena_items:
item_table["ARENA " + arena_items[item_id]] = LOLItemData("GameMode(Arena)", code = 565_000000 + int(item_id), classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Bronze Rank"] = LOLItemData("Victory", code = 565_000001, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Silver Rank"] = LOLItemData("Victory", code = 565_000002, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Gold Rank"] = LOLItemData("Victory", code = 565_000003, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Platinum Rank"] = LOLItemData("Victory", code = 565_000004, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Emerald Rank"] = LOLItemData("Victory", code = 565_000005, classification = ItemClassification.progression, max_quantity = 1, weight = 1)
item_table["Diamond Rank"] = LOLItemData("Victory", code = 565_000006, classification = ItemClassification.progression, max_quantity = 1, weight = 1)


event_item_table: Dict[str, LOLItemData] = {
Expand Down
22 changes: 13 additions & 9 deletions worlds/lol/Locations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Dict, NamedTuple, Optional
from .Data import items
from .Data import sr_items, aram_items, arena_items
import typing


Expand All @@ -25,14 +25,18 @@ def get_locations_by_category(category: str) -> Dict[str, LOLLocationData]:


location_table: Dict[str, LOLLocationData] = {}
for item_id in items:
location_table["Win with " + str(items[item_id])] = LOLLocationData("Progression", 566_0000 + int(item_id))
location_table["Starting Item 1"] = LOLLocationData("Starting" , 566_0001)
location_table["Starting Item 2"] = LOLLocationData("Starting" , 566_0002)
location_table["Starting Item 3"] = LOLLocationData("Starting" , 566_0003)
location_table["Starting Item 4"] = LOLLocationData("Starting" , 566_0004)
location_table["Starting Item 5"] = LOLLocationData("Starting" , 566_0005)
location_table["Starting Item 6"] = LOLLocationData("Starting" , 566_0006)
for item_id in sr_items:
location_table["Win Summoners Rift with " + str(sr_items[item_id])] = LOLLocationData("GameMode(Summoners Rift)", 566_000000 + int(item_id))
for item_id in aram_items:
location_table["Win ARAM with " + str(aram_items[item_id])] = LOLLocationData("GameMode(Aram)", 566_000000 + int(item_id))
for item_id in arena_items:
location_table["Win Arena with " + str(arena_items[item_id])] = LOLLocationData("GameMode(Arena)", 566_000000 + int(item_id))
location_table["Starting Item 1"] = LOLLocationData("Starting" , 566_000001)
location_table["Starting Item 2"] = LOLLocationData("Starting" , 566_000002)
location_table["Starting Item 3"] = LOLLocationData("Starting" , 566_000003)
location_table["Starting Item 4"] = LOLLocationData("Starting" , 566_000004)
location_table["Starting Item 5"] = LOLLocationData("Starting" , 566_000005)
location_table["Starting Item 6"] = LOLLocationData("Starting" , 566_000006)

event_location_table: Dict[str, LOLLocationData] = {
}
Expand Down
14 changes: 13 additions & 1 deletion worlds/lol/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@

from Options import Choice, Range, Option, Toggle, DeathLink, DefaultOnToggle, OptionSet

lol_options: Dict[str, type(Option)] = {}
class GameMode(Choice):
"""
Select game mode to base items/location on.
"""
display_name = "Game Mode"
option_summoners_rift = 0
option_aram = 1
option_arena = 2
default = 0

lol_options: Dict[str, type(Option)] = {
"game_mode": GameMode
}
35 changes: 21 additions & 14 deletions worlds/lol/Regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,43 @@

from BaseClasses import MultiWorld, Region, Entrance
from .Locations import LOLLocation, location_table, get_locations_by_category
from .Data import items
from .Data import sr_items, aram_items, arena_items


class LOLRegionData(NamedTuple):
locations: Optional[List[str]]
region_exits: Optional[List[str]]


def create_regions(multiworld: MultiWorld, player: int):
def create_regions(multiworld: MultiWorld, player: int, game_mode: str):
regions: Dict[str, LOLRegionData] = {
"Menu": LOLRegionData(None, ["Summoner's Rift"]),
"Summoner's Rift": LOLRegionData([], []),
"Menu": LOLRegionData(None, ["Match"]),
"Match": LOLRegionData([], []),
}

# Set up locations

for item_id in items:
regions["Summoner's Rift"].locations.append("Win with " + str(items[item_id]))
regions["Summoner's Rift"].locations.append("Starting Item 1")
regions["Summoner's Rift"].locations.append("Starting Item 2")
regions["Summoner's Rift"].locations.append("Starting Item 3")
regions["Summoner's Rift"].locations.append("Starting Item 4")
regions["Summoner's Rift"].locations.append("Starting Item 5")
regions["Summoner's Rift"].locations.append("Starting Item 6")

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 game_mode == "GameMode(Aram)":
for item_id in aram_items:
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]))
regions["Match"].locations.append("Starting Item 1")
regions["Match"].locations.append("Starting Item 2")
regions["Match"].locations.append("Starting Item 3")
regions["Match"].locations.append("Starting Item 4")
regions["Match"].locations.append("Starting Item 5")
regions["Match"].locations.append("Starting Item 6")

# Set up the regions correctly.
for name, data in regions.items():
multiworld.regions.append(create_region(multiworld, player, name, data))

multiworld.get_entrance("Summoner's Rift", player).connect(multiworld.get_region("Summoner's Rift", player))
multiworld.get_entrance("Match", player).connect(multiworld.get_region("Match", player))


def create_region(multiworld: MultiWorld, player: int, name: str, data: LOLRegionData):
Expand Down
15 changes: 11 additions & 4 deletions worlds/lol/Rules.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
from BaseClasses import CollectionState, MultiWorld, LocationProgressType
from .Locations import get_locations_by_category
from .Data import items
from .Data import sr_items, aram_items, arena_items

def has_item(state: CollectionState, player: int, item) -> bool:
return state.has(item, player)

def set_rules(multiworld: MultiWorld, player: int):
for item_id in items:
multiworld.get_location("Win with " + str(items[item_id]), player).access_rule = lambda state: has_item(state, player, items[item_id])
def set_rules(multiworld: MultiWorld, player: int, game_mode: 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 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 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])

# Win condition.
multiworld.completion_condition[player] = lambda state: state.has_all({"Bronze Rank", "Silver Rank", "Gold Rank", "Platinum Rank", "Emerald Rank", "Diamond Rank"}, player)
10 changes: 6 additions & 4 deletions worlds/lol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ def fill_slot_data(self) -> dict:
def create_items(self):
item_pool: List[LOLItem] = []

for name, data in item_table.items():
quantity = data.max_quantity
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)]

self.multiworld.itempool += item_pool
Expand All @@ -77,7 +79,7 @@ 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)
set_rules(self.multiworld, self.player, str(self.get_setting("game_mode")))

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

0 comments on commit fc4bb7f

Please sign in to comment.