miduo_client/Assets/ManagedResources/~Lua/Modules/GodSoul/GodSoulManager.lua

532 lines
19 KiB
Lua
Raw Normal View History

2021-10-18 10:36:32 +08:00
GodSoulManager = {}
local this = GodSoulManager
2021-10-20 18:02:09 +08:00
local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
2021-10-22 15:47:59 +08:00
local heroRankupGroup = ConfigManager.GetConfig(ConfigName.HeroRankupGroup)
local passiveSkillConfig = ConfigManager.GetConfig(ConfigName.PassiveSkillConfig)
2021-10-18 10:36:32 +08:00
this.heroDatas = {}
2021-10-20 18:02:09 +08:00
this.GodSoulTableData = {}
2021-10-18 10:36:32 +08:00
function this.Initialize()
2021-10-22 15:47:59 +08:00
this.InitializeTableData()
this.heroDatas = {}
2021-10-18 10:36:32 +08:00
end
function this.InitializeTableData()
2021-10-20 18:02:09 +08:00
for k,v in ConfigPairs(heroConfig) do
if not this.GodSoulTableData[v.Id] then
this.GodSoulTableData[v.Id] = {}
end
2021-10-22 15:47:59 +08:00
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
2021-10-20 18:02:09 +08:00
end
2021-10-22 15:47:59 +08:00
local data = {}
data.index = v.Soul[i][2]
2021-11-01 19:11:59 +08:00
data.num = 1 --v.Soul[i][4]
2021-10-22 15:47:59 +08:00
local config = heroRankupGroup[v.Soul[i][3]]
if config.Issame == 1 then
data.id = v.Id
2021-10-27 12:50:15 +08:00
data.property = 0
data.profession = 0
2021-10-22 15:47:59 +08:00
elseif config.IsId > 0 then
data.id = config.IsId
2021-10-27 12:50:15 +08:00
data.property = 0
data.profession = 0
2021-10-20 18:02:09 +08:00
else
2021-10-22 15:47:59 +08:00
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
2021-10-20 18:02:09 +08:00
end
2021-10-22 15:47:59 +08:00
data.star = config.StarLimit
2021-11-01 19:11:59 +08:00
for j = 1,v.Soul[i][4] do
table.insert(this.GodSoulTableData[v.Id][v.Soul[i][1]],data)
end
2021-10-20 18:02:09 +08:00
end
end
end
2021-10-18 10:36:32 +08:00
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
2021-10-26 16:00:31 +08:00
this.heroDatas[heroData.id].BindHeroDatas = {}
2021-10-18 10:36:32 +08:00
end
2021-10-22 15:47:59 +08:00
for k,v in ipairs(heroData.godSoulList) do
2021-10-18 10:36:32 +08:00
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
2021-10-26 16:00:31 +08:00
if this.CheckExistBindHeroDataByDid(heroData.id,m) and this.CheckExistBindHeroDataByDid(heroData.id,m) > 0 then
2021-10-18 10:36:32 +08:00
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
2021-10-26 16:00:31 +08:00
if not this.heroDatas[Id].BindToHeroDatas then
2021-10-18 10:36:32 +08:00
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
2021-10-26 16:00:31 +08:00
if m == bindId then
2021-10-18 10:36:32 +08:00
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绑定的
2021-10-26 16:00:31 +08:00
function this.UnBindHeroDatas(curId,curlv,isOnly)
2021-10-18 10:36:32 +08:00
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
2021-10-26 16:00:31 +08:00
if (k >= curlv and not isOnly) or (isOnly and k == curlv) then
2021-10-18 10:36:32 +08:00
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
2021-10-22 15:47:59 +08:00
--获取id,lv级绑定的神将
2021-11-01 19:11:59 +08:00
function this.GetBindHeroDatasByLevel(id,lv,conditionIndex)
2021-10-22 15:47:59 +08:00
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
2021-10-27 17:42:50 +08:00
for i = 1,#v do
2021-11-01 19:11:59 +08:00
if conditionIndex and i == conditionIndex then
table.insert(data,v[i])
elseif not conditionIndex then
table.insert(data,v[i])
end
2021-10-27 17:42:50 +08:00
end
break
2021-10-22 15:47:59 +08:00
end
end
return data
end
--获取激活神魂所需的神将条件
2021-11-01 19:11:59 +08:00
function this.GetGodSoulDataByLv(id,lv,conditionIndex)
2021-10-20 18:02:09 +08:00
if lv == 0 then
2021-10-22 15:47:59 +08:00
return this.GodSoulTableData[id] or {}
2021-10-20 18:02:09 +08:00
end
if this.GodSoulTableData[id] and this.GodSoulTableData[id][lv] and #this.GodSoulTableData[id][lv] > 0 then
2021-11-01 19:11:59 +08:00
if conditionIndex and conditionIndex > 0 then
return {this.GodSoulTableData[id][lv][conditionIndex]}
else
return this.GodSoulTableData[id][lv]
end
2021-10-20 18:02:09 +08:00
end
2021-10-22 15:47:59 +08:00
return {}
2021-10-20 18:02:09 +08:00
end
2021-11-02 10:20:17 +08:00
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
2021-10-22 15:47:59 +08:00
--检测红点
2021-10-20 18:02:09 +08:00
function this.CheckRedPointGodSoul(curHeroData)
2021-10-27 17:04:33 +08:00
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.shenhun)
or curHeroData.heroConfig.IsSoulOpen == 0 or curHeroData.star < 11 then
return false
2021-10-20 18:02:09 +08:00
end
local lv = this.GetGodSoulLv(curHeroData.dynamicId)
2021-11-03 10:13:44 +08:00
local isShow = this.CheckCanUpGodSoul2(curHeroData,lv + 1) or false
2021-10-27 17:04:33 +08:00
return isShow
2021-10-20 18:02:09 +08:00
end
2021-10-22 15:47:59 +08:00
--筛选符合条件的所有神将
2021-11-01 19:11:59 +08:00
function this.GetGodSoulData(curHeroData,lv,conditionIndex)
2021-10-20 18:02:09 +08:00
local datas = HeroManager.GetAllHeroList()
2021-11-01 19:11:59 +08:00
local godData = this.GetGodSoulDataByLv(curHeroData.heroConfig.Id,lv,conditionIndex)
2021-10-20 18:02:09 +08:00
local haveDatas = {}
if godData then
2021-10-22 15:47:59 +08:00
for k,v in pairs(datas) do
2021-10-26 16:00:31 +08:00
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)
2021-11-03 10:13:44 +08:00
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
2021-10-26 16:00:31 +08:00
index = 666
2021-11-03 10:13:44 +08:00
elseif isChoosed > 0 and isChoosed ~= lv then
2021-10-26 16:00:31 +08:00
index = 664
2021-11-03 10:13:44 +08:00
else
index = 665
2021-10-26 16:00:31 +08:00
end
break
elseif isChoosed > 0 and isChoosed ~= lv then
index = 0
break
2021-11-01 19:11:59 +08:00
elseif (v.star >= godData[j].star) and godData[j].id < 1 then
2021-10-26 16:00:31 +08:00
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
table.insert(haveDatas,{state = index,herodata = v})
end
2021-10-20 18:02:09 +08:00
end
end
2021-10-26 16:00:31 +08:00
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
2021-10-20 18:02:09 +08:00
return haveDatas
end
2021-10-22 15:47:59 +08:00
--检测所选择神将是否满足激活神魂
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
2021-10-20 18:02:09 +08:00
local godData = this.GetGodSoulDataByLv(curHeroData.heroConfig.Id,lv)
2021-10-27 12:50:15 +08:00
local enoughData = {} --每个条件满足的数量
local enoughDatas = {} --每个条件是否满足
2021-10-20 18:02:09 +08:00
for j = 1,#godData do
if not enoughData[j] then
enoughData[j] = 0
end
end
2021-10-27 12:50:15 +08:00
for j = 1,#godData do
if not enoughDatas[j] then
enoughDatas[j] = false
end
end
2021-10-20 18:02:09 +08:00
local s = function()
local isAll = true
2021-10-27 12:50:15 +08:00
enoughDatas = {}
2021-10-20 18:02:09 +08:00
for i = 1,#enoughData do
2021-10-22 15:47:59 +08:00
if enoughData[i] < godData[i].num then
2021-10-20 18:02:09 +08:00
isAll = false
2021-10-27 12:50:15 +08:00
enoughDatas[i] = false
else
enoughDatas[i] = true
2021-10-20 18:02:09 +08:00
end
end
2021-10-27 12:50:15 +08:00
return isAll,enoughData,enoughDatas
2021-10-20 18:02:09 +08:00
end
if godData then
2021-10-27 18:03:09 +08:00
for k,v in pairs(godDatas) do
if curHeroData.dynamicId == v.dynamicId then
2021-10-22 15:47:59 +08:00
else
2021-10-27 18:03:09 +08:00
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
2021-10-27 12:50:15 +08:00
end
2021-10-22 15:47:59 +08:00
end
2021-10-27 12:50:15 +08:00
end
end
2021-10-20 18:02:09 +08:00
end
return s()
end
2021-10-27 12:50:15 +08:00
return false,enoughData,enoughDatas
2021-10-20 18:02:09 +08:00
end
2021-10-18 10:36:32 +08:00
2021-11-03 10:13:44 +08:00
--检测所选择神将是否满足激活神魂
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当前神将 curHeroDatacurLv 当前等级
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
2021-10-26 16:00:31 +08:00
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
2021-10-18 10:36:32 +08:00
return this