BoxPanel.cs 9.2 KB

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