using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using LitJson;
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
public class FullServerRechargeRedpackModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
RedPacketModel redbagModel { get { return ModelCenter.Instance.GetModel<RedPacketModel>(); } }
|
|
//全服充值红包类型
|
public const int FullServer_Recharge_Redpack = 36;
|
public const int ActivityType = 34;
|
const int REDPOINTID = 20934;
|
public readonly Redpoint redpoint = new Redpoint(MainRedDot.REDPOINT_OPENSERVER, REDPOINTID);
|
public event Action<int> onStateUpdate;
|
public Dictionary<int, int> vipRedpackCount = new Dictionary<int, int>();
|
public bool hasQFRedbag = false;//可领红包
|
|
public override void Init()
|
{
|
redbagModel.RedbagRefresh += RedEnvelopeToRefresh;//红包的刷新
|
redbagModel.ServerGrabCntEvent += ServerGrabCntEvent;
|
ParseConfig();
|
OpenServerActivityCenter.Instance.Register(ActivityType, this);
|
}
|
|
public bool IsOpen
|
{
|
get
|
{
|
return FuncOpen.Instance.IsClientLVLimit(1);
|
}
|
}
|
|
public bool IsAdvance { get { return false; } }
|
public bool priorityOpen { get { return redpoint.state == RedPointState.Simple; } }
|
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
hasQFRedbag = false;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
void ParseConfig()
|
{
|
vipRedpackCount.Clear();
|
var config = JsonMapper.ToObject(FuncConfigConfig.Get("RechargeRedPacket").Numerical3);
|
foreach (var key in config.Keys)
|
{
|
vipRedpackCount[int.Parse(key)] = int.Parse(config[key].ToString());
|
}
|
|
}
|
|
//全服充值红包的可开启次数, 0代表无限制
|
public int GetMaxOpenRedpackCount()
|
{
|
var keyList = vipRedpackCount.Keys.ToList();
|
keyList.Sort();
|
var viplv = PlayerDatas.Instance.baseData.VIPLv;
|
foreach (var key in keyList)
|
{
|
if (viplv <= key)
|
{
|
return vipRedpackCount[key];
|
}
|
}
|
|
return 0;
|
}
|
|
void RedEnvelopeToRefresh()//红包的刷新
|
{
|
ServerGrabCntEvent();
|
}
|
|
//hasQFRedbag: 可抢个数,已领完,已领取
|
public void ServerGrabCntEvent()
|
{
|
hasQFRedbag = false;
|
int maxCnt = GetMaxOpenRedpackCount();
|
foreach (int key in redbagModel._DicRedBag.Keys)
|
{
|
if (!redbagModel.IsDisplayRechargeTH(redbagModel._DicRedBag[key]))
|
{
|
continue;
|
}
|
|
if (redbagModel._DicRedBag[key].State == 1)
|
{
|
if ((maxCnt == 0 || maxCnt > redbagModel.ServerGrabCnt) && IsOpen)
|
{
|
hasQFRedbag = true;
|
break;
|
}
|
|
}
|
}
|
UpdateRedPoint();
|
}
|
|
void UpdateRedPoint()
|
{
|
redpoint.state = RedPointState.None;
|
if (!IsOpen)
|
return;
|
|
int maxCnt = GetMaxOpenRedpackCount();
|
foreach (int key in redbagModel._DicRedBag.Keys)
|
{
|
if (!redbagModel.IsDisplayRechargeTH(redbagModel._DicRedBag[key]))
|
{
|
continue;
|
}
|
if (redbagModel._DicRedBag[key].State == 0 || hasQFRedbag)
|
{
|
redpoint.state = RedPointState.Simple;
|
break;
|
}
|
}
|
}
|
}
|
}
|