少年修仙传客户端代码仓库
client_Wu Xijin
2019-03-05 efa5f8d07fc3321f6ac5f5d97fb422db28d0886f
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
using System;
using System.Collections.Generic;
 
using Snxxz.UI;
using System.Linq;
using UnityEngine;
using System.Text;
 
[XLua.LuaCallCSharp]
    public class RealmPracticeModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
{
    private Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> OpenRealmPraDict = new Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>>(); 
    private SuccessConfig _tagAchievementModel = null;
    private ItemConfig _tagChinItemModel = null;
    private FuncOpenLVConfig _tagFuncOpenModel = null;
 
    AchievementModel _achieveModel;
    public AchievementModel AchieveModel
    {
        get
        {
            return _achieveModel ?? (_achieveModel = ModelCenter.Instance.GetModel<AchievementModel>());
        }
    }
 
    public const string PLAYERLV_KEY = "PlayerID";
 
    public override void Init()
    {
        SetRealmFirstTypeRedPoint();
        SetRealmSecondTypeRedPoint();
        SetPracTaskRedPoint();
    }
 
    public void OnBeforePlayerDataInitialize()
    {
        _tagAchievementModel = null;
       _tagChinItemModel = null;
       _tagFuncOpenModel = null;
 
        FuncOpen.Instance.OnFuncStateChangeEvent -= RefreshFuncOpenState;
        AchieveModel.achievementProgressUpdateEvent -= RefreshAchieveState;
        AchieveModel.achievementCompletedEvent -= RefreshAchieveState;
    }
 
    public void OnAfterPlayerDataInitialize()
    {
       
    }
 
 
    public void OnPlayerLoginOk()
    {
        RefreshFuncOpenState((int)FuncOpenEnum.Realm);
        FuncOpen.Instance.OnFuncStateChangeEvent += RefreshFuncOpenState;
        AchieveModel.achievementProgressUpdateEvent += RefreshAchieveState;
        AchieveModel.achievementCompletedEvent += RefreshAchieveState;
    }
 
    public override void UnInit()
    {
       
    }
 
    private void RefreshFuncOpenState(int funcId)
    {
        if(FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Realm))
        {
            RefreshOpenPracModel();
        }
 
        if (funcId != (int)FuncOpenEnum.Realm) return;
 
         RealmTypeRedPointCtrl();
    }
 
    public void RefreshOpenPracModel()
    {
        OpenRealmPraDict.Clear();
        Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> realmPraDict = RealmPracticeConfig.GetRealmPraDict();
        foreach(var first in realmPraDict.Keys)
        {
            Dictionary<int, List<RealmPracticeConfig>> secondDict = new Dictionary<int, List<RealmPracticeConfig>>();
            OpenRealmPraDict.Add(first,secondDict);
            foreach(var second in realmPraDict[first].Keys)
            {
                List<RealmPracticeConfig> praclist = realmPraDict[first][second];
                for(int i = 0; i < praclist.Count; i++)
                {
                    if(!secondDict.ContainsKey(second))
                    {
                        List<RealmPracticeConfig> list = new List<RealmPracticeConfig>();
                        list.Add(praclist[i]);
                        if(praclist[i].FunctionID == 0)
                        {
                            secondDict.Add(second,list);
                        }
                        else
                        {
                            if (FuncOpen.Instance.IsFuncOpen(praclist[i].FunctionID))
                            {
                                secondDict.Add(second, list);
                            }
                        }
                    }
                    else
                    {
                        if (praclist[i].FunctionID == 0)
                        {
                            secondDict[second].Add(praclist[i]);
                        }
                        else
                        {
                            if (FuncOpen.Instance.IsFuncOpen(praclist[i].FunctionID))
                            {
                                secondDict[second].Add(praclist[i]);
                            }
                        }
                       
                    }
                }
            }
        }
    }
 
    private List<RealmPracticeConfig> GetOpenRealmPralist(int firstType,int secondType)
    {
        if(OpenRealmPraDict.ContainsKey(firstType))
        {
            if(OpenRealmPraDict[firstType].ContainsKey(secondType))
            {
                return OpenRealmPraDict[firstType][secondType];
            }
        }
        return null;
    }
 
    public Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> GetAllOpenRealmPra()
    {
        return OpenRealmPraDict;
    }
 
    private List<RealmPracticeConfig> orderlist = new List<RealmPracticeConfig>();
    private List<RealmPracticeConfig> OpenPraclist;
    public List<RealmPracticeConfig> GetRealmPracticelist(int firstType,int secondType)
    {
        orderlist.Clear();
        OpenPraclist = GetOpenRealmPralist(firstType,secondType);
        if (OpenPraclist == null) return orderlist;
 
        orderlist.AddRange(OpenPraclist);
        orderlist.Sort(CompareTaskState);
        return orderlist;
    }
 
    private int CompareTaskState(RealmPracticeConfig start, RealmPracticeConfig next)
    {
        Achievement startAchieve = null;
        SetAchievement(start.AchieveID, out startAchieve);
        Achievement nextAchieve = null;
        SetAchievement(next.AchieveID, out nextAchieve);
 
        bool x = IsReach(startAchieve);
        bool y = IsReach(nextAchieve);
        if (x.CompareTo(y) != 0) return -x.CompareTo(y);
 
        x = IsCompleted(startAchieve);
        y = IsCompleted(nextAchieve);
        if (x.CompareTo(y) != 0) return x.CompareTo(y);
 
        int orderx = OpenPraclist.IndexOf(start);
        int ordery = OpenPraclist.IndexOf(next);
        if (orderx.CompareTo(ordery) != 0)
            return orderx.CompareTo(ordery);
 
        return 0;
    }
 
    private bool IsReach(Achievement achieve)
    {
        bool isReach = false;
        if(!achieve.completed)
        {
            if(Achievement.IsReach(achieve.id, achieve.progress))
            {
                isReach = true;
            }
        }
        return isReach;
    }
 
    private bool IsCompleted(Achievement achieve)
    {
        return achieve.completed;
    }
 
    public SuccessConfig GetTagSuccessModel(int achievementId)
    {
        _tagAchievementModel = SuccessConfig.Get(achievementId);
        if (_tagAchievementModel != null)
            return _tagAchievementModel;
        else
            return null;
 
    }
 
 
    public ItemConfig GeTagChinItemModel(int Id)
    {
        _tagChinItemModel = ItemConfig.Get(Id);
        if (_tagChinItemModel != null)
            return _tagChinItemModel;
        else
            return null;
 
    }
    public int SetAchievement(int[] idlist,out Achievement achieve)
    {
        achieve = null;
        int k = 0;
        for (k = 0; k < idlist.Length; k++)
        {
            if (AchieveModel.TryGetAchievement(idlist[k], out achieve))
            {
                if (!achieve.completed)
                {
                    return k;
                }
                else
                {
                    if (idlist[idlist.Length - 1] == achieve.id)
                    {
                        return idlist.Length;
                    }
                }
            }
        }
        return -1;
 
    }
 
    private StringBuilder _pointStr = new StringBuilder();
 
    public string GetPracticePointStr(int firstType,int secondType = 0)
    {
        _pointStr.Length = 0;  
        string s = "";
        List<RealmPracticeConfig> typelist = GetOpenRealmPralist(firstType,secondType);
        List<RealmPracticeConfig> alllist = RealmPracticeConfig.GetRealmPraAchieveBySecondType(firstType,secondType);
        if (typelist != null)
        {
            if (secondType != 0)
            {
                s = alllist[0].SecondTypeName;
                _pointStr.AppendFormat("<Img img={0}/>{1}/{2}", "Money_Type_13", UIHelper.ReplaceLargeNum(GetRealmPraPointByType(firstType, secondType, false)), UIHelper.ReplaceLargeNum(GetRealmPraPointByType(firstType,secondType)));
                s = StringUtility.Contact(s, "\n", "(", _pointStr.ToString(), ")");
            }
            else
            {
                s = alllist[0].FirstTypeName;
            }
        }
        else
        {
            alllist = RealmPracticeConfig.GetRealmPraAchieveBySecondType(firstType,1);
            s = alllist[0].FirstTypeName;
        }
        return s;
 
    }
 
    public int GetRealmPraPointByType(int firstType,int secondType = 0,bool isSumRealmPraPoint = true)
    {
        if (!OpenRealmPraDict.ContainsKey(firstType)) return 0;
 
        int sumPoint = 0;
        Dictionary<int, List<RealmPracticeConfig>> secondDict = OpenRealmPraDict[firstType];
 
        if(secondType == 0)
        {
            foreach (var second in secondDict.Keys)
            {
                for (int i = 0; i < secondDict[second].Count; i++)
                {
                    RealmPracticeConfig config = secondDict[second][i];
                    sumPoint += GetAchieveRealmPraPoint(config,isSumRealmPraPoint);
                }
            }
        }
        else
        {
            if(secondDict.ContainsKey(secondType))
            {
                for (int i = 0; i < secondDict[secondType].Count; i++)
                {
                    RealmPracticeConfig config = secondDict[secondType][i];
                    sumPoint += GetAchieveRealmPraPoint(config,isSumRealmPraPoint);
                }
            }
        }
 
        return sumPoint;  
    }
 
    private int GetAchieveRealmPraPoint(RealmPracticeConfig config,bool isSumRealmPraPoint)
    {
        if (config == null) return 0;
 
        int[] idlist = config.AchieveID;
        int realmPraPoint = 0;
        for (int j = 0; j < idlist.Length; j++)
        {
            Achievement achieve = null;
            AchieveModel.TryGetAchievement(idlist[j], out achieve);
            if (achieve != null)
            {
                if(isSumRealmPraPoint)
                {
                    int k = 0;
                    for (k = 0; k < achieve.rewardCurrency.Length; k++)
                    {
                        if (achieve.rewardCurrency[k].id == 13)
                        {
                            realmPraPoint += achieve.rewardCurrency[k].count;
                        }
                    }
                }
                else
                {
                    if (achieve.completed)
                    {
                        int k = 0;
                        for (k = 0; k < achieve.rewardCurrency.Length; k++)
                        {
                            if (achieve.rewardCurrency[k].id == 13)
                            {
                                realmPraPoint += achieve.rewardCurrency[k].count;
                            }
                        }
                    }
                }
              
            }
        }
        return realmPraPoint;
    }
 
    #region 红点逻辑
    public const int REALMREDPOINT_KEY = 114;
    public const int REALMPRAFUNCREDPOINT_KEY = 11402;
    public Redpoint realmPraRedPoint = new Redpoint(REALMREDPOINT_KEY, REALMPRAFUNCREDPOINT_KEY);
 
    public Dictionary<int,Redpoint> realmFirstTypeDict { get;private set; }
    private void SetRealmFirstTypeRedPoint()
    {
        realmFirstTypeDict = null;
        Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> realmPraDict = RealmPracticeConfig.GetRealmPraDict();
        realmFirstTypeDict = new Dictionary<int, Redpoint>();
        int i = 0;
        foreach(var type in realmPraDict.Keys)
        {
            int id = REALMPRAFUNCREDPOINT_KEY * 100 + i;
            Redpoint redpoint = new Redpoint(REALMPRAFUNCREDPOINT_KEY, id);
            realmFirstTypeDict.Add(type, redpoint);
            i += 1;
        }
    }
    public Dictionary<int, Dictionary<int, Redpoint>> realmSecondTypeDict { get; private set; }
    private void SetRealmSecondTypeRedPoint()
    {
        realmSecondTypeDict = null;
        Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> realmPraDict = RealmPracticeConfig.GetRealmPraDict();
        realmSecondTypeDict = new Dictionary<int, Dictionary<int, Redpoint>>();
        int i = 0;
        foreach (var type in realmPraDict.Keys)
        {
            Dictionary<int, Redpoint> secondRedDict = new Dictionary<int, Redpoint>();
            realmSecondTypeDict.Add(type,secondRedDict);
            foreach (var second in realmPraDict[type].Keys)
            {
                if(second != 0)
                {
                    int id = realmFirstTypeDict[type].id * 100 + i;
                    Redpoint redpoint = new Redpoint(realmFirstTypeDict[type].id, id);
                    secondRedDict.Add(second, redpoint);
                    i += 1;
                }
            }      
        } 
    }
 
 
    private Dictionary<int, Redpoint> PracTaskRedPointDict = new Dictionary<int, Redpoint>(); //id 流水号
    private void SetPracTaskRedPoint()
    {
        PracTaskRedPointDict.Clear();
        Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> realmPraDict = RealmPracticeConfig.GetRealmPraDict();
        foreach(var first in realmPraDict.Keys)
        {
            foreach(var second in realmPraDict[first].Keys)
            {
                List<RealmPracticeConfig> pralist = realmPraDict[first][second];
                Redpoint redpointType;
                if(second != 0)
                {
                    redpointType = realmSecondTypeDict[first][second];
                }
                else
                {
                    redpointType = realmFirstTypeDict[first];
                }
                for (int i = 0; i < pralist.Count; i++)
                {
                    int id = redpointType.id * 10000 + i;
                    Redpoint redpoint = new Redpoint(redpointType.id, id);
                    if (!PracTaskRedPointDict.ContainsKey(pralist[i].ID))
                    {
                        PracTaskRedPointDict.Add(pralist[i].ID, redpoint);
                    }
                }
            }
        }
    }
 
    public void RealmTypeRedPointCtrl()
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Realm)) return;
 
        foreach(var first in OpenRealmPraDict.Keys)
        {
            foreach(var second in OpenRealmPraDict[first].Keys)
            {
                List<RealmPracticeConfig> praclist = OpenRealmPraDict[first][second];
                for (int j = 0; j < praclist.Count; j++)
                {
                    Achievement achieve = null;
                    SetAchievement(praclist[j].AchieveID, out achieve);
                    if (IsReachAchieve(achieve))
                    {
                        if (PracTaskRedPointDict[praclist[j].ID].state != RedPointState.Simple)
                        {
                            PracTaskRedPointDict[praclist[j].ID].state = RedPointState.Simple;
                        }
                    }
                    else
                    {
                        if (PracTaskRedPointDict[praclist[j].ID].state != RedPointState.None)
                        {
                            PracTaskRedPointDict[praclist[j].ID].state = RedPointState.None;
                        }
                    }
 
                }
            }
        }
    }
 
    public void RefreshAchieveState(int id)
    {
        if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Realm)) return;
 
        SuccessConfig successConfig = SuccessConfig.Get(id);
        if (successConfig != null)
        {
            RealmPracticeConfig practiceConfig = RealmPracticeConfig.Get(successConfig.RealmPracticeID);
            if (practiceConfig == null) return;
 
            if(OpenRealmPraDict.ContainsKey(practiceConfig.Type))
            {
                if(OpenRealmPraDict[practiceConfig.Type].ContainsKey(practiceConfig.SecondType))
                {
                    Achievement achieve = null;
                    SetAchievement(practiceConfig.AchieveID, out achieve);
 
                    if (IsReachAchieve(achieve))
                    {
                        if (PracTaskRedPointDict[successConfig.RealmPracticeID].state != RedPointState.Simple)
                        {
                            PracTaskRedPointDict[successConfig.RealmPracticeID].state = RedPointState.Simple;
                        }
                    }
                    else
                    {
                        if (PracTaskRedPointDict[successConfig.RealmPracticeID].state != RedPointState.None)
                        {
                            PracTaskRedPointDict[successConfig.RealmPracticeID].state = RedPointState.None;
                        }
                    }
                }
            }
        }
    }
 
 
    public bool IsReachAchieve(Achievement achieve)
    {
        if (achieve == null) return false;
        bool isReach = false;
 
        if(!achieve.completed)
        {
            if (Achievement.IsReach(achieve.id, achieve.progress))
            {
                isReach = true;
            }
        }
        return isReach;
    }
    #endregion
 
}