少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-16 fc714208ff3a320c3bb52bddd5ea3d91f647a206
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
namespace Snxxz.UI
{
    [XLua.LuaCallCSharp]
    public class OSGiftModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize, IOpenServerActivity
    {
        VipModel vipModel
        {
            get { return ModelCenter.Instance.GetModel<VipModel>(); }
        }
 
        public override void Init()
        {
            ParseConfig();
            vipModel.rechargeCountEvent += RechargeCountEvent;
            OpenServerActivityCenter.Instance.Register(6, this);
        }
 
        public override void UnInit()
        {
 
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            startSeconds = 0;
        }
 
        public void OnPlayerLoginOk()
        {
            if (onStateUpate != null)
            {
                onStateUpate(6);
            }
            UpdateRedpoint();
        }
 
        public event Action<int> onStateUpate;
        public event Action onSelectUpdate;
 
        public bool IsOpen
        {
            get
            {
                return IsExist();
            }
        }
 
        public bool priorityOpen
        {
            get
            {
                for (int i = 0; i < redpoints.Count; i++)
                {
                    if (redpoints[i].state == RedPointState.Simple)
                    {
                        return true;
                    }
                }
                return false;
            }
        }
 
        public bool IsAdvance
        {
            get
            {
                return false;
            }
        }
 
        int m_SelectIndex = 0;
        public int selectIndex
        {
            get { return m_SelectIndex; }
            set
            {
                if (value != m_SelectIndex)
                {
                    m_SelectIndex = value;
                    if (onSelectUpdate != null)
                    {
                        onSelectUpdate();
                    }
                }
                m_SelectIndex = value;
            }
        }
 
        public int jumpGiftId { get; set; }
 
        public List<SuperValueGift> gifts { get; private set; }
        public List<int> alreadyOpens { get; private set; }
        void ParseConfig()
        {
            gifts = new List<SuperValueGift>();
            alreadyOpens = new List<int>();
            var config = FuncConfigConfig.Get("SuperGiftTimeList");
            var array = LitJson.JsonMapper.ToObject<int[][]>(config.Numerical1);
            for (int i = 0; i < array.Length; i++)
            {
                gifts.Add(new SuperValueGift()
                {
                    payType = array[i][0],
                    openDays = array[i][1],
                });
            }
 
            for (int i = 0; i < gifts.Count; i++)
            {
                redpoints.Add(new Redpoint(MainRedDot.REDPOINT_OPENSERVER, 20906 * 100 + i));
            }
        }
 
        private void RechargeCountEvent(int id)
        {
            UpdateRedpoint();
        }
 
        public uint startSeconds { get; private set; }
        public void UpdateTime(HAA16_tagMCSuperGiftInfo package)
        {
            startSeconds = package.StartTime;
            if (onStateUpate != null)
            {
                onStateUpate(6);
            }
            UpdateRedpoint();
        }
 
        public bool IsExist()
        {
            for (int i = 0; i < gifts.Count; i++)
            {
                if (!IsGiftExist(gifts[i].payType))
                {
                    continue;
                }
                return true;
            }
            return false;
        }
 
        public bool IsGiftExist(int payType)
        {
            if (startSeconds == 0)
            {
                return false;
            }
            if (IsGiftBuy(payType))
            {
                return false;
            }
            var gift = gifts.Find((x) =>
            {
                return x.payType == payType;
            });
            if (!gift.Equals(default(SuperValueGift)))
            {
                var startTime = TimeUtility.GetTime(startSeconds);
                var endTime = startTime.AddDays(gift.openDays);
                endTime = new DateTime(endTime.Year, endTime.Month, endTime.Day, 0, 0, 0);
                return TimeUtility.ServerNow < endTime;
            }
            return true;
        }
 
        public bool IsGiftBuy(int payType)
        {
            var rechargeId = GetRechargeId(payType);
            if (rechargeId != 0)
            {
                VipModel.RechargeCount rechargeCount;
                if (vipModel.TryGetRechargeCount(rechargeId, out rechargeCount))
                {
                    return rechargeCount.totalCount >= 1;
                }
            }
            return false;
        }
 
        public int GetRechargeId(int payType)
        {
            var list = vipModel.GetCTGConfigs(VersionConfig.Get().appId);
            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    var config = CTGConfig.Get(list[i]);
                    if (config != null && config.PayType == payType)
                    {
                        return config.RecordID;
                    }
                }
            }
            return 0;
        }
 
        public void SetAreadyOpens()
        {
            alreadyOpens.Clear();
            for (int i = 0; i < gifts.Count; i++)
            {
                if (IsGiftExist(gifts[i].payType))
                {
                    alreadyOpens.Add(i);
                }
            }
        }
 
        public int GetDefaultSelect()
        {
            for (int i = 0; i < alreadyOpens.Count; i++)
            {
                if (gifts[i].payType == jumpGiftId)
                {
                    jumpGiftId = 0;
                    return alreadyOpens[i];
                }
            }
            jumpGiftId = 0;
            for (int i = 0; i < alreadyOpens.Count; i++)
            {
                if (redpoints[alreadyOpens[i]].state == RedPointState.Simple)
                {
                    return alreadyOpens[i];
                }
            }
            return alreadyOpens[0];
        }
 
        bool GetDayRemind(int index)
        {
            return LocalSave.GetInt(StringUtility.Contact("OSGift_", index, "_",
                PlayerDatas.Instance.baseData.PlayerID), 0) == TimeUtility.Day;
        }
 
        public void SetDayRemind(int index)
        {
            if (redpoints[index].state == RedPointState.Simple)
            {
                LocalSave.SetInt(StringUtility.Contact("OSGift_", index, "_",
                       PlayerDatas.Instance.baseData.PlayerID), TimeUtility.Day);
                UpdateRedpoint();
            }
        }
 
        List<Redpoint> redpoints = new List<Redpoint>();
 
        void UpdateRedpoint()
        {
            for (int i = 0; i < redpoints.Count; i++)
            {
                redpoints[i].state = RedPointState.None;
                if (IsGiftExist(gifts[i].payType) && !IsGiftBuy(gifts[i].payType)
                    && !GetDayRemind(i))
                {
                    redpoints[i].state = RedPointState.Simple;
                }
            }
        }
 
        public struct SuperValueGift
        {
            public int payType;
            public int openDays;
        }
    }
}