using Snxxz.UI; using System; using System.Collections; using System.Collections.Generic; using System.Text.RegularExpressions; using TableConfig; using UnityEngine; public class PetBackpack//宠物背包 { public int PetClass;//宠物阶级 public int PetStatus;//宠物当前状态 1为出战 0未出战 public int ItemPlace;//宠物位置索引 public int[] PetSkill;//宠物当前学习的技能 public int petExp; //宠物当前经验 } public enum PetEnum { PetDan = 0,//灵宠丹 PetDebris = 1,//灵宠碎片 PetStone = 2,//灵宠魂石 } public class PlayerPetDatas : Model, IBeforePlayerDataInitialize, IPlayerLoginOk { public Dictionary _TagPetItem = new Dictionary();//关于灵兽魂石 public Dictionary _DicPetBack = new Dictionary();//宠物背包列表 public Dictionary _PetSkillAcquire = new Dictionary();//灵宠已获得的技能(同类技能只存最高等级)1.技能TypeID,2.技能ID public delegate void Delegate_HB701(HB701_tagMCPetLV info); public delegate void Delegate_Ha339(HA339_tagMCAttrFruitEatCntList info); public static event Delegate_Ha339 Event_Ha339;//灵兽魂石 public delegate void Delegate_H0704(); public static event Delegate_H0704 Event_H0704Add;//灵宠添加(进阶) public static Action Event_H0704Update;//灵宠刷新 public delegate void SpiritPetPlay(int _toPlay = 0);//宠物是否出战 public static event SpiritPetPlay Event_SpiritPetPlay; public int PetNow = 0;//用来保存出战的灵宠 public bool Wait = true;//(使用灵宠丹)等待回包 public Dictionary DeblockingRedPoint = new Dictionary();//解锁按钮红点(灵宠红点子级) public Dictionary PetRedpoint = new Dictionary();//灵宠列表 public Dictionary CultivateRedPoint = new Dictionary();//灵宠培养按钮红点 private List Sortpet = new List();//用于红点排序 public int MinAtkNunber = 0;//灵宠最小攻击力 public int MaxAtkNunber = 0;//灵宠最大攻击力 public int PetStoneItemId = 0;//用来记录坐骑魂石的ID public bool IsOk = false; public bool RedPointMaxLv = true;//用来标记灵宠最大限制等级 public List ListEffectSkill = new List(); PlayerPackModel _playerPack; PlayerPackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel()); } } PackModelInterface _modelInterface; PackModelInterface modelInterface { get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel()); } } public Dictionary petLvNameDict { get; private set; } public int curPetId { get; set; } public int petUpgradeToolId { get; set; } public event Action PlayerLoginOkData; public override void Init() { ToAddSorting(); playerPack.RefreshItemCountAct += OnItemRefreshEvent; FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChange; PetAttributeWin.IsRedPointCultivate += IsRedPointCultivate; PetNumberPreservation(); petLvNameDict = new Dictionary(); FuncConfigConfig petLvName = Config.Instance.Get("PetQuality"); int[] petLvArray = ConfigParse.GetMultipleStr(petLvName.Numerical1); string[] petLvNameArray = ConfigParse.GetMultipleStr(petLvName.Numerical2); for (int i = 0; i < petLvArray.Length; i++) { if (!petLvNameDict.ContainsKey(petLvArray[i])) { petLvNameDict.Add(petLvArray[i], petLvNameArray[i]); } } petUpgradeToolId = int.Parse(Config.Instance.Get("PetUpItem").Numerical1); string str = Config.Instance.Get("PetSkillEffect").Numerical1; int[] listeffect = ConfigParse.GetMultipleStr(str); ListEffectSkill.Clear(); for (int i = 0; i < listeffect.Length; i++) { ListEffectSkill.Add(listeffect[i]); } } public override void UnInit() { playerPack.RefreshItemCountAct -= OnItemRefreshEvent; FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChange; PetAttributeWin.IsRedPointCultivate -= IsRedPointCultivate; } public void OnBeforePlayerDataInitialize() { Wait = true; RedPointMaxLv = true; IsOk = false; _TagPetItem.Clear(); _DicPetBack.Clear(); PetNow = 0; MinAtkNunber = 0; MaxAtkNunber = 0; curPetId = 0; } public void OnPlayerLoginOk() { GlobalTimeEvent.Instance.secondEvent -= secondEvent; GlobalTimeEvent.Instance.secondEvent += secondEvent; SinglePackModel singPack = playerPack.GetSinglePackModel(PackType.rptPetPack); if (singPack == null) return; foreach (var index in singPack.GetPackModelIndexDict().Keys) { OnItemRefreshEvent(singPack.packType, index, singPack.GetPackModelIndexDict()[index].itemId); } IsOk = true; if (PlayerLoginOkData != null) { PlayerLoginOkData(); } } private DateTime dateTimeA; private void secondEvent() { if (!Wait) { TimeSpan timeS = DateTime.Now - dateTimeA; if (timeS.Seconds>= 2f) { Wait = true; } } else { dateTimeA = DateTime.Now; } } #region 发送服务端请求 public void SendPetSwitchQuest(int petIndex) { C1603_tagCPetStateChange tag_Cpet = new C1603_tagCPetStateChange(); tag_Cpet.PetID = (uint)petIndex; tag_Cpet.State = 1; GameNetSystem.Instance.SendInfo(tag_Cpet); } public void SendBreakPetLockQuest(int petId) { CA702_tagCMActivatePet CMPet = new CA702_tagCMActivatePet(); CMPet.PetNPCID = (uint)petId; GameNetSystem.Instance.SendInfo(CMPet); if (PackSendQuestMgr.Instance.useItemModel != null) { PackSendQuestMgr.Instance.useItemModel = null; } } public void SendPetTrainQuest(int petIndex,int number) { CA704_tagCMPetClassUP _tagCA704 = new CA704_tagCMPetClassUP(); _tagCA704.PetItemIndex = (byte)petIndex; _tagCA704.UseItemCnt = (ushort)number; GameNetSystem.Instance.SendInfo(_tagCA704); } #endregion private void OnItemRefreshEvent(PackType type, int index, int id) { PetH0704(playerPack.GetItemModelByIndex(type, index)); if (type == PackType.rptItem) { if (_TagPetItem.ContainsKey(id)) { PetStoneRed(); } PetActivateRedPoint(); GetCultivateRedPoint(); } } private void OnFuncStateChange(int obj) { if (obj == 6) { PetStoneRed(); PetActivateRedPoint(); GetCultivateRedPoint(); } } private const int Redpoint_key1 = 1050201; private Redpoint redPointStre1 = new Redpoint(MainRedDot.RedPoint_PetKey2, Redpoint_key1); private void PetStoneRed()//灵宠魂石红点 { redPointStre1.state = RedPointState.None; if (!FuncOpen.Instance.IsFuncOpen(6)) { return; } int type = 0; foreach (var key in _TagPetItem.Keys) { if (_TagPetItem[key] >= Config.Instance.Get(key).MaxUseCnt) { continue; } type += playerPack.GetItemCountByID(PackType.rptItem, key); } if (type > 0) { redPointStre1.state = RedPointState.Simple; return; } } //Lcj 是否可吞噬装备 public bool CanDevour { get { return false; } } private void PetNumberPreservation()//用来对灵宠个数进行保存 { if (PetRedpoint.Count != 0) { return; } int type = 0; var allPetConfigs = Config.Instance.GetAllValues(); foreach (var config in allPetConfigs) { if (!DeblockingRedPoint.ContainsKey(config.ID)) { type += 1; int petID = config.ID; int RedPoint_Mountkey = MainRedDot.RedPoint_PetKey2 * 10 + type; Redpoint redPointMountStare = new Redpoint(MainRedDot.RedPoint_PetKey2, RedPoint_Mountkey); PetRedpoint.Add(petID, redPointMountStare);//列表 int RedPoint_Mountkey1 = RedPoint_Mountkey * 10 + type; Redpoint redPointMountStare1 = new Redpoint(RedPoint_Mountkey, RedPoint_Mountkey1); DeblockingRedPoint.Add(petID, redPointMountStare1);//解锁按钮 int RedPoint_Mountkey2 = RedPoint_Mountkey1 * 10 + type; Redpoint redPointMountStare2 = new Redpoint(RedPoint_Mountkey, RedPoint_Mountkey2); CultivateRedPoint.Add(petID, redPointMountStare2); } } } private void PetActivateRedPoint()//灵宠激活红点 { foreach (var key in PetRedpoint.Keys) { DeblockingRedPoint[key].state = RedPointState.None; } if (!FuncOpen.Instance.IsFuncOpen(6)) { return; } var configs = Config.Instance.GetAllValues(); foreach (var config in configs) { int unlockItemID = config.UnLockNeedItemID; int itemCount = playerPack.GetItemCountByID(PackType.rptItem, unlockItemID); int unlockItemCnt = config.UnLockNeedItemCnt; if (itemCount >= unlockItemCnt && !_DicPetBack.ContainsKey(config.ID) && FuncOpen.Instance.IsFuncOpen(6)) { DeblockingRedPoint[config.ID].state = RedPointState.Simple; } } } //灵宠进阶和灵宠分解红点 public bool CanDecom { get { return false; } } public bool CanEssence { get; private set; } private void IsRedPointCultivate() { RedPointMaxLv = false; GetCultivateRedPoint(); } private void ToAddSorting() { Sortpet.Clear(); Sortpet = Config.Instance.GetAllValues(); Sortpet.Sort(Compare); } int Compare(PetInfoConfig x, PetInfoConfig y)//数组排列 { if (x.Sort.CompareTo(y.Sort) != 0) { return x.Sort.CompareTo(y.Sort); } return 1; } public void GetCultivateRedPoint()//灵宠培养红点 { foreach (var key in CultivateRedPoint.Keys) { CultivateRedPoint[key].state = RedPointState.None; } if (!FuncOpen.Instance.IsFuncOpen(6)) { return; } if (_DicPetBack.Count <= 0) { return; } int GetPetId = 0; int petLv = 0; for (int i = 0; i < Sortpet.Count; i++) { int petID = Sortpet[i].ID; if (_DicPetBack.ContainsKey(petID)) { var key = petID; if (petLv == 0 && _DicPetBack[key].PetClass < GetPetSkillMaxLv(key)) { petLv = _DicPetBack[key].PetClass; GetPetId = key; } if (_DicPetBack[key].PetClass < petLv && _DicPetBack[key].PetClass < GetPetSkillMaxLv(key)) { petLv = _DicPetBack[key].PetClass; GetPetId = key; } } } int itemCount = playerPack.GetItemCountByID(PackType.rptItem, 4151); PetInfoConfig petinfo = Config.Instance.Get(GetPetId); if (PlayerDatas.Instance.baseData.LV >= 1500) { if (CultivateRedPoint.ContainsKey(GetPetId) && itemCount > 0 && RedPointMaxLv && petinfo.MaxRank> petLv) { CultivateRedPoint[GetPetId].state = RedPointState.Simple; CanEssence = true; } } else { if (CultivateRedPoint.ContainsKey(GetPetId) && itemCount > 0 && petinfo.MaxRank > petLv) { CultivateRedPoint[GetPetId].state = RedPointState.Simple; CanEssence = true; } } } public int GetMinPetLv() { int GetPetId = 0; int petLv = 0; for (int i = 0; i < Sortpet.Count; i++) { int petID = Sortpet[i].ID; if (_DicPetBack.ContainsKey(petID)) { var key = petID; if (petLv == 0 && _DicPetBack[key].PetClass < GetPetSkillMaxLv(key)) { petLv = _DicPetBack[key].PetClass; GetPetId = key; } if (_DicPetBack[key].PetClass < petLv && _DicPetBack[key].PetClass < GetPetSkillMaxLv(key)) { petLv = _DicPetBack[key].PetClass; GetPetId = key; } } } return GetPetId; } private int GetPetSkillMaxLv(int PetID) { int maxskillLV = 0; int[] curPetUnlocks; PetInfoConfig petInfo = Config.Instance.Get(PetID); if (petInfo != null) { curPetUnlocks= ConfigParse.GetMultipleStr(petInfo.SkillUnLock); maxskillLV = curPetUnlocks[(curPetUnlocks.Length)-1]; } return maxskillLV; } public void PetA339(HA339_tagMCAttrFruitEatCntList info) { for (int i = 0; i < info.count; i++) { var configItem = Config.Instance.Get((int)info.EatCntList[i].ItemID); if (configItem == null) { continue; } if (_TagPetItem.ContainsKey((int)info.EatCntList[i].ItemID)) { _TagPetItem[(int)info.EatCntList[i].ItemID] = (int)info.EatCntList[i].EatCnt; if (Event_Ha339 != null) Event_Ha339(info); } else { if (configItem.Type == 28) { _TagPetItem.Add((int)info.EatCntList[i].ItemID, (int)info.EatCntList[i].EatCnt); } } } PetStoneRed(); } private void AddPetSkill(int[] intlist) { for (int i = 0; i < intlist.Length; i++) { var skillPet = Config.Instance.Get(intlist[i]); if (_PetSkillAcquire.ContainsKey(skillPet.SkillTypeID)) { int skilllv = Config.Instance.Get(_PetSkillAcquire[skillPet.SkillTypeID]).SkillLV; if (skillPet.SkillLV > skilllv) { _PetSkillAcquire[skillPet.SkillTypeID] = skillPet.SkillID; } } else { _PetSkillAcquire.Add(skillPet.SkillTypeID, skillPet.SkillID); } } } public void PetH0704(ItemModel info)//宠物背包列表 { if (info == null) return; if (info.packType == PackType.rptPetPack) { Dictionary _dic = Analysis(info.itemInfo.UserData); if (GetUseDataModel(200, _dic) != null) { int petId = _dic[200][0]; int petLv = 0; int petState = 0; int[] petSkill = null; int petIndex = info.itemInfo.ItemPlace; int petExp = 0; if (GetUseDataModel(201, _dic) != null) { petSkill = _dic[201];//宠物当前学习的技能 } if (GetUseDataModel(202, _dic) != null) { petLv = _dic[202][0] + 1;//宠物阶级 } if (GetUseDataModel(204, _dic) != null) { petState = _dic[204][0];//宠物当前状态; } if (GetUseDataModel(208, _dic) != null) { petExp = _dic[208][0]; //宠物经验 } if (!_DicPetBack.ContainsKey(petId)) { PetBackpack _petBack = new PetBackpack(); _petBack.PetClass = petLv; _petBack.petExp = petExp; //宠物经验 _petBack.PetStatus = petState;//宠物当前状态 if (_petBack.PetStatus == 1) { PetNow = petId; } if (petSkill != null) { _petBack.PetSkill = petSkill;//宠物当前学习的技能 AddPetSkill(_petBack.PetSkill); } else { _petBack.PetSkill = null; } _petBack.ItemPlace = petIndex;//宠物位置索引 _DicPetBack.Add(petId, _petBack); if (Event_H0704Add != null && IsOk) { Event_H0704Add(); } } else { _DicPetBack[petId].PetClass = petLv; _DicPetBack[petId].PetStatus = petState; _DicPetBack[petId].petExp = petExp; //宠物经验 if (petSkill != null) { _DicPetBack[petId].PetSkill = petSkill;//宠物当前学习的技能 AddPetSkill(_DicPetBack[petId].PetSkill); } else { _DicPetBack[petId].PetSkill = null; } _DicPetBack[petId].ItemPlace = petIndex; if (Event_H0704Update != null && IsOk) { Event_H0704Update(); } if (_DicPetBack[petId].PetStatus == 1) { PetNow = petId; if (Event_SpiritPetPlay != null && IsOk) { Event_SpiritPetPlay(petState); } } } } } PetStoneRed(); PetActivateRedPoint(); GetCultivateRedPoint(); GetPetMinAndMaxAttack(); } public int[] GetUseDataModel(int key, Dictionary useDataDict) { int[] list = null; if (useDataDict != null) { useDataDict.TryGetValue(key, out list); } return list; } private void GetPetMinAndMaxAttack() { if (_DicPetBack.Count <= 0) { return; } MinAtkNunber = 0; MaxAtkNunber = 0; foreach (var key in _DicPetBack.Keys) { PetClassCostConfig _tagPetClass = PetClassCostConfig.GetPetIdAndRank(key, _DicPetBack[key].PetClass); MinAtkNunber += _tagPetClass.AtkAdd; MaxAtkNunber += _tagPetClass.AtkAdd; } } public static Regex userData = new Regex(@"'([0-9]+)':\[(.*?)\]", RegexOptions.Singleline); public Dictionary Analysis(string val)//正则表达式的字符串分割 { if (!userData.IsMatch(val)) { return null; } else { Dictionary dics = new Dictionary(); foreach (Match match in userData.Matches(val)) { int id = int.Parse(match.Groups[1].Value); string str = match.Groups[2].Value; string[] vals = str.Split(','); int[] intarray = new int[vals.Length]; for (int i = 0; i < vals.Length; i++) { int intval = int.Parse(vals[i].Replace('\'', ' ')); intarray[i] = intval; } if (!dics.ContainsKey(id)) { dics.Add(id, intarray); } } return dics; } } public bool IsHint(PetEnum petEnum, int id = 0)//True提示,False不提示 { bool iSHint = false; switch (petEnum) { case PetEnum.PetDan: foreach (var key in _DicPetBack.Keys) { PetInfoConfig petConfig = Config.Instance.Get(key); if (petConfig.MaxRank > _DicPetBack[key].PetClass) { iSHint = true; } } return iSHint; case PetEnum.PetDebris: foreach (var value in Config.Instance.GetAllValues()) { if (value.UnLockNeedItemID == id) { if (!_DicPetBack.ContainsKey(value.ID)) { iSHint = true; } } } return iSHint; case PetEnum.PetStone: int _maxuse = Config.Instance.Get(id).MaxUseCnt; if (_TagPetItem.ContainsKey(id)) { if (_maxuse > _TagPetItem[id]) { iSHint = true; } } return iSHint; default: return true; } } public int IsPetPanelRedPointState()//用于判断当前灵宠页签是否有红点亮起 { int Type = 0; foreach (var value in DeblockingRedPoint.Values) { if (value.state == RedPointState.Simple) { Type = 2; return Type; } } if (MainRedDot.Instance.redPonintPetFunc2.state == RedPointState.Simple) { Type = 1; return Type; } return Type; } #region 预览宠物碎片属性 Dictionary petAttrDict = new Dictionary(); public Dictionary GetPetAttrAddDict(int petCode) { PetInfoConfig infoConfig = Config.Instance.Get(petCode); petAttrDict.Clear(); if (infoConfig == null) return petAttrDict; int maxRank = infoConfig.MaxRank; PetClassCostConfig cost = PetClassCostConfig.GetPetIdAndRank(petCode,maxRank); int allAtkAdd = 0; if(cost != null) { allAtkAdd = cost.AtkAdd; } petAttrDict.Add(7,allAtkAdd); return petAttrDict; } #endregion }