GachaPanel.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 =
  73. $"当前进度:{SummonData.drawHistory.Count * 10}/{_openBoxConfig.ProgressRewardChoukaCount}";
  74. Text_Score.text = $"目前得分:{SummonData.score}";
  75. OpenBoxScoreRule openBoxScoreRule = CheckAchievements(SummonData);
  76. if (openBoxScoreRule.ID != 0)
  77. {
  78. ScoreRoot.SetActive(true);
  79. Text_ScoreName.text = LanguageManager.Instance.Text(openBoxScoreRule.lanID);
  80. Text_ScoreCount.text = $"+{openBoxScoreRule.score}";
  81. Slider_Score2.maxValue = _openBoxConfig.ProgressRewardChoukaCount;
  82. Slider_Score1.maxValue = _openBoxConfig.ProgressRewardChoukaCount;
  83. Slider_Score2.value = SummonData.drawHistory.Count * 10;
  84. Slider_Score1.value = (SummonData.drawHistory.Count - 1) * 10;
  85. }
  86. else
  87. {
  88. ScoreRoot.SetActive(false);
  89. }
  90. }
  91. else
  92. {
  93. ScoreRoot.SetActive(false);
  94. }
  95. if (itemInfos.Count > 1)
  96. {
  97. for (var i = 0; i < itemInfos.Count; i++)
  98. {
  99. WidgetItemType2 widgetItem =
  100. await UIManager.Instance.CreateGComponentForObject<WidgetItemType2>(TenWidgetitems[i], null);
  101. widgetItem.InitWidget(itemInfos[i]);
  102. }
  103. TenRoot.gameObject.SetActive(true);
  104. OneRoot.gameObject.SetActive(false);
  105. }
  106. if (itemInfos.Count == 1)
  107. {
  108. for (var i = 0; i < itemInfos.Count; i++)
  109. {
  110. WidgetItemType2 widgetItem =
  111. await UIManager.Instance.CreateGComponentForObject<WidgetItemType2>(WidgetItemType2Gam, null);
  112. widgetItem.InitWidget(itemInfos[i]);
  113. }
  114. TenRoot.gameObject.SetActive(false);
  115. OneRoot.gameObject.SetActive(true);
  116. }
  117. return await base.AsyncInit(uiData);
  118. }
  119. private float timer = 0;
  120. public async CTask CusstomInit()
  121. {
  122. tenButton.gameObject.SetActive(true);
  123. }
  124. // 检查成就匹配
  125. private OpenBoxScoreRule CheckAchievements(AccountFileInfo.SummonData summonData)
  126. {
  127. List<OpenBoxScoreRule> openBoxScoreRuleList =
  128. PlayerManager.Instance.SummonManager.openBoxScoreRuleMap[summonData.id];
  129. List<OpenBoxScoreRule> daChengOpenBoxScoreRuleList = new List<OpenBoxScoreRule>();
  130. foreach (var openBoxScoreRule in openBoxScoreRuleList)
  131. {
  132. // 检查连续 Para0 次十连
  133. if (summonData.drawHistory.Count < openBoxScoreRule.para0) continue;
  134. bool allDrawsSatisfy = true;
  135. // 检查最近 Para0 次十连是否都满足条件
  136. for (int i = summonData.drawHistory.Count - openBoxScoreRule.para0;
  137. i < summonData.drawHistory.Count;
  138. i++)
  139. {
  140. if (!PlayerManager.Instance.SummonManager.CheckSingleDraw(openBoxScoreRule,
  141. summonData.drawHistory[i].list))
  142. {
  143. allDrawsSatisfy = false;
  144. break;
  145. }
  146. }
  147. if (allDrawsSatisfy)
  148. {
  149. daChengOpenBoxScoreRuleList.Add(openBoxScoreRule);
  150. }
  151. }
  152. if (daChengOpenBoxScoreRuleList.Count > 0)
  153. {
  154. int id = daChengOpenBoxScoreRuleList.Max(obsr => obsr.ID);
  155. OpenBoxScoreRule openBoxScoreRule = ConfigComponent.Instance.Get<OpenBoxScoreRule>(id);
  156. return openBoxScoreRule;
  157. }
  158. return default;
  159. }
  160. public override void Close()
  161. {
  162. // foreach (var widgetItem in widgetItems)
  163. // {
  164. // UIManager.Instance.DormancyGComponent(widgetItem);
  165. // }
  166. //
  167. // widgetItems.Clear();
  168. tenButton.gameObject.SetActive(false);
  169. tenButton.gameObject.SetActive(false);
  170. OneRoot.gameObject.SetActive(true);
  171. //完成挑战过后自动打开挑战界面
  172. if (_openBoxConfig.ProgressRewardChoukaCount != -1 &&
  173. SummonData.drawHistory.Count >= _openBoxConfig.ProgressRewardChoukaCount)
  174. {
  175. OpenBoxScorePanel.OpenPanel();
  176. }
  177. base.Close();
  178. }
  179. public async static CTask OpenPanel(List<ItemInfo> itemInfos, int type, int configId)
  180. {
  181. if (UIManager.Instance.GetComponent<GachaPanel>() == null ||
  182. UIManager.Instance.GetComponent<GachaPanel>().IsClose)
  183. {
  184. GachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel<GachaPanel>(null, UILayer.Middle,
  185. uiData: new object[] { itemInfos, type, configId }, isShowBG: true);
  186. // await TimerComponent.Instance.WaitAsync(300);
  187. gachaPanel.CusstomInit();
  188. }
  189. }
  190. }
  191. }