AngelMajorTalent.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. --- 天使天赋
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by zhoutao.
  4. --- DateTime: 2024/11/11 17:45
  5. AngelMajorTalent = {}
  6. local this = {}
  7. --- 获取天赋加点信息
  8. ---@param actor table 角色
  9. function AngelMajorTalent.getTalentInfo(actor)
  10. local res = {}
  11. local talentInfo = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO)
  12. res["talentInfo"] = talentInfo and talentInfo or {}
  13. local talentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT)
  14. res["talentPoint"] = talentPoint and talentPoint or 0
  15. local allTalentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT)
  16. res["allTalentPoint"] = allTalentPoint or 0
  17. local alreadyIncrementId = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_INCREMENT_ID)
  18. res["alreadyIncrementId"] = alreadyIncrementId
  19. sendluamsg(actor, LuaMessageIdToClient.RES_ANGEL_TALENT_INFO, res)
  20. end
  21. --- 天赋加点
  22. ---@param actor table 角色
  23. ---@param msgData table 消息数据
  24. function AngelMajorTalent.addTalentPoint(actor, msgData)
  25. local talentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT)
  26. if talentPoint and talentPoint <= 0 then
  27. noticeTip.noticeinfo(actor, StringIdConst.TEXT482)
  28. return
  29. end
  30. local talentGroup = msgData["talentGroup"]
  31. local talentId = msgData["talentId"]
  32. local talentInfo = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO)
  33. -- 判断天赋前置点数条件
  34. local talentTableInfo = ConfigDataManager.getTable("cfg_equip_angelTalent", "id", talentId)
  35. local talentType = talentTableInfo[1]["talenttype"]
  36. local beforePointCount = talentTableInfo[1]["talentrequest"]
  37. if not string.isNullOrEmpty(beforePointCount) then
  38. beforePointCount = tonumber(beforePointCount)
  39. if string.isNullOrEmpty(talentInfo) then
  40. gameDebug.print("天赋前置点数:" .. beforePointCount .. "条件不满足")
  41. noticeTip.noticeinfo(actor, StringIdConst.TEXT483)
  42. return
  43. end
  44. local pageInfo = talentInfo[talentGroup]
  45. if string.isNullOrEmpty(pageInfo) then
  46. gameDebug.print("天赋前置点数:" .. beforePointCount .. "条件不满足")
  47. noticeTip.noticeinfo(actor, StringIdConst.TEXT483)
  48. return
  49. end
  50. local currentPoint = 0
  51. for id, level in pairs(pageInfo) do
  52. local tableValues = ConfigDataManager.getTable("cfg_equip_angelTalentLv", "talentId", id)
  53. for _, v in pairs(tableValues) do
  54. if tonumber(v["level"]) <= tonumber(level) then
  55. currentPoint = currentPoint + tonumber(v["consumpoint"])
  56. end
  57. end
  58. end
  59. if currentPoint < beforePointCount then
  60. gameDebug.print("天赋前置点数:" .. beforePointCount .. "条件不满足")
  61. noticeTip.noticeinfo(actor, StringIdConst.TEXT483)
  62. return
  63. end
  64. end
  65. if string.isNullOrEmpty(talentInfo) then
  66. -- 没有存储的天赋信息,则创建存入
  67. local temp = {}
  68. temp[talentGroup] = {
  69. [talentId] = 1
  70. }
  71. local result = this.addPoint(actor, talentId, talentType, 0)
  72. if result then
  73. setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO, temp)
  74. talentInfo = temp
  75. end
  76. else
  77. -- 判断是否有存入的天赋信息,有则更新,没有新增
  78. local pageInfo = talentInfo[talentGroup]
  79. local result = false
  80. if string.isNullOrEmpty(pageInfo) then
  81. talentInfo[talentGroup] = {
  82. [talentId] = 1
  83. }
  84. result = this.addPoint(actor, talentId, talentType, 0)
  85. else
  86. local level = pageInfo[talentId] and pageInfo[talentId] or 0
  87. result = this.addPoint(actor, talentId, talentType, level)
  88. if result then
  89. pageInfo[talentId] = level + 1
  90. end
  91. end
  92. if result then
  93. setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO, talentInfo)
  94. end
  95. end
  96. local res = {}
  97. res["talentInfo"] = talentInfo and talentInfo or {}
  98. talentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT)
  99. res["talentPoint"] = talentPoint and talentPoint or 0
  100. local allTalentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT)
  101. res["allTalentPoint"] = allTalentPoint
  102. local alreadyIncrementId = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_INCREMENT_ID)
  103. res["alreadyIncrementId"] = alreadyIncrementId
  104. sendluamsg(actor, LuaMessageIdToClient.RES_ANGEL_TALENT_INFO, res)
  105. end
  106. --- 重置天赋点
  107. ---@param actor table 角色
  108. function AngelMajorTalent.resetTalentPoint(actor)
  109. -- 10040001#300
  110. local configValue = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.RESET_ANGEL_TALENT_COST)
  111. if string.isNullOrEmpty(configValue) then
  112. gameDebug.print("没有配置重置天赋点消耗信息")
  113. return
  114. end
  115. local tmps = string.split(configValue, "#")
  116. local itemConfigId = tmps[1]
  117. local costCount = tmps[2]
  118. if not Bag.checkItem(actor, itemConfigId, costCount) then
  119. noticeTip.noticeinfo(actor, StringIdConst.TEXT346)
  120. return
  121. end
  122. Bag.cost(actor, itemConfigId, costCount, ItemAction.ANGEL_TALENT_RESET_COST)
  123. -- 重置所有天赋为0点
  124. setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO, {})
  125. -- 重置天赋点
  126. local allPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT)
  127. setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT, tonumber(allPoint and allPoint or 0))
  128. -- 清除增加的天赋属性
  129. RoleAttr.clearRoleAttrAndDB(actor, RoleAttrKey.ANGEL_MAJOR_TALENT)
  130. -- 移除学习过的技能
  131. local skillIds = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_LEARN_SKILL)
  132. if not table.isNullOrEmpty(skillIds) then
  133. removeskill(actor, skillIds)
  134. setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_LEARN_SKILL, {})
  135. end
  136. -- 响应天赋信息
  137. AngelMajorTalent.getTalentInfo(actor)
  138. end
  139. --- 响应天赋大师已激活的id
  140. ---@param actor table 角色
  141. function AngelMajorTalent.sendActiveTalentInfo(actor)
  142. local activeIds = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ACTIVE_ID)
  143. sendluamsg(actor, LuaMessageIdToClient.RES_ANGEL_TALENT_ACTIVE_INFO, activeIds and activeIds or {})
  144. end
  145. --- 激活天赋大师
  146. ---@param actor table 角色
  147. ---@param id number cfg_equip_angelSuit表id
  148. function AngelMajorTalent.activateTalent(actor, id)
  149. local result, point = AngelMajorEquipment.checkDressedConditionType2(actor, id)
  150. if result then
  151. local activeIds = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ACTIVE_ID)
  152. if table.isNullOrEmpty(activeIds) then
  153. activeIds = {}
  154. end
  155. table.insert(activeIds, id)
  156. setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ACTIVE_ID, activeIds)
  157. -- 增加天赋点
  158. AngelMajorTalent.incrementTalentPoint(actor, point)
  159. sendluamsg(actor, LuaMessageIdToClient.RES_ANGEL_TALENT_ACTIVE_INFO, activeIds)
  160. end
  161. end
  162. --- 增加天赋点
  163. ---@param actor table 角色
  164. ---@param point number 增加的点数
  165. function AngelMajorTalent.incrementTalentPoint(actor, point)
  166. local talentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT)
  167. talentPoint = talentPoint and tonumber(talentPoint) or 0
  168. setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT, talentPoint + point)
  169. local talentAllPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT)
  170. talentAllPoint = talentAllPoint and tonumber(talentAllPoint) or 0
  171. setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT, talentAllPoint + point)
  172. -- 响应客户端天赋点变化
  173. local res = {}
  174. local talentInfo = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO)
  175. res["talentInfo"] = talentInfo and talentInfo or {}
  176. res["talentPoint"] = talentPoint + point
  177. local allTalentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT)
  178. res["allTalentPoint"] = allTalentPoint
  179. local alreadyIncrementId = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_INCREMENT_ID)
  180. res["alreadyIncrementId"] = alreadyIncrementId
  181. sendluamsg(actor, LuaMessageIdToClient.RES_ANGEL_TALENT_INFO, res)
  182. end
  183. --- 实际添加天赋点操作
  184. ---@param actor table 角色
  185. ---@param talentId number 天赋id
  186. ---@param talentType number 天赋类型 1.属性类 2.技能类
  187. ---@param level number 当前天赋等级
  188. ---@return boolean 是否添加成功
  189. function this.addPoint(actor, talentId, talentType, level)
  190. level = level + 1
  191. local maxLevel = ConfigDataManager.getTableValue("cfg_equip_angelTalent", "talentMaxLv", "id", talentId)
  192. if level > tonumber(maxLevel) then
  193. gameDebug.print("天赋已经升级到最大等级 talentId:" .. talentId .. " level:" .. level)
  194. return false
  195. end
  196. local consumePoint = ConfigDataManager.getTableValue("cfg_equip_angelTalentLv", "consumpoint", "talentid", talentId, "level", level)
  197. if not string.isNullOrEmpty(consumePoint) then
  198. -- 删除天赋点
  199. local pointCount = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT)
  200. pointCount = pointCount and pointCount or 0
  201. if pointCount < tonumber(consumePoint) then
  202. noticeTip.noticeinfo(actor, StringIdConst.TEXT482)
  203. return false
  204. end
  205. setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT, pointCount - consumePoint)
  206. -- 根据天赋类型添加对应的属性或技能
  207. local parameter = ConfigDataManager.getTableValue("cfg_equip_angelTalentLv", "parameter", "talentId", talentId, "level", level)
  208. local split = string.split(parameter, "|")
  209. if tonumber(talentType) == AngelTalentType.ATTR then
  210. local addAttr = {}
  211. for _, v in pairs(split) do
  212. local tmps = string.split(v, "#")
  213. local attrId = tmps[1]
  214. local attrValue = tmps[2]
  215. addAttr[attrId] = attrValue
  216. end
  217. RoleAttr.addAndSaveRoleAttr(actor, RoleAttrKey.ANGEL_MAJOR_TALENT, addAttr)
  218. elseif tonumber(talentType) == AngelTalentType.SKILL then
  219. local tmps = string.split(split[1], "#")
  220. local skillId = tmps[1]
  221. local toLevel = tmps[2]
  222. levelupskill(actor, skillId, toLevel)
  223. local skillIds = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_LEARN_SKILL)
  224. skillIds = skillIds and skillIds or {}
  225. if not table.contains(skillIds, skillId) then
  226. table.insert(skillIds, skillId)
  227. end
  228. setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_LEARN_SKILL, skillIds)
  229. end
  230. return true
  231. end
  232. return false
  233. end
  234. --- 测试增加天赋点
  235. ---@param actor table 角色
  236. function testincrementtalentpoint(actor)
  237. AngelMajorTalent.incrementTalentPoint(actor, 50)
  238. end