CombatPosLogic.lua 24 KB

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