少年修仙传客户端代码仓库
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Thursday, April 26, 2018
//--------------------------------------------------------
using System;
using System.Collections.Generic;
 
using vnxbqy.UI;
using System.Linq;
//仙玉投资
public struct FairyInvestInfo
{
    public int money;//金额
    public int gear;//
}
 
public struct FairyInvestItems
{
    public int id;
    public int levelLimit;
    public Dictionary<int, List<Item>> items;//奖励
}
 
public class FairyJadeInvestmentModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
{
    public Dictionary<int, Dictionary<int, FairyInvestItems>> fairyInvestItems = new Dictionary<int, Dictionary<int, FairyInvestItems>>();//根据投资类型来存储奖励类型和金额(类型3,4,5);
    public Dictionary<int, Dictionary<int, int>> fairyInvestSingleInfos = new Dictionary<int, Dictionary<int, int>>();//根据类型存储奖励信息
    public Dictionary<int, FairyInvestInfo> fairyInvestInfos = new Dictionary<int, FairyInvestInfo>();//根据类型获取各个类型投资的档位金额和分档
    public Dictionary<int, int> fairyInvestLevelLimits { get; private set; }
 
    public List<int> fairyInvestMultiples = new List<int>();
 
    public int fairyInvestType { get; set; }
 
    public int selectInvestMoney { get; set; }
 
    public int prioritySelectIndex { get; private set; }
 
    bool isServerPrepare = false;
    public bool IsRedpoint = false;
 
    private int redpointLevelLimit = 0;//显示等级
    private int redpointDays = 0;//显示天数
    private bool redpointDirty = true;
 
    public readonly Redpoint redpoint = new Redpoint(209, 20910);//仙玉投资红点
 
 
    public bool IsOpen
    {
        get
        {
            return IsFuncOpen();
        }
    }
 
    public bool priorityOpen
    {
        get
        {
            return redpoint.state != RedPointState.None;
        }
    }
 
    public bool IsAdvance
    {
        get
        {
            return false;
        }
    }
 
    public event Action<int> onStateUpdate;
    public event Action fairyInvestUpdate;
 
    VipInvestModel investModel { get { return ModelCenter.Instance.GetModel<VipInvestModel>(); } }
 
    public override void Init()
    {
        ParseConfig();
 
        OpenServerActivityCenter.Instance.Register(10, this);
    }
 
    public void OnBeforePlayerDataInitialize()
    {
        redpointDirty = true;
        isServerPrepare = false;
        IsRedpoint = false;
        selectInvestMoney = 0;
        fairyInvestInfos.Clear();
        fairyInvestSingleInfos.Clear();
    }
 
    public void OnPlayerLoginOk()
    {
        redpointDirty = true;
        isServerPrepare = true;
        fairyInvestType = GetFairyInvestType();
        UpdateRedpoint();
        IsShowRedPointSimple();      
        PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshEvent;
        PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshEvent;
        FairyJadeInvestmentWin.FairyJadeInvestmentRedPointEvent -= FairyJadeInvestmentRedPoint;
        FairyJadeInvestmentWin.FairyJadeInvestmentRedPointEvent += FairyJadeInvestmentRedPoint;
        GlobalTimeEvent.Instance.secondEvent -= PerSecond;
        GlobalTimeEvent.Instance.secondEvent += PerSecond;
    }
 
    public override void UnInit()
    {
 
    }
 
    private void ParseConfig()
    {
        var funcConfig = FuncConfigConfig.Get("InvestRedPoint");
        redpointLevelLimit = int.Parse(funcConfig.Numerical2);
        redpointDays = int.Parse(funcConfig.Numerical3);
 
        funcConfig = FuncConfigConfig.Get("JadeInvest");
        fairyInvestMultiples.AddRange(ConfigParse.GetMultipleStr<int>(funcConfig.Numerical1));
 
        funcConfig = FuncConfigConfig.Get("GoldInvestLVLimit");
        fairyInvestLevelLimits = ConfigParse.GetDic<int, int>(funcConfig.Numerical1);
 
        var configs = InvestConfig.GetValues();
        foreach (var config in configs)
        {
            if (fairyInvestLevelLimits.ContainsKey(config.type))
            {
                Dictionary<int, FairyInvestItems> dict;
                if (!fairyInvestItems.TryGetValue(config.type,out dict))
                {
                    dict = new Dictionary<int, FairyInvestItems>();
                    fairyInvestItems.Add(config.type, dict);
                }
 
                var items = new Dictionary<int, List<Item>>();
                var json = LitJson.JsonMapper.ToObject(config.award);
                foreach (string gearKey in json.Keys)
                {
                    var gear = int.Parse(gearKey);
                    items.Add(gear, new List<Item>());
                    var itemArray = LitJson.JsonMapper.ToObject<int[][]>(json[gearKey].ToJson());
                    for (int j = 0; j < itemArray.Length; j++)
                    {
                        items[gear].Add(new Item()
                        {
                            id = itemArray[j][0],
                            count = itemArray[j][1],
                        });
                    }
                }
 
                dict.Add(config.id % 100, new FairyInvestItems()
                {
                    id = config.id % 100,
                    levelLimit = config.needLV,
                    items = items,
                });
            }
        }
    }
 
 
    private void PerSecond()
    {
        if (redpointDirty)
        {
            int InvestGold = GetInvestGold();
            if (InvestGold > 0)
            {
                UpdateRedpoint();
            }
            IsShowRedPointSimple();
            redpointDirty = false;
        }
    }
 
    private void PlayerDataRefreshEvent(PlayerDataType dataType)
    {
        if (dataType == PlayerDataType.LV)
        {
            redpointDirty = true;
        }
    }
 
    private void FairyJadeInvestmentRedPoint()
    {
        RedPointSate();
    }
 
    private bool IsFuncOpen()//功能是否开启
    {
        bool existInvestGear = false;
 
        int gear = GetFairyInvestGear();
        var maxGear = investModel.GetInvestMaxGear(fairyInvestType);
 
        if (gear > 0)
        {
            if (gear < maxGear)
            {
                existInvestGear = true;
            }
            else if (gear == maxGear)
            {
                var dit = GetInfoSeriors();
                foreach (int key in dit.Keys)
                {
                    if (dit[key] < gear)
                    {
                        existInvestGear = true;
                    }
                }
            }
        }
 
        if (!FuncOpen.Instance.IsFuncOpen(118))
        {
            return false;
        }
 
        var maxLevelLimit = fairyInvestLevelLimits.Values.Last();
 
        if (PlayerDatas.Instance.baseData.LV > maxLevelLimit && !existInvestGear)
        {
            return false;
        }
        else
        {
            return true;
        }
    }
 
    public void GetInfoSeriors(HA337_tagMCGoldInvestInfo package)//接受信息
    {
        if (fairyInvestLevelLimits.ContainsKey(package.InvestType))
        {
            var fairyInvestInfo = new FairyInvestInfo()
            {
                money = (int)package.InvestGold,
                gear = investModel.GetInvestGear(package.InvestType, (int)package.InvestGold),
            };
            fairyInvestInfos[package.InvestType] = fairyInvestInfo;
 
            if (!fairyInvestSingleInfos.ContainsKey(package.InvestType))//奖励刷新赋值
            {
                fairyInvestSingleInfos.Add(package.InvestType, new Dictionary<int, int>());
            }
            var Dit = fairyInvestSingleInfos[package.InvestType];
            for (int i = 0; i < package.RewardRecordCnt; i++)
            {
                Dit[(int)package.InvestRewardList[i].RewardIndex] = (int)package.InvestRewardList[i].RewardValue;
            }
 
            UpdateRedpoint();
            if (fairyInvestUpdate != null)
            {
                fairyInvestUpdate();
            }
        }
    }
 
    public void SendGotInvestReward(int type, int index)//领取奖励
    {
        var pak = new CA541_tagCMGetInvestReward();
        pak.InvestType = (byte)type;
        pak.RewardIndex = (byte)index;
        GameNetSystem.Instance.SendInfo(pak);
    }
 
    public void SendFairyInvest(int type, int money)//仙玉投资
    {
        var pak = new CA540_tagCMGoldInvest();
        pak.InvestType = (byte)type;
        pak.InvestGold = (uint)money;
        GameNetSystem.Instance.SendInfo(pak);
    }
 
    private void UpdateRedpoint()//红点
    {
        prioritySelectIndex = 0;
 
        var redpointAble = false;
 
        int playerLevel = PlayerDatas.Instance.baseData.LV;
 
        if (fairyInvestLevelLimits.ContainsKey(fairyInvestType) && fairyInvestItems.ContainsKey(fairyInvestType))
        {
 
            int investGear = fairyInvestInfos.ContainsKey(fairyInvestType) ? fairyInvestInfos[fairyInvestType].gear : 0;
 
            var investItems = fairyInvestItems[fairyInvestType];
 
            var index = 0;
            foreach (var investItem in investItems.Values)
            {
                if (playerLevel >= investItem.levelLimit)
                {
                    if (investGear != 0)
                    {
                        var gear = fairyInvestSingleInfos[fairyInvestType][investItem.id];
                        if (gear == 0)
                        {
                            redpointAble = true;
                            prioritySelectIndex = index;
                            break;
                        }
                        else
                        {
                            var currentItems = investItem.items.ContainsKey(investGear) ? investItem.items[investGear] : null;
                            var items = investItem.items.ContainsKey(gear) ? investItem.items[gear] : null;
                            if (currentItems[0].count > items[0].count)
                            {
                                redpointAble = true;
                                prioritySelectIndex = index;
                                break;
                            }
                        }
                    }
                }
                index++;
            }
 
            index = 0;
            if (!redpointAble && investGear != 0)
            {
                foreach (var investItem in investItems.Values)
                {
                    if (investItem.levelLimit > playerLevel)
                    {
                        prioritySelectIndex = index;
                        return;
                    }
                    index++;
                }
            }
        }
 
        redpoint.state = redpointAble ? RedPointState.GetReward : RedPointState.None;
 
 
    }
    private void RedPointSate()//月卡投资创角前三天红点
    {
        int InvestGold = GetInvestGold();
        if (InvestGold > 0)
        {
            return;
        }
        if (IsRedpoint)
        {
            if (IsFuncOpen())
            {
                redpoint.state = RedPointState.Simple;
            }
 
        }
        else
        {
            UpdateRedpoint();
        }
    }
 
    private void IsShowRedPointSimple()
    {
        int GetDayOfYear = DateTime.Now.DayOfYear;
        string strKey = "IsOpenFiaryJadeRedPoint" + PlayerDatas.Instance.baseData.PlayerID;
        int day = LocalSave.GetInt(strKey);
        if (day != GetDayOfYear)
        {
            if (TimeUtility.CreateDays <= redpointDays && redpoint.state == RedPointState.None
                && PlayerDatas.Instance.baseData.LV >= redpointLevelLimit)
            {
                LocalSave.SetInt(strKey, GetDayOfYear);
                IsRedpoint = true;
                RedPointSate();
                return;
            }
 
        }
        if (!IsFuncOpen())//功能关闭
        {
            redpoint.state = RedPointState.None;
            return;
        }
    }
 
    public void MessageNotification()
    {
        var _funcOrder = 0;
        var gear = GetFairyInvestGear();
        if (!OpenServerActivityCenter.Instance.IsAnyActivityOpen(out _funcOrder))
        {
            SysNotifyMgr.Instance.ShowTip("JadeInvestmentLimit1");//信息提示
            return;
        }
        else if (gear <= 0 && PlayerDatas.Instance.baseData.LV >= fairyInvestLevelLimits.Values.Last())
        {
            SysNotifyMgr.Instance.ShowTip("JadeInvestmentLimit2");//信息提示
            return;
        }
        else
        {
            bool isOpen = false;
            if (gear == 4)
            {
                var dit = GetInfoSeriors();
                foreach (int key in dit.Keys)
                {
                    if (dit[key] != 4)
                    {
                        isOpen = true;
                    }
                }
            }
            if (!isOpen && PlayerDatas.Instance.baseData.LV >= 300)
            {
                SysNotifyMgr.Instance.ShowTip("JadeInvestmentLimit3");//信息提示
                return;
            }
        }
    }
 
    public int GetFairyInvestType()//获取投资类型
    {
        int playerLevel = PlayerDatas.Instance.baseData.LV;
 
        var selectType = fairyInvestLevelLimits.Keys.First();
 
        foreach (var type in fairyInvestInfos.Keys)
        {
            if (fairyInvestInfos[type].money == 0)
            {
                continue;
            }
 
            var existUnGotReward = false;
 
            var investGear = fairyInvestInfos[type].gear;
 
            if (fairyInvestSingleInfos.ContainsKey(type))
            {
                var singleInfos = fairyInvestSingleInfos[type];
                var investItems = fairyInvestItems[type];
                foreach (var investItem in investItems.Values)
                {
                    if (playerLevel >= investItem.levelLimit)
                    {
                        var gotGear = singleInfos[investItem.id];
                        if (gotGear == 0)
                        {
                            existUnGotReward = true;
                        }
                        else
                        {
                            List<Item> currentItems = investItem.items.ContainsKey(investGear) ? investItem.items[investGear] : null;
                            List<Item> items = investItem.items.ContainsKey(gotGear) ? investItem.items[gotGear] : null;
                            if (currentItems[0].count > items[0].count)
                            {
                                existUnGotReward = true;
                            }
                        }
                    }
                }
 
                if (existUnGotReward || playerLevel <= fairyInvestLevelLimits[type])
                {
                    selectType = type;
                    break;
                }
            }
        }
 
        return selectType;
    }
 
    public int GetFairyInvestGear()//获取投资档位
    {
        if (fairyInvestInfos.ContainsKey(fairyInvestType))
        {
            return fairyInvestInfos[fairyInvestType].gear;
        }
        return 0;
    }
 
    public int GetInvestGold()//获取投资金额
    {
        int InvestGold = 0;
        int type = fairyInvestType;
        if (fairyInvestInfos.ContainsKey(type))
        {
            InvestGold = fairyInvestInfos[type].money;
        }
        return InvestGold;
    }
    public Dictionary<int, int> GetInfoSeriors()
    {
        Dictionary<int, int> dit = new Dictionary<int, int>();
        int type = fairyInvestType;
        if (fairyInvestSingleInfos.ContainsKey(type))
        {
            dit = fairyInvestSingleInfos[type];
        }
        return dit;
    }
}