miduo_client/Assets/ManagedResources/~Lua/Modules/Hero/HeroPowerManager.lua

75 lines
1.7 KiB
Lua

HeroPowerManager = {}
local this = HeroPowerManager
--计算战斗力
local function CalculateWarForce(powerVal)
local powerEndVal = 0
for i, v in pairs(powerVal) do
if v > 0 then
powerEndVal = powerEndVal + v * HeroManager.heroPropertyScore[i]
end
end
return math.floor(powerEndVal)
end
function this.Initialize()
this.HeroPowerList = {}
end
function this.LateUpdate()
if this.IsInitAll and this.coInitPower then
-- LogRed("coStatus : "..coroutine.status(this.coInitPower))
-- if coroutine.status(this.coInitPower) == "suspended" then
-- coroutine.resume(this.coInitPower)
-- end
end
end
-- 卸程计算每个人的战斗力
function this.CO_InitPower()
local heroList = HeroManager.GetAllHeroList()
LogRed("co start")
for k, v in pairs(heroList) do
local power = this.GetHeroPower(v.dynamicId)
v.warPower = power
LogRed("heroPower : "..v.dynamicId .. "|"..power)
-- coroutine.yield()
end
this.IsInitAll = false
this.coInitPower = nil
LogRed("co end")
end
-- 初始化所有人的战斗力
function this.InitAllPower()
this.IsInitAll = true
-- if not this.coInitPower then
-- this.coInitPower = coroutine.create(this.CO_InitPower)
-- end
this.CO_InitPower()
end
-- 获取英雄战斗力
function this.GetHeroPower(dId, formationId)
-- 重新计算战斗力
local propList = HeroPropManager.GetHeroProp(dId, formationId)
local allPower = CalculateWarForce(propList)
--
if not this.HeroPowerList[dId] then
this.HeroPowerList[dId] = {}
end
this.HeroPowerList[dId].allPower = allPower
return this.HeroPowerList[dId].allPower
end
return HeroPowerManager