少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
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
using System;
using System.Text;
using UnityEngine;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
 
using System.Text.RegularExpressions;
using System.IO;
using Snxxz.UI;
 
/// <summary>
/// UI辅助类
/// </summary>
[XLua.LuaCallCSharp]
public static class UIHelper
{
    #region UI通用
    public static void SetIconWithMoneyType(this Image _image, int moneyType)
    {
        if (_image == null) return;
        string iconKey = StringUtility.Contact("Money_Type_", moneyType);
        _image.SetSprite(iconKey);
    }
 
    /// <summary>
    /// 分离字符串插入空格
    /// </summary>
    public static string GetSuitNameByName(string attrName)
    {
        string suitStr = "";
        for (int i = 0; i < attrName.Length; i++)
        {
            if (i != attrName.Length - 1)
            {
                if (attrName.Length == 2)
                {
                    suitStr = StringUtility.Contact(suitStr, attrName[i], "        ");
                }
                else if (attrName.Length == 3)
                {
                    suitStr = StringUtility.Contact(suitStr, attrName[i], "  ");
                }
                else
                {
                    suitStr = StringUtility.Contact(suitStr, attrName[i]);
                }
            }
            else
            {
                suitStr = StringUtility.Contact(suitStr, attrName[i]);
            }
        }
        return suitStr;
 
    }
 
    public static void SetItemBackGround(this Image _image, int itemColor)
    {
        if (_image == null)
        {
            return;
        }
 
        switch (itemColor)
        {
            case 0:
                _image.SetSprite("Common_Public_ItemNormalBG");
                break;
            case 1:
                _image.SetSprite("Common_Public_ItemNormalBG");
                break;
            case 2:
                _image.SetSprite("Common_Public_ItemBlueBG");
                break;
            case 3:
                _image.SetSprite("Common_Public_ItemPurpleBG");
                break;
            case 5:
                _image.SetSprite("Common_Public_ItemRedBG");
                break;
            case 4:
                _image.SetSprite("Common_Public_ItemOrangeBG");
                break;
            case 6:
                _image.SetSprite("Common_Public_ItemPinkBG");
                break;
        }
    }
    /// <summary>
    /// 剩余时间
    /// </summary>
    /// <param name="startTime">格式 年-月-日 小时:分钟:秒</param>
    /// <param name="ownTime">毫秒</param>
    /// <returns></returns>
    private static Regex TimeRegex = new Regex(@"([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+):([0-9]+)", RegexOptions.Singleline);
    public static int GetSurplusSeconds(string startTime, int seconds)
    {
        string start = GetTime(startTime);
        if (start.Equals(string.Empty))
        {
            return 0;
        }
        DateTime s = Convert.ToDateTime(start);
        DateTime t = s.AddTicks(seconds * TimeSpan.TicksPerSecond);
        DateTime n = TimeUtility.ServerNow;
        TimeSpan span = t - n;
        return Mathf.Max(0, (int)span.TotalSeconds);
    }
 
    public static string GetTime(string startTime)
    {
        if (!TimeRegex.IsMatch(startTime))
        {
            return string.Empty;
        }
        Match match = TimeRegex.Match(startTime);
        int year = int.Parse(match.Groups[1].Value);
        int month = int.Parse(match.Groups[2].Value);
        int day = int.Parse(match.Groups[3].Value);
        int h = int.Parse(match.Groups[4].Value);
        int mi = int.Parse(match.Groups[5].Value);
        int sc = int.Parse(match.Groups[6].Value);
 
        return string.Format("{0}-{1}-{2} {3}:{4}:{5}", year, month, day, h, mi, sc);
 
    }
    /// <summary>
    /// 获取消逝的时间
    /// </summary>
    /// <param name="lastTime"></param>
    /// <returns></returns>
    public static string GetFadeTime(uint lastTime)
    {
        DateTime n = TimeUtility.ServerNow;
        TimeSpan span = n - TimeUtility.GetTime(lastTime);
        if (span.TotalDays > 1) return Math.Floor(span.TotalDays) + Language.Get("L1074");
        else if (span.TotalHours > 1) return Math.Floor(span.TotalHours) + Language.Get("L1072");
        else if (span.TotalMinutes > 1) return Math.Floor(span.TotalMinutes) + Language.Get("L1073");
        else return 1 + Language.Get("L1073");
    }
    /// <summary>
    /// 根据属性获取玩家数据
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public static int GetPropertyValue(PropertyType type)
    {
        switch (type)
        {
            case PropertyType.LV:
                return PlayerDatas.Instance.baseData.LV;
            case PropertyType.POWER:
                return PlayerDatas.Instance.baseData.STR;
            case PropertyType.AGILITY:
                return PlayerDatas.Instance.baseData.PHY;
            case PropertyType.PHYSIQUE:
                return PlayerDatas.Instance.baseData.CON;
            case PropertyType.MENTALITY:
                return PlayerDatas.Instance.baseData.PNE;
            case PropertyType.HP:
                return (int)PlayerDatas.Instance.extersion.MaxHP;
            case PropertyType.ATK:
                return PlayerDatas.Instance.extersion.MAXATK;
            case PropertyType.DEF:
                return PlayerDatas.Instance.extersion.DEF;
            case PropertyType.HIT:
                return PlayerDatas.Instance.extersion.HIT;
            case PropertyType.MISS:
                return PlayerDatas.Instance.extersion.Miss;
            case PropertyType.ATKSPEED:
                return PlayerDatas.Instance.extersion.battleValEx1;
            case PropertyType.CritChance:
                return PlayerDatas.Instance.extersion.SuperHitRate;
            case PropertyType.CritHurt:
                return PlayerDatas.Instance.extersion.SuperHit;
            case PropertyType.CritResis:
                return PlayerDatas.Instance.extersion.SuperHitReduce;
            case PropertyType.HeartHit:
                return PlayerDatas.Instance.extersion.luckHitRate;
            case PropertyType.HeartHurt:
                return PlayerDatas.Instance.extersion.luckHitVal;
            case PropertyType.HeartResis:
                return PlayerDatas.Instance.extersion.LuckyHitRateReduce;
            case PropertyType.SkillHurt:
                return PlayerDatas.Instance.extersion.SkillAtkRate;
            case PropertyType.PVPAddHurt:
                return PlayerDatas.Instance.extersion.DamagePVP;
            case PropertyType.PVPReduceHurt:
                return PlayerDatas.Instance.extersion.damageReduceRate;
            case PropertyType.LifeReply:
                return PlayerDatas.Instance.extersion.HPRestorePer;
            case PropertyType.HurtReflect:
                return PlayerDatas.Instance.extersion.DamageBackRate;
            case PropertyType.MoveSpeed:
                return PlayerDatas.Instance.extersion.SpeedValue;
            case PropertyType.PetAddHurt:
                return PlayerDatas.Instance.extersion.PetDamPer;
            case PropertyType.RealHurt:
                return PlayerDatas.Instance.extersion.realATK;
            case PropertyType.RealResis:
                return PlayerDatas.Instance.extersion.realDEF;
            case PropertyType.DefyDef:
                return PlayerDatas.Instance.extersion.IgnoreDefRate;
            case PropertyType.DefyDefResis:
                return PlayerDatas.Instance.extersion.IgnoreDefRateReduce;
            case PropertyType.DefChance:
                return PlayerDatas.Instance.extersion.DamChanceDef;
            case PropertyType.BloodHurt:
                return PlayerDatas.Instance.extersion.BleedDamage;
            case PropertyType.AktReplyBlood:
                return PlayerDatas.Instance.extersion.BattleValEx2;
            case PropertyType.Stun:
                return PlayerDatas.Instance.extersion.FaintRate;
            case PropertyType.CtrlResis:
                return PlayerDatas.Instance.extersion.FaintDefRate;
            case PropertyType.AddFinalHurt:
                return PlayerDatas.Instance.extersion.FinalHurt;
            case PropertyType.ReduceFinalHurt:
                return PlayerDatas.Instance.extersion.FinalHurtReduce;
            case PropertyType.PVPAddHurtPer:
                return PlayerDatas.Instance.extersion.DamagePerPVP;
            case PropertyType.PVPReduceHurtPer:
                return PlayerDatas.Instance.extersion.DamagePerPVPReduce;
            case PropertyType.DleHitChance:
                return PlayerDatas.Instance.extersion.ComboDamPerRate;
            case PropertyType.DleHurt:
                return PlayerDatas.Instance.extersion.ComboDamPer;
            case PropertyType.ReduceSkillHurtPercent:
                return PlayerDatas.Instance.extersion.skillAtkRateReduce;
            case PropertyType.NpcHurtAddPer:
                return PlayerDatas.Instance.extersion.NpcHurtAddPer;
            case PropertyType.Luck:
                return PlayerDatas.Instance.extersion.luckValue;
            case PropertyType.Mater:
                return PlayerDatas.Instance.baseData.mater;
            case PropertyType.Wood:
                return PlayerDatas.Instance.baseData.wood;
            case PropertyType.Water:
                return PlayerDatas.Instance.baseData.water;
            case PropertyType.Fire:
                return PlayerDatas.Instance.baseData.fire;
            case PropertyType.Earth:
                return PlayerDatas.Instance.baseData.earth;
            case PropertyType.ReduceCrit:
                return PlayerDatas.Instance.baseData.reduceCrit;
            case PropertyType.ReduceHeartHurtPer:
                return PlayerDatas.Instance.baseData.reduceHeartHurt;
            case PropertyType.ReduceFinalHurtPer:
                return PlayerDatas.Instance.baseData.reduceFinalHurt;
            case PropertyType.AtkPercent:
            case PropertyType.CritHurtPercent:
            case PropertyType.DodgePercent:
                return ModelCenter.Instance.GetModel<ReikiRootModel>().GetReikiPropertyValue((int)type);
        }
        return 0;
    }
 
 
    /// <summary>
    /// 换行
    /// </summary>
    /// <param name="val"></param>
    /// <returns></returns>
    private static Regex NewLineRegex = new Regex(@"</r>", RegexOptions.Singleline);
    public static string ReplaceNewLine(string val)
    {
        return val.Replace(@"</r>", "\n");
    }
    /// <summary>
    /// 大数值转化
    /// </summary>
    private static StringBuilder _textBuilder = new StringBuilder();
    public static string ReplaceLargeNum(double num)
    {
        _textBuilder.Length = 0;
        float hm = (float)Math.Round(num / 100000000, 2);
        if (hm >= 100)
        {
            hm = (int)Math.Round(num / 100000000);
            _textBuilder.Append(hm);
            _textBuilder.Append(Language.Get("L1070"));
            return _textBuilder.ToString();
        }
        else if (hm >= 10)
        {
            hm = (float)Math.Round(num / 100000000, 1);
            _textBuilder.Append(hm);
            _textBuilder.Append(Language.Get("L1070"));
            return _textBuilder.ToString();
        }
        if (hm >= 1)
        {
            _textBuilder.Append(hm);
            _textBuilder.Append(Language.Get("L1070"));
            return _textBuilder.ToString();
        }
 
        float tt = (float)Math.Round(num / 10000, 2);
        if (tt >= 100)
        {
            tt = (float)Math.Round(num / 10000);
            _textBuilder.Append(tt);
            _textBuilder.Append(Language.Get("L1071"));
            return _textBuilder.ToString();
        }
        else if (tt >= 10)
        {
            tt = (float)Math.Round(num / 10000, 1);
            _textBuilder.Append(tt);
            _textBuilder.Append(Language.Get("L1071"));
            return _textBuilder.ToString();
        }
        else if (tt >= 1)
        {
            _textBuilder.Append(tt);
            _textBuilder.Append(Language.Get("L1071"));
            return _textBuilder.ToString();
        }
 
        if (_textBuilder.Length == 0)
        {
            tt = (float)Math.Round(num, 2);
            _textBuilder.Append(tt);
        }
        return _textBuilder.ToString();
    }
 
    public static string ReplaceXianYuanCoinsNum(double num)
    {
        StringBuilder sb = new StringBuilder();
        float hm = (float)Math.Round(num / 100000000, 2);
        if (hm >= 100)
        {
            hm = (int)Math.Round(num / 100000000);
            sb.Append(hm);
            sb.Append(Language.Get("L1070"));
            return sb.ToString();
        }
        else if (hm >= 10)
        {
            hm = (float)Math.Round(num / 100000000, 1);
            sb.Append(hm);
            sb.Append(Language.Get("L1070"));
            return sb.ToString();
        }
        else if (hm >= 1)
        {
            sb.Append(hm);
            sb.Append(Language.Get("L1070"));
            return sb.ToString();
        }
 
        float tt = (float)Math.Round(num / 10000, 2);
        if (tt >= 100)
        {
            tt = (float)Math.Round(num / 10000);
            sb.Append(tt);
            sb.Append(Language.Get("L1071"));
            return sb.ToString();
        }
 
        if (sb.Length == 0)
        {
            tt = (float)Math.Round(num, 2);
            sb.Append(tt);
        }
        return sb.ToString();
    }
 
    public static float ReplacePercentage(float num, int isPer, int decimals = 1)
    {
        if (isPer == 1 || isPer == 2)
        {
            return (float)Math.Round(num / 100, decimals);
        }
        else
        {
            return (int)num;
        }
    }
 
    static Regex s_SpecialCharacterRegex = new Regex("[ ()()@!#$%^&*[]|_]");
    static Regex s_AsciiCharacterRegex = new Regex("[\x00-\x2F]|[\x3A-\x40]|[\x5B-\x60]|[\x7B-\x7E]");
    public static bool HasSpecialCharac(string str)
    {
        if (s_SpecialCharacterRegex.IsMatch(str))
        {
            return true;
        }
        if (s_AsciiCharacterRegex.IsMatch(str))
        {
            return true;
        }
        return false;
    }
 
    public static string GetColorNameByItemColor(int itemColor)
    {
        switch (itemColor)
        {
            case 1:
                return Language.Get("Market_Text_42");
            case 2:
                return Language.Get("Market_Text_43");
            case 3:
                return Language.Get("Market_Text_44");
            case 4:
                return Language.Get("Market_Text_45");
            case 5:
                return Language.Get("Market_Text_46");
            case 6:
                return Language.Get("Market_Text_47");
        }
        return "";
    }
 
    #endregion
 
    #region 文字色值
    public static readonly Color s_BrightPinkColor = new Color32(246, 64, 141, 255);
    public static readonly Color s_BrightRedColor = new Color32(255, 3, 3, 255);
    public static readonly Color s_BrightPurpleColor = new Color32(218, 72, 213, 255);
    public static readonly Color s_BrightBlueColor = new Color32(0, 107, 227, 255); //006BE3FF
    public static readonly Color s_BrightOrangeColor = new Color32(255, 103, 1, 255); //FF6701FF
    public static readonly Color s_BrightWhiteColor = new Color32(104, 104, 104, 255); //686868
    public static readonly Color s_BrightGreenColor = new Color32(16, 157, 6, 255); //109d06
 
    public static readonly Color s_DarkPinkColor = new Color32(255, 124, 124, 255);
    public static readonly Color s_DarkRedColor = new Color32(250, 1, 1, 255);
    public static readonly Color s_DarkPurpleColor = new Color32(236, 75, 246, 255);
    public static readonly Color s_DarkBlueColor = new Color32(49, 206, 251, 255);//31cefb
    public static readonly Color s_DarkOrangeColor = new Color32(248, 152, 59, 255);
    public static readonly Color s_DarkWhiteColor = new Color32(247, 247, 247, 255);
    public static readonly Color s_DarkGreenColor = new Color32(53, 225, 34, 255); //35e122
 
    public static readonly Color s_NavyBrown = new Color32(64, 28, 6, 255);//401c06
    public static readonly Color s_Black = new Color32(0, 0, 0, 255);
    public static readonly Color s_NavyYellow = new Color32(255, 239, 71, 255);
    public static readonly Color s_LightGreen = new Color32(141, 220, 17, 255);//8ddc11
    public static readonly Color s_LightYellow = new Color32(255, 244, 205, 255); //fff4cd
    public static readonly Color s_Gray = new Color32(204, 204, 204, 255);
    public static readonly Color s_Gold = new Color32(255, 239, 71, 255);//ffef47
    public static readonly Color s_EarthYellow = new Color32(248, 152, 59, 255);//f8983b
 
    public static readonly Color s_BrightDanLV0 = new Color32(102, 102, 102, 255); //666666
    public static readonly Color s_BrightDanLV1 = new Color32(148, 96, 255, 255); //9460ff
    public static readonly Color s_BrightDanLV2 = new Color32(0, 102, 255, 255); //0066ff
    public static readonly Color s_BrightDanLV3 = new Color32(0, 179, 55, 255); //00b337
    public static readonly Color s_BrightDanLV4 = new Color32(255, 102, 0, 255); //ff6600
    public static readonly Color s_BrightDanLV5 = new Color32(255, 0, 0, 255); //ff0000
    public static readonly Color s_BrightDanLV6 = new Color32(255, 0, 246, 255); //ff00f6
 
    public static readonly Color s_GrayDanLV0 = new Color32(221, 221, 221, 255); //dddddd
    public static readonly Color s_GrayDanLV1 = new Color32(121, 153, 255, 255); //7999ff
    public static readonly Color s_GrayDanLV2 = new Color32(0, 198, 255, 255); //00c6ff
    public static readonly Color s_GrayDanLV3 = new Color32(102, 255, 0, 255); //66ff00
    public static readonly Color s_GrayDanLV4 = new Color32(255, 144, 0, 255); //ff9000
    public static readonly Color s_GrayDanLV5 = new Color32(255, 0, 0, 255); //ff0000
    public static readonly Color s_GrayDanLV6 = new Color32(240, 0, 255, 255); //f000ff
 
    public static Color GetDanLVColor(int danLv, bool bright = false)
    {
        var crossDanLVConfig = CrossServerArenaConfig.Get(danLv);
        if (crossDanLVConfig != null)
        {
            switch (crossDanLVConfig.DanType)
            {
                case 0:
                    return bright ? s_BrightDanLV0 : s_GrayDanLV0;
                case 1:
                    return bright ? s_BrightDanLV1 : s_GrayDanLV1;
                case 2:
                    return bright ? s_BrightDanLV2 : s_GrayDanLV2;
                case 3:
                    return bright ? s_BrightDanLV3 : s_GrayDanLV3;
                case 4:
                    return bright ? s_BrightDanLV4 : s_GrayDanLV4;
                case 5:
                    return bright ? s_BrightDanLV5 : s_GrayDanLV5;
                case 6:
                    return bright ? s_BrightDanLV6 : s_GrayDanLV6;
            }
        }
        return Color.white;
    }
 
    public static string AppendDanLVNameColor(int danLv, bool bright = false)
    {
        var crossDanLVConfig = CrossServerArenaConfig.Get(danLv);
        if (crossDanLVConfig == null)
        {
            return string.Empty;
        }
        var name = crossDanLVConfig.Name;
        switch (crossDanLVConfig.DanType)
        {
            case 0:
                return StringUtility.Contact("<color=#", bright ? "666666" : "dddddd", ">", name, "</color>");
            case 1:
                return StringUtility.Contact("<color=#", bright ? "9460ff" : "7999ff", ">", name, "</color>");
            case 2:
                return StringUtility.Contact("<color=#", bright ? "0066ff" : "00c6ff", ">", name, "</color>");
            case 3:
                return StringUtility.Contact("<color=#", bright ? "00b337" : "66ff00", ">", name, "</color>");
            case 4:
                return StringUtility.Contact("<color=#", bright ? "ff6600" : "ff9000", ">", name, "</color>");
            case 5:
                return StringUtility.Contact("<color=#", bright ? "ff0000" : "ff0000", ">", name, "</color>");
            case 6:
                return StringUtility.Contact("<color=#", bright ? "ff00f6" : "f000ff", ">", name, "</color>");
        }
        return name;
    }
 
    public static Color GetUIColor(int itemColor, bool bright = false)
    {
        switch (itemColor)
        {
            case 0:
                return GetUIColor(TextColType.White, bright);
            case 1:
                return GetUIColor(TextColType.White, bright);
            case 2:
                return GetUIColor(TextColType.Blue, bright);
            case 3:
                return GetUIColor(TextColType.Purple, bright);
            case 4:
                return GetUIColor(TextColType.Orange, bright);
            case 5:
                return GetUIColor(TextColType.Red, bright);
            case 6:
                return GetUIColor(TextColType.Pink, bright);
        }
        return GetUIColor(TextColType.White, bright);
    }
 
    public static Color GetUIColor(TextColType type, bool bright = false)
    {
        switch (type)
        {
            case TextColType.None:
            case TextColType.White:
                return bright ? s_BrightWhiteColor : s_DarkWhiteColor;
            case TextColType.Blue:
                return bright ? s_BrightBlueColor : s_DarkBlueColor;
            case TextColType.Purple:
                return bright ? s_BrightPurpleColor : s_DarkPurpleColor;
            case TextColType.Orange:
                return bright ? s_BrightOrangeColor : s_DarkOrangeColor;
            case TextColType.Red:
                return bright ? s_BrightRedColor : s_DarkRedColor;
            case TextColType.Pink:
                return bright ? s_BrightPinkColor : s_DarkPinkColor;
            case TextColType.Green:
                return bright ? s_BrightGreenColor : s_DarkGreenColor;
            case TextColType.NavyBrown:
                return s_NavyBrown;
            case TextColType.DarkGreen:
                return s_BrightGreenColor;
            case TextColType.Black:
                return s_Black;
            case TextColType.NavyYellow:
                return s_NavyYellow;
            case TextColType.LightGreen:
                return s_LightGreen;
            case TextColType.LightYellow:
                return s_LightYellow;
            case TextColType.Gray:
                return s_Gray;
        }
        return bright ? s_BrightWhiteColor : s_DarkWhiteColor;
    }
 
    private static Regex m_TextColorRegex = new Regex("<color=#[0-9a-zA-Z]+>(.*)</color>", RegexOptions.Singleline);
 
    public static string AppendColor(TextColType type, string msg, bool bright = false)
    {
        if (m_TextColorRegex.IsMatch(msg) && msg.ToLower().StartsWith("<color=#")
            && msg.ToLower().EndsWith("</color>"))
        {
            Match match = m_TextColorRegex.Match(msg);
            msg = match.Groups[1].Value;
        }
        switch (type)
        {
            case TextColType.None:
            case TextColType.White:
                return StringUtility.Contact("<color=#", bright ? "686868" : "f7f7f7", ">", msg, "</color>");
            case TextColType.Blue:
                return StringUtility.Contact("<color=#", bright ? "006be3" : "31cefb", ">", msg, "</color>");
            case TextColType.Purple:
                return StringUtility.Contact("<color=#", bright ? "da48d5" : "ec4bf6", ">", msg, "</color>");
            case TextColType.Orange:
                return StringUtility.Contact("<color=#", bright ? "ff6701" : "f8983b", ">", msg, "</color>");
            case TextColType.Red:
                return StringUtility.Contact("<color=#", bright ? "ff0303" : "ff0101", ">", msg, "</color>");
            case TextColType.Pink:
                return StringUtility.Contact("<color=#", bright ? "f6408d" : "ff7c7c", ">", msg, "</color>");
            case TextColType.Green:
                return StringUtility.Contact("<color=#", bright ? "109d06" : "35e122", ">", msg, "</color>");
            case TextColType.NavyBrown:
                return StringUtility.Contact("<color=#", "401c06", ">", msg, "</color>");
            case TextColType.DarkGreen:
                return StringUtility.Contact("<color=#", "109d06", ">", msg, "</color>");
            case TextColType.Black:
                return StringUtility.Contact("<color=#", "000000", ">", msg, "</color>");
            case TextColType.LightYellow:
                return StringUtility.Contact("<color=#", "fff4cd", ">", msg, "</color>");
            case TextColType.LightGreen:
                return StringUtility.Contact("<color=#", "8ddc11", ">", msg, "</color>");
        }
        return msg;
    }
 
    public static string GetRealmName(int realmLv, bool bright = false)
    {
        var config = RealmConfig.Get(realmLv);
        if (config == null)
        {
            return string.Empty;
        }
        return GetRealmColorByLv(realmLv, config.Name, bright);
    }
 
    public static string GetRealmColorByLv(int realmLv, string msg, bool bright = false)
    {
        var config = RealmConfig.Get(realmLv);
        if (config == null)
        {
            return string.Empty;
        }
        switch (config.Quality)
        {
            case 1:
                return StringUtility.Contact("<color=#", bright ? "666666" : "dddddd", ">", msg, "</color>");
            case 2:
                return StringUtility.Contact("<color=#", bright ? "00b337" : "66ff00", ">", msg, "</color>");
            case 3:
                return StringUtility.Contact("<color=#", bright ? "0066ff" : "00c6ff", ">", msg, "</color>");
            case 4:
                return StringUtility.Contact("<color=#", bright ? "ff00f6" : "f000ff", ">", msg, "</color>");
            case 5:
                return StringUtility.Contact("<color=#", bright ? "ff6600" : "ff9000", ">", msg, "</color>");
            case 6:
                return StringUtility.Contact("<color=#", bright ? "ff0000" : "ff0000", ">", msg, "</color>");
            default:
                return msg;
        }
    }
 
    public static string AppendColor(int itemColor, string msg, bool bright = false)
    {
        switch (itemColor)
        {
            case 0:
            case 1:
                return AppendColor(TextColType.White, msg, bright);
            case 2:
                return AppendColor(TextColType.Blue, msg, bright);
            case 3:
                return AppendColor(TextColType.Purple, msg, bright);
            case 4:
                return AppendColor(TextColType.Orange, msg, bright);
            case 5:
                return AppendColor(TextColType.Red, msg, bright);
            case 6:
                return AppendColor(TextColType.Pink, msg, bright);
            case 9:
                return AppendColor(TextColType.Green, msg, bright);
        }
        return msg;
    }
 
    public static int GetItemColor(int _id, Dictionary<int, List<int>> _dict = null)
    {
        int _itemColor = 0;
        var _itemCfg = ItemConfig.Get(_id);
        if (_itemCfg != null)
        {
            _itemColor = _itemCfg.ItemColor;
            if (_itemCfg.Type == 113 && _dict != null)
            {
                _itemColor = ItemLogicUtility.Instance.GetItemQuality(_itemCfg.ID, _dict);
            }
        }
        return _itemColor;
    }
 
    public static Color GetPropertyColor(int property)
    {
        switch ((PropertyType)property)
        {
            case PropertyType.Mater:
                return s_Gold;
            case PropertyType.Wood:
                return s_LightGreen;
            case PropertyType.Water:
                return s_DarkBlueColor;
            case PropertyType.Fire:
                return s_GrayDanLV5;
            case PropertyType.Earth:
                return s_EarthYellow;
        }
        return s_NavyBrown;
    }
    #endregion
 
    #region 计算战斗力
    public static readonly string FightPowerFormula = "FightpowerFormula";
 
    public static int GetFightPower(Dictionary<int, int> _propertyDict)
    {
        Equation.Instance.Clear();
        if (_propertyDict == null || _propertyDict.Count == 0)
        {
            return 0;
        }
 
        foreach (var _key in _propertyDict.Keys)
        {
            PlayerPropertyConfig cfg = PlayerPropertyConfig.Get(_key);
            if (cfg != null)
            {
                if (_key == 7)
                {
                    Equation.Instance.AddKeyValue("MinAtk", _propertyDict[_key]);
                    Equation.Instance.AddKeyValue("MaxAtk", _propertyDict[_key]);
                }
                else if (_key == 24)
                {
                    Equation.Instance.AddKeyValue("PetMinAtk", _propertyDict[_key]);
                    Equation.Instance.AddKeyValue("PetMaxAtk", _propertyDict[_key]);
                }
                else
                {
                    var attrValue = _propertyDict[_key];
                    var fightParm = GetFightPowerParmByAttrId(_key);
                    if (_key == 11)
                    {
                        var playerLv = PlayerDatas.Instance.baseData.LV;
                        var paramConfig = FightPowerParamConfig.Get(playerLv);
                        Equation.Instance.AddKeyValue("AtkSpeedParameter", paramConfig.AtkSpeedParameter);
                    }
                    else
                    {
                        if (fightParm != 0)
                        {
                            attrValue = attrValue * fightParm;
                        }
                    }
                    Equation.Instance.AddKeyValue(cfg.Parameter, attrValue);
                }
            }
 
        }
        FuncConfigConfig funcCfg = FuncConfigConfig.Get(FightPowerFormula);
        return Equation.Instance.Eval<int>(funcCfg.Numerical1);
    }
 
    public static int GetFightPowerParmByAttrId(int attrId)
    {
        int playerLv = PlayerDatas.Instance.baseData.LV;
        FightPowerParamConfig paramConfig = FightPowerParamConfig.Get(playerLv);
        PlayerPropertyConfig cfg = PlayerPropertyConfig.Get(attrId);
        if (paramConfig == null || cfg == null) return 0;
 
        switch (cfg.Parameter)
        {
            case "Hit":
                return paramConfig.Hit;
            case "Miss":
                return paramConfig.Miss;
            case "IgnoreDefRate":
                return paramConfig.IgnoreDefRate;
            case "DamChanceDef":
                return paramConfig.DamChanceDef;
            case "FaintRate":
                return paramConfig.FaintRate;
            case "LuckyHitRateReduce":
                return paramConfig.LuckyHitRateReduce;
            case "SkillAtkRate":
                return paramConfig.SkillAtkRate;
            case "SkillAtkRateReduce":
                return paramConfig.SkillAtkRateReduce;
            case "DamagePerPVP":
                return paramConfig.DamagePerPVP;
            case "DamagePerPVPReduce":
                return paramConfig.DamagePerPVPReduce;
            case "DamBackPer":
                return paramConfig.DamBackPer;
            case "IgnoreDefRateReduce":
                return paramConfig.IgnoreDefRateReduce;
            case "FaintDefRate":
                return paramConfig.FaintDefRate;
            case "AtkSpeedParameter":
                return paramConfig.AtkSpeedParameter;
            case "JobAHurtAddPer":
                return paramConfig.JobAHurtAddPer;
            case "JobBHurtAddPer":
                return paramConfig.JobBHurtAddPer;
            case "JobCHurtAddPer":
                return paramConfig.JobCHurtAddPer;
            case "JobAAtkReducePer":
                return paramConfig.JobAAtkReducePer;
            case "JobBAtkReducePer":
                return paramConfig.JobBAtkReducePer;
            case "JobCAtkReducePer":
                return paramConfig.JobCAtkReducePer;
            case "SuperHitRate":
                return paramConfig.SuperHitRate;
            case "LuckyHitRate":
                return paramConfig.LuckyHitRate;
            case "SuperHitRateReduce":
                return paramConfig.SuperHitRateReduce;
            case "FinalHurtPer":
                return paramConfig.FinalHurtPer;
            case "FinalHurtReducePer":
                return paramConfig.FinalHurtReducePer;
            case "NPCHurtAddPer":
                return paramConfig.NPCHurtAddPer;
            case "NormalHurtPer":
                return paramConfig.NormalHurtPer;
            case "FabaoHurtPer":
                return paramConfig.FabaoHurtPer;
        }
 
        return 0;
    }
 
    #endregion
 
    #region 得到金钱数量根据金钱类型
    public static ulong GetMoneyCnt(int moneyType)
    {
        switch (moneyType)
        {
            case 1:
                {
                    return PlayerDatas.Instance.baseData.diamond;
                }
            case 3:
                {
                    return PlayerDatas.Instance.baseData.allCopper;
                }
            case 18:
                {
                    return (ulong)PlayerDatas.Instance.extersion.honorValue;
                }
            case 25:
                {
                    return (ulong)ModelCenter.Instance.GetModel<StoreModel>().GetTCBPlayerData(PlayerDataType.CDBPlayerRefresh_TreasureScore);
                }
            case 24:
                {
                    return (ulong)PlayerDatas.Instance.extersion.runeChip;
                }
            case 15:
                {
                    return (ulong)ModelCenter.Instance.GetModel<StoreModel>().GetTCBPlayerData(PlayerDataType.UnionLiven);
                }
            case 17:
                {
                    return (ulong)ModelCenter.Instance.GetModel<StoreModel>().GetTCBPlayerData(PlayerDataType.FBHelpPoint);
                }
            case 27:
                {
                    return (ulong)ModelCenter.Instance.GetModel<StoreModel>().GetTCBPlayerData(PlayerDataType.CDBPlayerRefresh_Danjing);
                }
            case 28:
                {
                    return PlayerDatas.Instance.extersion.soulDust;
                }
            case 29:
                {
                    return PlayerDatas.Instance.extersion.soulSplinters;
                }
            case 30:
                {
                    return PlayerDatas.Instance.extersion.soulCore;
                }
        }
        return 0;
    }
    #endregion
 
    #region 得到装备位对应的部位名称
    public static string GetEquipPlaceName(int place)
    {
        if (GeneralDefine.equipPlaceNameDict.ContainsKey(place))
        {
            return GeneralDefine.equipPlaceNameDict[place];
        }
        return "";
    }
    #endregion
 
    #region 服务端发过来文字显示不出来问题
    public static string ServerStringTrim(string str)
    {
        if (!string.IsNullOrEmpty(str))
        {
            str = str.Replace("\0", "");
            str = str.Replace("\x00", "");
            return str;
        }
        else
        {
            return string.Empty;
        }
    }
    #endregion
 
    #region 获取间隔奖励
    public static int GetIntervalAward(ICollection<int> _keys, int _present)
    {
        foreach (var _key in _keys)
        {
            if (_present <= _key)
            {
                return _key;
            }
        }
        return _keys.Last();
    }
    #endregion
 
    public static string GetGrade(int _star)
    {
        switch (_star)
        {
            case 5:
                return "S";
            case 4:
                return "A";
            case 3:
                return "B";
            case 2:
                return "C";
            case 1:
                return "D";
        }
        return "D";
    }
 
    public static string TrimContentToServer(string content)
    {
        content = WordAnalysis.Color_Start_Regex.Replace(content, string.Empty);
        content = WordAnalysis.Color_End_Regex.Replace(content, string.Empty);
        content = content.Replace("=", string.Empty);
        content = content.Replace(" ", string.Empty);
        return content;
    }
 
    public static bool SatisfyNameLength(string name, out int error)
    {
        error = 0;
        bool pureChinese = Regex.IsMatch(name, "^[\u4e00-\u9fa5]+$");
        var chsCount = GetChsCount(name);
        var maxlength = pureChinese ? 5 : chsCount > 0 ? 6 : 8;
        var minlength = pureChinese ? 2 : 3;
        if (name.Length > maxlength)
        {
            error = 1;
        }
        else if (name.Length < minlength)
        {
            error = 2;
        }
        return error == 0;
    }
 
    public static int GetChsCount(string name)
    {
        var count = 0;
        for (int i = 0; i < name.Length; i++)
        {
            if (Regex.IsMatch(name[i].ToString(), "[\u4e00-\u9fa5]"))
            {
                count++;
            }
        }
        return count;
    }
 
    public static string GetEquipSuitName(int itemId, bool bright = false)
    {
        if (ItemLogicUtility.Instance.IsSuitEquip(itemId))
        {
            var itemConfig = ItemConfig.Get(itemId);
            return AppendColor(TextColType.Green, EquipModel.GetSuitName(itemConfig.LV), bright);
        }
        return string.Empty;
    }
 
    public static string GetItemName(int itmeId, bool bright = false)
    {
        var itemConfig = ItemConfig.Get(itmeId);
        if (itemConfig == null)
        {
            return string.Empty;
        }
        return StringUtility.Contact(GetEquipSuitName(itmeId, bright), itemConfig.ItemName);
    }
}