CombatLogic.lua 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804
  1. ----------------------------------
  2. -- 战斗逻辑
  3. -- combatBegin 开始战斗
  4. -- createCombatFakeHuman 根据uuid创角战斗human
  5. -- fight 战斗开始前各模块自己的判断函数,成功调用CombatLogic.combatBegin()
  6. -- onFightBegin 战斗帧计算前的属性重新计算
  7. -- onFightEnd 战斗结束回调,发送GC_COMBAT_FINISH前
  8. -- checkCombatPos 可否打开上阵界面(默认可打开)
  9. -- 获取双方上阵对象信息
  10. -- getCombatMonsterOutID 获取上阵怪物组id
  11. -- getCombatTarget 获取上阵human信息
  12. -- getCombatObjList 获取上阵队伍列表
  13. ----------------------------------
  14. local CombatExcel = require("excel.combat")
  15. local MonsterExcel = require("excel.monster")
  16. local HeroExcel = require("excel.hero")
  17. local SkillExcel = require("excel.skill")
  18. local BufferExcel = require("excel.buffer")
  19. local Config = require("Config")
  20. local Util = require("common.Util")
  21. local Lang = require("common.Lang")
  22. local Log = require("common.Log")
  23. local Msg = require("core.Msg")
  24. local ObjHuman = require("core.ObjHuman")
  25. local Grid = require("bag.Grid")
  26. local Broadcast = require("broadcast.Broadcast")
  27. local BeSkill = require("combat.BeSkill")
  28. local CombatObj = require("combat.CombatObj")
  29. local CombatImpl = require("combat.CombatImpl")
  30. local CombatDefine = require("combat.CombatDefine")
  31. local CombatPosLogic = require("combat.CombatPosLogic")
  32. local CombatPetCalc = require("combat.CombatPetCalc")
  33. local MoshouLogic = require("moshou.MoshouLogic")
  34. local RoleDBLogic = require("role.RoleDBLogic")
  35. local RoleAttr = require("role.RoleAttr")
  36. local RoleDefine = require("role.RoleDefine")
  37. local RoleLogic = require("role.RoleLogic")
  38. local HeroGrid = require("hero.HeroGrid")
  39. local DrillLogic = require("drill.DrillLogic")
  40. local SkinLogic = require("skin.SkinLogic")
  41. local BeginStory = require("scene.BeginStory")
  42. local Skill = require("combat.Skill")
  43. local CombatPosExcel = require("excel.combatPos")
  44. local ValleyLogic = require("valley.ValleyLogic")
  45. local LianyuLogic = require("lianyu.LianyuLogic")
  46. local TheStarsLogic = require("theStars.TheStarsLogic")
  47. local HeroDefine = require("hero.HeroDefine")
  48. local JibanLogic = require("combat.JibanLogic")
  49. local EquipLogic = require("equip.EquipLogic")
  50. local ItemDefine = require("bag.ItemDefine")
  51. local HeroLogic = require("hero.HeroLogic")
  52. local XingYaoGongMing = require("xingYaoMen.XingYaoGongMing")
  53. local MoshouLogic = require("moshou.MoshouLogic")
  54. local LostTempleCombatLogic = require("lostTemple.lostTempleCombatLogic")
  55. local SkinExcel = require("excel.skin")
  56. local BattleLogic = require("battle.BattleLogic")
  57. FieldsCombat = {
  58. lv = 1, name = 1, head = 1, headFrame = 1, unionUuid = 1, lastLogoutTime = 1,
  59. combatHero = 1, heroBag = 1, moshou = 1, technology=1, chengjiu=1,
  60. }
  61. COMBAT_CACHE = COMBAT_CACHE or {}
  62. ------------------------------------------- 模块相关 start -------------------------------------------------
  63. -- 初始
  64. COMBATTYPE_2_MODULE = COMBATTYPE_2_MODULE or {}
  65. function init()
  66. for combatType, cf in pairs(CombatExcel.combat) do
  67. if cf.moduleFn ~= "" then
  68. local moduleFn = load("return require(\""..cf.moduleFn.."\")")()
  69. COMBATTYPE_2_MODULE[combatType] = moduleFn
  70. end
  71. end
  72. end
  73. -- 获取模块
  74. function getModule(combatType)
  75. if not combatType then return end
  76. return COMBATTYPE_2_MODULE[combatType]
  77. end
  78. -- 获取攻/守方怪物组id
  79. local function getCombatMonsterOutID(human, side, combatType, args)
  80. local moduleFn = getModule(combatType)
  81. if moduleFn and moduleFn.getCombatMonsterOutID then
  82. return moduleFn.getCombatMonsterOutID(human, side, args, combatType)
  83. end
  84. end
  85. -- 获取攻/守方怪物组id
  86. function getMapID(human, combatType, param)
  87. local moduleFn = getModule(combatType)
  88. local mapID = nil
  89. if moduleFn and moduleFn.getMapID then
  90. mapID = moduleFn.getMapID(human, param)
  91. end
  92. if not mapID then
  93. local config = CombatExcel.combat[combatType]
  94. mapID = config.mapID == 0 and 1001 or config.mapID
  95. end
  96. return mapID
  97. end
  98. -- 获取是否跳过
  99. function getQuick(human, combatType)
  100. local config = CombatExcel.combat[combatType]
  101. local moduleFn = getModule(combatType)
  102. local quick = nil
  103. if moduleFn and moduleFn.getQuick then
  104. quick = moduleFn.getQuick(human, combatType)
  105. end
  106. if quick ~= nil and quick >= 0 then
  107. return quick
  108. end
  109. if human.db.combatQuick[combatType] and human.db.combatQuick[combatType] ~= 0 then
  110. if config.isQuick == 0 then
  111. human.db.combatQuick[combatType] = 0
  112. end
  113. end
  114. return config.isQuick
  115. end
  116. -- 获取攻/守方对象
  117. local function getCombatTarget(human, side, combatType, args)
  118. local moduleFn = getModule(combatType)
  119. if moduleFn and moduleFn.getCombatTarget then
  120. return moduleFn.getCombatTarget(human, side, args, combatType)
  121. end
  122. end
  123. --更新上阵信息回调
  124. function onUpdatePos(human,combatType)
  125. local moduleFn = getModule(combatType)
  126. if moduleFn and moduleFn.onUpdatePos then
  127. return moduleFn.onUpdatePos(human)
  128. end
  129. end
  130. -- 获取攻/守方上阵信息
  131. function getCombatObjList(human, side, combatType, args)
  132. if type(args) == "table" then
  133. if side == CombatDefine.ATTACK_SIDE then
  134. if args.attacker then
  135. return args.attacker, args.atkHelp, args.atkRBase, args.atkFormation,args.atkJiban
  136. end
  137. else
  138. if args.defender then
  139. return args.defender, args.defHelp, args.defRBase, args.defFormation,args.defJiban
  140. end
  141. end
  142. end
  143. local moduleFn = getModule(combatType)
  144. if not moduleFn then return end
  145. if moduleFn.getCombatObjList then
  146. local objList, helpList, rolebase, formation,jiban = moduleFn.getCombatObjList(human, side, args, combatType)
  147. if objList then
  148. return objList, helpList, rolebase ,formation,jiban
  149. end
  150. end
  151. local monsterOutID, zhandouli = getCombatMonsterOutID(human, side, combatType, args)
  152. if monsterOutID then
  153. local objList, helpList, rolebase, formation, jiban = getMonsterObjList(monsterOutID, nil, args)
  154. if zhandouli then
  155. rolebase.zhandouli = zhandouli
  156. end
  157. return objList, helpList, rolebase,formation,jiban
  158. end
  159. if moduleFn.getHumanObjList then
  160. return moduleFn.getHumanObjList(human, combatType)
  161. end
  162. local target = getCombatTarget(human, side, combatType, args)
  163. if target then
  164. return getHumanObjList(target, combatType)
  165. end
  166. if side == CombatDefine.ATTACK_SIDE then -- 没有模块没有特写,攻防默认取自身上阵信息
  167. return getHumanObjList(human, combatType)
  168. end
  169. end
  170. --获取战斗最大回合数
  171. local function getMaxRound(human,combatType)
  172. local config = CombatExcel.combat[combatType]
  173. if config and config.maxRound and config.maxRound > 0 then
  174. return config.maxRound
  175. end
  176. return CombatDefine.COMBAT_ROUND_MAX
  177. end
  178. --获取战斗模式
  179. local function getFightMode(combatType)
  180. local config = CombatExcel.combat[combatType]
  181. if config.fightMode[1] == CombatDefine.FIGHT_MODE1 or config.fightMode[1] == CombatDefine.FIGHT_MODE3 then
  182. return config.fightMode
  183. end
  184. end
  185. -- 尝试战斗
  186. function tryCombatBegin(human, combatType, param)
  187. local moduleFn = getModule(combatType)
  188. if moduleFn and moduleFn.fight then
  189. local args = Util.split(param, "|")
  190. return moduleFn.fight(human, args, combatType)
  191. end
  192. end
  193. -- 可否打开上阵界面
  194. function checkCombatPos(human, combatType, args)
  195. local moduleFn = getModule(combatType)
  196. if moduleFn and moduleFn.checkCombatPos then
  197. return moduleFn.checkCombatPos(human, args, combatType)
  198. end
  199. return true
  200. end
  201. -- 战斗结束回调 在发送GC_COMBAT_FINISH前
  202. local function onFightEnd(human, result, combatType, cbParam, combatInfo, isSaodang,param)
  203. local moduleFn = getModule(combatType)
  204. if not moduleFn then return end
  205. if not moduleFn.onFightEnd then return end
  206. moduleFn.onFightEnd(human, result, combatType, cbParam, combatInfo, isSaodang,param)
  207. end
  208. -- 战斗名称
  209. function getCombatName(human, combatType, args)
  210. local moduleFn = getModule(combatType)
  211. if not moduleFn then return "" end
  212. if not moduleFn.getCombatName then return "" end
  213. return moduleFn.getCombatName(human, args, combatType) or ""
  214. end
  215. ------------------------------------------- 模块相关 end -------------------------------------------------
  216. -- 判断阵容是不是为空
  217. function isCombatHeroEmpty(combatHero)
  218. if not combatHero then return true end
  219. local isEmpty = true
  220. for _, heroUuid in pairs(combatHero) do
  221. if heroUuid and heroUuid ~= "" and heroUuid ~= "0" then
  222. isEmpty = nil
  223. break
  224. end
  225. end
  226. return isEmpty
  227. end
  228. -- 根据阵营和下标获取对战位置
  229. function getPos(side, index)
  230. if side == CombatDefine.ATTACK_SIDE then
  231. return index
  232. elseif side == CombatDefine.DEFEND_SIDE then
  233. return index + CombatDefine.COMBAT_HERO_CNT
  234. else
  235. assert()
  236. end
  237. end
  238. function getIndexByPos(side, pos)
  239. if side == CombatDefine.ATTACK_SIDE then
  240. return pos
  241. elseif side == CombatDefine.DEFEND_SIDE then
  242. return pos - CombatDefine.COMBAT_HERO_CNT
  243. end
  244. end
  245. -- 获取对象配置
  246. function getConfigByObj(obj)
  247. if not obj then return end
  248. local id = obj.id or obj.heroID
  249. if obj.type == CombatDefine.COMBAT_OBJ_TYPE1 then
  250. return HeroExcel.hero[id]
  251. end
  252. return MonsterExcel.monster[id]
  253. end
  254. -- 创建战斗Human
  255. function createCombatFakeHuman(uuid)
  256. if not uuid then return end
  257. local db = RoleDBLogic.getDb(uuid, FieldsCombat)
  258. if not db then return end
  259. local fakeHuman = {}
  260. fakeHuman.db = db
  261. return fakeHuman
  262. end
  263. -- 创建初始角色信息
  264. function createRoleBaseDefault()
  265. local rolebase = {}
  266. RoleLogic.makeRoleBase(nil, rolebase, nil, true)
  267. rolebase.name = Lang.COMBAT_DEFEND_NAME
  268. return rolebase
  269. end
  270. -- 根据怪物信息创建角色信息
  271. function createRoleBaseByMOutID(monsterOutID, zhandouli, args)
  272. local _, monsterConfig, monsterLv = getMonsterIDByOutID(monsterOutID, args)
  273. local rolebase = createRoleBaseDefault()
  274. if monsterConfig then
  275. rolebase.name = monsterConfig.name
  276. rolebase.lv = monsterLv or 1
  277. rolebase.head = monsterConfig.head
  278. rolebase.zhandouli = zhandouli or 0
  279. end
  280. return rolebase
  281. end
  282. -- 创建角色信息
  283. function createRoleBaseByDB(db, zhandouli)
  284. local rolebase = {}
  285. RoleLogic.makeRoleBase(db, rolebase, nil, true)
  286. rolebase.zhandouli = zhandouli or 0
  287. return rolebase
  288. end
  289. -- 根据怪物表信息创建临时对象
  290. function createMonsterObj(id, lv, attrID, index, objType, monsterOutConfig, attrInput)
  291. local monsterConfig = MonsterExcel.monster[id]
  292. if not monsterConfig then return end
  293. local obj = {}
  294. obj.type = objType or CombatDefine.COMBAT_OBJ_TYPE2
  295. obj.bagIndex = index
  296. obj.id = id
  297. obj.lv = lv
  298. obj.job = monsterConfig.job
  299. obj.quality = 6
  300. obj.star = monsterConfig.star
  301. obj.head = monsterConfig.head
  302. obj.body = monsterConfig.body
  303. obj.camp = monsterConfig.camp
  304. obj.sex = monsterConfig.sex
  305. BeSkill.initBeSkill(obj)
  306. BeSkill.setBeSkill(obj, monsterConfig, nil, monsterOutConfig)
  307. Skill.setSkill(obj, monsterConfig)
  308. obj.attrs = RoleAttr.calcMonsterConf(id, attrID, attrInput)
  309. return obj
  310. end
  311. -- 根据英雄ID信息创建临时对象
  312. function createHeroObjByID(heroId, lv, star, quality, index)
  313. local heroConfig = HeroExcel.hero[heroId]
  314. if not heroConfig then return end
  315. local obj = {}
  316. obj.type = CombatDefine.COMBAT_OBJ_TYPE1
  317. obj.bagIndex = index
  318. obj.id = heroId
  319. obj.lv = lv
  320. obj.job = heroConfig.job
  321. obj.quality = quality and quality or HeroGrid.getMaxQuality(star)
  322. obj.star = star
  323. obj.body = heroConfig.body
  324. obj.head = heroConfig.head
  325. local attrConfig = HeroDefine.getAttrConfig(obj.id, obj.star)
  326. BeSkill.initBeSkill(obj)
  327. Skill.setSkill(obj, attrConfig)
  328. BeSkill.setBeSkill(obj, attrConfig)
  329. obj.attrs = Util.copyTable(RoleAttr.calcHeroGrid(obj, index))
  330. obj.zhandouli = obj.attrs[RoleDefine.ZHANDOULI]
  331. return obj
  332. end
  333. -- 根据英雄表信息创建临时对象
  334. function createHeroObj(human, heroId, lv, star, index,skin)
  335. local heroConfig = HeroExcel.hero[heroId]
  336. local skinCfg = skin and SkinExcel.skin[skin]
  337. if not heroConfig then return end
  338. local obj = {}
  339. obj.type = CombatDefine.COMBAT_OBJ_TYPE1
  340. obj.bagIndex = index
  341. obj.id = heroId
  342. obj.lv = lv
  343. obj.job = heroConfig.job
  344. obj.quality = HeroGrid.getMaxQuality(star)
  345. obj.star = star
  346. obj.body = skinCfg and skinCfg.body --or heroConfig.body
  347. obj.head = skinCfg and skinCfg.head --or heroConfig.head
  348. if not obj.body or obj.body == 0 then
  349. obj.body = heroConfig.body
  350. end
  351. if not obj.head or obj.head == 0 then
  352. obj.head = heroConfig.head
  353. end
  354. local attrConfig = HeroDefine.getAttrConfig(obj.id, obj.star)
  355. BeSkill.initBeSkill(obj)
  356. if not SkinLogic.setSkill(human,index,attrConfig,obj) then
  357. Skill.setSkill(obj, attrConfig)
  358. BeSkill.setBeSkill(obj, attrConfig)
  359. end
  360. obj.attrs = Util.copyTable(RoleAttr.calcHeroGrid(obj, index, human))
  361. obj.zhandouli = obj.attrs[RoleDefine.ZHANDOULI]
  362. return obj
  363. end
  364. function createHeroObjByHeroGrid(human, heroGrid)
  365. local heroConfig = HeroExcel.hero[heroGrid.id]
  366. if not heroConfig then return end
  367. local obj = {}
  368. obj.type = CombatDefine.COMBAT_OBJ_TYPE1
  369. obj.bagIndex = heroGrid.bagIndex
  370. obj.uuid = heroGrid.uuid
  371. obj.id = heroGrid.id
  372. obj.lv = heroGrid.lv
  373. obj.job = heroConfig.job
  374. obj.quality = heroGrid.quality
  375. obj.star = heroGrid.star -- dxzeng 取db star
  376. obj.fuwen = Util.copyTable(heroGrid.fuwen)
  377. obj.bingshu = Util.copyTable(heroGrid.bingshu)
  378. obj.body, obj.head = SkinLogic.getBody(human, obj.bagIndex)
  379. obj.camp = heroConfig.camp
  380. obj.isGongMing = XingYaoGongMing.isGongMing(human, heroGrid.bagIndex)
  381. obj.sex = heroConfig.sex
  382. local attrConfig = HeroDefine.getAttrConfig(obj.id, obj.star)
  383. BeSkill.initBeSkill(obj)
  384. if not SkinLogic.setSkill(human,obj.bagIndex,attrConfig,obj) then
  385. Skill.setSkill(obj, attrConfig)
  386. BeSkill.setBeSkill(obj, attrConfig)
  387. end
  388. if heroGrid.isLostTemple then
  389. obj.attrs = Util.copyTable(LostTempleCombatLogic.getHeroAttrs(human, heroGrid.bagIndex))
  390. else
  391. obj.attrs = Util.copyTable(ObjHuman.getHeroAttrs(human, obj.bagIndex))
  392. end
  393. obj.zhandouli = obj.attrs[RoleDefine.ZHANDOULI]
  394. return obj
  395. end
  396. -- 根据英雄背包创建临时对象
  397. function createHumanObj(human, uuid)
  398. if not uuid then return end
  399. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  400. if not heroGrid or type(heroGrid) ~= "table" then return end
  401. return createHeroObjByHeroGrid(human, heroGrid)
  402. end
  403. -- 根据怪物组id获取出战英雄列表
  404. function getMonsterObjList(monsterOutID, objType, args)
  405. if not monsterOutID then return end
  406. local monsterOutConfig = MonsterExcel.monsterOut[monsterOutID]
  407. if not monsterOutConfig then return end
  408. local formation = monsterOutConfig.formation
  409. if formation == 0 then
  410. formation = 1
  411. end
  412. local mationConfig = CombatPosExcel.formation[formation]
  413. local posList = mationConfig.pos
  414. if not posList then return end
  415. local objList = nil
  416. local zhandouli = 0
  417. for i, member in ipairs(monsterOutConfig.member) do
  418. local monsterID = member[1]
  419. local monsterConfig = MonsterExcel.monster[monsterID]
  420. if posList[i] then
  421. local monsterLv = member[2]
  422. local attrID = monsterOutConfig.attrID[i]
  423. local attrInput = nil
  424. if monsterOutConfig.combatType == CombatDefine.COMBAT_TYPE5 then
  425. if args then
  426. local throneID = args[1]
  427. local evolveCnt = args[2]
  428. monsterLv, attrInput = TheStarsLogic.getMonsterLvAttr(i, throneID, evolveCnt)
  429. end
  430. end
  431. local obj = createMonsterObj(monsterID, monsterLv, attrID, i, objType, monsterOutConfig.beSkill[i], attrInput)
  432. if obj then
  433. zhandouli = zhandouli + obj.attrs[RoleDefine.ZHANDOULI]
  434. objList = objList or {}
  435. local pos = posList[i]
  436. if monsterOutConfig.combatType == CombatDefine.COMBAT_TYPE10 then
  437. pos = 5
  438. end
  439. objList[pos] = obj
  440. end
  441. end
  442. end
  443. if not objList then
  444. assert(nil, "getMonsterObjList is nil, monsterOutID = " .. monsterOutID)
  445. end
  446. local rolebase = createRoleBaseByMOutID(monsterOutID, zhandouli, args)
  447. local jiban = nil -- todo 怪物的羁绊
  448. return objList, nil, rolebase,formation,jiban
  449. end
  450. -- 获取human出战英雄列表 objList, helpList, rolebase, formation
  451. function getHumanObjList(human, combatType)
  452. local teamType = CombatPosLogic.getTeamType(combatType)
  453. if not teamType then return end
  454. local combatHero, _, formation,combatHeroDB = CombatPosLogic.getCombatHeros(human, combatType)
  455. if not combatHero then return end
  456. if formation == 0 then
  457. formation = 1
  458. end
  459. local jiban = JibanLogic.getJibanHero(human,combatHeroDB)
  460. local objList = {}
  461. local zhandouli = 0
  462. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  463. local uuid = combatHero[i]
  464. local obj = createHumanObj(human, uuid)
  465. if obj then
  466. zhandouli = zhandouli + obj.attrs[RoleDefine.ZHANDOULI]
  467. objList[i] = obj
  468. end
  469. end
  470. local helpList = {}
  471. local pet = MoshouLogic.createCombatMoshow(human,combatType)
  472. helpList[CombatDefine.HELP_TYPE1] = pet
  473. local rolebase = createRoleBaseByDB(human.db, zhandouli)
  474. return objList, helpList, rolebase,formation,jiban
  475. end
  476. ---------------------------------------------- msg -----------------------------------------------
  477. -- 封装对战英雄信息
  478. local function fontCombatHeroNet(net, obj)
  479. local config = getConfigByObj(obj)
  480. if not config then return end
  481. net.pos = obj.pos
  482. net.heroID = obj.id
  483. net.star = obj.star
  484. net.lv = obj.lv or 0
  485. net.body = obj.body or config.body
  486. net.hpMax = CombatObj.getHpMax(obj)
  487. net.hpNow = obj.initHp
  488. net.icon = config.head
  489. net.width = config.width
  490. net.height = config.height
  491. net.camp = config.camp
  492. net.name = config.name
  493. net.posX = CombatDefine.DEFAULT_POS_SIZE[obj.pos][1]
  494. net.posY = CombatDefine.DEFAULT_POS_SIZE[obj.pos][2]
  495. net.size = CombatDefine.DEFAULT_POS_SIZE[obj.pos][3]
  496. net.isBoss = 0
  497. net.isGongMing = obj.isGongMing or 0
  498. net.grade = config.grade or 0
  499. local len = 0
  500. for _,v in pairs(obj.skillList) do
  501. if SkillExcel.skill[v[1]].contentType == 3 then
  502. len = len + 1
  503. net.sayList[len] = v[1]
  504. end
  505. end
  506. for _,v in pairs(obj.beSkillList) do
  507. for _,v1 in ipairs(v) do
  508. if SkillExcel.skill[v1[1]].contentType == 3 then
  509. len = len + 1
  510. net.sayList[len] = v1[1]
  511. end
  512. end
  513. end
  514. net.sayList[0] = len
  515. return true
  516. end
  517. -- 封装辅助对象
  518. function fontCombatHelpNet(net, help)
  519. net.pos = help.pos
  520. net.id = help.id or 0
  521. net.head = help.head or 0
  522. net.body = help.body or 0
  523. net.skill[0] = 0
  524. local skillConfig = SkillExcel.skill[help.icon]
  525. if skillConfig then
  526. net.skill[1].id = help.icon
  527. net.skill[1].icon = skillConfig.icon
  528. net.skill[1].name = skillConfig.name
  529. net.skill[1].desc = skillConfig.desc
  530. net.skill[1].lv = help.skillLV or 0
  531. net.skill[1].index = 0
  532. net.skill[1].state = 2
  533. net.skill[0] = 1
  534. end
  535. net.args[0] = 0
  536. if help.clientArgs then
  537. local len = 0
  538. for k,v in ipairs(help.clientArgs) do
  539. len = len + 1
  540. net.args[len] = v
  541. end
  542. net.args[0] = len
  543. end
  544. return true
  545. end
  546. -- 封装战斗技能信息
  547. function fontCombatSkillNet(skillNet, skillID)
  548. local skillConfig = SkillExcel.skill[skillID]
  549. if not skillConfig then return end
  550. skillNet.skillID = skillID
  551. skillNet.fireType = skillConfig.fireType
  552. skillNet.readyAction = skillConfig.readyAction
  553. skillNet.attackPart = skillConfig.attackPart
  554. skillNet.attackAction = skillConfig.attackAction
  555. skillNet.readyEffect = skillConfig.readyEffect
  556. skillNet.attackEffect = skillConfig.attackEffect
  557. skillNet.hitEffect = skillConfig.hitEffect
  558. skillNet.flyEffect = skillConfig.flyEffect
  559. skillNet.flyCoords = skillConfig.flyCoords
  560. skillNet.hitBack = skillConfig.hitBack
  561. skillNet.effectTime = skillConfig.effectTime
  562. skillNet.contentType = skillConfig.contentType
  563. skillNet.content = skillConfig.content
  564. skillNet.movieEffect = skillConfig.movieEffect
  565. skillNet.quake = skillConfig.quake
  566. skillNet.flySound = skillConfig.flySound
  567. skillNet.fireSound = skillConfig.fireSound
  568. skillNet.hitSound = skillConfig.hitSound
  569. skillNet.cvSound = skillConfig.cvSound
  570. skillNet.screenMask = skillConfig.screenMask
  571. skillNet.screenCam = skillConfig.screenCam
  572. skillNet.largeEffect = skillConfig.largeEffect
  573. skillNet.lie = skillConfig.lie
  574. skillNet.cuoZhen = skillConfig.cuoZhen
  575. skillNet.skillDelay = skillConfig.skillDelay
  576. skillNet.isFraming = skillConfig.isFraming
  577. return true
  578. end
  579. -- 封装技能cmd
  580. local function fontSkillCmd(cmdNet, cmd)
  581. local cmdConfig = SkillExcel.cmd[cmd]
  582. if not cmdConfig then return end
  583. cmdNet.cmd = cmd
  584. cmdNet.hitEffect = cmdConfig.hitEffect
  585. cmdNet.hitSound = cmdConfig.hitSound
  586. return true
  587. end
  588. -- 封装buff
  589. local function fontBufferNet(bufferNet, bufferID)
  590. local bufferConf = BufferExcel.buffer[bufferID]
  591. if not bufferConf then return end
  592. bufferNet.bufferID = bufferID
  593. bufferNet.name = bufferConf.name
  594. bufferNet.desc = bufferConf.desc
  595. bufferNet.icon = bufferConf.icon
  596. bufferNet.keepEffect = bufferConf.keepEffect
  597. bufferNet.hitEffect = bufferConf.hitEffect
  598. bufferNet.validateEffect = bufferConf.validateEffect
  599. bufferNet.dieEffect = bufferConf.dieEffect
  600. bufferNet.cmd = bufferConf.cmd
  601. bufferNet.hitSound = bufferConf.hitSound
  602. bufferNet.holdOnDie = bufferConf.holdOnDie
  603. bufferNet.effectOffset = bufferConf.effectOffset
  604. bufferNet.canAppend = bufferConf.canAppend
  605. bufferNet.appendCnt = bufferConf.appendCnt
  606. return true
  607. end
  608. -- 封装阵法属性
  609. local function fontCombatPosAttr(attrNets, attrs)
  610. attrNets[0] = 0
  611. if type(attrs) ~= "table" then return end
  612. for key, value in pairs(attrs) do
  613. attrNets[0] = attrNets[0] + 1
  614. local attrNet = attrNets[attrNets[0]]
  615. attrNet.key = key
  616. attrNet.value = value
  617. end
  618. end
  619. -- 发送战斗开始
  620. local function sendCombatBegin(human, combatInfo, isLogin)
  621. combatInfo = combatInfo or human.combat
  622. if not combatInfo then return end
  623. local msgRet = Msg.gc.GC_COMBAT_BEGIN
  624. msgRet.isLogin = isLogin == true and 1 or 0
  625. msgRet.combatType = combatInfo.type
  626. local keepTime = os.time() - combatInfo.time
  627. if combatInfo.passTime < keepTime then
  628. combatInfo.passTime = keepTime
  629. end
  630. msgRet.keepTime = combatInfo.passTime
  631. if combatInfo.isVideo then -- 录像回放
  632. msgRet.keepTime = 0
  633. end
  634. local isCanQuick = getQuick(human, combatInfo.type)
  635. msgRet.isQuick = isCanQuick or 0
  636. msgRet.isVideo = combatInfo.isVideo == true and 1 or 0
  637. msgRet.mapID = combatInfo.mapID
  638. msgRet.speed = human.db and human.db.combatSpeed or 1
  639. msgRet.atkName = combatInfo.attacker and combatInfo.attacker.name or ""
  640. msgRet.defName = combatInfo.defender and combatInfo.defender.name or ""
  641. msgRet.atkUuid = combatInfo.attacker and combatInfo.attacker.uuid or ""
  642. msgRet.defUuid = combatInfo.defender and combatInfo.defender.uuid or ""
  643. msgRet.maxRound = combatInfo.maxRound
  644. msgRet.petCD = CombatDefine.PET_CD
  645. msgRet.heros[0] = 0
  646. msgRet.atkFormation = combatInfo.atkFormation
  647. msgRet.defFormation = combatInfo.defFormation
  648. msgRet.backup[0] = 2
  649. for i = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  650. local obj = combatInfo.objList[i]
  651. if fontCombatHeroNet(msgRet.heros[msgRet.heros[0] + 1], obj) then
  652. msgRet.heros[0] = msgRet.heros[0] + 1
  653. end
  654. if i % CombatDefine.COMBAT_HERO_CNT == 0 then
  655. msgRet.backup[i/CombatDefine.COMBAT_HERO_CNT] = obj and obj.backupPos or 0
  656. end
  657. end
  658. msgRet.helps[0] = 0
  659. for _, help in pairs(combatInfo.helpList) do
  660. if fontCombatHelpNet(msgRet.helps[msgRet.helps[0] + 1], help) then
  661. msgRet.helps[0] = msgRet.helps[0] + 1
  662. end
  663. end
  664. msgRet.skillList[0] = 0
  665. for skillID in pairs(combatInfo.skillUseList) do
  666. if fontCombatSkillNet(msgRet.skillList[msgRet.skillList[0] + 1], skillID) then
  667. msgRet.skillList[0] = msgRet.skillList[0] + 1
  668. end
  669. end
  670. msgRet.cmdList[0] = 0
  671. if combatInfo.cmdUseList then
  672. for cmd in pairs(combatInfo.cmdUseList) do
  673. if fontSkillCmd(msgRet.cmdList[msgRet.cmdList[0] + 1], cmd) then
  674. msgRet.cmdList[0] = msgRet.cmdList[0] + 1
  675. end
  676. end
  677. end
  678. msgRet.bufferList[0] = 0
  679. for bufferID in pairs(combatInfo.bufferUseList) do
  680. if fontBufferNet(msgRet.bufferList[msgRet.bufferList[0] + 1], bufferID) then
  681. msgRet.bufferList[0] = msgRet.bufferList[0] + 1
  682. end
  683. end
  684. fontCombatPosAttr(msgRet.attrsAtk, combatInfo.posAttr[1])
  685. fontCombatPosAttr(msgRet.attrsDef, combatInfo.posAttr[2])
  686. msgRet.atkJibanDesc = JibanLogic.getDesc(combatInfo.jiban[CombatDefine.ATTACK_SIDE])
  687. msgRet.defJibanDesc = JibanLogic.getDesc(combatInfo.jiban[CombatDefine.DEFEND_SIDE])
  688. Msg.send(msgRet, human.fd)
  689. end
  690. -- 封装战斗帧技能信息
  691. local function fontFrameSkillNet(skillNet, skillData)
  692. skillNet.attackPos = skillData.attackPos
  693. skillNet.skillID = skillData.skillID
  694. skillNet.hitList[0] = 0
  695. for i = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  696. local skillHitData = skillData.hitList[i]
  697. if skillHitData then
  698. skillNet.hitList[0] = skillNet.hitList[0] + 1
  699. local skillHitNet = skillNet.hitList[skillNet.hitList[0]]
  700. skillHitNet.pos = i
  701. skillHitNet.flag = skillHitData.flag
  702. skillHitNet.cmd = 0
  703. skillHitNet.hpNow = skillHitData.hpNow
  704. local frameAttrs = skillHitData.attrs
  705. skillHitNet.attrs[0] = frameAttrs and #frameAttrs or 0
  706. for j = 1, #frameAttrs do
  707. skillHitNet.attrs[j].key = frameAttrs[j][1]
  708. skillHitNet.attrs[j].value = frameAttrs[j][2]
  709. end
  710. end
  711. end
  712. skillNet.helpList[0] = 0
  713. --for i = CombatDefine.PET_POS_ATTACK, CombatDefine.PET_POS_DEFEND do
  714. -- local helpHitData = skillData.helpList and skillData.helpList[i]
  715. -- if helpHitData then
  716. -- skillNet.helpList[0] = skillNet.helpList[0] + 1
  717. -- local helpHitNet = skillNet.helpList[skillNet.helpList[0]]
  718. -- helpHitNet.pos = i
  719. -- end
  720. --end
  721. skillNet.extraList[0] = 0
  722. for i = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  723. local extraHitData = skillData.extraList[i]
  724. if extraHitData then
  725. skillNet.extraList[0] = skillNet.extraList[0] + 1
  726. local extraHitNet = skillNet.extraList[skillNet.extraList[0]]
  727. extraHitNet.pos = i
  728. extraHitNet.flag = extraHitData.flag
  729. extraHitNet.cmd = extraHitData.cmd
  730. extraHitNet.hpNow = extraHitData.hpNow
  731. local frameAttrs = extraHitData.attrs
  732. local attrsLen = math.min(frameAttrs and #frameAttrs or 0, #extraHitNet.attrs)
  733. extraHitNet.attrs[0] = attrsLen
  734. for j = 1, attrsLen do
  735. extraHitNet.attrs[j].key = frameAttrs[j][1]
  736. extraHitNet.attrs[j].value = frameAttrs[j][2]
  737. end
  738. end
  739. end
  740. end
  741. -- 封装战斗帧buff信息
  742. local function fontFrameBuff(net, buffers)
  743. net[0] = #buffers
  744. for i = 1, net[0] do
  745. local bufferNet = net[i]
  746. local bufferData = buffers[i]
  747. bufferNet.bufferID = bufferData.id
  748. bufferNet.op = bufferData.op
  749. bufferNet.cnt = bufferData.cnt
  750. bufferNet.round = bufferData.round or -1
  751. bufferNet.hpNow = bufferData.hpNow
  752. bufferNet.attrs[0] = bufferData.attrs and #bufferData.attrs or 0
  753. for j = 1, bufferNet.attrs[0] do
  754. bufferNet.attrs[j].key = bufferData.attrs[j][1]
  755. bufferNet.attrs[j].value = bufferData.attrs[j][2]
  756. end
  757. end
  758. end
  759. -- 封装战斗帧
  760. local function fontFrameNet(net, frame)
  761. net.round = frame.round
  762. net.petCD = frame.petCD
  763. net.skillList[0] = #frame.skillList
  764. for i = 1, net.skillList[0] do
  765. local skillNet = net.skillList[i]
  766. local skillData = frame.skillList[i]
  767. fontFrameSkillNet(skillNet, skillData)
  768. end
  769. net.bufferList[0] = 0
  770. for i = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  771. local bufferData = frame.bufferList[i]
  772. if bufferData then
  773. net.bufferList[0] = net.bufferList[0] + 1
  774. local bufferNet = net.bufferList[net.bufferList[0]]
  775. bufferNet.pos = i
  776. fontFrameBuff(bufferNet.list, bufferData)
  777. end
  778. end
  779. net.sayList[0] = 0
  780. for i = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  781. if frame.sayList[i] then
  782. for _,saySkillID in ipairs(frame.sayList[i]) do
  783. net.sayList[0] = net.sayList[0] + 1
  784. local sayNet = net.sayList[net.sayList[0]]
  785. sayNet.pos = i
  786. sayNet.skillID = saySkillID
  787. end
  788. end
  789. end
  790. return net.skillList[0] > 0 or net.bufferList[0] > 0 or net.sayList[0] > 0
  791. end
  792. -- 发送战斗帧
  793. local function sendCombatFrame(human, combatInfo, isLogin)
  794. combatInfo = combatInfo or human.combat
  795. if not combatInfo then return end
  796. local result = combatInfo.result
  797. local msgFrame = Msg.gc.GC_COMBAT_FRAME
  798. msgFrame.isLogin = isLogin == true and 1 or 0
  799. msgFrame.isEnd = 0
  800. msgFrame.combatType = combatInfo.type
  801. msgFrame.frames[0] = 0
  802. local frameCnt = result.frames and #result.frames or 0
  803. local len = 1
  804. for i = 1, frameCnt do
  805. local frame = result.frames[i]
  806. msgFrame.frames[0] = len
  807. local frameNet = msgFrame.frames[msgFrame.frames[0]]
  808. if fontFrameNet(frameNet, frame) then
  809. if len >= CombatDefine.COMBAT_FRAME_MAXCNT then
  810. msgFrame.isEnd = (i == frameCnt) and 1 or 0
  811. Msg.send(msgFrame, human.fd)
  812. msgFrame.frames[0] = 0
  813. len = 1
  814. else
  815. len = len + 1
  816. end
  817. end
  818. end
  819. if msgFrame.isEnd == 0 or msgFrame.frames[0] > 0 then
  820. msgFrame.isEnd = 1
  821. Msg.send(msgFrame, human.fd)
  822. end
  823. end
  824. -- 发送战斗开始
  825. function sendCombatData(human, combatInfo, isLogin)
  826. sendCombatBegin(human, combatInfo, isLogin)
  827. sendCombatFrame(human, combatInfo, isLogin)
  828. end
  829. -- 封装战斗统计
  830. function fontFinishResultNet(net, obj)
  831. net.pos = obj.pos
  832. net.hurt = obj.result[1]
  833. net.hp = obj.result[2]
  834. net.beHurt = obj.result[3]
  835. net.bout = obj.result[4]
  836. net.isDie = obj.hp == 0 and 1 or 0
  837. net.heroID = obj.id or 0
  838. net.head = obj.head or 0
  839. net.lv = obj.lv or 0
  840. net.star = obj.star or 0
  841. local heroConfig = HeroExcel.hero[net.heroID]
  842. local monsterConfig = MonsterExcel.monster[net.heroID]
  843. if obj.type == CombatDefine.COMBAT_OBJ_TYPE1 then
  844. net.name = heroConfig and heroConfig.name or ""
  845. net.body = heroConfig and heroConfig.body.."" or ""
  846. net.head = heroConfig and heroConfig.head or 0
  847. net.grade = heroConfig and heroConfig.grade or 0
  848. else
  849. net.name = monsterConfig and monsterConfig.name or ""
  850. net.body = monsterConfig and monsterConfig.body.."" or ""
  851. net.head = monsterConfig and monsterConfig.head or 0
  852. net.grade = monsterConfig and monsterConfig.grade or 0
  853. end
  854. net.camp = heroConfig and heroConfig.camp or 0
  855. end
  856. -- 封装战斗结束魔兽信息
  857. local function fontFinishPetNet(net, pet)
  858. net.pos = pet.pos
  859. net.side = pet.side
  860. net.lv = pet.lv or 0
  861. net.head = pet.head
  862. end
  863. function fontCombatFinish(dataNet, combatInfo, isQuick)
  864. if not combatInfo then return end
  865. local combatConfig = CombatExcel.combat[combatInfo.type]
  866. if not combatConfig then return end
  867. dataNet.nBattleType = 0
  868. dataNet.ret = combatInfo.isWin and 1 or 2
  869. dataNet.type = combatInfo.type
  870. dataNet.param = combatInfo.endParam or "0"
  871. dataNet.isVideo = (combatInfo.isVideo == true) and 1 or 0
  872. dataNet.lookType = combatInfo.lookType or 0
  873. dataNet.isQuick = isQuick or 0
  874. dataNet.combatTime = getCombatUseTime(combatInfo)
  875. dataNet.double = combatInfo.double or 0
  876. dataNet.oldLv = combatInfo.attacker.oldLv or 0
  877. dataNet.panelIDs[0] = #combatConfig.panelIDs
  878. for i, panelID in ipairs(combatConfig.panelIDs) do
  879. dataNet.panelIDs[i] = tonumber(panelID)
  880. end
  881. if combatInfo.panelID then
  882. dataNet.panelIDs[0] = dataNet.panelIDs[0] + 1
  883. dataNet.panelIDs[dataNet.panelIDs[0]] = tonumber(combatInfo.panelID)
  884. end
  885. -- 攻守方基本信息
  886. RoleLogic.makeRoleBase(combatInfo.defender, dataNet.target)
  887. RoleLogic.makeRoleBase(combatInfo.attacker, dataNet.self)
  888. -- 每个出战单位的战斗统计
  889. dataNet.result[0] = 0
  890. for pos = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  891. local obj = combatInfo.objList and combatInfo.objList[pos]
  892. if obj then
  893. dataNet.result[0] = dataNet.result[0] + 1
  894. local net = dataNet.result[dataNet.result[0]]
  895. fontFinishResultNet(net, obj)
  896. end
  897. end
  898. -- 出战魔兽
  899. for _,pos in ipairs(CombatDefine.SIDE2HELPPOS[0]) do
  900. local pet = combatInfo.helpList and combatInfo.helpList[pos]
  901. if pet and pet.isPet then
  902. dataNet.result[0] = dataNet.result[0] + 1
  903. local net = dataNet.result[dataNet.result[0]]
  904. fontFinishResultNet(net, pet)
  905. end
  906. end
  907. -- 奖励
  908. local rewardItem = combatInfo.rewardItem
  909. local len = 0
  910. for k, v in pairs(rewardItem) do
  911. if not ItemDefine.isEquip(v[1]) then
  912. len = len + 1
  913. Grid.makeItem(dataNet.items[len], v[1], v[2])
  914. end
  915. end
  916. dataNet.items[0] = EquipLogic.makeEquipItem(combatInfo, dataNet.items, len)
  917. return true
  918. end
  919. -- 发送战斗结束
  920. function sendCombatFinish(human, combatInfo)
  921. local msgRet = Msg.gc.GC_COMBAT_FINISH
  922. msgRet.data.nBattleType = 0
  923. local dataNet = msgRet.data
  924. local isQuick = human.db.combatQuick[combatInfo.type] or 0
  925. if not fontCombatFinish(dataNet, combatInfo, isQuick) then
  926. return
  927. end
  928. BeginStory.handleBattleFail(human, combatInfo.isWin, combatInfo.type, combatInfo.isVideo, msgRet)
  929. BeginStory.handleBattle8End(human, combatInfo.isWin, combatInfo.isVideo, combatInfo.type, msgRet)
  930. BeginStory.handleBattle12End(human, combatInfo.isWin, combatInfo.isVideo, combatInfo.type, msgRet)
  931. if CombatDefine.COMBAT_TYPE1 == combatInfo.type then
  932. msgRet.data.nBattleType = human.db.battleType
  933. if true == combatInfo.isWin and BattleLogic.BattleLogic_IsLastLevels(human, human.db.battleType) then
  934. msgRet.data.param = "0"
  935. end
  936. end
  937. Msg.send(msgRet,human.fd)
  938. end
  939. ---------------------------------------- 下面是战斗各种设置逻辑 ------------------------------------------------
  940. local function getMonsterBossName(param)
  941. local monsterOutID = param.monsterOutID
  942. local posList = param.posList
  943. for i,member in ipairs(MonsterExcel.monsterOut[monsterOutID].member) do
  944. local monsterID = member[1]
  945. local monsterConfig = MonsterExcel.monster[monsterID]
  946. if monsterConfig and posList[monsterID] ~= nil then
  947. return monsterConfig.name
  948. end
  949. end
  950. end
  951. -- 在各种战前加成后,重新设置血量
  952. function recalcHpFightBegin(human, combatType, cbParam)
  953. for i = 1,CombatDefine.COMBAT_HERO_CNT do
  954. local atkPos = getPos(CombatDefine.ATTACK_SIDE, i)
  955. local atkObj = CombatImpl.objList[atkPos]
  956. if atkObj then
  957. if atkObj.isSysAttrChange then
  958. CombatObj.calcAttr(atkObj)
  959. -- 重新计算血量
  960. if combatType == CombatDefine.COMBAT_TYPE9 then
  961. DrillLogic.calcAttrAtk(human, i, atkObj, cbParam)
  962. elseif combatType == CombatDefine.COMBAT_TYPE17 then
  963. ValleyLogic.calcAttr(CombatDefine.ATTACK_SIDE, i, atkObj, cbParam)
  964. elseif combatType == CombatDefine.COMBAT_TYPE8 then
  965. LianyuLogic.recalcHpFightBegin(human, i, atkObj)
  966. end
  967. end
  968. atkObj.hp = atkObj.hp or CombatObj.getHpMax(atkObj)
  969. atkObj.mp = atkObj.mp or atkObj.attr[RoleDefine.INIT_MP]
  970. atkObj.initHp = atkObj.hp
  971. atkObj.initMp = atkObj.mp
  972. end
  973. local defPos = getPos(CombatDefine.DEFEND_SIDE, i)
  974. local defObj = CombatImpl.objList[defPos]
  975. if defObj then
  976. if defObj.isSysAttrChange then
  977. CombatObj.calcAttr(defObj)
  978. if combatType == CombatDefine.COMBAT_TYPE9 then
  979. DrillLogic.calcAttrDef(human, i, defObj, cbParam)
  980. elseif combatType == CombatDefine.COMBAT_TYPE17 then
  981. ValleyLogic.calcAttr(CombatDefine.DEFEND_SIDE, i, defObj, cbParam)
  982. end
  983. end
  984. defObj.hp = defObj.hp or CombatObj.getHpMax(defObj)
  985. defObj.mp = defObj.mp or defObj.attr[RoleDefine.INIT_MP]
  986. defObj.initHp = defObj.hp
  987. defObj.initMp = defObj.mp
  988. end
  989. end
  990. end
  991. --战前加属性(包括各系统,被动技能,阵营光环)
  992. function onFightBegin(human, combatType, cbParam, param)
  993. local moduleFn = getModule(combatType)
  994. if moduleFn and moduleFn.onFightBegin then
  995. moduleFn.onFightBegin(human, cbParam, combatType, param)
  996. end
  997. BeSkill.onFightBegin(human)
  998. SkinLogic.onFightBegin(human) -- 处理皮肤属性
  999. CombatPosLogic.onFightBegin(human)
  1000. recalcHpFightBegin(human, combatType, cbParam)
  1001. end
  1002. function getHumanHeroList(human,combatType, cbParam)
  1003. return getHumanObjList(human, combatType)
  1004. end
  1005. -- 设置英雄出战
  1006. local function setCombatInfo(formation,objList, side)
  1007. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  1008. local obj = objList[index]
  1009. if obj then
  1010. -- 出战英雄站位
  1011. if CombatPosLogic.checkPos(formation,index, side) then
  1012. local pos = CombatDefine.SIDE2POS[side][index]
  1013. CombatImpl.setData(pos, obj)
  1014. end
  1015. end
  1016. end
  1017. end
  1018. -- 设置辅助对象出战
  1019. local function setHelp(helpList, side)
  1020. if not helpList then return end
  1021. for k,v in pairs(helpList) do
  1022. if k == CombatDefine.HELP_TYPE1 then
  1023. CombatPetCalc.calcGrowArgs(v)
  1024. CombatPetCalc.clacBuffArgs(v)
  1025. end
  1026. CombatImpl.setHelp(side,k,v)
  1027. end
  1028. end
  1029. -- 初始combatInfo
  1030. local function initCombatInfo(human, combatType, mapID)
  1031. local combatInfo = {}
  1032. combatInfo.time = os.time() -- 战斗时间
  1033. combatInfo.passTime = 0 -- 客户端经过的时间
  1034. combatInfo.type = combatType -- 战斗类型
  1035. combatInfo.mapID = mapID -- 地图
  1036. combatInfo.posAttr = {} -- 阵法属性
  1037. combatInfo.jiban = {} -- 阵法属性
  1038. combatInfo.attacker = nil -- 攻方基础角色信息 roleBase
  1039. combatInfo.defender = nil -- 守方基础角色信息 roleBase
  1040. combatInfo.atkJiban = nil -- 攻方羁绊英雄
  1041. combatInfo.defJiban = nil -- 守方羁绊英雄
  1042. combatInfo.isWin = nil -- 战斗结果
  1043. combatInfo.result = nil -- 战斗帧
  1044. combatInfo.skillUseList = nil -- 战斗技能
  1045. combatInfo.cmdUseList = nil -- 战斗技能命令
  1046. combatInfo.bufferUseList = nil -- 战斗buff
  1047. combatInfo.objList = nil -- 战斗英雄列表
  1048. combatInfo.helpList = nil -- 战斗魔兽列表
  1049. combatInfo.rewardItem = {} -- 奖励
  1050. combatInfo.endParam = nil -- 额外参数
  1051. combatInfo.isVideo = nil -- 是否录像
  1052. combatInfo.videoUuid = nil -- 录像uuid
  1053. combatInfo.panelID = nil -- 返回界面(特殊)
  1054. combatInfo.maxRound = nil -- 最大会合数
  1055. combatInfo.fightMode = nil -- 战斗模式
  1056. human.combat = combatInfo
  1057. return combatInfo
  1058. end
  1059. -- 为了战斗回放,某些数据需要保存
  1060. local function copyToCombatInfo(combatInfo)
  1061. combatInfo.isWin = CombatImpl.result.isWin
  1062. combatInfo.result = Util.copyTable(CombatImpl.result)
  1063. combatInfo.result.round = CombatImpl.round
  1064. combatInfo.skillUseList = Util.copyTable(CombatImpl.skillUseList)
  1065. combatInfo.cmdUseList = Util.copyTable(CombatImpl.cmdUseList)
  1066. combatInfo.bufferUseList = Util.copyTable(CombatImpl.bufferUseList)
  1067. combatInfo.objList = Util.copyTable(CombatImpl.objList)
  1068. combatInfo.helpList = Util.copyTable(CombatImpl.helpList)
  1069. combatInfo.totalAtkCnt = CombatImpl.totalAtkCnt
  1070. end
  1071. function setSkillAndBeskill(human,combatInfo)
  1072. local combatType = combatInfo.type
  1073. local moduleFn = getModule(combatType)
  1074. if moduleFn and moduleFn.setSkillAndBeskill then
  1075. moduleFn.setSkillAndBeskill(human,combatInfo)
  1076. end
  1077. end
  1078. function combatBegin(human, mapID, param, combatType, cbParam, isSaodang)
  1079. if COMBAT_CACHE[human.db._id] and COMBAT_CACHE[human.db._id][combatType] then
  1080. --assert(nil, "has combat cache "..combatType .. " " .. human.db.account) -- reyes test
  1081. human.combat = COMBAT_CACHE[human.db._id][combatType].combatInfo
  1082. sendCombatData(human, human.combat)
  1083. return
  1084. end
  1085. -- 获得地图ID
  1086. CombatImpl.init(combatType)
  1087. mapID = getMapID(human, combatType, param)
  1088. local defender, defHelp, defRBase,defFormation,defJiban = getCombatObjList(human, CombatDefine.DEFEND_SIDE, combatType, param)
  1089. local attacker, atkHelp, atkRBase, atkFormation,atkJiban
  1090. if defender then
  1091. attacker, atkHelp, atkRBase, atkFormation,atkJiban = getCombatObjList(human, CombatDefine.ATTACK_SIDE, combatType, param)
  1092. end
  1093. if not (attacker and next(attacker)) then
  1094. return
  1095. end
  1096. if not defender then
  1097. return
  1098. end
  1099. local combatInfo = initCombatInfo(human, combatType, mapID)
  1100. combatInfo.attacker = atkRBase or {}
  1101. combatInfo.atkHelp = atkHelp or {}
  1102. combatInfo.atkFormation = atkFormation
  1103. combatInfo.atkJiban = atkJiban
  1104. combatInfo.defender = defRBase or {}
  1105. combatInfo.defHelp = defHelp or {}
  1106. combatInfo.defFormation = defFormation
  1107. combatInfo.defJiban = defJiban
  1108. combatInfo.posAttr[CombatDefine.ATTACK_SIDE] = CombatPosLogic.getPosAttr(attacker)
  1109. combatInfo.posAttr[CombatDefine.DEFEND_SIDE] = CombatPosLogic.getPosAttr(defender)
  1110. combatInfo.jiban[CombatDefine.ATTACK_SIDE] = JibanLogic.getJiban(attacker,atkJiban)
  1111. combatInfo.jiban[CombatDefine.DEFEND_SIDE] = JibanLogic.getJiban(defender,defJiban)
  1112. combatInfo.maxRound = getMaxRound(human,combatType)
  1113. combatInfo.fightMode = getFightMode(combatType)
  1114. --战役第五关特殊处理
  1115. BeginStory.handleBattle5(human, combatType, defender)
  1116. JibanLogic.setBeSkill(attacker,combatInfo.jiban[CombatDefine.ATTACK_SIDE])
  1117. JibanLogic.setBeSkill(defender,combatInfo.jiban[CombatDefine.DEFEND_SIDE])
  1118. local changePos = nil
  1119. if combatType == CombatDefine.COMBAT_TYPE10 then
  1120. for k,v in pairs(attacker) do
  1121. changePos = k
  1122. attacker[k] = nil
  1123. attacker[5] = v
  1124. break
  1125. end
  1126. end
  1127. setCombatInfo(atkFormation, attacker, CombatDefine.ATTACK_SIDE)
  1128. setCombatInfo(defFormation, defender, CombatDefine.DEFEND_SIDE)
  1129. setHelp(atkHelp, CombatDefine.ATTACK_SIDE)
  1130. setHelp(defHelp, CombatDefine.DEFEND_SIDE)
  1131. CombatImpl.setMaxRound(combatInfo.maxRound)
  1132. CombatImpl.setFightMode(combatInfo.fightMode)
  1133. --需要对技能特殊处理的(比如不重置cd)
  1134. setSkillAndBeskill(human,combatInfo)
  1135. -- 战前属性/血量重算
  1136. local tempParam = cbParam
  1137. if combatType == CombatDefine.COMBAT_TYPE10 then
  1138. tempParam = {}
  1139. tempParam.cbParam = cbParam
  1140. tempParam.changePos = changePos
  1141. end
  1142. onFightBegin(human, combatType, tempParam, param)
  1143. makeAttrLogStr(human)
  1144. while CombatImpl.calcFrame() do end
  1145. copyToCombatInfo(combatInfo)
  1146. combatInfo.changePos = changePos
  1147. local result = combatInfo.isWin and CombatDefine.RESULT_WIN or CombatDefine.RESULT_FAIL
  1148. local isQuick = human.db.combatQuick[combatType] == 1-- 是否跳过战斗
  1149. if isSaodang or isQuick then
  1150. -- 扫荡/跳过战斗需要立刻出结果
  1151. onFightEnd(human, result, combatType, cbParam, combatInfo, isSaodang,param)
  1152. sendCombatFinish(human, combatInfo)
  1153. else
  1154. -- 发送战斗开始+战斗帧
  1155. sendCombatData(human, combatInfo)
  1156. addCombatCache(human.db._id, combatInfo, cbParam,param)
  1157. end
  1158. makeLogStr(human) -- 写战斗日志
  1159. end
  1160. function getCombatUseTime(combatInfo)
  1161. local combatUseTime = CombatDefine.COMBAT_ATK_TIME * (combatInfo.totalAtkCnt or 0) -- 1.2秒1次行动
  1162. combatUseTime = combatUseTime + 10 --带上出场时间
  1163. return combatUseTime
  1164. end
  1165. function combatGm(human,mapID,atkFormation,attacker,defFormation,defender,atkPet,defPet,rewardItem)
  1166. local combatType = 0
  1167. local config = CombatExcel.combat[combatType]
  1168. local combatInfo = initCombatInfo(human, combatType, mapID)
  1169. combatInfo.attacker = {}
  1170. combatInfo.defender = {}
  1171. combatInfo.posAttr[CombatDefine.ATTACK_SIDE] = CombatPosLogic.getPosAttr(attacker)
  1172. combatInfo.posAttr[CombatDefine.DEFEND_SIDE] = CombatPosLogic.getPosAttr(defender)
  1173. combatInfo.jiban[CombatDefine.ATTACK_SIDE] = JibanLogic.getJiban(attacker)
  1174. combatInfo.jiban[CombatDefine.DEFEND_SIDE] = JibanLogic.getJiban(defender)
  1175. combatInfo.rewardItem = rewardItem or combatInfo.rewardItem
  1176. combatInfo.atkFormation = atkFormation
  1177. combatInfo.defFormation = defFormation
  1178. combatInfo.fightMode = config.fightMode
  1179. CombatImpl.init(combatType)
  1180. setCombatInfo(atkFormation,attacker, CombatDefine.ATTACK_SIDE)
  1181. setCombatInfo(defFormation,defender, CombatDefine.DEFEND_SIDE)
  1182. setHelp({atkPet}, CombatDefine.ATTACK_SIDE)
  1183. setHelp({defPet}, CombatDefine.DEFEND_SIDE)
  1184. combatInfo.maxRound = getMaxRound(human,combatType)
  1185. CombatImpl.setMaxRound(combatInfo.maxRound)
  1186. CombatImpl.setFightMode(combatInfo.fightMode)
  1187. -- 战前属性/血量重算
  1188. onFightBegin(human, combatType, nil, {}, {})
  1189. makeAttrLogStr(human)
  1190. while CombatImpl.calcFrame() do end
  1191. copyToCombatInfo(combatInfo)
  1192. sendCombatData(human, combatInfo)
  1193. -- 方便调试不做缓存
  1194. addCombatCache(human.db._id, combatInfo)
  1195. makeLogStr(human) -- 写战斗日志
  1196. end
  1197. function combatGuide(human, atkFormation,attacker,defFormation,defender,atkPet,defPet)
  1198. local combatType = CombatDefine.COMBAT_TYPE18
  1199. local config = CombatExcel.combat[combatType]
  1200. local combatInfo = initCombatInfo(human, combatType, config.mapID)
  1201. combatInfo.attacker = {}
  1202. combatInfo.defender = {}
  1203. combatInfo.posAttr[CombatDefine.ATTACK_SIDE] = CombatPosLogic.getPosAttr(attacker)
  1204. combatInfo.posAttr[CombatDefine.DEFEND_SIDE] = CombatPosLogic.getPosAttr(defender)
  1205. combatInfo.jiban[CombatDefine.ATTACK_SIDE] = JibanLogic.getJiban(attacker)
  1206. combatInfo.jiban[CombatDefine.DEFEND_SIDE] = JibanLogic.getJiban(defender)
  1207. combatInfo.rewardItem = rewardItem or combatInfo.rewardItem
  1208. combatInfo.atkFormation = atkFormation
  1209. combatInfo.defFormation = defFormation
  1210. combatInfo.fightMode = config.fightMode
  1211. CombatImpl.init(combatType)
  1212. setCombatInfo(atkFormation,attacker, CombatDefine.ATTACK_SIDE)
  1213. setCombatInfo(defFormation,defender, CombatDefine.DEFEND_SIDE)
  1214. setHelp({atkPet}, CombatDefine.ATTACK_SIDE)
  1215. setHelp({defPet}, CombatDefine.DEFEND_SIDE)
  1216. combatInfo.maxRound = getMaxRound(human, combatType)
  1217. CombatImpl.setMaxRound(combatInfo.maxRound)
  1218. CombatImpl.setFightMode(combatInfo.fightMode)
  1219. JibanLogic.setBeSkill(attacker,combatInfo.jiban[CombatDefine.ATTACK_SIDE])
  1220. JibanLogic.setBeSkill(defender,combatInfo.jiban[CombatDefine.DEFEND_SIDE])
  1221. -- 战前属性/血量重算
  1222. onFightBegin(human, combatType, nil, {}, {})
  1223. human.combat = combatInfo
  1224. while CombatImpl.calcFrame() do end
  1225. copyToCombatInfo(human.combat)
  1226. end
  1227. --
  1228. function combatVedio(human, atkFormation, attacker,defFormation,defender,atkPet,defPet, fakeHuman)
  1229. local combatType = CombatDefine.COMBAT_TYPE22
  1230. local config = CombatExcel.combat[combatType]
  1231. local combatInfo = initCombatInfo(human, combatType, config.mapID)
  1232. combatInfo.attacker = {}
  1233. combatInfo.defender = {}
  1234. combatInfo.posAttr[CombatDefine.ATTACK_SIDE] = CombatPosLogic.getPosAttr(attacker)
  1235. combatInfo.posAttr[CombatDefine.DEFEND_SIDE] = CombatPosLogic.getPosAttr(defender)
  1236. combatInfo.jiban[CombatDefine.ATTACK_SIDE] = JibanLogic.getJiban(attacker)
  1237. combatInfo.jiban[CombatDefine.DEFEND_SIDE] = JibanLogic.getJiban(defender)
  1238. combatInfo.rewardItem = rewardItem or combatInfo.rewardItem
  1239. combatInfo.atkFormation = atkFormation
  1240. combatInfo.defFormation = defFormation
  1241. combatInfo.fightMode = config.fightMode
  1242. CombatImpl.init(combatType)
  1243. setCombatInfo(atkFormation,attacker, CombatDefine.ATTACK_SIDE)
  1244. setCombatInfo(defFormation,defender, CombatDefine.DEFEND_SIDE)
  1245. setHelp({atkPet}, CombatDefine.ATTACK_SIDE)
  1246. setHelp({defPet}, CombatDefine.DEFEND_SIDE)
  1247. combatInfo.maxRound = getMaxRound(human, combatType)
  1248. CombatImpl.setMaxRound(combatInfo.maxRound)
  1249. CombatImpl.setFightMode(combatInfo.fightMode)
  1250. JibanLogic.setBeSkill(attacker,combatInfo.jiban[CombatDefine.ATTACK_SIDE])
  1251. JibanLogic.setBeSkill(defender,combatInfo.jiban[CombatDefine.DEFEND_SIDE])
  1252. -- 战前属性/血量重算
  1253. onFightBegin(human, combatType, nil, {}, {})
  1254. human.combat = combatInfo
  1255. while CombatImpl.calcFrame() do end
  1256. copyToCombatInfo(human.combat)
  1257. sendCombatData(fakeHuman, combatInfo)
  1258. end
  1259. -- 战斗录像
  1260. local VEDIO_COMBAT_INFO = VEDIO_COMBAT_INFO or { db = {} }
  1261. function combatFightVedio(human, heroID)
  1262. local heroConfig = HeroExcel.hero[heroID]
  1263. if not heroConfig then return end
  1264. local combatConf = CombatExcel.gm[heroConfig.gm]
  1265. if not combatConf then return end
  1266. VEDIO_COMBAT_INFO.attacker = {}
  1267. VEDIO_COMBAT_INFO.defender = {}
  1268. VEDIO_COMBAT_INFO.atkFormation = combatConf.atkF
  1269. VEDIO_COMBAT_INFO.defFormation = combatConf.defF
  1270. local atkConf = nil
  1271. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1272. atkConf = nil
  1273. for k, v in ipairs(combatConf.atk) do
  1274. if i == v[2] then
  1275. atkConf = v
  1276. break
  1277. end
  1278. end
  1279. if atkConf then
  1280. VEDIO_COMBAT_INFO.attacker[i] = createHeroObj(VEDIO_COMBAT_INFO, atkConf[1], atkConf[3], atkConf[4], i,atkConf[5])
  1281. end
  1282. atkConf = nil
  1283. for k, v in ipairs(combatConf.def) do
  1284. if i == v[2] then
  1285. atkConf = v
  1286. break
  1287. end
  1288. end
  1289. if atkConf then
  1290. VEDIO_COMBAT_INFO.defender[i] = createHeroObj(VEDIO_COMBAT_INFO, atkConf[1], atkConf[3], atkConf[4], i,atkConf[5])
  1291. end
  1292. end
  1293. combatVedio(VEDIO_COMBAT_INFO, VEDIO_COMBAT_INFO.atkFormation, VEDIO_COMBAT_INFO.attacker,
  1294. VEDIO_COMBAT_INFO.defFormation, VEDIO_COMBAT_INFO.defender, nil, nil, human)
  1295. end
  1296. function repeatCombat(human, combatInfo)
  1297. if not combatInfo then
  1298. return
  1299. end
  1300. -- if isCombating(human) then
  1301. -- return Broadcast.sendErr(human, Lang.COMBAT_VIDEO_LOOK_ERR_ING)
  1302. -- end
  1303. combatInfo.isVideo = true
  1304. human.combat = combatInfo
  1305. sendCombatData(human, combatInfo)
  1306. sendCombatFinish(human, combatInfo)
  1307. end
  1308. -- 初始属性数据写日志
  1309. function makeAttrLogStr(human)
  1310. if not Config.IS_DEBUG then
  1311. return
  1312. end
  1313. local logStr = "\n初始属性数据:\n"
  1314. for i = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  1315. data = CombatImpl.objList[i]
  1316. if data then
  1317. logStr = logStr .. "\n\t" .. "{pos:"..data.pos.." heroID:"..data.id.."}\n\t"
  1318. for k,v in pairs(data.attr) do
  1319. if v ~= 0 then
  1320. logStr = logStr .."{key:"..k..",value:"..v.."},"
  1321. end
  1322. end
  1323. end
  1324. end
  1325. logStr = logStr .."\n"
  1326. local f = io.open("./log/fight_log.log", "w+")
  1327. f:write(logStr)
  1328. assert(io.close(f))
  1329. end
  1330. function makeLogStr(human)
  1331. if not Config.IS_DEBUG then
  1332. return
  1333. end
  1334. local logStr = "\n战斗开始数据:\n"
  1335. for i = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  1336. data = CombatImpl.objList[i]
  1337. if data then
  1338. logStr = logStr .. "\t" .. "{pos:"..data.pos.." heroID:"..data.id.."}"
  1339. end
  1340. end
  1341. logStr = logStr .. "\n"
  1342. logStr = logStr .. "战斗帧数据:\n"
  1343. local result = CombatImpl.result
  1344. local frameCnt = result.frames and #result.frames or 0
  1345. for i = 1,frameCnt do
  1346. local data = result.frames[i]
  1347. logStr = logStr .. "\t" .. i .."帧\n"
  1348. for j = 1,#data.skillList do
  1349. local skillData = data.skillList[j]
  1350. logStr = logStr .. "\t\t技能释放 attackPos:"..skillData.attackPos.." skillID:"..skillData.skillID.."\n"
  1351. local hitLen = 0
  1352. for k = 1,CombatDefine.COMBAT_HERO_ALL_CNT do
  1353. if skillData.hitList[k] then
  1354. hitLen = hitLen + 1
  1355. local skillHitData = skillData.hitList[k]
  1356. logStr = logStr .. "\t\t\t技能对象"..hitLen.." pos:"..k.." hpNow:"..skillHitData.hpNow.." attrs:"
  1357. local frameAttrs = skillHitData.attrs
  1358. local attrsLen = 0
  1359. if frameAttrs then
  1360. for m = 1,#frameAttrs do
  1361. logStr = logStr .. " {key:"..frameAttrs[m][1].." value:"..frameAttrs[m][2].."}"
  1362. end
  1363. end
  1364. logStr = logStr .. "\n"
  1365. end
  1366. end
  1367. local extraLen = 0
  1368. for k = 1,CombatDefine.COMBAT_HERO_ALL_CNT do
  1369. if skillData.extraList[k] then
  1370. extraLen = extraLen + 1
  1371. local extraHitData = skillData.extraList[k]
  1372. logStr = logStr .. "\t\t\t额外作用对象"..extraLen.." pos:"..k.." cmd:"..extraHitData.cmd.." hpNow:"..extraHitData.hpNow.." attrs:"
  1373. local frameAttrs = extraHitData.attrs
  1374. if frameAttrs then
  1375. for m = 1,#frameAttrs do
  1376. logStr = logStr .. " {key:"..frameAttrs[m][1].." value:"..frameAttrs[m][2].."}"
  1377. end
  1378. end
  1379. logStr = logStr .. "\n"
  1380. end
  1381. end
  1382. end
  1383. local bufferLen = 0
  1384. for j = 1,CombatDefine.COMBAT_HERO_ALL_CNT do
  1385. if data.bufferList[j] then
  1386. bufferLen = bufferLen + 1
  1387. logStr = logStr .. "\t\tbuffer更新 pos:"..j.."\n"
  1388. local bufferDataList = data.bufferList[j]
  1389. for i = 1,#bufferDataList do
  1390. local bufferData = bufferDataList[i]
  1391. logStr = logStr .. "\t\t\t bufferID:"..bufferData.id.." op:"..bufferData.op.." cnt:"..bufferData.cnt.." round:"..(bufferData.round or -1).." hpNow:"..bufferData.hpNow.." attrs:"
  1392. local attrsLen = 0
  1393. if bufferData.attrs then
  1394. for k,v in ipairs(bufferData.attrs) do
  1395. logStr = logStr .. " {key:"..v[1].." value:"..v[2].."}"
  1396. end
  1397. end
  1398. end
  1399. logStr = logStr .. "\n"
  1400. end
  1401. end
  1402. end
  1403. local f = io.open("./log/fight_log.log", "a+")
  1404. f:write(logStr)
  1405. assert(io.close(f))
  1406. end
  1407. -- 获取角色上阵的形象
  1408. function getRoleBody(human, combatType)
  1409. local teamType = CombatPosLogic.getTeamType(combatType)
  1410. local combatHero = teamType and human.db.combatHero[teamType]
  1411. if not combatHero then return end
  1412. local zhandouli = 0
  1413. local maxGrid = nil
  1414. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  1415. local uuid = combatHero.list[i]
  1416. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  1417. if heroGrid and type(heroGrid) == "table" and
  1418. zhandouli < heroGrid.zhandouli then
  1419. zhandouli = heroGrid.zhandouli
  1420. maxGrid = heroGrid
  1421. end
  1422. end
  1423. if not maxGrid then return end
  1424. return HeroGrid.getHeroBodyById(maxGrid.id)
  1425. end
  1426. -- 根据怪物组id获取外显
  1427. function getMonsterIDByOutID(monsterOutID, args)
  1428. local mocf = MonsterExcel.monsterOut[monsterOutID]
  1429. if not mocf then return end
  1430. local memberCnt = #mocf.member
  1431. local index = (monsterOutID % 1000) % memberCnt
  1432. if index == 0 then index = memberCnt - 1 end
  1433. local minfo = mocf.member[index]
  1434. if not minfo then
  1435. for _, minfo0 in ipairs(mocf.member) do
  1436. if minfo0[1] > 0 then
  1437. minfo = minfo0
  1438. break
  1439. end
  1440. end
  1441. end
  1442. if not minfo then return end
  1443. local monsterID = minfo[1]
  1444. local monsterLv = minfo[2]
  1445. local mcf = monsterID and MonsterExcel.monster[monsterID]
  1446. if not mcf then return end
  1447. if mocf.combatType == CombatDefine.COMBAT_TYPE5 then
  1448. if args then
  1449. local throneID = args[1]
  1450. local evolveCnt = args[2]
  1451. monsterLv = TheStarsLogic.getMonsterLvAttr(1, throneID, evolveCnt)
  1452. end
  1453. end
  1454. return monsterID, mcf, monsterLv
  1455. end
  1456. -- 根据伤害计算胜负
  1457. function calcWinByHurt(combatInfo)
  1458. if not combatInfo.isWin then return end
  1459. if not combatInfo.objList then return end
  1460. local atkHurt = 0
  1461. local defHurt = 0
  1462. local atkLive = 0
  1463. local defLive = 0
  1464. for i = 1,CombatDefine.COMBAT_HERO_CNT do
  1465. local atkPos = getPos(CombatDefine.ATTACK_SIDE, i)
  1466. local atkObj = combatInfo.objList[atkPos]
  1467. if atkObj then
  1468. atkHurt = atkHurt + atkObj.result[1]
  1469. if atkObj.hp > 0 and not atkLive then
  1470. atkLive = 1
  1471. end
  1472. end
  1473. local defPos = getPos(CombatDefine.DEFEND_SIDE, i)
  1474. local defObj = combatInfo.objList[defPos]
  1475. if defObj then
  1476. defHurt = defHurt + defObj.result[1]
  1477. if atkObj.hp > 0 and not defLive then
  1478. defLive = 1
  1479. end
  1480. end
  1481. end
  1482. if atkLive == 0 then
  1483. atkHurt = 0
  1484. elseif defLive == 0 then
  1485. defLive = 0
  1486. end
  1487. combatInfo.isWin = atkHurt > defHurt and true or false
  1488. return combatInfo.isWin
  1489. end
  1490. ------------- reyes test ---------------------
  1491. function isCombating(human)
  1492. local list = COMBAT_CACHE[human.db._id]
  1493. if not list then return end
  1494. for combatType, combatCache in pairs(list) do
  1495. if not combatCache.combatInfo.isVideo then
  1496. return true
  1497. end
  1498. end
  1499. end
  1500. function getCombatCache(uuid, type)
  1501. return COMBAT_CACHE[uuid] and COMBAT_CACHE[uuid][type]
  1502. end
  1503. function addCombatCache(uuid, combatInfo, cbParam,param)
  1504. COMBAT_CACHE[uuid] = COMBAT_CACHE[uuid] or {} -- reyes test
  1505. local tempCache = {}
  1506. local result = combatInfo.isWin and CombatDefine.RESULT_WIN or CombatDefine.RESULT_FAIL
  1507. tempCache.result = result
  1508. tempCache.combatType = combatInfo.type
  1509. tempCache.cbParam = cbParam
  1510. tempCache.combatInfo = combatInfo
  1511. tempCache.param = param
  1512. tempCache.ts = os.time() + getCombatUseTime(combatInfo)
  1513. COMBAT_CACHE[uuid][combatInfo.type] = tempCache
  1514. end
  1515. function cleanCombatCache(uuid, type)
  1516. if not COMBAT_CACHE[uuid] then return end
  1517. COMBAT_CACHE[uuid][type] = nil
  1518. if Util.getTableCount(COMBAT_CACHE[uuid]) == 0 then
  1519. COMBAT_CACHE[uuid] = nil
  1520. end
  1521. end
  1522. function clientFinish(human, type, noSend)
  1523. if COMBAT_CACHE[human.db._id] == nil or COMBAT_CACHE[human.db._id][type] == nil then
  1524. return
  1525. end
  1526. local combatCache = COMBAT_CACHE[human.db._id][type]
  1527. cleanCombatCache(human.db._id, type)
  1528. --print("onend-=----------------------")
  1529. if not combatCache.combatInfo.isVideo then
  1530. onFightEnd(human, combatCache.result, combatCache.combatType, combatCache.cbParam, combatCache.combatInfo,combatCache.param)
  1531. end
  1532. -- 绝望深渊 非失败 不发
  1533. -- 冰龙 次元魔珠 失落神庙 不走默认结算协议
  1534. if type ~= CombatDefine.COMBAT_TYPE8 and
  1535. type ~= CombatDefine.COMABT_TYPE23 and
  1536. type ~= CombatDefine.COMBAT_TYPE20 and
  1537. type ~= CombatDefine.COMBAT_TYPE24
  1538. and not noSend then
  1539. sendCombatFinish(human, combatCache.combatInfo)
  1540. end
  1541. end
  1542. function clientPassTime(human, type, passTime)
  1543. if COMBAT_CACHE[human.db._id] == nil or COMBAT_CACHE[human.db._id][type] == nil then
  1544. return
  1545. end
  1546. local combatInfo = COMBAT_CACHE[human.db._id][type].combatInfo
  1547. combatInfo.passTime = passTime
  1548. end
  1549. function onLogin(human)
  1550. checkFinish(human)
  1551. -- 这里要先check才判断cache 因为check完cache可能就空了
  1552. if COMBAT_CACHE[human.db._id] == nil then
  1553. return
  1554. end
  1555. for k, v in pairs(COMBAT_CACHE[human.db._id]) do
  1556. --assert(nil, "has combat cache "..combatType .. " " .. human.db.account) -- reyes test
  1557. human.combat = v.combatInfo
  1558. sendCombatData(human, human.combat, true)
  1559. end
  1560. end
  1561. function checkFinish(human)
  1562. if COMBAT_CACHE[human.db._id] == nil then
  1563. return
  1564. end
  1565. local now = os.time()
  1566. for k, v in pairs(COMBAT_CACHE[human.db._id]) do
  1567. if now >= v.ts then
  1568. clientFinish(human, k)
  1569. if COMBAT_CACHE[human.db._id] == nil then
  1570. return
  1571. end
  1572. end
  1573. end
  1574. end
  1575. -- 不管时间立刻结算 目前只有踢人等非正常下线会用到
  1576. function forceFinish(human)
  1577. if COMBAT_CACHE[human.db._id] == nil then
  1578. return
  1579. end
  1580. local now = os.time()
  1581. for k, v in pairs(COMBAT_CACHE[human.db._id]) do
  1582. clientFinish(human, k)
  1583. if COMBAT_CACHE[human.db._id] == nil then
  1584. return
  1585. end
  1586. end
  1587. end
  1588. function killFrames(combatInfo)
  1589. --60帧2倍速情况下大概1分半。限制录像时长再3-5分钟。节省包量
  1590. if combatInfo.result.frames and #combatInfo.result.frames > 200 then
  1591. for i = 201,#combatInfo.result.frames do
  1592. combatInfo.result.frames[i] = nil
  1593. end
  1594. end
  1595. end