CombatPosLogic.lua 26 KB

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