CombatBuff.lua 65 KB

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