CombatLogic.lua 66 KB

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