少年修仙传客户端代码仓库
client_linchunjie
2018-08-30 eed4e4b6c64f7286b608b971764b337f9ef545d0
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
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 DateTime overDueTime = DateTime.Now;
        public bool allOverdue { get; private set; }
        public void UpdateTime(HAA16_tagMCSuperGiftInfo package)
        {
            timeOverdueGiftId = (int)package.GiftID;
            var _time = new DateTime(TimeUtility.Year, TimeUtility.Month, TimeUtility.Day, 0, 0, 0);
            overDueTime = _time.AddDays(package.RemainDay);
            allOverdue = package.RemainDay == 0;
            bool _activate = CheckActivate();
            if (activate != _activate)
            {
                activate = _activate;
                if (onStateUpate != null)
                {
                    onStateUpate(6);
                }
            }
            if (timeLimitUpdate != null)
            {
                timeLimitUpdate();
            }
            UpdateRedpoint();
        }
 
        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;
            }
            if (allOverdue)
            {
                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 (allOverdue || _id < timeOverdueGiftId)
            {
                return true;
            }
            if (_id == timeOverdueGiftId)
            {
                return TimeUtility.ServerNow >= overDueTime;
            }
            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()
        {
            allOverdue = false;
            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);
    }
}