using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
using System.Linq;
|
using LitJson;
|
|
//跨服充值 功能废弃
|
public class CSRechargeModel :ILModel<CSRechargeModel>
|
{
|
public event Action UpdatePlayerBillboardEvent;
|
public event Action onRechargeInfoUpdate;
|
|
public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_JCHD;
|
//精彩活动表中的ID
|
public const int activityID = 36;
|
public const Operation operationType = Operation.default7; //跨服充值
|
public ILOpenServerActivityProxy activity;
|
|
public Dictionary<int, Redpoint> titleRedpoints = new Dictionary<int, Redpoint>();
|
public Dictionary<uint, int> getRechareDic = new Dictionary<uint, int>();
|
public const int redpointID = 20936;
|
public Redpoint redpoint = new Redpoint(MainRedDot.REDPOINT_OPENSERVER, redpointID);
|
public List<int> rechargeList = new List<int>(); //活动可参与的充值档次
|
public bool IsEnd = false;
|
public uint playerRecharges = 0; // 活动已累计充值RMB
|
uint playerAwardState = 0; // 达标奖励记录,与达标奖励索引位或运算判断是否已领取
|
public List<HC007_tagGCCrossBillboardInfo.tagGCCrossBillboardData> CrossBillboardDataList = new List<HC007_tagGCCrossBillboardInfo.tagGCCrossBillboardData>();
|
|
public int RankIndex;
|
public List<ServerType> serverTypeList = new List<ServerType>();
|
protected override void Init()
|
{
|
activity = new ILOpenServerActivityProxy(IsOpen, IsAdvance, priorityOpen);
|
OpenServerActivityCenter.Instance.Register(activityID, activity, activityType);
|
|
GameEvent.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
ILOperationTimeHepler.Instance.operationTimeUpdateEvent += operationTimeUpdateEvent;
|
}
|
|
protected override void UnInit()
|
{
|
GameEvent.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
|
ILOperationTimeHepler.Instance.operationTimeUpdateEvent -= operationTimeUpdateEvent;
|
}
|
|
public bool IsOpen()
|
{
|
return OperationTimeHepler.Instance.SatisfyOpenCondition(operationType) && !IsEnd;
|
}
|
|
public bool IsAdvance()
|
{
|
return false;
|
}
|
|
public bool priorityOpen()
|
{
|
//红点
|
return redpoint.state == RedPointState.Simple;
|
}
|
|
|
public void OnPlayerLoginOk()
|
{
|
|
}
|
|
//跨服充值排行活动玩家信息
|
public void UpdateCSRechargePlayerInfo(IL_HAA33_tagMCCACTGBillboardPlayerInfo package)
|
{
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
return;
|
}
|
//OperationCSRecharge operation = operationBase as OperationCSRecharge;
|
|
playerRecharges = package.CTGRMBTotal;
|
playerAwardState = package.DabiaoAwardRecord;
|
|
UpdateRedpoint();
|
|
onRechargeInfoUpdate?.Invoke();
|
|
//SendViewCrossBillboard();
|
}
|
// 跨服运营活动结束
|
public void UpdateCSActEnd(IL_HAC12_tagGCCrossActEnd package)
|
{
|
IsEnd = true;
|
}
|
public void OnBeforePlayerDataInitialize()
|
{
|
CrossBillboardDataList.Clear();
|
rechargeList.Clear();
|
getRechareDic.Clear();
|
|
}
|
|
//跨服排行榜信息
|
public void UpdateCSBillboardInfo(HC007_tagGCCrossBillboardInfo package)
|
{
|
if (package.Type != 150)
|
return;
|
CrossBillboardDataList.Clear();
|
RankIndex = -1;
|
for(int i= 0;i < package.BillboardCount;i++)
|
{
|
if (PlayerDatas.Instance.baseData.PlayerID == package.CrossBillboardDataList[i].ID)
|
RankIndex = i + 1;
|
CrossBillboardDataList.Add(package.CrossBillboardDataList[i]);
|
}
|
UpdatePlayerBillboardEvent?.Invoke();
|
|
}
|
private void operationTimeUpdateEvent(Operation type)
|
{
|
if (type == operationType)
|
{
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
return;
|
}
|
OperationCSRecharge operation = operationBase as OperationCSRecharge;
|
|
//用于排版和红点
|
rechargeList = operation.drlcInfoDict.Keys.ToList();
|
rechargeList.Sort();
|
titleRedpoints.Clear();
|
for (int i = 0; i < rechargeList.Count; i++)
|
{
|
titleRedpoints.Add(rechargeList[i], new Redpoint(redpointID, redpointID * 100 + i));
|
}
|
|
UpdateRedpoint();
|
}
|
}
|
|
public void ParseServerName(string json)
|
{
|
var itemArray = LitJson.JsonMapper.ToObject<int[][]>(json);
|
if (itemArray != null)
|
{
|
for (int i = 0; i < itemArray.Length; i++)
|
{
|
var item = itemArray[i];
|
|
int id1 = 0;
|
int.TryParse(item[0].ToString(), out id1);
|
int id2 = 0;
|
int.TryParse(item[1].ToString(), out id2);
|
|
var serverType = new ServerType();
|
serverType.server1 = id1;
|
serverType.server2 = id2;
|
serverTypeList.Add(serverType);
|
}
|
}
|
}
|
|
//获取档位状态 0未达成,1可领取,2已领取
|
public int GetRechargeStateByIndex(int index,int AwardIndex)
|
{
|
if (rechargeList[index] > playerRecharges)
|
return 0;
|
|
//每个数按位存31个激活索引
|
//var listIndex = AwardIndex / 31;
|
var bitIndex = AwardIndex % 31;
|
if (((int)Math.Pow(2, bitIndex) & playerAwardState) == 0)
|
{
|
return 1;
|
}
|
|
return 2;
|
}
|
|
void UpdateRedpoint()
|
{
|
OperationBase operationBase;
|
if (!OperationTimeHepler.Instance.TryGetOperationTime(operationType, out operationBase))
|
{
|
return;
|
}
|
OperationCSRecharge operation = operationBase as OperationCSRecharge;
|
|
var keyList = titleRedpoints.Keys.ToList();
|
for (int i = 0; i < keyList.Count; i++)
|
{
|
titleRedpoints[keyList[i]].state = RedPointState.None;
|
var rechargeList = operation.drlcInfoDict[keyList[i]];
|
int result = GetRechargeStateByIndex(i, rechargeList.AwardIndex);
|
if (getRechareDic.ContainsKey(rechargeList.NeedRMB))
|
{
|
result =getRechareDic[rechargeList.NeedRMB];
|
}
|
if (result == 1)
|
{
|
titleRedpoints[keyList[i]].state = RedPointState.Simple;
|
}
|
}
|
}
|
|
//查看跨服排行榜
|
public void SendViewCrossBillboard()
|
{
|
//OperationBase operationBase;
|
//if (!OperationTimeHepler.Instance.TryGetOperationTime(CSRechargeModel.operationType, out operationBase))
|
//{
|
// return;
|
//}
|
//OperationCSRecharge operation = operationBase as OperationCSRecharge;
|
//var pak = new CC004_tagCGViewCrossBillboard();
|
//pak.Type = 150;
|
//pak.GroupValue1 = (byte)operation.GroupValue; // 活动榜单分组值1,用于查询对应榜单
|
//GameNetSystem.Instance.SendInfo(pak);
|
}
|
//玩家领取奖励
|
public void SendPlayerGetReward(uint RewardIndex)
|
{
|
var pak = new IL_CA504_tagCMPlayerGetReward();
|
pak.RewardType = 36;
|
pak.DataEx = RewardIndex; // 奖励索引
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
|
public class ServerType
|
{
|
public int server1;
|
public int server2;
|
}
|
|
|
}
|