//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Wednesday, July 18, 2018
|
//--------------------------------------------------------
|
using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
|
|
public class HolidayLimitedTimePackageModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
Operation operationType = Operation.HolidayGiftPackage;
|
int regesitType = 107;
|
|
int m_SelectIndex = 0;
|
public int selectIndex
|
{
|
get { return m_SelectIndex; }
|
set
|
{
|
if (m_SelectIndex != value)
|
{
|
if (selectUpdate != null)
|
{
|
selectUpdate(value);
|
}
|
}
|
m_SelectIndex = value;
|
}
|
}
|
public event Action<int> selectUpdate;
|
public Dictionary<int, int> DicBuyPackage = new Dictionary<int, int>();
|
public event Action UpdateLimitedTimePackageItem;
|
public event Action<int> onStateUpdate;
|
public override void Init()
|
{
|
OpenServerActivityCenter.Instance.Register(regesitType, this, (int)OpenServerActivityCenter.ActivityType.AT_JRZF);
|
OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
|
}
|
private const int Redpoint_key1 = 28007;
|
public Redpoint redPointStre1 = new Redpoint(MainRedDot.RedPoint_HolidayWishes, Redpoint_key1);//限时礼包红点
|
public bool IsOpen
|
{
|
get
|
{
|
return !IsExpired();
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get
|
{
|
return false;
|
}
|
}
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyAdvanceCondition(operationType);
|
}
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
DicBuyPackage.Clear();
|
}
|
public override void UnInit()
|
{
|
|
}
|
public void OnPlayerLoginOk()
|
{
|
OperationTimeHepler.Instance.operationStartEvent -= operationStartEvent;
|
OperationTimeHepler.Instance.operationStartEvent += operationStartEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent -= operationAdvanceEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent += operationAdvanceEvent;
|
IsShowTip();
|
|
}
|
|
|
|
private void operationStartEvent(Operation arg1, int arg2)
|
{
|
if (arg1 == operationType)
|
{
|
IsShowTip();
|
if (arg2 == 0 && onStateUpdate != null)
|
{
|
onStateUpdate(regesitType);
|
}
|
}
|
}
|
private void operationAdvanceEvent(Operation obj)
|
{
|
if (obj == operationType)
|
{
|
// IsShowTip();
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(regesitType);
|
}
|
}
|
}
|
private void OperationEndEvent(Operation arg1, int arg2)
|
{
|
if (arg1 == operationType && arg2 == 0)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(regesitType);
|
}
|
}
|
}
|
|
public void IsShowTip()
|
{
|
if (OperationTimeHepler.Instance.SatisfyAdvanceCondition(operationType))
|
{
|
return;
|
}
|
int GetDayOfYear = DateTime.Now.DayOfYear;
|
int day = LocalSave.GetInt("IsOpenLimitedTime");
|
bool Isbool = !IsExpired();
|
if (day != GetDayOfYear && !IsExpired())
|
{
|
// LocalSave.SetInt("IsOpenLimitedTime", GetDayOfYear);
|
redPointStre1.state = RedPointState.Simple;
|
}
|
else
|
{
|
redPointStre1.state = RedPointState.None;
|
}
|
|
}
|
public void BuyCoutList(HAA13_tagMCFlashGiftbagPlayerInfo Info)
|
{
|
GiftPackageClass operation;
|
if (!OperationTimeHepler.Instance.TryGetOperation(operationType, out operation))
|
{
|
return;
|
}
|
if (operation.ActNum != Info.ActNum)
|
{
|
return;
|
}
|
|
for (int i = 0; i < Info.Count; i++)
|
{
|
if (DicBuyPackage.ContainsKey((int)Info.BuyCountList[i].GiftbagID))
|
{
|
DicBuyPackage[(int)Info.BuyCountList[i].GiftbagID] = (int)Info.BuyCountList[i].BuyCount;
|
}
|
else
|
{
|
DicBuyPackage.Add((int)Info.BuyCountList[i].GiftbagID, (int)Info.BuyCountList[i].BuyCount);
|
}
|
}
|
if (UpdateLimitedTimePackageItem != null)
|
{
|
UpdateLimitedTimePackageItem();
|
}
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(regesitType);
|
}
|
}
|
|
public bool IsExpired(int index = 0)
|
{
|
bool IsSatisfyAliveCondition = false;
|
IsSatisfyAliveCondition = (OperationTimeHepler.Instance.SatisfyOpenCondition(operationType)
|
|| OperationTimeHepler.Instance.SatisfyAdvanceCondition(operationType));
|
bool IsBuyBool = false;
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
GiftPackageClass operation = operationBase as GiftPackageClass;
|
GiftPackageClass.Gift_Package gift;
|
if (operation.TryGetGift(TimeUtility.ServerNow, out gift))
|
{
|
if (gift.gifts.Length > 0)
|
{
|
int BuyCountLimit = gift.gifts[index].limitNum;//限购数量
|
int GiftID = gift.gifts[index].id;//礼包ID
|
if (DicBuyPackage.ContainsKey(GiftID) && DicBuyPackage[GiftID] >= BuyCountLimit)
|
{
|
IsBuyBool = true;
|
}
|
}
|
}
|
}
|
if (IsSatisfyAliveCondition)
|
{
|
return false;
|
}
|
else
|
{
|
return true;
|
}
|
}
|
|
}
|