少年修仙传客户端代码仓库
client_Wu Xijin
2018-10-18 1868bc632a9134b6891d4fc5f427e3f280b9e973
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, October 09, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using TableConfig;
using System;
using System.Text.RegularExpressions;
 
namespace Snxxz.UI
{
 
    public class Treasure
    {
        public int id { get; private set; }
 
        int m_Stage;
        public int stage
        {
            get { return m_Stage; }
            private set { m_Stage = value; }
        }
 
        int m_Exp;
        public int exp
        {
            get { return m_Exp; }
            private set { m_Exp = value; }
        }
 
        bool m_HasClickChallenge = false;
        public bool hasClickChallenge
        {
            get { return m_HasClickChallenge; }
            set { m_HasClickChallenge = value; }
        }
 
        TreasureState m_State = TreasureState.Locked;
        public TreasureState state
        {
            get { return m_State; }
            set { m_State = value; }
        }
 
        int m_Progress = 0;
        public int progress
        {
            get { return m_Progress; }
            set { m_Progress = value; }
        }
 
        public bool isChallengeDungeonAble
        {
            get
            {
                if (state != TreasureState.Collecting)
                {
                    return false;
                }
                var config = Config.Instance.Get<TreasureConfig>(id);
                return progress >= config.RequirementTotal;// && config.LastSuccID > 0;
            }
        }
 
        public int unLockSkill
        {
            get
            {
                var job = PlayerDatas.Instance.baseData.Job;
                var stage = treasureStages.Find((x) =>
                {
                    return x.unlockType == TreasureStageUnlock.Skill;
                });
                return stage != null ? stage.GetSkill(job) : 0;
            }
        }
 
        public int unLockPrivilege
        {
            get; private set;
        }
 
        public int autoSelectPotential { get; set; }
 
        Dictionary<int, List<TreasurePotential>> jobToPotentials = new Dictionary<int, List<TreasurePotential>>();
 
        public List<TreasurePotential> potentials
        {
            get
            {
                if (jobToPotentials.ContainsKey(PlayerDatas.Instance.baseData.Job))
                {
                    return jobToPotentials[PlayerDatas.Instance.baseData.Job];
                }
                else
                {
                    return null;
                }
            }
        }
 
        public List<int> achievements = new List<int>();
        public Dictionary<int, AchievementGroup> achievementGroups = new Dictionary<int, AchievementGroup>();
 
        public Redpoint skillLevelUpRedpoint { get; private set; }
        public Redpoint achievementRedpoint { get; private set; }
 
        public Treasure(int _id)
        {
            this.id = _id;
        }
 
        public Treasure(int _id, int[] _potentialIds, Redpoint _skillLevelUpRedpoint, Redpoint _achievementPoint)
        {
            this.id = _id;
            this.skillLevelUpRedpoint = _skillLevelUpRedpoint;
            this.achievementRedpoint = _achievementPoint;
 
            var config = Config.Instance.Get<TreasureConfig>(this.id);
            List<int> _expAchievements;
            if (SuccessConfig.TryGetTreasureExpAchievements(_id, out _expAchievements))
            {
                achievements.AddRange(_expAchievements);
            }
 
            foreach (var achievement in achievements)
            {
                var achievementConfig = Config.Instance.Get<SuccessConfig>(achievement);
 
                AchievementGroup group;
                if (achievementGroups.ContainsKey(achievementConfig.Group))
                {
                    group = achievementGroups[achievementConfig.Group];
                }
                else
                {
                    achievementGroups[achievementConfig.Group] = group = new AchievementGroup(achievementConfig.Group);
                }
 
                group.AddAchievement(achievement);
            }
 
            foreach (var group in achievementGroups.Values)
            {
                group.Sort();
            }
 
            for (int i = 0; i < _potentialIds.Length; i++)
            {
                var skillId = _potentialIds[i];
                var skillConfig = Config.Instance.Get<SkillConfig>(skillId);
                if (skillConfig == null)
                {
                    continue;
                }
 
                for (int j = 0; j < GeneralDefine.openJobs.Length; j++)
                {
                    var job = GeneralDefine.openJobs[j];
                    List<TreasurePotential> tempPotentials;
                    if (jobToPotentials.ContainsKey(job))
                    {
                        tempPotentials = jobToPotentials[job];
                    }
                    else
                    {
                        jobToPotentials[job] = tempPotentials = new List<TreasurePotential>();
                    }
 
                    if (skillConfig.UseType == 0 || skillConfig.UseType == 1 << job)
                    {
                        tempPotentials.Add(new TreasurePotential(skillId, 0));
                    }
                }
            }
        }
 
        public TreasurePotential GetPotential(int _potentialId)
        {
            if (potentials == null)
            {
                return null;
            }
            else
            {
                for (int i = 0; i < potentials.Count; i++)
                {
                    var potential = potentials[i];
                    if (potential.id == _potentialId)
                    {
                        return potential;
                    }
                }
 
                return null;
            }
        }
 
        public TreasurePotential GetPotentialByIndex(int index)
        {
            if (potentials == null)
            {
                return null;
            }
            else
            {
                if (index >= 0 && index < potentials.Count)
                {
                    return potentials[index];
                }
 
                return null;
            }
        }
 
        public void UpdatePotentialLevel(int _potentialId, int _level)
        {
            for (int i = 0; i < potentials.Count; i++)
            {
                var potential = potentials[i];
                if (potential.id == _potentialId)
                {
                    potential.level = _level;
                    break;
                }
            }
        }
 
        public AchievementGroup FindAchievementGroup(int _achievementId)
        {
            foreach (var key in achievementGroups.Keys)
            {
                var achievementGroup = achievementGroups[key];
                if (achievementGroup.Contain(_achievementId))
                {
                    return achievementGroup;
                }
            }
 
            return null;
        }
 
        private int AchievementCompare(int _lhs, int _rhs)
        {
            var configA = Config.Instance.Get<SuccessConfig>(_lhs);
            var configB = Config.Instance.Get<SuccessConfig>(_rhs);
 
            return configA.ReOrder < configB.ReOrder ? -1 : 1;
        }
 
        public List<TreasureStage> treasureStages = new List<TreasureStage>();
        public void UpdateTreasureStage(TreasureUpConfig _cfg)
        {
            TreasureStage _stage = new TreasureStage(_cfg);
            treasureStages.Add(_stage);
        }
 
 
 
        public void UpdateTreasureLevelExp(int _lv, int _exp, bool _hasClickChallenge)
        {
            stage = _lv;
            exp = _exp;
            hasClickChallenge = _hasClickChallenge;
            if ((this is HumanTreasure))
            {
                (this as HumanTreasure).UpdateTreasureState();
            }
        }
 
        public bool IsHighestStage
        {
            get
            {
                return treasureStages.FindIndex((x) =>
                {
                    return x.stage >= stage + 1;
                }) == -1;
            }
        }
 
        public bool IsUnlockStage(TreasureStageUnlock _type)
        {
            var _stage = treasureStages.Find((x) =>
            {
                return x.unlockType == _type;
            });
            if (_stage == null)
            {
                return false;
            }
            return stage >= _stage.stage;
        }
 
        public int GetStageId(int _stageIndex)
        {
            foreach (var item in treasureStages)
            {
                if (item.stage == _stageIndex)
                {
                    return item.id;
                }
            }
 
            return 0;
        }
 
        public int GetStageIndex(int _stage)
        {
            if (treasureStages[0].unlockType == TreasureStageUnlock.None)
            {
                return Mathf.Max(_stage - 1, 0);
            }
            return _stage;
        }
 
        public int StageCount
        {
            get { return treasureStages.Count; }
        }
    }
 
    public class HumanTreasure : Treasure
    {
        HumanTreasureState m_State = HumanTreasureState.Locked;
        public HumanTreasureState humanState
        {
            get
            {
                return m_State;
            }
            private set
            {
                m_State = value;
                ModelCenter.Instance.GetModel<TreasureModel>().HumanTreasureStateChange(base.id);
            }
        }
 
        public HumanTreasure(int _id, int[] _potentialIds, Redpoint _skillLevelUpRedpoint, Redpoint _achievementPoint
            , Redpoint _castSoulPoint)
            : base(_id, _potentialIds, _skillLevelUpRedpoint, _achievementPoint)
        {
            castSoulRedpoint = _castSoulPoint;
        }
 
        public void UpdateTreasureState()
        {
            if (state == TreasureState.Locked)
            {
                humanState = HumanTreasureState.Locked;
                return;
            }
            if (state == TreasureState.Collecting)
            {
                humanState = HumanTreasureState.Challenge;
                return;
            }
            if (IsHighestStage && FuncOpen.Instance.IsFuncOpen(82))
            {
                humanState = HumanTreasureState.Potential;
            }
            else
            {
                humanState = HumanTreasureState.CastSoul;
            }
        }
 
        public Redpoint castSoulRedpoint { get; private set; }
    }
 
    public class AchievementGroup
    {
        AchievementModel model { get { return ModelCenter.Instance.GetModel<AchievementModel>(); } }
        public int group { get; private set; }
        List<int> achievements = new List<int>();
 
        public AchievementGroup(int _category)
        {
            group = _category;
        }
 
        public void AddAchievement(int _achievement)
        {
            if (!achievements.Contains(_achievement))
            {
                achievements.Add(_achievement);
            }
        }
 
        public void Sort()
        {
            achievements.Sort(AchievementCompare);
        }
 
        public bool Contain(int _achievementId)
        {
            return achievements.Contains(_achievementId);
        }
 
        public bool IsAwardable()
        {
            var doingAchievement = GetDoingAchievement();
            if (doingAchievement > 0)
            {
                Achievement achievement;
                if (model.TryGetAchievement(doingAchievement, out achievement) && !achievement.completed)
                {
                    return Achievement.IsReach(doingAchievement, achievement.progress);
                }
            }
            return false;
        }
 
        public bool IsCompleted()
        {
            var achievementId = GetDoingAchievement();
            Achievement doingAchievement;
            if (model.TryGetAchievement(achievementId, out doingAchievement) && doingAchievement.completed)
            {
                return true;
            }
            for (int i = 0; i < achievements.Count; i++)
            {
                var id = achievements[i];
                Achievement achievement;
                if (model.TryGetAchievement(id, out achievement) && !achievement.completed)
                {
                    return false;
                }
            }
 
            return true;
        }
 
        public int GetDoingAchievement()
        {
            var achievementId = 0;
            for (int i = 0; i < achievements.Count; i++)
            {
                var id = achievements[i];
                Achievement achievement;
 
                if (model.TryGetAchievement(id, out achievement) && !achievement.completed)
                {
                    return id;
                }
 
                achievementId = id;
            }
 
            return achievementId;
        }
 
        public int GetLastAchievement()
        {
            if (achievements.Count == 0)
            {
                return 0;
            }
            else
            {
                var achievementId = GetDoingAchievement();
                Achievement doingAchievement;
                if (model.TryGetAchievement(achievementId, out doingAchievement) && doingAchievement.completed)
                {
                    return achievementId;
                }
                return achievements[achievements.Count - 1];
            }
        }
 
        private int AchievementCompare(int _lhs, int _rhs)
        {
            var configA = Config.Instance.Get<SuccessConfig>(_lhs);
            var configB = Config.Instance.Get<SuccessConfig>(_rhs);
 
            return configA.ReOrder.CompareTo(configB.ReOrder);
        }
 
        public static int Compare(AchievementGroup _lhs, AchievementGroup _rhs)
        {
            var awardableA = _lhs.IsAwardable();
            var awardableB = _rhs.IsAwardable();
 
            if (awardableA != awardableB)
            {
                return awardableA ? -1 : 1;
            }
            else
            {
                var completedA = _lhs.IsCompleted();
                var completedB = _rhs.IsCompleted();
                if (completedA != completedB)
                {
                    return completedA.CompareTo(completedB);
                }
                else if (completedA && completedB)
                {
                    return _lhs.group < _rhs.group ? -1 : 1;
                }
                else
                {
                    var idA = _lhs.GetDoingAchievement();
                    var idB = _rhs.GetDoingAchievement();
 
                    var configA = Config.Instance.Get<SuccessConfig>(idA);
                    var configB = Config.Instance.Get<SuccessConfig>(idB);
 
                    if (configA == null)
                    {
                        return 1;
                    }
                    else if (configB == null)
                    {
                        return -1;
                    }
                    else if (configA == null && configB == null)
                    {
                        return 0;
                    }
                    else
                    {
                        return configA.ReOrder < configB.ReOrder ? -1 : 1;
                    }
                }
            }
        }
 
    }
 
    public class TreasurePotential
    {
        public int id { get; private set; }
        public int level { get; set; }
 
        public TreasurePotential(int _id, int _level)
        {
            this.id = _id;
            this.level = _level;
        }
    }
 
    public struct PotentialBook
    {
        public int itemId;
        public int needCount;
        public int successRate;
        public int levelUpId;
 
        public PotentialBook(int _itemId, int _needCount, int _successRate, int _levelUpId)
        {
            this.itemId = _itemId;
            this.needCount = _needCount;
            this.successRate = _successRate;
            this.levelUpId = _levelUpId;
        }
 
    }
 
    public struct VIPKillNPCTreasure
    {
        public int level;
        public long currentExp;
    }
 
    public class TreasureStage
    {
        public int id { get; private set; }
 
        public int stage { get; set; }
        public TreasureStageUnlock unlockType { get; private set; }
        public Dictionary<int, int> propertyDict { get; private set; }
        public Dictionary<int, int> skillDict { get; private set; }
        public int func { get; private set; }
        public Item item { get; private set; }
        public int treasure { get; private set; }
        public int treasureSoul { get; private set; }
        public int exp { get; set; }
        public int stateSfxId { get; private set; }
        public const int selectedSfxId = 5144;
        public string sfxGotState { get; private set; }
        public string sfxUnGotState { get; private set; }
 
        public TreasureStage(TreasureUpConfig _config)
        {
            id = _config.ID;
            unlockType = TreasureStageUnlock.None;
            if (_config.UnLockFuncID != 0)
            {
                unlockType = TreasureStageUnlock.Func;
                func = _config.UnLockFuncID;
            }
            else if (_config.UnLockSkill != null && _config.UnLockSkill.Length > 1)
            {
                unlockType = TreasureStageUnlock.Skill;
                skillDict = new Dictionary<int, int>();
                for (int i = 0; i < _config.UnLockSkill.Length; i++)
                {
                    skillDict.Add(i + 1, _config.UnLockSkill[i]);
                }
            }
            else if (!string.IsNullOrEmpty(_config.AddAttr))
            {
                unlockType = TreasureStageUnlock.Property;
                propertyDict = ConfigParse.GetDic<int, int>(_config.AddAttr);
            }
            else if (_config.ActiveMWID != 0)
            {
                unlockType = TreasureStageUnlock.Treasure;
                treasure = _config.ActiveMWID;
            }
            else if (_config.SoulID != 0)
            {
                unlockType = TreasureStageUnlock.TreasureSoul;
                treasureSoul = _config.SoulID;
            }
            else if (!string.IsNullOrEmpty(_config.ItemAward))
            {
                unlockType = TreasureStageUnlock.Item;
                var itemArray = LitJson.JsonMapper.ToObject<int[]>(_config.ItemAward);
                if (itemArray != null && itemArray.Length > 0)
                {
                    item = new Item()
                    {
                        id = itemArray[0],
                        count = itemArray.Length > 1 ? itemArray[1] : 1,
                        bind = itemArray.Length > 2 ? (itemArray[2] == 1) : false,
                    };
                }
            }
 
            exp = _config.NeedExp;
            stage = _config.LV;
 
            switch (unlockType)
            {
                case TreasureStageUnlock.Property:
                    stateSfxId = propertyDict.ContainsKey(6) ? 5142 : 5139;
                    sfxGotState = propertyDict.ContainsKey(6) ? "Effect_FaBao_Icon_ShengMing" : "Effect_FaBao_Icon_GongJi";
                    sfxUnGotState = propertyDict.ContainsKey(6) ? "Effect_FaBao_Icon_ShengMing" : "Effect_FaBao_Icon_GongJi";
                    break;
                default:
                    stateSfxId = 5141;
                    sfxGotState = "Effect_FaBao_Icon_JiNeng_01";
                    sfxUnGotState = "Effect_FaBao_Icon_JiNeng_02";
                    break;
            }
        }
 
        public int GetSkill(int _job)
        {
            if (skillDict.ContainsKey(_job))
            {
                return skillDict[_job];
            }
            return 0;
        }
 
        public int GetFightPower()
        {
            switch (unlockType)
            {
                case TreasureStageUnlock.Property:
                    return UIHelper.GetFightPower(propertyDict);
                case TreasureStageUnlock.Skill:
                    var _job = PlayerDatas.Instance.baseData.Job;
                    var _skillCfg = Config.Instance.Get<SkillConfig>(GetSkill(_job));
                    if (_skillCfg != null)
                    {
                        return _skillCfg.FightPower;
                    }
                    break;
            }
            return 0;
        }
    }
 
    public enum TreasureStageUnlock
    {
        None,
        Property,
        Skill,
        Func,
        Item,
        Treasure,
        TreasureSoul,
    }
}