123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- 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<WidgetItem> widgetItems = new List<WidgetItem>();
- private List<ItemInfo> 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<int>() { 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<GachaPanel>();
- });
- }
- public async override CTask<bool> AsyncInit(object[] uiData)
- {
- itemInfos = uiData[0] as List<ItemInfo>;
- type = (int)uiData[1];
- _openBoxConfig = ConfigComponent.Instance.Get<OpenBoxConfig>((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<WidgetItemType2>(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<WidgetItemType2>(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<OpenBoxScoreRule> openBoxScoreRuleList = PlayerManager.Instance.SummonManager.openBoxScoreRuleMap[summonData.id];
- List<OpenBoxScoreRule> daChengOpenBoxScoreRuleList = new List<OpenBoxScoreRule>();
- 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<OpenBoxScoreRule>(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<ItemInfo> itemInfos, int type, int configId)
- {
- if (UIManager.Instance.GetComponent<GachaPanel>() == null ||
- UIManager.Instance.GetComponent<GachaPanel>().IsClose)
- {
- GachaPanel gachaPanel = await UIManager.Instance.LoadAndOpenPanel<GachaPanel>(null, UILayer.Middle,
- uiData: new object[] { itemInfos, type, configId }, isShowBG: true);
- // await TimerComponent.Instance.WaitAsync(300);
- gachaPanel.CusstomInit();
- }
- }
- }
- }
|