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

150 lines
4.2 KiB
Lua

GodSoulManager = {}
local this = GodSoulManager
this.heroDatas = {}
function this.Initialize()
end
function this.InitializeTableData()
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 = {} --绑定了哪些神将
this.heroDatas[heroData.id].BindToHeroDatas = {} --被绑定了哪些神将
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) > 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].BindHeroDatas then
this.heroDatas[Id].BindHeroDatas = {} --绑定了哪些神将
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 v == 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)
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 then
for n,m in ipairs(v) do
this.UnBindToHeroDatas(m,curId)
return
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
return this