少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
using System;
using System.Linq;
 
namespace vnxbqy.UI
{
    
    public class TalentModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize
    {
        Dictionary<int, TalentSkill> talentSkills = new Dictionary<int, TalentSkill>();
        Dictionary<int, TalentTree> talentTreeDict = new Dictionary<int, TalentTree>();
 
        int m_SelectSeries;
        public int selectSeries
        {
            get { return m_SelectSeries; }
            set
            {
                if (m_SelectSeries != value && selectSeriesEvent != null)
                {
                    m_SelectSeries = value;
                    selectSeriesEvent();
                }
                m_SelectSeries = value;
            }
        }
        int m_SelectTalentType;
        public int selectTalentType
        {
            get { return m_SelectTalentType; }
            set
            {
                if (m_SelectTalentType != value && selectTalentTypeEvnet != null)
                {
                    m_SelectTalentType = value;
                    selectTalentTypeEvnet();
                }
                m_SelectTalentType = value;
            }
        }
        int m_SelectSkill;
        public int selectSkill
        {
            get { return m_SelectSkill; }
            set
            {
                if (m_SelectSkill != value && selectSkillEvent != null)
                {
                    m_SelectSkill = value;
                    selectSkillEvent();
                }
                m_SelectSkill = value;
            }
        }
 
        bool serverInited = false;
 
        public event Action selectTalentTypeEvnet;
        public event Action selectSeriesEvent;
        public event Action selectSkillEvent;
        public event Action talentPointUpdate;
        public event Action<int> talentSkillUpdate;
        public event Action<int> talentSkillLevelUp;
 
        public override void Init()
        {
            ParseConfig();
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
            PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            foreach (var talent in talentSkills.Values)
            {
                talent.level = 0;
            }
            serverInited = false;
        }
 
        public void OnPlayerLoginOk()
        {
            serverInited = true;
            if (WindowCenter.Instance.IsOpen<TalentWin>())
            {
                foreach (var talent in talentSkills.Values)
                {
                    if (talentSkillUpdate != null)
                    {
                        talentSkillUpdate(talent.skillId);
                    }
                }
            }
            UpdateRedpoint();
        }
 
        public override void UnInit()
        {
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
            PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
        }
 
        private void OnFuncStateChangeEvent(int _id)
        {
            if (_id == (int)FuncOpenEnum.Talent)
            {
                UpdateRedpoint();
            }
        }
 
        public int talentResetBook { get; private set; }
        public int talentResetBookCost { get; private set; }
        Dictionary<int, List<int>> jobTalentTypeDict = new Dictionary<int, List<int>>();
        void ParseConfig()
        {
            var configs = TalentConfig.GetValues();
            for (int i = 0; i < configs.Count; i++)
            {
                var skillId = configs[i].skillId;
                var skillConfig = SkillConfig.Get(skillId);
                TalentSkill talent;
                if (!TryGetTalent(skillConfig.SkillTypeID, out talent))
                {
                    talent = new TalentSkill(skillConfig.SkillTypeID, skillConfig.SkillMaxLV);
                    talent.level = 0;
                    talentSkills.Add(skillConfig.SkillTypeID, talent);
 
                    TalentTree talentTree;
                    if (!talentTreeDict.TryGetValue(skillConfig.UseType, out talentTree))
                    {
                        talentTree = new TalentTree();
                        talentTreeDict.Add(skillConfig.UseType, talentTree);
                    }
                    talentTree.Add(configs[i], skillConfig.SkillTypeID);
 
                    List<int> list = null;
                    if (!jobTalentTypeDict.TryGetValue(skillConfig.UseType, out list))
                    {
                        list = new List<int>();
                        jobTalentTypeDict.Add(skillConfig.UseType, list);
                    }
                    if (!list.Contains(configs[i].type))
                    {
                        list.Add(configs[i].type);
                    }
                }
            }
            var jobs = jobTalentTypeDict.Keys.ToList();
            for (int i = 0; i < jobs.Count; i++)
            {
                var list = jobTalentTypeDict[jobs[i]];
                list.Sort((x, y) =>
                {
                    return x.CompareTo(y);
                });
            }
 
 
            var config = FuncConfigConfig.Get("TalentResetBook");
            talentResetBook = int.Parse(config.Numerical1);
            talentResetBookCost = int.Parse(config.Numerical2);
        }
 
        public int GetTalentType(int index)
        {
            var job = (int)Math.Pow(2, PlayerDatas.Instance.baseData.Job);
            if (jobTalentTypeDict.ContainsKey(job))
            {
                var list = jobTalentTypeDict[job];
                return index < list.Count ? list[index] : list[0];
            }
            return 1;
        }
 
        public int talentTypeCount
        {
            get
            {
                var job = (int)Math.Pow(2, PlayerDatas.Instance.baseData.Job);
                if (jobTalentTypeDict.ContainsKey(job))
                {
                    var list = jobTalentTypeDict[job];
                    return list.Count;
                }
                return 0;
            }
        }
 
        public bool TryGetTalents(int job, int talentType, int talentSeries, out List<int> talents)
        {
            talents = null;
            TalentTree talentTree = null;
            var _job = (int)Math.Pow(2, job);
            talentTreeDict.TryGetValue(_job, out talentTree);
            if (null != talentTree)
            {
                return talentTree.TryGetTalents(talentType, talentSeries, out talents);
            }
            return false;
        }
 
        public bool TryGetTalent(int talentId, out TalentSkill talent)
        {
            return talentSkills.TryGetValue(talentId, out talent);
        }
 
        public int GetTalentTypePoint(int talentType)
        {
            var point = 0;
            for (int i = 1; i <= 3; i++)
            {
                point += GetSeriesPoint(talentType, i);
            }
            return point;
        }
 
        public int GetAllTalentPoint()
        {
            var point = 0;
            var job = (int)Math.Pow(2, PlayerDatas.Instance.baseData.Job);
            if (jobTalentTypeDict.ContainsKey(job))
            {
                var list = jobTalentTypeDict[job];
                for (int i = 0; i < list.Count; i++)
                {
                    point += GetTalentTypePoint(list[i]);
                }
            }
            return point;
        }
 
        public int GetSeriesPoint(int talentType, int talentSeries)
        {
            var job = PlayerDatas.Instance.baseData.Job;
            List<int> list;
            var point = 0;
            if (TryGetTalents(job, talentType, talentSeries, out list))
            {
                for (int i = 0; i < list.Count; i++)
                {
                    TalentSkill talent;
                    if (TryGetTalent(list[i], out talent))
                    {
                        point += talent.level;
                    }
                }
            }
            return point;
        }
 
        public bool SatisfyLevelUp(int talentId, out int error)
        {
            error = 0;
            TalentSkill talent;
            if (TryGetTalent(talentId, out talent))
            {
                if (talent.level >= talent.maxLevel)
                {
                    error = 1;
                    return false;
                }
                if (talentPoint <= 0)
                {
                    error = 2;
                    return false;
                }
                var talentConfig = talent.GetTalentConfig(talent.level + 1);
                var skillConfig = talent.GetSkillConfig(talent.level + 1);
                var requireSeriesPoint = skillConfig.RequireTalentSeriesPoint();
                if (requireSeriesPoint != 0)
                {
                    var requireSeries = skillConfig.RequireTalentSeries();
                    if (GetSeriesPoint(talentConfig.type, requireSeries) < requireSeriesPoint)
                    {
                        error = 3;
                        return false;
                    }
                }
                if (skillConfig.LearnSkillReq != 0)
                {
                    var reqSkillConfig = SkillConfig.Get(skillConfig.LearnSkillReq);
                    if (reqSkillConfig.FuncType == 1)
                    {
                        if (PlayerDatas.Instance.skill.GetSKillById(skillConfig.LearnSkillReq) == null)
                        {
                            error = 6;
                            return false;
                        }
                    }
                    else
                    {
                        TalentSkill learnTalent;
                        if (TryGetTalent(skillConfig.LearnSkillReq, out learnTalent))
                        {
                            if (learnTalent.level < skillConfig.LearnSkillLV)
                            {
                                error = 4;
                                return false;
                            }
                        }
                    }
                }
                var requireProperty = skillConfig.RequireProperty();
                if (requireProperty != 0)
                {
                    var requirePropertyValue = skillConfig.RequirePropertyValue();
                    if (UIHelper.GetPropertyValue((PropertyType)requireProperty) < (ulong)requirePropertyValue)
                    {
                        error = 5;
                        return false;
                    }
                }
            }
            return true;
        }
 
        public void ProcessLevelUpError(int talentId, int error)
        {
            switch (error)
            {
                case 1:
                    SysNotifyMgr.Instance.ShowTip("TalentHighestLevel");
                    break;
                case 2:
                    SysNotifyMgr.Instance.ShowTip("LackTalentPoint");
                    break;
                case 3:
                    SysNotifyMgr.Instance.ShowTip("LackTalentSeriesPoint");
                    break;
                case 4:
                    SysNotifyMgr.Instance.ShowTip("PreTalentLevelLimit");
                    break;
                case 5:
                    SysNotifyMgr.Instance.ShowTip("TalentRequirePropertyLimit");
                    break;
                case 6:
                    TalentSkill talent;
                    if (TryGetTalent(talentId, out talent))
                    {
                        var skillConfig = talent.GetSkillConfig();
                        var treasureModel = ModelCenter.Instance.GetModel<TreasureModel>();
                        var treasureId = treasureModel.GetTreasureBySkillId(skillConfig.LearnSkillReq);
                        var treasureConfig = TreasureConfig.Get(treasureId);
                        SysNotifyMgr.Instance.ShowTip("PreTreasureSkillLimit", treasureConfig.Name);
                    }
                    break;
            }
        }
 
        #region 服务端数据
        public int talentPoint { get { return PlayerDatas.Instance.extersion.talentPoint; } }
 
        private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
        {
            if (refreshType == PlayerDataType.CDBPlayerRefresh_TalentPoint)
            {
                if (talentPointUpdate != null)
                {
                    talentPointUpdate();
                }
                UpdateRedpoint();
            }
            else if (refreshType == PlayerDataType.STR
                || refreshType == PlayerDataType.PNE
                || refreshType == PlayerDataType.PHY
                || refreshType == PlayerDataType.CON)
            {
                UpdateRedpoint();
            }
        }
 
        public void UpdateTalentSkill(int _oldSkillId, int _newSkillId)
        {
            var config = SkillConfig.Get(_newSkillId);
            if (config == null)
            {
                return;
            }
            if (talentSkills.ContainsKey(config.SkillTypeID))
            {
                var talentSkill = talentSkills[config.SkillTypeID];
                bool levelUp = talentSkill.level < config.SkillLV;
                talentSkill.level = config.SkillLV;
                if (talentSkillUpdate != null)
                {
                    talentSkillUpdate(config.SkillTypeID);
                }
                if (levelUp && serverInited)
                {
                    if (talentSkillLevelUp != null)
                    {
                        talentSkillLevelUp(config.SkillTypeID);
                    }
                }
            }
            UpdateRedpoint();
        }
 
        public void DeleteTalentSkill(int _skillId)
        {
            var config = SkillConfig.Get(_skillId);
            if (config == null)
            {
                return;
            }
            if (talentSkills.ContainsKey(config.SkillTypeID))
            {
                var talentSkill = talentSkills[config.SkillTypeID];
                talentSkill.level = 0;
                if (talentSkillUpdate != null)
                {
                    talentSkillUpdate(config.SkillTypeID);
                }
            }
            UpdateRedpoint();
        }
        #endregion
 
        #region 红点
        public Redpoint talentRedpoint = new Redpoint(103, 10303);
        void UpdateRedpoint()
        {
            talentRedpoint.state = RedPointState.None;
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Talent))
            {
                return;
            }
            if (talentPoint == 0)
            {
                return;
            }
            var error = 0;
            foreach (var talent in talentSkills.Values)
            {
                if (SatisfyLevelUp(talent.skillId, out error))
                {
                    talentRedpoint.state = RedPointState.Simple;
                    break;
                }
            }
        }
        #endregion
    }
 
    public class TalentSkill
    {
        public int skillId { get; private set; }
        public int level { get; set; }
        public int maxLevel { get; private set; }
 
        public TalentSkill(int skillId, int maxLevel)
        {
            this.skillId = skillId;
            this.maxLevel = maxLevel;
        }
 
        public SkillConfig GetSkillConfig(int level = 0)
        {
            if (level > 0)
            {
                return SkillConfig.Get(skillId + level - 1);
            }
            else
            {
                return SkillConfig.Get(skillId + level);
            }
        }
 
        public TalentConfig GetTalentConfig(int level = 0)
        {
            return TalentConfig.Get(skillId);
        }
    }
 
    public class TalentSeries
    {
        public int series { get; private set; }
        public List<int> talentSkills { get; private set; }
 
        public TalentSeries(int series)
        {
            this.series = series;
            talentSkills = new List<int>();
        }
 
        public void Add(int skillId)
        {
            if (talentSkills.Contains(skillId))
            {
                return;
            }
            talentSkills.Add(skillId);
        }
    }
 
    public class TalentTree
    {
        Dictionary<int, List<TalentSeries>> talentSeriesDict = new Dictionary<int, List<TalentSeries>>();
 
        public void Add(TalentConfig config, int skillId)
        {
            List<TalentSeries> list = null;
            if (!talentSeriesDict.TryGetValue(config.type, out list))
            {
                list = new List<TalentSeries>();
                talentSeriesDict.Add(config.type, list);
            }
            TalentSeries talentSeries = list.Find((x) =>
             {
                 return x.series == config.series;
             });
            if (talentSeries == null)
            {
                talentSeries = new TalentSeries(config.series);
                list.Add(talentSeries);
            }
            talentSeries.Add(skillId);
        }
 
        public bool TryGetTalents(int type, int series, out List<int> list)
        {
            list = null;
            if (talentSeriesDict.ContainsKey(type))
            {
                var talentSeries = talentSeriesDict[type].Find((x) =>
                 {
                     return x.series == series;
                 });
                if (talentSeries != null)
                {
                    list = talentSeries.talentSkills;
                    return true;
                }
            }
            return false;
        }
    }
 
    public static class TalentHelper
    {
        public static int RequireTalentSeries(this SkillConfig config)
        {
            if (config == null)
            {
                return 0;
            }
            return config.LearnSkillPointReq / 10000;
        }
 
        public static int RequireTalentSeriesPoint(this SkillConfig config)
        {
            if (config == null)
            {
                return 0;
            }
            return config.LearnSkillPointReq % 10000;
        }
 
        public static int RequireProperty(this SkillConfig config)
        {
            if (config == null)
            {
                return 0;
            }
            return config.StateSkillLV / 100000;
        }
 
        public static int RequirePropertyValue(this SkillConfig config)
        {
            if (config == null)
            {
                return 0;
            }
            return config.StateSkillLV % 100000;
        }
    }
}