some QOL
This commit is contained in:
parent
b755e9a9ee
commit
09fba10a53
2
Items.py
2
Items.py
|
@ -179,3 +179,5 @@ item_table = {'Bow': (True, False, None, 0x0B, 'You have\nchosen the\narcher cla
|
||||||
lookup_lower_name_to_id = {name.lower(): data[3] for name, data in item_table.items()}
|
lookup_lower_name_to_id = {name.lower(): data[3] for name, data in item_table.items()}
|
||||||
lookup_lower_name_to_name = {name.lower(): name for name in item_table}
|
lookup_lower_name_to_name = {name.lower(): name for name in item_table}
|
||||||
lookup_id_to_name = {data[3]: name for name, data in item_table.items()}
|
lookup_id_to_name = {data[3]: name for name, data in item_table.items()}
|
||||||
|
|
||||||
|
hint_blacklist = {"Triforce"}
|
|
@ -14,6 +14,10 @@ ModuleUpdate.update()
|
||||||
import colorama
|
import colorama
|
||||||
import websockets
|
import websockets
|
||||||
import aioconsole
|
import aioconsole
|
||||||
|
try:
|
||||||
|
import tqdm
|
||||||
|
except:
|
||||||
|
tqdm = None
|
||||||
|
|
||||||
import Items
|
import Items
|
||||||
import Regions
|
import Regions
|
||||||
|
@ -74,7 +78,7 @@ def color(text, *args):
|
||||||
return color_code(*args) + text + color_code('reset')
|
return color_code(*args) + text + color_code('reset')
|
||||||
|
|
||||||
|
|
||||||
RECONNECT_DELAY = 30
|
RECONNECT_DELAY = 5
|
||||||
|
|
||||||
ROM_START = 0x000000
|
ROM_START = 0x000000
|
||||||
WRAM_START = 0xF50000
|
WRAM_START = 0xF50000
|
||||||
|
@ -415,6 +419,10 @@ async def snes_connect(ctx : Context, address):
|
||||||
asyncio.create_task(snes_autoreconnect(ctx))
|
asyncio.create_task(snes_autoreconnect(ctx))
|
||||||
|
|
||||||
async def snes_autoreconnect(ctx: Context):
|
async def snes_autoreconnect(ctx: Context):
|
||||||
|
if tqdm:
|
||||||
|
for _ in tqdm.trange(100, unit='%', leave=False):
|
||||||
|
await asyncio.sleep(RECONNECT_DELAY/100)
|
||||||
|
else:
|
||||||
await asyncio.sleep(RECONNECT_DELAY)
|
await asyncio.sleep(RECONNECT_DELAY)
|
||||||
if ctx.snes_reconnect_address and ctx.snes_socket is None:
|
if ctx.snes_reconnect_address and ctx.snes_socket is None:
|
||||||
await snes_connect(ctx, ctx.snes_reconnect_address)
|
await snes_connect(ctx, ctx.snes_reconnect_address)
|
||||||
|
@ -601,6 +609,10 @@ async def server_loop(ctx : Context, address = None):
|
||||||
asyncio.create_task(server_autoreconnect(ctx))
|
asyncio.create_task(server_autoreconnect(ctx))
|
||||||
|
|
||||||
async def server_autoreconnect(ctx: Context):
|
async def server_autoreconnect(ctx: Context):
|
||||||
|
if tqdm:
|
||||||
|
for _ in tqdm.trange(100, unit='%', leave=False):
|
||||||
|
await asyncio.sleep(RECONNECT_DELAY/100)
|
||||||
|
else:
|
||||||
await asyncio.sleep(RECONNECT_DELAY)
|
await asyncio.sleep(RECONNECT_DELAY)
|
||||||
if ctx.server_address and ctx.server_task is None:
|
if ctx.server_address and ctx.server_task is None:
|
||||||
ctx.server_task = asyncio.create_task(server_loop(ctx))
|
ctx.server_task = asyncio.create_task(server_loop(ctx))
|
||||||
|
|
|
@ -57,13 +57,15 @@ class Context:
|
||||||
self.location_checks = collections.defaultdict(set)
|
self.location_checks = collections.defaultdict(set)
|
||||||
self.hint_cost = hint_cost
|
self.hint_cost = hint_cost
|
||||||
self.location_check_points = location_check_points
|
self.location_check_points = location_check_points
|
||||||
self.hints_used = collections.defaultdict(lambda: 0)
|
self.hints_used = collections.defaultdict(int)
|
||||||
|
self.hints_sent = collections.defaultdict(set)
|
||||||
|
|
||||||
def get_save(self) -> dict:
|
def get_save(self) -> dict:
|
||||||
return {
|
return {
|
||||||
"rom_names": list(self.rom_names.items()),
|
"rom_names": list(self.rom_names.items()),
|
||||||
"received_items": tuple((k, [i.__dict__ for i in v]) for k, v in self.received_items.items()),
|
"received_items": tuple((k, [i.__dict__ for i in 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_sent" : tuple((key,tuple(value)) for key, value in self.hints_sent.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())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +76,7 @@ class Context:
|
||||||
raise Exception('Save file mismatch, will start a new game')
|
raise Exception('Save file mismatch, will start a new game')
|
||||||
self.received_items = received_items
|
self.received_items = received_items
|
||||||
self.hints_used.update({tuple(key): value for key, value in savedata["hints_used"]})
|
self.hints_used.update({tuple(key): value for key, value in savedata["hints_used"]})
|
||||||
|
self.hints_sent.update({tuple(key): set(value) for key, value in savedata["hints_sent"]})
|
||||||
self.location_checks.update({tuple(key): set(value) for key, value in savedata["location_checks"]})
|
self.location_checks.update({tuple(key): set(value) for key, value in savedata["location_checks"]})
|
||||||
logging.info(f'Loaded save file with {sum([len(p) for p in received_items.values()])} received items '
|
logging.info(f'Loaded save file with {sum([len(p) for p in received_items.values()])} received items '
|
||||||
f'for {len(received_items)} players')
|
f'for {len(received_items)} players')
|
||||||
|
@ -410,21 +413,34 @@ async def process_client_cmd(ctx: Context, client: Client, cmd, args):
|
||||||
"for example !hint Lamp or !hint Link's House. "
|
"for example !hint Lamp or !hint Link's House. "
|
||||||
f"A hint costs {ctx.hint_cost} points. "
|
f"A hint costs {ctx.hint_cost} points. "
|
||||||
f"You have {points_available} points.")
|
f"You have {points_available} points.")
|
||||||
|
for item_name in ctx.hints_sent[client.team, client.slot]:
|
||||||
|
if item_name in Items.item_table: # item name
|
||||||
|
hints = collect_hints(ctx, client.team, client.slot, item_name)
|
||||||
|
else: # location name
|
||||||
|
hints = collect_hints_location(ctx, client.team, client.slot, item_name)
|
||||||
|
notify_hints(ctx, client.team, hints)
|
||||||
else:
|
else:
|
||||||
item_name, usable, response = get_intended_text(item_name)
|
item_name, usable, response = get_intended_text(item_name)
|
||||||
if usable:
|
if usable:
|
||||||
if item_name in Items.item_table: # item name
|
if item_name in Items.hint_blacklist:
|
||||||
|
notify_client(client, f"Sorry, \"{item_name}\" is marked as non-hintable.")
|
||||||
|
hints = []
|
||||||
|
elif item_name in Items.item_table: # item name
|
||||||
hints = collect_hints(ctx, client.team, client.slot, item_name)
|
hints = collect_hints(ctx, client.team, client.slot, item_name)
|
||||||
else: # location name
|
else: # location name
|
||||||
hints = collect_hints_location(ctx, client.team, client.slot, item_name)
|
hints = collect_hints_location(ctx, client.team, client.slot, item_name)
|
||||||
|
|
||||||
if hints:
|
if hints:
|
||||||
|
if item_name in ctx.hints_sent[client.team, client.slot]:
|
||||||
|
notify_hints(ctx, client.team, hints)
|
||||||
|
notify_client(client, "Hint was previously used, no points deducted.")
|
||||||
|
else:
|
||||||
found = 0
|
found = 0
|
||||||
for hint in hints:
|
for hint in hints:
|
||||||
found += 1 - hint.found
|
found += 1 - hint.found
|
||||||
if not found:
|
if not found:
|
||||||
notify_hints(ctx, client.team, hints)
|
notify_hints(ctx, client.team, hints)
|
||||||
notify_client(client, "No new items found, points refunded.")
|
notify_client(client, "No new items found, no points deducted.")
|
||||||
else:
|
else:
|
||||||
if ctx.hint_cost:
|
if ctx.hint_cost:
|
||||||
can_pay = points_available // (ctx.hint_cost * found) >= 1
|
can_pay = points_available // (ctx.hint_cost * found) >= 1
|
||||||
|
@ -433,6 +449,7 @@ async def process_client_cmd(ctx: Context, client: Client, cmd, args):
|
||||||
|
|
||||||
if can_pay:
|
if can_pay:
|
||||||
ctx.hints_used[client.team, client.slot] += found
|
ctx.hints_used[client.team, client.slot] += found
|
||||||
|
ctx.hints_sent[client.team, client.slot].add(item_name)
|
||||||
notify_hints(ctx, client.team, hints)
|
notify_hints(ctx, client.team, hints)
|
||||||
save(ctx)
|
save(ctx)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue