少年修仙传客户端代码仓库
client_Wu Xijin
2018-09-04 d9e6e5aac14261fad5bd18053b600bd513b45509
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
using LitJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TableConfig;
 
namespace Snxxz.UI
{
    public class ActivitiesPushMgr : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
    {
        public const int WholePeopleRankStart = 2091000; //全民冲榜开始
        public const int WholePeopleRankEnd = 20910000; //全民冲榜截止
 
        ImpactRankModel impactRank { get { return ModelCenter.Instance.GetModel<ImpactRankModel>(); } }
        private List<int> rankTypelist = new List<int>();
 
        public override void Init()
        {
            List<OSCBillRankAwardConfig> configs = Config.Instance.GetAllValues<OSCBillRankAwardConfig>();
            for(int i = 0; i < configs.Count; i++)
            {
                if(!rankTypelist.Contains(configs[i].RangListType))
                {
                    rankTypelist.Add(configs[i].RangListType);
                }
            }
        }
 
        public void OnBeforePlayerDataInitialize()
        {
 
        }
 
        public void OnAfterPlayerDataInitialize()
        {
            
        }
 
        public void OnPlayerLoginOk()
        {
            SetRankStartPushInfo();
            SetRankEndPushInfo();
            GlobalTimeEvent.Instance.minuteEvent -= RefreshMinuteTime;
            GlobalTimeEvent.Instance.minuteEvent += RefreshMinuteTime;
            OpenServerActivityCenter.Instance.openServerActivityStateChange -= RefreshOpenServerState;
            OpenServerActivityCenter.Instance.openServerActivityStateChange += RefreshOpenServerState;
        }
 
        public override void UnInit()
        {
          
        }
 
 
        private void RefreshMinuteTime()
        {
            RemovePushByTime(PushInfoType.RankStart,11);
            RemovePushByTime(PushInfoType.RankEnd,23);
        }
 
        private void RefreshOpenServerState()
        {
            SetRankStartPushInfo();
            SetRankEndPushInfo();
            RemovePushByActiveClose(PushInfoType.RankStart);
            RemovePushByActiveClose(PushInfoType.RankEnd);
        }
 
        private void SetRankStartPushInfo()
        {
            for(int i = 0; i <rankTypelist.Count; i++)
            {
                int rankStartId = WholePeopleRankStart + rankTypelist[i];
                if (impactRank.IsActivityClose(rankTypelist[i]))
                {
                    RemovePushInfo(rankStartId);
                }
                else
                {
                    int day = impactRank.GetOpenDay(rankTypelist[i]);
                    int remainHour = 11 - TimeUtility.ServerNow.Hour;
                    int remainMinute = 0 - TimeUtility.ServerNow.Minute;
                    int remainSecond = day * 24 * 60 * 60 + remainHour * 60 * 60 + remainMinute * 60;
                    if (remainSecond > 0)
                    {
                        PlayerRankData.RankType rankType = impactRank.GetRankType(rankTypelist[i]);
                        string rankName = StringUtility.Contact("OSCBillRankTitle_", rankType);
                        SendPushInfo(GetPushJsonData(rankStartId, remainSecond, Language.Get("SetUpPrivate106"), Language.Get("SetUpPrivate107",Language.Get(rankName))));
                    }
                }
            }
        }
 
        private void SetRankEndPushInfo()
        {
            for(int i = 0; i < rankTypelist.Count; i++)
            {
                int rankEndId = WholePeopleRankEnd + rankTypelist[i];
                if (impactRank.IsActivityClose(rankTypelist[i]))
                {
                    RemovePushInfo(rankEndId);
                }
                else
                {
                    int day = impactRank.GetSurplusDay(rankTypelist[i]);
                    int remainHour = 23 - TimeUtility.ServerNow.Hour;
                    int remainMinute = 0 - TimeUtility.ServerNow.Minute;
                    int remainSecond = (day - 1) * 24 * 60 * 60 + remainHour * 60 * 60 + remainMinute * 60;
                    if (remainSecond > 0)
                    {
                        PlayerRankData.RankType rankType = impactRank.GetRankType(rankTypelist[i]);
                        string rankName = StringUtility.Contact("OSCBillRankTitle_", rankType);
                        SendPushInfo(GetPushJsonData(rankEndId, remainSecond, Language.Get("SetUpPrivate106"), Language.Get("SetUpPrivate108", Language.Get(rankName))));
                    }
                }
            }
        }
 
        private void RemovePushByActiveClose(PushInfoType type)
        {
            switch (type)
            {
                case PushInfoType.RankStart:
                    for (int i = 0; i < rankTypelist.Count; i++)
                    {
                        int rankStartId = WholePeopleRankStart + rankTypelist[i];
                        if (impactRank.IsActivityClose(rankTypelist[i]))
                        {
                            RemovePushInfo(rankStartId);
                        }
                    }
                    break;
                case PushInfoType.RankEnd:
                    for (int i = 0; i < rankTypelist.Count; i++)
                    {
                        int rankEndId = WholePeopleRankEnd + rankTypelist[i];
                        if (impactRank.IsActivityClose(rankTypelist[i]))
                        {
                            RemovePushInfo(rankEndId);
                        }
                    }
                    break;
            }
        }
 
        private void RemovePushByTime(PushInfoType type,int time)
        {
            int remainHour = time - TimeUtility.ServerNow.Hour;
            int remainMinute = 0 - TimeUtility.ServerNow.Minute;
            int remainSecond = remainHour * 60 * 60 + remainMinute * 60;
            switch (type)
            {
                case PushInfoType.RankStart:
                    for (int i = 0; i < rankTypelist.Count; i++)
                    {
                        int rankStartId = WholePeopleRankStart + rankTypelist[i];
                        if (!impactRank.IsActivityClose(rankTypelist[i]))
                        {
                            int day = impactRank.GetOpenDay(rankTypelist[i]);
                            if (day <= 0 && remainSecond <= 120)
                            {
                                RemovePushInfo(rankStartId);
                            }
                        }
                    }
                    break;
                case PushInfoType.RankEnd:
                    for (int i = 0; i < rankTypelist.Count; i++)
                    {
                        int rankEndId = WholePeopleRankEnd + rankTypelist[i];
                        if (!impactRank.IsActivityClose(rankTypelist[i]))
                        {
                            int day = impactRank.GetSurplusDay(rankTypelist[i]);
                            if (day <= 1 && remainSecond <= 120)
                            {
                                RemovePushInfo(rankEndId);
                            }
                        }
                    }
                    break;
            }
        }
 
        public void RemovePushInfo(int pushId)
        {
            SDKUtility.Instance.GeTui_RemoveLocalMessage(pushId.ToString());
        }
 
        public void SendPushInfo(JsonData data)
        {
            SDKUtility.Instance.GeTui_SendLocalMessage(data);
        }
 
        public JsonData GetPushJsonData(int pushId,int pushtime,string title,string content)
        {
            JsonData _params = new JsonData();
            _params["code"] = 2005;
            _params["id"] = pushId;// id 重要, 标示每个通知的更新或者移除
            _params["title"] = title;// 推送标题
            _params["subtitle"] = "";// 副标题
            _params["content"] = content;// 具体内容
            _params["badge"] = -1;// 角标
 
            // 以下为决定应该多久后弹出此通知
            System.TimeSpan ts = System.DateTime.UtcNow - new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
            long ret = System.Convert.ToInt64(ts.TotalSeconds) + pushtime;// 表示3秒后
            _params["fireTime"] = ret;
            return _params;
        }
 
        public enum PushInfoType
        {
            RankStart,
            RankEnd,
        }
    }
}