少年修仙传客户端代码仓库
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
using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
 
namespace vnxbqy.UI
{
    //仙盟新增功能
    public class FairyNewModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        public int affairCount { get; private set; } // 已经完成的事务数量
        public int affairMaxCount { get; private set; }
        public int freeRefreshCount { get; private set; }
        public int freeRefreshMaxCount { get; private set; }
        public int[] payRefresh;
        public Dictionary<int, int> allAttrsDict = new Dictionary<int, int>();
        public bool lvUpSuccess = false;
        public Dictionary<int, AffairStarInfo> affairStarInfo = new Dictionary<int, AffairStarInfo>(); //星级:时间和奖励
        public Dictionary<int, FamilyAffair> familyAffairDic = new Dictionary<int, FamilyAffair>();
        public Dictionary<int, List<int>> useItemsDict = new Dictionary<int, List<int>>();
        public event Action UpdateFamilyAffairEvent;
 
        public Dictionary<int, Int2> zhenfaInfo = new Dictionary<int, Int2>();
        public event Action UpdateFamilyZhenfaEvent;
        public event Action OnSelectZhenfaEvent;
        private int m_selectZhenfaType = 0;  // 选择的阵眼类型索引  需换算为阵眼类型使用
        public int selectZhenfaType
        {
            get
            {
                return m_selectZhenfaType;
            }
            set
            {
                if (m_selectZhenfaType != value)
                {
                    m_selectZhenfaType = value;
                    OnSelectZhenfaEvent?.Invoke();
                }
            }
        }
 
        public int selectItemIndex = 0;
 
        public int sitRound { get; private set; }
        public int sitMaxRound { get; private set; }
        public int roundSeconds = 0;    // 打坐一轮所需时间
        public int[] addExpRateInfo;    // 打坐加成经验倍率 | 最高经验加成
        public bool showSitFinishTip = false;
        public Dictionary<string, int> sitDungeonInfo = new Dictionary<string, int>();
 
        private Redpoint affairRedpoint = new Redpoint(10701, 1070112); //历练
        private Redpoint zhenfaRedpoint = new Redpoint(10701, 1070113); //阵法
        public Redpoint sitRedpoint = new Redpoint(10701, 1070114); //打坐
        private List<Redpoint> zhanfaredpoints = new List<Redpoint>();
        Redpoint zbgRedpoint = new Redpoint(10701, 1070115); //珍宝阁
 
        //珍宝阁
        public int zhenbaogeCutState = 0;
        public int zhenbaogeBuyState = 0;
        public bool needCheckCutCD = false;
        public event Action UpdateZhenbaogeEvent;
        public bool isQueryZBGYet = false;
        public float lastZBGStartTime = 0; //过天刷新用
        public const int ZBGFamilyActionType = 16;
        //{id:数据} 砍价行为,value1为玩家ID,特殊约定为1时为家族的数据
        public Dictionary<int, HA403_tagGCFamilyActionInfo.tagGCFamilyAction> familyZBGActions = new Dictionary<int, HA403_tagGCFamilyActionInfo.tagGCFamilyAction>();
        public List<int> sortPlayerCut = new List<int>();
        public event Action<bool> UpdateFamilyActionEvent;
        public int zbgPriceType;
        public int zbgOrgPriceValue;
        public int zbgChangFamilyCD;
        public List<int> cutCntListForTalk = new List<int>();
 
 
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
 
 
        public override void Init()
        {
            ParseConfig();
            PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += OnRefreshFairyInfo;
            PlayerDatas.Instance.fairyData.OnRefreshFairyMine += OnRefreshFairyMine;//退出仙盟
            GlobalTimeEvent.Instance.minuteEvent += UpdateRedpoint;
            foreach (int type in useItemsDict.Keys)
            {
                zhanfaredpoints.Add(new Redpoint(1070113, 1070113 * 10 + type));
            }
        }
 
 
        public override void UnInit()
        {
            GlobalTimeEvent.Instance.minuteEvent -= UpdateRedpoint;
            PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= OnRefreshFairyInfo;
            PlayerDatas.Instance.fairyData.OnRefreshFairyMine -= OnRefreshFairyMine;//退出仙盟
        }
 
 
        void ParseConfig()
        {
            var config = FuncConfigConfig.Get("FamilyAffair");
            affairMaxCount = int.Parse(config.Numerical1);
            freeRefreshMaxCount = int.Parse(config.Numerical2);
            payRefresh = ConfigParse.GetMultipleStr<int>(config.Numerical3);
            var json = JsonMapper.ToObject(config.Numerical4);
            var keys = json.Keys.ToList();
            foreach (var key in keys)
            {
                var info = new AffairStarInfo();
                var json2 = JsonMapper.ToObject(json[key].ToJson());
                info.times = int.Parse(json2[1].ToString());
                info.items = JsonMapper.ToObject<int[][]>(json2[2].ToJson());
                affairStarInfo.Add(int.Parse(key), info);
            }
 
            useItemsDict = ConfigParse.ParseJsonDict(FuncConfigConfig.Get("FamilyZhenfa").Numerical1);
 
            config = FuncConfigConfig.Get("FamilySit");
            int[] sitInfo = ConfigParse.GetMultipleStr<int>(config.Numerical1);
            roundSeconds = sitInfo[0];
            sitMaxRound = sitInfo[1];
            addExpRateInfo = ConfigParse.GetMultipleStr<int>(config.Numerical3);
 
            config = FuncConfigConfig.Get("Zhenbaoge");
            zbgPriceType = int.Parse(config.Numerical1);
            zbgOrgPriceValue = int.Parse(config.Numerical2);
            zbgChangFamilyCD = int.Parse(config.Numerical3);
            cutCntListForTalk = JsonMapper.ToObject<List<int>>(config.Numerical4);
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            freeRefreshCount = 0;
            familyAffairDic.Clear();
            zhenfaInfo.Clear();
            allAttrsDict.Clear();
            lvUpSuccess = false;
            sitRound = 0;
            showSitFinishTip = false;
            sitDungeonInfo.Clear();
            isQueryZBGYet = false;
            familyZBGActions.Clear();
            sortPlayerCut.Clear();
            zhenbaogeCutState = 0;
            zhenbaogeBuyState = 0;
            needCheckCutCD = false;
        }
 
        private void OnRefreshFairyInfo()
        {
            if (PlayerDatas.Instance.fairyData.HasFairy)
            {
                UpdateRedpoint();
                QueryZBGFamilyInfo();
            }
 
        }
 
 
        void UpdateRedpoint()
        {
            affairRedpoint.state = RedPointState.None;
            if (!PlayerDatas.Instance.fairyData.HasFairy)
            {
                return;
            }
            if (affairCount >= affairMaxCount) return;
 
            foreach (var affair in familyAffairDic)
            {
                if (affair.Value.State == 0)
                {
                    affairRedpoint.state = RedPointState.Simple;
                    return;
                }
                else if (affair.Value.State == 1 && TimeUtility.AllSeconds - affair.Value.StartSeconds - affair.Value.RemainDuration >= 0)
                {
                    affairRedpoint.state = RedPointState.Simple;
                    return;
                }
            }
        }
 
 
 
        public void UpdateFamilyAffairInfo(HA508_tagMCFamilyAffairInfo netPack)
        {
            freeRefreshCount = netPack.RefreshFreeCount;
            for (int i = 0; i < netPack.Count; i++)
            {
                familyAffairDic[netPack.AffairInfoList[i].AffairID] = new FamilyAffair()
                {
                    StartSeconds = TimeUtility.AllSeconds,
                    Star = netPack.AffairInfoList[i].Star,
                    State = netPack.AffairInfoList[i].State,
                    RemainDuration = netPack.AffairInfoList[i].RemainDuration
 
                };
            }
            affairCount = 0;
            foreach (var item in familyAffairDic)
            {
                if (item.Value.State == 2)
                {
                    affairCount++;
                }
            }
 
            UpdateFamilyAffairEvent?.Invoke();
            UpdateRedpoint();
        }
 
 
        public struct AffairStarInfo
        {
            public int times;
            public int[][] items;
        }
 
        public struct FamilyAffair
        {
            public int StartSeconds;        // 开始时间
            public int Star;        // 星级
            public int State;        // 状态:0-无;1-进行中;2-已完成
            public int RemainDuration;        // 剩余时长,秒,有剩余时间代表进行中
        }
 
 
        #region 阵法
 
 
 
 
 
        public void UpdateFamilyZhenfaInfo(HA509_tagMCFamilyZhenfaInfo netPack)
        {
            for (int i = 0; i < netPack.ZhenfaInfoList.Length; i++)
            {
                if (zhenfaInfo.ContainsKey(netPack.ZhenfaInfoList[i].ZhenfaType))
                {
                    if (zhenfaInfo[netPack.ZhenfaInfoList[i].ZhenfaType].x != netPack.ZhenfaInfoList[i].ZhenfaLV)
                    {
                        lvUpSuccess = true;
                    }
                }
                else
                {
                    lvUpSuccess = true;
                }
                zhenfaInfo[netPack.ZhenfaInfoList[i].ZhenfaType] = new Int2(netPack.ZhenfaInfoList[i].ZhenfaLV, (int)netPack.ZhenfaInfoList[i].ZhenfaExp);
            }
 
            RefreshAllAttrs();
 
            if (WindowCenter.Instance.IsOpen<FamilyZhenfaWin>())
            {
                UpdateZhenfaRedpoint();
            }
 
            UpdateFamilyZhenfaEvent?.Invoke();
        }
 
        public int GetZhenyanLV(int type)
        {
            if (zhenfaInfo.ContainsKey(type))
            {
                return zhenfaInfo[type].x;
            }
            return 0;
        }
        public int GetZhenyanExp(int type)
        {
            if (zhenfaInfo.ContainsKey(type))
            {
                return zhenfaInfo[type].y;
            }
            return 0;
        }
 
        public void RefreshAllAttrs()
        {
            allAttrsDict.Clear();
            foreach (var type in zhenfaInfo.Keys)
            {
                var config = FamilyZhenfaConfig.GetConfig(type, zhenfaInfo[type].x);
                for (int i = 0; i < config.LVAttrType.Length; i++)
                {
                    var attrType = config.LVAttrType[i];
                    if (!allAttrsDict.ContainsKey(attrType))
                    {
                        allAttrsDict[attrType] = 0;
                    }
                    allAttrsDict[attrType] += config.LVAttrValue[i];
                }
            }
        }
 
        public Dictionary<int, int> GetAttrsByType(int type)
        {
            int lv = 0;
            if (zhenfaInfo.ContainsKey(type))
            {
                lv = zhenfaInfo[type].x;
            }
 
            Dictionary<int, int> attrs = new Dictionary<int, int>();
            var config = FamilyZhenfaConfig.GetConfig(type, lv);
            for (int i = 0; i < config.LVAttrType.Length; i++)
            {
                attrs[config.LVAttrType[i]] = config.LVAttrValue[i];
            }
 
            return attrs;
        }
 
        public Dictionary<int, int> GetNextAttrsByType(int type)
        {
            int lv = 0;
            if (zhenfaInfo.ContainsKey(type))
            {
                lv = zhenfaInfo[type].x;
            }
 
            Dictionary<int, int> attrs = new Dictionary<int, int>();
            var config = FamilyZhenfaConfig.GetConfig(type, lv + 1);
            if (config == null) return attrs;
            for (int i = 0; i < config.LVAttrType.Length; i++)
            {
                attrs[config.LVAttrType[i]] = config.LVAttrValue[i];
            }
 
            return attrs;
        }
 
        public void UpdateZhenfaRedpoint()
        {
            foreach (var point in zhanfaredpoints)
            {
                point.state = RedPointState.None;
            }
            if (!PlayerDatas.Instance.fairyData.HasFairy)
            {
                return;
            }
            foreach (var type in useItemsDict.Keys)
            {
                for (int i = 0; i < useItemsDict[type].Count; i++)
                {
                    if (packModel.GetItemCountByID(PackType.Item, useItemsDict[type][i]) > 0)
                    {
                        zhanfaredpoints[type - 1].state = RedPointState.Simple;
                        continue;
                    }
                }
            }
        }
 
        public void OnPlayerLoginOk()
        {
            UpdateZhenfaRedpoint();
            UpdateSitRedpoint();
            UpdateZBGRedpoint();
 
            if (PlayerDatas.Instance.fairyData.HasFairy)
                QueryZBGFamilyInfo();
        }
 
        #endregion
 
        #region 打坐
 
        public void UpdateSitInfo(HA511_tagMCFamilySitInfo netPack)
        {
            sitRound = netPack.ExpRound;
            UpdateSitRedpoint();
        }
 
 
        //"sitInfo": {"playerCount": 1, "expPoint": 0, "exp": 4108587, "expRound": 75}
        public void OnReceiveHelpMessage(string _mission)
        {
            var json = JsonMapper.ToObject(_mission);
            if (json != null && json.Keys.Contains("sitInfo"))
            {
                sitDungeonInfo = JsonMapper.ToObject<Dictionary<string, int>>(json["sitInfo"].ToJson());
            }
        }
 
        void UpdateSitRedpoint()
        {
            sitRedpoint.state = RedPointState.None;
            if (!PlayerDatas.Instance.fairyData.HasFairy)
            {
                return;
            }
            if (sitRound >= sitMaxRound)
            {
                return;
            }
 
            DailyQuestOpenTime openTime;
            dailyQuestModel.TryGetOpenTime((int)DailyQuestType.default3, out openTime);
            if (openTime == null)
            {
                return;
            }
            if (openTime.InOpenTime())
            {
                sitRedpoint.state = RedPointState.Simple;
            }
        }
        #endregion
 
        #region 珍宝阁
       
        
        public void UpdateZhenbaogeInfo(HA512_tagMCFamilyZhenbaogeInfo netPack)
        {
            //砍价状态:仙盟里记录已砍价才是真的已砍价状态,封包中的砍价状态用于判断cd间隔使用
            needCheckCutCD = netPack.CutState == 1;
            zhenbaogeBuyState = netPack.BuyState;
            UpdateZhenbaogeEvent?.Invoke();
            UpdateZBGRedpoint();
        }
 
        
        
 
        //登录后首次打开查询,换新仙盟查询
        public void QueryZBGFamilyInfo()
        {
            if (isQueryZBGYet)
                return;
 
            var pack = new CA408_tagCGQueryFamilyAction();
            pack.ActionType = 16;
            pack.FamilyID = PlayerDatas.Instance.baseData.FamilyId;
            GameNetSystem.Instance.SendInfo(pack);
            isQueryZBGYet = true;
        }
 
        private void OnRefreshFairyMine()
        {
            if (!PlayerDatas.Instance.fairyData.HasFairy)
            {
                isQueryZBGYet = false;
                zhenbaogeCutState = 0;
                familyZBGActions.Clear();
                sortPlayerCut.Clear();
                WindowCenter.Instance.Close<FamilyZBGWin>();
            }
 
            UpdateZBGRedpoint();
        }
 
        public void UpdateZBGRedpoint()
        {
            zbgRedpoint.state = RedPointState.None;
 
            if (!PlayerDatas.Instance.fairyData.HasFairy)
            {
                return;
            }
 
            if (zhenbaogeCutState == 0)
            {
                zbgRedpoint.state = RedPointState.Simple;
            }
        }
 
        public void UpdateFamilyAction(HA403_tagGCFamilyActionInfo vNetData)
        {
            if (vNetData.ActionType != ZBGFamilyActionType)
            {
                return;
            }
            if (vNetData.FamilyID != PlayerDatas.Instance.baseData.FamilyId)
            {
                return;
            }
 
            bool restart = false;
            if (vNetData.FamilyActionList.Length == 1 && vNetData.FamilyActionList[0].Value1 == 1)
            {
                if (familyZBGActions.ContainsKey(1) && familyZBGActions[1].Time != vNetData.FamilyActionList[0].Time)
                {
                    familyZBGActions.Clear();
                    sortPlayerCut.Clear();
                    restart = true;
                }
            }
 
            for (int i = 0; i < vNetData.FamilyActionList.Length; i++)
            {
                int playerID = (int)vNetData.FamilyActionList[i].Value1;
                familyZBGActions[playerID] = vNetData.FamilyActionList[i];
 
            }
 
            if (familyZBGActions.ContainsKey((int)PlayerDatas.Instance.baseData.PlayerID))
            {
                //自己是否已砍价 从列表中查找
                zhenbaogeCutState = 1;
            }
 
 
            sortPlayerCut = familyZBGActions.Keys.ToList();
            if (sortPlayerCut.Contains(1))
                sortPlayerCut.Remove(1);
            sortPlayerCut.Sort((a, b) => { return familyZBGActions[a].Time.CompareTo(familyZBGActions[b].Time); });
 
            UpdateFamilyActionEvent?.Invoke(restart);
            UpdateZBGRedpoint();
        }
 
        //砍价人数
        public int GetZBGFamilyActionCount()
        {
            return Math.Max(0, familyZBGActions.Count - 1);
        }
 
        public int GetTalkState()
        {
            int cnt = GetZBGFamilyActionCount();
            for (int i = 0; i < cutCntListForTalk.Count; i++)
            {
                if (cnt < cutCntListForTalk[i])
                {
                    return i;
                }
            }
            return 0;
        }
 
        public int[][] GetZBGItems()
        {
            if (!familyZBGActions.ContainsKey(1))
                return null;
 
            return JsonMapper.ToObject<int[][]>(familyZBGActions[1].UseData);
        }
 
        public void OnZhenbaogeOP(byte type)
        {
            var pack = new CA616_tagCMZhenbaogeOP();
            pack.OpType = type;
            GameNetSystem.Instance.SendInfo(pack);
        }
 
 
        public Dictionary <int , PlayerFairyData.FairyMember> tmpNoCutMembers = new Dictionary<int, PlayerFairyData.FairyMember>();
 
        //未议价成员
        public void CalcNoCutMembers()
        {
            tmpNoCutMembers.Clear();
            var fairy = PlayerDatas.Instance.fairyData.fairy;
            if (fairy == null)
            {
                return;
            }
 
            foreach(var member in fairy.Member)
            {
                if (!familyZBGActions.ContainsKey((int)member.PlayerID))
                {
                    tmpNoCutMembers[(int)member.PlayerID] = member;
                }
            }
        }
 
        #endregion
    }
}