少年修仙传客户端代码仓库
hch
2025-03-03 28785d6ddf9c08e49527ede9405c7b6c93c6ed32
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
 
namespace vnxbqy.UI
{
    
    public class EquipTrainModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize
    {
        public readonly LogicInt selectedLevel = new LogicInt();
        public readonly LogicInt selectedPlace = new LogicInt();
        public readonly LogicInt equipTrainLevel = new LogicInt();
        public readonly LogicInt equipTrainMaxLevel = new LogicInt();
        public readonly LogicInt3 material = new LogicInt3();
        public readonly LogicInt inevitableMaterialCount = new LogicInt();
        public readonly LogicEnum<TrainOperateType> operateType = new LogicEnum<TrainOperateType>(TrainOperateType.None);
        public readonly LogicList<EquipTrainCandidate> candidatePlaces = new LogicList<EquipTrainCandidate>();
        public readonly LogicList<EquipTrainPropertyBar> propertyBars = new LogicList<EquipTrainPropertyBar>();
        public readonly LogicBool trainLimit = new LogicBool();
        public readonly LogicInt trainEffect = new LogicInt();
 
        static Dictionary<int, int> trainTypes = new Dictionary<int, int>();
        Dictionary<int, EquipTrainSet> equipTrains = new Dictionary<int, EquipTrainSet>();
 
        Redpoint redpoint = new Redpoint(106, 910000);
        bool redpointDirty = false;
        LogicUpdate logicUpdate = new LogicUpdate(1);
 
        EquipStarModel starModel { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
 
        //自动洗炼至下一级(没有保存概念,自动洗练手动升级)
        public bool autoTrain = false; 
 
        public int limitLevel;
 
        public override void Init()
        {
            ParseConfig();
 
            var levels = equipModel.GetAllEquipSets();
            foreach (var level in levels)
            {
                if (level < limitLevel) continue;
                equipTrains[level] = new EquipTrainSet(level);
            }
 
            logicUpdate.Start(OnUpdate);
 
            packModel.refreshItemCountEvent += OnItemCountRefresh;
            autoTrain = false;
        }
 
        public override void UnInit()
        {
            packModel.refreshItemCountEvent -= OnItemCountRefresh;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            foreach (var train in equipTrains.Values)
            {
                train.Reset();
            }
        }
 
        public void OnAfterPlayerDataInitialize()
        {
            redpointDirty = true;
        }
 
        public void ResetOperateParams()
        {
            selectedLevel.value = 0;
            selectedPlace.value = 0;
            equipTrainLevel.value = 0;
            equipTrainMaxLevel.value = 0;
            material.value = Int3.zero;
            inevitableMaterialCount.value = 0;
            trainEffect.value = 0;
            operateType.value = TrainOperateType.None;
            candidatePlaces.Clear();
            propertyBars.Clear();
        }
 
        public void UpdateEquipTrainInfo(HA3BB_tagMCEquipPartXLAttrInfo info)
        {
            foreach (var item in info.InfoList)
            {
                var clientEquipPlace = EquipSet.ServerPlaceToClientPlace(item.EquipPlace);
                var trainLevel = item.XLAttrLV;
                if (equipTrains.ContainsKey(clientEquipPlace.x))
                {
                    var equipTrain = equipTrains[clientEquipPlace.x];
                    var unSavedProperties = Int3.zero;
                    var trainedProperties = Int3.zero;
                    for (int i = 0; i < item.XLAttrList.Length; i++)
                    {
                        var property = item.XLAttrList[i];
                        trainedProperties[i] = (int)property.XLAttrValue;
                        unSavedProperties[i] = (int)(property.XLAttrChange > 0 ? property.XLAttrChange - property.XLAttrValue : 0);
                    }
 
                    equipTrain.UpdateEquipTrainLevel(clientEquipPlace.y, trainLevel);
                    equipTrain.UpdateTrainedProperties(clientEquipPlace.y, trainedProperties);
                    equipTrain.UpdateUnSavedProperties(clientEquipPlace.y, unSavedProperties);
 
                    if (clientEquipPlace.x == selectedLevel.value && clientEquipPlace.y == selectedPlace.value)
                    {
                        equipTrainLevel.value = trainLevel;
                        for (int i = 0; i < propertyBars.Count; i++)
                        {
                            var bar = propertyBars[i];
                            bar.deltaValue.value = unSavedProperties[i];
                            bar.propertyValue.value = trainedProperties[i];
                        }
                    }
                }
            }
 
            if (selectedLevel.value > 0)
            {
                var equipPosition = new Int2(selectedLevel.value, selectedPlace.value);
                var trainState = GetEquipPlaceTrainState(equipPosition);
                equipTrainLevel.value = GetTrainLevel(equipPosition);
                equipTrainMaxLevel.value = trainState == TrainState.Empty ? -1 : GetMaxTrainLevel(equipPosition);
                material.value = GetTrainMaterial(equipPosition);
 
                operateType.value = CalculateTrainOperateType(equipPosition);
                InitTrainableProperties(equipPosition, operateType.value);
                UpdateTrainLimitState(equipPosition);
            }
 
            if (candidatePlaces.Count > 0)
            {
                for (int i = 0; i < candidatePlaces.Count; i++)
                {
                    candidatePlaces[i].trainLevel.value = GetTrainLevel(candidatePlaces[i].equipPosition);
                }
            }
 
            redpointDirty = true;
        }
 
        
        public void Train(Int2 equipPosition, bool[] inevitables)
        {
            var maxLevel = GetMaxTrainLevel(equipPosition);
            if (maxLevel < 0)
            {
                SysNotifyMgr.Instance.ShowTip("WashStarRequirement");
                return;
            }
 
            var material = GetTrainMaterial(equipPosition);
            if (material.z > material.y)
            {
 
                SysNotifyMgr.Instance.ShowTip("WashStone1");
                return;
            }
 
            LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(3, material.x, material.z, 1, 0);
            var code = 0;
            var inevitableCount = 0;
            for (int i = 0; i < inevitables.Length; i++)
            {
                inevitableCount += inevitables[i] ? 1 : 0;
                code += inevitables[i] ? MathUtility.Power(2, i) : 0;
            }
 
            Action processTrain = () =>
            {
                trainEffect.dirty = true;
                trainEffect.value = code > 0 ? 2 : 1;
 
                var equipWash = new CA325_tagCMEquipXLAttrChange();
                equipWash.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
                equipWash.CheckUseGoldAttr = (byte)code;
                GameNetSystem.Instance.SendInfo(equipWash);
                autoTrain = true;
 
            };
 
            if (inevitableCount == 0)
            {
                processTrain();
                return;
            }
 
            var trainLevel = GetTrainLevel(equipPosition);
            var trainType = GetTrainType(equipPosition.y);
            var config = EquipWashConfig.Get(trainType, trainLevel);
 
            var inevitableNeed = config != null ? config.mustCosts[inevitableCount - 1] : 0;
            var inevitableOwn = packModel.GetItemCountByID(PackType.Item, GeneralDefine.equipTrainMustItemId);
 
            if (inevitableOwn >= inevitableNeed)
            {
                processTrain();
                return;
            }
 
            var diamondNeed = (inevitableNeed - inevitableOwn) * GetInevitableMaterialPrice();
            var diamondOwn = PlayerDatas.Instance.baseData.diamond;
            LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(52, 1, diamondNeed, 2, 0);
 
            if (diamondNeed > diamondOwn)
            {
                WindowCenter.Instance.Open<RechargeTipWin>();
                return;
            }
            if (DayRemind.Instance.GetDayRemind(DayRemind.EQUIPTRAIN_COSTDIAMOND))
            {
                processTrain();
                return;
            }
            autoTrain = false;
            ConfirmCancel.ToggleConfirmCancel(Language.Get("Mail101"),
                Language.Get("EquipWash103", inevitableNeed - inevitableOwn, diamondNeed),
                Language.Get("TodayNoNotify"), (bool ok, bool isToggle) =>
                {
 
                    if (ok)
                    {
                        processTrain();
                    }
                    if (isToggle)
                    {
                        DayRemind.Instance.SetDayRemind(DayRemind.EQUIPTRAIN_COSTDIAMOND, true);
                    }
                    else
                    {
                        autoTrain = false;
                    }
                });
 
        }
 
        public void Save(Int2 equipPosition)
        {
            var result = new CA326_tagCMEquipXLAttrChangeOK();
            result.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
            result.IsSave = 1;
            GameNetSystem.Instance.SendInfo(result);
        }
 
        public void GiveUp(Int2 equipPosition)
        {
            var result = new CA326_tagCMEquipXLAttrChangeOK();
            result.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
            result.IsSave = 0;
            GameNetSystem.Instance.SendInfo(result);
        }
 
        public void UpdateLevel(Int2 equipPosition)
        {
            var result = new CA326_tagCMEquipXLAttrChangeOK();
            result.EquipPlace = (byte)EquipSet.ClientPlaceToServerPlace(equipPosition);
            result.IsSave = 2;
            GameNetSystem.Instance.SendInfo(result);
        }
 
        public void SelectLevel(int level)
        {
            selectedLevel.value = level;
            selectedLevel.dirty = true;
            candidatePlaces.Clear();
 
            if (level > 0)
            {
                for (var i = 1; i <= 12; i++)
                {
                    var place = i;
                    var equipPosition = new Int2(level, place);
 
                    var trainCandidate = new EquipTrainCandidate(equipPosition);
                    trainCandidate.trainLevel.value = GetTrainLevel(equipPosition);
                    trainCandidate.equipGuid.value = equipModel.GetEquip(equipPosition);
                    trainCandidate.starLevel.value = starModel.GetEquipStarLevel(equipPosition);
                    candidatePlaces.Add(trainCandidate);
                }
 
                candidatePlaces.Sort(EquipTrainCandidateCompare);
                SelectPlace(candidatePlaces[0].equipPosition);
            }
            else
            {
                SelectPlace(Int2.zero);
            }
        }
 
        public void SelectPlace(Int2 equipPosition)
        {
            selectedPlace.value = equipPosition.y;
            selectedPlace.dirty = true;
 
            if (equipPosition.x > 0 && equipPosition.y >= 1 && equipPosition.y <= 12)
            {
                for (int i = 0; i < candidatePlaces.Count; i++)
                {
                    var candidate = candidatePlaces[i];
                    candidate.selected.value = candidate.equipPosition == equipPosition;
                }
 
                var trainState = GetEquipPlaceTrainState(equipPosition);
                equipTrainLevel.value = GetTrainLevel(equipPosition);
                equipTrainMaxLevel.value = trainState == TrainState.Empty ? -1 : GetMaxTrainLevel(equipPosition);
                equipTrainMaxLevel.dirty = true;
                material.value = GetTrainMaterial(equipPosition);
 
                operateType.value = CalculateTrainOperateType(equipPosition);
                InitTrainableProperties(equipPosition, operateType.value);
                UpdateTrainLimitState(equipPosition);
            }
        }
 
        public void SetInevitable(int index, bool invevitable)
        {
            var equipPosition = new Int2(selectedLevel.value, selectedPlace.value);
            var state = GetEquipPlaceTrainState(equipPosition);
 
            var unsavedProperties = GetUnSavedProperties(equipPosition);
            if (unsavedProperties != Int3.zero)
            {
                SysNotifyMgr.Instance.ShowTip("WashUnSavedTip");
                return;
            }
 
            var maxLevel = GetMaxTrainLevel(equipPosition);
            if (maxLevel < 0)
            {
                SysNotifyMgr.Instance.ShowTip("WashStarRequirement");
                return;
            }
 
            if (state == TrainState.Empty)
            {
                SysNotifyMgr.Instance.ShowTip("Wash_NoEquip1");
                return;
            }
 
            if (state == TrainState.StarLimit)
            {
                SysNotifyMgr.Instance.ShowTip("WashStarRequirement");
                return;
            }
 
            if (invevitable)
            {
                var properties = GetTrainedProperties(equipPosition);
                var type = GetTrainType(selectedPlace.value);
                var trainLevel = GetTrainLevel(equipPosition);
                var data = EquipWashConfig.Get(type, trainLevel);
                var isPerfect = false;
                switch (index)
                {
                    case 0:
                        isPerfect = properties[index] >= data.config.attMax1;
                        break;
                    case 1:
                        isPerfect = properties[index] >= data.config.attMax2;
                        break;
                    case 2:
                        isPerfect = properties[index] >= data.config.attMax3;
                        break;
                }
 
                if (isPerfect)
                {
                    SysNotifyMgr.Instance.ShowTip("WashOperateTip1");
                    return;
                }
            }
 
            if (propertyBars.Count > index)
            {
                propertyBars[index].inevitable.value = invevitable;
            }
 
            inevitableMaterialCount.value = CalculateInevitableMaterialCount(equipPosition);
            inevitableMaterialCount.dirty = true; //相同值不改变的情况下无法刷新 会是锁定状态
        }
 
        public Int2 GetRecommendEquipPosition()
        {
            foreach (var trainSet in equipTrains.Values)
            {
                var level = trainSet.level;
                for (var i = 1; i <= 12; i++)
                {
                    var isRedpoint = trainSet.GetRedpointState(i) != RedPointState.None;
                    if (isRedpoint)
                    {
                        return new Int2(level, i);
                    }
                }
            }
 
            return new Int2(limitLevel, 1);
        }
 
        public int GetTrainLevel(Int2 equipPosition)
        {
            var equip = equipModel.GetEquip(equipPosition);
            if (string.IsNullOrEmpty(equip))
            {
                return -1;
            }
 
            if (!equipTrains.ContainsKey(equipPosition.x))
            {
                return -1;
            }
 
            var maxLevel = GetMaxTrainLevel(equipPosition);
            return Mathf.Min(maxLevel, equipTrains[equipPosition.x].GetTrainLevel(equipPosition.y));
        }
 
        public int GetTrainLevelEx(Int2 equipPosition)
        {
            var equip = equipModel.GetEquip(equipPosition);
            if (string.IsNullOrEmpty(equip))
            {
                return 0;
            }
 
            if (!equipTrains.ContainsKey(equipPosition.x))
            {
                return 0;
            }
 
            return equipTrains[equipPosition.x].GetTrainLevel(equipPosition.y);
        }
 
 
        public int GetMaterialNeed(Int2 equipPosition)
        {
            var level = GetTrainLevel(equipPosition);
            var type = GetTrainType(equipPosition.y);
            var data = EquipWashConfig.Get(type, level);
 
            return data.config.costCount;
        }
 
        public int GetMaxTrainLevel(int place)
        {
            var type = GetTrainType(place);
            return WashLevelMaxConfig.GetMaxLevel(type);
        }
 
        public int GetMaxTrainLevel(Int2 equipPosition)
        {
            var equip = equipModel.GetEquip(equipPosition);
            if (string.IsNullOrEmpty(equip))
            {
                return -1;
            }
 
            var star = starModel.GetEquipStarLevel(equipPosition);
            var type = GetTrainType(equipPosition.y);
            var config = WashLevelMaxConfig.Get(type, star);
            if (config == null)
            {
                return -1;
            }
            else
            {
                return config.levelMax;
            }
        }
 
        public TrainState GetEquipPlaceTrainState(Int2 equipPosition)
        {
            var equipGuid = equipModel.GetEquip(equipPosition);
            if (string.IsNullOrEmpty(equipGuid))
            {
                return TrainState.Empty;
            }
 
            var equip = packModel.GetItemByGuid(equipGuid);
            if (equip == null)
            {
                return TrainState.Empty;
            }
 
            var type = GetTrainType(equipPosition.y);
            var currentTrainLevel = GetTrainLevel(equipPosition);
            var absoluteMax = GetMaxTrainLevel(equipPosition.y);
            var data = EquipWashConfig.Get(type, Mathf.Clamp(currentTrainLevel, 0, absoluteMax));
            if (data == null)
            {
                return TrainState.Empty;
            }
 
            var relativeMax = GetMaxTrainLevel(new Int2(equip.config.LV, equip.config.EquipPlace));
            if (relativeMax == -1)
            {
                return TrainState.StarLimit;
            }
 
            var properties = GetTrainedProperties(equipPosition);
            var isFull = properties.x >= data.config.attMax1
                && properties.y >= data.config.attMax2
                && properties.z >= data.config.attMax3;
            if (isFull)
            {
                if (currentTrainLevel >= absoluteMax)
                {
                    return TrainState.MaxLevel;
                }
 
                if (currentTrainLevel >= relativeMax)
                {
                    return TrainState.StarLimit;
                }
            }
 
            return TrainState.Allowable;
        }
 
        public Int3 GetUnSavedProperties(Int2 equipPosition)
        {
            return equipTrains.ContainsKey(equipPosition.x) ? equipTrains[equipPosition.x].GetUnSavedProperties(equipPosition.y) : Int3.zero;
        }
 
        public Int3 GetTrainedProperties(Int2 equipPosition)
        {
            var equip = equipModel.GetEquip(equipPosition);
            if (string.IsNullOrEmpty(equip))
            {
                return Int3.zero;
            }
 
            if (!equipTrains.ContainsKey(equipPosition.x))
            {
                return Int3.zero;
            }
 
            var maxLevel = GetMaxTrainLevel(equipPosition);
            var trainedProperties = equipTrains[equipPosition.x].GetTrainedProperties(equipPosition.y);
            var type = GetTrainType(equipPosition.y);
            var data = EquipWashConfig.Get(type, maxLevel);
 
            var property1 = 0;
            var property2 = 0;
            var property3 = 0;
            if (data != null)
            {
                property1 = Mathf.Min(trainedProperties.x, data.config.attMax1);
                property2 = Mathf.Min(trainedProperties.y, data.config.attMax2);
                property3 = Mathf.Min(trainedProperties.z, data.config.attMax3);
            }
 
            return new Int3(property1, property2, property3);
        }
 
        private void InitTrainableProperties(Int2 equipPosition, TrainOperateType operateType)
        {
            //此段代码特殊处理,因为 propertyBars.Clear();
            bool ison1 = false;
            bool ison2 = false;
            bool ison3 = false;
            if (propertyBars.Count == 3)
            {
                ison1 = propertyBars[0].inevitable.value;
                ison2 = propertyBars[1].inevitable.value;
                ison3 = propertyBars[2].inevitable.value;
            }
            ///=============================
            
            propertyBars.Clear();
            var trainState = GetEquipPlaceTrainState(equipPosition);
            var absoluteMax = GetMaxTrainLevel(equipPosition.y);
 
            var unSavedProperties = GetUnSavedProperties(equipPosition);
            var trainedProperties = GetTrainedProperties(equipPosition);
            var trainLevel = GetTrainLevel(equipPosition);
            var data = EquipWashConfig.Get(GetTrainType(equipPosition.y), Mathf.Clamp(trainLevel, 0, absoluteMax));
 
            if (data != null)
            {
                var propertyBar = new EquipTrainPropertyBar(data.config.attType1, data.config.attMax1, data.config.attCostMoney1, trainState);
                propertyBar.propertyValue.value = trainedProperties.x;
                propertyBar.deltaValue.value = unSavedProperties.x;
                propertyBar.operateType.value = operateType;
                propertyBar.inevitable.value = ison1;
                propertyBars.Add(propertyBar);
 
                propertyBar = new EquipTrainPropertyBar(data.config.attType2, data.config.attMax2, data.config.attCostMoney2, trainState);
                propertyBar.propertyValue.value = trainedProperties.y;
                propertyBar.deltaValue.value = unSavedProperties.y;
                propertyBar.operateType.value = operateType;
                propertyBar.inevitable.value = ison2;
                propertyBars.Add(propertyBar);
 
                propertyBar = new EquipTrainPropertyBar(data.config.attType3, data.config.attMax3, data.config.attCostMoney3, trainState);
                propertyBar.propertyValue.value = trainedProperties.z;
                propertyBar.deltaValue.value = unSavedProperties.z;
                propertyBar.operateType.value = operateType;
                propertyBar.inevitable.value = ison3;
                propertyBars.Add(propertyBar);
            }
 
            inevitableMaterialCount.value = CalculateInevitableMaterialCount(equipPosition);
            inevitableMaterialCount.dirty = true; //相同值不改变的情况下无法刷新 会是锁定状态
        }
 
        private Int3 GetTrainMaterial(Int2 equipPosition)
        {
            if (GetEquipPlaceTrainState(equipPosition) == TrainState.Allowable)
            {
                var type = GetTrainType(equipPosition.y);
                var level = GetTrainLevel(equipPosition);
                var data = EquipWashConfig.Get(type, level);
                var count = packModel.GetItemCountByID(PackType.Item, data.config.costItem);
                var need = GetMaterialNeed(equipPosition);
                return new Int3(data.config.costItem, count, need);
            }
            else
            {
                return Int3.zero;
            }
        }
 
        public int GetInevitableMaterialPrice()
        {
            var config = StoreConfig.GetStoreCfg(GeneralDefine.equipTrainMustItemId, 1);
            return config != null ? config.MoneyNumber : 0;
        }
 
        private int CalculateInevitableMaterialCount(Int2 equipPosition)
        {
            var count = 0;
            for (int i = 0; i < propertyBars.Count; i++)
            {
                count += propertyBars[i].inevitable.value ? 1 : 0;
            }
 
            if (count > 0)
            {
                var type = GetTrainType(equipPosition.y);
                var trainLevel = GetTrainLevel(equipPosition);
                var config = EquipWashConfig.Get(type, trainLevel);
                if (config == null)
                    return 0;
                return config.mustCosts[count - 1];
            }
            else
            {
                return 0;
            }
        }
 
        private TrainOperateType CalculateTrainOperateType(Int2 equipPosition)
        {
            var trainState = GetEquipPlaceTrainState(equipPosition);
            if (trainState == TrainState.StarLimit || trainState == TrainState.MaxLevel)
            {
                return TrainOperateType.Max;
            }
 
            var properties = GetTrainedProperties(equipPosition);
            var equip = packModel.GetItemByGuid(equipModel.GetEquip(equipPosition));
            if (equip == null)
            {
                return TrainOperateType.None;
            }
 
            var type = GetTrainType(equip.config.EquipPlace);
            var trainLevel = GetTrainLevel(equipPosition);
 
            var data = EquipWashConfig.Get(type, trainLevel);
            if (properties.x >= data.config.attMax1 && properties.y >= data.config.attMax2 && properties.z >= data.config.attMax3)
            {
                return TrainOperateType.LevelUp;
            }
 
            var unSavedProperties = GetUnSavedProperties(equipPosition);
            if (unSavedProperties != Int3.zero)
            {
                return TrainOperateType.Save;
            }
 
            if (trainState == TrainState.Allowable)
            {
                return TrainOperateType.Train;
            }
 
            return TrainOperateType.None;
        }
 
        private void UpdateTrainLimitState(Int2 equipPosition)
        {
            var type = GetTrainType(equipPosition.y);
            var currentLevel = GetTrainLevel(equipPosition);
            var data = EquipWashConfig.Get(type, currentLevel);
            if (data == null)
            {
                trainLimit.value = false;
            }
            else
            {
                var properties = GetTrainedProperties(equipPosition);
                var isFull = properties.x >= data.config.attMax1
                    && properties.y >= data.config.attMax2
                    && properties.z >= data.config.attMax3;
 
                var trainState = GetEquipPlaceTrainState(equipPosition);
                trainLimit.value = isFull && (trainState == TrainState.StarLimit || trainState == TrainState.MaxLevel);
            }
        }
 
        private void OnItemCountRefresh(PackType type, int index, int itemId)
        {
            switch (type)
            {
                case PackType.Item:
                    if (itemId == 5303)
                    {
                        redpointDirty = true;
                    }
                    break;
                case PackType.Equip:
                    var clientEquipPosition = EquipSet.ServerPlaceToClientPlace(index);
                    if (clientEquipPosition.x > 0)
                    {
                        redpointDirty = true;
                    }
                    break;
            }
        }
 
        private void UpdateTrainRedpoint()
        {
            var ownTrainMaterial = packModel.GetItemCountByID(PackType.Item, 5303);
            var targetEquipPosition = Int2.zero;
            if (ownTrainMaterial != 0)
            {
                var minTrainLevel = 999;
                foreach (var trainSet in equipTrains.Values)
                {
                    var level = trainSet.level;
                    for (var i = 1; i <= 12; i++)
                    {
                        var trainState = GetEquipPlaceTrainState(new Int2(level, i));
                        if (trainState != TrainState.Allowable)
                        {
                            continue;
                        }
 
                        var needMaterial = GetMaterialNeed(new Int2(level, i));
                        if (needMaterial > ownTrainMaterial)
                        {
                            continue;
                        }
 
                        var tranLevel = trainSet.GetTrainLevel(i);
                        if (tranLevel < minTrainLevel)
                        {
                            minTrainLevel = tranLevel;
                            targetEquipPosition = new Int2(level, i);
                        }
                    }
                }
            }
 
            foreach (var trainSet in equipTrains.Values)
            {
                var level = trainSet.level;
                for (var i = 1; i <= 12; i++)
                {
                    var isRedpoint = level == targetEquipPosition.x && i == targetEquipPosition.y;
                    trainSet.UpdateRedpoint(i, isRedpoint ? RedPointState.Simple : RedPointState.None);
                }
            }
 
        }
 
        private void OnUpdate()
        {
            if (redpointDirty && FuncOpen.Instance.IsFuncOpen(91))
            {
                redpointDirty = false;
                UpdateTrainRedpoint();
            }
        }
 
        private int EquipTrainCandidateCompare(EquipTrainCandidate x, EquipTrainCandidate y)
        {
            var stateX = GetEquipPlaceTrainState(x.equipPosition);
            var stateY = GetEquipPlaceTrainState(y.equipPosition);
 
            if (stateX == TrainState.Allowable && stateY != TrainState.Allowable)
            {
                return -1;
            }
 
            if (stateX != TrainState.Allowable && stateY == TrainState.Allowable)
            {
                return 1;
            }
 
            if (stateX == TrainState.Allowable && stateY == TrainState.Allowable)
            {
                var compareResult = x.trainLevel.value.CompareTo(y.trainLevel.value);
                if (compareResult == 0)
                {
                    var factorX = x.equipPosition.x * 100 + x.equipPosition.y;
                    var factorY = y.equipPosition.x * 100 + y.equipPosition.y;
                    compareResult = factorX.CompareTo(factorY);
                }
 
                return compareResult;
            }
 
            if (stateX == TrainState.StarLimit && stateY != TrainState.StarLimit)
            {
                return -1;
            }
            else if (stateX != TrainState.StarLimit && stateY == TrainState.StarLimit)
            {
                return 1;
            }
            else if (stateX == TrainState.MaxLevel && stateY != TrainState.MaxLevel)
            {
                return -1;
            }
            else if (stateX != TrainState.MaxLevel && stateY == TrainState.MaxLevel)
            {
                return 1;
            }
            else if (stateX == TrainState.Empty && stateY != TrainState.Empty)
            {
                return -1;
            }
            else if (stateX != TrainState.Empty && stateY == TrainState.Empty)
            {
                return 1;
            }
            else
            {
                return x.equipPosition.y.CompareTo(y.equipPosition.y);
            }
        }
 
        private void ParseConfig()
        {
            var config = FuncConfigConfig.Get("EquipWashGroup");
            trainTypes = ConfigParse.GetDic<int, int>(config.Numerical1);
 
            if (equipModel.EquipLevelFuncID == null)
                equipModel.ParseEquipLevelFuncID();
            limitLevel = equipModel.EquipLevelFuncID[91];
        }
 
        public static int GetTrainType(int place)
        {
            return trainTypes.ContainsKey(place) ? trainTypes[place] : 0;
        }
 
        public enum TrainOperateType
        {
            None = 0,
            Train = 1,
            Forbid = 2,
            Save = 3,
            LevelUp = 4,
            Max = 5,
        }
 
        public enum TrainState
        {
            Empty,
            StarLimit,
            MaxLevel,
            Allowable,
        }
    }
}