少年修仙传客户端代码仓库
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
using vnxbqy.UI;
using System.Collections.Generic;
using UnityEngine.UI;
using System.Linq;
using LitJson;
using System;
using System.Reflection;
 
 
public class DailySpecialsModel : ILModel<DailySpecialsModel>
{
    public uint PackBuyTime;    // 打包购买的时间戳,如果有该值,代表已经一次性打包购买了,可根据次时间戳算出当前是第几天
    public uint BuyStateToday;    // 今日礼包购买状态,按礼包索引二进制位计算代表是否已购买,仅非打包购买状态下有用
    public uint AwardState;    // 今日礼包领奖状态,按礼包索引二进制位计算代表是否已领取
    public int maxDay; //总共可以领取几天
    public int giftLvRestrict; //礼包等级限制
 
    public Dictionary<int, List<List<int>>> giftInfoDict = new Dictionary<int, List<List<int>>>();
    public Dictionary<int, List<int>> ctgIdDict = new Dictionary<int, List<int>>();
    public List<int> packRechargeIdList = new List<int>();
    public List<List<Item>> itemAllList = new List<List<Item>>();
    Redpoint redpoint = new Redpoint(MainRedPoint.RechargeGenerousGiftWinRedpoint, MainRedPoint.DailySpecialsRedpoint);
    Dictionary<int, Redpoint> childRedpointDict = new Dictionary<int, Redpoint>();
    VipModel vipModel { get { return ModelCenter.Instance.GetModelEx<VipModel>(); } }
    public event Action UpdateGiftStateEvent;
 
    protected override void Init()
    {
        GameEvent.beforePlayerDataInitializeEvent += OnbeforePlayerDataInitialize;
        FuncOpen.Instance.OnFuncStateChangeEvent += OnFunctionStateChange;
        var tempDict = JsonMapper.ToObject(FuncConfigConfig.Get("DailyPackBuyGift").Numerical1);
        var keyList = tempDict.Keys.ToList();
        for (int i = 0; i < keyList.Count; i++)
        {
            List<List<int>> giftInfoList = new List<List<int>>();
            for (int j = 0; j < tempDict[i].Count; j++)
            {
                List<int> giftInfo = JsonMapper.ToObject<List<int>>(tempDict[keyList[i]][j].ToJson());
                giftInfoList.Add(giftInfo);
            }
            giftInfoDict.Add(int.Parse(keyList[i]), giftInfoList);
        }
 
        tempDict = JsonMapper.ToObject(FuncConfigConfig.Get("DailyPackBuyGift").Numerical2);
        keyList = tempDict.Keys.ToList();
        for (int i = 0; i < keyList.Count; i++)
        {
            ctgIdDict[int.Parse(keyList[i])] = JsonMapper.ToObject<List<int>>(tempDict[keyList[i]].ToJson());
        }
 
        packRechargeIdList = JsonMapper.ToObject<List<int>>(FuncConfigConfig.Get("DailyPackBuyGift").Numerical3);
        maxDay = int.Parse(FuncConfigConfig.Get("DailyPackBuyGift").Numerical4);
 
        List<int> giftInfokeyList = giftInfoDict.Keys.ToList();
        for (int i = 0; i < giftInfoDict.Count; i++)
        {
            List<Item> itemList = new List<Item>();
            for (int j = 0; j < giftInfoDict[giftInfokeyList[i]].Count; j++)
            {
                Item item = new Item(giftInfoDict[giftInfokeyList[i]][j][0], giftInfoDict[giftInfokeyList[i]][j][1]);
                itemList.Add(item);
            }
            itemAllList.Add(itemList);
        }
        List<int> keyList2 = giftInfoDict.Keys.ToList();
        for (int i = 0; i < giftInfoDict.Count; i++)
        {
            childRedpointDict[keyList2[i]] = new Redpoint(MainRedPoint.DailySpecialsRedpoint, MainRedPoint.DailySpecialsRedpoint * 100 + i);
        }
 
    }
 
    protected override void UnInit()
    {
        GameEvent.beforePlayerDataInitializeEvent -= OnbeforePlayerDataInitialize;
        FuncOpen.Instance.OnFuncStateChangeEvent -= OnFunctionStateChange;
    }
 
    public void OnbeforePlayerDataInitialize()
    {
        PackBuyTime = 0;
        BuyStateToday = 0;
        AwardState = 0;
    }
 
 
    private void OnFunctionStateChange(int id)
    {
        if (id == 222)
        {
            UpdateRedpoint();
        }
    }
 
 
    public void UpdateGiftState(IL_HAA03_tagMCDailyPackBuyGiftInfo vNetData)
    {
        this.PackBuyTime = vNetData.PackBuyTime;
        this.BuyStateToday = vNetData.BuyStateToday;
        this.AwardState = vNetData.AwardState;
        UpdateGiftStateEvent?.Invoke();
        UpdateRedpoint();
 
    }
 
    // 在功能开启的时候判断是否每日特惠开启, 触发UpdateRedpoint
 
    //每日特惠
    //1. 功能是否开启
    //2. 免费是否已领取
    //3. 购买后是否可领取
    void UpdateRedpoint()
    {
        redpoint.state = RedPointState.None;
        if (!FuncOpen.Instance.IsFuncOpen(222))
            return;
 
        List<int> keyList = childRedpointDict.Keys.ToList();
 
        for (int i = 0; i < childRedpointDict.Count; i++)
        {
            childRedpointDict[keyList[i]].state = RedPointState.None;
            if (GetGiftState(i) == 2)
            {
                childRedpointDict[keyList[i]].state = RedPointState.Simple;
            }
        }
    }
 
    //获得按钮状态
    //0 未购买 1 已购买 2 可领取 3 已领取
    public int GetGiftState(int index)
    {
        if (index == 0)
        {
            return IsHavePack(index) ? 3 : 2;
        }
        else
        {
            if (IsBuyAllPack())
            {
                return IsHavePack(index) ? 3 : 2;
            }
            else
            {
                if (IsBuyPack(index))
                {
                    return IsHavePack(index) ? 3 : 2;
                }
                else
                {
                    return 0;
                }
            }
        }
    }
 
    //是否购买总包
    public bool IsBuyAllPack()
    {
 
        if (PackBuyTime == 0)
        {
            return false;
        }
        else
        {
            return (TimeUtility.ServerNow - TimeUtility.GetTime(PackBuyTime)).Days < maxDay;
        }
    }
 
    //是否购买分包
    public bool IsBuyPack(int index)
    {
        return ((int)Math.Pow(2, index) & BuyStateToday) != 0;
    }
 
    //分包是否已领取
    public bool IsHavePack(int index)
    {
        return ((int)Math.Pow(2, index) & AwardState) != 0;
    }
 
}