少年修仙传客户端代码仓库
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
using System;
using System.Linq;
using vnxbqy.UI;
 
namespace vnxbqy.UI
{
    
    
    public class MagicianModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        public event Action onSelectUpdate;
 
        PackModel packModel
        {
            get { return ModelCenter.Instance.GetModel<PackModel>(); }
        }
 
        bool serverInited = false;
 
        public override void Init()
        {
            ParseConfig();
            packModel.refreshItemCountEvent += RefreshPackItem;
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
            PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
        }
 
        private void OnFuncStateChangeEvent(int func)
        {
            if (func == (int)FuncOpenEnum.GodWeapon)
            {
                UpdateRedPoint();
            }
        }
 
        private void RefreshPackItem(PackType packType, int index, int id)
        {
            if (packType != PackType.Item)
            {
                return;
            }
            UpdateRedPoint();
        }
 
        private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
        {
            if (refreshType == PlayerDataType.LV)
            {
                UpdateRedPoint();
            }
        }
 
        public override void UnInit()
        {
            packModel.refreshItemCountEvent -= RefreshPackItem;
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
            PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            serverInited = false;
            foreach (var godWeapon in godWeaponInfoDict.Values)
            {
                godWeapon.level = 0;
                godWeapon.exp = 0;
            }
        }
 
        public void OnPlayerLoginOk()
        {
            serverInited = true;
            UpdateRedPoint();
        }
 
        private Dictionary<int, int[]> godWeaponLevelUpCost = new Dictionary<int, int[]>();
        public List<int> godWeaponTypes { get; private set; }
        public Dictionary<int, int> godWeaponBoxDict { get; private set; } //key 神兵石礼包 value 神兵类型
        public Dictionary<int, string> godWeaponIcons { get; private set; }
        public Dictionary<int, Dictionary<int, int>> godWeaponSkillDict = new Dictionary<int, Dictionary<int, int>>();
        Dictionary<int, List<GodWeaponCondition>> godWeaponConditions = new Dictionary<int, List<GodWeaponCondition>>();
        Dictionary<int, int> playerLevelConditions = new Dictionary<int, int>();
        public List<int> godWeaponSorts = new List<int>();
        Dictionary<int, AutoHammerCost> autoHammerCostDict = new Dictionary<int, AutoHammerCost>();
        Dictionary<int, int> exteriorPowerDict = new Dictionary<int, int>();
        Dictionary<int, int> godWeaponSkillEffect = new Dictionary<int, int>();
        Dictionary<int, int> singleHarmmerExp = new Dictionary<int, int>();
        int[] autoHammerExpArea { get; set; }
        int[] autoHammerCount { get; set; }
 
        int m_SelectType = 0;
        public int selectType
        {
            get { return m_SelectType; }
            set
            {
                if (m_SelectType != value)
                {
                    m_SelectType = value;
                    if (onSelectUpdate != null)
                    {
                        onSelectUpdate();
                    }
                }
            }
        }
 
        public int selectItemIndex = 0;
        public int gotoType = 0;
 
        public int autoHammerLevel { get; set; }
 
        public int hammerAudioId { get; private set; }
        public int audioLength { get; private set; }
        void ParseConfig()
        {
            var godWeaponBox = FuncConfigConfig.Get("GodWeaponBox");
            godWeaponBoxDict = ConfigParse.GetDic<int, int>(godWeaponBox.Numerical1);
 
            godWeaponTypes = GodWeaponConfig.GetGodWeaponType();
            for (int i = 0; i < godWeaponTypes.Count; i++)
            {
                GodWeaponInfo godWeapon = new GodWeaponInfo()
                {
                    exp = 0,
                    level = 0,
                    type = godWeaponTypes[i],
                };
                godWeaponInfoDict.Add(godWeapon.type, godWeapon);
 
                if (!redpointDict.ContainsKey(godWeapon.type))
                {
                    Redpoint redpoint = new Redpoint(MAGICAIN_REDPOINT, MAGICAIN_REDPOINT * MAGICAIN_INTERVAL + godWeapon.type);
                    redpointDict.Add(godWeapon.type, redpoint);
                    redpoint.state = RedPointState.None;
                }
 
                var config = FuncConfigConfig.Get(string.Format("GodWeapon{0}", godWeaponTypes[i]));
                int[] itemarray = ConfigParse.GetMultipleStr<int>(config.Numerical1);
                godWeaponLevelUpCost.Add(godWeaponTypes[i], itemarray);
            }
 
            godWeaponIcons = new Dictionary<int, string>();
            var _cfg = FuncConfigConfig.Get("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 = GodWeaponConfig.GetValues();
            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);
                }
            }
 
            var conditionConfig = FuncConfigConfig.Get("GodWeaponActive");
            var json = LitJson.JsonMapper.ToObject(conditionConfig.Numerical2);
            foreach (var key in json.Keys)
            {
                var type = int.Parse(key);
                List<GodWeaponCondition> list;
                if (!godWeaponConditions.TryGetValue(type, out list))
                {
                    list = new List<GodWeaponCondition>();
                    godWeaponConditions.Add(type, list);
                }
                int[][] conditions = LitJson.JsonMapper.ToObject<int[][]>(json[key].ToJson());
                for (int i = 0; i < conditions.Length; i++)
                {
                    var condition = conditions[i];
                    list.Add(new GodWeaponCondition()
                    {
                        type = condition[0],
                        level = condition[1],
                    });
                }
            }
 
            json = LitJson.JsonMapper.ToObject(conditionConfig.Numerical3);
            foreach (var key in json.Keys)
            {
                var type = int.Parse(key);
                playerLevelConditions.Add(type, int.Parse(json[key].ToString()));
            }
 
            var sortConfig = FuncConfigConfig.Get("GodWeaponSort");
            godWeaponSorts.AddRange(ConfigParse.GetMultipleStr<int>(sortConfig.Numerical1));
 
            var autoHammerConfig = FuncConfigConfig.Get("GodWeaponAutoHammer");
            if (autoHammerConfig != null)
            {
                autoHammerExpArea = ConfigParse.GetMultipleStr<int>(autoHammerConfig.Numerical1);
                autoHammerCount = ConfigParse.GetMultipleStr<int>(autoHammerConfig.Numerical2);
                singleHarmmerExp = ConfigParse.GetDic<int, int>(autoHammerConfig.Numerical3);
            }
 
            var funcConfig = FuncConfigConfig.Get("GodMagicExp");
            json = LitJson.JsonMapper.ToObject(funcConfig.Numerical1);
            foreach (var key in json.Keys)
            {
                var type = int.Parse(key);
                var array = LitJson.JsonMapper.ToObject<int[]>(json[key].ToJson());
                autoHammerCostDict.Add(type, new AutoHammerCost()
                {
                    cost = array[0],
                    exp = array[1],
                });
            }
 
            funcConfig = FuncConfigConfig.Get("MagicExterior");
            json = LitJson.JsonMapper.ToObject(funcConfig.Numerical1);
            foreach (var key in json.Keys)
            {
                var type = int.Parse(key);
                var power = int.Parse(json[key].ToString());
                exteriorPowerDict.Add(type, power);
            }
 
            funcConfig = FuncConfigConfig.Get("Godvideo");
            hammerAudioId = int.Parse(funcConfig.Numerical1);
            audioLength = int.Parse(funcConfig.Numerical2);
        }
 
        public int[] GetLevelUpItemByType(int type)
        {
            return godWeaponLevelUpCost[type];
        }
 
        public bool TryGetMagicType(int itemId,out int type)
        {
            type = 0;
            foreach(var key in godWeaponLevelUpCost.Keys)
            {
                var costlist = godWeaponLevelUpCost[key];
                if(costlist.Contains(itemId))
                {
                    type = key;
                    return true;
                }
            }
 
            if(godWeaponBoxDict.ContainsKey(itemId))
            {
                type = godWeaponBoxDict[itemId];
                return true;
            }
            return false;
        }
 
        #region 红点
        public const int MAGICAIN_REDPOINT = 10102;
        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()
        {
            foreach (var redpoint in redpointDict.Values)
            {
                redpoint.state = RedPointState.None;
            }
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.GodWeapon))
            {
                return;
            }
            foreach (var key in redpointDict.Keys)
            {
                if (IsGodWeaponMaxLevel(key))
                {
                    continue;
                }
                if (!IsGodWeaponUnlock(key) && ContainsCondition(key))
                {
                    if (SatisfyUnlockCondition(key))
                    {
                        redpointDict[key].state = RedPointState.Simple;
                    }
                    continue;
                }
                int[] items = GetLevelUpItemByType((int)key);
                for (int i = 0; i < items.Length; i++)
                {
                    if (packModel.GetItemCountByID(PackType.Item, items[i]) > 0)
                    {
                        redpointDict[key].state = RedPointState.Simple;
                        break;
                    }
                }
            }
        }
 
        public bool GetRedpointLightByType(int _type)
        {
            if (redpointDict.ContainsKey(_type))
            {
                return redpointDict[_type].state == RedPointState.Simple;
            }
            return false;
        }
        #endregion
 
        public void HammerGodWeapon(int type)
        {
            GodWeaponInfo godWeaponInfo = GetGodWeaponInfo(type);
            if (godWeaponInfo == null)
            {
                return;
            }
            if (IsGodWeaponMaxLevel(type))
            {
                ServerTipDetails.DisplayNormalTip(Language.Get("L1054"));
                return;
            }
            int[] items = GetLevelUpItemByType(type);
            if (selectItemIndex >= items.Length)
            {
                return;
            }
            var itemId = items[selectItemIndex];
            ItemConfig itemConfig = ItemConfig.Get(itemId);
            var count = packModel.GetItemCountByID(PackType.Item, itemId);
            if (count < 1)
            {
                ItemTipUtility.Show(itemId);
                return;
            }
            CA555_tagCMGodWeaponPlus pak = new CA555_tagCMGodWeaponPlus();
            pak.WeaponType = (uint)type;
            pak.ItemID = (uint)itemId;
            pak.ItemCount = 1;
            pak.IsAutoBuy = 0;
            GameNetSystem.Instance.SendInfo(pak);
            PlayHammerAudio();
        }
 
        DateTime lastAudioTime = DateTime.Now;
        public void PlayHammerAudio()
        {
            var seconds = (float)audioLength / 1000;
            if ((DateTime.Now - lastAudioTime).TotalSeconds < seconds)
            {
                return;
            }
            lastAudioTime = DateTime.Now;
            SoundPlayer.Instance.PlayUIAudio(hammerAudioId);
        }
 
        public event Action godWeaponUpdate;
        private Dictionary<int, GodWeaponInfo> godWeaponInfoDict = new Dictionary<int, GodWeaponInfo>();
        public void UpdateGodWeaponInfo(HA31D_tagMCGodWeaponLVList package)
        {
            for (byte i = 0; i < package.WeaponNum; i++)
            {
                HA31D_tagMCGodWeaponLVList.tagMCGodWeaponLVInfo data = package.WeaponInfoList[i];
                GodWeaponInfo godWeaponInfo = GetGodWeaponInfo(data.WeaponType);
                if (godWeaponInfo != null)
                {
                    var beforeLevel = godWeaponInfo.level;
                    godWeaponInfo.exp = data.WeaponExp;
                    godWeaponInfo.level = data.WeaponLV;
                    CheckActivate(godWeaponInfo.type, beforeLevel, data.WeaponLV);
                }
            }
            UpdateRedPoint();
            if (godWeaponUpdate != null)
            {
                godWeaponUpdate();
            }
        }
 
        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.IsOpen<MagicianWin>()
                    && !NewBieCenter.Instance.inGuiding)
                {
                    if (WindowCenter.Instance.IsOpen<HowToPlayWin>())
                    {
                        WindowCenter.Instance.Close<HowToPlayWin>();
                    }
                    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 bool TryGetGodWeaponSkills(int type, out Dictionary<int, int> skills)
        {
            return godWeaponSkillDict.TryGetValue(type, out skills);
        }
 
        public GodWeaponInfo GetGodWeaponInfo(int type)
        {
            GodWeaponInfo data = null;
            godWeaponInfoDict.TryGetValue(type, out data);
            return data;
        }
 
        public bool IsGodWeaponMaxLevel(int _type)
        {
            var _data = GetGodWeaponInfo(_type);
            var config = GodWeaponConfig.GetConfig(_type, _data.level + 1);
            return config == null;
        }
 
        public bool IsGodWeaponHammerItem(int _type,int _itemId)
        {
            var items = GetLevelUpItemByType(_type);
            if (items == null)
            {
                return false;
            }
            for (int i = 0; i < items.Length; i++)
            {
                if (items[i] == _itemId)
                {
                    return true;
                }
            }
            return false;
        }
 
        public bool IsGodWeaponUnlock(int type)
        {
            var godWeaponInfo = GetGodWeaponInfo(type);
            if (godWeaponInfo != null && godWeaponInfo.level >= 1)
            {
                return true;
            }
            return false;
        }
 
        public bool SatisfyUnlockCondition(int type)
        {
            if (!playerLevelConditions.ContainsKey(type)
                && !godWeaponConditions.ContainsKey(type))
            {
                return true;
            }
            List<GodWeaponCondition> list;
            bool satisfyCondition = false;
            if (godWeaponConditions.TryGetValue(type, out list))
            {
                bool satisfy = true;
                for (int i = 0; i < list.Count; i++)
                {
                    var godWeaponInfo = GetGodWeaponInfo(list[i].type);
                    if (godWeaponInfo == null || godWeaponInfo.level < list[i].level)
                    {
                        satisfy = false;
                        break;
                    }
                }
                if (satisfy)
                {
                    satisfyCondition = true;
                }
            }
            var playerLevelLimit = 0;
            if (TryGetPlayerLevelCondition(type, out playerLevelLimit))
            {
                if (PlayerDatas.Instance.baseData.LV >= playerLevelLimit)
                {
                    satisfyCondition = true;
                }
            }
            return satisfyCondition;
        }
 
        public int GetAutoHammerCount(int type)
        {
            ulong totalExp = 0;
            var godWeaponInfo = GetGodWeaponInfo(type);
            if (godWeaponInfo == null || autoHammerExpArea == null || autoHammerCount == null)
            {
                return 1;
            }
            var config = GodWeaponConfig.GetConfig(type, godWeaponInfo.level);
            totalExp = (ulong)config.NeedExp;
            var index = 0;
            for (int i = 0; i < autoHammerExpArea.Length; i++)
            {
                if (totalExp < (ulong)autoHammerExpArea[i])
                {
                    index = i;
                    break;
                }
                else
                {
                    index++;
                }
            }
            if (index < autoHammerCount.Length)
            {
                return autoHammerCount[index];
            }
            return autoHammerCount[autoHammerCount.Length - 1];
        }
 
        public int GetAutoHammerCount(int type, int index)
        {
            var items = GetLevelUpItemByType(type);
            var moneyCount = GetAutoHammerCount(type);
            AutoHammerCost autoHammerCost;
            var totalExp = 0;
            if (TryGetAutoHammerCost(type, out autoHammerCost))
            {
                totalExp = moneyCount * autoHammerCost.exp;
            }
            else if (singleHarmmerExp.ContainsKey(type))
            {
                totalExp = moneyCount * singleHarmmerExp[type];
            }
            var itemId = items[index];
            var itemConfig = ItemConfig.Get(itemId);
            var expCount = Mathf.CeilToInt((float)totalExp / itemConfig.EffectValueA1);
            var packCount = packModel.GetItemCountByID(PackType.Item, itemId);
            return Mathf.Min(expCount, packCount);
        }
 
        public bool ContainsCondition(int type)
        {
            return godWeaponConditions.ContainsKey(type) || playerLevelConditions.ContainsKey(type);
        }
 
        public bool TryGetConditions(int type, out List<GodWeaponCondition> list)
        {
            return godWeaponConditions.TryGetValue(type, out list);
        }
 
        public bool TryGetPlayerLevelCondition(int type,out int level)
        {
            return playerLevelConditions.TryGetValue(type, out level);
        }
 
        public bool IsGodWeaponMaxLevelByItem(int _itemId)
        {
            foreach (var _key in godWeaponLevelUpCost.Keys)
            {
                for (int i = 0; i < godWeaponLevelUpCost[_key].Length; i++)
                {
                    if (godWeaponLevelUpCost[_key][i] == _itemId)
                    {
                        return IsGodWeaponMaxLevel(_key);
                    }
                }
            }
            return false;
        }
 
        public bool TryGetAutoHammerCost(int type,out AutoHammerCost autoHammerCost)
        {
            return autoHammerCostDict.TryGetValue(type, out autoHammerCost);
        }
 
        public bool TryGetExteriorPower(int type, out int power)
        {
            return exteriorPowerDict.TryGetValue(type, out power);
        }
 
        public List<int> TryGetDisplaySkillLevels(int type)
        {
            List<int> displaySkillLevels = new List<int>();
            Dictionary<int, int> dict;
            if (TryGetGodWeaponSkills(type, out dict))
            {
                displaySkillLevels.AddRange(dict.Keys);
            }
            displaySkillLevels.Sort();
            return displaySkillLevels;
        }
    }
 
    public class GodWeaponInfo
    {
        public int type;
        public int level;
        public uint exp;
    }
 
    public struct GodWeaponCondition
    {
        public int type;
        public int level;
    }
 
    public struct AutoHammerCost
    {
        public int cost;
        public int exp;
    }
}