|
using LitJson;
|
using System.Collections.Generic;
|
using System;
|
using System.Linq;
|
|
namespace vnxbqy.UI
|
{
|
|
public class TreasureFindHostModel : Model,IBeforePlayerDataInitialize,IAfterPlayerDataInitialize,IPlayerLoginOk
|
{
|
Dictionary<int, List<FindTreasureInfo>> findTreasures = new Dictionary<int, List<FindTreasureInfo>>();
|
|
public List<int> treasureIdlist { get; set; }
|
public event Action TreasureFindHostCompleteAct;
|
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
EquipModel equipModel { get { return ModelCenter.Instance.GetModel<EquipModel>(); } }
|
|
public override void Init()
|
{
|
var configs = TreasureFindHostConfig.GetValues();
|
foreach (var config in configs)
|
{
|
int treasureId = config.MagicWeaponID;
|
List<FindTreasureInfo> list;
|
if (!findTreasures.TryGetValue(treasureId, out list))
|
{
|
list = new List<FindTreasureInfo>();
|
findTreasures.Add(treasureId, list);
|
}
|
var treasureInfo = new FindTreasureInfo(config.ID);
|
list.Add(treasureInfo);
|
}
|
|
treasureIdlist = findTreasures.Keys.ToList();
|
SetTreasureCellRedKey();
|
PlayerDatas.Instance.playerDataRefreshEvent += RefreshPlayerData;
|
packModel.refreshItemCountEvent += RefreshEquipInfo;
|
treasureModel.treasureStateChangeEvent += RefreshTreasureState;
|
}
|
|
public void OnBeforePlayerDataInitialize()
|
{
|
jumpTreasureId = 0;
|
foreach (var list in findTreasures.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;
|
packModel.refreshItemCountEvent -= RefreshEquipInfo;
|
treasureModel.treasureStateChangeEvent -= RefreshTreasureState;
|
}
|
|
public Dictionary<int, List<FindTreasureInfo>> GetFindTreasureInfoDict()
|
{
|
return findTreasures;
|
}
|
|
|
//条件类型 类型说明 数量 条件
|
//1 穿戴X件X价X品质X套装X部位装备 件数[[阶, 品质, 是否套装, 部位]]
|
//2 穿戴X件X价X品质装备 件数[x阶, x品质]
|
//3 X阶装备总强化等级 强化等级[x阶]
|
//4 X阶装备总升星等级 升星等级[x阶]
|
//5 X阶装备总洗炼等级 洗炼等级[x阶]
|
//6 X阶装备总宝石等级 宝石等级[x阶]
|
//7 坐骑达到X阶 阶 无
|
//8 天星塔达到X层 层 无
|
//9 符印塔达到X层 层 无
|
//10 击杀X只BOSS 只数[boss归类索引]
|
//11 神兵达到X级 等级[x类型]
|
//12 玩家等级达到X级 等级 无
|
//13 获得法宝XXX 个数[法宝ID]
|
//14 境界达到XXX 境界 无
|
|
public bool IsReachCondition(FindTreasureInfo treasureInfo, out int findCount)
|
{
|
findCount = 0;
|
if (treasureInfo == null)
|
{
|
return false;
|
}
|
|
switch (treasureInfo.type)
|
{
|
case 1:
|
if (CheckType1IsReachCondition(treasureInfo))
|
{
|
findCount = 1;
|
return true;
|
}
|
return false;
|
case 2:
|
for (int i = 0; i <= 12; i++)
|
{
|
var equipIndex = EquipSet.ClientPlaceToServerPlace(new Int2(treasureInfo.conditions[0], i));
|
var itemModel = packModel.GetItemByIndex(PackType.Equip, equipIndex);
|
if (itemModel != null && itemModel.config.ItemColor >= treasureInfo.conditions[1])
|
{
|
findCount++;
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
}
|
}
|
return false;
|
case 3:
|
findCount = 0;
|
for (int i = 1; i <= 12; i++)
|
{
|
findCount += ModelCenter.Instance.GetModel<EquipStrengthModel>().GetStrengthLevel(treasureInfo.conditions[0], i);
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
}
|
return false;
|
case 4:
|
findCount = ModelCenter.Instance.GetModel<EquipStarModel>().GetTotalStarLevel(treasureInfo.conditions[0]);
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
return false;
|
case 5:
|
findCount = 0;
|
for (int i = 1; i <= 12; i++)
|
{
|
findCount += ModelCenter.Instance.GetModel<EquipTrainModel>().GetTrainLevelEx(new Int2(treasureInfo.conditions[0], i));
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
}
|
return false;
|
case 6:
|
findCount = ModelCenter.Instance.GetModel<EquipGemModel>().GetGemLevelByEquipLevel(treasureInfo.conditions[0]);
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
return false;
|
case 7:
|
findCount = ModelCenter.Instance.GetModel<MountModel>().HorseLV;
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
return false;
|
case 8:
|
findCount = ModelCenter.Instance.GetModel<SkyTowerModel>().highestPassFloor;
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
return false;
|
case 9:
|
findCount = ModelCenter.Instance.GetModel<RuneModel>().passRuneTowerFloor;
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
return false;
|
case 10:
|
if (ModelCenter.Instance.GetModel<FindPreciousModel>().totalKillCountDict.ContainsKey(treasureInfo.conditions[0]))
|
{
|
findCount = ModelCenter.Instance.GetModel<FindPreciousModel>().totalKillCountDict[treasureInfo.conditions[0]];
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
}
|
return false;
|
case 11:
|
var godWeaponInfo = ModelCenter.Instance.GetModel<MagicianModel>().GetGodWeaponInfo(treasureInfo.conditions[0]);
|
if (godWeaponInfo != null)
|
{
|
findCount = godWeaponInfo.level;
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
}
|
return false;
|
case 12:
|
findCount = PlayerDatas.Instance.baseData.LV;
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
return false;
|
case 13:
|
Treasure treasure = null;
|
if (treasureModel.TryGetTreasure(treasureInfo.conditions[0], out treasure))
|
{
|
if (treasure.state == TreasureState.Collected)
|
{
|
findCount = 1;
|
return true;
|
}
|
}
|
return false;
|
case 14:
|
findCount = PlayerDatas.Instance.baseData.realmLevel;
|
if (findCount >= treasureInfo.targetNum)
|
return true;
|
return false;
|
}
|
return false;
|
}
|
|
private bool CheckType1IsReachCondition(FindTreasureInfo treasureInfo)
|
{
|
foreach (var findHostEquip in treasureInfo.findHostEquips)
|
{
|
var equipIndex = EquipSet.ClientPlaceToServerPlace(new Int2(findHostEquip.level, findHostEquip.place));
|
var itemModel = packModel.GetItemByIndex(PackType.Equip, equipIndex);
|
if (itemModel != null)
|
{
|
if (itemModel.config.ItemColor >= findHostEquip.itemColor)
|
{
|
if (findHostEquip.isSuit)
|
{
|
if (ItemLogicUtility.Instance.IsSuitEquip(itemModel.itemId))
|
{
|
return true;
|
}
|
}
|
else
|
{
|
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;
|
findTreasures.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;
|
findTreasures.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 (!findTreasures.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 findTreasures.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 TreasureFindHost_RedKey = 210;
|
public Redpoint findHostRed = new Redpoint(TreasureFindHost_RedKey);
|
private Dictionary<int, Redpoint> treasureCellRedDict = new Dictionary<int, Redpoint>();
|
public void SetTreasureCellRedKey()
|
{
|
treasureCellRedDict.Clear();
|
int i = 0;
|
foreach(var id in findTreasures.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 = findTreasures[treasureId];
|
for (int i = 0; i < list.Count; i++)
|
{
|
int process;
|
bool isReach = IsReachCondition(list[i], out process);
|
if(!list[i].IsCompleted && isReach)
|
{
|
treasureCellRedDict[treasureId].state = RedPointState.Simple;
|
return;
|
}
|
}
|
|
Treasure treasure = null;
|
treasureModel.TryGetTreasure(treasureId, out treasure);
|
|
var progress = 0;
|
if (IsReachUnlock(treasureId,out progress)
|
&& treasure != null && treasure.state != TreasureState.Collected)
|
{
|
treasureCellRedDict[treasureId].state = RedPointState.Simple;
|
return;
|
}
|
}
|
#endregion
|
}
|
|
public class FindTreasureInfo
|
{
|
public readonly int id;
|
public readonly int treasureId;
|
public readonly int type;
|
public readonly int targetNum;
|
public readonly int jumpId; //跳转最终法宝
|
public readonly int recommendJumpID; //推荐跳转ID 和 findRecommandItems同字段来源
|
|
public List<FindHostEquip> findHostEquips { get; private set; } //需要满足的装备条件
|
public List<Item> findHostItems = new List<Item>(); // 货币和奖励2选1显示
|
public List<FindHostMoney> findHostMoneys = new List<FindHostMoney>();
|
public Dictionary<int, List<int>> findRecommandItems = new Dictionary<int, List<int>>();
|
public List<int> conditions = new List<int>(); //原类型1的装备存findHostEquips
|
|
public bool IsCompleted;
|
|
public FindTreasureInfo(int id)
|
{
|
var config = TreasureFindHostConfig.Get(id);
|
|
this.id = id;
|
this.type = config.Type;
|
this.targetNum = config.NeedCnt;
|
this.jumpId = config.JumpID;
|
this.treasureId = config.MagicWeaponID;
|
|
IsCompleted = false;
|
|
switch (type)
|
{
|
case 1:
|
var equipArray = JsonMapper.ToObject<int[][]>(config.Condition);
|
findHostEquips = new List<FindHostEquip>();
|
for (int i = 0; i < equipArray.Length; i++)
|
{
|
findHostEquips.Add(new FindHostEquip()
|
{
|
level = equipArray[i][0],
|
itemColor = equipArray[i][1],
|
isSuit = equipArray[i][2] == 1,
|
place = equipArray[i][3],
|
});
|
}
|
break;
|
default:
|
conditions = JsonMapper.ToObject<int[]>(config.Condition).ToList();
|
break;
|
}
|
|
var itemArray = JsonMapper.ToObject<int[][]>(config.AwardItemList);
|
for (int i = 0; i < itemArray.Length; i++)
|
{
|
findHostItems.Add(new Item()
|
{
|
id = itemArray[i][0],
|
count = itemArray[i][1],
|
});
|
}
|
var moneyArray = JsonMapper.ToObject<int[][]>(config.Money);
|
for (int i = 0; i < moneyArray.Length; i++)
|
{
|
findHostMoneys.Add(new FindHostMoney()
|
{
|
moneyType = moneyArray[i][0],
|
count = moneyArray[i][1],
|
});
|
}
|
|
//如果是纯数字就是跳转,否则是推荐装备
|
if (!int.TryParse(config.AdviceIds, out recommendJumpID))
|
{
|
recommendJumpID = 0;
|
var recommandJson = JsonMapper.ToObject(config.AdviceIds);
|
foreach (var jobKey in recommandJson.Keys)
|
{
|
findRecommandItems.Add(int.Parse(jobKey), JsonMapper.ToObject<int[]>(recommandJson[jobKey].ToJson()).ToList());
|
}
|
}
|
}
|
}
|
|
public struct FindHostEquip
|
{
|
public int level;
|
public int place;
|
public int itemColor;
|
public bool isSuit;
|
}
|
|
public struct FindHostMoney
|
{
|
public int moneyType;
|
public int count;
|
}
|
}
|