using System;
|
using UnityEngine;
|
|
namespace vnxbqy.UI
|
{
|
|
public class MultipleRealmPointModel : Model, IBeforePlayerDataInitialize, IAfterPlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
public Redpoint multipleRed = new Redpoint(MainRedDot.REDPOINT_OPENSERVER, 20908);
|
public string LocalRecord_Key;
|
bool isNewDay = false;
|
bool openNotify = false;
|
|
public event Action<int> onStateUpdate;
|
|
public override void Init()
|
{
|
OpenServerActivityCenter.Instance.Register(8, this);
|
//StageLoad.Instance.onStageLoadFinish += CheckReconnect;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
alreadyRealmPoint = 0;
|
isNewDay = false;
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
openNotify = false;
|
LocalRecord_Key = StringUtility.Contact("MultipleRealmRecord", PlayerDatas.Instance.baseData.PlayerID);
|
GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
|
GlobalTimeEvent.Instance.secondEvent += SecondEvent;
|
CheckShowRed();
|
}
|
|
public override void UnInit()
|
{
|
StageLoad.Instance.onStageLoadFinish -= CheckReconnect;
|
}
|
|
public bool IsOpen
|
{
|
get
|
{
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(Operation.MultipRealmPoint, out operationBase))
|
{
|
var operation = operationBase as OperationMultipleRealmPoint;
|
return operation.InActiveTime(TimeUtility.ServerNow) && operation.SatisfyOpenCondition();
|
}
|
return false;
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get
|
{
|
return multipleRed.state == RedPointState.Simple;
|
}
|
}
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyAdvanceCondition(Operation.MultipRealmPoint);
|
}
|
}
|
|
public event Action UpdateRealmPointEvent;
|
public int alreadyRealmPoint { get; private set; }
|
public void SetAlreadyRealmPoint(int point)
|
{
|
alreadyRealmPoint = point;
|
if(UpdateRealmPointEvent != null)
|
{
|
UpdateRealmPointEvent();
|
}
|
}
|
|
private void CheckReconnect()
|
{
|
if (!(StageLoad.Instance.stageType == Stage.E_StageType.Dungeon))
|
{
|
CheckShowRed();
|
}
|
}
|
|
private void SecondEvent()
|
{
|
if (IsOpen && !openNotify)
|
{
|
openNotify = true;
|
CheckShowRed();
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(8);
|
}
|
}
|
else if (!IsOpen && openNotify)
|
{
|
openNotify = false;
|
CheckShowRed();
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(8);
|
}
|
}
|
}
|
|
public void CheckShowRed(bool isClick = false)
|
{
|
if (!IsOpen) return;
|
|
if(!isNewDay)
|
{
|
|
if (!PlayerPrefs.HasKey(LocalRecord_Key))
|
{
|
LocalSave.SetInt(LocalRecord_Key, TimeUtility.ServerNow.Day);
|
isNewDay = true;
|
}
|
else
|
{
|
if (TimeUtility.ServerNow.Day != LocalSave.GetInt(LocalRecord_Key))
|
{
|
isNewDay = true;
|
LocalSave.SetInt(LocalRecord_Key, TimeUtility.ServerNow.Day);
|
}
|
}
|
}
|
|
if(!isClick)
|
{
|
if (IsOpen && isNewDay)
|
{
|
multipleRed.state = RedPointState.Simple;
|
}
|
else
|
{
|
multipleRed.state = RedPointState.None;
|
}
|
}
|
else
|
{
|
multipleRed.state = RedPointState.None;
|
}
|
|
}
|
}
|
}
|