yyl
22 小时以前 4b5b31a23a74c1559460643836d70778d7d49931
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
 
 
public class BlessLVManager : GameSystemManager<BlessLVManager>
{
    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;
    }
 
 
}