AngelMajorTalent.lua 11 KB

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