using System;
|
using System.Collections.Generic;
|
|
namespace vnxbqy.UI
|
{
|
//ͬÑùÊÇÈÕÆÚÐÍÀñ°ü»î¶¯£¬³äÖµÄÚÈݲ»Í¬£¬ÆÕͨµÄ³äÖµÀñ°ü + ÀۼƳäÖµ´ÎÊý½±Àø
|
public class LianQiRechargeGiftActModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
//ͬ²½²¥·Å°Ú¶¯¶¯»
|
public Action PlayAnimationSync;
|
|
private bool isPlayAnimation = false;
|
public bool IsPlayAnimation
|
{
|
get
|
{
|
return isPlayAnimation;
|
}
|
set
|
{
|
isPlayAnimation = value;
|
if (isPlayAnimation)
|
{
|
PlayAnimationSync?.Invoke();
|
}
|
isPlayAnimation = false;
|
}
|
}
|
|
public event Action<int> onStateUpdate;
|
public Redpoint redPoint = new Redpoint(MainRedDot.LianQiRepoint, MainRedDot.LianQiRepoint * 10 + 3); //¿ÉÄܹҶà¸ö¸¸ºìµã
|
|
private int GiftAwardRecord; //Áìȡ״̬
|
|
public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity2;
|
public const int activityID = (int)NewDayActivityID.LianQiRechargeGiftActCross;
|
public static Operation operaType = Operation.default52;
|
|
public const int actNum = 13; //¶ÔÓ¦½çÃæ
|
public event Action UpdateRechargeGiftActEvent;
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
|
public override void Init()
|
{
|
OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
|
storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
|
vipModel.rechargeCountEvent += VipModel_rechargeCountEvent;
|
OpenServerActivityCenter.Instance.Register(activityID, this, activityType);
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
}
|
|
public override void UnInit()
|
{
|
OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent -= OperationAdvanceEvent;
|
storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
|
vipModel.rechargeCountEvent -= VipModel_rechargeCountEvent;
|
}
|
|
private void VipModel_rechargeCountEvent(int obj)
|
{
|
if (IsOpen)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
public bool IsOpen
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyOpenCondition(operaType);
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get
|
{
|
return redPoint.state == RedPointState.Simple;
|
}
|
}
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyAdvanceCondition(operaType);
|
}
|
}
|
|
private void OperationEndEvent(Operation type, int state)
|
{
|
if (type == operaType)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(activityID);
|
}
|
UpdateRedpoint();
|
if (WindowCenter.Instance.IsOpen<YunShiWin>())
|
{
|
WindowCenter.Instance.Close<YunShiWin>();
|
}
|
}
|
}
|
|
private void RefreshBuyShopLimitEvent()
|
{
|
UpdateRedpoint();
|
}
|
|
private void OperationAdvanceEvent(Operation type)
|
{
|
if (type == operaType)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(activityID);
|
}
|
}
|
}
|
|
private void OperationStartEvent(Operation type, int state)
|
{
|
if (type == operaType && state == 0)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(activityID);
|
}
|
}
|
}
|
|
//0 ²»¿ÉÁìÈ¡ 1 ¿ÉÁìÈ¡ 2 ÒÑÁìÈ¡
|
public int GetBuyGiftState(int count)
|
{
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out act);
|
|
if (act == null)
|
return 0;
|
if (GetBuyTotalCnt() < count)
|
return 0;
|
if (((int)Math.Pow(2, count) & GiftAwardRecord) == 0)
|
{
|
return 1;
|
}
|
return 2;
|
}
|
|
public int GetBuyTotalCnt()
|
{
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out act);
|
|
if (act == null) return 0;
|
int total = 0;
|
for (int i = 0; i < act.ctgIDs.Count; i++)
|
{
|
int ctgID = act.ctgIDs[i];
|
VipModel.RechargeCount rechargeCount;
|
if (vipModel.TryGetRechargeCount(ctgID, out rechargeCount))
|
{
|
total += rechargeCount.totalCount;
|
}
|
}
|
return total;
|
}
|
|
public Int2 GetBuyCntInfo(int ctgID)
|
{
|
VipModel.RechargeCount rechargeCount;
|
vipModel.TryGetRechargeCount(ctgID, out rechargeCount);
|
|
var ctgConfig = CTGConfig.Get(ctgID);
|
int buyCnt = 0;
|
int totalCnt = 0;
|
if (ctgConfig.DailyBuyCount != 0)
|
{
|
buyCnt = rechargeCount.todayCount;
|
totalCnt = ctgConfig.DailyBuyCount;
|
}
|
else
|
{
|
buyCnt = rechargeCount.totalCount;
|
totalCnt = ctgConfig.TotalBuyCount;
|
}
|
|
return new Int2(buyCnt, totalCnt);
|
}
|
|
private void UpdateRedpoint()
|
{
|
redPoint.state = RedPointState.None;
|
if (!IsOpen) return;
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out act);
|
if (act == null) return; //·â°ü˳ÐòÈç¹ûÓÐÎÊÌâ ´Ë´¦Îª¿Õ
|
|
for (int i = 0; i < act.buyCountGifts.Count; i++)
|
{
|
if (GetBuyGiftState(act.buyCountGifts[i].NeedBuyCount) == 1)
|
{
|
redPoint.state = RedPointState.Simple;
|
return;
|
}
|
}
|
|
//É̵êÃâ·Ñ
|
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs(act.shopType, out _list);
|
|
int storeCnt = _list == null ? 0 : _list.Count;
|
|
for (int i = 0; i < storeCnt; i++)
|
{
|
if (_list[i].MoneyNumber == 0)
|
{
|
int remainNum;
|
storeModel.TryGetIsSellOut(_list[i], out remainNum);
|
if (remainNum > 0)
|
redPoint.state = RedPointState.Simple;
|
}
|
}
|
}
|
|
public void UpdateBuyCountGiftPlayerInfo(HAA75_tagMCActBuyCountGiftPlayerInfo netPack)
|
{
|
if (actNum != netPack.ActNum) return;
|
|
GiftAwardRecord = (int)netPack.GiftAwardRecord;
|
UpdateRechargeGiftActEvent?.Invoke();
|
|
UpdateRedpoint();
|
}
|
|
public void SendGetAward(int count)
|
{
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = 72;
|
getReward.DataEx = (uint)count;
|
getReward.DataExStr = actNum.ToString();
|
getReward.DataExStrLen = (byte)getReward.DataExStr.Length;
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
}
|
}
|