|
using LitJson;
|
using System.Collections.Generic;
|
using System;
|
|
namespace vnxbqy.UI
|
{
|
|
public class NewYearFairylandCeremonyModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
|
{
|
public ReceiveState receiveState { get; private set; }
|
|
public override void Init()
|
{
|
ParseFuncConfig();
|
ParseAllPeoplePartyConfig();
|
ParseUniquenessArriveConfig();
|
//OperationTimeHepler.Instance.operationEndEvent += OnActiveEnd;
|
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
worldLv = 0;
|
sumHiPoint = 0;
|
preAwardRecord = 0;
|
peopleTaskRecordDict.Clear();
|
receiveState = ReceiveState.NoReach;
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
CheckRechargeRed();
|
CheckPeoplePartyRed();
|
}
|
#region 处理服务端数据
|
public int worldLv { get; private set;}
|
public void GetServerActiveInfo(HAC0B_tagGCNewFairyCeremonyInfo info)
|
{
|
worldLv = info.WorldLV;
|
OperationTimeHepler.Instance.RefreshNewYearFairyCeremonyInfo(info);
|
}
|
|
public Action RefreshRechargeStateAct;
|
public void GetServerRechargeInfo(HAA22_tagMCNewXJSDRecharge info)
|
{
|
switch(info.State)
|
{
|
case 0:
|
receiveState = ReceiveState.NoReach;
|
break;
|
case 1:
|
receiveState = ReceiveState.Reach;
|
break;
|
case 2:
|
receiveState = ReceiveState.Already;
|
break;
|
|
}
|
if(RefreshRechargeStateAct != null)
|
{
|
RefreshRechargeStateAct();
|
}
|
CheckRechargeRed();
|
}
|
|
|
public int sumHiPoint { get; private set; }
|
private int preAwardRecord;
|
Dictionary<int, bool> peopleAwardRecordDict = new Dictionary<int, bool>(); //领取记录
|
Dictionary<int, int> peopleTaskRecordDict = new Dictionary<int, int>(); //全民来嗨任务状态记录
|
public Action<int> RefreshHiPointAct;
|
public Action RefreshHiAwardStateAct;
|
|
public void GetServerPeopleInfo(HAA23_tagMCNewAllPeoplePartyInfo info)
|
{
|
peopleAwardRecordDict.Clear();
|
sumHiPoint = (int)info.CurPoint;
|
int sumIndex = GetPeoplePartAwardlist().Count;
|
for (int i = 0; i < sumIndex; i++)
|
{
|
bool isRecord = MathUtility.GetBitValue(info.AwardRecord, (ushort)i);
|
peopleAwardRecordDict.Add(i, isRecord);
|
}
|
|
for(int i = 0; i < info.Count; i++)
|
{
|
if(!peopleTaskRecordDict.ContainsKey((int)info.BuyCountList[i].ActID))
|
{
|
peopleTaskRecordDict.Add((int)info.BuyCountList[i].ActID,info.BuyCountList[i].CurTimes);
|
}
|
else
|
{
|
peopleTaskRecordDict[(int)info.BuyCountList[i].ActID] = info.BuyCountList[i].CurTimes;
|
}
|
|
if(RefreshHiPointAct != null)
|
{
|
RefreshHiPointAct((int)info.BuyCountList[i].ActID);
|
}
|
}
|
|
if(preAwardRecord != info.AwardRecord)
|
{
|
if(RefreshHiAwardStateAct != null)
|
{
|
RefreshHiAwardStateAct();
|
}
|
}
|
CheckPeoplePartyRed();
|
preAwardRecord = (int)info.AwardRecord;
|
}
|
|
public int GetPeopleTaskTimesById(int actId)
|
{
|
int times = 0;
|
peopleTaskRecordDict.TryGetValue(actId,out times);
|
return times;
|
}
|
|
public bool GetPeopleAwardRecordByIndex(int index)
|
{
|
bool isReceive = false;
|
peopleAwardRecordDict.TryGetValue(index,out isReceive);
|
return isReceive;
|
}
|
|
private void OnActiveEnd(Operation type, int arg2)
|
{
|
if (type != Operation.NewYearFairyCeremony) return;
|
|
peopleTaskRecordDict.Clear();
|
sumHiPoint = 0;
|
worldLv = 0;
|
}
|
|
public void SendReceiveAward(GotServerRewardType type,int index)
|
{
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = (byte)type;
|
getReward.DataEx = (uint)index;
|
getReward.DataExStrLen = 0;
|
getReward.DataExStr = string.Empty;
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
|
public void SendGetRankInfo(RankType type)
|
{
|
C1001_tagCWatchBillboard rankPack = new C1001_tagCWatchBillboard();
|
rankPack.Type = (byte)type;
|
GameNetSystem.Instance.SendInfo(rankPack);
|
}
|
#endregion
|
|
#region 处理本地数据
|
|
#region 解析功能配置表
|
Dictionary<CeremonyType, Dictionary<int, List<int>>> typeLvDict = new Dictionary<CeremonyType, Dictionary<int, List<int>>>();
|
Dictionary<int, List<AwardItem>> rechargeAwardDict = new Dictionary<int, List<AwardItem>>();
|
public Dictionary<int, int> fireDict = new Dictionary<int, int>();
|
Dictionary<int, Dictionary<int, List<AwardItem>>> fireGiftsDict = new Dictionary<int, Dictionary<int, List<AwardItem>>>();
|
|
private void ParseFuncConfig()
|
{
|
FuncConfigConfig lvConfig = FuncConfigConfig.Get("NewCeremonyWorldLv");
|
JsonData lvData = JsonMapper.ToObject(lvConfig.Numerical1);
|
foreach (var type in lvData.Keys)
|
{
|
Dictionary<int, List<int>> lvDict = new Dictionary<int, List<int>>();
|
typeLvDict.Add((CeremonyType)int.Parse(type), lvDict);
|
if (lvData[type].IsArray)
|
{
|
for (int i = 0; i < lvData[type].Count; i++)
|
{
|
JsonData rangeData = lvData[type][i];
|
List<int> lvlist = new List<int>();
|
lvDict.Add(i, lvlist);
|
lvlist.Add(int.Parse(rangeData[0].ToString()));
|
lvlist.Add(int.Parse(rangeData[1].ToString()));
|
}
|
}
|
}
|
|
FuncConfigConfig rechargeConfig = FuncConfigConfig.Get("NewCeremonyRecharge");
|
JsonData rechargeData = JsonMapper.ToObject(rechargeConfig.Numerical1);
|
foreach (var index in rechargeData.Keys)
|
{
|
List<AwardItem> awardItems = new List<AwardItem>();
|
rechargeAwardDict.Add(int.Parse(index), awardItems);
|
if (rechargeData[index].IsArray)
|
{
|
for (int i = 0; i < rechargeData[index].Count; i++)
|
{
|
JsonData itemData = rechargeData[index][i];
|
AwardItem item = new AwardItem(int.Parse(itemData[0].ToString()), int.Parse(itemData[1].ToString()),
|
int.Parse(itemData[2].ToString()));
|
awardItems.Add(item);
|
}
|
}
|
}
|
|
FuncConfigConfig fireConfig = FuncConfigConfig.Get("NewCeremonyFireParty");
|
JsonData fireData = JsonMapper.ToObject(fireConfig.Numerical1);
|
foreach (var index in fireData.Keys)
|
{
|
fireDict.Add(int.Parse(index), int.Parse(fireData[index].ToString()));
|
}
|
|
FuncConfigConfig fireAwardConfig = FuncConfigConfig.Get("NewCeremonyFireAward");
|
JsonData fireAwardData = JsonMapper.ToObject(fireAwardConfig.Numerical1);
|
foreach (var index in fireAwardData.Keys)
|
{
|
Dictionary<int, List<AwardItem>> jobFireAwardDict = new Dictionary<int, List<AwardItem>>();
|
fireGiftsDict.Add(int.Parse(index), jobFireAwardDict);
|
foreach (var job in fireAwardData[index].Keys)
|
{
|
List<AwardItem> awardItems = new List<AwardItem>();
|
jobFireAwardDict.Add(int.Parse(job), awardItems);
|
if (fireAwardData[index][job].IsArray)
|
{
|
for (int i = 0; i < fireAwardData[index][job].Count; i++)
|
{
|
JsonData itemData = fireAwardData[index][job][i];
|
AwardItem item = new AwardItem(int.Parse(itemData[0].ToString()), int.Parse(itemData[1].ToString()),
|
int.Parse(itemData[2].ToString()));
|
awardItems.Add(item);
|
}
|
}
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#region 解析全民来嗨
|
List<NewAllPeoplePartyConfig> allPeoples = new List<NewAllPeoplePartyConfig>();
|
List<NewAllPeoplePartyAwardConfig> allPeopleAwards = new List<NewAllPeoplePartyAwardConfig>();
|
Dictionary<int, Dictionary<int, List<AwardItem>>> jobToHiAwardDict = new Dictionary<int, Dictionary<int, List<AwardItem>>>();
|
private void ParseAllPeoplePartyConfig()
|
{
|
allPeoples = NewAllPeoplePartyConfig.GetValues();
|
allPeopleAwards = NewAllPeoplePartyAwardConfig.GetValues();
|
for (int i = 0; i < allPeopleAwards.Count; i++)
|
{
|
Dictionary<int, List<AwardItem>> awardKeyDict = new Dictionary<int, List<AwardItem>>();
|
jobToHiAwardDict.Add(allPeopleAwards[i].ID, awardKeyDict);
|
JsonData awardData = JsonMapper.ToObject(allPeopleAwards[i].Award);
|
foreach (var job in awardData.Keys)
|
{
|
List<AwardItem> awardItems = new List<AwardItem>();
|
awardKeyDict.Add(int.Parse(job), awardItems);
|
if (awardData[job].IsArray)
|
{
|
for (int j = 0; j < awardData[job].Count; j++)
|
{
|
JsonData itemData = awardData[job][j];
|
AwardItem item = new AwardItem(int.Parse(itemData[0].ToString()), int.Parse(itemData[1].ToString()),
|
int.Parse(itemData[2].ToString()));
|
awardItems.Add(item);
|
}
|
}
|
}
|
}
|
}
|
#endregion
|
|
#region 解析绝版降临
|
Dictionary<string, Dictionary<int, List<AwardItem>>> rankAwardDict = new Dictionary<string, Dictionary<int, List<AwardItem>>>();
|
private void ParseUniquenessArriveConfig()
|
{
|
List<NewUniquenessArriveConfig> arriveConfigs = NewUniquenessArriveConfig.GetValues();
|
for (int i = 0; i < arriveConfigs.Count; i++)
|
{
|
string key = StringUtility.Contact(arriveConfigs[i].WorldLvNum, arriveConfigs[i].Rank);
|
Dictionary<int, List<AwardItem>> awardKeyDict = new Dictionary<int, List<AwardItem>>();
|
rankAwardDict.Add(key, awardKeyDict);
|
JsonData awardData = JsonMapper.ToObject(arriveConfigs[i].Award);
|
foreach (var job in awardData.Keys)
|
{
|
List<AwardItem> awardItems = new List<AwardItem>();
|
awardKeyDict.Add(int.Parse(job), awardItems);
|
if (awardData[job].IsArray)
|
{
|
for (int j = 0; j < awardData[job].Count; j++)
|
{
|
JsonData itemData = awardData[job][j];
|
AwardItem item = new AwardItem(int.Parse(itemData[0].ToString()), int.Parse(itemData[1].ToString()),
|
int.Parse(itemData[2].ToString()));
|
awardItems.Add(item);
|
}
|
}
|
}
|
}
|
}
|
#endregion
|
|
public int GetWorldLvIndex(CeremonyType type)
|
{
|
if(typeLvDict.ContainsKey(type))
|
{
|
foreach(var index in typeLvDict[type].Keys)
|
{
|
if(worldLv >= typeLvDict[type][index][0] && worldLv <= typeLvDict[type][index][1])
|
{
|
return index;
|
}
|
}
|
}
|
return -1;
|
}
|
|
public List<AwardItem> GetRechargeAwardByLv()
|
{
|
int index = GetWorldLvIndex(CeremonyType.Recharge);
|
List<AwardItem> awardItems = null;
|
rechargeAwardDict.TryGetValue(index,out awardItems);
|
return awardItems;
|
}
|
|
public StoreConfig GetFireIdByLv()
|
{
|
int index = GetWorldLvIndex(CeremonyType.Fire);
|
int storeId = 0;
|
fireDict.TryGetValue(index,out storeId);
|
StoreConfig storeConfig = StoreConfig.Get(storeId);
|
return storeConfig;
|
}
|
|
public List<AwardItem> GetFireAwardlist()
|
{
|
int index = GetWorldLvIndex(CeremonyType.Fire);
|
if(fireGiftsDict.ContainsKey(index))
|
{
|
if(fireGiftsDict[index].ContainsKey(PlayerDatas.Instance.baseData.Job))
|
{
|
return fireGiftsDict[index][PlayerDatas.Instance.baseData.Job];
|
}
|
}
|
return null;
|
}
|
|
public bool CheckIsBuyFireCondi(StoreConfig storeConfig,int buyNum = 1)
|
{
|
ulong price =(ulong)(storeConfig.MoneyNumber * buyNum);
|
if(UIHelper.GetMoneyCnt(storeConfig.MoneyType) >= price)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
List<NewAllPeoplePartyConfig> openTasklist = new List<NewAllPeoplePartyConfig>();
|
public List<NewAllPeoplePartyConfig> GetPeoplePartTasklist()
|
{
|
openTasklist.Clear();
|
for(int i = 0; i < allPeoples.Count; i++)
|
{
|
var funcId = allPeoples[i].FuncID;
|
if(funcId == 0 || FuncOpen.Instance.IsFuncOpen(funcId))
|
{
|
openTasklist.Add(allPeoples[i]);
|
}
|
}
|
openTasklist.Sort(CompareByTimes);
|
return openTasklist;
|
}
|
|
private int CompareByTimes(NewAllPeoplePartyConfig start, NewAllPeoplePartyConfig end)
|
{
|
bool startIsComplte = PeopleTaskComplete(start);
|
bool endIsComplte = PeopleTaskComplete(end);
|
if (startIsComplte.CompareTo(endIsComplte) != 0) return startIsComplte.CompareTo(endIsComplte);
|
|
int startIndex = allPeoples.IndexOf(start);
|
int endIndex = allPeoples.IndexOf(end);
|
if (startIndex.CompareTo(endIndex) != 0) return startIndex.CompareTo(endIndex);
|
|
return 0;
|
}
|
|
public bool PeopleTaskComplete(NewAllPeoplePartyConfig partyConfig)
|
{
|
if (GetPeopleTaskTimesById(partyConfig.ID) >= partyConfig.TotalTimes)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
List<NewAllPeoplePartyAwardConfig> worldAwardlist = new List<NewAllPeoplePartyAwardConfig>();
|
public List<NewAllPeoplePartyAwardConfig> GetPeoplePartAwardlist()
|
{
|
worldAwardlist.Clear();
|
int index = GetWorldLvIndex(CeremonyType.WholePeople);
|
for (int i = 0; i < allPeopleAwards.Count; i++)
|
{
|
if(allPeopleAwards[i].WorldLvNum == index)
|
{
|
worldAwardlist.Add(allPeopleAwards[i]);
|
}
|
}
|
worldAwardlist.Sort(CompareByIndex);
|
return worldAwardlist;
|
}
|
|
public int CompareByIndex(NewAllPeoplePartyAwardConfig start, NewAllPeoplePartyAwardConfig end)
|
{
|
int startIndex = start.Index;
|
int endIndex = end.Index;
|
if (startIndex.CompareTo(endIndex) != 0) return startIndex.CompareTo(endIndex);
|
|
startIndex = allPeopleAwards.IndexOf(start);
|
endIndex = allPeopleAwards.IndexOf(end);
|
if (startIndex.CompareTo(endIndex) != 0) return startIndex.CompareTo(endIndex);
|
|
return 0;
|
}
|
|
public List<AwardItem> GetPeoplePartyAwardById(int peopleId)
|
{
|
if(jobToHiAwardDict.ContainsKey(peopleId))
|
{
|
if(jobToHiAwardDict[peopleId].ContainsKey(PlayerDatas.Instance.baseData.Job))
|
{
|
return jobToHiAwardDict[peopleId][PlayerDatas.Instance.baseData.Job];
|
}
|
}
|
return null;
|
}
|
|
public List<AwardItem> GetRankAwardByLv(int rank)
|
{
|
int index = GetWorldLvIndex(CeremonyType.OutOfPrint);
|
string key = StringUtility.Contact(index,rank);
|
int playerJob = PlayerDatas.Instance.baseData.Job;
|
|
if(rankAwardDict.ContainsKey(key))
|
{
|
if(rankAwardDict[key].ContainsKey(playerJob))
|
{
|
return rankAwardDict[key][playerJob];
|
}
|
}
|
return null;
|
}
|
#endregion
|
|
#region 红点逻辑处理
|
public const int FairyCeremony_RedKey = 216;
|
public Redpoint fairyCeremonyRedp = new Redpoint(FairyCeremony_RedKey);
|
|
public const int CeremonyRecharge_RedKey = 21601;
|
public Redpoint rechargeRedp = new Redpoint(FairyCeremony_RedKey,CeremonyRecharge_RedKey);
|
public const int RechargeReceiveBtn_RedKey = 2160101;
|
public Redpoint receiveBtnRedp = new Redpoint(CeremonyRecharge_RedKey, RechargeReceiveBtn_RedKey);
|
public void CheckRechargeRed()
|
{
|
if (!OperationTimeHepler.Instance.SatisfyOpenCondition(Operation.NewYearFairyCeremony)) return;
|
|
if(receiveState == ReceiveState.Reach)
|
{
|
receiveBtnRedp.state = RedPointState.Simple;
|
}
|
else
|
{
|
receiveBtnRedp.state = RedPointState.None;
|
}
|
}
|
|
public const int CeremonyPeople_RedKey = 21603;
|
public Redpoint peopleRedp = new Redpoint(FairyCeremony_RedKey, CeremonyPeople_RedKey);
|
|
public void CheckPeoplePartyRed()
|
{
|
if (!OperationTimeHepler.Instance.SatisfyOpenCondition(Operation.NewYearFairyCeremony)) return;
|
|
int index = 0;
|
if(IsPeopleAwardRecive(out index))
|
{
|
peopleRedp.state = RedPointState.Simple;
|
}
|
else
|
{
|
peopleRedp.state = RedPointState.None;
|
}
|
}
|
#endregion
|
|
public bool IsPeopleAwardRecive(out int index)
|
{
|
index = 0;
|
if (worldAwardlist.Count < 1) return false;
|
|
for (int i = 0; i < worldAwardlist.Count; i++)
|
{
|
if (!GetPeopleAwardRecordByIndex(worldAwardlist[i].Index))
|
{
|
if (sumHiPoint >= worldAwardlist[i].NeedPoint)
|
{
|
index = i;
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
public struct AwardItem
|
{
|
public int itemId { get; private set;}
|
public int itemCount { get; private set; }
|
public int isBind { get; private set; }
|
public AwardItem(int id,int cnt,int isBind)
|
{
|
this.itemId = id;
|
this.itemCount = cnt;
|
this.isBind = isBind;
|
}
|
}
|
|
public enum ReceiveState
|
{
|
NoReach, //未充值
|
Reach, //可领取
|
Already, //已领取
|
}
|
/// <summary>
|
/// 庆典类型
|
/// </summary>
|
public enum CeremonyType
|
{
|
Recharge = 1, // 充值
|
Fire = 2, //烟花
|
WholePeople = 3, //全民
|
OutOfPrint = 4, //绝版降临
|
}
|
}
|
}
|