using System.Collections; using System.Collections.Generic; using UnityEngine; using System; public class BlessLVManager : GameSystemManager { public int m_TreeLV { get; private set; } // 当前仙树等级 public int m_LVUPState { get; private set; } // 0-非升级中;1-升级中 public int m_LVUPRemainTime { get; private set; } // 升级剩余时间,秒;当升级中且倒计时为0时可发送B223执行升级包进行升级 public int m_FreeTimeCnt { get; private set; } // 今日已免费减时次数 public int m_FreeTimeLast { get; private set; } // 上次免费减时时间戳 public event Action OnBlessLVUpdateEvent; int m_LVPackTime; //收包时间用于计算剩余时间m_LVUPRemainTime public int upgradeTreeMoneyType; //升级仙树消耗的货币类型 public int timeUpTreeItemID; //加速仙树升级的道具ID public int timeUpTreeItemSubTime; //减少仙树升级时间的道具减少的时间 public int dayFreeMaxTimes; //每日免费升级次数 public int freeTimeCD; //免费减少时间的冷却CD 分 public int freeSubTime; //免费减少的时间 分 public int lastTreeLV; //上一次树的等级 用于打开界面的时候播放下升级特效 public override void Init() { m_TreeLV = 0; m_LVUPState = 0; m_LVUPRemainTime = 0; m_LVPackTime = 0; DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOK; GlobalTimeEvent.Instance.fiveSecondEvent += OnTimeEvent; ParseConfig(); } public override void Release() { DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOK; GlobalTimeEvent.Instance.fiveSecondEvent -= OnTimeEvent; } void OnPlayerLoginOK() { lastTreeLV = 0; AutoUpgrade(); UpdateTreeRedpoint(); } void ParseConfig() { var config = FuncConfigConfig.Get("TreeLVUP"); upgradeTreeMoneyType = int.Parse(config.Numerical1); var arr = config.Numerical2.Split('|'); timeUpTreeItemID = int.Parse(arr[0]); timeUpTreeItemSubTime = int.Parse(arr[1]); dayFreeMaxTimes = int.Parse(config.Numerical3); freeTimeCD = int.Parse(config.Numerical4); freeSubTime = int.Parse(config.Numerical5); } public void UpdateBlessLVInfo(HB121_tagMCTreeInfo netPack) { m_TreeLV = netPack.TreeLV; m_LVUPState = netPack.LVUPState; m_LVUPRemainTime = (int)netPack.LVUPRemainTime; m_FreeTimeCnt = netPack.FreeTimeCnt; m_FreeTimeLast = (int)netPack.FreeTimeLast; m_LVPackTime = TimeUtility.AllSeconds; if (lastTreeLV == 0) { lastTreeLV = m_TreeLV; } OnBlessLVUpdateEvent?.Invoke(); UpdateTreeRedpoint(); AutoUpgrade(); } public int GetLVUPRemainTime() { if (m_LVUPState == 0) return 0; return m_LVUPRemainTime - (TimeUtility.AllSeconds - m_LVPackTime); } public int GetFreeRemainTime() { if (m_LVUPState == 0) return 0; return m_FreeTimeLast + freeTimeCD * 60 - TimeUtility.AllSeconds; } Redpoint redpointTree = new Redpoint(MainRedDot.BlessLVRedpoint); Redpoint redpointTreeItem = new Redpoint(MainRedDot.BlessLVRedpoint, MainRedDot.BlessLVRedpoint * 10); Redpoint redpointTreeFree = new Redpoint(MainRedDot.BlessLVRedpoint, MainRedDot.BlessLVRedpoint * 10 + 1); void UpdateTreeRedpoint() { redpointTreeFree.state = RedPointState.None; redpointTreeItem.state = RedPointState.None; redpointTree.state = RedPointState.None; var config = TreeLVConfig.Get(m_TreeLV); if (config == null) return; //非升级中检查升级材料 if (m_LVUPState == 0) { if (UIHelper.GetMoneyCnt(upgradeTreeMoneyType) >= config.LVUPNeedMoney) { redpointTree.state = RedPointState.Simple; } } else { //检查时间道具 和 免费的时间 if (PackManager.Instance.GetSinglePack(PackType.Item).HasItem(timeUpTreeItemID)) { redpointTreeItem.state = RedPointState.Simple; return; } if (m_FreeTimeCnt > 0 && GetFreeRemainTime() <= 0) { redpointTreeFree.state = RedPointState.Simple; return; } } } public void AutoUpgrade() { //时间结束自动通知服务端升级,或者打开界面时,或者上线 都做检查 if (m_LVUPState == 0) { return; } if (GetLVUPRemainTime() > 0) { return; } var pack = new CB223_tagCMTreeLVUP(); pack.Type = 1; GameNetSystem.Instance.SendInfo(pack); } void OnTimeEvent() { //升级中检查 倒计时结束;非升级中检查免费次数时间 红点 if (m_LVUPState == 1) { //升级 AutoUpgrade(); } UpdateTreeRedpoint(); } //装备品质的起始表现,最小1 public int GetStartEquipQuality() { var rateList = TreeLVConfig.Get(m_TreeLV).EquipColorRateList; for (int i = 0; i < rateList.Length; i++) { if (rateList[i] != 0) return i + 1; } return 1; } }