CombatBuff.lua 80 KB

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