GachaPanel.cs 9.4 KB

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