lcy
13 小时以前 11dbbeb220a366951cbcccb5b823b845b77e1b9d
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
using System;
using System.Collections.Generic;
using UnityEngine.UI;
using System.Linq;
using LitJson;
 
public class InvestModel : GameSystemManager<InvestModel>
{
    public const int monthCardType = 1; // 月卡
    public const int foreverCardType = 2; //永久卡 权限 
 
 
    //投资对应奖励
    Dictionary<int, int[][]> m_InvestItems = new Dictionary<int, int[][]>();
    Dictionary<int, int> m_InvestDays = new Dictionary<int, int>(); //投资对应天数
    Dictionary<int, int> m_InvestMaxDays = new Dictionary<int, int>();  //投资对应最大购买累加天数
 
    //投资对应充值ID
    Dictionary<int, int[]> m_InvestRechargeIds = new Dictionary<int, int[]>();
    Dictionary<int, int> m_InvestCTGIDToType = new Dictionary<int, int>();
 
    //投资对应购买情况
    Dictionary<int, InvestInfo> m_InvestInfos = new Dictionary<int, InvestInfo>();
    //投资类型
 
    //--特权--
    //增加副本购买次数
    Dictionary<int, Dictionary<int, int>> m_InvestAddFBCount = new Dictionary<int, Dictionary<int, int>>();
    //副本购买次数免费的副本ID 和 m_InvestAddFBCount 配合使用 相当于 特权增加副本上限但是发包流程需和服务端商量
    Dictionary<int, int[]> m_InvestFreeFBID = new Dictionary<int, int[]>();
    //演武场增加上限
    Dictionary<int, int> m_InvestArenaMaxCnt = new Dictionary<int, int>();
    //祝福树能量增加上限
    Dictionary<int, int> m_InvestAddBlessEnergyCount = new Dictionary<int, int>();
 
    // 特权权限数量
    Dictionary<int, int> m_PrivilegeLins = new Dictionary<int, int>();
    // 战斗倍数开启对应特权
    Dictionary<int, int> m_PrivilegeFightSpeed = new Dictionary<int, int>();
    // 英雄积分招募开启的特权类型
    int[] heroScoreCallOpenType;
        
 
    public event Action<int> onInvestUpdate;
 
    public Redpoint redpoint1 = new Redpoint(MainRedDot.RedPoint_PrivilegeCard, MainRedDot.RedPoint_PrivilegeCard * 10 + 1);
    public Redpoint redpoint2 = new Redpoint(MainRedDot.RedPoint_PrivilegeCard, MainRedDot.RedPoint_PrivilegeCard * 10 + 2);
 
 
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        RechargeManager.Instance.rechargeCountEvent += OnRechargeCountEvent;
        //通过配置决定是否有此投资项,如港台没有登录投资
        ParseConfig();
 
    }
 
 
 
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
        RechargeManager.Instance.rechargeCountEvent -= OnRechargeCountEvent;
    }
 
    public bool IsOpen()
    {
        return FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.PrivilegeCard);
    }
 
    
    public void OnBeforePlayerDataInitialize()
    {
        m_InvestInfos.Clear();
        lastTotalBuyCountDict.Clear();
    }
 
 
 
    void ParseConfig()
    {
        var funcConfig = FuncConfigConfig.Get("InvestCost");
        m_InvestRechargeIds = ConfigParse.ParseIntArrayDict(funcConfig.Numerical1);
        foreach (var item in m_InvestRechargeIds)
        {
            m_InvestCTGIDToType[item.Value[0]] = item.Key;
        }
 
        funcConfig = FuncConfigConfig.Get("InvestDay");
        m_InvestDays = ConfigParse.ParseIntDict(funcConfig.Numerical1);
        m_InvestMaxDays = ConfigParse.ParseIntDict(funcConfig.Numerical2);
        m_InvestItems = ConfigParse.ParseIntArray2Dict(funcConfig.Numerical3);
 
 
        funcConfig = FuncConfigConfig.Get("InvestPower");
        m_InvestAddFBCount = ConfigParse.ParseDictInDict(funcConfig.Numerical1);
        m_InvestFreeFBID = ConfigParse.ParseIntArrayDict(funcConfig.Numerical2);
        m_InvestArenaMaxCnt = ConfigParse.ParseIntDict(funcConfig.Numerical3);
        m_InvestAddBlessEnergyCount = ConfigParse.ParseIntDict(funcConfig.Numerical4);
 
        funcConfig = FuncConfigConfig.Get("PrivilegeCard");
        m_PrivilegeLins = ConfigParse.ParseIntDict(funcConfig.Numerical1);
        m_PrivilegeFightSpeed = ConfigParse.ParseIntDict(funcConfig.Numerical2);
        heroScoreCallOpenType = JsonMapper.ToObject<int[]>(funcConfig.Numerical3);
        
    }
 
    Dictionary<int, int> lastTotalBuyCountDict = new Dictionary<int, int>();
    void OnRechargeCountEvent(int ctgID)
    {
 
        if (m_InvestCTGIDToType.ContainsKey(ctgID))
        {
            var type = m_InvestCTGIDToType[ctgID];
            RechargeManager.Instance.TryGetRechargeCount(ctgID, out var rechargeCount);
            if (!DTC0403_tagPlayerLoginLoadOK.finishedLogin)
            {
                lastTotalBuyCountDict[type] = rechargeCount.totalCount;
                return;
            }
            var count = 0;
            lastTotalBuyCountDict.TryGetValue(type, out count);
            if (count < rechargeCount.totalCount)
            {
                lastTotalBuyCountDict[type] = rechargeCount.totalCount;
                UIManager.Instance.OpenWindow<PrivilegeActiveCardWin>(type);
            }
        }
    }
 
 
 
    //获取投资剩余时间 秒
    public int GetInvestLeftTime(int type)
    {
        if (type == 1 && m_InvestInfos[type].InvestEndTime > 0)
        {
            //月卡 限时类型的投资 未到期就算投资
            return m_InvestInfos[type].InvestEndTime - TimeUtility.AllSeconds;
        }
        return 0;
    }
 
 
 
    //0-未投资 1-可领取 2-已领取
    public int GetInvestState(int type)
    {
        if (IsInvested(type))
        {
            if (m_InvestInfos[type].AwardState == 0)
            {
                return 1;
            }
            return 2;
        }
        return 0;
    }
 
 
    //判断是否购买了投资
    public bool IsInvested(int type)
    {
        if (!m_InvestInfos.ContainsKey(type))
        {
            return false;
        }
        if (type == 1)
        {
            //月卡 限时类型的投资 未到期就算投资
            return m_InvestInfos[type].InvestEndTime > 0 && m_InvestInfos[type].InvestEndTime > TimeUtility.AllSeconds;
        }
        
        //永久类型的投资 只要购买了就算投资
        return m_InvestInfos[type].InvestBuyTime > 0;
    }
 
 
    //type 投资类型
    public void SendGetReward(int type, int id = 0)
    {
        var pak = new CA541_tagCMGetInvestReward();
        pak.InvestType = (byte)type;
        pak.RewardIndex = (byte)id;
        GameNetSystem.Instance.SendInfo(pak);
    }
 
    //购买投资
    public void BuyInvest(int type)
    {
        RechargeManager.Instance.CTG(GetOrderInfo(type));
    }
 
 
    public void UpdateInvestInfo(HA338_tagSCInvestInfo package)
    {
 
        m_InvestInfos[package.InvestType] = new InvestInfo()
        {
            InvestBuyTime = (int)package.InvestBuyTime,
            InvestEndTime = (int)package.InvestEndTime,
            AwardState = package.AwardState
        };
 
 
        UpdateRedpoint();
 
        if (onInvestUpdate != null)
        {
            onInvestUpdate(package.InvestType);
        }
    }
 
    void UpdateRedpoint()
    {
        if (!IsOpen())
        {
            return;
        }
 
        redpoint1.state = GetInvestState(monthCardType) == 1 ? RedPointState.Simple : RedPointState.None;
        redpoint2.state = GetInvestState(foreverCardType) == 1 ? RedPointState.Simple : RedPointState.None;
 
    }
 
    #region 特权接口
 
    //副本增加的购买次数上限
    public int GetAddFBBuyCount(int _mapID)
    {
        int addCount = 0;
        foreach (var item in m_InvestAddFBCount)
        {
            if (!IsInvested(item.Key))
            {
                continue;
            }
            foreach (var mapID in item.Value.Keys)
            {
                if (mapID == _mapID)
                {
                    addCount += item.Value[mapID];
                }
            }
        }
 
        return addCount;
    }
 
    //副本免费的购买次数
    public bool GetFBIsFree(int _mapID)
    {
        foreach (var item in m_InvestFreeFBID)
        {
            if (!IsInvested(item.Key))
            {
                continue;
            }
            foreach (var mapID in item.Value)
            {
                if (mapID == _mapID)
                {
                    return true;
                }
            }
        }
        return false;
    }
 
 
    public int GetPrivilegeLins(int type)
    {
        if (m_PrivilegeLins.ContainsKey(type))
        {
            return m_PrivilegeLins[type];
        }
        return 0;
    }
 
    public OrderInfoConfig GetOrderInfo(int type)
    {
        var ids = m_InvestRechargeIds[type];
        for (int i = 0; i < ids.Length; i++)
        {
            OrderInfoConfig config;
            if (RechargeManager.Instance.TryGetOrderInfo(ids[i], out config))
            {
                return config;
            }
        }
        return null;
    }
 
    public int GetCTGID(int type)
    {
        return m_InvestRechargeIds[type][0];
    }
 
    public int[][] GetDayAwards(int type)
    {
        return m_InvestItems[type];
    }
 
    //演武场凭证上限
    public int GetArenaAddMaxCount()
    {
        int addCount = 0;
        foreach (var item in m_InvestArenaMaxCnt)
        {
            if (!IsInvested(item.Key))
            {
                continue;
            }
            addCount += item.Value;
        }
 
        return addCount;
    }
 
    //购买天数是否达上限
    public bool IsBuyMaxDay(int type)
    {
        if (m_InvestMaxDays.ContainsKey(type) && m_InvestInfos.ContainsKey(type))
        {
            if (m_InvestInfos[type].InvestEndTime > 0)
            {
                return (m_InvestInfos[type].InvestEndTime - TimeUtility.AllSeconds) / 60 / 60 / 24 + m_InvestDays[type] >= m_InvestMaxDays[type];
            }
        }
        return false;
    }
 
    //祝福能量上限
    public int GetBlessAddEnergyMax()
    {
        int addCount = 0;
        foreach (var item in m_InvestAddBlessEnergyCount)
        {
            if (!IsInvested(item.Key))
            {
                continue;
            }
            addCount += item.Value;
        }
 
        return addCount;
    }
 
    //是否激活英雄积分召唤
    public bool IsActiveHeroScoreCall()
    {
        foreach (var type in heroScoreCallOpenType)
        {
            if (IsInvested(type))
            {
                return true;
            }
        }
        return false;
    }
 
    public bool IsActiveFightSpeed(int speed)
    {
        foreach (var item in m_PrivilegeFightSpeed)
        {
            if (!IsInvested(item.Key))
            {
                continue;
            }
            if (item.Value == speed)
            {
                return true;
            }
        }
        return false;
    }
 
    #endregion
 
 
 
 
    public struct InvestInfo
    {
        public int InvestBuyTime;    // 投资购买时间戳,永久的通过该时间判断是否有效或已过天数,任意类型均有该值,过期没有重置,前端自己判断
        public int InvestEndTime;    // 投资到期时间戳,非永久的通过该时间判断到期时间,有天数限制的才有值
        public int AwardState;    // 今日是否已领取奖励
    }
}