CombatBuff.lua 66 KB

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