CombatBuff.lua 79 KB

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