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.
This commit is contained in:
CaitSith2 2021-10-09 20:47:12 -07:00
parent f8deb1bd7f
commit ca4b0acd92
1 changed files with 29 additions and 12 deletions

View File

@ -977,14 +977,9 @@ class ClientMessageProcessor(CommonCommandProcessor):
self.output("Cheating is disabled.") self.output("Cheating is disabled.")
return False return False
@mark_raw def get_hints(self, input_text: str, explicit_location: bool = False) -> bool:
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."""
points_available = get_client_points(self.ctx, self.client) 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 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]}
self.ctx.hints[self.client.team, self.client.slot] = hints self.ctx.hints[self.client.team, self.client.slot] = hints
@ -994,16 +989,16 @@ class ClientMessageProcessor(CommonCommandProcessor):
return True return True
else: else:
world = proxy_worlds[self.ctx.games[self.client.slot]] 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 usable:
if item_name in world.hint_blacklist: if item_name in world.hint_blacklist:
self.output(f"Sorry, \"{item_name}\" is marked as non-hintable.") self.output(f"Sorry, \"{item_name}\" is marked as non-hintable.")
hints = [] hints = []
elif item_name in world.item_name_groups: elif item_name in world.item_name_groups and not explicit_location:
hints = [] hints = []
for item in world.item_name_groups[item_name]: for item in world.item_name_groups[item_name]:
hints.extend(collect_hints(self.ctx, self.client.team, self.client.slot, item)) 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) hints = collect_hints(self.ctx, self.client.team, self.client.slot, item_name)
else: # location name else: # location name
hints = collect_hints_location(self.ctx, self.client.team, self.client.slot, item_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) hints.append(hint)
can_pay -= 1 can_pay -= 1
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)
if not hint.found: if not hint.found:
self.ctx.hints[self.client.team, hint.finding_player].add(hint) self.ctx.hints[self.client.team, hint.finding_player].add(hint)
self.ctx.hints[self.client.team, hint.receiving_player].add(hint) self.ctx.hints[self.client.team, hint.receiving_player].add(hint)
if not_found_hints: 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( self.output(
"There may be more hintables, you can rerun the command to find more.") "There may be more hintables, you can rerun the command to find more.")
else: else:
self.output(f"You can't afford the hint. " self.output(f"You can't afford the hint. "
f"You have {points_available} points and need at least " 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) notify_hints(self.ctx, self.client.team, hints)
self.ctx.save() self.ctx.save()
return True return True
@ -1060,6 +1061,22 @@ class ClientMessageProcessor(CommonCommandProcessor):
self.output(response) self.output(response)
return False 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]: def get_checked_checks(ctx: Context, client: Client) -> typing.List[int]:
return [location_id for return [location_id for