PassiveSkill.lua 7.1 KB

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