Server: allow LocationScouts to create free hints
This commit is contained in:
		
							parent
							
								
									0bd252e7f5
								
							
						
					
					
						commit
						8c638bcfd8
					
				| 
						 | 
					@ -497,20 +497,26 @@ class Context:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def notify_hints(ctx: Context, team: int, hints: typing.List[NetUtils.Hint]):
 | 
					def notify_hints(ctx: Context, team: int, hints: typing.List[NetUtils.Hint]):
 | 
				
			||||||
 | 
					    """Send and remember hints"""
 | 
				
			||||||
    concerns = collections.defaultdict(list)
 | 
					    concerns = collections.defaultdict(list)
 | 
				
			||||||
    for hint in hints:
 | 
					    for hint in hints:
 | 
				
			||||||
        net_msg = hint.as_network_message()
 | 
					        net_msg = hint.as_network_message()
 | 
				
			||||||
        concerns[hint.receiving_player].append(net_msg)
 | 
					        concerns[hint.receiving_player].append(net_msg)
 | 
				
			||||||
        if not hint.local:
 | 
					        if not hint.local:
 | 
				
			||||||
            concerns[hint.finding_player].append(net_msg)
 | 
					            concerns[hint.finding_player].append(net_msg)
 | 
				
			||||||
 | 
					        # remember hints in all cases
 | 
				
			||||||
 | 
					        if not hint.found:
 | 
				
			||||||
 | 
					            ctx.hints[team, hint.finding_player].add(hint)
 | 
				
			||||||
 | 
					            ctx.hints[team, hint.receiving_player].add(hint)
 | 
				
			||||||
    for text in (format_hint(ctx, team, hint) for hint in hints):
 | 
					    for text in (format_hint(ctx, team, hint) for hint in hints):
 | 
				
			||||||
        logging.info("Notice (Team #%d): %s" % (team + 1, text))
 | 
					        logging.info("Notice (Team #%d): %s" % (team + 1, text))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for slot, clients in ctx.clients[team].items():
 | 
					    if hints:
 | 
				
			||||||
        client_hints = concerns[slot]
 | 
					        for slot, clients in ctx.clients[team].items():
 | 
				
			||||||
        if client_hints:
 | 
					            client_hints = concerns[slot]
 | 
				
			||||||
            for client in clients:
 | 
					            if client_hints:
 | 
				
			||||||
                asyncio.create_task(ctx.send_msgs(client, client_hints))
 | 
					                for client in clients:
 | 
				
			||||||
 | 
					                    asyncio.create_task(ctx.send_msgs(client, client_hints))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def update_aliases(ctx: Context, team: int):
 | 
					def update_aliases(ctx: Context, team: int):
 | 
				
			||||||
| 
						 | 
					@ -766,8 +772,12 @@ def collect_hints(ctx: Context, team: int, slot: int, item: str) -> typing.List[
 | 
				
			||||||
    return hints
 | 
					    return hints
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def collect_hints_location(ctx: Context, team: int, slot: int, location: str) -> typing.List[NetUtils.Hint]:
 | 
					def collect_hint_location_name(ctx: Context, team: int, slot: int, location: str) -> typing.List[NetUtils.Hint]:
 | 
				
			||||||
    seeked_location: int = proxy_worlds[ctx.games[slot]].location_name_to_id[location]
 | 
					    seeked_location: int = proxy_worlds[ctx.games[slot]].location_name_to_id[location]
 | 
				
			||||||
 | 
					    return collect_hint_location_id(ctx, team, slot, seeked_location)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def collect_hint_location_id(ctx: Context, team: int, slot: int, seeked_location: int) -> typing.List[NetUtils.Hint]:
 | 
				
			||||||
    result = ctx.locations[slot].get(seeked_location, (None, None, None))
 | 
					    result = ctx.locations[slot].get(seeked_location, (None, None, None))
 | 
				
			||||||
    if result:
 | 
					    if result:
 | 
				
			||||||
        item_id, receiving_player, item_flags = result
 | 
					        item_id, receiving_player, item_flags = result
 | 
				
			||||||
| 
						 | 
					@ -1183,7 +1193,7 @@ class ClientMessageProcessor(CommonCommandProcessor):
 | 
				
			||||||
                elif not for_location and hint_name in world.item_names:  # item name
 | 
					                elif not for_location and hint_name in world.item_names:  # item name
 | 
				
			||||||
                    hints = collect_hints(self.ctx, self.client.team, self.client.slot, hint_name)
 | 
					                    hints = collect_hints(self.ctx, self.client.team, self.client.slot, hint_name)
 | 
				
			||||||
                else:  # location name
 | 
					                else:  # location name
 | 
				
			||||||
                    hints = collect_hints_location(self.ctx, self.client.team, self.client.slot, hint_name)
 | 
					                    hints = collect_hint_location_name(self.ctx, self.client.team, self.client.slot, hint_name)
 | 
				
			||||||
                cost = self.ctx.get_hint_cost(self.client.slot)
 | 
					                cost = self.ctx.get_hint_cost(self.client.slot)
 | 
				
			||||||
                if hints:
 | 
					                if hints:
 | 
				
			||||||
                    new_hints = set(hints) - self.ctx.hints[self.client.team, self.client.slot]
 | 
					                    new_hints = set(hints) - self.ctx.hints[self.client.team, self.client.slot]
 | 
				
			||||||
| 
						 | 
					@ -1215,10 +1225,6 @@ class ClientMessageProcessor(CommonCommandProcessor):
 | 
				
			||||||
                            self.ctx.hints_used[self.client.team, self.client.slot] += 1
 | 
					                            self.ctx.hints_used[self.client.team, self.client.slot] += 1
 | 
				
			||||||
                            points_available = get_client_points(self.ctx, self.client)
 | 
					                            points_available = get_client_points(self.ctx, self.client)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            if not hint.found:
 | 
					 | 
				
			||||||
                                self.ctx.hints[self.client.team, hint.finding_player].add(hint)
 | 
					 | 
				
			||||||
                                self.ctx.hints[self.client.team, hint.receiving_player].add(hint)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        if not_found_hints:
 | 
					                        if not_found_hints:
 | 
				
			||||||
                            if hints and cost and int((points_available // cost) == 0):
 | 
					                            if hints and cost and int((points_available // cost) == 0):
 | 
				
			||||||
                                self.output(
 | 
					                                self.output(
 | 
				
			||||||
| 
						 | 
					@ -1432,6 +1438,8 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        elif cmd == 'LocationScouts':
 | 
					        elif cmd == 'LocationScouts':
 | 
				
			||||||
            locs = []
 | 
					            locs = []
 | 
				
			||||||
 | 
					            create_as_hint = args.get("create_as_hint", False)
 | 
				
			||||||
 | 
					            hints = []
 | 
				
			||||||
            for location in args["locations"]:
 | 
					            for location in args["locations"]:
 | 
				
			||||||
                if type(location) is not int or location not in lookup_any_location_id_to_name:
 | 
					                if type(location) is not int or location not in lookup_any_location_id_to_name:
 | 
				
			||||||
                    await ctx.send_msgs(client,
 | 
					                    await ctx.send_msgs(client,
 | 
				
			||||||
| 
						 | 
					@ -1440,8 +1448,9 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
 | 
				
			||||||
                    return
 | 
					                    return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                target_item, target_player, flags = ctx.locations[client.slot][location]
 | 
					                target_item, target_player, flags = ctx.locations[client.slot][location]
 | 
				
			||||||
 | 
					                if create_as_hint: hints.extend(collect_hint_location_id(ctx, client.team, client.slot, location))
 | 
				
			||||||
                locs.append(NetworkItem(target_item, location, target_player, flags))
 | 
					                locs.append(NetworkItem(target_item, location, target_player, flags))
 | 
				
			||||||
 | 
					            notify_hints(ctx, client.team, hints)
 | 
				
			||||||
            await ctx.send_msgs(client, [{'cmd': 'LocationInfo', 'locations': locs}])
 | 
					            await ctx.send_msgs(client, [{'cmd': 'LocationInfo', 'locations': locs}])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        elif cmd == 'StatusUpdate':
 | 
					        elif cmd == 'StatusUpdate':
 | 
				
			||||||
| 
						 | 
					@ -1628,8 +1637,10 @@ class ServerCommandProcessor(CommonCommandProcessor):
 | 
				
			||||||
                        hints.extend(collect_hints(self.ctx, team, slot, item))
 | 
					                        hints.extend(collect_hints(self.ctx, team, slot, item))
 | 
				
			||||||
                else:  # item name
 | 
					                else:  # item name
 | 
				
			||||||
                    hints = collect_hints(self.ctx, team, slot, item)
 | 
					                    hints = collect_hints(self.ctx, team, slot, item)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if hints:
 | 
					                if hints:
 | 
				
			||||||
                    notify_hints(self.ctx, team, hints)
 | 
					                    notify_hints(self.ctx, team, hints)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    self.output("No hints found.")
 | 
					                    self.output("No hints found.")
 | 
				
			||||||
                return True
 | 
					                return True
 | 
				
			||||||
| 
						 | 
					@ -1650,7 +1661,7 @@ class ServerCommandProcessor(CommonCommandProcessor):
 | 
				
			||||||
            world = proxy_worlds[self.ctx.games[slot]]
 | 
					            world = proxy_worlds[self.ctx.games[slot]]
 | 
				
			||||||
            item, usable, response = get_intended_text(item, world.location_names)
 | 
					            item, usable, response = get_intended_text(item, world.location_names)
 | 
				
			||||||
            if usable:
 | 
					            if usable:
 | 
				
			||||||
                hints = collect_hints_location(self.ctx, team, slot, item)
 | 
					                hints = collect_hint_location_name(self.ctx, team, slot, item)
 | 
				
			||||||
                if hints:
 | 
					                if hints:
 | 
				
			||||||
                    notify_hints(self.ctx, team, hints)
 | 
					                    notify_hints(self.ctx, team, hints)
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue