From b41c90f15f02a60e3188c8881e5dfecb149f5e94 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Fri, 21 Jun 2024 16:09:07 +0900 Subject: [PATCH 1/6] Fix reset state in renderer --- nekoyume/Assets/_Scripts/Blockchain/ActionRenderHandler.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nekoyume/Assets/_Scripts/Blockchain/ActionRenderHandler.cs b/nekoyume/Assets/_Scripts/Blockchain/ActionRenderHandler.cs index a05fe4d779..3f9091a49d 100644 --- a/nekoyume/Assets/_Scripts/Blockchain/ActionRenderHandler.cs +++ b/nekoyume/Assets/_Scripts/Blockchain/ActionRenderHandler.cs @@ -1640,7 +1640,8 @@ private async void ResponseCancelProductRegistrationAsync( { var row = Game.Game.instance.TableSheets.MaterialItemSheet.Values .First(r => r.ItemSubType == ItemSubType.ApStone); - LocalLayerModifier.AddItem(eval.Action.AvatarAddress, row.ItemId); + // 액션을 스테이징한 시점에 미리 반영해둔 아이템의 레이어를 먼저 제거하고, 액션의 결과로 나온 실제 상태를 반영 + LocalLayerModifier.AddItem(eval.Action.AvatarAddress, row.ItemId, 1, false); } if (GameConfigStateSubject.ActionPointState.ContainsKey(eval.Action.AvatarAddress)) @@ -1716,7 +1717,8 @@ private async void ResponseReRegisterProduct(ActionEvaluation { var row = Game.Game.instance.TableSheets.MaterialItemSheet.Values .First(r => r.ItemSubType == ItemSubType.ApStone); - LocalLayerModifier.AddItem(eval.Action.AvatarAddress, row.ItemId); + // 액션을 스테이징한 시점에 미리 반영해둔 아이템의 레이어를 먼저 제거하고, 액션의 결과로 나온 실제 상태를 반영 + LocalLayerModifier.AddItem(eval.Action.AvatarAddress, row.ItemId, 1, false); } if (GameConfigStateSubject.ActionPointState.ContainsKey(eval.Action.AvatarAddress)) From 52e5e51fc70a89f9e8c0b574cc21c4e01d5648ab Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Fri, 21 Jun 2024 16:59:09 +0900 Subject: [PATCH 2/6] ResetState check blockIndex in mail --- .../_Scripts/UI/Widget/Popup/MailPopup.cs | 66 ++++++++++++------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs b/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs index 07cd1d9a39..203112ab36 100644 --- a/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs +++ b/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs @@ -121,6 +121,7 @@ private async void ReceiveAll() continue; } + var resetState = currentBlockIndex > mail.blockIndex; switch (mail) { case OrderBuyerMail: @@ -132,11 +133,11 @@ private async void ReceiveAll() case ProductCancelMail: case UnloadFromMyGaragesRecipientMail: case ClaimItemsMail: - LocalLayerModifier.RemoveNewMail(avatarAddress, mail.id, true); + LocalLayerModifier.RemoveNewMail(avatarAddress, mail.id, resetState); break; case ItemEnhanceMail: case CombinationMail: - LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, mail.id, true); + LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, mail.id, resetState); break; } } @@ -150,6 +151,7 @@ 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: @@ -238,7 +240,7 @@ private static async Task AddRewards(Mail mail, List mailRewards) cItem.ItemId, cItem.RequiredBlockIndex, 1, - false); + resetState); } break; @@ -253,7 +255,7 @@ private static async Task AddRewards(Mail mail, List mailRewards) LocalLayerModifier.AddNonFungibleItem( avatarAddress, eItem.ItemId, - false); + resetState); } else { @@ -262,7 +264,7 @@ private static async Task AddRewards(Mail mail, List mailRewards) eItem.ItemId, eItem.RequiredBlockIndex, 1, - false); + resetState); } } break; @@ -540,6 +542,8 @@ 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, @@ -548,8 +552,8 @@ public async void Read(OrderBuyerMail orderBuyerMail) model.OnClickSubmit.Subscribe(_ => { LocalLayerModifier.AddItem(avatarAddress, order.TradableId, order.ExpiredBlockIndex, - count); - LocalLayerModifier.RemoveNewMail(avatarAddress, orderBuyerMail.id, true); + count, false); + LocalLayerModifier.RemoveNewMail(avatarAddress, orderBuyerMail.id, resetState); }).AddTo(gameObject); popup.Pop(model); } @@ -560,8 +564,9 @@ 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); + LocalLayerModifier.RemoveNewMail(avatarAddress, orderSellerMail.id, currentBlockIndex > orderSellerMail.blockIndex); } public void Read(GrindingMail grindingMail) @@ -579,6 +584,8 @@ 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; @@ -598,7 +605,7 @@ public async void Read(ProductBuyerMail productBuyerMail) model.OnClickSubmit.Subscribe(_ => { - LocalLayerModifier.RemoveNewMail(avatarAddress, productBuyerMail.id, true); + LocalLayerModifier.RemoveNewMail(avatarAddress, productBuyerMail.id, resetState); }).AddTo(gameObject); Find().Pop(model); } @@ -609,7 +616,7 @@ public async void Read(ProductBuyerMail productBuyerMail) var fav = new FungibleAssetValue(currency, (int)favProduct.Quantity, 0); Find().Show( fav, - () => LocalLayerModifier.RemoveNewMail(avatarAddress, productBuyerMail.id, true)); + () => LocalLayerModifier.RemoveNewMail(avatarAddress, productBuyerMail.id, resetState)); } } @@ -622,18 +629,22 @@ 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); + LocalLayerModifier.RemoveNewMail(avatarAddress, productSellerMail.id, resetState); } 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); + LocalLayerModifier.RemoveNewMail(avatarAddress, productCancelMail.id, resetState); ReactiveShopState.SetSellProducts(); }); } @@ -642,14 +653,16 @@ public async 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); - LocalLayerModifier.RemoveNewMail(avatarAddress, orderExpirationMail.id); + order.ExpiredBlockIndex, 1, false); + LocalLayerModifier.RemoveNewMail(avatarAddress, orderExpirationMail.id, resetState); }); } @@ -657,14 +670,16 @@ public async 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); - LocalLayerModifier.RemoveNewMail(avatarAddress, cancelOrderMail.id); + order.ExpiredBlockIndex, 1, false); + LocalLayerModifier.RemoveNewMail(avatarAddress, cancelOrderMail.id, resetState); ReactiveShopState.SetSellProducts(); }); } @@ -672,6 +687,8 @@ 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"); @@ -696,7 +713,7 @@ await LocalLayerModifier.ModifyAgentCrystalAsync( LocalLayerModifier.AddNonFungibleItem( avatarAddress, itemUsable.ItemId, - false); + resetState); } else { @@ -705,7 +722,7 @@ await LocalLayerModifier.ModifyAgentCrystalAsync( itemUsable.ItemId, itemUsable.RequiredBlockIndex, 1, - false); + resetState); } LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, itemEnhanceMail.id, @@ -766,12 +783,12 @@ public void Read(MonsterCollectionMail monsterCollectionMail) LocalLayerModifier.AddItem(monsterCollectionResult.avatarAddress, tradableId, tradableItem.RequiredBlockIndex, - rewardInfo.Quantity); + rewardInfo.Quantity, false); } } LocalLayerModifier.RemoveNewAttachmentMail(monsterCollectionResult.avatarAddress, - monsterCollectionMail.id, true); + monsterCollectionMail.id, false); // ~LocalLayer widget.Close(); @@ -795,9 +812,12 @@ 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); + unloadFromMyGaragesRecipientMail.id, + resetState); ReactiveAvatarState.UpdateMailBox(game.States.CurrentAvatarState.mailBox); NcDebug.Log($"[MailRead] MailPopupReadUnloadFromMyGaragesRecipientMail mailid : {unloadFromMyGaragesRecipientMail.id} Memo : {unloadFromMyGaragesRecipientMail.Memo}"); @@ -925,9 +945,11 @@ 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); + claimItemsMail.id, resetState); ReactiveAvatarState.UpdateMailBox(game.States.CurrentAvatarState.mailBox); NcDebug.Log($"[MailRead] MailPopupReadClaimItemsMail mailid : {claimItemsMail.id} Memo : {claimItemsMail.Memo}"); From f443cca1afa69d719f93d2a11a7b2f916df44c1d Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Fri, 21 Jun 2024 17:41:50 +0900 Subject: [PATCH 3/6] Disable resetState in CelebratesPopup --- nekoyume/Assets/_Scripts/UI/Widget/Popup/CelebratesPopup.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nekoyume/Assets/_Scripts/UI/Widget/Popup/CelebratesPopup.cs b/nekoyume/Assets/_Scripts/UI/Widget/Popup/CelebratesPopup.cs index 1ebb63c15f..1376869960 100644 --- a/nekoyume/Assets/_Scripts/UI/Widget/Popup/CelebratesPopup.cs +++ b/nekoyume/Assets/_Scripts/UI/Widget/Popup/CelebratesPopup.cs @@ -341,10 +341,11 @@ private static void UpdateLocalState(int questId, IEnumerable> r LocalLayerModifier.AddItem( avatarAddress, materialRow.Value.ItemId, - reward.Item2); + reward.Item2, + false); } - LocalLayerModifier.RemoveReceivableQuest(avatarAddress, questId, true); + LocalLayerModifier.RemoveReceivableQuest(avatarAddress, questId, false); } private void PlayEffects() From 7d8ac4322baae0b1cc74f342a6d2e4a43389decb Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Fri, 21 Jun 2024 17:42:04 +0900 Subject: [PATCH 4/6] Disable reset state in quest popup --- nekoyume/Assets/_Scripts/UI/Widget/Popup/QuestPopup.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nekoyume/Assets/_Scripts/UI/Widget/Popup/QuestPopup.cs b/nekoyume/Assets/_Scripts/UI/Widget/Popup/QuestPopup.cs index 80ea4b3560..edbbc9d02e 100644 --- a/nekoyume/Assets/_Scripts/UI/Widget/Popup/QuestPopup.cs +++ b/nekoyume/Assets/_Scripts/UI/Widget/Popup/QuestPopup.cs @@ -152,7 +152,7 @@ private void ReceiveAll() .Where(q => q.isReceivable && q.Complete) .SelectMany(q => { - LocalLayerModifier.RemoveReceivableQuest(avatarAddress, q.Id); + LocalLayerModifier.RemoveReceivableQuest(avatarAddress, q.Id, false); return q.Reward.ItemMap; }).Select(itemMap => { @@ -161,7 +161,7 @@ private void ReceiveAll() itemMap.Item1); var itemId = item.ItemId; var count = itemMap.Item2; - LocalLayerModifier.AddItem(avatarAddress, itemId, count); + LocalLayerModifier.AddItem(avatarAddress, itemId, count, false); return new MailReward(item, count); }).ToList(); Find().Show(mailRewards); From 19c4ed982f35e91ee8ab309f2f68edf04fe6f0e5 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Mon, 24 Jun 2024 17:46:07 +0900 Subject: [PATCH 5/6] 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}"); From c45819c5976ba7b8e69209b8256e7a63c157add0 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Mon, 24 Jun 2024 19:31:37 +0900 Subject: [PATCH 6/6] Set mail.New false when read mail --- .../Assets/_Scripts/UI/Widget/Popup/MailPopup.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs b/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs index 86f5509159..b94fa73096 100644 --- a/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs +++ b/nekoyume/Assets/_Scripts/UI/Widget/Popup/MailPopup.cs @@ -111,6 +111,7 @@ private async void ReceiveAll() if (mail.New && mail.requiredBlockIndex <= currentBlockIndex) { await AddRewards(mail, mailRewards); + mail.New = false; } } @@ -149,7 +150,6 @@ private async void ReceiveAll() private static async Task AddRewards(Mail mail, List mailRewards) { - var avatarAddress = States.Instance.CurrentAvatarState.address; switch (mail) { case ProductBuyerMail productBuyerMail: @@ -473,6 +473,7 @@ public void Read(CombinationMail mail) var avatarAddress = States.Instance.CurrentAvatarState.address; LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, mail.id); + mail.New = false; NcDebug.Log("CombinationMail LocalLayer task completed"); ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); @@ -507,6 +508,7 @@ public async void Read(OrderBuyerMail orderBuyerMail) }; model.OnClickSubmit.Subscribe(_ => { + orderBuyerMail.New = false; LocalLayerModifier.RemoveNewMail(avatarAddress, orderBuyerMail.id); ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); }).AddTo(gameObject); @@ -520,6 +522,7 @@ public async void Read(OrderSellerMail orderSellerMail) var order = await Util.GetOrder(orderSellerMail.OrderId); var taxedPrice = order.Price - order.GetTax(); LocalLayerModifier.ModifyAgentGoldAsync(agentAddress, taxedPrice).Forget(); + orderSellerMail.New = false; LocalLayerModifier.RemoveNewMail(avatarAddress, orderSellerMail.id); ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); } @@ -527,12 +530,14 @@ public async void Read(OrderSellerMail orderSellerMail) public void Read(GrindingMail grindingMail) { NcDebug.Log($"[{nameof(GrindingMail)}] ItemCount: {grindingMail.ItemCount}, Asset: {grindingMail.Asset}"); + grindingMail.New = false; ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); } public void Read(MaterialCraftMail materialCraftMail) { NcDebug.Log($"[{nameof(MaterialCraftMail)}] ItemCount: {materialCraftMail.ItemCount}, ItemId: {materialCraftMail.ItemId}"); + materialCraftMail.New = false; ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); } @@ -560,6 +565,7 @@ public async void Read(ProductBuyerMail productBuyerMail) model.OnClickSubmit.Subscribe(_ => { + productBuyerMail.New = false; LocalLayerModifier.RemoveNewMail(avatarAddress, productBuyerMail.id); ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); }).AddTo(gameObject); @@ -574,6 +580,7 @@ public async void Read(ProductBuyerMail productBuyerMail) fav, () => { + productBuyerMail.New = false; LocalLayerModifier.RemoveNewMail(avatarAddress, productBuyerMail.id); ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); }); @@ -590,6 +597,7 @@ public async void Read(ProductSellerMail productSellerMail) var fav = new FungibleAssetValue(currency, (int)price, 0); var taxedPrice = fav.DivRem(100, out _) * Action.Buy.TaxRate; LocalLayerModifier.ModifyAgentGoldAsync(agentAddress, taxedPrice).Forget(); + productSellerMail.New = false; LocalLayerModifier.RemoveNewMail(avatarAddress, productSellerMail.id); ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); } @@ -601,6 +609,7 @@ public void Read(ProductCancelMail productCancelMail) L10nManager.Localize("UI_YES"), () => { + productCancelMail.New = false; LocalLayerModifier.RemoveNewMail(avatarAddress, productCancelMail.id); ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); ReactiveShopState.SetSellProducts(); @@ -614,6 +623,7 @@ public void Read(OrderExpirationMail orderExpirationMail) L10nManager.Localize("UI_YES"), () => { + orderExpirationMail.New = false; LocalLayerModifier.RemoveNewMail(avatarAddress, orderExpirationMail.id); ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); }); @@ -626,6 +636,7 @@ public void Read(CancelOrderMail cancelOrderMail) L10nManager.Localize("UI_YES"), () => { + cancelOrderMail.New = false; LocalLayerModifier.RemoveNewMail(avatarAddress, cancelOrderMail.id); ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); ReactiveShopState.SetSellProducts(); @@ -653,6 +664,7 @@ await LocalLayerModifier.ModifyAgentCrystalAsync( result.CRYSTAL.MajorUnit); } + itemEnhanceMail.New = false; LocalLayerModifier.RemoveNewAttachmentMail(avatarAddress, itemEnhanceMail.id); ReactiveAvatarState.UpdateMailBox(States.Instance.CurrentAvatarState.mailBox); }).ToObservable().SubscribeOnMainThread().Subscribe(_ =>