Skip to content

Commit

Permalink
update re: review
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyV99 committed Jun 13, 2024
1 parent ec3e662 commit 2e2d560
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ async def shutdown(self):
self.input_task.cancel()

# Hints
def update_hint(self, location: int, finding_player: int, priority: typing.Optional[bool]):
def update_hint(self, location: int, finding_player: int, priority: typing.Optional[bool]) -> None:
msg = {"cmd": "UpdateHint", "location": location, "player": finding_player}
if priority is not None:
msg["priority"] = priority
Expand Down
37 changes: 20 additions & 17 deletions MultiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,8 @@ def get_hint_cost(self, slot):
return 0

def recheck_hints(self, team: typing.Optional[int] = None, slot: typing.Optional[int] = None,
changed: typing.Set[tuple[int,int]] = None, already_updated: typing.Set[tuple[int,int]] = None):
changed: typing.Optional[typing.Set[tuple[int, int]]] = None,
already_updated: typing.Optional[typing.Set[tuple[int, int]]] = None) -> None:
if not already_updated:
already_updated = set()
needs_updating = set()
Expand Down Expand Up @@ -1060,7 +1061,7 @@ def register_location_checks(ctx: Context, team: int, slot: int, locations: typi
ctx.save()


def collect_hints(ctx: Context, team: int, slot: int, item: typing.Union[int, str], prioritize: bool) -> typing.List[NetUtils.Hint]:
def collect_hints(ctx: Context, team: int, slot: int, item: typing.Union[int, str], priority: bool) -> typing.List[NetUtils.Hint]:
hints = []
slots: typing.Set[int] = {slot}
for group_id, group in ctx.groups.items():
Expand All @@ -1073,24 +1074,24 @@ def collect_hints(ctx: Context, team: int, slot: int, item: typing.Union[int, st
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,
item_flags, prioritize))
item_flags, priority))

return hints


def collect_hint_location_name(ctx: Context, team: int, slot: int, location: str, prioritize: bool) -> typing.List[NetUtils.Hint]:
def collect_hint_location_name(ctx: Context, team: int, slot: int, location: str, priority: bool) -> typing.List[NetUtils.Hint]:
seeked_location: int = ctx.location_names_for_game(ctx.games[slot])[location]
return collect_hint_location_id(ctx, team, slot, seeked_location, prioritize)
return collect_hint_location_id(ctx, team, slot, seeked_location, priority)


def collect_hint_location_id(ctx: Context, team: int, slot: int, seeked_location: int, prioritize: bool) -> typing.List[NetUtils.Hint]:
def collect_hint_location_id(ctx: Context, team: int, slot: int, seeked_location: int, priority: bool) -> typing.List[NetUtils.Hint]:
result = ctx.locations[slot].get(seeked_location, (None, None, None))
if any(result):
item_id, receiving_player, item_flags = result

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, item_flags, prioritize)]
return [NetUtils.Hint(receiving_player, slot, seeked_location, item_id, found, entrance, item_flags, priority)]
return []

def format_hint(ctx: Context, team: int, hint: NetUtils.Hint) -> str:
Expand Down Expand Up @@ -1844,22 +1845,24 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
"original_cmd": cmd}])
return
hint = ctx.get_hint(client.team, player, location)
if not hint:
return # Ignored safely
if hint.receiving_player != client.slot:
await ctx.send_msgs(client,
[{'cmd': 'InvalidPacket', "type": "arguments", "text": 'UpdateHint: No Permission',
"original_cmd": cmd}])
return
if not hint:
return # Ignored safely
new_hint = hint
if priority is not None:
new_hint = new_hint.re_prioritize(ctx, priority)
if hint != new_hint:
ctx.replace_hint(client.team, hint.finding_player, hint, new_hint)
ctx.replace_hint(client.team, hint.receiving_player, hint, new_hint)
ctx.save()
ctx.on_changed_hints(client.team, hint.finding_player)
ctx.on_changed_hints(client.team, hint.receiving_player)
if priority is None:
return
new_hint = new_hint.re_prioritize(ctx, priority)
if hint == new_hint:
return
ctx.replace_hint(client.team, hint.finding_player, hint, new_hint)
ctx.replace_hint(client.team, hint.receiving_player, hint, new_hint)
ctx.save()
ctx.on_changed_hints(client.team, hint.finding_player)
ctx.on_changed_hints(client.team, hint.receiving_player)

elif cmd == 'StatusUpdate':
update_client_status(ctx, client, args["status"])
Expand Down
8 changes: 4 additions & 4 deletions NetUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,19 @@ class Hint(typing.NamedTuple):
found: bool
entrance: str = ""
item_flags: int = 0
prioritized: bool = True
priority: bool = True

def re_check(self, ctx, team) -> Hint:
if self.found:
return self
found = self.location in ctx.location_checks[team, self.finding_player]
if found:
return Hint(self.receiving_player, self.finding_player, self.location, self.item, found, self.entrance,
self.item_flags, self.prioritized)
self.item_flags, self.priority)
return self

def re_prioritize(self, ctx, priority: bool) -> Hint:
if priority != self.prioritized:
if priority != self.priority:
return Hint(self.receiving_player, self.finding_player, self.location, self.item, self.found, self.entrance,
self.item_flags, priority)
return self
Expand All @@ -341,7 +341,7 @@ def as_network_message(self) -> dict:
add_json_text(parts, ". ")
if self.found:
add_json_text(parts, "(found)", type="color", color="green")
elif self.prioritized:
elif self.priority:
add_json_text(parts, "(priority)", type="color", color="red")
else:
add_json_text(parts, "(non-priority)", type="color", color="red")
Expand Down

0 comments on commit 2e2d560

Please sign in to comment.