Skip to content

Commit

Permalink
Merge pull request #5169 from planetarium/issue/5164
Browse files Browse the repository at this point in the history
fix refresh inventory after arena
  • Loading branch information
eugene-doobu authored Jun 25, 2024
2 parents 3c8d50d + 95e3925 commit fc9e000
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 46 deletions.
15 changes: 0 additions & 15 deletions nekoyume/Assets/_Scripts/Blockchain/ActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,6 @@ await UpdateCurrentAvatarStateAsync(
}
}

protected async UniTask UpdateCurrentAvatarStateAsync()
{
var avatarAddress = States.Instance.CurrentAvatarState.address;
var avatars =
await Game.Game.instance.Agent.GetAvatarStatesAsync(new[] { avatarAddress });
if (avatars.TryGetValue(avatarAddress, out var avatarState))
{
await UpdateCurrentAvatarStateAsync(avatarState);
}
else
{
NcDebug.LogError($"Failed to get AvatarState: {avatarAddress}");
}
}

protected static void UpdateCurrentAvatarInventory<T>(ActionEvaluation<T> eval)
where T : ActionBase
{
Expand Down
57 changes: 26 additions & 31 deletions nekoyume/Assets/_Scripts/Blockchain/ActionRenderHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2683,22 +2683,24 @@ private async void ResponseBattleArenaAsync(ActionEvaluation<BattleArena> eval)
await UniTask.WhenAll(RxProps.ArenaInfoTuple.UpdateAsync(eval.OutputState),
RxProps.ArenaInformationOrderedWithScore.UpdateAsync(eval.OutputState));

void OnBattleEnd()
{
UpdateAgentStateAsync(eval).Forget();
UpdateCurrentAvatarStateAsync(eval).Forget();
// TODO!!!! [`PlayersArenaParticipant`]를 개별로 업데이트 한다.
// RxProps.PlayersArenaParticipant.UpdateAsync().Forget();
_disposableForBattleEnd = null;
Game.Game.instance.Arena.IsAvatarStateUpdatedAfterBattle = true;
}

_disposableForBattleEnd?.Dispose();
_disposableForBattleEnd = Game.Game.instance.Arena.OnArenaEnd
.First()
.Subscribe(_ =>
{
UniTask.Run(() =>
{
UpdateAgentStateAsync(eval).Forget();
UpdateCurrentAvatarStateAsync().Forget();
// TODO!!!! [`PlayersArenaParticipant`]를 개별로 업데이트 한다.
// RxProps.PlayersArenaParticipant.UpdateAsync().Forget();
_disposableForBattleEnd = null;
Game.Game.instance.Arena.IsAvatarStateUpdatedAfterBattle = true;
}).ToObservable()
UniTask.RunOnThreadPool(OnBattleEnd)
.ToObservable()
.First()
// ReSharper disable once ConvertClosureToMethodGroup
.DoOnError(e => NcDebug.LogException(e));
});

Expand Down Expand Up @@ -2726,17 +2728,9 @@ await UniTask.WhenAll(RxProps.ArenaInfoTuple.UpdateAsync(eval.OutputState),
.First()
.Subscribe(_ =>
{
UniTask.RunOnThreadPool(() =>
{
UpdateAgentStateAsync(eval).Forget();
UpdateCurrentAvatarStateAsync().Forget();
// TODO!!!! [`PlayersArenaParticipant`]를 개별로 업데이트 한다.
// RxProps.PlayersArenaParticipant.UpdateAsync().Forget();
_disposableForBattleEnd = null;
Game.Game.instance.Arena.IsAvatarStateUpdatedAfterBattle = true;
}, configureAwait: false).ToObservable()
UniTask.RunOnThreadPool(OnBattleEnd, configureAwait: false)
.ToObservable()
.First()
// ReSharper disable once ConvertClosureToMethodGroup
.DoOnError(e => NcDebug.LogException(e));
});
previousMyScore = StateGetter.TryGetArenaScore(
Expand All @@ -2761,7 +2755,6 @@ await UniTask.WhenAll(RxProps.ArenaInfoTuple.UpdateAsync(eval.OutputState),
enemyCollectionState = StateGetter.GetCollectionState(eval.OutputState, eval.Action.enemyAvatarAddress);
}).ToObservable().ObserveOnMainThread();


prepareObserve.Subscribe(_ =>
{
var hasMedalReward =
Expand Down Expand Up @@ -2819,18 +2812,20 @@ await UniTask.WhenAll(RxProps.ArenaInfoTuple.UpdateAsync(eval.OutputState),
rewards.AddRange(reward);
}
if (arenaBattlePreparation && arenaBattlePreparation.IsActive())
if (!arenaBattlePreparation || !arenaBattlePreparation.IsActive())
{
arenaBattlePreparation.OnRenderBattleArena(eval);
Game.Game.instance.Arena.Enter(
logs.First(),
rewards,
myDigest.Value,
enemyDigest.Value,
eval.Action.myAvatarAddress,
eval.Action.enemyAvatarAddress,
winCount + defeatCount > 1 ? (winCount, defeatCount) : null);
return;
}
arenaBattlePreparation.OnRenderBattleArena(eval);
Game.Game.instance.Arena.Enter(
logs.First(),
rewards,
myDigest.Value,
enemyDigest.Value,
eval.Action.myAvatarAddress,
eval.Action.enemyAvatarAddress,
winCount + defeatCount > 1 ? (winCount, defeatCount) : null);
});
}

Expand Down
1 change: 1 addition & 0 deletions nekoyume/Assets/_Scripts/Game/Battle/Arena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class Arena : MonoBehaviour, IArena

public SkillController SkillController { get; private set; }
public BuffController BuffController { get; private set; }
// Only Changed on Thread Pool
public bool IsAvatarStateUpdatedAfterBattle { get; set; }
public int TurnNumber => _turnNumber;

Expand Down

0 comments on commit fc9e000

Please sign in to comment.