少年修仙传客户端代码仓库
hch
3 天以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
976
977
978
979
980
981
982
983
984
985
986
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using UnityEngine.UI;
using System.Linq;
using LitJson;
using UnityEngine;
using System.Collections;
 
 
//跨服排位赛的数据来源上一赛季的跨服天梯前64位
public class CrossServerQualifyingModel : ILModel<CrossServerQualifyingModel>
{
    public const int DATA_MAPID = 32070;
    public int selectIndex; // 跨服排位主标签选择
    public int select64Index = 0;  // 选中的64强比赛标签,非当前赛程
    public List<uint> groupBtnMarks = new List<uint>() { 64, 32, 16 };//64强标签按钮对应的赛程
    public List<uint> group8BtnMarks = new List<uint>() { 8, 4, 2 };//8强 
    public uint select64Mark
    {
        get { return groupBtnMarks[select64Index]; }
    }
 
    public int actID;   // 活动ID,活动ID不同则可重置前端排位赛相关缓存数据
    public int stateError; // 本次活动是否已经出现流程状态异常;如服务器异常或维护服务器导致跳过步骤,则会废弃该次比赛,直到下次新活动;
    public int zoneID; //上一赛季所在的赛区ID, 以C015为准过滤其他不匹配的封包
    public int officialZoneID; //官职相关所在赛区可能是上上赛季的赛区
 
    //所有参赛者总名单
    public Dictionary<uint, CrossChampionshipPKPlayer> fightersInfo = new Dictionary<uint, CrossChampionshipPKPlayer>();
    //赛程对战列表 <赛程分组(如64强/32强),<赛程内分组, 分组信息>>
    public Dictionary<uint, Dictionary<uint, CrossChampionshipPKBattle>> battleInfo = new Dictionary<uint, Dictionary<uint, CrossChampionshipPKBattle>>();
    public event Action UpdateCrossChampionshipPKZoneGroupInfoEvent;
    //当前赛程(如64强/32强),0代表不在比赛流程中
    public uint nowGroupMark
    {
        get
        {
            var battleID = GetBattleID();
            if (battleID == -1) return 0;
            var state = ILChampionshipTimeConfig.Get(battleID).StateValue;
            if (state == 80) return 64;  //8强竞猜
            if (state == 40) return 8;   //四强竞猜
            return (uint)state / 10;
        }
    }
 
    public List<DateTime> openTimes = new List<DateTime>();
 
    //竞猜公共和个人信息
    public Dictionary<int, int> guess8Common = new Dictionary<int, int>();
    public Dictionary<int, int> guess4Common = new Dictionary<int, int>();
    public Dictionary<int, Int2> guess8Personal = new Dictionary<int, Int2>();
    public Dictionary<int, Int2> guess4Personal = new Dictionary<int, Int2>();  //投注额度和名次
    public List<int> guessPlayer64List = new List<int>();
    public List<int> guessPlayer8List = new List<int>();    //8强名单,由16强列表中筛选胜者
    public Dictionary<int, int> myGuessInfo = new Dictionary<int, int>();
    public event Action UpdateGuessEvent;
 
    public int guessMoneyType;
    public int guessMoney;
    public int guessMaxCnt;
    public bool isNetPackRefreshGuess4; //界面打开的情况下 封包刷新不刷名次,避免玩家选名次后被刷0
    //对阵表
    public List<int> raceList = new List<int>() { 82, 82, 82, 82, 42, 42, 42, 42, 22, 22, 22, 22 };
 
    //官职ID:官职信息
    public Dictionary<int, ChampionshipOfficial> rankOfficialDict = new Dictionary<int, ChampionshipOfficial>();
 
    public int myOfficialID = 0;    //我的官职
    public int selectOffcialID; //选中的界主官场
    public int selectOffcialSub;//0上界 1中界
    public int selectApplyOfficialID; //申请列表的仙官 或者查看挑战的仙官
    //官职上下管理 界主下包含哪些官职分上中界
    public Dictionary<int, List<List<int>>> offcialOperList = new Dictionary<int, List<List<int>>>();
    public event Action UpdateOffcialEvent;
 
    public int applyMaxTimes; //可同时申请的不同官位数量
    public int applyPlayerMaxCnt;   //一个官可以有几个玩家申请
    public int offcialNeedRealm;
    public int kickSeconds;
    public int myApplyCnt;
 
    Redpoint redpoint = new Redpoint(MainRedPoint.CrossServerQualifyingRedPoint);
    public Redpoint mobaiRedpoint = new Redpoint(MainRedPoint.CrossServerQualifyingRedPoint, 4232);//膜拜
    public Redpoint officialRedpoint = new Redpoint(MainRedPoint.CrossServerQualifyingRedPoint, 4233);
    public Redpoint loginRedpoint = new Redpoint(MainRedPoint.CrossServerQualifyingRedPoint, 4239);//登录
 
    public int worshipCntToday; //今日膜拜次数
    public event Action UpdateWorshipEvent;
    public int worshipMaxCnt;
    public int[][] doubleTimeArr;
    public int challengeMaxCnt; //挑战次数
 
    public Action<uint, uint> QueryRaceScoreEvent;    // 查询比分
 
    DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
    ServerMirrorFightModel mirrorFightModel { get { return ModelCenter.Instance.GetModel<ServerMirrorFightModel>(); } }
 
    protected override void Init()
    {
        ParseConfig();
        GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        GlobalTimeEvent.Instance.minuteEvent += OnMinuteEvent;
        GameEvent.playerLoginOkEvent += PlayerLoginOkEvent;
    }
 
    protected override void UnInit()
    {
        GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
        GlobalTimeEvent.Instance.minuteEvent -= OnMinuteEvent;
        GameEvent.playerLoginOkEvent -= PlayerLoginOkEvent;
    }
 
    void ParseConfig()
    {
        var config = FuncConfigConfig.Get("CrossChamFB");
        var openTimeArr = JsonMapper.ToObject<string[]>(config.Numerical1);
        for (int i = 0; i < openTimeArr.Length; i++)
        {
            openTimes.Add(Convert.ToDateTime(openTimeArr[i]));
        }
 
        config = FuncConfigConfig.Get("CrossChamGuess");
        var moneyInfo = config.Numerical1.Split('|');
        guessMoneyType = int.Parse(moneyInfo[0]);
        guessMoney = int.Parse(moneyInfo[1]);
        guessMaxCnt = int.Parse(config.Numerical2);
 
        for (int i = 1; i <= 8; i++)
        {
            var subArr = JsonMapper.ToObject<int[]>(ILChampionshipOfficialConfig.Get(i).JuniorOfficialIDList);
 
            if (!offcialOperList.ContainsKey(i))
            {
                List<List<int>> tmp = new List<List<int>>();
                tmp.Add(new List<int>());
                tmp.Add(new List<int>());
                offcialOperList[i] = tmp;
            }
 
            for (int j = 0; j < subArr.Length; j++)
            {
                if (ILChampionshipOfficialConfig.Get(subArr[j]).CanBeReplace == 0)
                {
                    //上界
                    offcialOperList[i][0].Add(subArr[j]);
                }
                else
                {
                    //中界
                    offcialOperList[i][1].Add(subArr[j]);
                }
            }
        }
 
        config = FuncConfigConfig.Get("CrossChamOfficial");
        applyPlayerMaxCnt = int.Parse(config.Numerical1);
        applyMaxTimes = int.Parse(config.Numerical2);
        offcialNeedRealm = int.Parse(config.Numerical3);
        kickSeconds = int.Parse(config.Numerical4);
 
        config = FuncConfigConfig.Get("CrossChamWorship");
        worshipMaxCnt = int.Parse(config.Numerical1);
        doubleTimeArr = JsonMapper.ToObject<int[][]>(config.Numerical3);
 
        config = FuncConfigConfig.Get("CrossChamMirrorPK");
        challengeMaxCnt = int.Parse(config.Numerical1);
    }
 
 
    //下一次开启时间
    public int GetNextOpenTimeIndex()
    {
        for (int i = 0; i < openTimes.Count; i++)
        {
            if (ILTimeUtility.ServerCrossNow < openTimes[i])
            {
                return i;
            }
        }
 
        return -1;
    }
 
    //获取当前开启阶段
    public int GetOpenTimeIndex()
    {
        if (openTimes.Count == 0) return -1;
        var index = 0;
        for (int i = 0; i < openTimes.Count; i++)
        {
            if (ILTimeUtility.ServerCrossNow < openTimes[i])
            {
                return index;
            }
            index = i;
        }
 
        return index;
    }
 
    //界面可打开的情况,判断是否赛程中
    public bool IsOpen()
    {
        if (stateError != 0)
        {
            return false;
        }
 
        if (fightersInfo.Count == 0)
        {
            return false;
        }
 
        return true;
    }
 
    public void UpdateCrossChampionshipPKZoneGroupInfo(HC015_tagGCCrossChampionshipPKZoneGroupInfo netPack)
    {
        stateError = netPack.StateError;
 
        if (actID != (int)netPack.ActID)
        {
            actID = (int)netPack.ActID;
            zoneID = netPack.ZoneID;
            fightersInfo.Clear();
            battleInfo.Clear();
        }
 
        for (int i = 0; i < netPack.PlayerList.Length; i++)
        {
            var player = netPack.PlayerList[i];
            fightersInfo[player.PlayerID] = new CrossChampionshipPKPlayer()
            {
                PlayerID = player.PlayerID,
                PlayerName = player.PlayerName,
                FightPower = (long)player.FightPowerEx * (long)Constants.ExpPointValue + player.FightPower,
                Job = player.Job,
                LV = player.LV,
                Face = player.Face,
                FacePic = player.FacePic,
            };
        }
 
        for (int i = 0; i < netPack.GroupList.Length; i++)
        {
            var group = netPack.GroupList[i];
            if (!battleInfo.ContainsKey(group.GroupMark))
            {
                battleInfo[group.GroupMark] = new Dictionary<uint, CrossChampionshipPKBattle>();
            }
            for (int j = 0; j < group.BattleList.Length; j++)
            {
                var battleList = group.BattleList[j];
                battleInfo[group.GroupMark][battleList.BattleNum] = new CrossChampionshipPKBattle()
                {
                    BattleNum = battleList.BattleNum,
                    WinPlayerID = battleList.WinPlayerID,
                    PlayerIDA = battleList.PlayerIDA,
                    PlayerIDB = battleList.PlayerIDB,
                    battleResult = ConfigParse.ParseIntArray2Dict(battleList.BattleRet),
                };
            }
        }
 
        UpdateCrossChampionshipPKZoneGroupInfoEvent?.Invoke();
    }
 
 
    public void OnBeforePlayerDataInitialize()
    {
        actID = 0;
        zoneID = 0;
        officialZoneID = 0;
        fightersInfo.Clear();
        battleInfo.Clear();
        guessPlayer8List.Clear();
        guessPlayer64List.Clear();
        guess8Common.Clear();
        guess4Common.Clear();
        guess8Personal.Clear();
        guess4Personal.Clear();
        myGuessInfo.Clear();
        rankOfficialDict.Clear();
        myOfficialID = 0;
        myApplyCnt = 0;
        worshipCntToday = 0;
        pushGroupMark = 0;
        isShowRaceInfoYet = false;
    }
 
    //获取当前的比赛赛程节点,-1代表当前时间不在排位赛流程中
    public int GetBattleID()
    {
        var index = GetOpenTimeIndex();
        if (index == -1) return -1;
        var startDay = openTimes[index];
        if (startDay > ILTimeUtility.ServerCrossNow)
        {
            //流程未开始
            return -1;
        }
        //第一天 从1开始
        var passDays = (ILTimeUtility.ServerCrossNow - startDay).Days + 1;
 
        var keys = ILChampionshipTimeConfig.GetKeys();
        //流程结束
        if (ILChampionshipTimeConfig.Get(keys[keys.Count - 1]).StartDay < passDays)
            return -1;
        for (int i = 0; i < keys.Count; i++)
        {
            var config = ILChampionshipTimeConfig.Get(keys[i]);
            if (passDays != config.StartDay && config.EndDay == config.StartDay)
                continue;
 
            var startTime = startDay.AddDays(config.StartDay - 1).AddSeconds(config.StartHour * 60 * 60 + config.StartMinute * 60);
            var endTime = startDay.AddDays(config.EndDay - 1).AddSeconds(config.EndHour * 60 * 60 + config.EndMinute * 60 + 59);
            if (ILTimeUtility.ServerCrossNow >= startTime && ILTimeUtility.ServerCrossNow <= endTime)
                return int.Parse(keys[i]);
        }
 
        return -1;
    }
 
    //获取流程的开始时间
    public string GetStartBattleTime(int battleID)
    {
        var index = GetOpenTimeIndex();
        if (index == -1) return string.Empty;
        var startDay = openTimes[index];
 
        var config = ILChampionshipTimeConfig.Get(battleID);
        var startTime = startDay.AddDays(config.StartDay - 1).AddSeconds(config.StartHour * 60 * 60 + config.StartMinute * 60);
 
        return startTime.ToString("yyyy-MM-dd HH:mm");
    }
 
    //获取流程的结束时间 分钟,负数代表未开始
    public double GetRaceEndRemindMinute(int battleID)
    {
        var index = GetOpenTimeIndex();
        if (index == -1) return -1;
        var startDay = openTimes[index];
 
        var config = ILChampionshipTimeConfig.Get(battleID);
        var endTime = startDay.AddDays(config.StartDay - 1).AddSeconds(config.EndHour * 60 * 60 + config.EndMinute * 60);
 
        return (endTime - ILTimeUtility.ServerCrossNow).TotalMinutes;
    }
 
    public struct CrossChampionshipPKPlayer
    {
        public uint PlayerID;
        public string PlayerName;
        public byte Job;
        public long FightPower;
        public ushort LV;
        public ushort RealmLV;
        public uint Face;        //基本脸型
        public uint FacePic;        //头像框
    }
 
    public struct CrossChampionshipPKBattle
    {
        public byte BattleNum;        // 对战组编号 1~n
        public uint WinPlayerID;        // 获胜玩家ID
        public uint PlayerIDA;        // 玩家IDA
        public uint PlayerIDB;        // 玩家IDB
        public Dictionary<int, int[][]> battleResult;  // 战斗结果明细 {"playerID":[[第1局胜负,第1局总积分,胜负基础分,hp分,时间分], ...], ...}
    }
 
    public struct ChampionshipOfficial
    {
        public uint LastDismissJuniorTime;        // 上次辞退下级仙官时间戳,跨服时间,如果自己是本界主时,用于计算辞退CD
        public uint WorshipCount;        // 被膜拜次数
        public byte WorshipDouble;        // 今日是否双倍膜拜,仅在规定时间点内有用
        public CrossChampionshipPKPlayer OfficialPlayer;        // 任职玩家信息,可能没有
        public List<CrossChampionshipPKPlayer> ApplyPlayerList;        // 申请该仙官玩家列表
    }
 
 
    //进入跨服排位赛,借用跨服竞技1v1模拟
    public void EnterCrossServerQualifying()
    {
        uint tagPlayerID;
        var battleResult = GetMyBattleInfo(nowGroupMark, out tagPlayerID);
        int challengeCnt = battleResult.ContainsKey((int)PlayerDatas.Instance.baseData.PlayerID) ? battleResult[(int)PlayerDatas.Instance.baseData.PlayerID].Length : 0;
        if (challengeCnt >= challengeMaxCnt)
        {
            SysNotifyMgr.Instance.ShowTip("CrossServerQualifying11");
            return;
        }
 
        int error;
        if (!dungeonModel.CanEnter(out error))
        {
            dungeonModel.ProcessEnterError(error);
            return;
        }
 
 
        var teamModel = ModelCenter.Instance.GetModel<TeamModel>();
        if (teamModel.isMatching)
        {
            teamModel.RequestCancelAutoMatchTeam();
        }
 
 
        var otherPlayerInfo = fightersInfo[tagPlayerID];
 
        var opponent = new HC001_tagGCCrossRealmPKMatchOK.tagGCCrossRealmPKMatchPlayer();
        opponent.Job = otherPlayerInfo.Job;
        opponent.PlayerName = otherPlayerInfo.PlayerName;
        opponent.PlayerID = otherPlayerInfo.PlayerID;
 
        opponent.LV = otherPlayerInfo.LV;
        opponent.RealmLV = otherPlayerInfo.RealmLV;
        opponent.Face = otherPlayerInfo.Face;
        opponent.FacePic = otherPlayerInfo.FacePic;
        opponent.FightPower = (uint)((ulong)otherPlayerInfo.FightPower % Constants.ExpPointValue);
        opponent.FightPowerEx = (uint)((ulong)otherPlayerInfo.FightPower / Constants.ExpPointValue);
 
        CrossServerLogin.Instance.InitOneVsOnePlayerInfo(opponent);
        mirrorFightModel.SendMirrorFight(DATA_MAPID, (ushort)(zoneID * 100 + nowGroupMark), tagPlayerID, 0);
        return;
    }
 
    //查找自己是否有比赛,包含竞猜 分组和战斗结束的缓存时间
    public bool HaveMyBattle(uint groupMark)
    {
        if (battleInfo.ContainsKey(groupMark))
        {
            var playerID = PlayerDatas.Instance.baseData.PlayerID;
            var battle = battleInfo[groupMark];
            var battleNums = battle.Keys.ToList();
            for (int i = 0; i < battleNums.Count; i++)
            {
                var battleNum = battleNums[i];
                //搜索玩家是否参赛者
                if (battle[battleNum].PlayerIDA == playerID || battle[battleNum].PlayerIDB == playerID)
                {
                    return true;
                }
            }
        }
 
        return false;
    }
 
    // 8强之前,查找玩家的下一场比赛,胜出未分组前也算
    public int GetMyNextBattle()
    {
        int nextGroupMark = 0;
        bool haveBattle = false;
        for (int k = 0; k < groupBtnMarks.Count; k++)
        {
            var groupMark = groupBtnMarks[k];
            nextGroupMark = (int)groupMark;
            if (battleInfo.ContainsKey(groupMark))
            {
                var playerID = PlayerDatas.Instance.baseData.PlayerID;
                var battle = battleInfo[groupMark];
                var battleNums = battle.Keys.ToList();
                for (int i = 0; i < battleNums.Count; i++)
                {
                    var battleNum = battleNums[i];
                    //搜索玩家是否参赛者
                    if (battle[battleNum].WinPlayerID == playerID)
                    {
                        haveBattle = true;
                        continue;
                    }
                    if (battle[battleNum].PlayerIDA == playerID || battle[battleNum].PlayerIDB == playerID)
                    {
                        haveBattle = true;
                        return nextGroupMark;
                    }
                }
            }
        }
 
        return haveBattle ? nextGroupMark : 0;
    }
 
 
    //当前的比赛比分情况
    public Dictionary<int, int[][]> GetMyBattleInfo(uint groupMark, out uint tagPlayerID)
    {
        tagPlayerID = 0;
        if (battleInfo.ContainsKey(groupMark))
        {
            var playerID = PlayerDatas.Instance.baseData.PlayerID;
            var battle = battleInfo[groupMark];
            var battleNums = battle.Keys.ToList();
            for (int i = 0; i < battleNums.Count; i++)
            {
                var battleNum = battleNums[i];
 
                if (battle[battleNum].PlayerIDA == playerID || battle[battleNum].PlayerIDB == playerID)
                {
                    tagPlayerID = battle[battleNum].PlayerIDA == playerID ? battle[battleNum].PlayerIDB : battle[battleNum].PlayerIDA;
                    return battle[battleNum].battleResult;
                }
            }
        }
 
        return null;
    }
 
    public CrossChampionshipPKBattle QueryPKScoreInfoByPlayerID(uint groupMark, uint playerID)
    {
        if (battleInfo.ContainsKey(groupMark))
        {
            var battle = battleInfo[groupMark];
            var battleNums = battle.Keys.ToList();
            for (int i = 0; i < battleNums.Count; i++)
            {
                var battleNum = battleNums[i];
                if (battle[battleNum].PlayerIDA == playerID || battle[battleNum].PlayerIDB == playerID)
                {
                    return battle[battleNum];
                }
            }
        }
 
        return new CrossChampionshipPKBattle();
    }
 
 
 
 
    public uint WinnerID;    // 胜方ID
    public int score;
 
    public void UpdatePKResult()
    {
        if (dungeonModel.dungeonResult.isWin == 1)
        {
            WinnerID = PlayerDatas.Instance.baseData.PlayerID;
        }
        else
        {
            WinnerID = 0;
        }
 
        score = dungeonModel.dungeonResult.addScore;
 
        if (WindowCenter.Instance.IsOpen<FightingPKWin>())
        {
            WindowCenter.Instance.Close<FightingPKWin>();
        }
        WindowCenter.Instance.OpenIL<CrossServerQualifyingSettlementWin>();
    }
 
 
 
    //竞猜公共信息:支持人数
    public void UpdateGuessCommon(IL_HC022_tagGCChampionshipGuessPubInfo netPack)
    {
        for (int i = 0; i < netPack.GuessList.Length; i++)
        {
            if (netPack.GuessList[i].GuessType == 8)
            {
                for (int j = 0; j < netPack.GuessList[i].GuessPlayerList.Length; j++)
                {
                    var player = netPack.GuessList[i].GuessPlayerList[j];
                    guess8Common[(int)player.PlayerID] = (int)player.SupportCount;
                }
            }
            else if (netPack.GuessList[i].GuessType == 4)
            {
                for (int j = 0; j < netPack.GuessList[i].GuessPlayerList.Length; j++)
                {
                    var player = netPack.GuessList[i].GuessPlayerList[j];
                    guess4Common[(int)player.PlayerID] = (int)player.SupportCount;
                }
            }
        }
 
        UpdateGuessEvent?.Invoke();
    }
 
    //竞猜个人信息:投注额度和名次
    public void UpdateGuessPersonal(IL_HC023_tagGCChampionshipGuessPriInfo netPack)
    {
        for (int i = 0; i < netPack.GuessList.Length; i++)
        {
            if (netPack.GuessList[i].GuessType == 8)
            {
                for (int j = 0; j < netPack.GuessList[i].GuessPlayerList.Length; j++)
                {
                    var player = netPack.GuessList[i].GuessPlayerList[j];
                    guess8Personal[(int)player.PlayerID] = new Int2((int)player.MoneyTotal, player.GuessRank);
                }
            }
            else if (netPack.GuessList[i].GuessType == 4)
            {
                for (int j = 0; j < netPack.GuessList[i].GuessPlayerList.Length; j++)
                {
                    var player = netPack.GuessList[i].GuessPlayerList[j];
                    guess4Personal[(int)player.PlayerID] = new Int2((int)player.MoneyTotal, player.GuessRank);
                    if (player.GuessRank != 0)
                    {
                        myGuessInfo[player.GuessRank] = (int)player.PlayerID;
                    }
                }
            }
        }
 
        UpdateGuessEvent?.Invoke();
    }
 
    ////竞猜列表顺序,是否投注-战力-玩家ID
    public void Player64ListSort()
    {
        guessPlayer64List.Clear();
 
        var tList = fightersInfo.Keys.ToList();
        for (int i = 0; i < tList.Count; i++)
        {
            guessPlayer64List.Add((int)tList[i]);
        }
        guessPlayer64List.Sort(CompareGuess64);
        return;
    }
 
    int CompareGuess64(int idA, int idB)
    {
        bool isGuessA = guess8Personal.ContainsKey(idA);
        bool isGusssB = guess8Personal.ContainsKey(idB);
 
        if (isGuessA != isGusssB)
        {
            return isGusssB.CompareTo(isGuessA);
        }
 
        long fightPowerA = fightersInfo[(uint)idA].FightPower;
        long fightPowerB = fightersInfo[(uint)idB].FightPower;
 
        if (fightPowerA != fightPowerB)
        {
            return fightPowerB.CompareTo(fightPowerA);
        }
 
        return idA.CompareTo(idB);
    }
 
    //8强名单来源于 16强淘汰赛后的胜者
    public void Player8ListSort()
    {
        if (!battleInfo.ContainsKey(16))
        {
            return;
        }
        guessPlayer8List.Clear();
        var tList = battleInfo[16].Keys.ToList();
        for (int i = 0; i < tList.Count; i++)
        {
            var battle = battleInfo[16][tList[i]];
            if (battle.WinPlayerID != 0)
            {
                guessPlayer8List.Add((int)battle.WinPlayerID);
            }
        }
 
        guessPlayer8List.Sort(CompareGuess8);
        return;
    }
 
    int CompareGuess8(int idA, int idB)
    {
        bool isGuessA = guess4Personal.ContainsKey(idA);
        bool isGusssB = guess4Personal.ContainsKey(idB);
 
        if (isGuessA != isGusssB)
        {
            return isGusssB.CompareTo(isGuessA);
        }
 
        long fightPowerA = fightersInfo[(uint)idA].FightPower;
        long fightPowerB = fightersInfo[(uint)idB].FightPower;
 
        if (fightPowerA != fightPowerB)
        {
            return fightPowerB.CompareTo(fightPowerA);
        }
 
        return idA.CompareTo(idB);
    }
 
    public bool isShowRaceInfoYet = false; //是否已经显示过赛程信息小提示
    uint pushGroupMark = 0; //每场比赛只推送一次
    void OnMinuteEvent()
    {
        if (!WindowCenter.Instance.IsOpen("CrossServerQualifyingWin") &&
            dungeonModel.GetDataMapIdByMapId(PlayerDatas.Instance.baseData.MapID) != DATA_MAPID)
        {
            uint nowMark = nowGroupMark;
            //准备入场的时候推送
            if (pushGroupMark != nowMark && HaveMyBattle(nowMark))
            {
                int battleID = GetBattleID();
                if (ILChampionshipTimeConfig.Get(battleID).StateValue % 10 == 2)
                {
                    HeroControler.Instance.FuncPush(210);
                    pushGroupMark = nowMark;
                }
            }
        }
    }
 
    //官职
    public void UpdateOfficialInfo(HC018_tagGCChampionshipOfficialInfo netPack)
    {
        officialZoneID = netPack.ZoneID;
        var playerID = PlayerDatas.Instance.baseData.PlayerID;
        for (int i = 0; i < netPack.OfficialList.Length; i++)
        {
            var officialInfo = netPack.OfficialList[i];
            List<CrossChampionshipPKPlayer> applyList = new List<CrossChampionshipPKPlayer>();
 
            for (int j = 0; j < officialInfo.ApplyPlayerList.Length; j++)
            {
                applyList.Add(new CrossChampionshipPKPlayer()
                {
                    PlayerID = officialInfo.ApplyPlayerList[j].PlayerID,
                    Job = officialInfo.ApplyPlayerList[j].Job,
                    PlayerName = officialInfo.ApplyPlayerList[j].PlayerName,
                    FightPower = officialInfo.ApplyPlayerList[j].FightPowerEx * (long)Constants.ExpPointValue + officialInfo.ApplyPlayerList[j].FightPower,
                    RealmLV = officialInfo.ApplyPlayerList[j].RealmLV,
                    Face = officialInfo.ApplyPlayerList[j].Face,
                    FacePic = officialInfo.ApplyPlayerList[j].FacePic,
                });
            }
 
            rankOfficialDict[(int)officialInfo.OfficialID] = new ChampionshipOfficial()
            {
                LastDismissJuniorTime = officialInfo.LastDismissJuniorTime,
                WorshipCount = officialInfo.WorshipCount,
                WorshipDouble = officialInfo.WorshipDouble,
 
                OfficialPlayer = new CrossChampionshipPKPlayer()
                {
                    PlayerID = officialInfo.OfficialPlayer.PlayerID,
                    Job = officialInfo.OfficialPlayer.Job,
                    PlayerName = officialInfo.OfficialPlayer.PlayerName,
                    FightPower = officialInfo.OfficialPlayer.FightPowerEx * (long)Constants.ExpPointValue + officialInfo.OfficialPlayer.FightPower,
                    RealmLV = officialInfo.OfficialPlayer.RealmLV,
                    Face = officialInfo.OfficialPlayer.Face,
                    FacePic = officialInfo.OfficialPlayer.FacePic,
                },
 
                ApplyPlayerList = applyList,
            };
            if (myOfficialID == (int)officialInfo.OfficialID && playerID != (int)officialInfo.OfficialPlayer.PlayerID)
            {
                //被辞退了
                myOfficialID = 0;
                officialRedpoint.state = RedPointState.Simple;
                LocalSave.SetInt("myOfficialID", 0);
            }
            if (playerID == (int)officialInfo.OfficialPlayer.PlayerID)
            {
                myOfficialID = (int)officialInfo.OfficialID;
                if (LocalSave.GetInt("myOfficialID") == 0 && ILChampionshipOfficialConfig.Get(myOfficialID).CanBeReplace == 0)
                {
                    //申请通过
                    officialRedpoint.state = RedPointState.Simple;
                }
                LocalSave.SetInt("myOfficialID", myOfficialID);
            }
        }
        RefreshMyApplyCnt();
        RefreshRedPoint();
        UpdateOffcialEvent?.Invoke();
    }
 
    //界主的申请列表红点
    void RefreshRedPoint()
    {
        RefreshMobaiRedpoint();
        if (myOfficialID > 0 && myOfficialID <= 8)
        {
            officialRedpoint.state = RedPointState.None;
            //写死了前4个申请
            for (int i = 0; i < 4; i++)
            {
                var id = myOfficialID * 100 + i + 1;
                if (GetOfficialPlayer(id).PlayerID != 0)
                {
                    return;
                }
                if (rankOfficialDict.ContainsKey(id) && rankOfficialDict[id].ApplyPlayerList.Count != 0)
                {
                    officialRedpoint.state = RedPointState.Simple;
                }
            }
        }
    }
 
    void RefreshMyApplyCnt()
    {
        if (myOfficialID != 0)
        {
            myApplyCnt = 0;
            return;
        }
        var playerID = PlayerDatas.Instance.baseData.PlayerID;
        var keys = rankOfficialDict.Keys.ToList();
        myApplyCnt = 0;
        for (int i = 0; i < keys.Count; i++)
        {
            var applyList = rankOfficialDict[keys[i]].ApplyPlayerList;
            for (int j = 0; j < applyList.Count; j++)
            {
                if (playerID == applyList[j].PlayerID)
                {
                    myApplyCnt++;
                }
            }
        }
    }
 
    public CrossChampionshipPKPlayer GetOfficialPlayer(int officialID)
    {
 
        if (!rankOfficialDict.ContainsKey(officialID))
            return new CrossChampionshipPKPlayer();
 
        return rankOfficialDict[officialID].OfficialPlayer;
    }
 
    public int GeDefaultOffcialSub()
    {
        if (myOfficialID <= 8)
            return 0;
        if (offcialOperList[selectOffcialID][1].IndexOf(myOfficialID) != -1)
        {
            return 1;
        }
        return 0;
    }
 
    public bool IsInApply(int officialID)
    {
        var playerID = PlayerDatas.Instance.baseData.PlayerID;
        if (!rankOfficialDict.ContainsKey(officialID))
        {
            return false;
        }
        var applyList = rankOfficialDict[officialID].ApplyPlayerList;
        for (int i = 0; i < applyList.Count; i++)
        {
            if (applyList[i].PlayerID == playerID)
            {
                return true;
            }
        }
        return false;
    }
 
    public void UpdateChampionshipOfficialChallengeRet(IL_HC020_tagGCChampionshipOfficialChallengeRet netPack)
    {
        string tip;
        if (netPack.Ret == 0)
            tip = "CrossServerQualifying59";
        else if (netPack.Ret == 1)
            tip = "CrossServerQualifying61";
        else
            tip = "CrossServerQualifying60";
 
        ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get(tip));
    }
 
    public void UpdateChampionshipOfficialApplyReplyRet(IL_HC019_tagGCChampionshipOfficialApplyReplyRet netPack)
    {
        if (netPack.IsOK == 1)
        {
            SysNotifyMgr.Instance.ShowTip("CrossServerQualifying9");
        }
        else
        {
            SysNotifyMgr.Instance.ShowTip("CrossServerQualifying10");
        }
    }
 
    public string challengeRecord;
    public void UpdateChampionshipOfficialChallengeRecordInfo(IL_HC021_tagGCChampionshipOfficialChallengeRecordInfo netPack)
    {
        for (int i = 0; i < netPack.RecordList.Length; i++)
        {
            var record = netPack.RecordList[i];
            if (record.Ret == 1)
            {
                challengeRecord += Language.Get("CrossServerQualifying62",
                    TimeUtility.GetTime(record.ChallengeTime).ToString("yyyy-MM-dd HH:mm:ss"), record.PlayerName);
            }
            else
            {
                challengeRecord += Language.Get("CrossServerQualifying63",
                    TimeUtility.GetTime(record.ChallengeTime).ToString("yyyy-MM-dd HH:mm:ss"), record.PlayerName);
            }
        }
        WindowCenter.Instance.OpenIL<CrossServerQualifyingOfficialNoteWin>();
    }
 
 
    public void UpdateWorship(IL_HC109_tagMCChampionshipPlayerInfo netPack)
    {
        worshipCntToday = netPack.WorshipCount;
        RefreshMobaiRedpoint();
        UpdateWorshipEvent?.Invoke();
    }
 
    bool queryKai = false;  //进入游戏后请求一次即可
    uint lastGroupMark = 0;  //从非0到0说明需要更新界主
    public List<uint> playerIDList = new List<uint>();
 
    //查询界主信息
    public void QueryAllKaiKingInfo()
    {
        if (queryKai)
        {
            if (!(lastGroupMark != 0 && nowGroupMark == 0))
            {
                return;
            }
        }
 
        playerIDList.Clear();
        for (int i = 1; i <= 8; i++)
        {
            var playerID = GetOfficialPlayer(i).PlayerID;
            if (playerID == 0)
                break;
            playerIDList.Add(playerID);
        }
        if (playerIDList.IsNullOrEmpty())
            return;
 
        SnxxzGame.Instance.StartCoroutine(PlayerQuery());
        lastGroupMark = nowGroupMark;
        queryKai = true;
    }
 
    private IEnumerator PlayerQuery()
    {
        for (int i = 0; i < playerIDList.Count; i++)
        {
            QueryKaiKingInfo(playerIDList[i]);
            yield return null;
        }
    }
 
    public void QueryKaiKingInfo(uint playerID)
    {
        ModelCenter.Instance.GetModel<RoleParticularModel>().ViewCrossPlayerCacheData((int)playerID);
    }
 
    void PlayerLoginOkEvent()
    {
        RefreshMobaiRedpoint();
        loginRedpoint.state = RedPointState.Simple;
    }
 
    void RefreshMobaiRedpoint()
    {
        mobaiRedpoint.state = RedPointState.None;
        if (rankOfficialDict.Count == 0)
            return;
        for (int i = 1; i <= 8; i++)
        {
            if (GetOfficialPlayer(1).PlayerID != 0)
            {
                //有膜拜对象且有次数
                if (worshipCntToday < worshipMaxCnt)
                {
                    mobaiRedpoint.state = RedPointState.Simple;
                }
                return;
            }
        }
 
    }
}