GachaPanel.cs 9.6 KB

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