少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-08 aa62264ce70008889d090d7402298e7850350708
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
using LitJson;
using Snxxz.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
 
using UnityEngine;
namespace Snxxz.UI
{
    public class RealmModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize
    {
        Dictionary<int, Dictionary<int, int>> m_RealmProperties = new Dictionary<int, Dictionary<int, int>>();
        Dictionary<int, Dictionary<int, int[]>> m_RealmPreviewEquips = new Dictionary<int, Dictionary<int, int[]>>();
        List<List<int>> m_RealmStages = new List<List<int>>();
        public int realmMaxLevel { get; private set; }
        public int realmPoolOpenLevel { get; private set; }
        public bool isBossPass { get; private set; }
        public int realmExpTime { get; private set; }
        public long startExp { get; private set; }
 
        public long totalExp
        {
            get
            {
                var exp = startExp;
                var tick = (TimeUtility.ServerNow - expStartTime).Ticks;
                var singleTick = realmExpTime * TimeSpan.TicksPerSecond;
                var times = tick / singleTick;
 
                var config = RealmConfig.Get(PlayerDatas.Instance.baseData.realmLevel);
                if (config != null && config.expRate != 0)
                {
                    exp = times * config.expRate + startExp;
                    exp = exp > config.expLimit ? config.expLimit : exp;
                }
 
                return exp;
            }
        }
 
        public long exp
        {
            get
            {
                var exp = startExp;
                var tick = (TimeUtility.ServerNow - expStartTime).Ticks;
                var singleTick = realmExpTime * TimeSpan.TicksPerSecond;
                var times = (float)tick / singleTick;
 
                var config = RealmConfig.Get(PlayerDatas.Instance.baseData.realmLevel);
                if (config != null && config.expRate != 0)
                {
                    exp = (long)(times * config.expRate) + startExp;
                    exp = exp > config.expLimit ? config.expLimit : exp;
                }
                return exp;
            }
        }
 
        public DateTime expStartTime { get; private set; }
 
        public const int REALM_DUNGEON_ID = 31110;
 
        public readonly Redpoint levelUpRedpoint = new Redpoint(114, 11401);
        public readonly Redpoint challengeRedpoint = new Redpoint(114, 11402);
        public readonly Redpoint realmPoolRedpoint = new Redpoint(114, 11403);
 
        int m_SelectRealm = 0;
        public int selectRealm
        {
            get { return m_SelectRealm; }
            set
            {
                if (m_SelectRealm != value)
                {
                    m_SelectRealm = value;
                    if (selectRealmRefresh != null)
                    {
                        selectRealmRefresh();
                    }
                }
            }
        }
 
        int cacheMapId = 0;
 
        bool redpointDirty = false;
 
        bool serverInited = false;
 
        public List<int> displayRealms = new List<int>();
 
        public int displayRealmLevel
        {
            get
            {
                if (displayRealms.Count > 0)
                {
                    return displayRealms[0];
                }
                return PlayerDatas.Instance.baseData.realmLevel;
            }
        }
 
        public event Action selectRealmRefresh;
        public event Action realmExpRefresh;
 
        EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        ActivitiesPushModel pushModel { get { return ModelCenter.Instance.GetModel<ActivitiesPushModel>(); } }
 
        public override void Init()
        {
            StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
            PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent;
            GlobalTimeEvent.Instance.secondEvent += PerSecond;
            packModel.refreshItemCountEvent += RefreshItemCountEvent;
            ParseConfig();
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            isBossPass = false;
            expStartTime = DateTime.Now;
            startExp = 0;
            serverInited = false;
            SysNotifyMgr.Instance.OnSystemNotifyEvent -= OnSystemNotifyEvent;
        }
 
        public void OnPlayerLoginOk()
        {
            redpointDirty = true;
            serverInited = true;
 
            SysNotifyMgr.Instance.OnSystemNotifyEvent -= OnSystemNotifyEvent;
            SysNotifyMgr.Instance.OnSystemNotifyEvent += OnSystemNotifyEvent;
        }
 
        public override void UnInit()
        {
            StageLoad.Instance.onStageLoadFinish -= OnStageLoadFinish;
            PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
            packModel.refreshItemCountEvent -= RefreshItemCountEvent;
            GlobalTimeEvent.Instance.secondEvent -= PerSecond;
        }
 
        private void PerSecond()
        {
            if (redpointDirty)
            {
                RefreshRedpoint();
                redpointDirty = false;
            }
            if (serverInited)
            {
                RefreshRealmPoolRedpoint();
            }
        }
 
        void ParseConfig()
        {
            realmMaxLevel = 0;
            List<int> stages = new List<int>();
            m_RealmStages.Add(stages);
            var configs = RealmConfig.GetValues();
            foreach (var config in configs)
            {
                if (config.Lv > realmMaxLevel)
                {
                    realmMaxLevel = config.Lv;
                }
 
                if (config.AddAttrType != null && config.AddAttrType.Length > 0)
                {
                    Dictionary<int, int> dict = new Dictionary<int, int>();
                    for (int i = 0; i < config.AddAttrType.Length; i++)
                    {
                        dict.Add(config.AddAttrType[i], config.AddAttrNum[i]);
                    }
                    m_RealmProperties.Add(config.Lv, dict);
                }
 
                if (config.Lv != 0)
                {
                    stages.Add(config.Lv);
 
                    if (config.BossID != 0)
                    {
                        stages = new List<int>();
                        m_RealmStages.Add(stages);
                    }
                }
 
                if (!string.IsNullOrEmpty(config.equips))
                {
                    var json = LitJson.JsonMapper.ToObject(config.equips);
                    Dictionary<int, int[]> dict = new Dictionary<int, int[]>();
                    foreach (var jobKey in json.Keys)
                    {
                        var job = int.Parse(jobKey);
                        var equipArray = LitJson.JsonMapper.ToObject<int[]>(json[jobKey].ToJson());
                        dict.Add(job, equipArray);
                    }
                    m_RealmPreviewEquips.Add(config.Lv, dict);
                }
 
                if (realmPoolOpenLevel == 0 && config.expRate != 0)
                {
                    realmPoolOpenLevel = config.Lv;
                }
            }
 
            var funcConfig = FuncConfigConfig.Get("RealmExpTime");
            realmExpTime = int.Parse(funcConfig.Numerical1);
        }
 
        public bool TryGetRealmProperty(int level, out Dictionary<int, int> propertyDict)
        {
            return m_RealmProperties.TryGetValue(level, out propertyDict);
        }
 
        public bool TryGetRealmStages(int index, out List<int> stages)
        {
            stages = null;
            if (index < m_RealmStages.Count)
            {
                stages = m_RealmStages[index];
                return true;
            }
            return false;
        }
 
        public bool TryGetRealmPreviewEquips(int level, int job, out int[] equips)
        {
            equips = null;
            if (m_RealmPreviewEquips.ContainsKey(level))
            {
                return m_RealmPreviewEquips[level].TryGetValue(job, out equips);
            }
            return false;
        }
 
        public bool TryLevelUp(out int error)
        {
            error = 0;
            var realmLevel = PlayerDatas.Instance.baseData.realmLevel;
            if (realmLevel >= realmMaxLevel)
            {
                error = 100;
                return false;
            }
            var config = RealmConfig.Get(realmLevel);
            if (PlayerDatas.Instance.baseData.LV < config.NeedLV)
            {
                error = 1;
                return false;
            }
            if (config.BossID != 0 && !isBossPass)
            {
                error = 2;
                return false;
            }
            if (config.NeedGood != 0)
            {
                var count = packModel.GetItemCountByID(PackType.Item, config.NeedGood);
                if (count < config.NeedNum)
                {
                    error = 3;
                    return false;
                }
            }
            return true;
        }
 
        public bool IsUnlockEquipRealm(int realmLevel, out int level)
        {
            level = 0;
            var equipSets = equipModel.GetAllEquipSets();
            var index = equipSets.FindIndex((x) =>
            {
                var equipSet = equipModel.GetEquipSet(x);
                if (equipSet != null)
                {
                    return equipSet.realm == realmLevel;
                }
                return false;
            });
            if (index != -1)
            {
                level = equipSets[index];
                return true;
            }
            return false;
        }
 
        public int GetRealmStage(int realmLevel)
        {
            if (realmLevel == 0)
            {
                return 0;
            }
            for (int i = 0; i < m_RealmStages.Count; i++)
            {
                var stages = m_RealmStages[i];
                var index = stages.IndexOf(realmLevel);
                if (index != -1)
                {
                    if (stages.Count == 1)
                    {
                        return i - 1;
                    }
                    return i;
                }
            }
            return m_RealmStages.Count - 1;
        }
 
        public int GetRealmStageEffect(int realmLevel)
        {
            var config = RealmConfig.Get(realmLevel);
            if (config != null)
            {
                switch (config.Quality)
                {
                    case 1: return 7028;
                    case 2: return 7029;
                    case 3: return 7030;
                    case 4: return 7031;
                    case 5: return 7032;
                    case 6: return 7033;
                }
            }
            return 7028;
        }
 
        public int GetRealmCoverEffect(int realmLevel)
        {
            var config = RealmConfig.Get(realmLevel);
            if (config != null)
            {
                switch (config.Quality)
                {
                    case 1: return 7039;
                    case 2: return 7040;
                    case 3: return 7041;
                    case 4: return 7042;
                    case 5: return 7043;
                    case 6: return 7044;
                }
            }
            return 7039;
        }
 
        public int GetRealmLineEffect(int realmLevel)
        {
            var config = RealmConfig.Get(realmLevel);
            if (config != null)
            {
                switch (config.Quality)
                {
                    case 1: return 7034;
                    case 2: return 7059;
                    case 3: return 7060;
                    case 4: return 7061;
                    case 5: return 7062;
                    case 6: return 7063;
                }
            }
            return 7034;
        }
 
        public bool GetBossEffectShow(int realmLevel)
        {
            var playerId = PlayerDatas.Instance.baseData.PlayerID;
            return LocalSave.GetBool(StringUtility.Contact("RealmBossEffect_", realmLevel, "_", playerId));
        }
 
        public void SetBossEffectShow(int realmLevel)
        {
            var playerId = PlayerDatas.Instance.baseData.PlayerID;
            LocalSave.SetBool(StringUtility.Contact("RealmBossEffect_", realmLevel, "_", playerId), true);
        }
 
        public bool SatisfyChallengeBoss(int reamLevel)
        {
            var config = RealmConfig.Get(reamLevel);
            if (config != null)
            {
                return config.BossID != 0 && !isBossPass && PlayerDatas.Instance.baseData.LV >= config.NeedLV;
            }
            return false;
        }
 
        public void SendLevelUpRealm()
        {
            CA523_tagCMRealmLVUp pak = new CA523_tagCMRealmLVUp();
            GameNetSystem.Instance.SendInfo(pak);
        }
 
        public void TryPushRealmPoolMessage()
        {
            var remainTime = 0f;
            if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Realm))
            {
                var realmLevel = PlayerDatas.Instance.baseData.realmLevel;
                if (realmLevel >= realmPoolOpenLevel)
                {
                    var config = RealmConfig.Get(realmLevel);
                    if (exp < config.expLimit)
                    {
                        remainTime = realmExpTime * ((config.expLimit - exp) / (float)config.expRate);
                    }
                }
            }
            if (remainTime > 0f)
            {
                var json = pushModel.GetPushJsonData(11403, (int)remainTime,
                    Language.Get("RealmPoolGeTui_Title"), Language.Get("RealmPoolGeTui_Content"));
                pushModel.SendPushInfo(json);
            }
            else
            {
                pushModel.RemovePushInfo(11403);
            }
        }
 
        public void ReceivePackage(HA311_tagMCSyncRealmInfo package)
        {
            isBossPass = package.IsPass == 1;
            RefreshRedpoint();
        }
 
        public void ReceivePackage(HA327_tagMCRealmExpInfo package)
        {
            expStartTime = TimeUtility.GetTime(package.BeginTime);
            startExp = (long)package.CurExpPoint * Constants.ExpPointValue + package.CurExp;
            if (realmExpRefresh != null)
            {
                realmExpRefresh();
            }
            RefreshRealmPoolRedpoint();
 
            TryPushRealmPoolMessage();
        }
 
        private void OnStageLoadFinish()
        {
            if (!(StageLoad.Instance.currentStage is DungeonStage))
            {
                cacheMapId = 0;
            }
            else
            {
                var mapId = PlayerDatas.Instance.baseData.MapID;
                if (cacheMapId == REALM_DUNGEON_ID
                    && mapId != REALM_DUNGEON_ID)
                {
                    SnxxzGame.Instance.StartCoroutine(Co_TryOpenRealmWin());
                }
                cacheMapId = mapId;
            }
        }
 
        private void OnSystemNotifyEvent(string key)
        {
            if (key == "BigRealmUpSuccess")
            {
                if (WindowCenter.Instance.IsOpen<MainInterfaceWin>()
                    && !WindowCenter.Instance.ExistAnyFullScreenOrMaskWin())
                {
                    EffectMgr.Instance.PlayUIEffect(7047, 1800, WindowCenter.Instance.uiRoot.baseCanvas, false);
                }
            }
        }
 
        private void PlayerDataRefreshEvent(PlayerDataType dataType)
        {
            if (dataType == PlayerDataType.RealmLevel
                || dataType == PlayerDataType.LV
                || dataType == PlayerDataType.FightPoint)
            {
                redpointDirty = true;
            }
        }
 
        private void RefreshItemCountEvent(PackType packType, int arg2, int itemId)
        {
            if (packType == PackType.Item)
            {
                var config = RealmConfig.Get(PlayerDatas.Instance.baseData.realmLevel);
                if (config != null && config.NeedGood == itemId)
                {
                    redpointDirty = true;
                }
            }
        }
 
        IEnumerator Co_TryOpenRealmWin()
        {
            yield return WaitingForSecondConst.WaitMS1000;
            TryOpenRealmWin();
        }
 
        private void TryOpenRealmWin()
        {
            if (NewBieCenter.Instance.inGuiding)
            {
                return;
            }
            var treasureModel = ModelCenter.Instance.GetModel<TreasureModel>();
            if (treasureModel.newGotShowing)
            {
                return;
            }
            if (WindowCenter.Instance.ExistAnyFullScreenOrMaskWin())
            {
                return;
            }
            WindowCenter.Instance.Open<RealmTransitionWin>();
        }
 
        void RefreshRedpoint()
        {
            var levelUpable = false;
            var challengeable = false;
 
            if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Realm))
            {
                var realmLevel = PlayerDatas.Instance.baseData.realmLevel;
                if (realmLevel < realmMaxLevel)
                {
                    var config = RealmConfig.Get(realmLevel);
                    if (SatisfyChallengeBoss(realmLevel))
                    {
                        challengeable = PlayerDatas.Instance.baseData.FightPoint >= config.FightPower;
                    }
 
                    var error = 0;
                    if (TryLevelUp(out error))
                    {
                        levelUpable = true;
                    }
                }
            }
 
            levelUpRedpoint.state = levelUpable ? RedPointState.Simple : RedPointState.None;
            challengeRedpoint.state = challengeable ? RedPointState.Simple : RedPointState.None;
 
            RefreshRealmPoolRedpoint();
        }
 
        void RefreshRealmPoolRedpoint()
        {
            var isPoolFull = false;
            if (FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Realm))
            {
                var realmLevel = PlayerDatas.Instance.baseData.realmLevel;
                if (realmLevel >= realmPoolOpenLevel)
                {
                    var config = RealmConfig.Get(PlayerDatas.Instance.baseData.realmLevel);
                    if (totalExp >= config.expLimit)
                    {
                        isPoolFull = true;
                    }
                }
            }
 
            realmPoolRedpoint.state = isPoolFull ? RedPointState.Simple : RedPointState.None;
        }
    }
}