using vnxbqy.UI;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
using System.Linq;
|
using LitJson;
|
using System;
|
using System.Reflection;
|
|
|
public class DailySpecialsModel : ILModel<DailySpecialsModel>
|
{
|
public uint PackBuyTime; // 打包购买的时间戳,如果有该值,代表已经一次性打包购买了,可根据次时间戳算出当前是第几天
|
public uint BuyStateToday; // 今日礼包购买状态,按礼包索引二进制位计算代表是否已购买,仅非打包购买状态下有用
|
public uint AwardState; // 今日礼包领奖状态,按礼包索引二进制位计算代表是否已领取
|
public int maxDay; //总共可以领取几天
|
public int giftLvRestrict; //礼包等级限制
|
|
public Dictionary<int, List<List<int>>> giftInfoDict = new Dictionary<int, List<List<int>>>();
|
public Dictionary<int, List<int>> ctgIdDict = new Dictionary<int, List<int>>();
|
public List<int> packRechargeIdList = new List<int>();
|
public List<List<Item>> itemAllList = new List<List<Item>>();
|
Redpoint redpoint = new Redpoint(MainRedPoint.RechargeGenerousGiftWinRedpoint, MainRedPoint.DailySpecialsRedpoint);
|
Dictionary<int, Redpoint> childRedpointDict = new Dictionary<int, Redpoint>();
|
VipModel vipModel { get { return ModelCenter.Instance.GetModelEx<VipModel>(); } }
|
public event Action UpdateGiftStateEvent;
|
|
protected override void Init()
|
{
|
GameEvent.beforePlayerDataInitializeEvent += OnbeforePlayerDataInitialize;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFunctionStateChange;
|
var tempDict = JsonMapper.ToObject(FuncConfigConfig.Get("DailyPackBuyGift").Numerical1);
|
var keyList = tempDict.Keys.ToList();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
List<List<int>> giftInfoList = new List<List<int>>();
|
for (int j = 0; j < tempDict[i].Count; j++)
|
{
|
List<int> giftInfo = JsonMapper.ToObject<List<int>>(tempDict[keyList[i]][j].ToJson());
|
giftInfoList.Add(giftInfo);
|
}
|
giftInfoDict.Add(int.Parse(keyList[i]), giftInfoList);
|
}
|
|
tempDict = JsonMapper.ToObject(FuncConfigConfig.Get("DailyPackBuyGift").Numerical2);
|
keyList = tempDict.Keys.ToList();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
ctgIdDict[int.Parse(keyList[i])] = JsonMapper.ToObject<List<int>>(tempDict[keyList[i]].ToJson());
|
}
|
|
packRechargeIdList = JsonMapper.ToObject<List<int>>(FuncConfigConfig.Get("DailyPackBuyGift").Numerical3);
|
maxDay = int.Parse(FuncConfigConfig.Get("DailyPackBuyGift").Numerical4);
|
|
List<int> giftInfokeyList = giftInfoDict.Keys.ToList();
|
for (int i = 0; i < giftInfoDict.Count; i++)
|
{
|
List<Item> itemList = new List<Item>();
|
for (int j = 0; j < giftInfoDict[giftInfokeyList[i]].Count; j++)
|
{
|
Item item = new Item(giftInfoDict[giftInfokeyList[i]][j][0], giftInfoDict[giftInfokeyList[i]][j][1]);
|
itemList.Add(item);
|
}
|
itemAllList.Add(itemList);
|
}
|
List<int> keyList2 = giftInfoDict.Keys.ToList();
|
for (int i = 0; i < giftInfoDict.Count; i++)
|
{
|
childRedpointDict[keyList2[i]] = new Redpoint(MainRedPoint.DailySpecialsRedpoint, MainRedPoint.DailySpecialsRedpoint * 100 + i);
|
}
|
|
}
|
|
protected override void UnInit()
|
{
|
GameEvent.beforePlayerDataInitializeEvent -= OnbeforePlayerDataInitialize;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFunctionStateChange;
|
}
|
|
public void OnbeforePlayerDataInitialize()
|
{
|
PackBuyTime = 0;
|
BuyStateToday = 0;
|
AwardState = 0;
|
}
|
|
|
private void OnFunctionStateChange(int id)
|
{
|
if (id == 222)
|
{
|
UpdateRedpoint();
|
}
|
}
|
|
|
public void UpdateGiftState(IL_HAA03_tagMCDailyPackBuyGiftInfo vNetData)
|
{
|
this.PackBuyTime = vNetData.PackBuyTime;
|
this.BuyStateToday = vNetData.BuyStateToday;
|
this.AwardState = vNetData.AwardState;
|
UpdateGiftStateEvent?.Invoke();
|
UpdateRedpoint();
|
|
}
|
|
// 在功能开启的时候判断是否每日特惠开启, 触发UpdateRedpoint
|
|
//每日特惠
|
//1. 功能是否开启
|
//2. 免费是否已领取
|
//3. 购买后是否可领取
|
void UpdateRedpoint()
|
{
|
redpoint.state = RedPointState.None;
|
if (!FuncOpen.Instance.IsFuncOpen(222))
|
return;
|
|
List<int> keyList = childRedpointDict.Keys.ToList();
|
|
for (int i = 0; i < childRedpointDict.Count; i++)
|
{
|
childRedpointDict[keyList[i]].state = RedPointState.None;
|
if (GetGiftState(i) == 2)
|
{
|
childRedpointDict[keyList[i]].state = RedPointState.Simple;
|
}
|
}
|
}
|
|
//获得按钮状态
|
//0 未购买 1 已购买 2 可领取 3 已领取
|
public int GetGiftState(int index)
|
{
|
if (index == 0)
|
{
|
return IsHavePack(index) ? 3 : 2;
|
}
|
else
|
{
|
if (IsBuyAllPack())
|
{
|
return IsHavePack(index) ? 3 : 2;
|
}
|
else
|
{
|
if (IsBuyPack(index))
|
{
|
return IsHavePack(index) ? 3 : 2;
|
}
|
else
|
{
|
return 0;
|
}
|
}
|
}
|
}
|
|
//是否购买总包
|
public bool IsBuyAllPack()
|
{
|
|
if (PackBuyTime == 0)
|
{
|
return false;
|
}
|
else
|
{
|
return (TimeUtility.ServerNow - TimeUtility.GetTime(PackBuyTime)).Days < maxDay;
|
}
|
}
|
|
//是否购买分包
|
public bool IsBuyPack(int index)
|
{
|
return ((int)Math.Pow(2, index) & BuyStateToday) != 0;
|
}
|
|
//分包是否已领取
|
public bool IsHavePack(int index)
|
{
|
return ((int)Math.Pow(2, index) & AwardState) != 0;
|
}
|
|
}
|
|