using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
namespace vnxbqy.UI
|
{
|
|
public class SingleRechargeSumModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
|
{
|
const int activityID = 38;
|
public const Operation operType = Operation.default28;
|
public bool IsOpen
|
{
|
get
|
{
|
return OperationTimeHepler.Instance.SatisfyOpenCondition(operType);
|
}
|
}
|
|
public bool IsAdvance
|
{
|
get
|
{
|
return false;
|
}
|
}
|
|
public bool priorityOpen
|
{
|
get { return redpoint.state == RedPointState.Simple; }
|
}
|
|
public event Action accumulateRechargeUpdate;
|
public event Action<int> onStateUpdate;
|
|
public override void Init()
|
{
|
OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
|
OperationTimeHepler.Instance.dayResetEvent += DayResetEvent;
|
OpenServerActivityCenter.Instance.Register(activityID, this);
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
awardStateInfo.Clear();
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
UpdateRedpoint();
|
}
|
|
public override void UnInit()
|
{
|
OperationTimeHepler.Instance.operationStartEvent -= OperationStartEvent;
|
OperationTimeHepler.Instance.operationEndEvent -= OperationEndEvent;
|
OperationTimeHepler.Instance.dayResetEvent -= DayResetEvent;
|
}
|
|
private void DayResetEvent(int resetType)
|
{
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(operType, out operationBase))
|
{
|
if (resetType == operationBase.resetType)
|
{
|
UpdateRedpoint();
|
}
|
}
|
}
|
|
private void OperationEndEvent(Operation operationType, int state)
|
{
|
if (operationType == operType && state == 0)
|
{
|
UpdateRedpoint();
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(activityID);
|
}
|
}
|
}
|
|
private void OperationStartEvent(Operation operationType, int state)
|
{
|
if (operationType == operType && state == 0)
|
{
|
UpdateRedpoint();
|
if (onStateUpdate != null)
|
{
|
onStateUpdate(activityID);
|
}
|
}
|
}
|
|
#region 服务端数据
|
Dictionary<int, Int2> awardStateInfo = new Dictionary<int, Int2>();
|
|
public uint ActNum { get; private set; }
|
public void UpdateSingleRecharge(HAA51_tagMCActSingleRechargePlayerInfo package)
|
{
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(operType, out operationBase))
|
{
|
OperationSingleRecharge operation = operationBase as OperationSingleRecharge;
|
if (operation.ActNum != package.ActNum)
|
{
|
return;
|
}
|
ActNum = package.ActNum;
|
|
for (int i = 0; i < package.AwardRecordList.Length; i++)
|
{
|
awardStateInfo[package.AwardRecordList[i].AwardIndex] = new Int2(package.AwardRecordList[i].CanGetCount, package.AwardRecordList[i].GetCount);
|
}
|
UpdateRedpoint();
|
if (accumulateRechargeUpdate != null)
|
{
|
accumulateRechargeUpdate();
|
}
|
}
|
}
|
|
|
bool IsRewardGot(int index)
|
{
|
return awardStateInfo[index].y >= GetMaxRewardCnt(index);
|
}
|
|
|
bool CanRewardGet(int index)
|
{
|
return awardStateInfo[index].x > awardStateInfo[index].y;
|
}
|
|
public int GetRewardGotCnt(int index)
|
{
|
return awardStateInfo[index].y;
|
}
|
|
public int GetCanRewardGetCnt(int index)
|
{
|
return awardStateInfo[index].x;
|
}
|
|
public int GetMaxRewardCnt(int index)
|
{
|
OperationBase operationBase;
|
|
if (OperationTimeHepler.Instance.TryGetOperationTime(SingleRechargeSumModel.operType, out operationBase))
|
{
|
OperationSingleRecharge operation = operationBase as OperationSingleRecharge;
|
return operation.awardMaxCount[index].x;
|
|
}
|
return 0;
|
}
|
|
|
//0 未达标 1 可领取 2 已领取
|
public int GetRewardState(int index)
|
{
|
if (!IsOpen)
|
{
|
return 0;
|
}
|
if (IsRewardGot(index))
|
{
|
return 2;
|
}
|
if (CanRewardGet(index))
|
{
|
return 1;
|
}
|
return 0;
|
}
|
|
public void SendGetReward(int index)
|
{
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.InOperationTime(operType))
|
{
|
SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
|
return;
|
}
|
if (OperationTimeHepler.Instance.TryGetOperationTime(operType, out operationBase))
|
{
|
OperationSingleRecharge operation = operationBase as OperationSingleRecharge;
|
if (GetRewardState(index) != 1)
|
{
|
return;
|
}
|
CA504_tagCMPlayerGetReward pak = new CA504_tagCMPlayerGetReward();
|
pak.RewardType = 43;
|
pak.DataEx = (uint)index;
|
pak.DataExStrLen = (byte)ActNum.ToString().Length;
|
pak.DataExStr = ActNum.ToString();
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
}
|
#endregion
|
|
#region 红点
|
public Redpoint redpoint = new Redpoint(MainRedDot.REDPOINT_OPENSERVER, 20900 + activityID);
|
|
public void UpdateRedpoint()
|
{
|
redpoint.state = RedPointState.None;
|
if (!IsOpen)
|
{
|
return;
|
}
|
OperationBase operationBase;
|
if (OperationTimeHepler.Instance.TryGetOperationTime(operType, out operationBase))
|
{
|
OperationSingleRecharge operation = operationBase as OperationSingleRecharge;
|
var count = operation.singleRechargeAwards.Keys.Count;
|
for (int i = 0; i < count; i++)
|
{
|
if (GetRewardState(i) == 1)
|
{
|
redpoint.state = RedPointState.Simple;
|
break;
|
}
|
}
|
}
|
}
|
#endregion
|
}
|
}
|
|