--- 天使天赋 --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by zhoutao. --- DateTime: 2024/11/11 17:45 AngelMajorTalent = {} local this = {} --- 获取天赋加点信息 ---@param actor table 角色 function AngelMajorTalent.getTalentInfo(actor) local res = {} local talentInfo = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO) res["talentInfo"] = talentInfo and talentInfo or {} local talentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT) res["talentPoint"] = talentPoint and talentPoint or 0 local allTalentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT) res["allTalentPoint"] = allTalentPoint or 0 local alreadyIncrementId = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_INCREMENT_ID) res["alreadyIncrementId"] = alreadyIncrementId sendluamsg(actor, LuaMessageIdToClient.RES_ANGEL_TALENT_INFO, res) end --- 天赋加点 ---@param actor table 角色 ---@param msgData table 消息数据 function AngelMajorTalent.addTalentPoint(actor, msgData) local talentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT) if talentPoint and talentPoint <= 0 then noticeTip.noticeinfo(actor, StringIdConst.TEXT482) return end local talentGroup = msgData["talentGroup"] local talentId = msgData["talentId"] local talentInfo = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO) -- 判断天赋前置点数条件 local talentTableInfo = ConfigDataManager.getTable("cfg_equip_angelTalent", "id", talentId) local talentType = talentTableInfo[1]["talenttype"] local beforePointCount = talentTableInfo[1]["talentrequest"] if not string.isNullOrEmpty(beforePointCount) then beforePointCount = tonumber(beforePointCount) if string.isNullOrEmpty(talentInfo) then gameDebug.print("天赋前置点数:" .. beforePointCount .. "条件不满足") noticeTip.noticeinfo(actor, StringIdConst.TEXT483) return end local pageInfo = talentInfo[talentGroup] if string.isNullOrEmpty(pageInfo) then gameDebug.print("天赋前置点数:" .. beforePointCount .. "条件不满足") noticeTip.noticeinfo(actor, StringIdConst.TEXT483) return end local currentPoint = 0 for id, level in pairs(pageInfo) do local tableValues = ConfigDataManager.getTable("cfg_equip_angelTalentLv", "talentId", id) for _, v in pairs(tableValues) do if tonumber(v["level"]) <= tonumber(level) then currentPoint = currentPoint + tonumber(v["consumpoint"]) end end end if currentPoint < beforePointCount then gameDebug.print("天赋前置点数:" .. beforePointCount .. "条件不满足") noticeTip.noticeinfo(actor, StringIdConst.TEXT483) return end end if string.isNullOrEmpty(talentInfo) then -- 没有存储的天赋信息,则创建存入 local temp = {} temp[talentGroup] = { [talentId] = 1 } local result = this.addPoint(actor, talentId, talentType, 0) if result then setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO, temp) talentInfo = temp end else -- 判断是否有存入的天赋信息,有则更新,没有新增 local pageInfo = talentInfo[talentGroup] local result = false if string.isNullOrEmpty(pageInfo) then talentInfo[talentGroup] = { [talentId] = 1 } result = this.addPoint(actor, talentId, talentType, 0) else local level = pageInfo[talentId] and pageInfo[talentId] or 0 result = this.addPoint(actor, talentId, talentType, level) if result then pageInfo[talentId] = level + 1 end end if result then setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO, talentInfo) end end local res = {} res["talentInfo"] = talentInfo and talentInfo or {} talentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT) res["talentPoint"] = talentPoint and talentPoint or 0 local allTalentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT) res["allTalentPoint"] = allTalentPoint local alreadyIncrementId = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_INCREMENT_ID) res["alreadyIncrementId"] = alreadyIncrementId sendluamsg(actor, LuaMessageIdToClient.RES_ANGEL_TALENT_INFO, res) end --- 重置天赋点 ---@param actor table 角色 function AngelMajorTalent.resetTalentPoint(actor) -- 10040001#300 local configValue = ConfigDataManager.getTableValue("cfg_global", "value", "id", GlobalConfigId.RESET_ANGEL_TALENT_COST) if string.isNullOrEmpty(configValue) then gameDebug.print("没有配置重置天赋点消耗信息") return end local tmps = string.split(configValue, "#") local itemConfigId = tmps[1] local costCount = tmps[2] if not Bag.checkItem(actor, itemConfigId, costCount) then noticeTip.noticeinfo(actor, StringIdConst.TEXT346) return end Bag.cost(actor, itemConfigId, costCount, ItemAction.ANGEL_TALENT_RESET_COST) -- 重置所有天赋为0点 setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO, {}) -- 重置天赋点 local allPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT) setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT, tonumber(allPoint and allPoint or 0)) -- 清除增加的天赋属性 RoleAttr.clearRoleAttrAndDB(actor, RoleAttrKey.ANGEL_MAJOR_TALENT) -- 移除学习过的技能 local skillIds = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_LEARN_SKILL) if not table.isNullOrEmpty(skillIds) then removeskill(actor, skillIds) setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_LEARN_SKILL, {}) end -- 响应天赋信息 AngelMajorTalent.getTalentInfo(actor) end --- 响应天赋大师已激活的id ---@param actor table 角色 function AngelMajorTalent.sendActiveTalentInfo(actor) local activeIds = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ACTIVE_ID) sendluamsg(actor, LuaMessageIdToClient.RES_ANGEL_TALENT_ACTIVE_INFO, activeIds and activeIds or {}) end --- 激活天赋大师 ---@param actor table 角色 ---@param id number cfg_equip_angelSuit表id function AngelMajorTalent.activateTalent(actor, id) local result, point = AngelMajorEquipment.checkDressedConditionType2(actor, id) if result then local activeIds = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ACTIVE_ID) if table.isNullOrEmpty(activeIds) then activeIds = {} end table.insert(activeIds, id) setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ACTIVE_ID, activeIds) -- 增加天赋点 AngelMajorTalent.incrementTalentPoint(actor, point) sendluamsg(actor, LuaMessageIdToClient.RES_ANGEL_TALENT_ACTIVE_INFO, activeIds) end end --- 增加天赋点 ---@param actor table 角色 ---@param point number 增加的点数 function AngelMajorTalent.incrementTalentPoint(actor, point) local talentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT) talentPoint = talentPoint and tonumber(talentPoint) or 0 setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT, talentPoint + point) local talentAllPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT) talentAllPoint = talentAllPoint and tonumber(talentAllPoint) or 0 setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT, talentAllPoint + point) -- 响应客户端天赋点变化 local res = {} local talentInfo = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_INFO) res["talentInfo"] = talentInfo and talentInfo or {} res["talentPoint"] = talentPoint + point local allTalentPoint = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_ALL_COUNT) res["allTalentPoint"] = allTalentPoint local alreadyIncrementId = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_INCREMENT_ID) res["alreadyIncrementId"] = alreadyIncrementId sendluamsg(actor, LuaMessageIdToClient.RES_ANGEL_TALENT_INFO, res) end --- 实际添加天赋点操作 ---@param actor table 角色 ---@param talentId number 天赋id ---@param talentType number 天赋类型 1.属性类 2.技能类 ---@param level number 当前天赋等级 ---@return boolean 是否添加成功 function this.addPoint(actor, talentId, talentType, level) level = level + 1 local maxLevel = ConfigDataManager.getTableValue("cfg_equip_angelTalent", "talentMaxLv", "id", talentId) if level > tonumber(maxLevel) then gameDebug.print("天赋已经升级到最大等级 talentId:" .. talentId .. " level:" .. level) return false end local consumePoint = ConfigDataManager.getTableValue("cfg_equip_angelTalentLv", "consumpoint", "talentid", talentId, "level", level) if not string.isNullOrEmpty(consumePoint) then -- 删除天赋点 local pointCount = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT) pointCount = pointCount and pointCount or 0 if pointCount < tonumber(consumePoint) then noticeTip.noticeinfo(actor, StringIdConst.TEXT482) return false end setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_POINT_COUNT, pointCount - consumePoint) -- 根据天赋类型添加对应的属性或技能 local parameter = ConfigDataManager.getTableValue("cfg_equip_angelTalentLv", "parameter", "talentId", talentId, "level", level) local split = string.split(parameter, "|") if tonumber(talentType) == AngelTalentType.ATTR then local addAttr = {} for _, v in pairs(split) do local tmps = string.split(v, "#") local attrId = tmps[1] local attrValue = tmps[2] addAttr[attrId] = attrValue end RoleAttr.addAndSaveRoleAttr(actor, RoleAttrKey.ANGEL_MAJOR_TALENT, addAttr) elseif tonumber(talentType) == AngelTalentType.SKILL then local tmps = string.split(split[1], "#") local skillId = tmps[1] local toLevel = tmps[2] levelupskill(actor, skillId, toLevel) local skillIds = getplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_LEARN_SKILL) skillIds = skillIds and skillIds or {} if not table.contains(skillIds, skillId) then table.insert(skillIds, skillId) end setplaydef(actor, PlayerDefKey.angel.ANGEL_TALENT_ALREADY_LEARN_SKILL, skillIds) end return true end return false end --- 测试增加天赋点 ---@param actor table 角色 function testincrementtalentpoint(actor) AngelMajorTalent.incrementTalentPoint(actor, 50) end