yyl
2 天以前 5d3366f2e0f687995eb7ad2107c4379fe7acd4e8
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
using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
 
 
public class HappyXBModel : GameSystemManager<HappyXBModel>
{
    private Dictionary<string, XBGetItemConfig> xbGetItemDict = new Dictionary<string, XBGetItemConfig>();
    private Dictionary<int, List<XBGetItemConfig>> xbTypeItemDict = new Dictionary<int, List<XBGetItemConfig>>();
    private Dictionary<string, Dictionary<int, XBGetItem>> jobXBItemDict = new Dictionary<string, Dictionary<int, XBGetItem>>();
    private Dictionary<int, XBFuncSet> xbFuncSetDict = new Dictionary<int, XBFuncSet>();
    public Dictionary<int, int> XBCostTypeDict = new Dictionary<int, int>();
    public HappXBTitle title = HappXBTitle.Best;
 
 
    public string USETOOLXBKey = string.Empty;
    public static string HAPPYXBITEMKEY;
    public List<ArrayList> XBNotifyParms = new List<ArrayList>();
    public bool isXBCoolTime { get; set; }
 
    public bool isJumpBestXB { get; set; }
    public bool isJumpRuneXB { get; set; }
    public bool isJumpGubaoXB { get; set; }
    public bool isJumpGatherSoulXB { get; set; } //聚魂寻宝:是否跳过动画
 
    public override void Init()
    {
        isJumpBestXB = false;
        isJumpRuneXB = false;
        isJumpGubaoXB = false;
        isJumpGatherSoulXB = false;
        xbGetItemDict.Clear();
        xbTypeItemDict.Clear();
        xbFuncSetDict.Clear();
        List<XBGetItemConfig> list = XBGetItemConfig.GetValues();
        for (int i = 0; i < list.Count; i++)
        {
            string key = StringUtility.Contact(list[i].TreasureType, list[i].MinLV);
            if (!xbGetItemDict.ContainsKey(key))
            {
                xbGetItemDict.Add(key, list[i]);
            }
 
            if (!xbTypeItemDict.ContainsKey(list[i].TreasureType))
            {
                List<XBGetItemConfig> typeItemlist = new List<XBGetItemConfig>();
                typeItemlist.Add(list[i]);
                xbTypeItemDict.Add(list[i].TreasureType, typeItemlist);
            }
            else
            {
                xbTypeItemDict[list[i].TreasureType].Add(list[i]);
            }
        }
 
        SetXBFuncDict(1);
        SetXBFuncDict(2);
        // var treasureIDArr = JsonMapper.ToObject<int[]>(FuncConfigConfig.Get("TreasureLuckyDraw").Numerical1);
        // for (int i = 0; i < treasureIDArr.Length; i++)
        // {
        //     int type = XBGetItemConfig.Get(treasureIDArr[i]).TreasureType;
        //     SetXBFuncDict(type);
        // }
 
        SetXBFuncDict(105);
        SetXBFuncDict(106);
        SetXBFuncDict(107);
        SetXBFuncDict(108);
        SysNotifyMgr.Instance.RegisterCondition("HappyXB", SatisfyNotifyCondition);
 
        XBCostTypeDict.Clear();
 
        XBCostTypeDict[(int)HappXBTitle.Best] = TreasureSetConfig.Get(1).CostMoneyType;
        XBCostTypeDict[(int)HappXBTitle.Rune] = TreasureSetConfig.Get(2).CostMoneyType;
        // for (int i = 0; i < treasureIDArr.Length; i++)
        // {
        //     int type = XBGetItemConfig.Get(treasureIDArr[i]).TreasureType;
        //     XBCostTypeDict[(int)HappXBTitle.Gubao1 + i] = TreasureSetConfig.Get(type).CostMoneyType;
        // }
        XBCostTypeDict[(int)HappXBTitle.YunShi1] = TreasureSetConfig.Get(105).CostMoneyType;
        XBCostTypeDict[(int)HappXBTitle.YunShi2] = TreasureSetConfig.Get(106).CostMoneyType;
        XBCostTypeDict[(int)HappXBTitle.YunShi3] = TreasureSetConfig.Get(107).CostMoneyType;
        XBCostTypeDict[(int)HappXBTitle.YunShi4] = TreasureSetConfig.Get(108).CostMoneyType;
    }
 
 
 
    public void OnBeforePlayerDataInitialize()
    {
        PlayerDatas.Instance.playerDataRefreshEvent -= RefreshStoreScore;
        FuncOpen.Instance.OnFuncStateChangeEvent -= UpdateFuncState;
        PackManager.Instance.refreshItemCountEvent -= RefreshXBTool;
        isXBCoolTime = false;
        XBNotifyParms.Clear();
        xbTypeInfoDict.Clear();
    }
    public void OnAfterPlayerDataInitialize()
    {
        SetXBGetItemModel();
    }
    public void OnPlayerLoginOk()
    {
        int playerId = (int)PlayerDatas.Instance.baseData.PlayerID;
        HAPPYXBITEMKEY = StringUtility.Contact(playerId, "HappyXBItemTime");
        USETOOLXBKey = StringUtility.Contact(playerId, "UseToolXB");
        XBWarehouseRedPoint();
        PlayerDatas.Instance.playerDataRefreshEvent += RefreshStoreScore;
        PackManager.Instance.refreshItemCountEvent += RefreshXBTool;
        FuncOpen.Instance.OnFuncStateChangeEvent += UpdateFuncState;
    }
 
 
    /// <summary>
    /// 检测自身玩家是否需要信息提示
    /// </summary>
    /// <param name="key"></param>
    /// <param name="paramArray"></param>
    /// <returns></returns>
    private bool SatisfyNotifyCondition(string key, ArrayList paramArray)
    {
        switch (title)
        {
            case HappXBTitle.Best:
                if (isJumpBestXB)
                {
                    return true;
                }
                break;
            case HappXBTitle.Rune:
                if (isJumpRuneXB)
                {
                    return true;
                }
                break;
            case HappXBTitle.Gubao1:
            case HappXBTitle.Gubao2:
            case HappXBTitle.Gubao3:
            case HappXBTitle.Gubao4:
                if (isJumpGubaoXB)
                {
                    return true;
                }
                break;
            case HappXBTitle.GatherSoul:
                if (isJumpGatherSoulXB)
                {
                    return true;
                }
                break;
            case HappXBTitle.YunShi1:
            case HappXBTitle.YunShi2:
            case HappXBTitle.YunShi3:
            case HappXBTitle.YunShi4:
                // if (ModelCenter.Instance.GetModelEx<YunShiXBActModel>().isSkipXB)
                // {
                //     return true;
                // }
                break;
        }
 
        XBNotifyParms.Add(new ArrayList(paramArray));
        if (paramArray != null && paramArray.Count > 0 &&
            paramArray[0].Equals(UIHelper.ServerStringTrim(PlayerDatas.Instance.baseData.PlayerName)))
        {
            return false;
        }
        return true;
    }
 
    public void GetNotifyResult(int itemId, int itemCount)
    {
        int notifyIndex = 0;
        if (CheckNotifyItemByIdAndCnt(itemId, itemCount, out notifyIndex))
        {
            SysNotifyMgr.Instance.ShowTip("HappyXB", XBNotifyParms[notifyIndex].ToArray());
        }
    }
 
    private bool CheckNotifyItemByIdAndCnt(int itemId, int itemCnt, out int notifyIndex)
    {
        notifyIndex = 0;
        for (int i = 0; i < XBNotifyParms.Count; i++)
        {
            if (XBNotifyParms[i] != null && XBNotifyParms[i].Count > 3)
            {
                int notifyItemId = 0;
                int.TryParse(XBNotifyParms[i][1].ToString(), out notifyItemId);
                int notifyItemCnt = 0;
                int.TryParse(XBNotifyParms[i][3].ToString(), out notifyItemCnt);
                if (notifyItemId == itemId && notifyItemCnt == itemCnt)
                {
                    notifyIndex = i;
                    return true;
                }
            }
        }
        return false;
    }
 
    private void SetXBFuncDict(int type)
    {
        var treasureSetCfg = TreasureSetConfig.Get(type);
        if (!xbFuncSetDict.ContainsKey(type))
        {
            XBFuncSet funcSet = new XBFuncSet();
            funcSet.xbType = type;
            funcSet.xbNums = treasureSetCfg.TreasureCountList;
 
            funcSet.xbPrices = treasureSetCfg.CostMoneyList;
 
            funcSet.costToolIds = new int[] { treasureSetCfg.CostItemID, treasureSetCfg.CostItemID };
            funcSet.costToolNums = treasureSetCfg.CostItemCountList;
            funcSet.dailyFreeCount = treasureSetCfg.DailyFreeCount;
            funcSet.xbScores = new int[] { treasureSetCfg.AwardMoneyValue, treasureSetCfg.AwardMoneyValue * treasureSetCfg.TreasureCountList[1] };
 
            xbFuncSetDict.Add(funcSet.xbType, funcSet);
        }
    }
 
    public XBFuncSet GetXBFuncSet(int type)
    {
        XBFuncSet funcSet = null;
        xbFuncSetDict.TryGetValue(type, out funcSet);
        return funcSet;
    }
 
    //默认优先使用道具寻宝
    public bool IsUseToolXB()
    {
        return true;
        //if (!PlayerPrefs.HasKey(USETOOLXBKey))
        //{
        //    LocalSave.SetBool(USETOOLXBKey, true);
        //    return true;
        //}
        //else
        //{
        //    return LocalSave.GetBool(USETOOLXBKey);
        //}
    }
 
    public void SetUseToolXB(bool isToolXB)
    {
        //LocalSave.SetBool(USETOOLXBKey, isToolXB);
    }
 
    private void SetXBGetItemModel()
    {
        jobXBItemDict.Clear();
        Dictionary<int, XBGetItem> getItemDict = new Dictionary<int, XBGetItem>();
        Dictionary<int, List<int>> jobItemDict = new Dictionary<int, List<int>>();
        int playerJob = PlayerDatas.Instance.baseData.Job;
        foreach (var key in xbGetItemDict.Keys)
        {
 
            getItemDict.Clear();
            jobItemDict.Clear();
            Dictionary<int, XBGetItem> jobGetItemDict = new Dictionary<int, XBGetItem>();
            XBGetItemConfig getItemConfig = xbGetItemDict[key];
            jobXBItemDict.Add(key, jobGetItemDict);
            JsonData getItemJson = JsonMapper.ToObject(getItemConfig.GridItemInfo);
            foreach (var grid in getItemJson.Keys)
            {
                int id = int.Parse(getItemJson[grid][0].ToString());
                int count = int.Parse(getItemJson[grid][1].ToString());
                XBGetItem getItem = new XBGetItem();
                getItem.SetModel(int.Parse(grid), id, count);
                getItemDict.Add(getItem.gridIndex, getItem);
            }
            JsonData jobReplaceJson = JsonMapper.ToObject(getItemConfig.JobItemList);
            if (jobReplaceJson.IsArray)
            {
                for (int i = 0; i < jobReplaceJson.Count; i++)
                {
                    List<int> itemIdlist = new List<int>();
                    jobItemDict.Add(i, itemIdlist);
                    if (jobReplaceJson[i].IsArray)
                    {
                        for (int j = 0; j < jobReplaceJson[i].Count; j++)
                        {
                            int id = int.Parse(jobReplaceJson[i][j].ToString());
                            itemIdlist.Add(id);
                        }
                    }
                }
            }
 
            foreach (var model in getItemDict.Values)
            {
                ItemConfig itemConfig = ItemConfig.Get(model.itemId);
                if (itemConfig.JobLimit == 0)
                {
                    jobGetItemDict.Add(model.gridIndex, model);
                }
                else
                {
                    bool isReplace = false;
                    foreach (var list in jobItemDict.Values)
                    {
                        if (list.Contains(model.itemId))
                        {
                            for (int i = 0; i < list.Count; i++)
                            {
                                int equipJob = int.Parse(list[i].ToString().Substring(0, 1));
                                if (playerJob == equipJob)
                                {
                                    isReplace = true;
                                    XBGetItem getItem = new XBGetItem();
                                    getItem.SetModel(model.gridIndex, list[i], model.count);
                                    jobGetItemDict.Add(getItem.gridIndex, getItem);
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    if (!isReplace)
                    {
                        jobGetItemDict.Add(model.gridIndex, model);
                    }
                }
 
            }
 
        }
 
    }
 
    public Dictionary<int, XBGetItem> GetXBGetItemByID(int type)
    {
        int lv = 0;
        List<XBGetItemConfig> configlist = null;
        xbTypeItemDict.TryGetValue(type, out configlist);
        if (configlist != null)
        {
            for (int i = configlist.Count - 1; i > -1; i--)
            {
                if (PlayerDatas.Instance.baseData.LV >= configlist[i].MinLV)
                {
                    lv = configlist[i].MinLV;
                    break;
                }
            }
        }
        string key = StringUtility.Contact(type, lv);
        Dictionary<int, XBGetItem> dict = null;
        jobXBItemDict.TryGetValue(key, out dict);
        return dict;
    }
 
    public XBGetItemConfig GetXBItemConfigByType(int type)
    {
        int lv = 0;
        List<XBGetItemConfig> configlist = null;
        xbTypeItemDict.TryGetValue(type, out configlist);
        if (configlist != null)
        {
            for (int i = configlist.Count - 1; i > -1; i--)
            {
                if (PlayerDatas.Instance.baseData.LV >= configlist[i].MinLV)
                {
                    lv = configlist[i].MinLV;
                    break;
                }
            }
        }
        XBGetItemConfig xbItemConfig = null;
        string key = StringUtility.Contact(type, lv);
        xbGetItemDict.TryGetValue(key, out xbItemConfig);
        return xbItemConfig;
    }
 
    #region 处理服务端数据
    public event Action RefreshXBTypeInfoAct;
    public event Action RefreshXBResultAct;
    public int addXBScore { get; private set; }
    public int addXBScoreType { get; private set; } //寻宝积分货币类型
    public int addXBLuckValue { get; private set; }
    private Dictionary<int, XBGetItem> xbResultDict = new Dictionary<int, XBGetItem>();
    public void GetServerXBResult(HA350_tagMCTreasureResult result)
    {
        XBNotifyParms.Clear();
        xbResultDict.Clear();
        addXBScore = result.AddMoneyValue;
        addXBScoreType = result.AddMoneyType;
        addXBLuckValue = result.AddTreasureLuck;
        JsonData resultData = JsonMapper.ToObject(result.TreasureResult);
        if (resultData.IsArray)
        {
            for (int i = 0; i < resultData.Count; i++)
            {
                if (resultData[i].IsArray)
                {
                    int index = int.Parse(resultData[i][0].ToString());
                    int itemId = int.Parse(resultData[i][1].ToString());
                    int count = int.Parse(resultData[i][2].ToString());
                    XBGetItem getItem = new XBGetItem();
                    getItem.SetModel(index, itemId, count);
                    if (!xbResultDict.ContainsKey(i))
                    {
                        xbResultDict.Add(i, getItem);
                    }
                    else
                    {
                        xbResultDict[i] = getItem;
                    }
                }
            }
        }
        SetXBResultRecord();
        isXBCoolTime = false;
        if (RefreshXBResultAct != null)
        {
            RefreshXBResultAct();
        }
    }
 
    List<string> itemGetTimeArray = new List<string>();
    List<string> getNewItemLoglist = new List<string>();
    List<XBGetItem> xbItemRecordlist = new List<XBGetItem>();
    public void SetXBResultRecord()
    {
        if (PlayerPrefs.HasKey(HAPPYXBITEMKEY))
        {
            itemGetTimeArray = LocalSave.GeStringArray(HappyXBModel.HAPPYXBITEMKEY).ToList();
        }
        else
        {
            itemGetTimeArray.Clear();
        }
        xbItemRecordlist.Clear();
        getNewItemLoglist.Clear();
        xbItemRecordlist.AddRange(GetXBResultlist());
        if (xbItemRecordlist != null)
        {
            int remianLogNum = (itemGetTimeArray.Count + xbItemRecordlist.Count) - 30;
            if (remianLogNum > 0)
            {
                int startIndex = itemGetTimeArray.Count - remianLogNum;
                itemGetTimeArray.RemoveRange(startIndex, remianLogNum);
            }
            xbItemRecordlist.Sort(CompareByTime);
            for (int i = 0; i < xbItemRecordlist.Count; i++)
            {
                string log = Language.Get("HappyXBGetItemTime", xbItemRecordlist[i].createTimeStr, UIHelper.ServerStringTrim(PlayerDatas.Instance.baseData.PlayerName),
                    xbItemRecordlist[i].itemId, xbItemRecordlist[i].count);
                getNewItemLoglist.Add(log);
            }
            if (getNewItemLoglist.Count > 0)
            {
                itemGetTimeArray.InsertRange(0, getNewItemLoglist);
                LocalSave.SetStringArray(HappyXBModel.HAPPYXBITEMKEY, itemGetTimeArray.ToArray());
            }
 
        }
    }
 
    public int CompareByTime(XBGetItem start, XBGetItem end)
    {
        DateTime startTime = start.createTime;
        DateTime endTime = end.createTime;
        if (startTime.CompareTo(endTime) != 0) return -startTime.CompareTo(endTime);
 
        return 0;
    }
 
    public List<XBGetItem> rangelist = new List<XBGetItem>();
    List<int> index = new List<int>();
    public List<XBGetItem> GetXBResultlist()
    {
        rangelist.Clear();
        index.Clear();
        List<XBGetItem> xbItemlist = xbResultDict.Values.ToList();
        for (int i = 0; i < xbItemlist.Count; i++)
        {
            index.Add(i);
        }
        SetRandomList(xbItemlist);
        return rangelist;
    }
 
    public void SetRandomList(List<XBGetItem> xbItemlist)
    {
        int currentRandom = UnityEngine.Random.Range(0, index.Count);
        XBGetItem current = xbItemlist[index[currentRandom]];
        if (!rangelist.Contains(current))
        {
            rangelist.Add(current);
            index.Remove(index[currentRandom]);
 
        }
        if (index.Count > 0)
        {
            SetRandomList(xbItemlist);
        }
    }
 
    public Dictionary<int, XBGetItem> GetXbResultDict()
    {
        return xbResultDict;
    }
 
    public void ClearXBRusltData()
    {
        xbResultDict.Clear();
    }
 
    private Dictionary<int, XBTypeInfo> xbTypeInfoDict = new Dictionary<int, XBTypeInfo>();
    public void GetServerXBInfo(HA351_tagMCTreasureInfo info)
    {
        for (int i = 0; i < info.InfoCount; i++)
        {
            if (!xbTypeInfoDict.ContainsKey(info.TreasuerInfoList[i].TreasureType))
            {
                XBTypeInfo typeInfo = new XBTypeInfo();
                typeInfo.xbType = info.TreasuerInfoList[i].TreasureType;
                typeInfo.luckValue = info.TreasuerInfoList[i].LuckValue;
                typeInfo.freeCountToday = info.TreasuerInfoList[i].FreeCountToday;
                typeInfo.treasureCount = (int)info.TreasuerInfoList[i].TreasureCount;
                typeInfo.treasureCountToday = (int)info.TreasuerInfoList[i].TreasureCountToday;
                typeInfo.treasureCntAward = (int)info.TreasuerInfoList[i].TreasureCntAward;
                if (typeInfo.gridLimitCntDict == null)
                    typeInfo.gridLimitCntDict = new Dictionary<int, int>();
                for (int j = 0; j < info.TreasuerInfoList[i].GridLimitCntList.Length; j++)
                {
                    int num = info.TreasuerInfoList[i].GridLimitCntList[j].GridNum;
                    int cnt = info.TreasuerInfoList[i].GridLimitCntList[j].GridCnt;
                    typeInfo.gridLimitCntDict[num] = cnt;
                }
                xbTypeInfoDict.Add(info.TreasuerInfoList[i].TreasureType, typeInfo);
            }
            else
            {
                xbTypeInfoDict[info.TreasuerInfoList[i].TreasureType].luckValue = info.TreasuerInfoList[i].LuckValue;
                xbTypeInfoDict[info.TreasuerInfoList[i].TreasureType].freeCountToday = info.TreasuerInfoList[i].FreeCountToday;
                xbTypeInfoDict[info.TreasuerInfoList[i].TreasureType].treasureCount = (int)info.TreasuerInfoList[i].TreasureCount;
                xbTypeInfoDict[info.TreasuerInfoList[i].TreasureType].treasureCountToday = (int)info.TreasuerInfoList[i].TreasureCountToday;
                xbTypeInfoDict[info.TreasuerInfoList[i].TreasureType].treasureCntAward = (int)info.TreasuerInfoList[i].TreasureCntAward;
                if (xbTypeInfoDict[info.TreasuerInfoList[i].TreasureType].gridLimitCntDict == null)
                    xbTypeInfoDict[info.TreasuerInfoList[i].TreasureType].gridLimitCntDict = new Dictionary<int, int>();
                for (int j = 0; j < info.TreasuerInfoList[i].GridLimitCntList.Length; j++)
                {
                    int num = info.TreasuerInfoList[i].GridLimitCntList[j].GridNum;
                    int cnt = info.TreasuerInfoList[i].GridLimitCntList[j].GridCnt;
                    xbTypeInfoDict[info.TreasuerInfoList[i].TreasureType].gridLimitCntDict[num] = cnt;
                }
            }
        }
 
 
        if (RefreshXBTypeInfoAct != null)
        {
            RefreshXBTypeInfoAct();
        }
 
        BestAndRuneXBRedPoint();
    }
 
    public XBTypeInfo GetXBInfoByType(int type)
    {
        XBTypeInfo typeInfo = null;
        xbTypeInfoDict.TryGetValue(type, out typeInfo);
        return typeInfo;
    }
 
    /// <summary>
    /// type 1 极品寻宝 2 符印寻宝  index 0 单次寻宝 1 多次寻宝
    ///costType 0-默认仙玉;1-免费次数;2-寻宝道具
    /// </summary>
    /// <param name="type"></param>
    /// <param name="index"></param>
    public event Action<int> StartXBEvent;
    public void SendXBQuest(int type, int index, int costType)
    {
        isXBCoolTime = true;
        CA568_tagCMRequestTreasure treasure = new CA568_tagCMRequestTreasure();
        treasure.TreasureType = (byte)type;
        treasure.TreasureIndex = (byte)index;
        treasure.CostType = (byte)costType;
        GameNetSystem.Instance.SendInfo(treasure);
        if (StartXBEvent != null)
        {
            StartXBEvent(index);
        }
    }
 
 
 
    public bool CheckIsEmptyGrid(PackType type, int needGrid = 1)
    {
        switch (type)
        {
            case PackType.Treasure:
                SinglePack singlePack = PackManager.Instance.GetSinglePack(type);
                if (GeneralDefine.maxXBGridCount - singlePack.GetAllItems().Count < needGrid)
                {
                    SysNotifyMgr.Instance.ShowTip("XBWarehouseFull");
                    return false;
                }
                break;
            case PackType.Item:
                if (PackManager.Instance.GetEmptyGridCount(type) < needGrid)
                {
                    SysNotifyMgr.Instance.ShowTip("BagFull");
                    return false;
                }
                break;
        }
        return true;
    }
 
    public void SendOneXBQuest(PackType type, int xbType)
    {
        var config = TreasureSetConfig.Get(xbType);
        if (GetXBInfoByType(xbType).treasureCountToday + config.TreasureCountList[0] > config.DailyMaxCount)
        {
            SysNotifyMgr.Instance.ShowTip("XBTodayMax");
            return;
        }
 
        var funcSet = GetXBFuncSet(xbType);
        if (CheckIsEmptyGrid(type))
        {
            if (IsHaveOneXBTool(xbType))
            {
                SendXBQuest(xbType, 0, 2);
                return;
            }
 
 
 
            int moneyType = XBCostTypeDict[xbType];
            int xbOneMoney = funcSet.xbPrices[0];
 
            if (UIHelper.GetMoneyCnt(moneyType) >= (ulong)xbOneMoney)
            {
                StoreModel.Instance.UseMoneyCheck(xbOneMoney, () =>
                {
                    SendXBQuest(xbType, 0, 0);
                }, xbType == 1 ? 5 : 6, fullTip: Language.Get("TreasurePavilion08", xbOneMoney, moneyType, funcSet.costToolIds[0], 1));
            }
            else
            {
                SysNotifyMgr.Instance.ShowTip("LackMoney", moneyType);
 
            }
        }
    }
 
 
    public void SendXBManyQuest(PackType type, int xbType)
    {
        var config = TreasureSetConfig.Get(xbType);
        if (GetXBInfoByType(xbType).treasureCountToday + config.TreasureCountList[1] > config.DailyMaxCount)
        {
            SysNotifyMgr.Instance.ShowTip("XBTodayMax");
            return;
        }
 
        var funcSet = GetXBFuncSet(xbType);
        if (CheckIsEmptyGrid(type))
        {
            int toolCnt = 0;
            int needToolCnt = 0;
            int needMoney = 0;
            if (IsHaveManyXBToolEx(xbType, out toolCnt, out needToolCnt, out needMoney))
            {
                if (toolCnt >= needToolCnt)
                {
                    CheckXBManyLimit(0, xbType, 2);
 
                    return;
                }
 
            }
 
            int moneyType = XBCostTypeDict[xbType];
            int xbManyMoney = needMoney == 0 ? funcSet.xbPrices[1] : needMoney;
 
            if (UIHelper.GetMoneyCnt(moneyType) >= (ulong)xbManyMoney)
            {
                StoreModel.Instance.UseMoneyCheck(xbManyMoney, () =>
                {
                    SendXBQuest(xbType, 1, toolCnt > 0 ? 2 : 0);
                }, xbType == 1 ? 5 : 6, fullTip: Language.Get("TreasurePavilion08", xbManyMoney, moneyType, funcSet.costToolIds[1], needToolCnt - toolCnt));
            }
            else
            {
                SysNotifyMgr.Instance.ShowTip("LackMoney", moneyType);
 
            }
 
        }
    }
 
    public void CheckXBManyLimit(int needMoney, int xbtype, int costType)
    {
        int moneyType = XBCostTypeDict[xbtype];
        if (UIHelper.GetMoneyCnt(moneyType) >= (ulong)needMoney)
        {
            SendXBQuest(xbtype, 1, costType);
        }
        else
        {
            //WindowCenter.Instance.Open<RechargeTipWin>();
            SysNotifyMgr.Instance.ShowTip("LackMoney", moneyType);
        }
    }
    #endregion
 
    public bool IsHaveFreeXB(int type)
    {
        XBTypeInfo typeInfo = GetXBInfoByType(type);
        if (typeInfo == null)
        {
            typeInfo = new XBTypeInfo()
            {
                xbType = type,
                luckValue = 0,
                freeCountToday = 0,
                treasureCount = 0,
            };
        }
 
        //判断是否有免费次数,且免费次数是否用完
        var funcSet = GetXBFuncSet(type);
        return typeInfo.freeCountToday < funcSet.dailyFreeCount;
    }
 
 
    public bool CheckIsXBTool(int itemId, int type)
    {
        XBFuncSet funcSet = GetXBFuncSet(type);
        if (funcSet == null) return false;
 
        if (funcSet.costToolIds.Contains(itemId))
        {
            return true;
        }
        return false;
    }
    public bool IsHaveOneXBTool(int type)
    {
        XBFuncSet funcSet = GetXBFuncSet(type);
        if (funcSet == null) return false;
 
        int toolCnt = PackManager.Instance.GetItemCountByID(PackType.Item, funcSet.costToolIds[0]);
        if (toolCnt >= funcSet.costToolNums[0])
        {
            return true;
        }
 
        return false;
    }
 
    //needToolCnt 为配表中需要的道具数量
    public bool IsHaveManyXBTool(int type, out int toolCnt, out int needToolCnt)
    {
        toolCnt = 0;
        needToolCnt = 0;
        XBFuncSet funcSet = GetXBFuncSet(type);
        if (funcSet == null) return false;
 
        toolCnt = PackManager.Instance.GetItemCountByID(PackType.Item, funcSet.costToolIds[1]);
        needToolCnt = funcSet.costToolNums[1];
        if (toolCnt > 0)
        {
            return true;
        }
        return false;
    }
 
    //needToolCnt 为配表中需要的道具数量
    // 可获得真正需要补足购买道具的金额
    public bool IsHaveManyXBToolEx(int type, out int toolCnt, out int needToolCnt, out int needMoney)
    {
        toolCnt = 0;
        needToolCnt = 0;    //配置中需要的道具数量
        needMoney = 0;  //真正需要补足购买道具的金额
        XBFuncSet funcSet = GetXBFuncSet(type);
        if (funcSet == null) return false;
 
        toolCnt = PackManager.Instance.GetItemCountByID(PackType.Item, funcSet.costToolIds[1]);
        needToolCnt = funcSet.costToolNums[1];
 
        if (toolCnt > 0)
        {
            if (toolCnt < needToolCnt)
            {
                needMoney = funcSet.xbPrices[1] / needToolCnt * (needToolCnt - toolCnt);
            }
 
            return true;
        }
        return false;
    }
 
 
 
    public event Action<float> RefreshBestXBTimeAct;
    public event Action<float> RefreshRuneXBTimeAct;
    public void RefreshBestXBTime(float time)
    {
        if (RefreshBestXBTimeAct != null)
        {
            RefreshBestXBTimeAct(time);
        }
 
        if (time <= 0)
        {
            BestAndRuneXBRedPoint();
        }
    }
    public void RefreshRuneXBTime(float time)
    {
        if (RefreshRuneXBTimeAct != null)
        {
            RefreshRuneXBTimeAct(time);
        }
 
        if (time <= 0)
        {
            BestAndRuneXBRedPoint();
        }
    }
 
    public event Action<HappXBTitle, int> RefreshAgainXBAct;
    /// <summary>
    /// xbtype 0-单次 1 多次
    /// </summary>
    /// <param name="xBTitle"></param>
    /// <param name="xbType"></param>
    public void SetAgainXBEvent(HappXBTitle xBTitle, int xbType)
    {
        if (RefreshAgainXBAct != null)
        {
            RefreshAgainXBAct(xBTitle, xbType);
        }
    }
 
    #region 红点逻辑
    public const int HappyXB_RedKey = 203;
    public const int BestXB_RedKey = 20301;
    public const int RuneXB_RedKey = 20302;
    public const int XBStore_RedKey = 20303;
    public const int XBWarehouse_RedKey = 20304;
    public const int BestXB_OneRedKey = 20301001;
    public const int BestXB_ManyRedKey = 20301002;
    public const int BestXB_FreeRedKey = 20301003;
    public const int RuneXB_OneRedKey = 20302001;
    public const int RuneXB_ManyRedKey = 20302002;
    public const int RuneXB_FreeRedKey = 20302003;
 
    public Redpoint happyXBRed = new Redpoint(HappyXB_RedKey);
    public Redpoint bestXBRed = new Redpoint(HappyXB_RedKey, BestXB_RedKey);
    public Redpoint runeXBRed = new Redpoint(HappyXB_RedKey, RuneXB_RedKey);
    public Redpoint xbStoreRed = new Redpoint(HappyXB_RedKey, XBStore_RedKey);
    public Redpoint xbWarehouseRed = new Redpoint(HappyXB_RedKey, XBWarehouse_RedKey);
    public Redpoint bestXBOneRed = new Redpoint(BestXB_RedKey, BestXB_OneRedKey);
    public Redpoint bestXBManyRed = new Redpoint(BestXB_RedKey, BestXB_ManyRedKey);
    public Redpoint bestXBFreeRed = new Redpoint(BestXB_RedKey, BestXB_FreeRedKey);
    public Redpoint runeXBOneRed = new Redpoint(RuneXB_RedKey, RuneXB_OneRedKey);
    public Redpoint runeXBManyRed = new Redpoint(RuneXB_RedKey, RuneXB_ManyRedKey);
    public Redpoint runeXBFreeRed = new Redpoint(RuneXB_RedKey, RuneXB_FreeRedKey);
 
    private void UpdateFuncState(int funcId)
    {
        if (funcId == (int)FuncOpenEnum.HappyFindTreasure
            || funcId == 184)
        {
            XBWarehouseRedPoint();
            BestAndRuneXBRedPoint();
            XBStoreRedPoint();
        }
    }
 
    public void RefreshXBWarehouse()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.HappyFindTreasure)) return;
 
        xbWarehouseRed.state = RedPointState.Simple;
    }
 
    public void XBWarehouseRedPoint()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.HappyFindTreasure)) return;
 
        SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Treasure);
        if (singlePack == null) return;
 
        if (singlePack.GetAllItems().Count > 0)
        {
            xbWarehouseRed.state = RedPointState.Simple;
        }
        else
        {
            xbWarehouseRed.state = RedPointState.None;
        }
    }
 
    private void RefreshXBTool(PackType type, int index, int id)
    {
        if (type != PackType.Item) return;
        if (!CheckIsXBTool(id, 1) && !CheckIsXBTool(id, 2)) return;
        BestAndRuneXBRedPoint();
    }
 
    public void BestAndRuneXBRedPoint()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.HappyFindTreasure)) return;
 
        int xbtoolCnt = 0;
        int needtoolCnt = 0;
        if (IsHaveFreeXB(1))
        {
            bestXBFreeRed.state = RedPointState.Simple;
        }
        else
        {
            bestXBFreeRed.state = RedPointState.None;
        }
 
        if (IsHaveManyXBTool(1, out xbtoolCnt, out needtoolCnt))
        {
            if (xbtoolCnt >= needtoolCnt)
            {
                bestXBManyRed.state = RedPointState.Simple;
            }
            else
            {
                bestXBManyRed.state = RedPointState.None;
            }
            bestXBOneRed.state = RedPointState.Simple;
        }
        else
        {
            bestXBOneRed.state = RedPointState.None;
            bestXBManyRed.state = RedPointState.None;
        }
 
        if (FuncOpen.Instance.IsFuncOpen(184) && IsHaveFreeXB(2))
        {
            runeXBFreeRed.state = RedPointState.Simple;
        }
        else
        {
            runeXBFreeRed.state = RedPointState.None;
        }
 
        if (FuncOpen.Instance.IsFuncOpen(184) &&
            IsHaveManyXBTool(2, out xbtoolCnt, out needtoolCnt))
        {
            if (xbtoolCnt >= needtoolCnt)
            {
                runeXBManyRed.state = RedPointState.Simple;
            }
            else
            {
                runeXBManyRed.state = RedPointState.None;
            }
            runeXBOneRed.state = RedPointState.Simple;
        }
        else
        {
            runeXBOneRed.state = RedPointState.None;
            runeXBManyRed.state = RedPointState.None;
        }
    }
 
 
    private void RefreshStoreScore(PlayerDataType type)
    {
        if (type != PlayerDataType.CDBPlayerRefresh_TreasureScore) return;
 
        XBStoreRedPoint();
    }
 
    private List<StoreModel.StoreData> storelist = null;
    public void XBStoreRedPoint()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.HappyFindTreasure)) return;
 
        ulong moneyNum = UIHelper.GetMoneyCnt(25);
        for (int i = 11; i < 14; i++)
        {
            storelist = StoreModel.Instance.TryGetStoreDatas((StoreFunc)i);
            if (storelist.Count > 0)
            {
                List<StoreModel.StoreData> orderlist = new List<StoreModel.StoreData>();
                orderlist.AddRange(storelist);
                orderlist.Sort(CompareByMoney);
                if (moneyNum >= (ulong)orderlist[0].storeConfig.MoneyNumber)
                {
                    xbStoreRed.state = RedPointState.Simple;
                    return;
                }
            }
        }
        xbStoreRed.state = RedPointState.None;
    }
 
    public int CompareByMoney(StoreModel.StoreData start, StoreModel.StoreData end)
    {
        int money1 = start.storeConfig.MoneyNumber;
        int money2 = end.storeConfig.MoneyNumber;
        if (money1.CompareTo(money2) != 0) return money1.CompareTo(money2);
        int index1 = storelist.IndexOf(start);
        int index2 = storelist.IndexOf(end);
        if (index1.CompareTo(index2) != 0) return index1.CompareTo(index2);
        return 0;
    }
    #endregion
}
 
public class XBTypeInfo
{
    public int xbType;   // 1 极品寻宝 2 符印寻宝 
    public int luckValue;
    public int freeCountToday;      //今日已免费寻宝次数
    public int treasureCount;        //已寻宝总次数
    public int treasureCountToday;        //今日已寻宝总次数
    public int treasureCntAward;        //累计寻宝次数对应奖励领奖状态,按奖励记录索引二进制记录是否已领取
    public Dictionary<int, int> gridLimitCntDict;        //<有限制抽取次数的格子编号,已抽到次数> 有限制抽取次数的格子次数信息
}
 
public class XBFuncSet
{
    public int xbType;// 1 极品寻宝 2 符印寻宝 
    public int[] xbNums;
    public int[] xbPrices;
    public int[] costToolIds;
    public int[] costToolNums;
    public int[] xbFreeCDs;
    public int[] xbScores;
    public int dailyFreeCount;
}
 
public class XBGetItem
{
    public int gridIndex;
    public int itemId;
    public int count;
    public DateTime createTime;
    public string createTimeStr;
 
    public void SetModel(int index, int id, int count)
    {
        this.gridIndex = index;
        this.itemId = id;
        this.count = count;
        createTime = TimeUtility.ServerNow;
        createTimeStr = TimeUtility.ServerNow.ToString("yyyy-MM-dd HH:mm:ss");
    }
}
 
public enum HappXBTitle
{
    Best = 1,
    Rune = 2,
    //Store = 3,
    //Warehouse = 4,
    GatherSoul = 4, //聚魂寻宝
    Gubao1 = 5,
    Gubao2 = 6,
    Gubao3 = 7,
    Gubao4 = 8,
    YunShi1 = 105,
    YunShi2 = 106,
    YunShi3 = 107,
    YunShi4 = 108,
}