GachaPanel.cs 9.4 KB

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