CombatPosLogic.lua 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. -------------------------------------------------
  2. -- 队伍上阵
  3. -- db.combatHero 上阵信息
  4. -- getTeamType 根据战斗类型获取出战队伍类型
  5. -- getCombatHeros 根据出战类型获取出战队伍下标列表
  6. -- getCombatHeroZDL 根据战斗类型获取出战战力
  7. -- cleanCombatHeros 清空出战信息
  8. -- updatePos 设置上阵信息
  9. -------------------------------------------------
  10. local CombatExcel = require("excel.combat")
  11. local HeroExcel = require("excel.hero")
  12. local MonsterExcel = require("excel.monster").monster
  13. local MonsterOutExcel = require("excel.monster").monsterOut
  14. local BattleMonsterExcel = require("excel.battlemonster")
  15. local BattleMonsterExcel2 = require("excel.battlemonster2")
  16. local CombatPosExcel = require("excel.combatPos")
  17. local FormationExcel = CombatPosExcel.formation
  18. local DefineExcel = CombatPosExcel.define[1]
  19. local Util = require("common.Util")
  20. local Lang = require("common.Lang")
  21. local Msg = require("core.Msg")
  22. local ObjHuman = require("core.ObjHuman")
  23. local Broadcast = require("broadcast.Broadcast")
  24. local CombatDefine = require("combat.CombatDefine")
  25. local CombatLogic = require("combat.CombatLogic")
  26. local CombatImpl = require("combat.CombatImpl")
  27. -- local DrillLogic = require("drill.DrillLogic")
  28. -- local JjcLogic = require("jjc.JjcLogic")
  29. -- local UnionWarLogic = require("union.UnionWarLogic")
  30. -- local UnionLogic = require("union.UnionLogic")
  31. -- local RoleDefine = require("role.RoleDefine")
  32. local MoshouLogic = require("moshou.MoshouLogic")
  33. local HeroLogic = require("hero.HeroLogic")
  34. -- local Grid = require("bag.Grid")
  35. -- local BagLogic = require("bag.BagLogic")
  36. -- local YjTreasureLogic = require("yjTreasure.YjTreasureLogic")
  37. local RoleHeadLogic = require("role.RoleHeadLogic")
  38. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  39. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  40. local JibanLogic = require("combat.JibanLogic")
  41. local JjcGodWarLogic = require("jjcGodWar.JjcGodWarLogic")
  42. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  43. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  44. local SkillExcel = require("excel.skill")
  45. local RoleAttr = require("role.RoleAttr")
  46. local LostTempleCombatLogic = require("lostTemple.lostTempleCombatLogic")
  47. local RecommendLineup = require("drawCard.RecommendLineup")
  48. local TalismanLogic = require("talisman.TalismanLogic")
  49. local NewFirstChargeLogic = require("present.NewFirstChargeLogic")
  50. local ElfLogic = require("elf.ElfLogic")
  51. local Skill = require("combat.Skill")
  52. local AnotherWorldBattleNS
  53. local ServerCommerceActBattleGroundNS
  54. --秘宝的加成
  55. local function getTalismanAdd(human)
  56. local res = TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.BATTLE_ISQUICKTIME)
  57. if res == 0 then
  58. return
  59. end
  60. return res
  61. end
  62. -- 根据战斗类型获取出战队伍类型
  63. function getTeamType(combatType)
  64. if not CombatExcel.combat[combatType] then
  65. -- print("[getTeamType] 不存在对应的 combatType = "..combatType)
  66. return
  67. end
  68. return CombatExcel.combat[combatType].teamType
  69. end
  70. function getCombatHeroDB(human,combatType)
  71. local teamType = getTeamType(combatType)
  72. if not human.db.combatHero[teamType] then
  73. human.db.combatHero[teamType] = {list = {},helpList = {},formation = 1,jiban = {}}
  74. end
  75. return human.db.combatHero[teamType],teamType
  76. end
  77. -- 重置阵容数据
  78. function ResetCombatData(human,combatType)
  79. local teamType = getTeamType(combatType)
  80. if teamType and human.db.combatHero[teamType] then
  81. human.db.combatHero[teamType] = nil
  82. end
  83. end
  84. --根据阵法id返回可用站位
  85. function getPosList(formation)
  86. local formationConf = FormationExcel[formation]
  87. if not formationConf.posList then
  88. for k,v in pairs(FormationExcel) do
  89. v.posList = {}
  90. for _,v1 in ipairs(v.pos) do
  91. v.posList[v1] = 1
  92. end
  93. end
  94. end
  95. return formationConf.posList
  96. end
  97. function getCombatHeros(human, combatType)
  98. local combatHeroDB = getCombatHeroDB(human,combatType)
  99. return combatHeroDB.list,combatHeroDB.helpList,combatHeroDB.formation or 1,combatHeroDB
  100. end
  101. -- 清空出战信息
  102. function cleanCombatHeros(human, combatType)
  103. local teamType = getTeamType(combatType)
  104. human.db.combatHero[teamType] = nil
  105. end
  106. -- 拷贝上阵
  107. function copyCombatHeros(human, sourceType, targetType)
  108. local sTeamType = getTeamType(sourceType)
  109. local tTeamType = getTeamType(targetType)
  110. if sTeamType == tTeamType then return end
  111. local combatHeroDB = human.db.combatHero[sTeamType]
  112. human.db.combatHero[tTeamType] = Util.copyTable(combatHeroDB)
  113. end
  114. local function table_find(tbl, val)
  115. for _, v in pairs(tbl) do
  116. if v == val then
  117. return true
  118. end
  119. end
  120. return false
  121. end
  122. -- 检查当前上阵的英雄是否在目标阵容里上阵了
  123. local function heroExclusionCheck(human, exclusionTypeList, nowHeroLlist)
  124. for _, combatType in ipairs(exclusionTypeList) do
  125. local combatHeroDB = getCombatHeroDB(human, combatType)
  126. if combatHeroDB and combatHeroDB.list then
  127. for _, heroUuid in pairs(nowHeroLlist)do
  128. if heroUuid ~= "0" and heroUuid ~= "" then
  129. if table_find(combatHeroDB.list, heroUuid) then
  130. return false
  131. end
  132. end
  133. end
  134. end
  135. end
  136. return true
  137. end
  138. -- 可否更新阵容
  139. function CheckUpdatePos(human, msg)
  140. if msg.type == CombatDefine.COMBAT_TYPE4 then
  141. if not JjcGodWarLogic.checkCanPos(human) then return end
  142. end
  143. if msg.type == CombatDefine.COMBAT_TYPE24 then
  144. local moduleFn = CombatLogic.getModule(msg.type)
  145. if moduleFn and moduleFn.checkUpdatePos then
  146. return moduleFn.checkUpdatePos(human, msg)
  147. end
  148. return
  149. end
  150. if msg.type == CombatDefine.COMBAT_TYPE25 or msg.type == CombatDefine.COMBAT_TYPE26 or
  151. msg.type == CombatDefine.COMBAT_TYPE27 or msg.type == CombatDefine.COMBAT_TYPE28 or
  152. msg.type == CombatDefine.COMBAT_TYPE35 or msg.type == CombatDefine.COMBAT_TYPE37 then
  153. local moduleFn = CombatLogic.getModule(msg.type)
  154. if moduleFn and moduleFn.checkUpdatePos then
  155. if not moduleFn.checkUpdatePos(human, msg) then
  156. return false
  157. end
  158. end
  159. end
  160. local posList = getPosList(msg.formation)
  161. local heroList = Util.split(msg.heroList, ",")
  162. local helpList = Util.split(msg.helpList, ",", true)
  163. local exclusionTypeList = CombatDefine.COMBAT_EXCLUSION_LIST[msg.type]
  164. if exclusionTypeList then
  165. if not heroExclusionCheck(human, exclusionTypeList, heroList) then
  166. return Broadcast.sendErr(human, Lang.COMMON_HERO_UPPOS)
  167. end
  168. end
  169. local cnt = 0
  170. local useList = { }
  171. local fatherList = { }
  172. -- 确定英雄存不存在
  173. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  174. local uuid = heroList[i] or ""
  175. if uuid ~= "0" and uuid ~= "" then
  176. if i == CombatDefine.COMBAT_HERO_CNT and canBackup(human) == 0 then
  177. -- 援军未激活
  178. return Broadcast.sendErr(human, Lang.HELP_HERO_NOT_ACTIVATE)
  179. end
  180. if posList[i] == nil and i ~= CombatDefine.COMBAT_HERO_CNT then
  181. -- 站位不可用 POS_ERROR
  182. return Broadcast.sendErr(human, Lang.POS_ERROR)
  183. end
  184. local heroGrid
  185. if msg.type == CombatDefine.COMBAT_TYPE37 then
  186. ServerCommerceActBattleGroundNS = ServerCommerceActBattleGroundNS or require("serverCommerce.ServerCommerceActBattleGroundNS")
  187. heroGrid = ServerCommerceActBattleGroundNS.getHeroGridByUuid(human, uuid)
  188. else
  189. heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  190. end
  191. if not heroGrid then
  192. return Broadcast.sendErr(human, Lang.DRILL_CHOOSE_FRIEND_ERR_INFO)
  193. end
  194. local heroConfig = HeroExcel.hero[heroGrid.id]
  195. if useList[uuid] or fatherList[heroGrid.id] then
  196. -- 同父类英雄重复
  197. return Broadcast.sendErr(human, Lang.HERO_SAME)
  198. else
  199. cnt = cnt + 1
  200. useList[uuid] = true
  201. fatherList[heroGrid.id] = true
  202. end
  203. end
  204. end
  205. if cnt == 0 then
  206. -- 上阵英雄空
  207. return Broadcast.sendErr(human, Lang.NO_HERO)
  208. end
  209. -- 检查辅助对象是否激活 todo
  210. return true, heroList, helpList
  211. end
  212. -- 上阵成功处理
  213. function onUpdatePos(human, teamType)
  214. for combatType, config in pairs(CombatExcel.combat) do
  215. if config.teamType == teamType then
  216. CombatLogic.onUpdatePos(human, combatType)
  217. if combatType == CombatDefine.COMBAT_TYPE1 then
  218. ObjHuman.doCalc(human)
  219. local heroListZDL = getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE1)
  220. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_8,heroListZDL)
  221. RecommendLineup.RecommendLineup_UpDate(human)
  222. end
  223. end
  224. end
  225. end
  226. -- 更新上阵信息
  227. function updatePos(human, msg)
  228. local combatType = msg.type
  229. local canUpdate,heroList,helpList = CheckUpdatePos(human,msg)
  230. if not canUpdate then
  231. return Broadcast.sendErr(human, Lang.COMBAT_POS__ERR)
  232. end
  233. local combatHeroDB, teamType = getCombatHeroDB(human,combatType)
  234. combatHeroDB.formation = msg.formation
  235. combatHeroDB.list = heroList
  236. combatHeroDB.helpList = helpList
  237. local msgRet = Msg.gc.GC_COMBAT_POS_UPDATE
  238. msgRet.type = combatType
  239. msgRet.teamType = teamType
  240. Msg.send(msgRet,human.fd)
  241. if combatType == CombatDefine.COMBAT_TYPE1 then
  242. HeroLogic.sendBagDots(human)
  243. end
  244. RoleHeadLogic.CG_ROLE_COMBATHERO_QUERY(human, msg.type)
  245. onUpdatePos(human, teamType)
  246. if combatType == CombatDefine.COMBAT_TYPE1 or combatType == CombatDefine.COMBAT_TYPE32 then
  247. if combatType == CombatDefine.COMBAT_TYPE1 then
  248. local list = getCombatHeros(human, CombatDefine.COMBAT_TYPE32)
  249. if next(list) then
  250. return
  251. end
  252. end
  253. local GodsAreaNS = require("godsArea.GodsAreaNS")
  254. GodsAreaNS.UpdateHeroData(human)
  255. end
  256. end
  257. -- 设置能否跳过
  258. function setQuick(human, combatType, isQuick)
  259. local combatConfig = CombatExcel.combat[combatType]
  260. if combatConfig.isQuick == 1 then
  261. human.db.combatQuick[combatType] = isQuick
  262. end
  263. end
  264. -- 升级检测
  265. function onLvUp(human, oldLv, newLv)
  266. local heroListZDL = getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE1)
  267. if heroListZDL <= 0 then return end
  268. local jjcDenType = CombatDefine.COMBAT_TYPE3
  269. local jjcGodType = CombatDefine.COMBAT_TYPE4
  270. local jjcDenLv = RoleSystemLogic.getOpenLv(CombatExcel.combat[jjcDenType].systemID)
  271. local jjcGodLv = RoleSystemLogic.getOpenLv(CombatExcel.combat[jjcGodType].systemID)
  272. local change = false
  273. -- 同步 战役阵容 到 竞技场防守阵容
  274. if oldLv < jjcDenLv and newLv >= jjcDenLv then
  275. local heroListJjc = getCombatHeroZDL(human, jjcDenType)
  276. if heroListJjc <= 0 then
  277. copyCombatHeros(human, CombatDefine.COMBAT_TYPE1, jjcDenType)
  278. change = true
  279. end
  280. end
  281. -- 同步 战役阵容 到 众神之战/王者争霸
  282. if oldLv < jjcGodLv and newLv >= jjcGodLv then
  283. local heroListJjc = getCombatHeroZDL(human, jjcGodType)
  284. if heroListJjc <= 0 then
  285. copyCombatHeros(human, CombatDefine.COMBAT_TYPE1, jjcGodType)
  286. change = true
  287. end
  288. end
  289. if change then
  290. ObjHuman.save(human)
  291. end
  292. end
  293. -- 获取上阵战力
  294. function getCombatHeroZDL(human, combatType)
  295. local zhandouli = 0
  296. local teamType = getTeamType(combatType)
  297. if teamType then
  298. local heroList = getCombatHeros(human, combatType)
  299. if heroList then
  300. for pos = 1, CombatDefine.COMBAT_HERO_CNT do
  301. local uuid = heroList[pos]
  302. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  303. if heroGrid and type(heroGrid) == "table" then
  304. if human.heroAttrs and not human.heroAttrs[heroGrid.bagIndex] then
  305. RoleAttr.doCalcHero(human, heroGrid.bagIndex)
  306. end
  307. zhandouli = zhandouli + (heroGrid.zhandouli or 0)
  308. end
  309. end
  310. end
  311. end
  312. return zhandouli
  313. end
  314. local function getSinglePosAttr(net, attrCfg)
  315. for k ,v in ipairs(attrCfg) do
  316. net[k].key = v[1]
  317. net[k].value = v[2]
  318. net[0] = k
  319. end
  320. end
  321. -- 发送阵型信息
  322. FormationInitFlag = nil
  323. function formationQuery(human)
  324. local msgRet = Msg.gc.GC_COMBAT_FORMATION_QUERY
  325. if not FormationInitFlag then
  326. FormationInitFlag = true
  327. local len = 0
  328. for k,v in ipairs(FormationExcel) do
  329. len = len + 1
  330. local net = msgRet.list[len]
  331. local len1 = 0
  332. for k1,v1 in ipairs(v.pos) do
  333. len1 = len1 + 1
  334. net.list[len1] = v1
  335. end
  336. net.list[0] = len1
  337. --阵法属性加成
  338. for k2,v2 in ipairs(v.attr) do
  339. getSinglePosAttr(net.posAttrLit[k2].posAttr, v2)
  340. net.posAttrLit[0] = k2
  341. end
  342. net.id = k
  343. net.lv = v.lv
  344. net.icon = v.icon
  345. net.name = v.name
  346. end
  347. msgRet.list[0] = len
  348. end
  349. msgRet.lv = human.db.lv
  350. Msg.send(msgRet,human.fd)
  351. end
  352. -- 去掉所有阵容中的数据
  353. function updateAllPos(human, uuid)
  354. heroIndexByDelForPos(human, uuid)
  355. local msgRet = Msg.gc.GC_HERO_UPDATE_ALL_POS
  356. Msg.send(msgRet,human.fd)
  357. end
  358. -- 英雄被分解 从默认出战中 去除
  359. function heroIndexByDelForPos(human, uuid)
  360. if not uuid or uuid == "0" or uuid == "" then return end
  361. for teamType, combatHero in pairs(human.db.combatHero) do
  362. if teamType ~= CombatDefine.COMBAT_TYPE10 then
  363. local isChange = nil
  364. for k, v in pairs(combatHero.list) do
  365. if v == uuid then
  366. combatHero.list[k] = nil
  367. isChange = true
  368. end
  369. end
  370. if isChange then
  371. onUpdatePos(human, teamType)
  372. posQuery(human, teamType)
  373. end
  374. end
  375. end
  376. end
  377. function caclCampAttr(attr, camp, cnt)
  378. -- 计算基础属性
  379. local conf = CombatPosExcel[camp]
  380. if basicsAttrExcel then
  381. for _, v in ipairs(conf) do
  382. if cnt == v.cnt then
  383. for k1,v1 in ipairs(v.attrs) do
  384. attr[v1[1]] = attr[v1[1]] or 0
  385. attr[v1[1]] = attr[v1[1]] + v1[2]
  386. end
  387. end
  388. end
  389. end
  390. end
  391. PosAttrInitFlag = nil
  392. function posAttrQuery(human)
  393. local msgRet = Msg.gc.GC_COMBAT_POS_ATTR_QUERY
  394. if not PosAttrInitFlag then
  395. PosAttrInitFlag = true
  396. local len = 0
  397. for k,v in ipairs(DefineExcel.attrs) do
  398. len = len + 1
  399. msgRet.attrs[len].key = v[1]
  400. msgRet.attrs[len].value = v[2]
  401. end
  402. msgRet.attrs[0] = len
  403. len = 0
  404. for camp = 1,CombatDefine.CAMP_ALL do
  405. local conf = CombatPosExcel[camp]
  406. len = len + 1
  407. local net = msgRet.list[len]
  408. net.camp = camp
  409. net.name = conf[1].name
  410. local len1 = 0
  411. for k,v in ipairs(conf) do
  412. len1 = len1 + 1
  413. local subNet = net.list[len1]
  414. subNet.cnt = v.cnt
  415. local len2 = 0
  416. for k,v in ipairs(v.attrs) do
  417. len2 = len2 + 1
  418. subNet.attrs[len2].key = v[1]
  419. subNet.attrs[len2].value = v[2]
  420. end
  421. subNet.attrs[0] = len2
  422. end
  423. net.list[0] = len1
  424. end
  425. msgRet.list[0] = len
  426. end
  427. Msg.send(msgRet,human.fd)
  428. end
  429. function getPosAttr(objList)
  430. local campList = {}
  431. for i = 1,CombatDefine.COMBAT_HERO_CNT do
  432. local obj = objList[i]
  433. local config = CombatLogic.getConfigByObj(obj)
  434. if not config then return end
  435. campList[config.camp] = campList[config.camp] or 0
  436. campList[config.camp] = campList[config.camp] + 1
  437. end
  438. local attr = {}
  439. for k, v in pairs(campList) do
  440. local camp = k
  441. local cnt = v
  442. caclCampAttr(attr, camp, cnt)
  443. end
  444. return attr
  445. end
  446. local function calcSinglePosAttr(posCfg, pos, obj)
  447. local idx = 0
  448. for k, v in ipairs(posCfg.pos) do
  449. if v == obj.formationPos then
  450. idx = k
  451. break
  452. end
  453. end
  454. local posAttr = posCfg.attr[idx]
  455. for _, v in ipairs(posAttr or {}) do
  456. local attrType = v[1]
  457. local attrValue = v[2]
  458. obj.sysAttr[attrType] = (obj.sysAttr[attrType] or 0) + attrValue
  459. obj.isSysAttrChange = true
  460. end
  461. end
  462. local function posAttrAdd(formation, posList)
  463. --阵法中单个位置的属性加成
  464. local posCfg = getFormationConfig(formation)
  465. if posCfg then
  466. for _,pos in ipairs(posList) do
  467. local obj = CombatImpl.objList[pos]
  468. if obj then
  469. calcSinglePosAttr(posCfg, pos, obj)
  470. end
  471. end
  472. end
  473. end
  474. function onFightBegin(human)
  475. -- 获取进攻方种族属性
  476. local attrs1 = human.combat.posAttr[1]
  477. if attrs1 then
  478. for k,v in pairs(attrs1) do
  479. for _,pos in ipairs(CombatDefine.SIDE2POS[CombatDefine.ATTACK_SIDE]) do
  480. local obj = CombatImpl.objList[pos]
  481. if obj then
  482. obj.sysAttr[k] = obj.sysAttr[k] + v
  483. obj.isSysAttrChange = true
  484. end
  485. end
  486. end
  487. end
  488. -- 获取防御方种族属性
  489. local attrs2 = human.combat.posAttr[2]
  490. if attrs2 then
  491. for k, v in pairs(attrs2) do
  492. for _,pos in ipairs(CombatDefine.SIDE2POS[CombatDefine.DEFEND_SIDE]) do
  493. local obj = CombatImpl.objList[pos]
  494. if obj then
  495. obj.sysAttr[k] = obj.sysAttr[k] + v
  496. obj.isSysAttrChange = true
  497. end
  498. end
  499. end
  500. end
  501. --阵法中位置的属性加成
  502. posAttrAdd(human.combat.atkFormation, CombatDefine.SIDE2POS[CombatDefine.ATTACK_SIDE])
  503. posAttrAdd(human.combat.defFormation, CombatDefine.SIDE2POS[CombatDefine.DEFEND_SIDE])
  504. end
  505. -- 获得 怪物组的 光环 血量加成
  506. function getCombatHpMaxJiaCheng(monsterOutID)
  507. local config = MonsterOutExcel[monsterOutID] or BattleMonsterExcel.monsterOut[monsterOutID] or BattleMonsterExcel2.monsterOut[monsterOutID]
  508. local jobList = {}
  509. if config and #config.member > 5 then
  510. for i,member in ipairs(config.member) do
  511. local monsterID = member[1]
  512. local monsterConfig = MonsterExcel[monsterID] or BattleMonsterExcel.monster[monsterID] or BattleMonsterExcel2.monster[monsterID]
  513. jobList[monsterConfig.job] = jobList[monsterConfig.job] or 0
  514. jobList[monsterConfig.job] = jobList[monsterConfig.job] + 1
  515. end
  516. end
  517. local attr = {}
  518. for k, v in pairs(jobList) do
  519. local camp = k
  520. local cnt = v
  521. caclCampAttr(attr, camp, cnt)
  522. end
  523. local buff = 0
  524. for k, v in pairs(attr) do
  525. if k == 203 then
  526. buff = v
  527. break
  528. end
  529. end
  530. return buff
  531. end
  532. function onLogin(human)
  533. posAttrQuery(human)
  534. formationQuery(human)
  535. sendAllCombatPos(human)
  536. end
  537. --获得type类型的战斗 上阵的魔兽id index 是指 冠军试炼场 有三个队列才用
  538. function getCombatMoshou(human,combatType)
  539. local _,helpList = getCombatHeros(human,combatType)
  540. return helpList[1]
  541. end
  542. function fontHelpNet(net,type,id,icon)
  543. net.type = type
  544. net.id = id or 0
  545. net.icon = icon or 0
  546. end
  547. function posQuery(human, combatType, group, param, flag, extraArgs)
  548. local combatConfig = CombatExcel.combat[combatType]
  549. if not combatConfig then return end
  550. local msgRet = Msg.gc.GC_COMBAT_POS_QUERY
  551. local len = 0
  552. local newIsQuickTime
  553. if combatType == CombatDefine.COMBAT_TYPE1 then
  554. newIsQuickTime = getTalismanAdd(human)
  555. end
  556. -- 购买新首充所有礼包后, 所有战斗都可以第一回合跳过
  557. local isAllQuick = NewFirstChargeLogic.IsBuyAllgift(human)
  558. -- local moduleFn = CombatLogic.getModule(msg.type)
  559. if group and group ~= 0 then
  560. for k,v in pairs(CombatExcel.combat) do
  561. if v.group == group and v.nRoleID then
  562. local bOpen = RoleSystemLogic.checkOpenByID(human, v.nRoleID)
  563. if true == bOpen then
  564. len = len + 1
  565. msgRet.list[len].type = k
  566. msgRet.list[len].name = v.name
  567. -- msgRet.list[len].isQuickTime = v.isQuickTime
  568. if isAllQuick then
  569. msgRet.list[len].isQuickTime = v.isQuickTime2
  570. else
  571. msgRet.list[len].isQuickTime = newIsQuickTime and newIsQuickTime or v.isQuickTime
  572. end
  573. msgRet.list[len].needLv = RoleSystemLogic.getOpenLv(v.systemID)
  574. end
  575. end
  576. end
  577. else
  578. len = len + 1
  579. msgRet.list[len].type = combatType
  580. msgRet.list[len].name = combatConfig.name
  581. -- msgRet.list[len].isQuickTime = combatConfig.isQuickTime
  582. if isAllQuick then
  583. msgRet.list[len].isQuickTime = combatConfig.isQuickTime2
  584. else
  585. msgRet.list[len].isQuickTime = newIsQuickTime and newIsQuickTime or combatConfig.isQuickTime
  586. end
  587. msgRet.list[len].needLv = RoleSystemLogic.getOpenLv(combatConfig.systemID)
  588. end
  589. msgRet.type = combatType
  590. msgRet.teamType = combatConfig.teamType
  591. msgRet.list[0] = len
  592. local heroList,helpList,formation
  593. if combatType == CombatDefine.COMBAT_TYPE36 and extraArgs then
  594. AnotherWorldBattleNS = AnotherWorldBattleNS or require("anotherWorldBattle.AnotherWorldBattleNS")
  595. heroList,helpList,formation = AnotherWorldBattleNS.getCombatHeros(human,combatType, extraArgs)
  596. else
  597. heroList,helpList,formation = getCombatHeros(human,combatType)
  598. end
  599. local formationConf = FormationExcel[formation]
  600. msgRet.formation = formation
  601. len = 0
  602. local totalZdl = 0
  603. for i = 1,CombatDefine.COMBAT_HERO_CNT do
  604. local uuid = heroList[i] or "0"
  605. local heroGrid = nil
  606. if combatType == CombatDefine.COMBAT_TYPE24 then
  607. heroGrid = LostTempleCombatLogic.getHeroGridByUuid(human, uuid)
  608. elseif combatType == CombatDefine.COMBAT_TYPE37 then
  609. ServerCommerceActBattleGroundNS = ServerCommerceActBattleGroundNS or require("serverCommerce.ServerCommerceActBattleGroundNS")
  610. heroGrid = ServerCommerceActBattleGroundNS.getHeroGridByUuid(human, uuid)
  611. else
  612. heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  613. end
  614. if heroGrid then
  615. len = len + 1
  616. msgRet.heroList[len].pos = i
  617. msgRet.heroList[len].bagIndex = heroGrid.bagIndex
  618. msgRet.heroList[len].uuid = heroGrid.uuid
  619. --重新计算战力 缓存的情况下
  620. if not heroGrid.isLostTemple then
  621. if not human.heroAttrs[heroGrid.bagIndex] then
  622. RoleAttr.doCalcHero(human, heroGrid.bagIndex)
  623. end
  624. else
  625. LostTempleCombatLogic.getHeroAttrs(human, heroGrid.bagIndex)
  626. end
  627. totalZdl = totalZdl + heroGrid.zhandouli
  628. end
  629. end
  630. msgRet.totalZdl = totalZdl
  631. msgRet.heroList[0] = len
  632. len = 0
  633. if helpList[1] and helpList[1] > 0 then
  634. len = len + 1
  635. MoshouLogic.setPosHelp(msgRet.helpList[len],helpList[1])
  636. end
  637. msgRet.helpList[0] = len
  638. msgRet.backUpLock = canBackup(human)
  639. local mapID = nil
  640. if param ~= nil then
  641. local args = Util.split(param, "|")
  642. mapID = CombatLogic.getMapID(human, combatType, args)
  643. end
  644. msgRet.mapID = mapID or 0
  645. msgRet.jibanLv = RoleSystemLogic.getOpenLv(RoleSystemDefine.ROLE_SYS_ID_207)
  646. msgRet.flag = flag or 0
  647. local cjPrivilege = ChengjiuLogic.checkPrivilege(human, ChengjiuDefine.PRIVILEGE_TYPE_8)
  648. msgRet.moshouLock = cjPrivilege and 1 or 0
  649. local skillID = MoshouLogic.getPutMoshouSkillID(human, combatType, helpList) or 0
  650. local skillConfig = SkillExcel.skill[skillID]
  651. msgRet.moshouSkill = skillConfig and skillConfig.icon or ""
  652. msgRet.elfSystemState = 0
  653. if ElfLogic.ModuleisOpen(human) then
  654. msgRet.elfSystemState = 1
  655. end
  656. Msg.send(msgRet,human.fd)
  657. end
  658. function canBackup(human)
  659. local backupDB = human.db.combatBackup or 0
  660. return backupDB
  661. end
  662. function activeBackup(human)
  663. human.db.combatBackup = 1
  664. end
  665. function checkPos(formation,pos)
  666. local ret
  667. if pos == CombatDefine.COMBAT_BACKUP_POS then
  668. ret = 1
  669. else
  670. local posList = getPosList(formation)
  671. if posList[pos] then
  672. ret = 1
  673. end
  674. end
  675. return ret
  676. end
  677. function getFormationConfig(formation)
  678. return FormationExcel[formation]
  679. end
  680. function sendAllCombatPos(human)
  681. for k, v in pairs(CombatExcel.combat) do
  682. posQuery(human, k, v.group)
  683. JibanLogic.sendQuery(human, k, v.teamType)
  684. end
  685. end
  686. -- 是否是阵容中最后一个英雄
  687. function isLastInCombat(human,heroIndex)
  688. if not heroIndex or heroIndex == "" then return end
  689. local combatTb = Util.copyTable(human.db.combatHero)
  690. for teamType, combatHero in pairs(combatTb) do
  691. local isChange = nil
  692. for k, v in pairs(combatHero.list) do
  693. if type(v) == "table" then
  694. for k2, v2 in pairs(v) do
  695. if v2 == heroIndex then
  696. v[k2] = nil
  697. isChange = true
  698. end
  699. end
  700. elseif v == heroIndex then
  701. combatHero[k] = nil
  702. isChange = true
  703. end
  704. end
  705. if isChange then
  706. local heroCnt = 0
  707. for k, v in pairs(combatHero) do
  708. if type(v) == "table" then
  709. for k2, v2 in pairs(v) do
  710. if v2 ~= 0 then
  711. heroCnt = heroCnt + 1
  712. end
  713. end
  714. elseif v ~= 0 then
  715. heroCnt = heroCnt + 1
  716. end
  717. end
  718. if heroCnt == 0 then
  719. return true
  720. end
  721. end
  722. end
  723. end
  724. local restrict = nil
  725. function getRestrict(attacker,defender,key)
  726. if not restrict then
  727. restrict = {}
  728. for k,v in ipairs(DefineExcel.attrs) do
  729. restrict[v[1]] = v[2]
  730. end
  731. end
  732. if restrict[key] and DefineExcel.restrict[attacker.camp] == defender.camp then
  733. return restrict[key]
  734. end
  735. return 0
  736. end
  737. function setCombatByUnionWarGm(human, combatType)
  738. local heroList = {}
  739. local cnt = 0
  740. local useList = { }
  741. local fatherList = { }
  742. local helpList = {}
  743. -- 确定英雄存不存在
  744. for i = 1, 6 do
  745. local uuid
  746. for k, v in pairs(human.db.heroBag) do
  747. if k and k > 0 and v and v.uuid then
  748. uuid = v.uuid
  749. break
  750. end
  751. end
  752. if uuid then
  753. cnt = cnt + 1
  754. heroList[cnt] = uuid
  755. end
  756. end
  757. local combatHeroDB, teamType = getCombatHeroDB(human,combatType)
  758. combatHeroDB.formation = 1
  759. combatHeroDB.list = heroList
  760. combatHeroDB.helpList = helpList
  761. end
  762. -- 更新战力
  763. function updateZdl(human, uuidList)
  764. local list = Util.split(uuidList, "|")
  765. local msgRet = Msg.gc.GC_HERO_UPDATE_ZDL
  766. local len = 0
  767. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  768. local uuid = list[i]
  769. if uuid then
  770. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  771. if not heroGrid then return end
  772. if not human.heroAttrs[heroGrid.bagIndex] then
  773. RoleAttr.doCalcHero(human, heroGrid.bagIndex)
  774. len = len + 1
  775. msgRet.list[len].uuid = uuid
  776. msgRet.list[len].zdl = heroGrid.zhandouli
  777. end
  778. end
  779. end
  780. if len > 0 then
  781. msgRet.list[0] = len
  782. Msg.send(msgRet,human.fd)
  783. end
  784. end
  785. ----------------------精灵-------------------------
  786. -- 查询某个战斗类型的精灵上阵数据
  787. function Elf_Pos_Query(human, combatType, extraArgs)
  788. local combatPosData
  789. if combatType == CombatDefine.COMBAT_TYPE36 and extraArgs then
  790. AnotherWorldBattleNS = AnotherWorldBattleNS or require("anotherWorldBattle.AnotherWorldBattleNS")
  791. local v1,v2, v3
  792. v1, v2, v3, combatPosData = AnotherWorldBattleNS.getCombatHeros(human, combatType, extraArgs)
  793. if not combatPosData then
  794. return
  795. end
  796. else
  797. combatPosData = getCombatHeroDB(human,combatType)
  798. end
  799. local elfList = combatPosData.elfList
  800. local msgRet = Msg.gc.GC_COMBAT_ELFPOS_QUERY
  801. local msgElfPosArr = msgRet.elfPosArr
  802. msgElfPosArr[0] = CombatDefine.COMBAT_ELF_NOW_CNT
  803. for i=1, CombatDefine.COMBAT_ELF_NOW_CNT do
  804. msgElfPosArr[i].elfId = 0
  805. msgElfPosArr[i].nowSkillDesc = ""
  806. msgElfPosArr[i].nowSkillIcon = ""
  807. if elfList and elfList[i] then
  808. local elfId = elfList[i]
  809. local skillId = ElfLogic.GetElfSkill(human, elfId)
  810. local skillConfig = Skill.GetSkillConfig(skillId)
  811. if skillConfig then
  812. msgElfPosArr[i].elfId = elfId
  813. msgElfPosArr[i].nowSkillDesc = skillConfig.desc
  814. msgElfPosArr[i].nowSkillIcon = skillConfig.icon
  815. end
  816. end
  817. end
  818. Msg.send(msgRet,human.fd)
  819. end
  820. -- 更新某个战斗类型的精灵上阵数据
  821. function Elf_Pos_Update(human, combatType, elfIdArr, extraArgs)
  822. local combatPosData
  823. if combatType == CombatDefine.COMBAT_TYPE36 and extraArgs then
  824. AnotherWorldBattleNS = AnotherWorldBattleNS or require("anotherWorldBattle.AnotherWorldBattleNS")
  825. local v1,v2, v3
  826. v1, v2, v3, combatPosData = AnotherWorldBattleNS.getCombatHeros(human, combatType, extraArgs)
  827. if not combatPosData then
  828. return
  829. end
  830. else
  831. combatPosData = getCombatHeroDB(human,combatType)
  832. end
  833. local ElfEecordTb = {}
  834. for _ ,elfId in ipairs(elfIdArr) do
  835. if elfId > 0 then
  836. if not ElfLogic.IsActivateElf(human, elfId) then
  837. return Broadcast.sendErr(human, Lang.ELF_NOT_ACTIVATE)
  838. end
  839. if ElfEecordTb[elfId] then
  840. return Broadcast.sendErr(human, Lang.ELF_SANME_ERR)
  841. end
  842. ElfEecordTb[elfId] = true
  843. end
  844. end
  845. combatPosData.elfList = {}
  846. for i=1, CombatDefine.COMBAT_ELF_NOW_CNT do
  847. local elfId = elfIdArr[i]
  848. if elfId > 0 then
  849. combatPosData.elfList[i] = elfId
  850. end
  851. end
  852. -- combatPosData.elfList = elfIdArr
  853. Elf_Pos_Query(human, combatType, extraArgs)
  854. end