CombatPosLogic.lua 23 KB

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