From e9ad895efae778c3ca83b77a7e95abbde3ba8c46 Mon Sep 17 00:00:00 2001 From: starknetdev Date: Wed, 4 Oct 2023 14:41:26 +0100 Subject: [PATCH] fix death screen on slay adventurer --- ui/src/app/lib/utils/syscalls.ts | 56 +++++++++++++++++++------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/ui/src/app/lib/utils/syscalls.ts b/ui/src/app/lib/utils/syscalls.ts index 0fc47dd40..6a7ca9f8d 100644 --- a/ui/src/app/lib/utils/syscalls.ts +++ b/ui/src/app/lib/utils/syscalls.ts @@ -1290,32 +1290,42 @@ export function syscalls({ (event) => event.name === "AdventurerDied" ); for (let adventurerDiedEvent of adventurerDiedEvents) { - setData("adventurerByIdQuery", { - adventurers: [adventurerDiedEvent.data[0]], - }); - const deadAdventurerIndex = - queryData.adventurersByOwnerQuery?.adventurers.findIndex( - (adventurer: any) => - adventurer.id == adventurerDiedEvent.data[0].id + if ( + adventurerDiedEvent.data[1].callerAddress === + adventurerDiedEvent.data[0].owner + ) { + setData("adventurerByIdQuery", { + adventurers: [adventurerDiedEvent.data[0]], + }); + const deadAdventurerIndex = + queryData.adventurersByOwnerQuery?.adventurers.findIndex( + (adventurer: any) => + adventurer.id == adventurerDiedEvent.data[0].id + ); + setData( + "adventurersByOwnerQuery", + 0, + "health", + deadAdventurerIndex ); - setData("adventurersByOwnerQuery", 0, "health", deadAdventurerIndex); - setAdventurer(adventurerDiedEvent.data[0]); - const killedByBeast = battles.some( - (battle) => - battle.attacker == "Beast" && battle.adventurerHealth == 0 - ); - // In a multicall someone can either die from swapping inventory or the death penalty. Here we handle those cases - if (killedByBeast) { - setDeathNotification( - "Multicall", - ["You equipped"], - adventurerDiedEvent.data[0] + setAdventurer(adventurerDiedEvent.data[0]); + const killedByBeast = battles.some( + (battle) => + battle.attacker == "Beast" && battle.adventurerHealth == 0 ); - } else { - setDeathNotification("Upgrade", "Death Penalty", []); + // In a multicall someone can either die from swapping inventory or the death penalty. Here we handle those cases + if (killedByBeast) { + setDeathNotification( + "Multicall", + ["You equipped"], + adventurerDiedEvent.data[0] + ); + } else { + setDeathNotification("Upgrade", "Death Penalty", []); + } + setScreen("start"); + setStartOption("create adventurer"); } - setScreen("start"); - setStartOption("create adventurer"); } setData("battlesByBeastQuery", {