少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace vnxbqy.UI
{
    public class OperationFlashRushToBuy : OperationBase
    {
        public List<FlashSaleShop> flashShops = new List<FlashSaleShop>();
 
        public bool TryGetFlashShop(int dayIndex,int timeIndex ,out FlashSaleShop flashSaleShop)
        {
           flashSaleShop = null;
           for (int i = 0; i < flashShops.Count; i++)
            {
                var shop = flashShops[i];
                if (shop.dayIndex == dayIndex
                    && shop.timeIndex == timeIndex)
                {
                    flashSaleShop = shop;
                    return true;
                }
            }
            return false;
        }
 
        public bool TryGetFlashItem(int shopGuid,out FlashSaleShop flashSaleShop, out FlashSaleItem saleItem)
        {
            saleItem = null;
            flashSaleShop = null;
            for (int i = 0; i < flashShops.Count; i++)
            {
                var saleItems = flashShops[i].items;
                for (int j = 0; j < saleItems.Length; j++)
                {
                    if (saleItems[j].shopGuid == shopGuid)
                    {
                        flashSaleShop = flashShops[i];
                        saleItem = saleItems[j];
                        return true;
                    }
                }
            }
          
            return false;
        }
 
        /// <summary>
        ///-1 未开始 0 开始 1结束
        /// </summary>
        /// <param name="time"></param>
        /// <param name="dayIndex"></param>
        /// <param name="timeIndex"></param>
        /// <returns></returns>
        public int GetBuyTimeState(DateTime time,int dayIndex,int timeIndex,out int seconds)
        {
            seconds = 0;
            var operationDate = startDate.AddDays(dayIndex);
            OperationTime operationTime = times[timeIndex];
            var startTime = new DateTime(operationDate.year, operationDate.month, operationDate.day, operationTime.startHour, operationTime.startMinute,0);
            var endTime = new DateTime(operationDate.year, operationDate.month, operationDate.day, operationTime.endHour, operationTime.endMinute, 0);
            int advanceSec = Mathf.CeilToInt((float)(startTime - time).TotalSeconds);
            int endSec = Mathf.CeilToInt((float)(endTime - time).TotalSeconds);
            if (advanceSec > 0)
            {
                seconds = advanceSec;
                return -1;
            }
            else if(endSec <= 0)
            {
                return 1;
            }
            else
            {
                seconds = endSec;
                return 0;
            }
        }
 
        public string ToDisplayBuyTime(int month,int day,int startHour,int startMinute)
        {
            return StringUtility.Contact(startHour.ToString("D2"), ":", startMinute.ToString("D2"), " ", day, "/", month);
        }
 
        public string ToDisplayBuyTime(int startHour, int startMinute)
        {
            return StringUtility.Contact(startHour.ToString("D2"), ":", startMinute.ToString("D2"));
        }
 
        public override bool SatisfyOpenCondition()
        {
            if(PlayerDatas.Instance.baseData.LV >= limitLv)
            {
                if(flashShops.Count > 0)
                {
                    int openSeconds = 0;
                    int endSeconds = 0;
                    var fristShop = flashShops[0];
                    var lastShop = flashShops[flashShops.Count - 1];
                    int OpenState = GetBuyTimeState(TimeUtility.ServerNow,fristShop.dayIndex,fristShop.timeIndex, out openSeconds);
                    int endState = GetBuyTimeState(TimeUtility.ServerNow,lastShop.dayIndex, lastShop.timeIndex,out endSeconds);
                    if(OpenState == -1 && openSeconds <= inAdvanceMinute*60)
                    {
                        return true;
                    }
                    else if(endState != 1 && OpenState != -1)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
 
        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 void ParsePackage(HAA17_tagMCFlashSaleInfo package)
        {
            for (int i = 0; i < package.ShopCount; i++)
            {
                var gift = new FlashSaleShop();
                var shop = package.ShopInfo[i];
                gift.dayIndex = shop.DayIndex;
                gift.timeIndex = shop.TimeIndex;
                gift.items = new FlashSaleItem[shop.GiftbagCount];
                gift.ActNum = package.ActNum;
                for (int k = 0; k < shop.GiftbagCount; k++)
                {
                    var item = new FlashSaleItem();
                    var saleItem = shop.GiftbagInfo[k];
                    item.shopId = (int)saleItem.GiftID;
                    item.shopGuid = shop.DayIndex*10000 + shop.TimeIndex*100 + k;
                    item.limitNum = saleItem.BuyCountLimit;
                    item.fullServerLimitNum = saleItem.ServerBuyCountLimit;
                    item.moneyType = saleItem.MoneyType;
                    item.moneyNumber = (int)saleItem.MoneyNumber;
                    item.moneyOriginal = (int)saleItem.MoneyOriginal;
                    item.itemId = (int)saleItem.ItemID;
                    item.itemCount = saleItem.ItemCount;
                    item.isBind = saleItem.IsBind;
                    item.isAppointment = 0;
                    gift.items[k] = item;
                }
                flashShops.Add(gift);
            }
        }
 
     
        public class FlashSaleShop
        {
            public int dayIndex; // 活动第几天
            public int timeIndex;//第几个时间段
            public FlashSaleItem[] items;
            public int ActNum;
        }
 
        public class FlashSaleItem
        {
            public int shopId;
            public int shopGuid;
            public int limitNum;//个人限购数量
            public int fullServerLimitNum; //全服限购数量
            public int moneyType;
            public int moneyNumber;
            public int moneyOriginal;
            public int itemId;
            public int itemCount;
            public int isBind;
            public int isAppointment; //是否预约
        }
    }
}