101 lines
3.0 KiB
Lua
101 lines
3.0 KiB
Lua
HeroTempPropManager = {}
|
|
local this = HeroTempPropManager
|
|
|
|
function this.Initialize()
|
|
this.TempHeroDatas = {}
|
|
end
|
|
-- 临时数据的生成规则
|
|
function this.GetTempHeroID(dId)
|
|
return "TEMP_"..dId
|
|
end
|
|
-- 判断是否是临时数据
|
|
function this.IsTempHeroID(tempId)
|
|
if startWith(tempId, "TEMP_") then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
-- 根据临时ID获取did
|
|
function this.GetDynamicIdByTempId(tempId)
|
|
if this.IsTempHeroID(tempId) then
|
|
return string.gsub(tempId, "TEMP_", "")
|
|
end
|
|
return tempId
|
|
end
|
|
-- 复制一个神将数据,不影响原数据
|
|
function this.CreateTempHero(dId)
|
|
if this.IsTempHeroID(dId) then
|
|
assert(false, "正在尝试复制一条临时数据")
|
|
return
|
|
end
|
|
local tempId = this.GetTempHeroID(dId)
|
|
-- 清空缓存
|
|
this.ClearTempHero(tempId)
|
|
-- 复制属性
|
|
local tempData = Table_DeepCopy(HeroPropManager.CreateHeroCountData(dId))
|
|
-- 保存
|
|
tempData.dId = tempId
|
|
this.TempHeroDatas[tempId] = tempData
|
|
return tempId, tempData
|
|
end
|
|
-- 判断数据是否存在
|
|
function this.IsTempHeroExist(tempId)
|
|
if this.TempHeroDatas[tempId] then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
-- 获取临时英雄数据
|
|
function this.GetTempHero(tempId)
|
|
return this.TempHeroDatas[tempId]
|
|
end
|
|
-- 清空缓存数据
|
|
function this.ClearTempHero(tempId)
|
|
this.TempHeroDatas[tempId] = nil
|
|
HeroPropManager.ClearHeroData(tempId)
|
|
end
|
|
|
|
-- 更新用于计算临时属性的编队
|
|
function this.UpdateTempFormation(tempId, formationId)
|
|
local dId = this.GetDynamicIdByTempId(tempId)
|
|
local teamInfo = FormationManager.GetFormationByID(formationId)
|
|
local heroList = {}
|
|
if teamInfo and teamInfo.teamHeroInfos and #teamInfo.teamHeroInfos > 0 then
|
|
for _, hero in ipairs(teamInfo.teamHeroInfos) do
|
|
local h = {}
|
|
h.heroId = hero.heroId
|
|
h.position = hero.position
|
|
-- 将对应的人替换成临时数据
|
|
if h.heroId == dId then
|
|
h.tempHeroId = tempId
|
|
end
|
|
table.insert(heroList, h)
|
|
end
|
|
-- 刷新用于计算临时属性的编队
|
|
FormationManager.UpdateTemporaryFormation(FormationTypeDef.FORMATION_TEMPORARY_PROP, heroList)
|
|
end
|
|
end
|
|
|
|
-- 获取临时英雄属性
|
|
function this.GetTempHeroProp(tempId, formationId)
|
|
if this.IsTempHeroExist(tempId) then
|
|
if formationId then
|
|
this.UpdateTempFormation(tempId, formationId)
|
|
formationId = FormationTypeDef.FORMATION_TEMPORARY_PROP
|
|
end
|
|
return HeroPropManager.GetHeroProp(tempId, formationId)
|
|
end
|
|
end
|
|
-- 获取临时英雄属性
|
|
function this.GetTempHeroPower(tempId, formationId)
|
|
if this.IsTempHeroExist(tempId) then
|
|
if formationId then
|
|
this.UpdateTempFormation(tempId, formationId)
|
|
formationId = FormationTypeDef.FORMATION_TEMPORARY_PROP
|
|
end
|
|
return HeroPowerManager.GetHeroPower(tempId, formationId)
|
|
end
|
|
end
|
|
|
|
|
|
return HeroTempPropManager |