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

731 lines
24 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

function REMOVE_ZERO_PROP(propList)
local list = {}
for k, v in pairs(propList) do
if v ~= 0 then
list[k] = v
end
end
return list
end
-- debug用
local _IsDebug = false
local emptyFunc = function()end
local noZeroFunc = function(func)
return function(propList)
if propList then
if func then
func(REMOVE_ZERO_PROP(propList))
end
end
end
end
Log_Prop = _IsDebug and Log or emptyFunc
LogRed_Prop = _IsDebug and LogRed or emptyFunc
LogBlue_Prop = _IsDebug and LogBlue or emptyFunc
LogGreen_Prop = _IsDebug and LogGreen or emptyFunc
LogPink_Prop = _IsDebug and LogPink or emptyFunc
LogYellow_Prop = _IsDebug and LogYellow or emptyFunc
LogRedTable_Prop = _IsDebug and noZeroFunc(LogRedTable) or emptyFunc
LogBlueTable_Prop = _IsDebug and noZeroFunc(LogBlueTable) or emptyFunc
LogGreenTable_Prop = _IsDebug and noZeroFunc(LogGreenTable) or emptyFunc
LogPinkTable_Prop = _IsDebug and noZeroFunc(LogPinkTable) or emptyFunc
local propertyConfig = ConfigManager.GetConfig(ConfigName.PropertyConfig)
local heroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
--
require("Modules.Hero.PropHero")
require("Modules.Hero.PropFunc")
require("Modules.Hero.PropCondition")
HeroPropManager = {}
local this = HeroPropManager
function this.IsDebug()
return _IsDebug
end
-- 合并属性列表
local function DoubleTableCompound(allProVal, addProVal)
if addProVal and LengthOfTable(addProVal) > 0 then
for k, v in pairs(addProVal) do
if v > 0 then
if allProVal[k] then
allProVal[k] = allProVal[k] + v
else
allProVal[k] = v
end
end
end
end
end
function this.Initialize()
this.HeroDataList = {}
this.HeroPropList = {} -- 角色自身属性
this.IsHeroDirty = {} -- 判断数据是否需要刷新
this.ConList = {} -- 自身的一些条件
this.ConPropList = {} -- 条件属性
this.IsConPropDirty = {} -- 脏数据判断
this.TeamPropList = {} -- 角色自身对编队成员的加成
this.IsTeamPropDirty = {}
this.ConTeamList = {} -- 编队条件属性
this.DePropList = {} -- 减益属性
this.IsDePropDirty = {} -- 判断减益数据是否变化
this.FormationPropList = {} -- 编队共鸣属性
this.IsFormationDirty = {} -- 判断编队共鸣数据是否需要刷新
this.FuncPropList = {} -- 功能属性(作用于全体)
this.IsFuncDirty = {} -- 判断功能属性是否需要刷新
end
function this.ClearHeroData(dId)
if this.HeroPropList[dId] then
this.HeroPropList[dId] = {}
end
if this.IsHeroDirty[dId] then
this.IsHeroDirty[dId] = {}
end
if this.ConList[dId] then
this.ConList[dId] = {}
end
if this.ConPropList[dId] then
this.ConPropList[dId] = {}
end
if this.IsConPropDirty[dId] then
this.IsConPropDirty[dId] = {}
end
if this.TeamPropList[dId] then
this.TeamPropList[dId] = {}
end
if this.IsTeamPropDirty[dId] then
this.IsTeamPropDirty[dId] = {}
end
if this.ConTeamList[dId] then
this.ConTeamList[dId] = {}
end
if this.DePropList[dId] then
this.DePropList[dId] = {}
end
if this.IsDePropDirty[dId] then
this.IsDePropDirty[dId] = {}
end
if this.FormationPropList[dId] then
this.FormationPropList[dId] = {}
end
if this.IsFormationDirty[dId] then
this.IsFormationDirty[dId] = {}
end
if this.FuncPropList[dId] then
this.FuncPropList[dId] = {}
end
if this.IsFuncDirty[dId] then
this.IsFuncDirty[dId] = {}
end
end
-- 创建用于计算英雄属性和战斗力的数据
function this.CreateHeroCountData(dId)
-- 判断是否是临时数据
if HeroTempPropManager.IsTempHeroID(dId) then
if HeroTempPropManager.IsTempHeroExist(dId) then
local tempData = HeroTempPropManager.GetTempHero(dId)
if tempData then
return tempData
end
end
assert(false, "是临时数据ID但未找到临时数据"..dId)
end
-- 判断是否有缓存
if this.HeroDataList[dId] then
return this.HeroDataList[dId]
end
-- 默认数据
local heroData = {
dId = 0,
tId = 0,
lv = 1,
star = 1,
breakId = 1,
upStarId = 1,
skinId = 0,
equipList = {},
treasureList = {},
soulPrintList = {},
godPrintList = {},
talismanLv = 1,
formationId = FormationTypeDef.FORMATION_NORMAL,
zhenYingId=0,
faxiang={},
}
if not dId then
return heroData
end
local curHeroData = HeroManager.GetSingleHeroData(dId)
if not curHeroData then
return heroData
end
heroData.dId = curHeroData.dynamicId -- 动态id
heroData.tId = curHeroData.id -- 表id
heroData.lv = curHeroData.lv -- 等级
heroData.star = curHeroData.star -- 星级
heroData.breakId = curHeroData.breakId -- 突破id
heroData.upStarId = curHeroData.upStarId -- 升星id
heroData.skinId = curHeroData.skinId -- 皮肤id
heroData.equipList = EquipManager.GetHeroEquipsBydIds(curHeroData.dynamicId, curHeroData.equipIdList) -- 装备数据
heroData.treasureList = EquipTreasureManager.GetTreasuresBydIds(curHeroData.jewels) -- 宝器数据
heroData.soulPrintList = curHeroData.soulPrintList -- 魂印数据
heroData.godPrintList = curHeroData.godPrintList
heroData.talismanLv = curHeroData.talismanList -- 法宝等级
heroData.formationId = FormationTypeDef.FORMATION_NORMAL
heroData.zhenYingId = curHeroData.changeProId
heroData.faxiang=curHeroData.faxiang
return heroData
end
function this.FinalShowDeal(heroData, propList)
-- 万分比转为百分比,这里处理用于兼容显示
for i, v in pairs(propList) do
if v > 0 and i < HeroProType.WarPower then
if propertyConfig[i].Style == 2 then
propList[i] = propList[i] / 100
end
end
end
-- 减去默认属性
local config = heroConfig[heroData.tId]
local subProp = config.SecondaryFactor
if subProp then
for i = 1, #subProp do
local propType = subProp[i][1]
local propValue = subProp[i][2]/100 -- 百分比数
if propList[propType] then
propList[propType] = propList[propType] - propValue
end
end
end
-- 将百分比加成计算到人物基础数值上
for k, v in pairs(propList) do
if k < HeroProType.WarPower then
local tpId = propertyConfig[k].TargetPropertyId
if propList[k] > 0 and tpId > 0 then
if k ~= 69 and k ~= 70 then--PVP 增减伤 没有处理
if not propList[tpId] then
propList[tpId] = 0
end
--LogError("tpid=="..tpId .." propList[k]=="..propList[k])
propList[tpId] = math.floor( propList[tpId] + propList[tpId] * propList[k] / 100)
end
end
else
propList[k] = v
end
end
return propList
end
-- 获取神将属性
function this.GetHeroProp(dId, formationId, NoFuncProp)
-- 清空数据
this.HeroDataList[dId] = nil
this.HeroDataList[dId] = this.CreateHeroCountData(dId)
--
local allPropList = {}
-- 获取基础属性
Log_Prop("基础属性")
local basePropList = this.GetBaseProp(dId)
LogGreenTable_Prop(basePropList)
DoubleTableCompound(allPropList, basePropList)
-- 自身条件属性加成
local conPropList = this.GetConditionProp(dId,formationId)
Log_Prop("自身条件属性")
LogGreenTable_Prop(conPropList)
DoubleTableCompound(allPropList, conPropList)
-- 获取功能属性加成
if not NoFuncProp then
local heroData = this.CreateHeroCountData(dId)
local funcProp = this.GetAllFuncProp(heroData,formationId)
Log_Prop("功能属性")
LogGreenTable_Prop(funcProp)
DoubleTableCompound(allPropList, funcProp)
else
Log_Prop("不计算功能属性")
end
-- 计算减益属性
--Log_Prop("减益属性")
--this.CountDeProp(dId, allPropList)
local isTempHero = HeroTempPropManager.IsTempHeroID(dId)
-- 判断是否需要加入团队属性加成
if formationId and (FormationManager.CheckFormationHasId(formationId, dId) or isTempHero) then
local formationList = FormationManager.GetFormationByID(formationId)
table.walk(formationList.teamHeroInfos, function(teamInfo)
local heroId = teamInfo.heroId
if isTempHero and teamInfo.tempHeroId then
heroId = teamInfo.tempHeroId
end
-- 团队属性加成
if heroId then
Log_Prop("团队属性")
local teamProp = this.GetTeamData(heroId)
LogGreenTable_Prop(teamProp)
DoubleTableCompound(allPropList, teamProp)
-- 团队条件属性加成
Log_Prop("团队条件属性")
local conTeamProp = this.GetConditionTeamData(heroId, dId,formationId)
LogGreenTable_Prop(conTeamProp)
DoubleTableCompound(allPropList, conTeamProp)
end
end)
-- 获取元素共鸣属性加成
Log_Prop("元素共鸣属性")
local formationProp = this.GetFormationProp(formationId)
LogGreenTable_Prop(formationProp)
DoubleTableCompound(allPropList, formationProp)
else
-- ******自己的团队属性对自己生效
-- 团队属性加成(
Log_Prop("团队属性")
local teamProp = this.GetTeamData(dId)
LogGreenTable_Prop(teamProp)
DoubleTableCompound(allPropList, teamProp)
-- 团队条件属性加成
Log_Prop("团队条件属性")
local conTeamProp = this.GetConditionTeamData(dId, dId)
LogGreenTable_Prop(conTeamProp)
DoubleTableCompound(allPropList, conTeamProp)
-- 没有元素共鸣
end
-- 处理前属性
Log_Prop("总属性")
LogGreenTable_Prop(allPropList)
-- 用于显示和战斗计算的处理
allPropList = this.FinalShowDeal(this.HeroDataList[dId], allPropList)
-- 处理后属性
Log_Prop("处理后属性")
LogGreenTable_Prop(allPropList)
return allPropList
end
---=================== 基础属性======================================
-- 获取基础属性
function this.GetBaseProp(dId)
-- 刷新角色信息
this.RefreshHeroProp(dId)
local basePropList = this.HeroPropList[dId].propList
return basePropList
end
-- 刷新角色信息
function this.RefreshHeroProp(dId)
if not this.IsHeroDirty[dId] then
this.IsHeroDirty[dId] = {}
end
-- 如果脏数据为空
if this.IsHeroDirty[dId].isDirty ~= false then
-- 创建计算属性的数据
local list = {}
local cData = this.CreateHeroCountData(dId)
for _, powerType in pairs(Hero_Prop_Type) do
--
local propList, conList, teamPropList, conTeamList, dePropList
-- 判断该类型数据是否需要刷新
if this.IsHeroDirty[dId][powerType] ~= false and Hero_Prop_Func[powerType] then
-- 计算属性
propList, conList, teamPropList, conTeamList, dePropList = Hero_Prop_Func[powerType](cData)
-- 创建新的数据
this.NewHeroProp(dId, powerType, propList)
LogGreen_Prop(_)
LogPink_Prop("base")
LogPinkTable_Prop(propList)
-- 条件属性
if not conList then
conList = {}
end
this.SetConditionData(dId, powerType, conList)
LogPink_Prop("con")
LogPinkTable_Prop(conList)
-- 对编队中其他人的数据
if not teamPropList then
teamPropList = {}
end
this.SetTeamData(dId, powerType, teamPropList)
LogPink_Prop("team")
LogPinkTable_Prop(teamPropList)
-- 对编队中其他人的数据
if not conTeamList then
conTeamList = {}
end
this.SetConditionTeamData(dId, powerType, conTeamList)
LogPink_Prop("conteam")
LogPinkTable_Prop(conTeamList)
-- 减益属性
if not dePropList then
dePropList = {}
end
this.SetDePropData(dId, powerType, dePropList)
LogPink_Prop("deprop")
LogPinkTable_Prop(dePropList)
--
this.IsHeroDirty[dId][powerType] = false
end
-- 加入
DoubleTableCompound(list, this.HeroPropList[dId][powerType])
end
-- 保存属性
this.HeroPropList[dId].propList = list
this.IsHeroDirty[dId].isDirty = false
end
end
-- 计算英雄自身数据
function this.CalHeroPropByType(heroData, powerType)
if not Hero_Prop_Func[powerType] then
return
end
-- 计算属性
local propList, conList, teamPropList, conTeamList, dePropList = Hero_Prop_Func[powerType](heroData)
return propList, conList, teamPropList, conTeamList, dePropList
end
-- 刷新角色属性信息
function this.NewHeroProp(dId, powerType, propList)
-- 普通属性加成
if not this.HeroPropList[dId] then
this.HeroPropList[dId] = {}
end
this.HeroPropList[dId][powerType] = propList
-- 清理脏数据
if not this.IsHeroDirty[dId] then
this.IsHeroDirty[dId] = {}
end
this.IsHeroDirty[dId][powerType] = false
end
-- 设置单个神将某一类型属性为脏数据
function this.SetDirtyByType(dId, powerType)
if not this.IsHeroDirty[dId] then
this.IsHeroDirty[dId] = {}
end
this.IsHeroDirty[dId][powerType] = true
this.IsHeroDirty[dId].isDirty = true
-- 战斗力需要重新计算
HeroPowerManager.SetPowerDirty(dId)
end
-- 设置某编队全部神将某一类型属性为脏数据
function this.SetFormationDirtyByType(formationType,powerType)
local herodata = FormationManager.GetFormationByID(formationType)--FormationTypeDef.FORMATION_NORMAL)
for k,v in pairs(herodata.teamHeroInfos) do
this.SetDirtyByType(v.heroId, powerType)
end
end
-- 将整个人置为脏数据
function this.SetHeroDirty(dId)
this.IsHeroDirty[dId] = {}
-- 战斗力需要重新计算
HeroPowerManager.SetPowerDirty(dId)
end
-- 将所有人某个数据置为脏数据
function this.SetAllHeroDirtyByType(powerType)
for dId, data in pairs(this.IsHeroDirty) do
data[powerType] = true
data.isDirty = true
-- 战斗力需要重新计算
HeroPowerManager.SetPowerDirty(dId)
end
end
--=========================== 条件属性管理 ==========================
-- 设置脏数据
function this.SetConditionData(dId, powerType, condList)
-- 编队属性加成
if not this.ConList[dId] then
this.ConList[dId] = {}
end
this.ConList[dId][powerType] = condList
-- 清理脏数据
if not this.IsConPropDirty[dId] then
this.IsConPropDirty[dId] = {}
end
this.IsConPropDirty[dId][powerType] = true
this.IsConPropDirty[dId].isDirty = true
end
function this.SetConditionProp(dId, powerType, condProp)
-- 编队属性加成
if not this.ConPropList[dId] then
this.ConPropList[dId] = {}
end
this.ConPropList[dId][powerType] = condProp
end
-- 获取条件属性
function this.GetConditionPropByType(dId, powerType)
if this.ConPropList[dId] and this.ConPropList[dId][powerType] then
return this.ConPropList[dId][powerType]
end
return {}
end
-- 获取自身的条件属性
function this.GetConditionProp(dId,teamId)
-- 判空
if not this.IsConPropDirty[dId] then
this.IsConPropDirty[dId] = {}
end
if this.IsConPropDirty[dId].isDirty ~= false then
-- 创建计算属性的数据
local list = {}
local formationList = FormationManager.GetFormationByID(teamId)
local cData = this.CreateHeroCountData(dId)
for _, powerType in pairs(Hero_Prop_Type) do
if this.IsConPropDirty[dId][powerType] ~= false then
local condProp = {}
if this.ConList[dId] and this.ConList[dId][powerType] then
for _, cond in ipairs(this.ConList[dId][powerType]) do
if Condition_Prop_Func[cond.type] then
local propList = Condition_Prop_Func[cond.type](cData, cData, cond.propList, cond.args,formationList)
DoubleTableCompound(condProp, propList)
end
end
end
-- 设置该类型条件属性
this.SetConditionProp(dId, powerType, condProp)
this.IsConPropDirty[dId][powerType] = false
end
-- 合并所有属性
local condProp = this.GetConditionPropByType(dId, powerType)
LogRedTable_Prop(condProp)
if condProp then
DoubleTableCompound(list, condProp)
-- this.IsConPropDirty[dId][powerType] = condProp
-- this.ConPropList[dId].propList = condProp
end
end
this.IsConPropDirty[dId].isDirty = false
this.ConPropList[dId].propList = list
end
return this.ConPropList[dId].propList
end
--=========================== 团队属性管理 ==========================
-- 设置脏数据
function this.SetTeamData(dId, powerType, propList)
-- 编队属性加成
if not this.TeamPropList[dId] then
this.TeamPropList[dId] = {}
end
this.TeamPropList[dId][powerType] = propList
-- 清理脏数据
if not this.IsTeamPropDirty[dId] then
this.IsTeamPropDirty[dId] = {}
end
this.IsTeamPropDirty[dId].isDirty = true
end
-- 刷新编队属性
function this.RefreshTeamData(dId)
-- 判空
if not this.IsTeamPropDirty[dId] then
this.IsTeamPropDirty[dId] = {}
end
if not this.TeamPropList[dId] then
this.TeamPropList[dId] = {}
end
-- 判断是否需要刷新
if this.IsTeamPropDirty[dId].isDirty ~= false then
-- 创建计算属性的数据
local list = {}
for _, powerType in pairs(Hero_Prop_Type) do
DoubleTableCompound(list, this.TeamPropList[dId][powerType])
end
--
this.TeamPropList[dId].propList = list
this.IsTeamPropDirty[dId].isDirty = false
end
end
-- 获取个人对编队的加成属性
function this.GetTeamData(dId)
-- 刷新团队加成属性
this.RefreshTeamData(dId)
--
if not this.TeamPropList[dId] then
return
end
return this.TeamPropList[dId].propList
end
--=========================== 团队条件属性管理 ==========================
-- 设置脏数据
function this.SetConditionTeamData(dId, powerType, condList)
-- 编队属性加成
if not this.ConTeamList[dId] then
this.ConTeamList[dId] = {}
end
this.ConTeamList[dId][powerType] = condList
end
-- 获取团队条件数据(动态计算,不缓存属性)
function this.GetConditionTeamData(dId, tdId,teamId)
local list = {}
local formationList = FormationManager.GetFormationByID(teamId)
if this.ConTeamList[dId] then
local dData = this.CreateHeroCountData(dId)
local tdData = this.CreateHeroCountData(tdId)
for powerType, conds in pairs(this.ConTeamList[dId]) do
for _, cond in ipairs(conds) do
if Condition_Prop_Func[cond.type] then
local propList = Condition_Prop_Func[cond.type](dData, tdData, cond.propList, cond.args,formationList)
DoubleTableCompound(list, propList)
end
end
end
end
return list
end
--=========================== 减益属性管理 ==========================
--
function this.SetDePropData(dId, powerType, propList)
-- 减益属性
if not this.DePropList[dId] then
this.DePropList[dId] = {}
end
this.DePropList[dId][powerType] = propList
end
-- 计算减益
function this.CountDeProp(dId, allPropList)
if this.DePropList[dId] then
for powerType, props in pairs(this.DePropList[dId]) do
for _, prop in ipairs(props) do
local id = prop.propId
local v = prop.value
Log_Prop(string.format("%s|%s", id, v))
-- allPropList[id] = allPropList[id] * (1 - v / 10000)
allPropList[id] = allPropList[id] * (1 - v)
end
end
end
end
-- ===============================================编队属性管理 ===================================
-- ===============================================编队属性管理 ===================================
-- ===============================================编队属性管理 ===================================
-- 刷新编队数据
function this.RefreshFormationProp(formationId)
if this.IsFormationDirty[formationId] ~= false then
local teamAddPro = FormationManager.GetFormationElementAdd(formationId)
this.FormationPropList[formationId] = teamAddPro
this.IsFormationDirty[formationId] = false
end
end
-- 设置编队数据变动
function this.SetFormationPropDirty(formationId)
this.IsFormationDirty[formationId] = true
end
-- 获取编队加成属性
function this.GetFormationProp(formationId)
this.RefreshFormationProp(formationId)
return this.FormationPropList[formationId]
end
--================================================ 功能属性管理 ====================================
--================================================ 功能属性管理 ====================================
--================================================ 功能属性管理 ====================================
-- 刷新编队数据
function this.RefreshFuncProp()
if this.IsFuncDirty.isDirty ~= false then
for _, funcPropId in pairs(Func_Prop_Type) do
if this.IsFuncDirty[funcPropId] ~= false then
local fData = Func_Prop_Func[funcPropId]()
this.FuncPropList[funcPropId] = fData
this.IsFuncDirty[funcPropId] = false
end
end
this.IsFuncDirty.isDirty = false
end
end
-- 获取功能属性加成
function this.GetFuncProp(heroData, funcPropId,formationId)
-- 检测是否刷新
this.RefreshFuncProp()
-- 获取活动数据
local fData = this.FuncPropList[funcPropId]
local propList = {}
if fData then
local filter = Func_Prop_Filter[funcPropId]
if filter then
propList = filter(fData, heroData,formationId)
end
end
return propList
end
-- 获取全部活动属性加成
function this.GetAllFuncProp(heroData,formationId)
-- 检测是否刷新
this.RefreshFuncProp()
--
local allPropList ={}
for _, funcPropId in pairs(Func_Prop_Type) do
local propList = this.GetFuncProp(heroData, funcPropId,formationId)
LogYellow_Prop("功能类型:".._)
LogBlueTable_Prop(propList)
if propList then
DoubleTableCompound(allPropList, propList)
end
end
return allPropList
end
-- 设置编队数据变动
function this.SetFuncPropDirty(funcPropId)
if not this.IsFuncDirty[funcPropId] then
this.IsFuncDirty[funcPropId] = {}
end
this.IsFuncDirty[funcPropId] = true
this.IsFuncDirty.isDirty = true
-- 战斗力需要重新计算
HeroPowerManager.SetAllPowerDirty()
end
return HeroPropManager