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
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 void UpdateHeroCollectInfo(HB122_tagSCHeroInfo netPack)
    {
        for (int i = 0; i < netPack.HeroCnt; i++)
        {
            heroCollectInfoDic[(int)netPack.HeroInfoList[i].HeroID] = netPack.HeroInfoList[i];
        }
        // allHeroBookPer = GetHeroCollectBookPer();
        OnHeroCollectEvent?.Invoke();
        UpdateHeroBookRedpoint();
    }
 
 
    // 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;
            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)
        {
            heroCollectList.AddRange(heroCollectDict[quality]);
        }
    }
 
    //图鉴总上限等级 = 图鉴星级上限 + 图鉴突破上限
    public int GetHeroBookMaxLevel(int heroID, int quality)
    {
        return GetMaxStarCount(heroID, quality) + HeroBreakConfig.GetMaxBreakLv(heroID);
    }
 
    public int GetHeroBookLevel(int heroID)
    {
        if (heroCollectInfoDic.ContainsKey(heroID))
        {
            return heroCollectInfoDic[heroID].BookStarLV + heroCollectInfoDic[heroID].BookBreakLV;
        }
        return 0;
    }
 
    //分为0未获得、1可激活、2常规、3突破升级、4、星升级、5已满级
    public int GetHeroBookState(int heroID, int quality)
    {
        int funcState = 0;
 
        HB122_tagSCHeroInfo.tagSCHero colData;
        TryGetHeroBookInfo(heroID, out colData);
        // int maxBreakLV = colData.BookBreakLVH; //历史最高突破等级
        // int maxStarLV = colData.BookStarLVH;  //历史最高星级
 
        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;
    // }
}