少年修仙传客户端代码仓库
hch
2025-07-24 50e53441950268933694eeb5aad36147bbe1014d
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace vnxbqy.UI
{
    public class MonthWeekInvestModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        Dictionary<int, Dictionary<int, List<Item>>> m_InvestItems = new Dictionary<int, Dictionary<int, List<Item>>>();
        Dictionary<int, List<int>> m_InvestRechargeIds = new Dictionary<int, List<int>>();
        Dictionary<int, InvestInfo> m_InvestInfos = new Dictionary<int, InvestInfo>();
        //{投资类型:[领取天,当前天]} 天从1开始
        Dictionary<int, List<List<int>>> m_InvestSingleInfos = new Dictionary<int, List<List<int>>>();
        Dictionary<int, Redpoint> m_Redpoints = new Dictionary<int, Redpoint>();
        public List<int> investTypes { get; private 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 jumpType { get; set; }
 
        public bool IsOpen
        {
            get
            {
                return FuncOpen.Instance.IsFuncOpen(119);
            }
        }
 
        public bool IsAdvance { get { return false; } }
 
        public bool priorityOpen
        {
            get
            {
                return redpoint.state == RedPointState.Simple || redpoint.state == RedPointState.GetReward;
            }
        }
 
        public event Action<int> onStateUpdate;
        public event Action onSelectUpdate;
        public event Action onInvestUpdate;
 
        public readonly Redpoint redpoint = new Redpoint(201, 20103);
        public readonly Redpoint redpoint2 = new Redpoint(201, 20104);
        VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
 
        public override void Init()
        {
            //OpenServerActivityCenter.Instance.Register(22, this);
            FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
 
            ParseConfig();
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            m_InvestInfos.Clear();
            m_InvestSingleInfos.Clear();
        }
 
        public void OnPlayerLoginOk()
        {
            //foreach (var type in investTypes)
            //{
            //    DayRemind.Instance.SetDayRemind("MonthWeekInvest_" + type);
            //}
 
            UpdateRedpoint();
        }
 
        public override void UnInit()
        {
            FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
        }
 
        void ParseConfig()
        {
            var funcConfig = FuncConfigConfig.Get("InvestCost");
            var json = LitJson.JsonMapper.ToObject(funcConfig.Numerical3);
            foreach (var typeKey in json.Keys)
            {
                var type = int.Parse(typeKey);
                m_InvestRechargeIds[type] = new List<int>(LitJson.JsonMapper.ToObject<int[]>(json[typeKey].ToJson()));
                if (type == 8)
                    m_Redpoints.Add(type, new Redpoint(redpoint.id, redpoint.id * 100 + type));
                else if (type == 7)
                    m_Redpoints.Add(type, new Redpoint(redpoint2.id, redpoint2.id * 100 + type));
            }
            investTypes = m_InvestRechargeIds.Keys.ToList();
 
            investTypes.Sort((x, y) =>
            {
                return -x.CompareTo(y);
            });
 
            var configs = InvestConfig.GetValues();
            foreach (var config in configs)
            {
                if (!investTypes.Contains(config.type))
                {
                    continue;
                }
 
                Dictionary<int, List<Item>> dict;
                if (!m_InvestItems.TryGetValue(config.type, out dict))
                {
                    dict = new Dictionary<int, List<Item>>();
                    m_InvestItems.Add(config.type, dict);
                }
 
                List<Item> items;
                if (!dict.TryGetValue(config.id, out items))
                {
                    items = new List<Item>();
                    dict.Add(config.id, items);
                }
 
                var itemJson = LitJson.JsonMapper.ToObject(config.award);
                var itemArray = LitJson.JsonMapper.ToObject<int[][]>(itemJson["1"].ToJson());
                for (int i = 0; i < itemArray.Length; i++)
                {
                    items.Add(new Item()
                    {
                        id = itemArray[i][0],
                        count = itemArray[i][1],
                    });
                }
            }
        }
 
        public int GetOrderInfoId(int type)
        {
            var ids = m_InvestRechargeIds[type];
            for (int i = 0; i < ids.Count; i++)
            {
                OrderInfoConfig config;
                if (vipModel.TryGetOrderInfo(ids[i], out config))
                {
                    return config.id;
                }
            }
            return 0;
        }
 
        public int GetSelectType()
        {
            if (jumpType != 0 && investTypes.Contains(jumpType))
            {
                var type = jumpType;
                jumpType = 0;
                return type;
            }
            else
            {
                foreach (var type in m_Redpoints.Keys)
                {
                    if (m_Redpoints[type].state == RedPointState.GetReward)
                    {
                        return type;
                    }
                }
            }
            return investTypes[0];
        }
 
        public int GetInvestPassDays(int type)
        {
            return m_InvestInfos.ContainsKey(type) ? m_InvestInfos[type].days : 0;
        }
 
        public int GetTotalIncome(int type)
        {
            var income = 0;
            if (m_InvestItems.ContainsKey(type))
            {
                foreach (var items in m_InvestItems[type].Values)
                {
                    income += items[0].count;
                }
            }
            return income;
        }
 
        public int GetFirstIncome(int type)
        {
            if (m_InvestItems.ContainsKey(type))
            {
                var ctgID = (int)OrderInfoConfig.Get(GetOrderInfoId(type)).CTGID;
                var config = CTGConfig.Get(ctgID);
                if (config == null)
                {
                    return 0 ;
                }
                return config.GainGold;
            }
            return 0;
        }
 
        public int GetDailyIncome(int type)
        {
            var income = 0;
            if (m_InvestItems.ContainsKey(type))
            {
                var index = 0;
                foreach (var items in m_InvestItems[type].Values)
                {
                    if (index == 1)
                    {
                        income = items[0].count;
                        break;
                    }
                    index++;
                }
            }
            return income;
        }
 
        public int GetSingleInvestState(int type, int id)//0-未投资 1-未达成 2-可领取 3-已领取 4-已过期
        {
            if (IsInvested(type))
            {
                var day = GetInvestPassDays(type);
                if (m_InvestItems.ContainsKey(type)
                    && m_InvestItems[type].ContainsKey(id))
                {
                    if (IsRewardGot(type, id))
                    {
                        return 3;
                    }
                    var config = InvestConfig.Get(id);
                    return day < config.needDay ? 1 : 2;//day == config.needDay ? 2 : 4;
                }
            }
            return 0;
        }
 
        public float GetIncomeRate(int type, int day)
        {
            var orderInfoId = GetOrderInfoId(type);
            var orderInfoConfig = OrderInfoConfig.Get(orderInfoId);
            //var money = (int)orderInfoConfig.PayRMBNum * 100;
            var money = 300;
            if (type == 7)
            {
                money = 9800;
            }
            var income = 0;
            if (m_InvestItems.ContainsKey(type))
            {
                foreach (var id in m_InvestItems[type].Keys)
                {
                    var config = InvestConfig.Get(id);
                    if (day >= config.needDay)
                    {
                        income += m_InvestItems[type][id][0].count;
                    }
                }
            }
            return (float)income / money;
        }
 
        public bool TryGetItems(int type, int id, out List<Item> items)
        {
            items = null;
            if (m_InvestItems.ContainsKey(type))
            {
                return m_InvestItems[type].TryGetValue(id, out items);
            }
            return false;
        }
 
        public bool TryGetInvestItems(int type, out Dictionary<int, List<Item>> dict)
        {
            return m_InvestItems.TryGetValue(type, out dict);
        }
 
        public bool IsInvested(int type)
        {
            return m_InvestInfos.ContainsKey(type) && m_InvestInfos[type].money > 0;
        }
 
        public bool IsRewardGot(int type, int id)
        {
            if (m_InvestSingleInfos.ContainsKey(type))
            {
                var index = id % 100;
                //每个数按位存31个激活索引
                var listIndex = index / 31;
                var bitIndex = index % 31;
                return ((int)Math.Pow(2, bitIndex) & m_InvestSingleInfos[type][1][listIndex]) != 0;
            }
            return false;
        }
 
        private void OnFuncStateChangeEvent(int id)
        {
            if (id == 119)
            {
                if (onStateUpdate != null)
                {
                    onStateUpdate(22);
                }
                UpdateRedpoint();
            }
        }
 
        public void SendGetReward(int type, int id)
        {
            var pak = new CA541_tagCMGetInvestReward();
            pak.InvestType = (byte)type;
            pak.RewardIndex = (byte)(id % 100);
            GameNetSystem.Instance.SendInfo(pak);
        }
 
        public void SendInvest(int type)
        {
            var orderInfoId = GetOrderInfoId(type);
            var config = OrderInfoConfig.Get(orderInfoId);
            vipModel.CTG(config);
        }
 
        public void SetDayRemind(int type)
        {
            //DayRemind.Instance.SetDayRemind("MonthWeekInvest_" + type, true);
            //UpdateRedpoint();
        }
 
        public void OnReceivePackageEx(HA338_tagMCInvestInfo package)
        {
            if (!investTypes.Contains(package.InvestType))
            {
                return;
            }
 
            m_InvestInfos[package.InvestType] = new InvestInfo()
            {
                days = (int)package.CurDay,
                money = package.CurDay >= 1 ? 1 : 0,
            };
 
            List<List<int>> singleInfos;
            if (!m_InvestSingleInfos.TryGetValue(package.InvestType, out singleInfos))
            {
                singleInfos = new List<List<int>>();
                m_InvestSingleInfos.Add(package.InvestType, singleInfos);
            }
            singleInfos.Clear();
            singleInfos.Add(new List<int>());
            singleInfos.Add(new List<int>());
            singleInfos.Add(new List<int>());
            singleInfos[0].Add((int)package.CurDay);
            for (int i = 0; i < package.ValueCount; i++)
            {
                singleInfos[1].Add((int)package.RewardValue[i]);
                singleInfos[2].Add((int)package.ProgressValue[i]);
            }
            UpdateRedpoint();
 
            if (onInvestUpdate != null)
            {
                onInvestUpdate();
            }
        }
 
        void UpdateRedpoint()
        {
            List<int> redpointTypes = new List<int>();
            List<int> dayReminds = new List<int>();
            if (IsOpen)
            {
                foreach (var type in investTypes)
                {
                    if (!IsInvested(type))
                    {
                        //if (!DayRemind.Instance.GetDayRemind("MonthWeekInvest_" + type))
                        //{
                        //    dayReminds.Add(type);
                        //}
                        continue;
                    }
                    foreach (var id in m_InvestItems[type].Keys)
                    {
                        if (GetSingleInvestState(type, id) == 2)
                        {
                            redpointTypes.Add(type);
                            break;
                        }
                    }
                }
            }
            foreach (var type in m_Redpoints.Keys)
            {
                m_Redpoints[type].state = redpointTypes.Contains(type) ? RedPointState.GetReward : dayReminds.Contains(type) ? RedPointState.Simple : RedPointState.None;
            }
        }
 
        public struct InvestInfo
        {
            public int money;
            public int days;
        }
    }
}