CombatLogic.lua 60 KB

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