CombatPosLogic.lua 29 KB

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