AnotherWorldBattleCS.lua 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. -- 异界之战(跨服)
  2. local InnerMsg = require("core.InnerMsg")
  3. local Log = require("common.Log")
  4. local Timer = require("core.Timer")
  5. local Util = require("common.Util")
  6. local MiddleManager = require("middle.MiddleManager")
  7. local AnotherWorldBattleDB = require("anotherWorldBattle.AnotherWorldBattleDB")
  8. local AnotherWorldBattleDefine = require("anotherWorldBattle.AnotherWorldBattleDefine")
  9. local CombatDefine = require("combat.CombatDefine")
  10. local AnotherWorldBattleConfig = require("excel.anotherWorldBattle")
  11. -- 当天处于星期几(星期六为7, 星期天为1)
  12. local wDay
  13. local function updateWDay()
  14. wDay = Util.getWeekDay()
  15. end
  16. local function getTodayStartTime()
  17. local now = os.time()
  18. return Util.getDayStartTime(now)
  19. end
  20. local function isOpen()
  21. if not wDay then
  22. updateWDay()
  23. end
  24. if wDay > AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and wDay < AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] then
  25. return false
  26. end
  27. local now = os.time()
  28. local toDayStartTime = getTodayStartTime()
  29. if wDay == AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[1] and now < (toDayStartTime + AnotherWorldBattleDefine.AB_START_SEC) then
  30. return false
  31. end
  32. -- 周三23点过后暂时不算结束
  33. -- if wDay == AnotherWorldBattleDefine.OPEN_WDAY_AREA[2] and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  34. -- return false
  35. -- end
  36. local lastRoundStartTime = AnotherWorldBattleDB.GetLastRoundStartTime()
  37. if lastRoundStartTime ~= 0 then
  38. local diffDays = Util.diffDay(lastRoundStartTime)
  39. -- < 5天说明处于本轮活动的开启时间
  40. if diffDays > 5 and diffDays <= AnotherWorldBattleDefine.AB_SUB_DAY then
  41. return false
  42. end
  43. end
  44. return true
  45. end
  46. local function isRunning()
  47. if not isOpen() then
  48. return false
  49. end
  50. -- 周三23点过后暂时不算结束
  51. local now = os.time()
  52. local toDayStartTime = getTodayStartTime()
  53. if wDay == AnotherWorldBattleDefine.AB_OPEN_WDAY_AREA[2] and now > (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  54. return false
  55. end
  56. return true
  57. end
  58. -- 进入新一轮的处理
  59. local function newRoundHandle()
  60. local stage = AnotherWorldBattleDB.GetStage()
  61. -- 上一轮奖励没有发放, 在新一轮开始时, 先发奖
  62. if stage == AnotherWorldBattleDefine.AB_STATE_AWARD then
  63. -- AwardPrizesHandle()
  64. end
  65. -- 重置数据
  66. AnotherWorldBattleDB.ResetData()
  67. -- 更新状态
  68. AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_JOIN)
  69. -- 更新活动开始时间
  70. local now = os.time()
  71. AnotherWorldBattleDB.UpdateLastRoundStartTime(now)
  72. end
  73. -- 能否进入新一轮的报名阶段
  74. local function joinStageCheck()
  75. local stage = AnotherWorldBattleDB.GetStage()
  76. if stage ~= AnotherWorldBattleDefine.AB_STATE_END and stage ~= AnotherWorldBattleDefine.AB_STATE_AWARD then
  77. return
  78. end
  79. -- local lastRoundStartTime = AnotherWorldBattleDB.GetLastRoundStartTime()
  80. -- local diffDays = Util.diffDay(lastRoundStartTime)
  81. -- 上一轮活动结束时间为0 或 当前时间 - 上一轮活动开启时间 > 9天, 开启新一轮活动
  82. -- if lastRoundStartTime == 0 or diffDays > AnotherWorldBattleDefine.AB_SUB_DAY then
  83. newRoundHandle()
  84. -- end
  85. end
  86. -- 公会分组算法
  87. local function groupingAlgorithm(unionArray, len)
  88. local usedTb = {}
  89. local groupArr = {}
  90. local function getNextUnuseIdx(nowIdx)
  91. for i=nowIdx, len do
  92. if not usedTb[i] then
  93. return i
  94. end
  95. end
  96. end
  97. local function checkRandIdx(startIdx, endIdx)
  98. local tbl= {}
  99. for i= startIdx, endIdx do
  100. if not usedTb[i] then
  101. table.insert(tbl, i)
  102. end
  103. end
  104. return tbl
  105. end
  106. local currentIdx = 1
  107. local selectNum, cnt = 0, 0
  108. while currentIdx <= len do
  109. currentIdx = getNextUnuseIdx(currentIdx)
  110. if not currentIdx then
  111. break
  112. end
  113. local startIdx = currentIdx + 1
  114. local endIdx = math.min(currentIdx + 19, len)
  115. groupArr[#groupArr+1] = { unionArray[currentIdx] }
  116. selectNum = selectNum + 1
  117. cnt = math.min(AnotherWorldBattleDefine.AB_GROUP_UNION_NUM - 1, len - selectNum )
  118. for i=1, cnt do
  119. local correctTb = checkRandIdx(startIdx, endIdx)
  120. local matchIdx = correctTb[math.random(1, #correctTb)]
  121. usedTb[currentIdx] = true
  122. usedTb[matchIdx] = true
  123. table.insert(groupArr[#groupArr], unionArray[matchIdx])
  124. selectNum = selectNum + 1
  125. end
  126. currentIdx = currentIdx + 1
  127. end
  128. return groupArr
  129. end
  130. -- 分组
  131. local function grouping()
  132. local function genUnionIdArray(sourceUnionArr, targetUnionArr)
  133. for k, v in ipairs(sourceUnionArr) do
  134. targetUnionArr[k] = v.unionId
  135. end
  136. end
  137. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  138. if not joinUnionArr then
  139. -- 没有公会参加, 本轮活动结束
  140. local now = os.time()
  141. AnotherWorldBattleDB.UpdateLastRoundStartTime(now)
  142. return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
  143. end
  144. local len = #joinUnionArr
  145. if len > AnotherWorldBattleDefine.AB_GROUP_UNION_NUM then
  146. table.sort(joinUnionArr, function (a, b)
  147. return a.power > b.power
  148. end)
  149. end
  150. local unionIdArr = {}
  151. genUnionIdArray(joinUnionArr, unionIdArr)
  152. local newGroupArray
  153. if len > AnotherWorldBattleDefine.AB_GROUP_UNION_NUM then
  154. newGroupArray = groupingAlgorithm(unionIdArr, len)
  155. else
  156. newGroupArray = { unionIdArr }
  157. end
  158. AnotherWorldBattleDB.UpdateGroupArray(newGroupArray)
  159. end
  160. -- 给各个分组中的公会随机分配出生点
  161. local function randomBaseCity()
  162. local baseCityIdArr = {}
  163. for cityId, cityCfg in ipairs(AnotherWorldBattleConfig.city) do
  164. if cityCfg.isBaseCity == 1 then
  165. baseCityIdArr[#baseCityIdArr+1] = cityId
  166. end
  167. end
  168. local now = os.time()
  169. local groupArray = AnotherWorldBattleDB.GetGroupArray()
  170. for _, unionIdArr in ipairs(groupArray) do
  171. -- 乱序
  172. table.shuffle(baseCityIdArr)
  173. for i, unionId in ipairs(unionIdArr) do
  174. local union = AnotherWorldBattleDB.GetUnionData(unionId)
  175. if union then
  176. union.baseCityId = baseCityIdArr[i]
  177. union.baseCityStartTime = now
  178. AnotherWorldBattleDB.UpdateUnionData(unionId, union)
  179. end
  180. end
  181. end
  182. end
  183. -- 统计单个公会的占领情况, 用于发放奖励
  184. local function genUnionOccupyInfo(unionId, union)
  185. local occupyTb = {
  186. occupyCityArr = {}, -- 曾占领, 当前还占领的城池列表
  187. occuoyPointNum = 0,
  188. playerUuidArr = {},
  189. }
  190. local now = os.time()
  191. local tbl = occupyTb.occupyCityArr
  192. tbl[#tbl+1] = { union.baseCityId, { {union.baseCityStartTime, union.baseCityEndTime or now} }, true }
  193. for cityId, cityIno in pairs(union.occupCityList or {}) do
  194. if cityIno.isOccupy or cityIno.occupyTimeArr then
  195. -- 更新目前还占领的城池的占领结束时间
  196. local lastTimeTb = cityIno.occupyTimeArr[#cityIno.occupyTimeArr]
  197. if #lastTimeTb == 1 then
  198. lastTimeTb[2] = now
  199. end
  200. tbl[#tbl+1] = { cityId, cityIno.occupyTimeArr, cityIno.isOccupy }
  201. end
  202. for _,_ in pairs(cityIno.occupyPointList) do
  203. occupyTb.occuoyPointNum = occupyTb.occuoyPointNum + 1
  204. end
  205. end
  206. local tbl2 = occupyTb.playerUuidArr
  207. for playerUuid in pairs(union.playerList) do
  208. tbl2[#tbl2+1] = playerUuid
  209. end
  210. -- 防止本次没有正常发放奖励,后续补发时, 结束时间异常的情况
  211. union.baseCityEndTime = now
  212. AnotherWorldBattleDB.UpdateUnionData(unionId, union)
  213. return occupyTb
  214. end
  215. -- 发奖
  216. local function issueReward(sourceServerId, occupyInfo)
  217. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_ISSUEREWARD
  218. msgData.unionOccupyInfo = occupyInfo
  219. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  220. InnerMsg.sendMsg(fd, msgData)
  221. end
  222. -- 奖励发放管理函数
  223. local function issueRewardManager()
  224. local delay_sec = 0
  225. local unionList = AnotherWorldBattleDB.GetUnionList()
  226. for unionId, union in pairs(unionList) do
  227. local occupyInfo = genUnionOccupyInfo(unionId, union)
  228. delay_sec = delay_sec + 5
  229. Timer.addLater(delay_sec, issueReward, union.serverId, occupyInfo)
  230. end
  231. end
  232. function oneMin()
  233. if _G.is_middle ~= true then return end
  234. if not isOpen() then
  235. return
  236. end
  237. -- 与 onHour() 处理错开
  238. if Util.getMin() == 0 then
  239. return
  240. end
  241. -- 处于报名阶段
  242. if table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
  243. joinStageCheck()
  244. end
  245. local now = os.time()
  246. -- 报名阶段 -> 战斗阶段
  247. if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
  248. local stage = AnotherWorldBattleDB.GetStage()
  249. local toDayStartTime = getTodayStartTime()
  250. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN and now >= (toDayStartTime + AnotherWorldBattleDefine.AB_START_SEC) then
  251. -- 分组
  252. grouping()
  253. -- 给各个分组中的公会随机分配出生点
  254. randomBaseCity()
  255. -- 最后更新活动阶段
  256. return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_BATTLE)
  257. end
  258. end
  259. -- 战斗阶段 -> 发奖阶段
  260. local toDayStartTime = getTodayStartTime()
  261. if wDay == AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] and now >= (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  262. local stage = AnotherWorldBattleDB.GetStage()
  263. if stage == AnotherWorldBattleDefine.AB_STATE_BATTLE then
  264. -- 改为发奖阶段
  265. AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_AWARD)
  266. -- 开始发奖
  267. issueRewardManager()
  268. -- 改为结束阶段
  269. return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
  270. end
  271. end
  272. end
  273. function onHour(hour)
  274. if _G.is_middle ~= true then return end
  275. if hour == 0 or not wDay then
  276. updateWDay()
  277. end
  278. if not isOpen() then
  279. return
  280. end
  281. -- 处于报名阶段
  282. if table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
  283. joinStageCheck()
  284. end
  285. local now = os.time()
  286. -- 报名阶段 -> 战斗阶段
  287. if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
  288. local stage = AnotherWorldBattleDB.GetStage()
  289. local toDayStartTime = getTodayStartTime()
  290. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN and now >= (toDayStartTime + AnotherWorldBattleDefine.AB_START_SEC) then
  291. -- 分组
  292. grouping()
  293. -- 给各个分组中的公会随机分配出生点
  294. randomBaseCity()
  295. -- 最后更新活动阶段
  296. return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_BATTLE)
  297. end
  298. end
  299. -- 战斗阶段 -> 发奖阶段
  300. local toDayStartTime = getTodayStartTime()
  301. if wDay == AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] and now >= (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  302. local stage = AnotherWorldBattleDB.GetStage()
  303. if stage == AnotherWorldBattleDefine.AB_STATE_BATTLE then
  304. AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_AWARD)
  305. -- 开始发奖
  306. issueRewardManager()
  307. -- 改为结束阶段
  308. return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
  309. end
  310. end
  311. end
  312. ------------------------------------C2N---------------------------------------------------
  313. -- 错误提示
  314. local function errTips(sourceServerId, playerUuid, errCode)
  315. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_TIPS
  316. msgData.playerUuid = playerUuid
  317. msgData.errCode = errCode
  318. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  319. InnerMsg.sendMsg(fd, msgData)
  320. end
  321. -- 通知玩家,据点被别的玩家占领了
  322. local function pointLose(sourceServerId, playerUuid, loseCityId, losePointIdx)
  323. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINT_LOSE
  324. msgData.playerUuid = playerUuid
  325. msgData.loseCityId = loseCityId
  326. msgData.losePointIdx = losePointIdx
  327. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  328. InnerMsg.sendMsg(fd, msgData)
  329. end
  330. ------------------------------------N2C---------------------------------------------------
  331. -- 统计单个服公会报名数量
  332. local function calcSvrUnionJoinNum(serverId)
  333. local num = 0
  334. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  335. if not joinUnionArr then
  336. return num
  337. end
  338. for _, unionInfo in ipairs(joinUnionArr) do
  339. if unionInfo.serverId == serverId then
  340. num = num + 1
  341. end
  342. end
  343. return num
  344. end
  345. -- 计算多个英雄的总战力
  346. local function calcHerosPower(heroArr)
  347. local power = 0
  348. for _, v in ipairs(heroArr) do
  349. power = power + v.heroPower
  350. end
  351. return power
  352. end
  353. -- 统计公会占领不同等级的城池数量
  354. local function calcOccupyCityNum(occupCityList, cityLv)
  355. if not occupCityList then
  356. return 0
  357. end
  358. local num = 0
  359. for cityId, occupyInfo in pairs(occupCityList) do
  360. if occupyInfo.isOccupy then
  361. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  362. if cityCfg.cityLv == cityLv then
  363. num = num + 1
  364. end
  365. end
  366. end
  367. return num
  368. end
  369. -- 统计公会占领的据点数量
  370. local function calcOccupyPointNum(occupCityList)
  371. if not occupCityList then
  372. return 0
  373. end
  374. local num = 0
  375. for cityId, occupyInfo in pairs(occupCityList) do
  376. for _,_ in pairs(occupyInfo.occupyPointList) do
  377. num = num + 1
  378. end
  379. end
  380. return num
  381. end
  382. -- 获取公会占领的城池列表
  383. local function getUnionOccupyArr(unionId)
  384. local union = AnotherWorldBattleDB.GetUnionData(unionId)
  385. if not union then
  386. return
  387. end
  388. local occupyCityArr = {}
  389. occupyCityArr[#occupyCityArr+1] = union.baseCityId
  390. for cityId, occupyInfo in pairs(union.occupCityList or {}) do
  391. if occupyInfo.isOccupy then
  392. occupyCityArr[#occupyCityArr+1] = cityId
  393. end
  394. end
  395. return occupyCityArr
  396. end
  397. -- 检查某个城池与公会占领的城池是否相邻
  398. local function isadJoin(cityIdArr, targetCityId)
  399. if not cityIdArr then
  400. return false
  401. end
  402. local targetCityCfg = AnotherWorldBattleConfig.city[targetCityId]
  403. if not targetCityCfg then
  404. return false
  405. end
  406. for _, cityId in ipairs(targetCityCfg.adJoinCityArr) do
  407. if table.find(cityIdArr, cityId) then
  408. return true
  409. end
  410. end
  411. return false
  412. end
  413. -- 检查某个据点是否能被玩家挑战
  414. local function isCanChallengePoint(targetCityId, targetPointIdx, myUnionId, playerUuid)
  415. -- 活动未开启
  416. if not isRunning() then
  417. return false
  418. end
  419. -- 公会没有参加活动
  420. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  421. if not groupId then
  422. return false
  423. end
  424. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  425. local tagetCityData = cityList[targetCityId]
  426. if not tagetCityData then
  427. return false
  428. end
  429. -- 城池已被本公会占领
  430. if tagetCityData.occupyUnion and tagetCityData.occupyUnion == myUnionId then
  431. return false
  432. end
  433. local targetPointData = tagetCityData.pointArr[targetPointIdx]
  434. if not targetPointData then
  435. return false
  436. end
  437. -- 据点已被本公会占领
  438. if targetPointData.unionId and targetPointData.unionId == myUnionId then
  439. return false
  440. end
  441. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  442. if not myUnionData then
  443. return false
  444. end
  445. -- 城池是否相邻
  446. local occupyCityArr = getUnionOccupyArr(myUnionId)
  447. if not isadJoin(occupyCityArr, targetCityId) then
  448. return false
  449. end
  450. -- 每个玩家最多占领据点数量是否超出
  451. local playerOccupyPonitNum = 0
  452. if myUnionData.playerList and myUnionData.playerList[playerUuid] then
  453. local heroList = myUnionData.playerList[playerUuid].heroList
  454. for cityId, pointList in pairs(heroList) do
  455. for _, _ in pairs(pointList) do
  456. playerOccupyPonitNum = playerOccupyPonitNum + 1
  457. end
  458. end
  459. end
  460. if playerOccupyPonitNum >= AnotherWorldBattleDefine.AB_PLAYER_OCCUPY_POINT_MAX_NUM then
  461. return false
  462. end
  463. return true
  464. end
  465. -- 公会是否能报名
  466. local function isCanJoin(sourceServerId, myUnionId)
  467. if not isRunning() then
  468. return 2
  469. end
  470. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  471. for _, unionData in ipairs(joinUnionArr or {}) do
  472. if unionData.unionId == myUnionId then
  473. return 1
  474. end
  475. end
  476. local num = calcSvrUnionJoinNum(sourceServerId)
  477. if num >= AnotherWorldBattleDefine.AB_SRV_UNION_MAX_NUM then
  478. return 2
  479. end
  480. return 0
  481. end
  482. -- 检查城池是否被己方公会完全占领
  483. local function isCompleteOccupy(cityData, myUnionId)
  484. for _, pointInfo in ipairs(cityData.pointArr) do
  485. if not pointInfo.unionId or pointInfo.unionId ~= myUnionId then
  486. return false
  487. end
  488. end
  489. return true
  490. end
  491. -- 查询玩家是否上榜
  492. local function getPlayerRank(playerRankList, playerUuid)
  493. for _, rankData in ipairs(playerRankList) do
  494. if rankData.playerUuid == playerUuid then
  495. return true
  496. end
  497. end
  498. return false
  499. end
  500. -- 更新公会排行榜数据
  501. local function updateUnionRanktData(unionRankList, unionId, cityNum, pointNum)
  502. for rank, rankData in ipairs(unionRankList) do
  503. if rankData.unionId == unionId then
  504. unionRankList[rank].occupyCityNum = unionRankList[rank].occupyCityNum + cityNum
  505. unionRankList[rank].occupyPointNum = unionRankList[rank].occupyPointNum + pointNum
  506. end
  507. end
  508. end
  509. -- 更新玩家排行榜数据
  510. local function updatePlayerRanktData(playerRankList, playerUuid, pointNum, pointWeight)
  511. local playerRank = 0
  512. for rank, rankData in ipairs(playerRankList) do
  513. if rankData.playerUuid == playerUuid then
  514. playerRank = rank
  515. end
  516. end
  517. if playerRank ~= 0 then
  518. playerRankList[playerRank].pointNum = playerRankList[playerRank].pointNum + pointNum
  519. playerRankList[playerRank].pointAllWeight = playerRankList[playerRank].pointAllWeight + pointWeight
  520. end
  521. end
  522. -- 查询状态
  523. function N2C_Get_State(msg)
  524. local sourceServerId = msg.sourceServerId
  525. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_GET_STATE
  526. msgData.playerUuid = msg.playerUuid
  527. local stage = AnotherWorldBattleDB.GetStage()
  528. msgData.systemState = stage
  529. msgData.joinState = 0
  530. if stage == 0 then
  531. local lastRoundStartTime = AnotherWorldBattleDB.GetLastRoundStartTime()
  532. if lastRoundStartTime == 0 then
  533. msgData.systemState = 0
  534. end
  535. end
  536. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  537. for _, unionData in ipairs(joinUnionArr or {}) do
  538. if unionData.unionId == msg.myUnionId then
  539. msgData.joinState = 1
  540. end
  541. end
  542. local num = calcSvrUnionJoinNum(sourceServerId)
  543. if num >= AnotherWorldBattleDefine.AB_SRV_UNION_MAX_NUM then
  544. msgData.joinState = 2
  545. end
  546. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  547. InnerMsg.sendMsg(fd, msgData)
  548. end
  549. -- 报名
  550. function N2C_Join(msg)
  551. local sourceServerId = msg.sourceServerId
  552. local playerUuid = msg.playerUuid
  553. local unionInfo = msg.unionInfo
  554. local state = isCanJoin(sourceServerId, unionInfo.unionId)
  555. if state == 2 then
  556. return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_1)
  557. elseif state == 1 then
  558. return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_8)
  559. end
  560. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  561. joinUnionArr = joinUnionArr or {}
  562. joinUnionArr[#joinUnionArr+1] = {
  563. unionId = unionInfo.unionId,
  564. power = unionInfo.power,
  565. serverId = sourceServerId
  566. }
  567. AnotherWorldBattleDB.UpdateJoinUnionArr(joinUnionArr)
  568. local unionList = AnotherWorldBattleDB.GetUnionList()
  569. unionList = unionList or {}
  570. unionList[unionInfo.unionId] = {
  571. serverId = sourceServerId,
  572. power = unionInfo.power,
  573. name = unionInfo.name,
  574. }
  575. AnotherWorldBattleDB.UpdateUnionList(unionList)
  576. -- 通知报名成功
  577. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_JOIN
  578. msgData.playerUuid = playerUuid
  579. msgData.myUnionId = unionInfo.unionId
  580. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  581. InnerMsg.sendMsg(fd, msgData)
  582. end
  583. -- 查询所有城池信息
  584. function N2C_AllCity_Query(msg)
  585. local myUnionId = msg.myUnionId
  586. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_ALLCITY_QUERY
  587. msgData.cityArr = {}
  588. msgData.playerUuid = msg.playerUuid
  589. msgData.myUnionBaseCityId = 0
  590. msgData.myOccupyCityArr = {}
  591. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  592. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  593. if not groupId then
  594. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  595. local stage = AnotherWorldBattleDB.GetStage()
  596. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  597. return InnerMsg.sendMsg(fd, msgData)
  598. end
  599. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  600. end
  601. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  602. if not cityList then
  603. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  604. end
  605. local cityArrMsg = msgData.cityArr
  606. local unionList = AnotherWorldBattleDB.GetUnionList()
  607. msgData.myUnionBaseCityId = unionList[myUnionId] and unionList[myUnionId].baseCityId or 0
  608. for cityId, cityInfo in ipairs(cityList) do
  609. cityArrMsg[cityId] = { occupyPointNum = 0 }
  610. if cityInfo.occupyUnion then
  611. cityArrMsg[cityId].occupyUnionName = unionList[cityInfo.occupyUnion] and unionList[cityInfo.occupyUnion].name
  612. end
  613. for _, pointInfo in ipairs(cityInfo.pointArr) do
  614. if pointInfo.unionId and pointInfo.unionId == myUnionId then
  615. cityArrMsg[cityId].occupyPointNum = cityArrMsg[cityId].occupyPointNum + 1
  616. end
  617. end
  618. end
  619. msgData.myOccupyCityArr = getUnionOccupyArr(myUnionId)
  620. InnerMsg.sendMsg(fd, msgData)
  621. end
  622. -- 查询某个城池的详细信息
  623. function N2C_CityDetailed_Query(msg)
  624. local myUnionId = msg.myUnionId
  625. local playerUuid = msg.playerUuid
  626. local targetCityId = msg.targetCityId
  627. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  628. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
  629. msgData.playerUuid = playerUuid
  630. msgData.targetCityId = targetCityId
  631. msgData.myUnionOccupyArr = {}
  632. msgData.pointArr = {}
  633. msgData.gatherState = 0
  634. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  635. if not groupId then
  636. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  637. local stage = AnotherWorldBattleDB.GetStage()
  638. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  639. return InnerMsg.sendMsg(fd, msgData)
  640. end
  641. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  642. end
  643. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  644. if not cityList or not cityList[targetCityId] then
  645. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  646. end
  647. local cityData = cityList[targetCityId]
  648. local myUnionOccupyArr = getUnionOccupyArr(myUnionId)
  649. msgData.myUnionOccupyArr = myUnionOccupyArr
  650. local pointArrMsg = msgData.pointArr
  651. for pointIdx, occupyInfo in ipairs(cityData.pointArr) do
  652. pointArrMsg[pointIdx] = {}
  653. local bl = isCanChallengePoint(targetCityId, pointIdx, myUnionId, playerUuid)
  654. pointArrMsg[pointIdx].isCanChallenge = bl and 1 or 0
  655. if occupyInfo.unionId and occupyInfo.playerUuid then
  656. local occupyUnionData = AnotherWorldBattleDB.GetUnionData(occupyInfo.unionId)
  657. if occupyUnionData then
  658. pointArrMsg[pointIdx].occupyUnionName = occupyUnionData.name
  659. pointArrMsg[pointIdx].occupyPlayerName = occupyUnionData.playerList[occupyInfo.playerUuid].name
  660. pointArrMsg[pointIdx].power = 0
  661. local heroList = occupyUnionData.playerList[occupyInfo.playerUuid].heroList
  662. if heroList and heroList[targetCityId] and heroList[targetCityId][pointIdx] then
  663. pointArrMsg[pointIdx].power = calcHerosPower(heroList[targetCityId][pointIdx])
  664. end
  665. end
  666. end
  667. end
  668. local isOk = isRunning()
  669. if isOk then
  670. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  671. local occupyCityArr = getUnionOccupyArr(myUnionId)
  672. isOk = isadJoin(occupyCityArr, targetCityId)
  673. if isOk then
  674. if not cityData.occupyUnion or cityData.occupyUnion ~= myUnionId then
  675. if not myUnionData.gatherInfo then
  676. msgData.gatherState = 1
  677. else
  678. if myUnionData.gatherInfo.gatherCity == targetCityId then
  679. msgData.gatherState = 2
  680. else
  681. local now = os.time()
  682. if now - myUnionData.gatherInfo.gatherTime >= AnotherWorldBattleDefine.AB_GATHER_CD_SEC then
  683. msgData.gatherState = 1
  684. end
  685. end
  686. end
  687. end
  688. end
  689. end
  690. InnerMsg.sendMsg(fd, msgData)
  691. end
  692. -- 查询某个据点信息
  693. function N2C_PointDetailed_Query(msg)
  694. local myUnionId = msg.myUnionId
  695. local targetCityId = msg.targetCityId
  696. local targetPointIdx = msg.targetPointIdx
  697. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  698. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINTDETAILED_QUERY
  699. msgData.playerUuid = msg.playerUuid
  700. msgData.targetCityId = targetCityId
  701. msgData.targetPointIdx = targetPointIdx
  702. msgData.pointInfo = {}
  703. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  704. if not groupId then
  705. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  706. local stage = AnotherWorldBattleDB.GetStage()
  707. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  708. return InnerMsg.sendMsg(fd, msgData)
  709. end
  710. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  711. end
  712. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  713. if not cityList or not cityList[targetCityId] then
  714. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  715. end
  716. local cityData = cityList[targetCityId]
  717. local pointData = cityData.pointArr[targetPointIdx]
  718. if not pointData then
  719. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  720. end
  721. local pointInfoMsg = msgData.pointInfo
  722. if pointData.unionId and pointData.playerUuid then
  723. local union = AnotherWorldBattleDB.GetUnionData(pointData.unionId)
  724. if not union then
  725. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  726. end
  727. local playerData = union.playerList and union.playerList[pointData.playerUuid]
  728. if not playerData then
  729. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  730. end
  731. pointInfoMsg.name = playerData.name
  732. pointInfoMsg.head = playerData.head
  733. pointInfoMsg.headFrame = playerData.headFrame
  734. pointInfoMsg.defLv = playerData.lv
  735. local targetHeroArr = playerData.heroList[targetCityId][targetPointIdx]
  736. if not targetHeroArr then
  737. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  738. end
  739. pointInfoMsg.power = calcHerosPower(targetHeroArr)
  740. pointInfoMsg.heroArr = {}
  741. for i, heroInfo in ipairs(targetHeroArr) do
  742. pointInfoMsg.heroArr[i] = {
  743. heroBody = heroInfo.heroBody,
  744. heroStar = heroInfo.heroStar,
  745. heroLv = heroInfo.heroLevel,
  746. heroCamp = heroInfo.heroCamp,
  747. heroIcon = heroInfo.heroIcon,
  748. }
  749. end
  750. end
  751. local isCanChallenge = isCanChallengePoint(targetCityId, targetPointIdx, myUnionId, msg.playerUuid)
  752. pointInfoMsg.isCanChallenge = isCanChallenge and 1 or 0
  753. InnerMsg.sendMsg(fd, msgData)
  754. end
  755. -- 查询公会出生点信息
  756. function N2C_BaseCity_Query(msg)
  757. local myUnionId = msg.myUnionId
  758. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  759. if not groupId then
  760. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  761. end
  762. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_BASECITY_QUERY
  763. msgData.playerUuid = msg.playerUuid
  764. local union = AnotherWorldBattleDB.GetUnionData(myUnionId)
  765. if not union then
  766. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  767. end
  768. local baseCityInfo = {}
  769. msgData.baseCityInfo = baseCityInfo
  770. baseCityInfo.cityId = union.baseCityId
  771. baseCityInfo.occupyPointNum = calcOccupyPointNum(union.occupCityList)
  772. baseCityInfo.myUnionOccupyArr = getUnionOccupyArr(myUnionId)
  773. baseCityInfo.occupyCityLv2Num = calcOccupyCityNum(union.occupCityList, 2)
  774. baseCityInfo.occupyCityLv3Num = calcOccupyCityNum(union.occupCityList, 3)
  775. baseCityInfo.occupyCityLv4Num = calcOccupyCityNum(union.occupCityList, 4)
  776. baseCityInfo.occupyCityLv5Num = calcOccupyCityNum(union.occupCityList, 5)
  777. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  778. InnerMsg.sendMsg(fd, msgData)
  779. end
  780. -- 查询玩家占领的所有据点信息
  781. function N2C_PlayerOccupyPoint_Query(msg)
  782. local myUnionId = msg.myUnionId
  783. local playerUuid = msg.playerUuid
  784. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  785. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
  786. msgData.playerUuid = playerUuid
  787. msgData.occupyPointArr = {}
  788. local union = AnotherWorldBattleDB.GetUnionData(myUnionId)
  789. if not union then
  790. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  791. local stage = AnotherWorldBattleDB.GetStage()
  792. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  793. return InnerMsg.sendMsg(fd, msgData)
  794. end
  795. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  796. end
  797. local playerList = union.playerList
  798. if not playerList[playerUuid] then
  799. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
  800. end
  801. local heroList = playerList[playerUuid].heroList
  802. if not heroList then
  803. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  804. end
  805. local occupyPointArrMsg = msgData.occupyPointArr
  806. for cityId, pointList in pairs(heroList) do
  807. for pointIdx, heroInfoArr in pairs(pointList) do
  808. occupyPointArrMsg[#occupyPointArrMsg+1] = {
  809. cityId = cityId,
  810. pointIdx = pointIdx,
  811. power = calcHerosPower(heroInfoArr),
  812. heroArr = {},
  813. }
  814. local TargetHeroArr = occupyPointArrMsg[#occupyPointArrMsg].heroArr
  815. for _, heroInfo in ipairs(heroInfoArr) do
  816. TargetHeroArr[#TargetHeroArr+1] = {
  817. heroBody = heroInfo.heroBody,
  818. heroStar = heroInfo.heroStar,
  819. heroLv = heroInfo.heroLevel,
  820. heroCamp = heroInfo.heroCamp,
  821. heroIcon = heroInfo.heroIcon,
  822. }
  823. end
  824. end
  825. end
  826. InnerMsg.sendMsg(fd, msgData)
  827. end
  828. -- 查询公会排行榜
  829. function N2C_UnionRank_Query(msg)
  830. local myUnionId = msg.myUnionId
  831. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  832. if not groupId then
  833. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  834. end
  835. local unionRankList = AnotherWorldBattleDB.GetUnionRankList(groupId)
  836. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
  837. msgData.playerUuid = msg.playerUuid
  838. msgData.myUnionRank = 0
  839. msgData.unionRankArr = {}
  840. for rank, randkData in ipairs(unionRankList) do
  841. if rank > AnotherWorldBattleDefine.AB_RANK_MAX_NUM then
  842. break
  843. end
  844. local unionName = AnotherWorldBattleDB.GetUnionName(randkData.unionId)
  845. msgData.unionRankArr[rank] = {
  846. name = unionName,
  847. power = randkData.power,
  848. cityNum = randkData.occupyCityNum,
  849. pointNum = randkData.occupyPointNum,
  850. }
  851. if randkData.unionId == myUnionId then
  852. msgData.myUnionRank = rank
  853. end
  854. end
  855. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  856. InnerMsg.sendMsg(fd, msgData)
  857. end
  858. -- 查询玩家排行榜
  859. function N2C_PlayerRank_Query(msg)
  860. local myUnionId = msg.myUnionId
  861. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  862. if not groupId then
  863. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  864. end
  865. local playerRankList = AnotherWorldBattleDB.GetPlayerRankList(groupId)
  866. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
  867. msgData.playerUuid = msg.playerUuid
  868. msgData.myRank = 0
  869. msgData.playerRankArr = {}
  870. for rank, randkData in ipairs(playerRankList) do
  871. if rank > AnotherWorldBattleDefine.AB_RANK_MAX_NUM then
  872. break
  873. end
  874. local playerName = AnotherWorldBattleDB.GetPlayerName(randkData.unionId, randkData.playerUuid)
  875. msgData.unionRankArr[rank] = {
  876. name = playerName,
  877. power = randkData.power,
  878. pointNum = randkData.occupyPointNum,
  879. pointWeight = randkData.pointAllWeight,
  880. }
  881. if randkData.playerUuid == msg.playerUuid then
  882. msgData.myRank = rank
  883. end
  884. end
  885. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  886. InnerMsg.sendMsg(fd, msgData)
  887. end
  888. -- 集结
  889. function N2C_Gather(msg)
  890. local sourceServerId = msg.sourceServerId
  891. local playerUuid = msg.playerUuid
  892. local myUnionId = msg.myUnionId
  893. if not isRunning() then
  894. return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_1)
  895. end
  896. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  897. if not groupId then
  898. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  899. end
  900. local targetCityId = msg.targetCityId
  901. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  902. if not myUnionData then
  903. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  904. end
  905. local now = os.time()
  906. if myUnionData.gatherInfo then
  907. local gatherTime = myUnionData.gatherInfo.gatherTime
  908. if now - gatherTime < AnotherWorldBattleDefine.AB_GATHER_CD_SEC then
  909. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_6)
  910. end
  911. end
  912. local occupCityyArr = getUnionOccupyArr(myUnionId)
  913. if not isadJoin(occupCityyArr, targetCityId) then
  914. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_7)
  915. end
  916. myUnionData.gatherInfo = myUnionData.gatherInfo or {}
  917. myUnionData.gatherInfo.gatherTime = now
  918. myUnionData.gatherInfo.gatherCity = targetCityId
  919. AnotherWorldBattleDB.UpdateUnionData(myUnionId, myUnionData)
  920. N2C_CityDetailed_Query(msg)
  921. end
  922. -- 查询据点是否可以被挑战
  923. function N2C_Try_Challengde_Point(msg)
  924. local playerUuid = msg.playerUuid
  925. local myUnionId = msg.myUnionId
  926. local targetCityId = msg.targetCityId
  927. local targetPointIdx = msg.targetPointIdx
  928. local isCanChallenge = isCanChallengePoint(targetCityId, msg.targetPointIdx, msg.myUnionId, playerUuid)
  929. if not isCanChallenge then
  930. return
  931. end
  932. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  933. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  934. local targetPointData = cityList[targetCityId].pointArr[targetPointIdx]
  935. local pointOccupyInfo = {targetCityId = targetCityId, targetPointIdx = targetPointIdx}
  936. if targetPointData.unionId then
  937. local occupyUnionData = AnotherWorldBattleDB.GetUnionData(targetPointData.unionId)
  938. pointOccupyInfo.occupySrvId = occupyUnionData.serverId
  939. pointOccupyInfo.occupyPlayerUuid = targetPointData.playerUuid
  940. end
  941. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  942. if myUnionData.gatherInfo and myUnionData.gatherInfo.gatherCity == targetCityId then
  943. pointOccupyInfo.isGather = 1
  944. end
  945. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
  946. msgData.playerUuid = playerUuid
  947. msgData.targetCityId = targetCityId
  948. msgData.targetPointIdx = targetPointIdx
  949. msgData.pointInfo = pointOccupyInfo
  950. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  951. InnerMsg.sendMsg(fd, msgData)
  952. end
  953. -- 玩家挑战据点胜利
  954. function N2C_Point_Challenge_Win(msg)
  955. local playerUuid = msg.playerUuid
  956. local myUnionId = msg.myUnionId
  957. local targetCityId = msg.targetCityId
  958. local targetPointIdx = msg.targetPointIdx
  959. local playerShowInfo = msg.playerShowInfo
  960. if not isRunning() then
  961. return
  962. end
  963. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  964. if not groupId then
  965. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  966. end
  967. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  968. if not myUnionData then
  969. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  970. end
  971. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  972. local cityData = cityList[targetCityId]
  973. local pointData = cityData.pointArr[targetPointIdx]
  974. local unionRankList = AnotherWorldBattleDB.GetUnionRankList(groupId)
  975. local playerRankList = AnotherWorldBattleDB.GetPlayerRankList(groupId)
  976. local pointWeight = AnotherWorldBattleConfig.city[targetCityId].pointWeight
  977. -- 防守方是真实玩家
  978. if pointData.unionId and pointData.playerUuid then
  979. -- 更新防守方公会数据
  980. local defUnionData = AnotherWorldBattleDB.GetUnionData(pointData.unionId)
  981. local defOccupCityList = defUnionData.occupCityList
  982. local cityNum, pointNum = 0, -1
  983. -- 防守方之前占领了城池
  984. if defOccupCityList[targetCityId].isOccupy then
  985. -- 修改防守方的占领状态
  986. defOccupCityList[targetCityId].isOccupy = false
  987. -- 更新防守方对该城池的最后占领时间
  988. local defOccupyTimeArr = defOccupCityList[targetCityId].occupyTimeArr
  989. defOccupyTimeArr[#defOccupyTimeArr][2] = os.time()
  990. -- 删除防守方的该据点的占领者
  991. local defOccupyPointList = defOccupCityList[targetCityId].occupyPointList
  992. defOccupyPointList[targetCityId] = nil
  993. -- 删除防守方玩家的防守阵容数据
  994. local defPlayData = defUnionData.playerList[pointData.playerUuid]
  995. defPlayData.heroList[targetCityId][targetPointIdx] = nil
  996. cityNum = -1
  997. end
  998. -- 更新排行榜数据
  999. updateUnionRanktData(unionRankList, pointData.unionId, cityNum, pointNum)
  1000. updatePlayerRanktData(playerRankList, pointData.playerUuid, pointNum, -pointWeight)
  1001. -- 通知玩家
  1002. pointLose(defUnionData.serverId, pointData.playerUuid, targetCityId, targetPointIdx)
  1003. -- 更新防守方公会数据
  1004. AnotherWorldBattleDB.UpdateUnionData(pointData.unionId, defUnionData)
  1005. end
  1006. -- 更新据点最新占领者数据
  1007. pointData.unionId = myUnionId
  1008. pointData.playerUuid = playerUuid
  1009. -- 更新进攻方公会数据——据点占有者
  1010. myUnionData.occupCityList = myUnionData.occupCityList or {}
  1011. local occupCityList = myUnionData.occupCityList
  1012. occupCityList[targetCityId] = occupCityList[targetCityId] or {}
  1013. occupCityList[targetCityId].occupyPointList = occupCityList[targetCityId].occupyPointList or {}
  1014. occupCityList[targetCityId].occupyPointList[targetPointIdx] = playerUuid
  1015. --更新进攻者的展示数据
  1016. myUnionData.playerList = myUnionData.playerList or {}
  1017. myUnionData.playerList[playerUuid] = myUnionData.playerList[playerUuid] or {}
  1018. local playerData = myUnionData.playerList[playerUuid]
  1019. playerData.name = playerShowInfo.name
  1020. playerData.lv = playerShowInfo.lv
  1021. playerData.head = playerShowInfo.head
  1022. playerData.headFrame = playerShowInfo.headFrame
  1023. playerData.power = playerShowInfo.power
  1024. playerData.heroList = playerData.heroList or {}
  1025. playerData.heroList[targetCityId] = playerData.heroList[targetCityId] or {}
  1026. playerData.heroList[targetCityId][targetPointIdx] = playerShowInfo.heroArr
  1027. -- 更新公会排行榜数据: 进攻方公会占领据点数量+1
  1028. updateUnionRanktData(unionRankList, myUnionId, 0, 1)
  1029. local bl = getPlayerRank(playerRankList, playerUuid)
  1030. if not bl then -- 如果玩家是第一次挑战据点, 则把玩家加入到玩家排行榜中
  1031. playerRankList[#playerRankList+1] = {
  1032. unionId = myUnionId,
  1033. playerUuid = playerUuid,
  1034. pointNum = 1,
  1035. pointAllWeight = pointWeight,
  1036. power = playerData.power
  1037. }
  1038. else
  1039. updatePlayerRanktData(playerRankList, playerUuid, 1, pointWeight)
  1040. end
  1041. -- 进攻方完全占领城池了
  1042. if isCompleteOccupy(cityData, myUnionId) then
  1043. -- 更新城池的占领公会
  1044. cityData.occupyUnion = myUnionId
  1045. -- 更新进攻方公会对该城池的占领状态
  1046. occupCityList[targetCityId].isOccupy = true
  1047. -- 增加进攻方公会对该城池的占领开始时间戳
  1048. local now = os.time()
  1049. occupCityList[targetCityId].occupyTimeArr = occupCityList[targetCityId].occupyTimeArr or {}
  1050. local occupyTimeArr = occupCityList[targetCityId].occupyTimeArr
  1051. occupyTimeArr[#occupyTimeArr+1] = { now }
  1052. -- 如果占领的是发起集结的城池, 那么取消集结
  1053. if myUnionData.gatherInfo and myUnionData.gatherInfo.gatherCity == targetCityId then
  1054. myUnionData.gatherInfo.gatherCity = 0
  1055. end
  1056. -- 更新公会排行榜数据
  1057. updateUnionRanktData(unionRankList, myUnionId, 1, 0)
  1058. end
  1059. -- 更新进攻方公会数据
  1060. AnotherWorldBattleDB.UpdateUnionData(myUnionId, myUnionData)
  1061. -- 更新城池数据
  1062. AnotherWorldBattleDB.UpdateCityList(groupId, cityList)
  1063. -- 更新公会/个人排行榜
  1064. AnotherWorldBattleDB.UpdateUnionRankList(groupId, unionRankList)
  1065. AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerRankList)
  1066. end