using vnxbqy.UI; using System; using System.Collections.Generic; using UnityEngine; using LitJson; using System.Text; //Arena主控制代码 public class FosterModel : ILModel { //坐骑培养信息 public event Action UpdateTrainHorseEvent; //宠物培养信息 public event Action UpdatePetTrainEvent; //灵器培养信息 public event Action UpdateLingQiTrainEvent; Dictionary LingQiDict = new Dictionary(); IL_HA817_tagMCPetTrainInfo m_PetTrainInfo = new IL_HA817_tagMCPetTrainInfo(); HA301_tagTrainHorseData m_TrainHorseData = new HA301_tagTrainHorseData(); PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } PetModel petmodel { get { return ModelCenter.Instance.GetModel(); } } int HorseAttrLength = 0; int HorseAttrLengthLV = 0; int PetAttrLength = 0; int PetAttrLengthLV = 0; int LingQiAttrLength = 0; int LingQiAttrLengthLV = 0; public int[] BuyItemID = new int[3];//当前购买物品ID public uint[] CurrentLevel = new uint[3] ;//购买当前状态的等级,培养丹 public uint[] CurrentHave = new uint[3];//已有的培养丹 public int StateNow = 1; //1.坐骑 2.灵宠 3.守护 4.翅膀 5.灭世 6.噬神 public int FeedState = 1;//1,2,3, public int FeedUpLevel = 1;//提升等级 public int curEquipID; public bool bOpenParent; public Dictionary> AllLevel = new Dictionary>(); protected override void Init() { CurrentLevel[0] = 0; CurrentLevel[1] = 0; CurrentLevel[2] = 0; AddKey(1); AddKey(2); AddKey(14); AddKey(13); AddKey(16); AddKey(17); } protected override void UnInit() { } void AddKey(int key) { List keys = new List(); keys.Add(0); keys.Add(0); keys.Add(0); AllLevel.Add(key, keys); } #region //发送命令 //购买 public void BuyItem(int ID,int count ) { CA310_tagCMBuyItem buyShop = new CA310_tagCMBuyItem(); buyShop.BuyItemIndex = (ushort)ID; buyShop.BuyCount = (uint)count; GameNetSystem.Instance.SendInfo(buyShop); } // A3 27 灵器培养 #tagCMLingQiTrain public void SendLingQiTrain(byte _EquipPlace, byte _TrainType, ushort _UseItemCnt) { FeedState = _TrainType; IL_CA327_tagCMLingQiTrain pack = new IL_CA327_tagCMLingQiTrain(); pack.EquipPlace= _EquipPlace; //灵器装备位 pack.TrainType = _TrainType; //培养类型: 1-基础培养,2-特殊培养,3-百分比培养 pack.UseItemCnt = _UseItemCnt; //消耗材料个数 GameNetSystem.Instance.SendInfo(pack); } // A5 31 坐骑培养 #tagCMHorseTrain public void SendHorseTrain(byte _TrainType, ushort _UseItemCnt) { FeedState = _TrainType; IL_CA531_tagCMHorseTrain pack = new IL_CA531_tagCMHorseTrain(); pack.TrainType = _TrainType; //培养类型: 1-基础培养,2-特殊培养,3-百分比培养 pack.UseItemCnt = _UseItemCnt; //消耗材料个数 GameNetSystem.Instance.SendInfo(pack); } // A7 05 宠物培养 #tagCMPetTrain public void SendPetTrain(byte _TrainType, ushort _UseItemCnt) { FeedState = _TrainType; IL_CA705_tagCMPetTrain pack = new IL_CA705_tagCMPetTrain(); pack.TrainType = _TrainType; //培养类型: 1-基础培养,2-特殊培养,3-百分比培养 pack.UseItemCnt = _UseItemCnt; //消耗材料个数 GameNetSystem.Instance.SendInfo(pack); } #endregion #region //接收命令 //坐骑培养信息 public void ReceiveTrainHorseData(HA301_tagTrainHorseData vNetData) { m_TrainHorseData = vNetData; AllLevel[1] = new List(vNetData.TrainLVList); if (UpdateTrainHorseEvent != null) { UpdateTrainHorseEvent(vNetData); } } // 宠物培养信息 public void ReceivePetTrainData(IL_HA817_tagMCPetTrainInfo vNetData) { m_PetTrainInfo = vNetData; AllLevel[2] = new List(vNetData.TrainLVList); if (UpdatePetTrainEvent != null) { UpdatePetTrainEvent(vNetData); } } //灵器培养信息 public void ReceiveLingQiTrainData(IL_HA818_tagMCLingQiTrainInfo vNetData) { if(LingQiDict.ContainsKey(vNetData.EquipPlace)) { LingQiDict[vNetData.EquipPlace] = vNetData; } else { LingQiDict.Add(vNetData.EquipPlace, vNetData); } AllLevel[vNetData.EquipPlace] = new List(vNetData.TrainLVList); if (UpdateLingQiTrainEvent != null) { UpdateLingQiTrainEvent(vNetData); } } #endregion public void InitTrainHorseData() { if (UpdateTrainHorseEvent != null) { UpdateTrainHorseEvent(m_TrainHorseData); } } public void InitPetTrainData() { if (UpdatePetTrainEvent != null) { UpdatePetTrainEvent(m_PetTrainInfo); } } public void InitLingQiTrainData() { if (UpdateLingQiTrainEvent != null) { UpdateLingQiTrainEvent(LingQiDict[curEquipID]); } } public ILHorseTrainConfig GeHorseTrainConfig(int type, uint level) { string key = type.ToString() + level.ToString(); return ILHorseTrainConfig.GetTrainConfigByType(key); } public ILPetTrainConfig GePetTrainConfig(int type, uint level) { string key = type.ToString() + level.ToString(); return ILPetTrainConfig.GetTrainConfigByType(key); } public ILLingQiTrainConfig GeLingQiTrainConfig(int equip,int type, uint level) { string key = equip.ToString()+type.ToString() + level.ToString(); return ILLingQiTrainConfig.GetTrainConfigByType(key); } //获取坐骑培养属性ID public void GeHorseUpItemAttrID(int type, uint level, out int[] values) { string key = type.ToString() + level.ToString(); ILHorseTrainConfig htConfig = ILHorseTrainConfig.GetTrainConfigByType(key); HorseAttrLength = htConfig.UpItemAttrTypeList.Length; values = new int[HorseAttrLength]; for (int j = 0; j < htConfig.UpItemAttrTypeList.Length; j++) { values[j] = htConfig.UpItemAttrTypeList[j]; } } //获取坐骑培养特殊属性ID public void GeHorseLVAttrID(int type, uint level, out int[] values) { level = level +1; int maxLevel = ILHorseTrainConfig.GetConfigCountByType(type); if (level >= maxLevel) level = (uint)maxLevel; string key = type.ToString() + level.ToString(); ILHorseTrainConfig htConfig = ILHorseTrainConfig.GetTrainConfigByType(key); HorseAttrLengthLV = htConfig.LVAttrTypeList.Length; values = new int[HorseAttrLengthLV]; for (int j = 0; j < htConfig.LVAttrTypeList.Length; j++) { values[j] = htConfig.LVAttrTypeList[j]; } } //获取宠物培养属性ID public void GePetUpItemAttrID(int type, uint level, out int[] values) { string key = type.ToString() + level.ToString(); ILPetTrainConfig htConfig = ILPetTrainConfig.GetTrainConfigByType(key); PetAttrLength = htConfig.UpItemAttrTypeList.Length; values = new int[PetAttrLength]; for (int j = 0; j < htConfig.UpItemAttrTypeList.Length; j++) { values[j] = htConfig.UpItemAttrTypeList[j]; } } //获取宠物培养特殊属性ID public void GePetLVAttrID(int type, uint level, out int[] values) { level = level + 1; int maxLevel = ILPetTrainConfig.GetConfigCountByType(type); if (level >= maxLevel) level = (uint)maxLevel; string key = type.ToString() + level.ToString(); ILPetTrainConfig htConfig = ILPetTrainConfig.GetTrainConfigByType(key); PetAttrLengthLV = htConfig.LVAttrTypeList.Length; values = new int[PetAttrLengthLV]; for (int j = 0; j < htConfig.LVAttrTypeList.Length; j++) { values[j] = htConfig.LVAttrTypeList[j]; } } //获取灵器培养属性ID public void GeLingQiUpItemAttrID(int Equip,int type, uint level, out int[] values) { string key = Equip.ToString()+ type.ToString() + level.ToString(); ILLingQiTrainConfig htConfig = ILLingQiTrainConfig.GetTrainConfigByType(key); LingQiAttrLength = htConfig.UpItemAttrTypeList.Length; values = new int[LingQiAttrLength]; for (int j = 0; j < htConfig.UpItemAttrTypeList.Length; j++) { values[j] = htConfig.UpItemAttrTypeList[j]; } } //获取灵器培养特殊属性ID public void GeLingQiLVAttrID(int Equip, int type, uint level, out int[] values) { level = level + 1; int maxLevel = ILLingQiTrainConfig.GetConfigCountByType(Equip,type); if (level >= maxLevel) level = (uint)maxLevel; string key = Equip.ToString() + type.ToString() + level.ToString(); ILLingQiTrainConfig htConfig = ILLingQiTrainConfig.GetTrainConfigByType(key); LingQiAttrLengthLV = htConfig.LVAttrTypeList.Length; values = new int[LingQiAttrLengthLV]; for (int j = 0; j < htConfig.LVAttrTypeList.Length; j++) { values[j] = htConfig.LVAttrTypeList[j]; } } //获取坐骑培养当前值 public void GetCurrentHorseValue(int type, uint level, int count, out int[] values) { string key = type.ToString() + level.ToString(); ILHorseTrainConfig htConfig = ILHorseTrainConfig.GetTrainConfigByType(key); values = new int[htConfig.UpItemAttrValueList.Length]; for (int j = 0; j < htConfig.UpItemAttrValueList.Length; j++) { values[j] = (count / htConfig.EatCntEverytime) * htConfig.UpItemAttrValueList[j]; } } //获取坐骑培养累加值 public void GetSumHorseValue(int type,uint level,out int[] values ) { string key = type.ToString() + level.ToString(); ILHorseTrainConfig htConfig = ILHorseTrainConfig.GetTrainConfigByType(key); HorseAttrLength = htConfig.UpItemAttrTypeList.Length; HorseAttrLengthLV = htConfig.LVAttrTypeList.Length; int length = HorseAttrLength + HorseAttrLengthLV; values = new int[length]; if (level <= 1) { for (int i = 0; i < values.Length; i++) values[i] = 0; } else { for (int i = 1; i < level ;i++) { key = type.ToString() + i.ToString(); htConfig = ILHorseTrainConfig.GetTrainConfigByType(key); int count = htConfig.UpItemAttrValueList.Length; for (int j = 0; j < htConfig.UpItemAttrValueList.Length; j++) { values[j] += (htConfig.EatCntTotal / htConfig.EatCntEverytime) * htConfig.UpItemAttrValueList[j]; } } for (int i = 1; i <= level; i++) { key = type.ToString() + i.ToString(); htConfig = ILHorseTrainConfig.GetTrainConfigByType(key); int count = htConfig.UpItemAttrValueList.Length; if (type >= 2) { for (int j = 0; j < htConfig.LVAttrValueList.Length; j++) { values[count + j] += htConfig.LVAttrValueList[j]; } } } } } //获取灵宠培养当前值 public void GetCurrentPetValue(int type, uint level, int count, out int[] values) { string key = type.ToString() + level.ToString(); ILPetTrainConfig htConfig = ILPetTrainConfig.GetTrainConfigByType(key); values = new int[htConfig.UpItemAttrValueList.Length]; for (int j = 0; j < htConfig.UpItemAttrValueList.Length; j++) { values[j] = (count / htConfig.EatCntEverytime) * htConfig.UpItemAttrValueList[j]; } } //获取灵宠培养累加值 public void GetSumPetValue(int type, uint level, out int[] values) { string key = type.ToString() + level.ToString(); ILPetTrainConfig htConfig = ILPetTrainConfig.GetTrainConfigByType(key); PetAttrLength = htConfig.UpItemAttrTypeList.Length; PetAttrLengthLV = htConfig.LVAttrTypeList.Length; int length = PetAttrLength + PetAttrLengthLV; values = new int[length]; if (level <= 1) { for (int i = 0; i < values.Length; i++) values[i] = 0; } else { for (int i = 1; i < level; i++) { key = type.ToString() + i.ToString(); htConfig = ILPetTrainConfig.GetTrainConfigByType(key); int count = htConfig.UpItemAttrValueList.Length; for (int j = 0; j < htConfig.UpItemAttrValueList.Length; j++) { values[j] += (htConfig.EatCntTotal / htConfig.EatCntEverytime) * htConfig.UpItemAttrValueList[j]; } } for (int i = 1; i <= level; i++) { key = type.ToString() + i.ToString(); htConfig = ILPetTrainConfig.GetTrainConfigByType(key); int count = htConfig.UpItemAttrValueList.Length; if (type >= 2) { for (int j = 0; j < htConfig.LVAttrValueList.Length; j++) { values[count + j] += htConfig.LVAttrValueList[j]; } } } } } //获取灵器培养当前值 public void GetCurrentLingQiValue(int Equip ,int type, uint level, int count, out int[] values) { string key = Equip.ToString()+type.ToString() + level.ToString(); ILLingQiTrainConfig htConfig = ILLingQiTrainConfig.GetTrainConfigByType(key); values = new int[htConfig.UpItemAttrValueList.Length]; for (int j = 0; j < htConfig.UpItemAttrValueList.Length; j++) { values[j] = (count / htConfig.EatCntEverytime) * htConfig.UpItemAttrValueList[j]; } } //获取灵器培养累加值 public void GetSumLingQiValue(int Equip, int type, uint level, out int[] values) { string key = Equip.ToString() + type.ToString() + level.ToString(); ILLingQiTrainConfig htConfig = ILLingQiTrainConfig.GetTrainConfigByType(key); LingQiAttrLength = htConfig.UpItemAttrTypeList.Length; LingQiAttrLengthLV = htConfig.LVAttrTypeList.Length; int length = LingQiAttrLength + LingQiAttrLengthLV; values = new int[length]; if (level <= 1) { for (int i = 0; i < values.Length; i++) values[i] = 0; } else { for (int i = 1; i < level; i++) { key = Equip.ToString() + type.ToString() + i.ToString(); htConfig = ILLingQiTrainConfig.GetTrainConfigByType(key); int count = htConfig.UpItemAttrValueList.Length; for (int j = 0; j < htConfig.UpItemAttrValueList.Length; j++) { values[j] += (htConfig.EatCntTotal / htConfig.EatCntEverytime) * htConfig.UpItemAttrValueList[j]; } } for (int i = 1; i <= level; i++) { key = Equip.ToString() + type.ToString() + i.ToString(); htConfig = ILLingQiTrainConfig.GetTrainConfigByType(key); int count = htConfig.UpItemAttrValueList.Length; if (type >= 2) { for (int j = 0; j < htConfig.LVAttrValueList.Length; j++) { values[count + j] += htConfig.LVAttrValueList[j]; } } } } } //更新坐骑培养红点 public bool GetHorseRedPointUpdate(int index,int id) { uint level = AllLevel[1][index]; if (level == 0) return false; ILHorseTrainConfig TrainConfig = GeHorseTrainConfig(index + 1, AllLevel[1][index]); bool isWork = PlayerDatas.Instance.baseData.realmLevel >= TrainConfig.NeedRealmLV ? true : false; if (!isWork) return false; isWork = false; int remainItemCount = packModel.GetItemCountByID(PackType.Item, id); if (remainItemCount > 0) { int type = index + 1; string key = type.ToString() + level.ToString(); ILHorseTrainConfig htConfig = ILHorseTrainConfig.GetTrainConfigByType(key); if (remainItemCount >= htConfig.EatCntEverytime) isWork = true; } return isWork; } //更新灵宠培养红点 public bool GetPetRedPointUpdate(int index, int id) { uint level = AllLevel[2][index]; if (level == 0) return false; ILPetTrainConfig TrainConfig = GePetTrainConfig(index + 1, AllLevel[2][index]); bool isWork = PlayerDatas.Instance.baseData.realmLevel >= TrainConfig.NeedRealmLV ? true : false; if (!isWork) return false; isWork = false; int remainItemCount = packModel.GetItemCountByID(PackType.Item, GeneralDefine.PetTrainIDList[index]); if (remainItemCount > 0) { int type = index + 1; string key = type.ToString() + level.ToString(); ILPetTrainConfig htConfig = ILPetTrainConfig.GetTrainConfigByType(key); if (remainItemCount >= htConfig.EatCntEverytime) isWork = true; } return isWork; } //更新灵器培养红点 public bool GetLingQiRedPointUpdate(int EquipID) { if (EquipID == 0) return false; bool isWork = false; ILLingQiTrainConfig TrainConfig; for (int i = 0; i < GeneralDefine.LingQiTrainIDList[EquipID].Count; i++) { int remainItemCount = packModel.GetItemCountByID(PackType.Item, GeneralDefine.LingQiTrainIDList[EquipID][i]); if (remainItemCount > 0) { int type = i + 1; uint level = AllLevel[EquipID][i]; if (level == 0) return false; TrainConfig = GeLingQiTrainConfig(EquipID, i + 1, AllLevel[EquipID][i]); isWork = PlayerDatas.Instance.baseData.realmLevel >= TrainConfig.NeedRealmLV ? true : false; if(!isWork) return false; string key = EquipID.ToString() + type.ToString() + level.ToString(); ILLingQiTrainConfig htConfig = ILLingQiTrainConfig.GetTrainConfigByType(key); if(remainItemCount >= htConfig.EatCntEverytime) return true; } } return isWork; } public bool CheckHorseOpen(bool _openParent) { bOpenParent = _openParent; ILHorseTrainConfig TrainConfig = GeHorseTrainConfig(1, 1); if (TrainConfig == null) return false; bool bOpen = PlayerDatas.Instance.baseData.realmLevel >= TrainConfig.NeedRealmLV ? true : false; if(!bOpen) { RealmConfig presentCfg = RealmConfig.Get(TrainConfig.NeedRealmLV); SysNotifyMgr.Instance.ShowTip("FosterHorseOpenFail", presentCfg.Name); } StateNow = 1; return bOpen; } public bool CheckPetOpen(bool _openParent) { bOpenParent = _openParent; ILPetTrainConfig TrainConfig = GePetTrainConfig(1, 1); bool bOpen = PlayerDatas.Instance.baseData.realmLevel >= TrainConfig.NeedRealmLV ? true : false; if (!bOpen) { RealmConfig presentCfg = RealmConfig.Get(TrainConfig.NeedRealmLV); SysNotifyMgr.Instance.ShowTip("FosterPetOpenFail", presentCfg.Name); } StateNow = 2; if (!petmodel.CheckPetNow()) { SysNotifyMgr.Instance.ShowTip("FosterPetLockFail"); return false; } return bOpen; } public bool CheckLingQiOpen(int _curEquType,bool _openParent) { bOpenParent = _openParent; ILLingQiTrainConfig TrainConfig; //int EquipID = (int)SpiritEquipModel.Instance.curEquType; //if (EquipID == 0) //{ // EquipID = _curEquType; //} int EquipID = _curEquType; var place = new Int2(0, (int)EquipID); var index = EquipSet.ClientPlaceToServerPlace(place); var itemModel = this.packModel.GetItemByIndex(PackType.Equip, index); if(itemModel == null) { switch (EquipID) { case 14: SysNotifyMgr.Instance.ShowTip("FosterLingQi14EquipFail"); break; case 13: SysNotifyMgr.Instance.ShowTip("FosterLingQi13EquipFail"); break; case 16: SysNotifyMgr.Instance.ShowTip("FosterLingQi16EquipFail"); break; case 17: SysNotifyMgr.Instance.ShowTip("FosterLingQi17EquipFail"); break; } return false; } curEquipID = EquipID; TrainConfig = GeLingQiTrainConfig(EquipID, 1, 1); bool bOpen = PlayerDatas.Instance.baseData.realmLevel >= TrainConfig.NeedRealmLV ? true : false; if (!bOpen) { RealmConfig presentCfg = RealmConfig.Get(TrainConfig.NeedRealmLV); switch (EquipID) { case 14: SysNotifyMgr.Instance.ShowTip("FosterLingQi14OpenFail", presentCfg.Name); break; case 13: SysNotifyMgr.Instance.ShowTip("FosterLingQi13OpenFail", presentCfg.Name); break; case 16: SysNotifyMgr.Instance.ShowTip("FosterLingQi16OpenFail", presentCfg.Name); break; case 17: SysNotifyMgr.Instance.ShowTip("FosterLingQi17OpenFail", presentCfg.Name); break; } } StateNow = 3; return bOpen; } }