CombatPosLogic.lua 28 KB

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