CombatBuff.lua 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155
  1. local Util = require("common.Util")
  2. local RoleAttr = require("role.RoleAttr")
  3. local CombatDefine = require("combat.CombatDefine")
  4. local CombatObj = require("combat.CombatObj")
  5. local CombatImpl = require("combat.CombatImpl")
  6. local TargetMode = require("combat.TargetMode")
  7. local CombatCalc = require("combat.CombatCalc")
  8. local RoleDefine = require("role.RoleDefine")
  9. local BeSkill = require("combat.BeSkill")
  10. local BufferExcel = require("excel.buffer")
  11. local Skill = require("combat.Skill")
  12. local SkillExcel = require("excel.skill").skill
  13. -- local HeroExcel = require("excel.hero").hero
  14. -- local FuwenExcel = require("excel.fuwen")
  15. local ProjectLogic = require("platform.ProjectLogic")
  16. local weaponBuffConfig = require("excel.weapon").buff
  17. local WinnerRelicLogic = require("winnerRelic.WinnerRelicLogic")
  18. local BUFF_FUMIAN = 1 -- 负面buff类型
  19. function GetBuffConfig(buffId)
  20. return weaponBuffConfig[buffId] or BufferExcel.buffer[buffId]
  21. end
  22. -- --如果该buff效果属于专属武器加强的效果, 则用专属武器配置表中的配置
  23. -- function GetFinalBuffConfig(obj, buffId)
  24. -- local targetId = buffId
  25. -- if obj and obj.weaponEffectIdList and obj.weaponEffectIdList[buffId] then
  26. -- targetId = obj.weaponEffectIdList[buffId]
  27. -- end
  28. -- return GetBuffConfig(targetId)
  29. -- end
  30. --和血量相关的作用
  31. local function isHpCmd(cmd)
  32. if cmd == "hp" or cmd == "hurt" or cmd == "hurt1" or cmd == "liuxue" or cmd == "liuxue2" or cmd == "zhongdu" or cmd == "ranshao" or cmd == "ranshao1" or cmd == "huiheYinji" then
  33. return true
  34. end
  35. return false
  36. end
  37. --控制类buff
  38. function isControlCmd(cmd)
  39. if cmd == "xuanyun" or cmd == "shihua" or cmd == "bingdong" or cmd == "chanrao" or cmd == "xuanyun2" or cmd == "chenshui" then
  40. return true
  41. end
  42. end
  43. --跳过行动回合
  44. function isStop(obj)
  45. if obj == nil then
  46. return
  47. end
  48. local bufferCmd = obj.bufferCmd
  49. local ret
  50. if bufferCmd["xuanyun"] or bufferCmd["shihua"] or bufferCmd["bingdong"]
  51. or bufferCmd["chanrao"] or bufferCmd["xuanyun2"] or bufferCmd["chenshui"] then
  52. ret = 1
  53. elseif bufferCmd["xuanyun"] or bufferCmd["xuanyun2"] then
  54. ret = 2
  55. end
  56. return ret
  57. end
  58. --判断英雄身上是否只有控制buff中的charao
  59. function IsJustHaveChanraoBuff(obj)
  60. if not obj then
  61. return false
  62. end
  63. local bufferCmd = obj.bufferCmd
  64. if not bufferCmd then
  65. return false
  66. end
  67. if bufferCmd["xuanyun"] or bufferCmd["shihua"] or bufferCmd["bingdong"] or bufferCmd["xuanyun2"] then
  68. return false
  69. end
  70. if bufferCmd["chanrao"] then
  71. return true
  72. end
  73. return false
  74. end
  75. --使用主动技能
  76. function isJingji(obj)
  77. if obj.bufferCmd["jinmo"] then
  78. return true
  79. end
  80. end
  81. -- 是否不使用主动技能
  82. function IsCanNoUseSkill(obj)
  83. --print("[IsCanNoUseSkill] 进入判断")
  84. if obj.bufferCmd["jinmo"] then
  85. --print("[IsCanNoUseSkill] jinmo 进入")
  86. return true
  87. end
  88. if obj.bufferCmd["jinmopro"] then
  89. local rand = math.random(1, 100)
  90. --print("[IsCanNoUseSkill] rand = "..rand)
  91. if rand >= 50 then
  92. --print("[IsCanNoUseSkill] 判断成功不释放技能 = "..rand)
  93. return true
  94. end
  95. end
  96. return false
  97. end
  98. --是否缠绕
  99. function isChanRao(obj)
  100. for j = obj.buffer[0], 1, -1 do
  101. local buffer = obj.buffer[j]
  102. --local conf = BufferExcel.buffer[buffer.id]
  103. local conf = GetBuffConfig(buffer.id)
  104. local cmd = conf.cmd
  105. if cmd == "chanrao" then
  106. return true
  107. end
  108. end
  109. end
  110. --是否被嘲讽
  111. function isChaofen(obj)
  112. if obj and obj.buffer then
  113. for j = obj.buffer[0], 1, -1 do
  114. local buffer = obj.buffer[j]
  115. --local conf = BufferExcel.buffer[buffer.id]
  116. local conf = GetBuffConfig(buffer.id)
  117. local cmd = conf.cmd
  118. if cmd == "chaofeng" then
  119. local attackPos = buffer.attackPos
  120. local attacker = CombatImpl.objList[attackPos]
  121. if attacker and attacker.pos ~= obj.pos then
  122. return true,attackPos
  123. end
  124. end
  125. end
  126. end
  127. return false,0
  128. end
  129. --是否被控制
  130. function isAtControl(obj)
  131. if obj and obj.buffer then
  132. for j = obj.buffer[0], 1, -1 do
  133. local buffer = obj.buffer[j]
  134. --local conf = BufferExcel.buffer[buffer.id]
  135. local conf = GetBuffConfig(buffer.id)
  136. local cmd = conf.cmd
  137. if isControlCmd(cmd) then
  138. return true
  139. end
  140. end
  141. end
  142. end
  143. -- 检查能否复活
  144. function canRevive(obj)
  145. if obj then
  146. if obj.hp > 0 then
  147. return
  148. end
  149. if obj.beBackup then
  150. return
  151. end
  152. if obj.dieSkill then
  153. --local skillConf = SkillExcel[obj.dieSkill]
  154. local skillConf = Skill.GetSkillConfig(obj.dieSkill)
  155. if skillConf.otherArgs.noRevive == 1 then
  156. return false
  157. end
  158. end
  159. if obj.bufferCmd and obj.bufferCmd["noRevive"] then
  160. return false
  161. end
  162. for k,v in ipairs(CombatImpl.frameReviceList) do
  163. if v[1] == obj.pos then
  164. return false
  165. end
  166. end
  167. return true
  168. end
  169. end
  170. --是否对某种状态免疫
  171. CMD2KEY = {
  172. ["xuanyun"] = RoleDefine.STATUS_MIANYI_RATE1,
  173. ["shihua"] = RoleDefine.STATUS_MIANYI_RATE2,
  174. ["bingdong"] = RoleDefine.STATUS_MIANYI_RATE3,
  175. ["jinmo"] = RoleDefine.STATUS_MIANYI_RATE4,
  176. ["ranshao"] = RoleDefine.STATUS_MIANYI_RATE5,
  177. ["ranshao1"] = RoleDefine.STATUS_MIANYI_RATE5,
  178. ["liuxue"] = RoleDefine.STATUS_MIANYI_RATE6,
  179. ["liuxue2"] = RoleDefine.STATUS_MIANYI_RATE6,
  180. ["zhongdu"] = RoleDefine.STATUS_MIANYI_RATE7,
  181. ["hunluan"] = RoleDefine.STATUS_MIANYI_RATE9,
  182. ["xuanyun2"] = RoleDefine.STATUS_MIANYI_RATE1,
  183. ["zuzhou"] = RoleDefine.STATUS_MIANYI_ZUZHOU,
  184. ["chenshui"] = RoleDefine.STATUS_MIANYI_CHENSHUI,
  185. }
  186. function isMianyi(obj,cmd)
  187. local key = CMD2KEY[cmd]
  188. local r = math.random(0,10000)
  189. if key and obj.attr[key] and obj.attr[key] >= r then
  190. return true
  191. end
  192. initCombatBufferType()
  193. -- 免疫所有负面状态
  194. if BUFFER_COMBAT_TYPE[cmd] and BUFFER_COMBAT_TYPE[cmd] == 1 then
  195. local r = math.random(0,10000)
  196. if obj.attr[RoleDefine.STATUS_MIANYI_RATE8] >= r then
  197. return true
  198. end
  199. end
  200. end
  201. local function isMiankong(obj, cmd, attacker, skillKongRate)
  202. if not isControlCmd(cmd) then return end
  203. if not attacker then return end
  204. if not skillKongRate then return end
  205. -- 新手剧情 100%控制
  206. if CombatImpl.fightMode[1] == CombatDefine.FIGHT_MODE2 then
  207. return false
  208. end
  209. local kongRate = attacker.attr[RoleDefine.KONG_RATE]
  210. -- 附带技能控制率
  211. kongRate = kongRate + skillKongRate
  212. local mianKongRate = obj.attr[RoleDefine.MIANKONG_RATE]
  213. kongRate = kongRate * (1 - mianKongRate/10000)
  214. kongRate = kongRate < 0 and 0 or kongRate
  215. if cmd == "xuanyun2" then
  216. kongRate = skillKongRate
  217. end
  218. -- 连击模式 控制概率
  219. if CombatImpl.comboType > 0 then
  220. kongRate = kongRate * CombatImpl.comboHurtRate / 10000
  221. end
  222. local r = math.random(1,10000)
  223. if r >= kongRate then
  224. return true
  225. end
  226. end
  227. function getStatus(obj)
  228. return obj.bufferCmd or {}
  229. end
  230. function isStatus(obj,status)
  231. local bufferCmd = obj.bufferCmd
  232. if not bufferCmd then return end
  233. for j = 1,#status do
  234. if bufferCmd[status[j]] then
  235. return true,status[j],bufferCmd[status[j]][1]
  236. end
  237. end
  238. end
  239. function isJob(obj,jobs)
  240. local job = obj.job
  241. -- print("当前传入的obj的job为:",obj.job)
  242. for i = 1,#jobs do
  243. if job == jobs[i] then
  244. return true
  245. end
  246. end
  247. end
  248. function isCamp(obj,camps)
  249. local camp = obj.camp
  250. for i = 1,#camps do
  251. if camp == camps[i] then
  252. return true
  253. end
  254. end
  255. end
  256. function isSide(obj,sides, attacker)
  257. if not attacker then return end
  258. local side = obj.side
  259. -- 只能对敌方
  260. if sides == 1 then
  261. if side == attacker.side then
  262. return true
  263. end
  264. -- 只能对友方
  265. elseif sides == 2 then
  266. if side ~= attacker.side then
  267. return true
  268. end
  269. end
  270. end
  271. local function isPos(obj,posList)
  272. local pos = obj.pos
  273. for i = 1,#posList do
  274. if pos == posList[i] then
  275. return true
  276. end
  277. end
  278. end
  279. function getBuffer(obj)
  280. return obj.buffer
  281. end
  282. function onBufferChange(obj)
  283. local bufferAttr = obj.bufferAttr
  284. RoleAttr.initCombatAttr(bufferAttr)
  285. local bufferCmd = obj.bufferCmd
  286. for k,v in pairs(bufferCmd) do
  287. bufferCmd[k] = nil
  288. end
  289. local changeList = {}
  290. for i = 1, obj.buffer[0] do
  291. local buffer = obj.buffer[i]
  292. --local conf = BufferExcel.buffer[buffer.id]
  293. local conf = GetBuffConfig(buffer.id)
  294. if conf.cmd == "stealattr" or
  295. conf.cmd == "handleattr" or
  296. conf.cmd == "attr" or
  297. conf.cmd == "attrdne" or
  298. conf.cmd == "attr1" or
  299. conf.cmd == "pojia" or
  300. conf.cmd == "jiansu" or
  301. conf.cmd == "defRate" or
  302. conf.cmd == "defRate2" or
  303. conf.cmd == "attrQusan" then
  304. if type(buffer.arg) == "table" then
  305. for j = 1,#buffer.arg do
  306. local attrData = buffer.arg[j]
  307. local key = attrData[1]
  308. local value = 0
  309. if not conf.attrRate then
  310. value = attrData[2]
  311. else
  312. value = conf.attrRate
  313. end
  314. RoleAttr.updateValue(key,value,bufferAttr,true)
  315. end
  316. else
  317. for j = 1,#conf.args do
  318. local attrData = conf.args[j]
  319. local key = attrData[1]
  320. local value = 0
  321. if not conf.attrRate then
  322. value = attrData[2]
  323. else
  324. value = conf.attrRate
  325. end
  326. RoleAttr.updateValue(key,buffer.arg or (value * buffer.cnt),bufferAttr,true)
  327. end
  328. end
  329. end
  330. if conf.cmd == "attraddsf" then
  331. -- print("[onBufferChange] 进入加 attraddsf")
  332. local nAttackPos = buffer.attackPos
  333. if nAttackPos then
  334. -- print("[onBufferChange] 存在 nAttackPos = "..nAttackPos)
  335. local tAttacker = CombatImpl.objList[nAttackPos]
  336. if tAttacker then
  337. -- print("[onBufferChange] 存在 tAttacker = ")
  338. for j = 1,#conf.args do
  339. local attrData = conf.args[j]
  340. local key = attrData[1]
  341. local nRate = attrData[2] / 10000
  342. local nCalValue = CombatObj.getValue(tAttacker, key)
  343. local nAddValue = nCalValue * nRate
  344. -- print("[onBufferChange] key = "..key.." nRate = "..nRate.." nCalValue = "..nCalValue.." nAddValue = "..nAddValue)
  345. RoleAttr.updateValue(key,nAddValue,bufferAttr,true)
  346. end
  347. end
  348. end
  349. end
  350. if conf.cmd == "xuruo" then
  351. RoleAttr.updateValue(RoleDefine.XURUO,buffer.arg or conf.args[1],bufferAttr,true)
  352. end
  353. if conf.cmd == "fansheZhuangjia" then
  354. RoleAttr.updateValue(RoleDefine.FANSHE_ZHUANGJIA,conf.args[1],bufferAttr,true)
  355. end
  356. if conf.cmd == "hudun" then
  357. RoleAttr.updateValue(RoleDefine.HUDUN_COMBAT, buffer.arg, bufferAttr,true)
  358. end
  359. --标识,给其他英雄加属性的buff
  360. if conf.cmd == "biaoshi" then
  361. local attacker = buffer.attackPos and CombatImpl.objList[buffer.attackPos]
  362. if attacker then
  363. if not changeList[attacker.pos] then
  364. changeList[attacker.pos] = 1
  365. attacker.bufferAttr2[obj.pos] = {}
  366. RoleAttr.initCombatAttr(attacker.bufferAttr2[obj.pos])
  367. end
  368. for j = 1,#conf.args do
  369. local attrData = conf.args[j]
  370. local key = attrData[1]
  371. local value = attrData[2]
  372. RoleAttr.updateValue(key,buffer.arg or (value * buffer.cnt),attacker.bufferAttr2[obj.pos],true)
  373. end
  374. end
  375. end
  376. bufferCmd[conf.cmd] = bufferCmd[conf.cmd] or {}
  377. bufferCmd[conf.cmd][#bufferCmd[conf.cmd] + 1] = i
  378. end
  379. CombatObj.calcAttr(obj)
  380. for pos in pairs(changeList) do
  381. CombatObj.calcAttr(CombatImpl.objList[pos])
  382. end
  383. end
  384. local function canAdd(obj, id, random, attacker, skillConfig)
  385. --local conf = BufferExcel.buffer[id]
  386. local conf = GetBuffConfig(id)
  387. if not conf then
  388. return
  389. end
  390. -- 非控制buff 走随机
  391. if not isControlCmd(conf.cmd) then
  392. -- print("[canAdd]111111111111 id = "..id.." random = "..random)
  393. -- 新手剧情 100%控制
  394. if CombatImpl.fightMode[1] == CombatDefine.FIGHT_MODE2 then
  395. random = 10000
  396. end
  397. -- print("[canAdd] 2222222222222222 id = "..id.." random = "..random)
  398. if random and not Util.checkRandom(random) then
  399. -- print("[canAdd] 333333333333333333333")
  400. return
  401. end
  402. end
  403. if obj.pos > CombatDefine.COMBAT_HERO_ALL_CNT then
  404. return
  405. end
  406. if obj.hp <= 0 then
  407. if conf.cmd == "revive" then
  408. return true
  409. else
  410. if conf.cmd == "noRevive" then
  411. return true
  412. end
  413. end
  414. return
  415. end
  416. if conf.cmd == "fixPos" then
  417. return true
  418. end
  419. if #conf.jobs > 0 and not isJob(obj,conf.jobs) then
  420. return
  421. end
  422. if conf.camp and #conf.camp > 0 and not isCamp(obj,conf.camp) then
  423. return
  424. end
  425. -- 只能给友方或者敌对方加
  426. if conf.side and conf.side > 0 and isSide(obj, conf.side, attacker) then
  427. return
  428. end
  429. if #conf.status > 0 and not isStatus(obj,conf.status) then
  430. return
  431. end
  432. if #conf.pos > 0 and not isPos(obj,conf.pos) then
  433. return
  434. end
  435. if isMianyi(obj,conf.cmd) then
  436. return
  437. end
  438. if isMiankong(obj,conf.cmd, attacker, random) then
  439. return
  440. end
  441. -- if skillConfig and skillConfig.cmd == "winnerRelicSkill" then
  442. -- if conf.cmd == "attr" then
  443. -- local random1 = math.random(1, 10000)
  444. -- print("[combatbuff - canAdd] random1 = "..random1.." random = "..random.." buffid = "..id)
  445. -- if random1 >= random then
  446. -- return true
  447. -- else
  448. -- return
  449. -- end
  450. -- end
  451. -- end
  452. --连击 BUFF率为 本来的一半
  453. if CombatImpl.comboType > 0 then
  454. local random = math.random(1, 10000)
  455. if random < 5000 then
  456. return
  457. end
  458. end
  459. return true
  460. end
  461. --根据cmd删除buff
  462. local function delBufferByCmd(obj,cmd,cnt)
  463. local delCnt = 0
  464. for j = obj.buffer[0], 1, -1 do
  465. local buffer = obj.buffer[j]
  466. --local conf = BufferExcel.buffer[buffer.id]
  467. local conf = GetBuffConfig(buffer.id)
  468. local bufferCmd = conf.cmd
  469. if bufferCmd == cmd then
  470. local bufferCnt = delBuffer(obj, j)
  471. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_DEL)
  472. delCnt = delCnt + 1
  473. if delCnt == cnt then
  474. return
  475. end
  476. end
  477. end
  478. end
  479. --删除所有buff
  480. local function delAllBuff(obj)
  481. for i = 1, obj.buffer[0] do
  482. obj.buffer[i] = nil
  483. end
  484. obj.buffer[0] = 0
  485. end
  486. --判断是否抵消buff
  487. local function cancelBuffer(obj,conf)
  488. local cancelCmd = conf.cancelCmd[1]
  489. local cnt = conf.cancelCmd[2]
  490. if not (cancelCmd and cnt) then
  491. return
  492. end
  493. local nowCnt = getBuffCnt(obj,cancelCmd)
  494. if cnt < 0 then --全删抵消buff
  495. if nowCnt > 0 then
  496. delBufferByCmd(obj,cancelCmd,cnt)
  497. return true
  498. end
  499. elseif cnt == 0 then--不删抵消buff
  500. if nowCnt > 0 then
  501. return true
  502. end
  503. elseif cnt > 0 then--删指定数量抵消buff
  504. if nowCnt >= cnt then
  505. delBufferByCmd(obj,cancelCmd,cnt)
  506. return true
  507. end
  508. end
  509. end
  510. DELAY_BUFF_OP = false
  511. DELAY_LIST = nil
  512. --不可以延迟加的buffcmd(加的时候可能会触发删除其他buff的cmd)
  513. NO_DELAY_BUFFCMD = {
  514. ["convert"] = 1
  515. }
  516. local function delayBegin()
  517. if DELAY_BUFF_OP then
  518. return
  519. end
  520. DELAY_BUFF_OP = true
  521. DELAY_LIST = {del = {},add = {}}
  522. end
  523. local function delayEnd()
  524. if not DELAY_BUFF_OP then
  525. return
  526. end
  527. table.sort(DELAY_LIST.del,function(a,b)
  528. return a[2] > b[2]
  529. end)
  530. DELAY_BUFF_OP = false
  531. local delRecord = {}
  532. for k,v in ipairs(DELAY_LIST.del) do
  533. delRecord[v[1]] =delRecord[v[1]] or {}
  534. if not delRecord[v[1]][v[2]] then
  535. delBuffer(v[1], v[2])
  536. delRecord[v[1]][v[2]] = 1
  537. end
  538. end
  539. for k,v in ipairs(DELAY_LIST.add) do
  540. addBuffer(v[1],v[2], v[3], v[4],v[5],v[6])
  541. end
  542. DELAY_LIST = {del = {},add = {}}
  543. end
  544. local function beforeAddBuffer(attackPos,obj, id, skillID,arg,parentConf)
  545. --local conf = BufferExcel.buffer[id]
  546. local conf = GetBuffConfig(id)
  547. local bufferCmd = conf.cmd
  548. if BUFFER_COMBAT_TYPE[bufferCmd] and BUFFER_COMBAT_TYPE[bufferCmd] == BUFF_FUMIAN then
  549. local nBuffNum = getBuffCnt(obj, "shuihua")
  550. -- print("[beforeAddBuffer] 在加buff之前 bufferCmd = "..bufferCmd.." nBuffNum = "..nBuffNum)
  551. if nBuffNum >= 1 then
  552. delBufferByCmd(obj, "shuihua", 1)
  553. print("[beforeAddBuffer] shuihua 生效抵消掉一个负面buff bufferCmd = "..bufferCmd)
  554. return true
  555. end
  556. end
  557. if bufferCmd == "fixPos" then
  558. elseif cancelBuffer(obj,conf) then
  559. return true
  560. elseif bufferCmd == "shengling" then
  561. elseif conf.holdOnDie ~= 1 and obj.hp <= 0 then
  562. return true
  563. elseif conf.roundOne == 1 then
  564. for j = obj.buffer[0], 1, -1 do
  565. local buffer = obj.buffer[j]
  566. if buffer.id == id and buffer.attackPos == attackPos and buffer.round == conf.round then
  567. return true
  568. end
  569. end
  570. end
  571. if conf.type == CombatDefine.BUFFER_TYPE4 then
  572. if handler[bufferCmd] then
  573. local attacker = CombatImpl.objList[attackPos]
  574. handler[bufferCmd](attacker,obj,conf)
  575. end
  576. return true
  577. end
  578. if bufferCmd == "convert" then
  579. local bufferList = {}
  580. for j = obj.buffer[0], 1, -1 do
  581. local buffer = obj.buffer[j]
  582. if buffer.id == id then
  583. bufferList[#bufferList + 1] = j
  584. end
  585. end
  586. local needCnt = conf.args[1]
  587. if #bufferList + 1 < needCnt then
  588. return
  589. end
  590. for _,v in ipairs(bufferList) do
  591. local buffer = obj.buffer[v]
  592. local bufferCnt = delBuffer(obj, v)
  593. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_DEL)
  594. end
  595. addBuffer(attackPos,obj, conf.args[2], skillID,arg,parentConf)
  596. return true
  597. end
  598. end
  599. -- 添加到复活列表
  600. local function checkRevive(attackPos,obj,bufferID,skillID)
  601. --local conf = BufferExcel.buffer[bufferID]
  602. local conf = GetBuffConfig(bufferID)
  603. if conf.cmd ~= "revive" then
  604. return
  605. end
  606. if not canRevive(obj) then
  607. return true
  608. end
  609. CombatImpl.addRevice(attackPos, obj, bufferID, skillID)
  610. return true
  611. end
  612. -- 复活对象
  613. function reviceObj(attackPos, obj, bufferID, skillID)
  614. --local conf = BufferExcel.buffer[bufferID]
  615. local conf = GetBuffConfig(bufferID)
  616. if not conf then return end
  617. local attacker = CombatImpl.objList[attackPos]
  618. --local skillConf = skillID and SkillExcel[skillID]
  619. local skillConf = skillID and Skill.GetSkillConfig(skillID)
  620. if not skillConf then return end
  621. local attacker = CombatImpl.objList[attackPos]
  622. local hpRevive = CombatCalc.calcHp(attacker, obj, conf.args[1], conf.args[2], true)
  623. local hpAddRate = CombatObj.getValue(attacker,RoleDefine.ZAOCHENG_HP_ADD_RATE) / 10000
  624. hpRevive = hpRevive * (1 + hpAddRate)
  625. hpRevive = hpRevive < 0 and 1 or hpRevive
  626. local d = CombatObj.updateHp(obj, hpRevive, true, nil, nil, CombatObj.EXTRA_HP_TYPE)
  627. local attrs = {}
  628. attrs[RoleDefine.REVIVE_COMBAT] = attackPos
  629. CombatImpl.setSkillID(attacker, skillID)
  630. CombatImpl.setSkillHit(obj,0, nil, nil, attacker, skillID)
  631. CombatImpl.setSaySkill(attacker.pos,skillConf.id,skillConf.contentType)
  632. CombatImpl.setExtraHit(obj,d,Skill.getCMD2ID("revive"),attrs)
  633. if skillConf and skillConf.type == 0 then
  634. onExtraCombatRecord(attackPos, 1, "reviveBeUse")
  635. else
  636. onExtraCombatRecord(attackPos, 1, "revive")
  637. end
  638. if skillConf.cmd == "revive" then
  639. local buffers = skillConf.args
  640. local addBufferID = buffers[1]
  641. if addBufferID then
  642. local targetMode = buffers[2]
  643. local random = buffers[3]
  644. local targets = TargetMode.getTargets(obj, targetMode)
  645. if #targets > 0 then
  646. for _,target in ipairs(targets) do
  647. if canAdd(target, addBufferID, random, obj, skillConf) then
  648. addBuffer(obj.pos, target, addBufferID, skillConf.id, arg)
  649. end
  650. end
  651. end
  652. end
  653. end
  654. BeSkill.onAddBuffer(obj,{id = bufferID})
  655. obj.dieSkill = nil
  656. CombatImpl.InsertAttackOrder(obj.pos)
  657. end
  658. function addBuffer(attackPos,obj, id, skillID,arg,parentConf)
  659. -- local conf = BufferExcel.buffer[id]
  660. local conf = GetBuffConfig(id)
  661. local bufferCmd = conf.cmd
  662. if DELAY_BUFF_OP then
  663. if not NO_DELAY_BUFFCMD[bufferCmd] then
  664. DELAY_LIST.add[#DELAY_LIST.add + 1] = {attackPos,obj, id, skillID,arg,parentConf}
  665. end
  666. return
  667. end
  668. if checkRevive(attackPos,obj, id, skillID) then
  669. return
  670. end
  671. if beforeAddBuffer(attackPos,obj, id, skillID,arg,parentConf) then
  672. return
  673. end
  674. local bufferCnt = 1
  675. local buffer
  676. local bufferCmdInd
  677. local bufferInd
  678. local tround = 0
  679. local index = 0
  680. local groupCnt = 0
  681. local group = conf.group[1]
  682. for i = 1, obj.buffer[0] do
  683. buffer = obj.buffer[i]
  684. if buffer.id == id then
  685. bufferCnt = bufferCnt + 1
  686. bufferInd = i
  687. if tround > buffer.round or tround == 0 then
  688. tround = buffer.round
  689. index = i
  690. end
  691. end
  692. --local nowBuffConf = BufferExcel.buffer[buffer.id]
  693. local nowBuffConf = GetBuffConfig(buffer.id)
  694. if nowBuffConf.cmd == bufferCmd then
  695. bufferCmdInd = i
  696. end
  697. if group and group == nowBuffConf.group[1] then
  698. groupCnt = groupCnt + 1
  699. end
  700. end
  701. local groupCmd = conf.group[2]
  702. if groupCmd and groupCnt > 0 and groupCnt >= groupCmd then
  703. return
  704. end
  705. if bufferCnt > 100 then
  706. return
  707. end
  708. local canAppend = parentConf and parentConf.canAppend or conf.canAppend
  709. local round = parentConf and parentConf.round or conf.round
  710. round = round == 0 and 1 or round
  711. if canAppend == 1 then
  712. local appendCnt = conf.appendCnt or 0
  713. if appendCnt > 0 and bufferCnt > conf.appendCnt then
  714. if conf.type == CombatDefine.BUFFER_TYPE2 then
  715. buffer = obj.buffer[index]
  716. buffer.round = round
  717. --bingdong清除buffer参数
  718. if conf.cmd == "bingdong" then
  719. buffer.arg = nil
  720. end
  721. CombatImpl.onAddBuffer(id)
  722. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_ADD,0)
  723. return
  724. end
  725. return
  726. end
  727. else
  728. if bufferCnt > 1 then
  729. if conf.type == CombatDefine.BUFFER_TYPE2 then
  730. buffer = obj.buffer[bufferInd]
  731. buffer.round = round
  732. --bingdong清除buffer参数
  733. if conf.cmd == "bingdong" then
  734. buffer.arg = nil
  735. end
  736. CombatImpl.onAddBuffer(id)
  737. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_ADD,0)
  738. return
  739. end
  740. return
  741. end
  742. end
  743. if isControlCmd(bufferCmd) and bufferCmdInd then
  744. buffer = obj.buffer[bufferCmdInd]
  745. if buffer.round < round then
  746. buffer.round = round
  747. end
  748. if conf.cmd == "bingdong" then
  749. buffer.arg = nil
  750. end
  751. return
  752. end
  753. obj.buffer[0] = obj.buffer[0] + 1
  754. index = obj.buffer[0]
  755. buffer = obj.buffer[index]
  756. if not buffer then
  757. obj.buffer[index] = {}
  758. buffer = obj.buffer[index]
  759. end
  760. buffer.id = id
  761. buffer.round = nil -- 剩余回合
  762. buffer.attrs = nil
  763. buffer.attackPos = nil
  764. buffer.skillID = nil
  765. buffer.cnt = 1
  766. buffer.arg = nil
  767. if round then
  768. buffer.round = round
  769. elseif conf.type == CombatDefine.BUFFER_TYPE1 then
  770. buffer.round = 1
  771. elseif conf.type == CombatDefine.BUFFER_TYPE2 then
  772. buffer.round = round
  773. elseif conf.type == CombatDefine.BUFFER_TYPE3 then
  774. buffer.round = nil
  775. else
  776. assert()
  777. end
  778. local attacker
  779. if attackPos > CombatDefine.COMBAT_HERO_ALL_CNT then
  780. attacker = CombatImpl.helpList[attackPos]
  781. else
  782. attacker = CombatImpl.objList[attackPos]
  783. end
  784. if arg then
  785. buffer.arg = arg
  786. elseif isHpCmd(conf.cmd) then
  787. local isAddHp = conf.cmd == "hp"
  788. buffer.arg = CombatCalc.calcBufferHp(attacker,obj,id,isAddHp)
  789. end
  790. buffer.attackPos = attackPos
  791. buffer.skillID = skillID
  792. buffer.attrs = {}
  793. if bufferCmd == "shengling" then
  794. buffer.arg = conf.args[3]
  795. elseif bufferCmd == "hudun" then
  796. local attackerHp = CombatCalc.calcHp(attacker, obj, conf.args[1], conf.args[2], true)
  797. local hudunValue = math.floor(conf.args[2] * attackerHp / 10000)
  798. buffer.arg = hudunValue
  799. end
  800. onBufferChange(obj)
  801. if conf.isAddCmd == 1 and handler[conf.cmd] then
  802. handler[conf.cmd](obj,buffer,conf)
  803. HANDLER_ONCE[conf.cmd] = nil
  804. end
  805. -- 立刻触发一次返回
  806. if conf.effectiveonce and conf.effectiveonce == 1 and handler[conf.cmd] then
  807. print("[addBuffer] 立刻触发一次buff效果id = "..buffer.id)
  808. handler[conf.cmd](obj,buffer,conf)
  809. HANDLER_ONCE[conf.cmd] = nil
  810. buffer.round = 0
  811. end
  812. if conf.type ~= CombatDefine.BUFFER_TYPE1 then
  813. CombatImpl.onAddBuffer(id)
  814. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_ADD)
  815. end
  816. BeSkill.onAddBuffer(obj,buffer)
  817. onExtraCombatRecord(attackPos,1,bufferCmd)
  818. if conf.effectiveonce and conf.effectiveonce == 1 then
  819. obj.buffer[0] = obj.buffer[0] - 1
  820. table.remove(obj.buffer, index)
  821. print("[addBuffer] 删除了对应的buff id = ".. buffer.id.." index = "..index)
  822. end
  823. return buffer
  824. end
  825. local function delBufferByTotem(obj,totemId)
  826. for j = obj.buffer[0], 1, -1 do
  827. local buffer = obj.buffer[j]
  828. --local conf = BufferExcel.buffer[buffer.id]
  829. local conf = GetBuffConfig(buffer.id)
  830. if bufferCmd ~= "totem" and buffer.totem == totemId then
  831. delBuffer(obj,j)
  832. end
  833. end
  834. end
  835. local function beforeDelBuffer(obj, buffer)
  836. --local conf = BufferExcel.buffer[buffer.id]
  837. local conf = GetBuffConfig(buffer.id)
  838. if conf.cmd == "fentan" and buffer.round < 1 then
  839. local hurt = CombatCalc.calcHp(obj, obj, conf.args[1], conf.args[2])
  840. if hurt > 0 then
  841. local d = CombatObj.updateHp(obj, hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  842. CombatImpl.setExtraHit(obj, hurt)
  843. CombatObj.onHpCB(obj, d, obj.pos)
  844. end
  845. end
  846. end
  847. function delBuffer(obj, ind)
  848. if not obj.buffer[ind] then
  849. return
  850. end
  851. if DELAY_BUFF_OP then
  852. for k,v in ipairs(DELAY_LIST.del) do
  853. if v[2] == ind then
  854. return
  855. end
  856. end
  857. DELAY_LIST.del[#DELAY_LIST.del + 1] = {obj, ind}
  858. return
  859. end
  860. local id = obj.buffer[ind].id
  861. beforeDelBuffer(obj,obj.buffer[ind])
  862. obj.buffer[ind] = obj.buffer[obj.buffer[0]]
  863. obj.buffer[obj.buffer[0]] = nil
  864. obj.buffer[0] = obj.buffer[0] - 1
  865. onBufferChange(obj)
  866. local bufferCnt = 0
  867. for i = 1, obj.buffer[0] do
  868. local buffer = obj.buffer[i]
  869. if buffer.id == id then
  870. bufferCnt = bufferCnt + 1
  871. end
  872. end
  873. return bufferCnt
  874. end
  875. --通过buff的cmd删除一定数量的buff
  876. function DelBuffByCmd(obj, cmd, cnt)
  877. delBufferByCmd(obj, cmd, cnt)
  878. end
  879. -- 战斗回合开始时添加buffer
  880. function beforeCombat()
  881. end
  882. function getSkillBuffers(skillConfig)
  883. local randBuffCnt = skillConfig.otherArgs.randBuffCnt
  884. if not randBuffCnt then
  885. return skillConfig.buffers
  886. end
  887. local ret = {}
  888. local c = #skillConfig.buffers
  889. if randBuffCnt >= c then
  890. return skillConfig.buffers
  891. end
  892. for i = 1,c do
  893. ret[i] = skillConfig.buffers[i]
  894. end
  895. for i = 1,c do
  896. if i <= randBuffCnt then
  897. local r = math.random(i,c)
  898. ret[i],ret[r] = ret[r],ret[i]
  899. else
  900. ret[i] = nil
  901. end
  902. end
  903. return ret
  904. end
  905. -- 战斗回合中触发buffer
  906. function onHit(attacker, skillTargets, skillConfig, cmdTargets, otherArgs)
  907. -- 处理施法者身上的buff
  908. if skillConfig.type == CombatDefine.SKILL_TYPE2 and
  909. attacker.buffer ~= nil then
  910. delayBegin()
  911. for j = attacker.buffer[0], 1, -1 do
  912. local buffer = attacker.buffer[j]
  913. --local conf = BufferExcel.buffer[buffer.id]
  914. local conf = GetBuffConfig(buffer.id)
  915. buffer.attrs = { }
  916. if attacker.hp > 0 and handlerEx[conf.cmd] then
  917. if handlerEx[conf.cmd](attacker, buffer, conf) then
  918. CombatImpl.addFrameBuffer(attacker, buffer, CombatDefine.BUFFER_OP_HOLD)
  919. end
  920. end
  921. end
  922. delayEnd()
  923. end
  924. for k, v in ipairs(skillTargets) do
  925. if attacker.helpType == 0 and attacker.side ~= v.side then
  926. local fantanBufferInd = v.bufferCmd["fantan"] and v.bufferCmd["fantan"][1]
  927. local fantanBuffer = v.buffer[fantanBufferInd]
  928. if fantanBuffer then
  929. --local conf = BufferExcel.buffer[fantanBuffer.id]
  930. local conf = GetBuffConfig(fantanBuffer.id)
  931. -- 是否限制技能类型
  932. local bHit = false
  933. if conf.args[3] then
  934. if conf.args[3] == skillConfig.type then
  935. bHit = true
  936. end
  937. else
  938. bHit = true
  939. end
  940. if bHit then
  941. local hurt = CombatCalc.calcHp(attacker, v, conf.args[1], conf.args[2])
  942. local d = CombatObj.updateHp(attacker, - hurt, nil, nil, v.pos, CombatObj.BUFFER_HP_TYPE)
  943. CombatImpl.setExtraHit(attacker, d)
  944. CombatObj.onHpCB(attacker, d, v.pos)
  945. end
  946. end
  947. end
  948. -- 只能敌方攻击触发降低冰冻
  949. if not(otherArgs and otherArgs.noFirst) and skillConfig.hurtRate[1] then
  950. local bufferCmd = v.bufferCmd["bingdong"]
  951. if bufferCmd then
  952. local delList = { }
  953. for i = #bufferCmd, 1, -1 do
  954. local bingdongBuffer = v.buffer[bufferCmd[i]]
  955. --local conf = BufferExcel.buffer[bingdongBuffer.id]
  956. local conf = GetBuffConfig(bingdongBuffer.id)
  957. bingdongBuffer.arg = bingdongBuffer.arg or 0
  958. bingdongBuffer.arg = bingdongBuffer.arg + 1
  959. if bingdongBuffer.arg >=(conf.args[1] or 0) then
  960. delList[#delList + 1] = bufferCmd[i]
  961. end
  962. end
  963. --冰冻buffer被打碎
  964. if #delList > 0 then
  965. local delBuffer = v.buffer[delList[1]]
  966. BeSkill.onDelBingDongBuffer(v, delBuffer)
  967. end
  968. for k1, v1 in ipairs(delList) do
  969. local buffer = v.buffer[v1]
  970. local bufferCnt = delBuffer(v, v1)
  971. CombatImpl.addFrameBuffer(v, buffer, CombatDefine.BUFFER_OP_DEL)
  972. end
  973. end
  974. end
  975. end
  976. local buffers = getSkillBuffers(skillConfig)
  977. local statusBuffRate = skillConfig.otherArgs.statusBuffRate
  978. local jobRateAdd = skillConfig.otherArgs.jobRateAdd
  979. for i = 1, #buffers do
  980. local bufferID = buffers[i][1]
  981. if type(bufferID) == "table" then
  982. local r = math.random(1, #bufferID)
  983. bufferID = bufferID[r]
  984. end
  985. local targetMode = buffers[i][2]
  986. local random = buffers[i][3]
  987. local bufferEx = buffers[i][4]
  988. local delayRound = buffers[i][5]
  989. if attacker.isPet and #skillConfig.bufferGrow > 0 then
  990. local growRate = 0
  991. local bufLv = attacker.lv
  992. if attacker.quality > 1 then
  993. bufLv = attacker.lv -(attacker.quality - 1) * 30
  994. end
  995. if skillConfig.bufferGrow and skillConfig.bufferGrow[i] then
  996. local gorwRat = skillConfig.bufferGrow[i][1]
  997. local growLv = skillConfig.bufferGrow[i][2]
  998. growRate = math.floor(bufLv / growLv) * gorwRat
  999. end
  1000. random = random + growRate
  1001. end
  1002. local targets = TargetMode.getTargets(attacker, targetMode, skillTargets, cmdTargets, nil, nil, skillConfig.id)
  1003. if #targets > 0 then
  1004. --local bufferConf = BufferExcel.buffer[bufferID]
  1005. local bufferConf = GetBuffConfig(bufferID)
  1006. for _, target in ipairs(targets) do
  1007. local r = random
  1008. if statusBuffRate and bufferConf.cmd == statusBuffRate[1] and isStatus(target, statusBuffRate[2]) then
  1009. r = r + statusBuffRate[3]
  1010. end
  1011. if jobRateAdd and bufferConf.cmd == jobRateAdd[1] and isJob(target, jobRateAdd[2]) then
  1012. r = r + jobRateAdd[3]
  1013. end
  1014. if canAdd(target, bufferID, r, attacker, skillConfig) then
  1015. local arg
  1016. if bufferConf.cmd == "zuzhou" then
  1017. local rate = bufferConf.args[2] + BeSkill.getBufferExtraHurt(attacker, bufferID, bufferConf.cmd)
  1018. arg = { CombatCalc.calcHp(attacker, target, bufferConf.args[1], rate) }
  1019. end
  1020. if bufferConf.cmd == "stealattr" then
  1021. local value = CombatCalc.calcValue(attacker, target, bufferConf.args[1], bufferConf.args[2])
  1022. arg = { { bufferConf.args[3], value } }
  1023. end
  1024. if bufferConf.cmd == "handleattr" then
  1025. arg = { }
  1026. if attacker.handleAttr then
  1027. local value = attacker.handleAttr[2] *(bufferConf.args[1] / 10000)
  1028. if target.side == attacker.side then
  1029. arg = { { attacker.handleAttr[1], value * bufferConf.args[2] } }
  1030. else
  1031. arg = { { attacker.handleAttr[1], - value } }
  1032. end
  1033. end
  1034. end
  1035. if delayRound and delayRound > 0 then
  1036. target.delayAddBuffer = target.delayAddBuffer or { }
  1037. target.delayAddBuffer[#target.delayAddBuffer + 1] = { delayRound, attacker.pos, bufferID, skillConfig.id, arg }
  1038. else
  1039. addBuffer(attacker.pos, target, bufferID, skillConfig.id, arg)
  1040. end
  1041. if bufferEx then
  1042. local bufferID = bufferEx[1]
  1043. local random = bufferEx[2]
  1044. local delayRound = bufferEx[3]
  1045. --local bufferConf = BufferExcel.buffer[bufferID]
  1046. local bufferConf = GetBuffConfig(bufferID)
  1047. for _, target in ipairs(targets) do
  1048. local r = random
  1049. if canAdd(target, bufferID, r, attacker, skillConfig) then
  1050. local arg
  1051. if bufferConf.cmd == "zuzhou" then
  1052. local rate = bufferConf.args[2] + BeSkill.getBufferExtraHurt(attacker, bufferID, bufferConf.cmd)
  1053. arg = { CombatCalc.calcHp(attacker, target, bufferConf.args[1], rate) }
  1054. end
  1055. if bufferConf.cmd == "stealattr" then
  1056. local value = CombatCalc.calcValue(attacker, target, bufferConf.args[1], bufferConf.args[2])
  1057. arg = { { bufferConf.args[3], value } }
  1058. end
  1059. if bufferConf.cmd == "handleattr" then
  1060. arg = { }
  1061. if attacker.handleAttr then
  1062. local value = attacker.handleAttr[2] *(bufferConf.args[1] / 10000)
  1063. if target.side == attacker.side then
  1064. arg = { { attacker.handleAttr[1], value * bufferConf.args[2] } }
  1065. else
  1066. arg = { { attacker.handleAttr[1], - value } }
  1067. end
  1068. end
  1069. end
  1070. if delayRound and delayRound > 0 then
  1071. target.delayAddBuffer = target.delayAddBuffer or { }
  1072. target.delayAddBuffer[#target.delayAddBuffer + 1] = { delayRound, attacker.pos, bufferID, skillConfig.id, arg }
  1073. else
  1074. addBuffer(attacker.pos, target, bufferID, skillConfig.id, arg)
  1075. end
  1076. end
  1077. end
  1078. end
  1079. end
  1080. end
  1081. end
  1082. end
  1083. end
  1084. local function getBeskillBuffers(attacker,skillConfig)
  1085. if skillConfig.otherArgs.buffer then
  1086. local checkArg = skillConfig.otherArgs.buffer
  1087. local checkValue
  1088. if checkArg.cmd == "hurtRate" then
  1089. checkValue = -attacker.combatResult[1]
  1090. elseif checkArg.cmd == "hpRate" then
  1091. checkValue = attacker.combatResult[2]
  1092. end
  1093. if checkValue and checkValue > 0 then
  1094. local hpMax = attacker.attr[RoleDefine.HP]
  1095. local rate = (10000 * checkValue)/(hpMax * checkArg.param[1])
  1096. if rate > 1 then
  1097. local retArg = {}
  1098. for k,v in ipairs(checkArg.param[2]) do
  1099. retArg[#retArg + 1] = {v[1],math.floor(v[2] * rate)}
  1100. end
  1101. return skillConfig.buffers,retArg
  1102. end
  1103. end
  1104. elseif skillConfig.otherArgs.randBuffCnt then
  1105. local randBuffCnt = skillConfig.otherArgs.randBuffCnt
  1106. local allBuffCnt = #skillConfig.buffers
  1107. if randBuffCnt >= allBuffCnt then
  1108. return skillConfig.buffers
  1109. end
  1110. local ret = {}
  1111. for i = 1, allBuffCnt do
  1112. ret[i] = skillConfig.buffers[i]
  1113. end
  1114. for i = 1, allBuffCnt do
  1115. if i <= randBuffCnt then
  1116. local r = math.random(i, allBuffCnt)
  1117. ret[i],ret[r] = ret[r],ret[i]
  1118. else
  1119. ret[i] = nil
  1120. end
  1121. end
  1122. return ret
  1123. else
  1124. return skillConfig.buffers
  1125. end
  1126. end
  1127. function onUseBeSkill(attacker,skillConfig,objs,cmdTargets, arg)--attacker是被动技能释放者,objs是attacker的对立方(attacker是攻击者的话,objs是被攻击者,attacker是被攻击者的话,objs是攻击者),cmdTargets是额外作用对象
  1128. -- 使用被动技能时,需要特殊处理遗物的args和otherArgs
  1129. local winnerID = attacker and attacker.relic and attacker.relic.relicID or 0
  1130. local winnerStar = attacker and attacker.relic and attacker.relic.star or 0
  1131. local buffers,bufferArg = getBeskillBuffers(attacker,skillConfig)
  1132. if not buffers then
  1133. -- print("[onUseBeSkill] 获取不到配置直接返回 id = "..skillConfig[1])
  1134. return
  1135. end
  1136. bufferArg = bufferArg or arg
  1137. local isAddSkillFrame
  1138. local bufferArg1
  1139. for i = 1, #buffers do
  1140. local bufferID = buffers[i][1]
  1141. --local bufferConf = BufferExcel.buffer[bufferID]
  1142. local bufferConf = GetBuffConfig(bufferID)
  1143. local targetMode = buffers[i][2]
  1144. local targets
  1145. bufferArg1 = nil
  1146. if targetMode[1] == 13 then
  1147. targets = objs
  1148. else
  1149. targets = TargetMode.getTargets(attacker, targetMode,objs,cmdTargets)
  1150. end
  1151. if #targets > 0 then
  1152. if bufferConf.cmd == "zuzhou" then
  1153. local rate = bufferConf.args[2] + BeSkill.getBufferExtraHurt(attacker,bufferID)
  1154. bufferArg1 = {CombatCalc.calcHp(attacker,targets[1],bufferConf.args[1],rate)}
  1155. end
  1156. local attackPos = attacker.pos
  1157. if bufferConf.roundOne == 1 and objs and objs[1] then
  1158. attackPos = objs[1].pos
  1159. end
  1160. for _,target in ipairs(targets) do
  1161. if canAdd(target,bufferID,buffers[i][3], attacker, skillConfig) then
  1162. isAddSkillFrame = true
  1163. addBuffer(attackPos,target, bufferID,skillConfig.id,bufferArg1 or bufferArg)
  1164. end
  1165. end
  1166. end
  1167. end
  1168. -- if skillConfig.cmd == "winnerRelicSkill" then
  1169. -- if skillConfig and skillConfig.otherArgs.selefDefense then
  1170. -- if attacker then
  1171. -- print("[onUseBeSkill] winnerRelicSkill 进入 1")
  1172. -- attacker.attr[RoleDefine.DEF] = 0
  1173. -- end
  1174. -- elseif skillConfig and skillConfig.otherArgs.jobDefense then
  1175. -- if isJob(attacker, {CombatDefine.JOB_TYPE4, CombatDefine.JOB_TYPE1}) then
  1176. -- if winnerID > 0 and winnerStar > 0 then
  1177. -- print("[onUseBeSkill] winnerRelicSkill 进入 2")
  1178. -- local extraRate = WinnerRelicLogic.WinnerRelic_GetRateAttack(winnerID, winnerStar)
  1179. -- attacker.attr[RoleDefine.DEF] = attacker.attr[RoleDefine.DEF] + extraRate
  1180. -- print("当前防御提升量为:",extraRate)
  1181. -- end
  1182. -- end
  1183. -- elseif skillConfig and skillConfig.otherArgs.jobMianshang then
  1184. -- if isJob(attacker, {CombatDefine.JOB_TYPE1}) then
  1185. -- print("[onUseBeSkill] winnerRelicSkill 进入 3")
  1186. -- local extraRate = WinnerRelicLogic.WinnerRelic_GetRateDef(winnerID, winnerStar)
  1187. -- attacker.attr[RoleDefine.JIANSHANG_RATE] = attacker.attr[RoleDefine.JIANSHANG_RATE] *(1 + extraRate/100)
  1188. -- print("当前护卫免伤量提升量为:",extraRate)
  1189. -- end
  1190. -- elseif skillConfig and skillConfig.otherArgs.racialAtk then
  1191. -- if isCamp(attacker, {CombatDefine.COMBAT_TYPE27}) then
  1192. -- print("[onUseBeSkill] winnerRelicSkill 进入 4")
  1193. -- local extraRate = WinnerRelicLogic.WinnerRelic_GetRateAttack(winnerID, winnerStar)
  1194. -- attacker.attr[RoleDefine.ATK] = attacker.attr[RoleDefine.ATK] *(1+ extraRate/100)
  1195. -- end
  1196. -- elseif skillConfig and skillConfig.otherArgs.jobZhiliao then
  1197. -- if isJob(attacker, {CombatDefine.JOB_TYPE4}) then
  1198. -- print("[onUseBeSkill] winnerRelicSkill 进入 5")
  1199. -- local extraRate = WinnerRelicLogic.WinnerRelic_GetRateAttack(winnerID, winnerStar)
  1200. -- attacker.attr[RoleDefine.HP_ADD_RATE] = attacker.attr[RoleDefine.HP_ADD_RATE] *(1 + extraRate/100)
  1201. -- end
  1202. -- end
  1203. -- end
  1204. return isAddSkillFrame
  1205. end
  1206. --战斗回合结束时处理buffer效果。删除失效buffer
  1207. --只执行一次的cmd,比如持续加血。
  1208. HANDLER_ONCE = HANDLER_ONCE or {}
  1209. function onRoundEnd(attacker,isRoundEnd)
  1210. --处理施法者身上的buff
  1211. for i = 1,CombatDefine.COMBAT_HERO_ALL_CNT do
  1212. local obj = CombatImpl.objList[i]
  1213. if obj then
  1214. for k,v in pairs(HANDLER_ONCE) do
  1215. HANDLER_ONCE[k] = nil
  1216. end
  1217. delayBegin()
  1218. for j = obj.buffer[0], 1, -1 do
  1219. local buffer = obj.buffer[j]
  1220. --local conf = BufferExcel.buffer[buffer.id]
  1221. local conf = GetBuffConfig(buffer.id)
  1222. if conf.type == CombatDefine.BUFFER_TYPE1 or isRoundEnd then
  1223. buffer.attrs = {}
  1224. local setFrame = false
  1225. if conf.type ~= CombatDefine.BUFFER_TYPE4 and handler[conf.cmd] then
  1226. if obj.hp > 0 or conf.cmd == "totem" then
  1227. if conf.cmd == "zuzhou" then
  1228. -- 最后一回合生效
  1229. if buffer.round == 1 then
  1230. handler[conf.cmd](obj, buffer,conf)
  1231. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_HOLD)
  1232. end
  1233. else
  1234. handler[conf.cmd](obj, buffer,conf)
  1235. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_HOLD)
  1236. end
  1237. end
  1238. end
  1239. if buffer.round then
  1240. local cmd = conf.cmd
  1241. buffer.round = buffer.round - 1
  1242. if buffer.round < 1 then
  1243. local bufferCnt = delBuffer(obj, j)
  1244. if (conf.type ~= CombatDefine.BUFFER_TYPE1 and obj.hp > 0) or conf.cmd == "fixPos" or conf.holdOnDie == 1 then
  1245. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_DEL)
  1246. end
  1247. end
  1248. end
  1249. end
  1250. end
  1251. if isRoundEnd and obj.delayAddBuffer then
  1252. --{delayRound,attacker.pos,bufferID,skillConfig.id,arg}
  1253. for k,v in ipairs(obj.delayAddBuffer) do
  1254. v[1] = v[1] - 1
  1255. end
  1256. local temp = {}
  1257. for i = 1,#obj.delayAddBuffer do
  1258. local data = obj.delayAddBuffer[i]
  1259. if data[1] > 0 then
  1260. temp[#temp + 1] = data
  1261. else
  1262. addBuffer(data[2],obj,data[3],data[4],data[5])
  1263. end
  1264. end
  1265. if #temp > 0 then
  1266. obj.delayAddBuffer = temp
  1267. else
  1268. obj.delayAddBuffer = nil
  1269. end
  1270. end
  1271. delayEnd()
  1272. end
  1273. end
  1274. for k,v in pairs(HANDLER_ONCE) do
  1275. HANDLER_ONCE[k] = nil
  1276. end
  1277. end
  1278. --攻击结束后,反击前,整合buffer前处理buffer效果
  1279. function beforeFanji()
  1280. local isFanshe = false
  1281. for i = 1,CombatDefine.COMBAT_HERO_ALL_CNT do
  1282. local obj = CombatImpl.objList[i]
  1283. if obj then
  1284. for k,v in pairs(obj.combatResult[3]) do
  1285. if k ~= i and v[1] and v[1] < 0 then
  1286. local target = CombatImpl.objList[k]
  1287. if target and target.hp > 0 then
  1288. local d = CombatObj.updateHp(target, v[1], nil, nil, obj.pos,CombatObj.BUFFER_HP_TYPE)
  1289. CombatImpl.setExtraHit(target,d)
  1290. CombatObj.onHpCB(target,d, obj.pos)
  1291. isFanshe = true
  1292. end
  1293. end
  1294. end
  1295. if isFanshe then
  1296. delBufferByCmd(obj,"fansheZhuangjia",1)
  1297. end
  1298. end
  1299. end
  1300. end
  1301. function getExtraHurtRate(attacker,target,skillConfig)
  1302. local skillID = skillConfig.id
  1303. local isBaoji = target.isBaoji
  1304. local baojiHurtRate = 0
  1305. local guanxinzheHurtRate = 0
  1306. local huiheHurtRate = 0
  1307. local shandianHurtRate = 0
  1308. local attackerHurtRat = 0
  1309. local biaoshiHurtRate = 0
  1310. local biaoshiCnt = 0
  1311. local moweiHurtRate = 0
  1312. local biaoshiCntLimit
  1313. local zhanyiHurtRate = 0
  1314. local chenshuiHurtRate = 0
  1315. if skillConfig.otherArgs.biaoshiHurtRate then
  1316. biaoshiCntLimit = skillConfig.otherArgs.biaoshiHurtRate[1]
  1317. end
  1318. for j = target.buffer[0], 1, -1 do
  1319. local obj = target
  1320. local buffer = obj.buffer[j]
  1321. --local conf = BufferExcel.buffer[buffer.id]
  1322. local conf = GetBuffConfig(buffer.id)
  1323. if conf.cmd == "guanxinzheYinji" then --观星者印记
  1324. guanxinzheHurtRate = guanxinzheHurtRate + conf.args[2]
  1325. elseif conf.cmd == "shandianYinji" then --闪电印记
  1326. for _,v in ipairs(conf.args[2]) do
  1327. if skillID == v then
  1328. shandianHurtRate = shandianHurtRate + conf.args[3]
  1329. break
  1330. end
  1331. end
  1332. elseif conf.cmd == "biaoshi" then
  1333. biaoshiCnt = biaoshiCnt + 1
  1334. elseif conf.cmd == "chenshui" then
  1335. chenshuiHurtRate = chenshuiHurtRate + 3000
  1336. end
  1337. end
  1338. --攻击者
  1339. for j = attacker.buffer[0], 1, -1 do
  1340. local obj = attacker
  1341. local buffer = obj.buffer[j]
  1342. --local conf = BufferExcel.buffer[buffer.id]
  1343. local conf = GetBuffConfig(buffer.id)
  1344. if conf.cmd == "mowei" then --魔威
  1345. local nowHp = attacker.hp
  1346. local hpMax = CombatObj.getHpMax(attacker)
  1347. local percent = math.floor( (hpMax - nowHp )/hpMax * 100)
  1348. if percent >= 1 then
  1349. --moweiHurtRate = moweiHurtRate + (percent * conf.args[1])
  1350. moweiHurtRate = percent * conf.args[1]
  1351. break
  1352. end
  1353. elseif conf.cmd == "zhanyi" then
  1354. local nowHp = attacker.hp
  1355. local hpMax = CombatObj.getHpMax(attacker)
  1356. local percent = math.floor( (hpMax - nowHp )/hpMax * 100)
  1357. if percent >= 1 then
  1358. local args = conf.args
  1359. percent = percent / (args[1] / 100)
  1360. zhanyiHurtRate = percent * args[2]
  1361. break
  1362. end
  1363. end
  1364. end
  1365. guanxinzheHurtRate = guanxinzheHurtRate > 30000 and 30000 or guanxinzheHurtRate --300%限制
  1366. if biaoshiCntLimit and biaoshiCnt >= biaoshiCntLimit then
  1367. biaoshiHurtRate = skillConfig.otherArgs.biaoshiHurtRate[2]
  1368. end
  1369. local extraHurtRate = baojiHurtRate + guanxinzheHurtRate + huiheHurtRate + shandianHurtRate
  1370. + attackerHurtRat + biaoshiHurtRate + moweiHurtRate + zhanyiHurtRate + chenshuiHurtRate
  1371. return extraHurtRate
  1372. end
  1373. function getExtraHurt(attacker, target, skillConfig)
  1374. local extraHurt = 0
  1375. for j = target.buffer[0], 1, -1 do
  1376. local obj = target
  1377. local buffer = obj.buffer[j]
  1378. --local conf = BufferExcel.buffer[buffer.id]
  1379. local conf = GetBuffConfig(buffer.id)
  1380. if conf.cmd == "shenhuo" then
  1381. local hurt = CombatCalc.calcHp(attacker, target, conf.args[1], conf.args[2], true)
  1382. extraHurt = extraHurt + hurt
  1383. end
  1384. end
  1385. return extraHurt
  1386. end
  1387. --处理器
  1388. local function chixuHurtDel(target,buffer)
  1389. local hurt = buffer.arg
  1390. local hurtDelRate = target.attr[RoleDefine.CHIXU_HURT_DEL_RATE] / 10000
  1391. --持续类buff 伤害加成
  1392. local attacker = CombatImpl.objList[buffer.attackPos]
  1393. --local conf = BufferExcel.buffer[buffer.id]
  1394. local conf = GetBuffConfig(buffer.id)
  1395. local beSkillHurtRate = BeSkill.getBuffChixuHurt(attacker, conf.cmd)
  1396. hurtDelRate = hurtDelRate > 1 and 1 or hurtDelRate
  1397. if hurtDelRate > 0 or beSkillHurtRate > 0 then
  1398. hurt = hurt * (1 - hurtDelRate + beSkillHurtRate)
  1399. end
  1400. return hurt
  1401. end
  1402. --处理器, 实时计算伤害
  1403. local function chixuHurtDel2(target,buffer)
  1404. local id = buffer.id
  1405. --local conf = BufferExcel.buffer[id]
  1406. local conf = GetBuffConfig(buffer.id)
  1407. local attackPos = buffer.attackPos
  1408. local attacker
  1409. if attackPos > CombatDefine.COMBAT_HERO_ALL_CNT then
  1410. attacker = CombatImpl.helpList[attackPos]
  1411. else
  1412. attacker = CombatImpl.objList[attackPos]
  1413. end
  1414. local isAddHp = conf.cmd == "hp"
  1415. buffer.arg = CombatCalc.calcBufferHp(attacker,target,id,isAddHp)
  1416. local hurt = buffer.arg
  1417. local hurtDelRate = target.attr[RoleDefine.CHIXU_HURT_DEL_RATE] / 10000
  1418. --持续类buff 伤害加成
  1419. -- local attacker = CombatImpl.objList[buffer.attackPos]
  1420. -- local conf = BufferExcel.buffer[buffer.id]
  1421. local beSkillHurtRate = BeSkill.getBuffChixuHurt(attacker, conf.cmd)
  1422. hurtDelRate = hurtDelRate > 1 and 1 or hurtDelRate
  1423. if hurtDelRate > 0 or beSkillHurtRate > 0 then
  1424. hurt = hurt * (1 - hurtDelRate + beSkillHurtRate)
  1425. end
  1426. return hurt
  1427. end
  1428. handler = {}
  1429. --持续伤害
  1430. function handler.hurt(target, buffer,conf)
  1431. local hurt = chixuHurtDel(target,buffer)
  1432. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1433. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1434. end
  1435. --燃烧
  1436. function handler.hurt1(target, buffer,conf)
  1437. local hurt = chixuHurtDel(target,buffer)
  1438. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1439. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1440. onExtraCombatRecord(buffer.attackPos,hurt,"ranshao")
  1441. -- 删除attr1 buffer
  1442. local attacker = CombatImpl.objList[buffer.attackPos]
  1443. if attacker and attacker.bufferCmd["attr1"] then
  1444. for i = #attacker.bufferCmd["attr1"],1,-1 do
  1445. local ind = attacker.bufferCmd["attr1"][i]
  1446. local buff = attacker.buffer[ind]
  1447. --local conf = BufferExcel.buffer[buff.id]
  1448. local conf = GetBuffConfig(buffer.id)
  1449. local bufferCnt = delBuffer(attacker, ind)
  1450. CombatImpl.addFrameBuffer(attacker, buff, CombatDefine.BUFFER_OP_DEL)
  1451. end
  1452. end
  1453. end
  1454. --持续治疗
  1455. function handler.hp(target, buffer,conf)
  1456. if target.bufferCmd["noHp"] then
  1457. return
  1458. end
  1459. if HANDLER_ONCE["hp"] == target.pos then
  1460. return
  1461. end
  1462. local hp = buffer.arg
  1463. local attacker = CombatImpl.objList[buffer.attackPos]
  1464. if attacker and attacker.attr[RoleDefine.ZAOCHENG_HP_ADD_RATE] then
  1465. local hpAddRate = attacker.attr[RoleDefine.ZAOCHENG_HP_ADD_RATE] / 10000
  1466. hp = hp * (1 + hpAddRate)
  1467. end
  1468. local calcType = conf and conf.args[1] or 0
  1469. if CombatCalc.NO_EXCALC_LIST[calcType] and target.attr[RoleDefine.HP_ADD_RATE] then
  1470. local hpAddRate = target.attr[RoleDefine.HP_ADD_RATE] / 10000
  1471. hp = hp * (1 + hpAddRate)
  1472. end
  1473. hp = hp < 0 and 1 or hp
  1474. if target.side == CombatDefine.DEFEND_SIDE then
  1475. hp = CombatImpl.commonArgs.hpLimit or hp
  1476. end
  1477. local d = CombatObj.updateHp(target, hp, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1478. buffer.attrs[RoleDefine.HP_COMBAT] = hp
  1479. HANDLER_ONCE["hp"] = target.pos
  1480. end
  1481. --流血
  1482. function handler.liuxue(target, buffer,conf)
  1483. local hurt = chixuHurtDel(target,buffer)
  1484. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1485. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1486. onExtraCombatRecord(buffer.attackPos,hurt,"liuxue")
  1487. end
  1488. --流血2
  1489. function handler.liuxue2(target, buffer,conf)
  1490. local hurt = chixuHurtDel2(target,buffer)
  1491. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1492. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1493. onExtraCombatRecord(buffer.attackPos,hurt,"liuxue")
  1494. end
  1495. --中毒
  1496. function handler.zhongdu(target, buffer,conf)
  1497. local hurt = chixuHurtDel(target,buffer)
  1498. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1499. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1500. onExtraCombatRecord(buffer.attackPos,hurt,"zhongdu")
  1501. end
  1502. --燃烧
  1503. function handler.ranshao(target, buffer,conf)
  1504. local hurt = chixuHurtDel(target,buffer)
  1505. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1506. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1507. onExtraCombatRecord(buffer.attackPos,hurt,"ranshao")
  1508. end
  1509. --燃烧
  1510. function handler.ranshao1(target, buffer,conf)
  1511. local hurt = chixuHurtDel(target,buffer)
  1512. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1513. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1514. onExtraCombatRecord(buffer.attackPos,hurt,"ranshao")
  1515. end
  1516. --回合印记
  1517. function handler.huiheYinji(target, buffer,conf)
  1518. if buffer.round > 1 then return end --最后一回合才生效
  1519. local hurt = chixuHurtDel(target,buffer)
  1520. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1521. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1522. end
  1523. --种子
  1524. function handler.zhongzi(target, buffer, conf)
  1525. if buffer.round > 1 then return end --最后一回合才生效
  1526. local cnt = #conf.args
  1527. for i= 1, cnt do
  1528. local bufferID = conf.args[i]
  1529. if canAdd(target,bufferID) then
  1530. addBuffer(buffer.attackPos, target, bufferID)
  1531. end
  1532. end
  1533. end
  1534. --buffer包处理器
  1535. --偷取护甲
  1536. function handler.touquhujia(attacker,target,conf)
  1537. local arg = conf.args[1]/10000
  1538. local targetBufferID = conf.args[2]
  1539. local attackerBufferID = conf.args[3]
  1540. local def = CombatObj.getValue(target,RoleDefine.DEF)
  1541. --local rate = CombatObj.getValue(target,RoleDefine.DEF_RATE)/10000
  1542. --def = def * (1 + rate)
  1543. def = def > 0 and def or 0
  1544. local arg = def * arg
  1545. if arg > 0 then
  1546. if canAdd(attacker,attackerBufferID) then
  1547. addBuffer(target.pos,attacker, attackerBufferID,nil,arg,conf)
  1548. end
  1549. if canAdd(target,targetBufferID) then
  1550. addBuffer(attacker.pos,target, targetBufferID,nil,-arg,conf)
  1551. end
  1552. end
  1553. end
  1554. --偷取攻击
  1555. function handler.touqugongji(attacker,target,conf)
  1556. local arg = conf.args[1]/10000
  1557. local targetBufferID = conf.args[2]
  1558. local attackerBufferID = conf.args[3]
  1559. local atk = CombatObj.getValue(target,RoleDefine.ATK)
  1560. --local rate = CombatObj.getValue(target,RoleDefine.ATK_RATE)/10000
  1561. --def = def * (1 + rate)
  1562. atk = atk > 0 and atk or 0
  1563. local arg = atk * arg
  1564. if arg > 0 then
  1565. if canAdd(attacker,attackerBufferID) then
  1566. addBuffer(target.pos,attacker, attackerBufferID,nil,arg,conf)
  1567. end
  1568. if canAdd(target,targetBufferID) then
  1569. addBuffer(attacker.pos,target, targetBufferID,nil,-arg,conf)
  1570. end
  1571. end
  1572. end
  1573. function handler.totem(obj,buffer,conf)
  1574. --图腾逻辑
  1575. local buffers = conf.args
  1576. for i = 1, #buffers do
  1577. local bufferID = buffers[i][1]
  1578. if type(bufferID) == "table" then
  1579. local r = math.random(1,#bufferID)
  1580. bufferID = bufferID[r]
  1581. end
  1582. local targetMode = buffers[i][2]
  1583. local random = buffers[i][3]
  1584. local targets = TargetMode.getTargets(obj, targetMode,{})
  1585. if #targets > 0 then
  1586. for _,target in ipairs(targets) do
  1587. if canAdd(target,bufferID,random) then
  1588. addBuffer(obj.pos,target, bufferID)
  1589. end
  1590. end
  1591. end
  1592. end
  1593. end
  1594. function handler.groupbuffer(attacker,target,conf)
  1595. for _,bufferID in ipairs(conf.args) do
  1596. if canAdd(target,bufferID) then
  1597. addBuffer(attacker.pos,target, bufferID,nil,nil,conf)
  1598. end
  1599. end
  1600. end
  1601. function handler.zuzhou(target,buffer,conf)
  1602. local hurt = buffer.arg[1]
  1603. local attacker = CombatImpl.objList[buffer.attackPos]
  1604. -- 二次元结算方式调整成
  1605. if BeSkill.getRandomBuffCmd(attacker, target, conf.cmd) and target.bufferCmd[conf.cmd] then
  1606. hurt = hurt * #target.bufferCmd[conf.cmd]
  1607. end
  1608. local beSkillHurtRate = BeSkill.getBuffChixuHurt(attacker, conf.cmd)
  1609. hurt = hurt * (1 + beSkillHurtRate)
  1610. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1611. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1612. BeSkill.handlerBuff(attacker, target, hurt, conf.cmd)
  1613. end
  1614. function yinbaoZuzhou(obj, skillTargets, skillConfig)
  1615. local newFrame = nil
  1616. for k,v in ipairs(skillTargets) do
  1617. if v.bufferCmd["zuzhou"] then
  1618. for i = #v.bufferCmd["zuzhou"],1,-1 do
  1619. local ind = v.bufferCmd["zuzhou"][i]
  1620. local buffer = v.buffer[ind]
  1621. --local conf = BufferExcel.buffer[buffer.id]
  1622. local conf = GetBuffConfig(buffer.id)
  1623. if conf and handler[conf.cmd] then
  1624. handler[conf.cmd](v, buffer, conf)
  1625. CombatImpl.addFrameBuffer(v,buffer,CombatDefine.BUFFER_OP_HOLD)
  1626. end
  1627. local bufferCnt = delBuffer(v, ind)
  1628. CombatImpl.addFrameBuffer(v,buffer,CombatDefine.BUFFER_OP_DEL)
  1629. newFrame = true
  1630. end
  1631. end
  1632. end
  1633. -- 有引爆成功的
  1634. if newFrame and ProjectLogic.isSsecy() then
  1635. CombatImpl.addFrame()
  1636. end
  1637. end
  1638. --主动技能释放后buff作用
  1639. handlerEx = {}
  1640. --印记
  1641. function handlerEx.yinJi(target, buffer, conf)
  1642. local attacker = CombatImpl.objList[buffer.attackPos]
  1643. if attacker == nil then
  1644. return
  1645. end
  1646. local hurtRate = conf.args[1]
  1647. local hurtRateMax = conf.args[2]
  1648. local hpMax = CombatObj.getHpMax(target)
  1649. local hurt = hurtRate * hpMax / 10000
  1650. local atk = CombatObj.getValue(attacker,RoleDefine.ATK) * hurtRateMax / 10000
  1651. if hurt > atk then
  1652. hurt = atk
  1653. end
  1654. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1655. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1656. return true
  1657. end
  1658. function qingsuan(target)
  1659. if target.hp <= 0 then
  1660. return 0
  1661. end
  1662. local baseValue = 0
  1663. local round
  1664. for j = target.buffer[0], 1, -1 do
  1665. local buffer = target.buffer[j]
  1666. --local conf = BufferExcel.buffer[buffer.id]
  1667. local conf = GetBuffConfig(buffer.id)
  1668. local cmd = conf.cmd
  1669. if cmd == "ranshao" or cmd == "ranshao1" or cmd == "liuxue"or cmd == "liuxue2" or cmd == "zhongdu" or cmd == "hurt" or cmd == "hurt1" then
  1670. round = 1
  1671. if buffer.round and buffer.round > 0 then
  1672. round = buffer.round
  1673. end
  1674. baseValue = baseValue + buffer.arg * round
  1675. local bufferCnt = delBuffer(target, j)
  1676. CombatImpl.addFrameBuffer(target,buffer,CombatDefine.BUFFER_OP_DEL)
  1677. end
  1678. end
  1679. return baseValue
  1680. end
  1681. --解控
  1682. function jiekong(target)
  1683. if target.hp <= 0 then
  1684. return 0
  1685. end
  1686. local baseValue = 0
  1687. local state = false
  1688. for j = target.buffer[0], 1, -1 do
  1689. local buffer = target.buffer[j]
  1690. --local conf = BufferExcel.buffer[buffer.id]
  1691. local conf = GetBuffConfig(buffer.id)
  1692. local cmd = conf.cmd
  1693. if isControlCmd(cmd) then
  1694. local bufferCnt = delBuffer(target, j)
  1695. CombatImpl.addFrameBuffer(target,buffer,CombatDefine.BUFFER_OP_DEL)
  1696. state = true
  1697. end
  1698. end
  1699. if state == true then
  1700. CombatImpl.setExtraHit(target,nil, Skill.getCMD2ID("jiekong"))
  1701. end
  1702. end
  1703. --杀意
  1704. function delShayi(target)
  1705. if target.hp <= 0 then
  1706. return 0
  1707. end
  1708. for j = target.buffer[0], 1, -1 do
  1709. local buffer = target.buffer[j]
  1710. --local conf = BufferExcel.buffer[buffer.id]
  1711. local conf = GetBuffConfig(buffer.id)
  1712. local cmd = conf.cmd
  1713. if cmd == "shayi" then
  1714. local bufferCnt = delBuffer(target, j)
  1715. CombatImpl.addFrameBuffer(target,buffer,CombatDefine.BUFFER_OP_DEL)
  1716. end
  1717. end
  1718. end
  1719. function getBuffCnt(target,checkCmd)
  1720. if target.hp <= 0 then
  1721. return 0
  1722. end
  1723. local cnt = 0
  1724. for j = target.buffer[0], 1, -1 do
  1725. local buffer = target.buffer[j]
  1726. --local conf = BufferExcel.buffer[buffer.id]
  1727. local conf = GetBuffConfig(buffer.id)
  1728. local cmd = conf.cmd
  1729. if cmd == checkCmd then
  1730. cnt = cnt + 1
  1731. end
  1732. end
  1733. return cnt
  1734. end
  1735. -- 获取护盾值
  1736. function getBuffHuDun(obj)
  1737. if obj and obj.bufferAttr and obj.bufferAttr[RoleDefine.HUDUN_COMBAT] then
  1738. return obj.bufferAttr[RoleDefine.HUDUN_COMBAT]
  1739. end
  1740. return 0
  1741. end
  1742. -- 护盾值的修改
  1743. function updateHuDun(obj, value)
  1744. if obj and obj.bufferAttr then
  1745. local oldValue = obj.bufferAttr[RoleDefine.HUDUN_COMBAT] or 0
  1746. local newValue = oldValue + value
  1747. if newValue <= 0 then
  1748. obj.bufferAttr[RoleDefine.HUDUN_COMBAT] = 0
  1749. delBufferByCmd(obj,"hudun", 0)
  1750. else
  1751. obj.bufferAttr[RoleDefine.HUDUN_COMBAT] = newValue
  1752. end
  1753. -- 护盾值没有全部去除 则 在对应英雄上吧 BUF 上的arg 数值 减除 防止 BufChange 重置 属性
  1754. if value < 0 and newValue > 0 then
  1755. if obj and obj.buffer then
  1756. for j = 1 , obj.buffer[0] do -- 从最早的护盾BUF中删除arg
  1757. local buffer = obj.buffer[j]
  1758. --local conf = BufferExcel.buffer[buffer.id]
  1759. local conf = GetBuffConfig(buffer.id)
  1760. local bufferCmd = conf.cmd
  1761. if bufferCmd == "hudun" then
  1762. local have = buffer.arg
  1763. if have > -value then
  1764. buffer.arg = have + value
  1765. else
  1766. buffer.arg = 0
  1767. local bufferCnt = delBuffer(obj, j)
  1768. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_DEL)
  1769. break
  1770. end
  1771. end
  1772. end
  1773. end
  1774. end
  1775. end
  1776. end
  1777. BUFFER_COMBAT_TYPE = nil
  1778. function initCombatBufferType()
  1779. if BUFFER_COMBAT_TYPE then return end
  1780. BUFFER_COMBAT_TYPE = {}
  1781. for k,conf in pairs(BufferExcel.qusan) do
  1782. if conf then
  1783. BUFFER_COMBAT_TYPE[conf.buffcmd] = conf.type
  1784. end
  1785. end
  1786. end
  1787. --
  1788. function getCombatBufferCnt(target, qusanType)
  1789. initCombatBufferType()
  1790. local buffCnt = 0
  1791. for i = target.buffer[0], 1, -1 do
  1792. local buffer = target.buffer[i]
  1793. --local conf = BufferExcel.buffer[buffer.id]
  1794. local conf = GetBuffConfig(buffer.id)
  1795. local cmd = conf.cmd
  1796. if conf.skillbufftype == 1 and BUFFER_COMBAT_TYPE[cmd] and BUFFER_COMBAT_TYPE[cmd] == qusanType then
  1797. buffCnt = buffCnt + 1
  1798. end
  1799. end
  1800. return buffCnt
  1801. end
  1802. --抵抗
  1803. QUSAN_CMD2KEY = {
  1804. ["zuzhou"] = RoleDefine.STATUS_DIKANG_RATE9,
  1805. }
  1806. function qusan(target, qusanType,cnt)
  1807. if target.isPet or not qusanType then
  1808. return 0
  1809. end
  1810. initCombatBufferType()
  1811. local state = false
  1812. local delIndex = {}
  1813. for i = target.buffer[0], 1, -1 do
  1814. local buffer = target.buffer[i]
  1815. --local conf = BufferExcel.buffer[buffer.id]
  1816. local conf = GetBuffConfig(buffer.id)
  1817. local cmd = conf.cmd
  1818. if conf.noQusan ~= 1 then
  1819. if BUFFER_COMBAT_TYPE[cmd] and BUFFER_COMBAT_TYPE[cmd] == qusanType then
  1820. local isDiKang = nil
  1821. local key = QUSAN_CMD2KEY[cmd]
  1822. local r = math.random(1,10000)
  1823. if key and target.attr[key] >= r then
  1824. isDiKang = true
  1825. end
  1826. if not isDiKang then
  1827. delIndex[#delIndex + 1] = i
  1828. end
  1829. elseif cmd == "attr" or cmd == "attrdne" then
  1830. if conf.args and conf.args[1][2] < 0 and qusanType == 1 then
  1831. delIndex[#delIndex + 1] = i
  1832. elseif conf.args and conf.args[1][2] > 0 and qusanType == 2 then
  1833. delIndex[#delIndex + 1] = i
  1834. end
  1835. end
  1836. end
  1837. end
  1838. cnt = cnt or 0
  1839. if cnt > 0 and cnt < #delIndex then
  1840. for i = cnt + 1,#delIndex do
  1841. delIndex[i] = nil
  1842. end
  1843. end
  1844. for k,v in ipairs(delIndex) do
  1845. local buffer = target.buffer[v]
  1846. if not buffer then break end
  1847. local bufferCnt = delBuffer(target, v)
  1848. CombatImpl.addFrameBuffer(target,buffer,CombatDefine.BUFFER_OP_DEL)
  1849. end
  1850. return #delIndex
  1851. end
  1852. function qusanAddBuff(attacker, targets, bufferID)
  1853. for _,target in ipairs(targets) do
  1854. if canAdd(target,bufferID) then
  1855. addBuffer(attacker.pos, target, bufferID)
  1856. end
  1857. end
  1858. end
  1859. function beforeUpdateHp(obj,sum)
  1860. local isStatus,cmd,ind = isStatus(obj,{"miansi","waitMiansi"})
  1861. if not isStatus then
  1862. return
  1863. end
  1864. --免死逻辑
  1865. if cmd == "miansi" then
  1866. return true
  1867. end
  1868. if sum == 0 and cmd == "waitMiansi" then
  1869. local buffer = obj.buffer[ind]
  1870. local bufferCnt = delBuffer(obj, ind)
  1871. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_DEL)
  1872. --local conf = BufferExcel.buffer[buffer.id]
  1873. local conf = GetBuffConfig(buffer.id)
  1874. local bufferID = conf.args[1]
  1875. if canAdd(obj,bufferID) then
  1876. addBuffer(obj.pos,obj, bufferID)
  1877. end
  1878. return true
  1879. end
  1880. end
  1881. function checkBaohu(obj,value)
  1882. local isStatus,cmd,ind = isStatus(obj,{"baohu"})
  1883. if not isStatus then
  1884. return value
  1885. end
  1886. local buffer = obj.buffer[ind]
  1887. local attackPos = buffer.attackPos
  1888. local attacker = CombatImpl.objList[attackPos]
  1889. if attacker.hp <= 0 then
  1890. return value
  1891. end
  1892. value = BeSkill.onCheckBuffer(attacker,obj,value)
  1893. return value
  1894. end
  1895. function onExtraCombatRecord(pos,value,param)
  1896. local obj = CombatObj.getObjByPos(pos)
  1897. if not obj then return end
  1898. obj.extraCombatRecord = obj.extraCombatRecord or {}
  1899. if param == "zhongdu" then
  1900. obj.extraCombatRecord.zhongdu = (obj.extraCombatRecord.zhongdu or 0) + value
  1901. elseif param == "liuxue" then
  1902. obj.extraCombatRecord.liuxue = (obj.extraCombatRecord.liuxue or 0) + value
  1903. elseif param == "ranshao" then
  1904. obj.extraCombatRecord.ranshao = (obj.extraCombatRecord.ranshao or 0) + value
  1905. elseif param == "xuanyun" or param == "xuanyun2" then
  1906. obj.extraCombatRecord.xuanyun = (obj.extraCombatRecord.xuanyun or 0) + value
  1907. elseif param == "revive" then
  1908. obj.extraCombatRecord.revive = (obj.extraCombatRecord.revive or 0) + value
  1909. elseif param == "reviveBeUse" then
  1910. obj.extraCombatRecord.reviveBeUse = (obj.extraCombatRecord.reviveBeUse or 0) + value
  1911. elseif param == "kill" then
  1912. obj.extraCombatRecord.kill = (obj.extraCombatRecord.kill or 0) + value
  1913. elseif param == "chenshui" then
  1914. obj.extraCombatRecord.kchenshuiill = (obj.extraCombatRecord.chenshui or 0) + value
  1915. end
  1916. end