少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-25 9a8583c696c85286956048e4955e4314e46202a2
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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
using System;
 
namespace Snxxz.UI
{
    [XLua.LuaCallCSharp]
    public class TreasureSoulModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        public const int TREASURE_SOUL_ID = 115;
        Redpoint treasureSoulRedpoint = new Redpoint(1, TREASURE_SOUL_ID);
        Redpoint treasureSoulNewGotRedpoint = new Redpoint(TREASURE_SOUL_ID, 115100);
 
        Dictionary<int, TreasureSpecialData> treasureSoulDict = new Dictionary<int, TreasureSpecialData>();
        List<int> treasureSouls = new List<int>();
        public Dictionary<int, int> signAddProperty = new Dictionary<int, int>();
        public int signAddTreasure { get; private set; }
 
        public event Action<int> treasureSoulEvent;
        public event Action<int> treasureSelectSoulChangeEvent;
 
        int m_SelectSoul = 0;
        public int selectSoul
        {
            get { return m_SelectSoul; }
            set
            {
                m_SelectSoul = value;
                if (treasureSelectSoulChangeEvent != null)
                {
                    treasureSelectSoulChangeEvent(value);
                }
            }
        }
 
        public int gotoSoul { get; set; }
 
        public int newGotSoul { get; set; }
 
        public bool serverInited { get; private set; }
 
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
        AchievementModel achievementModel { get { return ModelCenter.Instance.GetModel<AchievementModel>(); } }
        public override void Init()
        {
            packModel.refreshItemCountEvent += RefreshItemCountAct;
            StrengthenModel.RefreshEquipUpgradLvAct += RefreshEquipSTRLv;
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
            ParseConfig();
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            serverInited = false;
            foreach (var special in treasureSoulDict.Values)
            {
                special.presentFinishCount = 0;
                special.presentGetCount = 0;
                special.itemGet = false;
                special.active = false;
            }
            treasureSoulNewGotRedpoint.state = RedPointState.None;
        }
 
        public void OnPlayerLoginOk()
        {
            serverInited = true;
            UpdateRedpoints();
        }
 
        public override void UnInit()
        {
            packModel.refreshItemCountEvent -= RefreshItemCountAct;
            StrengthenModel.RefreshEquipUpgradLvAct -= RefreshEquipSTRLv;
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
        }
 
        void ParseConfig()
        {
            var configs = TreasurePrivilegeConfig.GetValues();
            for (int i = 0; i < configs.Count; i++)
            {
                var treasureConfig = TreasureConfig.Get(configs[i].treasureId);
                if (treasureConfig == null || treasureConfig.Category != (int)TreasureCategory.Human)
                {
                    continue;
                }
                treasureSouls.Add(configs[i].PrivilegeID);
                treasureSoulDict.Add(configs[i].PrivilegeID, new TreasureSpecialData((TreasurePrivilege)configs[i].PrivilegeID));
            }
            var funcConfig = FuncConfigConfig.Get("MWSignDayAttr");
            var jsonData = LitJson.JsonMapper.ToObject(funcConfig.Numerical1);
            signAddTreasure = int.Parse(funcConfig.Numerical2);
            foreach (var _key in jsonData.Keys)
            {
                signAddProperty.Add(int.Parse(_key), int.Parse(jsonData[_key].ToString()));
            }
        }
 
        public void SetViewTreasureNewGot()
        {
            treasureSoulNewGotRedpoint.state = RedPointState.None;
        }
 
        public List<int> GetTreasureSouls()
        {
            return treasureSouls;
        }
 
        public bool TryGetTreasureSoul(int _id, out TreasureSpecialData special)
        {
            return treasureSoulDict.TryGetValue(_id, out special);
        }
 
        public int GetTreasureSoulValue(int _soulId)
        {
            if (treasureSoulDict.ContainsKey(_soulId))
            {
                if (IsGetTreasureSoul(_soulId))
                {
                    var _specialData = treasureSoulDict[_soulId];
                    return _specialData.GetPrivilegeValue();
                }
            }
            return 0;
        }
 
        public bool IsGetTreasureSoul(int _soulId)
        {
            TreasureSpecialData special;
            return TryGetTreasureSoul(_soulId, out special) && special.active;
        }
 
        public bool IsOpenTreasureSoul(int _soulId)
        {
            TreasureSpecialData special;
            if (TryGetTreasureSoul(_soulId, out special))
            {
                Treasure treasure;
                return treasureModel.TryGetTreasure(special.treasureId, out treasure) && treasure.state == TreasureState.Collected;
            }
            return false;
        }
 
        private void RefreshEquipSTRLv(int obj)
        {
            UpdateTreasureSoulStrenthen();
        }
 
        private void RefreshItemCountAct(PackType packType, int arg2, int arg3)
        {
            if (packType == PackType.Equip)
            {
                UpdateTreasureSoulStrenthen();
            }
        }
 
        public void UpdateTreasureSoulStrenthen()
        {
            UpdateRedpoint((int)TreasurePrivilege.StrengthenAdd);
            if (treasureSoulEvent != null)
            {
                treasureSoulEvent((int)TreasurePrivilege.StrengthenAdd);
            }
        }
 
        private void OnFuncStateChangeEvent(int func)
        {
            if (func == 126)
            {
                UpdateRedpoints();
            }
        }
 
        public void UpdateTreasurePrivilege(HA353_tagMCMWPrivilegeDataInfo package)
        {
            for (int i = 0; i < package.Count; i++)
            {
                var _data = package.InfoList[i];
                TreasureSpecialData special;
                if (!treasureSoulDict.TryGetValue((int)_data.PriID, out special))
                {
                    continue;
                }
                bool beforeActived = special.active;
                special.active = _data.State == 1;
                if (!beforeActived && special.active && serverInited
                    && !WindowCenter.Instance.IsOpen<TreasureSoulWin>())
                {
                    treasureSoulNewGotRedpoint.state = RedPointState.Simple;
                    newGotSoul = (int)_data.PriID;
                }
                if ((TreasurePrivilege)_data.PriID == TreasurePrivilege.StrengthenAdd)
                {
                    if (treasureSoulEvent != null)
                    {
                        treasureSoulEvent((int)_data.PriID);
                    }
                    UpdateRedpoint((int)_data.PriID);
                    continue;
                }
 
                int beforeFinishCount = special.presentFinishCount;
 
                special.presentFinishCount = (int)_data.GotValue;
                special.presentGetCount = (int)_data.CurValue;
                special.itemGet = _data.ItemAwardState == 1;
                UpdateRedpoint((int)_data.PriID);
                if (treasureSoulEvent != null)
                {
                    treasureSoulEvent((int)_data.PriID);
                }
 
                if (beforeFinishCount < special.presentFinishCount && serverInited && special.active
                    && WindowCenter.Instance.IsOpen<TreasureSoulWin>()
                    && !WindowCenter.Instance.IsOpen<RealmPropertyUpWin>()
                    && !NewBieCenter.Instance.inGuiding)
                {
                    ActivateShow.TreasureSoulGetReward((int)_data.PriID, beforeFinishCount, special.presentFinishCount);
                }
            }
        }
 
        public void UpdateTreasurePrivilege(HA317_tagMCAllEquipAttrActiveInfo package)
        {
            for (int i = 0; i < package.ActiveInfo.Length; i++)
            {
                var _data = package.ActiveInfo[i];
                if (_data.Type == 0)
                {
                    if (treasureSoulDict.ContainsKey((int)TreasurePrivilege.StrengthenAdd))
                    {
                        var _specialData = treasureSoulDict[(int)TreasurePrivilege.StrengthenAdd];
                        int beforeFinishCount = _specialData.presentFinishCount;
                        _specialData.presentFinishCount = (int)_data.Cnt;
                        UpdateRedpoint((int)TreasurePrivilege.StrengthenAdd);
                        if (beforeFinishCount < _specialData.presentFinishCount && serverInited && _specialData.active
                             && WindowCenter.Instance.IsOpen<TreasureSoulWin>()
                             && !WindowCenter.Instance.IsOpen<RealmPropertyUpWin>())
                        {
                            ActivateShow.TreasureSoulGetReward((int)TreasurePrivilege.StrengthenAdd, 
                                beforeFinishCount, _specialData.presentFinishCount);
                        }
                    }
                    if (treasureSoulEvent != null)
                    {
                        treasureSoulEvent((int)TreasurePrivilege.StrengthenAdd);
                    }
 
                }
            }
        }
 
        private void UpdateRedpoint(int _id)
        {
            if (treasureSoulDict.ContainsKey(_id))
            {
                var special = treasureSoulDict[_id];
                special.UpdateState();
                if (special.privilegeRedpoint != null)
                {
                    special.privilegeRedpoint.state = RedPointState.None;
                    if (!FuncOpen.Instance.IsFuncOpen(126) || !IsOpenTreasureSoul(_id)
                        || !IsGetTreasureSoul(_id))
                    {
                        return;
                    }
                    switch (special.type)
                    {
                        case TreasurePrivilege.StrengthenAdd:
                        case TreasurePrivilege.DemonJarAtk:
                        case TreasurePrivilege.MountAtk:
                        case TreasurePrivilege.PetHp:
                        case TreasurePrivilege.Sp:
                            special.privilegeRedpoint.state = special.state == TreasurePrivilegeState.Reward ?
                                RedPointState.Simple : RedPointState.None;
                            break;
                        case TreasurePrivilege.Wash:
                            special.privilegeRedpoint.state = special.itemGet ?
                               RedPointState.None : RedPointState.Simple;
                            break;
                    }
                }
            }
        }
 
        private void UpdateRedpoints()
        {
            foreach (var special in treasureSoulDict.Keys)
            {
                UpdateRedpoint(special);
            }
        }
    }
 
    public class TreasureSpecialData
    {
        public TreasurePrivilege type { get; private set; }
        public int progress { get; private set; }
        public int totalProgress { get; private set; }
        public int effectValue { get; private set; }
        public List<AwardItem> items { get; private set; }
        public Dictionary<int, int> propertyDict { get; private set; }
        public Redpoint redpoint { get; private set; }
        public Redpoint privilegeRedpoint { get; private set; }
 
        public int treasureId { get; set; }
        public bool active { get; set; }
 
        private TreasurePrivilegeState m_State = TreasurePrivilegeState.Doing;
        public TreasurePrivilegeState state
        {
            get { return m_State; }
            set { m_State = value; }
        }
 
        public int presentFinishCount { get; set; }
        public int presentGetCount { get; set; }
        public bool itemGet { get; set; }
 
        public TreasureSpecialData(TreasurePrivilege _type)
        {
            type = _type;
            var config = TreasurePrivilegeConfig.Get((int)_type);
            progress = Mathf.Max(1, config.singleValue);
            totalProgress = config.maxValue;
            var _effectValue = 0;
            int.TryParse(config.EffectValue, out _effectValue);
            effectValue = _effectValue;
            treasureId = config.treasureId;
 
            if (!string.IsNullOrEmpty(config.attr))
            {
                var propertyJson = LitJson.JsonMapper.ToObject(config.attr);
                propertyDict = new Dictionary<int, int>();
                foreach (var _key in propertyJson.Keys)
                {
                    var _property = int.Parse(_key);
                    var _value = int.Parse(propertyJson[_key].ToJson());
                    propertyDict.Add(_property, _value);
                }
            }
            if (!string.IsNullOrEmpty(config.itemAward))
            {
                var itemArray = LitJson.JsonMapper.ToObject<int[][]>(config.itemAward);
                if (itemArray != null && itemArray.Length > 0)
                {
                    items = new List<AwardItem>();
                    for (int i = 0; i < itemArray.Length; i++)
                    {
                        var _array = itemArray[i];
                        items.Add(new AwardItem()
                        {
                            isBind = _array[2],
                            item = new Item()
                            {
                                id = _array[0],
                                count = _array[1],
                            },
                        });
                    }
                }
            }
 
            if (type == TreasurePrivilege.PetHp)
            {
                var petCount = PetInfoConfig.GetValues().Count;
                totalProgress = petCount;
            }
            else if (type == TreasurePrivilege.MountAtk)
            {
                var mountConfigs = HorseConfig.GetValues();
                var maxlv = 0;
                for (int i = 0; i < mountConfigs.Count; i++)
                {
                    maxlv += mountConfigs[i].MaxLV;
                }
                totalProgress = maxlv;
            }
            else if (type == TreasurePrivilege.StrengthenAdd)
            {
                var configs = ItemPlusSumAttrConfig.GetValues();
                totalProgress = configs[configs.Count - 1].countNeed;
            }
 
            redpoint = new Redpoint(TreasureSoulModel.TREASURE_SOUL_ID, TreasureSoulModel.TREASURE_SOUL_ID * 100 + (int)type);
            switch (_type)
            {
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.StrengthenAdd:
                case TreasurePrivilege.MountAtk:
                case TreasurePrivilege.PetHp:
                case TreasurePrivilege.Sp:
                case TreasurePrivilege.Wash:
                    privilegeRedpoint = new Redpoint(redpoint.id, redpoint.id * 100 + 2);
                    break;
            }
        }
 
        public int GetPrivilegeValue(int _index = 0)
        {
            switch (type)
            {
                case TreasurePrivilege.RuneBreakExpAdd:
                    return effectValue;
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.Suit:
                    return effectValue;
                case TreasurePrivilege.Wing:
                case TreasurePrivilege.StrengthenAdd:
                    return effectValue;
            }
            return 0;
        }
 
        public void UpdateState()
        {
            switch (type)
            {
                case TreasurePrivilege.Property:
                case TreasurePrivilege.RuneBreakExpAdd:
                case TreasurePrivilege.Wing:
                case TreasurePrivilege.Suit:
                    state = TreasurePrivilegeState.Complete;
                    break;
                case TreasurePrivilege.Sp:
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.PetHp:
                case TreasurePrivilege.MountAtk:
                    if (presentFinishCount >= totalProgress && (presentGetCount / progress) >= (totalProgress / progress))
                    {
                        state = TreasurePrivilegeState.Complete;
                    }
                    else if (presentGetCount > 0 && presentFinishCount / progress < presentGetCount / progress)
                    {
                        state = TreasurePrivilegeState.Reward;
                    }
                    else
                    {
                        state = TreasurePrivilegeState.Doing;
                    }
                    break;
                case TreasurePrivilege.Wash:
                    state = itemGet ? TreasurePrivilegeState.Doing : TreasurePrivilegeState.Reward;
                    break;
                case TreasurePrivilege.StrengthenAdd:
                    var strengthen = ModelCenter.Instance.GetModel<StrengthenModel>();
                    var playerpack = ModelCenter.Instance.GetModel<PackModel>();
                    presentGetCount = 0;
                    foreach (var value in strengthen._EqInfo.Values)
                    {
                        ItemModel itemModel = playerpack.GetItemByIndex(PackType.Equip, value.EquipIndex);
                        if (itemModel != null)
                        {
                            presentGetCount += value.EquipPartStarLV;
                        }
                    }
                    var configs = ItemPlusSumAttrConfig.GetValues();
                    bool contains = configs.FindIndex((x) =>
                    {
                        return x.countNeed > presentFinishCount && presentGetCount >= x.countNeed;
                    }) != -1;
                    if (presentFinishCount >= totalProgress && presentGetCount >= totalProgress)
                    {
                        state = TreasurePrivilegeState.Complete;
                    }
                    else if (contains)
                    {
                        state = TreasurePrivilegeState.Reward;
                    }
                    else
                    {
                        state = TreasurePrivilegeState.Doing;
                    }
                    break;
            }
        }
 
        public string ProgressDisplay()
        {
            switch (type)
            {
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.PetHp:
                case TreasurePrivilege.MountAtk:
                case TreasurePrivilege.Sp:
                    if (state == TreasurePrivilegeState.Complete) { return UIHelper.AppendStringColor(TextColType.Green, totalProgress.ToString(), true); }
                    else if (state == TreasurePrivilegeState.Doing)
                    {
                        return StringUtility.Contact(UIHelper.AppendStringColor(TextColType.Red, presentGetCount.ToString(), true), "/", (presentFinishCount / progress + 1) * progress);
                    }
                    else if (state == TreasurePrivilegeState.Reward)
                    {
                        var _completeCount = (presentFinishCount / progress + 1) * progress;
                        return StringUtility.Contact(UIHelper.AppendStringColor(TextColType.Green, presentGetCount.ToString(), true), "/", _completeCount);
                    }
                    break;
                case TreasurePrivilege.StrengthenAdd:
                    var configs = ItemPlusSumAttrConfig.GetValues();
                    var next = configs.Count - 1;
                    for (int i = 0; i < configs.Count; i++)
                    {
                        if (configs[i].countNeed > presentFinishCount)
                        {
                            next = i;
                            break;
                        }
                    }
                    if (state == TreasurePrivilegeState.Complete) { return totalProgress.ToString(); }
                    else if (state == TreasurePrivilegeState.Doing
                        || state == TreasurePrivilegeState.Reward)
                    {
                        var colortype = presentGetCount >= configs[next].countNeed ? TextColType.Green : TextColType.Red;
                        return StringUtility.Contact(UIHelper.AppendStringColor(colortype, presentGetCount.ToString(), true), "/", configs[next].countNeed);
                    }
                    break;
            }
            return string.Empty;
        }
 
        public void GetReward()
        {
            switch (type)
            {
                case TreasurePrivilege.MountAtk:
                case TreasurePrivilege.DemonJarAtk:
                case TreasurePrivilege.PetHp:
                case TreasurePrivilege.Sp:
                case TreasurePrivilege.Wash:
                    var _pak = new CA504_tagCMPlayerGetReward();
                    _pak.RewardType = (int)GotServerRewardType.Def_RewardType_TreasureSoul;
                    _pak.DataEx = (uint)type;
                    _pak.DataExStrLen = 0;
                    _pak.DataExStr = string.Empty;
                    GameNetSystem.Instance.SendInfo(_pak);
                    break;
                case TreasurePrivilege.StrengthenAdd:
                    var configs = ItemPlusSumAttrConfig.GetValues();
                    var present = 0;
                    for (int i = 0; i < configs.Count; i++)
                    {
                        if (presentGetCount >= configs[i].countNeed)
                        {
                            present = i;
                        }
                    }
                    CA503_tagCMActiveAllEquipAttr pak = new CA503_tagCMActiveAllEquipAttr();
                    pak.Type = 0;
                    pak.Cnt = (uint)configs[present].countNeed;
                    GameNetSystem.Instance.SendInfo(pak);
                    break;
            }
        }
 
        public int GetFightPower()
        {
            var _fightPower = 0;
            if (propertyDict != null)
            {
                _fightPower += UIHelper.GetFightPower(propertyDict);
            }
            return _fightPower;
        }
    }
 
    public enum TreasurePrivilegeState
    {
        Doing = 0,
        Reward = 1,
        Complete = 2
    }
 
    public enum TreasurePrivilege
    {
        Property = 1,
        DemonJarAtk = 2,
        StrengthenAdd = 3,
        RuneBreakExpAdd = 4,
        MountAtk = 5,
        PetHp = 6,
        Sp = 7,
        Wing = 8,
        Suit = 9,
        Wash = 10,
        Sign = 11,
    }
}