using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class OSGiftModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize, IOpenServerActivity
|
{
|
VipModel vipModel
|
{
|
get { return ModelCenter.Instance.GetModel<VipModel>(); }
|
}
|
|
public override void Init()
|
{
|
ParseConfig();
|
vipModel.rechargeCountEvent += RechargeCountEvent;
|
OpenServerActivityCenter.Instance.Register(6, this);
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
startSeconds = 0;
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
if (onStateUpate != null)
|
{
|
onStateUpate(6);
|
}
|
UpdateRedpoint();
|
}
|
|
public event Action<int> onStateUpate;
|
public event Action onSelectUpdate;
|
|
public bool IsOpen
|
{
|
get
|
{
|
return IsExist();
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get
|
{
|
for (int i = 0; i < redpoints.Count; i++)
|
{
|
if (redpoints[i].state == RedPointState.Simple)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
}
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return false;
|
}
|
}
|
|
int m_SelectIndex = 0;
|
public int selectIndex
|
{
|
get { return m_SelectIndex; }
|
set
|
{
|
if (value != m_SelectIndex)
|
{
|
m_SelectIndex = value;
|
if (onSelectUpdate != null)
|
{
|
onSelectUpdate();
|
}
|
}
|
m_SelectIndex = value;
|
}
|
}
|
|
public int jumpGiftId { get; set; }
|
|
public List<SuperValueGift> gifts { get; private set; }
|
public List<int> alreadyOpens { get; private set; }
|
void ParseConfig()
|
{
|
gifts = new List<SuperValueGift>();
|
alreadyOpens = new List<int>();
|
var config = FuncConfigConfig.Get("SuperGiftTimeList");
|
var array = LitJson.JsonMapper.ToObject<int[][]>(config.Numerical1);
|
for (int i = 0; i < array.Length; i++)
|
{
|
gifts.Add(new SuperValueGift()
|
{
|
payType = array[i][0],
|
openDays = array[i][1],
|
});
|
}
|
|
for (int i = 0; i < gifts.Count; i++)
|
{
|
redpoints.Add(new Redpoint(MainRedDot.REDPOINT_OPENSERVER, 20906 * 100 + i));
|
}
|
}
|
|
private void RechargeCountEvent(int id)
|
{
|
UpdateRedpoint();
|
}
|
|
public uint startSeconds { get; private set; }
|
public void UpdateTime(HAA16_tagMCSuperGiftInfo package)
|
{
|
startSeconds = package.StartTime;
|
if (onStateUpate != null)
|
{
|
onStateUpate(6);
|
}
|
UpdateRedpoint();
|
}
|
|
public bool IsExist()
|
{
|
for (int i = 0; i < gifts.Count; i++)
|
{
|
if (!IsGiftExist(gifts[i].payType))
|
{
|
continue;
|
}
|
return true;
|
}
|
return false;
|
}
|
|
public bool IsGiftExist(int payType)
|
{
|
if (startSeconds == 0)
|
{
|
return false;
|
}
|
if (IsGiftBuy(payType))
|
{
|
return false;
|
}
|
var gift = gifts.Find((x) =>
|
{
|
return x.payType == payType;
|
});
|
if (!gift.Equals(default(SuperValueGift)))
|
{
|
var startTime = TimeUtility.GetTime(startSeconds);
|
var endTime = startTime.AddDays(gift.openDays);
|
endTime = new DateTime(endTime.Year, endTime.Month, endTime.Day, 0, 0, 0);
|
return TimeUtility.ServerNow < endTime;
|
}
|
return true;
|
}
|
|
public bool IsGiftBuy(int payType)
|
{
|
var rechargeId = GetRechargeId(payType);
|
if (rechargeId != 0)
|
{
|
VipModel.RechargeCount rechargeCount;
|
if (vipModel.TryGetRechargeCount(rechargeId, out rechargeCount))
|
{
|
return rechargeCount.totalCount >= 1;
|
}
|
}
|
return false;
|
}
|
|
public int GetRechargeId(int payType)
|
{
|
var list = vipModel.GetCTGConfigs(VersionConfig.Get().appId);
|
if (list != null)
|
{
|
for (int i = 0; i < list.Count; i++)
|
{
|
var config = CTGConfig.Get(list[i]);
|
if (config != null && config.PayType == payType)
|
{
|
return config.RecordID;
|
}
|
}
|
}
|
return 0;
|
}
|
|
public void SetAreadyOpens()
|
{
|
alreadyOpens.Clear();
|
for (int i = 0; i < gifts.Count; i++)
|
{
|
if (IsGiftExist(gifts[i].payType))
|
{
|
alreadyOpens.Add(i);
|
}
|
}
|
}
|
|
public int GetDefaultSelect()
|
{
|
for (int i = 0; i < alreadyOpens.Count; i++)
|
{
|
if (gifts[i].payType == jumpGiftId)
|
{
|
jumpGiftId = 0;
|
return alreadyOpens[i];
|
}
|
}
|
jumpGiftId = 0;
|
for (int i = 0; i < alreadyOpens.Count; i++)
|
{
|
if (redpoints[alreadyOpens[i]].state == RedPointState.Simple)
|
{
|
return alreadyOpens[i];
|
}
|
}
|
return alreadyOpens[0];
|
}
|
|
bool GetDayRemind(int index)
|
{
|
return LocalSave.GetInt(StringUtility.Contact("OSGift_", index, "_",
|
PlayerDatas.Instance.baseData.PlayerID), 0) == TimeUtility.Day;
|
}
|
|
public void SetDayRemind(int index)
|
{
|
if (redpoints[index].state == RedPointState.Simple)
|
{
|
LocalSave.SetInt(StringUtility.Contact("OSGift_", index, "_",
|
PlayerDatas.Instance.baseData.PlayerID), TimeUtility.Day);
|
UpdateRedpoint();
|
}
|
}
|
|
List<Redpoint> redpoints = new List<Redpoint>();
|
|
void UpdateRedpoint()
|
{
|
for (int i = 0; i < redpoints.Count; i++)
|
{
|
redpoints[i].state = RedPointState.None;
|
if (IsGiftExist(gifts[i].payType) && !IsGiftBuy(gifts[i].payType)
|
&& !GetDayRemind(i))
|
{
|
redpoints[i].state = RedPointState.Simple;
|
}
|
}
|
}
|
|
public struct SuperValueGift
|
{
|
public int payType;
|
public int openDays;
|
}
|
}
|
}
|