Master.lua 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. ---
  2. --- Created by zhouzhipeng.
  3. --- DateTime: 2024/8/26 上午11:13
  4. --- Desc:大师之路
  5. ---
  6. Master = {}
  7. local this = {}
  8. --- 大师变量
  9. MasterVariable = {
  10. MASTER_TALENT_DATA = "T$大师天赋数据",
  11. JOB_TALENT_ATT = "jobTalentAttr", -- 职业天赋属性
  12. SKILL_TALENT_ATT = "skillTalentAttr", -- 技能天赋属性
  13. COMMON_TALENT_ATT = "commonTalentAttr", -- 通用天赋属性
  14. EXCHANGED_EXP_TIMES = "J$_EXCHANGED_EXP_TIMES", -- 已兑换的次数
  15. MASTER_CACHE = "G$master_cache", -- 大师之路系列缓存
  16. }
  17. --- 大师天赋类型
  18. MasterTalentType = {
  19. JOB_TALENT = 1, -- 职业天赋
  20. COMMON_TALENT = 2, -- 通用天赋
  21. SKILL_TALENT = 3, -- 技能天赋
  22. }
  23. --- 职业天赋类型
  24. JobTalentType = {
  25. -- cfg_master_protalent 表 type类型
  26. TALENT = 1, -- 天赋
  27. SKILL_TALENT = 2, -- 技能天赋
  28. }
  29. --- 职业天赋类型
  30. SkillTalentType = {
  31. -- cfg_master_skilltalent 表 type类型
  32. SKILL_TALENT = 1, -- 技能天赋
  33. JOB_TALENT = 2, -- 职业天赋
  34. }
  35. --- 大师天赋效果类型
  36. MasterTalentEffectType = {
  37. ATT_TYPE = 1, -- 属性类型
  38. }
  39. --- 缓存大师之路数据
  40. function Master.cacheMasterData()
  41. local proTalentList = ConfigDataManager.getList("cfg_master_protalent")
  42. local skillTalentList = ConfigDataManager.getList("cfg_master_skilltalent")
  43. if table.isNullOrEmpty(skillTalentList) or table.isNullOrEmpty(proTalentList) then
  44. return
  45. end
  46. local proTalentSeries = {}
  47. for _, cfg in pairs(proTalentList) do
  48. if not table.contains(proTalentSeries, cfg.series) then
  49. table.insert(proTalentSeries, cfg.series)
  50. end
  51. end
  52. local skillTalentSeries = {}
  53. for _, cfg in pairs(skillTalentList) do
  54. if not table.contains(skillTalentSeries, cfg.series) then
  55. table.insert(skillTalentSeries, cfg.series)
  56. end
  57. end
  58. local cacheTable = {}
  59. cacheTable[MasterTalentType.JOB_TALENT] = proTalentSeries
  60. cacheTable[MasterTalentType.SKILL_TALENT] = skillTalentSeries
  61. setsysvar(MasterVariable.MASTER_CACHE, cacheTable)
  62. info("cacheMasterData 启动缓存大师之路数据成功")
  63. Master.print("cacheMasterData 缓存大师之路数据:\n", cacheTable)
  64. return cacheTable
  65. end
  66. --- 登录发送红点信息
  67. function Master.login(actor)
  68. local exchangedExpTimesData = getplaydef(actor, MasterVariable.EXCHANGED_EXP_TIMES) or {}
  69. local masterAllInfo = {}
  70. for _, type in pairs(MasterTalentType) do
  71. local masterInfo = this.buildMasterRedDotInfo(actor, type, exchangedExpTimesData)
  72. table.insert(masterAllInfo, masterInfo)
  73. end
  74. sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_RED_DOT_INFO, masterAllInfo)
  75. Master.print("Master login actor:" .. actor:toString() .. ", 登录发送大师信息", masterAllInfo)
  76. end
  77. --- 请求大师信息
  78. function Master.reqMasterInfo(actor, msgData)
  79. local type = msgData.type
  80. local masterTalentData = this.getMasterTalentData(actor, type)
  81. local masterTalent = masterTalentData[type]
  82. local talentInfo = this.buildTalentInfo(actor, type, masterTalent)
  83. sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_INFO, talentInfo)
  84. Master.print("reqMasterInfo actor:" .. actor:toString() .. ", 请求大师信息,返回数据:", talentInfo)
  85. end
  86. --- 请求启用大师系列
  87. function Master.reqOpenMasterType(actor, msgData)
  88. Master.print("reqOpenMasterType actor:" .. actor:toString() .. ", 请求启用大师系列,msgData:", msgData)
  89. local masterType = msgData.type
  90. local series = msgData.series
  91. local masterTalentData = this.getMasterTalentData(actor, masterType)
  92. local masterTalent = masterTalentData[masterType]
  93. local seriesCount = masterTalent.seriesCount
  94. local now = getbaseinfo(actor, "now")
  95. local seriesCD = masterTalent.seriesCD
  96. local talent = masterTalent.talent
  97. if masterTalent.series == series then
  98. tipinfo(actor, "与当前系列一致")
  99. return
  100. end
  101. if masterType == MasterTalentType.JOB_TALENT then
  102. local openMasterSeriesCd = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.OPEN_MASTER_JOB_CD)
  103. local time = tonumber(seriesCD) + tonumber(openMasterSeriesCd) * 1000
  104. -- 校验cd
  105. if tonumber(now) < time then
  106. tipinfo(actor, string.format("职业天赋切换冷却中,还剩%s秒", math.ceil((time - now) / 1000)))
  107. return
  108. end
  109. --是否拥有特权
  110. local is_has = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.MASTER_TALENT_FREE_SWITCHING)
  111. local isPrivileges = is_has
  112. -- 首次免费
  113. if seriesCount > 0 and not isPrivileges then
  114. local openMasterSeriesCost = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.OPEN_MASTER_SERIES_COST)
  115. local seriesCost = string.split(openMasterSeriesCost, "#")
  116. local itemCfgId = tonumber(seriesCost[1])
  117. local count = tonumber(seriesCost[2])
  118. -- 校验消耗
  119. local bagCount = getbagitemcountbyid(actor, itemCfgId)
  120. if bagCount < count then
  121. tipinfo(actor, "消耗不足")
  122. return
  123. end
  124. -- 扣消耗
  125. removeitemfrombag(actor, itemCfgId, count,0,9999,'大师之路')
  126. end
  127. masterTalent.seriesCount = seriesCount + 1
  128. -- 职业天赋启用系列,技能天赋系列一起变动
  129. local skillTalentType = MasterTalentType.SKILL_TALENT
  130. local skillTalent = masterTalentData[skillTalentType]
  131. if table.isNullOrEmpty(skillTalent) then
  132. skillTalent = this.initSingleTalentData()
  133. masterTalentData[skillTalentType] = skillTalent
  134. end
  135. local skillTalentSeries = skillTalent.series
  136. if skillTalentSeries ~= tonumber(series) then
  137. skillTalent.series = series
  138. local allAttrMap = {}
  139. --local removesSkills = {}
  140. for _, value in pairs(skillTalent.talent) do
  141. local cfgId = value.cfgId
  142. local level = value.level
  143. local currSeries = value.series
  144. if currSeries == series then
  145. local talentList = ConfigDataManager.getTable("cfg_master_skilltalent", "id", cfgId)
  146. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level)
  147. if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then
  148. local talentCfg = talentList[1]
  149. local masterInfoCfg = masterList[1]
  150. local talentType = tonumber(talentCfg.type)
  151. if talentType == JobTalentType.TALENT then
  152. local masterInfoType = tonumber(masterInfoCfg.type)
  153. if masterInfoType == MasterTalentEffectType.ATT_TYPE then
  154. -- 添加属性
  155. local parameter = masterInfoCfg.parameter
  156. if parameter ~= "" then
  157. local skill_attr_map = this.getSplitAttr(parameter)
  158. allAttrMap[cfgId] = skill_attr_map
  159. end
  160. end
  161. --elseif talentType == 2 then
  162. -- -- todo 加技能效果 1类型的处理 type为1处理其他效果 学习或 升级技能 需要添加的技能
  163. -- local skillId = talentCfg.skillid
  164. -- levelupskill(actor, skillId, level)
  165. end
  166. end
  167. else
  168. -- 移除旧系列效果
  169. -- 属性上面覆盖了 无需处理 技能天赋不加技能也无需处理
  170. --if talentType == 1 then
  171. -- local masterInfoType = tonumber(masterInfoCfg.type)
  172. -- if masterInfoType == 1 then
  173. -- -- 移除属性 上面算了就算移除了
  174. -- end
  175. --elseif talentType == 2 then
  176. -- -- 放入移除技能table
  177. -- local skillId = talentCfg.skillid
  178. -- table.insert(removesSkills, skillId)
  179. --end
  180. end
  181. end
  182. skillTalent.allAttrMap = allAttrMap
  183. local addAttrMap = this.calculateAttr(allAttrMap)
  184. addrolekmlattributes(actor, MasterVariable.SKILL_TALENT_ATT, addAttrMap)
  185. --removeskill(actor, removesSkills)
  186. end
  187. local allAttrMap = {}
  188. local removesSkills = {}
  189. local addSkills = {}
  190. for _, value in pairs(talent) do
  191. local cfgId = value.cfgId
  192. local level = value.level
  193. local currSeries = value.series
  194. local talentList = ConfigDataManager.getTable("cfg_master_protalent", "id", cfgId)
  195. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level)
  196. if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then
  197. local talentCfg = talentList[1]
  198. local masterInfoCfg = masterList[1]
  199. local talentType = tonumber(talentCfg.type)
  200. --Master.print("reqOpenMasterType talentCfg:", talentCfg, "masterInfoCfg:", masterInfoCfg,"currSeries:",currSeries, "series:",series,"talentType",talentType,"value:",value)
  201. --Master.print("类型是否相同:",type(currSeries), type(series))
  202. if currSeries == series then
  203. --Master.print("相同系列")
  204. if talentType == JobTalentType.TALENT then
  205. local masterInfoType = tonumber(masterInfoCfg.type)
  206. if masterInfoType == MasterTalentEffectType.ATT_TYPE then
  207. -- 添加属性
  208. --local attr_map = getplaydef(actor, MasterVariable.MASTER_TALENT_ATT_DB) or {}
  209. local parameter = masterInfoCfg.parameter
  210. --Master.print("reqOpenMasterType talentCfg:", talentCfg, "masterInfoCfg:", masterInfoCfg,"parameter:",parameter)
  211. if parameter ~= "" then
  212. local attr_map = this.getSplitAttr(parameter)
  213. allAttrMap[cfgId] = attr_map
  214. end
  215. end
  216. elseif talentType == JobTalentType.SKILL_TALENT then
  217. -- todo 加技能效果 1类型的处理 type为1处理其他效果 学习或 升级技能 需要添加的技能
  218. local skillId = talentCfg.skillid
  219. levelupskill(actor, skillId, level)
  220. table.insert(addSkills, skillId)
  221. end
  222. else
  223. --Master.print("不同相同系列")
  224. -- 移除旧系列效果
  225. if talentType == JobTalentType.TALENT then
  226. local masterInfoType = tonumber(masterInfoCfg.type)
  227. if masterInfoType == MasterTalentEffectType.ATT_TYPE then
  228. -- 移除属性 上面算了就算移除了
  229. end
  230. elseif talentType == JobTalentType.SKILL_TALENT then
  231. -- 放入移除技能table
  232. local skillId = talentCfg.skillid
  233. table.insert(removesSkills, skillId)
  234. end
  235. end
  236. else
  237. Master.print("有数据配置为空", talentList, masterList, cfgId)
  238. end
  239. end
  240. Master.print(" 循环结束 talent信息:", talent, "要移除的技能id:", removesSkills, "添加的技能:", addSkills)
  241. local addAttrMap = this.calculateAttr(allAttrMap)
  242. addrolekmlattributes(actor, MasterVariable.JOB_TALENT_ATT, addAttrMap)
  243. removeskill(actor, removesSkills)
  244. elseif masterType == MasterTalentType.SKILL_TALENT then
  245. local openMasterSkillCd = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.OPEN_MASTER_SKILL_CD)
  246. local time = tonumber(seriesCD) + tonumber(openMasterSkillCd) * 1000
  247. -- 校验cd
  248. if tonumber(now) < time then
  249. tipinfo(actor, string.format("技能天赋切换冷却中,还剩%s秒", math.ceil((time - now) / 1000)))
  250. return
  251. end
  252. local allAttrMap = {}
  253. --local removesSkills = {}
  254. for _, value in pairs(talent) do
  255. local cfgId = value.cfgId
  256. local level = value.level
  257. local currSeries = value.series
  258. if currSeries == series then
  259. local talentList = ConfigDataManager.getTable("cfg_master_skilltalent", "id", cfgId)
  260. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level)
  261. if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then
  262. local talentCfg = talentList[1]
  263. local masterInfoCfg = masterList[1]
  264. local talentType = tonumber(talentCfg.type)
  265. if talentType == JobTalentType.TALENT then
  266. local masterInfoType = tonumber(masterInfoCfg.type)
  267. if masterInfoType == MasterTalentEffectType.ATT_TYPE then
  268. -- 添加属性
  269. local parameter = masterInfoCfg.parameter
  270. if parameter ~= "" then
  271. local attr_map = this.getSplitAttr(parameter)
  272. allAttrMap[cfgId] = attr_map
  273. end
  274. end
  275. --elseif talentType == 2 then
  276. -- -- todo 加技能效果 1类型的处理 type为1处理其他效果 学习或 升级技能 需要添加的技能
  277. -- local skillId = talentCfg.skillid
  278. -- levelupskill(actor, skillId, level)
  279. end
  280. end
  281. else
  282. -- 移除旧系列效果
  283. -- 属性上面覆盖了 无需处理 技能天赋不加技能也无需处理
  284. --if talentType == 1 then
  285. -- local masterInfoType = tonumber(masterInfoCfg.type)
  286. -- if masterInfoType == 1 then
  287. -- -- 移除属性 上面算了就算移除了
  288. -- end
  289. --elseif talentType == 2 then
  290. -- -- 放入移除技能table
  291. -- local skillId = talentCfg.skillid
  292. -- table.insert(removesSkills, skillId)
  293. --end
  294. end
  295. end
  296. masterTalent.allAttrMap = allAttrMap
  297. local addAttrMap = this.calculateAttr(allAttrMap)
  298. addrolekmlattributes(actor, MasterVariable.SKILL_TALENT_ATT, addAttrMap)
  299. --removeskill(actor, removesSkills)
  300. elseif masterType == MasterTalentType.COMMON_TALENT then
  301. local allAttrMap = {}
  302. --local removesSkills = {}
  303. for _, value in pairs(talent) do
  304. local cfgId = value.cfgId
  305. local level = value.level
  306. local currSeries = value.series
  307. --local talentList = ConfigDataManager.getTable("cfg_master_commontalent", "id", cfgId)
  308. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level)
  309. if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then
  310. --local talentCfg = talentList[1]
  311. local masterInfoCfg = masterList[1]
  312. if currSeries == series then
  313. local masterInfoType = tonumber(masterInfoCfg.type)
  314. if masterInfoType == MasterTalentEffectType.ATT_TYPE then
  315. -- 添加属性
  316. --local attr_map = getplaydef(actor, MasterVariable.MASTER_TALENT_ATT_DB) or {}
  317. local parameter = masterInfoCfg.parameter
  318. if parameter ~= "" then
  319. local attr_map = this.getSplitAttr(parameter)
  320. allAttrMap[cfgId] = attr_map
  321. end
  322. end
  323. --elseif talentType == 2 then
  324. -- -- todo 加技能效果 1类型的处理 type为1处理其他效果 学习或 升级技能 需要添加的技能
  325. -- local skillId = talentCfg.skillid
  326. -- levelupskill(actor, skillId, level)
  327. else
  328. -- 移除旧系列效果
  329. --if talentType == 1 then
  330. -- local masterInfoType = tonumber(masterInfoCfg.type)
  331. -- if masterInfoType == 1 then
  332. -- -- 移除属性 上面算了就算移除了
  333. -- end
  334. --elseif talentType == 2 then
  335. -- -- 放入移除技能table
  336. -- local skillId = talentCfg.skillid
  337. -- table.insert(removesSkills, skillId)
  338. --end
  339. end
  340. end
  341. end
  342. masterTalent.allAttrMap = allAttrMap
  343. local addAttrMap = this.calculateAttr(allAttrMap)
  344. addrolekmlattributes(actor, MasterVariable.COMMON_TALENT_ATT, addAttrMap)
  345. --removeskill(actor, removesSkills)
  346. end
  347. masterTalent.series = series
  348. masterTalent.seriesCD = tostring(now)
  349. setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData)
  350. sendluamsg(actor, LuaMessageIdToClient.RES_OPEN_MASTER_TYPE, { type = masterType, series = series })
  351. Master.print("reqOpenMasterType actor:" .. actor:toString() .. ", 请求启用大师系列 结束:", masterTalentData)
  352. end
  353. --- 请求兑换大师经验
  354. function Master.reqExchangeMasterExp(actor, msgData)
  355. Master.print("reqExchangeMasterExp actor:" .. actor:toString() .. ", 请求兑换大师经验,msgData:", msgData)
  356. local type = msgData.type
  357. local cost = msgData.cost
  358. local award = msgData.award
  359. local exchangedExpTimesData = getplaydef(actor, MasterVariable.EXCHANGED_EXP_TIMES) or {}
  360. local exchangedExpTimes = this.getTypeTimes(exchangedExpTimesData, type)
  361. -- todo 需要用每日自动清0的方式,或0点事件,或请求的时候触发 跨天就清0 已经改了,测试看看效果
  362. local masterTalentDayCount = ""
  363. if type == MasterTalentType.JOB_TALENT then
  364. masterTalentDayCount = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.JOB_TALENT_DAY_COUNT)
  365. elseif type == MasterTalentType.SKILL_TALENT then
  366. masterTalentDayCount = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.SKILL_TALENT_DAY_COUNT)
  367. end
  368. if exchangedExpTimes >= tonumber(masterTalentDayCount) then
  369. tipinfo(actor, "今日兑换次数已达上限")
  370. return
  371. end
  372. local masterTalentData = this.getMasterTalentData(actor, type)
  373. local masterTalent = masterTalentData[type]
  374. local maxLv = this.getMaxLevel(actor, type)
  375. if maxLv == -1 then
  376. return
  377. end
  378. if masterTalent.level == maxLv then
  379. tipinfo(actor, "已达到最高等级")
  380. return
  381. end
  382. if not table.isNullOrEmpty(cost) then
  383. for _, value in pairs(cost) do
  384. local costItemCfgId = value.costItemCfgId
  385. local costItemCount = value.costItemCount
  386. local bagCount = getbagitemcountbyid(actor, costItemCfgId)
  387. if bagCount < costItemCount then
  388. tipinfo(actor, "货币不足")
  389. return
  390. end
  391. end
  392. for _, value in pairs(cost) do
  393. local costItemCfgId = value.costItemCfgId
  394. local costItemCount = value.costItemCount
  395. removeitemfrombag(actor, costItemCfgId, costItemCount,0,9999,'大师之路')
  396. end
  397. end
  398. local masterTalentData = this.getMasterTalentData(actor, type)
  399. local masterTalent = masterTalentData[type]
  400. if not table.isNullOrEmpty(award) then
  401. for _, value in pairs(award) do
  402. local itemCfgId = value.itemCfgId
  403. local itemCount = value.itemCount
  404. --加经验
  405. this.addExp(actor, type, masterTalent, itemCount, maxLv)
  406. end
  407. end
  408. local count = exchangedExpTimes + 1
  409. exchangedExpTimesData[type] = count
  410. setplaydef(actor, MasterVariable.EXCHANGED_EXP_TIMES, exchangedExpTimesData)
  411. setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData)
  412. local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints)
  413. local resInfo = { type = type, level = masterTalent.level, exp = masterTalent.exp, exchangedExpTimes = count, points = masterTalent.points, seriesPoints = buildSeriesPoints }
  414. sendluamsg(actor, LuaMessageIdToClient.RES_EXCHANGE_MASTER_EXP, resInfo)
  415. Master.print("reqExchangeMasterExp actor:" .. actor:toString() .. ", 兑换大师经验结束 msgData:", msgData, ",旧使用次数", exchangedExpTimes, ",新使用次数", count)
  416. end
  417. --- 请求重置大师天赋
  418. function Master.reqResetMaster(actor, msgData)
  419. Master.print("reqResetMaster actor:" .. actor:toString() .. ", 请求重置大师天赋,msgData:", msgData)
  420. local masterType = msgData.type
  421. local masterTalentResetCost
  422. if masterType == MasterTalentType.JOB_TALENT then
  423. masterTalentResetCost = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.MASTER_TALENT_RESET_COST)
  424. elseif masterType == MasterTalentType.COMMON_TALENT then
  425. masterTalentResetCost = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.MASTER_TALENT_COMMON_RESET_COST)
  426. elseif masterType == MasterTalentType.SKILL_TALENT then
  427. masterTalentResetCost = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.MASTER_TALENT_SKILL_RESET_COST)
  428. end
  429. local resetCost = string.split(masterTalentResetCost, "#")
  430. local itemCfgId = tonumber(resetCost[1])
  431. local count = tonumber(resetCost[2])
  432. -- 校验消耗
  433. local bagCount = getbagitemcountbyid(actor, itemCfgId)
  434. if bagCount < count then
  435. tipinfo(actor, "货币不足")
  436. return
  437. end
  438. -- 扣消耗
  439. removeitemfrombag(actor, itemCfgId, count,0,9999,'大师之路')
  440. --重置点数
  441. local masterTalentData = this.getMasterTalentData(actor, masterType)
  442. local masterTalent = masterTalentData[masterType]
  443. local talent = masterTalent.talent
  444. local addPoint = 0
  445. local masterSeriesPoint = {}
  446. for id, value in pairs(talent) do
  447. if masterType == MasterTalentType.COMMON_TALENT then
  448. for i = 1, value.level do
  449. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", id, "level", i)
  450. if table.isNullOrEmpty(masterList) then
  451. tipinfo(actor, "未找到该天赋配置cfg_master_info")
  452. return
  453. end
  454. local masterInfoCfg = masterList[1]
  455. addPoint = addPoint + masterInfoCfg.consumpoint
  456. end
  457. else
  458. local series = value.series
  459. local add = 0
  460. for i = 1, value.level do
  461. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", id, "level", i)
  462. if table.isNullOrEmpty(masterList) then
  463. tipinfo(actor, "未找到该天赋配置cfg_master_info")
  464. return
  465. end
  466. local masterInfoCfg = masterList[1]
  467. add = add + masterInfoCfg.consumpoint
  468. end
  469. local oldPoint = masterSeriesPoint[series] or 0
  470. masterSeriesPoint[series] = oldPoint + add
  471. Master.print()
  472. end
  473. end
  474. -- todo 去除所有效果 遍历所以清空属性
  475. if masterType == MasterTalentType.JOB_TALENT then
  476. local attr_map = {}
  477. local removesSkills = {}
  478. for _, value in pairs(talent) do
  479. local cfgId = value.cfgId
  480. local level = value.level
  481. local currSeries = value.series
  482. local talentList = ConfigDataManager.getTable("cfg_master_protalent", "id", cfgId)
  483. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level)
  484. if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then
  485. local talentCfg = talentList[1]
  486. local masterInfoCfg = masterList[1]
  487. local talentType = tonumber(talentCfg.type)
  488. -- 移除效果
  489. if talentType == 1 then
  490. --local masterInfoType = tonumber(masterInfoCfg.type)
  491. --if masterInfoType == 1 then
  492. -- -- 移除属性 上面算了就算移除了
  493. --end
  494. elseif talentType == 2 then
  495. -- 放入移除技能table
  496. local skillId = talentCfg.skillid
  497. table.insert(removesSkills, skillId)
  498. end
  499. end
  500. end
  501. addrolekmlattributes(actor, MasterVariable.JOB_TALENT_ATT, attr_map)
  502. removeskill(actor, removesSkills)
  503. elseif masterType == MasterTalentType.SKILL_TALENT then
  504. local attr_map = {}
  505. local removesSkills = {}
  506. for _, value in pairs(talent) do
  507. local cfgId = value.cfgId
  508. local level = value.level
  509. local currSeries = value.series
  510. local talentList = ConfigDataManager.getTable("cfg_master_skilltalent", "id", cfgId)
  511. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level)
  512. if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then
  513. local talentCfg = talentList[1]
  514. local masterInfoCfg = masterList[1]
  515. local talentType = tonumber(talentCfg.type)
  516. -- 移除旧系列效果
  517. --if talentType == 1 then
  518. -- local masterInfoType = tonumber(masterInfoCfg.type)
  519. -- if masterInfoType == 1 then
  520. -- -- 移除属性 上面算了就算移除了
  521. -- end
  522. --elseif talentType == 2 then
  523. -- -- 放入移除技能table
  524. -- local skillId = talentCfg.skillid
  525. -- table.insert(removesSkills, skillId)
  526. --end
  527. end
  528. end
  529. addrolekmlattributes(actor, MasterVariable.SKILL_TALENT_ATT, attr_map)
  530. --removeskill(actor, removesSkills)
  531. elseif masterType == MasterTalentType.COMMON_TALENT then
  532. local attr_map = {}
  533. --local removesSkills = {}
  534. for _, value in pairs(talent) do
  535. local cfgId = value.cfgId
  536. local level = value.level
  537. local currSeries = value.series
  538. local talentList = ConfigDataManager.getTable("cfg_master_commontalent", "id", cfgId)
  539. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level)
  540. if not table.isNullOrEmpty(talentList) and not table.isNullOrEmpty(masterList) then
  541. local talentCfg = talentList[1]
  542. local masterInfoCfg = masterList[1]
  543. local talentType = tonumber(talentCfg.type)
  544. -- 移除旧系列效果
  545. --if talentType == 1 then
  546. -- local masterInfoType = tonumber(masterInfoCfg.type)
  547. -- if masterInfoType == 1 then
  548. -- -- 移除属性 上面算了就算移除了
  549. -- end
  550. --elseif talentType == 2 then
  551. -- -- 放入移除技能table
  552. -- local skillId = talentCfg.skillid
  553. -- table.insert(removesSkills, skillId)
  554. --end
  555. end
  556. end
  557. addrolekmlattributes(actor, MasterVariable.COMMON_TALENT_ATT, attr_map)
  558. --removeskill(actor, removesSkills)
  559. end
  560. local oldSeriesPoints = masterTalent.seriesPoints
  561. Master.print("reqResetMaster actor:" .. actor:toString() .. ", 已加的点数:", masterSeriesPoint, ",旧的点数", oldSeriesPoints)
  562. for series, point in pairs(masterSeriesPoint) do
  563. local oldPoint = oldSeriesPoints[series] or 0
  564. oldSeriesPoints[series] = oldPoint + point
  565. end
  566. Master.print("reqResetMaster actor:" .. actor:toString() .. ", 想加的结果:", oldSeriesPoints)
  567. masterTalent.seriesPoints = oldSeriesPoints
  568. masterTalent.points = masterTalent.points + addPoint
  569. masterTalent.talent = {}
  570. masterTalent.allAttrMap = {}
  571. setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData)
  572. local talentInfo = this.buildTalentInfo(actor, masterType, masterTalent)
  573. sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_INFO, talentInfo)
  574. Master.print("reqResetMaster actor:" .. actor:toString() .. ", 请求重置大师天赋,结束:", talentInfo)
  575. end
  576. --- 请求升级大师天赋
  577. function Master.reqUpgradeMasterTalent(actor, msgData)
  578. Master.print("reqUpgradeMasterTalent actor:" .. actor:toString() .. ", 请求升级大师天赋,msgData:", msgData)
  579. local talentType = msgData.type
  580. local cfgId = tonumber(msgData.cfgId)
  581. local addLv = msgData.addLv
  582. local masterTalentData = this.getMasterTalentData(actor, talentType)
  583. local masterTalent = masterTalentData[talentType]
  584. local talent = masterTalent.talent
  585. if talentType == MasterTalentType.JOB_TALENT then
  586. local talentList = ConfigDataManager.getTable("cfg_master_protalent", "id", cfgId)
  587. if table.isNullOrEmpty(talentList) then
  588. tipinfo(actor, "未找到该天赋配置cfg_master_protalent")
  589. return
  590. end
  591. local talentCfg = talentList[1]
  592. -- todo 考虑职业 career
  593. local talentInfo = this.getTalent(talent, talentCfg)
  594. local level = tonumber(talentInfo.level)
  595. local str = talentCfg.minmaxlevel
  596. local minMaxLevel = string.split(str, "#")
  597. if level >= tonumber(minMaxLevel[2]) then
  598. tipinfo(actor, "天赋已点满")
  599. return
  600. end
  601. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level + 1)
  602. if table.isNullOrEmpty(masterList) then
  603. tipinfo(actor, "未找到该天赋配置cfg_master_info")
  604. return
  605. end
  606. local masterInfoCfg = masterList[1]
  607. local totalNum = masterInfoCfg.frontnum
  608. local tier = talentCfg.tier
  609. -- 获取前置点数
  610. local totalPoints = this.getJobTalentPoints(talent, tier)
  611. Master.print("reqUpgradeMasterTalent actor:" .. actor:toString() .. ",totalPoints:" .. totalPoints, talent, tier)
  612. if totalPoints < tonumber(totalNum) then
  613. --tipinfo(actor, string.format("需要前置点数 需要前置点数数量%s", totalNum))
  614. tipinfo(actor, "前置天赋等级不足")
  615. return
  616. end
  617. local consumpoint = tonumber(masterInfoCfg.consumpoint)
  618. local seriesPoints = masterTalent.seriesPoints
  619. local series = tonumber(talentCfg.series)
  620. local points = seriesPoints[series] or 0
  621. if points < consumpoint then
  622. tipinfo(actor, "点数不足")
  623. return
  624. end
  625. seriesPoints[series] = points - consumpoint
  626. talentInfo.level = level + 1
  627. local cfgType = tonumber(talentCfg.type)
  628. -- 升级启用系列增加效果
  629. if masterTalent.series == series then
  630. if cfgType == JobTalentType.TALENT then
  631. local masterType = tonumber(masterInfoCfg.type)
  632. if masterType == MasterTalentEffectType.ATT_TYPE then
  633. -- 添加属性
  634. local addAttrMap = this.getAddAttMap(cfgId, masterTalent.allAttrMap, masterInfoCfg.parameter)
  635. addrolekmlattributes(actor, MasterVariable.JOB_TALENT_ATT, addAttrMap)
  636. end
  637. elseif cfgType == JobTalentType.SKILL_TALENT then
  638. -- 学习或 升级技能
  639. local skillId = talentCfg.skillid
  640. levelupskill(actor, skillId, talentInfo.level)
  641. end
  642. end
  643. local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints)
  644. local resTalent = {}
  645. table.insert(resTalent, talentInfo)
  646. local resInfo = { type = talentType, points = masterTalent.points, talent = resTalent, seriesPoints = buildSeriesPoints }
  647. sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_CHANGE_INFO, resInfo)
  648. elseif talentType == MasterTalentType.COMMON_TALENT then
  649. local talentList = ConfigDataManager.getTable("cfg_master_commontalent", "id", cfgId)
  650. if table.isNullOrEmpty(talentList) then
  651. tipinfo(actor, "未找到该天赋配置cfg_master_protalent")
  652. return
  653. end
  654. local talentCfg = talentList[1]
  655. -- todo 考虑职业 career
  656. local talentInfo = this.getTalent(talent, talentCfg)
  657. local level = tonumber(talentInfo.level)
  658. local str = talentCfg.minmaxlevel
  659. local minMaxLevel = string.split(str, "#")
  660. if level + addLv > tonumber(minMaxLevel[2]) then
  661. --Master.print("等级:",level, ",addlv:",addLv,",配置最大等级:", minMaxLevel[2])
  662. tipinfo(actor, "天赋已点满")
  663. return
  664. end
  665. local totalNum = 0
  666. for i = 1, addLv do
  667. local consumpoint = ConfigDataManager.getTableValue("cfg_master_info", "consumpoint", "talentId", cfgId, "level", level + i)
  668. totalNum = totalNum + consumpoint
  669. end
  670. local points = masterTalent.points
  671. if points < totalNum then
  672. tipinfo(actor, "点数不足")
  673. return
  674. end
  675. masterTalent.points = points - totalNum
  676. talentInfo.level = level + addLv
  677. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", talentInfo.level)
  678. if table.isNullOrEmpty(masterList) then
  679. tipinfo(actor, "未找到该天赋配置cfg_master_info")
  680. return
  681. end
  682. local masterInfoCfg = masterList[1]
  683. local masterType = tonumber(masterInfoCfg.type)
  684. if masterType == MasterTalentEffectType.ATT_TYPE then
  685. -- 添加属性
  686. local addAttrMap = this.getAddAttMap(cfgId, masterTalent.allAttrMap, masterInfoCfg.parameter)
  687. Master.print("属性添加成功", addAttrMap)
  688. addrolekmlattributes(actor, MasterVariable.COMMON_TALENT_ATT, addAttrMap)
  689. end
  690. local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints)
  691. local resTalent = {}
  692. table.insert(resTalent, talentInfo)
  693. local resInfo = { type = talentType, points = masterTalent.points, talent = resTalent, seriesPoints = buildSeriesPoints }
  694. sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_CHANGE_INFO, resInfo)
  695. elseif talentType == MasterTalentType.SKILL_TALENT then
  696. local talentList = ConfigDataManager.getTable("cfg_master_skilltalent", "id", cfgId)
  697. if table.isNullOrEmpty(talentList) then
  698. tipinfo(actor, "未找到该天赋配置 cfg_master_skilltalent")
  699. return
  700. end
  701. local talentCfg = talentList[1]
  702. -- todo 考虑职业 career
  703. local talentInfo = this.getTalent(talent, talentCfg)
  704. local level = tonumber(talentInfo.level)
  705. local str = talentCfg.minmaxlevel
  706. local minMaxLevel = string.split(str, "#")
  707. if level >= tonumber(minMaxLevel[2]) then
  708. tipinfo(actor, "天赋已点满")
  709. return
  710. end
  711. local masterList = ConfigDataManager.getTable("cfg_master_info", "talentId", cfgId, "level", level + 1)
  712. if table.isNullOrEmpty(masterList) then
  713. tipinfo(actor, "未找到该天赋配置cfg_master_info")
  714. return
  715. end
  716. local masterInfoCfg = masterList[1]
  717. local totalNum = masterInfoCfg.frontnum
  718. local cfgType = tonumber(talentCfg.type)
  719. if cfgType == SkillTalentType.SKILL_TALENT then
  720. local frontTalent = masterInfoCfg.fronttalent
  721. if frontTalent == "" then
  722. -- 不需要校验
  723. else
  724. local cfgList = ConfigDataManager.getTable("cfg_master_skilltalent", "id", frontTalent)
  725. if table.isNullOrEmpty(cfgList) then
  726. --Master.print("reqUpgradeMasterTalent actor:" .. actor:toString() .. ",frontTalent:", frontTalent,",frontTalent type:", type(frontTalent),",talentId:", cfgId, ",level:", level,",masterInfoCfg:",masterInfoCfg)
  727. tipinfo(actor, "cfg_master_skilltalent表frontTalent关联错误")
  728. return
  729. end
  730. local cfg = cfgList[1]
  731. -- 获取前置点数
  732. local totalPoints = 0
  733. if tonumber(cfg.type) == SkillTalentType.SKILL_TALENT then
  734. totalPoints = this.getSkillTalentPoints(talent, tonumber(frontTalent))
  735. elseif tonumber(cfg.type) == SkillTalentType.JOB_TALENT then
  736. local jobMasterTalent = masterTalentData[MasterTalentType.JOB_TALENT]
  737. totalPoints = this.getSkillTalentPoints(jobMasterTalent.talent, tonumber(cfg.protalentid))
  738. end
  739. --Master.print("reqUpgradeMasterTalent actor:" .. actor:toString() .. "已经加点数:", totalPoints, "配置要求达到点数", tonumber(totalNum))
  740. if totalPoints < tonumber(totalNum) then
  741. --tipinfo(actor, string.format("需要前置点数 需要前置点数数量%s", totalNum))
  742. tipinfo(actor, "前置天赋等级不足")
  743. return
  744. end
  745. end
  746. end
  747. local consumpoint = tonumber(masterInfoCfg.consumpoint)
  748. local seriesPoints = masterTalent.seriesPoints
  749. local series = tonumber(talentCfg.series)
  750. local points = seriesPoints[series] or 0
  751. if points < consumpoint then
  752. tipinfo(actor, "点数不足")
  753. return
  754. end
  755. seriesPoints[series] = points - consumpoint
  756. talentInfo.level = level + 1
  757. if masterTalent.series == series then
  758. if cfgType == SkillTalentType.SKILL_TALENT then
  759. local masterType = tonumber(masterInfoCfg.type)
  760. if masterType == MasterTalentEffectType.ATT_TYPE then
  761. -- 添加属性
  762. local addAttrMap = this.getAddAttMap(cfgId, masterTalent.allAttrMap, masterInfoCfg.parameter)
  763. addrolekmlattributes(actor, MasterVariable.SKILL_TALENT_ATT, addAttrMap)
  764. end
  765. end
  766. end
  767. setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData)
  768. local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints)
  769. local resTalent = {}
  770. table.insert(resTalent, talentInfo)
  771. local resInfo = { type = talentType, points = masterTalent.points, talent = resTalent, seriesPoints = buildSeriesPoints }
  772. sendluamsg(actor, LuaMessageIdToClient.RES_MASTER_CHANGE_INFO, resInfo)
  773. end
  774. setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData)
  775. Master.print("reqUpgradeMasterTalent actor:" .. actor:toString() .. ", 请求升级大师天赋,结束:", masterTalentData)
  776. end
  777. --- 角色升级触发获取通用天赋点
  778. function Master.levelup(actor, level, oldLevel)
  779. Master.print("Master levelup actor:" .. actor:toString() .. ", 角色升级触发获取通用天赋点,开始:" .. ",oldLevel:" .. oldLevel .. ",level:" .. level)
  780. local cfgLevel = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.COMMON_TALENT_MAX_LEVEL)
  781. local cfgLevelStr = string.split(cfgLevel, "#")
  782. local startLevel = tonumber(cfgLevelStr[1])
  783. local endLevel = tonumber(cfgLevelStr[2])
  784. if level < oldLevel then
  785. Master.print("Master levelup actor:" .. actor:toString() .. ",等级降级,无法获取通用天赋点", "level:" .. level)
  786. return
  787. end
  788. if level < startLevel or oldLevel > endLevel then
  789. Master.print("Master levelup actor:" .. actor:toString(), "等级不符合要求,无法获取通用天赋点", "level:" .. level .. ",oldLevel:" .. oldLevel .. ",startLevel" .. startLevel .. ",endLevel:" .. endLevel)
  790. return
  791. end
  792. --Master.print("Master levelup actor:" .. actor:toString(), "level:" .. level .. ",oldLevel:" .. oldLevel..",startLevel:"..startLevel..",endLevel:"..endLevel)
  793. --Master.print("Master levelup actor:" .. actor:toString(), "类型 level:" .. type(level) .. ",oldLevel:" .. type(oldLevel)..",startLevel:"..type(startLevel)..",endLevel:"..type(endLevel))
  794. local maxLv = math.min(level, endLevel)
  795. local minLv = math.max(oldLevel, startLevel - 1)
  796. local num = maxLv - minLv
  797. local commonTalentPoints = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.COMMON_TALENT_POINTS)
  798. local addPoints = num * tonumber(commonTalentPoints)
  799. local type = MasterTalentType.COMMON_TALENT
  800. local masterTalentData = this.getMasterTalentData(actor, type)
  801. local masterTalent = masterTalentData[type]
  802. masterTalent.points = masterTalent.points + addPoints
  803. setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData)
  804. local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints)
  805. local resInfo = { type = type, level = masterTalent.level, exp = masterTalent.exp, exchangedExpTimes = 0, points = masterTalent.points, seriesPoints = buildSeriesPoints }
  806. sendluamsg(actor, LuaMessageIdToClient.RES_EXCHANGE_MASTER_EXP, resInfo)
  807. Master.print("Master levelup actor:" .. actor:toString() .. ", 角色升级触发获取通用天赋点,结束:" .. ",oldLevel:" .. oldLevel .. ",level:" .. level, masterTalentData, resInfo)
  808. end
  809. --- 大师道具变化处理
  810. function Master.masterItemChange(actor, ids, cfgId, oldCount, newCount)
  811. -- ItemConfigId.EXP
  812. --local subType = ConfigDataManager.getTableValue("cfg_item", "subType", "id", cfgId)
  813. --if subType == nil then
  814. -- error("initguardequip actor:" .. actor:toString() .. " ,subType==nil itemCfgId:" .. cfgId)
  815. -- return
  816. --end
  817. if tonumber(newCount) < tonumber(oldCount) then
  818. -- 道具减少不处理
  819. return
  820. end
  821. local itemCount = newCount - oldCount
  822. --Master.print("masterItemChange 道具变化:actor:" .. actor:toString(), itemCount)
  823. local type = -1
  824. if cfgId == ItemConfigId.JOB_TALENT_ID then
  825. type = MasterTalentType.JOB_TALENT
  826. elseif cfgId == ItemConfigId.SKILL_TALENT_ID then
  827. type = MasterTalentType.SKILL_TALENT
  828. else
  829. -- 其他道具无需处理
  830. return
  831. end
  832. local masterTalentData = this.getMasterTalentData(actor, type)
  833. local masterTalent = masterTalentData[type]
  834. local maxLv = this.getMaxLevel(actor, type)
  835. if maxLv == -1 then
  836. return
  837. end
  838. if masterTalent.level == maxLv then
  839. tipinfo(actor, "已达到最高等级")
  840. return
  841. end
  842. -- 增加天赋经验
  843. this.addExp(actor, type, masterTalent, itemCount, maxLv)
  844. setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData)
  845. local exchangedExpTimesData = getplaydef(actor, MasterVariable.EXCHANGED_EXP_TIMES) or {}
  846. local exchangedExpTimes = this.getTypeTimes(exchangedExpTimesData, type)
  847. local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints)
  848. local resInfo = { type = type, level = masterTalent.level, exp = masterTalent.exp, exchangedExpTimes = exchangedExpTimes, points = masterTalent.points, seriesPoints = buildSeriesPoints }
  849. sendluamsg(actor, LuaMessageIdToClient.RES_EXCHANGE_MASTER_EXP, resInfo)
  850. end
  851. ---------------------------------------------------------------------------------------this----------------------------------------------------------------------------------------
  852. --- 增加经验
  853. function this.addExp(actor, type, talent, count, maxLv)
  854. if count < 1 then
  855. tipinfo(actor, "需要增加的经验不能小于1")
  856. return
  857. end
  858. local tableName = this.getTableName(type)
  859. local oldLv = talent.level
  860. local oldExp = talent.exp
  861. local addExp = count + oldExp
  862. local addPoint = 0
  863. while addExp > 0 do
  864. local level = talent.level
  865. local levelList = ConfigDataManager.getTable(tableName, "id", level)
  866. if table.isNullOrEmpty(levelList) then
  867. talent.exp = addExp
  868. tipinfo(actor, "未找到等级配置")
  869. Master.print("addExp 未找到等级配置 actor:", actor:toString(), ", oldLv:", oldLv, ", oldExp:", oldExp, ", addExp:", count, ", addPoint:", addPoint, ", lv:", talent.level, ", exp:", talent.exp)
  870. break
  871. end
  872. local levelCfg = levelList[1]
  873. local cfgExp = tonumber(levelCfg.exp)
  874. if addExp < cfgExp then
  875. talent.exp = addExp
  876. addExp = 0
  877. else
  878. addExp = addExp - cfgExp
  879. talent.level = talent.level + 1
  880. talent.exp = 0
  881. addPoint = addPoint + tonumber(levelCfg.point)
  882. if talent.level == maxLv then
  883. tipinfo(actor, "已到达最高等级")
  884. break
  885. end
  886. end
  887. end
  888. -- 两个系列增加点数
  889. local masterCache = getsysvar(actor,MasterVariable.MASTER_CACHE)
  890. local seriesTalent = masterCache[type]
  891. for _, series in pairs(seriesTalent) do
  892. local seriesNum = tonumber(series)
  893. local seriesPoints = talent.seriesPoints
  894. local points = seriesPoints[seriesNum] or 0
  895. seriesPoints[seriesNum] = points + addPoint
  896. end
  897. --talent.points = talent.points + addPoint
  898. Master.print("addExp actor:", actor:toString(), ", oldLv:", oldLv, ", oldExp:", oldExp, ", addExp:", count, ", addPoint:", addPoint, ", lv:", talent.level
  899. , ", exp:", talent.exp, "seriesPoints", talent.seriesPoints, ",type:", type)
  900. end
  901. --- 获取职业天赋已加点的天赋点数
  902. function this.getJobTalentPoints(talent, maxTier)
  903. local totalPoints = 0
  904. for cfgId, info in pairs(talent) do
  905. local tier = ConfigDataManager.getTableValue("cfg_master_protalent", "tier", "id", cfgId)
  906. if tier <= maxTier then
  907. for i = 1, info.level do
  908. local consumPoint = ConfigDataManager.getTableValue("cfg_master_info", "consumpoint", "talentId", cfgId, "level", i)
  909. Master.print("getJobTalentPoints 获取已加点 cfgId:" .. cfgId .. ",level:" .. i .. ",consumPoint:" .. tostring(consumPoint), talent, maxTier)
  910. totalPoints = totalPoints + tonumber(consumPoint)
  911. end
  912. end
  913. end
  914. return totalPoints
  915. end
  916. --- 获取技能天赋已加点的天赋点数
  917. function this.getSkillTalentPoints(talent, frontTalent)
  918. local totalPoints = 0
  919. for cfgId, info in pairs(talent) do
  920. if cfgId == frontTalent then
  921. for i = 1, info.level do
  922. local consumPoint = ConfigDataManager.getTableValue("cfg_master_info", "consumpoint", "talentId", cfgId, "level", i)
  923. totalPoints = totalPoints + tonumber(consumPoint)
  924. end
  925. end
  926. end
  927. return totalPoints
  928. end
  929. --- 初始化单个天赋
  930. function this.initTalentInfo(talentCfg)
  931. local talentInfo = {}
  932. talentInfo.cfgId = tonumber(talentCfg.id)
  933. talentInfo.level = 0
  934. talentInfo.series = tonumber(talentCfg.series)
  935. return talentInfo
  936. end
  937. --- 获取大师天赋数据
  938. function this.getMasterTalentData(actor, type)
  939. local masterTalentData = getplaydef(actor, MasterVariable.MASTER_TALENT_DATA) or {}
  940. local masterTalent = masterTalentData[type]
  941. if table.isNullOrEmpty(masterTalent) then
  942. masterTalent = this.initSingleTalentData()
  943. masterTalentData[type] = masterTalent
  944. setplaydef(actor, MasterVariable.MASTER_TALENT_DATA, masterTalentData)
  945. end
  946. return masterTalentData
  947. end
  948. --- 构建天赋信息
  949. function this.buildTalentInfo(actor, type, talent)
  950. local exchangedExpTimes = this.getExchangedExpTimes(actor, type)
  951. local talentInfo = {}
  952. talentInfo.type = type
  953. talentInfo.series = talent.series
  954. talentInfo.points = talent.points
  955. talentInfo.exchangedExpTimes = exchangedExpTimes
  956. talentInfo.level = talent.level
  957. talentInfo.exp = talent.exp
  958. talentInfo.talent = talent.talent
  959. -- 特权接口这里获取
  960. local is_has = PrivilegeMonth.hasPrivilege(actor, PrivilegeMonth.PrivilegeType.MASTER_TALENT_FREE_SWITCHING)
  961. talentInfo.isFree = is_has
  962. local seriesPoints = this.buildSeriesPoints(talent.seriesPoints)
  963. talentInfo.seriesPoints = seriesPoints
  964. return talentInfo
  965. end
  966. function this.buildSeriesPoints(points)
  967. local seriesPoints = {}
  968. if table.isNullOrEmpty(points) then
  969. return seriesPoints
  970. end
  971. for k, v in pairs(points) do
  972. local sp = {}
  973. sp.series = k
  974. sp.points = v
  975. table.insert(seriesPoints, sp)
  976. end
  977. return seriesPoints
  978. end
  979. function this.getExchangedExpTimes(actor, type)
  980. local exchangedExpTimesData = getplaydef(actor, MasterVariable.EXCHANGED_EXP_TIMES) or {}
  981. return this.getTypeTimes(exchangedExpTimesData, type)
  982. end
  983. function this.getTypeTimes(exchangedExpTimesData, type)
  984. local exchangedExpTimes = 0
  985. if exchangedExpTimesData == nil then
  986. return exchangedExpTimes
  987. end
  988. exchangedExpTimes = exchangedExpTimesData[type] or 0
  989. return exchangedExpTimes
  990. end
  991. function this.getTalent(talent, talentCfg)
  992. local cfgId = tonumber(talentCfg.id)
  993. local talentInfo = talent[cfgId]
  994. if table.isNullOrEmpty(talentInfo) then
  995. talentInfo = this.initTalentInfo(talentCfg)
  996. talent[cfgId] = talentInfo
  997. end
  998. return talentInfo
  999. end
  1000. function this.getAddAttMap(cfgId, allAttrMap, parameter)
  1001. if parameter ~= "" then
  1002. local attr_map = this.getSplitAttr(parameter)
  1003. allAttrMap[cfgId] = attr_map
  1004. local addAttrMap = this.calculateAttr(allAttrMap)
  1005. return addAttrMap
  1006. end
  1007. end
  1008. function this.getSplitAttr(parameter)
  1009. local attr_map = {}
  1010. local parameterStr = string.split(parameter, "&")
  1011. for _, value in pairs(parameterStr) do
  1012. local str = string.split(value, "#")
  1013. local attrId = str[1]
  1014. local oldValue = attr_map[attrId]
  1015. if oldValue == nil or oldValue == 0 then
  1016. attr_map[attrId] = str[2]
  1017. else
  1018. attr_map[attrId] = oldValue + str[2]
  1019. end
  1020. end
  1021. return attr_map
  1022. end
  1023. function this.calculateAttr(allAttrMap)
  1024. local addAttrMap = {}
  1025. for _, attr_map in pairs(allAttrMap) do
  1026. for attrId, value in pairs(attr_map) do
  1027. local oldValue = addAttrMap[attrId] or 0
  1028. addAttrMap[attrId] = oldValue + value
  1029. end
  1030. end
  1031. return addAttrMap
  1032. end
  1033. function this.getMaxLevel(actor, type)
  1034. local tableName = this.getTableName(type)
  1035. local configList = ConfigDataManager.getList(tableName)
  1036. if table.isNullOrEmpty(configList) then
  1037. tipinfo(actor, "未找到配置表")
  1038. Master.print("未找到配置",",表名:", tableName, ",type:", type)
  1039. return -1
  1040. end
  1041. -- 等级从0开始所以需要减1
  1042. local maxLv = table.count(configList) - 1
  1043. return maxLv
  1044. end
  1045. function this.getTableName(type)
  1046. local tableName = ""
  1047. if type == MasterTalentType.JOB_TALENT then
  1048. tableName = "cfg_master_proLevel"
  1049. elseif type == MasterTalentType.SKILL_TALENT then
  1050. tableName = "cfg_master_skillLevel"
  1051. end
  1052. return tableName
  1053. end
  1054. --- 初始化天赋数据
  1055. function this.initSingleTalentData()
  1056. return {
  1057. seriesPoints = {}, -- 系列天赋点数 {{[1]=0, [2]=0}} 服务器存储 发给客户端这个结构 {series= 1, points=0}, {series= 2, points=0}
  1058. series = 0, -- 系列 职业与技能天赋
  1059. seriesCount = 0, -- 选择启用系列次数 职业天赋
  1060. seriesCD = "0", -- 启用职业天赋CD 职业与技能天赋
  1061. points = 0, -- 通用天赋点数
  1062. level = 0, -- 等级
  1063. exp = 0, -- 当前经验
  1064. talent = {}, -- 天赋 索引天赋id 内容:{id, level, series系列}
  1065. allAttrMap = {}, -- 天赋配置 对应 获得的属性
  1066. }
  1067. end
  1068. --- 初始化天赋数据
  1069. function this.buildMasterRedDotInfo(actor, type, exchangedExpTimesData)
  1070. local masterInfo = {}
  1071. local exchangedExpTimes = this.getTypeTimes(exchangedExpTimesData, type)
  1072. local masterTalentData = this.getMasterTalentData(actor, type)
  1073. local masterTalent = masterTalentData[type]
  1074. masterInfo.type = type
  1075. masterInfo.exchangedExpTimes = exchangedExpTimes
  1076. masterInfo.level = masterTalent.level or 0
  1077. masterInfo.points = masterTalent.points or 0
  1078. local buildSeriesPoints = this.buildSeriesPoints(masterTalent.seriesPoints)
  1079. masterInfo.seriesPoints = buildSeriesPoints
  1080. return masterInfo
  1081. end
  1082. ---------------------------------------------------------------------------------------测试方法----------------------------------------------------------------------------------------
  1083. --- 打印日志
  1084. function Master.print(...)
  1085. local isPrintLog = true
  1086. if isPrintLog then
  1087. return
  1088. end
  1089. jprint(...)
  1090. end
  1091. --- 测试方法
  1092. function mastertest(actor)
  1093. --local masterTalentData = getplaydef(actor, MasterVariable.MASTER_TALENT_DATA) or {}
  1094. Master.print("reqMasterInfo actor:" .. actor:toString() .. ", 请求大师信息,返回数据:", getplaydef)
  1095. end