GachaPanel.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 = LanguageManager.Instance.Text(10260, SummonData.drawHistory.Count * 10,
  73. _openBoxConfig.ProgressRewardChoukaCount);
  74. Text_Score.text = LanguageManager.Instance.Text(10261, 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. return await base.AsyncInit(uiData);
  96. }
  97. private float timer = 0;
  98. public async CTask CusstomInit()
  99. {
  100. await MarskPanel.OpenPanel();
  101. tenButton.gameObject.SetActive(true);
  102. if (itemInfos.Count > 1)
  103. {
  104. TenRoot.gameObject.SetActive(true);
  105. OneRoot.gameObject.SetActive(false);
  106. await TimerComponent.Instance.WaitAsync(600);
  107. for (var i = 0; i < itemInfos.Count; i++)
  108. {
  109. WidgetItemType2 widgetItem =
  110. await UIManager.Instance.CreateGComponentForObject<WidgetItemType2>(TenWidgetitems[i], null);
  111. widgetItem.InitWidget(itemInfos[i]);
  112. widgetItem.own.SetActive(true);
  113. await TimerComponent.Instance.WaitAsync(50);
  114. }
  115. }
  116. if (itemInfos.Count == 1)
  117. {
  118. for (var i = 0; i < itemInfos.Count; i++)
  119. {
  120. WidgetItemType2 widgetItem =
  121. await UIManager.Instance.CreateGComponentForObject<WidgetItemType2>(WidgetItemType2Gam, null);
  122. widgetItem.InitWidget(itemInfos[i]);
  123. }
  124. TenRoot.gameObject.SetActive(false);
  125. OneRoot.gameObject.SetActive(true);
  126. }
  127. await MarskPanel.ClosePanel();
  128. root.gameObject.SetActive(true);
  129. }
  130. // 检查成就匹配
  131. private OpenBoxScoreRule CheckAchievements(AccountFileInfo.SummonData summonData)
  132. {
  133. List<OpenBoxScoreRule> openBoxScoreRuleList =
  134. PlayerManager.Instance.SummonManager.openBoxScoreRuleMap[summonData.id];
  135. List<OpenBoxScoreRule> daChengOpenBoxScoreRuleList = new List<OpenBoxScoreRule>();
  136. foreach (var openBoxScoreRule in openBoxScoreRuleList)
  137. {
  138. // 检查连续 Para0 次十连
  139. if (summonData.drawHistory.Count < openBoxScoreRule.para0) continue;
  140. bool allDrawsSatisfy = true;
  141. // 检查最近 Para0 次十连是否都满足条件
  142. for (int i = summonData.drawHistory.Count - openBoxScoreRule.para0;
  143. i < summonData.drawHistory.Count;
  144. i++)
  145. {
  146. if (!PlayerManager.Instance.SummonManager.CheckSingleDraw(openBoxScoreRule,
  147. summonData.drawHistory[i].list))
  148. {
  149. allDrawsSatisfy = false;
  150. break;
  151. }
  152. }
  153. if (allDrawsSatisfy)
  154. {
  155. daChengOpenBoxScoreRuleList.Add(openBoxScoreRule);
  156. }
  157. }
  158. if (daChengOpenBoxScoreRuleList.Count > 0)
  159. {
  160. int id = daChengOpenBoxScoreRuleList.Max(obsr => obsr.ID);
  161. OpenBoxScoreRule openBoxScoreRule = ConfigComponent.Instance.Get<OpenBoxScoreRule>(id);
  162. return openBoxScoreRule;
  163. }
  164. return default;
  165. }
  166. public async override CTask Close()
  167. {
  168. // foreach (var widgetItem in widgetItems)
  169. // {
  170. // UIManager.Instance.DormancyGComponent(widgetItem);
  171. // }
  172. //
  173. // widgetItems.Clear();
  174. tenButton.gameObject.SetActive(false);
  175. tenButton.gameObject.SetActive(false);
  176. OneRoot.gameObject.SetActive(true);
  177. //完成挑战过后自动打开挑战界面
  178. if (_openBoxConfig.ProgressRewardChoukaCount != -1 &&
  179. SummonData.drawHistory.Count * 10 >= _openBoxConfig.ProgressRewardChoukaCount)
  180. {
  181. OpenBoxScorePanel.OpenPanel();
  182. }
  183. foreach (var tenWidgetitem in TenWidgetitems)
  184. {
  185. tenWidgetitem.gameObject.SetActive(false);
  186. }
  187. root.gameObject.SetActive(false);
  188. await base.Close();
  189. }
  190. public async static CTask OpenPanel(List<ItemInfo> itemInfos, int type, int configId)
  191. {
  192. if (UIManager.Instance.GetComponent<GachaPanel>() == null ||
  193. UIManager.Instance.GetComponent<GachaPanel>().IsClose)
  194. {
  195. GachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel<GachaPanel>(null, UILayer.Middle,
  196. uiData: new object[] { itemInfos, type, configId }, isShowBG: true);
  197. // await TimerComponent.Instance.WaitAsync(300);
  198. gachaPanel.CusstomInit();
  199. }
  200. AudioManager.Instance.PlayAudio("ui_chouqugongfa.wav");
  201. }
  202. }
  203. }