CombatPosLogic.lua 28 KB

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