CombatPosLogic.lua 26 KB

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