少年修仙传客户端代码仓库
client_Wu Xijin
2018-09-21 b24abe465bdc9725f7225aea36b049c9f99a94a5
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
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, October 09, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using TableConfig;
using Snxxz.UI;
 
namespace Snxxz.UI
{
    public class TreasurePotentialPanel : MonoBehaviour
    {
        [SerializeField] TreasureAnimation m_TreasureAnimation;
        [SerializeField] TreasurePotentialBriefInfo[] potentialBriefInfos = null;
        [SerializeField] RectTransform m_ContainerPotentialEffect;
        [SerializeField] Text m_CurrentPotential;
        [SerializeField] Text m_NextPotential;
        [SerializeField] Transform m_PotentialMaxLevelTip;
        [SerializeField] Transform m_ContainerRequirement;
        [SerializeField] Text m_SPOwn;
        [SerializeField] Text m_SPNeed;
        [SerializeField] Transform m_ContainerUpgrade;
 
        [SerializeField] ItemBehaviour m_PotentialBook;
        [SerializeField] Text m_PotentialCount;
        [SerializeField] Text m_SuccessRatio;
        [SerializeField] Image m_RatioUp;
        [SerializeField] Button m_ItemBtn;
        [SerializeField] Image m_AddBookSign;
        [SerializeField] Image m_AddBookRedpoint;
        [SerializeField] Button m_RemoveBook;
        [SerializeField] ImageEx m_UpgradeImage;
        [SerializeField] Button m_Upgrade;
 
        [SerializeField] UIEffect m_FailureEffect;
 
        [SerializeField] Text m_SkillTitle;
 
        [SerializeField] RectTransform m_ContainerPotential;
        [SerializeField] RectTransform m_ContainerGetSkill;
        [SerializeField] Text m_GetSkillCondition;
        [SerializeField] Image m_GetSkillIcon;
        [SerializeField] Text m_GetSkillEffect;
        [SerializeField] Text m_GetSkillName;
 
        [SerializeField] RectTransform m_ContainerTotalEffect;
        [SerializeField] Image m_SkillIcon;
        [SerializeField] Text m_SkillName;
        [SerializeField] Text m_SkillCd;
        [SerializeField] Text m_SkillDescription;
        [SerializeField] Image m_StageSkillIcon;
        [SerializeField] Button m_StageSkillBtn;
        [SerializeField] Image m_SkillSelect;
        [SerializeField] PotentialInfo[] m_TotalPotentials;
 
        [SerializeField] RectTransform m_ContainerLock;
        [SerializeField] Text m_PotentialLimit;
 
        [SerializeField] TreasurePotentialLines m_PotentialLine;
 
        public event Action<int> potentialSelectEvent;
        PlayerPackModel playerPack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
 
        int m_SelectedPotential = 0;
        public int selectedPotential {
            get {
                return m_SelectedPotential;
            }
            set {
                if (m_SelectedPotential != value || selectTotalEffect)
                {
                    m_SelectedPotential = value;
                    model.selectedPotential = value;
                    model.selectedPotentialBook = 0;
 
                    DisplayPotentialEffect();
 
                    var potential = m_Treasure.GetPotential(selectedPotential);
                    var config = Config.Instance.Get<SkillConfig>(potential.id);
 
                    var level = potential.level;
                    var isMax = level >= config.SkillMaxLV;
                    m_PotentialMaxLevelTip.gameObject.SetActive(isMax);
                    m_ContainerUpgrade.gameObject.SetActive(!isMax &&
                        FuncOpen.Instance.IsFuncOpen(82) && model.IsPotentialUnlock(m_Treasure.id, selectedPotential));
                    m_ContainerRequirement.gameObject.SetActive(!isMax);
 
                    if (!isMax)
                    {
                        AutoSelectPotentialBook();
                        DisplayUpgradeCost();
                        DisplayGetSkill();
                        DisplaySuccessRatio();
                    }
                    else
                    {
                        DisplayGetSkill();
                    }
 
                    if (potentialSelectEvent != null)
                    {
                        potentialSelectEvent(m_SelectedPotential);
                    }
                }
            }
        }
 
        bool m_SelectTotalEffect = false;
        public bool selectTotalEffect {
            get {
                return m_SelectTotalEffect;
            }
        }
 
        int spNeed = 0;
        TreasureModel model { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
 
        Treasure m_Treasure;
 
        public void Display(Treasure _treasure, int _state = 0)
        {
            m_Treasure = _treasure;
            if (m_Treasure == null || m_Treasure.potentials == null)
            {
                return;
            }
 
            var _index = 0;
            var _level = -1;
            for (int i = 0; i < m_Treasure.potentials.Count; i++)
            {
                if (model.IsPotentialUnlock(_treasure.id, m_Treasure.potentials[i].id))
                {
                    if (m_Treasure.potentials[i].level < _level || _level == -1)
                    {
                        _level = m_Treasure.potentials[i].level;
                        _index = i;
                    }
                }
            }
 
            for (int i = 0; i < m_Treasure.potentials.Count; i++)
            {
                if (model.SatisyPotentialLevelUp(_treasure.id, m_Treasure.potentials[i].id))
                {
                    _index = i;
                    break;
                }
            }
 
            selectedPotential = m_Treasure.potentials[_index].id;
 
            for (int i = 0; i < potentialBriefInfos.Length; i++)
            {
                var behaviour = potentialBriefInfos[i];
                if (i < m_Treasure.potentials.Count)
                {
                    behaviour.gameObject.SetActive(true);
                    behaviour.treasurePotential = this;
                    behaviour.DisplayBaseInfo(m_Treasure.potentials[i], _state);
                    if (_state != 2 && m_TreasureAnimation.step == TreasureAnimation.TreasureShowStep.UnLock)
                    {
                        m_PotentialLine.Display(i, model.IsPotentialUnlock(m_Treasure.id, m_Treasure.potentials[i].id));
                    }
                }
                else
                {
                    behaviour.gameObject.SetActive(false);
                    m_PotentialLine.Display(i, false);
                }
            }
 
            model.selectedPotentialBook = 0;
 
            var level = m_Treasure.potentials[_index].level;
            var config = Config.Instance.Get<SkillConfig>(m_Treasure.potentials[_index].id);
            var isMax = level >= config.SkillMaxLV;
            if (!isMax)
            {
                AutoSelectPotentialBook();
                DisplayPotentialBook(model.selectedPotentialBook);
            }
 
            model.onPotentialLevelUpResultEvent -= OnPotentialLevelUp;
            model.onPotentialLevelUpResultEvent += OnPotentialLevelUp;
 
            model.potentialLevelUpdate -= PotentialLevelUpdate;
            model.potentialLevelUpdate += PotentialLevelUpdate;
 
            var _stageSkillCfg = Config.Instance.Get<SkillConfig>(m_Treasure.unLockSkill);
            if (_stageSkillCfg != null)
            {
                m_StageSkillIcon.SetSprite(_stageSkillCfg.IconName);
                m_StageSkillIcon.SetNativeSize();
            }
 
            m_ContainerLock.gameObject.SetActive(!FuncOpen.Instance.IsFuncOpen(82));
            var funcOpenConfig = Config.Instance.Get<FuncOpenLVConfig>(82);
            m_PotentialLimit.text = Language.Get("TreasureSkillLimit", funcOpenConfig.LimitLV);
 
            if (!model.IsPotentialUnlock(model.selectedTreasure, selectedPotential)
                || model.GetPotentialUnlockShow(model.selectedTreasure) || _state == 2)
            {
                DisplayTotalPotentialEffect();
            }
 
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= OnTreasurePotentialSPChange;
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent += OnTreasurePotentialSPChange;
 
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
 
            playerPack.RefreshItemCountAct -= RefreshItemCountAct;
            playerPack.RefreshItemCountAct += RefreshItemCountAct;
 
            m_TreasureAnimation.OnStepComplete -= OnStepComplete;
            m_TreasureAnimation.OnStepComplete += OnStepComplete;
 
            m_TreasureAnimation.OnUnlockPotentialComplete -= OnUnlockPotentialComplete;
            m_TreasureAnimation.OnUnlockPotentialComplete += OnUnlockPotentialComplete;
 
            m_TreasureAnimation.OnPotentialLevelUpComplete -= OnPotentialLevelUpComplete;
            m_TreasureAnimation.OnPotentialLevelUpComplete += OnPotentialLevelUpComplete;
 
            m_TreasureAnimation.OnPotentialLineAnimComplete -= OnPotentialLineAnimComplete;
            m_TreasureAnimation.OnPotentialLineAnimComplete += OnPotentialLineAnimComplete;
 
            model.potentialBookSelectEvent -= DisplayPotentialBook;
            model.potentialBookSelectEvent += DisplayPotentialBook;
 
            RedpointCenter.Instance.redpointValueChangeEvent -= RedpointValueChangeEvent;
            RedpointCenter.Instance.redpointValueChangeEvent += RedpointValueChangeEvent;
 
            if (m_TreasureAnimation.step == TreasureAnimation.TreasureShowStep.UnLock)
            {
                OnStepComplete(TreasureAnimation.TreasureShowStep.UnLock);
            }
        }
 
        public void Dispose()
        {
            for (int i = 0; i < potentialBriefInfos.Length; i++)
            {
                var behaviour = potentialBriefInfos[i];
                behaviour.Dispose();
            }
 
            m_PotentialLine.Dispose();
 
            model.potentialBookSelectEvent -= DisplayPotentialBook;
            model.onPotentialLevelUpResultEvent -= OnPotentialLevelUp;
            model.potentialLevelUpdate -= PotentialLevelUpdate;
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= OnTreasurePotentialSPChange;
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
            playerPack.RefreshItemCountAct -= RefreshItemCountAct;
            m_TreasureAnimation.OnStepComplete -= OnStepComplete;
            m_TreasureAnimation.OnUnlockPotentialComplete -= OnUnlockPotentialComplete;
            m_TreasureAnimation.OnPotentialLevelUpComplete -= OnPotentialLevelUpComplete;
            RedpointCenter.Instance.redpointValueChangeEvent -= RedpointValueChangeEvent;
            m_TreasureAnimation.OnPotentialLineAnimComplete -= OnPotentialLineAnimComplete;
 
            m_SelectedPotential = 0;
 
            model.inPotentialModifyPower = false;
        }
 
        private void RedpointValueChangeEvent(int _id)
        {
            if (m_Treasure != null && _id == m_Treasure.skillLevelUpRedpoint.id)
            {
                DisplayAddBookRedpoint();
            }
        }
 
        private void OnPotentialLevelUpComplete(int _index, int level)
        {
            var potential = m_Treasure.potentials[_index];
            potentialBriefInfos[_index].DisplayStateSfx();
            potentialBriefInfos[_index].StartLevelTween();
            var _nextPotential = GetNextPotential(potential.id);
            if (_nextPotential != 0)
            {
                var config = Config.Instance.Get<SkillConfig>(_nextPotential);
                if (level == config.LearnSkillLV && potentialBriefInfos != null)
                {
                    for (int i = 0; i < potentialBriefInfos.Length; i++)
                    {
                        if (potentialBriefInfos[i].potential.id == _nextPotential)
                        {
                            potentialBriefInfos[i].potentialTween.SetStartState();
                            potentialBriefInfos[i].potentialTween.enabled = false;
                            m_TreasureAnimation.UnlockTreasurePotential(i);
                        }
                    }
                }
            }
        }
 
        private void ModifyPowerUp(int treasureId, int index, int fightPower)
        {
            var power = model.GetPotentialInitialPower(treasureId, index);
            if (power != 0)
            {
                ModelCenter.Instance.GetModel<PlayerMainDate>().FabaoPowerAdd(fightPower);
                model.inPotentialModifyPower = true;
            }
        }
 
        private void OnUnlockPotentialComplete(int _index)
        {
            selectedPotential = m_Treasure.potentials[_index].id;
            m_TreasureAnimation.DisplayPotentialLine(_index);
            HandleAchievement();
 
            if (model.inPotentialModifyPower)
            {
                var power = model.GetPotentialInitialPower(m_Treasure.id, _index);
                model.inPotentialModifyPower = false;
                ModelCenter.Instance.GetModel<PlayerMainDate>().FabaoPowerAdd(power);
            }
        }
 
        private void OnPotentialLineAnimComplete(int _index)
        {
            if (_index < potentialBriefInfos.Length)
            {
                m_PotentialLine.Display(_index, true);
            }
        }
 
        private void OnStepComplete(TreasureAnimation.TreasureShowStep _step)
        {
            switch (_step)
            {
                case TreasureAnimation.TreasureShowStep.UnLock:
                    if (model.GetPotentialUnlockShow(model.selectedTreasure))
                    {
                        potentialBriefInfos[0].potentialTween.SetStartState();
                        potentialBriefInfos[0].potentialTween.enabled = false;
                        m_TreasureAnimation.UnlockTreasurePotential(0);
                        model.SetPotentialUnlockShow(model.selectedTreasure);
                    }
                    else
                    {
                        HandleAchievement();
                    }
                    DisplayLines();
                    break;
                case TreasureAnimation.TreasureShowStep.FirstPotential:
                    if (FuncOpen.Instance.IsFuncOpen(82))
                    {
                        potentialBriefInfos[0].potentialTween.SetStartState();
                        potentialBriefInfos[0].potentialTween.enabled = false;
                        m_TreasureAnimation.UnlockTreasurePotential(0);
                        model.SetPotentialUnlockShow(model.selectedTreasure);
                    }
                    else
                    {
                        HandleAchievement();
                    }
                    break;
            }
        }
 
        void HandleAchievement()
        {
            if (AchievementGoto.guideAchievementId != 0 && m_Treasure != null)
            {
                var config = Config.Instance.Get<SuccessConfig>(AchievementGoto.guideAchievementId);
                if (config != null && config.Type == 91)
                {
                    var index = PlayerDatas.Instance.baseData.Job - 1;
                    var skillId = index < config.Condition.Length ? config.Condition[index] : config.Condition[0];
                    var potential = m_Treasure.GetPotential(skillId);
                    if (potential != null)
                    {
                        if (model.IsPotentialUnlock(m_Treasure.id, potential.id))
                        {
                            selectedPotential = potential.id;
                        }
                        else
                        {
                            var skillConfig = Config.Instance.Get<SkillConfig>(potential.id);
                            if (skillConfig.LearnSkillReq > 0 && skillConfig.LearnSkillLV > 0)
                            {
                                var preskillConfig = Config.Instance.Get<SkillConfig>(skillConfig.LearnSkillReq);
                                SysNotifyMgr.Instance.ShowTip("TreasurePotentialSelectError", preskillConfig.SkillName, skillConfig.LearnSkillLV, skillConfig.SkillName);
                            }
                        }
                    }
                    AchievementGoto.guideAchievementId = 0;
                }
            }
        }
 
        void DisplayLines()
        {
            if (m_Treasure == null)
            {
                return;
            }
            for (int i = 0; i < potentialBriefInfos.Length; i++)
            {
                if (i < m_Treasure.potentials.Count)
                {
                    m_PotentialLine.Display(i, model.IsPotentialUnlock(m_Treasure.id, m_Treasure.potentials[i].id));
                }
                else
                {
                    m_PotentialLine.Display(i, false);
                }
            }
        }
 
        private void OnFuncStateChangeEvent(int _id)
        {
            if (_id == 82)
            {
                m_ContainerLock.gameObject.SetActive(!FuncOpen.Instance.IsFuncOpen(82));
                if (FuncOpen.Instance.IsFuncOpen(82))
                {
                    potentialBriefInfos[0].potentialTween.SetStartState();
                    potentialBriefInfos[0].potentialTween.enabled = false;
                    m_TreasureAnimation.UnlockTreasurePotential(0);
                    model.SetPotentialUnlockShow(model.selectedTreasure);
                }
            }
        }
 
        private void DisplayPotentialEffect()
        {
            m_ContainerUpgrade.gameObject.SetActive(FuncOpen.Instance.IsFuncOpen(82));
            m_ContainerPotential.gameObject.SetActive(true);
            m_ContainerTotalEffect.gameObject.SetActive(false);
            m_SelectTotalEffect = false;
            m_SkillTitle.text = Language.Get("TreasurePotential");
 
            m_SkillSelect.gameObject.SetActive(false);
 
            var potential = m_Treasure.GetPotential(selectedPotential);
            var level = potential.level;
            var config = Config.Instance.Get<SkillConfig>(potential.id);
            if (level <= 0)
            {
                m_CurrentPotential.text = Language.Get("Hallows_NotLearn");
            }
            else
            {
                var currentConfig = Config.Instance.Get<SkillConfig>(potential.id + level - 1);
                m_CurrentPotential.text = currentConfig.Description;
            }
 
            var isMax = level >= config.SkillMaxLV;
            if (isMax)
            {
                m_NextPotential.text = "";
            }
            else
            {
                var nextConfig = Config.Instance.Get<SkillConfig>(potential.id + level);
                m_NextPotential.text = nextConfig.Description;
            }
 
            DisplayAddBookRedpoint();
        }
 
        private void DisplayTotalPotentialEffect()
        {
            m_SelectTotalEffect = true;
 
            m_SkillSelect.gameObject.SetActive(true);
 
            for (int i = 0; i < potentialBriefInfos.Length; i++)
            {
                if (potentialBriefInfos[i].potential.id == model.selectedPotential)
                {
                    potentialBriefInfos[i].SelectTotal();
                }
            }
 
            m_ContainerGetSkill.gameObject.SetActive(false);
            m_ContainerUpgrade.gameObject.SetActive(false);
            m_ContainerPotential.gameObject.SetActive(false);
            m_ContainerTotalEffect.gameObject.SetActive(true);
            m_SkillTitle.text = Language.Get("PotentialSkill");
 
            var config = Config.Instance.Get<SkillConfig>(m_Treasure.unLockSkill);
            if (config != null)
            {
                m_SkillIcon.SetSprite(config.IconName);
                m_SkillName.text = config.SkillName;
                m_SkillCd.text = config.CoolDownTime == 0 ? string.Empty : Language.Get("L1065", config.CoolDownTime / 1000);
                m_SkillDescription.text = config.Description;
            }
 
 
            for (int i = 0; i < m_TotalPotentials.Length; i++)
            {
                if (i < m_Treasure.potentials.Count)
                {
                    m_TotalPotentials[i].SetActive(true);
                    var potential = m_Treasure.potentials[i];
                    m_TotalPotentials[i].Display(potential, model.selectedTreasure);
                }
                else
                {
                    m_TotalPotentials[i].SetActive(false);
                }
            }
        }
 
        void AutoSelectPotentialBook()
        {
            var potential = m_Treasure.GetPotential(model.selectedPotential);
            if (potential == null)
            {
                return;
            }
            var levelUpType = model.GetSkillLevelUpType(potential.id);
            var levelupId = TreasureModel.GetSkillLevelUpId(levelUpType, potential.level + 1);
            var config = Config.Instance.Get<TreasureSkillConfig>(levelupId);
            if (config == null)
            {
                return;
            }
            if (config.InitialRate >= 100)
            {
                model.selectedPotentialBook = 0;
                return;
            }
            var itemId = config.Meterial2ID.Length > 0 ? config.Meterial2ID[0] : 0;
            if (itemId != 0)
            {
                //var own = playerPack.GetItemCountByID(PackType.rptItem, itemId);
                //var need = config.MeterialNum2[0];
                var rate = config.Rate[0];
                if (rate >= 60)
                {
                    model.selectedPotentialBook = itemId;
                }
            }
        }
 
        private void DisplayUpgradeCost()
        {
            var potential = m_Treasure.GetPotential(selectedPotential);
            var levelUpType = model.GetSkillLevelUpType(potential.id);
            var levelupId = TreasureModel.GetSkillLevelUpId(levelUpType, potential.level + 1);
            var config = Config.Instance.Get<TreasureSkillConfig>(levelupId);
            var spOwn = PlayerDatas.Instance.baseData.treasurePotentialSp;
            spNeed = config.MeterialNum1;
            m_SPOwn.text = UIHelper.ReplaceLargeNum(spOwn);
            m_SPNeed.text = StringUtility.Contact("/", UIHelper.ReplaceLargeNum(spNeed));
            m_SPOwn.color = spOwn >= spNeed ? UIHelper.GetUIColor(TextColType.DarkGreen) : UIHelper.GetUIColor(TextColType.Red);
        }
 
        private void DisplayGetSkill(bool _levelUp = false)
        {
            var potential = m_Treasure.GetPotential(selectedPotential);
            var config = Config.Instance.Get<SkillConfig>(potential.id);
            int[] _getSkillArray;
            if (model.TryGetPotentialGetSkill(config.SkillTypeID, out _getSkillArray))
            {
                m_ContainerGetSkill.gameObject.SetActive(true);
                var _getSkillCfg = Config.Instance.Get<SkillConfig>(_getSkillArray[1]);
                m_GetSkillIcon.SetSprite(_getSkillCfg.IconName);
                m_GetSkillIcon.material = potential.level >= _getSkillArray[0] ?
                    MaterialUtility.GetUIDefaultGraphicMaterial() : MaterialUtility.GetInstantiatedSpriteGrayMaterial();
                m_GetSkillEffect.text = _getSkillCfg.Description;
                m_GetSkillName.text = _getSkillCfg.SkillName;
                if (potential.level >= _getSkillArray[0])
                {
                    m_GetSkillCondition.text = Language.Get("Role_TieTitle_2");
                    if (_levelUp && potential.level == _getSkillArray[0])
                    {
                        EffectMgr.Instance.PlayUIEffect(TreasureAnimation.SPIRALSFX, 2700, m_GetSkillIcon.transform, false);
                    }
                }
                else
                {
                    m_GetSkillCondition.text = Language.Get("PotentialGetSkillLevel", _getSkillArray[0]);
                }
                m_GetSkillCondition.color = potential.level >= _getSkillArray[0] ? UIHelper.GetUIColor(TextColType.NavyYellow) : UIHelper.GetUIColor(TextColType.Red);
            }
            else
            {
                m_ContainerGetSkill.gameObject.SetActive(false);
            }
        }
 
        private void DisplaySuccessRatio()
        {
            var levelUpConfig = GetPotentialLevelUpConfig();
            m_SuccessRatio.text = StringUtility.Contact((levelUpConfig.rate * 0.01f).ToString("f0"), "%");
            m_RatioUp.gameObject.SetActive(model.selectedPotentialBook != 0 && levelUpConfig.rate > 0);
            m_SuccessRatio.color = UIHelper.GetUIColor(model.selectedPotentialBook != 0 && levelUpConfig.rate > 0
                ? TextColType.DarkGreen : TextColType.LightYellow);
            m_UpgradeImage.gray = levelUpConfig.rate == 0 && model.selectedPotentialBook == 0;
        }
 
        private void DisplayAddBookRedpoint()
        {
            if (selectTotalEffect || model.selectedPotentialBook != 0)
            {
                m_AddBookRedpoint.gameObject.SetActive(false);
                return;
            }
            var levelUpConfig = GetPotentialLevelUpConfig();
            if (levelUpConfig.rate * 0.01f >= 60)
            {
                m_AddBookRedpoint.gameObject.SetActive(false);
                return;
            }
            bool levelUpHighSuccess = model.SatisyPotentialLevelUp(model.selectedTreasure, model.selectedPotential);
            m_AddBookRedpoint.gameObject.SetActive(levelUpHighSuccess);
        }
 
        private void OnSpNeedItem()
        {
            var levelUpConfig = GetPotentialLevelUpConfig();
            if (levelUpConfig.rate < 10000 || model.selectedPotentialBook != 0)
            {
                WindowCenter.Instance.Open<PotentialItemUseWin>();
            }
            else
            {
                SysNotifyMgr.Instance.ShowTip("SPSuccessHint");
                //DesignDebug.Log("成功率已经够高了,不需要再增加概率了!");
            }
        }
 
        private void RemovePotentialBook()
        {
            model.selectedPotentialBook = 0;
        }
 
        private void DisplayPotentialBook(int _potentialBookId)
        {
            m_PotentialBook.gameObject.SetActive(_potentialBookId != 0);
            m_PotentialCount.gameObject.SetActive(_potentialBookId != 0);
            m_RemoveBook.gameObject.SetActive(_potentialBookId != 0);
            m_AddBookSign.gameObject.SetActive(_potentialBookId == 0);
            if (_potentialBookId != 0)
            {
                m_PotentialBook.showCount = false;
                m_PotentialBook.SetItem(_potentialBookId, 1);
 
                var levelUpConfig = GetPotentialLevelUpConfig();
                bool satisfy = levelUpConfig.own >= levelUpConfig.need;
                m_PotentialCount.text = StringUtility.Contact(UIHelper.GetTextColorByItemColor(satisfy ?
                    TextColType.LightYellow : TextColType.Red, levelUpConfig.own.ToString()), "/", levelUpConfig.need);
            }
 
            DisplaySuccessRatio();
            DisplayAddBookRedpoint();
        }
 
        private void RefreshItemCountAct(PackType packType, int arg2, int _id)
        {
            var config = Config.Instance.Get<ItemConfig>(_id);
            if (packType == PackType.rptItem && config != null && config.Type == 6)
            {
                var levelUpConfig = GetPotentialLevelUpConfig();
                if (_id == model.selectedPotentialBook)
                {
                    DisplayPotentialBook(model.selectedPotentialBook);
                }
                //if (levelUpConfig.own < levelUpConfig.need)
                //{
                //    model.selectedPotentialBook = 0;
                //}
            }
        }
 
        private void UpgradeLevel()
        {
            if (!m_TreasureAnimation.stepComplete)
            {
                return;
            }
            var error = 0;
            if (!TestPotentialLevelUp(out error))
            {
                var skillConfig = Config.Instance.Get<SkillConfig>(selectedPotential);
                switch (error)
                {
                    case 1:
                        MessageWin.Inst.ShowFixedTip(Language.Get("Hallows_NeedLv", skillConfig.LearnLVReq));
                        break;
                    case 2:
                        if (skillConfig.LearnSkillReq > 0)
                        {
                            var preSkillConfig = Config.Instance.Get<SkillConfig>(skillConfig.LearnSkillReq);
                            MessageWin.Inst.ShowFixedTip(Language.Get("Hallows_NeedSkillLV", preSkillConfig.SkillName, skillConfig.LearnSkillLV));
                        }
                        break;
                    case 3:
                        ModelCenter.Instance.GetModel<GetItemPathModel>().SetChinItemModel(148);
                        //MessageWin.Inst.ShowFixedTip(Language.Get("Hallows_SpUnEnough"));
                        break;
                    case 4:
                        SysNotifyMgr.Instance.ShowTip("TreasureUnsealed");
                        break;
                    case 6:
                        if (model.selectedPotentialBook != 0)
                        {
                            ModelCenter.Instance.GetModel<GetItemPathModel>().SetChinItemModel(model.selectedPotentialBook);
                        }
                        else
                        {
                            SysNotifyMgr.Instance.ShowTip("LevelUpZeroRate");
                        }
                        break;
                }
 
                return;
            }
 
            var successRequirement = GeneralConfig.Instance.potentialUpSuccessRecommend;
            var levelUpConfig = GetPotentialLevelUpConfig();
 
            DisplaySuccessRatio();
            if (levelUpConfig.rate * 0.0001f >= successRequirement)
            {
                model.RequestPotentialUpgrade(m_Treasure.id, selectedPotential, levelUpConfig.materilaIndex);
            }
            else
            {
                if (DayRemind.Instance.GetDayRemind(DayRemind.POTENTIAL_NO_NOTIFY))
                {
                    model.RequestPotentialUpgrade(m_Treasure.id, selectedPotential, levelUpConfig.materilaIndex);
                    return;
                }
                ConfirmCancel.ToggleConfirmCancel(
                     Language.Get("Mail101"),
                     Language.Get("Hallows_SuccessTooLow"),
                     Language.Get("TodayNoNotify"),
                    (bool _ok, bool _toggle) =>
                    {
                        if (_ok)
                        {
                            model.RequestPotentialUpgrade(m_Treasure.id, selectedPotential, levelUpConfig.materilaIndex);
                        }
                        if (_toggle)
                        {
                            DayRemind.Instance.SetDayRemind(DayRemind.POTENTIAL_NO_NOTIFY, true);
                        }
                    });
            }
 
        }
 
        private PotentialLevelUpConfig GetPotentialLevelUpConfig()
        {
            var potential = m_Treasure.GetPotential(selectedPotential);
            var levelUpType = model.GetSkillLevelUpType(potential.id);
            var levelupId = TreasureModel.GetSkillLevelUpId(levelUpType, potential.level + 1);
            var config = Config.Instance.Get<TreasureSkillConfig>(levelupId);
            if (config == null)
            {
                return new PotentialLevelUpConfig(0, 0, 0, 0);
            }
            if (model.selectedPotentialBook == 0)
            {
                return new PotentialLevelUpConfig(config.InitialRate, 0, 0, 0);
            }
            else
            {
                var index = 0;
                for (int i = 0; i < config.Meterial2ID.Length; i++)
                {
                    if (config.Meterial2ID[i] == model.selectedPotentialBook)
                    {
                        index = i;
                        break;
                    }
                }
 
                var own = playerPack.GetItemCountByID(PackType.rptItem, model.selectedPotentialBook);
                var need = config.MeterialNum2[index];
                var ratio = own >= need ? config.Rate[index] : config.InitialRate;
 
                return new PotentialLevelUpConfig(ratio, index + 1, own, need);
            }
        }
 
        private bool ContainsPotentialBook(int potentialBook)
        {
            if (potentialBook == 0)
            {
                return false;
            }
            var potential = m_Treasure.GetPotential(selectedPotential);
            var levelUpType = model.GetSkillLevelUpType(potential.id);
            var levelupId = TreasureModel.GetSkillLevelUpId(levelUpType, potential.level + 1);
            var config = Config.Instance.Get<TreasureSkillConfig>(levelupId);
            if (config == null)
            {
                return false;
            }
            for (int i = 0; i < config.Meterial2ID.Length; i++)
            {
                if (config.Meterial2ID[i] == potentialBook)
                {
                    return true;
                }
            }
            return false;
        }
 
        private int GetNextPotential(int _potentialId)
        {
            for (int i = 0; i < m_Treasure.potentials.Count; i++)
            {
                var potential = m_Treasure.potentials[i];
                if (potential.id == _potentialId)
                {
                    continue;
                }
                var skillConfig = Config.Instance.Get<SkillConfig>(potential.id);
                if (skillConfig.LearnSkillReq == _potentialId)
                {
                    return potential.id;
                }
            }
            return 0;
        }
 
        private void PotentialLevelUpdate(int _potentialId, int arg2)
        {
            if (_potentialId == model.selectedPotential)
            {
                DisplayPotentialEffect();
            }
            var potential = m_Treasure.GetPotential(_potentialId);
            if (potential != null && model.serverInited)
            {
                PotentialLevelUpAnimation(_potentialId, potential.level);
                var nextPotential = GetNextPotential(potential.id);
                if (nextPotential != 0)
                {
                    var config = Config.Instance.Get<SkillConfig>(nextPotential);
                    if (potential.level == config.LearnSkillLV && potentialBriefInfos != null)
                    {
                        for (int i = 0; i < potentialBriefInfos.Length; i++)
                        {
                            if (potentialBriefInfos[i].potential.id == nextPotential)
                            {
                                var current = Config.Instance.Get<SkillConfig>(potential.id + potential.level - 1);
                                var before = Config.Instance.Get<SkillConfig>(potential.id + potential.level - 2);
                                ModifyPowerUp(m_Treasure.id, i, current.FightPower - before.FightPower);
                            }
                        }
                    }
                }
            }
 
            var levelUpConfig = GetPotentialLevelUpConfig();
            if (!ContainsPotentialBook(model.selectedPotentialBook))
            {
                AutoSelectPotentialBook();
                //model.selectedPotentialBook = 0;
            }
 
            var curconfig = Config.Instance.Get<SkillConfig>(potential.id);
 
            var level = potential.level;
            var isMax = level >= curconfig.SkillMaxLV;
            m_ContainerUpgrade.gameObject.SetActive(!isMax && FuncOpen.Instance.IsFuncOpen(82));
 
        }
 
        private void OnPotentialLevelUp(int _treasureId, int _potential, bool _ok)
        {
            if (m_Treasure.id != _treasureId)
            {
                return;
            }
 
            if (selectedPotential != _potential)
            {
                return;
            }
 
            if (!_ok)
            {
                m_FailureEffect.Play();
            }
 
            if (_ok)
            {
                DisplayPotentialEffect();
                var potential = m_Treasure.GetPotential(selectedPotential);
                var config = Config.Instance.Get<SkillConfig>(potential.id);
 
                var level = potential.level;
                var isMax = level >= config.SkillMaxLV;
                m_PotentialMaxLevelTip.gameObject.SetActive(isMax);
                m_ContainerUpgrade.gameObject.SetActive(!isMax && FuncOpen.Instance.IsFuncOpen(82));
                m_ContainerRequirement.gameObject.SetActive(!isMax);
 
                if (!isMax)
                {
                    DisplayUpgradeCost();
                    DisplaySuccessRatio();
                    DisplayGetSkill(true);
                    DisplayPotentialBook(model.selectedPotentialBook);
                }
            }
            else
            {
                DisplayPotentialBook(model.selectedPotentialBook);
                var levelUpConfig = GetPotentialLevelUpConfig();
                m_PotentialCount.text = StringUtility.Contact(levelUpConfig.own, "/", levelUpConfig.need);
            }
        }
 
        private void PotentialLevelUpAnimation(int id, int level)
        {
            for (int i = 0; i < potentialBriefInfos.Length; i++)
            {
                if (potentialBriefInfos[i].potential == null)
                {
                    continue;
                }
                if (potentialBriefInfos[i].potential.id == id)
                {
                    m_TreasureAnimation.DisplayPotentialLevelUp(i, level);
                    break;
                }
            }
        }
 
        private void OnTreasurePotentialSPChange(PlayerDataRefresh refreshType)
        {
            switch (refreshType)
            {
                case PlayerDataRefresh.ExAttr7:
                case PlayerDataRefresh.ExAttr8:
                    var spOwn = PlayerDatas.Instance.baseData.treasurePotentialSp;
                    m_SPOwn.text = UIHelper.ReplaceLargeNum(spOwn);
                    m_SPNeed.text = StringUtility.Contact("/", UIHelper.ReplaceLargeNum(spNeed));
                    m_SPOwn.color = spOwn >= spNeed ? UIHelper.GetUIColor(TextColType.DarkGreen) : UIHelper.GetUIColor(TextColType.Red);
                    break;
            }
        }
 
        private bool TestPotentialLevelUp()
        {
            var error = 0;
            return TestPotentialLevelUp(out error);
        }
 
        private bool TestPotentialLevelUp(out int _error)
        {
            //1.人物等级要求不足;2.前置技能等级不足;3.sp不足;4.法宝未获得;5.已经最大等级;6.概率为0
            _error = 0;
            if (m_Treasure.state != TreasureState.Collected)
            {
                _error = 4;
                return false;
            }
 
            var skillConfig = Config.Instance.Get<SkillConfig>(selectedPotential);
            if (PlayerDatas.Instance.baseData.LV < skillConfig.LearnLVReq)
            {
                _error = 1;
                return false;
            }
 
            if (skillConfig.LearnSkillReq > 0)
            {
                var preSkillConfig = Config.Instance.Get<SkillConfig>(selectedPotential);
                var preSkillLevelRequirement = skillConfig.LearnSkillLV;
                var preSkill = PlayerDatas.Instance.skill.GetSkillBySkillTypeID(skillConfig.LearnSkillReq);
                var preSkillLevel = preSkill == null ? 0 : preSkill.level;
 
                if (preSkillLevel < preSkillLevelRequirement)
                {
                    _error = 2;
                    return false;
                }
            }
 
            if (PlayerDatas.Instance.baseData.treasurePotentialSp < spNeed)
            {
                _error = 3;
                return false;
            }
 
            if (m_Treasure.GetPotential(selectedPotential).level >= skillConfig.SkillMaxLV)
            {
                _error = 5;
                return false;
            }
 
            var levelUpConfig = GetPotentialLevelUpConfig();
            if (levelUpConfig.rate == 0)
            {
                _error = 6;
                return false;
            }
 
            _error = 0;
            return true;
        }
 
        private void OnStageSkillBtn()
        {
            DisplayTotalPotentialEffect();
        }
 
        private void Awake()
        {
            m_ItemBtn.AddListener(OnSpNeedItem);
            m_Upgrade.AddListener(UpgradeLevel);
            m_RemoveBook.AddListener(RemovePotentialBook);
            m_StageSkillBtn.AddListener(OnStageSkillBtn);
        }
 
        private void CheckAchievementGuide()
        {
            if (AchievementGoto.guideAchievementId != 0)
            {
                var config = Config.Instance.Get<SuccessConfig>(AchievementGoto.guideAchievementId);
                var condition = config.Type == 91 && config.Condition[0] == model.selectedPotential;
 
                if (condition)
                {
                    var guideEffect = AchievementGuideEffectPool.Require(1);
                    guideEffect.transform.SetParentEx(m_Upgrade.transform, Vector3.zero, Vector3.zero, Vector3.one);
                }
            }
        }
 
#if UNITY_EDITOR
        [ContextMenu("连线")]
        public void PreviewSfx()
        {
        }
#endif
 
        struct PotentialLevelUpConfig
        {
            public int materilaIndex;
            public int rate;
            public int need;
            public int own;
 
            public PotentialLevelUpConfig(int _rate, int _materilaIndex, int _own, int _need)
            {
                this.rate = _rate;
                this.materilaIndex = _materilaIndex;
                this.need = _need;
                this.own = _own;
            }
        }
        [Serializable]
        public class PotentialInfo
        {
            [SerializeField] Transform m_Container;
            [SerializeField] Text m_Name;
            [SerializeField] Text m_Effect;
            [SerializeField] Text m_Level;
            [SerializeField] Text m_GetSkillName;
            [SerializeField] Text m_GetSkillEffect;
            [SerializeField] Text m_GetSkillCondition;
 
            public void Display(TreasurePotential potential, int treasureId)
            {
                var model = ModelCenter.Instance.GetModel<TreasureModel>();
 
                var level = potential.level;
                var potentialConifg = Config.Instance.Get<SkillConfig>(potential.id);
 
                int[] _getskillArray;
                m_GetSkillName.gameObject.SetActive(false);
                m_GetSkillEffect.gameObject.SetActive(false);
                m_GetSkillCondition.gameObject.SetActive(false);
                if (model.TryGetPotentialGetSkill(potentialConifg.SkillTypeID, out _getskillArray))
                {
                    var _getSkillCfg = Config.Instance.Get<SkillConfig>(_getskillArray[1]);
                    m_GetSkillName.text = _getSkillCfg.SkillName;
                    m_GetSkillEffect.text = _getSkillCfg.Description;
                    m_GetSkillName.gameObject.SetActive(true);
                    if (potential.level < _getskillArray[0])
                    {
                        m_GetSkillCondition.gameObject.SetActive(true);
                        m_GetSkillCondition.text = Language.Get("Hallows_NeedSkillLV", potentialConifg.SkillName, _getskillArray[0]);
                        m_GetSkillCondition.color = UIHelper.GetUIColor(TextColType.Red);
                    }
                    else
                    {
                        m_GetSkillEffect.gameObject.SetActive(true);
                    }
                }
 
                m_Name.text = potentialConifg.SkillName;
                if (!model.IsPotentialUnlock(treasureId, potential.id))
                {
                    var skillConfig = Config.Instance.Get<SkillConfig>(potential.id);
                    var requirement = string.Empty;
                    if (skillConfig.LearnSkillReq > 0 && skillConfig.LearnSkillLV > 0)
                    {
                        var preskillConfig = Config.Instance.Get<SkillConfig>(skillConfig.LearnSkillReq);
                        requirement = Language.Get("Hallows_NeedSkillLV", preskillConfig.SkillName, skillConfig.LearnSkillLV);
                    }
                    else
                    {
                        requirement = Language.Get("Hallows_NeedLv", potentialConifg.LearnLVReq);
                    }
 
                    m_Level.text = requirement;
                    m_Level.color = UIHelper.GetUIColor(TextColType.Red);
                    m_Effect.gameObject.SetActive(false);
                }
                else
                {
                    m_Level.text = StringUtility.Contact(level, Language.Get("Z1041"));
                    m_Level.color = UIHelper.s_LightYellow;
                    var currentConfig = Config.Instance.Get<SkillConfig>(potential.id + level - 1);
                    if (currentConfig == null)
                    {
                        m_Effect.gameObject.SetActive(false);
                        m_Effect.text = string.Empty;
                    }
                    else
                    {
                        m_Effect.gameObject.SetActive(true);
                        m_Effect.text = currentConfig.Description;
                    }
                }
            }
 
            public void SetActive(bool _active)
            {
                m_Container.gameObject.SetActive(_active);
            }
        }
 
    }
 
}