少年修仙传客户端代码仓库
hch
3 天以前 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using LitJson;
using System.Linq;
using UnityEngine;
 
public class ILAchievementModel : ILModel<ILAchievementModel>
{
    PackModel packModel { get { return ModelCenter.Instance.GetModelEx<PackModel>(); } }
    AchievementModel achievementModel { get { return ModelCenter.Instance.GetModelEx<AchievementModel>(); } }
    public int[] m_NewAchieveMentGroup;
    public Dictionary<int, int> typeToGroup = new Dictionary<int, int>();
    public Dictionary<int, List<int>> scoreAwards = new Dictionary<int, List<int>>();
    public Redpoint redpoint = new Redpoint(MainRedDot.RedPoint_key, MainRedPoint.achievementRedpoint);
    Redpoint redpoint1 = new Redpoint(MainRedPoint.achievementRedpoint, MainRedPoint.achievementRedpoint * 10);  //累计成就红点
    Dictionary<int, Redpoint> redpoints = new Dictionary<int, Redpoint>();
    public event Action UpdateScoreAwardState;
    public event Action UpdateAchievement;
 
    public int m_ScoreAwardState;
 
    int m_SelectIndex;  //分组
    public event Action OnSelectUpdate;
    public int selectIndex
    {
        get { return m_SelectIndex; }
        set
        {
            if (m_SelectIndex != value)
            {
                m_SelectIndex = value;
                OnSelectUpdate?.Invoke();
            }
        }
    }
 
    int m_NewSuccID;  // 新成就可领取奖励 用于提示
    public event Action OnNewSuccAward;
    public int newSuccID
    {
        get { return m_NewSuccID; }
        set
        {
            if (m_NewSuccID != value)
            {
                m_NewSuccID = value;
                OnNewSuccAward?.Invoke();
            }
        }
    }
 
 
 
    protected override void Init()
    {
        GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitializeEvent;
        GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitializeEvent;
        GameEvent.playerDataRefreshEvent -= OnPlayerDataRefreshEvent;
        GameEvent.playerDataRefreshEvent += OnPlayerDataRefreshEvent;
        GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
        GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
        achievementModel.achievementAwardableEvent -= OnAchievementAwardableEvent;
        achievementModel.achievementAwardableEvent += OnAchievementAwardableEvent;
        ParseConfig();
 
    }
 
    protected override void UnInit()
    {
    }
 
    void OnAchievementAwardableEvent(int succID)
    {
        if (DTC0403_tagPlayerLoginLoadOK.neverLoginOk)
            return;
 
        if (achievementModel.reachSuccessIDs.Contains(succID))
            return;
 
        var config = SuccessConfig.Get(succID);
        if (config == null)
            return;
 
        if (!typeToGroup.ContainsKey(config.Type))
        {
            return;
        }
 
        var idList = achievementModel.GetAchievementsByCategory(typeToGroup[config.Type]);
 
        if (!idList.Contains(succID)) return;
 
        newSuccID = succID;
        WindowCenter.Instance.Open<AchievementTipWin>();
    }
 
 
    void ParseConfig()
    {
        m_NewAchieveMentGroup = GeneralDefine.GetIntArray("NewAchieveMent");
        for (int i = 0; i < m_NewAchieveMentGroup.Length; i++)
        {
            redpoints.Add(m_NewAchieveMentGroup[i], new Redpoint(MainRedPoint.achievementRedpoint, MainRedPoint.achievementRedpoint * 100000 + m_NewAchieveMentGroup[i]));
            var typeList = achievementModel.groupToType[m_NewAchieveMentGroup[i]];
            for (int j = 0; j < typeList.Count; j++)
            {
                typeToGroup[typeList[j]] = m_NewAchieveMentGroup[i];
            }
        }
 
        var scoreDict = JsonMapper.ToObject(FuncConfigConfig.Get("SucceeScore").Numerical1);
        var keys = scoreDict.Keys.ToList();
        for (int i = 0; i < keys.Count; i++)
        {
            var key = int.Parse(scoreDict[keys[i]][0].ToJson());
            var arr = JsonMapper.ToObject<int[][]>(scoreDict[keys[i]][1].ToJson());
            scoreAwards[key] = arr[0].ToList();
        }
 
    }
 
    void OnBeforePlayerDataInitializeEvent()
    {
        m_ScoreAwardState = 0;
    }
 
    void OnPlayerDataRefreshEvent(PlayerDataType dataType)
    {
        if (dataType != PlayerDataType.default19)
        {
            return;
        }
        UpdateScoreAwardState?.Invoke();
        UpdateScoreRedpoint();
    }
 
 
    void OnSecondEvent()
    {
        RefreshSuccessRedpoint();
 
        if (refreshAgain)
        {
            UpdateAchievement?.Invoke();
            refreshAgain = false;
        }
    }
 
    public void UpdateSuccessRedpoint(HA340_tagMCSuccessInfoList netPack)
    {
        bool isRefresh = false;
        for (int i = 0; i < netPack.SuccessInfoList.Length; i++)
        {
            bool refresh;
            UpdateSuccessRedpoint(0, netPack.SuccessInfoList[i].SuccType, out refresh);
            if (refresh) isRefresh = true;
        }
 
        if (isRefresh)
            UpdateAchievement?.Invoke();
 
    }
 
    //进度和领取封包 A340 A342  不同的封包需要延迟刷新
    //记录刷新的成就类型,控制刷新频率
    List<int> refreshType = new List<int>();
    public void UpdateSuccessRedpoint(int successID, int successType, out bool refresh)
    {
        refresh = false;
        if (successType != 0)
        {
            if (refreshType.Contains(successType))
            {
                return;
            }
            if (!typeToGroup.ContainsKey(successType))
            {
                return;
            }
            refreshType.Add(successType);
            refresh = true;
            return;
        }
        var config = SuccessConfig.Get(successID);
        if (config == null)
            return;
 
        if (refreshType.Contains(config.Type))
        {
            return;
        }
 
        if (!typeToGroup.ContainsKey(config.Type))
        {
            return;
        }
        refreshType.Add(config.Type);
        refresh = true;
        return;
    }
 
 
    public void RefreshSuccessRedpoint()
    {
        if (refreshType.Count == 0)
        {
            return;
        }
 
        for (int i = 0; i < refreshType.Count; i++)
        {
            int group = typeToGroup[refreshType[i]];
 
            var idList = achievementModel.GetAchievementsByCategory(group);
 
            bool state = false;
            for (int j = 0; j < idList.Count; j++)
            {
                var successID = idList[j];
                Achievement achievement;
                if (!achievementModel.TryGetAchievement(successID, out achievement))
                {
                    continue;
                }
                if (!Achievement.IsReach(successID, achievement.progress) && !achievement.completed)
                {
                    continue;
                }
                if (!achievement.completed)
                {
                    state = true;
                    break;
                }
            }
            redpoints[group].state = state ? RedPointState.Simple : RedPointState.None;
        }
        refreshType.Clear();
    }
 
 
    public void UpdateSuccessScoreInfo(IL_HA343_tagMCSuccessScoreInfo netPack)
    {
        m_ScoreAwardState = (int)netPack.ScoreAwardState;
        UpdateScoreAwardState?.Invoke();
        UpdateScoreRedpoint();
    }
 
    void UpdateScoreRedpoint()
    {
        int showIndex = GetScoreAwardShowIndex();
        int index = showIndex;
        var keys = scoreAwards.Keys.ToList();
        keys.Sort();
        if (showIndex == -1)
        {
            index = keys.Count - 1;
        }
        var showScore = GetShowScore();
        ulong needScore = (ulong)keys[index];
 
        if (showIndex != -1 && showScore >= needScore)
        {
            redpoint1.state = RedPointState.Simple;
        }
        else
        {
            redpoint1.state = RedPointState.None;
        }
    }
    
 
    public int GetScoreAwardShowIndex()
    {
        int index = -1;
        var keys = scoreAwards.Keys.ToList();
        keys.Sort();
        for (int i = 0; i < keys.Count; i++)
        {
            if (((int)Math.Pow(2, i) & m_ScoreAwardState) == 0)
            {
                index = i;
                break;
            }
 
        }
 
        return index;
    }
 
    public ulong GetShowScore()
    {
        return HeroControler.Instance.GetMoneyCntIL(39);
    }
 
 
    private int SuccessSort(int x, int y)
    {
        Achievement achievementX;
        achievementModel.TryGetAchievement(x, out achievementX);
        Achievement achievementY;
        achievementModel.TryGetAchievement(y, out achievementY);
 
        if (achievementX.completed == achievementY.completed)
        {
            var xconfig = SuccessConfig.Get(x);
            var yconfig = SuccessConfig.Get(y);
 
            bool canGetX = achievementX.progress >= xconfig.NeedCnt;
            bool canGetY = achievementY.progress >= yconfig.NeedCnt;
 
            if (canGetX == canGetY)
                return xconfig.ReOrder.CompareTo(yconfig.ReOrder);
 
            return canGetY.CompareTo(canGetX);
        }
 
        return achievementX.completed.CompareTo(achievementY.completed);
    }
 
    public List<int> GetAchieveIDs(int group)
    {
        var ids = achievementModel.GetAchievementsByCategory(group);
        ids.Sort(SuccessSort);
        return ids;
    }
 
    //成就是两个封包A340 A342合并逻辑,没有通知进度的情况下已领取则代表进度满; 只有修仙之路是战令购买特殊处理
    //批量领取同类型成就
    public void GetAchievementReward(int successID, byte isPassport = 0)
    {
        var config = SuccessConfig.Get(successID);
 
        var ids = GetAchieveIDs(config.Group);
 
        int sendCount = 0;
        for (int i = 0; i < ids.Count; i++)
        {
            var configEx = SuccessConfig.Get(ids[i]);
            Achievement achievement;
            achievementModel.TryGetAchievement(ids[i], out achievement);
            if (configEx.Type != config.Type)
                continue;
            int process = Mathf.Min(achievement.progress, configEx.NeedCnt);
            if (achievement.completed)
                process = configEx.NeedCnt;
 
            if (isPassport == 0)
            { 
                if (achievement.completed)
                    continue;
            }
            else
            {
                if (achievement.completedBP && achievement.completed)
                    continue;
            }
            if (process < configEx.NeedCnt)
            {
                if (isPassport == 1)
                    continue;
                else
                    return;
 
            }
 
            if (sendCount > 30) return; //分批
            var sendInfo = new CA542_tagMCGetSuccessAward();
            sendInfo.SuccID = (uint)ids[i];
            sendInfo.IsPassport = isPassport;
            GameNetSystem.Instance.SendInfo(sendInfo);
            sendCount++;
        }
 
 
    }
 
    public bool refreshAgain = false;   //批量领取二次刷新
 
    public void UpdateAchievementRecord(HA342_tagMCSuccessFinishAwardRecordList vNetData)
    {
        bool refresh = false;
        Achievement achievement;
        for (int i = 0; i < vNetData.RecordList.Length; i++)
        {
            var record = vNetData.RecordList[i];
            var _index = record.RecordIndex;
            for (int j = 0; j < 31; j++)
            {
                var achievementId = _index * 31 + j;
                if (achievementModel.TryGetAchievement(achievementId, out achievement))
                {
                    bool isRefresh;
                    UpdateSuccessRedpoint(achievementId, 0, out isRefresh);
                    if (isRefresh) refresh = true;
                }
            }
        }
        if (refresh)
        {
            //UpdateAchievement?.Invoke();
            if (WindowCenter.Instance.IsOpen("ILAchievementActivityWin"))
            {
                refreshAgain = true;
            }
        }
 
    }
 
    int jumpSuccessGroup = 0;
 
    public void SetJumpSuccessGroup(int group)
    {
        jumpSuccessGroup = group;
    }
 
    public int GetJumpIndex()
    {
        if (jumpSuccessGroup != 0)
        {
            for (int i = 0; i < m_NewAchieveMentGroup.Length; i++)
            {
                if (m_NewAchieveMentGroup[i] == jumpSuccessGroup)
                {
                    jumpSuccessGroup = 0;
                    return i;
                }
            }
            jumpSuccessGroup = 0;
            return 0;
        }
 
        for (int i = 0; i < m_NewAchieveMentGroup.Length; i++)
        {
            if (redpoints[m_NewAchieveMentGroup[i]].state == RedPointState.Simple)
                return i;
        }
        return 0;
    }
}