diff --git a/MultiServer.py b/MultiServer.py index 1bfa1f9d..4bbf3486 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -712,15 +712,15 @@ def json_format_send_event(net_item: NetworkItem, receiving_player: int): NetUtils.add_json_text(parts, net_item.player, type=NetUtils.JSONTypes.player_id) if net_item.player == receiving_player: NetUtils.add_json_text(parts, " found their ") - NetUtils.add_json_text(parts, net_item.item, type=NetUtils.JSONTypes.item_id) + NetUtils.add_json_item(parts, net_item.item, net_item.player) else: NetUtils.add_json_text(parts, " sent ") - NetUtils.add_json_text(parts, net_item.item, type=NetUtils.JSONTypes.item_id) + NetUtils.add_json_item(parts, net_item.item, receiving_player) NetUtils.add_json_text(parts, " to ") NetUtils.add_json_text(parts, receiving_player, type=NetUtils.JSONTypes.player_id) NetUtils.add_json_text(parts, " (") - NetUtils.add_json_text(parts, net_item.location, type=NetUtils.JSONTypes.location_id) + NetUtils.add_json_location(parts, net_item.location, net_item.player) NetUtils.add_json_text(parts, ")") return {"cmd": "PrintJSON", "data": parts, "type": "ItemSend", diff --git a/NetUtils.py b/NetUtils.py index 8b2e08c8..20c78528 100644 --- a/NetUtils.py +++ b/NetUtils.py @@ -15,6 +15,8 @@ class JSONMessagePart(typing.TypedDict, total=False): color: str # mainly for items, optional found: bool + # owning player for location/item + player: int class ClientStatus(enum.IntEnum): @@ -111,7 +113,6 @@ def _object_hook(o: typing.Any) -> typing.Any: decode = JSONDecoder(object_hook=_object_hook).decode - class Endpoint: socket: websockets.WebSocketServerProtocol @@ -241,6 +242,14 @@ def add_json_text(parts: list, text: typing.Any, **kwargs) -> None: parts.append({"text": str(text), **kwargs}) +def add_json_item(parts: list, item_id: int, player: int = 0, **kwargs) -> None: + parts.append({"text": str(item_id), "player": player, "type": JSONTypes.item_id, **kwargs}) + + +def add_json_location(parts: list, item_id: int, player: int = 0, **kwargs) -> None: + parts.append({"text": str(item_id), "player": player, "type": JSONTypes.location_id, **kwargs}) + + class Hint(typing.NamedTuple): receiving_player: int finding_player: int @@ -265,9 +274,9 @@ class Hint(typing.NamedTuple): add_json_text(parts, "[Hint]: ") add_json_text(parts, self.receiving_player, type="player_id") add_json_text(parts, "'s ") - add_json_text(parts, self.item, type="item_id", found=self.found) + add_json_item(parts, self.item, self.receiving_player, found=self.found) add_json_text(parts, " is at ") - add_json_text(parts, self.location, type="location_id") + add_json_location(parts, self.location, self.finding_player) add_json_text(parts, " in ") add_json_text(parts, self.finding_player, type="player_id") if self.entrance: diff --git a/docs/network protocol.md b/docs/network protocol.md index 5cdca2a7..8758df25 100644 --- a/docs/network protocol.md +++ b/docs/network protocol.md @@ -333,6 +333,7 @@ class JSONMessagePart(TypedDict): type: Optional[str] color: Optional[str] text: Optional[str] + player: Optional[int] # marks owning player id for location/item ``` `type` is used to denote the intent of the message part. This can be used to indicate special information which may be rendered differently depending on client. How these types are displayed in Archipelago's ALttP client is not the end-all be-all. Other clients may choose to interpret and display these messages differently. @@ -340,6 +341,7 @@ Possible values for `type` include: * player_id * item_id * location_id +* entrance_name `color` is used to denote a console color to display the message part with. This is limited to console colors due to backwards compatibility needs with games such as ALttP. Although background colors as well as foreground colors are listed, only one may be applied to a [JSONMessagePart](#JSONMessagePart) at a time. diff --git a/kvui.py b/kvui.py index 92efb217..2c8c5d08 100644 --- a/kvui.py +++ b/kvui.py @@ -111,7 +111,7 @@ class ServerLabel(HoverBehavior, Label): text += "\nPermissions:" for permission_name, permission_data in ctx.permissions.items(): text += f"\n {permission_name}: {permission_data}" - if ctx.hint_cost is not None: + if ctx.hint_cost is not None and ctx.total_locations: text += f"\nA new !hint costs {ctx.hint_cost}% of checks made. " \ f"For you this means every {max(0, int(ctx.hint_cost * 0.01 * ctx.total_locations))} " \ "location checks."