CombatLogic.lua 60 KB

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