GachaPanel.cs 10 KB

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