少年修仙传客户端代码仓库
Client_PangDeRong
2018-09-21 d1a2ab5b56bae336a1b5cbc4f307cb67e76c22e6
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TableConfig;
using System;
using System.Linq;
using Snxxz.UI;
 
namespace Snxxz.UI
{
    public class MagicianModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        PlayerPackModel _playerPack;
        PlayerPackModel playerPack
        {
            get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
        }
 
        bool serverInited = false;
 
        public override void Init()
        {
            ParseConfig();
            playerPack.RefreshItemCountAct += RefreshPackItem;
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
        }
 
        private void OnFuncStateChangeEvent(int func)
        {
            if (func == (int)FuncOpenEnum.Magician)
            {
                UpdateRedPoint();
            }
        }
 
        private void RefreshPackItem(PackType packType, int index, int id)
        {
            if (packType != PackType.rptItem)
            {
                return;
            }
            UpdateRedPoint();
        }
 
        public override void UnInit()
        {
            playerPack.RefreshItemCountAct -= RefreshPackItem;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            serverInited = false;
        }
 
        public void OnPlayerLoginOk()
        {
            serverInited = true;
        }
 
        private Dictionary<int, int[]> godWeaponLvUpItem = new Dictionary<int, int[]>();
        public int[] GetLvUpItemByType(int type)
        {
            return godWeaponLvUpItem[type];
        }
        public List<int> magicianTypes { get; private set; }
        public Dictionary<int, string> godWeaponIcons { get; private set; }
        public Dictionary<int, Dictionary<int, int>> godWeaponSkillDict = new Dictionary<int, Dictionary<int, int>>();
        public int selectType = 0;
        public int selectItemIndex = 0;
        public int gotoType = 0;
        void ParseConfig()
        {
            magicianTypes = GodWeaponConfig.GetGodWeaponType();
            for (int i = 0; i < magicianTypes.Count; i++)
            {
                FuncConfigConfig _funcCfg = Config.Instance.Get<FuncConfigConfig>(string.Format("GodWeapon{0}", magicianTypes[i]));
                int[] itemarray = ConfigParse.GetMultipleStr<int>(_funcCfg.Numerical1);
                godWeaponLvUpItem.Add(magicianTypes[i], itemarray);
            }
            godWeaponIcons = new Dictionary<int, string>();
            var _cfg = Config.Instance.Get<FuncConfigConfig>("GodModel");
            var _godWeaponJson = LitJson.JsonMapper.ToObject(_cfg.Numerical2);
            foreach (var _key in _godWeaponJson.Keys)
            {
                var _godWeaponType = int.Parse(_key);
                if (!godWeaponIcons.ContainsKey(_godWeaponType))
                {
                    godWeaponIcons.Add(_godWeaponType, _godWeaponJson[_key].ToString());
                }
            }
 
            var configs = Config.Instance.GetAllValues<GodWeaponConfig>();
            for (int i = 0; i < configs.Count; i++)
            {
                if (configs[i].SkillID != 0)
                {
                    Dictionary<int, int> _dict = null;
                    if (!godWeaponSkillDict.TryGetValue(configs[i].Type, out _dict))
                    {
                        _dict = new Dictionary<int, int>();
                        godWeaponSkillDict.Add(configs[i].Type, _dict);
                    }
                    _dict.Add(configs[i].Lv, configs[i].SkillID);
                }
            }
        }
        #region 红点
        public const int MAGICAIN_REDPOINT = 10104;
        public const int MAGICAIN_INTERVAL = 100;
        public Dictionary<int, Redpoint> redpointDict = new Dictionary<int, Redpoint>();
        Redpoint magicianPoint = new Redpoint(101, MAGICAIN_REDPOINT);
        public Redpoint magicianRedpoint { get { return magicianPoint; } }
        public void UpdateRedPoint()
        {
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Magician))
            {
                return;
            }
            foreach (var key in redpointDict.Keys)
            {
                int[] items = GetLvUpItemByType((int)key);
                redpointDict[key].state = RedPointState.None;
                for (int i = 0; i < items.Length; i++)
                {
                    if (playerPack.GetItemCountByID(PackType.rptItem, items[i]) > 0)
                    {
                        MagicianData data = null;
                        if (magicianDict.TryGetValue(key, out data))
                        {
                            var _godWeaponCfg = Config.Instance.Get<GodWeaponConfig>(data.level + 1);
                            if (_godWeaponCfg == null)
                            {
                                redpointDict[key].state = RedPointState.None;
                                break;
                            }
                        }
                        redpointDict[key].state = RedPointState.Simple;
                        break;
                    }
                }
            }
        }
        public bool CanTemperMagician()
        {
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Magician))
            {
                return false;
            }
            foreach (var key in redpointDict.Keys)
            {
                if (redpointDict[key].state == RedPointState.Simple)
                {
                    return true;
                }
            }
            return false;
        }
        public bool GetRedpointLightByType(int _type)
        {
            if (redpointDict.ContainsKey(_type))
            {
                return redpointDict[_type].state == RedPointState.Simple;
            }
            return false;
        }
        #endregion
        public void TemperMagician(int type)
        {
            MagicianData data = GetMagicianData(type);
            if (data != null)
            {
                if (IsGodWeaponMaxLevel(type))
                {
                    MessageWin.Inst.ShowFixedTip(Language.Get("L1054"));
                    return;
                }
            }
            int[] items = GetLvUpItemByType(type);
            if (selectItemIndex >= items.Length)
            {
                return;
            }
            ItemConfig itemCfg = Config.Instance.Get<ItemConfig>(items[selectItemIndex]);
            var _itemCnt = playerPack.GetItemCountByID(PackType.rptItem, itemCfg.ID);
            if (_itemCnt < 1)
            {
                ModelCenter.Instance.GetModel<GetItemPathModel>().SetChinItemModel(itemCfg.ID);
                if (!IsGodWeaponTemperItem(3, itemCfg.ID) && !NewBieCenter.Instance.completeGuidesBuf.Contains(85))
                {
                    NewBieCenter.Instance.StartNewBieGuide(85);
                }
                return;
            }
            CA555_tagCMGodWeaponPlus _pak = new CA555_tagCMGodWeaponPlus();
            _pak.WeaponType = (uint)type;
            _pak.ItemID = (uint)items[selectItemIndex];
            GameNetSystem.Instance.SendInfo(_pak);
        }
        public event Action OnRefresh;
        private Dictionary<int, MagicianData> magicianDict = new Dictionary<int, MagicianData>();
        public void OnMagicianChange(HA31D_tagMCGodWeaponLVList vNetData)
        {
            for (byte i = 0; i < vNetData.WeaponNum; i++)
            {
                HA31D_tagMCGodWeaponLVList.tagMCGodWeaponLVInfo _sData = vNetData.WeaponInfoList[i];
                MagicianData data = null;
                magicianDict.TryGetValue(_sData.WeaponType, out data);
                if (data == null)
                {
                    data = new MagicianData();
                    magicianDict.Add(_sData.WeaponType, data);
                }
 
                CheckActivate((int)data.type, data.level, _sData.WeaponLV);
 
                data.exp = _sData.WeaponExp;
                data.level = _sData.WeaponLV;
                data.type = _sData.WeaponType;
                if (!redpointDict.ContainsKey((int)data.type))
                {
                    Redpoint redpoint = new Redpoint(MAGICAIN_REDPOINT, MAGICAIN_REDPOINT * MAGICAIN_INTERVAL + (int)data.type);
                    redpointDict.Add((int)data.type, redpoint);
                    redpoint.state = RedPointState.None;
                }
            }
            UpdateRedPoint();
            if (OnRefresh != null)
            {
                OnRefresh();
            }
        }
 
        void CheckActivate(int _type, int _beforeLv, int _nowLv)
        {
            var _skillId = 0;
            if (serverInited && _beforeLv != _nowLv
                && (_beforeLv == 0 || TryGetUnlockSkill(_type, _beforeLv, _nowLv, out _skillId)))
            {
                if (WindowCenter.Instance.CheckOpen<MagicianWin>()
                    && !NewBieCenter.Instance.inGuiding)
                {
                    ActivateShow.GodWeaponActivate(_type, _nowLv, _beforeLv);
                }
            }
        }
 
        public bool TryGetUnlockSkill(int _type, int _beforeLv, int _nowLv,out int _skillid)
        {
            _skillid = 0;
            if (godWeaponSkillDict.ContainsKey(_type))
            {
                var _dict = godWeaponSkillDict[_type];
                foreach (var _lv in _dict.Keys)
                {
                    if (_beforeLv < _lv && _lv <= _nowLv)
                    {
                        _skillid = _dict[_lv];
                        return true;
                    }
                }
            }
            return false;
        }
 
 
        public MagicianData GetMagicianData(int type)
        {
            MagicianData data = null;
            magicianDict.TryGetValue(type, out data);
            return data;
        }
 
        public bool IsGodWeaponMaxLevel(int _type)
        {
            var _data = GetMagicianData(_type);
            var config = Config.Instance.Get<GodWeaponConfig>(_data.level + 1);
            return config == null;
        }
 
        public bool IsGodWeaponTemperItem(int _type,int _itemId)
        {
            var items = GetLvUpItemByType(_type);
            if (items == null)
            {
                return false;
            }
            for (int i = 0; i < items.Length; i++)
            {
                if (items[i] == _itemId)
                {
                    return true;
                }
            }
            return false;
        }
 
        public bool IsGodWeaponMaxLevelByItem(int _itemId)
        {
            foreach (var _key in godWeaponLvUpItem.Keys)
            {
                for (int i = 0; i < godWeaponLvUpItem[_key].Length; i++)
                {
                    if (godWeaponLvUpItem[_key][i] == _itemId)
                    {
                        return IsGodWeaponMaxLevel(_key);
                    }
                }
            }
            return false;
        }
 
    }
 
    public class MagicianData
    {
        public uint type;
        public int level;
        public uint exp;
    }
}