From f0d5b564b54cfb2165dec9b546169f027667d95d Mon Sep 17 00:00:00 2001 From: jonny Date: Thu, 19 Dec 2024 18:44:19 +0900 Subject: [PATCH] add battlearena exception handle --- .../_Scripts/Blockchain/ActionManager.cs | 94 ++++++++++--------- .../UI/Widget/ArenaBattlePreparation.cs | 35 ++++--- 2 files changed, 72 insertions(+), 57 deletions(-) diff --git a/nekoyume/Assets/_Scripts/Blockchain/ActionManager.cs b/nekoyume/Assets/_Scripts/Blockchain/ActionManager.cs index cf97435dff1..1142fdc3fcc 100644 --- a/nekoyume/Assets/_Scripts/Blockchain/ActionManager.cs +++ b/nekoyume/Assets/_Scripts/Blockchain/ActionManager.cs @@ -958,54 +958,62 @@ public IObservable> BattleArena( int ticket ) { - var action = new BattleArena + try { - myAvatarAddress = States.Instance.CurrentAvatarState.address, - enemyAvatarAddress = enemyAvatarAddress, - costumes = costumes, - equipments = equipments, - runeInfos = runeInfos, - championshipId = championshipId, - round = round, - ticket = ticket - }; - - var sentryTrace = Analyzer.Instance.Track("Unity/BattleArena", - new Dictionary() + var action = new BattleArena { - ["championshipId"] = championshipId, - ["round"] = round, - ["enemyAvatarAddress"] = enemyAvatarAddress.ToString(), - ["AvatarAddress"] = States.Instance.CurrentAvatarState.address.ToString(), - ["AgentAddress"] = States.Instance.AgentState.address.ToString() - }, true); - - var evt = new AirbridgeEvent("BattleArena"); - evt.SetValue(championshipId); - evt.AddCustomAttribute("round", round); - evt.AddCustomAttribute("enemy-avatar-address", enemyAvatarAddress.ToString()); - evt.AddCustomAttribute("agent-address", States.Instance.CurrentAvatarState.address.ToString()); - evt.AddCustomAttribute("avatar-address", States.Instance.AgentState.address.ToString()); - AirbridgeUnity.TrackEvent(evt); + myAvatarAddress = States.Instance.CurrentAvatarState.address, + enemyAvatarAddress = enemyAvatarAddress, + costumes = costumes, + equipments = equipments, + runeInfos = runeInfos, + championshipId = championshipId, + round = round, + ticket = ticket + }; + + var sentryTrace = Analyzer.Instance.Track("Unity/BattleArena", + new Dictionary() + { + ["championshipId"] = championshipId, + ["round"] = round, + ["enemyAvatarAddress"] = enemyAvatarAddress.ToString(), + ["AvatarAddress"] = States.Instance.CurrentAvatarState.address.ToString(), + ["AgentAddress"] = States.Instance.AgentState.address.ToString() + }, true); + + var evt = new AirbridgeEvent("BattleArena"); + evt.SetValue(championshipId); + evt.AddCustomAttribute("round", round); + evt.AddCustomAttribute("enemy-avatar-address", enemyAvatarAddress.ToString()); + evt.AddCustomAttribute("agent-address", States.Instance.CurrentAvatarState.address.ToString()); + evt.AddCustomAttribute("avatar-address", States.Instance.AgentState.address.ToString()); + AirbridgeUnity.TrackEvent(evt); - action.PayCost(Game.Game.instance.Agent, States.Instance, TableSheets.Instance); - LocalLayerActions.Instance.Register(action.Id, action.PayCost, _agent.BlockIndex); - ProcessAction(action); - _lastBattleActionId = action.Id; - return _agent.ActionRenderer.EveryRender() - .Timeout(ActionTimeout) - .Where(eval => eval.Action.Id.Equals(action.Id)) - .First() - .ObserveOnMainThread() - .DoOnError(e => - { - if (_lastBattleActionId == action.Id) + action.PayCost(Game.Game.instance.Agent, States.Instance, TableSheets.Instance); + LocalLayerActions.Instance.Register(action.Id, action.PayCost, _agent.BlockIndex); + ProcessAction(action); + _lastBattleActionId = action.Id; + return _agent.ActionRenderer.EveryRender() + .Timeout(ActionTimeout) + .Where(eval => eval.Action.Id.Equals(action.Id)) + .First() + .ObserveOnMainThread() + .DoOnError(e => { - _lastBattleActionId = null; - } + if (_lastBattleActionId == action.Id) + { + _lastBattleActionId = null; + } - Game.Game.BackToMainAsync(HandleException(action.Id, e)).Forget(); - }).Finally(() => Analyzer.Instance.FinishTrace(sentryTrace)); + Game.Game.BackToMainAsync(HandleException(action.Id, e)).Forget(); + }).Finally(() => Analyzer.Instance.FinishTrace(sentryTrace)); + } + catch (Exception e) + { + Game.Game.BackToMainAsync(e).Forget(); + return null; + } } public IObservable> PatchTableSheet( diff --git a/nekoyume/Assets/_Scripts/UI/Widget/ArenaBattlePreparation.cs b/nekoyume/Assets/_Scripts/UI/Widget/ArenaBattlePreparation.cs index fe0da788eb8..c06e97f73b5 100644 --- a/nekoyume/Assets/_Scripts/UI/Widget/ArenaBattlePreparation.cs +++ b/nekoyume/Assets/_Scripts/UI/Widget/ArenaBattlePreparation.cs @@ -267,20 +267,27 @@ private void SendBattleArenaAction(int ticket = TicketCountToUse) _info.PortraitId, _info.AvatarAddr); - var costumes = States.Instance.CurrentItemSlotStates[BattleType.Arena].Costumes; - var equipments = States.Instance.CurrentItemSlotStates[BattleType.Arena].Equipments; - var runeInfos = States.Instance.CurrentRuneSlotStates[BattleType.Arena] - .GetEquippedRuneSlotInfos(); - ActionRenderHandler.Instance.Pending = true; - ActionManager.Instance.BattleArena( - _info.AvatarAddr, - costumes, - equipments, - runeInfos, - _roundData.ChampionshipId, - _roundData.Round, - ticket) - .Subscribe(); + try + { + var costumes = States.Instance.CurrentItemSlotStates[BattleType.Arena].Costumes; + var equipments = States.Instance.CurrentItemSlotStates[BattleType.Arena].Equipments; + var runeInfos = States.Instance.CurrentRuneSlotStates[BattleType.Arena] + .GetEquippedRuneSlotInfos(); + ActionRenderHandler.Instance.Pending = true; + ActionManager.Instance.BattleArena( + _info.AvatarAddr, + costumes, + equipments, + runeInfos, + _roundData.ChampionshipId, + _roundData.Round, + ticket) + .Subscribe(); + } + catch(Exception e) + { + Game.Game.BackToMainAsync(e).Forget(); + } } public void OnRenderBattleArena(ActionEvaluation eval)