--- --- Created by zhouzhipeng. --- DateTime: 2024/8/26 上午11:13 --- Desc:大师之路 --- Master = {} local this = {} --- 大师变量 MasterVariable = { MASTER_TALENT_DATA = "T$大师天赋数据", JOB_TALENT_ATT = "jobTalentAttr", -- 职业天赋属性 SKILL_TALENT_ATT = "skillTalentAttr", -- 技能天赋属性 COMMON_TALENT_ATT = "commonTalentAttr", -- 通用天赋属性 EXCHANGED_EXP_TIMES = "J$_EXCHANGED_EXP_TIMES", -- 已兑换的次数 MASTER_CACHE = "G$master_cache", -- 大师之路系列缓存 } --- 大师天赋类型 MasterTalentType = { JOB_TALENT = 1, -- 职业天赋 COMMON_TALENT = 2, -- 通用天赋 SKILL_TALENT = 3, -- 技能天赋 } --- 职业天赋类型 JobTalentType = { -- cfg_master_protalent 表 type类型 TALENT = 1, -- 天赋 SKILL_TALENT = 2, -- 技能天赋 } --- 职业天赋类型 SkillTalentType = { -- cfg_master_skilltalent 表 type类型 SKILL_TALENT = 1, -- 技能天赋 JOB_TALENT = 2, -- 职业天赋 } --- 大师天赋效果类型 MasterTalentEffectType = { ATT_TYPE = 1, -- 属性类型 } --- 缓存大师之路数据 function Master.cacheMasterData() local proTalentList = ConfigDataManager.getList("cfg_master_protalent") local skillTalentList = ConfigDataManager.getList("cfg_master_skilltalent") if table.isNullOrEmpty(skillTalentList) or table.isNullOrEmpty(proTalentList) then return end local proTalentSeries = {} for _, cfg in pairs(proTalentList) do if not table.contains(proTalentSeries, cfg.series) then table.insert(proTalentSeries, cfg.series) end end local skillTalentSeries = {} for _, cfg in pairs(skillTalentList) do if not table.contains(skillTalentSeries, cfg.series) then table.insert(skillTalentSeries, cfg.series) end end local cacheTable = {} cacheTable[MasterTalentType.JOB_TALENT] = proTalentSeries cacheTable[MasterTalentType.SKILL_TALENT] = skillTalentSeries setsysvar(MasterVariable.MASTER_CACHE, cacheTable) info("cacheMasterData 启动缓存大师之路数据成功") Master.print("cacheMasterData 缓存大师之路数据:\n", cacheTable) return cacheTable end --- 登录发送红点信息 function Master.login(actor) local exchangedExpTimesData = getplaydef(actor, MasterVariable.EXCHANGED_EXP_TIMES) or {} local masterAllInfo = {} for _, type in pairs(MasterTalentType) do local masterInfo = this.buildMasterRedDotInfo(actor, type, exchangedExpTimesData) table.insert(masterAllInfo, masterInfo) end sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_RED_DOT_INFO, masterAllInfo) Master.print("Master login actor:" .. actor:toString() .. ", 登录发送大师信息", masterAllInfo) end --- 请求大师信息 function Master.reqMasterInfo(actor, msgData) local type = msgData.type local masterTalentData = this.getMasterTalentData(actor, type) local masterTalent = masterTalentData[type] local talentInfo = this.buildTalentInfo(actor, type, masterTalent) sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_INFO, talentInfo) Master.print("reqMasterInfo actor:" .. actor:toString() .. ", 请求大师信息,返回数据:", talentInfo) end --- 请求启用大师系列 function Master.reqOpenMasterType(actor, msgData) Master.print("reqOpenMasterType actor:" .. actor:toString() .. ", 请求启用大师系列,msgData:", msgData) local masterType = msgData.type local series = msgData.series local masterTalentData = this.getMasterTalentData(actor, masterType) local masterTalent = masterTalentData[masterType] local seriesCount = masterTalent.seriesCount local now = getbaseinfo(actor, "now") local seriesCD = masterTalent.seriesCD local talent = masterTalent.talent if masterTalent.series == series then tipinfo(actor, "与当前系列一致") return end if masterType == MasterTalentType.JOB_TALENT then local openMasterSeriesCd = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.OPEN_MASTER_JOB_CD) local time = tonumber(seriesCD) + tonumber(openMasterSeriesCd) * 1000 -- 校验cd if tonumber(now) < time then tipinfo(actor, string.format("职业天赋切换冷却中,还剩%s秒", math.ceil((time - now) / 1000))) return end --是否拥有特权 local is_has = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.MASTER_TALENT_FREE_SWITCHING) local isPrivileges = is_has -- 首次免费 if seriesCount > 0 and not isPrivileges then local openMasterSeriesCost = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.OPEN_MASTER_SERIES_COST) local seriesCost = string.split(openMasterSeriesCost, "#") local itemCfgId = tonumber(seriesCost[1]) local count = tonumber(seriesCost[2]) -- 校验消耗 local bagCount = getbagitemcountbyid(actor, itemCfgId) if bagCount < count then tipinfo(actor, "消耗不足") return end -- 扣消耗 removeitemfrombag(actor, itemCfgId, count,0,9999,'大师之路') end masterTalent.seriesCount = seriesCount + 1 -- 职业天赋启用系列,技能天赋系列一起变动 local skillTalentType = MasterTalentType.SKILL_TALENT local skillTalent = masterTalentData[skillTalentType] if table.isNullOrEmpty(skillTalent) then skillTalent = this.initSingleTalentData() masterTalentData[skillTalentType] = skillTalent end local skillTalentSeries = skillTalent.series if skillTalentSeries ~= tonumber(series) then skillTalent.series = series local allAttrMap = {} --local removesSkills = {} for _, value in pairs(skillTalent.talent) do local cfgId = value.cfgId local level = value.level local currSeries = value.series if currSeries == series then local talentList = ConfigDataManager.getTable("cfg_master_skilltalent", "id", cfgId) local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level) if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then local talentCfg = talentList[1] local masterInfoCfg = masterList[1] local talentType = tonumber(talentCfg.type) if talentType == JobTalentType.TALENT then local masterInfoType = tonumber(masterInfoCfg.type) if masterInfoType == MasterTalentEffectType.ATT_TYPE then -- 添加属性 local parameter = masterInfoCfg.parameter if parameter ~= "" then local skill_attr_map = this.getSplitAttr(parameter) allAttrMap[cfgId] = skill_attr_map end end --elseif talentType == 2 then -- -- todo 加技能效果 1类型的处理 type为1处理其他效果 学习或 升级技能 需要添加的技能 -- local skillId = talentCfg.skillid -- levelupskill(actor, skillId, level) end end else -- 移除旧系列效果 -- 属性上面覆盖了 无需处理 技能天赋不加技能也无需处理 --if talentType == 1 then -- local masterInfoType = tonumber(masterInfoCfg.type) -- if masterInfoType == 1 then -- -- 移除属性 上面算了就算移除了 -- end --elseif talentType == 2 then -- -- 放入移除技能table -- local skillId = talentCfg.skillid -- table.insert(removesSkills, skillId) --end end end skillTalent.allAttrMap = allAttrMap local addAttrMap = this.calculateAttr(allAttrMap) addrolekmlattributes(actor, MasterVariable.SKILL_TALENT_ATT, addAttrMap) --removeskill(actor, removesSkills) end local allAttrMap = {} local removesSkills = {} local addSkills = {} for _, value in pairs(talent) do local cfgId = value.cfgId local level = value.level local currSeries = value.series local talentList = ConfigDataManager.getTable("cfg_master_protalent", "id", cfgId) local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level) if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then local talentCfg = talentList[1] local masterInfoCfg = masterList[1] local talentType = tonumber(talentCfg.type) --Master.print("reqOpenMasterType talentCfg:", talentCfg, "masterInfoCfg:", masterInfoCfg,"currSeries:",currSeries, "series:",series,"talentType",talentType,"value:",value) --Master.print("类型是否相同:",type(currSeries), type(series)) if currSeries == series then --Master.print("相同系列") if talentType == JobTalentType.TALENT then local masterInfoType = tonumber(masterInfoCfg.type) if masterInfoType == MasterTalentEffectType.ATT_TYPE then -- 添加属性 --local attr_map = getplaydef(actor, MasterVariable.MASTER_TALENT_ATT_DB) or {} local parameter = masterInfoCfg.parameter --Master.print("reqOpenMasterType talentCfg:", talentCfg, "masterInfoCfg:", masterInfoCfg,"parameter:",parameter) if parameter ~= "" then local attr_map = this.getSplitAttr(parameter) allAttrMap[cfgId] = attr_map end end elseif talentType == JobTalentType.SKILL_TALENT then -- todo 加技能效果 1类型的处理 type为1处理其他效果 学习或 升级技能 需要添加的技能 local skillId = talentCfg.skillid levelupskill(actor, skillId, level) table.insert(addSkills, skillId) end else --Master.print("不同相同系列") -- 移除旧系列效果 if talentType == JobTalentType.TALENT then local masterInfoType = tonumber(masterInfoCfg.type) if masterInfoType == MasterTalentEffectType.ATT_TYPE then -- 移除属性 上面算了就算移除了 end elseif talentType == JobTalentType.SKILL_TALENT then -- 放入移除技能table local skillId = talentCfg.skillid table.insert(removesSkills, skillId) end end else Master.print("有数据配置为空", talentList, masterList, cfgId) end end Master.print(" 循环结束 talent信息:", talent, "要移除的技能id:", removesSkills, "添加的技能:", addSkills) local addAttrMap = this.calculateAttr(allAttrMap) addrolekmlattributes(actor, MasterVariable.JOB_TALENT_ATT, addAttrMap) removeskill(actor, removesSkills) elseif masterType == MasterTalentType.SKILL_TALENT then local openMasterSkillCd = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.OPEN_MASTER_SKILL_CD) local time = tonumber(seriesCD) + tonumber(openMasterSkillCd) * 1000 -- 校验cd if tonumber(now) < time then tipinfo(actor, string.format("技能天赋切换冷却中,还剩%s秒", math.ceil((time - now) / 1000))) return end local allAttrMap = {} --local removesSkills = {} for _, value in pairs(talent) do local cfgId = value.cfgId local level = value.level local currSeries = value.series if currSeries == series then local talentList = ConfigDataManager.getTable("cfg_master_skilltalent", "id", cfgId) local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level) if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then local talentCfg = talentList[1] local masterInfoCfg = masterList[1] local talentType = tonumber(talentCfg.type) if talentType == JobTalentType.TALENT then local masterInfoType = tonumber(masterInfoCfg.type) if masterInfoType == MasterTalentEffectType.ATT_TYPE then -- 添加属性 local parameter = masterInfoCfg.parameter if parameter ~= "" then local attr_map = this.getSplitAttr(parameter) allAttrMap[cfgId] = attr_map end end --elseif talentType == 2 then -- -- todo 加技能效果 1类型的处理 type为1处理其他效果 学习或 升级技能 需要添加的技能 -- local skillId = talentCfg.skillid -- levelupskill(actor, skillId, level) end end else -- 移除旧系列效果 -- 属性上面覆盖了 无需处理 技能天赋不加技能也无需处理 --if talentType == 1 then -- local masterInfoType = tonumber(masterInfoCfg.type) -- if masterInfoType == 1 then -- -- 移除属性 上面算了就算移除了 -- end --elseif talentType == 2 then -- -- 放入移除技能table -- local skillId = talentCfg.skillid -- table.insert(removesSkills, skillId) --end end end masterTalent.allAttrMap = allAttrMap local addAttrMap = this.calculateAttr(allAttrMap) addrolekmlattributes(actor, MasterVariable.SKILL_TALENT_ATT, addAttrMap) --removeskill(actor, removesSkills) elseif masterType == MasterTalentType.COMMON_TALENT then local allAttrMap = {} --local removesSkills = {} for _, value in pairs(talent) do local cfgId = value.cfgId local level = value.level local currSeries = value.series --local talentList = ConfigDataManager.getTable("cfg_master_commontalent", "id", cfgId) local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level) if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then --local talentCfg = talentList[1] local masterInfoCfg = masterList[1] if currSeries == series then local masterInfoType = tonumber(masterInfoCfg.type) if masterInfoType == MasterTalentEffectType.ATT_TYPE then -- 添加属性 --local attr_map = getplaydef(actor, MasterVariable.MASTER_TALENT_ATT_DB) or {} local parameter = masterInfoCfg.parameter if parameter ~= "" then local attr_map = this.getSplitAttr(parameter) allAttrMap[cfgId] = attr_map end end --elseif talentType == 2 then -- -- todo 加技能效果 1类型的处理 type为1处理其他效果 学习或 升级技能 需要添加的技能 -- local skillId = talentCfg.skillid -- levelupskill(actor, skillId, level) else -- 移除旧系列效果 --if talentType == 1 then -- local masterInfoType = tonumber(masterInfoCfg.type) -- if masterInfoType == 1 then -- -- 移除属性 上面算了就算移除了 -- end --elseif talentType == 2 then -- -- 放入移除技能table -- local skillId = talentCfg.skillid -- table.insert(removesSkills, skillId) --end end end end masterTalent.allAttrMap = allAttrMap local addAttrMap = this.calculateAttr(allAttrMap) addrolekmlattributes(actor, MasterVariable.COMMON_TALENT_ATT, addAttrMap) --removeskill(actor, removesSkills) end masterTalent.series = series masterTalent.seriesCD = tostring(now) setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData) sendluamsg(actor, LuaMessageIdToClient.RES_OPEN_MASTER_TYPE, { type = masterType, series = series }) Master.print("reqOpenMasterType actor:" .. actor:toString() .. ", 请求启用大师系列 结束:", masterTalentData) end --- 请求兑换大师经验 function Master.reqExchangeMasterExp(actor, msgData) Master.print("reqExchangeMasterExp actor:" .. actor:toString() .. ", 请求兑换大师经验,msgData:", msgData) local type = msgData.type local cost = msgData.cost local award = msgData.award local exchangedExpTimesData = getplaydef(actor, MasterVariable.EXCHANGED_EXP_TIMES) or {} local exchangedExpTimes = this.getTypeTimes(exchangedExpTimesData, type) -- todo 需要用每日自动清0的方式,或0点事件,或请求的时候触发 跨天就清0 已经改了,测试看看效果 local masterTalentDayCount = "" if type == MasterTalentType.JOB_TALENT then masterTalentDayCount = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.JOB_TALENT_DAY_COUNT) elseif type == MasterTalentType.SKILL_TALENT then masterTalentDayCount = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.SKILL_TALENT_DAY_COUNT) end if exchangedExpTimes >= tonumber(masterTalentDayCount) then tipinfo(actor, "今日兑换次数已达上限") return end local masterTalentData = this.getMasterTalentData(actor, type) local masterTalent = masterTalentData[type] local maxLv = this.getMaxLevel(actor, type) if maxLv == -1 then return end if masterTalent.level == maxLv then tipinfo(actor, "已达到最高等级") return end if not table.isNullOrEmpty(cost) then for _, value in pairs(cost) do local costItemCfgId = value.costItemCfgId local costItemCount = value.costItemCount local bagCount = getbagitemcountbyid(actor, costItemCfgId) if bagCount < costItemCount then tipinfo(actor, "货币不足") return end end for _, value in pairs(cost) do local costItemCfgId = value.costItemCfgId local costItemCount = value.costItemCount removeitemfrombag(actor, costItemCfgId, costItemCount,0,9999,'大师之路') end end local masterTalentData = this.getMasterTalentData(actor, type) local masterTalent = masterTalentData[type] if not table.isNullOrEmpty(award) then for _, value in pairs(award) do local itemCfgId = value.itemCfgId local itemCount = value.itemCount --加经验 this.addExp(actor, type, masterTalent, itemCount, maxLv) end end local count = exchangedExpTimes + 1 exchangedExpTimesData[type] = count setplaydef(actor, MasterVariable.EXCHANGED_EXP_TIMES, exchangedExpTimesData) setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData) local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints) local resInfo = { type = type, level = masterTalent.level, exp = masterTalent.exp, exchangedExpTimes = count, points = masterTalent.points, seriesPoints = buildSeriesPoints } sendluamsg(actor, LuaMessageIdToClient.RES_EXCHANGE_MASTER_EXP, resInfo) Master.print("reqExchangeMasterExp actor:" .. actor:toString() .. ", 兑换大师经验结束 msgData:", msgData, ",旧使用次数", exchangedExpTimes, ",新使用次数", count) end --- 请求重置大师天赋 function Master.reqResetMaster(actor, msgData) Master.print("reqResetMaster actor:" .. actor:toString() .. ", 请求重置大师天赋,msgData:", msgData) local masterType = msgData.type local masterTalentResetCost if masterType == MasterTalentType.JOB_TALENT then masterTalentResetCost = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.MASTER_TALENT_RESET_COST) elseif masterType == MasterTalentType.COMMON_TALENT then masterTalentResetCost = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.MASTER_TALENT_COMMON_RESET_COST) elseif masterType == MasterTalentType.SKILL_TALENT then masterTalentResetCost = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.MASTER_TALENT_SKILL_RESET_COST) end local resetCost = string.split(masterTalentResetCost, "#") local itemCfgId = tonumber(resetCost[1]) local count = tonumber(resetCost[2]) -- 校验消耗 local bagCount = getbagitemcountbyid(actor, itemCfgId) if bagCount < count then tipinfo(actor, "货币不足") return end -- 扣消耗 removeitemfrombag(actor, itemCfgId, count,0,9999,'大师之路') --重置点数 local masterTalentData = this.getMasterTalentData(actor, masterType) local masterTalent = masterTalentData[masterType] local talent = masterTalent.talent local addPoint = 0 local masterSeriesPoint = {} for id, value in pairs(talent) do if masterType == MasterTalentType.COMMON_TALENT then for i = 1, value.level do local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", id, "level", i) if table.isNullOrEmpty(masterList) then tipinfo(actor, "未找到该天赋配置cfg_master_info") return end local masterInfoCfg = masterList[1] addPoint = addPoint + masterInfoCfg.consumpoint end else local series = value.series local add = 0 for i = 1, value.level do local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", id, "level", i) if table.isNullOrEmpty(masterList) then tipinfo(actor, "未找到该天赋配置cfg_master_info") return end local masterInfoCfg = masterList[1] add = add + masterInfoCfg.consumpoint end local oldPoint = masterSeriesPoint[series] or 0 masterSeriesPoint[series] = oldPoint + add Master.print() end end -- todo 去除所有效果 遍历所以清空属性 if masterType == MasterTalentType.JOB_TALENT then local attr_map = {} local removesSkills = {} for _, value in pairs(talent) do local cfgId = value.cfgId local level = value.level local currSeries = value.series local talentList = ConfigDataManager.getTable("cfg_master_protalent", "id", cfgId) local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level) if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then local talentCfg = talentList[1] local masterInfoCfg = masterList[1] local talentType = tonumber(talentCfg.type) -- 移除效果 if talentType == 1 then --local masterInfoType = tonumber(masterInfoCfg.type) --if masterInfoType == 1 then -- -- 移除属性 上面算了就算移除了 --end elseif talentType == 2 then -- 放入移除技能table local skillId = talentCfg.skillid table.insert(removesSkills, skillId) end end end addrolekmlattributes(actor, MasterVariable.JOB_TALENT_ATT, attr_map) removeskill(actor, removesSkills) elseif masterType == MasterTalentType.SKILL_TALENT then local attr_map = {} local removesSkills = {} for _, value in pairs(talent) do local cfgId = value.cfgId local level = value.level local currSeries = value.series local talentList = ConfigDataManager.getTable("cfg_master_skilltalent", "id", cfgId) local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level) if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then local talentCfg = talentList[1] local masterInfoCfg = masterList[1] local talentType = tonumber(talentCfg.type) -- 移除旧系列效果 --if talentType == 1 then -- local masterInfoType = tonumber(masterInfoCfg.type) -- if masterInfoType == 1 then -- -- 移除属性 上面算了就算移除了 -- end --elseif talentType == 2 then -- -- 放入移除技能table -- local skillId = talentCfg.skillid -- table.insert(removesSkills, skillId) --end end end addrolekmlattributes(actor, MasterVariable.SKILL_TALENT_ATT, attr_map) --removeskill(actor, removesSkills) elseif masterType == MasterTalentType.COMMON_TALENT then local attr_map = {} --local removesSkills = {} for _, value in pairs(talent) do local cfgId = value.cfgId local level = value.level local currSeries = value.series local talentList = ConfigDataManager.getTable("cfg_master_commontalent", "id", cfgId) local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level) if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then local talentCfg = talentList[1] local masterInfoCfg = masterList[1] local talentType = tonumber(talentCfg.type) -- 移除旧系列效果 --if talentType == 1 then -- local masterInfoType = tonumber(masterInfoCfg.type) -- if masterInfoType == 1 then -- -- 移除属性 上面算了就算移除了 -- end --elseif talentType == 2 then -- -- 放入移除技能table -- local skillId = talentCfg.skillid -- table.insert(removesSkills, skillId) --end end end addrolekmlattributes(actor, MasterVariable.COMMON_TALENT_ATT, attr_map) --removeskill(actor, removesSkills) end local oldSeriesPoints = masterTalent.seriesPoints Master.print("reqResetMaster actor:" .. actor:toString() .. ", 已加的点数:", masterSeriesPoint, ",旧的点数", oldSeriesPoints) for series, point in pairs(masterSeriesPoint) do local oldPoint = oldSeriesPoints[series] or 0 oldSeriesPoints[series] = oldPoint + point end Master.print("reqResetMaster actor:" .. actor:toString() .. ", 想加的结果:", oldSeriesPoints) masterTalent.seriesPoints = oldSeriesPoints masterTalent.points = masterTalent.points + addPoint masterTalent.talent = {} masterTalent.allAttrMap = {} setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData) local talentInfo = this.buildTalentInfo(actor, masterType, masterTalent) sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_INFO, talentInfo) Master.print("reqResetMaster actor:" .. actor:toString() .. ", 请求重置大师天赋,结束:", talentInfo) end --- 请求升级大师天赋 function Master.reqUpgradeMasterTalent(actor, msgData) Master.print("reqUpgradeMasterTalent actor:" .. actor:toString() .. ", 请求升级大师天赋,msgData:", msgData) local talentType = msgData.type local cfgId = tonumber(msgData.cfgId) local addLv = msgData.addLv local masterTalentData = this.getMasterTalentData(actor, talentType) local masterTalent = masterTalentData[talentType] local talent = masterTalent.talent if talentType == MasterTalentType.JOB_TALENT then local talentList = ConfigDataManager.getTable("cfg_master_protalent", "id", cfgId) if table.isNullOrEmpty(talentList) then tipinfo(actor, "未找到该天赋配置cfg_master_protalent") return end local talentCfg = talentList[1] -- todo 考虑职业 career local talentInfo = this.getTalent(talent, talentCfg) local level = tonumber(talentInfo.level) local str = talentCfg.minmaxlevel local minMaxLevel = string.split(str, "#") if level >= tonumber(minMaxLevel[2]) then tipinfo(actor, "天赋已点满") return end local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level + 1) if table.isNullOrEmpty(masterList) then tipinfo(actor, "未找到该天赋配置cfg_master_info") return end local masterInfoCfg = masterList[1] local totalNum = masterInfoCfg.frontnum local tier = talentCfg.tier -- 获取前置点数 local totalPoints = this.getJobTalentPoints(talent, tier) Master.print("reqUpgradeMasterTalent actor:" .. actor:toString() .. ",totalPoints:" .. totalPoints, talent, tier) if totalPoints < tonumber(totalNum) then --tipinfo(actor, string.format("需要前置点数 需要前置点数数量%s", totalNum)) tipinfo(actor, "前置天赋等级不足") return end local consumpoint = tonumber(masterInfoCfg.consumpoint) local seriesPoints = masterTalent.seriesPoints local series = tonumber(talentCfg.series) local points = seriesPoints[series] or 0 if points < consumpoint then tipinfo(actor, "点数不足") return end seriesPoints[series] = points - consumpoint talentInfo.level = level + 1 local cfgType = tonumber(talentCfg.type) -- 升级启用系列增加效果 if masterTalent.series == series then if cfgType == JobTalentType.TALENT then local masterType = tonumber(masterInfoCfg.type) if masterType == MasterTalentEffectType.ATT_TYPE then -- 添加属性 local addAttrMap = this.getAddAttMap(cfgId, masterTalent.allAttrMap, masterInfoCfg.parameter) addrolekmlattributes(actor, MasterVariable.JOB_TALENT_ATT, addAttrMap) end elseif cfgType == JobTalentType.SKILL_TALENT then -- 学习或 升级技能 local skillId = talentCfg.skillid levelupskill(actor, skillId, talentInfo.level) end end local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints) local resTalent = {} table.insert(resTalent, talentInfo) local resInfo = { type = talentType, points = masterTalent.points, talent = resTalent, seriesPoints = buildSeriesPoints } sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_CHANGE_INFO, resInfo) elseif talentType == MasterTalentType.COMMON_TALENT then local talentList = ConfigDataManager.getTable("cfg_master_commontalent", "id", cfgId) if table.isNullOrEmpty(talentList) then tipinfo(actor, "未找到该天赋配置cfg_master_protalent") return end local talentCfg = talentList[1] -- todo 考虑职业 career local talentInfo = this.getTalent(talent, talentCfg) local level = tonumber(talentInfo.level) local str = talentCfg.minmaxlevel local minMaxLevel = string.split(str, "#") if level + addLv > tonumber(minMaxLevel[2]) then --Master.print("等级:",level, ",addlv:",addLv,",配置最大等级:", minMaxLevel[2]) tipinfo(actor, "天赋已点满") return end local totalNum = 0 for i = 1, addLv do local consumpoint = ConfigDataManager.getTableValue("cfg_master_info", "consumpoint", "talentId", cfgId, "level", level + i) totalNum = totalNum + consumpoint end local points = masterTalent.points if points < totalNum then tipinfo(actor, "点数不足") return end masterTalent.points = points - totalNum talentInfo.level = level + addLv local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", talentInfo.level) if table.isNullOrEmpty(masterList) then tipinfo(actor, "未找到该天赋配置cfg_master_info") return end local masterInfoCfg = masterList[1] local masterType = tonumber(masterInfoCfg.type) if masterType == MasterTalentEffectType.ATT_TYPE then -- 添加属性 local addAttrMap = this.getAddAttMap(cfgId, masterTalent.allAttrMap, masterInfoCfg.parameter) Master.print("属性添加成功", addAttrMap) addrolekmlattributes(actor, MasterVariable.COMMON_TALENT_ATT, addAttrMap) end local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints) local resTalent = {} table.insert(resTalent, talentInfo) local resInfo = { type = talentType, points = masterTalent.points, talent = resTalent, seriesPoints = buildSeriesPoints } sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_CHANGE_INFO, resInfo) elseif talentType == MasterTalentType.SKILL_TALENT then local talentList = ConfigDataManager.getTable("cfg_master_skilltalent", "id", cfgId) if table.isNullOrEmpty(talentList) then tipinfo(actor, "未找到该天赋配置 cfg_master_skilltalent") return end local talentCfg = talentList[1] -- todo 考虑职业 career local talentInfo = this.getTalent(talent, talentCfg) local level = tonumber(talentInfo.level) local str = talentCfg.minmaxlevel local minMaxLevel = string.split(str, "#") if level >= tonumber(minMaxLevel[2]) then tipinfo(actor, "天赋已点满") return end local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level + 1) if table.isNullOrEmpty(masterList) then tipinfo(actor, "未找到该天赋配置cfg_master_info") return end local masterInfoCfg = masterList[1] local totalNum = masterInfoCfg.frontnum local cfgType = tonumber(talentCfg.type) if cfgType == SkillTalentType.SKILL_TALENT then local frontTalent = masterInfoCfg.fronttalent if frontTalent == "" then -- 不需要校验 else local cfgList = ConfigDataManager.getTable("cfg_master_skilltalent", "id", frontTalent) if table.isNullOrEmpty(cfgList) then --Master.print("reqUpgradeMasterTalent actor:" .. actor:toString() .. ",frontTalent:", frontTalent,",frontTalent type:", type(frontTalent),",talentId:", cfgId, ",level:", level,",masterInfoCfg:",masterInfoCfg) tipinfo(actor, "cfg_master_skilltalent表frontTalent关联错误") return end local cfg = cfgList[1] -- 获取前置点数 local totalPoints = 0 if tonumber(cfg.type) == SkillTalentType.SKILL_TALENT then totalPoints = this.getSkillTalentPoints(talent, tonumber(frontTalent)) elseif tonumber(cfg.type) == SkillTalentType.JOB_TALENT then local jobMasterTalent = masterTalentData[MasterTalentType.JOB_TALENT] totalPoints = this.getSkillTalentPoints(jobMasterTalent.talent, tonumber(cfg.protalentid)) end --Master.print("reqUpgradeMasterTalent actor:" .. actor:toString() .. "已经加点数:", totalPoints, "配置要求达到点数", tonumber(totalNum)) if totalPoints < tonumber(totalNum) then --tipinfo(actor, string.format("需要前置点数 需要前置点数数量%s", totalNum)) tipinfo(actor, "前置天赋等级不足") return end end end local consumpoint = tonumber(masterInfoCfg.consumpoint) local seriesPoints = masterTalent.seriesPoints local series = tonumber(talentCfg.series) local points = seriesPoints[series] or 0 if points < consumpoint then tipinfo(actor, "点数不足") return end seriesPoints[series] = points - consumpoint talentInfo.level = level + 1 if masterTalent.series == series then if cfgType == SkillTalentType.SKILL_TALENT then local masterType = tonumber(masterInfoCfg.type) if masterType == MasterTalentEffectType.ATT_TYPE then -- 添加属性 local addAttrMap = this.getAddAttMap(cfgId, masterTalent.allAttrMap, masterInfoCfg.parameter) addrolekmlattributes(actor, MasterVariable.SKILL_TALENT_ATT, addAttrMap) end end end setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData) local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints) local resTalent = {} table.insert(resTalent, talentInfo) local resInfo = { type = talentType, points = masterTalent.points, talent = resTalent, seriesPoints = buildSeriesPoints } sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_CHANGE_INFO, resInfo) end setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData) Master.print("reqUpgradeMasterTalent actor:" .. actor:toString() .. ", 请求升级大师天赋,结束:", masterTalentData) end --- 角色升级触发获取通用天赋点 function Master.levelup(actor, level, oldLevel) Master.print("Master levelup actor:" .. actor:toString() .. ", 角色升级触发获取通用天赋点,开始:" .. ",oldLevel:" .. oldLevel .. ",level:" .. level) local cfgLevel = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.COMMON_TALENT_MAX_LEVEL) local cfgLevelStr = string.split(cfgLevel, "#") local startLevel = tonumber(cfgLevelStr[1]) local endLevel = tonumber(cfgLevelStr[2]) if level < oldLevel then Master.print("Master levelup actor:" .. actor:toString() .. ",等级降级,无法获取通用天赋点", "level:" .. level) return end if level < startLevel or oldLevel > endLevel then Master.print("Master levelup actor:" .. actor:toString(), "等级不符合要求,无法获取通用天赋点", "level:" .. level .. ",oldLevel:" .. oldLevel .. ",startLevel" .. startLevel .. ",endLevel:" .. endLevel) return end --Master.print("Master levelup actor:" .. actor:toString(), "level:" .. level .. ",oldLevel:" .. oldLevel..",startLevel:"..startLevel..",endLevel:"..endLevel) --Master.print("Master levelup actor:" .. actor:toString(), "类型 level:" .. type(level) .. ",oldLevel:" .. type(oldLevel)..",startLevel:"..type(startLevel)..",endLevel:"..type(endLevel)) local maxLv = math.min(level, endLevel) local minLv = math.max(oldLevel, startLevel - 1) local num = maxLv - minLv local commonTalentPoints = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.COMMON_TALENT_POINTS) local addPoints = num * tonumber(commonTalentPoints) local type = MasterTalentType.COMMON_TALENT local masterTalentData = this.getMasterTalentData(actor, type) local masterTalent = masterTalentData[type] masterTalent.points = masterTalent.points + addPoints setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData) local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints) local resInfo = { type = type, level = masterTalent.level, exp = masterTalent.exp, exchangedExpTimes = 0, points = masterTalent.points, seriesPoints = buildSeriesPoints } sendluamsg(actor, LuaMessageIdToClient.RES_EXCHANGE_MASTER_EXP, resInfo) Master.print("Master levelup actor:" .. actor:toString() .. ", 角色升级触发获取通用天赋点,结束:" .. ",oldLevel:" .. oldLevel .. ",level:" .. level, masterTalentData, resInfo) end --- 大师道具变化处理 function Master.masterItemChange(actor, ids, cfgId, oldCount, newCount) -- ItemConfigId.EXP --local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId) --if subType == nil then -- error("initguardequip actor:" .. actor:toString() .. " ,subType==nil itemCfgId:" .. cfgId) -- return --end if tonumber(newCount) < tonumber(oldCount) then -- 道具减少不处理 return end local itemCount = newCount - oldCount --Master.print("masterItemChange 道具变化:actor:" .. actor:toString(), itemCount) local type = -1 if cfgId == ItemConfigId.JOB_TALENT_ID then type = MasterTalentType.JOB_TALENT elseif cfgId == ItemConfigId.SKILL_TALENT_ID then type = MasterTalentType.SKILL_TALENT else -- 其他道具无需处理 return end local masterTalentData = this.getMasterTalentData(actor, type) local masterTalent = masterTalentData[type] local maxLv = this.getMaxLevel(actor, type) if maxLv == -1 then return end if masterTalent.level == maxLv then tipinfo(actor, "已达到最高等级") return end -- 增加天赋经验 this.addExp(actor, type, masterTalent, itemCount, maxLv) setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData) local exchangedExpTimesData = getplaydef(actor, MasterVariable.EXCHANGED_EXP_TIMES) or {} local exchangedExpTimes = this.getTypeTimes(exchangedExpTimesData, type) local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints) local resInfo = { type = type, level = masterTalent.level, exp = masterTalent.exp, exchangedExpTimes = exchangedExpTimes, points = masterTalent.points, seriesPoints = buildSeriesPoints } sendluamsg(actor, LuaMessageIdToClient.RES_EXCHANGE_MASTER_EXP, resInfo) end ---------------------------------------------------------------------------------------this---------------------------------------------------------------------------------------- --- 增加经验 function this.addExp(actor, type, talent, count, maxLv) if count < 1 then tipinfo(actor, "需要增加的经验不能小于1") return end local tableName = this.getTableName(type) local oldLv = talent.level local oldExp = talent.exp local addExp = count + oldExp local addPoint = 0 while addExp > 0 do local level = talent.level local levelList = ConfigDataManager.getTable(tableName, "id", level) if table.isNullOrEmpty(levelList) then talent.exp = addExp tipinfo(actor, "未找到等级配置") Master.print("addExp 未找到等级配置 actor:", actor:toString(), ", oldLv:", oldLv, ", oldExp:", oldExp, ", addExp:", count, ", addPoint:", addPoint, ", lv:", talent.level, ", exp:", talent.exp) break end local levelCfg = levelList[1] local cfgExp = tonumber(levelCfg.exp) if addExp < cfgExp then talent.exp = addExp addExp = 0 else addExp = addExp - cfgExp talent.level = talent.level + 1 talent.exp = 0 addPoint = addPoint + tonumber(levelCfg.point) if talent.level == maxLv then tipinfo(actor, "已到达最高等级") break end end end -- 两个系列增加点数 local masterCache = getsysvar(actor,MasterVariable.MASTER_CACHE) local seriesTalent = masterCache[type] for _, series in pairs(seriesTalent) do local seriesNum = tonumber(series) local seriesPoints = talent.seriesPoints local points = seriesPoints[seriesNum] or 0 seriesPoints[seriesNum] = points + addPoint end --talent.points = talent.points + addPoint Master.print("addExp actor:", actor:toString(), ", oldLv:", oldLv, ", oldExp:", oldExp, ", addExp:", count, ", addPoint:", addPoint, ", lv:", talent.level , ", exp:", talent.exp, "seriesPoints", talent.seriesPoints, ",type:", type) end --- 获取职业天赋已加点的天赋点数 function this.getJobTalentPoints(talent, maxTier) local totalPoints = 0 for cfgId, info in pairs(talent) do local tier = ConfigDataManager.getTableValue("cfg_master_protalent", "tier", "id", cfgId) if tier <= maxTier then for i = 1, info.level do local consumPoint = ConfigDataManager.getTableValue("cfg_master_info", "consumpoint", "talentId", cfgId, "level", i) Master.print("getJobTalentPoints 获取已加点 cfgId:" .. cfgId .. ",level:" .. i .. ",consumPoint:" .. tostring(consumPoint), talent, maxTier) totalPoints = totalPoints + tonumber(consumPoint) end end end return totalPoints end --- 获取技能天赋已加点的天赋点数 function this.getSkillTalentPoints(talent, frontTalent) local totalPoints = 0 for cfgId, info in pairs(talent) do if cfgId == frontTalent then for i = 1, info.level do local consumPoint = ConfigDataManager.getTableValue("cfg_master_info", "consumpoint", "talentId", cfgId, "level", i) totalPoints = totalPoints + tonumber(consumPoint) end end end return totalPoints end --- 初始化单个天赋 function this.initTalentInfo(talentCfg) local talentInfo = {} talentInfo.cfgId = tonumber(talentCfg.id) talentInfo.level = 0 talentInfo.series = tonumber(talentCfg.series) return talentInfo end --- 获取大师天赋数据 function this.getMasterTalentData(actor, type) local masterTalentData = getplaydef(actor, MasterVariable.MASTER_TALENT_DATA) or {} local masterTalent = masterTalentData[type] if table.isNullOrEmpty(masterTalent) then masterTalent = this.initSingleTalentData() masterTalentData[type] = masterTalent setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData) end return masterTalentData end --- 构建天赋信息 function this.buildTalentInfo(actor, type, talent) local exchangedExpTimes = this.getExchangedExpTimes(actor, type) local talentInfo = {} talentInfo.type = type talentInfo.series = talent.series talentInfo.points = talent.points talentInfo.exchangedExpTimes = exchangedExpTimes talentInfo.level = talent.level talentInfo.exp = talent.exp talentInfo.talent = talent.talent -- 特权接口这里获取 local is_has = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.MASTER_TALENT_FREE_SWITCHING) talentInfo.isFree = is_has local seriesPoints = this.buildSeriesPoints(talent.seriesPoints) talentInfo.seriesPoints = seriesPoints return talentInfo end function this.buildSeriesPoints(points) local seriesPoints = {} if table.isNullOrEmpty(points) then return seriesPoints end for k, v in pairs(points) do local sp = {} sp.series = k sp.points = v table.insert(seriesPoints, sp) end return seriesPoints end function this.getExchangedExpTimes(actor, type) local exchangedExpTimesData = getplaydef(actor, MasterVariable.EXCHANGED_EXP_TIMES) or {} return this.getTypeTimes(exchangedExpTimesData, type) end function this.getTypeTimes(exchangedExpTimesData, type) local exchangedExpTimes = 0 if exchangedExpTimesData == nil then return exchangedExpTimes end exchangedExpTimes = exchangedExpTimesData[type] or 0 return exchangedExpTimes end function this.getTalent(talent, talentCfg) local cfgId = tonumber(talentCfg.id) local talentInfo = talent[cfgId] if table.isNullOrEmpty(talentInfo) then talentInfo = this.initTalentInfo(talentCfg) talent[cfgId] = talentInfo end return talentInfo end function this.getAddAttMap(cfgId, allAttrMap, parameter) if parameter ~= "" then local attr_map = this.getSplitAttr(parameter) allAttrMap[cfgId] = attr_map local addAttrMap = this.calculateAttr(allAttrMap) return addAttrMap end end function this.getSplitAttr(parameter) local attr_map = {} local parameterStr = string.split(parameter, "&") for _, value in pairs(parameterStr) do local str = string.split(value, "#") local attrId = str[1] local oldValue = attr_map[attrId] if oldValue == nil or oldValue == 0 then attr_map[attrId] = str[2] else attr_map[attrId] = oldValue + str[2] end end return attr_map end function this.calculateAttr(allAttrMap) local addAttrMap = {} for _, attr_map in pairs(allAttrMap) do for attrId, value in pairs(attr_map) do local oldValue = addAttrMap[attrId] or 0 addAttrMap[attrId] = oldValue + value end end return addAttrMap end function this.getMaxLevel(actor, type) local tableName = this.getTableName(type) local configList = ConfigDataManager.getList(tableName) if table.isNullOrEmpty(configList) then tipinfo(actor, "未找到配置表") Master.print("未找到配置",",表名:", tableName, ",type:", type) return -1 end -- 等级从0开始所以需要减1 local maxLv = table.count(configList) - 1 return maxLv end function this.getTableName(type) local tableName = "" if type == MasterTalentType.JOB_TALENT then tableName = "cfg_master_proLevel" elseif type == MasterTalentType.SKILL_TALENT then tableName = "cfg_master_skillLevel" end return tableName end --- 初始化天赋数据 function this.initSingleTalentData() return { seriesPoints = {}, -- 系列天赋点数 {{[1]=0, [2]=0}} 服务器存储 发给客户端这个结构 {series= 1, points=0}, {series= 2, points=0} series = 0, -- 系列 职业与技能天赋 seriesCount = 0, -- 选择启用系列次数 职业天赋 seriesCD = "0", -- 启用职业天赋CD 职业与技能天赋 points = 0, -- 通用天赋点数 level = 0, -- 等级 exp = 0, -- 当前经验 talent = {}, -- 天赋 索引天赋id 内容:{id, level, series系列} allAttrMap = {}, -- 天赋配置 对应 获得的属性 } end --- 初始化天赋数据 function this.buildMasterRedDotInfo(actor, type, exchangedExpTimesData) local masterInfo = {} local exchangedExpTimes = this.getTypeTimes(exchangedExpTimesData, type) local masterTalentData = this.getMasterTalentData(actor, type) local masterTalent = masterTalentData[type] masterInfo.type = type masterInfo.exchangedExpTimes = exchangedExpTimes masterInfo.level = masterTalent.level or 0 masterInfo.points = masterTalent.points or 0 local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints) masterInfo.seriesPoints = buildSeriesPoints return masterInfo end ---------------------------------------------------------------------------------------测试方法---------------------------------------------------------------------------------------- --- 打印日志 function Master.print(...) local isPrintLog = true if isPrintLog then return end jprint(...) end --- 测试方法 function mastertest(actor) --local masterTalentData = getplaydef(actor, MasterVariable.MASTER_TALENT_DATA) or {} Master.print("reqMasterInfo actor:" .. actor:toString() .. ", 请求大师信息,返回数据:", getplaydef) end