少年修仙传客户端代码仓库
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
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace vnxbqy.UI
{
    public class PhantasmPavilionZhanLingModel : Model, IBeforePlayerDataInitialize
    {
        public readonly int ZhanLingHType = 10;
        public readonly int FuncId = 238;
 
        // 高级战令类型对应的充值ID列表
        public Dictionary<int, List<int>> ctgIdDictH = new Dictionary<int, List<int>>();
 
        public Dictionary<int, List<int>> ctgIdDict = new Dictionary<int, List<int>>();
 
        //收到的所有服务器战令包字典
        public Dictionary<int, ZhanlingInfo> zhanLingInfoDict = new Dictionary<int, ZhanlingInfo>();
 
        public Action UpdateGiftStateEvent;
        public Redpoint redpoint = new Redpoint(MainRedPoint.RechargeGenerousGiftWinRedpoint, MainRedDot.PhantasmPavilionZhanLingRepoint);
        List<ZhanLingGiftItemInfo> allGiftItemList = new List<ZhanLingGiftItemInfo>();
        WorldBossModel worldBossModel { get { return ModelCenter.Instance.GetModel<WorldBossModel>(); } }
 
        //同步播放摆动动画
        public Action PlayAnimationSync;
 
        private bool isPlayAnimation = false;
        public bool IsPlayAnimation
        {
            get
            {
                return isPlayAnimation;
            }
            set
            {
                isPlayAnimation = value;
                if (isPlayAnimation)
                {
                    PlayAnimationSync?.Invoke();
                }
                isPlayAnimation = false;
            }
        }
 
        public override void Init()
        {
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFunctionStateChange;
            worldBossModel.killCntEvent += OnkillCntEvent;
            ctgIdDict = GeneralDefine.ZhanLingCtgIdDict;
            ctgIdDictH = GeneralDefine.ZhanLingCtgIdHDict;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            zhanLingInfoDict.Clear();
        }
 
        public override void UnInit()
        {
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFunctionStateChange;
            worldBossModel.killCntEvent -= OnkillCntEvent;
        }
 
        private void OnFunctionStateChange(int obj)
        {
            if (obj == FuncId)
            {
                UpdateRedpoint(ZhanLingHType);
                UpdateGiftStateEvent?.Invoke();
            }
        }
 
        private void OnkillCntEvent()
        {
            UpdateRedpoint(ZhanLingHType);
            UpdateGiftStateEvent?.Invoke();
        }
 
        public void UpdateGiftState(HB120_tagMCZhanlingInfo vNetData)
        {
            if (zhanLingInfoDict.ContainsKey(vNetData.ZhanlingType))
            {
                zhanLingInfoDict[vNetData.ZhanlingType].isActivite = vNetData.IsActivite;
                zhanLingInfoDict[vNetData.ZhanlingType].isActiviteH = vNetData.IsActiviteH;
                zhanLingInfoDict[vNetData.ZhanlingType].value1 = (int)vNetData.Value1;
                if (vNetData.RewardCount != 0)
                {
                    for (int i = 0; i < vNetData.RewardCount; i++)
                    {
                        zhanLingInfoDict[vNetData.ZhanlingType].freeZhanHaveDict[(int)vNetData.RewardList[i].NeedValue] = (int)vNetData.RewardList[i].FreeRewardState;
                        zhanLingInfoDict[vNetData.ZhanlingType].paidZhanHaveDict[(int)vNetData.RewardList[i].NeedValue] = (int)vNetData.RewardList[i].ZLRewardState;
                        zhanLingInfoDict[vNetData.ZhanlingType].paidZhanHaveHDict[(int)vNetData.RewardList[i].NeedValue] = (int)vNetData.RewardList[i].ZLRewardStateH;
                    }
                }
            }
            else
            {
                ZhanlingInfo zhanlingInfo = new ZhanlingInfo();
                zhanlingInfo.zhanLingType = vNetData.ZhanlingType;
                zhanlingInfo.isActivite = vNetData.IsActivite;
                zhanlingInfo.isActiviteH = vNetData.IsActiviteH;
                zhanlingInfo.rewardCount = vNetData.RewardCount;
                zhanlingInfo.value1 = (int)vNetData.Value1;
                zhanlingInfo.freeZhanHaveDict = new Dictionary<int, int>();
                zhanlingInfo.paidZhanHaveDict = new Dictionary<int, int>();
                zhanlingInfo.paidZhanHaveHDict = new Dictionary<int, int>();
                for (int i = 0; i < zhanlingInfo.rewardCount; i++)
                {
                    zhanlingInfo.freeZhanHaveDict[(int)vNetData.RewardList[i].NeedValue] = vNetData.RewardList[i].FreeRewardState;
                    zhanlingInfo.paidZhanHaveDict[(int)vNetData.RewardList[i].NeedValue] = vNetData.RewardList[i].ZLRewardState;
                    zhanlingInfo.paidZhanHaveHDict[(int)vNetData.RewardList[i].NeedValue] = vNetData.RewardList[i].ZLRewardStateH;
                }
                zhanLingInfoDict[zhanlingInfo.zhanLingType] = zhanlingInfo;
            }
            if (vNetData.ZhanlingType == ZhanLingHType)
            {
                UpdateRedpoint(ZhanLingHType);
                UpdateGiftStateEvent?.Invoke();
            }
        }
 
        public int GetValue1()
        {
            return zhanLingInfoDict.ContainsKey(ZhanLingHType) ? zhanLingInfoDict[ZhanLingHType].value1 : 0;
        }
 
        public bool IsNeedValueOk(int needValue)
        {
            int nowNeedValue = GetValue1();
            return nowNeedValue >= needValue;
        }
 
        //0 没购买进阶和玄级 1 购买了进阶没买玄级 2 购买了玄级没买进阶 3 购买了进阶和玄级
        public int GetBuyState(int zhanLingType)
        {
            bool isBuyPaid = zhanLingInfoDict[zhanLingType].isActivite > 0;
            bool isBuyPaidH = zhanLingInfoDict[zhanLingType].isActiviteH > 0;
            if (isBuyPaid && isBuyPaidH)
            {
                return 3;
            }
            else if (isBuyPaid && !isBuyPaidH)
            {
                return 1;
            }
            else if (!isBuyPaid && isBuyPaidH)
            {
                return 2;
            }
            else
            {
                return 0;
            }
        }
 
        // 0 不能领 1 未领取 2 已领取
        public int GetFreeGiftState(int zhanLingType, int needValue)
        {
            if (IsNeedValueOk(needValue))
            {
                return zhanLingInfoDict[zhanLingType].freeZhanHaveDict[needValue] > 0 ? 2 : 1;
            }
            else
            {
                return 0;
            }
        }
 
        // 0 不能领 1 未领取 2 已领取
        public int GetPaidGiftState(int zhanLingType, int needValue)
        {
            if (IsNeedValueOk(needValue) && zhanLingInfoDict[zhanLingType].isActivite > 0)
            {
                return zhanLingInfoDict[zhanLingType].paidZhanHaveDict[needValue] > 0 ? 2 : 1;
            }
            else
            {
                return 0;
            }
        }
 
        // 0 不能领 1 未领取 2 已领取
        public int GetPaidGiftHState(int zhanLingType, int needValue)
        {
            if (IsNeedValueOk(needValue) && zhanLingInfoDict[zhanLingType].isActiviteH > 0)
            {
                return zhanLingInfoDict[zhanLingType].paidZhanHaveHDict[needValue] > 0 ? 2 : 1;
            }
            else
            {
                return 0;
            }
        }
 
        //发包 type 0-免费;1-普通战令;2-高级战令
        public void HaveGift(int zhanLingType, int needValue, int type)
        {
            var pak = new IL_CA504_tagCMPlayerGetReward();
            string dataExStr = (needValue * 10 + type).ToString();
            pak.RewardType = (byte)65;
            pak.DataEx = (uint)zhanLingType;
            pak.DataExStrLen = (byte)dataExStr.Length;
            pak.DataExStr = dataExStr;
            GameNetSystem.Instance.SendInfo(pak);
        }
 
        //获取最小未领取的物品索引
        public int GetJumpStartIndex(int zhanLingType)
        {
            var infoDict = ILZhanlingConfig.GetTypeToIDDict(zhanLingType);
            if (infoDict.IsNullOrEmpty())
                return 0;
 
            List<int> infoList = infoDict.Keys.ToList();
            if (infoList.IsNullOrEmpty())
                return 0;
 
            if (zhanLingInfoDict.IsNullOrEmpty() || !zhanLingInfoDict.ContainsKey(zhanLingType))
                return 0;
 
            var zhanLingInfo = zhanLingInfoDict[zhanLingType];
 
            int index = 0;
            bool allItemsClaimed = true;
 
            for (int i = 0; i < infoList.Count; i++)
            {
                int needValue = infoList[i];
                bool isHaveFree = zhanLingInfo.freeZhanHaveDict.GetValueOrDefault(needValue, 0) > 0;
                bool isHavePaid = zhanLingInfo.paidZhanHaveDict.GetValueOrDefault(needValue, 0) > 0;
                bool isHavePaidH = zhanLingInfo.paidZhanHaveHDict.GetValueOrDefault(needValue, 0) > 0;
 
                if (!isHaveFree || !isHavePaid || !isHavePaidH)
                {
                    allItemsClaimed = false;
                    if (!isHaveFree)
                    {
                        index = i;
                        break;
                    }
 
                    if (zhanLingInfo.isActivite > 0 && !isHavePaid)
                    {
                        index = i;
                        break;
                    }
 
                    if (zhanLingInfo.isActiviteH > 0 && !isHavePaidH)
                    {
                        index = i;
                        break;
                    }
                }
            }
 
            if (allItemsClaimed && zhanLingInfo.isActivite > 0 && zhanLingInfo.isActiviteH > 0)
            {
                return infoList.Count - 1;
            }
 
            return Math.Max(0, index - 2);
        }
 
        //一键获取所有可领取的礼品,弹出展示窗口
        public void HaveAllZhanLingGift(int zhanLingType)
        {
            //没有格子
            if (ModelCenter.Instance.GetModelEx<PackModel>().GetEmptyGridCount(PackType.Item) < 1)
            {
                SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580");
                return;
            }
            List<int> haveFreeRewardItemList = new List<int>(); //用户领到的免费物品的所需值列表
            List<int> havePaidRewardItemList = new List<int>(); //用户领到的付费物品的所需值列表
            List<int> havePaidRewardItemHList = new List<int>(); //用户领到的付费物品的所需值列表
            var needValueList = ILZhanlingConfig.GetTypeToIDDict(zhanLingType).Keys.ToList();
            for (int i = 0; i < needValueList.Count; i++)
            {
                int needValue = needValueList[i];
                int freeState = GetFreeGiftState(zhanLingType, needValue);
                int paidState = GetPaidGiftState(zhanLingType, needValue);
                int paidHState = GetPaidGiftHState(zhanLingType, needValue);
                if (freeState == 1)
                {
                    haveFreeRewardItemList.Add(needValue);
                }
                if (paidState == 1)
                {
                    havePaidRewardItemList.Add(needValue);
                }
                if (paidHState == 1)
                {
                    havePaidRewardItemHList.Add(needValue);
                }
            }
            MergeAllHaveZhanLingGift(zhanLingType, haveFreeRewardItemList, havePaidRewardItemList, havePaidRewardItemHList);
            DebugEx.Log($"背包空格 {ModelCenter.Instance.GetModelEx<PackModel>().GetEmptyGridCount(PackType.Item)} 需要格子 {allGiftItemList.Count}");
            if (ModelCenter.Instance.GetModelEx<PackModel>().GetEmptyGridCount(PackType.Item) >= allGiftItemList.Count)
            {
                for (int i = 0; i < needValueList.Count; i++)
                {
                    int needValue = needValueList[i];
                    int freeState = GetFreeGiftState(zhanLingType, needValue);
                    int paidState = GetPaidGiftState(zhanLingType, needValue);
                    int paidHState = GetPaidGiftHState(zhanLingType, needValue);
                    if (freeState == 1)
                    {
                        HaveGift(zhanLingType, needValue, 0);
                    }
                    if (paidState == 1)
                    {
                        HaveGift(zhanLingType, needValue, 1);
                    }
                    if (paidHState == 1)
                    {
                        HaveGift(zhanLingType, needValue, 2);
                    }
                }
            }
            else
            {
                SysNotifyMgr.Instance.ShowTip("GeRen_lhs_202580");
                return;
            }
        }
 
        //type 0 免费物品 1 进阶令物品 2 玄阶进阶令物品
        public void MergeAllHaveZhanLingGift(int zhanLingType, List<int> haveFreeRewardItemList, List<int> havePaidRewardItemList, List<int> havePaidRewardItemHList)
        {
            for (int i = 0; i < haveFreeRewardItemList.Count; i++)
            {
                for (int j = 0; j < ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[haveFreeRewardItemList[i]]).FreeRewardItemList.Length; j++)
                {
                    ZhanLingGiftItemInfo tempAllGiftItems = new ZhanLingGiftItemInfo();
                    tempAllGiftItems.id = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[haveFreeRewardItemList[i]]).FreeRewardItemList[j][0];
                    tempAllGiftItems.count = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[haveFreeRewardItemList[i]]).FreeRewardItemList[j][1];
                    tempAllGiftItems.name = ItemConfig.Get(tempAllGiftItems.id).ItemName;
                    tempAllGiftItems.quality = ItemConfig.Get(tempAllGiftItems.id).ItemColor;
                    if (allGiftItemList.Count == 0)
                    {
                        allGiftItemList.Add(tempAllGiftItems);
                    }
                    else
                    {
                        bool isExist = false;
                        for (int k = 0; k < allGiftItemList.Count; k++)
                        {
                            if (allGiftItemList[k].id == tempAllGiftItems.id)
                            {
                                isExist = true;
                                allGiftItemList[k].count += tempAllGiftItems.count;
                                break;
                            }
                        }
                        if (!isExist)
                        {
                            allGiftItemList.Add(tempAllGiftItems);
                        }
                    }
                }
            }
            for (int i = 0; i < havePaidRewardItemList.Count; i++)
            {
                for (int j = 0; j < ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemList[i]]).ZLRewardItemList.Length; j++)
                {
                    ZhanLingGiftItemInfo tempAllGiftItems = new ZhanLingGiftItemInfo();
                    tempAllGiftItems.id = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemList[i]]).ZLRewardItemList[j][0];
                    tempAllGiftItems.count = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemList[i]]).ZLRewardItemList[j][1];
                    tempAllGiftItems.name = ItemConfig.Get(tempAllGiftItems.id).ItemName;
                    tempAllGiftItems.quality = ItemConfig.Get(tempAllGiftItems.id).ItemColor;
                    if (allGiftItemList.Count == 0)
                    {
                        allGiftItemList.Add(tempAllGiftItems);
                    }
                    else
                    {
                        bool isExist = false;
                        for (int k = 0; k < allGiftItemList.Count; k++)
                        {
                            if (allGiftItemList[k].id == tempAllGiftItems.id)
                            {
                                isExist = true;
                                allGiftItemList[k].count += tempAllGiftItems.count;
                                break;
                            }
                        }
                        if (!isExist)
                        {
                            allGiftItemList.Add(tempAllGiftItems);
                        }
                    }
                }
            }
            for (int i = 0; i < havePaidRewardItemHList.Count; i++)
            {
                for (int j = 0; j < ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemHList[i]]).ZLRewardItemListH.Length; j++)
                {
                    ZhanLingGiftItemInfo tempAllGiftItems = new ZhanLingGiftItemInfo();
                    tempAllGiftItems.id = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemHList[i]]).ZLRewardItemListH[j][0];
                    tempAllGiftItems.count = ILZhanlingConfig.Get(ILZhanlingConfig.GetTypeToIDDict(zhanLingType)[havePaidRewardItemHList[i]]).ZLRewardItemListH[j][1];
                    tempAllGiftItems.name = ItemConfig.Get(tempAllGiftItems.id).ItemName;
                    tempAllGiftItems.quality = ItemConfig.Get(tempAllGiftItems.id).ItemColor;
                    if (allGiftItemList.Count == 0)
                    {
                        allGiftItemList.Add(tempAllGiftItems);
                    }
                    else
                    {
                        bool isExist = false;
                        for (int k = 0; k < allGiftItemList.Count; k++)
                        {
                            if (allGiftItemList[k].id == tempAllGiftItems.id)
                            {
                                isExist = true;
                                allGiftItemList[k].count += tempAllGiftItems.count;
                                break;
                            }
                        }
                        if (!isExist)
                        {
                            allGiftItemList.Add(tempAllGiftItems);
                        }
                    }
                }
            }
        }
 
        private int SortGift(ZhanLingGiftItemInfo a, ZhanLingGiftItemInfo b)
        {
            return b.quality.CompareTo(a.quality);
        }
 
        //按品质排序
        public List<ZhanLingGiftItemInfo> SortAllHaveZhanLingGift()
        {
            allGiftItemList.Sort(SortGift);
            return allGiftItemList;
        }
 
        private void UpdateRedpoint(int zhanLingType)
        {
            redpoint.state = RedPointState.None;
            if (zhanLingInfoDict == null || !zhanLingInfoDict.ContainsKey(zhanLingType))
                return;
            if (!FuncOpen.Instance.IsFuncOpen(FuncId))
                return;
            var needValueList = ILZhanlingConfig.GetTypeToIDDict(zhanLingType).Keys.ToList();
            for (int i = 0; i < needValueList.Count; i++)
            {
                int freeState = GetFreeGiftState(zhanLingType, needValueList[i]);
                int paidState = GetPaidGiftState(zhanLingType, needValueList[i]);
                int paidHState = GetPaidGiftHState(zhanLingType, needValueList[i]);
                if (freeState == 1 || paidState == 1 || paidHState == 1)
                {
                    redpoint.state = RedPointState.Simple;
                    break;
                }
            }
        }
 
        //已经购买并领取所有物品
        public bool IsFinish()
        {
            int zhanLingType = ZhanLingHType;
            if (zhanLingInfoDict.IsNullOrEmpty() || !zhanLingInfoDict.TryGetValue(zhanLingType, out var zhanlingInfo) ||
                zhanlingInfo == null || zhanlingInfo.freeZhanHaveDict == null || zhanlingInfo.paidZhanHaveDict == null)
                return false;
            //有没购买的
            if (GetBuyState(zhanLingType) != 3)
                return false;
            //有没领取的物品
            var arr = zhanlingInfo.freeZhanHaveDict.Keys.ToArray();
            for (int i = 0; i < arr.Length; i++)
            {
                int needValue = arr[i];
                if (GetFreeGiftState(zhanLingType, needValue) != 2 || GetPaidGiftState(zhanLingType, needValue) != 2 || GetPaidGiftHState(zhanLingType, needValue) != 2)
                    return false;
            }
            return true;
        }
    }
}