GodSoulManager = {} local this = GodSoulManager local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig) local heroRankupGroup = ConfigManager.GetConfig(ConfigName.HeroRankupGroup) local passiveSkillConfig = ConfigManager.GetConfig(ConfigName.PassiveSkillConfig) this.heroDatas = {} this.GodSoulTableData = {} function this.Initialize() this.InitializeTableData() this.heroDatas = {} end function this.InitializeTableData() for k,v in ConfigPairs(heroConfig) do if not this.GodSoulTableData[v.Id] then this.GodSoulTableData[v.Id] = {} end if not v.Soul then else for i = 1,#v.Soul do if not this.GodSoulTableData[v.Id][v.Soul[i][1]] then this.GodSoulTableData[v.Id][v.Soul[i][1]] = {} for j = 1,#v.SoulSkill do if v.Soul[i][1] == v.SoulSkill[j][1] then this.GodSoulTableData[v.Id][v.Soul[i][1]].skill = GetSkillConfigDesc(passiveSkillConfig[v.SoulSkill[j][2]]) break end end end local data = {} data.index = v.Soul[i][2] data.num = v.Soul[i][4] local config = heroRankupGroup[v.Soul[i][3]] if config.Issame == 1 then data.id = v.Id data.property = 0 data.profession = 0 elseif config.IsId > 0 then data.id = config.IsId data.property = 0 data.profession = 0 else data.id = 0 if config.IsSameClan == 1 then data.property = v.PropertyName else data.property = 0 end if config.IsSameJob == 1 then data.profession = v.Profession else data.profession = 0 end end data.star = config.StarLimit table.insert(this.GodSoulTableData[v.Id][v.Soul[i][1]],data) end end end end function this.BindHeroDatas(heroData) if not this.heroDatas[heroData.id] then this.heroDatas[heroData.id] = {} end if not this.heroDatas[heroData.id].BindHeroDatas then this.heroDatas[heroData.id].BindHeroDatas = {} end for k,v in ipairs(heroData.godSoulList) do if not this.heroDatas[heroData.id].BindHeroDatas[v.level] then this.heroDatas[heroData.id].BindHeroDatas[v.level] = {} end for n,m in ipairs(v.heros) do if this.CheckExistBindHeroDataByDid(heroData.id,m) and this.CheckExistBindHeroDataByDid(heroData.id,m) > 0 then else table.insert(this.heroDatas[heroData.id].BindHeroDatas[v.level],m) this.BingToHeroData(heroData.id,v.level,m) end end end HeroPropManager.SetDirtyByType(heroData.id,Hero_Prop_Type.GodSoul) end function this.GetGodSoulLv(curId) local level = 0 if not this.heroDatas[curId] then return level end local existLevel = {} local unExistLevel = {} for k,v in pairs(this.heroDatas[curId].BindHeroDatas) do if #v > 0 and level < k then level = k end end return level end function this.BingToHeroData(targetId,tarGetLv,Id) if not this.heroDatas[Id] then this.heroDatas[Id] = {} end if not this.heroDatas[Id].BindToHeroDatas then this.heroDatas[Id].BindToHeroDatas = {} --被绑定了哪些神将 end if not this.heroDatas[Id].BindToHeroDatas[targetId] then this.heroDatas[Id].BindToHeroDatas[targetId] = {} end this.heroDatas[Id].BindToHeroDatas[targetId] = tarGetLv end --检测curId 是否绑定了bindId function this.CheckExistBindHeroDataByDid(curId,bindId) local level = 0 if not this.heroDatas[curId] then return level end if not this.heroDatas[curId].BindHeroDatas then return level end for k,v in pairs(this.heroDatas[curId].BindHeroDatas) do for n,m in ipairs(v) do if m == bindId then return k end end end return level end --检测 curId 是否被 bindId 绑定 function this.CheckExistBindToHeroDataByDid(curId,bindId) if not this.heroDatas[curId] then return false end if not this.heroDatas[curId].BindHeroDatas then return false end if not this.heroDatas[curId].BindToHeroDatas[bindId] or this.heroDatas[curId].BindToHeroDatas[bindId] == 0 then return false end return this.heroDatas[curId].BindToHeroDatas[bindId] end --解除curId,curlv绑定的 function this.UnBindHeroDatas(curId,curlv,isOnly) if not this.heroDatas[curId] then return end if not this.heroDatas[curId].BindHeroDatas then return end for k,v in pairs(this.heroDatas[curId].BindHeroDatas) do if (k >= curlv and not isOnly) or (isOnly and k == curlv) then for n,m in ipairs(v) do this.UnBindToHeroDatas(m,curId) end this.heroDatas[curId].BindHeroDatas[k] = {} end end HeroPropManager.SetDirtyByType(curId,Hero_Prop_Type.GodSoul) end --解除bindId被绑定的curId function this.UnBindToHeroDatas(bindId,curId) if not this.heroDatas[bindId] then return end if not this.heroDatas[bindId].BindToHeroDatas then return end if not this.heroDatas[bindId].BindToHeroDatas[curId] or this.heroDatas[bindId].BindToHeroDatas[curId] == 0 then return end this.heroDatas[bindId].BindToHeroDatas[curId] = nil end --删除一个神将 function this.DeleteHeroId(heroId) if not this.heroDatas[heroId] then return false end this.UnBindHeroDatas(heroId,1) if not this.heroDatas[heroId].BindToHeroDatas then return false end for k,v in pairs(this.heroDatas[heroId].BindToHeroDatas) do if v > 0 then this.UnBindHeroDatas(k,v) end end this.heroDatas[heroId] = {} end --获取id,lv级绑定的神将 function this.GetBindHeroDatasByLevel(id,lv) local data = {} if not this.heroDatas[id] then return data end if not this.heroDatas[id].BindHeroDatas then return data end for k,v in pairs(this.heroDatas[id].BindHeroDatas) do if k == lv then return v end end return data end --获取激活神魂所需的神将条件 function this.GetGodSoulDataByLv(id,lv) if lv == 0 then return this.GodSoulTableData[id] or {} end if this.GodSoulTableData[id] and this.GodSoulTableData[id][lv] and #this.GodSoulTableData[id][lv] > 0 then return this.GodSoulTableData[id][lv] end return {} end --检测红点 function this.CheckRedPointGodSoul(curHeroData) if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.shenhun) or curHeroData.heroConfig.IsSoulOpen == 0 or curHeroData.star < 11 then return false end local lv = this.GetGodSoulLv(curHeroData.dynamicId) local isShow = this.CheckCanUpGodSoul(curHeroData,lv + 1) or false return isShow end --筛选符合条件的所有神将 function this.GetGodSoulData(curHeroData,lv) local datas = HeroManager.GetAllHeroList() local godData = this.GetGodSoulDataByLv(curHeroData.heroConfig.Id,lv) local haveDatas = {} if godData then for k,v in pairs(datas) do if v.star >= 10 and curHeroData.dynamicId ~= v.dynamicId then local index = -1 --无法使用 for j = 1,#godData do local isChoosed = this.CheckExistBindHeroDataByDid(curHeroData.dynamicId,v.dynamicId) --LogGreen("isChoosed:"..isChoosed.." lv:"..lv.." v.heroConfig.Id:"..v.heroConfig.Id.." index:"..index) if godData[j].id > 0 and v.heroConfig.Id == godData[j].id then if isChoosed and isChoosed == lv then index = 666 elseif v.star >= godData[j].star then index = 665 else index = 664 end break elseif isChoosed > 0 and isChoosed ~= lv then --LogYellow("isChoosed:"..isChoosed.." lv:"..lv.." v.heroConfig.Id:"..v.heroConfig.Id.." index:"..index) index = 0 break elseif (v.star >= godData[j].star) then if (godData[j].property > 0 and v.property == godData[j].property) or (godData[j].profession > 0 and v.profession == godData[j].profession) or (godData[j].property == 0 and godData[j].profession == 0) then if index == -1 then index = 0 end end if (godData[j].property > 0 and v.property == godData[j].property) then index = index + 1 elseif (godData[j].profession > 0 and v.profession == godData[j].profession) then index = index + 1 elseif godData[j].property == 0 and godData[j].profession == 0 then index = index + 1 end else end end --LogGreen("index:"..index.." v.heroConfig.Id:"..v.heroConfig.Id) table.insert(haveDatas,{state = index,herodata = v}) end end end table.sort(haveDatas,function(a,b) if a.state == b.state then if a.herodata.star == b.herodata.star then return a.herodata.star > b.herodata.star end return a.herodata.heroConfig.Sort < b.herodata.heroConfig.Sort end return a.state > b.state end) -- for k,v in ipairs(haveDatas) do -- LogGreen("v.state:"..v.state.." v.heroConfig.Id:"..v.herodata.heroConfig.Id) -- end return haveDatas end --检测所选择神将是否满足激活神魂 function this.CheckCanUpGodSoul(curHeroData,lv,datas) local godDatas = HeroManager.GetAllHeroList() if datas then godDatas = {} for i = 1,#datas do local tempData = HeroManager.GetSingleHeroData(datas[i]) table.insert(godDatas,tempData) end end local godData = this.GetGodSoulDataByLv(curHeroData.heroConfig.Id,lv) local enoughData = {} --每个条件满足的数量 local enoughDatas = {} --每个条件是否满足 for j = 1,#godData do if not enoughData[j] then enoughData[j] = 0 end end for j = 1,#godData do if not enoughDatas[j] then enoughDatas[j] = false end end local s = function() local isAll = true enoughDatas = {} for i = 1,#enoughData do if enoughData[i] < godData[i].num then isAll = false enoughDatas[i] = false else enoughDatas[i] = true end end return isAll,enoughData,enoughDatas end if godData then for k,v in pairs(godDatas) do local isChoosed = this.CheckExistBindHeroDataByDid(curHeroData.dynamicId,v.dynamicId) if isChoosed and isChoosed ~= lv and isChoosed > 0 then else for j = 1,#godData do if v.star >= godData[j].star then if godData[j].id > 0 and v.heroConfig.Id == godData[j].id then enoughData[j] = enoughData[j] + 1 elseif godData[j].property > 0 and v.property == godData[j].property then enoughData[j] = enoughData[j] + 1 elseif godData[j].profession > 0 and v.profession == godData[j].profession then enoughData[j] = enoughData[j] + 1 elseif godData[j].property == 0 and godData[j].profession == 0 and godData[j].id == 0 then enoughData[j] = enoughData[j] + 1 end local isAll,enoughData,enoughDatas = s() if isAll then return isAll,enoughData,enoughDatas end end end end end return s() end return false,enoughData,enoughDatas end function this.GetHeroGodSoulDatas(dynamicId,id,_lv) local lv = _lv or 0 if HeroManager.GetHongMengData(dynamicId) then lv = this.GetGodSoulLv(dynamicId) or 0 end local data = {} for j = 1,#heroConfig[id].SoulSkill do if heroConfig[id].SoulSkill[j][1] <= lv then table.insert(data,heroConfig[id].SoulSkill[j][2]) end end return data end return this