少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 f1f2599ba0e6b64358ffef7ae5c9f9af3ed8b8b4
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Snxxz.UI
{
    [XLua.LuaCallCSharp]
    [XLua.Hotfix]
    public class TreasureSkillModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        Dictionary<int, TreasureSkill> treasureSkills = new Dictionary<int, TreasureSkill>();
        Dictionary<int, List<int>> jobTreasureSkills = new Dictionary<int, List<int>>();
 
        public List<int> skillLevelUpItems = new List<int>();
 
        int m_SelectSkill;
        public int selectSkill
        {
            get { return m_SelectSkill; }
            set
            {
                if (m_SelectSkill != value)
                {
                    m_SelectSkill = value;
                    if (selectRefresh != null)
                    {
                        selectRefresh();
                    }
                }
            }
        }
 
        bool serverInited = false;
 
        public bool requireRemind { get; private set; }
 
        public readonly Redpoint redpoint = new Redpoint(103, 10304);
        public const int REDPOINTID_BASE = 10304000;
        public static int redpointIndex = 100;
 
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
        public event Action selectRefresh;
        public event Action<int> treasureSkillRefresh;
        public event Action<int> skillLevelUpRefresh;
        public event Action<int, int> potentialLevelRefresh;
        public override void Init()
        {
            ParseConfig();
 
            packModel.refreshItemCountEvent += RefreshItemCountAct;
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            foreach (var skill in treasureSkills.Values)
            {
                skill.Reset();
            }
            serverInited = false;
        }
 
        public void OnPlayerLoginOk()
        {
            serverInited = true;
            requireRemind = true;
            UpdateRedpoint();
        }
 
        public override void UnInit()
        {
            packModel.refreshItemCountEvent -= RefreshItemCountAct;
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
        }
 
        private void OnFuncStateChangeEvent(int id)
        {
            if (id == 82)
            {
                UpdateRedpoint();
            }
        }
 
        private void RefreshItemCountAct(PackType packType, int arg2, int itemId)
        {
            if (packType == PackType.Item && skillLevelUpItems.Contains(itemId))
            {
                if (serverInited)
                {
                    requireRemind = true;
                }
                UpdateRedpoint();
            }
        }
 
        void ParseConfig()
        {
            var configs = TreasureSkillConfig.GetValues();
            var index = 0;
            foreach (var config in configs)
            {
                TreasureSkill treasureSkill;
                if (!treasureSkills.TryGetValue(config.limitSkillId, out treasureSkill))
                {
                    treasureSkill = new TreasureSkill(config.limitSkillId, index);
                    treasureSkills.Add(config.limitSkillId, treasureSkill);
                    index++;
                }
                treasureSkill.potentials.Add(new TreasurePotential(config.id, 0,
                    config.limitLevel, treasureSkill.redpoint.id));
                var skillConfig = SkillConfig.Get(config.limitSkillId);
 
                List<int> skills;
                if (!jobTreasureSkills.TryGetValue(skillConfig.UseType, out skills))
                {
                    skills = new List<int>();
                    jobTreasureSkills.Add(skillConfig.UseType, skills);
                }
                if (!skills.Contains(config.limitSkillId))
                {
                    skills.Add(config.limitSkillId);
                }
            }
 
            foreach (var skill in treasureSkills.Values)
            {
                for (int i = 1; i <= skill.maxLevel; i++)
                {
                    var config = skill.GetSkillConfig(i);
                    if (!skillLevelUpItems.Contains(config.ExAttr4))
                    {
                        skillLevelUpItems.Add(config.ExAttr4);
                    }
                }
 
                foreach (var potential in skill.potentials)
                {
                    for (int i = 1; i <= potential.maxLevel; i++)
                    {
                        var config = potential.GetSkillConfig(i);
                        if (!skillLevelUpItems.Contains(config.ExAttr4))
                        {
                            skillLevelUpItems.Add(config.ExAttr4);
                        }
                    }
                }
            }
        }
 
        public bool TryGetSkills(out List<int> skills)
        {
            var job = PlayerDatas.Instance.baseData.Job;
            var useType = (int)Mathf.Pow(2, job);
            return jobTreasureSkills.TryGetValue(useType, out skills);
        }
 
        public bool TryGetSkill(int skillId, out TreasureSkill treasureSkill)
        {
            return treasureSkills.TryGetValue(skillId, out treasureSkill);
        }
 
        public bool TryGetPotential(int skillId, out TreasurePotential potential)
        {
            var treasureSkillId = 0;
            potential = null;
            if (ContainsSkill(skillId, out treasureSkillId))
            {
                var treasureSkill = treasureSkills[treasureSkillId];
                potential = treasureSkill.potentials.Find((x) =>
                {
                    return x.id == skillId;
                });
                return potential != null;
            }
            return false;
        }
 
        public bool IsPotentialUnlock(int skillId)
        {
            var treasureSkillId = 0;
            if (ContainsSkill(skillId, out treasureSkillId))
            {
                var treasureSkill = treasureSkills[treasureSkillId];
                TreasurePotential potential;
                if (TryGetPotential(skillId, out potential))
                {
                    return treasureSkill.level >= potential.openLevel;
                }
            }
            return false;
        }
 
        public void OnReceivePackage(int oldSkillID, int newSkillID)
        {
            var config = SkillConfig.Get(newSkillID);
            var skillTypeId = config.SkillTypeID;
            var treasureSkillId = 0;
            if (ContainsSkill(skillTypeId, out treasureSkillId))
            {
                var treasureSkill = treasureSkills[treasureSkillId];
 
                var level = 0;
                if (skillTypeId == treasureSkillId)
                {
                    level = treasureSkill.level;
                }
                else
                {
                    TreasurePotential potential;
                    if (TryGetPotential(skillTypeId, out potential))
                    {
                        level = potential.level;
                    }
                }
 
                treasureSkill.Refresh(newSkillID);
 
                bool levelUp = false;
                if (skillTypeId == treasureSkillId)
                {
                    levelUp = treasureSkill.level > level;
                }
                else
                {
                    TreasurePotential potential;
                    if (TryGetPotential(skillTypeId, out potential))
                    {
                        levelUp = potential.level > level;
                    }
 
                    if (potential != null && potentialLevelRefresh != null)
                    {
                        potentialLevelRefresh(skillTypeId, potential.level);
                    }
                }
 
                if (levelUp && serverInited)
                {
                    if (skillLevelUpRefresh != null)
                    {
                        skillLevelUpRefresh(skillTypeId);
                    }
                }
 
                if (treasureSkillRefresh != null)
                {
                    treasureSkillRefresh(skillTypeId);
                }
 
                UpdateRedpoint();
            }
        }
 
        public bool TryLevelUpTreasureSkill(int skillId, out int error)
        {
            error = 0;
            TreasureSkill skill;
            if (TryGetSkill(skillId, out skill))
            {
                if (skill.level >= skill.maxLevel)
                {
                    error = 1;
                    return false;
                }
                var upConfig = skill.GetSkillConfig(skill.level + 1);
                var count = packModel.GetItemCountByID(PackType.Item, upConfig.ExAttr4);
                if (count < upConfig.ExAttr5)
                {
                    error = 2;
                    return false;
                }
            }
            return true;
        }
 
        public bool TryLevelUpPotential(int skillId, out int error)
        {
            error = 0;
            TreasurePotential potential;
            if (TryGetPotential(skillId, out potential))
            {
                if (potential.level >= potential.maxLevel)
                {
                    error = 11;
                    return false;
                }
                var config = potential.GetSkillConfig(potential.level);
                if (config.LearnSkillReq != 0 && config.LearnSkillLV > 0)
                {
                    TreasurePotential requirePotential;
                    if (!TryGetPotential(config.LearnSkillReq, out requirePotential)
                        || requirePotential.level < config.LearnSkillLV)
                    {
                        error = 12;
                        return false;
                    }
                }
                var upConfig = potential.GetSkillConfig(potential.level + 1);
                var count = packModel.GetItemCountByID(PackType.Item, upConfig.ExAttr4);
                if (count < upConfig.ExAttr5)
                {
                    error = 13;
                    return false;
                }
            }
            return true;
        }
 
        public void DisplayLevelUpError(int error)
        {
            switch (error)
            {
                case 1:
                    break;
                case 2:
                    SysNotifyMgr.Instance.ShowTip("TreasureSkillLevelUpError2");
                    break;
                case 11:
                    break;
                case 12:
                    break;
                case 13:
                    break;
            }
        }
 
        public bool ContainsSkill(int skillId, out int treasureSkillId)
        {
            treasureSkillId = 0;
            foreach (var skill in treasureSkills.Values)
            {
                if (skill.skillId == skillId)
                {
                    treasureSkillId = skill.skillId;
                    return true;
                }
                if (skill.potentials.FindIndex((x) =>
                 {
                     return x.id == skillId;
                 }) != -1)
                {
                    treasureSkillId = skill.skillId;
                    return true;
                }
            }
            return false;
        }
 
        public void SetAlreadyRemind()
        {
            requireRemind = false;
            UpdateRedpoint();
        }
 
        void UpdateRedpoint()
        {
            var funcOpen = FuncOpen.Instance.IsFuncOpen(82);
            foreach (var skill in treasureSkills.Values)
            {
                var error = 0;
                if (requireRemind && funcOpen &&
                    TryLevelUpTreasureSkill(skill.skillId, out error)
                    && skill.level > 0)
                {
                    skill.levelUpRedpoint.state = RedPointState.Simple;
                }
                else
                {
                    skill.levelUpRedpoint.state = RedPointState.None;
                }
 
                foreach (var potential in skill.potentials)
                {
                    if (requireRemind && funcOpen && IsPotentialUnlock(potential.id) &&
                        TryLevelUpPotential(potential.id, out error)
                        && skill.level > 0)
                    {
                        potential.levelUpRedpoint.state = RedPointState.Simple;
                    }
                    else
                    {
                        potential.levelUpRedpoint.state = RedPointState.None;
                    }
                }
            }
        }
    }
 
    public class TreasureSkill
    {
        public readonly int skillId;
        public readonly int maxLevel;
 
        public int level { get; private set; }
        public Redpoint redpoint { get; private set; }
        public Redpoint levelUpRedpoint { get; private set; }
        public List<TreasurePotential> potentials { get; private set; }
 
        public TreasureSkill(int skillId, int redpointIndex)
        {
            this.skillId = skillId;
            potentials = new List<TreasurePotential>();
 
            var config = SkillConfig.Get(skillId);
            maxLevel = config.SkillMaxLV;
 
            redpoint = new Redpoint(10304,
                TreasureSkillModel.REDPOINTID_BASE + redpointIndex);
            levelUpRedpoint = new Redpoint(redpoint.id,
                TreasureSkillModel.REDPOINTID_BASE + TreasureSkillModel.redpointIndex++);
        }
 
        public SkillConfig GetSkillConfig(int level)
        {
            if (level > 0)
            {
                return SkillConfig.Get(skillId + level - 1);
            }
            else
            {
                return SkillConfig.Get(skillId + level);
            }
        }
 
        public void Refresh(int newSkillId)
        {
            var config = SkillConfig.Get(newSkillId);
            if (config.SkillTypeID == skillId)
            {
                level = config.SkillLV;
            }
            else
            {
                var index = potentials.FindIndex((x) =>
                {
                    return x.id == config.SkillTypeID;
                });
                if (index != -1)
                {
                    potentials[index].Refresh(newSkillId);
                }
            }
        }
 
        public void Reset()
        {
            level = 0;
            foreach (var potential in potentials)
            {
                potential.Reset();
            }
        }
    }
 
    public class TreasurePotential
    {
        public readonly int id;
        public readonly int openLevel;
        public readonly int maxLevel;
        public int level { get; private set; }
 
        public Redpoint levelUpRedpoint { get; private set; }
 
        public TreasurePotential(int id, int level, int openLevel, int redpointBase)
        {
            this.id = id;
            this.level = level;
            this.openLevel = openLevel;
 
            var config = SkillConfig.Get(id);
            maxLevel = config.SkillMaxLV;
 
            levelUpRedpoint = new Redpoint(redpointBase,
                TreasureSkillModel.REDPOINTID_BASE + TreasureSkillModel.redpointIndex++);
        }
 
        public SkillConfig GetSkillConfig(int level)
        {
            if (level > 0)
            {
                return SkillConfig.Get(id + level - 1);
            }
            else
            {
                return SkillConfig.Get(id + level);
            }
        }
 
        public void Refresh(int newSkillId)
        {
            var config = SkillConfig.Get(newSkillId);
            if (config.SkillTypeID == id)
            {
                level = config.SkillLV;
            }
        }
 
        public void Reset()
        {
            level = 0;
        }
    }
}