using LitJson;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
namespace vnxbqy.UI
|
{
|
//同样是日期型礼包活动,充值内容不同,有自选充值和商店
|
public class RechargeGiftAct31Model : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
public event Action<int> onStateUpdate;
|
public const int redPointID = MainRedDot.NewDayActionRedPoint * 10 + 3;
|
public Redpoint redPoint = new Redpoint(MainRedDot.RankActRepoint, redPointID);
|
|
|
public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity2;
|
public const int activityID = (int)NewDayActivityID.RechargeGiftAct31;
|
public static Operation operaType = Operation.default38;
|
|
public const int actNum = 31; //对应界面
|
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;
|
OpenServerActivityCenter.Instance.Register(activityID, this, activityType);
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
UpdateRedpoint();
|
}
|
|
public override void UnInit()
|
{
|
OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent -= OperationAdvanceEvent;
|
storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
|
}
|
|
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 && state == 0)
|
{
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(activityID);
|
}
|
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);
|
}
|
}
|
}
|
|
|
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)
|
{
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out act);
|
|
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);
|
}
|
|
void UpdateRedpoint()
|
{
|
redPoint.state = RedPointState.None;
|
if (!IsOpen) return;
|
OperationRechargeGiftAct act;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out act);
|
if (act == null) 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;
|
|
UpdateRechargeGiftActEvent?.Invoke();
|
|
}
|
|
void RefreshBuyShopLimitEvent()
|
{
|
UpdateRedpoint();
|
}
|
}
|
}
|