GachaPanel.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Core.Audio;
  5. using Core.Language;
  6. using Core.Utility;
  7. using Excel2Json;
  8. using Fort23.Core;
  9. using Fort23.UTool;
  10. using GameLogic.Bag;
  11. using UnityEngine;
  12. using Random = UnityEngine.Random;
  13. namespace Fort23.Mono
  14. {
  15. [UIBinding(prefab = "GachaPanel")]
  16. public partial class GachaPanel : UIPanel
  17. {
  18. List<WidgetItem> widgetItems = new List<WidgetItem>();
  19. private List<ItemInfo> itemInfos;
  20. private int type;
  21. private OpenBoxConfig _openBoxConfig;
  22. private AccountFileInfo.SummonData SummonData;
  23. private void Init()
  24. {
  25. isAddStack = true;
  26. IsShowAppBar = false;
  27. }
  28. public override CTask GetFocus()
  29. {
  30. AppBarPanel.ClosePanel();
  31. TitlePanel.ClosePanel();
  32. // TitlePanel.OpenPanel(new List<int>() { GlobalParam.Item_Coin_ID, GlobalParam.Item_Diamond_ID });
  33. return base.GetFocus();
  34. }
  35. public override CTask LoseFocus()
  36. {
  37. TitlePanel.ClosePanel();
  38. return base.LoseFocus();
  39. }
  40. protected override void AddEvent()
  41. {
  42. }
  43. protected override void DelEvent()
  44. {
  45. }
  46. public override void AddButtonEvent()
  47. {
  48. tenButton.onClick.AddListener(() =>
  49. {
  50. float beLv =
  51. Utility.UtilTools.GetRandomByWeight(_openBoxConfig.betPara1.ToList(), _openBoxConfig.betPara2);
  52. foreach (var itemInfo in itemInfos)
  53. {
  54. ItemInfo itemInfo1 = new ItemInfo(itemInfo.itemID, (long)(itemInfo.count.Value * (beLv - 1)));
  55. PlayerManager.Instance.BagController.AddItem(itemInfo1);
  56. }
  57. UIManager.Instance.HideUIUIPanel<GachaPanel>();
  58. });
  59. }
  60. public async override CTask<bool> AsyncInit(object[] uiData)
  61. {
  62. itemInfos = uiData[0] as List<ItemInfo>;
  63. type = (int)uiData[1];
  64. _openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>((int)uiData[2]);
  65. SummonData = PlayerManager.Instance.SummonManager.summonDataMap[_openBoxConfig.ID];
  66. Slider_Count.maxValue = _openBoxConfig.reward2para1;
  67. Slider_Count.value = SummonData.baodiCount2;
  68. Text_Count.text = $"{SummonData.baodiCount2}/{_openBoxConfig.reward2para1}";
  69. StartRoot.gameObject.SetActive(SummonData.isSummonSocre);
  70. if (SummonData.isSummonSocre)
  71. {
  72. Text_JingDu.text = $"当前进度:{SummonData.drawHistory.Count}/{_openBoxConfig.ProgressRewardChoukaCount}";
  73. Text_Score.text = $"目前得分:{SummonData.score}";
  74. OpenBoxScoreRule openBoxScoreRule = CheckAchievements(SummonData);
  75. if (openBoxScoreRule.ID != 0)
  76. {
  77. ScoreName.SetActive(true);
  78. Text_ScoreCount.text = $"+{openBoxScoreRule.score}";
  79. }
  80. else
  81. {
  82. ScoreName.SetActive(false);
  83. }
  84. }
  85. else
  86. {
  87. ScoreName.SetActive(false);
  88. }
  89. if (itemInfos.Count > 1)
  90. {
  91. for (var i = 0; i < itemInfos.Count; i++)
  92. {
  93. WidgetItemType2 widgetItem =
  94. await UIManager.Instance.CreateGComponentForObject<WidgetItemType2>(TenWidgetitems[i], null);
  95. widgetItem.InitWidget(itemInfos[i]);
  96. }
  97. TenRoot.gameObject.SetActive(true);
  98. OneRoot.gameObject.SetActive(false);
  99. }
  100. if (itemInfos.Count == 1)
  101. {
  102. for (var i = 0; i < itemInfos.Count; i++)
  103. {
  104. WidgetItemType2 widgetItem =
  105. await UIManager.Instance.CreateGComponentForObject<WidgetItemType2>(WidgetItemType2Gam, null);
  106. widgetItem.InitWidget(itemInfos[i]);
  107. }
  108. TenRoot.gameObject.SetActive(false);
  109. OneRoot.gameObject.SetActive(true);
  110. }
  111. return await base.AsyncInit(uiData);
  112. }
  113. private float timer = 0;
  114. public async CTask CusstomInit()
  115. {
  116. tenButton.gameObject.SetActive(true);
  117. }
  118. // 检查成就匹配
  119. private OpenBoxScoreRule CheckAchievements(AccountFileInfo.SummonData summonData)
  120. {
  121. List<OpenBoxScoreRule> openBoxScoreRuleList = PlayerManager.Instance.SummonManager.openBoxScoreRuleMap[summonData.id];
  122. List<OpenBoxScoreRule> daChengOpenBoxScoreRuleList = new List<OpenBoxScoreRule>();
  123. foreach (var openBoxScoreRule in openBoxScoreRuleList)
  124. {
  125. // 检查连续 Para0 次十连
  126. if (summonData.drawHistory.Count < openBoxScoreRule.para0) continue;
  127. bool allDrawsSatisfy = true;
  128. // 检查最近 Para0 次十连是否都满足条件
  129. for (int i = summonData.drawHistory.Count - openBoxScoreRule.para0; i < summonData.drawHistory.Count; i++)
  130. {
  131. if (!PlayerManager.Instance.SummonManager.CheckSingleDraw(openBoxScoreRule, summonData.drawHistory[i].list))
  132. {
  133. allDrawsSatisfy = false;
  134. break;
  135. }
  136. }
  137. if (allDrawsSatisfy)
  138. {
  139. daChengOpenBoxScoreRuleList.Add(openBoxScoreRule);
  140. }
  141. }
  142. if (daChengOpenBoxScoreRuleList.Count > 0)
  143. {
  144. int id = daChengOpenBoxScoreRuleList.Max(obsr => obsr.ID);
  145. OpenBoxScoreRule openBoxScoreRule = ConfigComponent.Instance.Get<OpenBoxScoreRule>(id);
  146. return openBoxScoreRule;
  147. }
  148. return default;
  149. }
  150. public override void Close()
  151. {
  152. // foreach (var widgetItem in widgetItems)
  153. // {
  154. // UIManager.Instance.DormancyGComponent(widgetItem);
  155. // }
  156. //
  157. // widgetItems.Clear();
  158. tenButton.gameObject.SetActive(false);
  159. tenButton.gameObject.SetActive(false);
  160. OneRoot.gameObject.SetActive(true);
  161. //完成挑战过后自动打开挑战界面
  162. if (_openBoxConfig.ProgressRewardChoukaCount != -1 &&
  163. SummonData.drawHistory.Count >= _openBoxConfig.ProgressRewardChoukaCount)
  164. {
  165. OpenBoxScorePanel.OpenPanel();
  166. }
  167. base.Close();
  168. }
  169. public async static CTask OpenPanel(List<ItemInfo> itemInfos, int type, int configId)
  170. {
  171. if (UIManager.Instance.GetComponent<GachaPanel>() == null ||
  172. UIManager.Instance.GetComponent<GachaPanel>().IsClose)
  173. {
  174. GachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel<GachaPanel>(null, UILayer.Middle,
  175. uiData: new object[] { itemInfos, type, configId }, isShowBG: true);
  176. // await TimerComponent.Instance.WaitAsync(300);
  177. gachaPanel.CusstomInit();
  178. }
  179. }
  180. }
  181. }