PassiveSkill_1.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. -- 被动技能
  2. PassiveSkill = {}
  3. local this = {}
  4. -- @description 传入cfg_passive_condition表id,释放被动技能
  5. -- @param 释放者;cfg_passive_condition表id;目标对象id列表
  6. -- @return
  7. function this.ReleaseByConditionId(actor, cfgId, targetList)
  8. cfgId = tonumber(cfgId)
  9. if cfgId == nil then
  10. return
  11. end
  12. local passiveSkills = {}
  13. -- 获取学习的所有技能
  14. local allSkills = getplayskilllist(actor, SkillType.PASSIVE)
  15. -- 是否是被动技能且关联释放条件
  16. for _, skillInfo in pairs(allSkills) do
  17. local skillId = skillInfo.id
  18. local skillLevel = skillInfo.level
  19. local type = skillInfo.type
  20. if type == SkillType.PASSIVE then
  21. local passivityTrigger = tonumber(ConfigDataManager.getTableValue("cfg_skill_info", "passivityTrigger",
  22. "skillID", skillId, "skillLevel", skillLevel))
  23. if passivityTrigger == cfgId then
  24. table.insert(passiveSkills, skillInfo)
  25. end
  26. end
  27. end
  28. -- 如果有,则释放被动技能
  29. if table.count(passiveSkills) > 0 then
  30. for _, skillInfo in pairs(passiveSkills) do
  31. local skillId = skillInfo.id
  32. local skillLevel = skillInfo.level
  33. this.ReleaseSkill0(actor, skillId, skillLevel, nil, targetList)
  34. end
  35. end
  36. end
  37. function this.ReleaseSkill0(actor, skillId, skillLevel, targetId, otherIds)
  38. if table.count(otherIds) == 1 and (targetId == nil) then
  39. targetId = otherIds[1]
  40. end
  41. if targetId ~= nil then
  42. local targetType = tonumber(ConfigDataManager.getTableValue("cfg_skill", "targetType", "id", skillId))
  43. if targetType == 4 then
  44. targetId = actor:toString()
  45. if table.count(otherIds) > 1 then
  46. error("玩家" .. actor:toString() .. "自我释放技能存在多个目标,skillId:" .. skillId)
  47. return
  48. end
  49. end
  50. end
  51. if table.count(otherIds) > 1 and (targetId == nil) then
  52. -- 多个目标
  53. local canReleaseTargetList = {}
  54. for _, otherId in pairs(otherIds) do
  55. -- 可以作用的目标玩家放到一个列表里
  56. if isskillavailable(actor, skillId, skillLevel, otherId) then
  57. table.insert(canReleaseTargetList, otherId)
  58. end
  59. end
  60. if table.count(canReleaseTargetList) > 0 then
  61. skill(actor, skillId, skillLevel, canReleaseTargetList[1], canReleaseTargetList)
  62. end
  63. else
  64. if targetId ~= nil then
  65. -- 单个目标
  66. if isskillavailable(actor, skillId, skillLevel, targetId) then
  67. skill(actor, skillId, skillLevel, targetId)
  68. end
  69. else
  70. -- 无目标
  71. if isskillavailable(actor, skillId, skillLevel) then
  72. skill(actor, skillId, skillLevel)
  73. end
  74. end
  75. end
  76. end
  77. -------------------------------------------------变身瞬间被动技能-------------------------------------------------
  78. -- @description 卡牌变身瞬间触发被动技能
  79. function PassiveSkill.DoTransfermation(actor, group)
  80. local config = ConfigDataManager.getTableFirst("cfg_passive_condition", "type", PassiveSkillType.DO_TRANSFERMATION,
  81. "parameter1", group)
  82. if config == nil then
  83. return
  84. end
  85. this.ReleaseByConditionId(actor, config.id)
  86. end
  87. ---------------------------------------------------------------------------------------------------------------
  88. -------------------------------------------------变身持续被动技能-------------------------------------------------
  89. -- @description 玩家秒钟心跳
  90. function PassiveSkill.RoleSecondHeart(actor)
  91. this.CheckTransfermationAndRelease(actor)
  92. end
  93. -- @description 卡牌变身持续监测被动技能
  94. function this.CheckTransfermationAndRelease(actor)
  95. local group = TransferCard.GetCurrentTransfermation(actor)
  96. if group == nil or group <= 0 then
  97. return
  98. end
  99. local config = ConfigDataManager.getTableFirst("cfg_passive_condition", "type", PassiveSkillType.IN_TRANSFERMATION,
  100. "parameter1", group)
  101. if config == nil then
  102. return
  103. end
  104. -- 时间检查
  105. local duration = tonumber(config.parameter2)
  106. local nowMillis = getbaseinfo("now")
  107. local varKey = this.BuildTransferDefKey(group)
  108. -- 这里不允许用持久化变量
  109. local lastReleaseTime = getplaydef(actor, varKey)
  110. if lastReleaseTime == nil then
  111. lastReleaseTime = 0
  112. end
  113. if nowMillis - lastReleaseTime < duration then
  114. return
  115. end
  116. local cfgId = config.id
  117. this.ReleaseByConditionId(actor, cfgId)
  118. setplaydef(actor, varKey, nowMillis)
  119. end
  120. function this.BuildTransferDefKey(group)
  121. return PlayerDefKey.LAST_PASSIVE_SKILL_TIME_BY_TRANSFER .. group
  122. end
  123. ---------------------------------------------------------------------------------------------------------------
  124. -------------------------------------------------攻击前被动技能-------------------------------------------------
  125. -- @description 攻击
  126. function PassiveSkill.RoleAttack(caster, targetList, skillId, skillLevel)
  127. local skillType = tonumber(ConfigDataManager.getTableValue("cfg_skill", "type", "id", skillId))
  128. if skillType == SkillType.PASSIVE then
  129. return
  130. end
  131. local configList = ConfigDataManager.getTable("cfg_passive_condition", "type", PassiveSkillType.ATTACK_WITH_HP)
  132. if configList == nil or table.count(configList) <= 0 then
  133. return
  134. end
  135. -- 分组
  136. for _, oneConfig in pairs(configList) do
  137. local cfgId = oneConfig.id
  138. local parameter1 = tonumber(oneConfig.parameter1)
  139. local targetGroup = {}
  140. for _, target in pairs(targetList) do
  141. local curHP = getbaseinfo(target, "hp")
  142. if curHP ~= nil then
  143. local maxHP = getbaseinfo(target, "maxhp")
  144. local rate = curHP / maxHP * 10000
  145. -- 目标血量万分比
  146. if rate >= parameter1 then
  147. table.insert(targetGroup, target:toString())
  148. end
  149. end
  150. end
  151. if table.count(targetGroup) > 0 then
  152. this.ReleaseByConditionId(caster, cfgId, targetGroup)
  153. end
  154. end
  155. end
  156. ---------------------------------------------------------------------------------------------------------------
  157. -------------------------------------------------受到控制buff-------------------------------------------------
  158. function PassiveSkill.BuffEffect(actor, caster, buffId)
  159. if actor:toString() == caster:toString() then
  160. return
  161. end
  162. -- 判断buff是不是控制类
  163. local buffTag = tonumber(ConfigDataManager.getTableValue("cfg_buff", "tag", "id", buffId))
  164. if buffTag ~= BuffTag.CONTROL then
  165. return
  166. end
  167. local configList = ConfigDataManager.getTable("cfg_passive_condition", "type", PassiveSkillType.UNDER_CONTROL)
  168. if configList == nil or table.count(configList) <= 0 then
  169. return
  170. end
  171. for _, oneConfig in pairs(configList) do
  172. local cfgId = oneConfig.id
  173. this.ReleaseByConditionId(actor, cfgId, {caster:toString()})
  174. end
  175. end
  176. ---------------------------------------------------------------------------------------------------------------