少年修仙传客户端代码仓库
client_linchunjie
2018-09-19 4ddb4556bde9483379cb1a56025c95dfb008192d
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TableConfig;
using System;
 
namespace Snxxz.UI
{
    public class TalentModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize
    {
        Dictionary<int, TalentSkill> talentSkillDict = new Dictionary<int, TalentSkill>();
        Dictionary<int, Dictionary<int, List<int>>> talentSkills = new Dictionary<int, Dictionary<int, List<int>>>();
 
        int m_SelectSeries;
        public int selectSeries
        {
            get { return m_SelectSeries; }
            set
            {
                if (m_SelectSeries != value && OnSelectSeriesEvent != null)
                {
                    m_SelectSeries = value;
                    OnSelectSeriesEvent();
                }
                m_SelectSeries = value;
            }
        }
        int m_SelectTalentType;
        public int selectTalentType
        {
            get { return m_SelectTalentType; }
            set
            {
                if (m_SelectTalentType != value && OnSelectTalentTypeEvnet != null)
                {
                    m_SelectTalentType = value;
                    OnSelectTalentTypeEvnet();
                }
                m_SelectTalentType = value;
            }
        }
        int m_SelectSkill;
        public int selectSkill
        {
            get { return m_SelectSkill; }
            set
            {
                if (m_SelectSkill != value && OnSelectSkillEvent != null)
                {
                    m_SelectSkill = value;
                    OnSelectSkillEvent();
                }
                m_SelectSkill = value;
            }
        }
 
        public event Action OnSelectTalentTypeEvnet;
        public event Action OnSelectSeriesEvent;
        public event Action OnSelectSkillEvent;
        public event Action talentPointUpdate;
        public event Action<int> talentSkillUpdate;
 
        public override void Init()
        {
            //ParseConfig();
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            foreach (var talent in talentSkillDict.Values)
            {
                talent.level = 0;
            }
        }
 
        public void OnPlayerLoginOk()
        {
        }
 
        public override void UnInit()
        {
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
        }
 
        private void OnFuncStateChangeEvent(int _id)
        {
            if (_id == (int)FuncOpenEnum.Talent)
            {
                UpdateRedpoint();
            }
        }
 
        void ParseConfig()
        {
            var configs = Config.Instance.GetAllValues<TalentConfig>();
            for (int i = 0; i < configs.Count; i++)
            {
                var skillId = configs[i].SkillId;
                var skillConfig = Config.Instance.Get<SkillConfig>(skillId);
                TalentSkill talent;
                if (!TryGetTalent(skillConfig.SkillTypeID, out talent))
                {
                    talent = new TalentSkill(skillConfig.SkillTypeID, skillConfig.SkillMaxLV);
                    talent.level = 0;
                    talentSkillDict.Add(skillConfig.SkillTypeID, talent);
 
                    Dictionary<int, List<int>> dict = null;
                    if (!talentSkills.TryGetValue(skillConfig.UseType, out dict))
                    {
                        dict = new Dictionary<int, List<int>>();
                        talentSkills.Add(skillConfig.UseType, dict);
                    }
                    List<int> list = null;
                    var type = configs[i].series * 10 + configs[i].talentType;
                    if (!dict.TryGetValue(type, out list))
                    {
                        list = new List<int>();
                        dict.Add(type, list);
                    }
                    list.Add(skillConfig.SkillTypeID);
                }
            }
        }
 
        public bool TryGetTalents(int job, int series, int talentType, out List<int> talents)
        {
            talents = null;
            Dictionary<int, List<int>> dict = null;
            var _job = (int)Math.Pow(2, job);
            talentSkills.TryGetValue(_job, out dict);
            if (null != dict)
            {
                return dict.TryGetValue(series * 10 + talentType, out talents);
            }
            return false;
        }
 
        public bool TryGetTalent(int talentId,out TalentSkill talent)
        {
            return talentSkillDict.TryGetValue(talentId, out talent);
        }
 
        public int GetTalentTypeTotalPoint(int series, int talentType)
        {
            var job = (int)Math.Pow(PlayerDatas.Instance.baseData.Job, 2);
            List<int> list;
            var point = 0;
            if (TryGetTalents(job, series, talentType, 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.max)
                {
                    error = 1;
                    return false;
                }
                if (talentPoint <= 0)
                {
                    error = 2;
                    return false;
                }
                var talentConfig = Config.Instance.Get<TalentConfig>(talent.skillId + talent.level);
                if (talentConfig.property != 0)
                {
                    if (UIHelper.GetPropertyMapPlayerData((AttrEnum)talentConfig.property) < talentConfig.propertyValue)
                    {
                        error = 3;
                        return false;
                    }
                }
                if (talentConfig.seriesCondition != 0)
                {
                    if (GetTalentTypeTotalPoint(talentConfig.series, talentConfig.seriesCondition) < talentConfig.point)
                    {
                        error = 4;
                        return false;
                    }
                }
                var skillConfig = Config.Instance.Get<SkillConfig>(talent.skillId + talent.level);
                if (skillConfig.LearnSkillReq != 0)
                {
                    TalentSkill learnTalent;
                    if (TryGetTalent(skillConfig.LearnSkillReq, out learnTalent))
                    {
                        if (learnTalent.level < skillConfig.LearnSkillLV)
                        {
                            error = 5;
                            return false;
                        }
                    }
                }
            }
            return true;
        }
 
        public void ProcessLevelUpError(int error)
        {
 
        }
 
        #region 服务端数据
        public int talentPoint { get; private set; }
 
        public void UpdateTalent()
        {
 
            UpdateRedpoint();
        }
        #endregion
 
        #region 红点
        Redpoint talentRedpoint = new Redpoint(103, 10303);
        void UpdateRedpoint()
        {
            talentRedpoint.state = RedPointState.None;
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Talent))
            {
                return;
            }
            if (talentPoint > 0)
            {
                talentRedpoint.state = RedPointState.Simple;
            }
        }
        #endregion
    }
 
    public class TalentSkill
    {
        public int skillId { get; private set; }
        public int level { get; set; }
        public int max { get; private set; }
 
        public TalentSkill(int id, int maxLevel)
        {
            skillId = id;
            max = maxLevel;
        }
    }
}