using System;
|
using System.Collections.Generic;
|
|
using Snxxz.UI;
|
using System.Linq;
|
using UnityEngine;
|
using System.Text;
|
|
[XLua.LuaCallCSharp]
|
public class RealmPracticeModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
|
{
|
private Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> OpenRealmPraDict = new Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>>();
|
private SuccessConfig _tagAchievementModel = null;
|
private ItemConfig _tagChinItemModel = null;
|
private FuncOpenLVConfig _tagFuncOpenModel = null;
|
|
AchievementModel _achieveModel;
|
public AchievementModel AchieveModel
|
{
|
get
|
{
|
return _achieveModel ?? (_achieveModel = ModelCenter.Instance.GetModel<AchievementModel>());
|
}
|
}
|
|
public const string PLAYERLV_KEY = "PlayerID";
|
|
public override void Init()
|
{
|
SetRealmFirstTypeRedPoint();
|
SetRealmSecondTypeRedPoint();
|
SetPracTaskRedPoint();
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
_tagAchievementModel = null;
|
_tagChinItemModel = null;
|
_tagFuncOpenModel = null;
|
|
FuncOpen.Instance.OnFuncStateChangeEvent -= RefreshFuncOpenState;
|
AchieveModel.achievementProgressUpdateEvent -= RefreshAchieveState;
|
AchieveModel.achievementCompletedEvent -= RefreshAchieveState;
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
|
}
|
|
|
public void OnPlayerLoginOk()
|
{
|
RefreshFuncOpenState((int)FuncOpenEnum.Realm);
|
FuncOpen.Instance.OnFuncStateChangeEvent += RefreshFuncOpenState;
|
AchieveModel.achievementProgressUpdateEvent += RefreshAchieveState;
|
AchieveModel.achievementCompletedEvent += RefreshAchieveState;
|
}
|
|
public override void UnInit()
|
{
|
|
}
|
|
private void RefreshFuncOpenState(int funcId)
|
{
|
if(FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Realm))
|
{
|
RefreshOpenPracModel();
|
}
|
|
if (funcId != (int)FuncOpenEnum.Realm) return;
|
|
RealmTypeRedPointCtrl();
|
}
|
|
public void RefreshOpenPracModel()
|
{
|
OpenRealmPraDict.Clear();
|
Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> realmPraDict = RealmPracticeConfig.GetRealmPraDict();
|
foreach(var first in realmPraDict.Keys)
|
{
|
Dictionary<int, List<RealmPracticeConfig>> secondDict = new Dictionary<int, List<RealmPracticeConfig>>();
|
OpenRealmPraDict.Add(first,secondDict);
|
foreach(var second in realmPraDict[first].Keys)
|
{
|
List<RealmPracticeConfig> praclist = realmPraDict[first][second];
|
for(int i = 0; i < praclist.Count; i++)
|
{
|
if(!secondDict.ContainsKey(second))
|
{
|
List<RealmPracticeConfig> list = new List<RealmPracticeConfig>();
|
list.Add(praclist[i]);
|
if(praclist[i].FunctionID == 0)
|
{
|
secondDict.Add(second,list);
|
}
|
else
|
{
|
if (FuncOpen.Instance.IsFuncOpen(praclist[i].FunctionID))
|
{
|
secondDict.Add(second, list);
|
}
|
}
|
}
|
else
|
{
|
if (praclist[i].FunctionID == 0)
|
{
|
secondDict[second].Add(praclist[i]);
|
}
|
else
|
{
|
if (FuncOpen.Instance.IsFuncOpen(praclist[i].FunctionID))
|
{
|
secondDict[second].Add(praclist[i]);
|
}
|
}
|
|
}
|
}
|
}
|
}
|
}
|
|
private List<RealmPracticeConfig> GetOpenRealmPralist(int firstType,int secondType)
|
{
|
if(OpenRealmPraDict.ContainsKey(firstType))
|
{
|
if(OpenRealmPraDict[firstType].ContainsKey(secondType))
|
{
|
return OpenRealmPraDict[firstType][secondType];
|
}
|
}
|
return null;
|
}
|
|
public Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> GetAllOpenRealmPra()
|
{
|
return OpenRealmPraDict;
|
}
|
|
private List<RealmPracticeConfig> orderlist = new List<RealmPracticeConfig>();
|
private List<RealmPracticeConfig> OpenPraclist;
|
public List<RealmPracticeConfig> GetRealmPracticelist(int firstType,int secondType)
|
{
|
orderlist.Clear();
|
OpenPraclist = GetOpenRealmPralist(firstType,secondType);
|
if (OpenPraclist == null) return orderlist;
|
|
orderlist.AddRange(OpenPraclist);
|
orderlist.Sort(CompareTaskState);
|
return orderlist;
|
}
|
|
private int CompareTaskState(RealmPracticeConfig start, RealmPracticeConfig next)
|
{
|
Achievement startAchieve = null;
|
SetAchievement(start.AchieveID, out startAchieve);
|
Achievement nextAchieve = null;
|
SetAchievement(next.AchieveID, out nextAchieve);
|
|
bool x = IsReach(startAchieve);
|
bool y = IsReach(nextAchieve);
|
if (x.CompareTo(y) != 0) return -x.CompareTo(y);
|
|
x = IsCompleted(startAchieve);
|
y = IsCompleted(nextAchieve);
|
if (x.CompareTo(y) != 0) return x.CompareTo(y);
|
|
int orderx = OpenPraclist.IndexOf(start);
|
int ordery = OpenPraclist.IndexOf(next);
|
if (orderx.CompareTo(ordery) != 0)
|
return orderx.CompareTo(ordery);
|
|
return 0;
|
}
|
|
private bool IsReach(Achievement achieve)
|
{
|
bool isReach = false;
|
if(!achieve.completed)
|
{
|
if(Achievement.IsReach(achieve.id, achieve.progress))
|
{
|
isReach = true;
|
}
|
}
|
return isReach;
|
}
|
|
private bool IsCompleted(Achievement achieve)
|
{
|
return achieve.completed;
|
}
|
|
public SuccessConfig GetTagSuccessModel(int achievementId)
|
{
|
_tagAchievementModel = SuccessConfig.Get(achievementId);
|
if (_tagAchievementModel != null)
|
return _tagAchievementModel;
|
else
|
return null;
|
|
}
|
|
|
public ItemConfig GeTagChinItemModel(int Id)
|
{
|
_tagChinItemModel = ItemConfig.Get(Id);
|
if (_tagChinItemModel != null)
|
return _tagChinItemModel;
|
else
|
return null;
|
|
}
|
public int SetAchievement(int[] idlist,out Achievement achieve)
|
{
|
achieve = null;
|
int k = 0;
|
for (k = 0; k < idlist.Length; k++)
|
{
|
if (AchieveModel.TryGetAchievement(idlist[k], out achieve))
|
{
|
if (!achieve.completed)
|
{
|
return k;
|
}
|
else
|
{
|
if (idlist[idlist.Length - 1] == achieve.id)
|
{
|
return idlist.Length;
|
}
|
}
|
}
|
}
|
return -1;
|
|
}
|
|
private StringBuilder _pointStr = new StringBuilder();
|
|
public string GetPracticePointStr(int firstType,int secondType = 0)
|
{
|
_pointStr.Length = 0;
|
string s = "";
|
List<RealmPracticeConfig> typelist = GetOpenRealmPralist(firstType,secondType);
|
List<RealmPracticeConfig> alllist = RealmPracticeConfig.GetRealmPraAchieveBySecondType(firstType,secondType);
|
if (typelist != null)
|
{
|
if (secondType != 0)
|
{
|
s = alllist[0].SecondTypeName;
|
_pointStr.AppendFormat("<Img img={0}/>{1}/{2}", "Money_Type_13", UIHelper.ReplaceLargeNum(GetRealmPraPointByType(firstType, secondType, false)), UIHelper.ReplaceLargeNum(GetRealmPraPointByType(firstType,secondType)));
|
s = StringUtility.Contact(s, "\n", "(", _pointStr.ToString(), ")");
|
}
|
else
|
{
|
s = alllist[0].FirstTypeName;
|
}
|
}
|
else
|
{
|
alllist = RealmPracticeConfig.GetRealmPraAchieveBySecondType(firstType,1);
|
s = alllist[0].FirstTypeName;
|
}
|
return s;
|
|
}
|
|
public int GetRealmPraPointByType(int firstType,int secondType = 0,bool isSumRealmPraPoint = true)
|
{
|
if (!OpenRealmPraDict.ContainsKey(firstType)) return 0;
|
|
int sumPoint = 0;
|
Dictionary<int, List<RealmPracticeConfig>> secondDict = OpenRealmPraDict[firstType];
|
|
if(secondType == 0)
|
{
|
foreach (var second in secondDict.Keys)
|
{
|
for (int i = 0; i < secondDict[second].Count; i++)
|
{
|
RealmPracticeConfig config = secondDict[second][i];
|
sumPoint += GetAchieveRealmPraPoint(config,isSumRealmPraPoint);
|
}
|
}
|
}
|
else
|
{
|
if(secondDict.ContainsKey(secondType))
|
{
|
for (int i = 0; i < secondDict[secondType].Count; i++)
|
{
|
RealmPracticeConfig config = secondDict[secondType][i];
|
sumPoint += GetAchieveRealmPraPoint(config,isSumRealmPraPoint);
|
}
|
}
|
}
|
|
return sumPoint;
|
}
|
|
private int GetAchieveRealmPraPoint(RealmPracticeConfig config,bool isSumRealmPraPoint)
|
{
|
if (config == null) return 0;
|
|
int[] idlist = config.AchieveID;
|
int realmPraPoint = 0;
|
for (int j = 0; j < idlist.Length; j++)
|
{
|
Achievement achieve = null;
|
AchieveModel.TryGetAchievement(idlist[j], out achieve);
|
if (achieve != null)
|
{
|
if(isSumRealmPraPoint)
|
{
|
int k = 0;
|
for (k = 0; k < achieve.rewardCurrency.Length; k++)
|
{
|
if (achieve.rewardCurrency[k].id == 13)
|
{
|
realmPraPoint += achieve.rewardCurrency[k].count;
|
}
|
}
|
}
|
else
|
{
|
if (achieve.completed)
|
{
|
int k = 0;
|
for (k = 0; k < achieve.rewardCurrency.Length; k++)
|
{
|
if (achieve.rewardCurrency[k].id == 13)
|
{
|
realmPraPoint += achieve.rewardCurrency[k].count;
|
}
|
}
|
}
|
}
|
|
}
|
}
|
return realmPraPoint;
|
}
|
|
#region 红点逻辑
|
public const int REALMREDPOINT_KEY = 114;
|
public const int REALMPRAFUNCREDPOINT_KEY = 11402;
|
public Redpoint realmPraRedPoint = new Redpoint(REALMREDPOINT_KEY, REALMPRAFUNCREDPOINT_KEY);
|
|
public Dictionary<int,Redpoint> realmFirstTypeDict { get;private set; }
|
private void SetRealmFirstTypeRedPoint()
|
{
|
realmFirstTypeDict = null;
|
Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> realmPraDict = RealmPracticeConfig.GetRealmPraDict();
|
realmFirstTypeDict = new Dictionary<int, Redpoint>();
|
int i = 0;
|
foreach(var type in realmPraDict.Keys)
|
{
|
int id = REALMPRAFUNCREDPOINT_KEY * 100 + i;
|
Redpoint redpoint = new Redpoint(REALMPRAFUNCREDPOINT_KEY, id);
|
realmFirstTypeDict.Add(type, redpoint);
|
i += 1;
|
}
|
}
|
public Dictionary<int, Dictionary<int, Redpoint>> realmSecondTypeDict { get; private set; }
|
private void SetRealmSecondTypeRedPoint()
|
{
|
realmSecondTypeDict = null;
|
Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> realmPraDict = RealmPracticeConfig.GetRealmPraDict();
|
realmSecondTypeDict = new Dictionary<int, Dictionary<int, Redpoint>>();
|
int i = 0;
|
foreach (var type in realmPraDict.Keys)
|
{
|
Dictionary<int, Redpoint> secondRedDict = new Dictionary<int, Redpoint>();
|
realmSecondTypeDict.Add(type,secondRedDict);
|
foreach (var second in realmPraDict[type].Keys)
|
{
|
if(second != 0)
|
{
|
int id = realmFirstTypeDict[type].id * 100 + i;
|
Redpoint redpoint = new Redpoint(realmFirstTypeDict[type].id, id);
|
secondRedDict.Add(second, redpoint);
|
i += 1;
|
}
|
}
|
}
|
}
|
|
|
private Dictionary<int, Redpoint> PracTaskRedPointDict = new Dictionary<int, Redpoint>(); //id 流水号
|
private void SetPracTaskRedPoint()
|
{
|
PracTaskRedPointDict.Clear();
|
Dictionary<int, Dictionary<int, List<RealmPracticeConfig>>> realmPraDict = RealmPracticeConfig.GetRealmPraDict();
|
foreach(var first in realmPraDict.Keys)
|
{
|
foreach(var second in realmPraDict[first].Keys)
|
{
|
List<RealmPracticeConfig> pralist = realmPraDict[first][second];
|
Redpoint redpointType;
|
if(second != 0)
|
{
|
redpointType = realmSecondTypeDict[first][second];
|
}
|
else
|
{
|
redpointType = realmFirstTypeDict[first];
|
}
|
for (int i = 0; i < pralist.Count; i++)
|
{
|
int id = redpointType.id * 10000 + i;
|
Redpoint redpoint = new Redpoint(redpointType.id, id);
|
if (!PracTaskRedPointDict.ContainsKey(pralist[i].ID))
|
{
|
PracTaskRedPointDict.Add(pralist[i].ID, redpoint);
|
}
|
}
|
}
|
}
|
}
|
|
public void RealmTypeRedPointCtrl()
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Realm)) return;
|
|
foreach(var first in OpenRealmPraDict.Keys)
|
{
|
foreach(var second in OpenRealmPraDict[first].Keys)
|
{
|
List<RealmPracticeConfig> praclist = OpenRealmPraDict[first][second];
|
for (int j = 0; j < praclist.Count; j++)
|
{
|
Achievement achieve = null;
|
SetAchievement(praclist[j].AchieveID, out achieve);
|
if (IsReachAchieve(achieve))
|
{
|
if (PracTaskRedPointDict[praclist[j].ID].state != RedPointState.Simple)
|
{
|
PracTaskRedPointDict[praclist[j].ID].state = RedPointState.Simple;
|
}
|
}
|
else
|
{
|
if (PracTaskRedPointDict[praclist[j].ID].state != RedPointState.None)
|
{
|
PracTaskRedPointDict[praclist[j].ID].state = RedPointState.None;
|
}
|
}
|
|
}
|
}
|
}
|
}
|
|
public void RefreshAchieveState(int id)
|
{
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Realm)) return;
|
|
SuccessConfig successConfig = SuccessConfig.Get(id);
|
if (successConfig != null)
|
{
|
RealmPracticeConfig practiceConfig = RealmPracticeConfig.Get(successConfig.RealmPracticeID);
|
if (practiceConfig == null) return;
|
|
if(OpenRealmPraDict.ContainsKey(practiceConfig.Type))
|
{
|
if(OpenRealmPraDict[practiceConfig.Type].ContainsKey(practiceConfig.SecondType))
|
{
|
Achievement achieve = null;
|
SetAchievement(practiceConfig.AchieveID, out achieve);
|
|
if (IsReachAchieve(achieve))
|
{
|
if (PracTaskRedPointDict[successConfig.RealmPracticeID].state != RedPointState.Simple)
|
{
|
PracTaskRedPointDict[successConfig.RealmPracticeID].state = RedPointState.Simple;
|
}
|
}
|
else
|
{
|
if (PracTaskRedPointDict[successConfig.RealmPracticeID].state != RedPointState.None)
|
{
|
PracTaskRedPointDict[successConfig.RealmPracticeID].state = RedPointState.None;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
public bool IsReachAchieve(Achievement achieve)
|
{
|
if (achieve == null) return false;
|
bool isReach = false;
|
|
if(!achieve.completed)
|
{
|
if (Achievement.IsReach(achieve.id, achieve.progress))
|
{
|
isReach = true;
|
}
|
}
|
return isReach;
|
}
|
#endregion
|
|
}
|