GachaPanel.cs 9.7 KB

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