CombatBuff.lua 80 KB

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