BoxPanel.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. using System.Collections.Generic;
  2. using Core.Language;
  3. using Core.Utility;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Bag;
  8. using GameLogic.Combat.CombatTool;
  9. using GameLogic.Player;
  10. using UnityEngine;
  11. namespace Fort23.Mono
  12. {
  13. public static class BoxHelper
  14. {
  15. public async static CTask<List<ItemInfo>> TenBox(int configId, bool isFree = false)
  16. {
  17. AccountFileInfo.SummonData summonData = PlayerManager.Instance.SummonManager.summonDataMap[configId];
  18. OpenBoxConfig openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(configId);
  19. //有免费次数,并且让到时间了就免费抽
  20. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] &&
  21. PlayerManager.Instance.serverTime >= summonData.nextTenFreeTime)
  22. {
  23. return PlayerManager.Instance.SummonManager.Summon(configId, 10);
  24. }
  25. else
  26. {
  27. //验证道具是否足够
  28. if (PlayerManager.Instance.BagController.IsEnough(openBoxConfig.CostItemID, openBoxConfig.tenConsume))
  29. {
  30. return PlayerManager.Instance.SummonManager.Summon(configId, 10);
  31. }
  32. else
  33. {
  34. TipMessagePanel.OpenTipMessagePanel("道具不足", Vector2.zero);
  35. return null;
  36. }
  37. }
  38. }
  39. public async static CTask<List<ItemInfo>> OneBox(int configId)
  40. {
  41. AccountFileInfo.SummonData summonData = PlayerManager.Instance.SummonManager.summonDataMap[configId];
  42. OpenBoxConfig openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(configId);
  43. //有免费次数,并且让到时间了就免费抽
  44. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] &&
  45. PlayerManager.Instance.serverTime >= summonData.nextOneFreeTime)
  46. {
  47. return PlayerManager.Instance.SummonManager.Summon(configId, 1);
  48. }
  49. else
  50. {
  51. //验证道具是否足够
  52. if (PlayerManager.Instance.BagController.IsEnough(openBoxConfig.CostItemID, openBoxConfig.oneConsume))
  53. {
  54. return PlayerManager.Instance.SummonManager.Summon(configId, 1);
  55. }
  56. else
  57. {
  58. TipMessagePanel.OpenTipMessagePanel("道具不足", Vector2.zero);
  59. return null;
  60. }
  61. }
  62. }
  63. }
  64. [UIBinding(prefab = "BoxPanel")]
  65. public partial class BoxPanel : UIPanel
  66. {
  67. private OpenBoxConfig openBoxConfig;
  68. private AccountFileInfo.SummonData summonData;
  69. public static async void OpenBoxPanel()
  70. {
  71. BoxPanel boxPanel = await UIManager.Instance.LoadAndOpenPanel<BoxPanel>(null, layer: UILayer.Middle);
  72. boxPanel.OpenPanel();
  73. }
  74. private void Init()
  75. {
  76. isAddStack = true;
  77. IsShowAppBar = false;
  78. }
  79. public override CTask GetFocus()
  80. {
  81. // AppBarPanel.ClosePanel();
  82. TitlePanel.OpenPanel(new List<int>() { openBoxConfig.CostItemID });
  83. return base.GetFocus();
  84. }
  85. protected override void AddEvent()
  86. {
  87. }
  88. protected override void DelEvent()
  89. {
  90. }
  91. private bool isStartAd = false;
  92. public override void AddButtonEvent()
  93. {
  94. Btn_Score.onClick.AddListener(() => { OpenBoxScorePanel.OpenPanel(); });
  95. oneButton.onClick.AddListener(OnButtonCallBack);
  96. tenButton.onClick.AddListener(TenButtonCallBack);
  97. Btn_Close.onClick.AddListener(CloseButtonCallBack);
  98. bg.onClick.AddListener(CloseButtonCallBack);
  99. }
  100. private async void OnButtonCallBack()
  101. {
  102. if (summonData.isSummonSocre)
  103. {
  104. TipMessagePanel.OpenTipMessagePanel("已经开启300抽挑战,不能进行单抽了");
  105. return;
  106. }
  107. //测试代码
  108. List<ItemInfo> allIitem = await BoxHelper.OneBox(openBoxConfig.ID);
  109. if (allIitem != null)
  110. GachaPanel.OpenPanel(allIitem, 1, openBoxConfig.ID);
  111. UpdateUi();
  112. }
  113. private async void TenButtonCallBack()
  114. {
  115. //测试代码
  116. List<ItemInfo> allIitem = await BoxHelper.TenBox(openBoxConfig.ID);
  117. if (allIitem != null)
  118. GachaPanel.OpenPanel(allIitem, 2, openBoxConfig.ID);
  119. UpdateUi();
  120. }
  121. private void CloseButtonCallBack()
  122. {
  123. UIManager.Instance.HideUIUIPanel(this);
  124. EventManager.Instance.Dispatch(CustomEventType.Combat_EquipFall, null);
  125. }
  126. public override void Close()
  127. {
  128. CombatController.currActiveCombat.isUpdate = true;
  129. base.Close();
  130. }
  131. public void OpenPanel()
  132. {
  133. CombatController.currActiveCombat.isUpdate = false;
  134. openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(2);
  135. ItemConfig config = ConfigComponent.Instance.Get<ItemConfig>(openBoxConfig.CostItemID);
  136. icon_Oneitem.icon_name = config.icon;
  137. Icon_TenItem.icon_name = config.icon;
  138. onCion.text = "x" + openBoxConfig.oneConsume;
  139. tenCion.text = "x" + openBoxConfig.tenConsume;
  140. Slider_Count.maxValue = openBoxConfig.reward2para1;
  141. UpdateUi();
  142. }
  143. [CustomMethod(CustomMethodType.Update)]
  144. public void Update()
  145. {
  146. if (summonData == null)
  147. return;
  148. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] &&
  149. PlayerManager.Instance.serverTime < summonData.nextTenFreeTime)
  150. {
  151. int time = (int)(summonData.nextTenFreeTime - PlayerManager.Instance.serverTime);
  152. Text_TenFree.text = PlayerManager.TimeToHSM(time / 1000);
  153. }
  154. else
  155. {
  156. if (Text_TenFree.gameObject.activeSelf)
  157. {
  158. Text_TenFree.gameObject.SetActive(false);
  159. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1])
  160. {
  161. tenCion.text = "免费";
  162. }
  163. else
  164. {
  165. tenCion.text = "x" + openBoxConfig.tenConsume;
  166. }
  167. }
  168. }
  169. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] &&
  170. PlayerManager.Instance.serverTime < summonData.nextOneFreeTime)
  171. {
  172. int time = (int)(summonData.nextOneFreeTime - PlayerManager.Instance.serverTime);
  173. Text_OneFree.text = PlayerManager.TimeToHSM(time / 1000);
  174. }
  175. else
  176. {
  177. if (Text_OneFree.gameObject.activeSelf)
  178. {
  179. Text_OneFree.gameObject.SetActive(false);
  180. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1])
  181. {
  182. onCion.text = "免费";
  183. }
  184. else
  185. {
  186. onCion.text = "x" + openBoxConfig.oneConsume;
  187. }
  188. }
  189. }
  190. }
  191. public void UpdateUi()
  192. {
  193. summonData = PlayerManager.Instance.SummonManager.summonDataMap[openBoxConfig.ID];
  194. Slider_Count.value = summonData.baodiCount2;
  195. Text_Count.text = $"{summonData.baodiCount2}/{openBoxConfig.reward2para1}";
  196. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] &&
  197. PlayerManager.Instance.serverTime >= summonData.nextTenFreeTime)
  198. {
  199. Text_TenFree.gameObject.SetActive(false);
  200. tenCion.text = "免费";
  201. }
  202. //今日次数已用完
  203. else if (summonData.tenFreeCount >= openBoxConfig.oneConsumeFreePara_1[1])
  204. {
  205. Text_TenFree.gameObject.SetActive(false);
  206. tenCion.text = "x" + openBoxConfig.tenConsume;
  207. }
  208. else
  209. {
  210. Text_TenFree.gameObject.SetActive(true);
  211. tenCion.text = "x" + openBoxConfig.tenConsume;
  212. }
  213. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] &&
  214. PlayerManager.Instance.serverTime >= summonData.nextOneFreeTime)
  215. {
  216. Text_OneFree.gameObject.SetActive(false);
  217. onCion.text = "免费";
  218. }
  219. else if (summonData.oneFreeCount >= openBoxConfig.oneConsumeFreePara[1])
  220. {
  221. onCion.text = "x" + openBoxConfig.oneConsume;
  222. Text_OneFree.gameObject.SetActive(false);
  223. }
  224. else
  225. {
  226. onCion.text = "x" + openBoxConfig.oneConsume;
  227. Text_OneFree.gameObject.SetActive(true);
  228. }
  229. }
  230. }
  231. }