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
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
 
public class OSActivityManager : GameSystemManager<OSActivityManager>
{
    Dictionary<int, int[]> rankOpenDays = new Dictionary<int, int[]>();  //排行榜类型:【开始开服天, 结束开服天】
    public Dictionary<int, int[][]> mainLevelRankAwards = new Dictionary<int, int[][]>();  //主线关卡名次:奖励
    public Dictionary<int, int[][]> heroCallRankAwards = new Dictionary<int, int[][]>();  //武将招募名次:奖励
 
    public List<int> osHeroCallGiftSortList = new List<int>();    //开服招募礼包 充值ID + 100000000
 
    //开服榜对应的功能ID
    Dictionary<int, int> rankTypeToFuncID = new Dictionary<int, int>()
    {
        {3, 45},
        {4, 46},
    };
 
 
 
    public override void Init()
    {
 
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerDataInitialize;
        StoreModel.Instance.RefreshBuyShopLimitEvent += RefreshStore;
        FuncOpen.Instance.OnFuncStateChangeEvent += FuncStateChange;
 
        ParseConfig();
    }
 
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= BeforePlayerDataInitialize;
        StoreModel.Instance.RefreshBuyShopLimitEvent -= RefreshStore;
        FuncOpen.Instance.OnFuncStateChangeEvent -= FuncStateChange;
    }
 
    void BeforePlayerDataInitialize()
    {
        osGalaScore = 0; //当前积分 累计的;消耗的是货币55
        osGalaAwardState = 0; //按位记录是否领取
    }
 
    void ParseConfig()
    {
        var config = FuncConfigConfig.Get("OSABillboard");
        rankOpenDays = ConfigParse.ParseIntArrayDict(config.Numerical1);
        mainLevelRankAwards = ConfigParse.ParseIntArray2Dict(config.Numerical2);
        heroCallRankAwards = ConfigParse.ParseIntArray2Dict(config.Numerical3);
 
        var list = StoreModel.Instance.storeTypeDict[(int)StoreFunc.OSHeroCall];
        var _list = RechargeManager.Instance.GetCTGIDListByType(18);
 
        for (int i = 0; i < list.Count; i++)
        {
            var item = list[i];
            osHeroCallGiftSortList.Add(item.shopId);
        }
        for (int i = 0; i < _list.Count; i++)
        {
            osHeroCallGiftSortList.Add(_list[i] + 100000000);
        }
 
        ParseOSGalaConfig();
    }
 
    // 开服排行活动是否开启
    public bool IsOpened(int rankType, bool needLastDay = true)
    {
        if (!rankTypeToFuncID.ContainsKey(rankType))
        {
            return false;
        }
 
        if (!FuncOpen.Instance.IsFuncOpen(rankTypeToFuncID[rankType]))
        {
            return false;
        }
 
        //功能开启里有开始天以开启为准,活动结束后延迟一天关闭展示
        if (!rankOpenDays.ContainsKey(rankType))
        {
            return false;
        }
 
        var openDays = rankOpenDays[rankType];
        if (needLastDay)
        {
            if (TimeUtility.OpenDay > openDays[1])
            {
                return false;
            }
        }
        else
        {
            if (TimeUtility.OpenDay >= openDays[1])
            {
                return false;
            }
        }
 
        return true;
    }
 
    public int GetEndTime(int rankType)
    {
        if (!rankOpenDays.ContainsKey(rankType))
        {
            return 0;
        }
        var openDays = rankOpenDays[rankType];
 
        return TimeUtility.GetRemindTimeByOpenDay(openDays[1]);
    }
 
    int CmpGift(int a, int b)
    {
        bool isSaleOutA = false;
        bool isSaleOutB = false;
 
        if (a < 100000000)
        {
            //商店
            isSaleOutA = StoreModel.Instance.GetShopIDState(a) == 1;
        }
        else
        {
            RechargeManager.Instance.TryGetRechargeCount(a % 100000000, out RechargeCount countData);
            if (countData.totalCount >= CTGConfig.Get(a % 100000000).DailyBuyCount)
            {
                isSaleOutA = true;
            }
        }
        if (b < 100000000)
        {
            isSaleOutB = StoreModel.Instance.GetShopIDState(b) == 1;
        }
        else
        {
            RechargeManager.Instance.TryGetRechargeCount(b % 100000000, out RechargeCount countData);
            if (countData.totalCount >= CTGConfig.Get(b % 100000000).DailyBuyCount)
            {
                isSaleOutB = true;
            }
        }
        if (isSaleOutA != isSaleOutB)
        {
            return isSaleOutA ? 1 : -1;
        }
 
        return a.CompareTo(b);
    }
 
    //开服招募榜礼包
    public void RefreshGiftSortList()
    {
        osHeroCallGiftSortList.Sort(CmpGift);
    }
 
    void RefreshStore()
    {
        UpdateRedpoint();
    }
 
 
    Redpoint osMainLevelRedpoint = new Redpoint(MainRedDot.RedPoint_OSMainLevel);
    Redpoint osHeroCallRedpoint = new Redpoint(MainRedDot.RedPoint_OSHeroCard);
 
    public void UpdateRedpoint()
    {
        osMainLevelRedpoint.state = !DayRemind.Instance.GetDayRemind(DayRemind.OSMainLevel) ? RedPointState.Simple : RedPointState.None;
        osGalaRedpoint2.state = !DayRemind.Instance.GetDayRemind(DayRemind.OSGalaChange) ? RedPointState.Simple : RedPointState.None;
        
        osHeroCallRedpoint.state = RedPointState.None;
        osGalaRedpoint3.state = RedPointState.None;
 
        if (StoreModel.Instance.freeShopDict.Count == 0) return;
 
        if (StoreModel.Instance.freeShopDict.ContainsKey((int)StoreFunc.OSHeroCall) && IsOpened(4, false))
        {
            var shopList = StoreModel.Instance.freeShopDict[(int)StoreFunc.OSHeroCall];
 
            for (int i = 0; i < shopList.Count; i++)
            {
                var shopID = shopList[i];
                var config = StoreConfig.Get(shopID);
                if (StoreModel.Instance.GetShopLimitBuyCount(shopID) < config.LimitCnt)
                {
                    osHeroCallRedpoint.state = RedPointState.Simple;
                    break;
                }
            }
        }
 
        if (StoreModel.Instance.freeShopDict.ContainsKey((int)StoreFunc.OSGalaGift) && IsOpenedOSGala(false))
        {
            var shopList = StoreModel.Instance.freeShopDict[(int)StoreFunc.OSGalaGift];
 
            for (int i = 0; i < shopList.Count; i++)
            {
                var shopID = shopList[i];
                var config = StoreConfig.Get(shopID);
                if (StoreModel.Instance.GetShopLimitBuyCount(shopID) < config.LimitCnt)
                {
                    osGalaRedpoint3.state = RedPointState.Simple;
                    break;
                }
            }
        }
    }
 
    private void FuncStateChange(int funcId)
    {
        switch ((FuncOpenEnum)funcId)
        {
            case FuncOpenEnum.OSMainLevl:
            case FuncOpenEnum.OSHeroCall:
                UpdateRedpoint();
                break;
        }
    }
 
    #region 开服庆典
    //开服庆典
    public int osGalaOpenDays = 0; //持续天数
    public Dictionary<int, int[][]> osGalaScoreAwards = new Dictionary<int, int[][]>();  // 开服庆典积分奖励 积分:奖励
    public Dictionary<int, int> typeToGuideID = new Dictionary<int, int>();
    public List<int> osGalaChangeSortList = new List<int>();    //兑换列表(商店5)
    public List<int> osGalaGiftSortList = new List<int>();    //开服庆典礼包 充值ID + 100000000
 
    public int osGalaScore = 0; //当前积分 累计的;消耗的是货币55
    public int osGalaAwardState = 0; //按位记录是否领取
    public event Action OnOSGalaDataChangeEvent;
 
    // 兑换商店
    Redpoint osGalaRedpoint2 = new Redpoint(MainRedDot.RedPoint_OSGala, MainRedDot.RedPoint_OSGala * 10 + 2);
    // 礼包免费
    Redpoint osGalaRedpoint3 = new Redpoint(MainRedDot.RedPoint_OSGala, MainRedDot.RedPoint_OSGala * 10 + 3);
    // 总奖励
    Redpoint osGalaRedpoint4 = new Redpoint(MainRedDot.RedPoint_OSGala, MainRedDot.RedPoint_OSGala * 10 + 4);
 
 
    public void UpdateOSGalaData(HAB05_tagSCOSACelebrationInfo netPack)
    {
        osGalaScore = (int)netPack.PointTotal;
        osGalaAwardState = (int)netPack.PointAward;
        OnOSGalaDataChangeEvent?.Invoke();
        UpdateGalaRedpoint();
    }
 
    public bool IsOpenedOSGala(bool needLastDay = true)
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.OSGala))
        {
            return false;
        }
        if (needLastDay)
        {
            //结束后延迟一天关闭展示
            return TimeUtility.OpenDay <= osGalaOpenDays;
        }
        else
        {
            return TimeUtility.OpenDay < osGalaOpenDays;
        }
    }
 
    // 是否已领取奖励
    public bool IsGotAward(int index)
    {
        return (osGalaAwardState & (1 << index)) != 0;
    }
 
    // 是否可领取奖励
    public bool CanGetAward(int index, int score)
    {
        if (IsGotAward(index))
        {
            return false;
        }
 
        if (osGalaScore < score)
        {
            return false;
        }
 
        return true;
    }
 
    void ParseOSGalaConfig()
    {
        var config = FuncConfigConfig.Get("OSACelebration");
        osGalaOpenDays = int.Parse(config.Numerical1);
        osGalaScoreAwards = ConfigParse.ParseIntArray2Dict(config.Numerical2);
 
        config = FuncConfigConfig.Get("Achievement");
        typeToGuideID = ConfigParse.ParseIntDict(config.Numerical1);
 
 
        var list = StoreModel.Instance.storeTypeDict[(int)StoreFunc.OSGalaChange];
        for (int i = 0; i < list.Count; i++)
        {
            var item = list[i];
            osGalaChangeSortList.Add(item.shopId);
        }
 
        var _list1 = StoreModel.Instance.storeTypeDict[(int)StoreFunc.OSGalaGift];
        var _list2 = RechargeManager.Instance.GetCTGIDListByType(19);
        for (int i = 0; i < _list1.Count; i++)
        {
            var item = _list1[i];
            osGalaGiftSortList.Add(item.shopId);
        }
        for (int i = 0; i < _list2.Count; i++)
        {
            osGalaGiftSortList.Add(_list2[i] + 100000000);
        }
    }
 
    public void RefreshOSGalaGiftSortList()
    {
        osGalaGiftSortList.Sort(CmpGift);
    }
 
    public void RefreshOSGalaChangeSortList()
    {
        osGalaGiftSortList.Sort(CmpGift);
    }
 
    void UpdateGalaRedpoint()
    {
        osGalaRedpoint4.state = RedPointState.None;
        var keys = osGalaScoreAwards.Keys.ToList();
        keys.Sort();
        for (int i = 0; i < keys.Count; i++)
        {
            var score = keys[i];
            if (CanGetAward(i, score))
            {
                osGalaRedpoint4.state = RedPointState.Simple;
                return;
            }
        }
 
    }
    #endregion
}