-- 被动技能 PassiveSkill = {} local this = {} -- @description 传入cfg_passive_condition表id,释放被动技能 -- @param 释放者;cfg_passive_condition表id;目标对象id列表 -- @return function this.ReleaseByConditionId(actor, cfgId, targetList) cfgId = tonumber(cfgId) if cfgId == nil then return end local passiveSkills = {} -- 获取学习的所有技能 local allSkills = getplayskilllist(actor, SkillType.PASSIVE) -- 是否是被动技能且关联释放条件 for _, skillInfo in pairs(allSkills) do local skillId = skillInfo.id local skillLevel = skillInfo.level local type = skillInfo.type if type == SkillType.PASSIVE then local passivityTrigger = tonumber(ConfigDataManager.getTableValue("cfg_skill_info", "passivityTrigger", "skillID", skillId, "skillLevel", skillLevel)) if passivityTrigger == cfgId then table.insert(passiveSkills, skillInfo) end end end -- 如果有,则释放被动技能 if table.count(passiveSkills) > 0 then for _, skillInfo in pairs(passiveSkills) do local skillId = skillInfo.id local skillLevel = skillInfo.level this.ReleaseSkill0(actor, skillId, skillLevel, nil, targetList) end end end function this.ReleaseSkill0(actor, skillId, skillLevel, targetId, otherIds) if table.count(otherIds) == 1 and (targetId == nil) then targetId = otherIds[1] end if targetId ~= nil then local targetType = tonumber(ConfigDataManager.getTableValue("cfg_skill", "targetType", "id", skillId)) if targetType == 4 then targetId = actor:toString() if table.count(otherIds) > 1 then error("玩家" .. actor:toString() .. "自我释放技能存在多个目标,skillId:" .. skillId) return end end end if table.count(otherIds) > 1 and (targetId == nil) then -- 多个目标 local canReleaseTargetList = {} for _, otherId in pairs(otherIds) do -- 可以作用的目标玩家放到一个列表里 if isskillavailable(actor, skillId, skillLevel, otherId) then table.insert(canReleaseTargetList, otherId) end end if table.count(canReleaseTargetList) > 0 then skill(actor, skillId, skillLevel, canReleaseTargetList[1], canReleaseTargetList) end else if targetId ~= nil then --单个目标 if isskillavailable(actor, skillId, skillLevel, targetId) then skill(actor, skillId, skillLevel, targetId) end else --无目标 if isskillavailable(actor, skillId, skillLevel) then skill(actor, skillId, skillLevel) end end end end -------------------------------------------------变身瞬间被动技能------------------------------------------------- -- @description 卡牌变身瞬间触发被动技能 function PassiveSkill.DoTransfermation(actor, group) local config = ConfigDataManager.getTableFirst("cfg_passive_condition", "type", PassiveSkillType.DO_TRANSFERMATION, "parameter1", group) if config == nil then return end this.ReleaseByConditionId(actor, config.id) end --------------------------------------------------------------------------------------------------------------- -------------------------------------------------变身持续被动技能------------------------------------------------- -- @description 玩家秒钟心跳 function PassiveSkill.RoleSecondHeart(actor) this.CheckTransfermationAndRelease(actor) end -- @description 卡牌变身持续监测被动技能 function this.CheckTransfermationAndRelease(actor) local group = TransferCard.GetCurrentTransfermation(actor) if group == nil or group <= 0 then return end local config = ConfigDataManager.getTableFirst("cfg_passive_condition", "type", PassiveSkillType.IN_TRANSFERMATION, "parameter1", group) if config == nil then return end -- 时间检查 local duration = tonumber(config.parameter2) local nowMillis = getbaseinfo("now") local varKey = this.BuildTransferDefKey(group) -- 这里不允许用持久化变量 local lastReleaseTime = getplaydef(actor, varKey) if lastReleaseTime == nil then lastReleaseTime = 0 end if nowMillis - lastReleaseTime < duration then return end local cfgId = config.id this.ReleaseByConditionId(actor, cfgId) setplaydef(actor, varKey, nowMillis) end function this.BuildTransferDefKey(group) return PlayerDefKey.LAST_PASSIVE_SKILL_TIME_BY_TRANSFER .. group end --------------------------------------------------------------------------------------------------------------- -------------------------------------------------攻击前被动技能------------------------------------------------- -- @description 攻击 function PassiveSkill.RoleAttack(caster, targetList, skillId, skillLevel) local skillType = tonumber(ConfigDataManager.getTableValue("cfg_skill", "type", "id", skillId)) if skillType == SkillType.PASSIVE then return end local configList = ConfigDataManager.getTable("cfg_passive_condition", "type", PassiveSkillType.ATTACK_WITH_HP) if configList == nil or table.count(configList) <= 0 then return end -- 分组 for _, oneConfig in pairs(configList) do local cfgId = oneConfig.id local parameter1 = tonumber(oneConfig.parameter1) local targetGroup = {} for _, target in pairs(targetList) do local curHP = getbaseinfo(target, "hp") local maxHP = getbaseinfo(target, "maxhp") local rate = curHP / maxHP * 10000 -- 目标血量万分比 if rate >= parameter1 then table.insert(targetGroup, target:toString()) end end if table.count(targetGroup) > 0 then this.ReleaseByConditionId(caster, cfgId, targetGroup) end end end --------------------------------------------------------------------------------------------------------------- -------------------------------------------------受到控制buff------------------------------------------------- function PassiveSkill.BuffEffect(actor, caster, buffId) if actor:toString() == caster:toString() then return end -- 判断buff是不是控制类 local buffTag = tonumber(ConfigDataManager.getTableValue("cfg_buff", "tag", "id", buffId)) if buffTag ~= BuffTag.CONTROL then return end local configList = ConfigDataManager.getTable("cfg_passive_condition", "type", PassiveSkillType.UNDER_CONTROL) if configList == nil or table.count(configList) <= 0 then return end for _, oneConfig in pairs(configList) do local cfgId = oneConfig.id this.ReleaseByConditionId(actor, cfgId, { caster:toString() }) end end ---------------------------------------------------------------------------------------------------------------