lcy
12 小时以前 a2a86b160ae0a0f982edd3749ed4c1fa0d517556
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
using System;
using System.Collections.Generic;
using UnityEngine;
 
public partial class PhantasmPavilionManager : GameSystemManager<PhantasmPavilionManager>
{
    public event Action<PhantasmPavilionType> OnShowItemListChange;
    private PhantasmPavilionType m_nowType;
    public PhantasmPavilionType nowType
    {
        get
        {
            return m_nowType;
        }
        set
        {
            if (m_nowType == value)
                return;
            m_nowType = value;
            OnShowItemListChange?.Invoke(value);
        }
    }
 
    public event Action<int> OnSelectItemIdChange;
    private int m_selectId;
    public int selectId
    {
        get { return m_selectId; }
        set
        {
            if (m_selectId == value)
                return;
            m_selectId = value;
            RemoveNewHero(nowType, value);
            OnSelectItemIdChange?.Invoke(value);
        }
    }
 
 
    //<类型,<id,PhantasmPavilionData>>
    public Dictionary<PhantasmPavilionType, Dictionary<int, PhantasmPavilionData>> dataDict = new Dictionary<PhantasmPavilionType, Dictionary<int, PhantasmPavilionData>>();
    public event Action OnUpdateModelInfoEvent;
    public event Action OnUpdateFacePicInfo;
    public event Action OnUpdateChatBoxInfoEvent;
    public event Action OnUpdateTitleInfoEvent;
    public event Action OnUpdateFaceInfoEvent;
    public event Action OnTimeOut;
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitializeEvent;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
        PlayerDatas.Instance.playerDataRefreshEvent += OnPlayerDataRefreshEvent;
        PackManager.Instance.RefreshItemEvent += OnRefreshItemEvent;
        GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
        InitTable();
        InitTabRedPoint();
    }
 
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitializeEvent;
        DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent -= OnPlayerLoginOk;
        PlayerDatas.Instance.playerDataRefreshEvent -= OnPlayerDataRefreshEvent;
        PackManager.Instance.RefreshItemEvent -= OnRefreshItemEvent;
        GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
    }
 
    private void OnSecondEvent()
    {
        CheckTimeOut();
    }
 
 
 
 
    private void OnRefreshItemEvent(PackType type, int arg2, int arg3)
    {
        if (type != PackType.Item)
            return;
        UpdateRedPoint();
    }
 
    private void OnPlayerLoginOk()
    {
        InitNowIDDict();
        LoadLocal();
        RefreshAttr();
        UpdateRedPoint();
    }
 
    public void OnBeforePlayerDataInitializeEvent()
    {
        dataDict.Clear();
        nowIDDict.Clear();
    }
    private void OnPlayerDataRefreshEvent(PlayerDataType type)
    {
        UpdateNowIDDict(type);
    }
 
    public int GetJumpIndex(PhantasmPavilionType type, int tabType = 0)
    {
        if (!TryGetRowCountMax(type, out int rowCountMax) || type != nowType)
            return 0;
        int id = selectId;
        List<int> list = ShowItemList(type, tabType);
        if (list.IsNullOrEmpty() || !list.Contains(id))
            return 0;
        int index = list.IndexOf(id);
        int rowCount = (int)Math.Ceiling((double)index / rowCountMax);
        return Mathf.Max(0, rowCount - 1);
    }
 
    public void SetSelectItemId(PhantasmPavilionType type, int tabType = 0)
    {
        List<int> list = new List<int>();
        switch (type)
        {
            case PhantasmPavilionType.Model:
                list = ModelConfig.GetTabTypeTitles(tabType);
                break;
            case PhantasmPavilionType.Title:
                list = TitleConfig.GetTabTypeTitles(tabType);
                break;
            default:
                list = GetTableKeys(type);
                break;
        }
        if (list.IsNullOrEmpty() || !TryGetNowShowID(type, out int nowShowID))
            return;
 
        int id = nowShowID;
        if (list.Contains(id))
        {
            selectId = id;
            return;
        }
 
        foreach (var key in list)
        {
            bool isUnlock = IsUnlock(type, key);
            if (isUnlock)
            {
                selectId = key;
                return;
            }
        }
 
        selectId = list[0];
    }
 
 
    // 检查是否满足“通过道具升级”的条件
    public bool CheckCanUpByItem(PhantasmPavilionType type, int id)
    {
        bool isUnlock = IsUnlock(type, id);
        bool isCanStarAdd = HasStarAddAttr(type, id);
        bool isStarMax = IsStarMax(type, id);
        int unlockWay = GetUnlockWay(type, id);
        int unlockValue = GetUnlockValue(type, id);
        if (!isUnlock || !isCanStarAdd || isStarMax || unlockWay != 2)
            return false;
        int itemId = unlockValue;
        // 道具配置不存在
        if (!ItemConfig.HasKey(itemId))
            return false;
 
        ItemConfig itemConfig = ItemConfig.Get(itemId);
 
        // 玩家等级不足
        if (itemConfig.UseLV > PlayerDatas.Instance.baseData.LV)
            return false;
 
        // 道具数量不足
        var hasCnt = PackManager.Instance.GetItemCountByID(PackType.Item, itemId);
        int upNeedCnt = GetUpNeedCnt(type, id);
        if (hasCnt < upNeedCnt)
            return false;
 
        return true;
    }
 
 
 
    public void ShowFace(ImageEx imgFace, UIEffectPlayer spine, UIFrame uiFrame, EllipseMask ellipseMask, int id)
    {
        PhantasmPavilionType type = PhantasmPavilionType.Face;
        int UnlockWay = GetUnlockWay(type, id);
        int unlockValue = GetUnlockValue(type, id);
        int resourceType = GetResourceType(type, id);
        string resourceValue = GetResourceValue(type, id);
        if (UnlockWay == 3 && resourceValue == "")
        {
            int heroID = unlockValue;
            if (!HeroConfig.HasKey(heroID))
                return;
            HeroConfig heroConfig = HeroConfig.Get(heroID);
            int skinID = heroConfig.SkinIDList[0];
            if (!HeroSkinConfig.HasKey(skinID))
                return;
            HeroSkinConfig skinConfig = HeroSkinConfig.Get(skinID);
            var sprite = UILoader.LoadSprite("HeroHead", skinConfig.SquareIcon);
            if (sprite == null)
            {
                Show(imgFace, spine, uiFrame, resourceType, "herohead_default", null, ellipseMask);
            }
            else
            {
                Show(imgFace, spine, uiFrame, resourceType, string.Empty, sprite, ellipseMask);
            }
        }
        else
        {
            resourceValue = GetResourceValue(type, id);
            Show(imgFace, spine, uiFrame, resourceType, resourceValue, null, ellipseMask);
        }
 
    }
 
    public void Show(ImageEx imgFace, UIEffectPlayer spine, UIFrame uiFrame, int resourceType, string resourceValue, Sprite sprite = null, EllipseMask ellipseMask = null)
    {
        spine.Stop();
 
        switch (resourceType)
        {
            // 静态图
            case 1:
                imgFace.enabled = true;
                spine.enabled = false;
                uiFrame.enabled = false;
 
                if (sprite == null)
                {
                    if (!IconConfig.HasKey(resourceValue))
                        return;
                    imgFace.SetSprite(resourceValue);
                }
                else
                {
                    imgFace.overrideSprite = sprite;
                }
                break;
            case 2: // spine
                imgFace.enabled = true;
                uiFrame.enabled = false;
                spine.enabled = true;
 
                imgFace.sprite = null;
                imgFace.overrideSprite = null;
 
                spine.effectId = int.Parse(resourceValue);
                spine.isPlaySpineLoop = true;
                spine.Play();
                break;
            // 序列帧
            case 3:
                imgFace.enabled = true;
                spine.enabled = false;
                uiFrame.enabled = true;
 
                imgFace.sprite = null;
                imgFace.overrideSprite = null;
 
                if (!UIFrameMgr.Inst.ContainsDynamicImage(resourceValue))
                    break;
                //List<UnityEngine.Sprite> spriteList = UIFrameMgr.Inst.GetDynamicImage(resourceValue);
                // if (!spriteList.IsNullOrEmpty())
                // {
                //     imgFace.rectTransform.sizeDelta = new Vector2(spriteList[0].rect.width, spriteList[0].rect.height);
                // }
 
                uiFrame.ResetFrame(resourceValue);
                uiFrame.enabled = true;
                break;
        }
 
        if (ellipseMask != null)
        {
            ellipseMask.UpdateChildrenStencil();
        }
    }
 
    public bool TryGetInfo(PhantasmPavilionType type, int id, out PhantasmPavilionData info)
    {
        info = null;
        return dataDict.TryGetValue(type, out var dict) && dict.TryGetValue(id, out info);
    }
 
    // 有没有属性
    public bool HasInitAttr(PhantasmPavilionType type, int id)
    {
        if (!Has(type, id))
            return false;
        int[] attrIDList = GetAttrIDList(type, id);
        int[] initAttrValueList = GetInitAttrValueList(type, id);
        if (attrIDList.IsNullOrEmpty() || initAttrValueList.IsNullOrEmpty() || attrIDList.Length != initAttrValueList.Length)
            return false;
        return true;
    }
 
 
    //是否已经升满星
    public bool IsStarMax(PhantasmPavilionType type, int id)
    {
        if (!HasStarAddAttr(type, id))
            return false;
        if (!TryGetInfo(type, id, out PhantasmPavilionData info))
            return false;
        int starMax = GetStarMax(type, id);
        return info.Star >= starMax;
    }
 
    // 是否可升星
    public bool HasStarAddAttr(PhantasmPavilionType type, int id)
    {
        if (!Has(type, id))
            return false;
        if (!HasInitAttr(type, id))
            return false;
        int[] initAttrValueList = GetInitAttrValueList(type, id);
        int[] AttrPerStarAddList = GetAttrPerStarAddList(type, id);
        if (initAttrValueList.IsNullOrEmpty() || AttrPerStarAddList.IsNullOrEmpty() || initAttrValueList.Length != AttrPerStarAddList.Length)
            return false;
        return true;
    }
 
    public bool IsUsing(PhantasmPavilionType type, int id)
    {
        if (!Has(type, id))
            return false;
        if (!TryGetNowShowID(type, out int result))
            return false;
        return result == id;
    }
 
    public List<int> ShowItemList(PhantasmPavilionType type, int tabType = 0)
    {
        var resList = new List<int>();
        switch (type)
        {
            case PhantasmPavilionType.Model:
                resList = ModelConfig.GetTabTypeTitles(tabType);
                break;
            case PhantasmPavilionType.Title:
                resList = TitleConfig.GetTabTypeTitles(tabType);
                break;
            default:
                resList = GetTableKeys(type);
                break;
        }
        resList.Sort((int a, int b) => Cmp(a, b, type));
        return resList;
    }
 
    public int Cmp(int a, int b, PhantasmPavilionType type)
    {
        // 获取 a 和 b 的解锁状态
        int stateA = (int)GetUnLockState(type, a);
        int stateB = (int)GetUnLockState(type, b);
 
        // 将状态重新定义为优先级排序数值:已激活(2) > 可激活(1) > 未激活(0)
        int priorityA = stateA == 2 ? 0 : (stateA == 1 ? 1 : 2);
        int priorityB = stateB == 2 ? 0 : (stateB == 1 ? 1 : 2);
 
 
        if (priorityA != priorityB)
        {
            return priorityA.CompareTo(priorityB);
        }
        return a.CompareTo(b);
    }
 
    // 除道具解锁外,其他方式暂默认永久
    // 是否有时效 true 有时间限制 false 永久(无时间限制)
    public bool IsLimitTime(PhantasmPavilionType type, int id)
    {
        if (!Has(type, id))
            return false;
 
        // 如果不是“道具解锁”方式,也视为永久
        if (GetUnlockWay(type, id) != (int)PhantasmPavilionUnlockWay.Item)
            return false;
 
        // 物品存在且是“道具解锁”,取决于有效期
        int expireMinutes = GetExpireMinutes(type, id);
        return expireMinutes > 0;
    }
 
    //物品是否已过期
    private bool IsExpired(PhantasmPavilionData info, PhantasmPavilionUnlockWay unlockWay)
    {
        // 只有“道具”方式才需要检查时效,武将解锁(Hero) 或 默认(Activate) 视为永久
        if (unlockWay != PhantasmPavilionUnlockWay.Item)
            return false;
 
        // EndTime == 0 表示永久
        bool isLimitedTime = info.EndTime > 0;
        if (!isLimitedTime)
            return false;
 
        // 是限时道具,检查当前时间是否已经超过了截止时间
        bool timeHasPassed = info.EndTime < TimeUtility.AllSeconds;
        return timeHasPassed;
    }
 
    // 除道具解锁外,其他方式暂默认永久
    // 1 - 默认解锁,即创角就可用的
    // 2 - 道具解锁,支持时效、升级, Value配物品ID
    // 3 - 关联武将解锁,Value配武将ID
    public bool IsUnlock(PhantasmPavilionType type, int id)
    {
        // 配置表中不存在,视为未解锁
        if (!Has(type, id))
            return false;
 
        int unlockWayValue = GetUnlockWay(type, id);
        int unlockValue = GetUnlockValue(type, id);
        // 解锁方式无效
        if (!Enum.IsDefined(typeof(PhantasmPavilionUnlockWay), unlockWayValue))
            return false;
        var unlockWay = (PhantasmPavilionUnlockWay)unlockWayValue;
 
        switch (unlockWay)
        {
            case PhantasmPavilionUnlockWay.Activate:
                return true;
            case PhantasmPavilionUnlockWay.Hero:
                bool hasHero = HeroManager.Instance.HasHero(unlockValue);
                return hasHero;
            case PhantasmPavilionUnlockWay.Item:
                // 封包里没有
                if (!TryGetInfo(type, id, out var info))
                    return false;
                // 玩家数据中的状态是“未激活”
                if (!info.State)
                    return false;
                // 是否为“已过期的道具”
                if (IsExpired(info, unlockWay))
                    return false;
                return true;
            default:
                return false;
        }
    }
 
    /// <summary>
    /// 获得当前状态
    /// </summary>
    /// <returns>0 - 未激活, 1 - 可激活, 2 - 已激活</returns>
    public PhantasmPavilionState GetUnLockState(PhantasmPavilionType type, int id)
    {
        // 配置表中不存在,视为“未激活”
        if (!Has(type, id))
            return PhantasmPavilionState.Locked;
 
        // 已经解锁
        if (IsUnlock(type, id))
            return PhantasmPavilionState.Activated;
 
        // 运行到这里,说明物品是“未激活”或“已过期”状态 (IsUnlock 返回 false)
        // 无效的解锁方式
        int unlockWayValue = GetUnlockWay(type, id);
        if (!Enum.IsDefined(typeof(PhantasmPavilionUnlockWay), unlockWayValue))
            return PhantasmPavilionState.Locked;
 
        var unlockWay = (PhantasmPavilionUnlockWay)unlockWayValue;
        int unlockValue = GetUnlockValue(type, id);
 
        switch (unlockWay)
        {
            // 检查道具激活条件
            case PhantasmPavilionUnlockWay.Item:
                return CheckCanActivateByItem(type, id, unlockValue)
                    ? PhantasmPavilionState.CanActivate
                    : PhantasmPavilionState.Locked;
            // 检查武将激活条件
            case PhantasmPavilionUnlockWay.Hero:
                int heroID = unlockValue;
                return HeroManager.Instance.HasHero(heroID)
                    ? PhantasmPavilionState.Activated
                    : PhantasmPavilionState.Locked;
            default:
                return PhantasmPavilionState.Locked;
        }
    }
 
    // 检查是否满足“通过道具激活”的条件
    private bool CheckCanActivateByItem(PhantasmPavilionType type, int id, int itemId)
    {
        // 道具配置不存在
        if (!ItemConfig.HasKey(itemId))
            return false;
 
        ItemConfig itemConfig = ItemConfig.Get(itemId);
 
        // 玩家等级不足
        if (itemConfig.UseLV > PlayerDatas.Instance.baseData.LV)
            return false;
 
        // 道具数量不足
        var hasCnt = PackManager.Instance.GetItemCountByID(PackType.Item, itemId);
        int unlockNeedCnt = GetUnlockNeedCnt(type, id);
        if (hasCnt < unlockNeedCnt)
            return false;
 
        return true;
    }
 
    public void CheckTimeOut()
    {
        bool isTimeOut = false;
        var expiredItems = new Dictionary<PhantasmPavilionType, List<int>>();
 
        if (dataDict.IsNullOrEmpty())
            return;
 
        // 单次遍历:检查限时物品并收集过期项目
        foreach (var kv in dataDict)
        {
            var type = kv.Key;
            var dict = kv.Value;
            foreach (var kv2 in dict)
            {
                var id = kv2.Key;
                var data = kv2.Value;
 
                // 只检查限时物品
                if (!IsLimitTime(type, id))
                    continue;
 
                int unlockWay = GetUnlockWay(type, id);
                bool isExpired = IsExpired(data, (PhantasmPavilionUnlockWay)unlockWay);
 
                if (isExpired)
                {
                    isTimeOut = true;
 
                    if (!expiredItems.ContainsKey(type))
                    {
                        expiredItems[type] = new List<int>();
                    }
                    if (!expiredItems[type].Contains(id))
                    {
                        expiredItems[type].Add(id);
                    }
                }
            }
        }
 
        // 如果没有过期物品,直接返回
        if (!isTimeOut)
            return;
 
        // 从dataDict中移除过期的项目
        if (!expiredItems.IsNullOrEmpty())
        {
            foreach (var kv in expiredItems)
            {
                var type = kv.Key;
                var list = kv.Value;
                if (dataDict.ContainsKey(type))
                {
                    foreach (var id in list)
                    {
                        dataDict[type].Remove(id);
                    }
                }
            }
        }
 
        RefreshAttr();
        UpdateRedPoint();
        OnTimeOut?.Invoke();
    }
 
    #region 收封包
    public event Action OnUpdateModelStarAdd;
    public void UpdateModelInfo(HB119_tagSCModelInfo vNetData)
    {
        if (vNetData == null)
            return;
 
        PhantasmPavilionType type = PhantasmPavilionType.Model;
        if (!dataDict.ContainsKey(type))
        {
            dataDict.Add(type, new Dictionary<int, PhantasmPavilionData>());
        }
 
        // 判断当前封包是否有任何一项的星级大于之前的星级
        bool hasStarIncreased = false;
        foreach (var item in vNetData.ModelList)
        {
            if (dataDict[type].ContainsKey((int)item.ModelID))
            {
                var oldData = dataDict[type][(int)item.ModelID];
                if (item.Star > oldData.Star)
                {
                    hasStarIncreased = true;
                    break;
                }
            }
        }
 
        foreach (var item in vNetData.ModelList)
        {
            if (!dataDict[type].ContainsKey((int)item.ModelID))
            {
                dataDict[type][(int)item.ModelID] = new PhantasmPavilionData();
            }
 
            var data = dataDict[type][(int)item.ModelID];
            data.ID = item.ModelID;
            data.State = item.State == 1;
            data.EndTime = item.EndTime;
            data.Star = item.Star;
        }
        RefreshAttr();
        UpdateRedPoint();
        if (hasStarIncreased)
        {
            OnUpdateModelStarAdd?.Invoke();
        }
        OnUpdateModelInfoEvent?.Invoke();
    }
 
 
    public void UpdateTitleInfo(HB126_tagSCTitleInfo vNetData)
    {
        if (vNetData == null)
            return;
        PhantasmPavilionType type = PhantasmPavilionType.Title;
        if (!dataDict.ContainsKey(type))
        {
            dataDict.Add(type, new Dictionary<int, PhantasmPavilionData>());
        }
 
        foreach (var item in vNetData.TitleList)
        {
            if (!dataDict[type].ContainsKey((int)item.TitleID))
            {
                dataDict[type][(int)item.TitleID] = new PhantasmPavilionData();
            }
 
            var data = dataDict[type][(int)item.TitleID];
            data.ID = item.TitleID;
            data.State = item.State == 1;
            data.EndTime = item.EndTime;
            data.Star = item.Star;
        }
        RefreshAttr();
        UpdateRedPoint();
        OnUpdateTitleInfoEvent?.Invoke();
    }
 
 
    public void UpdateChatBoxInfo(HB127_tagSCChatBoxInfo vNetData)
    {
        if (vNetData == null)
            return;
        PhantasmPavilionType type = PhantasmPavilionType.ChatBox;
        if (!dataDict.ContainsKey(type))
        {
            dataDict.Add(type, new Dictionary<int, PhantasmPavilionData>());
        }
 
        foreach (var item in vNetData.BoxList)
        {
            if (!dataDict[type].ContainsKey((int)item.BoxID))
            {
                dataDict[type][(int)item.BoxID] = new PhantasmPavilionData();
            }
 
            var data = dataDict[type][(int)item.BoxID];
            data.ID = item.BoxID;
            data.State = item.State == 1;
            data.EndTime = item.EndTime;
            data.Star = item.Star;
        }
        RefreshAttr();
        UpdateRedPoint();
        OnUpdateChatBoxInfoEvent?.Invoke();
    }
 
 
    public void UpdateFaceInfo(HB117_tagMCFaceInfo vNetData)
    {
        if (vNetData == null)
            return;
        PhantasmPavilionType type = PhantasmPavilionType.Face;
        if (!dataDict.ContainsKey(type))
        {
            dataDict.Add(type, new Dictionary<int, PhantasmPavilionData>());
        }
 
        foreach (var item in vNetData.FaceList)
        {
            if (!dataDict[type].ContainsKey((int)item.FaceID))
            {
                dataDict[type][(int)item.FaceID] = new PhantasmPavilionData();
            }
 
            var data = dataDict[type][(int)item.FaceID];
            data.ID = item.FaceID;
            data.State = item.State == 1;
            data.EndTime = item.EndTime;
            data.Star = item.Star;
        }
        RefreshAttr();
        UpdateRedPoint();
        OnUpdateFaceInfoEvent?.Invoke();
    }
 
 
    public void UpdateFacePicInfo(HB118_tagMCFacePicInfo vNetData)
    {
        if (vNetData == null)
            return;
        PhantasmPavilionType type = PhantasmPavilionType.FacePic;
        if (!dataDict.ContainsKey(type))
        {
            dataDict.Add(type, new Dictionary<int, PhantasmPavilionData>());
        }
 
        foreach (var item in vNetData.FacePicList)
        {
            if (!dataDict[type].ContainsKey((int)item.FacePicID))
            {
                dataDict[type][(int)item.FacePicID] = new PhantasmPavilionData();
            }
 
            var data = dataDict[type][(int)item.FacePicID];
            data.ID = item.FacePicID;
            data.State = item.State == 1;
            data.EndTime = item.EndTime;
            data.Star = item.Star;
        }
        RefreshAttr();
        UpdateRedPoint();
        OnUpdateFacePicInfo?.Invoke();
    }
    #endregion
 
    public void SendOPPack(PhantasmPavilionType type, PhantasmPavilionOperation op, uint opID)
    {
        SendB225Pack((byte)type, (byte)op, opID);
    }
 
    public void SendB225Pack(byte type, byte opType, uint opID)
    {
        var pack = new CB225_tagCSHJGOP();
        pack.Type = type;                     // 类型 1-形象;2-头像;3-头像框;4-气泡;5-称号    
        pack.OPType = opType;                 // 操作 1-激活;2-佩戴;3-卸下;4-升星
        pack.OPID = opID;                     // 操作对应的ID,如形象ID等
        GameNetSystem.Instance.SendInfo(pack);
    }
 
}
 
public class PhantasmPavilionData
{
    public uint ID;             //ID
    public bool State;          //是否已激活
    public uint EndTime;        //到期时间戳,0为永久
    public byte Star;           //星级
}
 
//对应发包 1-形象;2-头像;3-头像框;4-气泡;5-称号    
public enum PhantasmPavilionType
{
    Model = 1,                  // 形象
    Face,                       // 头像
    FacePic,                    // 头像框
    ChatBox,                    // 聊天气泡
    Title,                      //称号
}
 
//对应发包 1-激活;2-佩戴;3-卸下;4-升星
public enum PhantasmPavilionOperation
{
    Activate = 1,               // 激活
    Wear,                       // 佩戴
    Remove,                     // 卸下
    UpgradeStar,                // 升星
}
 
public enum PhantasmPavilionUnlockWay
{
    Activate = 1,               // 默认(创角色就可以用的)
    Item,                       // 道具
    Hero,                       // 武将
}
 
/// 幻境阁物品的状态
public enum PhantasmPavilionState
{
    // 未激活 (0)
    Locked = 0,
    // 可激活 (1) - 满足激活条件,但尚未激活
    CanActivate = 1,
    //已激活 (2) - 已激活且未过期
    Activated = 2
}