using System;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
namespace vnxbqy.UI
|
{
|
public class LoginActModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
public event Action<int> onStateUpdate;
|
public const int redPointID = MainRedDot.NewDayActionRedPoint * 10;
|
public Redpoint redPoint = new Redpoint(MainRedDot.RankActRepoint, redPointID); //可能挂多个父红点
|
|
private uint LoginAwardState; //领取状态 可以补签
|
|
public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity2;
|
public const int activityID = (int)NewDayActivityID.LoginAct;
|
public static Operation operaType = Operation.default29;
|
|
public int actNum = 10; //对应界面
|
public event Action UpdateyLoginEvent;
|
|
public override void Init()
|
{
|
OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
|
OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
|
OpenServerActivityCenter.Instance.Register(activityID, this, activityType);
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
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);
|
}
|
}
|
}
|
|
//0 不可领取(日期未到) 1 可领取 2 已领取 3补签(已过天)
|
//day 从1开始
|
public int GetLoginAwardState(int day)
|
{
|
//校验日期
|
OperationLoginAct holiday;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out holiday);
|
if (holiday == null) return 0;
|
|
int days = holiday.IndexOfDays(TimeUtility.ServerNow); //当前是第几天
|
if (days == -1) return 0;
|
if (day > days + 1) return 0;
|
|
if (((int)Math.Pow(2, day) & LoginAwardState) == 0)
|
{
|
if (day != days + 1)
|
return 3;
|
return 1;
|
}
|
|
return 2;
|
}
|
|
void UpdateRedpoint()
|
{
|
redPoint.state = RedPointState.None;
|
if (!IsOpen) return;
|
OperationLoginAct holiday;
|
OperationTimeHepler.Instance.TryGetOperation(operaType, out holiday);
|
if (holiday == null) return; //封包顺序如果有问题 此处为空
|
|
for (int i = 0; i < holiday.loginAwards.Count; i++)
|
{
|
if (GetLoginAwardState(holiday.loginAwards[i].DayNum) == 1)
|
{
|
redPoint.state = RedPointState.Simple;
|
return;
|
}
|
}
|
}
|
|
public void UpdateLoginInfo(HAA70_tagMCActLoginPlayerInfoNew netPack)
|
{
|
if (actNum != netPack.ActNum)
|
return;
|
LoginAwardState = netPack.LoginAward;
|
UpdateyLoginEvent?.Invoke();
|
|
UpdateRedpoint();
|
}
|
|
public void SendGetAward(int day)
|
{
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = 70;
|
getReward.DataEx = (uint)day;
|
getReward.DataExStr = actNum.ToString();
|
getReward.DataExStrLen = (byte)getReward.DataExStr.Length;
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
|
}
|
}
|