using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using TableConfig;
|
using UnityEngine;
|
namespace Snxxz.UI
|
{
|
public class OSGiftModel : Model, IPlayerLoginOk, IBeforePlayerDataInitialize, IOpenServerActivity
|
{
|
public override void Init()
|
{
|
PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent;
|
storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
|
vipModel.firstChargeRewardEvent += FirstChargeRewardEvent;
|
OpenServerActivityCenter.Instance.Register(6, this);
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
activate = CheckActivate();
|
if (onStateUpate != null)
|
{
|
onStateUpate(6);
|
}
|
UpdateRedpoint();
|
}
|
|
public event Action<int> onStateUpate;
|
public event Action timeLimitUpdate;
|
|
public bool activate { get; private set; }
|
|
StoreModel storeModel
|
{
|
get
|
{
|
return ModelCenter.Instance.GetModel<StoreModel>();
|
}
|
}
|
|
VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
|
|
public bool IsOpen
|
{
|
get
|
{
|
return CheckActivate();
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get
|
{
|
return OSGiftRedpoint.state == RedPointState.Simple;
|
}
|
}
|
|
private void RefreshBuyShopLimitEvent()
|
{
|
bool _activate = CheckActivate();
|
if (activate != _activate)
|
{
|
activate = _activate;
|
if (onStateUpate != null)
|
{
|
onStateUpate(6);
|
}
|
UpdateRedpoint();
|
}
|
}
|
|
public int timeOverdueGiftId { get; private set; }
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return false;
|
}
|
}
|
|
public DateTime overDueTime = DateTime.Now;
|
public void UpdateTime(HAA16_tagMCSuperGiftInfo package)
|
{
|
timeOverdueGiftId = (int)package.GiftID;
|
overDueTime = ParseOverdueTime(package.EndtDate);
|
bool _activate = CheckActivate();
|
if (activate != _activate)
|
{
|
activate = _activate;
|
if (onStateUpate != null)
|
{
|
onStateUpate(6);
|
}
|
}
|
if (timeLimitUpdate != null)
|
{
|
timeLimitUpdate();
|
}
|
UpdateRedpoint();
|
}
|
|
DateTime ParseOverdueTime(string _date)
|
{
|
var array = _date.Split('-');
|
var year = int.Parse(array[0]);
|
var month = int.Parse(array[1]);
|
var day = int.Parse(array[2]);
|
var time = new DateTime(year, month, day, 0, 0, 0);
|
return time.AddDays(1);
|
}
|
|
private void FirstChargeRewardEvent()
|
{
|
bool _activate = CheckActivate();
|
if (activate != _activate)
|
{
|
activate = _activate;
|
if (onStateUpate != null)
|
{
|
onStateUpate(6);
|
}
|
}
|
UpdateRedpoint();
|
}
|
|
public bool CheckActivate()
|
{
|
if (PlayerDatas.Instance.baseData.coinPointTotal == 0
|
|| !ModelCenter.Instance.GetModel<VipModel>().firstChargeRewardGet)
|
{
|
return false;
|
}
|
List<StoreConfig> _list = null;
|
StoreConfig.TryGetStoreConfigs((int)StoreFunc.OSGift,out _list);
|
for (int i = 0; i < _list.Count; i++)
|
{
|
if (IsGiftOverdue(_list[i].ID))
|
{
|
continue;
|
}
|
var _limit = storeModel.GetBuyShopLimit((uint)_list[i].ID);
|
if (_limit == null || _limit.BuyCnt < _list[i].PurchaseNumber[0])
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public bool IsGiftOverdue(int _id)
|
{
|
if (_id == timeOverdueGiftId)
|
{
|
return TimeUtility.ServerNow >= overDueTime;
|
}
|
return true;
|
}
|
|
public bool IsGiftBuy(int _id)
|
{
|
var _limit = storeModel.GetBuyShopLimit((uint)_id);
|
var config = Config.Instance.Get<StoreConfig>(_id);
|
if (_limit != null && config != null
|
&& _limit.BuyCnt >= config.PurchaseNumber[0])
|
{
|
return true;
|
}
|
return false;
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataRefresh _type)
|
{
|
bool _activate = CheckActivate();
|
if (_type == PlayerDataRefresh.ChangeCoinPointTotal && activate != _activate)
|
{
|
activate = _activate;
|
if (onStateUpate != null)
|
{
|
onStateUpate(6);
|
}
|
}
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
timeOverdueGiftId = 0;
|
}
|
|
public void SetDayRemind()
|
{
|
if (OSGiftRedpoint.state == RedPointState.Simple)
|
{
|
DayRemind.Instance.SetDayRemind(DayRemind.OSGIFT_REDPOINT, true);
|
UpdateRedpoint();
|
}
|
}
|
|
void UpdateRedpoint()
|
{
|
OSGiftRedpoint.state = RedPointState.None;
|
if (CheckActivate() && !DayRemind.Instance.GetDayRemind(DayRemind.OSGIFT_REDPOINT))
|
{
|
OSGiftRedpoint.state = RedPointState.Simple;
|
}
|
}
|
|
public Redpoint OSGiftRedpoint = new Redpoint(MainRedDot.REDPOINT_OPENSERVER, 20906);
|
}
|
}
|