少年修仙传客户端代码仓库
client_Zxw
2018-09-19 ab3e936c7be0fdcc6c814cc0cb0e4c88a0f346eb
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Text.RegularExpressions;
using Snxxz.UI;
using TableConfig;
using LitJson;
 
public class DailyQuestData
{
    public int id { get; private set; }
    public Redpoint redpoint { get; private set; }
 
    public DailyQuestData(int _id)
    {
        this.id = _id;
    }
 
    public DailyQuestData(int _id, int _redpointId, int _parentRedpoint)
    {
        this.id = _id;
        this.redpoint = new Redpoint(_parentRedpoint, _redpointId);
    }
 
    public void UpdateRedpointState(RedPointState _redpointState)
    {
        if (this.redpoint != null)
        {
            this.redpoint.state = _redpointState;
        }
    }
 
}
 
public class DailyQuestActiveValueReward
{
    public int id { get; private set; }
 
    bool m_Got = false;
    public bool got {
        get { return this.m_Got; }
        set { this.m_Got = value; }
    }
 
    public DailyQuestActiveValueReward(int _id)
    {
        this.id = _id;
    }
}
 
public class DailyQuestOpenTime
{
    public int id;
    public bool always;
 
    //常规的活动时间,key是星期x
    Dictionary<int, List<HourMinute>> openTimes = new Dictionary<int, List<HourMinute>>();
    //开服前2周的活动时间,key1是开服日的星期,key2是开服第几天
    Dictionary<int, Dictionary<int, List<HourMinute>>> specialOpenTimes = new Dictionary<int, Dictionary<int, List<HourMinute>>>();
 
    public DailyQuestOpenTime(int _id)
    {
        this.id = _id;
    }
 
    public void ParseQuestNormalOpenTime(string timeString, int duration)
    {
        var matches = Regex.Matches(timeString, "\\\"[0-9]\\\":\\[[0-9|,|\\[|\\]]+");
        always = matches.Count == 0;
 
        for (int i = 0; i < matches.Count; i++)
        {
            var match = matches[i];
            var stringArray = match.Value.Split(':');
 
            var week = 0;
            var weekMatch = Regex.Match(stringArray[0], "[0-9]");
            int.TryParse(weekMatch.Value, out week);
 
            if (week == 0)
            {
                var subMatches = Regex.Matches(stringArray[1], "[0-9]{1,2},[0-9]{1,2}");
                var tempHourMinutes = new List<HourMinute>();
 
                for (int j = 0; j < subMatches.Count; j++)
                {
                    tempHourMinutes.Add(new HourMinute(subMatches[j].Value, duration));
                }
 
                tempHourMinutes.Sort((HourMinute a, HourMinute b) => { return HourMinute.Compare(a, b); });
 
                for (int j = 0; j < 7; j++)
                {
                    var hourMinutes = openTimes[j] = new List<HourMinute>(tempHourMinutes);
                }
            }
            else
            {
                var hourMinutes = openTimes[week % 7] = new List<HourMinute>();
                var subMatches = Regex.Matches(stringArray[1], "[0-9]{1,2},[0-9]{1,2}");
 
                for (int j = 0; j < subMatches.Count; j++)
                {
                    hourMinutes.Add(new HourMinute(subMatches[j].Value, duration));
                }
 
                hourMinutes.Sort((HourMinute a, HourMinute b) => { return HourMinute.Compare(a, b); });
            }
        }
    }
 
    public void ParseQuestSpecialOpenTimes(List<DailyQuestSpecialOpenTimeConfig> configs)
    {
        if (configs == null)
        {
            return;
        }
 
        foreach (var config in configs)
        {
            var openDayWeek = config.OpenServerWeek % 7;
            if (!specialOpenTimes.ContainsKey(openDayWeek))
            {
                specialOpenTimes[openDayWeek] = new Dictionary<int, List<HourMinute>>();
            }
 
            var dayIndexOpenTimes = specialOpenTimes[openDayWeek];
            var dayIndex = config.OpenServerDay;
            if (!dayIndexOpenTimes.ContainsKey(dayIndex))
            {
                dayIndexOpenTimes[dayIndex] = new List<HourMinute>();
            }
 
            var matches = Regex.Matches(config.TimeList, "\\[[0-9]{1,2},[0-9]{1,2}\\]");
            var hourMinutes = dayIndexOpenTimes[dayIndex];
 
            for (int i = 0; i < matches.Count; i++)
            {
                var temp = matches[i].Value;
                hourMinutes.Add(new HourMinute(temp, config.Duration));
            }
        }
    }
 
    public void ParseDungeonNormalOpenTimes(List<DungeonStateTimeConfig> configs)
    {
        always = configs == null || configs.Count == 0;
 
        if (!always)
        {
            for (int i = 0; i < configs.Count; i++)
            {
                var config = configs[i];
                if (config.StartWeekday == 0 && config.EndWeekday == 0)
                {
                    for (int j = 0; j < 7; j++)
                    {
                        if (!openTimes.ContainsKey(j))
                        {
                            openTimes[j] = new List<HourMinute>();
                        }
                        var hourMinutes = openTimes[j];
                        hourMinutes.Add(new HourMinute(config.StartHour, config.StartMinute, config.EndHour, config.EndMinute));
                    }
                }
                else
                {
                    var dayOfWeek = config.StartWeekday % 7;
                    if (!openTimes.ContainsKey(dayOfWeek))
                    {
                        openTimes[dayOfWeek] = new List<HourMinute>();
                    }
 
                    var hourMinutes = openTimes[dayOfWeek];
                    hourMinutes.Add(new HourMinute(config.StartHour, config.StartMinute, config.EndHour, config.EndMinute));
                }
            }
        }
    }
 
    public void ParseDungeonSpecialOpenTimes(List<DungeonSpecialStateTimeConfig> configs)
    {
        if (configs == null)
        {
            return;
        }
 
        foreach (var config in configs)
        {
            var openDayWeek = config.OpenServerWeek % 7;
            if (!specialOpenTimes.ContainsKey(openDayWeek))
            {
                specialOpenTimes[openDayWeek] = new Dictionary<int, List<HourMinute>>();
            }
 
            var dayIndexOpenTimes = specialOpenTimes[openDayWeek];
            var dayIndex = config.OpenServerDay;
            if (!dayIndexOpenTimes.ContainsKey(dayIndex))
            {
                dayIndexOpenTimes[dayIndex] = new List<HourMinute>();
            }
 
            var hourMinutes = dayIndexOpenTimes[dayIndex];
            hourMinutes.Add(new HourMinute(config.StartHour, config.StartMinute, config.EndHour, config.EndMinute));
        }
    }
 
 
    public bool IsValidServerOpenTime()
    {
        return true;
    }
 
    public bool InOpenTime()
    {
        if (always)
        {
            return true;
        }
 
        var isSpecialDay = TimeUtility.OpenWeekCnt <= 1;
        var openDayWeek = (int)TimeUtility.openServerTime.DayOfWeek;
        var dayIndex = TimeUtility.OpenDay + 1;
        if (isSpecialDay && specialOpenTimes.ContainsKey(openDayWeek) && specialOpenTimes[openDayWeek].ContainsKey(dayIndex))
        {
            if (specialOpenTimes.ContainsKey(openDayWeek) && specialOpenTimes[openDayWeek].ContainsKey(dayIndex))
            {
                var hourMinutes = specialOpenTimes[openDayWeek][dayIndex];
                for (int i = 0; i < hourMinutes.Count; i++)
                {
                    if (hourMinutes[i].InOpenTime())
                    {
                        return true;
                    }
                }
 
                return false;
            }
            else
            {
                return false;
            }
        }
        else
        {
            var dayOfWeek = (int)TimeUtility.ServerNow.DayOfWeek;
            if (!openTimes.ContainsKey(dayOfWeek))
            {
                return false;
            }
            else
            {
                var hourMinutes = openTimes[dayOfWeek];
                for (int i = 0; i < hourMinutes.Count; i++)
                {
                    if (hourMinutes[i].InOpenTime())
                    {
                        return true;
                    }
                }
 
                return false;
            }
        }
 
    }
 
    public bool TryGetTodayNearestOpenTime(out HourMinute _hourMinute)
    {
        var isSpecialDay = TimeUtility.OpenWeekCnt <= 1;
        var openDayWeek = (int)TimeUtility.openServerTime.DayOfWeek;
        var dayIndex = TimeUtility.OpenDay + 1;
        if (isSpecialDay)
        {
            if (specialOpenTimes.ContainsKey(openDayWeek) && specialOpenTimes[openDayWeek].ContainsKey(dayIndex))
            {
                var hour = TimeUtility.ServerNow.Hour;
                var minute = TimeUtility.ServerNow.Minute;
                var hourMinutes = specialOpenTimes[openDayWeek][dayIndex];
                _hourMinute = hourMinutes[hourMinutes.Count - 1];
                for (int i = 0; i < hourMinutes.Count; i++)
                {
                    var hourMinute = hourMinutes[i];
                    if (hour <= hourMinute.hourEnd && minute <= hourMinute.minuteEnd)
                    {
                        _hourMinute = hourMinute;
                        break;
                    }
                }
 
                return true;
            }
            else
            {
                _hourMinute = default(HourMinute);
                return false;
            }
        }
        else
        {
            var dayOfWeek = (int)TimeUtility.ServerNow.DayOfWeek;
            if (!openTimes.ContainsKey(dayOfWeek))
            {
                _hourMinute = default(HourMinute);
                return false;
            }
 
            var hour = TimeUtility.ServerNow.Hour;
            var minute = TimeUtility.ServerNow.Minute;
            var hourMinutes = openTimes[dayOfWeek];
            _hourMinute = hourMinutes[hourMinutes.Count - 1];
            for (int i = 0; i < hourMinutes.Count; i++)
            {
                var hourMinute = hourMinutes[i];
                if (hour <= hourMinute.hourEnd && minute <= hourMinute.minuteEnd)
                {
                    _hourMinute = hourMinute;
                    break;
                }
            }
 
            return true;
        }
 
    }
 
    public bool ContainTimeNode(int week, int timeNode)
    {
        var openDayWeek = (int)TimeUtility.openServerTime.DayOfWeek;
 
        List<HourMinute> hourMinutes = null;
        var dayDelta = (week == 0 ? 7 : week) - (openDayWeek == 0 ? 7 : openDayWeek);
        if (TimeUtility.OpenWeekCnt < 1 && dayDelta < 0)
        {
            openTimes.TryGetValue(week, out hourMinutes);
        }
        else
        {
            hourMinutes = GetHourMinuteByWeek(week);
        }
 
        if (hourMinutes != null)
        {
            foreach (var item in hourMinutes)
            {
                if (item.hourBegin * 60 + item.minuteBegin == timeNode)
                {
                    return true;
                }
            }
        }
 
        return false;
    }
 
    private bool ContainWeek(int week)
    {
        var openDayWeek = (int)TimeUtility.openServerTime.DayOfWeek;
        var todayWeek = (int)TimeUtility.ServerNow.DayOfWeek;
        var dayDelta = (week == 0 ? 7 : week) - (openDayWeek == 0 ? 7 : openDayWeek);
 
        if (TimeUtility.OpenWeekCnt < 1 && dayDelta < 0)
        {
            return openTimes.ContainsKey(week);
        }
        else
        {
            return GetHourMinuteByWeek(week) != null;
        }
    }
 
    public string ToOpenTimeString()
    {
        if (always || openTimes.Count >= 7)
        {
            return Language.Get("DailyQuest_NoTimeLimit");
        }
        else
        {
            var timeStringList = new List<string>();
            for (var i = 1; i <= 7; i++)
            {
                var week = i % 7;
                if (ContainWeek(week))
                {
                    switch (week)
                    {
                        case 0:
                            timeStringList.Add(Language.Get("Weekday7"));
                            break;
                        case 1:
                            timeStringList.Add(Language.Get("Weekday1"));
                            break;
                        case 2:
                            timeStringList.Add(Language.Get("Weekday2"));
                            break;
                        case 3:
                            timeStringList.Add(Language.Get("Weekday3"));
                            break;
                        case 4:
                            timeStringList.Add(Language.Get("Weekday4"));
                            break;
                        case 5:
                            timeStringList.Add(Language.Get("Weekday5"));
                            break;
                        case 6:
                            timeStringList.Add(Language.Get("Weekday6"));
                            break;
                    }
                }
            }
 
            return string.Join("、", timeStringList.ToArray());
        }
 
    }
 
    public List<HourMinute> GetHourMinuteByWeek(int week)
    {
        var isSpecificDay = TimeUtility.OpenWeekCnt <= 1;
        if (isSpecificDay)
        {
            var openDayWeek = (int)TimeUtility.openServerTime.DayOfWeek;
            var todayWeek = (int)TimeUtility.ServerNow.DayOfWeek;
            var dayDelta = ((week == 0 ? 7 : week) - (todayWeek == 0 ? 7 : todayWeek));
            var dayIndex = TimeUtility.OpenDay + 1 + dayDelta;
            if (specialOpenTimes.ContainsKey(openDayWeek) && specialOpenTimes[openDayWeek].ContainsKey(dayIndex))
            {
                return specialOpenTimes[openDayWeek][dayIndex];
            }
        }
        else if (openTimes.ContainsKey(week))
        {
            return openTimes[week];
        }
 
        return null;
    }
}
 
public struct HourMinute
{
    public int hourBegin;
    public int minuteBegin;
    public int hourEnd;
    public int minuteEnd;
    public bool wholeDay;
 
    public HourMinute(string _input, int _duration)
    {
        var matches = Regex.Matches(_input, "[0-9]{1,2}");
        if (matches.Count >= 2)
        {
            hourBegin = int.Parse(matches[0].Value);
            minuteBegin = int.Parse(matches[1].Value);
 
            hourEnd = hourBegin + _duration / 60;
            minuteEnd = minuteBegin + _duration % 60;
            if (minuteEnd >= 60)
            {
                minuteEnd = minuteEnd % 60;
                hourEnd += 1;
            }
 
            wholeDay = false;
        }
        else
        {
            hourBegin = 0;
            minuteBegin = 0;
            hourEnd = 0;
            minuteEnd = 0;
 
            wholeDay = true;
        }
    }
 
    public HourMinute(int _hourBegin, int _minuteBegin, int _hourEnd, int _minuteEnd)
    {
        hourBegin = _hourBegin;
        minuteBegin = _minuteBegin;
        hourEnd = _hourEnd;
        minuteEnd = _minuteEnd;
 
        wholeDay = hourBegin == 0 && minuteBegin == 0 && hourEnd == 0 && minuteEnd == 0;
    }
 
    public bool InOpenTime()
    {
        if (wholeDay)
        {
            return true;
        }
        else
        {
            var minutes = TimeUtility.ServerNow.Hour * 60 + TimeUtility.ServerNow.Minute;
            if ((hourBegin * 60 + minuteBegin) <= minutes && (hourEnd * 60 + minuteEnd) > minutes)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
 
    public override string ToString()
    {
        var minuteBeginStr = minuteBegin > 9 ? minuteBegin.ToString() : StringUtility.Contact("0", minuteBegin);
        var minuteEndStr = minuteEnd > 9 ? minuteEnd.ToString() : StringUtility.Contact("0", minuteEnd);
        return StringUtility.Contact(hourBegin, ":", minuteBeginStr, "--", hourEnd, ":", minuteEndStr);
    }
 
    public string ToOpenTime()
    {
        if (minuteBegin < 10)
        {
            return StringUtility.Contact(hourBegin, ":0", minuteBegin);
        }
        else
        {
            return StringUtility.Contact(hourBegin, ":", minuteBegin);
        }
    }
 
    public static int Compare(HourMinute _lhs, HourMinute _rhs)
    {
        return (_lhs.hourBegin * 60 + _lhs.minuteBegin) < (_rhs.hourBegin * 60 + _rhs.minuteBegin) ? -1 : 1;
    }
 
}