From 7353b489ced30eae3a1e391430d2ca537fdb56f2 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Mon, 15 Jun 2020 06:30:51 +0200 Subject: [PATCH] add available hint points to UI --- MultiClient.py | 6 ++++++ MultiServer.py | 11 ++++++++--- Utils.py | 2 +- WebUI.py | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/MultiClient.py b/MultiClient.py index d964d77d..5450f9d7 100644 --- a/MultiClient.py +++ b/MultiClient.py @@ -56,6 +56,7 @@ class Context(): self.check_points = 0 self.forfeit_mode = '' self.remaining_mode = '' + self.hint_points = 0 # End WebUI Stuff self.exit_event = asyncio.Event() @@ -892,8 +893,13 @@ async def process_server_cmd(ctx: Context, cmd, args): elif cmd == "AliasUpdate": ctx.player_names = {p: n for p, n in args} + elif cmd == 'Print': ctx.ui_node.log_info(args) + + elif cmd == 'HintPointUpdate': + ctx.hint_points = args[0] + else: logging.debug(f"unknown command {args}") diff --git a/MultiServer.py b/MultiServer.py index 8b298068..5efa95a6 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -402,6 +402,9 @@ def register_location_checks(ctx: Context, team: int, slot: int, locations): send_new_items(ctx) if found_items: + for client in ctx.endpoints: + if client.team == team and client.slot == slot: + asyncio.create_task(ctx.send_msgs(client, [["HintPointUpdate", (get_client_points(ctx, client),)]])) save(ctx) @@ -702,9 +705,7 @@ class ClientMessageProcessor(CommandProcessor): @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. """ - points_available = self.ctx.location_check_points * len( - self.ctx.location_checks[self.client.team, self.client.slot]) - \ - self.ctx.hint_cost * self.ctx.hints_used[self.client.team, self.client.slot] + points_available = get_client_points(self.ctx, self.client) if not item_or_location: self.output(f"A hint costs {self.ctx.hint_cost} points. " f"You have {points_available} points.") @@ -784,6 +785,10 @@ class ClientMessageProcessor(CommandProcessor): return False +def get_client_points(ctx: Context, client: Client) -> int: + return (ctx.location_check_points * len(ctx.location_checks[client.team, client.slot]) - + ctx.hint_cost * ctx.hints_used[client.team, client.slot]) + async def process_client_cmd(ctx: Context, client: Client, cmd, args): if type(cmd) is not str: await ctx.send_msgs(client, [['InvalidCmd']]) diff --git a/Utils.py b/Utils.py index 4e6ac7d9..c8234efc 100644 --- a/Utils.py +++ b/Utils.py @@ -1,6 +1,6 @@ from __future__ import annotations -__version__ = "2.3.2" +__version__ = "2.3.3" _version_tuple = tuple(int(piece, 10) for piece in __version__.split(".")) import os diff --git a/WebUI.py b/WebUI.py index d1547da5..ab9143d6 100644 --- a/WebUI.py +++ b/WebUI.py @@ -118,7 +118,7 @@ class WebUiClient(Node): def send_location_check(self, ctx: Context, last_check: str): self.broadcast_all(self.build_message('locationCheck', { 'totalChecks': len(ctx.locations_checked), - 'hintPoints': 0, + 'hintPoints': ctx.hint_points, 'lastCheck': last_check, }))