少年修仙传客户端代码仓库
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
using System;
 
namespace Snxxz.UI
{
    [XLua.Hotfix]
    [XLua.LuaCallCSharp]
    public class CrossServerBossModel : Model, IMapInitOk, IPlayerLoginOk
    {
        public const int DATA_MAPID = 32020;
        public const int REDPOINT = 21302;
 
        List<int> sortedBossIds = new List<int>();
        Dictionary<int, CrossServerBossData> bosses = new Dictionary<int, CrossServerBossData>();
 
        public int bigBoxNpcId = 0;
        public int smallBoxNpcId = 0;
        public List<int> eliteMonsters = new List<int>();
 
        int m_SelectedBoss = 0;
        public int selectedBoss {
            get {
                return this.m_SelectedBoss;
            }
            set {
                if (this.m_SelectedBoss != value)
                {
                    this.m_SelectedBoss = value;
                    if (bossSelectedEvent != null)
                    {
                        bossSelectedEvent(value);
                    }
                }
            }
        }
 
        int m_WearyValue = 0;
        public int wearyValue {
            get { return m_WearyValue; }
            set {
                if (m_WearyValue != value)
                {
                    m_WearyValue = value;
                    UpdateRedpoint();
                    if (bossWearyValueChangeEvent != null)
                    {
                        bossWearyValueChangeEvent();
                    }
                }
            }
        }
 
        int m_BigBoxCollectCount = 0;
        public int bigBoxCollectCount {
            get { return m_BigBoxCollectCount; }
            set {
                if (m_BigBoxCollectCount != value)
                {
                    m_BigBoxCollectCount = value;
                    UpdateRedpoint();
                    if (bigBoxCollectCountChangeEvent != null)
                    {
                        bigBoxCollectCountChangeEvent();
                    }
                }
            }
        }
 
        int m_SmallBoxCollectCount = 0;
        public int smallBoxCollectCount {
            get { return m_SmallBoxCollectCount; }
            set { m_SmallBoxCollectCount = value; }
        }
 
        public event Action bossWearyValueChangeEvent;
        public event Action<int> bossSelectedEvent;
        public event Action bigBoxCollectCountChangeEvent;
        public event Action boxSurplusChangeEvent;
        public event Action eliteSurplusChangeEvent;
 
        public CrossServerBossBox boxInfo = new CrossServerBossBox();
        public CrossServerBossElite eliteInfo = new CrossServerBossElite();
        public Redpoint redpoint = new Redpoint(FindPreciousModel.LOOTPRECIOUs_REDPOINTID, REDPOINT);
 
        FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
        TeamModel teamModel { get { return ModelCenter.Instance.GetModel<TeamModel>(); } }
 
        public override void Init()
        {
            ParseConfig();
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFunctionStateChange;
        }
 
        public override void UnInit()
        {
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFunctionStateChange;
        }
 
        public void OnMapInitOk()
        {
            if (PlayerDatas.Instance.baseData.MapID == DATA_MAPID)
            {
                if (selectedBoss != 0)
                {
                    MapTransferUtility.Instance.MoveToNPC(selectedBoss);
                }
            }
        }
 
        public void RequestEnter()
        {
            if (PlayerDatas.Instance.extersion.bossState == 1)
            {
                SysNotifyMgr.Instance.ShowTip("CrossMap11");
                return;
            }
 
            if (!AssetVersionUtility.IsUnpriorAssetDownLoadOk())
            {
                InGameDownLoad.Instance.TryDownLoad(InGameDownLoad.Dominant.Whole);
                return;
            }
 
            var sendInfo = new CC105_tagCMEnterCrossServer();
            sendInfo.DataMapID = DATA_MAPID;
            GameNetSystem.Instance.SendInfo(sendInfo);
        }
 
        public bool CanEnter(out int error)
        {
            var mapId = PlayerDatas.Instance.baseData.MapID;
            var mapConfig = MapConfig.Get(mapId);
            if (mapConfig.MapFBType != (int)MapType.OpenCountry)
            {
                error = 1;
                return false;
            }
 
            if (teamModel.isMatching)
            {
                error = 2;
                return false;
            }
 
            if (teamModel.teamPrepare.isPreparing)
            {
                error = 3;
                return false;
            }
 
            if (CrossServerLogin.Instance.IsEnterCrossServerPreparing())
            {
                error = 4;
                return false;
            }
 
            var deadModel = ModelCenter.Instance.GetModel<PlayerDeadModel>();
            if (deadModel.playerIsDie)
            {
                error = 5;
                return false;
            }
 
            var config = CrossServerBossConfig.Get(selectedBoss);
            if (config.MonsterType == 4 && !findPreciousModel.IsBossUnlock(selectedBoss))
            {
                error = 6;
                return false;
            }
 
            error = 0;
            return true;
        }
 
        public void ProcessEnterError(int error)
        {
            switch (error)
            {
                case 1:
                    SysNotifyMgr.Instance.ShowTip("InDungeon_CantGo");
                    break;
                case 2:
                    SysNotifyMgr.Instance.ShowTip("CrossMap1");
                    break;
                case 3:
                    SysNotifyMgr.Instance.ShowTip("CrossMap2");
                    break;
                case 4:
                    SysNotifyMgr.Instance.ShowTip("CrossMap3");
                    break;
                case 5:
                    SysNotifyMgr.Instance.ShowTip("CrossMap4");
                    break;
                case 6:
                    SysNotifyMgr.Instance.ShowTip("BossRealmHint2", NPCConfig.Get(selectedBoss).Realm);
                    break;
            }
        }
 
        public void RequestExit()
        {
            var match = new CC104_tagCMExitCrossRealm();
            GameNetSystem.Instance.SendToCrossServer(match);
        }
 
        public bool TryGetBossData(int bossId, out CrossServerBossData data)
        {
            return bosses.TryGetValue(bossId, out data);
        }
 
        public List<int> GetNpcIds()
        {
            var npcIds = new List<int>();
            npcIds.Add(bigBoxNpcId);
            npcIds.Add(eliteMonsters[0]);
 
            var lockedCount = 0;
            foreach (var bossId in bosses.Keys)
            {
                if (findPreciousModel.IsBossUnlock(bossId))
                {
                    npcIds.Add(bossId);
                }
                else
                {
                    if (lockedCount < 2)
                    {
                        lockedCount++;
                        npcIds.Add(bossId);
                    }
                }
            }
 
            return npcIds;
        }
 
        public List<int> GetShowBosses()
        {
            return new List<int>(sortedBossIds);
        }
 
        public int GetRecommendNpc()
        {
            if (bigBoxCollectCount < GeneralDefine.dogzBoxLimit)
            {
                return bigBoxNpcId;
            }
 
            if (wearyValue < GeneralDefine.bossWearyValues[2])
            {
                var preferBoss = 0;
                for (int i = sortedBossIds.Count - 1; i >= 0; i--)
                {
                    var bossId = sortedBossIds[i];
                    if (IsBossUnLocked(bossId))
                    {
                        if (preferBoss == 0)
                        {
                            preferBoss = bossId;
                        }
 
                        if (findPreciousModel.IsBossAlive(bossId) && findPreciousModel.IsSameBigRealmStageBoss(bossId))
                        {
                            return bossId;
                        }
                    }
                }
 
                if (preferBoss == 0)
                {
                    preferBoss = sortedBossIds[0];
                }
 
                return preferBoss;
            }
 
            return eliteMonsters[0];
        }
 
        public int GetRecommendKillElite()
        {
            var Elite = eliteInfo.GetAliveElite();
            if (Elite == 0)
            {
                Elite = eliteMonsters[0];
            }
 
            return Elite;
        }
 
        public bool IsBossUnLocked(int bossId)
        {
            if (bossId == bigBoxNpcId || bossId == smallBoxNpcId)
            {
                return true;
            }
 
            if (eliteMonsters.Contains(bossId))
            {
                return true;
            }
 
            return bosses.ContainsKey(bossId) && findPreciousModel.IsBossUnlock(bossId);
        }
 
        public void RequestBoxAndEliteSurplusInfo()
        {
            var sendInfo = new CA227_tagCMQueryNPCCntInfo();
            sendInfo.MapID = DATA_MAPID;
            sendInfo.LineID = 0;
            var stringArray = new string[eliteMonsters.Count + 2];
            for (int i = 0; i < eliteMonsters.Count; i++)
            {
                stringArray[i] = eliteMonsters[i].ToString();
            }
 
            stringArray[eliteMonsters.Count] = bigBoxNpcId.ToString();
            stringArray[eliteMonsters.Count + 1] = smallBoxNpcId.ToString();
 
            sendInfo.NPCIDList = string.Format("[{0}]", string.Join(",", stringArray));
            sendInfo.NPCIDListLen = (byte)sendInfo.NPCIDList.Length;
            if (CrossServerUtility.IsCrossServerBoss())
            {
                GameNetSystem.Instance.SendToCrossServer(sendInfo);
            }
            else
            {
                GameNetSystem.Instance.SendInfo(sendInfo);
            }
        }
 
        public void RequestBoxSurplusInfo()
        {
            var sendInfo = new CA227_tagCMQueryNPCCntInfo();
            sendInfo.MapID = DATA_MAPID;
            sendInfo.LineID = (ushort)PlayerDatas.Instance.baseData.dungeonLineId;
            sendInfo.NPCIDList = string.Format("[{0},{1}]", bigBoxNpcId, smallBoxNpcId);
            sendInfo.NPCIDListLen = (byte)sendInfo.NPCIDList.Length;
            if (CrossServerUtility.IsCrossServerBoss())
            {
                GameNetSystem.Instance.SendToCrossServer(sendInfo);
            }
            else
            {
                GameNetSystem.Instance.SendInfo(sendInfo);
            }
        }
 
        public void RequestEliteSurplusInfo()
        {
            var sendInfo = new CA227_tagCMQueryNPCCntInfo();
            sendInfo.MapID = DATA_MAPID;
            sendInfo.LineID = 0;
            var stringArray = new string[eliteMonsters.Count];
            for (int i = 0; i < stringArray.Length; i++)
            {
                stringArray[i] = eliteMonsters[i].ToString();
            }
 
            sendInfo.NPCIDList = string.Format("[{0}]", string.Join(",", stringArray));
            sendInfo.NPCIDListLen = (byte)sendInfo.NPCIDList.Length;
 
            if (CrossServerUtility.IsCrossServerBoss())
            {
                GameNetSystem.Instance.SendToCrossServer(sendInfo);
            }
            else
            {
                GameNetSystem.Instance.SendInfo(sendInfo);
            }
        }
 
        public void UpdateMonsterSurplusInfo(HA714_tagMCNPCCntList _npcInfoes)
        {
            if (_npcInfoes.MapID != DATA_MAPID)
            {
                return;
            }
 
            var updatedBigBox = false;
            var updatedSmallBox = false;
            var updatedEliteNpcIds = new List<int>();
 
            for (int i = 0; i < _npcInfoes.NPCInfoList.Length; i++)
            {
                var npcInfo = _npcInfoes.NPCInfoList[i];
                if (npcInfo.NPCID == bigBoxNpcId)
                {
                    boxInfo.bigBoxSurplus = (int)npcInfo.Cnt;
                    updatedBigBox = true;
                }
 
                if (npcInfo.NPCID == smallBoxNpcId)
                {
                    boxInfo.smallBoxSurplus = (int)npcInfo.Cnt;
                    updatedSmallBox = true;
                }
 
                if (eliteMonsters.Contains((int)npcInfo.NPCID))
                {
                    eliteInfo.UpdateEliteInfo((int)npcInfo.NPCID, (int)npcInfo.Cnt);
                    updatedEliteNpcIds.Add((int)npcInfo.NPCID);
                }
            }
 
            if (!updatedBigBox)
            {
                boxInfo.bigBoxSurplus = 0;
            }
 
            if (!updatedSmallBox)
            {
                boxInfo.smallBoxSurplus = 0;
            }
 
            if (boxSurplusChangeEvent != null)
            {
                boxSurplusChangeEvent();
            }
 
            foreach (var item in eliteMonsters)
            {
                if (!updatedEliteNpcIds.Contains(item))
                {
                    eliteInfo.UpdateEliteInfo(item, 0);
                }
            }
 
            if (eliteSurplusChangeEvent != null)
            {
                eliteSurplusChangeEvent();
            }
        }
 
        public void UpdateBoxOrEliteRefreshTime(HA904_tagGCDogzNPCRefreshTime _refreshTimes)
        {
            var containBox = false;
            var boxRefreshSecond = 0;
 
            var containElite = false;
            var eliteRefreshSecond = 0;
 
            for (int i = 0; i < _refreshTimes.InfoList.Length; i++)
            {
                var info = _refreshTimes.InfoList[i];
                if (bigBoxNpcId == info.NPCID || smallBoxNpcId == info.NPCID)
                {
                    containBox = true;
                    boxRefreshSecond = (int)info.RefreshSecond;
                }
 
                if (eliteMonsters.Contains((int)info.NPCID))
                {
                    containElite = true;
                    eliteRefreshSecond = (int)info.RefreshSecond;
                }
            }
 
            if (containBox)
            {
                boxInfo.UpdateBoxRefreshTime(boxRefreshSecond);
            }
 
            if (containElite)
            {
                eliteInfo.UpdateEliteRefreshTime(eliteRefreshSecond);
            }
 
            if (WindowCenter.Instance.IsOpen("CrossServerBossWin"))
            {
                if (containBox)
                {
                    RequestBoxSurplusInfo();
                }
 
                if (containElite)
                {
                    RequestEliteSurplusInfo();
                }
            }
        }
 
        public void OnPlayerLoginOk()
        {
            UpdateRedpoint();
        }
 
        private void OnFunctionStateChange(int id)
        {
            if (id == 162)
            {
                UpdateRedpoint();
            }
        }
 
        public void UpdateRedpoint()
        {
            if (FuncOpen.Instance.IsFuncOpen(162) && TimeUtility.OpenDay >= GeneralDefine.crossServerOneVsOneOpenDay)
            {
                var wearyValueLimit = GeneralDefine.bossWearyValues[2];
                var count = (wearyValueLimit - wearyValue) + (GeneralDefine.dogzBoxLimit - bigBoxCollectCount);
                redpoint.count = count;
            }
            else
            {
                redpoint.count = 0;
            }
 
            redpoint.state = redpoint.count > 0 ? RedPointState.Quantity : RedPointState.None;
            CrossServerUtility.UpdateCrossServerRedpoint();
        }
 
        private void ParseConfig()
        {
            var configs = CrossServerBossConfig.GetValues();
            foreach (var config in configs)
            {
                switch (config.MonsterType)
                {
                    case 1:
                        bigBoxNpcId = config.NPCID;
                        break;
                    case 2:
                        smallBoxNpcId = config.NPCID;
                        break;
                    case 3:
                        eliteMonsters.Add(config.NPCID);
                        break;
                    case 4:
                        bosses[config.NPCID] = new CrossServerBossData(config.NPCID);
                        sortedBossIds.Add(config.NPCID);
                        break;
                }
            }
 
            sortedBossIds.Sort(CrossServerBossData.LevelCompare);
        }
 
 
    }
 
    public class CrossServerBossBox
    {
        public int bigBoxSurplus;
        public int smallBoxSurplus;
        public DateTime refreshTime { get; private set; }
 
        public event Action refreshTimeEvent;
 
        public void UpdateBoxInfo(int _big, int _small)
        {
            bigBoxSurplus = _big;
            smallBoxSurplus = _small;
        }
 
        public void UpdateBoxRefreshTime(int _seconds)
        {
            refreshTime = TimeUtility.ServerNow + new TimeSpan(_seconds * TimeSpan.TicksPerSecond);
            if (refreshTimeEvent != null)
            {
                refreshTimeEvent();
            }
        }
    }
 
    public class CrossServerBossElite
    {
        public Dictionary<int, int> eliteCounts = new Dictionary<int, int>();
        public int eliteSurplus {
            get {
                var count = 0;
                foreach (var eliteCount in eliteCounts.Values)
                {
                    count += eliteCount;
                }
                return count;
            }
        }
 
        public DateTime refreshTime { get; private set; }
        public event Action refreshTimeEvent;
 
        public void UpdateEliteInfo(int _npcId, int _count)
        {
            eliteCounts[_npcId] = _count;
        }
 
        public void UpdateEliteRefreshTime(int _seconds)
        {
            refreshTime = TimeUtility.ServerNow + new TimeSpan(_seconds * TimeSpan.TicksPerSecond);
            if (refreshTimeEvent != null)
            {
                refreshTimeEvent();
            }
        }
 
        public int GetAliveElite()
        {
            foreach (var EliteCount in eliteCounts)
            {
                if (EliteCount.Value > 0)
                {
                    return EliteCount.Key;
                }
            }
 
            return 0;
        }
    }
 
    public class CrossServerBossData
    {
        public int id { get; private set; }
        public CrossServerBossData(int _id)
        {
            this.id = _id;
        }
 
        public static int LevelCompare(int a, int b)
        {
            var configA = NPCConfig.Get(a);
            var configB = NPCConfig.Get(b);
 
            return configA.NPCLV < configB.NPCLV ? -1 : 1;
        }
    }
 
}