少年修仙传客户端代码仓库
hch
2025-07-02 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using LitJson;
using UnityEngine;
 
public class ShentongModel : ILModel<ShentongModel>
{
    public Dictionary<int, structShentongLV> shentongDict = new Dictionary<int, structShentongLV>();
    public List<int> shentongSetSkillIDs = new List<int>(); //已放置的神通技能
    public List<int> shentongIDSortBySkillID = new List<int>();    //已出战神通的顺序
    public List<int> shentongIDList = new List<int>(); //神通列表(排序)
    Dictionary<int, int> gubaoToShentong = new Dictionary<int, int>();
    public Dictionary<int, int> shentongIDToSkillID = new Dictionary<int, int>();  //已学的神通对应技能
    public event Action UpdateShentongEvent;
    public event Action UpdateShentongSkillEvent;
    Dictionary<int, int> skillIDToShentongIDDict = new Dictionary<int, int>();  //所有神通技能(含不同等级)对应神通ID
    Dictionary<int, Redpoint> redpoints = new Dictionary<int, Redpoint>();
    public int[] skillSetLimitLV;
 
    public bool isShowShentongSkill;
 
    public event Action SelectEvent;
 
    private int m_SelectType;
    public int selectShentong
    {
        get { return m_SelectType; }
        set
        {
            m_SelectType = value;
            m_SelectShentongSkillID = 0;
            SelectEvent?.Invoke();
        }
 
    }
 
    public event Action SelectShentongSkillIDEvent;
    private int m_SelectShentongSkillID;
    public int selectShentongSkillID
    {
        get { return m_SelectShentongSkillID; }
        set
        {
            m_SelectShentongSkillID = value;
            SelectShentongSkillIDEvent?.Invoke();
        }
 
    }
 
    public event Action OnSkillPositionStateEvent;
    private int m_SkillPositionState;
    public int skillPositionState
    {
        get { return m_SkillPositionState; }
        set
        {
            m_SkillPositionState = value;
            OnSkillPositionStateEvent?.Invoke();
        }
 
    }
 
 
    public int shentongPoint = MainRedPoint.faqiRedPoint * 10 + 2;
    public Redpoint redpoint1 = new Redpoint(MainRedPoint.faqiRedPoint, MainRedPoint.faqiRedPoint * 10 + 2);
 
    PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
    protected override void Init()
    {
        ParseConfig();
        GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitializeEvent;
        GameEvent.playerLoginOkEvent += OnPlayerLoginOkEvent;
        packModel.refreshItemCountEvent += OnRefreshItem;
 
    }
 
    protected override void UnInit()
    {
        GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitializeEvent;
        packModel.refreshItemCountEvent -= OnRefreshItem;
        GameEvent.playerLoginOkEvent -= OnPlayerLoginOkEvent;
    }
 
 
    void ParseConfig()
    {
        var keys = ILShentongConfig.GetKeys();
        for (int i = 0; i < keys.Count; i++)
        {
            var id = int.Parse(keys[i]);
            shentongIDList.Add(id);
            redpoints.Add(id, new Redpoint(shentongPoint, shentongPoint * 1000 + id));
            gubaoToShentong[ILShentongConfig.Get(id).NeedGubaoID] = id;
        }
 
        keys = ILShentongLVConfig.GetKeys();
        for (int i = 0; i < keys.Count; i++)
        {
            var config = ILShentongLVConfig.Get(keys[i]);
            skillIDToShentongIDDict[config.LVSkillID] = config.ShentongID;
        }
 
        var configFunc = FuncConfigConfig.Get("Shentong");
 
        skillSetLimitLV = JsonMapper.ToObject<int[]>(configFunc.Numerical1);
        for (int i = 0; i < skillSetLimitLV.Length; i++)
        {
            shentongSetSkillIDs.Add(0);
            shentongIDSortBySkillID.Add(0);
        }
 
    }
 
    void OnBeforePlayerDataInitializeEvent()
    {
        shentongDict.Clear();
        shentongSetSkillIDs.Clear();
        shentongIDSortBySkillID.Clear();
        for (int i = 0; i < skillSetLimitLV.Length; i++)
        {
            shentongSetSkillIDs.Add(0);
            shentongIDSortBySkillID.Add(0);
        }
        shentongIDToSkillID.Clear();
    }
 
    void OnPlayerLoginOkEvent()
    {
        isShowShentongSkill = PlayerPrefs.GetInt("hidestskill" + PlayerDatas.Instance.baseData.PlayerID) == 0;
        UpdateRedpoint();
    }
 
    public void UpdateShentongLVInfo(IL_HA3C8_tagMCShentongLVInfo netPack)
    {
        for (int i = 0; i < netPack.ShentongLVList.Length; i++)
        {
            var info = netPack.ShentongLVList[i];
            shentongDict[info.ShentongID] = new structShentongLV()
            {
                ClassLV = info.ClassLV,
                LV = info.LV
            };
            
        }
 
        UpdateShentongSkill();
        SortShentong();
        UpdateShentongEvent?.Invoke();
        UpdateRedpoint();
    }
 
    public void UpdateShentongSkill(IL_HA3C9_tagMCShentongSkillInfo netPack)
    {
        for (int i = 0; i < netPack.SkillIDList.Length; i++)
        {
            shentongSetSkillIDs[i] = (int)netPack.SkillIDList[i];
        }
 
        for (int i = 0; i < shentongSetSkillIDs.Count; i++)
        {
            if (shentongSetSkillIDs[i] != 0)
            {
                shentongIDSortBySkillID[i] = skillIDToShentongIDDict[shentongSetSkillIDs[i]];
            }
        }
 
        SortShentong();
        ILSkillManager.Instance.InitSkill();
        UpdateShentongSkillEvent?.Invoke();
    }
 
    public void UpdateShentongSkill()
    {
        var keyList = shentongDict.Keys.ToList();
        for (int k = 0; k < keyList.Count; k++)
        {
            var shentongID = keyList[k];
            var classLV = shentongDict.ContainsKey(shentongID) ? shentongDict[shentongID].ClassLV : 0;
            var lv = shentongDict.ContainsKey(shentongID) ? shentongDict[shentongID].LV : 0;
            for (int i = 1; i <= classLV; i++)
            {
                for (int j = 1; j <= 10; j++)
                {
                    if (classLV == i && j > lv)
                    {
                        break;
                    }
                    var id = ILShentongLVConfig.GetShentongLVID(shentongID, i, j);
                    var config = ILShentongLVConfig.Get(id);
                    if (config.LVSkillID != 0)
                        shentongIDToSkillID[shentongID] = config.LVSkillID;
                }
            }
        }
    }
 
    //根据技能排序 优先已放置技能ID  - 已激活神通 - 排序
    public void SortShentong()
    {
        shentongIDList.Sort(CmpShentong);
    }
 
    int CmpShentong(int x, int y)
    {
        int indexX = shentongIDSortBySkillID.IndexOf(x);
        indexX = indexX == -1 ? 10 : indexX;
        int indexY = shentongIDSortBySkillID.IndexOf(y);
        indexY = indexY == -1 ? 10 : indexY;
 
        if (indexX != indexY)
        {
            return indexX.CompareTo(indexY);
        }
 
        //古宝解锁问题
        bool isActiveX = shentongDict.ContainsKey(x) || IsGubaoActive(x);
        bool isActiveY = shentongDict.ContainsKey(y) || IsGubaoActive(y);
        if (isActiveX != isActiveY)
        {
            return isActiveY.CompareTo(isActiveX);
        }
 
        return ILShentongConfig.Get(x).SortIndex.CompareTo(ILShentongConfig.Get(y).SortIndex);
    }
 
    public bool IsGubaoActive(int id)
    {
        return TreasurePavilionModel.Instance.TryGetGubaoInfo(ILShentongConfig.Get(id).NeedGubaoID).Count != 0;
    }
 
    public struct structShentongLV
    {
        public int ClassLV;
        public int LV;
    }
 
 
    void UpdateRedpoint()
    {
        var keys = redpoints.Keys.ToList();
        for (int i = 0; i < keys.Count; i++)
        {
            var shentongID = keys[i];
            redpoints[shentongID].state = RedPointState.None;
            if (!IsGubaoActive(shentongID))
                continue;
 
            var nextID = GetNextShentongIndex(shentongID);
            if (nextID == -1) continue;
            var items = ILShentongLVConfig.GetUseItems(nextID);
            var isEnough = true;
            for (int j = 0; j < items.Count; j++)
            {
                var cnt = packModel.GetItemCountByID(PackType.Item, items[j].x);
                if (cnt < items[j].y)
                {
                    isEnough = false;
                    break;
                }
            }
            if (isEnough)
            {
                redpoints[shentongID].state = RedPointState.Simple;
            }
        }
 
 
    }
 
    void OnRefreshItem(PackType type, int index, int id)
    {
        if (type == PackType.Item && ILShentongLVConfig.needItemIDs.Contains(id))
        {
            UpdateRedpoint();
        }
    }
 
    public void SetShentongSkill()
    {
        var pack = new IL_CB220_tagCMShentongSkillSet();
        pack.SkillIDList = new uint[skillSetLimitLV.Length] ;
        for (int i = 0; i < shentongSetSkillIDs.Count; i++)
        {
            pack.SkillIDList[i] = (uint)shentongSetSkillIDs[i];
        }
        pack.Count = (byte)pack.SkillIDList.Length;
        GameNetSystem.Instance.SendInfo(pack);
    }
 
    public Dictionary<int, int> shentongAttrDict = new Dictionary<int, int>();
 
    public void CalcAttr()
    {
        shentongAttrDict.Clear();
        var classLV = shentongDict.ContainsKey(selectShentong) ? shentongDict[selectShentong].ClassLV : 0;
        var lv = shentongDict.ContainsKey(selectShentong) ? shentongDict[selectShentong].LV : 0;
        for (int i = 1; i <= classLV; i++)
        {
            for (int j = 1; j <= 10; j++)
            {
                if (classLV == i && j > lv)
                {
                    break;
                }
                var id = ILShentongLVConfig.GetShentongLVID(selectShentong, classLV, j);
                var config = ILShentongLVConfig.Get(id);
                for (int k = 0; k < config.LVAttrTypeList.Length; k++)
                {
                    if (!shentongAttrDict.ContainsKey(config.LVAttrTypeList[k]))
                        shentongAttrDict[config.LVAttrTypeList[k]] = 0;
                    shentongAttrDict[config.LVAttrTypeList[k]] = shentongAttrDict[config.LVAttrTypeList[k]] + config.LVAttrValueList[k];
                }
            }
        }
    }
 
    public int GetNextShentongIndex(int id = 0)
    {
        if (id == 0)
            id = selectShentong;
        var classLV = shentongDict.ContainsKey(id) ? shentongDict[id].ClassLV : 0;
        var lv = shentongDict.ContainsKey(id) ? shentongDict[id].LV : 0;
 
        if (classLV == 0)
        {
            classLV = 1;
            lv = 1;
        }
        else if (lv == 10)
        {
            classLV = classLV + 1;
            lv = 1;
        }
        else
        {
            lv = lv + 1;
        }
        return ILShentongLVConfig.GetShentongLVID(id, classLV, lv);
    }
 
 
    public void SetSkillPositionState(int state)
    {
        skillPositionState = state;
    }
 
    public int GetShentongIDByGubaoID(int gubaoID)
    {
        if (gubaoToShentong.ContainsKey(gubaoID))
            return gubaoToShentong[gubaoID];
        return 0;
    }
}