BoxPanel.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. OpenBoxConfig openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(configId);
  18. if (PlayerManager.Instance.BagController.IsEnough(GlobalParam.Item_Coin_ID, openBoxConfig.tenConsume) || isFree)
  19. {
  20. PlayerManager.Instance.BagController.DeductCoin(openBoxConfig.tenConsume);
  21. List<ItemInfo> allIitem = new List<ItemInfo>();
  22. for (int i = 0; i < 10; i++)
  23. {
  24. List<ItemInfo> currItem = DropManager.Instance.DropItem(openBoxConfig.reward);
  25. allIitem.AddRange(currItem);
  26. }
  27. PlayerManager.Instance.BagController.AddItem(allIitem);
  28. return allIitem;
  29. }
  30. else
  31. {
  32. bool isOK = await TipsPanle.OpenPnael(1041);
  33. if (isOK)
  34. {
  35. ShopPanel.OpenPanel();
  36. }
  37. return null;
  38. }
  39. }
  40. public async static CTask<List<ItemInfo>> OneBox(int configId)
  41. {
  42. OpenBoxConfig openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(configId);
  43. if (PlayerManager.Instance.BagController.IsEnough(GlobalParam.Item_Coin_ID, openBoxConfig.oneConsume))
  44. {
  45. PlayerManager.Instance.BagController.DeductCoin(openBoxConfig.oneConsume);
  46. List<ItemInfo> allIitem = DropManager.Instance.DropItem(openBoxConfig.reward);
  47. PlayerManager.Instance.BagController.AddItem(allIitem);
  48. return allIitem;
  49. }
  50. else
  51. {
  52. bool isOK = await TipsPanle.OpenPnael(1041);
  53. if (isOK)
  54. {
  55. ShopPanel.OpenPanel();
  56. }
  57. // TipMessagePanel.OpenTipMessagePanel(LanguageManager.Instance.Text(102), Vector2.zero);
  58. return null;
  59. }
  60. }
  61. }
  62. [UIBinding(prefab = "BoxPanel")]
  63. public partial class BoxPanel : UIPanel
  64. {
  65. private OpenBoxConfig openBoxConfig;
  66. public static async void OpenBoxPanel()
  67. {
  68. BoxPanel boxPanel = await UIManager.Instance.LoadAndOpenPanel<BoxPanel>(null, layer: UILayer.Top);
  69. boxPanel.OpenPanel();
  70. }
  71. private void Init()
  72. {
  73. isAddStack = false;
  74. IsShowAppBar = false;
  75. }
  76. protected override void AddEvent()
  77. {
  78. }
  79. protected override void DelEvent()
  80. {
  81. }
  82. private bool isStartAd = false;
  83. public override void AddButtonEvent()
  84. {
  85. oneButton.onClick.AddListener(OnButtonCallBack);
  86. tenButton.onClick.AddListener(TenButtonCallBack);
  87. close.onClick.AddListener(CloseButtonCallBack);
  88. bg.onClick.AddListener(CloseButtonCallBack);
  89. Btn_AdsFree.onClick.AddListener(async () =>
  90. {
  91. if (AccountFileInfo.Instance.playerData.boxFree)
  92. {
  93. TipMessagePanel.OpenTipMessagePanel(938, Vector2.zero);
  94. return;
  95. }
  96. if (isStartAd)
  97. return;
  98. isStartAd = true;
  99. var dic = new Dictionary<string, string>();
  100. dic.Add("Chouka", "");
  101. // YouLoftSDK.Instance.CustomEvent("OnclickAds", dic);
  102. // bool isOK = await YouLoftSDK.Instance.ShowAd();
  103. bool isOK = true;
  104. isStartAd = false;
  105. if (!isOK)
  106. {
  107. return;
  108. }
  109. dic = new Dictionary<string, string>();
  110. dic.Add("Chouka", "");
  111. // YouLoftSDK.Instance.CustomEvent("AdsPlayOver", dic);
  112. AccountFileInfo.Instance.playerData.boxFree = true;
  113. AccountFileInfo.Instance.SavePlayerData();
  114. Btn_AdsFree.gameObject.SetActive(false);
  115. List<ItemInfo> allIitem = await BoxHelper.TenBox(openBoxConfig.ID, true);
  116. if (allIitem != null)
  117. GachaPanel.OpenPanel(allIitem, 2, openBoxConfig.ID);
  118. });
  119. }
  120. private async void OnButtonCallBack()
  121. {
  122. //测试代码
  123. List<ItemInfo> allIitem = await BoxHelper.OneBox(openBoxConfig.ID);
  124. if (allIitem != null)
  125. GachaPanel.OpenPanel(allIitem, 1, openBoxConfig.ID);
  126. }
  127. private async void TenButtonCallBack()
  128. {
  129. //测试代码
  130. List<ItemInfo> allIitem = await BoxHelper.TenBox(openBoxConfig.ID);
  131. if (allIitem != null)
  132. GachaPanel.OpenPanel(allIitem, 2, openBoxConfig.ID);
  133. }
  134. private void CloseButtonCallBack()
  135. {
  136. UIManager.Instance.HideUIUIPanel(this);
  137. EventManager.Instance.Dispatch(CustomEventType.Combat_EquipFall, null);
  138. }
  139. public override void Close()
  140. {
  141. CombatController.currActiveCombat.isUpdate = true;
  142. base.Close();
  143. }
  144. public void OpenPanel()
  145. {
  146. CombatController.currActiveCombat.isUpdate = false;
  147. openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(1);
  148. onCion.text = "x" + openBoxConfig.oneConsume;
  149. tenCion.text = "x" + openBoxConfig.tenConsume;
  150. if (AccountFileInfo.Instance.playerData.boxFree)
  151. {
  152. Btn_AdsFree.gameObject.SetActive(false);
  153. }
  154. else
  155. {
  156. Btn_AdsFree.gameObject.SetActive(true);
  157. }
  158. }
  159. }
  160. }