using System; using System.Collections.Generic; using System.Linq; using Core.Audio; using Core.Language; using Core.Utility; using Excel2Json; using Fort23.Core; using Fort23.UTool; using GameLogic.Bag; using UnityEngine; using Random = UnityEngine.Random; namespace Fort23.Mono { [UIBinding(prefab = "GachaPanel")] public partial class GachaPanel : UIPanel { List widgetItems = new List(); private List itemInfos; private int type; private OpenBoxConfig _openBoxConfig; private AccountFileInfo.SummonData SummonData; private void Init() { isAddStack = true; IsShowAppBar = false; } public override CTask GetFocus() { AppBarPanel.ClosePanel(); TitlePanel.ClosePanel(); // TitlePanel.OpenPanel(new List() { GlobalParam.Item_Coin_ID, GlobalParam.Item_Diamond_ID }); return base.GetFocus(); } public override CTask LoseFocus() { TitlePanel.ClosePanel(); return base.LoseFocus(); } protected override void AddEvent() { } protected override void DelEvent() { } public override void AddButtonEvent() { tenButton.onClick.AddListener(() => { float beLv = Utility.UtilTools.GetRandomByWeight(_openBoxConfig.betPara1.ToList(), _openBoxConfig.betPara2); foreach (var itemInfo in itemInfos) { ItemInfo itemInfo1 = new ItemInfo(itemInfo.itemID, (long)(itemInfo.count.Value * (beLv - 1))); PlayerManager.Instance.BagController.AddItem(itemInfo1); } UIManager.Instance.HideUIUIPanel(); }); } public async override CTask AsyncInit(object[] uiData) { itemInfos = uiData[0] as List; type = (int)uiData[1]; _openBoxConfig = ConfigComponent.Instance.Get((int)uiData[2]); SummonData = PlayerManager.Instance.SummonManager.summonDataMap[_openBoxConfig.ID]; Slider_Count.maxValue = _openBoxConfig.reward2para1; Slider_Count.value = SummonData.baodiCount2; Text_Count.text = $"{SummonData.baodiCount2}/{_openBoxConfig.reward2para1}"; StartRoot.gameObject.SetActive(SummonData.isSummonSocre); if (SummonData.isSummonSocre) { Text_JingDu.text = $"当前进度:{SummonData.drawHistory.Count}/{_openBoxConfig.ProgressRewardChoukaCount}"; Text_Score.text = $"目前得分:{SummonData.score}"; OpenBoxScoreRule openBoxScoreRule = CheckAchievements(SummonData); if (openBoxScoreRule.ID != 0) { ScoreName.SetActive(true); Text_ScoreCount.text = $"+{openBoxScoreRule.score}"; } else { ScoreName.SetActive(false); } } else { ScoreName.SetActive(false); } if (itemInfos.Count > 1) { for (var i = 0; i < itemInfos.Count; i++) { WidgetItemType2 widgetItem = await UIManager.Instance.CreateGComponentForObject(TenWidgetitems[i], null); widgetItem.InitWidget(itemInfos[i]); } TenRoot.gameObject.SetActive(true); OneRoot.gameObject.SetActive(false); } if (itemInfos.Count == 1) { for (var i = 0; i < itemInfos.Count; i++) { WidgetItemType2 widgetItem = await UIManager.Instance.CreateGComponentForObject(WidgetItemType2Gam, null); widgetItem.InitWidget(itemInfos[i]); } TenRoot.gameObject.SetActive(false); OneRoot.gameObject.SetActive(true); } return await base.AsyncInit(uiData); } private float timer = 0; public async CTask CusstomInit() { tenButton.gameObject.SetActive(true); } // 检查成就匹配 private OpenBoxScoreRule CheckAchievements(AccountFileInfo.SummonData summonData) { List openBoxScoreRuleList = PlayerManager.Instance.SummonManager.openBoxScoreRuleMap[summonData.id]; List daChengOpenBoxScoreRuleList = new List(); foreach (var openBoxScoreRule in openBoxScoreRuleList) { // 检查连续 Para0 次十连 if (summonData.drawHistory.Count < openBoxScoreRule.para0) continue; bool allDrawsSatisfy = true; // 检查最近 Para0 次十连是否都满足条件 for (int i = summonData.drawHistory.Count - openBoxScoreRule.para0; i < summonData.drawHistory.Count; i++) { if (!PlayerManager.Instance.SummonManager.CheckSingleDraw(openBoxScoreRule, summonData.drawHistory[i].list)) { allDrawsSatisfy = false; break; } } if (allDrawsSatisfy) { daChengOpenBoxScoreRuleList.Add(openBoxScoreRule); } } if (daChengOpenBoxScoreRuleList.Count > 0) { int id = daChengOpenBoxScoreRuleList.Max(obsr => obsr.ID); OpenBoxScoreRule openBoxScoreRule = ConfigComponent.Instance.Get(id); return openBoxScoreRule; } return default; } public override void Close() { // foreach (var widgetItem in widgetItems) // { // UIManager.Instance.DormancyGComponent(widgetItem); // } // // widgetItems.Clear(); tenButton.gameObject.SetActive(false); tenButton.gameObject.SetActive(false); OneRoot.gameObject.SetActive(true); //完成挑战过后自动打开挑战界面 if (_openBoxConfig.ProgressRewardChoukaCount != -1 && SummonData.drawHistory.Count >= _openBoxConfig.ProgressRewardChoukaCount) { OpenBoxScorePanel.OpenPanel(); } base.Close(); } public async static CTask OpenPanel(List itemInfos, int type, int configId) { if (UIManager.Instance.GetComponent() == null || UIManager.Instance.GetComponent().IsClose) { GachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel(null, UILayer.Middle, uiData: new object[] { itemInfos, type, configId }, isShowBG: true); // await TimerComponent.Instance.WaitAsync(300); gachaPanel.CusstomInit(); } } } }