yyl
2 天以前 973edc44a04dceb8b48a32ca912e6167f86189d4
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
 
//武将相关界面的操作数据管理
public partial class HeroUIManager : GameSystemManager<HeroUIManager>
{
    #region 武将列表界面
    public List<string> heroSortList { get; private set; } = new List<string>();  //上阵为主线的 GUID列表 
    public int selectHeroListJob = 0;    //武将列表界面 筛选职业
    public int selectHeroListCountry = 0;    //武将列表界面筛选国家
    public string selectHeroGuid; //选中的武将id
    #endregion
 
    public WaitHeroFuncResponse waitResponse;    //请求武将功能,与服务端交互
 
    public const float lihuiScale = 0.6f;   //立绘缩放大小
 
    //用于非上阵武将战力变化时 武将ID:上次战力
    public KeyValuePair<string, long> lastFightPower = new KeyValuePair<string, long>(); 
 
    public override void Init()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        HeroManager.Instance.onHeroChangeEvent += OnHeroChangeEvent;
        ParseConfig();
    }
 
    public override void Release()
    {
        DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
        HeroManager.Instance.onHeroChangeEvent -= OnHeroChangeEvent;
    }
 
    void ParseConfig()
    {
        var config = FuncConfigConfig.Get("HeroRebirth");
        payBackMoneyType = int.Parse(config.Numerical1);
        rebornAwakeHeroMaxCount = int.Parse(config.Numerical2);
    }
 
    public void OnBeforePlayerDataInitialize()
    {
        heroSortList.Clear();
        heroOnTeamSortList.Clear();
        awakeRebirthCnt = 0;
        waitResponse = default;
        heroCollectInfoDic.Clear();
    }
 
    private void OnHeroChangeEvent(HeroInfo hero)
    {
        if (!DTC0403_tagPlayerLoginLoadOK.finishedLogin)
            return;
        WaitServerResponse(hero);
    }
 
    private void WaitServerResponse(HeroInfo hero)
    {
        if (waitResponse.Equals(default(WaitHeroFuncResponse)))
        {
            return;
        }
        // 等待超过5秒 不处理
        var nowTime = Time.time;
        if (waitResponse.time > 0f && waitResponse.time + 5 < nowTime)
        {
            waitResponse = default;
            return;
        }
 
        if (hero.itemHero.guid != waitResponse.guid)
        {
            return;
        }
 
        if (waitResponse.type == HeroFuncType.Break)
        {
            UIManager.Instance.OpenWindow<HeroLVBreakSuccessWin>();
        }
 
        waitResponse = default;
 
    }
 
    #region 武将UI常用接口
    public string GetCountryName(int index)
    {
        return RichTextMsgReplaceConfig.GetRichReplace("Country", index);
    }
 
    public string GetJobName(int index)
    {
        return RichTextMsgReplaceConfig.GetRichReplace("Class", index);
    }
 
    public string GetCountryIconName(int index)
    {
        return StringUtility.Contact("herocountry", index);
    }
 
    public string GetJobIconName(int index)
    {
        return StringUtility.Contact("herojob", index);
    }
 
    public int GetMaxLV(int quality)
    {
        return HeroQualityBreakConfig.maxlvDic[quality];
    }
 
    //是否达到最高级
    public bool IsLVMax(HeroInfo hero)
    {
        return hero.heroLevel >= GetMaxLV(hero.Quality);
 
    }
    //突破限制的最高等级
    public int GetMaxLVByBreakLV(int quality, int breakLevel)
    {
        return HeroQualityBreakConfig.GetQualityBreakConfig(quality, breakLevel).LVMax;
    }
 
    public bool IsLVMaxByBreakLevel(HeroInfo hero)
    {
        return hero.heroLevel == GetMaxLVByBreakLV(hero.Quality, hero.breakLevel);
    }
 
    #endregion
 
 
    public void QueryUnLockHeroPack()
    {
        //解锁更多的武将背包
        int canBuyCnt = PackManager.Instance.GetCanBuyPackGirdCount(PackType.Hero);
        if (canBuyCnt <= 0)
        {
            return;
        }
 
        var buyInfo = PackManager.Instance.BuyPackGirdNeedData(PackType.Hero);
        ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
        Language.Get("HeroPack1", UIHelper.GetIconNameWithMoneyType(buyInfo[0]), buyInfo[1], buyInfo[2]),
            (bool isOK) =>
            {
                if (isOK)
                {
                    if (UIHelper.GetMoneyCnt(buyInfo[0]) < buyInfo[1])
                    {
                        SysNotifyMgr.Instance.ShowTip("LackMoney", buyInfo[0]);
                        return;
                    }
                    PackManager.Instance.BuyPackGird(PackType.Hero);
                }
            });
    }
 
    //刷新时机, 打开武将界面 或者 关闭功能界面
    public void SortHeroList()
    {
        heroSortList = HeroManager.Instance.GetHeroGuidList(selectHeroListJob, selectHeroListCountry);
        heroSortList.Sort(CmpHero);
    }
 
 
    int CmpHero(string guidA, string guidB)
    {
        HeroInfo heroA = HeroManager.Instance.GetHero(guidA);
        HeroInfo heroB = HeroManager.Instance.GetHero(guidB);
        if (heroA == null || heroB == null)
        {
            return 0;
        }
 
        // 排序规则:上阵>武将等级>突破等级>武将觉醒阶级>武将品质>武将吞噬星级>武将ID
        bool isInTeamA = heroA.IsInTeamByTeamType(TeamType.Story);
        bool isInTeamB = heroB.IsInTeamByTeamType(TeamType.Story);
        if (isInTeamA != isInTeamB)
        {
            return isInTeamA ? -1 : 1;
        }
        if (heroA.heroLevel != heroB.heroLevel)
        {
            return heroA.heroLevel > heroB.heroLevel ? -1 : 1;
        }
        if (heroA.breakLevel != heroB.breakLevel)
        {
            return heroA.breakLevel > heroB.breakLevel ? -1 : 1;
        }
        if (heroA.awakeLevel != heroB.awakeLevel)
        {
            return heroA.awakeLevel > heroB.awakeLevel ? -1 : 1;
        }
        if (heroA.Quality != heroB.Quality)
        {
            return heroA.Quality > heroB.Quality ? -1 : 1;
        }
        if (heroA.heroStar != heroA.heroStar)
        {
            return heroA.heroStar > heroB.heroStar ? -1 : 1;
        }
 
        return heroA.heroId.CompareTo(heroB.heroId);
    }
 
 
 
    #region 招募
 
    public HappXBTitle selectCallType;  //寻宝枚举类型
    public int selectCallIndex;//0:1抽 1:10抽 对应配置顺序
    public const string skipKey = "SkipHeroCall";
 
    //积分招募预览
    public List<int> heroCallSortList { get; private set; } = new List<int>();  //积分招募列表 
    public int selectHeroCallListJob = 0;    //筛选职业
    public int selectHeroCallListCountry = 0;    //筛选国家
 
    public bool IsNewHero(int heroID)
    {
        var bookInfo = GetHeroBookInfo(heroID);
        if (bookInfo != null)
        {
            if (bookInfo.BookInitState < 2)
            {
                //更精准的 需要比较本次抽的同武将个数 和 背包里有的个数再比较
                if (HappyXBModel.Instance.GetCountInResult(heroID) >= HeroManager.Instance.GetHeroCountByID(heroID))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
 
        return true;
    }
 
    List<int> allHeroCallScoreList = new List<int>();  //积分招募列表 
    public void SortHeroCallList()
    {
        if (allHeroCallScoreList.IsNullOrEmpty())
        { 
            allHeroCallScoreList = HappyXBModel.Instance.GetAllGridLibItemIDByType((int)HappXBTitle.HeroCallScore);
        }
        heroCallSortList = new List<int>();
        if (selectHeroCallListJob == 0 && selectHeroCallListCountry == 0)
        {
            heroCallSortList = allHeroCallScoreList;
        }
        else
        {
            foreach (var item in allHeroCallScoreList)
            {
                HeroConfig heroConfig = HeroConfig.Get(item);
                if (heroConfig == null)
                {
                    continue;
                }
                if (selectHeroCallListJob != 0 && selectHeroCallListJob != heroConfig.Class)
                {
                    continue;
                }
                if (selectHeroCallListCountry != 0 && selectHeroCallListCountry != heroConfig.Country)
                {
                    continue;
                }
                heroCallSortList.Add(item);
            }
        }
 
        heroCallSortList.Sort(CmpHeroID);
    }
 
    int CmpHeroID(int idA, int idB)
    {
        HeroConfig heroA = HeroConfig.Get(idA);
        HeroConfig heroB = HeroConfig.Get(idB);
 
 
        // 排序规则:武将品质>武将ID
        if (heroA.Quality != heroB.Quality)
        {
            return heroA.Quality > heroB.Quality ? -1 : 1;
        }
 
 
        return heroA.HeroID.CompareTo(heroB.HeroID);
    }
 
    #endregion
 
 
}
 
public struct WaitHeroFuncResponse
{
    public HeroFuncType type;
    public string guid;
    public float time;
}
 
//武将功能类型
public enum HeroFuncType
{
    None = 0,   //无功能
    Break = 1,  //突破
    
}