168 lines
5.5 KiB
Lua
168 lines
5.5 KiB
Lua
|
|
local propertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
|
|
|
|
HeroPowerManager = {}
|
|
local this = HeroPowerManager
|
|
|
|
--计算战斗力
|
|
local propToSS = {}
|
|
|
|
local function CalculateWarForce(powerVal)
|
|
local powerEndVal = 0
|
|
for i, v in pairs(powerVal) do
|
|
if v > 0 and i < HeroProType.WarPower then
|
|
-- 计算战斗
|
|
local power = v * propertyConfig[i].Score
|
|
powerEndVal = powerEndVal + power
|
|
elseif v > 0 and i >= HeroProType.WarPower then
|
|
powerEndVal = powerEndVal + v
|
|
end
|
|
end
|
|
return math.floor(powerEndVal)
|
|
end
|
|
local function CalculateWarForce2(powerVal)
|
|
local powerEndVal = 0
|
|
local basePower = 0
|
|
local HighPower = 0
|
|
local extPower = 0
|
|
for i, v in pairs(powerVal) do
|
|
if v > 0 and i < HeroProType.WarPower then
|
|
if propertyConfig[i].Style == 1 then
|
|
if propertyConfig[i].TargetPropertyId == 0 then
|
|
basePower = basePower + v*propertyConfig[i].Score
|
|
end
|
|
elseif propertyConfig[i].Style == 2 then
|
|
-- 这里百分比数要转换成小数,用于计算战斗力
|
|
--LogError("v====="..v.." propertyConfig[i].id=="..propertyConfig[i].Id)
|
|
HighPower = HighPower + v/100*propertyConfig[i].Score
|
|
end
|
|
elseif v > 0 and i == HeroProType.WarPower then
|
|
extPower = extPower + v
|
|
end
|
|
end
|
|
LogBlue_Prop("basePower: "..basePower)
|
|
LogBlue_Prop("HighPower: "..HighPower)
|
|
LogBlue_Prop("extPower: "..extPower)
|
|
--LogError("basePower=="..basePower.." HighPower=="..HighPower.." extPower=="..extPower)
|
|
powerEndVal = basePower * (1 + HighPower) + extPower
|
|
return math.floor(powerEndVal)
|
|
end
|
|
|
|
|
|
|
|
function this.Initialize()
|
|
this.HeroPowerList = {}
|
|
end
|
|
|
|
function this.LateUpdate()
|
|
if this.IsInitAll and this.coInitPower then
|
|
LogRed_Prop("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_Prop("co start")
|
|
for k, v in pairs(heroList) do
|
|
local power = this.GetHeroPower(v.dynamicId, nil, true)
|
|
v.warPower = power
|
|
LogRed_Prop("heroPower : "..v.dynamicId .. "|"..power)
|
|
-- coroutine.wait(0.01)
|
|
coroutine.yield()
|
|
end
|
|
this.IsInitAll = false
|
|
this.coInitPower = nil
|
|
LogRed_Prop("co end")
|
|
|
|
end
|
|
|
|
|
|
-- 初始化所有人的战斗力
|
|
function this.InitAllPower()
|
|
this.IsInitAll = true
|
|
if not this.coInitPower then
|
|
this.coInitPower = coroutine.create(this.CO_InitPower)
|
|
end
|
|
end
|
|
|
|
|
|
function this.CalPower(propList)
|
|
return CalculateWarForce2(propList)
|
|
end
|
|
|
|
|
|
-- 获取英雄战斗力
|
|
function this.GetHeroPower(dId, formationId, NoFuncProp)
|
|
if not this.HeroPowerList[dId] then
|
|
this.HeroPowerList[dId] = {}
|
|
end
|
|
-- 判断是否脏数据
|
|
if formationId ~= nil or this.HeroPowerList[dId].isDirty ~= false then
|
|
LogYellow_Prop("++++++++++++++++++++++++++++++++++")
|
|
local heroData = HeroPropManager.CreateHeroCountData(dId)
|
|
LogRed_Prop("heroTID: "..heroData.tId)
|
|
-- 重新计算人物属性
|
|
local propList = HeroPropManager.GetHeroProp(dId, formationId, NoFuncProp)
|
|
-- 计算战斗力
|
|
local allPower = this.CalPower(propList)
|
|
-- 旧战斗力
|
|
if HeroPropManager.IsDebug() and not NoFuncProp then
|
|
-- local curHeroData = HeroManager.GetSingleHeroData(dId)
|
|
-- local oldProp = HeroManager.CalculateHeroAllProValList(1, dId, false, nil, nil, nil, nil,nil, formationId)
|
|
-- local power = oldProp[HeroProType.WarPower]
|
|
-- if power ~= allPower then
|
|
-- LogGreenTable(REMOVE_ZERO_PROP(oldProp))
|
|
-- LogRed("GetHeroPower OldPower:"..tostring(power))
|
|
LogGreenTable(REMOVE_ZERO_PROP(propList))
|
|
LogRed("GetHeroPower NewPower:"..allPower)
|
|
-- end
|
|
end
|
|
LogYellow_Prop("++++++++++++++++++++++++++++++++++")
|
|
if formationId then
|
|
return allPower
|
|
else
|
|
this.HeroPowerList[dId].allPower = allPower
|
|
if NoFuncProp then
|
|
this.HeroPowerList[dId].isDirty = true
|
|
else
|
|
this.HeroPowerList[dId].isDirty = false
|
|
end
|
|
end
|
|
end
|
|
--
|
|
return this.HeroPowerList[dId].allPower
|
|
end
|
|
-- 获取英雄战斗力
|
|
function this.GetNextHeroPower(dId, formationId,breakId,upStarId)
|
|
local curHeroData = HeroManager.GetSingleHeroData(dId)
|
|
local oldBreakId = curHeroData.breakId
|
|
local oldStarId = curHeroData.upStarId
|
|
HeroManager.UpdateSingleHeroDatas(dId, curHeroData.lv, curHeroData.star, breakId, upStarId)
|
|
local curAllPro = HeroPropManager.GetHeroProp(curHeroData.dynamicId,formationId)
|
|
local curPower = this.GetHeroPower(dId, formationId)
|
|
HeroManager.UpdateSingleHeroDatas(dId, curHeroData.lv, curHeroData.star, oldBreakId, oldStarId)
|
|
return curAllPro,curPower
|
|
end
|
|
|
|
-- 设置战斗力为脏数据
|
|
function this.SetPowerDirty(dId)
|
|
if not this.HeroPowerList[dId] then
|
|
this.HeroPowerList[dId] = {}
|
|
end
|
|
this.HeroPowerList[dId].isDirty = true
|
|
end
|
|
|
|
-- 设置所有战斗力为脏数据
|
|
function this.SetAllPowerDirty()
|
|
for k, v in pairs(this.HeroPowerList) do
|
|
this.HeroPowerList[k].isDirty = true
|
|
end
|
|
end
|
|
|
|
|
|
return HeroPowerManager |