少年修仙传客户端代码仓库
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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
 
using LitJson;
using System.Collections.Generic;
using System;
using System.Linq;
 
namespace vnxbqy.UI
{
    
    public class TreasureFindHostModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
    {
        Dictionary<int, List<FindTreasureInfo>> findTreasures = new Dictionary<int, List<FindTreasureInfo>>();
 
        public List<int> treasureIdlist { get; set; }
        public event Action TreasureFindHostCompleteAct;
 
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
        EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
 
        public override void Init()
        {
            var configs = TreasureFindHostConfig.GetValues();
            foreach (var config in configs)
            {
                int treasureId = config.MagicWeaponID;
                List<FindTreasureInfo> list;
                if (!findTreasures.TryGetValue(treasureId, out list))
                {
                    list = new List<FindTreasureInfo>();
                    findTreasures.Add(treasureId, list);
                }
                var treasureInfo = new FindTreasureInfo(config.ID);
                list.Add(treasureInfo);
            }
 
            treasureIdlist = findTreasures.Keys.ToList();
            SetTreasureCellRedKey();
            PlayerDatas.Instance.playerDataRefreshEvent += RefreshPlayerData;
            packModel.refreshItemCountEvent += RefreshEquipInfo;
            treasureModel.treasureStateChangeEvent += RefreshTreasureState;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            jumpTreasureId = 0;
            foreach (var list in findTreasures.Values)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    list[i].IsCompleted = false;
                }
            }
        }
 
        public void OnAfterPlayerDataInitialize()
        {
           
        }
 
        public void OnPlayerLoginOk()
        {
            for (int i = 0; i < treasureIdlist.Count; i++)
            {
                if (i == 0)
                {
                    RedPointStateCtrl(treasureIdlist[i]);
                }
                else
                {
                    Treasure treasure = null;
                    treasureModel.TryGetTreasure(treasureIdlist[i - 1], out treasure);
                    if (treasure != null && treasure.state == TreasureState.Collected)
                    {
                        RedPointStateCtrl(treasureIdlist[i]);
                    }
                }
            }
 
            TreasureFindHostState();
        }
 
        public override void UnInit()
        {
            PlayerDatas.Instance.playerDataRefreshEvent -= RefreshPlayerData;
            packModel.refreshItemCountEvent -= RefreshEquipInfo;
            treasureModel.treasureStateChangeEvent -= RefreshTreasureState;
        }
 
        public Dictionary<int, List<FindTreasureInfo>> GetFindTreasureInfoDict()
        {
            return findTreasures;
        }
 
 
        //条件类型 类型说明    数量 条件
        //1    穿戴X件X价X品质X套装X部位装备 件数[[阶, 品质, 是否套装, 部位]]
        //2    穿戴X件X价X品质装备 件数[x阶, x品质]
        //3    X阶装备总强化等级 强化等级[x阶]
        //4    X阶装备总升星等级 升星等级[x阶]
        //5    X阶装备总洗炼等级 洗炼等级[x阶]
        //6    X阶装备总宝石等级 宝石等级[x阶]
        //7    坐骑达到X阶 阶   无
        //8    天星塔达到X层 层   无
        //9    符印塔达到X层 层   无
        //10    击杀X只BOSS 只数[boss归类索引]
        //11    神兵达到X级 等级[x类型]
        //12    玩家等级达到X级 等级  无
        //13    获得法宝XXX 个数[法宝ID]
        //14    境界达到XXX 境界  无
 
        public bool IsReachCondition(FindTreasureInfo treasureInfo, out int findCount)
        {
            findCount = 0;
            if (treasureInfo == null)
            {
                return false;
            }
 
            switch (treasureInfo.type)
            {
                case 1:
                    if (CheckType1IsReachCondition(treasureInfo))
                    {
                        findCount = 1;
                        return true;
                    }
                    return false;
                case 2:
                    for (int i = 0; i <= 12; i++)
                    {
                        var equipIndex = EquipSet.ClientPlaceToServerPlace(new Int2(treasureInfo.conditions[0], i));
                        var itemModel = packModel.GetItemByIndex(PackType.Equip, equipIndex);
                        if (itemModel != null && itemModel.config.ItemColor >= treasureInfo.conditions[1])
                        {
                            findCount++;
                            if (findCount >= treasureInfo.targetNum)
                                return true;
                        }
                    }
                    return false;
                case 3:
                    findCount = 0;
                    for (int i = 1; i <= 12; i++)
                    { 
                        findCount += ModelCenter.Instance.GetModel<EquipStrengthModel>().GetStrengthLevel(treasureInfo.conditions[0], i);
                        if (findCount >= treasureInfo.targetNum)
                            return true;
                    }
                    return false;
                case 4:
                    findCount = ModelCenter.Instance.GetModel<EquipStarModel>().GetTotalStarLevel(treasureInfo.conditions[0]);
                    if (findCount >= treasureInfo.targetNum)
                        return true;
                    return false;
                case 5:
                    findCount = 0;
                    for (int i = 1; i <= 12; i++)
                    {
                        findCount += ModelCenter.Instance.GetModel<EquipTrainModel>().GetTrainLevelEx(new Int2(treasureInfo.conditions[0], i));
                        if (findCount >= treasureInfo.targetNum)
                            return true;
                    }
                    return false;
                case 6:
                    findCount = ModelCenter.Instance.GetModel<EquipGemModel>().GetGemLevelByEquipLevel(treasureInfo.conditions[0]);
                    if (findCount >= treasureInfo.targetNum)
                        return true;
                    return false;
                case 7:
                    findCount = ModelCenter.Instance.GetModel<MountModel>().HorseLV;
                    if (findCount >= treasureInfo.targetNum)
                        return true;
                    return false;
                case 8:
                    findCount = ModelCenter.Instance.GetModel<SkyTowerModel>().highestPassFloor;
                    if (findCount >= treasureInfo.targetNum)
                        return true;
                    return false;
                case 9:
                    findCount = ModelCenter.Instance.GetModel<RuneModel>().passRuneTowerFloor;
                    if (findCount >= treasureInfo.targetNum)
                        return true;
                    return false;
                case 10:
                    if (ModelCenter.Instance.GetModel<FindPreciousModel>().totalKillCountDict.ContainsKey(treasureInfo.conditions[0]))
                    { 
                        findCount = ModelCenter.Instance.GetModel<FindPreciousModel>().totalKillCountDict[treasureInfo.conditions[0]];
                        if (findCount >= treasureInfo.targetNum)
                            return true;
                    }
                    return false;
                case 11:
                    var godWeaponInfo = ModelCenter.Instance.GetModel<MagicianModel>().GetGodWeaponInfo(treasureInfo.conditions[0]);
                    if (godWeaponInfo != null)
                    {
                        findCount = godWeaponInfo.level;
                        if (findCount >= treasureInfo.targetNum)
                            return true;
                    }
                    return false;
                case 12:
                    findCount = PlayerDatas.Instance.baseData.LV;
                    if (findCount >= treasureInfo.targetNum)
                        return true;
                    return false;
                case 13:
                    Treasure treasure = null;
                    if (treasureModel.TryGetTreasure(treasureInfo.conditions[0], out treasure))
                    {
                        if (treasure.state == TreasureState.Collected)
                        {
                            findCount = 1;
                            return true;
                        }
                    }
                    return false;
                case 14:
                    findCount = PlayerDatas.Instance.baseData.realmLevel;
                    if (findCount >= treasureInfo.targetNum)
                        return true;
                    return false;
            }
            return false;
        }
 
        private bool CheckType1IsReachCondition(FindTreasureInfo treasureInfo)
        {
            foreach (var findHostEquip in treasureInfo.findHostEquips)
            {
                var equipIndex = EquipSet.ClientPlaceToServerPlace(new Int2(findHostEquip.level, findHostEquip.place));
                var itemModel = packModel.GetItemByIndex(PackType.Equip, equipIndex);
                if (itemModel != null)
                {
                    if (itemModel.config.ItemColor >= findHostEquip.itemColor)
                    {
                        if (findHostEquip.isSuit)
                        {
                            if (ItemLogicUtility.Instance.IsSuitEquip(itemModel.itemId))
                            {
                                return true;
                            }
                        }
                        else
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
 
 
 
        public bool TryGetFindTreasureInfo(int findId,out FindTreasureInfo info)
        {
            info = null;
            TreasureFindHostConfig hostConfig = TreasureFindHostConfig.Get(findId);
            if (hostConfig != null)
            {
                List<FindTreasureInfo> infolist = null;
                findTreasures.TryGetValue(hostConfig.MagicWeaponID,out infolist);
                if(infolist != null)
                {
                    for (int i = 0; i < infolist.Count; i++)
                    {
                        if(infolist[i].id == findId)
                        {
                            info = infolist[i];
                            return true;
                        }
                    }
                }
            }
            return false;
        }
 
        public bool IsReachUnlock(int treasureId,out int progress)
        {
            progress = 0;
            List<FindTreasureInfo> infolist = null;
            findTreasures.TryGetValue(treasureId,out infolist);
            if (infolist == null)
            {
                return false;
            }
            
            for(int i = 0; i < infolist.Count; i++)
            {
                if(infolist[i].IsCompleted)
                {
                    progress += 1;
                }
            }
 
            if(progress >= infolist.Count)
            {
                return true;
            }
 
            return false;
        }
 
        private void RefreshTreasureState(int id)
        {
            if (!findTreasures.ContainsKey(id)) return;
 
            Treasure treasure = null;
            treasureModel.TryGetTreasure(id, out treasure);
            if(treasure.state == TreasureState.Collected)
            {
                TreasureFindHostState();
                for (int i = 0; i < treasureIdlist.Count; i++)
                {
                    if (treasureIdlist[i] == id)
                    {
                        RedPointStateCtrl(treasureIdlist[i]);
                        if (i < treasureIdlist.Count - 1)
                        {
                            RedPointStateCtrl(treasureIdlist[i + 1]);
                            break;
                        }
                    }
                }
            }
        }
 
        public void TreasureFindHostState()
        {
            if(CheckTreasureFindHostFinish())
            {
                if(TreasureFindHostCompleteAct != null)
                {
                    TreasureFindHostCompleteAct();
                }
            }
        }
 
        public bool CheckTreasureFindHostFinish()
        {
            bool isfinish = true;
            foreach (var id in findTreasures.Keys)
            {
                Treasure treasure = null;
                treasureModel.TryGetTreasure(id, out treasure);
                if (treasure.state != TreasureState.Collected)
                {
                    isfinish = false;
                    break;
                }
            }
            return isfinish;
        }
        public int jumpTreasureId { get; set;}
        public bool IsUnlockTreasure(int treasureId)
        {
            jumpTreasureId = 0;
           for (int i = 0; i < treasureIdlist.Count; i++)
            {
                if(treasureIdlist[i] == treasureId)
                {
                    if(i != 0)
                    {
                        Treasure treasure = null;
                        treasureModel.TryGetTreasure(treasureIdlist[i-1], out treasure);
                        if (treasure.state != TreasureState.Collected)
                        {
                            TreasureConfig config = TreasureConfig.Get(treasure.id);
                            SysNotifyMgr.Instance.ShowTip("UnLock_TreasureLimit", config.Name);
                            return false;
                        }
                        else
                        {
                            jumpTreasureId = treasureId;
                            return true;
                        }
                    }
                    else
                    {
                        jumpTreasureId = treasureId;
                        return true;
                    }
                }
            }
 
            return false;
        }
 
        public int SelectTreasureId { get; private set; }
        public void SetSelectTreasureId(int treasureId)
        {
            SelectTreasureId = treasureId;
        }
 
        public List<int> adviceIdlist = new List<int>();
        public void SetAdviceIdlist(List<int> idlist)
        {
            if (idlist == null || idlist.Count < 1) return;
 
            adviceIdlist.Clear();
            adviceIdlist.AddRange(idlist);
        }
 
        #region 处理服务端数据
        public event Action OnCompletedAct;
        public void GetServerAwardRecord(HA348_tagMCXBXZAwardRecordList awardRecord)
        {
            for(int i = 0; i < awardRecord.RecordCnt; i++)
            {
                var record = awardRecord.RecordList[i];
                var index = record.RecordIndex;
                for(int j = 0; j < 31; j++)
                {
                    var findHostId = index * 31 + j;
                    FindTreasureInfo treasureInfo;
                    if(TryGetFindTreasureInfo(findHostId,out treasureInfo))
                    {
                        bool isCompleted = MathUtility.GetBitValue(record.Record, (ushort)j);
                        if(isCompleted != treasureInfo.IsCompleted)
                        {
                            treasureInfo.IsCompleted = isCompleted;
                            if (treasureInfo.IsCompleted)
                            {
                                if (OnCompletedAct != null)
                                {
                                    OnCompletedAct();
                                }
                                RedPointStateCtrl(treasureInfo.treasureId);
                            }
                        }
                    }
                }
            }
        }
 
        public void SendGetRewardQuest(int id)
        {
            CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
            getReward.RewardType = (byte)GotServerRewardType.Def_RewardType_XBXZ;
            getReward.DataEx = (uint)id;
            getReward.DataExStrLen = 0;
            getReward.DataExStr = string.Empty;
            GameNetSystem.Instance.SendInfo(getReward);
        }
        #endregion
 
        #region 红点逻辑
        public const int TreasureFindHost_RedKey = 210;
        public Redpoint findHostRed = new Redpoint(TreasureFindHost_RedKey);
        private Dictionary<int, Redpoint> treasureCellRedDict = new Dictionary<int, Redpoint>();
        public void SetTreasureCellRedKey()
        {
            treasureCellRedDict.Clear();
            int i = 0;
            foreach(var id in findTreasures.Keys)
            {
                int redKey = TreasureFindHost_RedKey * 100 + i;
                Redpoint redpoint = new Redpoint(TreasureFindHost_RedKey,redKey);
                treasureCellRedDict.Add(id,redpoint);
                i += 1;
            }
        }
 
        public int GetTreasureCellRedIdById(int treasureId)
        {
            if(treasureCellRedDict.ContainsKey(treasureId))
            {
                return treasureCellRedDict[treasureId].id;
            }
 
            return 0;
        }
 
        private void RefreshEquipInfo(PackType type, int index, int itemId)
        {
            if (type != PackType.Equip)
            {
                return;
            }
 
            for (int i = 0; i < treasureIdlist.Count; i++)
            {
                if (i == 0)
                {
                    RedPointStateCtrl(treasureIdlist[i]);
                }
                else
                {
                    Treasure treasure = null;
                    treasureModel.TryGetTreasure(treasureIdlist[i - 1], out treasure);
                    if (treasure != null && treasure.state == TreasureState.Collected)
                    {
                        RedPointStateCtrl(treasureIdlist[i]);
                    }
                }
            }
        }
 
        private void RefreshPlayerData(PlayerDataType type)
        {
            if (type != PlayerDataType.CDBPlayerRefresh_FuncDef) return;
 
            for (int i = 0; i < treasureIdlist.Count; i++)
            {
                if (i == 0)
                {
                    RedPointStateCtrl(treasureIdlist[i]);
                }
                else
                {
                    Treasure treasure = null;
                    treasureModel.TryGetTreasure(treasureIdlist[i - 1], out treasure);
                    if (treasure != null && treasure.state == TreasureState.Collected)
                    {
                        RedPointStateCtrl(treasureIdlist[i]);
                    }
                }
            }
        }
 
        public void RedPointStateCtrl(int treasureId)
        {
            if (treasureCellRedDict.ContainsKey(treasureId))
            {
                treasureCellRedDict[treasureId].state = RedPointState.None;
            }
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.TreasureFindHost)) return;
 
            List<FindTreasureInfo> list = findTreasures[treasureId];
            for (int i = 0; i < list.Count; i++)
            {
                int process;
                bool isReach = IsReachCondition(list[i], out process);
                if(!list[i].IsCompleted && isReach)
                {
                    treasureCellRedDict[treasureId].state = RedPointState.Simple;
                    return;
                }
            }
 
            Treasure treasure = null;
            treasureModel.TryGetTreasure(treasureId, out treasure);
 
            var progress = 0;
            if (IsReachUnlock(treasureId,out progress) 
                && treasure != null && treasure.state != TreasureState.Collected)
            {
                treasureCellRedDict[treasureId].state = RedPointState.Simple;
                return;
            }
        }
        #endregion
    }
 
    public class FindTreasureInfo
    {
        public readonly int id;
        public readonly int treasureId;
        public readonly int type;
        public readonly int targetNum;
        public readonly int jumpId; //跳转最终法宝
        public readonly int recommendJumpID;  //推荐跳转ID 和 findRecommandItems同字段来源
 
        public List<FindHostEquip> findHostEquips { get; private set; }  //需要满足的装备条件
        public List<Item> findHostItems = new List<Item>(); //  货币和奖励2选1显示
        public List<FindHostMoney> findHostMoneys = new List<FindHostMoney>();
        public Dictionary<int, List<int>> findRecommandItems = new Dictionary<int, List<int>>();
        public List<int> conditions = new List<int>(); //原类型1的装备存findHostEquips
 
        public bool IsCompleted;
 
        public FindTreasureInfo(int id)
        {
            var config = TreasureFindHostConfig.Get(id);
 
            this.id = id;
            this.type = config.Type;
            this.targetNum = config.NeedCnt;
            this.jumpId = config.JumpID;
            this.treasureId = config.MagicWeaponID;
 
            IsCompleted = false;
 
            switch (type)
            {
                case 1:
                    var equipArray = JsonMapper.ToObject<int[][]>(config.Condition);
                    findHostEquips = new List<FindHostEquip>();
                    for (int i = 0; i < equipArray.Length; i++)
                    {
                        findHostEquips.Add(new FindHostEquip()
                        {
                            level = equipArray[i][0],
                            itemColor = equipArray[i][1],
                            isSuit = equipArray[i][2] == 1,
                            place = equipArray[i][3],
                        });
                    }
                    break;
                default:
                    conditions = JsonMapper.ToObject<int[]>(config.Condition).ToList();
                    break;
            }
 
            var itemArray = JsonMapper.ToObject<int[][]>(config.AwardItemList);
            for (int i = 0; i < itemArray.Length; i++)
            {
                findHostItems.Add(new Item()
                {
                    id = itemArray[i][0],
                    count = itemArray[i][1],
                });
            }
            var moneyArray = JsonMapper.ToObject<int[][]>(config.Money);
            for (int i = 0; i < moneyArray.Length; i++)
            {
                findHostMoneys.Add(new FindHostMoney()
                {
                    moneyType = moneyArray[i][0],
                    count = moneyArray[i][1],
                });
            }
 
            //如果是纯数字就是跳转,否则是推荐装备
            if (!int.TryParse(config.AdviceIds, out recommendJumpID))
            {
                recommendJumpID = 0;
                var recommandJson = JsonMapper.ToObject(config.AdviceIds);
                foreach (var jobKey in recommandJson.Keys)
                {
                    findRecommandItems.Add(int.Parse(jobKey), JsonMapper.ToObject<int[]>(recommandJson[jobKey].ToJson()).ToList());
                }
            }
        }
    }
 
    public struct FindHostEquip
    {
        public int level;
        public int place;
        public int itemColor;
        public bool isSuit;
    }
 
    public struct FindHostMoney
    {
        public int moneyType;
        public int count;
    }
}