少年修仙传客户端代码仓库
client_linchunjie
2018-09-21 edfd535734a7adab6d0f24c863149ed63bcd37c8
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
using System;
using System.Collections;
using System.Collections.Generic;
using TableConfig;
using UnityEngine;
namespace Snxxz.UI
{
    public class OSGiftModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize, IOpenServerActivity
    {
        public override void Init()
        {
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent;
            storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
            vipModel.firstChargeRewardEvent += FirstChargeRewardEvent;
            OpenServerActivityCenter.Instance.Register(6, this);
        }
 
        public override void UnInit()
        {
 
        }
 
        public void OnPlayerLoginOk()
        {
            activate = CheckActivate();
            if (onStateUpate != null)
            {
                onStateUpate(6);
            }
            UpdateRedpoint();
        }
 
        public event Action<int> onStateUpate;
        public event Action timeLimitUpdate;
 
        public bool activate { get; private set; }
 
        StoreModel storeModel
        {
            get
            {
                return ModelCenter.Instance.GetModel<StoreModel>();
            }
        }
 
        VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
 
        public bool IsOpen
        {
            get
            {
                return CheckActivate();
            }
        }
 
        public bool priorityOpen
        {
            get
            {
                return OSGiftRedpoint.state == RedPointState.Simple;
            }
        }
 
        private void RefreshBuyShopLimitEvent()
        {
            bool _activate = CheckActivate();
            if (activate != _activate)
            {
                activate = _activate;
                if (onStateUpate != null)
                {
                    onStateUpate(6);
                }
                UpdateRedpoint();
            }
        }
 
        public int timeOverdueGiftId { get; private set; }
 
        public bool IsAdvance
        {
            get
            {
                return false;
            }
        }
 
        public DateTime overDueTime = DateTime.Now;
        public void UpdateTime(HAA16_tagMCSuperGiftInfo package)
        {
            timeOverdueGiftId = (int)package.GiftID;
            overDueTime = ParseOverdueTime(package.EndtDate);
            bool _activate = CheckActivate();
            if (activate != _activate)
            {
                activate = _activate;
                if (onStateUpate != null)
                {
                    onStateUpate(6);
                }
            }
            if (timeLimitUpdate != null)
            {
                timeLimitUpdate();
            }
            UpdateRedpoint();
        }
 
        DateTime ParseOverdueTime(string _date)
        {
            var array = _date.Split('-');
            var year = int.Parse(array[0]);
            var month = int.Parse(array[1]);
            var day = int.Parse(array[2]);
            var time = new DateTime(year, month, day, 0, 0, 0);
            return time.AddDays(1);
        }
 
        private void FirstChargeRewardEvent()
        {
            bool _activate = CheckActivate();
            if (activate != _activate)
            {
                activate = _activate;
                if (onStateUpate != null)
                {
                    onStateUpate(6);
                }
            }
            UpdateRedpoint();
        }
 
        public bool CheckActivate()
        {
            if (PlayerDatas.Instance.baseData.coinPointTotal == 0
                || !ModelCenter.Instance.GetModel<VipModel>().firstChargeRewardGet)
            {
                return false;
            }
            List<StoreConfig> _list = null;
            StoreConfig.TryGetStoreConfigs((int)StoreFunc.OSGift,out _list);
            for (int i = 0; i < _list.Count; i++)
            {
                if (IsGiftOverdue(_list[i].ID))
                {
                    continue;
                }
                var _limit = storeModel.GetBuyShopLimit((uint)_list[i].ID);
                if (_limit == null || _limit.BuyCnt < _list[i].PurchaseNumber[0])
                {
                    return true;
                }
            }
            return false;
        }
 
        public bool IsGiftOverdue(int _id)
        {
            if (_id == timeOverdueGiftId)
            {
                return TimeUtility.ServerNow >= overDueTime;
            }
            return true;
        }
 
        public bool IsGiftBuy(int _id)
        {
            var _limit = storeModel.GetBuyShopLimit((uint)_id);
            var config = Config.Instance.Get<StoreConfig>(_id);
            if (_limit != null && config != null
                && _limit.BuyCnt >= config.PurchaseNumber[0])
            {
                return true;
            }
            return false;
        }
 
        private void PlayerDataRefreshInfoEvent(PlayerDataRefresh _type)
        {
            bool _activate = CheckActivate();
            if (_type == PlayerDataRefresh.ChangeCoinPointTotal && activate != _activate)
            {
                activate = _activate;
                if (onStateUpate != null)
                {
                    onStateUpate(6);
                }
            }
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            timeOverdueGiftId = 0;
        }
 
        public void SetDayRemind()
        {
            if (OSGiftRedpoint.state == RedPointState.Simple)
            {
                DayRemind.Instance.SetDayRemind(DayRemind.OSGIFT_REDPOINT, true);
                UpdateRedpoint();
            }
        }
 
        void UpdateRedpoint()
        {
            OSGiftRedpoint.state = RedPointState.None;
            if (CheckActivate() && !DayRemind.Instance.GetDayRemind(DayRemind.OSGIFT_REDPOINT))
            {
                OSGiftRedpoint.state = RedPointState.Simple;
            }
        }
 
        public Redpoint OSGiftRedpoint = new Redpoint(MainRedDot.REDPOINT_OPENSERVER, 20906);
    }
}