From 19c4ed982f35e91ee8ab309f2f68edf04fe6f0e5 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Mon, 24 Jun 2024 17:46:07 +0900 Subject: [PATCH] Delete item layer in render & mail read --- .../Blockchain/ActionRenderHandler.cs | 29 --- .../_Scripts/State/LocalLayerModifier.cs | 40 +--- .../_Scripts/UI/Widget/Popup/MailPopup.cs | 183 ++++-------------- 3 files changed, 40 insertions(+), 212 deletions(-) diff --git a/nekoyume/Assets/_Scripts/Blockchain/ActionRenderHandler.cs b/nekoyume/Assets/_Scripts/Blockchain/ActionRenderHandler.cs index 3f9091a49d..e4dacc8e3a 100644 --- a/nekoyume/Assets/_Scripts/Blockchain/ActionRenderHandler.cs +++ b/nekoyume/Assets/_Scripts/Blockchain/ActionRenderHandler.cs @@ -1014,11 +1014,6 @@ private void ResponseCombinationEquipment( result.gold); }); - LocalLayerModifier.RemoveItem( - avatarAddress, - result.itemUsable.ItemId, - result.itemUsable.RequiredBlockIndex, - 1); LocalLayerModifier.AddNewAttachmentMail(avatarAddress, result.id); var tableSheets = Game.Game.instance.TableSheets; @@ -1189,11 +1184,6 @@ private void ResponseCombinationConsumable( result.gold); }); - LocalLayerModifier.RemoveItem( - avatarAddress, - result.itemUsable.ItemId, - result.itemUsable.RequiredBlockIndex, - 1); LocalLayerModifier.AddNewAttachmentMail(avatarAddress, result.id); RenderQuest(avatarAddress, renderArgs.AvatarState.questList.completedQuestIds); @@ -1246,11 +1236,6 @@ private void ResponseEventConsumableItemCrafts( result.gold); }); - LocalLayerModifier.RemoveItem( - avatarAddress, - itemUsable.ItemId, - itemUsable.RequiredBlockIndex, - 1); LocalLayerModifier.AddNewAttachmentMail(avatarAddress, result.id); // Notify @@ -1389,20 +1374,6 @@ private void ResponseItemEnhancement( } } - if (itemUsable.ItemSubType == ItemSubType.Aura) - { - //Because aura is a tradable item, local removal or add fails and an exception is handled. - LocalLayerModifier.RemoveNonFungibleItem(avatarAddress, itemUsable.ItemId); - } - else - { - LocalLayerModifier.RemoveItem( - avatarAddress, - itemUsable.ItemId, - itemUsable.RequiredBlockIndex, - 1); - } - LocalLayerModifier.AddNewAttachmentMail(avatarAddress, result.id); RenderQuest(avatarAddress, renderArgs.AvatarState.questList.completedQuestIds); diff --git a/nekoyume/Assets/_Scripts/State/LocalLayerModifier.cs b/nekoyume/Assets/_Scripts/State/LocalLayerModifier.cs index 1cd64a0989..2b1dd6a3a6 100644 --- a/nekoyume/Assets/_Scripts/State/LocalLayerModifier.cs +++ b/nekoyume/Assets/_Scripts/State/LocalLayerModifier.cs @@ -351,56 +351,24 @@ long blockIndex /// /// /// - /// - public static async void RemoveNewAttachmentMail( + public static void RemoveNewAttachmentMail( Address avatarAddress, - Guid mailId, - bool resetState = true) + Guid mailId) { UnityEngine.Debug.Log($"[MailRead] RemoveNewAttachmentMail mailid : {mailId}"); var modifier = new AvatarAttachmentMailNewSetter(mailId); LocalLayer.Instance.Remove(avatarAddress, modifier); - - if (!resetState) - { - return; - } - - await TryResetLoadedAvatarState(avatarAddress); } - public static async void RemoveNewMail( + public static void RemoveNewMail( Address avatarAddress, - Guid mailId, - bool resetState = true) + Guid mailId) { UnityEngine.Debug.Log($"[MailRead] RemoveNewMail mailid : {mailId}"); var modifier = new AvatarMailNewSetter(mailId); LocalLayer.Instance.Remove(avatarAddress, modifier); - - if (!resetState) - { - return; - } - - await TryResetLoadedAvatarState(avatarAddress); } - public static async void RemoveAttachmentResult( - Address avatarAddress, - Guid mailId, - bool resetState = true) - { - var resultModifier = new AvatarAttachmentMailResultSetter(mailId); - LocalLayer.Instance.Remove(avatarAddress, resultModifier); - - if (!resetState) - { - return; - } - - await TryResetLoadedAvatarState(avatarAddress); - } #endregion #region Avatar / Quest diff --git a/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs b/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs index 203112ab36..86f5509159 100644 --- a/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs +++ b/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs @@ -121,7 +121,6 @@ private async void ReceiveAll() continue; } - var resetState = currentBlockIndex > mail.blockIndex; switch (mail) { case OrderBuyerMail: @@ -133,11 +132,11 @@ private async void ReceiveAll() case ProductCancelMail: case UnloadFromMyGaragesRecipientMail: case ClaimItemsMail: - LocalLayerModifier.RemoveNewMail(avatarAddress, mail.id, resetState); + LocalLayerModifier.RemoveNewMail(avatarAddress, mail.id); break; case ItemEnhanceMail: case CombinationMail: - LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, mail.id, resetState); + LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, mail.id); break; } } @@ -151,7 +150,6 @@ private async void ReceiveAll() private static async Task AddRewards(Mail mail, List mailRewards) { var avatarAddress = States.Instance.CurrentAvatarState.address; - bool resetState = Game.Game.instance.Agent.BlockIndex > mail.blockIndex; switch (mail) { case ProductBuyerMail productBuyerMail: @@ -235,12 +233,6 @@ private static async Task AddRewards(Mail mail, List mailRewards) if (cItem is not null) { mailRewards.Add(new MailReward(cItem, 1)); - LocalLayerModifier.AddItem( - avatarAddress, - cItem.ItemId, - cItem.RequiredBlockIndex, - 1, - resetState); } break; @@ -249,23 +241,6 @@ private static async Task AddRewards(Mail mail, List mailRewards) if (eItem is not null) { mailRewards.Add(new MailReward(eItem, 1)); - if (eItem.ItemSubType == ItemSubType.Aura) - { - //Because aura is a tradable item, local removal fails and an exception is handled. - LocalLayerModifier.AddNonFungibleItem( - avatarAddress, - eItem.ItemId, - resetState); - } - else - { - LocalLayerModifier.AddItem( - avatarAddress, - eItem.ItemId, - eItem.RequiredBlockIndex, - 1, - resetState); - } } break; case UnloadFromMyGaragesRecipientMail unloadFromMyGaragesRecipientMail: @@ -497,26 +472,9 @@ public void Read(CombinationMail mail) } var avatarAddress = States.Instance.CurrentAvatarState.address; - - // LocalLayer - UniTask.Run(async () => - { - LocalLayerModifier.AddItem( - avatarAddress, - itemUsable.ItemId, - itemUsable.RequiredBlockIndex, - 1, - false); - LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, mail.id, false); - return (await Game.Game.instance.Agent.GetAvatarStatesAsync( - new[] { avatarAddress }))[avatarAddress]; - }).ToObservable().SubscribeOnMainThread().Subscribe(async avatarState => - { - NcDebug.Log("CombinationMail LocalLayer task completed"); - await States.Instance.AddOrReplaceAvatarStateAsync(avatarState, - States.Instance.CurrentAvatarKey); - }); - // ~LocalLayer + LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, mail.id); + NcDebug.Log("CombinationMail LocalLayer task completed"); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); if (mail.attachment is CombinationConsumable5.ResultModel resultModel) { @@ -542,8 +500,6 @@ public async void Read(OrderBuyerMail orderBuyerMail) await Util.GetItemBaseByTradableId(order.TradableId, order.ExpiredBlockIndex); var count = order is FungibleOrder fungibleOrder ? fungibleOrder.ItemCount : 1; var popup = Find(); - var currentBlockIndex = Game.Game.instance.Agent.BlockIndex; - bool resetState = currentBlockIndex > orderBuyerMail.blockIndex; var model = new UI.Model.BuyItemInformationPopup(new CountableItem(itemBase, count)) { isSuccess = true, @@ -551,9 +507,8 @@ public async void Read(OrderBuyerMail orderBuyerMail) }; model.OnClickSubmit.Subscribe(_ => { - LocalLayerModifier.AddItem(avatarAddress, order.TradableId, order.ExpiredBlockIndex, - count, false); - LocalLayerModifier.RemoveNewMail(avatarAddress, orderBuyerMail.id, resetState); + LocalLayerModifier.RemoveNewMail(avatarAddress, orderBuyerMail.id); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); }).AddTo(gameObject); popup.Pop(model); } @@ -564,19 +519,21 @@ public async void Read(OrderSellerMail orderSellerMail) var agentAddress = States.Instance.AgentState.address; var order = await Util.GetOrder(orderSellerMail.OrderId); var taxedPrice = order.Price - order.GetTax(); - var currentBlockIndex = Game.Game.instance.Agent.BlockIndex; LocalLayerModifier.ModifyAgentGoldAsync(agentAddress, taxedPrice).Forget(); - LocalLayerModifier.RemoveNewMail(avatarAddress, orderSellerMail.id, currentBlockIndex > orderSellerMail.blockIndex); + LocalLayerModifier.RemoveNewMail(avatarAddress, orderSellerMail.id); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); } public void Read(GrindingMail grindingMail) { NcDebug.Log($"[{nameof(GrindingMail)}] ItemCount: {grindingMail.ItemCount}, Asset: {grindingMail.Asset}"); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); } public void Read(MaterialCraftMail materialCraftMail) { NcDebug.Log($"[{nameof(MaterialCraftMail)}] ItemCount: {materialCraftMail.ItemCount}, ItemId: {materialCraftMail.ItemId}"); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); } public async void Read(ProductBuyerMail productBuyerMail) @@ -584,8 +541,6 @@ public async void Read(ProductBuyerMail productBuyerMail) var avatarAddress = States.Instance.CurrentAvatarState.address; var productId = productBuyerMail.ProductId; var (_, itemProduct, favProduct) = await Game.Game.instance.MarketServiceClient.GetProductInfo(productId); - var currentBlockIndex = Game.Game.instance.Agent.BlockIndex; - bool resetState = currentBlockIndex > productBuyerMail.blockIndex; if (itemProduct is not null) { var count = (int)itemProduct.Quantity; @@ -605,7 +560,8 @@ public async void Read(ProductBuyerMail productBuyerMail) model.OnClickSubmit.Subscribe(_ => { - LocalLayerModifier.RemoveNewMail(avatarAddress, productBuyerMail.id, resetState); + LocalLayerModifier.RemoveNewMail(avatarAddress, productBuyerMail.id); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); }).AddTo(gameObject); Find().Pop(model); } @@ -616,7 +572,11 @@ public async void Read(ProductBuyerMail productBuyerMail) var fav = new FungibleAssetValue(currency, (int)favProduct.Quantity, 0); Find().Show( fav, - () => LocalLayerModifier.RemoveNewMail(avatarAddress, productBuyerMail.id, resetState)); + () => + { + LocalLayerModifier.RemoveNewMail(avatarAddress, productBuyerMail.id); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); + }); } } @@ -629,57 +589,45 @@ public async void Read(ProductSellerMail productSellerMail) var price = itemProduct?.Price ?? favProduct.Price; var fav = new FungibleAssetValue(currency, (int)price, 0); var taxedPrice = fav.DivRem(100, out _) * Action.Buy.TaxRate; - var currentBlockIndex = Game.Game.instance.Agent.BlockIndex; - bool resetState = currentBlockIndex > productSellerMail.blockIndex; LocalLayerModifier.ModifyAgentGoldAsync(agentAddress, taxedPrice).Forget(); - LocalLayerModifier.RemoveNewMail(avatarAddress, productSellerMail.id, resetState); + LocalLayerModifier.RemoveNewMail(avatarAddress, productSellerMail.id); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); } public void Read(ProductCancelMail productCancelMail) { var avatarAddress = States.Instance.CurrentAvatarState.address; - var currentBlockIndex = Game.Game.instance.Agent.BlockIndex; - bool resetState = currentBlockIndex > productCancelMail.blockIndex; Find().Show(L10nManager.Localize("UI_SELL_CANCEL_INFO"), L10nManager.Localize("UI_YES"), () => { - LocalLayerModifier.RemoveNewMail(avatarAddress, productCancelMail.id, resetState); + LocalLayerModifier.RemoveNewMail(avatarAddress, productCancelMail.id); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); ReactiveShopState.SetSellProducts(); }); } - public async void Read(OrderExpirationMail orderExpirationMail) + public void Read(OrderExpirationMail orderExpirationMail) { var avatarAddress = States.Instance.CurrentAvatarState.address; - var order = await Util.GetOrder(orderExpirationMail.OrderId); - var currentBlockIndex = Game.Game.instance.Agent.BlockIndex; - bool resetState = currentBlockIndex > orderExpirationMail.blockIndex; - Find().Show(L10nManager.Localize("UI_SELL_CANCEL_INFO"), L10nManager.Localize("UI_YES"), () => { - LocalLayerModifier.AddItem(avatarAddress, order.TradableId, - order.ExpiredBlockIndex, 1, false); - LocalLayerModifier.RemoveNewMail(avatarAddress, orderExpirationMail.id, resetState); + LocalLayerModifier.RemoveNewMail(avatarAddress, orderExpirationMail.id); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); }); } - public async void Read(CancelOrderMail cancelOrderMail) + public void Read(CancelOrderMail cancelOrderMail) { var avatarAddress = States.Instance.CurrentAvatarState.address; - var order = await Util.GetOrder(cancelOrderMail.OrderId); - var currentBlockIndex = Game.Game.instance.Agent.BlockIndex; - bool resetState = currentBlockIndex > cancelOrderMail.blockIndex; - Find().Show(L10nManager.Localize("UI_SELL_CANCEL_INFO"), L10nManager.Localize("UI_YES"), () => { - LocalLayerModifier.AddItem(avatarAddress, order.TradableId, - order.ExpiredBlockIndex, 1, false); - LocalLayerModifier.RemoveNewMail(avatarAddress, cancelOrderMail.id, resetState); + LocalLayerModifier.RemoveNewMail(avatarAddress, cancelOrderMail.id); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); ReactiveShopState.SetSellProducts(); }); } @@ -687,8 +635,6 @@ public async void Read(CancelOrderMail cancelOrderMail) public void Read(ItemEnhanceMail itemEnhanceMail) { var itemUsable = itemEnhanceMail?.attachment?.itemUsable; - var currentBlockIndex = Game.Game.instance.Agent.BlockIndex; - bool resetState = currentBlockIndex > itemEnhanceMail.blockIndex; if (itemUsable is null) { NcDebug.LogError("ItemEnhanceMail.itemUsable is null"); @@ -707,33 +653,11 @@ await LocalLayerModifier.ModifyAgentCrystalAsync( result.CRYSTAL.MajorUnit); } - if (itemUsable.ItemSubType == ItemSubType.Aura) - { - //Because aura is a tradable item, local removal fails and an exception is handled. - LocalLayerModifier.AddNonFungibleItem( - avatarAddress, - itemUsable.ItemId, - resetState); - } - else - { - LocalLayerModifier.AddItem( - avatarAddress, - itemUsable.ItemId, - itemUsable.RequiredBlockIndex, - 1, - resetState); - } - - LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, itemEnhanceMail.id, - false); - return (await Game.Game.instance.Agent.GetAvatarStatesAsync( - new[] { avatarAddress }))[avatarAddress]; - }).ToObservable().SubscribeOnMainThread().Subscribe(async avatarState => + LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, itemEnhanceMail.id); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); + }).ToObservable().SubscribeOnMainThread().Subscribe(_ => { NcDebug.Log("ItemEnhanceMail LocalLayer task completed"); - await States.Instance.AddOrReplaceAvatarStateAsync(avatarState, - States.Instance.CurrentAvatarKey); }); // ~LocalLayer @@ -756,40 +680,9 @@ public void Read(MonsterCollectionMail monsterCollectionMail) var popup = Find(); popup.OnClickSubmit.First().Subscribe(widget => { - // LocalLayer - for (var i = 0; i < monsterCollectionResult.rewards.Count; i++) - { - var rewardInfo = monsterCollectionResult.rewards[i]; - if (!rewardInfo.ItemId.TryParseAsTradableId( - Game.Game.instance.TableSheets.ItemSheet, - out var tradableId)) - { - continue; - } - - - if (!rewardInfo.ItemId.TryGetFungibleId( - Game.Game.instance.TableSheets.ItemSheet, - out var fungibleId)) - { - continue; - } - - var avatarState = States.Instance.CurrentAvatarState; - avatarState.inventory.TryGetFungibleItems(fungibleId, out var items); - var item = items.FirstOrDefault(x => x.item is ITradableItem); - if (item != null && item is ITradableItem tradableItem) - { - LocalLayerModifier.AddItem(monsterCollectionResult.avatarAddress, - tradableId, - tradableItem.RequiredBlockIndex, - rewardInfo.Quantity, false); - } - } - LocalLayerModifier.RemoveNewAttachmentMail(monsterCollectionResult.avatarAddress, - monsterCollectionMail.id, false); - // ~LocalLayer + monsterCollectionMail.id); + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); widget.Close(); }); @@ -799,6 +692,7 @@ public void Read(MonsterCollectionMail monsterCollectionMail) public void Read(RaidRewardMail raidRewardMail) { raidRewardMail.New = false; + ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); NcDebug.Log($"[MailRead] MailPopupReadRaidRewardMail mailid : {raidRewardMail.id}"); } @@ -812,12 +706,9 @@ public void Read(UnloadFromMyGaragesRecipientMail unloadFromMyGaragesRecipientMa var game = Game.Game.instance; unloadFromMyGaragesRecipientMail.New = false; - var currentBlockIndex = Game.Game.instance.Agent.BlockIndex; - bool resetState = currentBlockIndex > unloadFromMyGaragesRecipientMail.blockIndex; LocalLayerModifier.RemoveNewMail( game.States.CurrentAvatarState.address, - unloadFromMyGaragesRecipientMail.id, - resetState); + unloadFromMyGaragesRecipientMail.id); ReactiveAvatarState.UpdateMailBox(game.States.CurrentAvatarState.mailBox); NcDebug.Log($"[MailRead] MailPopupReadUnloadFromMyGaragesRecipientMail mailid : {unloadFromMyGaragesRecipientMail.id} Memo : {unloadFromMyGaragesRecipientMail.Memo}"); @@ -945,11 +836,9 @@ public void Read(ClaimItemsMail claimItemsMail) var game = Game.Game.instance; claimItemsMail.New = false; - var currentBlockIndex = Game.Game.instance.Agent.BlockIndex; - bool resetState = currentBlockIndex > claimItemsMail.blockIndex; LocalLayerModifier.RemoveNewMail( game.States.CurrentAvatarState.address, - claimItemsMail.id, resetState); + claimItemsMail.id); ReactiveAvatarState.UpdateMailBox(game.States.CurrentAvatarState.mailBox); NcDebug.Log($"[MailRead] MailPopupReadClaimItemsMail mailid : {claimItemsMail.id} Memo : {claimItemsMail.Memo}");