mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
[Network_Item] Add item flags to network item so client can distinct some details (#210)
This commit is contained in:
@@ -78,7 +78,7 @@ class Context:
|
||||
"compatibility": int}
|
||||
# team -> slot id -> list of clients authenticated to slot.
|
||||
clients: typing.Dict[int, typing.Dict[int, typing.List[Client]]]
|
||||
locations: typing.Dict[int, typing.Dict[int, typing.Tuple[int, int]]]
|
||||
locations: typing.Dict[int, typing.Dict[int, typing.Tuple[int, int, int]]]
|
||||
|
||||
def __init__(self, host: str, port: int, server_password: str, password: str, location_check_points: int,
|
||||
hint_cost: int, item_cheat: bool, forfeit_mode: str = "disabled", collect_mode="disabled",
|
||||
@@ -662,8 +662,13 @@ def register_location_checks(ctx: Context, team: int, slot: int, locations: typi
|
||||
if count_activity:
|
||||
ctx.client_activity_timers[team, slot] = datetime.datetime.now(datetime.timezone.utc)
|
||||
for location in new_locations:
|
||||
item_id, target_player = ctx.locations[slot][location]
|
||||
new_item = NetworkItem(item_id, location, slot)
|
||||
if len(ctx.locations[slot][location]) == 3:
|
||||
item_id, target_player, flags = ctx.locations[slot][location]
|
||||
else:
|
||||
item_id, target_player = ctx.locations[slot][location]
|
||||
flags = 0
|
||||
|
||||
new_item = NetworkItem(item_id, location, slot, flags)
|
||||
if target_player != slot or slot in ctx.remote_items:
|
||||
get_received_items(ctx, team, target_player).append(new_item)
|
||||
|
||||
@@ -694,22 +699,33 @@ def collect_hints(ctx: Context, team: int, slot: int, item: str) -> typing.List[
|
||||
seeked_item_id = proxy_worlds[ctx.games[slot]].item_name_to_id[item]
|
||||
for finding_player, check_data in ctx.locations.items():
|
||||
for location_id, result in check_data.items():
|
||||
item_id, receiving_player = result
|
||||
if len(result) == 3:
|
||||
item_id, receiving_player, item_flags = result
|
||||
else:
|
||||
item_id, receiving_player = result
|
||||
item_flags = 0
|
||||
|
||||
if receiving_player == slot and item_id == seeked_item_id:
|
||||
found = location_id in ctx.location_checks[team, finding_player]
|
||||
entrance = ctx.er_hint_data.get(finding_player, {}).get(location_id, "")
|
||||
hints.append(NetUtils.Hint(receiving_player, finding_player, location_id, item_id, found, entrance))
|
||||
hints.append(NetUtils.Hint(receiving_player, finding_player, location_id, item_id, found, entrance, item_flags))
|
||||
|
||||
return hints
|
||||
|
||||
|
||||
def collect_hints_location(ctx: Context, team: int, slot: int, location: str) -> typing.List[NetUtils.Hint]:
|
||||
seeked_location: int = proxy_worlds[ctx.games[slot]].location_name_to_id[location]
|
||||
item_id, receiving_player = ctx.locations[slot].get(seeked_location, (None, None))
|
||||
if item_id:
|
||||
result = ctx.locations[slot].get(seeked_location, (None, None, None))
|
||||
if result:
|
||||
if len(result) == 3:
|
||||
item_id, receiving_player, item_flags = result
|
||||
else:
|
||||
item_id, receiving_player = result
|
||||
item_flags = 0
|
||||
|
||||
found = seeked_location in ctx.location_checks[team, slot]
|
||||
entrance = ctx.er_hint_data.get(slot, {}).get(seeked_location, "")
|
||||
return [NetUtils.Hint(receiving_player, slot, seeked_location, item_id, found, entrance)]
|
||||
return [NetUtils.Hint(receiving_player, slot, seeked_location, item_id, found, entrance, item_flags)]
|
||||
return []
|
||||
|
||||
|
||||
@@ -729,10 +745,10 @@ 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_item(parts, net_item.item, net_item.player)
|
||||
NetUtils.add_json_item(parts, net_item.item, net_item.player, net_item.flags)
|
||||
else:
|
||||
NetUtils.add_json_text(parts, " sent ")
|
||||
NetUtils.add_json_item(parts, net_item.item, receiving_player)
|
||||
NetUtils.add_json_item(parts, net_item.item, receiving_player, net_item.flags)
|
||||
NetUtils.add_json_text(parts, " to ")
|
||||
NetUtils.add_json_text(parts, receiving_player, type=NetUtils.JSONTypes.player_id)
|
||||
|
||||
@@ -1342,8 +1358,13 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
|
||||
[{'cmd': 'InvalidPacket', "type": "arguments", "text": 'LocationScouts',
|
||||
"original_cmd": cmd}])
|
||||
return
|
||||
target_item, target_player = ctx.locations[client.slot][location]
|
||||
locs.append(NetworkItem(target_item, location, target_player))
|
||||
if len(ctx.locations[client.slot][location]) == 3:
|
||||
target_item, target_player, flags = ctx.locations[client.slot][location]
|
||||
else:
|
||||
target_item, target_player = ctx.locations[client.slot][location]
|
||||
flags = 0
|
||||
|
||||
locs.append(NetworkItem(target_item, location, target_player, flags))
|
||||
|
||||
await ctx.send_msgs(client, [{'cmd': 'LocationInfo', 'locations': locs}])
|
||||
|
||||
|
Reference in New Issue
Block a user