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 = 1 --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 for j = 1,v.Soul[i][4] do table.insert(this.GodSoulTableData[v.Id][v.Soul[i][1]],data) end 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,conditionIndex) 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 for i = 1,#v do if conditionIndex and i == conditionIndex then table.insert(data,v[i]) elseif not conditionIndex then table.insert(data,v[i]) end end break end end return data end --获取激活神魂所需的神将条件 function this.GetGodSoulDataByLv(id,lv,conditionIndex) 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 if conditionIndex and conditionIndex > 0 then return {this.GodSoulTableData[id][lv][conditionIndex]} else return this.GodSoulTableData[id][lv] end end return {} end function this.MergeGodSoulDataByLv(heroId,lv) local tempData = {} for k,v in ipairs(heroConfig[heroId].Soul) do if v[1] == lv then local data = {} data.index = v[2] data.num = v[4] local config = heroRankupGroup[v[3]] if config.Issame == 1 then data.id = heroConfig[heroId].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 = heroConfig[heroId].PropertyName else data.property = 0 end if config.IsSameJob == 1 then data.profession = heroConfig[heroId].Profession else data.profession = 0 end end data.star = config.StarLimit table.insert(tempData,data) end end return tempData 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.CheckCanUpGodSoul2(curHeroData,lv + 1) or false return isShow end --筛选符合条件的所有神将 function this.GetGodSoulData(curHeroData,lv,conditionIndex) local datas = HeroManager.GetAllHeroList() local godData = this.GetGodSoulDataByLv(curHeroData.heroConfig.Id,lv,conditionIndex) 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) if godData[j].id > 0 and v.heroConfig.Id == godData[j].id then if v.star < godData[j].star then index = -1 elseif isChoosed and isChoosed == lv then index = 666 elseif isChoosed > 0 and isChoosed ~= lv then index = 664 else index = 665 end break elseif isChoosed > 0 and isChoosed ~= lv then index = 0 break elseif (v.star >= godData[j].star) and godData[j].id < 1 then if (godData[j].property > 0 and v.heroConfig.PropertyName == 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.heroConfig.PropertyName == 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 table.insert(haveDatas,{state = index,herodata = v,skinId=v.skinId}) 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 if curHeroData.dynamicId == v.dynamicId then else 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 end return s() end return false,enoughData,enoughDatas end --检测所选择神将是否满足激活神魂 function this.CheckCanUpGodSoul2(curHeroData,lv) local godDatas = HeroManager.GetAllHeroList() local godData = this.GetGodSoulDataByLv(curHeroData.heroConfig.Id,lv) if godData and #godData > 0 then local godSingleDatas = {} for i = 1,#godData do godSingleDatas[i] = 0 end -- for k,v in pairs(godDatas) do -- LogGreen("v.heroConfig.Id:"..v.heroConfig.Id) -- end -- coroutine.start(function() -- this.PutQueen(godData, godDatas,1,godSingleDatas,curHeroData,lv) -- end) --用条件进行匹配,使得满足条件 --return this.PutQueen(godData, godDatas,1,godSingleDatas,curHeroData,lv) else return false end return false end -- 放置神将 --godData 条件 -- 神将列表 --下一个条件 --已经放置的条件 --当前神将 当前等级 function this.PutQueen(godData, godDatas, nextIndex,godSingleDatas,curHeroData,lv) for k,v in pairs(godDatas) do coroutine.wait(0.01) if this.CheckoutCanPut(v,godSingleDatas,nextIndex,godData[nextIndex],curHeroData,lv) then nextIndex = nextIndex + 1 if this.CheckConditionEnough(godSingleDatas)then return true else if this.PutQueen(godData, godDatas, nextIndex,godSingleDatas,curHeroData,lv) then return true end end nextIndex = nextIndex - 1 godSingleDatas[nextIndex] = 0 end end return false end -- 是否满足条件 function this.CheckConditionEnough(godSingleDatas) for i = 1,#godSingleDatas do if not tonumber(godSingleDatas[i]) and godSingleDatas[i] and godSingleDatas[i].dynamicId then else return false end end return true end --heroData 要放置的神将 heroList 已经放置的神将列表 index 放置位置 condition 放置条件 curHeroData,当前神将 curHeroData,curLv 当前等级 function this.CheckoutCanPut(heroData,heroList,index,condition,curHeroData,curLv) --这个神将不是它本身 并且这个神将可以选择(没有被其他位置选择) local returnValue = false if heroData.dynamicId ~= curHeroData.dynamicId and not this.HaveHeroData(heroData,heroList,index) then --这个神将满足这个位置的条件 if this.CheckCanUpGodSoul3(heroData,condition,curHeroData,curLv) then heroList[index] = heroData returnValue = true else returnValue = false end end return returnValue end --这个神将没有被其他位置选择并且这个神将不是他本身 function this.HaveHeroData(heroData,heroList,pos) for i = 1,#heroList do if not tonumber(heroList[i]) and heroList[i].dynamicId and heroData.dynamicId == heroList[i].dynamicId then return true end end return false end --检测所选择神将是否满足激活神魂 function this.CheckCanUpGodSoul3(heroData,condition,curHeroData,curLv) if condition then local isChoosed = this.CheckExistBindHeroDataByDid(curHeroData.dynamicId,heroData.dynamicId) if isChoosed and isChoosed > 0 and isChoosed ~= curLv then return false else if heroData.star >= condition.star then if condition.id > 0 and heroData.heroConfig.Id == condition.id then return true elseif condition.property > 0 and heroData.property == condition.property then return true elseif condition.profession > 0 and heroData.profession == condition.profession then return true elseif condition.property == 0 and condition.profession == 0 and condition.id == 0 then return true end end end end return false 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