lcy
2026-06-10 bcbbdae9f85dbb3efd58f0eaafe9f548caa5d923
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
 
using UnityEngine;
 
//图鉴和皮肤
public partial class HeroUIManager : GameSystemManager<HeroUIManager>
{
 
 
    public Dictionary<int, List<int>> heroCollectDict { get; private set; } = new Dictionary<int, List<int>>();  //武将图鉴按品质列表
    public List<int> heroCollectList = new List<int>(); //武将图鉴列表
    public List<int> selectHeroCollectList = new List<int>();    //武将列表界面 筛选
    public int selectCollectHeroID; //选中的武将id 用于升级
 
    public int selectForPreviewHeroID; //选中的武将id 用于预览
 
    //图鉴和皮肤的激活情况
    Dictionary<int, HB122_tagSCHeroInfo.tagSCHero> heroCollectInfoDic = new Dictionary<int, HB122_tagSCHeroInfo.tagSCHero>();
 
    // public int allHeroBookPer; //全体武将的图鉴激活百分比
    public event Action OnHeroCollectEvent;
    public event Action<int, int, int> OnHeroSkinStateChanged;// 皮肤状态变化事件 (参数: HeroID, SkinID, 新的State)
    public void UpdateHeroCollectInfo(HB122_tagSCHeroInfo netPack)
    {
        for (int i = 0; i < netPack.HeroCnt; i++)
        {
            var newHeroData = netPack.HeroInfoList[i];
            int heroID = (int)newHeroData.HeroID;
 
            // 1. 调用封装好的方法:检测并触发新皮肤事件
            CheckAndTriggerNewSkinEvents(heroID, newHeroData);
 
            // 2. 更新字典为最新的网络包数据
            heroCollectInfoDic[heroID] = newHeroData;
        }
 
        // allHeroBookPer = GetHeroCollectBookPer();
        UpdateHeroBookRedpoint();
        RefreshAllSkinAttr();
        UpdateHeroCardSkinRedpoint();
        UpdateHeroBookRedpoint();
        OnHeroCollectEvent?.Invoke();
    }
 
    public event Action<int, int> OnNewSkinAcquired;// 当玩家获得新皮肤(激活皮肤)时触发的事件 HeroID SkinID
 
    /// <summary>
    /// 检查并触发获得新皮肤的事件
    /// </summary>
    private void CheckAndTriggerNewSkinEvents(int heroID, HB122_tagSCHeroInfo.tagSCHero newHeroData)
    {
        // 如果新数据中没有皮肤信息,直接返回
        if (newHeroData?.SkinList == null || newHeroData?.SkinCnt <= 0) return;
 
        // 尝试获取旧数据
        bool isOldHeroExist = heroCollectInfoDic.TryGetValue(heroID, out var oldHeroData);
 
        for (int j = 0; j < newHeroData.SkinCnt; j++)
        {
            var newSkin = newHeroData.SkinList[j];
            
            // 如果新皮肤未激活,直接跳过当前循环,检查下一个皮肤
            if (newSkin.State <= 0) continue;
 
            bool isNewlyAcquired = false;
 
            if (!isOldHeroExist)
            {
                // 场景A:这是一个全新的武将,且自带了已激活的非默认皮肤
                isNewlyAcquired = true;
            }
            else
            {
                // 场景B:已有的老武将,需要对比旧数据看这个皮肤是不是刚刚才获得的
                bool foundOldSkin = false;
 
                if (oldHeroData.SkinList != null)
                {
                    for (int k = 0; k < oldHeroData.SkinCnt; k++)
                    {
                        var oldSkin = oldHeroData.SkinList[k];
                        if (oldSkin.SkinID == newSkin.SkinID)
                        {
                            foundOldSkin = true;
                            // 如果旧数据中该皮肤未激活 (State == 0),现在激活了,算作获得新皮肤
                            if (oldSkin.State == 0)
                            {
                                isNewlyAcquired = true;
                            }
                            break; 
                        }
                    }
                }
 
                // 如果旧武将数据里压根没有这个皮肤的数据(现在是激活状态),也算作获得新皮肤
                if (!foundOldSkin)
                {
                    isNewlyAcquired = true;
                }
            }
 
            // 如果最终判定为“全新获得”的皮肤,则触发事件
            if (isNewlyAcquired)
            {
                OnNewSkinAcquired?.Invoke(heroID, (int)newSkin.SkinID);
            }
        }
    }
 
    // public int GetHeroCollectBookPer()
    // {
    //     int per = 0;
    //     foreach (var kv in heroCollectInfoDic)
    //     {
    //         var config = HeroQualityConfig.Get(HeroConfig.Get(kv.Key).Quality);
    //         if (kv.Value.BookInitState != 2)
    //             continue;
    //         per += config.BookInitAddPer;
    //         per += kv.Value.BookStarLV * config.BookStarAddPer;
    //         per += kv.Value.BookBreakLV * config.BookBreakLVAddPer;
    //     }
    //     return per;
    // }
 
    public bool TryGetHeroBookInfo(int heroID, out HB122_tagSCHeroInfo.tagSCHero heroData)
    {
        if (heroCollectInfoDic.ContainsKey(heroID))
        {
            heroData = heroCollectInfoDic[heroID];
            return true;
        }
        heroData = new HB122_tagSCHeroInfo.tagSCHero();
        return false;
    }
 
 
    public void SortHeroCollectList()
    {
 
        var heroIDs = HeroConfig.GetKeys().ToList();
 
        int job = 0;
        int country = 0;
        int hurtType = 0;
        int fightAttrType = 0;
        int specialAttrType = 0;
        if (!selectHeroCollectList.IsNullOrEmpty())
        {
            job = selectHeroCollectList[0];
            country = selectHeroCollectList[1];
            hurtType = selectHeroCollectList[2];
            fightAttrType = selectHeroCollectList[3];
            specialAttrType = selectHeroCollectList[4];
        }
 
        heroCollectDict.Clear();
        foreach (var heroID in heroIDs)
        {
            HeroConfig heroConfig = HeroConfig.Get(heroID);
            if (heroConfig.PlayerCanUse == 0)
                continue;
            // 开服第x天显示图鉴,0表示不限制开服天
            if (HasOpenCollectionDayLimit(heroID) && !IsOpenCollectionDayMet(heroID))
                continue;
            if (!heroCollectDict.ContainsKey(heroConfig.Quality))
            {
                heroCollectDict[heroConfig.Quality] = new List<int>();
            }
 
            //0代表全部, 同级别是可复选,不同级别为且的关系
            bool isMatch = true;
            if (job != 0)
            {
                isMatch = isMatch && (job & (1 << heroConfig.Class)) > 0;
            }
            if (country != 0)
            {
                isMatch = isMatch && (country & (1 << heroConfig.Country)) > 0;
            }
            if (hurtType != 0)
            {
                isMatch = isMatch && (hurtType & (1 << heroConfig.HurtType)) > 0;
            }
            if (fightAttrType != 0)
            {
                isMatch = isMatch && (fightAttrType & (1 << heroConfig.Specialty)) > 0;
            }
            if (specialAttrType != 0)
            {
                bool isMatch2 = false;
                for (int i = 0; i < heroConfig.Specialty2.Length; i++)
                {
                    isMatch2 = (specialAttrType & (1 << heroConfig.Specialty2[i])) > 0;
                    if (isMatch2)
                        break;
                }
                isMatch = isMatch && isMatch2;
            }
            if (!isMatch)
            {
                continue;
            }
 
            heroCollectDict[heroConfig.Quality].Add(heroID);
        }
 
        heroCollectList.Clear();
        //按品质倒序加入
        var _list = heroCollectDict.Keys.ToList();
        _list.Reverse();
        foreach (var quality in _list)
        {
            // 排序逻辑:优先按阵营分组排序,同阵营中按开服天数降序排序,最后按武将ID排序
            heroCollectDict[quality].Sort((a, b) =>
            {
                var cfgA = HeroConfig.Get(a);
                var cfgB = HeroConfig.Get(b);
 
                // 1. 按阵营(国家)排序
                if (cfgA.Country != cfgB.Country)
                {
                    return cfgA.Country.CompareTo(cfgB.Country);
                }
 
                // 2. 同阵营中,开服天数越大的排序越靠前 (降序)
                if (cfgA.OpenCollectionDay != cfgB.OpenCollectionDay)
                {
                    return cfgB.OpenCollectionDay.CompareTo(cfgA.OpenCollectionDay);
                }
 
                // 3. 其他条件一致时,默认按武将ID升序
                return a.CompareTo(b);
            });
            
            heroCollectList.AddRange(heroCollectDict[quality]);
        }
    }
 
 
    //分为0未获得、1可激活、2常规、(3突破升级、4、星升级、5已满级 废弃功能保留逻辑)
    public int GetHeroBookState(int heroID, int quality)
    {
        int funcState = 0;
 
        HB122_tagSCHeroInfo.tagSCHero colData;
        TryGetHeroBookInfo(heroID, out colData);
 
        if (colData.BookInitState == 0)
        {
            funcState = 0;
        }
        else if (colData.BookInitState == 1)
        {
            funcState = 1;
        }
        else
        {
            funcState = 2;
        }
 
        // else if (colData.BookInitState == 2)
        // {
        //     if (GetHeroBookMaxLevel(heroID, quality) == colData.BookBreakLV + colData.BookStarLV)
        //     {
        //         funcState = 5;
        //     }
        //     else if (maxBreakLV + maxStarLV == colData.BookBreakLV + colData.BookStarLV)
        //     {
        //         funcState = 2;
        //     }
        //     else
        //     {
        //         //优先突破升级
        //         if (colData.BookBreakLV < colData.BookBreakLVH)
        //         {
        //             funcState = 3;
        //         }
        //         else
        //         {
        //             funcState = 4;
        //         }
        //     }
 
        // }
        return funcState;
    }
 
    //找到可以操作的图鉴武将
    public int FindHeroIDCanAddCollectAttr(int excludeHeroID = 0)
    {
        foreach (var kv in heroCollectInfoDic)
        {
            if (kv.Key == excludeHeroID)
                continue;
            var state = GetHeroBookState(kv.Key, HeroConfig.Get(kv.Key).Quality);
            if (state == 1 || state == 3 || state == 4)
            {
                return kv.Key;
            }
        }
        return 0;
    }
 
    // public int GetHeroBookPer(int heroID)
    // { 
    //     var config = HeroQualityConfig.Get(HeroConfig.Get(heroID).Quality);
    //     HB122_tagSCHeroInfo.tagSCHero heroData;
    //     TryGetHeroBookInfo(heroID, out heroData);
    //     if (heroData.BookInitState < 2)
    //     { 
    //         return 0;
    //     }
    //     return config.BookInitAddPer + heroData.BookStarLV * config.BookStarAddPer + heroData.BookBreakLV * config.BookBreakLVAddPer;
    // }
 
    #region 皮肤
    //策划去除了升星功能
    //属性分穿戴(武将个体)和全体
    public Dictionary<int, long> allSkinAttrDic = new Dictionary<int, long>();
    int m_selectSkinIndex = -1;
    public event Action OnSkinIndexChanged;
    public int selectSkinIndex
    {
        get { return m_selectSkinIndex; }
        set
        {
            m_selectSkinIndex = value;
            OnSkinIndexChanged?.Invoke();
        }
    }
 
    //全体属性
    public void RefreshAllSkinAttr()
    {
        allSkinAttrDic.Clear();
        foreach (var config in HeroSkinAttrConfig.GetValues())
        {
            var heroID = HeroConfig.GetHeroIDBySkinID(config.SkinID);
            if (heroID == 0)
            {
                Debug.LogError("不存在的皮肤 皮肤属性表配置错误 :" + config.SkinID);
                continue;
            }
            if (!IsHeroSkinActive(heroID, config.SkinID))
            {
                continue;
            }
            for (int i = 0; i < config.RoleAttrIDList.Length; i++)
            {
                if (!allSkinAttrDic.ContainsKey(config.RoleAttrIDList[i]))
                {
                    allSkinAttrDic[config.RoleAttrIDList[i]] = 0;
                }
                allSkinAttrDic[config.RoleAttrIDList[i]] += config.RoleAttrValueList[i];
            }
        }
 
    }
 
    public bool IsHeroSkinActive(int heroID, int skinID)
    {
        //默认皮肤返回true
        if (HeroConfig.Get(heroID).SkinIDList[0] == skinID)
        {
            return true;
        }
        HB122_tagSCHeroInfo.tagSCHero colData;
        TryGetHeroBookInfo(heroID, out colData);
 
        if (colData != null && colData.SkinList != null)
        {
            foreach (var data in colData.SkinList)
            {
                if (data.SkinID != skinID)
                {
                    continue;
                }
                return data.State == 1;
            }
        }
 
        return false;
    }
 
    public long GetSkinAttrValue(int attrID)
    {
        allSkinAttrDic.TryGetValue(attrID, out long value);
        return value;
    }
 
    public int GetSkinAttrPer(int attrID)
    {
        if (PlayerPropertyConfig.baseAttr2perDict.ContainsKey(attrID))
        {
            var pertype = PlayerPropertyConfig.baseAttr2perDict[attrID];
            allSkinAttrDic.TryGetValue(pertype, out long value);
            return (int)(value);
        }
        return 0;
    }
 
    //操作 1-激活;2-选择形象;4-选择属性
    public void SendSkinOP(int heroID, int skinID, int opType, int itemIndex = 0)
    {
        var pack = new CB236_tagCSHeroSkinOP();
        pack.HeroID = (uint)heroID;
        pack.SkinID = (uint)skinID;
        pack.OPType = (byte)opType;
        pack.ItemIndex = (ushort)itemIndex;
        GameNetSystem.Instance.SendInfo(pack);
 
    }
 
    #region 开服天数相关方法
 
    /// <summary>
    /// 检查武将是否配置了开服展示天数限制
    /// </summary>
    /// <param name="heroID">武将ID</param>
    /// <returns>true: 有开服天限制; false: 无限制(OpenCollectionDay==0 或配置不存在)</returns>
    public static bool HasOpenCollectionDayLimit(int heroID)
    {
        HeroConfig heroConfig = HeroConfig.Get(heroID);
        if (heroConfig == null)
            return false;
        return heroConfig.OpenCollectionDay > 0;
    }
 
    /// <summary>
    /// 检查武将是否已满足开服展示天数要求(仅在有限制时调用有意义)
    /// </summary>
    /// <param name="heroID">武将ID</param>
    /// <returns>true: 已满足展示天数; false: 尚未满足</returns>
    public static bool IsOpenCollectionDayMet(int heroID)
    {
        HeroConfig heroConfig = HeroConfig.Get(heroID);
        if (heroConfig == null)
            return false;
        // OpenCollectionDay==0 无限制,视为已满足
        if (heroConfig.OpenCollectionDay <= 0)
            return true;
        return TimeUtility.OpenDay + 1 >= heroConfig.OpenCollectionDay;
    }
 
    /// <summary>
    /// 检查羁绊组合中所有武将是否都满足开服展示天数
    /// 只有配置了开服天限制的武将才需要检查,未配置限制的武将视为满足
    /// </summary>
    /// <param name="fetterConfig">羁绊配置</param>
    /// <returns>true: 所有武将都满足; false: 有武将不满足</returns>
    public static bool IsFetterAllHeroOpen(HeroFetterConfig fetterConfig)
    {
        for (int i = 0; i < fetterConfig.HeroIDList.Length; i++)
        {
            int heroID = fetterConfig.HeroIDList[i];
            // 有限制但未满足 -> 该羁绊不可显示
            if (HasOpenCollectionDayLimit(heroID) && !IsOpenCollectionDayMet(heroID))
                return false;
        }
        return true;
    }
 
    #endregion
 
    #region 皮肤开服天数相关方法
 
    /// <summary>
    /// 检查皮肤是否满足开服天数展示条件
    /// </summary>
    /// <param name="skinID">皮肤ID</param>
    /// <returns>true: 可展示; false: 尚未满足开服天数</returns>
    public static bool IsSkinOpenDayMet(int skinID)
    {
        var skinConfig = HeroSkinConfig.Get(skinID);
        if (skinConfig == null || skinConfig.OpenDay <= 0)
            return true;  // OpenDay <= 0 表示无限制
        return TimeUtility.OpenDay + 1 >= skinConfig.OpenDay;
    }
 
    /// <summary>
    /// 判断武将在考虑 OpenDay 限制后,是否有至少一个可显示的非默认皮肤
    /// 默认皮肤(SkinIDList[0])不受 OpenDay 控制,始终可用
    /// </summary>
    /// <param name="heroID">武将ID</param>
    /// <returns>true: 有至少一个非默认皮肤可显示; false: 仅默认皮肤可显示</returns>
    public static bool HasHeroAnyAvailableSkin(int heroID)
    {
        var heroConfig = HeroConfig.Get(heroID);
        if (heroConfig == null || heroConfig.SkinIDList.Length <= 1)
            return false;  // 只有默认皮肤或没有皮肤
 
        // 从索引 1 开始检查非默认皮肤
        for (int i = 1; i < heroConfig.SkinIDList.Length; i++)
        {
            if (IsSkinOpenDayMet(heroConfig.SkinIDList[i]))
                return true;
        }
        return false;
    }
 
    #endregion
 
    #endregion
}