CombatBuff.lua 65 KB

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