Skip to content

Commit

Permalink
add battlearena exception handle
Browse files Browse the repository at this point in the history
  • Loading branch information
jonny-jeahyunchoi committed Dec 19, 2024
1 parent 2840c53 commit f0d5b56
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 57 deletions.
94 changes: 51 additions & 43 deletions nekoyume/Assets/_Scripts/Blockchain/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -958,54 +958,62 @@ public IObservable<ActionEvaluation<BattleArena>> 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<string, Value>()
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<string, Value>()
{
["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<BattleArena>()
.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<BattleArena>()
.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<ActionEvaluation<PatchTableSheet>> PatchTableSheet(
Expand Down
35 changes: 21 additions & 14 deletions nekoyume/Assets/_Scripts/UI/Widget/ArenaBattlePreparation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BattleArena> eval)
Expand Down

0 comments on commit f0d5b56

Please sign in to comment.