BoxPanel.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. using System.Collections.Generic;
  2. using Core.Audio;
  3. using Core.Language;
  4. using Core.Utility;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using Fort23.UTool;
  8. using GameLogic.Bag;
  9. using GameLogic.Combat.CombatTool;
  10. using GameLogic.Player;
  11. using UnityEngine;
  12. namespace Fort23.Mono
  13. {
  14. public static class BoxHelper
  15. {
  16. public async static CTask<List<ItemInfo>> TenBox(int configId, bool isFree = false)
  17. {
  18. if (!TimeHelper.IsNetworkTimeReady)
  19. {
  20. LogTool.Error($"获取网络时间失败,抽卡失败");
  21. return null;
  22. }
  23. AccountFileInfo.SummonData summonData = PlayerManager.Instance.SummonManager.summonDataMap[configId];
  24. OpenBoxConfig openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(configId);
  25. //有免费次数,并且让到时间了就免费抽
  26. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] &&
  27. PlayerManager.Instance.serverTime >= summonData.nextTenFreeTime)
  28. {
  29. await MarskPanel.OpenPanel();
  30. List<ItemInfo> itemInfos = await PlayerManager.Instance.SummonManager.Summon(configId, 10);
  31. MarskPanel.ClosePanel();
  32. return itemInfos;
  33. // return await PlayerManager.Instance.SummonManager.Summon(configId, 10);
  34. }
  35. else
  36. {
  37. //验证道具是否足够
  38. if (openBoxConfig.CostItemID != 1007 && !PlayerManager.Instance.BagController.IsEnough(
  39. openBoxConfig.CostItemID,
  40. openBoxConfig.tenConsume))
  41. {
  42. ItemSourcePanel.OpenPanel(openBoxConfig.CostItemID);
  43. return null;
  44. }
  45. //看广告
  46. if (openBoxConfig.CostItemID == 1007)
  47. {
  48. if (AccountFileInfo.Instance.playerData.todayTotalAds >= 80)
  49. {
  50. TipMessagePanel.OpenTipMessagePanel("今日看广告次数已经达上限!");
  51. return null;
  52. }
  53. // AccountFileInfo.Instance.playerData.todayTotalAds++;
  54. // AccountFileInfo.Instance.SavePlayerData();
  55. }
  56. if (!PlayerManager.Instance.BagController.IsEnough(23002, 1))
  57. {
  58. await MarskPanel.OpenPanel();
  59. }
  60. List<ItemInfo> itemInfos = await PlayerManager.Instance.SummonManager.Summon(configId, 10);
  61. Dictionary<string, object> properties = new Dictionary<string, object>();
  62. properties.Add("#IsFreeAds",PlayerManager.Instance.BagController.IsEnough(23002, 1));
  63. DBManager.Instance.UpdateUserProperty(properties);
  64. if (!PlayerManager.Instance.BagController.IsEnough(23002, 1))
  65. {
  66. MarskPanel.ClosePanel();
  67. }
  68. return itemInfos;
  69. // return await PlayerManager.Instance.SummonManager.Summon(configId, 10);
  70. }
  71. }
  72. public async static CTask<List<ItemInfo>> OneBox(int configId)
  73. {
  74. if (!TimeHelper.IsNetworkTimeReady)
  75. {
  76. LogTool.Error($"获取网络时间失败,抽卡失败");
  77. return null;
  78. }
  79. AccountFileInfo.SummonData summonData = PlayerManager.Instance.SummonManager.summonDataMap[configId];
  80. OpenBoxConfig openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(configId);
  81. //有免费次数,并且让到时间了就免费抽
  82. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] &&
  83. PlayerManager.Instance.serverTime >= summonData.nextOneFreeTime)
  84. {
  85. await MarskPanel.OpenPanel();
  86. List<ItemInfo> itemInfos = await PlayerManager.Instance.SummonManager.Summon(configId, 1);
  87. MarskPanel.ClosePanel();
  88. return itemInfos;
  89. }
  90. else
  91. {
  92. //验证道具是否足够
  93. if (openBoxConfig.CostItemID != 1007 && !PlayerManager.Instance.BagController.IsEnough(
  94. openBoxConfig.CostItemID,
  95. openBoxConfig.oneConsume))
  96. {
  97. ItemSourcePanel.OpenPanel(openBoxConfig.CostItemID);
  98. return null;
  99. }
  100. if (PlayerGuideManager.Instance.curPhase == 8 && openBoxConfig.ID == 2)
  101. {
  102. //TODO 消耗:不记引导
  103. PlayerManager.Instance.BagController.DeductItem(openBoxConfig.CostItemID, openBoxConfig.oneConsume);
  104. var item = DropManager.Instance.DropItem(999011);
  105. PlayerManager.Instance.BagController.AddItem(item);
  106. return item;
  107. }
  108. // await MarskPanel.OpenPanel();
  109. List<ItemInfo> itemInfos = await PlayerManager.Instance.SummonManager.Summon(configId, 1);
  110. // MarskPanel.ClosePanel();
  111. return itemInfos;
  112. // return await PlayerManager.Instance.SummonManager.Summon(configId, 1);
  113. }
  114. }
  115. }
  116. [UIBinding(prefab = "BoxPanel")]
  117. public partial class BoxPanel : UIPanel
  118. {
  119. private OpenBoxConfig openBoxConfig;
  120. private AccountFileInfo.SummonData summonData;
  121. public static async void OpenBoxPanel()
  122. {
  123. BoxPanel boxPanel = await UIManager.Instance.LoadAndOpenPanel<BoxPanel>(null, layer: UILayer.Middle);
  124. boxPanel.OpenPanel();
  125. }
  126. private void Init()
  127. {
  128. isAddStack = true;
  129. IsShowAppBar = false;
  130. }
  131. public override CTask GetFocus()
  132. {
  133. // AppBarPanel.ClosePanel();
  134. TitlePanel.OpenPanel(new List<int>() { openBoxConfig.CostItemID });
  135. if (PlayerGuideManager.Instance.GuideIsCanDo(8, 1))
  136. {
  137. PlayerGuideManager.Instance.NextGuide();
  138. }
  139. return base.GetFocus();
  140. }
  141. protected override void AddEvent()
  142. {
  143. }
  144. protected override void DelEvent()
  145. {
  146. }
  147. private bool isStartAd = false;
  148. public override void AddButtonEvent()
  149. {
  150. Btn_Score.onClick.AddListener(() => { OpenBoxScorePanel.OpenPanel(); });
  151. oneButton.onClick.AddListener(OnButtonCallBack);
  152. tenButton.onClick.AddListener(TenButtonCallBack);
  153. Btn_Close.onClick.AddListener(CloseButtonCallBack);
  154. bg.onClick.AddListener(CloseButtonCallBack);
  155. Btn_Gl.onClick.AddListener(() => { OpenBoxaiLvPanel.OpenPanel(); });
  156. }
  157. private async void OnButtonCallBack()
  158. {
  159. if (summonData.isSummonSocre)
  160. {
  161. TipMessagePanel.OpenTipMessagePanel(10793);
  162. return;
  163. }
  164. //测试代码
  165. List<ItemInfo> allIitem = await BoxHelper.OneBox(openBoxConfig.ID);
  166. if (allIitem != null)
  167. {
  168. if (PlayerGuideManager.Instance.curPhase == 8)
  169. {
  170. PlayerGuideManager.Instance.StepInit();
  171. }
  172. group.gameObject.SetActive(false);
  173. await MarskPanel.OpenPanel();
  174. fx_ui_chouka.gameObject.SetActive(true);
  175. await TimerComponent.Instance.WaitAsync(700);
  176. MarskPanel.ClosePanel();
  177. GachaPanel gachaPanel = await GachaPanel.OpenPanel(allIitem, 1, openBoxConfig.ID);
  178. await gachaPanel.UIClosed();
  179. fx_ui_chouka.gameObject.SetActive(false);
  180. group.gameObject.SetActive(true);
  181. }
  182. UpdateUi();
  183. }
  184. private async void TenButtonCallBack()
  185. {
  186. //测试代码
  187. List<ItemInfo> allIitem = await BoxHelper.TenBox(openBoxConfig.ID);
  188. if (allIitem != null)
  189. {
  190. group.gameObject.SetActive(false);
  191. await MarskPanel.OpenPanel();
  192. fx_ui_chouka.gameObject.SetActive(true);
  193. await TimerComponent.Instance.WaitAsync(700);
  194. MarskPanel.ClosePanel();
  195. GachaPanel gachaPanel = await GachaPanel.OpenPanel(allIitem, 2, openBoxConfig.ID);
  196. await gachaPanel.UIClosed();
  197. fx_ui_chouka.gameObject.SetActive(false);
  198. group.gameObject.SetActive(true);
  199. }
  200. UpdateUi();
  201. }
  202. private void CloseButtonCallBack()
  203. {
  204. AudioManager.Instance.PlayAudio("ui_fanhui.wav");
  205. UIManager.Instance.HideUIUIPanel(this);
  206. EventManager.Instance.Dispatch(CustomEventType.Combat_EquipFall, null);
  207. }
  208. public async override CTask Close()
  209. {
  210. CombatController.currActiveCombat.isUpdate = true;
  211. await base.Close();
  212. }
  213. public void OpenPanel()
  214. {
  215. CombatController.currActiveCombat.isUpdate = false;
  216. openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(2);
  217. ItemConfig config = ConfigComponent.Instance.Get<ItemConfig>(openBoxConfig.CostItemID);
  218. icon_Oneitem.icon_name = config.icon;
  219. Icon_TenItem.icon_name = config.icon;
  220. onCion.text = "x" + openBoxConfig.oneConsume;
  221. tenCion.text = "x" + openBoxConfig.tenConsume;
  222. Slider_Count.maxValue = openBoxConfig.reward2para1;
  223. TitlePanel.OpenPanel(new List<int>() { openBoxConfig.CostItemID });
  224. UpdateUi();
  225. }
  226. [CustomMethod(CustomMethodType.Update)]
  227. public void Update()
  228. {
  229. if (summonData == null)
  230. return;
  231. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] &&
  232. PlayerManager.Instance.serverTime < summonData.nextTenFreeTime)
  233. {
  234. int time = (int)(summonData.nextTenFreeTime - PlayerManager.Instance.serverTime);
  235. Text_TenFree.text = PlayerManager.TimeToHSM(time / 1000);
  236. }
  237. else
  238. {
  239. if (Text_TenFree.gameObject.activeSelf)
  240. {
  241. Text_TenFree.gameObject.SetActive(false);
  242. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1])
  243. {
  244. tenCion.text = "免费";
  245. }
  246. else
  247. {
  248. tenCion.text = "x" + openBoxConfig.tenConsume;
  249. }
  250. }
  251. }
  252. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] &&
  253. PlayerManager.Instance.serverTime < summonData.nextOneFreeTime)
  254. {
  255. int time = (int)(summonData.nextOneFreeTime - PlayerManager.Instance.serverTime);
  256. Text_OneFree.text = PlayerManager.TimeToHSM(time / 1000);
  257. }
  258. else
  259. {
  260. if (Text_OneFree.gameObject.activeSelf)
  261. {
  262. Text_OneFree.gameObject.SetActive(false);
  263. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1])
  264. {
  265. onCion.text = "免费";
  266. }
  267. else
  268. {
  269. onCion.text = "x" + openBoxConfig.oneConsume;
  270. }
  271. }
  272. }
  273. }
  274. public void UpdateUi()
  275. {
  276. summonData = PlayerManager.Instance.SummonManager.summonDataMap[openBoxConfig.ID];
  277. Slider_Count.value = summonData.baodiCount2;
  278. Text_Count.text = $"{summonData.baodiCount2}/{openBoxConfig.reward2para1}";
  279. if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] &&
  280. PlayerManager.Instance.serverTime >= summonData.nextTenFreeTime)
  281. {
  282. Text_TenFree.gameObject.SetActive(false);
  283. tenCion.text = "免费";
  284. }
  285. //今日次数已用完
  286. else if (summonData.tenFreeCount >= openBoxConfig.oneConsumeFreePara_1[1])
  287. {
  288. Text_TenFree.gameObject.SetActive(false);
  289. tenCion.text = "x" + openBoxConfig.tenConsume;
  290. }
  291. else
  292. {
  293. Text_TenFree.gameObject.SetActive(true);
  294. tenCion.text = "x" + openBoxConfig.tenConsume;
  295. }
  296. if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] &&
  297. PlayerManager.Instance.serverTime >= summonData.nextOneFreeTime)
  298. {
  299. Text_OneFree.gameObject.SetActive(false);
  300. onCion.text = "免费";
  301. }
  302. else if (summonData.oneFreeCount >= openBoxConfig.oneConsumeFreePara[1])
  303. {
  304. onCion.text = "x" + openBoxConfig.oneConsume;
  305. Text_OneFree.gameObject.SetActive(false);
  306. }
  307. else
  308. {
  309. onCion.text = "x" + openBoxConfig.oneConsume;
  310. Text_OneFree.gameObject.SetActive(true);
  311. }
  312. }
  313. }
  314. }