少年修仙传客户端代码仓库
client_linchunjie
2018-09-13 7e74b65bd0d3661c97cc26850d743a11c9631af7
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Snxxz.UI
{
    public class OperationFlashSale : OperationBase
    {
        public List<FlashSale> flashShops = new List<FlashSale>();
 
        public bool TryGetFlashSale(DateTime time, out FlashSale flashSale)
        {
            flashSale = default(FlashSale);
            var index = IndexOfFlashSale(time);
            index = Mathf.Min(index, flashShops.Count - 1);
            if (index >= 0)
            {
                flashSale = flashShops[index];
            }
            return index >= 0;
        }
 
        int IndexOfFlashSale(DateTime time)
        {
            if (allDay)
            {
                if (!dayReset)
                {
                    return 0;
                }
                var index = IndexOfDays(time);
                switch (resetType)
                {
                    case 0:
                        return index;
                    case 1:
                        if (time.Hour < DayResetHour)
                        {
                            return Mathf.Max(0, index - 1);
                        }
                        else
                        {
                            return index;
                        }
                    default:
                        return index;
                }
            }
            else
            {
                var index = 0;
                for (int i = 0; i < times.Count; i++)
                {
                    if (times[i].InTime(time))
                    {
                        index = i;
                        break;
                    }
                }
                return index;
            }
        }
 
        public override bool SatisfyOpenCondition()
        {
            return PlayerDatas.Instance.baseData.LV >= limitLv;
        }
 
        public override void Reset()
        {
            base.Reset();
            flashShops.Clear();
        }
 
        public override string ToDisplayTime()
        {
            var textBuilder = OperationTimeHepler.textBuilder;
            textBuilder.Length = 0;
            textBuilder.Append(startDate.ToDisplay());
            if (startDate != endDate)
            {
                textBuilder.Append("—");
                textBuilder.Append(endDate.ToDisplay());
            }
            return textBuilder.ToString();
        }
 
        public int GetSurplusTime()
        {
            var time = TimeUtility.ServerNow;
            if (!InTime(time))
            {
                return 0;
            }
            var seconds = 0;
            if (allDay)
            {
                if (!dayReset)
                {
                    return GetSurplusTime(time);
                }
                if (resetType == 0)
                {
                    DateTime endOperationTime = new DateTime(TimeUtility.Year, TimeUtility.Month,
                          TimeUtility.Day, 0, 0, 0);
                    endOperationTime = endOperationTime.AddDays(1);
                    seconds = (int)(endOperationTime - TimeUtility.ServerNow).TotalSeconds;
                }
                else if (resetType == 1)
                {
                    DateTime endOperationTime = new DateTime(TimeUtility.Year, TimeUtility.Month,
                          TimeUtility.Day, DayResetHour, 0, 0);
                    if (time.Hour >= DayResetHour)
                    {
                        endOperationTime = endOperationTime.AddDays(1);
                    }
                    seconds = (int)(endOperationTime - TimeUtility.ServerNow).TotalSeconds;
                }
            }
            else
            {
                for (int i = 0; i < times.Count; i++)
                {
                    if (times[i].InTime(time))
                    {
                        DateTime endOperationTime = new DateTime(TimeUtility.Year, TimeUtility.Month,
                                TimeUtility.Day, times[i].endHour, times[i].endMinute, 0);
                        seconds = (int)(endOperationTime - TimeUtility.ServerNow).TotalSeconds;
                        break;
                    }
                }
            }
            return seconds;
        }
 
        public void ParsePackage(HAA11_tagMCSpringSaleInfo package)
        {
            for (int i = 0; i < package.ShopCount; i++)
            {
                var flashShop = new FlashSale();
                var shop = package.ShopInfo[i];
                flashShop.gifts = new FlashSaleGift[shop.GiftbagCount];
                for (int k = 0; k < shop.GiftbagCount; k++)
                {
                    var gift = new FlashSaleGift();
                    var pakGift = shop.GiftbagInfo[k];
                    gift.id = (int)pakGift.GiftID;
                    gift.limitNum = pakGift.BuyCountLimit;
                    gift.moneyNumber = (int)pakGift.MoneyNumber;
                    gift.moneyType = pakGift.MoneyType;
                    gift.moneyOriginal = (int)pakGift.MoneyOriginal;
                    gift.items = new FlashSaleItem[pakGift.GiftItemCount];
                    for (int q = 0; q < pakGift.GiftItemCount; q++)
                    {
                        var item = new FlashSaleItem();
                        item.itemId = (int)pakGift.ItemInfo[q].ItemID;
                        item.isBind = pakGift.ItemInfo[q].IsBind;
                        item.itemCount = pakGift.ItemInfo[q].ItemCount;
                        item.isMainItem = pakGift.ItemInfo[q].IsMainItem == 1;
                        gift.items[q] = item;
                    }
                    flashShop.gifts[k] = gift;
                }
                flashShops.Add(flashShop);
            }
        }
 
        public struct FlashSale
        {
            public FlashSaleGift[] gifts;
        }
 
        public struct FlashSaleGift
        {
            public int id;
            public int limitNum;
            public int moneyType;
            public int moneyNumber;
            public int moneyOriginal;
            public FlashSaleItem[] items;
        }
 
        public struct FlashSaleItem
        {
            public int itemId;
            public int itemCount;
            public int isBind;
            public bool isMainItem;
        }
    }
}