少年修仙传客户端代码仓库
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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
 
namespace vnxbqy.UI
{
    
    public class CrossServerOneVsOnePKSeason : Singleton<CrossServerOneVsOnePKSeason>
    {
        public int ZoneCount { get; private set; }    // 所有赛区个数
 
        public List<PkZoneInfo> ZoneIDList { get; private set; }    // 所有赛区列表
 
        public int ZoneID { get; private set; }    // 所属赛区ID
 
        public int SeasonID { get; private set; }   // 当前赛季ID
 
        public int SeasonState { get; private set; }    // 赛季状态;0-未开启,1-开启中,2-已结束
 
        public int MatchState { get; private set; }    // 匹配状态;0-未开启;1-开启中
 
        public string CrossZoneName { get; private set; }     // 跨服分区名
 
        public bool isSatisfyMatch
        {
            get
            {
                return FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.CrossServer)
                    && TimeUtility.OpenDay >= crossServerModel.afterOpenDayOpenCross
                    && InPkSeason(TimeUtility.ServerNow)
                    && InOpenTime();
            }
        }
 
        public class PkZoneInfo
        {
            public int ZoneID { get; private set; }        // 赛区ID
 
            public string ZoneName { get; private set; }         // 赛区名
 
            public int SeasonCount { get; private set; }
 
            public List<PkSeasonInfo> SeasonList { get; private set; }          // 赛季列表
 
            public void SetZoneInfo(HC004_tagGCCrossRealmPKSeasonInfo.tagGCCrossRealmPKZone pKZone)
            {
                this.ZoneID = pKZone.ZoneID;
                this.ZoneName = pKZone.ZoneName;
                this.SeasonCount = pKZone.SeasonCount;
                SeasonList = new List<PkSeasonInfo>();
                for (int i = 0; i < pKZone.SeasonCount; i++)
                {
                    var pkSeason = pKZone.SeasonList[i];
                    PkSeasonInfo seasonInfo = new PkSeasonInfo();
                    seasonInfo.SetPkSeasonInfo(pkSeason);
                    SeasonList.Add(seasonInfo);
                }
            }
        }
 
        public class PkSeasonInfo
        {
            public int SeasonID { get; private set; }      // 当前赛季ID
 
            public OperationDate StartDate { get; private set; }      // 开始日期 yyyy-MM-dd
 
            public OperationDate EndDate { get; private set; }       // 结束日期 yyyy-MM-dd
 
            public string EndTime { get; private set; }      // 赛季结算时间,赛季奖励该时间后才可领取 hh:mm
 
            public void SetPkSeasonInfo(HC004_tagGCCrossRealmPKSeasonInfo.tagGCCrossRealmPKSeason seasonInfo)
            {
                this.SeasonID = seasonInfo.SeasonID;
                this.StartDate = ParseOperationDate(seasonInfo.StartDate);
                this.EndDate = ParseOperationDate(seasonInfo.EndDate);
                this.EndTime = seasonInfo.EndTime;
            }
 
            private OperationDate ParseOperationDate(string date)
            {
                string[] dateArray = date.Split('-');
                if (dateArray != null && dateArray.Length == 3)
                {
                    return new OperationDate()
                    {
                        year = int.Parse(dateArray[0].Trim()),
                        month = int.Parse(dateArray[1].Trim()),
                        day = int.Parse(dateArray[2].Trim())
                    };
                }
                return default(OperationDate);
            }
        }
 
        public event Action activityStartEvent;
        public event Action activityEndEvent;
        public event Action updateSelfSeasonEvent;
        private bool inDateNotify = false;
        private bool stepDateNotify = false;
        DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
        CrossServerOneVsOneModel crossServerModel { get { return ModelCenter.Instance.GetModel<CrossServerOneVsOneModel>(); } }
 
        public CrossServerOneVsOnePKSeason()
        {
            GlobalTimeEvent.Instance.secondEvent += SecondEvent;
        }
 
        public void InitData()
        {
            ZoneCount = 0;
            ZoneIDList = null;
            ZoneID = 0;
            SeasonID = 0;
            SeasonState = 0;
            MatchState = 0;
            CrossZoneName = string.Empty;
        }
 
        private void SecondEvent()
        {
            if (!inDateNotify && InPkSeason(TimeUtility.ServerNow))
            {
                inDateNotify = true;
                stepDateNotify = false;
                if (activityStartEvent != null)
                {
                    activityStartEvent();
                }
            }
            else if (!stepDateNotify && !InPkSeason(TimeUtility.ServerNow))
            {
                inDateNotify = false;
                stepDateNotify = true;
                if (activityEndEvent != null)
                {
                    activityEndEvent();
                }
            }
        }
 
        public bool IsEnterCrossServer(bool isTip = false)
        {
            bool isFuncOpen = FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.CrossServer);
            bool isOpenDay = TimeUtility.OpenDay >= crossServerModel.afterOpenDayOpenCross;
            if (!isFuncOpen)
            {
                if (isTip)
                {
                    SysNotifyMgr.Instance.ShowTip("FuncLimit_Level");
                }
 
                return false;
            }
            if (!isOpenDay)
            {
                if (isTip)
                {
                    SysNotifyMgr.Instance.ShowTip("CrossMatching15", crossServerModel.afterOpenDayOpenCross);
                }
                return false;
            }
            return true;
        }
 
 
        public void UpdatePkSeason(HC004_tagGCCrossRealmPKSeasonInfo pkSeason)
        {
            inDateNotify = false;
            stepDateNotify = false;
            this.ZoneCount = pkSeason.ZoneCount;
            var zoneIDs = pkSeason.ZoneList;
            this.ZoneIDList = new List<PkZoneInfo>();
            for (int i = 0; i < pkSeason.ZoneCount; i++)
            {
                var pkZone = pkSeason.ZoneList[i];
                PkZoneInfo zoneInfo = new PkZoneInfo();
                zoneInfo.SetZoneInfo(pkZone);
                ZoneIDList.Add(zoneInfo);
            }
        }
 
        public void UpdateSelfSeason(HC006_tagGCCrossRealmPKSeasonState pKSeasonState)
        {
            this.ZoneID = pKSeasonState.ZoneID;
            this.SeasonID = pKSeasonState.SeasonID;
            this.SeasonState = pKSeasonState.SeasonState;
            this.MatchState = pKSeasonState.MatchState;
            this.CrossZoneName = pKSeasonState.CrossZoneName;
            if (this.SeasonState != 1 || this.MatchState != 1)
            {
                if (crossServerModel.IsMatching)
                {
                    crossServerModel.IsMatching = false;
                }
            }
 
            if (updateSelfSeasonEvent != null)
            {
                updateSelfSeasonEvent();
            }
        }
 
 
        public bool TryGetZoneInfo(out PkZoneInfo zoneInfo)
        {
            zoneInfo = null;
            if (ZoneIDList == null) return false;
 
            for (int i = 0; i < ZoneIDList.Count; i++)
            {
                var info = ZoneIDList[i];
                if (this.ZoneID == info.ZoneID)
                {
                    zoneInfo = info;
                    return true;
                }
            }
            return false;
        }
 
        public bool TryGetSeasonInfo(out PkSeasonInfo seasonInfo)
        {
            seasonInfo = null;
            PkZoneInfo zoneInfo = null;
            bool isZone = TryGetZoneInfo(out zoneInfo);
            if (!isZone) return false;
 
            for (int i = 0; i < zoneInfo.SeasonList.Count; i++)
            {
                var info = zoneInfo.SeasonList[i];
                if (this.SeasonID == info.SeasonID)
                {
                    seasonInfo = info;
                    return true;
                }
            }
            return false;
        }
 
        public bool TryGetNextSeasonInfo(out PkSeasonInfo seasonInfo)
        {
            seasonInfo = null;
            PkZoneInfo zoneInfo = null;
            bool isZone = TryGetZoneInfo(out zoneInfo);
            if (!isZone) return false;
 
            for (int i = 0; i < zoneInfo.SeasonList.Count; i++)
            {
                var info = zoneInfo.SeasonList[i];
                if (info.SeasonID > this.SeasonID)
                {
                    seasonInfo = info;
                    return true;
                }
            }
            return false;
        }
 
        public bool InPkSeason(DateTime time)
        {
            OperationDate date = new OperationDate()
            {
                year = time.Year,
                month = time.Month,
                day = time.Day,
            };
            PkSeasonInfo seasonInfo = null;
            bool isSeason = TryGetSeasonInfo(out seasonInfo);
            if (isSeason && SeasonState == 1)
            {
                return date >= seasonInfo.StartDate && date <= seasonInfo.EndDate;
            }
            return false;
        }
 
        public bool InOpenTime()
        {
            List<HourMinute> hourMinutes = GetActivityTimes();
            if (hourMinutes != null && MatchState == 1)
            {
                for (int i = 0; i < hourMinutes.Count; i++)
                {
                    if (hourMinutes[i].InOpenTime())
                    {
                        return true;
                    }
                }
            }
 
            return false;
        }
 
        public List<HourMinute> GetActivityTimes()
        {
            DailyQuestOpenTime _openTime = null;
            dailyQuestModel.TryGetOpenTime((int)DailyQuestType.CrossServerPk, out _openTime);
            var dayOfWeek = (int)TimeUtility.ServerNow.DayOfWeek;
            Dictionary<int, List<HourMinute>> keyValues = null;
            if (_openTime != null)
            {
                keyValues = _openTime.NormalOpenTimes;
                if (keyValues.ContainsKey(dayOfWeek))
                {
                    return keyValues[dayOfWeek];
                }
            }
            return null;
        }
 
        public int IndexOfDays(DateTime time)
        {
            if (!InPkSeason(time))
            {
                return -1;
            }
            PkSeasonInfo seasonInfo = null;
            bool isSeason = TryGetSeasonInfo(out seasonInfo);
            if (isSeason)
            {
                DateTime s = new DateTime(seasonInfo.StartDate.year, seasonInfo.StartDate.month, seasonInfo.StartDate.day);
                return (time - s).Days;
            }
            return 0;
        }
 
        public string ToDisplaySeasonTime()
        {
            PkSeasonInfo seasonInfo = null;
            bool isSeason = TryGetSeasonInfo(out seasonInfo);
            if (isSeason)
            {
                if (!seasonInfo.StartDate.Equals(default(OperationDate))
                    && InPkSeason(TimeUtility.ServerNow))
                {
                    return Language.Get("CrossServer106", ToDisplayTime(seasonInfo.StartDate, seasonInfo.EndDate));
                }
            }
 
            PkSeasonInfo nextSeasonInfo = null;
            bool isNextSeason = TryGetNextSeasonInfo(out nextSeasonInfo);
            if (isNextSeason && !nextSeasonInfo.StartDate.Equals(default(OperationDate)))
            {
                return Language.Get("CrossServer107", ToDisplayTime(nextSeasonInfo.StartDate, nextSeasonInfo.EndDate));
            }
            return Language.Get("CrossServer107", Language.Get("CrossServer108"));
        }
 
        private string ToDisplayTime(OperationDate start, OperationDate end)
        {
            if (start != end)
            {
                return StringUtility.Contact(start.ToDisplay(), "-", end.ToDisplay());
            }
            return start.ToDisplay();
        }
    }
}