GachaPanel.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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<WidgetItemType2> widgetItems = new List<WidgetItemType2>();
  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. tenButton.gameObject.SetActive(false);
  51. float beLv =
  52. Utility.UtilTools.GetRandomByWeight(_openBoxConfig.betPara1.ToList(), _openBoxConfig.betPara2);
  53. foreach (var itemInfo in itemInfos)
  54. {
  55. ItemInfo itemInfo1 = new ItemInfo(itemInfo.itemID, (long)(itemInfo.count.Value * (beLv - 1)));
  56. PlayerManager.Instance.BagController.AddItem(itemInfo1);
  57. }
  58. foreach (var widgetItemType2 in widgetItems)
  59. {
  60. widgetItemType2.Play(beLv);
  61. }
  62. // UIManager.Instance.HideUIUIPanel<GachaPanel>();
  63. });
  64. Btn_Close.onClick.AddListener(() => { UIManager.Instance.HideUIUIPanel<GachaPanel>(); });
  65. }
  66. public async override CTask<bool> AsyncInit(object[] uiData)
  67. {
  68. itemInfos = uiData[0] as List<ItemInfo>;
  69. type = (int)uiData[1];
  70. _openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>((int)uiData[2]);
  71. SummonData = PlayerManager.Instance.SummonManager.summonDataMap[_openBoxConfig.ID];
  72. Slider_Count.maxValue = _openBoxConfig.reward2para1;
  73. Slider_Count.value = SummonData.baodiCount2;
  74. Text_Count.text = $"{SummonData.baodiCount2}/{_openBoxConfig.reward2para1}";
  75. StartRoot.gameObject.SetActive(SummonData.isSummonSocre);
  76. if (SummonData.isSummonSocre)
  77. {
  78. Text_JingDu.text = LanguageManager.Instance.Text(10260, SummonData.drawHistory.Count * 10,
  79. _openBoxConfig.ProgressRewardChoukaCount);
  80. Text_Score.text = LanguageManager.Instance.Text(10261, SummonData.score);
  81. OpenBoxScoreRule openBoxScoreRule = CheckAchievements(SummonData);
  82. if (openBoxScoreRule.ID != 0)
  83. {
  84. ScoreRoot.SetActive(true);
  85. Text_ScoreName.text = LanguageManager.Instance.Text(openBoxScoreRule.lanID);
  86. Text_ScoreCount.text = $"+{openBoxScoreRule.score}";
  87. Slider_Score2.maxValue = _openBoxConfig.ProgressRewardChoukaCount;
  88. Slider_Score1.maxValue = _openBoxConfig.ProgressRewardChoukaCount;
  89. Slider_Score2.value = SummonData.drawHistory.Count * 10;
  90. Slider_Score1.value = (SummonData.drawHistory.Count - 1) * 10;
  91. }
  92. else
  93. {
  94. ScoreRoot.SetActive(false);
  95. }
  96. }
  97. else
  98. {
  99. ScoreRoot.SetActive(false);
  100. }
  101. return await base.AsyncInit(uiData);
  102. }
  103. private float timer = 0;
  104. public async CTask CusstomInit()
  105. {
  106. await MarskPanel.OpenPanel();
  107. tenButton.gameObject.SetActive(true);
  108. if (itemInfos.Count > 1)
  109. {
  110. TenRoot.gameObject.SetActive(true);
  111. OneRoot.gameObject.SetActive(false);
  112. // await TimerComponent.Instance.WaitAsync(600);
  113. for (var i = 0; i < itemInfos.Count; i++)
  114. {
  115. WidgetItemType2 widgetItem =
  116. await UIManager.Instance.CreateGComponentForObject<WidgetItemType2>(TenWidgetitems[i], null);
  117. widgetItem.InitWidget(itemInfos[i]);
  118. widgetItem.own.SetActive(true);
  119. widgetItems.Add(widgetItem);
  120. await TimerComponent.Instance.WaitAsync(50);
  121. }
  122. }
  123. if (itemInfos.Count == 1)
  124. {
  125. for (var i = 0; i < itemInfos.Count; i++)
  126. {
  127. WidgetItemType2 widgetItem =
  128. await UIManager.Instance.CreateGComponentForObject<WidgetItemType2>(WidgetItemType2Gam, null);
  129. widgetItem.InitWidget(itemInfos[i]);
  130. }
  131. TenRoot.gameObject.SetActive(false);
  132. OneRoot.gameObject.SetActive(true);
  133. }
  134. await MarskPanel.ClosePanel();
  135. root.gameObject.SetActive(true);
  136. }
  137. // 检查成就匹配
  138. private OpenBoxScoreRule CheckAchievements(AccountFileInfo.SummonData summonData)
  139. {
  140. List<OpenBoxScoreRule> openBoxScoreRuleList =
  141. PlayerManager.Instance.SummonManager.openBoxScoreRuleMap[summonData.id];
  142. List<OpenBoxScoreRule> daChengOpenBoxScoreRuleList = new List<OpenBoxScoreRule>();
  143. foreach (var openBoxScoreRule in openBoxScoreRuleList)
  144. {
  145. // 检查连续 Para0 次十连
  146. if (summonData.drawHistory.Count < openBoxScoreRule.para0) continue;
  147. bool allDrawsSatisfy = true;
  148. // 检查最近 Para0 次十连是否都满足条件
  149. for (int i = summonData.drawHistory.Count - openBoxScoreRule.para0;
  150. i < summonData.drawHistory.Count;
  151. i++)
  152. {
  153. if (!PlayerManager.Instance.SummonManager.CheckSingleDraw(openBoxScoreRule,
  154. summonData.drawHistory[i].list))
  155. {
  156. allDrawsSatisfy = false;
  157. break;
  158. }
  159. }
  160. if (allDrawsSatisfy)
  161. {
  162. daChengOpenBoxScoreRuleList.Add(openBoxScoreRule);
  163. }
  164. }
  165. if (daChengOpenBoxScoreRuleList.Count > 0)
  166. {
  167. int id = daChengOpenBoxScoreRuleList.Max(obsr => obsr.ID);
  168. OpenBoxScoreRule openBoxScoreRule = ConfigComponent.Instance.Get<OpenBoxScoreRule>(id);
  169. return openBoxScoreRule;
  170. }
  171. return default;
  172. }
  173. public async override CTask Close()
  174. {
  175. // foreach (var widgetItem in widgetItems)
  176. // {
  177. // UIManager.Instance.DormancyGComponent(widgetItem);
  178. // }
  179. //
  180. // widgetItems.Clear();
  181. tenButton.gameObject.SetActive(false);
  182. tenButton.gameObject.SetActive(false);
  183. OneRoot.gameObject.SetActive(true);
  184. //完成挑战过后自动打开挑战界面
  185. if (_openBoxConfig.ProgressRewardChoukaCount != -1 &&
  186. SummonData.drawHistory.Count * 10 >= _openBoxConfig.ProgressRewardChoukaCount)
  187. {
  188. OpenBoxScorePanel.OpenPanel();
  189. }
  190. foreach (var tenWidgetitem in TenWidgetitems)
  191. {
  192. tenWidgetitem.gameObject.SetActive(false);
  193. }
  194. root.gameObject.SetActive(false);
  195. await base.Close();
  196. }
  197. public async static CTask<GachaPanel> OpenPanel(List<ItemInfo> itemInfos, int type, int configId)
  198. {
  199. GachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel<GachaPanel>(null, UILayer.Middle,
  200. uiData: new object[] { itemInfos, type, configId }, isShowBG: false);
  201. // await TimerComponent.Instance.WaitAsync(300);
  202. gachaPanel.CusstomInit();
  203. AudioManager.Instance.PlayAudio("ui_chouqugongfa.wav");
  204. return gachaPanel;
  205. }
  206. }
  207. }