Fix task issues

This commit is contained in:
CaitSith2 2021-11-11 12:32:42 -08:00
parent fd07bc3f2c
commit f26d2d5f20
1 changed files with 7 additions and 3 deletions

View File

@ -116,6 +116,7 @@ class Context(CommonContext):
self.snes_write_buffer = []
self.snes_connector_lock = threading.Lock()
self.death_state = DeathState.alive # for death link flop behaviour
self.killing_player_task = None
self.awaiting_rom = False
self.rom = None
@ -149,24 +150,27 @@ class Context(CommonContext):
}])
def on_deathlink(self, data: dict):
asyncio.create_task(deathlink_kill_player(self))
if not self.killing_player_task or self.killing_player_task.done():
self.killing_player_task = asyncio.create_task(deathlink_kill_player(self))
super(Context, self).on_deathlink(data)
async def deathlink_kill_player(ctx: Context):
ctx.death_state = DeathState.killing_player
while ctx.death_state == DeathState.killing_player:
while ctx.death_state == DeathState.killing_player and \
ctx.snes_state == SNESState.SNES_ATTACHED:
snes_buffered_write(ctx, WRAM_START + 0xF36D, bytes([0])) # set current health to 0
snes_buffered_write(ctx, WRAM_START + 0x0373, bytes([8])) # deal 1 full heart of damage at next opportunity
await snes_flush_writes(ctx)
await asyncio.sleep(1)
gamemode = await snes_read(ctx, WRAM_START + 0x10, 1)
if gamemode[0] in DEATH_MODES:
if not gamemode or gamemode[0] in DEATH_MODES:
ctx.death_state = DeathState.dead
ctx.last_death_link = time.time()
def color_item(item_id: int, green: bool = False) -> str:
item_name = get_item_name_from_id(item_id)
item_colors = ['green' if green else 'cyan']