GachaPanel.cs 9.0 KB

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