using System.Collections.Generic; using Core.Language; using Core.Utility; using Excel2Json; using Fort23.Core; using Fort23.UTool; using GameLogic.Bag; using GameLogic.Combat.CombatTool; using GameLogic.Player; using UnityEngine; namespace Fort23.Mono { public static class BoxHelper { public async static CTask> TenBox(int configId, bool isFree = false) { AccountFileInfo.SummonData summonData = PlayerManager.Instance.SummonManager.summonDataMap[configId]; OpenBoxConfig openBoxConfig = ConfigComponent.Instance.Get(configId); //有免费次数,并且让到时间了就免费抽 if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] && PlayerManager.Instance.serverTime >= summonData.nextTenFreeTime) { return PlayerManager.Instance.SummonManager.Summon(configId, 10); } else { //验证道具是否足够 if (PlayerManager.Instance.BagController.IsEnough(openBoxConfig.CostItemID, openBoxConfig.tenConsume)) { return PlayerManager.Instance.SummonManager.Summon(configId, 10); } else { TipMessagePanel.OpenTipMessagePanel("道具不足", Vector2.zero); return null; } } } public async static CTask> OneBox(int configId) { AccountFileInfo.SummonData summonData = PlayerManager.Instance.SummonManager.summonDataMap[configId]; OpenBoxConfig openBoxConfig = ConfigComponent.Instance.Get(configId); //有免费次数,并且让到时间了就免费抽 if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] && PlayerManager.Instance.serverTime >= summonData.nextOneFreeTime) { return PlayerManager.Instance.SummonManager.Summon(configId, 1); } else { //验证道具是否足够 if (PlayerManager.Instance.BagController.IsEnough(openBoxConfig.CostItemID, openBoxConfig.oneConsume)) { return PlayerManager.Instance.SummonManager.Summon(configId, 1); } else { TipMessagePanel.OpenTipMessagePanel("道具不足", Vector2.zero); return null; } } } } [UIBinding(prefab = "BoxPanel")] public partial class BoxPanel : UIPanel { private OpenBoxConfig openBoxConfig; private AccountFileInfo.SummonData summonData; public static async void OpenBoxPanel() { BoxPanel boxPanel = await UIManager.Instance.LoadAndOpenPanel(null, layer: UILayer.Middle, isShowBG: true); boxPanel.OpenPanel(); } private void Init() { isAddStack = true; IsShowAppBar = false; } public override CTask GetFocus() { // AppBarPanel.ClosePanel(); return base.GetFocus(); } protected override void AddEvent() { } protected override void DelEvent() { } private bool isStartAd = false; public override void AddButtonEvent() { oneButton.onClick.AddListener(OnButtonCallBack); tenButton.onClick.AddListener(TenButtonCallBack); close.onClick.AddListener(CloseButtonCallBack); bg.onClick.AddListener(CloseButtonCallBack); Btn_AdsFree.onClick.AddListener(async () => { if (AccountFileInfo.Instance.playerData.boxFree) { TipMessagePanel.OpenTipMessagePanel(938, Vector2.zero); return; } if (isStartAd) return; isStartAd = true; var dic = new Dictionary(); dic.Add("Chouka", ""); // YouLoftSDK.Instance.CustomEvent("OnclickAds", dic); // bool isOK = await YouLoftSDK.Instance.ShowAd(); bool isOK = true; isStartAd = false; if (!isOK) { return; } dic = new Dictionary(); dic.Add("Chouka", ""); // YouLoftSDK.Instance.CustomEvent("AdsPlayOver", dic); AccountFileInfo.Instance.playerData.boxFree = true; AccountFileInfo.Instance.SavePlayerData(); // Btn_AdsFree.gameObject.SetActive(false); List allIitem = await BoxHelper.TenBox(openBoxConfig.ID, true); if (allIitem != null) GachaPanel.OpenPanel(allIitem, 2, openBoxConfig.ID); }); } private async void OnButtonCallBack() { //测试代码 List allIitem = await BoxHelper.OneBox(openBoxConfig.ID); if (allIitem != null) GachaPanel.OpenPanel(allIitem, 1, openBoxConfig.ID); UpdateUi(); } private async void TenButtonCallBack() { //测试代码 List allIitem = await BoxHelper.TenBox(openBoxConfig.ID); if (allIitem != null) GachaPanel.OpenPanel(allIitem, 2, openBoxConfig.ID); UpdateUi(); } private void CloseButtonCallBack() { UIManager.Instance.HideUIUIPanel(this); EventManager.Instance.Dispatch(CustomEventType.Combat_EquipFall, null); } public override void Close() { CombatController.currActiveCombat.isUpdate = true; base.Close(); } public void OpenPanel() { CombatController.currActiveCombat.isUpdate = false; openBoxConfig = ConfigComponent.Instance.Get(1); ItemConfig config = ConfigComponent.Instance.Get(openBoxConfig.CostItemID); icon_Oneitem.icon_name = config.icon; Icon_TenItem.icon_name = config.icon; onCion.text = "x" + openBoxConfig.oneConsume; tenCion.text = "x" + openBoxConfig.tenConsume; UpdateUi(); } [CustomMethod(CustomMethodType.Update)] public void Update() { if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] && PlayerManager.Instance.serverTime < summonData.nextTenFreeTime) { int time = (int)(summonData.nextTenFreeTime - PlayerManager.Instance.serverTime); Text_TenFree.text = PlayerManager.TimeToHSM(time/1000); } else { if (Text_TenFree.gameObject.activeSelf) { Text_TenFree.gameObject.SetActive(false); tenCion.text = "x" + openBoxConfig.tenConsume; } } if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] && PlayerManager.Instance.serverTime < summonData.nextOneFreeTime) { int time = (int)(summonData.nextOneFreeTime - PlayerManager.Instance.serverTime); Text_OneFree.text = PlayerManager.TimeToHSM(time/1000); } else { if (Text_OneFree.gameObject.activeSelf) { Text_OneFree.gameObject.SetActive(false); onCion.text = "x" + openBoxConfig.oneConsume; } } } public void UpdateUi() { summonData = PlayerManager.Instance.SummonManager.summonDataMap[1]; if (summonData.tenFreeCount < openBoxConfig.oneConsumeFreePara_1[1] && PlayerManager.Instance.serverTime >= summonData.nextTenFreeTime) { Text_TenFree.gameObject.SetActive(false); tenCion.text = "免费"; } //今日次数已用完 else if (summonData.tenFreeCount >= openBoxConfig.oneConsumeFreePara_1[1]) { Text_TenFree.gameObject.SetActive(false); tenCion.text = "x" + openBoxConfig.tenConsume; } else { Text_TenFree.gameObject.SetActive(true); tenCion.text = "x" + openBoxConfig.tenConsume; } if (summonData.oneFreeCount < openBoxConfig.oneConsumeFreePara[1] && PlayerManager.Instance.serverTime >= summonData.nextOneFreeTime) { Text_OneFree.gameObject.SetActive(false); onCion.text = "免费"; } else if (summonData.oneFreeCount >= openBoxConfig.oneConsumeFreePara[1]) { onCion.text = "x" + openBoxConfig.oneConsume; Text_OneFree.gameObject.SetActive(false); } else { onCion.text = "x" + openBoxConfig.oneConsume; Text_OneFree.gameObject.SetActive(true); } } } }