519 lines
16 KiB
Lua
519 lines
16 KiB
Lua
|
|
-- debug用
|
|
local IsDebug = false
|
|
local emptyFunc = function()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
|
|
LogRedTable_Prop = IsDebug and LogRedTable or emptyFunc
|
|
LogBlueTable_Prop = IsDebug and LogBlueTable or emptyFunc
|
|
LogGreenTable_Prop = IsDebug and LogGreenTable or emptyFunc
|
|
LogPinkTable_Prop = IsDebug and LogPinkTable or emptyFunc
|
|
|
|
|
|
--
|
|
require("Modules.Hero.PropHero")
|
|
require("Modules.Hero.PropFunc")
|
|
require("Modules.Hero.PropCondition")
|
|
|
|
|
|
HeroPropManager = {}
|
|
local this = HeroPropManager
|
|
|
|
-- 合并属性列表
|
|
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.AllPropList = {}
|
|
|
|
|
|
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.LateUpdate()
|
|
|
|
end
|
|
|
|
|
|
function this.Get()
|
|
-- body
|
|
end
|
|
|
|
function this.GetHeroProp(dId, formationId)
|
|
local allPropList = {}
|
|
-- 获取基础属性
|
|
Log_Prop("基础属性")
|
|
local basePropList = this.GetBaseProp(dId)
|
|
LogGreenTable_Prop(basePropList)
|
|
DoubleTableCompound(allPropList, basePropList)
|
|
|
|
-- 自身条件属性加成
|
|
local conPropList = this.GetConditionProp(dId)
|
|
Log_Prop("自身条件属性")
|
|
LogGreenTable_Prop(conPropList)
|
|
DoubleTableCompound(allPropList, conPropList)
|
|
|
|
-- 获取功能属性加成
|
|
local heroData = HeroManager.CreateHeroCountData(dId)
|
|
local funcProp = this.GetAllFuncProp(heroData,formationId)
|
|
Log_Prop("功能属性")
|
|
LogGreenTable_Prop(funcProp)
|
|
DoubleTableCompound(allPropList, funcProp)
|
|
|
|
-- 计算减益属性
|
|
Log_Prop("减益属性")
|
|
this.CountDeProp(dId, allPropList)
|
|
|
|
|
|
-- 判断是否需要加入团队属性加成
|
|
if formationId and FormationManager.CheckFormationHasId(formationId, dId) then
|
|
local formationList = FormationManager.GetFormationByID(formationId)
|
|
table.walk(formationList.teamHeroInfos, function(teamInfo)
|
|
-- 团队属性加成
|
|
if teamInfo.heroId then
|
|
Log_Prop("团队属性")
|
|
local teamProp = this.GetTeamData(teamInfo.heroId)
|
|
LogGreenTable_Prop(teamProp)
|
|
DoubleTableCompound(allPropList, teamProp)
|
|
-- 团队条件属性加成
|
|
Log_Prop("团队条件属性")
|
|
local conTeamProp = this.GetConditionTeamData(teamInfo.heroId, dId)
|
|
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)
|
|
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 = HeroManager.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 conList then
|
|
this.SetConditionData(dId, powerType, conList)
|
|
LogPink_Prop("con")
|
|
LogPinkTable_Prop(conList)
|
|
end
|
|
-- 对编队中其他人的数据
|
|
if teamPropList then
|
|
this.SetTeamData(dId, powerType, teamPropList)
|
|
LogPink_Prop("team")
|
|
LogPinkTable_Prop(teamPropList)
|
|
end
|
|
-- 对编队中其他人的数据
|
|
if conTeamList then
|
|
this.SetConditionTeamData(dId, powerType, conTeamList)
|
|
LogPink_Prop("conteam")
|
|
LogPinkTable_Prop(conTeamList)
|
|
end
|
|
-- 减益属性
|
|
if dePropList then
|
|
this.SetDePropData(dId, powerType, dePropList)
|
|
LogPink_Prop("deprop")
|
|
LogPinkTable_Prop(dePropList)
|
|
end
|
|
--
|
|
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
|
|
end
|
|
|
|
-- 将整个人置为脏数据
|
|
function this.SetHeroDirty(dId)
|
|
this.IsHeroDirty[dId] = {}
|
|
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)
|
|
-- 判空
|
|
if this.IsConPropDirty[dId] then
|
|
this.IsConPropDirty[dId] = {}
|
|
end
|
|
if this.IsConPropDirty[dId].isDirty ~= false then
|
|
-- 创建计算属性的数据
|
|
local list = {}
|
|
local cData = HeroManager.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)
|
|
DoubleTableCompound(condProp, propList)
|
|
end
|
|
end
|
|
end
|
|
-- 设置该类型条件属性
|
|
this.SetConditionProp(dId, powerType, condProp)
|
|
this.IsConPropDirty[dId][powerType] = false
|
|
end
|
|
|
|
-- 合并所有属性
|
|
local condProp = this.GetConditionPropByType(dId, powerType)
|
|
if condProp then
|
|
DoubleTableCompound(list, condProp)
|
|
this.IsConPropDirty[dId][powerType] = condProp
|
|
this.ConPropList[dId].propList = condProp
|
|
end
|
|
end
|
|
this.IsConPropDirty[dId].isDirty = false
|
|
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 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)
|
|
local list = {}
|
|
if this.ConTeamList[dId] then
|
|
local dData = HeroManager.CreateHeroCountData(dId)
|
|
local tdData = HeroManager.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)
|
|
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
|
|
LogGreenTable_Prop(string.format("%s|%s", id, v))
|
|
allPropList[id] = allPropList[id] * (1 - v / 10000)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
-- ===============================================编队属性管理 ===================================
|
|
-- ===============================================编队属性管理 ===================================
|
|
-- ===============================================编队属性管理 ===================================
|
|
|
|
-- 刷新编队数据
|
|
function this.RefreshFormationProp(formationId)
|
|
if this.IsFormationDirty[formationId] ~= false then
|
|
local teamAddPro = FormationManager.GetFormationElementAdd(FormationTypeDef.FORMATION_NORMAL)
|
|
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)
|
|
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
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return HeroPropManager |