|
using LitJson;
|
using System.Collections.Generic;
|
using System;
|
using System.Linq;
|
|
namespace Snxxz.UI
|
{
|
[XLua.LuaCallCSharp]
|
public class TreasureFindHostModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
|
{
|
private Dictionary<int, List<FindTreasureInfo>> findTreasureDict = new Dictionary<int, List<FindTreasureInfo>>();
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
|
public List<int> treasureIdlist { get; set; }
|
public event Action TreasureFindHostCompleteAct;
|
public int[] specEquipIds { get; private set;}
|
|
public override void Init()
|
{
|
findTreasureDict.Clear();
|
List<TreasureFindHostConfig> findlist = TreasureFindHostConfig.GetValues();
|
for(int i = 0; i < findlist.Count; i++)
|
{
|
int treasureId = findlist[i].MagicWeaponID;
|
if(!findTreasureDict.ContainsKey(treasureId))
|
{
|
List<FindTreasureInfo> infolist = new List<FindTreasureInfo>();
|
FindTreasureInfo treasureInfo = new FindTreasureInfo(findlist[i].ID);
|
infolist.Add(treasureInfo);
|
findTreasureDict.Add(treasureId,infolist);
|
}
|
else
|
{
|
FindTreasureInfo treasureInfo = new FindTreasureInfo(findlist[i].ID);
|
findTreasureDict[treasureId].Add(treasureInfo);
|
}
|
}
|
|
treasureIdlist = findTreasureDict.Keys.ToList();
|
SetTreasureCellRedKey();
|
PlayerDatas.Instance.playerDataRefreshEvent += RefreshPlayerData;
|
playerPack.refreshItemCountEvent += RefreshEquipInfo;
|
treasureModel.treasureStateChangeEvent += RefreshTreasureState;
|
FuncConfigConfig SamboSpecialUnlock = FuncConfigConfig.Get("SamboSpecialUnlock");
|
specEquipIds = ConfigParse.GetMultipleStr<int>(SamboSpecialUnlock.Numerical1);
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
jumpTreasureId = 0;
|
foreach (var list in findTreasureDict.Values)
|
{
|
for (int i = 0; i < list.Count; i++)
|
{
|
list[i].IsCompleted = false;
|
}
|
}
|
}
|
|
public void OnAfterPlayerDataInitialize()
|
{
|
|
}
|
|
public void OnPlayerLoginOk()
|
{
|
for (int i = 0; i < treasureIdlist.Count; i++)
|
{
|
if (i == 0)
|
{
|
RedPointStateCtrl(treasureIdlist[i]);
|
}
|
else
|
{
|
Treasure treasure = null;
|
treasureModel.TryGetTreasure(treasureIdlist[i - 1], out treasure);
|
if (treasure != null && treasure.state == TreasureState.Collected)
|
{
|
RedPointStateCtrl(treasureIdlist[i]);
|
}
|
}
|
}
|
|
TreasureFindHostState();
|
}
|
|
public override void UnInit()
|
{
|
PlayerDatas.Instance.playerDataRefreshEvent -= RefreshPlayerData;
|
playerPack.refreshItemCountEvent -= RefreshEquipInfo;
|
treasureModel.treasureStateChangeEvent -= RefreshTreasureState;
|
}
|
|
public Dictionary<int, List<FindTreasureInfo>> GetFindTreasureInfoDict()
|
{
|
return findTreasureDict;
|
}
|
|
public bool IsReachCondition(FindTreasureInfo treasureInfo,out int progress)
|
{
|
progress = 0;
|
if (treasureInfo == null) return false;
|
|
switch(treasureInfo.type)
|
{
|
case 1:
|
return CheckType1IsReachCondition(treasureInfo, out progress);
|
case 2:
|
return CheckType2IsReachCondition(treasureInfo, out progress);
|
case 3:
|
return CheckType3IsReachCondition(treasureInfo, out progress);
|
case 4:
|
return CheckType4IsReachCondition(treasureInfo,out progress);
|
}
|
return false;
|
}
|
|
private bool CheckType1IsReachCondition(FindTreasureInfo treasureInfo, out int progress)
|
{
|
progress = PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.CDBPlayerRefresh_FuncDef);
|
if(progress < treasureInfo.targetNum)
|
{
|
return false;
|
}
|
else
|
{
|
return true;
|
}
|
}
|
|
private bool CheckType2IsReachCondition(FindTreasureInfo treasureInfo, out int progress)
|
{
|
progress = 0;
|
SinglePack singlePack = playerPack.GetSinglePack(PackType.Equip);
|
if (singlePack == null) return false;
|
|
|
foreach (var condi in treasureInfo.needConditionsDict.Values)
|
{
|
progress = 0;
|
ItemModel itemModel = playerPack.GetItemByIndex(PackType.Equip,condi[3]);
|
if(itemModel != null)
|
{
|
if(specEquipIds != null && specEquipIds.Contains(itemModel.itemId))
|
{
|
progress += 1;
|
return true;
|
}
|
if(itemModel.config.LV >= condi[0]
|
&& itemModel.config.ItemColor >= condi[1]
|
&& itemModel.config.StarLevel >= condi[2])
|
{
|
progress += 1;
|
return true;
|
}
|
}
|
}
|
return false;
|
}
|
|
private bool CheckType3IsReachCondition(FindTreasureInfo treasureInfo, out int progress)
|
{
|
progress = 0;
|
SinglePack singlePack = playerPack.GetSinglePack(PackType.Equip);
|
if (singlePack == null) return false;
|
|
Dictionary<int, ItemModel> equipDict = singlePack.GetAllItems();
|
foreach(var model in equipDict.Values)
|
{
|
progress += model.config.StarLevel;
|
}
|
if(progress >= treasureInfo.targetNum)
|
{
|
return true;
|
}
|
return false;
|
}
|
|
private bool CheckType4IsReachCondition(FindTreasureInfo treasureInfo,out int progress)
|
{
|
progress = 0;
|
SinglePack singlePack = playerPack.GetSinglePack(PackType.Equip);
|
if (singlePack == null) return false;
|
|
Dictionary<int, ItemModel> equipDict = singlePack.GetAllItems();
|
foreach(var condi in treasureInfo.needConditionsDict.Values)
|
{
|
progress = 0;
|
if(progress >= treasureInfo.targetNum)
|
{
|
return true;
|
}
|
}
|
|
return false;
|
}
|
|
public bool TryGetFindTreasureInfo(int findId,out FindTreasureInfo info)
|
{
|
info = null;
|
TreasureFindHostConfig hostConfig = TreasureFindHostConfig.Get(findId);
|
if (hostConfig != null)
|
{
|
List<FindTreasureInfo> infolist = null;
|
findTreasureDict.TryGetValue(hostConfig.MagicWeaponID,out infolist);
|
if(infolist != null)
|
{
|
for (int i = 0; i < infolist.Count; i++)
|
{
|
if(infolist[i].id == findId)
|
{
|
info = infolist[i];
|
return true;
|
}
|
}
|
}
|
}
|
return false;
|
}
|
|
public bool IsReachUnlock(int treasureId,out int progress)
|
{
|
progress = 0;
|
List<FindTreasureInfo> infolist = null;
|
findTreasureDict.TryGetValue(treasureId,out infolist);
|
if (infolist == null) return false;
|
|
for(int i = 0; i < infolist.Count; i++)
|
{
|
if(infolist[i].IsCompleted)
|
{
|
progress += 1;
|
}
|
}
|
|
if(progress >= infolist.Count)
|
{
|
return true;
|
}
|
|
return false;
|
}
|
|
private void RefreshTreasureState(int id)
|
{
|
if (!findTreasureDict.ContainsKey(id)) return;
|
|
Treasure treasure = null;
|
treasureModel.TryGetTreasure(id, out treasure);
|
if(treasure.state == TreasureState.Collected)
|
{
|
TreasureFindHostState();
|
for (int i = 0; i < treasureIdlist.Count; i++)
|
{
|
if (treasureIdlist[i] == id)
|
{
|
RedPointStateCtrl(treasureIdlist[i]);
|
if (i < treasureIdlist.Count - 1)
|
{
|
RedPointStateCtrl(treasureIdlist[i + 1]);
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
public void TreasureFindHostState()
|
{
|
if(CheckTreasureFindHostFinish())
|
{
|
if(TreasureFindHostCompleteAct != null)
|
{
|
TreasureFindHostCompleteAct();
|
}
|
}
|
}
|
|
public bool CheckTreasureFindHostFinish()
|
{
|
bool isfinish = true;
|
foreach (var id in findTreasureDict.Keys)
|
{
|
Treasure treasure = null;
|
treasureModel.TryGetTreasure(id, out treasure);
|
if (treasure.state != TreasureState.Collected)
|
{
|
isfinish = false;
|
break;
|
}
|
}
|
return isfinish;
|
}
|
public int jumpTreasureId { get; set;}
|
public bool IsUnlockTreasure(int treasureId)
|
{
|
jumpTreasureId = 0;
|
for (int i = 0; i < treasureIdlist.Count; i++)
|
{
|
if(treasureIdlist[i] == treasureId)
|
{
|
if(i != 0)
|
{
|
Treasure treasure = null;
|
treasureModel.TryGetTreasure(treasureIdlist[i-1], out treasure);
|
if (treasure.state != TreasureState.Collected)
|
{
|
TreasureConfig config = TreasureConfig.Get(treasure.id);
|
SysNotifyMgr.Instance.ShowTip("UnLock_TreasureLimit", config.Name);
|
return false;
|
}
|
else
|
{
|
jumpTreasureId = treasureId;
|
return true;
|
}
|
}
|
else
|
{
|
jumpTreasureId = treasureId;
|
return true;
|
}
|
}
|
}
|
|
return false;
|
}
|
|
public int SelectTreasureId { get; private set; }
|
public void SetSelectTreasureId(int treasureId)
|
{
|
SelectTreasureId = treasureId;
|
}
|
|
public List<int> adviceIdlist = new List<int>();
|
public void SetAdviceIdlist(List<int> idlist)
|
{
|
if (idlist == null || idlist.Count < 1) return;
|
|
adviceIdlist.Clear();
|
adviceIdlist.AddRange(idlist);
|
}
|
|
#region 处理服务端数据
|
public event Action OnCompletedAct;
|
public void GetServerAwardRecord(HA348_tagMCXBXZAwardRecordList awardRecord)
|
{
|
for(int i = 0; i < awardRecord.RecordCnt; i++)
|
{
|
var record = awardRecord.RecordList[i];
|
var index = record.RecordIndex;
|
for(int j = 0; j < 31; j++)
|
{
|
var findHostId = index * 31 + j;
|
FindTreasureInfo treasureInfo;
|
if(TryGetFindTreasureInfo(findHostId,out treasureInfo))
|
{
|
bool isCompleted = MathUtility.GetBitValue(record.Record, (ushort)j);
|
if(isCompleted != treasureInfo.IsCompleted)
|
{
|
treasureInfo.IsCompleted = isCompleted;
|
if (treasureInfo.IsCompleted)
|
{
|
if (OnCompletedAct != null)
|
{
|
OnCompletedAct();
|
}
|
RedPointStateCtrl(treasureInfo.treasureId);
|
}
|
}
|
}
|
}
|
}
|
}
|
|
public void SendGetRewardQuest(int id)
|
{
|
CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
|
getReward.RewardType = (byte)GotServerRewardType.Def_RewardType_XBXZ;
|
getReward.DataEx = (uint)id;
|
getReward.DataExStrLen = 0;
|
getReward.DataExStr = string.Empty;
|
GameNetSystem.Instance.SendInfo(getReward);
|
}
|
#endregion
|
|
#region 红点逻辑
|
public const int MainTop_RedKey = 2;
|
public const int TreasureFindHost_RedKey = 210;
|
public Redpoint mainTopRed = new Redpoint(MainTop_RedKey);
|
public Redpoint findHostRed = new Redpoint(MainTop_RedKey, TreasureFindHost_RedKey);
|
private Dictionary<int, Redpoint> treasureCellRedDict = new Dictionary<int, Redpoint>();
|
public void SetTreasureCellRedKey()
|
{
|
treasureCellRedDict.Clear();
|
int i = 0;
|
foreach(var id in findTreasureDict.Keys)
|
{
|
int redKey = TreasureFindHost_RedKey * 100 + i;
|
Redpoint redpoint = new Redpoint(TreasureFindHost_RedKey,redKey);
|
treasureCellRedDict.Add(id,redpoint);
|
i += 1;
|
}
|
}
|
|
public int GetTreasureCellRedIdById(int treasureId)
|
{
|
if(treasureCellRedDict.ContainsKey(treasureId))
|
{
|
return treasureCellRedDict[treasureId].id;
|
}
|
|
return 0;
|
}
|
|
private void RefreshEquipInfo(PackType type, int index, int itemId)
|
{
|
if (type != PackType.Equip) return;
|
|
for (int i = 0; i < treasureIdlist.Count; i++)
|
{
|
if (i == 0)
|
{
|
RedPointStateCtrl(treasureIdlist[i]);
|
}
|
else
|
{
|
Treasure treasure = null;
|
treasureModel.TryGetTreasure(treasureIdlist[i - 1], out treasure);
|
if (treasure != null && treasure.state == TreasureState.Collected)
|
{
|
RedPointStateCtrl(treasureIdlist[i]);
|
}
|
}
|
}
|
}
|
|
private void RefreshPlayerData(PlayerDataType type)
|
{
|
if (type != PlayerDataType.CDBPlayerRefresh_FuncDef) return;
|
|
for (int i = 0; i < treasureIdlist.Count; i++)
|
{
|
if (i == 0)
|
{
|
RedPointStateCtrl(treasureIdlist[i]);
|
}
|
else
|
{
|
Treasure treasure = null;
|
treasureModel.TryGetTreasure(treasureIdlist[i - 1], out treasure);
|
if (treasure != null && treasure.state == TreasureState.Collected)
|
{
|
RedPointStateCtrl(treasureIdlist[i]);
|
}
|
}
|
}
|
}
|
|
public void RedPointStateCtrl(int treasureId)
|
{
|
if (treasureCellRedDict.ContainsKey(treasureId))
|
{
|
treasureCellRedDict[treasureId].state = RedPointState.None;
|
}
|
if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.TreasureFindHost)) return;
|
|
List<FindTreasureInfo> list = findTreasureDict[treasureId];
|
int progress = 0;
|
for (int i = 0; i < list.Count; i++)
|
{
|
bool isReach = IsReachCondition(list[i],out progress);
|
if(!list[i].IsCompleted && isReach)
|
{
|
treasureCellRedDict[treasureId].state = RedPointState.Simple;
|
return;
|
}
|
}
|
|
Treasure treasure = null;
|
treasureModel.TryGetTreasure(treasureId, out treasure);
|
|
if (IsReachUnlock(treasureId,out progress)
|
&& treasure != null && treasure.state != TreasureState.Collected)
|
{
|
treasureCellRedDict[treasureId].state = RedPointState.Simple;
|
return;
|
}
|
}
|
#endregion
|
}
|
|
public class FindTreasureInfo
|
{
|
public int id;
|
public int treasureId;
|
public int type;
|
public int targetNum;
|
public int jumpId;
|
public Dictionary<int, List<int>> needConditionsDict = new Dictionary<int, List<int>>();
|
public Dictionary<int, List<int>> awardItemDict = new Dictionary<int, List<int>>();
|
public Dictionary<int, List<int>> awardMoneyDict = new Dictionary<int, List<int>>();
|
public Dictionary<int, List<int>> adviceItemIdDict = new Dictionary<int, List<int>>();
|
public bool IsCompleted;
|
public FindTreasureInfo(int id)
|
{
|
needConditionsDict.Clear();
|
awardItemDict.Clear();
|
awardMoneyDict.Clear();
|
adviceItemIdDict.Clear();
|
|
this.id = id;
|
IsCompleted = false;
|
TreasureFindHostConfig hostConfig = TreasureFindHostConfig.Get(id);
|
this.type = hostConfig.Type;
|
this.targetNum = hostConfig.NeedCnt;
|
this.jumpId = hostConfig.JumpID;
|
this.treasureId = hostConfig.MagicWeaponID;
|
JsonData needCondiData = JsonMapper.ToObject(hostConfig.Condition);
|
if(needCondiData.IsArray)
|
{
|
for(int i = 0; i < needCondiData.Count; i++)
|
{
|
List<int> condlist = new List<int>();
|
needConditionsDict.Add(i,condlist);
|
if (needCondiData[i].IsArray)
|
{
|
for(int j = 0; j < needCondiData[i].Count;j++)
|
{
|
condlist.Add(int.Parse(needCondiData[i][j].ToString()));
|
}
|
}
|
else
|
{
|
condlist.Add(int.Parse(needCondiData[i].ToString()));
|
}
|
}
|
}
|
|
JsonData awardItemData = JsonMapper.ToObject(hostConfig.AwardItemList);
|
if(awardItemData.IsArray)
|
{
|
for(int i= 0; i < awardItemData.Count;i++)
|
{
|
List<int> awardlist = new List<int>();
|
awardItemDict.Add(i, awardlist);
|
if (awardItemData[i].IsArray)
|
{
|
for(int j = 0; j < awardItemData[i].Count; j++)
|
{
|
awardlist.Add(int.Parse(awardItemData[i][j].ToString()));
|
}
|
}
|
}
|
}
|
|
JsonData awardMoneyData = JsonMapper.ToObject(hostConfig.Money);
|
if (awardMoneyData.IsArray)
|
{
|
for (int i = 0; i < awardMoneyData.Count; i++)
|
{
|
List<int> awardlist = new List<int>();
|
awardMoneyDict.Add(i, awardlist);
|
if (awardMoneyData[i].IsArray)
|
{
|
for (int j = 0; j < awardMoneyData[i].Count; j++)
|
{
|
awardlist.Add(int.Parse(awardMoneyData[i][j].ToString()));
|
}
|
}
|
}
|
}
|
|
JsonData adviceData = JsonMapper.ToObject(hostConfig.AdviceIds);
|
foreach(var job in adviceData.Keys)
|
{
|
List<int> idlist = new List<int>();
|
adviceItemIdDict.Add(int.Parse(job),idlist);
|
if(adviceData[job].IsArray)
|
{
|
for(int i = 0; i < adviceData[job].Count; i++)
|
{
|
idlist.Add(int.Parse(adviceData[job][i].ToString()));
|
}
|
}
|
}
|
|
}
|
}
|
}
|