GachaPanel.cs 8.4 KB

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