CombatBuff.lua 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153
  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. CombatImpl.InsertAttackOrder(obj.pos)
  656. end
  657. function addBuffer(attackPos,obj, id, skillID,arg,parentConf)
  658. -- local conf = BufferExcel.buffer[id]
  659. local conf = GetBuffConfig(id)
  660. local bufferCmd = conf.cmd
  661. if DELAY_BUFF_OP then
  662. if not NO_DELAY_BUFFCMD[bufferCmd] then
  663. DELAY_LIST.add[#DELAY_LIST.add + 1] = {attackPos,obj, id, skillID,arg,parentConf}
  664. end
  665. return
  666. end
  667. if checkRevive(attackPos,obj, id, skillID) then
  668. return
  669. end
  670. if beforeAddBuffer(attackPos,obj, id, skillID,arg,parentConf) then
  671. return
  672. end
  673. local bufferCnt = 1
  674. local buffer
  675. local bufferCmdInd
  676. local bufferInd
  677. local tround = 0
  678. local index = 0
  679. local groupCnt = 0
  680. local group = conf.group[1]
  681. for i = 1, obj.buffer[0] do
  682. buffer = obj.buffer[i]
  683. if buffer.id == id then
  684. bufferCnt = bufferCnt + 1
  685. bufferInd = i
  686. if tround > buffer.round or tround == 0 then
  687. tround = buffer.round
  688. index = i
  689. end
  690. end
  691. --local nowBuffConf = BufferExcel.buffer[buffer.id]
  692. local nowBuffConf = GetBuffConfig(buffer.id)
  693. if nowBuffConf.cmd == bufferCmd then
  694. bufferCmdInd = i
  695. end
  696. if group and group == nowBuffConf.group[1] then
  697. groupCnt = groupCnt + 1
  698. end
  699. end
  700. local groupCmd = conf.group[2]
  701. if groupCmd and groupCnt > 0 and groupCnt >= groupCmd then
  702. return
  703. end
  704. if bufferCnt > 100 then
  705. return
  706. end
  707. local canAppend = parentConf and parentConf.canAppend or conf.canAppend
  708. local round = parentConf and parentConf.round or conf.round
  709. round = round == 0 and 1 or round
  710. if canAppend == 1 then
  711. local appendCnt = conf.appendCnt or 0
  712. if appendCnt > 0 and bufferCnt > conf.appendCnt then
  713. if conf.type == CombatDefine.BUFFER_TYPE2 then
  714. buffer = obj.buffer[index]
  715. buffer.round = round
  716. --bingdong清除buffer参数
  717. if conf.cmd == "bingdong" then
  718. buffer.arg = nil
  719. end
  720. CombatImpl.onAddBuffer(id)
  721. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_ADD,0)
  722. return
  723. end
  724. return
  725. end
  726. else
  727. if bufferCnt > 1 then
  728. if conf.type == CombatDefine.BUFFER_TYPE2 then
  729. buffer = obj.buffer[bufferInd]
  730. buffer.round = round
  731. --bingdong清除buffer参数
  732. if conf.cmd == "bingdong" then
  733. buffer.arg = nil
  734. end
  735. CombatImpl.onAddBuffer(id)
  736. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_ADD,0)
  737. return
  738. end
  739. return
  740. end
  741. end
  742. if isControlCmd(bufferCmd) and bufferCmdInd then
  743. buffer = obj.buffer[bufferCmdInd]
  744. if buffer.round < round then
  745. buffer.round = round
  746. end
  747. if conf.cmd == "bingdong" then
  748. buffer.arg = nil
  749. end
  750. return
  751. end
  752. obj.buffer[0] = obj.buffer[0] + 1
  753. index = obj.buffer[0]
  754. buffer = obj.buffer[index]
  755. if not buffer then
  756. obj.buffer[index] = {}
  757. buffer = obj.buffer[index]
  758. end
  759. buffer.id = id
  760. buffer.round = nil -- 剩余回合
  761. buffer.attrs = nil
  762. buffer.attackPos = nil
  763. buffer.skillID = nil
  764. buffer.cnt = 1
  765. buffer.arg = nil
  766. if round then
  767. buffer.round = round
  768. elseif conf.type == CombatDefine.BUFFER_TYPE1 then
  769. buffer.round = 1
  770. elseif conf.type == CombatDefine.BUFFER_TYPE2 then
  771. buffer.round = round
  772. elseif conf.type == CombatDefine.BUFFER_TYPE3 then
  773. buffer.round = nil
  774. else
  775. assert()
  776. end
  777. local attacker
  778. if attackPos > CombatDefine.COMBAT_HERO_ALL_CNT then
  779. attacker = CombatImpl.helpList[attackPos]
  780. else
  781. attacker = CombatImpl.objList[attackPos]
  782. end
  783. if arg then
  784. buffer.arg = arg
  785. elseif isHpCmd(conf.cmd) then
  786. local isAddHp = conf.cmd == "hp"
  787. buffer.arg = CombatCalc.calcBufferHp(attacker,obj,id,isAddHp)
  788. end
  789. buffer.attackPos = attackPos
  790. buffer.skillID = skillID
  791. buffer.attrs = {}
  792. if bufferCmd == "shengling" then
  793. buffer.arg = conf.args[3]
  794. elseif bufferCmd == "hudun" then
  795. local attackerHp = CombatCalc.calcHp(attacker, obj, conf.args[1], conf.args[2], true)
  796. local hudunValue = math.floor(conf.args[2] * attackerHp / 10000)
  797. buffer.arg = hudunValue
  798. end
  799. onBufferChange(obj)
  800. if conf.isAddCmd == 1 and handler[conf.cmd] then
  801. handler[conf.cmd](obj,buffer,conf)
  802. HANDLER_ONCE[conf.cmd] = nil
  803. end
  804. -- 立刻触发一次返回
  805. if conf.effectiveonce and conf.effectiveonce == 1 and handler[conf.cmd] then
  806. print("[addBuffer] 立刻触发一次buff效果id = "..buffer.id)
  807. handler[conf.cmd](obj,buffer,conf)
  808. HANDLER_ONCE[conf.cmd] = nil
  809. buffer.round = 0
  810. end
  811. if conf.type ~= CombatDefine.BUFFER_TYPE1 then
  812. CombatImpl.onAddBuffer(id)
  813. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_ADD)
  814. end
  815. BeSkill.onAddBuffer(obj,buffer)
  816. onExtraCombatRecord(attackPos,1,bufferCmd)
  817. if conf.effectiveonce and conf.effectiveonce == 1 then
  818. obj.buffer[0] = obj.buffer[0] - 1
  819. table.remove(obj.buffer, index)
  820. print("[addBuffer] 删除了对应的buff id = ".. buffer.id.." index = "..index)
  821. end
  822. return buffer
  823. end
  824. local function delBufferByTotem(obj,totemId)
  825. for j = obj.buffer[0], 1, -1 do
  826. local buffer = obj.buffer[j]
  827. --local conf = BufferExcel.buffer[buffer.id]
  828. local conf = GetBuffConfig(buffer.id)
  829. if bufferCmd ~= "totem" and buffer.totem == totemId then
  830. delBuffer(obj,j)
  831. end
  832. end
  833. end
  834. local function beforeDelBuffer(obj, buffer)
  835. --local conf = BufferExcel.buffer[buffer.id]
  836. local conf = GetBuffConfig(buffer.id)
  837. if conf.cmd == "fentan" and buffer.round < 1 then
  838. local hurt = CombatCalc.calcHp(obj, obj, conf.args[1], conf.args[2])
  839. if hurt > 0 then
  840. local d = CombatObj.updateHp(obj, hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  841. CombatImpl.setExtraHit(obj, hurt)
  842. CombatObj.onHpCB(obj, d, obj.pos)
  843. end
  844. end
  845. end
  846. function delBuffer(obj, ind)
  847. if not obj.buffer[ind] then
  848. return
  849. end
  850. if DELAY_BUFF_OP then
  851. for k,v in ipairs(DELAY_LIST.del) do
  852. if v[2] == ind then
  853. return
  854. end
  855. end
  856. DELAY_LIST.del[#DELAY_LIST.del + 1] = {obj, ind}
  857. return
  858. end
  859. local id = obj.buffer[ind].id
  860. beforeDelBuffer(obj,obj.buffer[ind])
  861. obj.buffer[ind] = obj.buffer[obj.buffer[0]]
  862. obj.buffer[obj.buffer[0]] = nil
  863. obj.buffer[0] = obj.buffer[0] - 1
  864. onBufferChange(obj)
  865. local bufferCnt = 0
  866. for i = 1, obj.buffer[0] do
  867. local buffer = obj.buffer[i]
  868. if buffer.id == id then
  869. bufferCnt = bufferCnt + 1
  870. end
  871. end
  872. return bufferCnt
  873. end
  874. --通过buff的cmd删除一定数量的buff
  875. function DelBuffByCmd(obj, cmd, cnt)
  876. delBufferByCmd(obj, cmd, cnt)
  877. end
  878. -- 战斗回合开始时添加buffer
  879. function beforeCombat()
  880. end
  881. function getSkillBuffers(skillConfig)
  882. local randBuffCnt = skillConfig.otherArgs.randBuffCnt
  883. if not randBuffCnt then
  884. return skillConfig.buffers
  885. end
  886. local ret = {}
  887. local c = #skillConfig.buffers
  888. if randBuffCnt >= c then
  889. return skillConfig.buffers
  890. end
  891. for i = 1,c do
  892. ret[i] = skillConfig.buffers[i]
  893. end
  894. for i = 1,c do
  895. if i <= randBuffCnt then
  896. local r = math.random(i,c)
  897. ret[i],ret[r] = ret[r],ret[i]
  898. else
  899. ret[i] = nil
  900. end
  901. end
  902. return ret
  903. end
  904. -- 战斗回合中触发buffer
  905. function onHit(attacker, skillTargets, skillConfig, cmdTargets, otherArgs)
  906. -- 处理施法者身上的buff
  907. if skillConfig.type == CombatDefine.SKILL_TYPE2 and
  908. attacker.buffer ~= nil then
  909. delayBegin()
  910. for j = attacker.buffer[0], 1, -1 do
  911. local buffer = attacker.buffer[j]
  912. --local conf = BufferExcel.buffer[buffer.id]
  913. local conf = GetBuffConfig(buffer.id)
  914. buffer.attrs = { }
  915. if attacker.hp > 0 and handlerEx[conf.cmd] then
  916. if handlerEx[conf.cmd](attacker, buffer, conf) then
  917. CombatImpl.addFrameBuffer(attacker, buffer, CombatDefine.BUFFER_OP_HOLD)
  918. end
  919. end
  920. end
  921. delayEnd()
  922. end
  923. for k, v in ipairs(skillTargets) do
  924. if attacker.helpType == 0 and attacker.side ~= v.side then
  925. local fantanBufferInd = v.bufferCmd["fantan"] and v.bufferCmd["fantan"][1]
  926. local fantanBuffer = v.buffer[fantanBufferInd]
  927. if fantanBuffer then
  928. --local conf = BufferExcel.buffer[fantanBuffer.id]
  929. local conf = GetBuffConfig(fantanBuffer.id)
  930. -- 是否限制技能类型
  931. local bHit = false
  932. if conf.args[3] then
  933. if conf.args[3] == skillConfig.type then
  934. bHit = true
  935. end
  936. else
  937. bHit = true
  938. end
  939. if bHit then
  940. local hurt = CombatCalc.calcHp(attacker, v, conf.args[1], conf.args[2])
  941. local d = CombatObj.updateHp(attacker, - hurt, nil, nil, v.pos, CombatObj.BUFFER_HP_TYPE)
  942. CombatImpl.setExtraHit(attacker, d)
  943. CombatObj.onHpCB(attacker, d, v.pos)
  944. end
  945. end
  946. end
  947. -- 只能敌方攻击触发降低冰冻
  948. if not(otherArgs and otherArgs.noFirst) and skillConfig.hurtRate[1] then
  949. local bufferCmd = v.bufferCmd["bingdong"]
  950. if bufferCmd then
  951. local delList = { }
  952. for i = #bufferCmd, 1, -1 do
  953. local bingdongBuffer = v.buffer[bufferCmd[i]]
  954. --local conf = BufferExcel.buffer[bingdongBuffer.id]
  955. local conf = GetBuffConfig(bingdongBuffer.id)
  956. bingdongBuffer.arg = bingdongBuffer.arg or 0
  957. bingdongBuffer.arg = bingdongBuffer.arg + 1
  958. if bingdongBuffer.arg >=(conf.args[1] or 0) then
  959. delList[#delList + 1] = bufferCmd[i]
  960. end
  961. end
  962. --冰冻buffer被打碎
  963. if #delList > 0 then
  964. local delBuffer = v.buffer[delList[1]]
  965. BeSkill.onDelBingDongBuffer(v, delBuffer)
  966. end
  967. for k1, v1 in ipairs(delList) do
  968. local buffer = v.buffer[v1]
  969. local bufferCnt = delBuffer(v, v1)
  970. CombatImpl.addFrameBuffer(v, buffer, CombatDefine.BUFFER_OP_DEL)
  971. end
  972. end
  973. end
  974. end
  975. local buffers = getSkillBuffers(skillConfig)
  976. local statusBuffRate = skillConfig.otherArgs.statusBuffRate
  977. local jobRateAdd = skillConfig.otherArgs.jobRateAdd
  978. for i = 1, #buffers do
  979. local bufferID = buffers[i][1]
  980. if type(bufferID) == "table" then
  981. local r = math.random(1, #bufferID)
  982. bufferID = bufferID[r]
  983. end
  984. local targetMode = buffers[i][2]
  985. local random = buffers[i][3]
  986. local bufferEx = buffers[i][4]
  987. local delayRound = buffers[i][5]
  988. if attacker.isPet and #skillConfig.bufferGrow > 0 then
  989. local growRate = 0
  990. local bufLv = attacker.lv
  991. if attacker.quality > 1 then
  992. bufLv = attacker.lv -(attacker.quality - 1) * 30
  993. end
  994. if skillConfig.bufferGrow and skillConfig.bufferGrow[i] then
  995. local gorwRat = skillConfig.bufferGrow[i][1]
  996. local growLv = skillConfig.bufferGrow[i][2]
  997. growRate = math.floor(bufLv / growLv) * gorwRat
  998. end
  999. random = random + growRate
  1000. end
  1001. local targets = TargetMode.getTargets(attacker, targetMode, skillTargets, cmdTargets, nil, nil, skillConfig.id)
  1002. if #targets > 0 then
  1003. --local bufferConf = BufferExcel.buffer[bufferID]
  1004. local bufferConf = GetBuffConfig(bufferID)
  1005. for _, target in ipairs(targets) do
  1006. local r = random
  1007. if statusBuffRate and bufferConf.cmd == statusBuffRate[1] and isStatus(target, statusBuffRate[2]) then
  1008. r = r + statusBuffRate[3]
  1009. end
  1010. if jobRateAdd and bufferConf.cmd == jobRateAdd[1] and isJob(target, jobRateAdd[2]) then
  1011. r = r + jobRateAdd[3]
  1012. end
  1013. if canAdd(target, bufferID, r, attacker, skillConfig) then
  1014. local arg
  1015. if bufferConf.cmd == "zuzhou" then
  1016. local rate = bufferConf.args[2] + BeSkill.getBufferExtraHurt(attacker, bufferID, bufferConf.cmd)
  1017. arg = { CombatCalc.calcHp(attacker, target, bufferConf.args[1], rate) }
  1018. end
  1019. if bufferConf.cmd == "stealattr" then
  1020. local value = CombatCalc.calcValue(attacker, target, bufferConf.args[1], bufferConf.args[2])
  1021. arg = { { bufferConf.args[3], value } }
  1022. end
  1023. if bufferConf.cmd == "handleattr" then
  1024. arg = { }
  1025. if attacker.handleAttr then
  1026. local value = attacker.handleAttr[2] *(bufferConf.args[1] / 10000)
  1027. if target.side == attacker.side then
  1028. arg = { { attacker.handleAttr[1], value * bufferConf.args[2] } }
  1029. else
  1030. arg = { { attacker.handleAttr[1], - value } }
  1031. end
  1032. end
  1033. end
  1034. if delayRound and delayRound > 0 then
  1035. target.delayAddBuffer = target.delayAddBuffer or { }
  1036. target.delayAddBuffer[#target.delayAddBuffer + 1] = { delayRound, attacker.pos, bufferID, skillConfig.id, arg }
  1037. else
  1038. addBuffer(attacker.pos, target, bufferID, skillConfig.id, arg)
  1039. end
  1040. if bufferEx then
  1041. local bufferID = bufferEx[1]
  1042. local random = bufferEx[2]
  1043. local delayRound = bufferEx[3]
  1044. --local bufferConf = BufferExcel.buffer[bufferID]
  1045. local bufferConf = GetBuffConfig(bufferID)
  1046. for _, target in ipairs(targets) do
  1047. local r = random
  1048. if canAdd(target, bufferID, r, attacker, skillConfig) then
  1049. local arg
  1050. if bufferConf.cmd == "zuzhou" then
  1051. local rate = bufferConf.args[2] + BeSkill.getBufferExtraHurt(attacker, bufferID, bufferConf.cmd)
  1052. arg = { CombatCalc.calcHp(attacker, target, bufferConf.args[1], rate) }
  1053. end
  1054. if bufferConf.cmd == "stealattr" then
  1055. local value = CombatCalc.calcValue(attacker, target, bufferConf.args[1], bufferConf.args[2])
  1056. arg = { { bufferConf.args[3], value } }
  1057. end
  1058. if bufferConf.cmd == "handleattr" then
  1059. arg = { }
  1060. if attacker.handleAttr then
  1061. local value = attacker.handleAttr[2] *(bufferConf.args[1] / 10000)
  1062. if target.side == attacker.side then
  1063. arg = { { attacker.handleAttr[1], value * bufferConf.args[2] } }
  1064. else
  1065. arg = { { attacker.handleAttr[1], - value } }
  1066. end
  1067. end
  1068. end
  1069. if delayRound and delayRound > 0 then
  1070. target.delayAddBuffer = target.delayAddBuffer or { }
  1071. target.delayAddBuffer[#target.delayAddBuffer + 1] = { delayRound, attacker.pos, bufferID, skillConfig.id, arg }
  1072. else
  1073. addBuffer(attacker.pos, target, bufferID, skillConfig.id, arg)
  1074. end
  1075. end
  1076. end
  1077. end
  1078. end
  1079. end
  1080. end
  1081. end
  1082. end
  1083. local function getBeskillBuffers(attacker,skillConfig)
  1084. if skillConfig.otherArgs.buffer then
  1085. local checkArg = skillConfig.otherArgs.buffer
  1086. local checkValue
  1087. if checkArg.cmd == "hurtRate" then
  1088. checkValue = -attacker.combatResult[1]
  1089. elseif checkArg.cmd == "hpRate" then
  1090. checkValue = attacker.combatResult[2]
  1091. end
  1092. if checkValue and checkValue > 0 then
  1093. local hpMax = attacker.attr[RoleDefine.HP]
  1094. local rate = (10000 * checkValue)/(hpMax * checkArg.param[1])
  1095. if rate > 1 then
  1096. local retArg = {}
  1097. for k,v in ipairs(checkArg.param[2]) do
  1098. retArg[#retArg + 1] = {v[1],math.floor(v[2] * rate)}
  1099. end
  1100. return skillConfig.buffers,retArg
  1101. end
  1102. end
  1103. elseif skillConfig.otherArgs.randBuffCnt then
  1104. local randBuffCnt = skillConfig.otherArgs.randBuffCnt
  1105. local allBuffCnt = #skillConfig.buffers
  1106. if randBuffCnt >= allBuffCnt then
  1107. return skillConfig.buffers
  1108. end
  1109. local ret = {}
  1110. for i = 1, allBuffCnt do
  1111. ret[i] = skillConfig.buffers[i]
  1112. end
  1113. for i = 1, allBuffCnt do
  1114. if i <= randBuffCnt then
  1115. local r = math.random(i, allBuffCnt)
  1116. ret[i],ret[r] = ret[r],ret[i]
  1117. else
  1118. ret[i] = nil
  1119. end
  1120. end
  1121. return ret
  1122. else
  1123. return skillConfig.buffers
  1124. end
  1125. end
  1126. function onUseBeSkill(attacker,skillConfig,objs,cmdTargets, arg)--attacker是被动技能释放者,objs是attacker的对立方(attacker是攻击者的话,objs是被攻击者,attacker是被攻击者的话,objs是攻击者),cmdTargets是额外作用对象
  1127. -- 使用被动技能时,需要特殊处理遗物的args和otherArgs
  1128. local winnerID = attacker and attacker.relic and attacker.relic.relicID or 0
  1129. local winnerStar = attacker and attacker.relic and attacker.relic.star or 0
  1130. local buffers,bufferArg = getBeskillBuffers(attacker,skillConfig)
  1131. if not buffers then
  1132. -- print("[onUseBeSkill] 获取不到配置直接返回 id = "..skillConfig[1])
  1133. return
  1134. end
  1135. bufferArg = bufferArg or arg
  1136. local isAddSkillFrame
  1137. local bufferArg1
  1138. for i = 1, #buffers do
  1139. local bufferID = buffers[i][1]
  1140. --local bufferConf = BufferExcel.buffer[bufferID]
  1141. local bufferConf = GetBuffConfig(bufferID)
  1142. local targetMode = buffers[i][2]
  1143. local targets
  1144. bufferArg1 = nil
  1145. if targetMode[1] == 13 then
  1146. targets = objs
  1147. else
  1148. targets = TargetMode.getTargets(attacker, targetMode,objs,cmdTargets)
  1149. end
  1150. if #targets > 0 then
  1151. if bufferConf.cmd == "zuzhou" then
  1152. local rate = bufferConf.args[2] + BeSkill.getBufferExtraHurt(attacker,bufferID)
  1153. bufferArg1 = {CombatCalc.calcHp(attacker,targets[1],bufferConf.args[1],rate)}
  1154. end
  1155. local attackPos = attacker.pos
  1156. if bufferConf.roundOne == 1 and objs and objs[1] then
  1157. attackPos = objs[1].pos
  1158. end
  1159. for _,target in ipairs(targets) do
  1160. if canAdd(target,bufferID,buffers[i][3], attacker, skillConfig) then
  1161. isAddSkillFrame = true
  1162. addBuffer(attackPos,target, bufferID,skillConfig.id,bufferArg1 or bufferArg)
  1163. end
  1164. end
  1165. end
  1166. end
  1167. -- if skillConfig.cmd == "winnerRelicSkill" then
  1168. -- if skillConfig and skillConfig.otherArgs.selefDefense then
  1169. -- if attacker then
  1170. -- print("[onUseBeSkill] winnerRelicSkill 进入 1")
  1171. -- attacker.attr[RoleDefine.DEF] = 0
  1172. -- end
  1173. -- elseif skillConfig and skillConfig.otherArgs.jobDefense then
  1174. -- if isJob(attacker, {CombatDefine.JOB_TYPE4, CombatDefine.JOB_TYPE1}) then
  1175. -- if winnerID > 0 and winnerStar > 0 then
  1176. -- print("[onUseBeSkill] winnerRelicSkill 进入 2")
  1177. -- local extraRate = WinnerRelicLogic.WinnerRelic_GetRateAttack(winnerID, winnerStar)
  1178. -- attacker.attr[RoleDefine.DEF] = attacker.attr[RoleDefine.DEF] + extraRate
  1179. -- print("当前防御提升量为:",extraRate)
  1180. -- end
  1181. -- end
  1182. -- elseif skillConfig and skillConfig.otherArgs.jobMianshang then
  1183. -- if isJob(attacker, {CombatDefine.JOB_TYPE1}) then
  1184. -- print("[onUseBeSkill] winnerRelicSkill 进入 3")
  1185. -- local extraRate = WinnerRelicLogic.WinnerRelic_GetRateDef(winnerID, winnerStar)
  1186. -- attacker.attr[RoleDefine.JIANSHANG_RATE] = attacker.attr[RoleDefine.JIANSHANG_RATE] *(1 + extraRate/100)
  1187. -- print("当前护卫免伤量提升量为:",extraRate)
  1188. -- end
  1189. -- elseif skillConfig and skillConfig.otherArgs.racialAtk then
  1190. -- if isCamp(attacker, {CombatDefine.COMBAT_TYPE27}) then
  1191. -- print("[onUseBeSkill] winnerRelicSkill 进入 4")
  1192. -- local extraRate = WinnerRelicLogic.WinnerRelic_GetRateAttack(winnerID, winnerStar)
  1193. -- attacker.attr[RoleDefine.ATK] = attacker.attr[RoleDefine.ATK] *(1+ extraRate/100)
  1194. -- end
  1195. -- elseif skillConfig and skillConfig.otherArgs.jobZhiliao then
  1196. -- if isJob(attacker, {CombatDefine.JOB_TYPE4}) then
  1197. -- print("[onUseBeSkill] winnerRelicSkill 进入 5")
  1198. -- local extraRate = WinnerRelicLogic.WinnerRelic_GetRateAttack(winnerID, winnerStar)
  1199. -- attacker.attr[RoleDefine.HP_ADD_RATE] = attacker.attr[RoleDefine.HP_ADD_RATE] *(1 + extraRate/100)
  1200. -- end
  1201. -- end
  1202. -- end
  1203. return isAddSkillFrame
  1204. end
  1205. --战斗回合结束时处理buffer效果。删除失效buffer
  1206. --只执行一次的cmd,比如持续加血。
  1207. HANDLER_ONCE = HANDLER_ONCE or {}
  1208. function onRoundEnd(attacker,isRoundEnd)
  1209. --处理施法者身上的buff
  1210. for i = 1,CombatDefine.COMBAT_HERO_ALL_CNT do
  1211. local obj = CombatImpl.objList[i]
  1212. if obj then
  1213. for k,v in pairs(HANDLER_ONCE) do
  1214. HANDLER_ONCE[k] = nil
  1215. end
  1216. delayBegin()
  1217. for j = obj.buffer[0], 1, -1 do
  1218. local buffer = obj.buffer[j]
  1219. --local conf = BufferExcel.buffer[buffer.id]
  1220. local conf = GetBuffConfig(buffer.id)
  1221. if conf.type == CombatDefine.BUFFER_TYPE1 or isRoundEnd then
  1222. buffer.attrs = {}
  1223. local setFrame = false
  1224. if conf.type ~= CombatDefine.BUFFER_TYPE4 and handler[conf.cmd] then
  1225. if obj.hp > 0 or conf.cmd == "totem" then
  1226. if conf.cmd == "zuzhou" then
  1227. -- 最后一回合生效
  1228. if buffer.round == 1 then
  1229. handler[conf.cmd](obj, buffer,conf)
  1230. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_HOLD)
  1231. end
  1232. else
  1233. handler[conf.cmd](obj, buffer,conf)
  1234. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_HOLD)
  1235. end
  1236. end
  1237. end
  1238. if buffer.round then
  1239. local cmd = conf.cmd
  1240. buffer.round = buffer.round - 1
  1241. if buffer.round < 1 then
  1242. local bufferCnt = delBuffer(obj, j)
  1243. if (conf.type ~= CombatDefine.BUFFER_TYPE1 and obj.hp > 0) or conf.cmd == "fixPos" or conf.holdOnDie == 1 then
  1244. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_DEL)
  1245. end
  1246. end
  1247. end
  1248. end
  1249. end
  1250. if isRoundEnd and obj.delayAddBuffer then
  1251. --{delayRound,attacker.pos,bufferID,skillConfig.id,arg}
  1252. for k,v in ipairs(obj.delayAddBuffer) do
  1253. v[1] = v[1] - 1
  1254. end
  1255. local temp = {}
  1256. for i = 1,#obj.delayAddBuffer do
  1257. local data = obj.delayAddBuffer[i]
  1258. if data[1] > 0 then
  1259. temp[#temp + 1] = data
  1260. else
  1261. addBuffer(data[2],obj,data[3],data[4],data[5])
  1262. end
  1263. end
  1264. if #temp > 0 then
  1265. obj.delayAddBuffer = temp
  1266. else
  1267. obj.delayAddBuffer = nil
  1268. end
  1269. end
  1270. delayEnd()
  1271. end
  1272. end
  1273. for k,v in pairs(HANDLER_ONCE) do
  1274. HANDLER_ONCE[k] = nil
  1275. end
  1276. end
  1277. --攻击结束后,反击前,整合buffer前处理buffer效果
  1278. function beforeFanji()
  1279. local isFanshe = false
  1280. for i = 1,CombatDefine.COMBAT_HERO_ALL_CNT do
  1281. local obj = CombatImpl.objList[i]
  1282. if obj then
  1283. for k,v in pairs(obj.combatResult[3]) do
  1284. if k ~= i and v[1] and v[1] < 0 then
  1285. local target = CombatImpl.objList[k]
  1286. if target and target.hp > 0 then
  1287. local d = CombatObj.updateHp(target, v[1], nil, nil, obj.pos,CombatObj.BUFFER_HP_TYPE)
  1288. CombatImpl.setExtraHit(target,d)
  1289. CombatObj.onHpCB(target,d, obj.pos)
  1290. isFanshe = true
  1291. end
  1292. end
  1293. end
  1294. if isFanshe then
  1295. delBufferByCmd(obj,"fansheZhuangjia",1)
  1296. end
  1297. end
  1298. end
  1299. end
  1300. function getExtraHurtRate(attacker,target,skillConfig)
  1301. local skillID = skillConfig.id
  1302. local isBaoji = target.isBaoji
  1303. local baojiHurtRate = 0
  1304. local guanxinzheHurtRate = 0
  1305. local huiheHurtRate = 0
  1306. local shandianHurtRate = 0
  1307. local attackerHurtRat = 0
  1308. local biaoshiHurtRate = 0
  1309. local biaoshiCnt = 0
  1310. local moweiHurtRate = 0
  1311. local biaoshiCntLimit
  1312. local zhanyiHurtRate = 0
  1313. local chenshuiHurtRate = 0
  1314. if skillConfig.otherArgs.biaoshiHurtRate then
  1315. biaoshiCntLimit = skillConfig.otherArgs.biaoshiHurtRate[1]
  1316. end
  1317. for j = target.buffer[0], 1, -1 do
  1318. local obj = target
  1319. local buffer = obj.buffer[j]
  1320. --local conf = BufferExcel.buffer[buffer.id]
  1321. local conf = GetBuffConfig(buffer.id)
  1322. if conf.cmd == "guanxinzheYinji" then --观星者印记
  1323. guanxinzheHurtRate = guanxinzheHurtRate + conf.args[2]
  1324. elseif conf.cmd == "shandianYinji" then --闪电印记
  1325. for _,v in ipairs(conf.args[2]) do
  1326. if skillID == v then
  1327. shandianHurtRate = shandianHurtRate + conf.args[3]
  1328. break
  1329. end
  1330. end
  1331. elseif conf.cmd == "biaoshi" then
  1332. biaoshiCnt = biaoshiCnt + 1
  1333. elseif conf.cmd == "chenshui" then
  1334. chenshuiHurtRate = chenshuiHurtRate + 3000
  1335. end
  1336. end
  1337. --攻击者
  1338. for j = attacker.buffer[0], 1, -1 do
  1339. local obj = attacker
  1340. local buffer = obj.buffer[j]
  1341. --local conf = BufferExcel.buffer[buffer.id]
  1342. local conf = GetBuffConfig(buffer.id)
  1343. if conf.cmd == "mowei" then --魔威
  1344. local nowHp = attacker.hp
  1345. local hpMax = CombatObj.getHpMax(attacker)
  1346. local percent = math.floor( (hpMax - nowHp )/hpMax * 100)
  1347. if percent >= 1 then
  1348. --moweiHurtRate = moweiHurtRate + (percent * conf.args[1])
  1349. moweiHurtRate = percent * conf.args[1]
  1350. break
  1351. end
  1352. elseif conf.cmd == "zhanyi" then
  1353. local nowHp = attacker.hp
  1354. local hpMax = CombatObj.getHpMax(attacker)
  1355. local percent = math.floor( (hpMax - nowHp )/hpMax * 100)
  1356. if percent >= 1 then
  1357. local args = conf.args
  1358. percent = percent / (args[1] / 100)
  1359. zhanyiHurtRate = percent * args[2]
  1360. break
  1361. end
  1362. end
  1363. end
  1364. guanxinzheHurtRate = guanxinzheHurtRate > 30000 and 30000 or guanxinzheHurtRate --300%限制
  1365. if biaoshiCntLimit and biaoshiCnt >= biaoshiCntLimit then
  1366. biaoshiHurtRate = skillConfig.otherArgs.biaoshiHurtRate[2]
  1367. end
  1368. local extraHurtRate = baojiHurtRate + guanxinzheHurtRate + huiheHurtRate + shandianHurtRate
  1369. + attackerHurtRat + biaoshiHurtRate + moweiHurtRate + zhanyiHurtRate + chenshuiHurtRate
  1370. return extraHurtRate
  1371. end
  1372. function getExtraHurt(attacker, target, skillConfig)
  1373. local extraHurt = 0
  1374. for j = target.buffer[0], 1, -1 do
  1375. local obj = target
  1376. local buffer = obj.buffer[j]
  1377. --local conf = BufferExcel.buffer[buffer.id]
  1378. local conf = GetBuffConfig(buffer.id)
  1379. if conf.cmd == "shenhuo" then
  1380. local hurt = CombatCalc.calcHp(attacker, target, conf.args[1], conf.args[2], true)
  1381. extraHurt = extraHurt + hurt
  1382. end
  1383. end
  1384. return extraHurt
  1385. end
  1386. --处理器
  1387. local function chixuHurtDel(target,buffer)
  1388. local hurt = buffer.arg
  1389. local hurtDelRate = target.attr[RoleDefine.CHIXU_HURT_DEL_RATE] / 10000
  1390. --持续类buff 伤害加成
  1391. local attacker = CombatImpl.objList[buffer.attackPos]
  1392. --local conf = BufferExcel.buffer[buffer.id]
  1393. local conf = GetBuffConfig(buffer.id)
  1394. local beSkillHurtRate = BeSkill.getBuffChixuHurt(attacker, conf.cmd)
  1395. hurtDelRate = hurtDelRate > 1 and 1 or hurtDelRate
  1396. if hurtDelRate > 0 or beSkillHurtRate > 0 then
  1397. hurt = hurt * (1 - hurtDelRate + beSkillHurtRate)
  1398. end
  1399. return hurt
  1400. end
  1401. --处理器, 实时计算伤害
  1402. local function chixuHurtDel2(target,buffer)
  1403. local id = buffer.id
  1404. --local conf = BufferExcel.buffer[id]
  1405. local conf = GetBuffConfig(buffer.id)
  1406. local attackPos = buffer.attackPos
  1407. local attacker
  1408. if attackPos > CombatDefine.COMBAT_HERO_ALL_CNT then
  1409. attacker = CombatImpl.helpList[attackPos]
  1410. else
  1411. attacker = CombatImpl.objList[attackPos]
  1412. end
  1413. local isAddHp = conf.cmd == "hp"
  1414. buffer.arg = CombatCalc.calcBufferHp(attacker,target,id,isAddHp)
  1415. local hurt = buffer.arg
  1416. local hurtDelRate = target.attr[RoleDefine.CHIXU_HURT_DEL_RATE] / 10000
  1417. --持续类buff 伤害加成
  1418. -- local attacker = CombatImpl.objList[buffer.attackPos]
  1419. -- local conf = BufferExcel.buffer[buffer.id]
  1420. local beSkillHurtRate = BeSkill.getBuffChixuHurt(attacker, conf.cmd)
  1421. hurtDelRate = hurtDelRate > 1 and 1 or hurtDelRate
  1422. if hurtDelRate > 0 or beSkillHurtRate > 0 then
  1423. hurt = hurt * (1 - hurtDelRate + beSkillHurtRate)
  1424. end
  1425. return hurt
  1426. end
  1427. handler = {}
  1428. --持续伤害
  1429. function handler.hurt(target, buffer,conf)
  1430. local hurt = chixuHurtDel(target,buffer)
  1431. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1432. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1433. end
  1434. --燃烧
  1435. function handler.hurt1(target, buffer,conf)
  1436. local hurt = chixuHurtDel(target,buffer)
  1437. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1438. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1439. onExtraCombatRecord(buffer.attackPos,hurt,"ranshao")
  1440. -- 删除attr1 buffer
  1441. local attacker = CombatImpl.objList[buffer.attackPos]
  1442. if attacker and attacker.bufferCmd["attr1"] then
  1443. for i = #attacker.bufferCmd["attr1"],1,-1 do
  1444. local ind = attacker.bufferCmd["attr1"][i]
  1445. local buff = attacker.buffer[ind]
  1446. --local conf = BufferExcel.buffer[buff.id]
  1447. local conf = GetBuffConfig(buffer.id)
  1448. local bufferCnt = delBuffer(attacker, ind)
  1449. CombatImpl.addFrameBuffer(attacker, buff, CombatDefine.BUFFER_OP_DEL)
  1450. end
  1451. end
  1452. end
  1453. --持续治疗
  1454. function handler.hp(target, buffer,conf)
  1455. if target.bufferCmd["noHp"] then
  1456. return
  1457. end
  1458. if HANDLER_ONCE["hp"] == target.pos then
  1459. return
  1460. end
  1461. local hp = buffer.arg
  1462. local attacker = CombatImpl.objList[buffer.attackPos]
  1463. if attacker and attacker.attr[RoleDefine.ZAOCHENG_HP_ADD_RATE] then
  1464. local hpAddRate = attacker.attr[RoleDefine.ZAOCHENG_HP_ADD_RATE] / 10000
  1465. hp = hp * (1 + hpAddRate)
  1466. end
  1467. local calcType = conf and conf.args[1] or 0
  1468. if CombatCalc.NO_EXCALC_LIST[calcType] and target.attr[RoleDefine.HP_ADD_RATE] then
  1469. local hpAddRate = target.attr[RoleDefine.HP_ADD_RATE] / 10000
  1470. hp = hp * (1 + hpAddRate)
  1471. end
  1472. hp = hp < 0 and 1 or hp
  1473. if target.side == CombatDefine.DEFEND_SIDE then
  1474. hp = CombatImpl.commonArgs.hpLimit or hp
  1475. end
  1476. local d = CombatObj.updateHp(target, hp, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1477. buffer.attrs[RoleDefine.HP_COMBAT] = hp
  1478. HANDLER_ONCE["hp"] = target.pos
  1479. end
  1480. --流血
  1481. function handler.liuxue(target, buffer,conf)
  1482. local hurt = chixuHurtDel(target,buffer)
  1483. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1484. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1485. onExtraCombatRecord(buffer.attackPos,hurt,"liuxue")
  1486. end
  1487. --流血2
  1488. function handler.liuxue2(target, buffer,conf)
  1489. local hurt = chixuHurtDel2(target,buffer)
  1490. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1491. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1492. onExtraCombatRecord(buffer.attackPos,hurt,"liuxue")
  1493. end
  1494. --中毒
  1495. function handler.zhongdu(target, buffer,conf)
  1496. local hurt = chixuHurtDel(target,buffer)
  1497. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1498. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1499. onExtraCombatRecord(buffer.attackPos,hurt,"zhongdu")
  1500. end
  1501. --燃烧
  1502. function handler.ranshao(target, buffer,conf)
  1503. local hurt = chixuHurtDel(target,buffer)
  1504. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1505. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1506. onExtraCombatRecord(buffer.attackPos,hurt,"ranshao")
  1507. end
  1508. --燃烧
  1509. function handler.ranshao1(target, buffer,conf)
  1510. local hurt = chixuHurtDel(target,buffer)
  1511. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1512. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1513. onExtraCombatRecord(buffer.attackPos,hurt,"ranshao")
  1514. end
  1515. --回合印记
  1516. function handler.huiheYinji(target, buffer,conf)
  1517. if buffer.round > 1 then return end --最后一回合才生效
  1518. local hurt = chixuHurtDel(target,buffer)
  1519. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1520. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1521. end
  1522. --种子
  1523. function handler.zhongzi(target, buffer, conf)
  1524. if buffer.round > 1 then return end --最后一回合才生效
  1525. local cnt = #conf.args
  1526. for i= 1, cnt do
  1527. local bufferID = conf.args[i]
  1528. if canAdd(target,bufferID) then
  1529. addBuffer(buffer.attackPos, target, bufferID)
  1530. end
  1531. end
  1532. end
  1533. --buffer包处理器
  1534. --偷取护甲
  1535. function handler.touquhujia(attacker,target,conf)
  1536. local arg = conf.args[1]/10000
  1537. local targetBufferID = conf.args[2]
  1538. local attackerBufferID = conf.args[3]
  1539. local def = CombatObj.getValue(target,RoleDefine.DEF)
  1540. --local rate = CombatObj.getValue(target,RoleDefine.DEF_RATE)/10000
  1541. --def = def * (1 + rate)
  1542. def = def > 0 and def or 0
  1543. local arg = def * arg
  1544. if arg > 0 then
  1545. if canAdd(attacker,attackerBufferID) then
  1546. addBuffer(target.pos,attacker, attackerBufferID,nil,arg,conf)
  1547. end
  1548. if canAdd(target,targetBufferID) then
  1549. addBuffer(attacker.pos,target, targetBufferID,nil,-arg,conf)
  1550. end
  1551. end
  1552. end
  1553. --偷取攻击
  1554. function handler.touqugongji(attacker,target,conf)
  1555. local arg = conf.args[1]/10000
  1556. local targetBufferID = conf.args[2]
  1557. local attackerBufferID = conf.args[3]
  1558. local atk = CombatObj.getValue(target,RoleDefine.ATK)
  1559. --local rate = CombatObj.getValue(target,RoleDefine.ATK_RATE)/10000
  1560. --def = def * (1 + rate)
  1561. atk = atk > 0 and atk or 0
  1562. local arg = atk * arg
  1563. if arg > 0 then
  1564. if canAdd(attacker,attackerBufferID) then
  1565. addBuffer(target.pos,attacker, attackerBufferID,nil,arg,conf)
  1566. end
  1567. if canAdd(target,targetBufferID) then
  1568. addBuffer(attacker.pos,target, targetBufferID,nil,-arg,conf)
  1569. end
  1570. end
  1571. end
  1572. function handler.totem(obj,buffer,conf)
  1573. --图腾逻辑
  1574. local buffers = conf.args
  1575. for i = 1, #buffers do
  1576. local bufferID = buffers[i][1]
  1577. if type(bufferID) == "table" then
  1578. local r = math.random(1,#bufferID)
  1579. bufferID = bufferID[r]
  1580. end
  1581. local targetMode = buffers[i][2]
  1582. local random = buffers[i][3]
  1583. local targets = TargetMode.getTargets(obj, targetMode,{})
  1584. if #targets > 0 then
  1585. for _,target in ipairs(targets) do
  1586. if canAdd(target,bufferID,random) then
  1587. addBuffer(obj.pos,target, bufferID)
  1588. end
  1589. end
  1590. end
  1591. end
  1592. end
  1593. function handler.groupbuffer(attacker,target,conf)
  1594. for _,bufferID in ipairs(conf.args) do
  1595. if canAdd(target,bufferID) then
  1596. addBuffer(attacker.pos,target, bufferID,nil,nil,conf)
  1597. end
  1598. end
  1599. end
  1600. function handler.zuzhou(target,buffer,conf)
  1601. local hurt = buffer.arg[1]
  1602. local attacker = CombatImpl.objList[buffer.attackPos]
  1603. -- 二次元结算方式调整成
  1604. if BeSkill.getRandomBuffCmd(attacker, target, conf.cmd) and target.bufferCmd[conf.cmd] then
  1605. hurt = hurt * #target.bufferCmd[conf.cmd]
  1606. end
  1607. local beSkillHurtRate = BeSkill.getBuffChixuHurt(attacker, conf.cmd)
  1608. hurt = hurt * (1 + beSkillHurtRate)
  1609. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1610. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1611. BeSkill.handlerBuff(attacker, target, hurt, conf.cmd)
  1612. end
  1613. function yinbaoZuzhou(obj, skillTargets, skillConfig)
  1614. local newFrame = nil
  1615. for k,v in ipairs(skillTargets) do
  1616. if v.bufferCmd["zuzhou"] then
  1617. for i = #v.bufferCmd["zuzhou"],1,-1 do
  1618. local ind = v.bufferCmd["zuzhou"][i]
  1619. local buffer = v.buffer[ind]
  1620. --local conf = BufferExcel.buffer[buffer.id]
  1621. local conf = GetBuffConfig(buffer.id)
  1622. if conf and handler[conf.cmd] then
  1623. handler[conf.cmd](v, buffer, conf)
  1624. CombatImpl.addFrameBuffer(v,buffer,CombatDefine.BUFFER_OP_HOLD)
  1625. end
  1626. local bufferCnt = delBuffer(v, ind)
  1627. CombatImpl.addFrameBuffer(v,buffer,CombatDefine.BUFFER_OP_DEL)
  1628. newFrame = true
  1629. end
  1630. end
  1631. end
  1632. -- 有引爆成功的
  1633. if newFrame and ProjectLogic.isSsecy() then
  1634. CombatImpl.addFrame()
  1635. end
  1636. end
  1637. --主动技能释放后buff作用
  1638. handlerEx = {}
  1639. --印记
  1640. function handlerEx.yinJi(target, buffer, conf)
  1641. local attacker = CombatImpl.objList[buffer.attackPos]
  1642. if attacker == nil then
  1643. return
  1644. end
  1645. local hurtRate = conf.args[1]
  1646. local hurtRateMax = conf.args[2]
  1647. local hpMax = CombatObj.getHpMax(target)
  1648. local hurt = hurtRate * hpMax / 10000
  1649. local atk = CombatObj.getValue(attacker,RoleDefine.ATK) * hurtRateMax / 10000
  1650. if hurt > atk then
  1651. hurt = atk
  1652. end
  1653. local d = CombatObj.updateHp(target, -hurt, nil, nil, buffer.attackPos,CombatObj.BUFFER_HP_TYPE)
  1654. buffer.attrs[RoleDefine.HP_COMBAT] = -hurt
  1655. return true
  1656. end
  1657. function qingsuan(target)
  1658. if target.hp <= 0 then
  1659. return 0
  1660. end
  1661. local baseValue = 0
  1662. local round
  1663. for j = target.buffer[0], 1, -1 do
  1664. local buffer = target.buffer[j]
  1665. --local conf = BufferExcel.buffer[buffer.id]
  1666. local conf = GetBuffConfig(buffer.id)
  1667. local cmd = conf.cmd
  1668. if cmd == "ranshao" or cmd == "ranshao1" or cmd == "liuxue"or cmd == "liuxue2" or cmd == "zhongdu" or cmd == "hurt" or cmd == "hurt1" then
  1669. round = 1
  1670. if buffer.round and buffer.round > 0 then
  1671. round = buffer.round
  1672. end
  1673. baseValue = baseValue + buffer.arg * round
  1674. local bufferCnt = delBuffer(target, j)
  1675. CombatImpl.addFrameBuffer(target,buffer,CombatDefine.BUFFER_OP_DEL)
  1676. end
  1677. end
  1678. return baseValue
  1679. end
  1680. --解控
  1681. function jiekong(target)
  1682. if target.hp <= 0 then
  1683. return 0
  1684. end
  1685. local baseValue = 0
  1686. local state = false
  1687. for j = target.buffer[0], 1, -1 do
  1688. local buffer = target.buffer[j]
  1689. --local conf = BufferExcel.buffer[buffer.id]
  1690. local conf = GetBuffConfig(buffer.id)
  1691. local cmd = conf.cmd
  1692. if isControlCmd(cmd) then
  1693. local bufferCnt = delBuffer(target, j)
  1694. CombatImpl.addFrameBuffer(target,buffer,CombatDefine.BUFFER_OP_DEL)
  1695. state = true
  1696. end
  1697. end
  1698. if state == true then
  1699. CombatImpl.setExtraHit(target,nil, Skill.getCMD2ID("jiekong"))
  1700. end
  1701. end
  1702. --杀意
  1703. function delShayi(target)
  1704. if target.hp <= 0 then
  1705. return 0
  1706. end
  1707. for j = target.buffer[0], 1, -1 do
  1708. local buffer = target.buffer[j]
  1709. --local conf = BufferExcel.buffer[buffer.id]
  1710. local conf = GetBuffConfig(buffer.id)
  1711. local cmd = conf.cmd
  1712. if cmd == "shayi" then
  1713. local bufferCnt = delBuffer(target, j)
  1714. CombatImpl.addFrameBuffer(target,buffer,CombatDefine.BUFFER_OP_DEL)
  1715. end
  1716. end
  1717. end
  1718. function getBuffCnt(target,checkCmd)
  1719. if target.hp <= 0 then
  1720. return 0
  1721. end
  1722. local cnt = 0
  1723. for j = target.buffer[0], 1, -1 do
  1724. local buffer = target.buffer[j]
  1725. --local conf = BufferExcel.buffer[buffer.id]
  1726. local conf = GetBuffConfig(buffer.id)
  1727. local cmd = conf.cmd
  1728. if cmd == checkCmd then
  1729. cnt = cnt + 1
  1730. end
  1731. end
  1732. return cnt
  1733. end
  1734. -- 获取护盾值
  1735. function getBuffHuDun(obj)
  1736. if obj and obj.bufferAttr and obj.bufferAttr[RoleDefine.HUDUN_COMBAT] then
  1737. return obj.bufferAttr[RoleDefine.HUDUN_COMBAT]
  1738. end
  1739. return 0
  1740. end
  1741. -- 护盾值的修改
  1742. function updateHuDun(obj, value)
  1743. if obj and obj.bufferAttr then
  1744. local oldValue = obj.bufferAttr[RoleDefine.HUDUN_COMBAT] or 0
  1745. local newValue = oldValue + value
  1746. if newValue <= 0 then
  1747. obj.bufferAttr[RoleDefine.HUDUN_COMBAT] = 0
  1748. delBufferByCmd(obj,"hudun", 0)
  1749. else
  1750. obj.bufferAttr[RoleDefine.HUDUN_COMBAT] = newValue
  1751. end
  1752. -- 护盾值没有全部去除 则 在对应英雄上吧 BUF 上的arg 数值 减除 防止 BufChange 重置 属性
  1753. if value < 0 and newValue > 0 then
  1754. if obj and obj.buffer then
  1755. for j = 1 , obj.buffer[0] do -- 从最早的护盾BUF中删除arg
  1756. local buffer = obj.buffer[j]
  1757. --local conf = BufferExcel.buffer[buffer.id]
  1758. local conf = GetBuffConfig(buffer.id)
  1759. local bufferCmd = conf.cmd
  1760. if bufferCmd == "hudun" then
  1761. local have = buffer.arg
  1762. if have > -value then
  1763. buffer.arg = have + value
  1764. else
  1765. buffer.arg = 0
  1766. local bufferCnt = delBuffer(obj, j)
  1767. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_DEL)
  1768. break
  1769. end
  1770. end
  1771. end
  1772. end
  1773. end
  1774. end
  1775. end
  1776. BUFFER_COMBAT_TYPE = nil
  1777. function initCombatBufferType()
  1778. if BUFFER_COMBAT_TYPE then return end
  1779. BUFFER_COMBAT_TYPE = {}
  1780. for k,conf in pairs(BufferExcel.qusan) do
  1781. if conf then
  1782. BUFFER_COMBAT_TYPE[conf.buffcmd] = conf.type
  1783. end
  1784. end
  1785. end
  1786. --
  1787. function getCombatBufferCnt(target, qusanType)
  1788. initCombatBufferType()
  1789. local buffCnt = 0
  1790. for i = target.buffer[0], 1, -1 do
  1791. local buffer = target.buffer[i]
  1792. --local conf = BufferExcel.buffer[buffer.id]
  1793. local conf = GetBuffConfig(buffer.id)
  1794. local cmd = conf.cmd
  1795. if conf.skillbufftype == 1 and BUFFER_COMBAT_TYPE[cmd] and BUFFER_COMBAT_TYPE[cmd] == qusanType then
  1796. buffCnt = buffCnt + 1
  1797. end
  1798. end
  1799. return buffCnt
  1800. end
  1801. --抵抗
  1802. QUSAN_CMD2KEY = {
  1803. ["zuzhou"] = RoleDefine.STATUS_DIKANG_RATE9,
  1804. }
  1805. function qusan(target, qusanType,cnt)
  1806. if target.isPet or not qusanType then
  1807. return 0
  1808. end
  1809. initCombatBufferType()
  1810. local state = false
  1811. local delIndex = {}
  1812. for i = target.buffer[0], 1, -1 do
  1813. local buffer = target.buffer[i]
  1814. --local conf = BufferExcel.buffer[buffer.id]
  1815. local conf = GetBuffConfig(buffer.id)
  1816. local cmd = conf.cmd
  1817. if conf.noQusan ~= 1 then
  1818. if BUFFER_COMBAT_TYPE[cmd] and BUFFER_COMBAT_TYPE[cmd] == qusanType then
  1819. local isDiKang = nil
  1820. local key = QUSAN_CMD2KEY[cmd]
  1821. local r = math.random(1,10000)
  1822. if key and target.attr[key] >= r then
  1823. isDiKang = true
  1824. end
  1825. if not isDiKang then
  1826. delIndex[#delIndex + 1] = i
  1827. end
  1828. elseif cmd == "attr" or cmd == "attrdne" then
  1829. if conf.args and conf.args[1][2] < 0 and qusanType == 1 then
  1830. delIndex[#delIndex + 1] = i
  1831. elseif conf.args and conf.args[1][2] > 0 and qusanType == 2 then
  1832. delIndex[#delIndex + 1] = i
  1833. end
  1834. end
  1835. end
  1836. end
  1837. cnt = cnt or 0
  1838. if cnt > 0 and cnt < #delIndex then
  1839. for i = cnt + 1,#delIndex do
  1840. delIndex[i] = nil
  1841. end
  1842. end
  1843. for k,v in ipairs(delIndex) do
  1844. local buffer = target.buffer[v]
  1845. if not buffer then break end
  1846. local bufferCnt = delBuffer(target, v)
  1847. CombatImpl.addFrameBuffer(target,buffer,CombatDefine.BUFFER_OP_DEL)
  1848. end
  1849. return #delIndex
  1850. end
  1851. function qusanAddBuff(attacker, targets, bufferID)
  1852. for _,target in ipairs(targets) do
  1853. if canAdd(target,bufferID) then
  1854. addBuffer(attacker.pos, target, bufferID)
  1855. end
  1856. end
  1857. end
  1858. function beforeUpdateHp(obj,sum)
  1859. local isStatus,cmd,ind = isStatus(obj,{"miansi","waitMiansi"})
  1860. if not isStatus then
  1861. return
  1862. end
  1863. --免死逻辑
  1864. if cmd == "miansi" then
  1865. return true
  1866. end
  1867. if sum == 0 and cmd == "waitMiansi" then
  1868. local buffer = obj.buffer[ind]
  1869. local bufferCnt = delBuffer(obj, ind)
  1870. CombatImpl.addFrameBuffer(obj,buffer,CombatDefine.BUFFER_OP_DEL)
  1871. --local conf = BufferExcel.buffer[buffer.id]
  1872. local conf = GetBuffConfig(buffer.id)
  1873. local bufferID = conf.args[1]
  1874. if canAdd(obj,bufferID) then
  1875. addBuffer(obj.pos,obj, bufferID)
  1876. end
  1877. return true
  1878. end
  1879. end
  1880. function checkBaohu(obj,value)
  1881. local isStatus,cmd,ind = isStatus(obj,{"baohu"})
  1882. if not isStatus then
  1883. return value
  1884. end
  1885. local buffer = obj.buffer[ind]
  1886. local attackPos = buffer.attackPos
  1887. local attacker = CombatImpl.objList[attackPos]
  1888. if attacker.hp <= 0 then
  1889. return value
  1890. end
  1891. value = BeSkill.onCheckBuffer(attacker,obj,value)
  1892. return value
  1893. end
  1894. function onExtraCombatRecord(pos,value,param)
  1895. local obj = CombatObj.getObjByPos(pos)
  1896. if not obj then return end
  1897. obj.extraCombatRecord = obj.extraCombatRecord or {}
  1898. if param == "zhongdu" then
  1899. obj.extraCombatRecord.zhongdu = (obj.extraCombatRecord.zhongdu or 0) + value
  1900. elseif param == "liuxue" then
  1901. obj.extraCombatRecord.liuxue = (obj.extraCombatRecord.liuxue or 0) + value
  1902. elseif param == "ranshao" then
  1903. obj.extraCombatRecord.ranshao = (obj.extraCombatRecord.ranshao or 0) + value
  1904. elseif param == "xuanyun" or param == "xuanyun2" then
  1905. obj.extraCombatRecord.xuanyun = (obj.extraCombatRecord.xuanyun or 0) + value
  1906. elseif param == "revive" then
  1907. obj.extraCombatRecord.revive = (obj.extraCombatRecord.revive or 0) + value
  1908. elseif param == "reviveBeUse" then
  1909. obj.extraCombatRecord.reviveBeUse = (obj.extraCombatRecord.reviveBeUse or 0) + value
  1910. elseif param == "kill" then
  1911. obj.extraCombatRecord.kill = (obj.extraCombatRecord.kill or 0) + value
  1912. elseif param == "chenshui" then
  1913. obj.extraCombatRecord.kchenshuiill = (obj.extraCombatRecord.chenshui or 0) + value
  1914. end
  1915. end