EqRecyclePanel.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections.Generic;
  3. using Fort23.Core;
  4. using Fort23.UTool;
  5. using GameLogic.Bag;
  6. namespace Fort23.Mono
  7. {
  8. [UIBinding(prefab = "EqRecyclePanel" )]
  9. public partial class EqRecyclePanel : UIPanel
  10. {
  11. private string eqItemPolPoolName = "eqItem";
  12. private string awardItemPoolName = "awardItem";
  13. private List<WidgetItem> pendingEqs = new List<WidgetItem>();
  14. private void Init()
  15. {
  16. }
  17. protected override void AddEvent()
  18. {
  19. }
  20. protected override void DelEvent()
  21. {
  22. }
  23. public override void AddButtonEvent()
  24. {
  25. btnBack.onClick.AddListener(OnclickClose);
  26. btnRec.onClick.AddListener(OnClickRecycle);
  27. }
  28. private async void OnClickRecycle()
  29. {
  30. if (pendingEqs.Count <= 0)
  31. {
  32. LogTool.Log("暂无可以分解的装备");
  33. return;
  34. }
  35. foreach (WidgetItem widgetItem in pendingEqs)
  36. {
  37. ItemInfo itemInfo = BagController.Instance.allBagDic[widgetItem.itemInfo.guid];
  38. if(itemInfo.count.Value - widgetItem.itemInfo.count.Value <= 0)
  39. {
  40. //删除到0后,如果装备被穿了,不移除背包。
  41. if (itemInfo.eqInfo.isWear)
  42. {
  43. itemInfo.count.Value = 0;
  44. BagController.Instance.RemoveItem(itemInfo, false, false);
  45. }
  46. else{
  47. // BagController.Instance.allBagDic.Remove(widgetItem.itemInfo.guid);
  48. BagController.Instance.RemoveItem(itemInfo, false, true);
  49. }
  50. }
  51. else {
  52. // itemInfo.count.Value -= widgetItem.itemInfo.count.Value;
  53. BagController.Instance.ModifyItem(itemInfo, false);
  54. }
  55. }
  56. BagController.Instance.ReInitAllEqItem();
  57. foreach (KeyValuePair<string,ItemInfo> keyValuePair in awardDic)
  58. {
  59. BagController.Instance.AddItem(keyValuePair.Value.itemID, keyValuePair.Value.count.Value, keyValuePair.Value.guid);
  60. }
  61. AccountFileInfo.Instance.SavePlayerData(true);
  62. pendingEqs.Clear();
  63. RewardsPanel rewardsPanel = await UIManager.Instance.LoadAndOpenPanel<RewardsPanel>(null, layer: UILayer.Top);
  64. rewardsPanel.InitRewardsPanel(awardDic, delegate
  65. {
  66. OnclickClose();
  67. awardDic.Clear();
  68. });
  69. EventManager.Instance.Dispatch(CustomEventType.Combat_EquipFall, null);
  70. }
  71. private void OnclickClose()
  72. {
  73. UIManager.Instance.HideUIUIPanel(this);
  74. UIManager.Instance.DormancyAllGComponent<WidgetItem>(eqItemPolPoolName);
  75. UIManager.Instance.DormancyAllGComponent<WidgetItem>(awardItemPoolName);
  76. }
  77. /// <summary>
  78. /// 回收奖励
  79. /// </summary>
  80. private Dictionary<string, ItemInfo> awardDic = new Dictionary<string, ItemInfo>();
  81. public async void InitEqRecyclePanel()
  82. {
  83. // GameObject eqGo = eqsUIObj[0] as GameObject;
  84. pendingEqs.Clear();
  85. awardDic.Clear();
  86. foreach (KeyValuePair<int,Dictionary<int,List<ItemInfo>>> keyValuePair in PlayerManager.Instance.eqController.allZyEqDic)
  87. {
  88. foreach (KeyValuePair<int,List<ItemInfo>> valuePair in keyValuePair.Value)
  89. {
  90. foreach (ItemInfo itemInfo in valuePair.Value)
  91. {
  92. if (!ValidityCheck(itemInfo))
  93. {
  94. continue;
  95. }
  96. WidgetItem widgetItem = await UIManager.Instance.
  97. CreateGComponentForObject<WidgetItem>(eqItem, null, isInstance : true,
  98. poolName:eqItemPolPoolName, root:itemRoot);
  99. widgetItem.InitWidget(itemInfo);
  100. pendingEqs.Add(widgetItem);
  101. for (int i = 0; i < itemInfo.eqInfo.basicEquipConfig.disItems.Length; i++)
  102. {
  103. AddToRecycleDic(itemInfo.eqInfo.basicEquipConfig.disItems[i], itemInfo.eqInfo.basicEquipConfig.count[i]);
  104. }
  105. }
  106. }
  107. }
  108. foreach (KeyValuePair<string,ItemInfo> keyValuePair in awardDic)
  109. {
  110. WidgetItem awardItem = await UIManager.Instance.
  111. CreateGComponentForObject<WidgetItem>(recItem, null, isInstance : true,
  112. poolName:awardItemPoolName, root:rewardRoot);
  113. awardItem.InitWidget(keyValuePair.Value);
  114. }
  115. }
  116. private void AddToRecycleDic(int itemID, int count)
  117. {
  118. ItemInfo itemInfo = new ItemInfo(itemID, count);
  119. if (awardDic.ContainsKey(itemInfo.guid))
  120. {
  121. awardDic[itemInfo.guid].count += count;
  122. }
  123. else {
  124. awardDic.Add(itemInfo.guid, itemInfo);
  125. }
  126. }
  127. /// <summary>
  128. /// 装备有效性检查
  129. /// </summary>
  130. /// <param name="itemInfo"></param>
  131. /// <returns></returns>
  132. private bool ValidityCheck(ItemInfo itemInfo)
  133. {
  134. if (itemInfo.eqInfo == null)
  135. {
  136. return false;
  137. }
  138. if (itemInfo.count.Value <= 0)
  139. {
  140. LogTool.Log(itemInfo.count.Value +"装备只有1个,而且被穿了:" + itemInfo.eqInfo.isWear);
  141. if (!itemInfo.eqInfo.isWear)
  142. {
  143. LogTool.Log("不应该出现,数量为0的装备还未穿戴?需要检查:eqConfigID"
  144. + itemInfo.eqInfo.basicEquipConfig.ID
  145. + "| itemID:" + itemInfo.itemID
  146. + "| guid:" + itemInfo.guid);
  147. }
  148. return false;
  149. }
  150. return true;
  151. }
  152. }
  153. }