少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
 
using LitJson;
using System.Collections.Generic;
using System;
 
namespace vnxbqy.UI
{
    
    public class NewYearFairylandCeremonyModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
    {
        public ReceiveState receiveState { get; private set; }
      
        public override void Init()
        {
            ParseFuncConfig();
            ParseAllPeoplePartyConfig();
            ParseUniquenessArriveConfig();
            //OperationTimeHepler.Instance.operationEndEvent += OnActiveEnd;
            
        }
 
        public override void UnInit()
        {
 
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            worldLv = 0;
            sumHiPoint = 0;
            preAwardRecord = 0;
            peopleTaskRecordDict.Clear();
            receiveState = ReceiveState.NoReach;
        }
 
        public void OnAfterPlayerDataInitialize()
        {
 
        }
 
        public void OnPlayerLoginOk()
        {
            CheckRechargeRed();
            CheckPeoplePartyRed();
        }
        #region 处理服务端数据
        public int worldLv { get; private set;}
        public void GetServerActiveInfo(HAC0B_tagGCNewFairyCeremonyInfo info)
        {
            worldLv = info.WorldLV;
            OperationTimeHepler.Instance.RefreshNewYearFairyCeremonyInfo(info);
        }
 
        public Action RefreshRechargeStateAct;
        public void GetServerRechargeInfo(HAA22_tagMCNewXJSDRecharge info)
        {
            switch(info.State)
            {
                case 0:
                    receiveState = ReceiveState.NoReach;
                    break;
                case 1:
                    receiveState = ReceiveState.Reach;
                    break;
                case 2:
                    receiveState = ReceiveState.Already;
                    break;
 
            }
            if(RefreshRechargeStateAct != null)
            {
                RefreshRechargeStateAct();
            }
            CheckRechargeRed();
        }
 
     
        public int sumHiPoint { get; private set; }
        private int preAwardRecord;
        Dictionary<int, bool> peopleAwardRecordDict = new Dictionary<int, bool>();  //领取记录
        Dictionary<int, int> peopleTaskRecordDict = new Dictionary<int, int>();  //全民来嗨任务状态记录
        public Action<int> RefreshHiPointAct;
        public Action RefreshHiAwardStateAct;
    
        public void GetServerPeopleInfo(HAA23_tagMCNewAllPeoplePartyInfo info)
        {
            peopleAwardRecordDict.Clear();
            sumHiPoint = (int)info.CurPoint;
            int sumIndex = GetPeoplePartAwardlist().Count;
            for (int i = 0; i < sumIndex; i++)
            {
                bool isRecord = MathUtility.GetBitValue(info.AwardRecord, (ushort)i);
                peopleAwardRecordDict.Add(i, isRecord);
            }
 
            for(int i = 0; i < info.Count; i++)
            {
                if(!peopleTaskRecordDict.ContainsKey((int)info.BuyCountList[i].ActID))
                {
                    peopleTaskRecordDict.Add((int)info.BuyCountList[i].ActID,info.BuyCountList[i].CurTimes);
                }
                else
                {
                    peopleTaskRecordDict[(int)info.BuyCountList[i].ActID] = info.BuyCountList[i].CurTimes;
                }
 
                if(RefreshHiPointAct != null)
                {
                    RefreshHiPointAct((int)info.BuyCountList[i].ActID);
                }
            }
 
            if(preAwardRecord != info.AwardRecord)
            {
                if(RefreshHiAwardStateAct != null)
                {
                    RefreshHiAwardStateAct();
                }
            }
            CheckPeoplePartyRed();
            preAwardRecord = (int)info.AwardRecord;
        }
 
        public int GetPeopleTaskTimesById(int actId)
        {
            int times = 0;
            peopleTaskRecordDict.TryGetValue(actId,out times);
            return times;
        }
 
        public bool GetPeopleAwardRecordByIndex(int index)
        {
            bool isReceive = false;
            peopleAwardRecordDict.TryGetValue(index,out isReceive);
            return isReceive;
        }
 
        private void OnActiveEnd(Operation type, int arg2)
        {
            if (type != Operation.NewYearFairyCeremony) return;
 
            peopleTaskRecordDict.Clear();
            sumHiPoint = 0;
            worldLv = 0;
        }
 
        public void SendReceiveAward(GotServerRewardType type,int index)
        {
            CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
            getReward.RewardType = (byte)type;
            getReward.DataEx = (uint)index;
            getReward.DataExStrLen = 0;
            getReward.DataExStr = string.Empty;
            GameNetSystem.Instance.SendInfo(getReward);
        }
 
        public void SendGetRankInfo(RankType type)
        {
            C1001_tagCWatchBillboard rankPack = new C1001_tagCWatchBillboard();
            rankPack.Type = (byte)type;
            GameNetSystem.Instance.SendInfo(rankPack);
        }
        #endregion
 
        #region 处理本地数据
 
        #region 解析功能配置表
        Dictionary<CeremonyType, Dictionary<int, List<int>>> typeLvDict = new Dictionary<CeremonyType, Dictionary<int, List<int>>>();
        Dictionary<int, List<AwardItem>> rechargeAwardDict = new Dictionary<int, List<AwardItem>>();
        public Dictionary<int, int> fireDict = new Dictionary<int, int>();
        Dictionary<int, Dictionary<int, List<AwardItem>>> fireGiftsDict = new Dictionary<int, Dictionary<int, List<AwardItem>>>();
 
        private void ParseFuncConfig()
        {
            FuncConfigConfig lvConfig = FuncConfigConfig.Get("NewCeremonyWorldLv");
            JsonData lvData = JsonMapper.ToObject(lvConfig.Numerical1);
            foreach (var type in lvData.Keys)
            {
                Dictionary<int, List<int>> lvDict = new Dictionary<int, List<int>>();
                typeLvDict.Add((CeremonyType)int.Parse(type), lvDict);
                if (lvData[type].IsArray)
                {
                    for (int i = 0; i < lvData[type].Count; i++)
                    {
                        JsonData rangeData = lvData[type][i];
                        List<int> lvlist = new List<int>();
                        lvDict.Add(i, lvlist);
                        lvlist.Add(int.Parse(rangeData[0].ToString()));
                        lvlist.Add(int.Parse(rangeData[1].ToString()));
                    }
                }
            }
 
            FuncConfigConfig rechargeConfig = FuncConfigConfig.Get("NewCeremonyRecharge");
            JsonData rechargeData = JsonMapper.ToObject(rechargeConfig.Numerical1);
            foreach (var index in rechargeData.Keys)
            {
                List<AwardItem> awardItems = new List<AwardItem>();
                rechargeAwardDict.Add(int.Parse(index), awardItems);
                if (rechargeData[index].IsArray)
                {
                    for (int i = 0; i < rechargeData[index].Count; i++)
                    {
                        JsonData itemData = rechargeData[index][i];
                        AwardItem item = new AwardItem(int.Parse(itemData[0].ToString()), int.Parse(itemData[1].ToString()),
                            int.Parse(itemData[2].ToString()));
                        awardItems.Add(item);
                    }
                }
            }
 
            FuncConfigConfig fireConfig = FuncConfigConfig.Get("NewCeremonyFireParty");
            JsonData fireData = JsonMapper.ToObject(fireConfig.Numerical1);
            foreach (var index in fireData.Keys)
            {
                fireDict.Add(int.Parse(index), int.Parse(fireData[index].ToString()));
            }
 
            FuncConfigConfig fireAwardConfig = FuncConfigConfig.Get("NewCeremonyFireAward");
            JsonData fireAwardData = JsonMapper.ToObject(fireAwardConfig.Numerical1);
            foreach (var index in fireAwardData.Keys)
            {
                Dictionary<int, List<AwardItem>> jobFireAwardDict = new Dictionary<int, List<AwardItem>>();
                fireGiftsDict.Add(int.Parse(index), jobFireAwardDict);
                foreach (var job in fireAwardData[index].Keys)
                {
                    List<AwardItem> awardItems = new List<AwardItem>();
                    jobFireAwardDict.Add(int.Parse(job), awardItems);
                    if (fireAwardData[index][job].IsArray)
                    {
                        for (int i = 0; i < fireAwardData[index][job].Count; i++)
                        {
                            JsonData itemData = fireAwardData[index][job][i];
                            AwardItem item = new AwardItem(int.Parse(itemData[0].ToString()), int.Parse(itemData[1].ToString()),
                                int.Parse(itemData[2].ToString()));
                            awardItems.Add(item);
                        }
                    }
                }
 
            }
 
        }
 
        #endregion
 
        #region 解析全民来嗨
        List<NewAllPeoplePartyConfig> allPeoples = new List<NewAllPeoplePartyConfig>();
        List<NewAllPeoplePartyAwardConfig> allPeopleAwards = new List<NewAllPeoplePartyAwardConfig>();
        Dictionary<int, Dictionary<int, List<AwardItem>>> jobToHiAwardDict = new Dictionary<int, Dictionary<int, List<AwardItem>>>();
        private void ParseAllPeoplePartyConfig()
        {
            allPeoples = NewAllPeoplePartyConfig.GetValues();
            allPeopleAwards = NewAllPeoplePartyAwardConfig.GetValues();
            for (int i = 0; i < allPeopleAwards.Count; i++)
            {
                Dictionary<int, List<AwardItem>> awardKeyDict = new Dictionary<int, List<AwardItem>>();
                jobToHiAwardDict.Add(allPeopleAwards[i].ID, awardKeyDict);
                JsonData awardData = JsonMapper.ToObject(allPeopleAwards[i].Award);
                foreach (var job in awardData.Keys)
                {
                    List<AwardItem> awardItems = new List<AwardItem>();
                    awardKeyDict.Add(int.Parse(job), awardItems);
                    if (awardData[job].IsArray)
                    {
                        for (int j = 0; j < awardData[job].Count; j++)
                        {
                            JsonData itemData = awardData[job][j];
                            AwardItem item = new AwardItem(int.Parse(itemData[0].ToString()), int.Parse(itemData[1].ToString()),
                                int.Parse(itemData[2].ToString()));
                            awardItems.Add(item);
                        }
                    }
                }
            }
        }
        #endregion
 
        #region 解析绝版降临
        Dictionary<string, Dictionary<int, List<AwardItem>>> rankAwardDict = new Dictionary<string, Dictionary<int, List<AwardItem>>>();
        private void ParseUniquenessArriveConfig()
        {
            List<NewUniquenessArriveConfig> arriveConfigs = NewUniquenessArriveConfig.GetValues();
            for (int i = 0; i < arriveConfigs.Count; i++)
            {
                string key = StringUtility.Contact(arriveConfigs[i].WorldLvNum, arriveConfigs[i].Rank);
                Dictionary<int, List<AwardItem>> awardKeyDict = new Dictionary<int, List<AwardItem>>();
                rankAwardDict.Add(key, awardKeyDict);
                JsonData awardData = JsonMapper.ToObject(arriveConfigs[i].Award);
                foreach (var job in awardData.Keys)
                {
                    List<AwardItem> awardItems = new List<AwardItem>();
                    awardKeyDict.Add(int.Parse(job), awardItems);
                    if (awardData[job].IsArray)
                    {
                        for (int j = 0; j < awardData[job].Count; j++)
                        {
                            JsonData itemData = awardData[job][j];
                            AwardItem item = new AwardItem(int.Parse(itemData[0].ToString()), int.Parse(itemData[1].ToString()),
                                int.Parse(itemData[2].ToString()));
                            awardItems.Add(item);
                        }
                    }
                }
            }
        }
        #endregion
 
        public int GetWorldLvIndex(CeremonyType type)
        {
           if(typeLvDict.ContainsKey(type))
            {
                foreach(var index in typeLvDict[type].Keys)
                {
                    if(worldLv >= typeLvDict[type][index][0] && worldLv <= typeLvDict[type][index][1])
                    {
                        return index;
                    }
                }
            }
            return -1;
        }
 
        public List<AwardItem> GetRechargeAwardByLv()
        {
            int index = GetWorldLvIndex(CeremonyType.Recharge);
            List<AwardItem> awardItems = null;
            rechargeAwardDict.TryGetValue(index,out awardItems);
            return awardItems;
        }
 
        public StoreConfig GetFireIdByLv()
        {
            int index = GetWorldLvIndex(CeremonyType.Fire);
            int storeId = 0;
            fireDict.TryGetValue(index,out storeId);
            StoreConfig storeConfig = StoreConfig.Get(storeId);
            return storeConfig;
        }
 
        public List<AwardItem> GetFireAwardlist()
        {
            int index = GetWorldLvIndex(CeremonyType.Fire);
            if(fireGiftsDict.ContainsKey(index))
            {
                if(fireGiftsDict[index].ContainsKey(PlayerDatas.Instance.baseData.Job))
                {
                    return fireGiftsDict[index][PlayerDatas.Instance.baseData.Job];
                }
            }
            return null;
        }
 
        public bool CheckIsBuyFireCondi(StoreConfig storeConfig,int buyNum = 1)
        {
            ulong price =(ulong)(storeConfig.MoneyNumber * buyNum);
            if(UIHelper.GetMoneyCnt(storeConfig.MoneyType) >= price)
            {
                return true;
            }
            return false;
        }
 
        List<NewAllPeoplePartyConfig> openTasklist = new List<NewAllPeoplePartyConfig>();
        public List<NewAllPeoplePartyConfig> GetPeoplePartTasklist()
        {
            openTasklist.Clear();
            for(int i = 0; i < allPeoples.Count; i++)
            {
                var funcId = allPeoples[i].FuncID;
                if(funcId == 0 || FuncOpen.Instance.IsFuncOpen(funcId))
                {
                    openTasklist.Add(allPeoples[i]);
                }
            }
            openTasklist.Sort(CompareByTimes);
            return openTasklist;
        }
 
        private int CompareByTimes(NewAllPeoplePartyConfig start, NewAllPeoplePartyConfig end)
        {
            bool startIsComplte = PeopleTaskComplete(start);
            bool endIsComplte = PeopleTaskComplete(end);
            if (startIsComplte.CompareTo(endIsComplte) != 0) return startIsComplte.CompareTo(endIsComplte);
 
            int startIndex = allPeoples.IndexOf(start);
            int endIndex = allPeoples.IndexOf(end);
            if (startIndex.CompareTo(endIndex) != 0) return startIndex.CompareTo(endIndex);
 
            return 0;
        }
 
        public bool PeopleTaskComplete(NewAllPeoplePartyConfig partyConfig)
        {
            if (GetPeopleTaskTimesById(partyConfig.ID) >= partyConfig.TotalTimes)
            {
                return true;
            }
            return false;
        }
 
        List<NewAllPeoplePartyAwardConfig> worldAwardlist = new List<NewAllPeoplePartyAwardConfig>();
        public List<NewAllPeoplePartyAwardConfig> GetPeoplePartAwardlist()
        {
            worldAwardlist.Clear();
            int index = GetWorldLvIndex(CeremonyType.WholePeople);
            for (int i = 0; i < allPeopleAwards.Count; i++)
            {
                if(allPeopleAwards[i].WorldLvNum == index)
                {
                    worldAwardlist.Add(allPeopleAwards[i]);
                }
            }
            worldAwardlist.Sort(CompareByIndex);
            return worldAwardlist;
        }
 
        public int CompareByIndex(NewAllPeoplePartyAwardConfig start, NewAllPeoplePartyAwardConfig end)
        {
            int startIndex = start.Index;
            int endIndex = end.Index;
            if (startIndex.CompareTo(endIndex) != 0) return startIndex.CompareTo(endIndex);
 
            startIndex = allPeopleAwards.IndexOf(start);
            endIndex = allPeopleAwards.IndexOf(end);
            if (startIndex.CompareTo(endIndex) != 0) return startIndex.CompareTo(endIndex);
 
            return 0;
        }
 
        public List<AwardItem> GetPeoplePartyAwardById(int peopleId)
        {
            if(jobToHiAwardDict.ContainsKey(peopleId))
            {
                if(jobToHiAwardDict[peopleId].ContainsKey(PlayerDatas.Instance.baseData.Job))
                {
                    return jobToHiAwardDict[peopleId][PlayerDatas.Instance.baseData.Job];
                }
            }
            return null;
        }
 
        public List<AwardItem> GetRankAwardByLv(int rank)
        {
            int index = GetWorldLvIndex(CeremonyType.OutOfPrint);
            string key = StringUtility.Contact(index,rank);
            int playerJob = PlayerDatas.Instance.baseData.Job;
 
            if(rankAwardDict.ContainsKey(key))
            {
                if(rankAwardDict[key].ContainsKey(playerJob))
                {
                    return rankAwardDict[key][playerJob];
                }
            }
            return null;
        }
        #endregion
 
        #region 红点逻辑处理
        public const int FairyCeremony_RedKey = 216;
        public Redpoint fairyCeremonyRedp = new Redpoint(FairyCeremony_RedKey);
 
        public const int CeremonyRecharge_RedKey = 21601;
        public Redpoint rechargeRedp = new Redpoint(FairyCeremony_RedKey,CeremonyRecharge_RedKey);
        public const int RechargeReceiveBtn_RedKey = 2160101;
        public Redpoint receiveBtnRedp = new Redpoint(CeremonyRecharge_RedKey, RechargeReceiveBtn_RedKey);
        public void CheckRechargeRed()
        {
            if (!OperationTimeHepler.Instance.SatisfyOpenCondition(Operation.NewYearFairyCeremony)) return;
 
            if(receiveState == ReceiveState.Reach)
            {
                receiveBtnRedp.state = RedPointState.Simple;
            }
            else
            {
                receiveBtnRedp.state = RedPointState.None;
            }
        }
 
        public const int CeremonyPeople_RedKey = 21603;
        public Redpoint peopleRedp = new Redpoint(FairyCeremony_RedKey, CeremonyPeople_RedKey);
 
        public void CheckPeoplePartyRed()
        {
            if (!OperationTimeHepler.Instance.SatisfyOpenCondition(Operation.NewYearFairyCeremony)) return;
 
            int index = 0;
            if(IsPeopleAwardRecive(out index))
            {
                peopleRedp.state = RedPointState.Simple;
            }
            else
            {
                peopleRedp.state = RedPointState.None;
            }
        }
        #endregion
 
        public bool IsPeopleAwardRecive(out int index)
        {
            index = 0;
            if (worldAwardlist.Count < 1) return false;
 
            for (int i = 0; i < worldAwardlist.Count; i++)
            {
                if (!GetPeopleAwardRecordByIndex(worldAwardlist[i].Index))
                {
                    if (sumHiPoint >= worldAwardlist[i].NeedPoint)
                    {
                        index = i;
                        return true;
                    }
                }
            }
            return false;
        }
 
        public struct AwardItem
        {
            public int itemId { get; private set;}
            public int itemCount { get; private set; }
            public int isBind { get; private set; }
            public AwardItem(int id,int cnt,int isBind)
            {
                this.itemId = id;
                this.itemCount = cnt;
                this.isBind = isBind;
            }
        }
 
        public enum ReceiveState
        {
            NoReach, //未充值
            Reach,  //可领取
            Already, //已领取
        }
        /// <summary>
        /// 庆典类型
        /// </summary>
        public enum CeremonyType
        {
            Recharge = 1, // 充值
            Fire = 2, //烟花
            WholePeople = 3, //全民
            OutOfPrint = 4, //绝版降临
        }
    }
}