Add group collect (#424)

* Add group collect

* code cleanup
This commit is contained in:
CaitSith2 2022-04-10 14:08:54 -07:00 committed by GitHub
parent df3757657e
commit 8e68aa0ccd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 1 deletions

View File

@ -182,6 +182,7 @@ class Context:
self.minimum_client_versions: typing.Dict[int, Utils.Version] = {}
self.seed_name = ""
self.groups = {}
self.group_collected: typing.Dict[int, typing.Set[int]] = {}
self.random = random.Random()
self.stored_data = {}
self.stored_data_notification_clients = collections.defaultdict(weakref.WeakSet)
@ -433,6 +434,7 @@ class Context:
"client_connection_timers": tuple(
(key, value.timestamp()) for key, value in self.client_connection_timers.items()),
"random_state": self.random.getstate(),
"group_collected": dict(self.group_collected),
"stored_data": self.stored_data,
"game_options": {"hint_cost": self.hint_cost, "location_check_points": self.location_check_points,
"server_password": self.server_password, "password": self.password, "forfeit_mode":
@ -487,6 +489,9 @@ class Context:
self.item_cheat = savedata["game_options"]["item_cheat"]
self.compatibility = savedata["game_options"]["compatibility"]
if "group_collected" in savedata:
self.group_collected = savedata["group_collected"]
if "stored_data" in savedata:
self.stored_data = savedata["stored_data"]
# count items and slots from lists for item_handling = remote
@ -765,7 +770,7 @@ def forfeit_player(ctx: Context, team: int, slot: int):
update_checked_locations(ctx, team, slot)
def collect_player(ctx: Context, team: int, slot: int):
def collect_player(ctx: Context, team: int, slot: int, is_group: bool = False):
"""register any locations that are in the multidata, pointing towards this player"""
all_locations = collections.defaultdict(set)
for source_slot, location_data in ctx.locations.items():
@ -778,6 +783,14 @@ def collect_player(ctx: Context, team: int, slot: int):
register_location_checks(ctx, team, source_player, location_ids, count_activity=False)
update_checked_locations(ctx, team, source_player)
if not is_group:
for group, group_players in ctx.groups.items():
if slot in group_players:
group_collected_players = ctx.group_collected.setdefault(group, set())
group_collected_players.add(slot)
if set(group_players) == group_collected_players:
collect_player(ctx, team, group, True)
def get_remaining(ctx: Context, team: int, slot: int) -> typing.List[int]:
items = []