少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
 
namespace Snxxz.UI
{
    public class PetBackpack//宠物背包
    {
        public int PetClass;//宠物阶级
        public int PetStatus;//宠物当前状态 1为出战 0未出战
        public int ItemPlace;//宠物位置索引
        public int[] PetSkill;//宠物当前学习的技能
        public int petExp; //宠物当前经验
    }
 
    public enum PetEnum
    {
        PetDan = 0,//灵宠丹
        PetDebris = 1,//灵宠碎片
        PetStone = 2,//灵宠魂石
    }
 
    public class PetModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        public Dictionary<int, int> _TagPetItem = new Dictionary<int, int>();//关于灵兽魂石
        public Dictionary<int, PetBackpack> _DicPetBack = new Dictionary<int, PetBackpack>();//宠物背包列表
        public Dictionary<int, int> _PetSkillAcquire = new Dictionary<int, int>();//灵宠已获得的技能(同类技能只存最高等级)1.技能TypeID,2.技能ID
        public delegate void Delegate_HB701(HB701_tagMCPetLV info);
        public delegate void Delegate_Ha339(HA339_tagMCAttrFruitEatCntList info);
        public static event Delegate_Ha339 Event_Ha339;//灵兽魂石
        public delegate void Delegate_H0704();
        public static event Delegate_H0704 Event_H0704Add;//灵宠添加(进阶)
        public static Action<int> Event_H0704Update;//灵宠刷新
        public delegate void SpiritPetPlay(int _toPlay = 0);//宠物是否出战
        public static event SpiritPetPlay Event_SpiritPetPlay;
        public int PetNow = 0;//用来保存出战的灵宠
        public bool Wait = true;//(使用灵宠丹)等待回包
        public Dictionary<int, Redpoint> DeblockingRedPoint = new Dictionary<int, Redpoint>();//解锁按钮红点(灵宠红点子级)
        public Dictionary<int, Redpoint> PetRedpoint = new Dictionary<int, Redpoint>();//灵宠列表
        public Dictionary<int, Redpoint> CultivateRedPoint = new Dictionary<int, Redpoint>();//灵宠培养按钮红点
        private List<PetInfoConfig> Sortpet = new List<PetInfoConfig>();//用于红点排序
 
        public int MinAtkNunber = 0;//灵宠最小攻击力
        public int MaxAtkNunber = 0;//灵宠最大攻击力
 
        public int PetStoneItemId = 0;//用来记录坐骑魂石的ID
 
        public bool isServerPrepare { get; private set; }
        private int PetDanExp = 0;//灵宠丹经验
        public List<int> ListEffectSkill = new List<int>();
        PackModel _playerPack;
        PackModel playerPack
        {
            get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
        }
 
        public Dictionary<int, string> petLvNameDict { get; private set; }
        public int curPetId { get; set; }
        public int petUpgradeToolId { get; set; }
        public int autoActivePetId { get; private set; }
        public bool hasSendAutoActive { get; private set; }
 
        public event Action PlayerLoginOkData;
        private Dictionary<int, int> DicDefaultPet = new Dictionary<int, int>();
        List<PetInfoConfig> allPetConfigs = new List<PetInfoConfig>();
 
        Dictionary<SkillEffectGroup, int> integrationSkills = new Dictionary<SkillEffectGroup, int>();
        Dictionary<SkillEffectGroup, List<int>> integrationPetSkills = new Dictionary<SkillEffectGroup, List<int>>();
        Dictionary<int, SkillEffectGroup> petSkillEffectValues = new Dictionary<int, SkillEffectGroup>();
        Dictionary<int, int> petSkills = new Dictionary<int, int>();
 
        public override void Init()
        {
            ToAddSorting();
            playerPack.refreshItemCountEvent += OnItemRefreshEvent;
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChange;
            PetAttributeWin.IsRedPointCultivate += IsRedPointCultivate;
            PetNumberPreservation();
 
            petLvNameDict = new Dictionary<int, string>();
            FuncConfigConfig petLvName = FuncConfigConfig.Get("PetQuality");
            int[] petLvArray = ConfigParse.GetMultipleStr<int>(petLvName.Numerical1);
            string[] petLvNameArray = ConfigParse.GetMultipleStr(petLvName.Numerical2);
            for (int i = 0; i < petLvArray.Length; i++)
            {
                if (!petLvNameDict.ContainsKey(petLvArray[i]))
                {
                    petLvNameDict.Add(petLvArray[i], petLvNameArray[i]);
                }
            }
 
            petUpgradeToolId = int.Parse(FuncConfigConfig.Get("PetUpItem").Numerical1);
            string str = FuncConfigConfig.Get("PetSkillEffect").Numerical1;
            int[] listeffect = ConfigParse.GetMultipleStr<int>(str);
            ListEffectSkill.Clear();
            for (int i = 0; i < listeffect.Length; i++)
            {
                ListEffectSkill.Add(listeffect[i]);
            }
            string PetRedDotstr = FuncConfigConfig.Get("MountPetRedDot").Numerical2;
            DicDefaultPet = ConfigParse.GetDic<int, int>(PetRedDotstr);
            PetDanExp = int.Parse(FuncConfigConfig.Get("PetUpItem").Numerical2);
 
            var funcConfig = FuncConfigConfig.Get("PetHorseSkillIntegration");
            var intArray = ConfigParse.GetMultipleStr<int>(funcConfig.Numerical1);
            for (int i = 0; i < intArray.Length; i++)
            {
                var skillConfig = SkillConfig.Get(intArray[i]);
                if (skillConfig != null)
                {
                    var effectValue = SkillConfig.GetSkillEffectValue(skillConfig);
                    integrationSkills.Add(effectValue, intArray[i]);
                }
            }
 
            funcConfig = FuncConfigConfig.Get("AutoActivePetHorse");
            autoActivePetId = int.Parse(funcConfig.Numerical1);
 
            var configs = PetInfoConfig.GetValues();
            foreach (var config in configs)
            {
                for (int i = 0; i < config.SkillID.Length; i++)
                {
                    var skillConfig = SkillConfig.Get(config.SkillID[i]);
                    var effectValue = SkillConfig.GetSkillEffectValue(skillConfig);
 
                    if (integrationSkills.ContainsKey(effectValue))
                    {
                        List<int> skills = null;
                        if (!integrationPetSkills.TryGetValue(effectValue, out skills))
                        {
                            skills = new List<int>();
                            integrationPetSkills.Add(effectValue, skills);
                        }
                        skills.Add(config.SkillID[i]);
                    }
 
                    petSkills.Add(config.SkillID[i], config.ID);
                    petSkillEffectValues.Add(config.SkillID[i], effectValue);
                }
            }
        }
 
        public override void UnInit()
        {
            playerPack.refreshItemCountEvent -= OnItemRefreshEvent;
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChange;
            PetAttributeWin.IsRedPointCultivate -= IsRedPointCultivate;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            Wait = true;
            isServerPrepare = false;
            hasSendAutoActive = false;
            _TagPetItem.Clear();
            _DicPetBack.Clear();
            PetNow = 0;
            MinAtkNunber = 0;
            MaxAtkNunber = 0;
            curPetId = 0;
        }
 
        public void OnPlayerLoginOk()
        {
            GlobalTimeEvent.Instance.secondEvent -= secondEvent;
            GlobalTimeEvent.Instance.secondEvent += secondEvent;
            SinglePack singPack = playerPack.GetSinglePack(PackType.PetPack);
            if (singPack == null) return;
            foreach (var index in singPack.GetAllItems().Keys)
            {
                OnItemRefreshEvent(singPack.type, index, singPack.GetAllItems()[index].itemId);
            }
            isServerPrepare = true;
            if (PlayerLoginOkData != null)
            {
                PlayerLoginOkData();
            }
        }
 
        private DateTime dateTimeA;
        private void secondEvent()
        {
            if (!Wait)
            {
                TimeSpan timeS = DateTime.Now - dateTimeA;
                if (timeS.Seconds >= 2f)
                {
                    Wait = true;
                }
            }
            else
            {
                dateTimeA = DateTime.Now;
            }
        }
 
        #region 发送服务端请求
        public void SendPetSwitchQuest(int petIndex)
        {
            C1603_tagCPetStateChange tag_Cpet = new C1603_tagCPetStateChange();
            tag_Cpet.PetID = (uint)petIndex;
            tag_Cpet.State = 1;
            GameNetSystem.Instance.SendInfo(tag_Cpet);
        }
 
        public void SendBreakPetLockQuest(int petId)
        {
            CA702_tagCMActivatePet CMPet = new CA702_tagCMActivatePet();
            CMPet.PetNPCID = (uint)petId;
            GameNetSystem.Instance.SendInfo(CMPet);
            if (ItemOperateUtility.Instance.useItemModel != null)
            {
                ItemOperateUtility.Instance.useItemModel = null;
            }
        }
 
        public void SendPetTrainQuest(int petIndex, int number)
        {
            CA704_tagCMPetClassUP _tagCA704 = new CA704_tagCMPetClassUP();
            _tagCA704.PetItemIndex = (byte)petIndex;
            _tagCA704.UseItemCnt = (ushort)number;
            GameNetSystem.Instance.SendInfo(_tagCA704);
        }
        #endregion
 
 
        private void OnItemRefreshEvent(PackType type, int index, int id)
        {
            PetH0704(playerPack.GetItemByIndex(type, index));
            if (type == PackType.Item)
            {
                if (_TagPetItem.ContainsKey(id))
                {
                    PetStoneRed();
                }
                PetActivateRedPoint();
                GetCultivateRedPoint();
 
                var config = PetInfoConfig.Get(autoActivePetId);
                if (config != null && id == config.UnLockNeedItemID)
                {
                    TryAutoActivePet();
                }
            }
        }
 
        private void OnFuncStateChange(int funcId)
        {
            if (funcId == (int)FuncOpenEnum.Pet)
            {
                PetStoneRed();
                PetActivateRedPoint();
                GetCultivateRedPoint();
 
                TryAutoActivePet();
            }
        }
 
        private void TryAutoActivePet()
        {
            if (isServerPrepare && FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Pet)
                && !_DicPetBack.ContainsKey(autoActivePetId) && !hasSendAutoActive)
            {
                var petConfig = PetInfoConfig.Get(autoActivePetId);
                if (petConfig != null)
                {
                    var itemCount = playerPack.GetItemCountByID(PackType.Item, petConfig.UnLockNeedItemID);
                    if (itemCount >= petConfig.UnLockNeedItemCnt)
                    {
                        hasSendAutoActive = true;
                        SendBreakPetLockQuest(autoActivePetId);
                    }
                }
            }
        }
 
        private const int Redpoint_key1 = 1050201;
        private Redpoint redPointStre1 = new Redpoint(MainRedDot.RedPoint_PetKey2, Redpoint_key1);
        private void PetStoneRed()//灵宠魂石红点
        {
            redPointStre1.state = RedPointState.None;
            if (!FuncOpen.Instance.IsFuncOpen(6))
            {
                return;
            }
            int type = 0;
            foreach (var key in _TagPetItem.Keys)
            {
                if (_TagPetItem[key] >= AttrFruitConfig.Get(key).basicUseLimit)
                {
                    continue;
                }
                type += playerPack.GetItemCountByID(PackType.Item, key);
 
            }
            if (type > 0)
            {
                redPointStre1.state = RedPointState.Simple;
                return;
            }
        }
        private void PetNumberPreservation()//用来对灵宠个数进行保存
        {
            if (PetRedpoint.Count != 0)
            {
                return;
            }
            int type = 0;
            if (allPetConfigs.Count <= 0)
            {
                allPetConfigs = PetInfoConfig.GetValues();
            }
            //  var allPetConfigs = PetInfoConfig.GetValues();
            foreach (var config in allPetConfigs)
            {
                if (!DeblockingRedPoint.ContainsKey(config.ID))
                {
                    type += 1;
                    int petID = config.ID;
                    int RedPoint_Mountkey = MainRedDot.RedPoint_PetKey2 * 10 + type;
                    Redpoint redPointMountStare = new Redpoint(MainRedDot.RedPoint_PetKey2, RedPoint_Mountkey);
                    PetRedpoint.Add(petID, redPointMountStare);//列表
 
                    int RedPoint_Mountkey1 = RedPoint_Mountkey * 10 + type;
                    Redpoint redPointMountStare1 = new Redpoint(RedPoint_Mountkey, RedPoint_Mountkey1);
                    DeblockingRedPoint.Add(petID, redPointMountStare1);//解锁按钮
                    int RedPoint_Mountkey2 = RedPoint_Mountkey1 * 10 + type;
                    Redpoint redPointMountStare2 = new Redpoint(RedPoint_Mountkey, RedPoint_Mountkey2);
                    CultivateRedPoint.Add(petID, redPointMountStare2);
                }
            }
        }
 
        private void PetActivateRedPoint()//灵宠激活红点
        {
            foreach (var key in PetRedpoint.Keys)
            {
                DeblockingRedPoint[key].state = RedPointState.None;
            }
            if (!FuncOpen.Instance.IsFuncOpen(6))
            {
                return;
            }
            // var configs = PetInfoConfig.GetValues();
            if (allPetConfigs.Count <= 0)
            {
                allPetConfigs = PetInfoConfig.GetValues();
            }
            foreach (var config in allPetConfigs)
            {
                int unlockItemID = config.UnLockNeedItemID;
                int itemCount = playerPack.GetItemCountByID(PackType.Item, unlockItemID);
                int unlockItemCnt = config.UnLockNeedItemCnt;
                if (itemCount >= unlockItemCnt && !_DicPetBack.ContainsKey(config.ID) && FuncOpen.Instance.IsFuncOpen(6))
                {
                    DeblockingRedPoint[config.ID].state = RedPointState.Simple;
                }
            }
        }
        private void IsRedPointCultivate()
        {
            GetCultivateRedPoint();
        }
        private void ToAddSorting()
        {
            Sortpet.Clear();
            if (allPetConfigs.Count <= 0)
            {
                allPetConfigs = PetInfoConfig.GetValues();
            }
            Sortpet = allPetConfigs;
            Sortpet.Sort(Compare);
        }
        int Compare(PetInfoConfig x, PetInfoConfig y)//数组排列
        {
            if (x.Sort.CompareTo(y.Sort) != 0)
            {
                return x.Sort.CompareTo(y.Sort);
            }
            return 1;
        }
        public void GetCultivateRedPoint()//灵宠培养红点
        {
            foreach (var key in CultivateRedPoint.Keys)
            {
                CultivateRedPoint[key].state = RedPointState.None;
            }
            if (!FuncOpen.Instance.IsFuncOpen(6))
            {
                return;
            }
            if (_DicPetBack.Count <= 0)
            {
                return;
            }
            int GetPetId = 0;
            int petLv = 100;
            int itemCount = playerPack.GetItemCountByID(PackType.Item, 4151);
            List<int> ListInt = new List<int>();
            for (int i = 0; i < Sortpet.Count; i++)
            {
                int petID = Sortpet[i].ID;
                int MaxLv = PetInfoConfig.Get(petID).MaxRank;
                if (_DicPetBack.ContainsKey(petID) && _DicPetBack[petID].PetClass < MaxLv)
                {
                    int _NeedExp = PetClassCostConfig.GetPetIdAndRank(petID, _DicPetBack[petID].PetClass).UpNeedExp;
                    int NeedExp = _NeedExp - _DicPetBack[petID].petExp;
                    int NeedNumber = Mathf.CeilToInt((float)NeedExp / PetDanExp);
                    if (itemCount >= NeedNumber)
                    {
                        ListInt.Add(petID);
                    }
                }
            }
 
            foreach (var key in _DicPetBack.Keys)//因为有成就任务限制所有 第一只坐骑红点逻辑特殊写
            {
                if (DicDefaultPet.ContainsKey(key) && DicDefaultPet[key] > _DicPetBack[key].PetClass
                    && itemCount > 0 && CultivateRedPoint.ContainsKey(key))
                {
                    CultivateRedPoint[key].state = RedPointState.Simple;
                    return;
                }
            }
            List<int> IntListSkill = new List<int>();
            for (int i = 0; i < ListInt.Count; i++)//选择出升级灵宠等级最低且有技能未解锁的且经验最接近
            {
                if (_DicPetBack.ContainsKey(ListInt[i]))
                {
                    var PetConfig = PetInfoConfig.Get(ListInt[i]);
                    if (PetConfig == null)
                    {
                        return;
                    }
                    int[] SkillUnLockInt = PetConfig.SkillUnLock;
                    int SkillLvMax = SkillUnLockInt[(SkillUnLockInt.Length - 1)];
                    if (_DicPetBack[(ListInt[i])].PetClass < SkillLvMax)
                    {
                        IntListSkill.Add((ListInt[i]));
                    }
                }
            }
            int SkillPetId = GetRedPointPetID(IntListSkill);
            if (SkillPetId != 0 && CultivateRedPoint.ContainsKey(SkillPetId))
            {
                CultivateRedPoint[SkillPetId].state = RedPointState.Simple;
                return;
            }
 
 
            for (int i = 0; i < ListInt.Count; i++)//选择出等级最低的灵宠
            {
                if (_DicPetBack.ContainsKey(ListInt[i]))
                {
                    if (_DicPetBack[(ListInt[i])].PetClass < petLv)
                    {
                        petLv = _DicPetBack[(ListInt[i])].PetClass;
                        GetPetId = (ListInt[i]);
                    }
                }
            }
            if (GetPetId != 0 && CultivateRedPoint.ContainsKey(GetPetId))
            {
                CultivateRedPoint[GetPetId].state = RedPointState.Simple;
                return;
            }
        }
 
 
        private int GetRedPointPetID(List<int> PetList)
        {
            int GetSkillMinLv = 999;
            for (int i = 0; i < PetList.Count; i++)
            {
                int SkillminLv = GetSkillLvDis(PetList[i]);
                if (SkillminLv < GetSkillMinLv && SkillminLv != 0)
                {
                    GetSkillMinLv = SkillminLv;
                }
            }
 
            int petId = 0;
            int ExpNumber = 999999999;
            for (int i = 0; i < PetList.Count; i++)
            {
                int SkillLv = GetSkillLvDis(PetList[i]);
                if (SkillLv > GetSkillMinLv || SkillLv == 0)
                {
                    continue;
                }
                var Pet1 = PetClassCostConfig.GetPetIdAndRank(PetList[i], SkillLv);
                var Pet2 = PetClassCostConfig.GetPetIdAndRank(PetList[i], _DicPetBack[(PetList[i])].PetClass);
                int Exp = Pet1.NeedExpTotal - Pet2.NeedExpTotal - _DicPetBack[(PetList[i])].petExp;
                if (Exp < ExpNumber)
                {
                    ExpNumber = Exp;
                    petId = PetList[i];
                }
            }
            return petId;
        }
        private int GetSkillLvDis(int PetId)//获取离升级最近的技能等级
        {
            int SkillLv = 0;
            var petInfo = PetInfoConfig.Get(PetId);
            if (petInfo == null)
            {
                return 0;
            }
            int[] ListPetSkillUnLock = petInfo.SkillUnLock;
            for (int i = 0; i < ListPetSkillUnLock.Length; i++)
            {
                if (_DicPetBack.ContainsKey(PetId) && ListPetSkillUnLock[i] > _DicPetBack[PetId].PetClass)
                {
                    SkillLv = ListPetSkillUnLock[i];
                    return SkillLv;
                }
            }
            return SkillLv;
        }
        public int GetMinPetExp()
        {
            foreach (var key in CultivateRedPoint.Keys)//当存在培养红点时,选中当有红点的那只
            {
                if (CultivateRedPoint[key].state == RedPointState.Simple)
                {
                    return key;
                }
            }
 
            List<int> IntListSkill = new List<int>();
            foreach (var key in _DicPetBack.Keys)
            {
                var petConfig = PetInfoConfig.Get(key);
                if (_DicPetBack[key].PetClass < petConfig.MaxRank)
                {
                    IntListSkill.Add(key);
                }
            }
            int SkillPetId = GetRedPointPetID(IntListSkill);
            if (SkillPetId != 0)
            {
                return SkillPetId;
            }
            int GetPetId = 0;
            int GetPetLv = 999;
 
            foreach (var key in _DicPetBack.Keys)//无红点时跳转选中等级最低的
            {
                var config = PetInfoConfig.Get(key);
                if (_DicPetBack[key].PetClass < GetPetLv && _DicPetBack[key].PetClass < config.MaxRank)
                {
                    GetPetId = key;
                    GetPetLv = _DicPetBack[key].PetClass;
                }
            }
            return GetPetId;
        }
        private int GetPetSkillMaxLv(int PetID)
        {
            int maxskillLV = 0;
            int[] curPetUnlocks;
            PetInfoConfig petInfo = PetInfoConfig.Get(PetID);
            if (petInfo != null)
            {
                curPetUnlocks = petInfo.SkillUnLock;
                maxskillLV = curPetUnlocks[(curPetUnlocks.Length) - 1];
            }
            return maxskillLV;
        }
        public void PetA339(HA339_tagMCAttrFruitEatCntList info)
        {
            for (int i = 0; i < info.count; i++)
            {
                var configItem = ItemConfig.Get((int)info.EatCntList[i].ItemID);
                if (configItem == null)
                {
                    continue;
                }
                if (_TagPetItem.ContainsKey((int)info.EatCntList[i].ItemID))
                {
                    _TagPetItem[(int)info.EatCntList[i].ItemID] = (int)info.EatCntList[i].EatCnt;
                    if (Event_Ha339 != null)
                        Event_Ha339(info);
                }
                else
                {
                    if (configItem.Type == 28)
                    {
                        _TagPetItem.Add((int)info.EatCntList[i].ItemID, (int)info.EatCntList[i].EatCnt);
 
                    }
                }
            }
            PetStoneRed();
        }
 
        private void AddPetSkill(int[] intlist)
        {
            for (int i = 0; i < intlist.Length; i++)
            {
                var skillPet = SkillConfig.Get(intlist[i]);
                if (_PetSkillAcquire.ContainsKey(skillPet.SkillTypeID))
                {
                    int skilllv = SkillConfig.Get(_PetSkillAcquire[skillPet.SkillTypeID]).SkillLV;
                    if (skillPet.SkillLV > skilllv)
                    {
                        _PetSkillAcquire[skillPet.SkillTypeID] = skillPet.SkillID;
                    }
                }
                else
                {
                    _PetSkillAcquire.Add(skillPet.SkillTypeID, skillPet.SkillID);
                }
            }
        }
 
        public void PetH0704(ItemModel info)//宠物背包列表
        {
            if (info == null)
                return;
 
            if (info.packType == PackType.PetPack)
            {
                var isChangePetNow = false;
 
                Dictionary<int, int[]> _dic = Analysis(info.itemInfo.userData);
                if (GetUseDataModel(200, _dic) != null)
                {
                    int petId = _dic[200][0];
                    int petLv = 0;
                    int petState = 0;
                    int[] petSkill = null;
                    int petIndex = info.gridIndex;
                    int petExp = 0;
                    if (GetUseDataModel(201, _dic) != null)
                    {
                        petSkill = _dic[201];//宠物当前学习的技能
                    }
 
                    if (GetUseDataModel(202, _dic) != null)
                    {
                        petLv = _dic[202][0] + 1;//宠物阶级
                    }
 
                    if (GetUseDataModel(204, _dic) != null)
                    {
                        petState = _dic[204][0];//宠物当前状态;
                    }
 
                    if (GetUseDataModel(208, _dic) != null)
                    {
                        petExp = _dic[208][0]; //宠物经验
                    }
 
                    if (!_DicPetBack.ContainsKey(petId))
                    {
 
                        PetBackpack _petBack = new PetBackpack();
                        _petBack.PetClass = petLv;
                        _petBack.petExp = petExp; //宠物经验
                        _petBack.PetStatus = petState;//宠物当前状态
                        if (_petBack.PetStatus == 1)
                        {
                            if (petId != PetNow)
                            {
                                isChangePetNow = true;
                            }
                            PetNow = petId;
                        }
 
                        if (petSkill != null)
                        {
                            _petBack.PetSkill = petSkill;//宠物当前学习的技能
                            AddPetSkill(_petBack.PetSkill);
                        }
                        else
                        {
                            _petBack.PetSkill = null;
                        }
                        _petBack.ItemPlace = petIndex;//宠物位置索引
                        _DicPetBack.Add(petId, _petBack);
                        if (Event_H0704Add != null && isServerPrepare)
                        {
                            Event_H0704Add();
                        }
 
                    }
                    else
                    {
                        _DicPetBack[petId].PetClass = petLv;
                        _DicPetBack[petId].PetStatus = petState;
                        _DicPetBack[petId].petExp = petExp; //宠物经验
                        if (petSkill != null)
                        {
                            _DicPetBack[petId].PetSkill = petSkill;//宠物当前学习的技能
                            AddPetSkill(_DicPetBack[petId].PetSkill);
                        }
                        else
                        {
                            _DicPetBack[petId].PetSkill = null;
                        }
 
                        _DicPetBack[petId].ItemPlace = petIndex;
                        if (Event_H0704Update != null && isServerPrepare)
                        {
                            Event_H0704Update(petId);
                        }
                        if (_DicPetBack[petId].PetStatus == 1)
                        {
                            if (petId != PetNow)
                            {
                                isChangePetNow = true;
                            }
                            PetNow = petId;
                            if (Event_SpiritPetPlay != null && isServerPrepare)
                            {
                                Event_SpiritPetPlay(petState);
 
                            }
                        }
                    }
                }
 
                if (isServerPrepare && isChangePetNow && PetNow != 0)
                {
                    ScrollTip.ShowTip(Language.Get("Z1811"));//外观切换成功
                }
            }
            PetStoneRed();
            PetActivateRedPoint();
            GetCultivateRedPoint();
            GetPetMinAndMaxAttack();
        }
 
        public int[] GetUseDataModel(int key, Dictionary<int, int[]> useDataDict)
        {
            int[] list = null;
            if (useDataDict != null)
            {
                useDataDict.TryGetValue(key, out list);
            }
            return list;
        }
 
        private void GetPetMinAndMaxAttack()
        {
            if (_DicPetBack.Count <= 0)
            {
                return;
            }
            MinAtkNunber = 0;
            MaxAtkNunber = 0;
            foreach (var key in _DicPetBack.Keys)
            {
                PetClassCostConfig _tagPetClass = PetClassCostConfig.GetPetIdAndRank(key, _DicPetBack[key].PetClass);
                MinAtkNunber += _tagPetClass.AtkAdd;
                MaxAtkNunber += _tagPetClass.AtkAdd;
            }
        }
 
        public static Regex userData = new Regex(@"'([0-9]+)':\[(.*?)\]", RegexOptions.Singleline);
 
        public Dictionary<int, int[]> Analysis(string val)//正则表达式的字符串分割
        {
            if (!userData.IsMatch(val))
            {
                return null;
            }
            else
            {
                Dictionary<int, int[]> dics = new Dictionary<int, int[]>();
                foreach (Match match in userData.Matches(val))
                {
                    int id = int.Parse(match.Groups[1].Value);
                    string str = match.Groups[2].Value;
                    string[] vals = str.Split(',');
                    int[] intarray = new int[vals.Length];
                    for (int i = 0; i < vals.Length; i++)
                    {
                        int intval = int.Parse(vals[i].Replace('\'', ' '));
                        intarray[i] = intval;
                    }
                    if (!dics.ContainsKey(id))
                    {
                        dics.Add(id, intarray);
                    }
                }
                return dics;
            }
        }
 
        public bool IsHint(PetEnum petEnum, int id = 0)//True提示,False不提示
        {
            bool iSHint = false;
            switch (petEnum)
            {
                case PetEnum.PetDan:
                    foreach (var key in _DicPetBack.Keys)
                    {
                        PetInfoConfig petConfig = PetInfoConfig.Get(key);
                        if (petConfig.MaxRank > _DicPetBack[key].PetClass)
                        {
                            iSHint = true;
                        }
                    }
                    return iSHint;
                case PetEnum.PetDebris:
                    if (allPetConfigs.Count <= 0)
                    {
                        allPetConfigs = PetInfoConfig.GetValues();
                    }
                    foreach (var value in allPetConfigs)
                    {
                        if (value.UnLockNeedItemID == id)
                        {
                            if (!_DicPetBack.ContainsKey(value.ID))
                            {
                                iSHint = true;
                            }
                        }
                    }
                    return iSHint;
                case PetEnum.PetStone:
                    int _maxuse = AttrFruitConfig.Get(id).basicUseLimit;
                    if (_TagPetItem.ContainsKey(id))
                    {
                        if (_maxuse > _TagPetItem[id])
                        {
                            iSHint = true;
                        }
                    }
                    return iSHint;
                default:
                    return true;
            }
        }
 
        public int IsPetPanelRedPointState()//用于判断当前灵宠页签是否有红点亮起
        {
            int Type = 0;
            foreach (var value in DeblockingRedPoint.Values)
            {
                if (value.state == RedPointState.Simple)
                {
                    Type = 2;
                    return Type;
                }
            }
            if (MainRedDot.Instance.redPonintPetFunc2.state == RedPointState.Simple)
            {
                Type = 1;
                return Type;
            }
            return Type;
 
        }
 
        #region 预览宠物碎片属性
        Dictionary<int, int> petAttrDict = new Dictionary<int, int>();
        public Dictionary<int, int> GetPetAttrAddDict(int petCode)
        {
            PetInfoConfig infoConfig = PetInfoConfig.Get(petCode);
            petAttrDict.Clear();
            if (infoConfig == null) return petAttrDict;
 
            int maxRank = infoConfig.MaxRank;
            PetClassCostConfig cost = PetClassCostConfig.GetPetIdAndRank(petCode, maxRank);
            int allAtkAdd = 0;
            if (cost != null)
            {
                allAtkAdd = cost.AtkAdd;
            }
            petAttrDict.Add(7, allAtkAdd);
            return petAttrDict;
        }
        #endregion
 
        #region 技能整合
        public ICollection<int> GetPetTotalSkills()
        {
            return petSkills.Keys;
        }
 
        public SkillEffectGroup GetSkillEffectGroup(int skillId)
        {
            if (petSkillEffectValues.ContainsKey(skillId))
            {
                return petSkillEffectValues[skillId];
            }
            return default(SkillEffectGroup);
        }
 
        public bool TryGetIntegrationSkill(SkillEffectGroup effect, out int skillId)
        {
            return integrationSkills.TryGetValue(effect, out skillId);
        }
 
        public bool TryGetPetSkills(SkillEffectGroup effect, out List<int> skills)
        {
            return integrationPetSkills.TryGetValue(effect, out skills);
        }
 
        public bool TryGetPetId(int skillId, out int petId)
        {
            return petSkills.TryGetValue(skillId, out petId);
        }
 
        public bool IsSkillUnlock(int skillId)
        {
            var config = SkillConfig.Get(skillId);
            if (config == null)
            {
                return false;
            }
            var effect = SkillConfig.GetSkillEffectValue(config);
 
            if (integrationPetSkills.ContainsKey(effect)
                && !integrationPetSkills[effect].Contains(skillId))
            {
                var skills = integrationPetSkills[effect];
                foreach (var id in skills)
                {
                    if (IsSkillUnlock(id))
                    {
                        return true;
                    }
                }
            }
            else
            {
                if (petSkills.ContainsKey(skillId))
                {
                    var petId = petSkills[skillId];
                    if (!_DicPetBack.ContainsKey(petId))
                    {
                        return false;
                    }
                    var petInfo = _DicPetBack[petId];
                    if (petInfo.PetClass >= GetSkillUnlockLevel(skillId))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
 
        public int GetSkillUnlockLevel(int skillId)
        {
            var petId = 0;
            if (TryGetPetId(skillId, out petId))
            {
                var petConfig = PetInfoConfig.Get(petId);
                var index = 0;
                for (int i = 0; i < petConfig.SkillID.Length; i++)
                {
                    if (petConfig.SkillID[i] == skillId)
                    {
                        index = i;
                    }
                }
                if (index < petConfig.SkillUnLock.Length)
                {
                    return petConfig.SkillUnLock[index];
                }
            }
            return 0;
        }
        #endregion
    }
}