少年修仙传客户端代码仓库
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
 
using UnityEngine;
namespace vnxbqy.UI
{
    
    
    public class FashionDressModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        Dictionary<int, FashionDress> fashionDressDict = new Dictionary<int, FashionDress>();
        Dictionary<int, int> fashionDressLevelDict = new Dictionary<int, int>();
        Dictionary<int, Dictionary<int, int>> cabinetPropertyDict = new Dictionary<int, Dictionary<int, int>>();
        Dictionary<int, List<int>> fashionDressTypeDict = new Dictionary<int, List<int>>();
        Dictionary<int, List<int>> fashionDressSuitTypeDict = new Dictionary<int, List<int>>();
        Dictionary<int, Dictionary<int, List<int>>> fashionDressQualityDict = new Dictionary<int, Dictionary<int, List<int>>>();
 
        const int FASHIONDRESS_REDPOINT_BASE = 10105;
        const int FASHIONDRESS_FUNC_ID = 160;
 
        readonly List<int> fashionDressTypeSort = new List<int>() { 1, 2, 3 };
        readonly List<int> fashionDressQualitySort = new List<int>() { 0, 1, 2 };
 
        public readonly Redpoint redpoint = new Redpoint(101, FASHIONDRESS_REDPOINT_BASE);
        public readonly Redpoint levelUpRedpoint = new Redpoint(FASHIONDRESS_REDPOINT_BASE, 1010501);
 
        public int cabinetLevel { get; private set; }
        public int cabinetExp { get; private set; }
        public int cabinetMaxLevel { get; private set; }
        public bool serverInited { get; private set; }
        public int jumpFashionDress { get; set; }
        public int fashoinDressCount
        {
            get
            {
                return fashionDressDict.Count;
            }
        }
 
        public Dictionary<int, int> fashionDressSelectDict { get; private set; }
        public Dictionary<int, int> fashionDressEquipDict { get; private set; }
        public List<int> fashionDressLevelUpItems { get; private set; }
        public List<int> fashionDressTypes { get; private set; }
        public Dictionary<int, int> fashionTypeMapPlaceDict { get; private set; }
 
        int m_SelectType = 1;
        public int selectType
        {
            get { return m_SelectType; }
            set
            {
                if (m_SelectType != value)
                {
                    m_SelectType = value;
                    if (selectTypeRefresh != null)
                    {
                        selectTypeRefresh();
                    }
                }
            }
        }
 
        int m_SelectQuality = 0;
        public int selectQuality
        {
            get { return m_SelectQuality; }
            set
            {
                if (m_SelectQuality != value)
                {
                    m_SelectQuality = value;
                    if (selectQualityRefresh != null)
                    {
                        selectQualityRefresh();
                    }
                }
            }
        }
 
        public event Action selectTypeRefresh;
        public event Action selectQualityRefresh;
        public event Action cabinetRefresh;
        public event Action<int> fashionDressRefresh;
        public event Action<int> selectFashionDressRefresh;
        public event Action<int> virtualEquipRefresh;
 
        PackModel packModel
        {
            get { return ModelCenter.Instance.GetModel<PackModel>(); }
        }
 
        public override void Init()
        {
            ParseConfig();
            fashionDressSelectDict = new Dictionary<int, int>();
            fashionDressEquipDict = new Dictionary<int, int>();
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
            packModel.refreshItemCountEvent += RefreshItemCountAct;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            fashionDressLevelDict.Clear();
            cabinetLevel = 0;
            cabinetExp = 0;
            serverInited = false;
        }
 
        public void OnPlayerLoginOk()
        {
            UpdateRedpoint();
            serverInited = true;
        }
 
        public override void UnInit()
        {
        }
 
        private void OnFuncStateChangeEvent(int id)
        {
            if (id == FASHIONDRESS_FUNC_ID)
            {
                UpdateRedpoint();
            }
        }
 
        private void RefreshItemCountAct(PackType packType, int arg2, int itemId)
        {
            if (packType == PackType.Item)
            {
                if (fashionDressLevelUpItems.Contains(itemId))
                {
                    UpdateRedpoint();
                }
            }
        }
 
        void ParseConfig()
        {
            {
                fashionDressSuitTypeDict.Clear();
                var configs = FashionDressConfig.GetValues();
                fashionDressLevelUpItems = new List<int>();
                foreach (var config in configs)
                {
                    fashionDressDict[config.CoatID] = new FashionDress(config);
                    {
                        List<int> list;
                        if (!fashionDressTypeDict.TryGetValue(config.type, out list))
                        {
                            list = new List<int>();
                            fashionDressTypeDict.Add(config.type, list);
                        }
                        list.Add(config.CoatID);
                    }
 
                    if (!fashionDressSuitTypeDict.ContainsKey(config.FashionSuitType))
                    {
                        var list = new List<int>();
                        list.Add(config.CoatID);
                        fashionDressSuitTypeDict.Add(config.FashionSuitType, list);
                    }
                    else
                    {
                        fashionDressSuitTypeDict[config.FashionSuitType].Add(config.CoatID);
                    }
 
                    if (!fashionDressLevelUpItems.Contains(config.UnlockItemID))
                    {
                        fashionDressLevelUpItems.Add(config.UnlockItemID);
                    }
 
                    {
                        Dictionary<int, List<int>> dict;
                        if (!fashionDressQualityDict.TryGetValue(config.type, out dict))
                        {
                            dict = new Dictionary<int, List<int>>();
                            fashionDressQualityDict.Add(config.type, dict);
                        }
                        List<int> list;
                        if (!dict.TryGetValue(config.quality, out list))
                        {
                            list = new List<int>();
                            dict.Add(config.quality, list);
                        }
                        list.Add(config.CoatID);
                    }
                }
            }
 
            {
                var configs = FashionDressCabinetConfig.GetValues();
                foreach (var config in configs)
                {
                    cabinetPropertyDict.Add(config.LV, ConfigParse.GetDic<int, int>(config.Attr));
                    if (config.LV > cabinetMaxLevel)
                    {
                        cabinetMaxLevel = config.LV;
                    }
                }
            }
 
            {
                var config = FuncConfigConfig.Get("FashionDressType");
                if (config != null)
                {
                    fashionTypeMapPlaceDict = ConfigParse.GetDic<int, int>(config.Numerical1);
                }
                fashionDressTypes = fashionTypeMapPlaceDict.Keys.ToList();
            }
 
        }
 
        public int GetFashionDressLevel(int id)
        {
            if (fashionDressLevelDict.ContainsKey(id))
            {
                return fashionDressLevelDict[id];
            }
            return 0;
        }
 
        public int GetFashionDressEquipId(int type)
        {
            if (fashionTypeMapPlaceDict.ContainsKey(type)
                && fashionDressTypeDict.ContainsKey(type))
            {
                var equipType = fashionTypeMapPlaceDict[type];
                var equipPlace = EquipPlaceMapConfig.GetServerPlace(0, equipType);
                var itemModel = packModel.GetItemByIndex(PackType.Equip, (int)equipPlace);
                var list = fashionDressTypeDict[type];
                if (itemModel != null)
                {
                    var index = list.FindIndex((id) =>
                    {
                        FashionDress fashionDress;
                        if (TryGetFashionDress(id, out fashionDress))
                        {
                            return fashionDress.GetEquipItemId() == itemModel.itemId;
                        }
                        return false;
                    });
                    if (index != -1)
                    {
                        return list[index];
                    }
                }
            }
            return 0;
        }
 
        public int GetSelectFashionDress(int type)
        {
            if (fashionDressSelectDict.ContainsKey(type))
            {
                return fashionDressSelectDict[type];
            }
            return 0;
        }
 
        public int GetVirtualEquipFashionDress(int type)
        {
            if (fashionDressEquipDict.ContainsKey(type))
            {
                return fashionDressEquipDict[type];
            }
            return 0;
        }
 
        public bool IsFashionDressUnlock(int id)
        {
            var level = GetFashionDressLevel(id);
            return level > 0;
        }
 
        public bool TryGetFashionDress(int id, out FashionDress fashionDress)
        {
            return fashionDressDict.TryGetValue(id, out fashionDress);
        }
 
        public bool TryGetFashionDresses(int type, int quality, out List<int> list)
        {
            list = null;
            if (fashionDressQualityDict.ContainsKey(type))
            {
                return fashionDressQualityDict[type].TryGetValue(quality, out list);
            }
            return false;
        }
 
        public bool TryGetFashionDresses(int type, out List<int> list)
        {
            return fashionDressTypeDict.TryGetValue(type, out list);
        }
 
        public bool TryGetFashionIds(int suitType, out List<int> list)
        {
            return fashionDressSuitTypeDict.TryGetValue(suitType, out list);
        }
 
        public bool TryGetFashionDressProperty(int id, int level, out Dictionary<int, int> dict)
        {
            dict = null;
            if (fashionDressDict.ContainsKey(id))
            {
                return fashionDressDict[id].TryGetProperty(level, out dict);
            }
            return false;
        }
 
        public bool TryGetCabinetProperty(int level, out Dictionary<int, int> dict)
        {
            return cabinetPropertyDict.TryGetValue(level, out dict);
        }
 
        public bool TryGetSatisfyResolves(ref List<int> list)
        {
            if (list == null)
            {
                list = new List<int>();
            }
            list.Clear();
            foreach (var fashionDress in fashionDressDict.Values)
            {
                var level = GetFashionDressLevel(fashionDress.id);
                if (level < fashionDress.maxLevel)
                {
                    continue;
                }
                var count = packModel.GetItemCountByID(PackType.Item, fashionDress.requireLevelUpItem);
                if (count > 0 && !list.Contains(fashionDress.requireLevelUpItem))
                {
                    list.Add(fashionDress.requireLevelUpItem);
                }
            }
            return list != null && list.Count > 0;
        }
 
        public bool TryGetActiveFashionDress(out List<int> list)
        {
            list = new List<int>();
            foreach (var fashionDress in fashionDressDict.Values)
            {
                var level = GetFashionDressLevel(fashionDress.id);
                if (level > 0)
                {
                    list.Add(fashionDress.id);
                }
            }
            return list.Count > 0;
        }
 
 
        public bool TryLevelUp(int id, out int error)
        {
            error = 0;
            FashionDress fashionDress;
            if (TryGetFashionDress(id, out fashionDress))
            {
                var level = GetFashionDressLevel(id);
                if (level >= fashionDress.maxLevel)
                {
                    return false;
                }
                var count = packModel.GetItemCountByID(PackType.Item, fashionDress.requireLevelUpItem);
                var levelUpRequireCount = fashionDress.GetLevelUpRequireCount(level);
                if (count < levelUpRequireCount)
                {
                    error = 1;
                    return false;
                }
            }
            return true;
        }
 
        public void DisplayLevelUpError(int error)
        {
            switch (error)
            {
                case 1:
                    SysNotifyMgr.Instance.ShowTip("FashionDressLevelUpError_1");
                    break;
            }
        }
 
        public void SetSelectFashionDress(int type, int id)
        {
            fashionDressSelectDict[type] = id;
            if (selectFashionDressRefresh != null)
            {
                selectFashionDressRefresh(type);
            }
        }
 
        public void SetVirtualEquipFashionDress(int type, int id)
        {
            fashionDressEquipDict[type] = id;
            if (virtualEquipRefresh != null)
            {
                virtualEquipRefresh(type);
            }
        }
 
        public void ReceivePackage(HB102_tagMCClothesCoatSkinState package)
        {
            cabinetLevel = (int)package.CoatChestLV;
            cabinetExp = (int)package.CoatChestExp;
            if (cabinetRefresh != null)
            {
                cabinetRefresh();
            }
            for (int i = 0; i < package.CoatNum; i++)
            {
                var id = (int)package.CoatInfoList[i].CoatIndex;
                var level = (int)package.CoatInfoList[i].CoatLV;
                fashionDressLevelDict[id] = level;
                if (fashionDressRefresh != null)
                {
                    fashionDressRefresh(id);
                }
                if (level == 1)
                {
                    HandleFashionDressUnlock(id);
                }
            }
            UpdateRedpoint();
        }
 
        public void HandleFashionDressUnlock(int id)
        {
            if (serverInited)
            {
                if (WindowCenter.Instance.IsOpen<FashionDressWin>())
                {
                    FashionDress fashionDress;
                    if (TryGetFashionDress(id, out fashionDress))
                    {
                        if (selectType == fashionDress.fashionDressType)
                        {
                            var virtualEquipId = GetVirtualEquipFashionDress(selectType);
                            if (virtualEquipId != 0)
                            {
                                SetSelectFashionDress(selectType, virtualEquipId);
                            }
                            else
                            {
                                SetVirtualEquipFashionDress(selectType, id);
                                SetSelectFashionDress(selectType, id);
                            }
                        }
                    }
                }
            }
        }
 
        public void SendLevelUp(int id)
        {
            CA50B_tagCMCoatUp pak = new CA50B_tagCMCoatUp();
            pak.CoatIndex = (uint)id;
            GameNetSystem.Instance.SendInfo(pak);
        }
 
        public void TryEquip()
        {
            foreach (var type in fashionDressEquipDict.Keys)
            {
                var equipId = GetFashionDressEquipId(type);
                var virtualEquipId = fashionDressEquipDict[type];
                var index = fashionTypeMapPlaceDict[type];
                if (virtualEquipId != 0)
                {
                    if (IsFashionDressUnlock(virtualEquipId)
                        && virtualEquipId != equipId)
                    {
                        SendEquipPackage((int)PackType.InterimPack, virtualEquipId,
                            (int)PackType.Equip, EquipPlaceMapConfig.GetServerPlace(0, index));
                    }
                }
                else
                {
                    if (equipId != 0)
                    {
                        SendEquipPackage((int)PackType.Equip, EquipPlaceMapConfig.GetServerPlace(0, index), (int)PackType.InterimPack, 0);
                    }
                }
            }
        }
 
        void SendEquipPackage(int srcpackType, int scrIndex, int destpackType, int destIndex)
        {
            C073D_tagCPackItemExchange pak = new C073D_tagCPackItemExchange();
            pak.SrcBackpack = (byte)srcpackType;
            pak.SrcIndex = (ushort)scrIndex;
            pak.DesBackPack = (byte)destpackType;
            pak.DestIndex = (ushort)destIndex;
            GameNetSystem.Instance.SendInfo(pak);
        }
 
        #region 时装详情
        public int viewFashionDressId { get; private set; }
        public void ViewFashionDressDetails(int id)
        {
            viewFashionDressId = id;
            WindowCenter.Instance.Open<FashionDetailsWin>();
        }
        #endregion
 
        #region 红点
        public int fashionDressRedpointId { get; private set; }
        void UpdateRedpoint()
        {
            levelUpRedpoint.state = RedPointState.None;
            if (!FuncOpen.Instance.IsFuncOpen(FASHIONDRESS_FUNC_ID))
            {
                return;
            }
            foreach (var type in fashionDressTypeSort)
            {
                foreach (var quality in fashionDressQualitySort)
                {
                    List<int> list;
                    if (TryGetFashionDresses(type, quality, out list))
                    {
                        foreach (var id in list)
                        {
                            FashionDress fashionDress;
                            if (TryGetFashionDress(id, out fashionDress))
                            {
                                var level = GetFashionDressLevel(fashionDress.id);
                                if (level >= fashionDress.maxLevel)
                                {
                                    continue;
                                }
                                var levelUpRequireCount = fashionDress.GetLevelUpRequireCount(level);
                                var count = packModel.GetItemCountByID(PackType.Item, fashionDress.requireLevelUpItem);
                                if (count >= levelUpRequireCount)
                                {
                                    fashionDressRedpointId = fashionDress.id;
                                    levelUpRedpoint.state = RedPointState.Simple;
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
        #endregion
    }
 
    public class FashionDress
    {
        public int id { get; private set; }
        public int requireLevelUpItem { get; private set; }
        public int maxLevel { get; private set; }
        public int equipPlace { get; private set; }
        public int fashionDressType { get; private set; }
 
        List<int> equipItems = new List<int>();
        List<int> requireLevelUpCounts = new List<int>();
        Dictionary<int, Dictionary<int, int>> propertys = new Dictionary<int, Dictionary<int, int>>();
        public FashionDress(FashionDressConfig config)
        {
            id = config.CoatID;
            requireLevelUpItem = config.UnlockItemID;
            maxLevel = config.MaxLV;
            fashionDressType = config.type;
            requireLevelUpCounts.AddRange(config.CostItemCnt);
            var json = LitJson.JsonMapper.ToObject(config.StarAttr);
            foreach (var starKey in json.Keys)
            {
                var star = int.Parse(starKey);
                Dictionary<int, int> dict = new Dictionary<int, int>();
                propertys.Add(star, dict);
                foreach (var propertyKey in json[starKey].Keys)
                {
                    var property = int.Parse(propertyKey);
                    dict.Add(property, int.Parse(json[starKey][propertyKey].ToString()));
                }
            }
            equipItems.AddRange(config.EquipItemID);
            var equipItemConfig = ItemConfig.Get(equipItems[0]);
            equipPlace = equipItemConfig.EquipPlace;
        }
 
        public int GetEquipItemId(int job = 0)
        {
            if (job == 0)
            {
                job = PlayerDatas.Instance.baseData.Job;
            }
            var index = job - 1;
            if (index < equipItems.Count)
            {
                return equipItems[index];
            }
            return 0;
        }
 
        public bool TryGetProperty(int level, out Dictionary<int, int> dict)
        {
            return propertys.TryGetValue(level, out dict);
        }
 
        public int GetLevelUpRequireCount(int level)
        {
            var index = level;
            if (index < requireLevelUpCounts.Count)
            {
                return requireLevelUpCounts[index];
            }
            return 0;
        }
    }
}