CombatPosLogic.lua 27 KB

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