From ca4b0acd921d036336982e1bffb80de2c1851da5 Mon Sep 17 00:00:00 2001 From: CaitSith2 Date: Sat, 9 Oct 2021 20:47:12 -0700 Subject: [PATCH] Add !hint_location command. As it turns out, because factorio location names are 100% identical to factorio item names, it is impossible without a command that explicitly hints locations to hint a specific factorio location, or any other game where location names match item names. --- MultiServer.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/MultiServer.py b/MultiServer.py index 5ad4654b..1520d528 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -977,14 +977,9 @@ class ClientMessageProcessor(CommonCommandProcessor): self.output("Cheating is disabled.") return False - @mark_raw - def _cmd_hint(self, item_or_location: str = "") -> bool: - """Use !hint {item_name/location_name}, - for example !hint Lamp or !hint Link's House to get a spoiler peek for that location or item. - If hint costs are on, this will only give you one new result, - you can rerun the command to get more in that case.""" + def get_hints(self, input_text: str, explicit_location: bool = False) -> bool: points_available = get_client_points(self.ctx, self.client) - if not item_or_location: + if not input_text: hints = {hint.re_check(self.ctx, self.client.team) for hint in self.ctx.hints[self.client.team, self.client.slot]} self.ctx.hints[self.client.team, self.client.slot] = hints @@ -994,16 +989,16 @@ class ClientMessageProcessor(CommonCommandProcessor): return True else: world = proxy_worlds[self.ctx.games[self.client.slot]] - item_name, usable, response = get_intended_text(item_or_location, world.all_names) + item_name, usable, response = get_intended_text(input_text, world.all_names if not explicit_location else world.location_names) if usable: if item_name in world.hint_blacklist: self.output(f"Sorry, \"{item_name}\" is marked as non-hintable.") hints = [] - elif item_name in world.item_name_groups: + elif item_name in world.item_name_groups and not explicit_location: hints = [] for item in world.item_name_groups[item_name]: hints.extend(collect_hints(self.ctx, self.client.team, self.client.slot, item)) - elif item_name in world.item_names: # item name + elif item_name in world.item_names and not explicit_location: # item name hints = collect_hints(self.ctx, self.client.team, self.client.slot, item_name) else: # location name hints = collect_hints_location(self.ctx, self.client.team, self.client.slot, item_name) @@ -1036,19 +1031,25 @@ class ClientMessageProcessor(CommonCommandProcessor): hints.append(hint) can_pay -= 1 self.ctx.hints_used[self.client.team, self.client.slot] += 1 + 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 hints: + if hints and cost and int((points_available // cost) == 0): + self.output( + f"There may be more hintables, however, you cannot afford to pay for any more. " + f" You have {points_available} and need at least " + f"{self.ctx.get_hint_cost(self.client.slot)}.") + elif hints: self.output( "There may be more hintables, you can rerun the command to find more.") else: self.output(f"You can't afford the hint. " f"You have {points_available} points and need at least " - f"{self.ctx.get_hint_cost(self.client.slot)}") + f"{self.ctx.get_hint_cost(self.client.slot)}.") notify_hints(self.ctx, self.client.team, hints) self.ctx.save() return True @@ -1060,6 +1061,22 @@ class ClientMessageProcessor(CommonCommandProcessor): self.output(response) return False + @mark_raw + def _cmd_hint(self, item_or_location: str = "") -> bool: + """Use !hint {item_name/location_name}, + for example !hint Lamp or !hint Link's House to get a spoiler peek for that location or item. + If hint costs are on, this will only give you one new result, + you can rerun the command to get more in that case.""" + return self.get_hints(item_or_location) + + @mark_raw + def _cmd_hint_location(self, location: str = "") -> bool: + """Use !hint_location {location_name}, + for example !hint atomic-bomb to get a spoiler peek for that location. + (In the case of factorio, or any other game where item names and location names are identical, + this command must be used explicitly.)""" + return self.get_hints(location, True) + def get_checked_checks(ctx: Context, client: Client) -> typing.List[int]: return [location_id for