add already found awareness to hint command

This commit is contained in:
Fabian Dill 2020-02-11 00:44:28 +01:00
parent bc081ded9d
commit 416a6e7e50
1 changed files with 19 additions and 10 deletions

View File

@ -223,19 +223,21 @@ def save(ctx:Context):
except Exception as e: except Exception as e:
logging.exception(e) logging.exception(e)
def hint(ctx:Context, team, slot, item:str): def collect_hints(ctx:Context, team, slot, item:str) -> list:
found = 0 hints = []
seeked_item_id = Items.item_table[item][3] seeked_item_id = Items.item_table[item][3]
for check, result in ctx.locations.items(): for check, result in ctx.locations.items():
item_id, receiving_player = result item_id, receiving_player = result
if receiving_player == slot and item_id == seeked_item_id: if receiving_player == slot and item_id == seeked_item_id:
location_id, finding_player = check location_id, finding_player = check
hint = f"[Hint]: {ctx.player_names[(team, slot)]}'s {item} can be found at " \ found = location_id in ctx.location_checks[team, finding_player]
f"{get_location_name_from_address(location_id)} in {ctx.player_names[team, finding_player]}'s World" hints.append((
notify_team(ctx, team, hint) found,
found += 1 f"[Hint]: {ctx.player_names[(team, slot)]}'s {item} can be found at " \
f"{get_location_name_from_address(location_id)} in {ctx.player_names[team, finding_player]}'s World." +
" (found)" if found else ""))
return found return hints
async def process_client_cmd(ctx : Context, client : Client, cmd, args): async def process_client_cmd(ctx : Context, client : Client, cmd, args):
if type(cmd) is not str: if type(cmd) is not str:
@ -342,10 +344,14 @@ async def process_client_cmd(ctx : Context, client : Client, cmd, args):
else: can_pay = True else: can_pay = True
if can_pay: if can_pay:
found = hint(ctx, client.team, client.slot, itemname) hints = collect_hints(ctx, client.team, client.slot, itemname)
found = 0
for already_found, hint in hints:
found += 1-already_found
notify_team(ctx, client.team, hint)
ctx.hints_used[client.team, client.slot] += found ctx.hints_used[client.team, client.slot] += found
if not found: if not found:
notify_client(client, "No items found, points refunded.") notify_client(client, "No new items found, points refunded.")
else: else:
save(ctx) save(ctx)
else: else:
@ -353,6 +359,7 @@ async def process_client_cmd(ctx : Context, client : Client, cmd, args):
f"You have {points_available} points and need {ctx.hint_cost}") f"You have {points_available} points and need {ctx.hint_cost}")
else: else:
notify_client(client, f'Item "{itemname}" not found.') notify_client(client, f'Item "{itemname}" not found.')
def set_password(ctx : Context, password): def set_password(ctx : Context, password):
ctx.password = password ctx.password = password
logging.warning('Password set to ' + password if password is not None else 'Password disabled') logging.warning('Password set to ' + password if password is not None else 'Password disabled')
@ -412,7 +419,9 @@ async def console(ctx : Context):
elif name.lower() == command[1].lower(): elif name.lower() == command[1].lower():
item = " ".join(command[2:]) item = " ".join(command[2:])
if item in Items.item_table: if item in Items.item_table:
hint(ctx, team, slot, item) hints = collect_hints(ctx, team, slot, item)
for already_found, hint in hints:
notify_team(ctx, team, hint)
else: else:
logging.warning("Unknown item: " + item) logging.warning("Unknown item: " + item)
if command[0][0] != '/': if command[0][0] != '/':