CombatLogic.lua 67 KB

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