fix payment for already found hints
This commit is contained in:
parent
e02025c534
commit
9842399d8b
|
@ -85,14 +85,16 @@ class Context:
|
||||||
self.commandprocessor = ServerCommandProcessor(self)
|
self.commandprocessor = ServerCommandProcessor(self)
|
||||||
|
|
||||||
def get_save(self) -> dict:
|
def get_save(self) -> dict:
|
||||||
return {
|
d = {
|
||||||
"rom_names": list(self.rom_names.items()),
|
"rom_names": list(self.rom_names.items()),
|
||||||
"received_items": tuple((k, v) for k, v in self.received_items.items()),
|
"received_items": tuple((k, v) for k, v in self.received_items.items()),
|
||||||
"hints_used": tuple((key, value) for key, value in self.hints_used.items()),
|
"hints_used": tuple((key, value) for key, value in self.hints_used.items()),
|
||||||
"hints": tuple((key, value) for key, value in self.hints.items()),
|
"hints": tuple((key, list(value)) for key, value in self.hints.items()),
|
||||||
"location_checks": tuple((key, tuple(value)) for key, value in self.location_checks.items())
|
"location_checks": tuple((key, tuple(value)) for key, value in self.location_checks.items())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return d
|
||||||
|
|
||||||
def set_save(self, savedata: dict):
|
def set_save(self, savedata: dict):
|
||||||
rom_names = savedata["rom_names"]
|
rom_names = savedata["rom_names"]
|
||||||
received_items = {tuple(k): [ReceivedItem(*i) for i in v] for k, v in savedata["received_items"]}
|
received_items = {tuple(k): [ReceivedItem(*i) for i in v] for k, v in savedata["received_items"]}
|
||||||
|
@ -557,31 +559,29 @@ class ClientMessageProcessor(CommandProcessor):
|
||||||
hints = collect_hints_location(self.ctx, self.client.team, self.client.slot, item_name)
|
hints = collect_hints_location(self.ctx, self.client.team, self.client.slot, item_name)
|
||||||
|
|
||||||
if hints:
|
if hints:
|
||||||
if item_name in self.ctx.hints[self.client.team, self.client.slot]:
|
new_hints = set(hints) - self.ctx.hints[self.client.team, self.client.slot]
|
||||||
notify_hints(self.ctx, self.client.team, hints)
|
old_hints = set(hints) - new_hints
|
||||||
|
if old_hints:
|
||||||
|
notify_hints(self.ctx, self.client.team, list(old_hints))
|
||||||
|
if not new_hints:
|
||||||
self.output("Hint was previously used, no points deducted.")
|
self.output("Hint was previously used, no points deducted.")
|
||||||
return True
|
if new_hints:
|
||||||
else:
|
found_hints = sum(not hint.found for hint in new_hints)
|
||||||
found = 0
|
if not found_hints: # everything's been found, no need to pay
|
||||||
for hint in hints:
|
can_pay = True
|
||||||
found += 1 - hint.found
|
elif self.ctx.hint_cost:
|
||||||
if not found:
|
can_pay = points_available // (self.ctx.hint_cost * found_hints) >= 1
|
||||||
notify_hints(self.ctx, self.client.team, hints)
|
|
||||||
self.output("No new items found, no points deducted.")
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
if self.ctx.hint_cost:
|
|
||||||
can_pay = points_available // (self.ctx.hint_cost * found) >= 1
|
|
||||||
else:
|
else:
|
||||||
can_pay = True
|
can_pay = True
|
||||||
|
|
||||||
if can_pay:
|
if can_pay:
|
||||||
self.ctx.hints_used[self.client.team, self.client.slot] += found
|
self.ctx.hints_used[self.client.team, self.client.slot] += found_hints
|
||||||
|
|
||||||
for hint in hints:
|
for hint in new_hints:
|
||||||
|
if not hint.found:
|
||||||
self.ctx.hints[self.client.team, hint.finding_player].add(hint)
|
self.ctx.hints[self.client.team, hint.finding_player].add(hint)
|
||||||
self.ctx.hints[self.client.team, hint.receiving_player].add(hint)
|
self.ctx.hints[self.client.team, hint.receiving_player].add(hint)
|
||||||
notify_hints(self.ctx, self.client.team, hints)
|
notify_hints(self.ctx, self.client.team, list(new_hints))
|
||||||
save(self.ctx)
|
save(self.ctx)
|
||||||
else:
|
else:
|
||||||
notify_client(self.client, f"You can't afford the hint. "
|
notify_client(self.client, f"You can't afford the hint. "
|
||||||
|
|
3
Utils.py
3
Utils.py
|
@ -168,6 +168,9 @@ class Hint(typing.NamedTuple):
|
||||||
return Hint(self.receiving_player, self.finding_player, self.location, self.item, found)
|
return Hint(self.receiving_player, self.finding_player, self.location, self.item, found)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def __hash__(self):
|
||||||
|
return hash((self.receiving_player, self.finding_player, self.location, self.item))
|
||||||
|
|
||||||
def get_public_ipv4() -> str:
|
def get_public_ipv4() -> str:
|
||||||
import socket
|
import socket
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
Loading…
Reference in New Issue