Skip to content

Commit

Permalink
Merge branch 'main' into smw-main
Browse files Browse the repository at this point in the history
  • Loading branch information
PoryGone committed Dec 11, 2022
2 parents a161083 + 2cdd03f commit 7f4eb70
Show file tree
Hide file tree
Showing 94 changed files with 5,510 additions and 2,106 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Output Logs/
/freeze_requirements.txt
/Archipelago.zip
/setup.ini

/installdelete.iss

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
24 changes: 16 additions & 8 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Group(TypedDict, total=False):
replacement_items: Dict[int, Optional[str]]
local_items: Set[str]
non_local_items: Set[str]
link_replacement: bool


class MultiWorld():
Expand Down Expand Up @@ -222,27 +223,32 @@ def set_options(self, args: Namespace) -> None:

def set_item_links(self):
item_links = {}

replacement_prio = [False, True, None]
for player in self.player_ids:
for item_link in self.item_links[player].value:
if item_link["name"] in item_links:
if item_links[item_link["name"]]["game"] != self.game[player]:
raise Exception(f"Cannot ItemLink across games. Link: {item_link['name']}")
item_links[item_link["name"]]["players"][player] = item_link["replacement_item"]
item_links[item_link["name"]]["item_pool"] &= set(item_link["item_pool"])
item_links[item_link["name"]]["exclude"] |= set(item_link.get("exclude", []))
item_links[item_link["name"]]["local_items"] &= set(item_link.get("local_items", []))
item_links[item_link["name"]]["non_local_items"] &= set(item_link.get("non_local_items", []))
current_link = item_links[item_link["name"]]
current_link["players"][player] = item_link["replacement_item"]
current_link["item_pool"] &= set(item_link["item_pool"])
current_link["exclude"] |= set(item_link.get("exclude", []))
current_link["local_items"] &= set(item_link.get("local_items", []))
current_link["non_local_items"] &= set(item_link.get("non_local_items", []))
current_link["link_replacement"] = min(current_link["link_replacement"],
replacement_prio.index(item_link["link_replacement"]))
else:
if item_link["name"] in self.player_name.values():
raise Exception(f"Cannot name a ItemLink group the same as a player ({item_link['name']}) ({self.get_player_name(player)}).")
raise Exception(f"Cannot name a ItemLink group the same as a player ({item_link['name']}) "
f"({self.get_player_name(player)}).")
item_links[item_link["name"]] = {
"players": {player: item_link["replacement_item"]},
"item_pool": set(item_link["item_pool"]),
"exclude": set(item_link.get("exclude", [])),
"game": self.game[player],
"local_items": set(item_link.get("local_items", [])),
"non_local_items": set(item_link.get("non_local_items", []))
"non_local_items": set(item_link.get("non_local_items", [])),
"link_replacement": replacement_prio.index(item_link["link_replacement"]),
}

for name, item_link in item_links.items():
Expand All @@ -267,10 +273,12 @@ def set_item_links(self):
for group_name, item_link in item_links.items():
game = item_link["game"]
group_id, group = self.add_group(group_name, game, set(item_link["players"]))

group["item_pool"] = item_link["item_pool"]
group["replacement_items"] = item_link["players"]
group["local_items"] = item_link["local_items"]
group["non_local_items"] = item_link["non_local_items"]
group["link_replacement"] = replacement_prio[item_link["link_replacement"]]

# intended for unittests
def set_default_common_options(self):
Expand Down
6 changes: 4 additions & 2 deletions CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class CommonContext:
tags: typing.Set[str] = {"AP"}
game: typing.Optional[str] = None
items_handling: typing.Optional[int] = None
want_slot_data: bool = True # should slot_data be retrieved via Connect

# datapackage
# Contents in flux until connection to server is made, to download correct data for this multiworld.
Expand Down Expand Up @@ -309,7 +310,7 @@ async def send_connect(self, **kwargs: typing.Any) -> None:
'cmd': 'Connect',
'password': self.password, 'name': self.auth, 'version': Utils.version_tuple,
'tags': self.tags, 'items_handling': self.items_handling,
'uuid': Utils.get_unique_identifier(), 'game': self.game
'uuid': Utils.get_unique_identifier(), 'game': self.game, "slot_data": self.want_slot_data,
}
if kwargs:
payload.update(kwargs)
Expand Down Expand Up @@ -798,9 +799,10 @@ def get_base_parser(description: typing.Optional[str] = None):
# Text Mode to use !hint and such with games that have no text entry

class TextContext(CommonContext):
tags = {"AP", "IgnoreGame", "TextOnly"}
tags = {"AP", "TextOnly"}
game = "" # empty matches any game since 0.3.2
items_handling = 0b111 # receive all items for /received
want_slot_data = False # Can't use game specific slot_data

async def server_auth(self, password_requested: bool = False):
if password_requested and not self.password:
Expand Down
3 changes: 2 additions & 1 deletion Generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ def roll_settings(weights: dict, plando_options: PlandoSettings = PlandoSettings
handle_option(ret, game_weights, option_key, option, plando_options)
for option_key, option in Options.per_game_common_options.items():
# skip setting this option if already set from common_options, defaulting to root option
if not (option_key in Options.common_options and option_key not in game_weights):
if option_key not in world_type.option_definitions and \
(option_key not in Options.common_options or option_key in game_weights):
handle_option(ret, game_weights, option_key, option, plando_options)
if PlandoSettings.items in plando_options:
ret.plando_items = game_weights.get("plando_items", [])
Expand Down
26 changes: 17 additions & 9 deletions Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import Dict, List, Tuple, Optional, Set

from BaseClasses import Item, MultiWorld, CollectionState, Region, RegionType, LocationProgressType, Location
from worlds.alttp.Items import item_name_groups
import worlds
from worlds.alttp.Regions import is_main_entrance
from Fill import distribute_items_restrictive, flood_items, balance_multiworld_progression, distribute_planned
from worlds.alttp.Shops import SHOP_ID_START, total_shop_slots, FillDisabledShopSlots
Expand Down Expand Up @@ -210,11 +210,15 @@ def find_common_pool(players: Set[int], shared_pool: Set[str]) -> Tuple[
while itemcount > len(world.itempool):
items_to_add = []
for player in group["players"]:
if group["link_replacement"]:
item_player = group_id
else:
item_player = player
if group["replacement_items"][player]:
items_to_add.append(
AutoWorld.call_single(world, "create_item", player, group["replacement_items"][player]))
items_to_add.append(AutoWorld.call_single(world, "create_item", item_player,
group["replacement_items"][player]))
else:
items_to_add.append(AutoWorld.call_single(world, "create_filler", player))
items_to_add.append(AutoWorld.call_single(world, "create_filler", item_player))
world.random.shuffle(items_to_add)
world.itempool.extend(items_to_add[:itemcount - len(world.itempool)])

Expand Down Expand Up @@ -364,16 +368,19 @@ def precollect_hint(location):
for player in world.groups.get(location.item.player, {}).get("players", [])]):
precollect_hint(location)

# custom datapackage
datapackage = {}
for game_world in world.worlds.values():
if game_world.data_version == 0 and game_world.game not in datapackage:
datapackage[game_world.game] = worlds.network_data_package["games"][game_world.game]
datapackage[game_world.game]["item_name_groups"] = game_world.item_name_groups

multidata = {
"slot_data": slot_data,
"slot_info": slot_info,
"names": names, # TODO: remove around 0.2.5 in favor of slot_info
"games": games, # TODO: remove around 0.2.5 in favor of slot_info
"connect_names": {name: (0, player) for player, name in world.player_name.items()},
"remote_items": {player for player in world.player_ids if
world.worlds[player].remote_items},
"remote_start_inventory": {player for player in world.player_ids if
world.worlds[player].remote_start_inventory},
"locations": locations_data,
"checks_in_area": checks_in_area,
"server_options": baked_server_options,
Expand All @@ -383,7 +390,8 @@ def precollect_hint(location):
"version": tuple(version_tuple),
"tags": ["AP"],
"minimum_versions": minimum_versions,
"seed_name": world.seed_name
"seed_name": world.seed_name,
"datapackage": datapackage,
}
AutoWorld.call_all(world, "modify_multidata", multidata)

Expand Down
Loading

0 comments on commit 7f4eb70

Please sign in to comment.