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; //是否预约
|
}
|
}
|
}
|
|