From 526fca39ebb6193e1c5d3b5f55f2f5f1dbb902f7 Mon Sep 17 00:00:00 2001
From: Client_PangDeRong <593317293@qq.com>
Date: 星期二, 16 十月 2018 15:37:57 +0800
Subject: [PATCH] 4074 【前端】限时抢购开发
---
System/KnapSack/KnapsackTimeCDMgr.cs | 112 +++++++++++++++++++++++++++++++++++++
System/OpenServerActivity/FlashRushToBuyCoolDown.cs | 16 ----
System/OpenServerActivity/FlashRushToBuyModel.cs | 6 +
System/OpenServerActivity/FlashSaleItemCell.cs | 27 ++++++--
4 files changed, 138 insertions(+), 23 deletions(-)
diff --git a/System/KnapSack/KnapsackTimeCDMgr.cs b/System/KnapSack/KnapsackTimeCDMgr.cs
index 701f5e3..bf5f203 100644
--- a/System/KnapSack/KnapsackTimeCDMgr.cs
+++ b/System/KnapSack/KnapsackTimeCDMgr.cs
@@ -9,6 +9,7 @@
public class KnapsackTimeCDMgr : SingletonMonobehaviour<KnapsackTimeCDMgr>
{
private List<ItemCDCool> itemCDList = new List<ItemCDCool>();
+ private List<NormalCDCool> normalCDList = new List<NormalCDCool>();
public event Action<string> RefresCoolTimeAct;
public event Action<string> RefreshItemOverdueTimeAct;
public event Action<string> RefreshItemOverdueAct;
@@ -18,6 +19,12 @@
{
CheckItemCoolTime(TimeRefreshType.Frame);
var minute = DateTime.Now.Minute;
+ var second = DateTime.Now.Second;
+ if(second != secondBuf)
+ {
+ CheckNormalCoolTime(TimeRefreshType.Second);
+ secondBuf = second;
+ }
if (minute != minuteBuf)
{
CheckItemCoolTime(TimeRefreshType.Minute);
@@ -61,6 +68,33 @@
}
+ private void CheckNormalCoolTime(TimeRefreshType type)
+ {
+ for (int i = 0; i < normalCDList.Count; i++)
+ {
+ double remianCD = normalCDList[i].GetRemainTime();
+ switch (type)
+ {
+ case TimeRefreshType.Frame:
+ break;
+ case TimeRefreshType.Second:
+ if(normalCDList[i].func != null)
+ {
+ normalCDList[i].func(normalCDList[i].code,(int)remianCD);
+ }
+ break;
+ case TimeRefreshType.Minute:
+ break;
+ }
+
+ if (remianCD <= 0)
+ {
+ UnRegister(normalCDList[i].code);
+ }
+ }
+
+ }
+
public void Register(string guid,int itemId,double cdTime)
{
int index;
@@ -75,12 +109,35 @@
}
}
+ public void Register(int code,double cdTime,Action<int,int> func)
+ {
+ int index;
+ if (ContainsNormalCD(code, out index))
+ {
+ normalCDList[index].SetTime(cdTime);
+ }
+ else
+ {
+ NormalCDCool cool = new NormalCDCool(code,cdTime,func);
+ normalCDList.Add(cool);
+ }
+ }
+
public void UnRegister(string guid)
{
int index;
if (ContainsItemCD(guid, out index))
{
itemCDList.RemoveAt(index);
+ }
+ }
+
+ public void UnRegister(int code)
+ {
+ int index;
+ if (ContainsNormalCD(code, out index))
+ {
+ normalCDList.RemoveAt(index);
}
}
@@ -92,6 +149,16 @@
return itemCDList[index];
}
return null;
+ }
+
+ public int GetNormalCDTime(int code)
+ {
+ int index;
+ if (ContainsNormalCD(code, out index))
+ {
+ return (int)normalCDList[index].GetRemainTime();
+ }
+ return 0;
}
List<ItemCDCool> typeCoollist = new List<ItemCDCool>();
@@ -119,6 +186,20 @@
for (int i = 0; i < itemCDList.Count; i++)
{
if (itemCDList[i].guid == guid)
+ {
+ index = i;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private bool ContainsNormalCD(int code,out int index)
+ {
+ index = 0;
+ for (int i = 0; i < normalCDList.Count; i++)
+ {
+ if (normalCDList[i].code == code)
{
index = i;
return true;
@@ -166,4 +247,35 @@
}
}
+ public class NormalCDCool
+ {
+ public int code;
+ public double totalTime;
+ public DateTime startTime { get; private set; }
+ public Action<int,int> func;
+ public NormalCDCool(int code,double totalTime,Action<int,int> func)
+ {
+ this.code = code;
+ this.totalTime = totalTime;
+ this.startTime = DateTime.Now;
+ this.func = func;
+ }
+
+ public void SetTime(double totalTime)
+ {
+ this.totalTime = totalTime;
+ this.startTime = DateTime.Now;
+ }
+
+ public double GetRemainTime()
+ {
+ double remainTime = totalTime - (DateTime.Now - startTime).TotalSeconds;
+ if (remainTime <= 0)
+ {
+ remainTime = 0;
+ }
+ return remainTime;
+ }
+ }
+
}
diff --git a/System/OpenServerActivity/FlashRushToBuyCoolDown.cs b/System/OpenServerActivity/FlashRushToBuyCoolDown.cs
index 22ff8b1..bcea5e3 100644
--- a/System/OpenServerActivity/FlashRushToBuyCoolDown.cs
+++ b/System/OpenServerActivity/FlashRushToBuyCoolDown.cs
@@ -11,11 +11,6 @@
[SerializeField] Text timeText;
FlashRushToBuyModel rushToBuyModel { get { return ModelCenter.Instance.GetModel<FlashRushToBuyModel>(); } }
bool isReplace = false;
- bool isStartReplace = false;
- private void Awake()
- {
- GlobalTimeEvent.Instance.halfMinuteEvent += UpdateHalfMinute;
- }
private void OnEnable()
{
@@ -29,12 +24,6 @@
GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
}
- private void UpdateHalfMinute()
- {
- if (!isStartReplace) return;
-
- isReplace = !isReplace;
- }
private void SecondEvent()
{
@@ -49,7 +38,6 @@
OperationTime operationTime;
OperationFlashRushToBuy.FlashSaleShop saleShop;
FlashRushToBuyModel.FlashRushToBuySate flashState = rushToBuyModel.GetActivityState(out seconds,out operationTime,out saleShop);
- isStartReplace = false;
switch (flashState)
{
case FlashRushToBuyModel.FlashRushToBuySate.NoOpen:
@@ -57,8 +45,8 @@
case FlashRushToBuyModel.FlashRushToBuySate.InAdvance:
if(seconds <= 3600)
{
- isStartReplace = true;
- if(!isReplace)
+ int split = (3600 - seconds)/30 % 2;
+ if(split == 0)
{
timeText.text = Language.Get("FlashRushToBuy106", TimeUtility.SecondsToHMS(seconds));
}
diff --git a/System/OpenServerActivity/FlashRushToBuyModel.cs b/System/OpenServerActivity/FlashRushToBuyModel.cs
index 940ec36..0f2bad3 100644
--- a/System/OpenServerActivity/FlashRushToBuyModel.cs
+++ b/System/OpenServerActivity/FlashRushToBuyModel.cs
@@ -158,10 +158,14 @@
}
}
}
-
+
for (int i = 0; i < appointmentInfo.GoodsCount; i++)
{
var saleItemInfo = appointmentInfo.GoodsList[i];
+ if (appointmentInfo.GoodsCount < 2 && saleItemInfo.State == 1)
+ {
+ SysNotifyMgr.Instance.ShowTip("FlashRushToBuy1");
+ }
for (int j = 0; j < operation.flashShops.Count; j++)
{
var saleItems = operation.flashShops[j].items;
diff --git a/System/OpenServerActivity/FlashSaleItemCell.cs b/System/OpenServerActivity/FlashSaleItemCell.cs
index 14ec735..df30b72 100644
--- a/System/OpenServerActivity/FlashSaleItemCell.cs
+++ b/System/OpenServerActivity/FlashSaleItemCell.cs
@@ -29,7 +29,8 @@
OperationFlashRushToBuy.FlashSaleItem saleItem;
int buyState = -1;
- float cdTime = 10;
+ int cdTime = 0;
+ int code = 0;
private void OnEnable()
{
battleModel.RefreshGameRecInfoAct += UpdateFullServerBuy;
@@ -51,6 +52,7 @@
if (rushToBuyModel.presentFlashShop == null) return;
saleItem = rushToBuyModel.presentFlashShop.items[cell.index];
+ code = rushToBuyModel.presentFlashShop.dayIndex * 1000 + rushToBuyModel.presentFlashShop.timeIndex * 100 + cell.index;
ItemCellModel cellModel = new ItemCellModel(saleItem.itemId,true,(ulong)saleItem.itemCount,saleItem.isBind);
itemBaisc.Init(cellModel);
itemBaisc.cellBtn.RemoveAllListeners();
@@ -87,6 +89,12 @@
private void UpdateAppointmentInfo(int shopGuid)
{
if (saleItem == null || shopGuid != saleItem.shopGuid) return;
+
+ if(saleItem.isAppointment == 1)
+ {
+ cdTime = 10;
+ KnapsackTimeCDMgr.Instance.Register(code, cdTime, RefreshCD);
+ }
UpdateSaleItem();
}
@@ -104,42 +112,44 @@
btnBgImg.SetSprite("SecondBtn1");
btnStateText.gameObject.SetActive(true);
cdText.gameObject.SetActive(false);
+ btnBgImg.material = MaterialUtility.GetUIDefaultGraphicMaterial();
switch (buyState)
{
case -1:
if(saleItem.isAppointment == 0)
{
- cdTime = 10;
btnStateText.text = Language.Get("FlashRushToBuy101");
flashSaleBtn.AddListener(() => { rushToBuyModel.SendFlashSaleAppointment(saleItem.shopGuid, 1); });
}
else
{
+ btnBgImg.SetSprite("BlackBtn");
+ RefreshCD(code,KnapsackTimeCDMgr.Instance.GetNormalCDTime(code));
btnStateText.gameObject.SetActive(false);
cdText.gameObject.SetActive(true);
- btnBgImg.SetSprite("BlackBtn");
- RefreshCD(cdTime);
- TimeDownMgr.Instance.Begin(TimeDownMgr.CoolTimeType.FlashRushToBuyAppointment,cdTime, RefreshCD);
flashSaleBtn.AddListener(CancelAppointment);
}
break;
case 0:
- cdTime = 10;
btnStateText.text = Language.Get("FlashRushToBuy102");
flashSaleBtn.AddListener(() => { storeModel.SendBuyShopItem(storeConfig,saleItem.itemCount); });
break;
}
}
- private void RefreshCD(float time)
+ private void RefreshCD(int code,int time)
{
+ if (this.code != code) return;
+
cdTime = time;
if (cdTime <= 0)
{
+ btnBgImg.material = MaterialUtility.GetUIDefaultGraphicMaterial();
cdText.text = Language.Get("FlashRushToBuy103");
}
else
{
+ btnBgImg.material = MaterialUtility.GetDefaultSpriteGrayMaterial();
cdText.text = Language.Get("FlashRushToBuy104",time);
}
}
@@ -161,7 +171,8 @@
{
int fullSeverRemain = 0;
int sellState = GetSellSate(out fullSeverRemain);
- fullServerRemainNum.text = fullSeverRemain.ToString();
+ string fullSeverRemainStr = fullSeverRemain > 0 ? fullSeverRemain.ToString() : UIHelper.GetTextColorByItemColor(TextColType.Red, fullSeverRemain.ToString());
+ fullServerRemainNum.text = fullSeverRemainStr;
switch (sellState)
{
case 0:
--
Gitblit v1.8.0