CombatLogic.lua 67 KB

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