少年修仙传客户端代码仓库
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using UnityEngine.UI;
using System.Linq;
using LitJson;
 
public class TTLBattlePassModel : ILModel<TTLBattlePassModel>
{
    public byte TTLBuyState;    //通天令是否已购买
    public byte TTLLV;    //通天令等级,从0开始
    public uint CurPoint;    //通天令当前等级经验积分点
    public byte AwardStateCount;    //等级领奖记录值数,每个值存31个记录   0-30, 31-61, ...
    public uint[] CommAwardStateList = new uint[] { 0 };    //常规奖励领奖记录,按等级二进制位存储是否领奖
    public uint[] XianAwardStateList = new uint[] { 0 };    //仙品奖励领奖记录,按等级二进制位存储是否领奖
    public DateTime endDay; //本轮结束日
 
    public int ttlScoreItemID = 720;    //通天令积分物品ID
    public event Action OnTTLInfoEvent;
    public event Action OnTaskState;
    public event Action SelectEvent;
 
    private int m_SelectType;
    public int selectType
    {
        get { return m_SelectType; }
        set
        {
            m_SelectType = value;
            SelectEvent?.Invoke();
        }
 
    }
    protected override void Init()
    {
        GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
        ParseConfig();
    }
 
    protected override void UnInit()
    {
        GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
    }
 
    public bool IsOpen()
    {
        if (!FuncOpen.Instance.IsFuncOpen(206))
            return false;
 
        //全部已领取后隐藏
        if (GetAwardState(ILTongTianLVConfig.GetKeys().Count - 1, true))
        {
            return false;
        }
 
        return true;
    }
 
    public int scoreMoneyType;  //购买积分
    public int scoreMoneyValue;
    public int ttlMoneyType;    //购买通天令
    public int ttlMoneyValue;
    public int ttlCTGID;    //通天令的CTGID, 由仙玉激活改成直购
    public int dayScoreLimit;   //日常的积分上限
    public int roundDay; //x天重置通天令
 
    void ParseConfig()
    {
        var config = FuncConfigConfig.Get("TongTianLing");
        var arr = config.Numerical1.Split('|');
        scoreMoneyType = int.Parse(arr[0]);
        scoreMoneyValue = int.Parse(arr[1]);
 
        var arr1 = JsonMapper.ToObject<int[]>(config.Numerical5);
        if (arr1.Length != 0) ttlCTGID = arr1[0];
        //arr = config.Numerical5.Split('|');
        //ttlMoneyType = int.Parse(arr[0]);
        //ttlMoneyValue = int.Parse(arr[1]);
 
        dayScoreLimit = int.Parse(config.Numerical3);
        roundDay = int.Parse(config.Numerical4);
        ParseTask();
    }
 
    Redpoint redpoint = new Redpoint(MainRedPoint.TTLRedPoint);
    Redpoint redpoint0 = new Redpoint(MainRedPoint.TTLRedPoint, MainRedPoint.TTLRedPoint * 10);
    Redpoint redpoint1 = new Redpoint(MainRedPoint.TTLRedPoint, MainRedPoint.TTLRedPoint * 10 + 1);
    Redpoint redpoint2 = new Redpoint(MainRedPoint.TTLRedPoint, MainRedPoint.TTLRedPoint * 10 + 2);
 
    public void UpdateRedpoint()
    {
        redpoint0.state = RedPointState.None;
        redpoint1.state = RedPointState.None;
        redpoint2.state = RedPointState.None;
        if (TTLBuyState == 1 && !GetAwardState(TTLLV, true))
        {
            redpoint0.state = RedPointState.Simple;
        }
        else if (!GetAwardState(TTLLV, false))
        {
            redpoint0.state = RedPointState.Simple;
        }
 
        if (dayScore < dayScoreLimit && normalTaskList.Count > 0 && IsTaskFinish(normalTaskList[0]) && !GetTaskState(normalTaskList[0]))
        {
            redpoint1.state = RedPointState.Simple;
        }
 
        if (hardTaskList.Count > 0 && IsTaskFinish(hardTaskList[0]) && !GetTaskState(hardTaskList[0]))
        {
            redpoint2.state = RedPointState.Simple;
        }
    }
 
    void OnBeforePlayerDataInitialize()
    {
        taskProcess.Clear();
        dayScore = 0;
    }
 
    public void UpdateTTLInfo(IL_HA356_tagMCTongTianLingInfo netPack)
    {
        TTLBuyState = netPack.TTLBuyState;
        TTLLV = netPack.TTLLV;
        CurPoint = netPack.CurPoint;
        CommAwardStateList = netPack.CommAwardStateList;
        XianAwardStateList = netPack.XianAwardStateList;
        var startDay = TimeUtility.GetTime(netPack.StartTime);
        endDay = TimeUtility.GetDayStartTime(startDay.Year, startDay.Month, startDay.Day).AddDays(roundDay);
        UpdateRedpoint();
        OnTTLInfoEvent?.Invoke();
    }
 
    //通天令奖励的领取情况
    public bool GetAwardState(int lv, bool ishard)
    {
        var listIndex = lv / 31;
        var bitIndex = lv % 31;
        if (listIndex >= XianAwardStateList.Length || listIndex >= CommAwardStateList.Length)
            return false;
        if (ishard)
        {
            return ((int)Math.Pow(2, bitIndex) & (int)XianAwardStateList[listIndex]) != 0;
        }
        return ((int)Math.Pow(2, bitIndex) & (int)CommAwardStateList[listIndex]) != 0;
    }
 
    //按难度分组,此处任务的处理逻辑为,相同类型的任务为一组只显示最新的一个
    //按类型和是否每日任务分字典(type*10 + daily):id
    Dictionary<int, List<int>> normalTask = new Dictionary<int, List<int>>();
    Dictionary<int, List<int>> hardTask = new Dictionary<int, List<int>>();
    List<int> allNormalTaskList = new List<int>(); //包含堆叠不显示的
    
    public Dictionary<int, int> taskProcess = new Dictionary<int, int>();
    public uint[] taskAwardState;
    public List<int> normalTaskList = new List<int>(); //用于显示
    public List<int> hardTaskList = new List<int>();
    public int dayScore = 0;
    public void ParseTask()
    {
        normalTask.Clear();
        hardTask.Clear();
        allNormalTaskList.Clear();
        var taskKeys = ILTongTianTaskConfig.GetKeys();
        for (int i = 0; i < taskKeys.Count; i++)
        {
            var config = ILTongTianTaskConfig.Get(taskKeys[i]);
            var key = config.TTTaskType * 10 + config.IsDailyTask;
            if (config.IsHard == 0)
            {
                if (!normalTask.ContainsKey(key))
                {
                    normalTask[key] = new List<int>();
                }
                normalTask[key].Add(config.TTTaskID);
            }
            else
            {
                if (!hardTask.ContainsKey(key))
                {
                    hardTask[key] = new List<int>();
                }
                hardTask[key].Add(config.TTTaskID);
            }
            allNormalTaskList.Add(config.TTTaskID);
        }
    }
 
    //1.筛选出一个正在进行的任务(未领取),或者全部已完成的最后一个
    //内层:进行中/可领取的 值从小到大,已领取的从大到小
    //外层:待领取的 进行中的 已领取的
    //任务排序
    void RefreshTask()
    {
        var keys = normalTask.Keys.ToList();
        for (int i = 0; i < keys.Count; i++)
        {
            normalTask[keys[i]].Sort(SortTask);
        }
 
        keys = hardTask.Keys.ToList();
        for (int i = 0; i < keys.Count; i++)
        {
            hardTask[keys[i]].Sort(SortTask);
        }
 
        normalTaskList.Clear();
        keys = normalTask.Keys.ToList();
        for (int i = 0; i < keys.Count; i++)
        {
            normalTaskList.Add(normalTask[keys[i]][0]);
        }
        normalTaskList.Sort(SortTaskEx);
 
        hardTaskList.Clear();
        keys = hardTask.Keys.ToList();
        for (int i = 0; i < keys.Count; i++)
        {
            hardTaskList.Add(hardTask[keys[i]][0]);
        }
        hardTaskList.Sort(SortTaskEx);
 
        UpdateRedpoint();
        OnTaskState?.Invoke();
    }
 
    //相同类型任务组内的分类 进行中/可领取的 值从小到大,已领取的从大到小
    int SortTask(int id1, int id2)
    {
        var config1 = ILTongTianTaskConfig.Get(id1);
        var config2 = ILTongTianTaskConfig.Get(id2);
 
        bool state1 = GetTaskState(id1);
        bool state2 = GetTaskState(id2);
 
        if (state1 != state2)
        {
            return state1.CompareTo(state2);
        }
        if (state1)
        {
            return config2.FinishNeedValue.CompareTo(config1.FinishNeedValue);
        }
 
        //可领取
        return config1.FinishNeedValue.CompareTo(config2.FinishNeedValue);
 
    }
 
    //不同类型的任务  待领取的 进行中的 已领取的
    int SortTaskEx(int id1, int id2)
    {
        bool state1 = GetTaskState(id1);
        bool state2 = GetTaskState(id2);
 
        if (state1 != state2)
        {
            return state1.CompareTo(state2);
        }
 
        if (!state1)
        {
            bool isFinish1 = IsTaskFinish(id1);
            bool isFinish2 = IsTaskFinish(id2);
            if (isFinish1 != isFinish2)
            {
                return isFinish2.CompareTo(isFinish1);
            }
        }
 
        return id1.CompareTo(id2);
    }
 
    //任务积分是否已领取
    public bool GetTaskState(int id)
    {
        var listIndex = id / 31;
        var bitIndex = id % 31;
 
        if (taskAwardState == null || listIndex >= taskAwardState.Length)
            return false;
 
        return ((int)Math.Pow(2, bitIndex) & (int)taskAwardState[listIndex]) != 0;
    }
 
    public int GetTaskProcess(int key)
    {
        if (taskProcess.ContainsKey(key))
        {
            return taskProcess[key];
        }
 
        return 0;
    }
 
    // 进度是否完成, 无关是否领取任务奖励
    public bool IsTaskFinish(int id)
    {
        var config = ILTongTianTaskConfig.Get(id);
        var key = config.TTTaskType * 10 + config.IsDailyTask;
        return GetTaskProcess(key) >= config.FinishNeedValue;
    }
 
    public void UpdateTaskProcess(IL_HA357_tagMCTongTianLingTaskValueInfo netPack)
    {
        for (int i = 0; i < netPack.TaskValueList.Length; i++)
        {
            var key = netPack.TaskValueList[i].TaskType * 10 + netPack.TaskValueList[i].IsDaily;
            taskProcess[key] = (int)netPack.TaskValueList[i].TaskValue;
        }
        RefreshTask();
    }
 
    public void UpdateTaskAwardState(IL_HA358_tagMCTongTianLingTaskAwardInfo netPack)
    {
        taskAwardState = netPack.TaskAwardStateList;
        CalcDayScore();
        RefreshTask();
    }
 
    //每日日常获得总积分
    void CalcDayScore()
    {
        dayScore = 0;
        for (int i = 0; i < allNormalTaskList.Count; i++)
        {
            var taskID = allNormalTaskList[i];
            var config = ILTongTianTaskConfig.Get(taskID);
            if (config.IsHard == 1)
                continue;
            if (GetTaskState(taskID))
            {
                dayScore += config.TaskPoint;
            }
        }
    }
 
    public List<ItemEx> buyItems = new List<ItemEx>();
 
    //未激活仙品的显示锁, 购买等级内的不显示锁
    public void GetItemsByBuyScore(int buylv)
    {
        buyItems.Clear();
        //先显示仙品
        for (int i = buylv; i > TTLLV; i--)
        {
            var config = ILTongTianLVConfig.Get(i);
            var xitems = JsonMapper.ToObject<int[][]>(config.XianAwardItemList);
            for (int j = 0; j < xitems.Length; j++)
            {
                buyItems.Add(new ItemEx()
                {
                    id = xitems[j][0],
                    count = xitems[j][1],
                    bind = TTLBuyState == 1 ? 0 : 1,  //用于显示锁
                });
            }
        }
 
        for (int i = buylv; i > TTLLV; i--)
        {
            var config = ILTongTianLVConfig.Get(i);
            var nitems = JsonMapper.ToObject<int[][]>(config.CommAwardItemList);
            for (int j = 0; j < nitems.Length; j++)
            {
                buyItems.Add(new ItemEx()
                {
                    id = nitems[j][0],
                    count = nitems[j][1],
                    bind = 0,  //用于显示锁
                });
            }
        }
 
    }
 
    //等级不足的显示锁
    public void GetItemsByBuyTTL()
    {
        buyItems.Clear();
        for (int i = ILTongTianLVConfig.GetKeys().Count - 1; i >= 0; i--)
        {
            var config = ILTongTianLVConfig.Get(i);
            var xitems = JsonMapper.ToObject<int[][]>(config.XianAwardItemList);
            for (int j = 0; j < xitems.Length; j++)
            {
                buyItems.Add(new ItemEx()
                {
                    id = xitems[j][0],
                    count = xitems[j][1],
                    bind = i > TTLLV ? 1:0,  //用于显示锁
                });
            }
        }
 
        for (int i = ILTongTianLVConfig.GetKeys().Count - 1; i > TTLLV; i--)
        {
            var config = ILTongTianLVConfig.Get(i);
            var nitems = JsonMapper.ToObject<int[][]>(config.CommAwardItemList);
            for (int j = 0; j < nitems.Length; j++)
            {
                buyItems.Add(new ItemEx()
                {
                    id = nitems[j][0],
                    count = nitems[j][1],
                    bind = i > TTLLV ? 1 : 0,  //用于显示锁
                });
            }
        }
    }
 
}