123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- 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<List<ItemInfo>> TenBox(int configId, bool isFree = false)
- {
- AccountFileInfo.SummonData summonData = PlayerManager.Instance.SummonManager.summonDataMap[configId];
- OpenBoxConfig openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(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<List<ItemInfo>> OneBox(int configId)
- {
- AccountFileInfo.SummonData summonData = PlayerManager.Instance.SummonManager.summonDataMap[configId];
- OpenBoxConfig openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>(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<BoxPanel>(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<string, string>();
- 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<string, string>();
- dic.Add("Chouka", "");
- // YouLoftSDK.Instance.CustomEvent("AdsPlayOver", dic);
- AccountFileInfo.Instance.playerData.boxFree = true;
- AccountFileInfo.Instance.SavePlayerData();
- // Btn_AdsFree.gameObject.SetActive(false);
- List<ItemInfo> allIitem = await BoxHelper.TenBox(openBoxConfig.ID, true);
- if (allIitem != null)
- GachaPanel.OpenPanel(allIitem, 2, openBoxConfig.ID);
- });
- }
- private async void OnButtonCallBack()
- {
- //测试代码
- List<ItemInfo> allIitem = await BoxHelper.OneBox(openBoxConfig.ID);
- if (allIitem != null)
- GachaPanel.OpenPanel(allIitem, 1, openBoxConfig.ID);
- UpdateUi();
- }
- private async void TenButtonCallBack()
- {
- //测试代码
- List<ItemInfo> 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<OpenBoxConfig>(1);
- ItemConfig config = ConfigComponent.Instance.Get<ItemConfig>(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);
- }
- }
- }
- }
|