MultiServer: Notify clients of hint points (#1548)
* notify clients of their amount of hint points on initial connection and when hinting * send in connect packet instead of sending a RoomUpdate on connect * send hint_points update in `on_new_hint` * add to connected packet docs * hint_points isn't a new variable on RoomUpdate now * note roomupdate can contain connected members * add the hint point stuff to commonclient * only show hint points when relevant and default to 0 * Revert "note roomupdate can contain connected members" * remove hint_points from roomupdate args list and condense explanation of possible packet args * updates from phar's review * Small tweak to wording in RoomUpdate --------- Co-authored-by: Fabian Dill <Berserker66@users.noreply.github.com> Co-authored-by: Phar <zach@alliware.com>
This commit is contained in:
parent
c7284f90d9
commit
77fbd0eb2b
|
@ -166,6 +166,7 @@ class CommonContext:
|
||||||
server_address: typing.Optional[str]
|
server_address: typing.Optional[str]
|
||||||
password: typing.Optional[str]
|
password: typing.Optional[str]
|
||||||
hint_cost: typing.Optional[int]
|
hint_cost: typing.Optional[int]
|
||||||
|
hint_points: typing.Optional[int]
|
||||||
player_names: typing.Dict[int, str]
|
player_names: typing.Dict[int, str]
|
||||||
|
|
||||||
finished_game: bool
|
finished_game: bool
|
||||||
|
@ -711,6 +712,7 @@ async def process_server_cmd(ctx: CommonContext, args: dict):
|
||||||
ctx.slot = args["slot"]
|
ctx.slot = args["slot"]
|
||||||
# int keys get lost in JSON transfer
|
# int keys get lost in JSON transfer
|
||||||
ctx.slot_info = {int(pid): data for pid, data in args["slot_info"].items()}
|
ctx.slot_info = {int(pid): data for pid, data in args["slot_info"].items()}
|
||||||
|
ctx.hint_points = args.get("hint_points", 0)
|
||||||
ctx.consume_players_package(args["players"])
|
ctx.consume_players_package(args["players"])
|
||||||
msgs = []
|
msgs = []
|
||||||
if ctx.locations_checked:
|
if ctx.locations_checked:
|
||||||
|
|
|
@ -700,6 +700,10 @@ class Context:
|
||||||
targets: typing.Set[Client] = set(self.stored_data_notification_clients[key])
|
targets: typing.Set[Client] = set(self.stored_data_notification_clients[key])
|
||||||
if targets:
|
if targets:
|
||||||
self.broadcast(targets, [{"cmd": "SetReply", "key": key, "value": self.hints[team, slot]}])
|
self.broadcast(targets, [{"cmd": "SetReply", "key": key, "value": self.hints[team, slot]}])
|
||||||
|
self.broadcast(self.clients[team][slot], [{
|
||||||
|
"cmd": "RoomUpdate",
|
||||||
|
"hint_points": get_slot_points(self, team, slot)
|
||||||
|
}])
|
||||||
|
|
||||||
|
|
||||||
def update_aliases(ctx: Context, team: int):
|
def update_aliases(ctx: Context, team: int):
|
||||||
|
@ -1639,7 +1643,8 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
|
||||||
"players": ctx.get_players_package(),
|
"players": ctx.get_players_package(),
|
||||||
"missing_locations": get_missing_checks(ctx, team, slot),
|
"missing_locations": get_missing_checks(ctx, team, slot),
|
||||||
"checked_locations": get_checked_checks(ctx, team, slot),
|
"checked_locations": get_checked_checks(ctx, team, slot),
|
||||||
"slot_info": ctx.slot_info
|
"slot_info": ctx.slot_info,
|
||||||
|
"hint_points": get_slot_points(ctx, team, slot),
|
||||||
}
|
}
|
||||||
reply = [connected_packet]
|
reply = [connected_packet]
|
||||||
start_inventory = get_start_inventory(ctx, slot, client.remote_start_inventory)
|
start_inventory = get_start_inventory(ctx, slot, client.remote_start_inventory)
|
||||||
|
|
|
@ -128,7 +128,8 @@ Sent to clients when the connection handshake is successfully completed.
|
||||||
| missing_locations | list\[int\] | Contains ids of remaining locations that need to be checked. Useful for trackers, among other things. |
|
| missing_locations | list\[int\] | Contains ids of remaining locations that need to be checked. Useful for trackers, among other things. |
|
||||||
| checked_locations | list\[int\] | Contains ids of all locations that have been checked. Useful for trackers, among other things. Location ids are in the range of ± 2<sup>53</sup>-1. |
|
| checked_locations | list\[int\] | Contains ids of all locations that have been checked. Useful for trackers, among other things. Location ids are in the range of ± 2<sup>53</sup>-1. |
|
||||||
| slot_data | dict\[str, any\] | Contains a json object for slot related data, differs per game. Empty if not required. Not present if slot_data in [Connect](#Connect) is false. |
|
| slot_data | dict\[str, any\] | Contains a json object for slot related data, differs per game. Empty if not required. Not present if slot_data in [Connect](#Connect) is false. |
|
||||||
| slot_info | dict\[int, [NetworkSlot](#NetworkSlot)\] | maps each slot to a [NetworkSlot](#NetworkSlot) information |
|
| slot_info | dict\[int, [NetworkSlot](#NetworkSlot)\] | maps each slot to a [NetworkSlot](#NetworkSlot) information. |
|
||||||
|
| hint_points | int | Number of hint points that the current player has. |
|
||||||
|
|
||||||
### ReceivedItems
|
### ReceivedItems
|
||||||
Sent to clients when they receive an item.
|
Sent to clients when they receive an item.
|
||||||
|
@ -146,17 +147,16 @@ Sent to clients to acknowledge a received [LocationScouts](#LocationScouts) pack
|
||||||
| locations | list\[[NetworkItem](#NetworkItem)\] | Contains list of item(s) in the location(s) scouted. |
|
| locations | list\[[NetworkItem](#NetworkItem)\] | Contains list of item(s) in the location(s) scouted. |
|
||||||
|
|
||||||
### RoomUpdate
|
### RoomUpdate
|
||||||
Sent when there is a need to update information about the present game session. Generally useful for async games.
|
Sent when there is a need to update information about the present game session.
|
||||||
Once authenticated (received Connected), this may also contain data from Connected.
|
|
||||||
#### Arguments
|
#### Arguments
|
||||||
The arguments for RoomUpdate are identical to [RoomInfo](#RoomInfo) barring:
|
RoomUpdate may contain the same arguments from [RoomInfo](#RoomInfo) and, once authenticated, arguments from
|
||||||
|
[Connected](#Connected) with the following exceptions:
|
||||||
|
|
||||||
| Name | Type | Notes |
|
| Name | Type | Notes |
|
||||||
| ---- | ---- | ----- |
|
|-------------------|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
|
||||||
| hint_points | int | New argument. The client's current hint points. |
|
| players | list\[[NetworkPlayer](#NetworkPlayer)\] | Sent in the event of an alias rename. Always sends all players, whether connected or not. |
|
||||||
| players | list\[[NetworkPlayer](#NetworkPlayer)\] | Send in the event of an alias rename. Always sends all players, whether connected or not. |
|
| checked_locations | list\[int\] | May be a partial update, containing new locations that were checked, especially from a coop partner in the same slot. |
|
||||||
| checked_locations | list\[int\] | May be a partial update, containing new locations that were checked, especially from a coop partner in the same slot. |
|
| missing_locations | - | Never sent in this packet. If needed, it is the inverse of `checked_locations`. |
|
||||||
| missing_locations | list\[int\] | Should never be sent as an update, if needed is the inverse of checked_locations. |
|
|
||||||
|
|
||||||
All arguments for this packet are optional, only changes are sent.
|
All arguments for this packet are optional, only changes are sent.
|
||||||
|
|
||||||
|
|
6
kvui.py
6
kvui.py
|
@ -151,11 +151,11 @@ class ServerLabel(HovererableLabel):
|
||||||
min_cost = int(ctx.server_version >= (0, 3, 9))
|
min_cost = int(ctx.server_version >= (0, 3, 9))
|
||||||
text += f"\nA new !hint <itemname> costs {ctx.hint_cost}% of checks made. " \
|
text += f"\nA new !hint <itemname> costs {ctx.hint_cost}% of checks made. " \
|
||||||
f"For you this means every " \
|
f"For you this means every " \
|
||||||
f"{max(min_cost, int(ctx.hint_cost * 0.01 * ctx.total_locations))}" \
|
f"{max(min_cost, int(ctx.hint_cost * 0.01 * ctx.total_locations))} " \
|
||||||
f" location checks."
|
"location checks." \
|
||||||
|
f"\nYou currently have {ctx.hint_points} points."
|
||||||
elif ctx.hint_cost == 0:
|
elif ctx.hint_cost == 0:
|
||||||
text += "\n!hint is free to use."
|
text += "\n!hint is free to use."
|
||||||
|
|
||||||
else:
|
else:
|
||||||
text += f"\nYou are not authenticated yet."
|
text += f"\nYou are not authenticated yet."
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue