CombatLogic.lua 66 KB

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