EqRecyclePanel.cs 6.3 KB

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