AnotherWorldBattleNS.lua 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. -- 异界之战
  2. --db
  3. --[=[
  4. human.db.anotherWorlBattle = {
  5. startTime = nil,
  6. formation = {
  7. [cityId1] = {
  8. [pointIdx1] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  9. [pointIdx2] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  10. },
  11. [cityId2] = {
  12. [pointIdx1] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  13. [pointIdx2] = {list = {},helpList = {},formation = 1,jiban = {}, elfList = {}}
  14. },
  15. }
  16. }
  17. ]=]--
  18. local Config = require("Config")
  19. local Msg = require("core.Msg")
  20. local Lang = require("common.Lang")
  21. local ObjHuman = require("core.ObjHuman")
  22. local Broadcast = require("broadcast.Broadcast")
  23. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  24. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  25. local CombatDefine = require("combat.CombatDefine")
  26. local RoleDBLogic = require("role.RoleDBLogic")
  27. local CombatPosLogic = require("combat.CombatPosLogic")
  28. local CombatLogic = require("combat.CombatLogic")
  29. local MailExcel = require("excel.mail")
  30. local Util = require("common.Util")
  31. local InnerMsg = require("core.InnerMsg")
  32. local RoleHeadLogic = require("role.RoleHeadLogic")
  33. local MailManager = require("mail.MailManager")
  34. local Log = require("common.Log")
  35. local Timer = require("core.Timer")
  36. local Grid = require("bag.Grid")
  37. local UnionLogic = require("union.UnionLogic")
  38. local BillboardLogic = require("billboard.BillboardLogic")
  39. local BillboardDefine = require("billboard.BillboardDefine")
  40. local AnotherWorldBattleDefine = require("anotherWorldBattle.AnotherWorldBattleDefine")
  41. local AnotherWorldBattleConfig = require("excel.anotherWorldBattle")
  42. local MonsterGrid = require("monster.MonsterGrid")
  43. local RoleConfig = require("excel.role")
  44. local MonsterExcel = require("excel.monster")
  45. local HeroExcel = require("excel.hero")
  46. local MiddleCommonLogic = require("middle.MiddleCommonLogic")
  47. local CombatImpl = require("combat.CombatImpl")
  48. local RoleAttr = require("role.RoleAttr")
  49. local function writeLog(logStr)
  50. Log.write(Log.LOGID_OSS_ANOTHERWORLDBATTLE, logStr)
  51. end
  52. local function sendMail(mailId, receiverUuid, itemArray, extraInfo)
  53. if not mailId or not receiverUuid then
  54. return
  55. end
  56. local v1,v2,v3,v4,v5 = extraInfo and extraInfo[1] or 0, extraInfo and extraInfo[2] or 0, extraInfo and extraInfo[3] or 0, extraInfo and extraInfo[4] or 0, extraInfo and extraInfo[5] or 0
  57. local mailCfg = MailExcel.mail[mailId]
  58. local content = Util.format(mailCfg.content, v1,v2,v3,v4,v5)
  59. MailManager.add(MailManager.SYSTEM, receiverUuid, mailCfg.title, content, itemArray, mailCfg.senderName or "GM")
  60. end
  61. local function createRewardQueue()
  62. local issueRewardQueue = {
  63. playerArray = {},
  64. insertMaxNum = 100, -- 一次最多插入数据库的邮件数量
  65. repeatMaxTimes = 3, -- 重试次数
  66. repeatTb = {},
  67. extraInfo = {},
  68. }
  69. function issueRewardQueue:add(playerInfo)
  70. table.insert(self.playerArray, playerInfo)
  71. end
  72. function issueRewardQueue:insertDB()
  73. local maxNum = math.min(self.insertMaxNum, #self.playerArray)
  74. for i=1, maxNum do
  75. local resTag = AnotherWorldBattleDefine.AB_MAIL_SUCC_TAG
  76. local playerInfo = table.remove(self.playerArray)
  77. local uuid = playerInfo[1]
  78. local ok, err = pcall(sendMail, AnotherWorldBattleDefine.AB_AWARD_MAIL_ID, uuid, playerInfo[2], issueRewardQueue.extraInfo)
  79. if not ok then
  80. if not self.repeatTb[uuid] or self.repeatTb[uuid] < self.repeatMaxTimes then
  81. issueRewardQueue:add(playerInfo)
  82. self.repeatTb[uuid] = (self.repeatTb[uuid] or 0) + 1
  83. end
  84. resTag = AnotherWorldBattleDefine.AB_MAIL_FAIL_TAG
  85. end
  86. local str = string.format("Result: %s, playerUuid: %s, insertErrTimes: %d, errInfo: %s",
  87. resTag, uuid, self.repeatTb[uuid] or 0, err)
  88. writeLog(str)
  89. end
  90. if #self.playerArray > 0 then
  91. Timer.addLater(3, self.insertDB, self)
  92. end
  93. end
  94. return issueRewardQueue
  95. end
  96. -- 获取当天是星期几
  97. local function getWDay()
  98. return Util.getWeekDay()
  99. end
  100. -- 计算怪物战力
  101. local function calcMonsterPower(monsterOutID)
  102. local power = 0
  103. local objList = MonsterGrid.createMonsterObjListByMonsterOutID(monsterOutID)
  104. if not objList then
  105. return power
  106. end
  107. for _, monster in ipairs(objList) do
  108. power = power + (monster.power or 0)
  109. end
  110. return power
  111. end
  112. -- 根据据点所属城池,计算多个据点每分钟产出道具数量之和
  113. local function calcPointAward(cityIdArr)
  114. local myUnionAwardNum = 0
  115. if cityIdArr then
  116. for _, cityId in ipairs(cityIdArr) do
  117. local targetCityCfg = AnotherWorldBattleConfig.city[cityId]
  118. if targetCityCfg.isBaseCity == 1 then
  119. myUnionAwardNum = myUnionAwardNum + targetCityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  120. else
  121. myUnionAwardNum = myUnionAwardNum + targetCityCfg.cityAward[2]
  122. end
  123. end
  124. end
  125. return myUnionAwardNum
  126. end
  127. -- 获取展示部位的固定Id
  128. local function getDefaultShowId(showType, idx)
  129. local targetCfg
  130. if showType == 1 then
  131. targetCfg = RoleConfig.head
  132. else
  133. targetCfg = RoleConfig.headFrame
  134. end
  135. local t = {}
  136. for k in pairs(targetCfg) do
  137. t[#t+1] = k
  138. end
  139. table.sort(t)
  140. return t[idx] or t[1]
  141. end
  142. -- 单个英雄数据
  143. local function getHeroInfo(human, targetHeroUuid)
  144. local HeroLogic = require("hero.HeroLogic")
  145. local heroGrid = HeroLogic.getHeroGridByUuid(human, targetHeroUuid)
  146. if heroGrid then
  147. local heroCfg = HeroExcel.hero[heroGrid.id]
  148. RoleAttr.calcHeroGrid(heroGrid, nil, human)
  149. local heroInfo = {
  150. heroUuid = targetHeroUuid,
  151. heroStar = heroGrid.star,
  152. heroLevel = heroGrid.lv,
  153. heroCamp = heroGrid.camp or heroCfg.camp,
  154. heroBody = heroCfg.body,
  155. heroIcon = heroGrid.head or heroCfg.head,
  156. heroPower = heroGrid.zhandouli,
  157. heroId = heroGrid.id,
  158. heroQuality = heroCfg.grade,
  159. }
  160. return heroInfo
  161. end
  162. end
  163. -- 获取上阵英雄数据
  164. local function getHeroListInfo(human, targetHeroUuid)
  165. local len = 0
  166. local heroArr = {}
  167. local heroList = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  168. if not next(heroList) then
  169. return heroArr
  170. end
  171. for _, heroUuid in pairs(heroList) do
  172. if (heroUuid ~= "" and heroUuid ~= "0") and (not targetHeroUuid or targetHeroUuid == heroUuid) then
  173. len = len + 1
  174. heroArr[len] = getHeroInfo(human, heroUuid)
  175. end
  176. end
  177. if len == 0 then
  178. return
  179. end
  180. return heroArr
  181. end
  182. -- 生成展示数据
  183. local function generateShowInfo(human)
  184. local showInfo = {
  185. name = human.db.name,
  186. lv = human.db.lv,
  187. power = human.db.zhandouli,
  188. }
  189. showInfo.head = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_1)
  190. showInfo.headFrame = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_2)
  191. -- showInfo.body = RoleHeadLogic.getRoleAppearance(human, RoleHeadLogic.HEAD_TYPE_3)
  192. showInfo.heroArr = getHeroListInfo(human)
  193. return showInfo
  194. end
  195. -- 阵容数据检查,如果不在 "活动开启且战斗阶段" 则清空
  196. local function formationDataCheeck(human)
  197. if not human.db.anotherWorlBattle then
  198. return
  199. end
  200. -- 不在战斗阶段时间范围
  201. local wDay = getWDay()
  202. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] > wDay and AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] < wDay then
  203. human.db.anotherWorlBattle = nil
  204. end
  205. -- 处于战斗阶段最后一天, 但是活动已经结束
  206. local now = os.time()
  207. local toDayStartTime = Util.getDayStartTime(now)
  208. if AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] == wDay and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  209. human.db.anotherWorlBattle = nil
  210. end
  211. -- 处于战斗阶段时间范围内, 但是活动未开(因为每两轮活动时间间隔至少9天)
  212. local startTime = human.db.anotherWorlBattle.startTime
  213. local diffDays = Util.diffDay(startTime)
  214. if diffDays > 3 then
  215. human.db.anotherWorlBattle = nil
  216. end
  217. end
  218. -- 把玩家最新的异界之战所有防守英雄uuid推给客户端
  219. local function sendDefHeroArr(human)
  220. if not human.db.anotherWorlBattle then
  221. return
  222. end
  223. local len = 0
  224. local msgRet = Msg.gc.GC_AB_DEF_HERO_QUERY
  225. local heroUuidArrMsg = msgRet.heroUuidArr
  226. heroUuidArrMsg[0] = 0
  227. for _, pointList in pairs(human.db.anotherWorlBattle.formation) do
  228. for _, combatData in pairs(pointList) do
  229. local heroList = combatData.list
  230. for _, heroUuid in pairs(heroList) do
  231. if heroUuid ~= "" and heroUuid ~= "0" then
  232. len = len + 1
  233. heroUuidArrMsg[len] = heroUuid
  234. end
  235. end
  236. end
  237. end
  238. heroUuidArrMsg[0] = len
  239. Msg.send(msgRet, human.fd)
  240. end
  241. -- 是否是防守阵容中的英雄
  242. local function isDefHero(human, checkHeroUuid, excludeCityId, excludePointIdx)
  243. if not human.db.anotherWorlBattle then
  244. return false
  245. end
  246. for cityId, pointList in pairs(human.db.anotherWorlBattle.formation) do
  247. for pointIdx, combatData in pairs(pointList) do
  248. if (excludeCityId and excludeCityId == cityId) and (excludePointIdx and excludePointIdx == pointIdx) then
  249. break
  250. end
  251. local heroList = combatData.list
  252. for _, heroUuid in pairs(heroList) do
  253. if heroUuid == checkHeroUuid then
  254. return true
  255. end
  256. end
  257. end
  258. end
  259. return false
  260. end
  261. -- 是否是公会前二名
  262. local function isTopTwoUnion(human)
  263. local unionRanList = BillboardLogic.GetRankList(BillboardDefine.TYPE_UNION)
  264. if not unionRanList then
  265. return false
  266. end
  267. local unionId = human.db.unionUuid
  268. local isTopTwo = false
  269. for i=1, 2 do
  270. if unionRanList[i].uuid == unionId then
  271. isTopTwo = true
  272. break
  273. end
  274. end
  275. return isTopTwo
  276. end
  277. -- 是否处于战斗阶段
  278. local function isBattleStage()
  279. local wDay = getWDay()
  280. if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
  281. return true
  282. end
  283. return false
  284. end
  285. -- 生成奖励发放对象列表
  286. local function genAwardObjArr(unionOccupyInfo)
  287. local function calcMinute(timeArr)
  288. local minuteVal = 0
  289. for _, timeTb in ipairs(timeArr or {}) do
  290. local sec = timeTb[2] - timeTb[1]
  291. if sec > 0 then
  292. minuteVal = minuteVal + sec
  293. end
  294. end
  295. return math.floor(minuteVal / 60)
  296. end
  297. if not unionOccupyInfo.playerUuidArr or #unionOccupyInfo.playerUuidArr <= 0 then
  298. return
  299. end
  300. local itemList = {}
  301. local occupyCityInfo = {0,0,0,0,0}
  302. local item_185_Id = 185
  303. local item_185_Num = 0
  304. item_185_Num = item_185_Num + (unionOccupyInfo.occuoyPointNum or 0) -- 待优化
  305. -- 额外奖励
  306. for _, cityId in ipairs(unionOccupyInfo.occupyCityArr) do
  307. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  308. if cityCfg then
  309. if cityCfg.isBaseCity == 1 then
  310. item_185_Num = item_185_Num + 20
  311. occupyCityInfo[1] = occupyCityInfo[1] + 1
  312. else
  313. if cityCfg.cityLv == 2 then
  314. item_185_Num = item_185_Num + 2
  315. occupyCityInfo[2] = occupyCityInfo[2] + 1
  316. elseif cityCfg.cityLv == 3 then
  317. item_185_Num = item_185_Num + 3
  318. occupyCityInfo[3] = occupyCityInfo[3] + 1
  319. elseif cityCfg.cityLv == 4 then
  320. item_185_Num = item_185_Num + 5
  321. occupyCityInfo[4] = occupyCityInfo[4] + 1
  322. elseif cityCfg.cityLv == 5 then
  323. item_185_Num = item_185_Num + 20
  324. occupyCityInfo[5] = occupyCityInfo[5] + 1
  325. end
  326. end
  327. end
  328. end
  329. -- 占领据点每分钟的奖励
  330. for _, pointInfo in ipairs(unionOccupyInfo.point2CityIdArr) do
  331. local cityId = pointInfo[1]
  332. local occupyTimeArr = pointInfo[2]
  333. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  334. local totalMinVal = calcMinute(occupyTimeArr)
  335. if totalMinVal > 0 then
  336. local itemId, itemNum = cityCfg.cityAward[1], cityCfg.cityAward[2]
  337. itemList[itemId] = totalMinVal * itemNum
  338. end
  339. end
  340. if item_185_Num > 0 then
  341. itemList[item_185_Id] = item_185_Num
  342. end
  343. local itemArr = {}
  344. for itemId, itemNum in pairs(itemList) do
  345. itemArr[#itemArr+1] = { itemId, itemNum }
  346. end
  347. local awardObjArr = {}
  348. for _, playerUuid in ipairs(unionOccupyInfo.playerUuidArr) do
  349. awardObjArr[#awardObjArr+1] = {playerUuid, itemArr}
  350. end
  351. return awardObjArr, occupyCityInfo
  352. end
  353. -- 活动是否处于开启中
  354. function IsRuning(joinTime)
  355. local diffDays = Util.diffDay(joinTime)
  356. -- 活动最后一天, 如果当前时间 > 结束时间则标识活动结束
  357. if diffDays == 5 then
  358. local now = os.time()
  359. local toDayStartTime = Util.getDayStartTime(now)
  360. if now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  361. return false
  362. end
  363. end
  364. -- < 5天说明处于本轮活动的开启时间
  365. if diffDays > 5 then
  366. return false
  367. end
  368. return true
  369. end
  370. --检测上阵英雄
  371. function checkUpdatePos(human, msg)
  372. local heroList = Util.split(msg.heroList, ",")
  373. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  374. local uuid = heroList[i] or ""
  375. if uuid ~= "0" and uuid ~= "" then
  376. if isDefHero(human, uuid) then
  377. return false
  378. end
  379. end
  380. end
  381. return true
  382. end
  383. -- 公会战力更新
  384. function UnionPowerChange(unionId, newPower)
  385. if not isBattleStage() then
  386. return
  387. end
  388. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_UNION
  389. msgData.myUnionId = unionId
  390. msgData.updateData = {}
  391. msgData.updateData.power = newPower
  392. InnerMsg.sendMsg(0, msgData)
  393. end
  394. -- 玩家战力更新
  395. function PlayerPowerChange(human)
  396. if not isBattleStage() then
  397. return
  398. end
  399. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_PLAYER
  400. msgData.playerUuid = human.db._id
  401. msgData.myUnionId = human.db.unionUuid
  402. msgData.updateData = {}
  403. msgData.updateData.power = human.db.zhandouli
  404. InnerMsg.sendMsg(0, msgData)
  405. end
  406. function isOpen(human)
  407. return RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1306) -- 待改
  408. end
  409. function onLogin(human)
  410. formationDataCheeck(human)
  411. sendDefHeroArr(human)
  412. end
  413. -- 请求状态
  414. function AB_GetState(human)
  415. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_STATE
  416. msgData.sourceServerId = Config.SVR_INDEX
  417. msgData.playerUuid = human.db._id
  418. msgData.myUnionId = human.db.unionUuid or ""
  419. InnerMsg.sendMsg(0, msgData)
  420. end
  421. -- 报名
  422. function AB_Join(human)
  423. local unionId = human.db.unionUuid
  424. local msgRet = Msg.gc.GC_AB_JOIN
  425. if not unionId then
  426. msgRet.Joinstate = 3
  427. return Msg.send(msgRet, human.fd)
  428. end
  429. -- if not isOpen(human) then
  430. -- return Broadcast.sendErr(human, Lang.AB_JOIN_COND_NOT_SATIFY)
  431. -- end
  432. local wDay = getWDay()
  433. -- if not table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
  434. -- msgRet.Joinstate = 5
  435. -- return Msg.send(msgRet, human.fd)
  436. -- end
  437. if wDay ~= AnotherWorldBattleDefine.AB_JOIN_WDAY then
  438. msgRet.Joinstate = 5
  439. return Msg.send(msgRet, human.fd)
  440. end
  441. -- 公会排名前二才能参加
  442. if not isTopTwoUnion(human) then
  443. msgRet.Joinstate = 2
  444. return Msg.send(msgRet, human.fd)
  445. end
  446. -- 会长/副会长才能报名
  447. if not UnionLogic.IsTopTwoManager(human, unionId) then
  448. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANGER)
  449. end
  450. local queryFiles = {name = 1, zhandouli = 1}
  451. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  452. if not unionInfo then
  453. return Broadcast.sendErr(human, Lang.DATA_ERR)
  454. end
  455. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_JOIN
  456. msgData.sourceServerId = Config.SVR_INDEX
  457. msgData.playerUuid = human.db._id
  458. msgData.unionInfo = {
  459. name = unionInfo.name,
  460. power = unionInfo.zhandouli,
  461. unionId = unionId
  462. }
  463. InnerMsg.sendMsg(0, msgData)
  464. end
  465. -- 查询所有城池信息
  466. function AB_AllCity_Query(human)
  467. if not human.db.unionUuid then
  468. return
  469. end
  470. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_ALLCITY_QUERY
  471. msgData.sourceServerId = Config.SVR_INDEX
  472. msgData.playerUuid = human.db._id
  473. msgData.myUnionId = human.db.unionUuid
  474. InnerMsg.sendMsg(0, msgData)
  475. -- 报名状态查询
  476. -- local msgData2 = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GET_JOIN_STATE
  477. -- msgData2.sourceServerId = Config.SVR_INDEX
  478. -- msgData2.playerUuid = human.db._id
  479. -- msgData2.myUnionId = human.db.unionUuid
  480. -- InnerMsg.sendMsg(0, msgData2)
  481. end
  482. -- 查询单个城池的详细信息
  483. function AB_CityDetailed_Query(human, targetCityId)
  484. if not AnotherWorldBattleConfig.city[targetCityId] then
  485. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  486. end
  487. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
  488. msgData.sourceServerId = Config.SVR_INDEX
  489. msgData.playerUuid = human.db._id
  490. msgData.myUnionId = human.db.unionUuid
  491. msgData.targetCityId = targetCityId
  492. InnerMsg.sendMsg(0, msgData)
  493. end
  494. -- 查询某个城池的某个据点的详细信息
  495. function AB_PointDetailed_Query(human, targetCityId, targetPointIdx)
  496. if not AnotherWorldBattleConfig.city[targetCityId] then
  497. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  498. end
  499. if 0 >= targetPointIdx or AnotherWorldBattleDefine.AB_POINT_MAX_NUM < targetPointIdx then
  500. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  501. end
  502. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINTtDETAILED_QUERY
  503. msgData.sourceServerId = Config.SVR_INDEX
  504. msgData.playerUuid = human.db._id
  505. msgData.myUnionId = human.db.unionUuid
  506. msgData.targetCityId = targetCityId
  507. msgData.targetPointIdx = targetPointIdx
  508. InnerMsg.sendMsg(0, msgData)
  509. end
  510. -- 查询本公会出生点信息
  511. function AB_BaseCity_Query(human)
  512. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_BASECITY_QUERY
  513. msgData.sourceServerId = Config.SVR_INDEX
  514. msgData.playerUuid = human.db._id
  515. msgData.myUnionId = human.db.unionUuid
  516. InnerMsg.sendMsg(0, msgData)
  517. end
  518. -- 查询玩家占领的所有据点信息
  519. function AB_PlayerOccupyPOint_Query(human)
  520. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
  521. msgData.sourceServerId = Config.SVR_INDEX
  522. msgData.playerUuid = human.db._id
  523. msgData.myUnionId = human.db.unionUuid
  524. InnerMsg.sendMsg(0, msgData)
  525. end
  526. -- 查询公会排行榜
  527. function AB_UnionRank_Query(human)
  528. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
  529. msgData.sourceServerId = Config.SVR_INDEX
  530. msgData.playerUuid = human.db._id
  531. msgData.myUnionId = human.db.unionUuid
  532. InnerMsg.sendMsg(0, msgData)
  533. end
  534. -- 查询玩家排行榜
  535. function AB_PlayerRank_Query(human)
  536. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
  537. msgData.sourceServerId = Config.SVR_INDEX
  538. msgData.playerUuid = human.db._id
  539. msgData.myUnionId = human.db.unionUuid
  540. InnerMsg.sendMsg(0, msgData)
  541. end
  542. -- 发起集结
  543. function AB_Gather(human, targetCityId, opType)
  544. if not AnotherWorldBattleConfig.city[targetCityId] then
  545. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  546. end
  547. if opType ~= 1 and opType ~= 2 then
  548. return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR)
  549. end
  550. local unionId = human.db.unionUuid
  551. if not unionId then
  552. return Broadcast.sendErr(human, Lang.AB_NO_UNION)
  553. end
  554. -- 会长/副会长才能集结
  555. if not UnionLogic.IsTopTwoManager(human, unionId) then
  556. return Broadcast.sendErr(human, Lang.AB_NOT_TOPTWO_MANAGER)
  557. end
  558. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_GATHER
  559. msgData.sourceServerId = Config.SVR_INDEX
  560. msgData.playerUuid = human.db._id
  561. msgData.myUnionId = human.db.unionUuid
  562. msgData.targetCityId = targetCityId
  563. msgData.opType = opType
  564. InnerMsg.sendMsg(0, msgData)
  565. end
  566. -- 请求挑战某个据点
  567. function AB_Try_Challenge_Point(human, targetCityId, targetPointIdx)
  568. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  569. if not combatHero or not next(combatHero) then
  570. return Broadcast.sendErr(human, Lang.COMBAT_NEED_FIGHT_HERO)
  571. end
  572. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
  573. msgData.sourceServerId = Config.SVR_INDEX
  574. msgData.playerUuid = human.db._id
  575. msgData.myUnionId = human.db.unionUuid
  576. msgData.targetCityId = targetCityId
  577. msgData.targetPointIdx = targetPointIdx
  578. InnerMsg.sendMsg(0, msgData)
  579. end
  580. -- 战斗结束
  581. local function challenge_End(human, args)
  582. local cityId = args.cityId
  583. local pointIdx = args.pointIdx
  584. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_POINT_CHALLENGE_END
  585. msgData.sourceServerId = Config.SVR_INDEX
  586. msgData.playerUuid = human.db._id
  587. msgData.myUnionId = human.db.unionUuid
  588. msgData.targetCityId = cityId
  589. msgData.targetPointIdx = pointIdx
  590. msgData.challengeRes = args.challengeRes
  591. -- 挑战没有胜利
  592. if args.challengeRes ~= CombatDefine.RESULT_WIN then
  593. -- 说明之前已经在跨服上保存玩家的基础数据了
  594. if human.db.anotherWorlBattle then
  595. return
  596. end
  597. msgData.playerShowInfo = {
  598. name = human.db.name,
  599. lv = human.db.lv,
  600. power = human.db.zhandouli,
  601. }
  602. return InnerMsg.sendMsg(0, msgData)
  603. end
  604. if not human.db.anotherWorlBattle then
  605. human.db.anotherWorlBattle = {
  606. startTime = os.time(),
  607. formation = {}
  608. }
  609. end
  610. -- 把当前战斗阵容数据保存到当前模块,作为防守阵容
  611. local combatData = CombatPosLogic.getCombatHeroDB(human, CombatDefine.COMBAT_TYPE35)
  612. local formationData = human.db.anotherWorlBattle.formation or {}
  613. formationData[cityId] = formationData[cityId] or {}
  614. formationData[cityId][pointIdx] = Util.copyTable(combatData)
  615. -- 把最新的防守英雄uuid列表推送给客户端
  616. sendDefHeroArr(human)
  617. --同步到跨服
  618. msgData.playerShowInfo = generateShowInfo(human)
  619. InnerMsg.sendMsg(0, msgData)
  620. -- 清空战斗阵容
  621. CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMBAT_TYPE35)
  622. end
  623. -- 更换据点的防守阵容
  624. function AB_Update_Lineup(human, msg)
  625. if not isBattleStage() then
  626. return Broadcast.sendErr(human, Lang.AB_NOT_BATTLE_TIME)
  627. end
  628. local anotherWorlBattle = human.db.anotherWorlBattle
  629. if not anotherWorlBattle or not anotherWorlBattle.formation then
  630. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  631. end
  632. local cityId = msg.cityId
  633. local pointIdx = msg.pointIdx
  634. local formationData = anotherWorlBattle.formation
  635. if not formationData[cityId] or not formationData[cityId][pointIdx] then
  636. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_TARGET_POINT)
  637. end
  638. local res, heroList, helpList = CombatPosLogic.CheckUpdatePos(human, msg)
  639. if not res then
  640. return Broadcast.sendErr(human, Lang.COMBAT_POS__ERR)
  641. end
  642. local len = 0
  643. local heroArr = {}
  644. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  645. local uuid = heroList[i] or ""
  646. if uuid ~= "0" and uuid ~= "" then
  647. if isDefHero(human, uuid, cityId, pointIdx) then
  648. return Broadcast.sendErr(human, Lang.AB_HERO_IN_OTHER_POINT)
  649. end
  650. len = len + 1
  651. heroArr[len] = getHeroInfo(human, uuid)
  652. end
  653. end
  654. if len == 0 then
  655. return
  656. end
  657. local msgData = InnerMsg.lw.LW_ANOTHERWORLDBATTLE_UPDATE_POINT_LINEIP
  658. msgData.sourceServerId = Config.SVR_INDEX
  659. msgData.playerUuid = human.db._id
  660. msgData.heroArr = heroArr
  661. msgData.targetCityId = cityId
  662. msgData.targetPointIdx = pointIdx
  663. msgData.formation = msg.formation
  664. msgData.heroList = heroList
  665. msgData.helpList = helpList
  666. InnerMsg.sendMsg(0, msgData)
  667. end
  668. ------------------------------------C2N---------------------------------------------------
  669. -- 错误提示
  670. function C2N_ErrTips(msg)
  671. local human = ObjHuman.onlineUuid[msg.playerUuid]
  672. if not human then
  673. return
  674. end
  675. local tips = Lang.DATA_ERR
  676. local errCode = msg.errCode
  677. if errCode == AnotherWorldBattleDefine.ERR_CODE_1 then
  678. tips = Lang.AB_NOT_OPEN_TIME
  679. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_2 then
  680. tips = Lang.AB_NOT_UNION_NUM_EXCEED
  681. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_3 then
  682. tips = Lang.AB_UNION_NO_JOIN
  683. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_4 then
  684. tips = Lang.DATA_ERR
  685. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_5 then
  686. tips = Lang.AB_NOT_OCCUPY_POINT
  687. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_6 then
  688. tips = Lang.AB_GATHER_CD
  689. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_7 then
  690. tips = Lang.AB_CITY_NOT_ADDJION
  691. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_8 then
  692. tips = Lang.AB_JOINED
  693. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_9 then
  694. tips = Lang.AB_CITY_NO_GATHER
  695. elseif errCode == AnotherWorldBattleDefine.ERR_CODE_10 then
  696. tips = Lang.AB_OCCUPY_POINT_MAX
  697. end
  698. Broadcast.sendErr(human, tips)
  699. end
  700. -- 跨服返回状态
  701. function C2N_State(msg)
  702. local human = ObjHuman.onlineUuid[msg.playerUuid]
  703. if not human then
  704. return
  705. end
  706. local msgRet = Msg.gc.GC_AB_GetState
  707. msgRet.joinState = msg.joinState
  708. msgRet.systemState = msg.systemState
  709. if msgRet.joinState == 0 then
  710. local unionId = human.db.unionUuid
  711. if not unionId then
  712. msgRet.Joinstate = 2
  713. return Msg.send(msgRet, human.fd)
  714. end
  715. -- 公会排名前二才行
  716. if not isTopTwoUnion(human) then
  717. msgRet.Joinstate = 2
  718. return Msg.send(msgRet, human.fd)
  719. end
  720. end
  721. Msg.send(msgRet, human.fd)
  722. end
  723. -- 报名成功
  724. function C2N_Join_Succ(msg)
  725. local now = os.time()
  726. local unionId = msg.myUnionId
  727. UnionLogic.UpdateJoinAbTime(unionId, now)
  728. local human = ObjHuman.onlineUuid[msg.playerUuid]
  729. if not human then
  730. return
  731. end
  732. local msgRet = Msg.gc.GC_AB_JOIN
  733. msgRet.Joinstate = 1
  734. Msg.send(msgRet, human.fd)
  735. end
  736. -- 跨服返回的所有城池数据
  737. function C2N_AllCity_Query(msg)
  738. local human = ObjHuman.onlineUuid[msg.playerUuid]
  739. if not human then
  740. return
  741. end
  742. local msgRet = Msg.gc.GC_AB_ALLCITY_QUERY
  743. msgRet.myBaseCityId = msg.myUnionBaseCityId
  744. msgRet.hasPointNum = msg.hasPointNum
  745. msgRet.challengeTimes = msg.challengeTimes
  746. local now = os.time()
  747. msgRet.leftTime = msg.lastTime
  748. if msgRet.leftTime ~= 0 then
  749. msgRet.leftTime = (msg.lastTime + AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC) - now
  750. end
  751. msgRet.cityArr[0] = 0
  752. local cityArrMsg = msgRet.cityArr
  753. for cityId, cityInfo in ipairs(msg.cityArr) do
  754. cityArrMsg[0] = cityId
  755. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  756. cityArrMsg[cityId].cityId = cityId
  757. cityArrMsg[cityId].cityName = cityCfg.cityName
  758. cityArrMsg[cityId].cityLv = cityCfg.cityLv
  759. cityArrMsg[cityId].occupyPointNum = cityInfo.occupyPointNum or 0
  760. cityArrMsg[cityId].occupyUnionName = cityInfo.occupyUnionName or ""
  761. cityArrMsg[cityId].cityState = cityInfo.cityState
  762. cityArrMsg[cityId].adJoinCityArr[0] = #cityCfg.adJoinCityArr
  763. for i, cId in ipairs(cityCfg.adJoinCityArr) do
  764. cityArrMsg[cityId].adJoinCityArr[i] = cId
  765. end
  766. end
  767. msgRet.myOccupyCityArr[0] = #msg.myOccupyCityArr
  768. for i, cityId in ipairs(msg.myOccupyCityArr) do
  769. msgRet.myOccupyCityArr[i] = cityId
  770. end
  771. Msg.send(msgRet, human.fd)
  772. end
  773. -- 跨服返回某个城池详细数据
  774. function C2N_CityDetailed_Query(msg)
  775. local human = ObjHuman.onlineUuid[msg.playerUuid]
  776. if not human then
  777. return
  778. end
  779. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  780. local msgRet = Msg.gc.GC_AB_CITY_DETAILED_QUERY
  781. msgRet.cityId = msg.targetCityId
  782. msgRet.cityLv = cityCfg.cityLv
  783. msgRet.cityIconId = cityCfg.cityIconId
  784. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM )
  785. local myUnionAwardNum = calcPointAward(msg.myUnionOccupyArr)
  786. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  787. -- 活动没有进入战斗阶段时, 使用默认数据
  788. if #msg.pointArr == 0 then
  789. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  790. msg.pointArr[i] = {}
  791. end
  792. end
  793. msgRet.pointArr[0] = AnotherWorldBattleDefine.AB_POINT_MAX_NUM
  794. for pointIdx, pointInfo in ipairs(msg.pointArr) do
  795. if pointInfo.occupyUnionName then
  796. msgRet.pointArr[pointIdx].occupyUnionName = pointInfo.occupyUnionName
  797. msgRet.pointArr[pointIdx].occupyPlayerName = pointInfo.occupyPlayerName
  798. msgRet.pointArr[pointIdx].power = pointInfo.power
  799. msgRet.pointArr[pointIdx].state = pointInfo.state
  800. else
  801. msgRet.pointArr[pointIdx].occupyUnionName = ""
  802. msgRet.pointArr[pointIdx].occupyPlayerName = "防守者".. pointIdx --待改
  803. msgRet.pointArr[pointIdx].power = calcMonsterPower(cityCfg.pointMonsterId)
  804. msgRet.pointArr[pointIdx].state = pointInfo.state
  805. end
  806. end
  807. msgRet.gatherState = msg.gatherState
  808. if msg.gatherState == 1 then
  809. -- 公会会长/副会长才能集结
  810. if not UnionLogic.IsTopTwoManager(human, human.db.unionUuid) then
  811. msgRet.gatherState = 0
  812. end
  813. end
  814. Msg.send(msgRet, human.fd)
  815. end
  816. -- 跨服返回某个据点数据
  817. function C2N_PointDetailed_Query(msg)
  818. local human = ObjHuman.onlineUuid[msg.playerUuid]
  819. if not human then
  820. return
  821. end
  822. local pointInfo = msg.pointInfo
  823. local msgRet = Msg.gc.GC_AB_POINT_DETAILEDINFO_QUERY
  824. msgRet.state = pointInfo.state
  825. if pointInfo.name then
  826. msgRet.name = pointInfo.name
  827. msgRet.power = pointInfo.power
  828. msgRet.head = pointInfo.head
  829. msgRet.headFrame = pointInfo.headFrame
  830. msgRet.defLv = pointInfo.defLv
  831. msgRet.heroArr[0] = #pointInfo.heroArr
  832. for i, heroInfo in ipairs(pointInfo.heroArr) do
  833. msgRet.heroArr[i].heroBody = heroInfo.heroBody
  834. msgRet.heroArr[i].heroStar = heroInfo.heroStar
  835. msgRet.heroArr[i].heroLv = heroInfo.heroLv
  836. msgRet.heroArr[i].heroCamp = heroInfo.heroCamp
  837. msgRet.heroArr[i].heroIcon = heroInfo.heroIcon
  838. msgRet.heroArr[i].heroId = heroInfo.heroId
  839. msgRet.heroArr[i].heroQuality = heroInfo.heroQuality
  840. end
  841. else
  842. msgRet.name = "防守者" .. msg.targetPointIdx -- 待改
  843. msgRet.head = getDefaultShowId(1, msg.targetPointIdx)
  844. msgRet.headFrame = getDefaultShowId(2, msg.targetPointIdx)
  845. msgRet.defLv = 200
  846. local cityCfg = AnotherWorldBattleConfig.city[msg.targetCityId]
  847. msgRet.power = calcMonsterPower(cityCfg.pointMonsterId)
  848. msgRet.heroArr[0] = 0
  849. local monsterOutConfig = MonsterExcel.monsterOut[cityCfg.pointMonsterId]
  850. for idx, monsterInfo in ipairs(monsterOutConfig.member) do
  851. if idx > 6 then
  852. break
  853. end
  854. msgRet.heroArr[0] = idx
  855. local monsterID = monsterInfo[1]
  856. local mcf = MonsterExcel.monster[monsterID]
  857. msgRet.heroArr[idx].heroBody = mcf.body
  858. msgRet.heroArr[idx].heroStar = mcf.star
  859. msgRet.heroArr[idx].heroLv = monsterInfo[2]
  860. msgRet.heroArr[idx].heroCamp = mcf.camp
  861. msgRet.heroArr[idx].heroIcon = mcf.head
  862. msgRet.heroArr[idx].heroId = monsterID
  863. msgRet.heroArr[idx].heroQuality = mcf.heroQuality or 1
  864. end
  865. end
  866. Msg.send(msgRet, human.fd)
  867. end
  868. -- 跨服返回公会出生点数据
  869. function C2N_BaseCity_Query(msg)
  870. local human = ObjHuman.onlineUuid[msg.playerUuid]
  871. if not human then
  872. return
  873. end
  874. local baseCityInfo = msg.baseCityInfo
  875. local msgRet = Msg.gc.GC_AB_BASECITY_QUERY
  876. local cityCfg = AnotherWorldBattleConfig.city[baseCityInfo.cityId]
  877. msgRet.cityIconId = cityCfg.cityIconId
  878. Grid.makeItem(msgRet.cityAward, cityCfg.cityAward[1], cityCfg.cityAward[2] * AnotherWorldBattleDefine.AB_POINT_MAX_NUM)
  879. local myUnionAwardNum = calcPointAward(baseCityInfo.myUnionOccupyArr)
  880. Grid.makeItem(msgRet.myUnionAward, cityCfg.cityAward[1], myUnionAwardNum)
  881. msgRet.cityIconId = baseCityInfo.occupyPointNum
  882. msgRet.occupyPointNum = baseCityInfo.occupyPointNum
  883. msgRet.occupyCityLv2Num = baseCityInfo.occupyCityLv2Num
  884. msgRet.occupyCityLv3Num = baseCityInfo.occupyCityLv3Num
  885. msgRet.occupyCityLv4Num = baseCityInfo.occupyCityLv4Num
  886. msgRet.occupyCityLv5Num = baseCityInfo.occupyCityLv5Num
  887. Msg.send(msgRet, human.fd)
  888. end
  889. -- 跨服返回玩家占领的据点数据
  890. function C2N_PlayerOccupyPoint_Query(msg)
  891. local human = ObjHuman.onlineUuid[msg.playerUuid]
  892. if not human then
  893. return
  894. end
  895. local msgRet = Msg.gc.GC_AB_MY_OCCUPY_POINT_QUERY
  896. local myPointArr = msgRet.myPointArr
  897. myPointArr[0] = 0
  898. for idx, pointInfo in ipairs(msg.occupyPointArr) do
  899. myPointArr[0] = idx
  900. local cityCfg = AnotherWorldBattleConfig.city[pointInfo.cityId]
  901. myPointArr[idx].cityIconId = cityCfg.cityIconId
  902. myPointArr[idx].cityName = cityCfg.cityName
  903. myPointArr[idx].cityLv = cityCfg.cityLv
  904. myPointArr[idx].pointIdx = pointInfo.pointIdx
  905. myPointArr[idx].power = pointInfo.power
  906. myPointArr[idx].cityId = pointInfo.cityId
  907. myPointArr[idx].heroArr[0] = #pointInfo.heroArr
  908. for heroIdx, heroInfo in ipairs(pointInfo.heroArr) do
  909. local hero = myPointArr[idx].heroArr[heroIdx]
  910. hero.heroBody = heroInfo.heroBody
  911. hero.heroStar = heroInfo.heroStar
  912. hero.heroLv = heroInfo.heroLv
  913. hero.heroCamp = heroInfo.heroCamp
  914. hero.heroIcon = heroInfo.heroIcon
  915. hero.heroId = heroInfo.heroId
  916. hero.heroQuality = heroInfo.heroQuality
  917. end
  918. end
  919. Msg.send(msgRet, human.fd)
  920. end
  921. -- 跨服返回集结/取消集结成功
  922. function C2N_Gather_End(msg)
  923. local human = ObjHuman.onlineUuid[msg.playerUuid]
  924. if not human then
  925. return
  926. end
  927. local targetCityId = msg.targetCityId
  928. local cityCfg = AnotherWorldBattleConfig.city[targetCityId]
  929. local msgRet = Msg.gc.GC_AB_GARHER
  930. msgRet.cityId = targetCityId
  931. msgRet.cityName = cityCfg.cityName
  932. msgRet.opType = msg.opType
  933. Msg.send(msgRet, human.fd)
  934. end
  935. --跨服返回公会排行榜数据
  936. function C2N_UnionRank_Query(msg)
  937. local human = ObjHuman.onlineUuid[msg.playerUuid]
  938. if not human then
  939. return
  940. end
  941. local msgRet = Msg.gc.GC_AB_UNION_RANK_QUERY
  942. msgRet.unionRankArr[0] = 0
  943. msgRet.myUnionRank = msg.myUnionRank
  944. msgRet.myData = { name = "", power = 0, cityNum = 0, pointNum = 0 }
  945. for rank, rankdData in ipairs(msg.unionRankArr) do
  946. msgRet.unionRankArr[0] = rank
  947. msgRet.unionRankArr[rank] = {
  948. name = rankdData.name,
  949. power = rankdData.power,
  950. cityNum = rankdData.cityNum,
  951. pointNum = rankdData.pointNum,
  952. }
  953. if rank == msg.myUnionRank then
  954. msgRet.myData.name = rankdData.name
  955. msgRet.myData.power = rankdData.power
  956. msgRet.myData.cityNum = rankdData.cityNum
  957. msgRet.myData.pointNum = rankdData.pointNum
  958. end
  959. end
  960. if msgRet.myData.power == 0 then
  961. local unionId = human.db.unionUuid
  962. local queryFiles = {name = 1, zhandouli = 1}
  963. local unionInfo = UnionLogic.GetUnionData(unionId, queryFiles)
  964. msgRet.myData.name = unionInfo and unionInfo.name or ""
  965. msgRet.myData.power = unionInfo and unionInfo.zhandouli or 0
  966. end
  967. Msg.send(msgRet, human.fd)
  968. end
  969. --跨服返回玩家排行榜数据
  970. function C2N_PlayerRank_Query(msg)
  971. local human = ObjHuman.onlineUuid[msg.playerUuid]
  972. if not human then
  973. return
  974. end
  975. local msgRet = Msg.gc.GC_AB_PLAYER_RANK_QUERY
  976. msgRet.playerRankArr[0] = 0
  977. msgRet.myRank = msg.myRank
  978. msgRet.myData = {
  979. name = human.db.name,
  980. power = human.db.zhandouli,
  981. pointNum = 0,
  982. pointWeight = 0,
  983. }
  984. for rank, rankdData in ipairs(msg.playerRankArr) do
  985. msgRet.playerRankArr[0] = rank
  986. msgRet.playerRankArr[rank] = {
  987. name = rankdData.name,
  988. power = rankdData.power,
  989. pointNum = rankdData.pointNum,
  990. pointWeight = rankdData.pointWeight,
  991. }
  992. if rank == msg.myRank then
  993. msgRet.myData.pointNum = rankdData.pointNum
  994. msgRet.myData.pointWeight = rankdData.pointWeight
  995. end
  996. end
  997. Msg.send(msgRet, human.fd)
  998. end
  999. -- 跨服返回要挑战的据点的数据(据点可以被挑战)
  1000. function C2N_Challenge_Point_OK(msg)
  1001. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1002. if not human then
  1003. return
  1004. end
  1005. local pointInfo = msg.pointInfo
  1006. human.AB_Battle_Cache = {
  1007. isGather = pointInfo.isGather,
  1008. cityId = pointInfo.targetCityId,
  1009. pointIdx = pointInfo.targetPointIdx,
  1010. }
  1011. if pointInfo.occupySrvId then -- 玩家占领
  1012. local args = {
  1013. combatType = CombatDefine.COMBAT_TYPE35,
  1014. nServerIndex = pointInfo.occupySrvId,
  1015. param = pointInfo.occupyPlayerUuid,
  1016. extraArgs = {
  1017. cityId = pointInfo.targetCityId,
  1018. pointIdx = pointInfo.targetPointIdx,
  1019. useDef = true,
  1020. }
  1021. }
  1022. MiddleCommonLogic.MiddleCommonLogic_CombatBegin_LW(human, args)
  1023. else
  1024. -- 机器人
  1025. CombatLogic.combatBegin(human, nil, {human.db._id, pointInfo.targetCityId }, CombatDefine.COMBAT_TYPE35)
  1026. end
  1027. end
  1028. -- 跨服通知据点被别的玩家占领了
  1029. function C2N_Point_Lose(msg)
  1030. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1031. if not human then
  1032. local db = RoleDBLogic.getDb(msg.playerUuid) --后续可优化只取 anotherWorlBattle 数据
  1033. if not db then
  1034. return
  1035. end
  1036. human = {}
  1037. human.db = db
  1038. end
  1039. -- 更新防守阵容数据
  1040. local loseCityId = msg.loseCityId
  1041. local losePointIdx = msg.losePointIdx
  1042. local formationData = human.db.anotherWorlBattle.formation
  1043. formationData[loseCityId][losePointIdx] = nil
  1044. -- 玩家不在线, 手动保存数据
  1045. if not human.fd then
  1046. ObjHuman.save(human) --后续可优化只更新 anotherWorlBattle 数据
  1047. end
  1048. -- 发邮件
  1049. local mailCfg = MailExcel.mail[AnotherWorldBattleDefine.AB_LOSE_POINT_MAIL_ID]
  1050. local content = Util.format(mailCfg.content, losePointIdx)
  1051. MailManager.add(MailManager.SYSTEM, msg.playerUuid, mailCfg.title, content, nil, mailCfg.senderName or "GM")
  1052. -- 把最新的防守阵容数据推给客户端
  1053. if human.fd then
  1054. sendDefHeroArr(human)
  1055. end
  1056. end
  1057. -- 跨服通知可以更换据点的防守阵容数据
  1058. function C2N_Update_Point_Lineup(msg)
  1059. local human = ObjHuman.onlineUuid[msg.playerUuid]
  1060. if not human then
  1061. local db = RoleDBLogic.getDb(msg.playerUuid)
  1062. if not db then
  1063. return
  1064. end
  1065. human = {}
  1066. human.db = db
  1067. end
  1068. local anotherWorlBattle = human.db.anotherWorlBattle
  1069. if not anotherWorlBattle or not anotherWorlBattle.formation then
  1070. return Broadcast.sendErr(human, Lang.AB_NOT_OCCUPY_POINT)
  1071. end
  1072. local cityId = msg.targetCityId
  1073. local pointIdx = msg.targetPointIdx
  1074. if not anotherWorlBattle.formation[cityId] or not anotherWorlBattle.formation[cityId][pointIdx] then
  1075. return
  1076. end
  1077. local pointLinupData = anotherWorlBattle.formation[cityId][pointIdx]
  1078. pointLinupData.list = msg.heroList
  1079. pointLinupData.helpList = msg.helpList
  1080. pointLinupData.formation = msg.formation
  1081. if not human.fd then
  1082. ObjHuman.save(human)
  1083. end
  1084. sendDefHeroArr(human)
  1085. Broadcast.sendCenter(human, Lang.AB_UPDATE_LINEUP_SUCC)
  1086. end
  1087. -- 跨服通知给玩家发奖
  1088. function C2N_IssueReward(msg)
  1089. -- 删除公会参加异界之战活动时间
  1090. UnionLogic.UpdateJoinAbTime(msg.unionId, nil)
  1091. -- 发奖
  1092. local awardObjArr, occupyCityInfo = genAwardObjArr(msg.unionOccupyInfo)
  1093. if awardObjArr then
  1094. local issueRewardQueue = createRewardQueue()
  1095. issueRewardQueue.extraInfo = occupyCityInfo
  1096. for _, obj in ipairs(awardObjArr) do
  1097. issueRewardQueue:add(obj)
  1098. end
  1099. issueRewardQueue:insertDB()
  1100. end
  1101. end
  1102. -------------------------------------------战斗---------------------------------
  1103. function getCombatMonsterOutID(human, side, args)
  1104. if side ~= CombatDefine.DEFEND_SIDE then return end
  1105. local cityId = args[2]
  1106. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  1107. return cityCfg.pointMonsterId
  1108. end
  1109. function getCombatObjList(human, side, args, combatType, extraArgs)
  1110. if side == CombatDefine.ATTACK_SIDE and not human then return end
  1111. if side == CombatDefine.DEFEND_SIDE and human then
  1112. return
  1113. end
  1114. if not human then
  1115. local uuid = args[1]
  1116. local db = RoleDBLogic.getDb(uuid)
  1117. if not db then
  1118. return
  1119. end
  1120. human = {}
  1121. human.db = db
  1122. end
  1123. return CombatLogic.getHumanObjList(human, combatType, extraArgs)
  1124. end
  1125. function getCombatHeros(human, combatType, args)
  1126. if not human.db.anotherWorlBattle then
  1127. return
  1128. end
  1129. local formation = human.db.anotherWorlBattle.formation
  1130. if not formation then
  1131. return
  1132. end
  1133. local cityId, pointIdx = args.cityId, args.pointIdx
  1134. if formation[cityId] and formation[cityId][pointIdx] then
  1135. local combatHeroDB = formation[cityId][pointIdx]
  1136. return combatHeroDB.list, combatHeroDB.helpList, combatHeroDB.formation or 1, combatHeroDB
  1137. end
  1138. end
  1139. function onFightBegin(human, cbParam, combatType, param)
  1140. if not human.AB_Battle_Cache or human.AB_Battle_Cache.isGather ~= 1 then
  1141. return
  1142. end
  1143. local gatherAttrs = AnotherWorldBattleConfig.var[1].gatherAttrs
  1144. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  1145. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  1146. local atkObj = CombatImpl.objList[atkPos]
  1147. if atkObj then
  1148. for _, atrrTb in ipairs(gatherAttrs) do
  1149. local attrId, attrVal = atrrTb[1], atrrTb[2]
  1150. atkObj.sysAttr[attrId] = (atkObj.sysAttr[attrId] or 0) + attrVal
  1151. end
  1152. atkObj.isSysAttrChange = true
  1153. end
  1154. end
  1155. end
  1156. function onFightEnd(human, result, type, cbParam, combatInfo)
  1157. -- if result == CombatDefine.RESULT_WIN then
  1158. -- challenge_Win(human, {cityId = human.AB_Battle_Cache.cityId, pointIdx = human.AB_Battle_Cache.pointIdx})
  1159. -- end
  1160. local args = {
  1161. cityId = human.AB_Battle_Cache.cityId,
  1162. pointIdx = human.AB_Battle_Cache.pointIdx,
  1163. challengeRes = result
  1164. }
  1165. human.AB_Battle_Cache = nil
  1166. challenge_End(human, args)
  1167. end