AnotherWorldBattleCS.lua 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753
  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. IssueRewardManager()
  64. return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
  65. end
  66. -- 重置数据
  67. AnotherWorldBattleDB.ResetData()
  68. -- 更新状态
  69. AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_JOIN)
  70. -- 更新活动开始时间
  71. local now = os.time()
  72. AnotherWorldBattleDB.UpdateLastRoundStartTime(now)
  73. -- 通知所有普通服, 新一轮活动开启了
  74. ActOpen(now)
  75. end
  76. -- 进入新一轮报名阶段检测
  77. local function joinStageCheck()
  78. local stage = AnotherWorldBattleDB.GetStage()
  79. if stage ~= AnotherWorldBattleDefine.AB_STATE_END and stage ~= AnotherWorldBattleDefine.AB_STATE_AWARD then
  80. return
  81. end
  82. -- local lastRoundStartTime = AnotherWorldBattleDB.GetLastRoundStartTime()
  83. -- local diffDays = Util.diffDay(lastRoundStartTime)
  84. -- 上一轮活动结束时间为0 或 当前时间 - 上一轮活动开启时间 > 9天, 开启新一轮活动
  85. -- if lastRoundStartTime == 0 or diffDays > AnotherWorldBattleDefine.AB_SUB_DAY then
  86. newRoundHandle()
  87. -- end
  88. end
  89. -- 公会分组算法
  90. local function groupingAlgorithm(unionArray, len)
  91. local usedTb = {}
  92. local groupArr = {}
  93. local function getNextUnuseIdx(nowIdx)
  94. for i=nowIdx, len do
  95. if not usedTb[i] then
  96. return i
  97. end
  98. end
  99. end
  100. local function checkRandIdx(startIdx, endIdx)
  101. local tbl= {}
  102. for i= startIdx, endIdx do
  103. if not usedTb[i] then
  104. table.insert(tbl, i)
  105. end
  106. end
  107. return tbl
  108. end
  109. local currentIdx = 1
  110. local selectNum, cnt = 0, 0
  111. while currentIdx <= len do
  112. currentIdx = getNextUnuseIdx(currentIdx)
  113. if not currentIdx then
  114. break
  115. end
  116. local startIdx = currentIdx + 1
  117. local endIdx = math.min(currentIdx + 19, len)
  118. groupArr[#groupArr+1] = { unionArray[currentIdx] }
  119. selectNum = selectNum + 1
  120. cnt = math.min(AnotherWorldBattleDefine.AB_GROUP_UNION_NUM - 1, len - selectNum )
  121. for i=1, cnt do
  122. local correctTb = checkRandIdx(startIdx, endIdx)
  123. if #correctTb == 0 then break end
  124. local matchIdx = correctTb[math.random(1, #correctTb)]
  125. usedTb[currentIdx] = true
  126. usedTb[matchIdx] = true
  127. table.insert(groupArr[#groupArr], unionArray[matchIdx])
  128. selectNum = selectNum + 1
  129. end
  130. currentIdx = currentIdx + 1
  131. end
  132. return groupArr
  133. end
  134. -- 分组
  135. local function grouping()
  136. local function genUnionIdArray(sourceUnionArr, targetUnionArr)
  137. for k, v in ipairs(sourceUnionArr) do
  138. targetUnionArr[k] = v.unionId
  139. end
  140. end
  141. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  142. if not joinUnionArr then
  143. -- 没有公会参加, 本轮活动结束
  144. local now = os.time()
  145. -- AnotherWorldBattleDB.UpdateLastRoundStartTime(now)
  146. return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
  147. end
  148. local len = #joinUnionArr
  149. if len > AnotherWorldBattleDefine.AB_GROUP_UNION_NUM then
  150. table.sort(joinUnionArr, function (a, b)
  151. return a.power > b.power
  152. end)
  153. end
  154. local unionIdArr = {}
  155. genUnionIdArray(joinUnionArr, unionIdArr)
  156. local newGroupArray
  157. if len > AnotherWorldBattleDefine.AB_GROUP_UNION_NUM then
  158. newGroupArray = groupingAlgorithm(unionIdArr, len)
  159. else
  160. newGroupArray = { unionIdArr }
  161. end
  162. AnotherWorldBattleDB.UpdateGroupArray(newGroupArray)
  163. end
  164. -- 给各个分组中的公会随机分配出生点
  165. local function randomBaseCity()
  166. local baseCityIdArr = {}
  167. for cityId, cityCfg in ipairs(AnotherWorldBattleConfig.city) do
  168. if cityCfg.isBaseCity == 1 then
  169. baseCityIdArr[#baseCityIdArr+1] = cityId
  170. end
  171. end
  172. local now = os.time()
  173. local groupArray = AnotherWorldBattleDB.GetGroupArray()
  174. for _, unionIdArr in ipairs(groupArray) do
  175. -- 乱序
  176. table.shuffle(baseCityIdArr)
  177. for i, unionId in ipairs(unionIdArr) do
  178. local union = AnotherWorldBattleDB.GetUnionData(unionId)
  179. if union then
  180. union.baseCityId = baseCityIdArr[i]
  181. union.baseCityStartTime = now
  182. AnotherWorldBattleDB.UpdateUnionData(unionId, union)
  183. end
  184. end
  185. end
  186. end
  187. -- 统计公会的占领情况, 用于发放奖励
  188. local function genUnionOccupyInfo(unionId, union, playerListData)
  189. local occupyTb = {
  190. occupyCityArr = {}, -- 当前还占领的城池列表
  191. point2CityIdArr = {}, -- 曾占领/当前还占领的据点的所属城池Id列表
  192. occuoyPointNum = 0,
  193. playerUuidArr = {},
  194. unionId = unionId,
  195. }
  196. local now = os.time()
  197. local t1 = occupyTb.occupyCityArr
  198. local t2 = occupyTb.point2CityIdArr
  199. t1[#t1+1] = union.baseCityId
  200. for cityId, cityIno in pairs(union.occupCityList or {}) do
  201. if cityIno.isOccupy then
  202. t1[#t1+1] = cityId
  203. end
  204. for _, pointInfo in pairs(cityIno.occupyPointList) do
  205. if pointInfo.playerUuid then
  206. if not cityIno.isOccupy then
  207. occupyTb.occuoyPointNum = occupyTb.occuoyPointNum + 1
  208. end
  209. -- 更新据点最新占领时间段的结束时间
  210. local occupyTimeArr = pointInfo.occupyTimeArr
  211. local lastTimeTb = occupyTimeArr[#occupyTimeArr]
  212. if #lastTimeTb == 1 then
  213. occupyTimeArr[#occupyTimeArr][2] = now
  214. end
  215. end
  216. t2[#t2+1] = {cityId, pointInfo.occupyTimeArr}
  217. end
  218. end
  219. -- 出生点算5个据点
  220. local baseCiyuTimeArr = { {union.baseCityStartTime, union.baseCityEndTime or now } }
  221. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  222. t2[#t2+1] = {union.baseCityId, baseCiyuTimeArr}
  223. end
  224. for playerUuid, playerInfo in pairs(playerListData) do
  225. if playerInfo.unionId == unionId then
  226. occupyTb.playerUuidArr[#occupyTb.playerUuidArr+1] = playerUuid
  227. end
  228. end
  229. -- 防止本次没有正常发放奖励, 后续补发时, 结束时间异常的情况
  230. union.baseCityEndTime = now
  231. AnotherWorldBattleDB.UpdateUnionData(unionId, union)
  232. return occupyTb
  233. end
  234. -- 发奖
  235. local function issueReward(sourceServerId, occupyInfo)
  236. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_ISSUEREWARD
  237. msgData.unionOccupyInfo = occupyInfo
  238. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  239. InnerMsg.sendMsg(fd, msgData)
  240. end
  241. -- 奖励发放管理函数
  242. function IssueRewardManager()
  243. local delay_sec = 0
  244. local unionList = AnotherWorldBattleDB.GetUnionList()
  245. local playerListData = AnotherWorldBattleDB.GetPlayerList()
  246. for unionId, union in pairs(unionList) do
  247. local occupyInfo = genUnionOccupyInfo(unionId, union, playerListData)
  248. delay_sec = delay_sec + 5
  249. Timer.addLater(delay_sec, issueReward, union.serverId, occupyInfo)
  250. end
  251. end
  252. -- 检测活动各阶段状态及相关处理
  253. local function timedStageHandle()
  254. -- 处于报名阶段
  255. if table.find(AnotherWorldBattleDefine.AB_JOIN_WDAY_AREA, wDay) then
  256. joinStageCheck()
  257. end
  258. -- if wDay == AnotherWorldBattleDefine.AB_JOIN_WDAY then
  259. -- joinStageCheck()
  260. -- end
  261. local now = os.time()
  262. -- 报名阶段 -> 战斗阶段
  263. if wDay >= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[1] and wDay <= AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] then
  264. local stage = AnotherWorldBattleDB.GetStage()
  265. local toDayStartTime = getTodayStartTime()
  266. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN and now >= (toDayStartTime + AnotherWorldBattleDefine.AB_START_SEC) then
  267. -- 分组
  268. grouping()
  269. -- 给各个分组中的公会随机分配出生点
  270. randomBaseCity()
  271. -- 改为战斗阶段
  272. return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_BATTLE)
  273. end
  274. end
  275. -- 战斗阶段 -> 发奖阶段
  276. local toDayStartTime = getTodayStartTime()
  277. if wDay == AnotherWorldBattleDefine.AB_BATTLE_WDAY_AREA[2] and now >= (toDayStartTime + AnotherWorldBattleDefine.AB_BATTLE_END_SEC) then
  278. local stage = AnotherWorldBattleDB.GetStage()
  279. if stage == AnotherWorldBattleDefine.AB_STATE_BATTLE or stage == AnotherWorldBattleDefine.AB_STATE_AWARD then
  280. -- 改为发奖阶段
  281. AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_AWARD)
  282. -- 开始发奖
  283. IssueRewardManager()
  284. -- 改为结束阶段
  285. return AnotherWorldBattleDB.UpdateStage(AnotherWorldBattleDefine.AB_STATE_END)
  286. end
  287. end
  288. end
  289. function oneMin()
  290. if _G.is_middle ~= true then return end
  291. if not isOpen() then
  292. return
  293. end
  294. -- 与 onHour() 处理错开
  295. if Util.getMin() == 0 then
  296. return
  297. end
  298. timedStageHandle()
  299. end
  300. function onHour(hour)
  301. if _G.is_middle ~= true then return end
  302. if hour == 0 or not wDay then
  303. updateWDay()
  304. end
  305. if not isOpen() then
  306. return
  307. end
  308. timedStageHandle()
  309. end
  310. ------------------------------------C2N---------------------------------------------------
  311. -- 错误提示
  312. local function errTips(sourceServerId, playerUuid, errCode)
  313. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_TIPS
  314. msgData.playerUuid = playerUuid
  315. msgData.errCode = errCode
  316. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  317. InnerMsg.sendMsg(fd, msgData)
  318. end
  319. -- 通知玩家,据点被别的玩家占领了
  320. local function pointLose(sourceServerId, playerUuid, loseCityId, losePointIdx)
  321. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINT_LOSE
  322. msgData.playerUuid = playerUuid
  323. msgData.loseCityId = loseCityId
  324. msgData.losePointIdx = losePointIdx
  325. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  326. InnerMsg.sendMsg(fd, msgData)
  327. end
  328. -- 通知所有普通服, 活动开启
  329. function ActOpen(ti)
  330. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_ACT_START
  331. msgData.startTime = ti or os.time()
  332. local fdList = MiddleManager.MiddleManager_GetAllFD()
  333. for _, fd in pairs(fdList) do
  334. InnerMsg.sendMsg(fd, msgData)
  335. end
  336. end
  337. ------------------------------------N2C---------------------------------------------------
  338. -- 获取自己公会所在分组的Id
  339. local function getMyUnionGourpId(myUnionId)
  340. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  341. return groupId
  342. end
  343. -- 获取自己公会/所在区服第一公会所在分组Id
  344. local function getGroupId(myUnionId, myServerId)
  345. local groupId = getMyUnionGourpId(myUnionId)
  346. if not groupId then
  347. groupId = AnotherWorldBattleDB.GetGroupIdByServerId(myServerId)
  348. end
  349. return groupId
  350. end
  351. -- 统计单个服公会报名数量
  352. local function calcSvrUnionJoinNum(serverId)
  353. local num = 0
  354. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  355. if not joinUnionArr then
  356. return num
  357. end
  358. for _, unionInfo in ipairs(joinUnionArr) do
  359. if unionInfo.serverId == serverId then
  360. num = num + 1
  361. end
  362. end
  363. return num
  364. end
  365. -- 计算多个英雄的总战力
  366. local function calcHerosPower(heroArr)
  367. local power = 0
  368. for _, v in ipairs(heroArr) do
  369. power = power + v.heroPower
  370. end
  371. return power
  372. end
  373. -- 统计公会占领不同等级的城池数量
  374. local function calcOccupyCityNum(occupCityList, cityLv)
  375. if not occupCityList then
  376. return 0
  377. end
  378. local num = 0
  379. for cityId, occupyInfo in pairs(occupCityList) do
  380. if occupyInfo.isOccupy then
  381. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  382. if cityCfg.cityLv == cityLv then
  383. num = num + 1
  384. end
  385. end
  386. end
  387. return num
  388. end
  389. -- 统计公会占领的据点所属城池Id数组
  390. local function calcOccupyPointArr(occupCityList)
  391. local pointInfoArr = {}
  392. if not occupCityList then
  393. return pointInfoArr
  394. end
  395. for cityId, occupyInfo in pairs(occupCityList) do
  396. for _, pointInfo in pairs(occupyInfo.occupyPointList) do
  397. if pointInfo.playerUuid then
  398. pointInfoArr[#pointInfoArr+1] = cityId
  399. end
  400. end
  401. end
  402. return pointInfoArr
  403. end
  404. -- 获取公会占领的城池列表
  405. local function getUnionOccupyArr(unionId)
  406. local union = AnotherWorldBattleDB.GetUnionData(unionId)
  407. if not union then
  408. return
  409. end
  410. local occupyCityArr = {}
  411. occupyCityArr[#occupyCityArr+1] = union.baseCityId
  412. for cityId, occupyInfo in pairs(union.occupCityList or {}) do
  413. if occupyInfo.isOccupy then
  414. occupyCityArr[#occupyCityArr+1] = cityId
  415. end
  416. end
  417. return occupyCityArr
  418. end
  419. -- 检查某个城池与公会占领的城池是否相邻
  420. local function isadJoin(cityIdArr, targetCityId)
  421. if not cityIdArr then
  422. return false
  423. end
  424. local targetCityCfg = AnotherWorldBattleConfig.city[targetCityId]
  425. if not targetCityCfg then
  426. return false
  427. end
  428. for _, cityId in ipairs(targetCityCfg.adJoinCityArr) do
  429. if table.find(cityIdArr, cityId) then
  430. return true
  431. end
  432. end
  433. return false
  434. end
  435. -- 统计玩家占据的据点数量
  436. local function calcPlayerOccupyPointNum(playerUuid)
  437. local playerOccupyPonitNum = 0
  438. local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
  439. if playerData and playerData.heroList then
  440. for _, pointList in pairs(playerData.heroList) do
  441. for _, _ in pairs(pointList) do
  442. playerOccupyPonitNum = playerOccupyPonitNum + 1
  443. end
  444. end
  445. end
  446. return playerOccupyPonitNum
  447. end
  448. -- 检查某个据点是否能被玩家挑战
  449. local function isCanChallengePoint(targetCityId, targetPointIdx, myUnionId, playerUuid)
  450. -- 活动未开启
  451. if not isRunning() then
  452. return -1
  453. end
  454. -- 公会没有参加活动
  455. local groupId = getMyUnionGourpId(myUnionId)
  456. if not groupId then
  457. return -2
  458. end
  459. local tagetCityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
  460. if not tagetCityData then
  461. return -3
  462. end
  463. local targetPointData = tagetCityData.pointArr[targetPointIdx]
  464. if not targetPointData then
  465. return -5
  466. end
  467. -- 自己占领了该据点
  468. if targetPointData.unionId and targetPointData.unionId == myUnionId and targetPointData.playerUuid == playerUuid then
  469. return 2
  470. end
  471. -- 城池已被本公会占领
  472. if tagetCityData.occupyUnion and tagetCityData.occupyUnion == myUnionId then
  473. return -4
  474. end
  475. -- 据点已被本公会占领
  476. if targetPointData.unionId and targetPointData.unionId == myUnionId then
  477. return -6
  478. end
  479. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  480. if not myUnionData then
  481. return -7
  482. end
  483. -- 城池是否相邻
  484. local occupyCityArr = getUnionOccupyArr(myUnionId)
  485. if not isadJoin(occupyCityArr, targetCityId) then
  486. return -8
  487. end
  488. return 1
  489. end
  490. -- 公会是否能报名
  491. local function isCanJoin(sourceServerId, myUnionId)
  492. if not isRunning() then
  493. return 2
  494. end
  495. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  496. for _, unionData in ipairs(joinUnionArr or {}) do
  497. if unionData.unionId == myUnionId then
  498. return 1
  499. end
  500. end
  501. local num = calcSvrUnionJoinNum(sourceServerId)
  502. if num >= AnotherWorldBattleDefine.AB_SRV_UNION_MAX_NUM then
  503. return 2
  504. end
  505. return 0
  506. end
  507. -- 检查城池是否被己方公会完全占领
  508. local function isCompleteOccupy(cityData, myUnionId)
  509. for _, pointInfo in ipairs(cityData.pointArr) do
  510. if not pointInfo.unionId or pointInfo.unionId ~= myUnionId then
  511. return false
  512. end
  513. end
  514. return true
  515. end
  516. -- 获取玩家挑战次数相关数据
  517. local function getPlayerChallengeTimesInfo(playerUuid)
  518. local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
  519. if not playerData then
  520. return AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_INIT_TIMES, 0
  521. end
  522. local now = os.time()
  523. local subSex = now - playerData.lastTime
  524. if subSex >= AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC then
  525. local addTimes = math.floor(subSex / AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC)
  526. playerData.challengeTimes = math.min(playerData.challengeTimes + addTimes, AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_MAX_TIMES)
  527. playerData.lastTime = playerData.lastTime + addTimes* AnotherWorldBattleDefine.AB_PLAYER_CHALLENGETIMES_SEC
  528. if playerData.challengeTimes == AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_MAX_TIMES then
  529. playerData.lastTime = 0
  530. end
  531. AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
  532. end
  533. return playerData.challengeTimes, playerData.lastTime
  534. end
  535. -- 获取城池被占领状态
  536. local function getCityState(cityData)
  537. local state = 0
  538. if cityData.occupyUnion then
  539. state = 1
  540. return state
  541. end
  542. local occupyPlayerUuid
  543. for _, pointInfo in ipairs(cityData.pointArr) do
  544. if pointInfo.playerUuid then
  545. if not occupyPlayerUuid then
  546. occupyPlayerUuid = pointInfo.playerUuid
  547. end
  548. if pointInfo.playerUuid ~= occupyPlayerUuid then
  549. state = 2
  550. break
  551. end
  552. end
  553. end
  554. return state
  555. end
  556. -- 获取公会占领据点的数据
  557. local function getOccupPointData(unionId)
  558. local t2 = {}
  559. local unionData = AnotherWorldBattleDB.GetUnionData(unionId)
  560. if not unionData then
  561. return t2
  562. end
  563. for cityId, cityIno in pairs(unionData.occupCityList or {}) do
  564. for _, pointInfo in pairs(cityIno.occupyPointList) do
  565. t2[#t2+1] = {cityId, pointInfo.occupyTimeArr}
  566. end
  567. end
  568. -- 出生点算5个据点
  569. local baseCiyuTimeArr = { {unionData.baseCityStartTime, unionData.baseCityEndTime or now } }
  570. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  571. t2[#t2+1] = {unionData.baseCityId, baseCiyuTimeArr}
  572. end
  573. return t2
  574. end
  575. -- 查询状态
  576. function N2C_Get_State(msg)
  577. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_GET_STATE
  578. msgData.playerUuid = msg.playerUuid
  579. msgData.systemState = 0
  580. msgData.joinState = 0
  581. local stage = AnotherWorldBattleDB.GetStage()
  582. msgData.systemState = stage
  583. if stage == 0 then
  584. local lastRoundStartTime = AnotherWorldBattleDB.GetLastRoundStartTime()
  585. if lastRoundStartTime == 0 then
  586. msgData.systemState = 0
  587. else
  588. msgData.systemState = 3
  589. end
  590. end
  591. local sourceServerId = msg.sourceServerId
  592. local num = calcSvrUnionJoinNum(sourceServerId)
  593. if num >= AnotherWorldBattleDefine.AB_SRV_UNION_MAX_NUM then
  594. msgData.joinState = 2
  595. end
  596. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  597. for _, unionData in ipairs(joinUnionArr or {}) do
  598. if unionData.unionId == msg.myUnionId then
  599. msgData.joinState = 1
  600. end
  601. end
  602. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  603. InnerMsg.sendMsg(fd, msgData)
  604. end
  605. -- 报名
  606. function N2C_Join(msg)
  607. local sourceServerId = msg.sourceServerId
  608. local playerUuid = msg.playerUuid
  609. local unionInfo = msg.unionInfo
  610. local state = isCanJoin(sourceServerId, unionInfo.unionId)
  611. if state == 2 then
  612. return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_1)
  613. elseif state == 1 then
  614. return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_8)
  615. end
  616. -- 更新参赛列表数据
  617. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  618. joinUnionArr = joinUnionArr or {}
  619. joinUnionArr[#joinUnionArr+1] = {
  620. unionId = unionInfo.unionId,
  621. power = unionInfo.power,
  622. serverId = sourceServerId
  623. }
  624. AnotherWorldBattleDB.UpdateJoinUnionArr(joinUnionArr)
  625. -- 更新公会列表数据
  626. local newUnionData = {
  627. serverId = sourceServerId,
  628. power = unionInfo.power,
  629. name = unionInfo.name,
  630. }
  631. AnotherWorldBattleDB.UpdateUnionData(unionInfo.unionId, newUnionData)
  632. -- 通知报名成功
  633. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_JOIN
  634. msgData.playerUuid = playerUuid
  635. msgData.myUnionId = unionInfo.unionId
  636. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  637. InnerMsg.sendMsg(fd, msgData)
  638. end
  639. -- 查询所有城池信息
  640. function N2C_AllCity_Query(msg)
  641. local myUnionId = msg.myUnionId
  642. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_ALLCITY_QUERY
  643. msgData.cityArr = {}
  644. msgData.playerUuid = msg.playerUuid
  645. msgData.myUnionBaseCityId = 0
  646. msgData.myOccupyCityArr = {}
  647. msgData.hasPointNum = 0
  648. msgData.challengeTimes = 0
  649. msgData.lastTime = 0
  650. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  651. local groupId = getGroupId(myUnionId, msg.sourceServerId)
  652. if not groupId then
  653. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  654. local stage = AnotherWorldBattleDB.GetStage()
  655. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  656. return InnerMsg.sendMsg(fd, msgData)
  657. end
  658. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  659. end
  660. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  661. if not cityList then
  662. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  663. end
  664. local cityArrMsg = msgData.cityArr
  665. local unionList = AnotherWorldBattleDB.GetUnionList()
  666. msgData.myUnionBaseCityId = unionList[myUnionId] and unionList[myUnionId].baseCityId or 0
  667. for cityId, cityInfo in ipairs(cityList) do
  668. cityArrMsg[cityId] = { occupyPointNum = 0 }
  669. if cityInfo.occupyUnion then
  670. cityArrMsg[cityId].occupyUnionName = unionList[cityInfo.occupyUnion] and unionList[cityInfo.occupyUnion].name
  671. end
  672. for _, pointInfo in ipairs(cityInfo.pointArr) do
  673. if pointInfo.unionId and pointInfo.unionId == myUnionId then
  674. cityArrMsg[cityId].occupyPointNum = cityArrMsg[cityId].occupyPointNum + 1
  675. end
  676. end
  677. cityArrMsg[cityId].cityState = getCityState(cityInfo)
  678. end
  679. msgData.myOccupyCityArr = getUnionOccupyArr(myUnionId)
  680. msgData.hasPointNum = calcPlayerOccupyPointNum(msg.playerUuid)
  681. local challengeTimes, leftTime = getPlayerChallengeTimesInfo(msg.playerUuid)
  682. msgData.challengeTimes = challengeTimes
  683. msgData.lastTime = leftTime
  684. msgData.occupyPointData = getOccupPointData(myUnionId)
  685. InnerMsg.sendMsg(fd, msgData)
  686. end
  687. -- 查询某个城池的详细信息
  688. function N2C_CityDetailed_Query(msg)
  689. local myUnionId = msg.myUnionId
  690. local playerUuid = msg.playerUuid
  691. local targetCityId = msg.targetCityId
  692. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  693. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
  694. msgData.playerUuid = playerUuid
  695. msgData.targetCityId = targetCityId
  696. msgData.myUnionOccupyArr = {}
  697. msgData.pointArr = {}
  698. msgData.gatherState = 0
  699. local groupId = getGroupId(myUnionId, msg.sourceServerId)
  700. if not groupId then
  701. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  702. local stage = AnotherWorldBattleDB.GetStage()
  703. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  704. return InnerMsg.sendMsg(fd, msgData)
  705. end
  706. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  707. end
  708. local cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
  709. if not cityData then
  710. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  711. end
  712. local union = AnotherWorldBattleDB.GetUnionData(myUnionId)
  713. local occupCityList = union and union.occupCityList
  714. local myUnionOccupyArr = calcOccupyPointArr(occupCityList)
  715. if union then
  716. myUnionOccupyArr[#myUnionOccupyArr+1] = union.baseCityId
  717. end
  718. msgData.myUnionOccupyArr = myUnionOccupyArr
  719. local pointArrMsg = msgData.pointArr
  720. for pointIdx, occupyInfo in ipairs(cityData.pointArr) do
  721. pointArrMsg[pointIdx] = {}
  722. local state = isCanChallengePoint(targetCityId, pointIdx, myUnionId, playerUuid)
  723. pointArrMsg[pointIdx].state = state < 0 and 0 or state
  724. if occupyInfo.unionId and occupyInfo.playerUuid then
  725. local occupyUnionData = AnotherWorldBattleDB.GetUnionData(occupyInfo.unionId)
  726. local occupyPlayerData = AnotherWorldBattleDB.GetPlayerData(occupyInfo.playerUuid)
  727. if occupyUnionData and occupyPlayerData then
  728. pointArrMsg[pointIdx].occupyUnionName = occupyUnionData.name
  729. pointArrMsg[pointIdx].occupyPlayerName = occupyPlayerData.name
  730. pointArrMsg[pointIdx].power = 0
  731. local heroList = occupyPlayerData.heroList
  732. if heroList and heroList[targetCityId] and heroList[targetCityId][pointIdx] then
  733. pointArrMsg[pointIdx].power = calcHerosPower(heroList[targetCityId][pointIdx])
  734. end
  735. end
  736. end
  737. end
  738. local isOk = isRunning()
  739. if isOk then
  740. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  741. local occupyCityArr = getUnionOccupyArr(myUnionId)
  742. isOk = isadJoin(occupyCityArr, targetCityId)
  743. if isOk then
  744. if not cityData.occupyUnion or cityData.occupyUnion ~= myUnionId then
  745. if not myUnionData.gatherInfo then
  746. msgData.gatherState = 1
  747. else
  748. if myUnionData.gatherInfo.gatherCity == targetCityId then
  749. msgData.gatherState = 2
  750. else
  751. local now = os.time()
  752. if now - myUnionData.gatherInfo.gatherTime >= AnotherWorldBattleDefine.AB_GATHER_CD_SEC then
  753. msgData.gatherState = 1
  754. end
  755. end
  756. end
  757. end
  758. end
  759. end
  760. InnerMsg.sendMsg(fd, msgData)
  761. end
  762. -- 查询某个据点信息
  763. function N2C_PointDetailed_Query(msg)
  764. local myUnionId = msg.myUnionId
  765. local targetCityId = msg.targetCityId
  766. local targetPointIdx = msg.targetPointIdx
  767. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  768. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINTDETAILED_QUERY
  769. msgData.playerUuid = msg.playerUuid
  770. msgData.targetCityId = targetCityId
  771. msgData.targetPointIdx = targetPointIdx
  772. msgData.pointInfo = {}
  773. local groupId = getGroupId(myUnionId, msg.sourceServerId)
  774. if not groupId then
  775. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  776. local stage = AnotherWorldBattleDB.GetStage()
  777. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  778. return InnerMsg.sendMsg(fd, msgData)
  779. end
  780. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  781. end
  782. local cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
  783. if not cityData then
  784. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  785. end
  786. local pointData = cityData.pointArr[targetPointIdx]
  787. if not pointData then
  788. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  789. end
  790. local pointInfoMsg = msgData.pointInfo
  791. if pointData.unionId and pointData.playerUuid then
  792. local playerData = AnotherWorldBattleDB.GetPlayerData(pointData.playerUuid)
  793. if not playerData then
  794. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  795. end
  796. pointInfoMsg.name = playerData.name
  797. pointInfoMsg.head = playerData.head
  798. pointInfoMsg.headFrame = playerData.headFrame
  799. pointInfoMsg.defLv = playerData.lv
  800. local targetHeroArr = playerData.heroList[targetCityId][targetPointIdx]
  801. if not targetHeroArr then
  802. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  803. end
  804. pointInfoMsg.power = calcHerosPower(targetHeroArr)
  805. pointInfoMsg.heroArr = {}
  806. for i, heroInfo in ipairs(targetHeroArr) do
  807. pointInfoMsg.heroArr[i] = {
  808. heroBody = heroInfo.heroBody,
  809. heroStar = heroInfo.heroStar,
  810. heroLv = heroInfo.heroLevel,
  811. heroCamp = heroInfo.heroCamp,
  812. heroIcon = heroInfo.heroIcon,
  813. heroId = heroInfo.heroId,
  814. heroQuality = heroInfo.heroQuality,
  815. }
  816. end
  817. end
  818. local state = isCanChallengePoint(targetCityId, targetPointIdx, myUnionId, msg.playerUuid)
  819. pointInfoMsg.state = state < 0 and 0 or state
  820. InnerMsg.sendMsg(fd, msgData)
  821. end
  822. -- 查询公会出生点信息
  823. function N2C_BaseCity_Query(msg)
  824. local myUnionId = msg.myUnionId
  825. local groupId = getGroupId(myUnionId, msg.sourceServerId)
  826. if not groupId then
  827. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  828. end
  829. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_BASECITY_QUERY
  830. msgData.playerUuid = msg.playerUuid
  831. local union = AnotherWorldBattleDB.GetUnionData(myUnionId)
  832. if not union then
  833. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  834. end
  835. local baseCityInfo = {}
  836. msgData.baseCityInfo = baseCityInfo
  837. baseCityInfo.cityId = union.baseCityId
  838. local pointInfoArr = calcOccupyPointArr(union.occupCityList)
  839. baseCityInfo.occupyPointNum = #pointInfoArr
  840. baseCityInfo.myUnionOccupyArr = calcOccupyPointArr(union.occupCityList)
  841. baseCityInfo.myUnionOccupyArr[#baseCityInfo.myUnionOccupyArr+1] = baseCityInfo.cityId
  842. baseCityInfo.occupyCityLv2Num = calcOccupyCityNum(union.occupCityList, 2)
  843. baseCityInfo.occupyCityLv3Num = calcOccupyCityNum(union.occupCityList, 3)
  844. baseCityInfo.occupyCityLv4Num = calcOccupyCityNum(union.occupCityList, 4)
  845. baseCityInfo.occupyCityLv5Num = calcOccupyCityNum(union.occupCityList, 5)
  846. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  847. InnerMsg.sendMsg(fd, msgData)
  848. end
  849. -- 查询玩家占领的所有据点信息
  850. function N2C_PlayerOccupyPoint_Query(msg)
  851. local myUnionId = msg.myUnionId
  852. local playerUuid = msg.playerUuid
  853. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  854. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
  855. msgData.playerUuid = playerUuid
  856. msgData.occupyPointArr = {}
  857. local union = AnotherWorldBattleDB.GetUnionData(myUnionId)
  858. if not union then
  859. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  860. local stage = AnotherWorldBattleDB.GetStage()
  861. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  862. return InnerMsg.sendMsg(fd, msgData)
  863. end
  864. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  865. end
  866. local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
  867. if not playerData then
  868. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
  869. end
  870. local heroList = playerData.heroList
  871. if not heroList then
  872. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
  873. end
  874. local occupyPointArrMsg = msgData.occupyPointArr
  875. for cityId, pointList in pairs(heroList) do
  876. for pointIdx, heroInfoArr in pairs(pointList) do
  877. occupyPointArrMsg[#occupyPointArrMsg+1] = {
  878. cityId = cityId,
  879. pointIdx = pointIdx,
  880. power = calcHerosPower(heroInfoArr),
  881. heroArr = {},
  882. }
  883. local targetHeroArr = occupyPointArrMsg[#occupyPointArrMsg].heroArr
  884. for _, heroInfo in ipairs(heroInfoArr) do
  885. targetHeroArr[#targetHeroArr+1] = {
  886. heroBody = heroInfo.heroBody,
  887. heroStar = heroInfo.heroStar,
  888. heroLv = heroInfo.heroLevel,
  889. heroCamp = heroInfo.heroCamp,
  890. heroIcon = heroInfo.heroIcon,
  891. heroId = heroInfo.heroId,
  892. heroQuality = heroInfo.heroQuality
  893. }
  894. end
  895. end
  896. end
  897. InnerMsg.sendMsg(fd, msgData)
  898. end
  899. -- 查询公会排行榜
  900. function N2C_UnionRank_Query(msg)
  901. local myUnionId = msg.myUnionId
  902. local groupId = getGroupId(myUnionId, msg.sourceServerId)
  903. if not groupId then
  904. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  905. end
  906. local unionRankList = AnotherWorldBattleDB.GetUnionRankList(groupId)
  907. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
  908. msgData.playerUuid = msg.playerUuid
  909. msgData.myUnionRank = 0
  910. msgData.unionRankArr = {}
  911. for rank, randkData in ipairs(unionRankList) do
  912. msgData.unionRankArr[rank] = {
  913. name = randkData.name,
  914. power = randkData.power,
  915. cityNum = randkData.occupyCityNum,
  916. pointNum = randkData.occupyPointNum,
  917. }
  918. if randkData.guildId == myUnionId then
  919. msgData.myUnionRank = rank
  920. end
  921. end
  922. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  923. InnerMsg.sendMsg(fd, msgData)
  924. end
  925. -- 查询玩家排行榜
  926. function N2C_PlayerRank_Query(msg)
  927. local myUnionId = msg.myUnionId
  928. local groupId = getGroupId(myUnionId, msg.sourceServerId)
  929. if not groupId then
  930. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  931. end
  932. local playerRankList = AnotherWorldBattleDB.GetPlayerRankList(groupId)
  933. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
  934. msgData.playerUuid = msg.playerUuid
  935. msgData.myRank = 0
  936. msgData.playerRankArr = {}
  937. for rank, randkData in ipairs(playerRankList) do
  938. if rank > AnotherWorldBattleDefine.AB_RANK_MAX_NUM then
  939. break
  940. end
  941. msgData.playerRankArr[rank] = {
  942. name = randkData.name,
  943. power = randkData.power,
  944. pointNum = randkData.pointNum,
  945. pointWeight = randkData.pointAllWeight,
  946. }
  947. if randkData.playerId == msg.playerUuid then
  948. msgData.myRank = rank
  949. end
  950. end
  951. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  952. InnerMsg.sendMsg(fd, msgData)
  953. end
  954. -- 集结
  955. function N2C_Gather(msg)
  956. local sourceServerId = msg.sourceServerId
  957. local playerUuid = msg.playerUuid
  958. local myUnionId = msg.myUnionId
  959. if not isRunning() then
  960. return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_1)
  961. end
  962. local groupId = getMyUnionGourpId(myUnionId)
  963. if not groupId then
  964. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  965. end
  966. local targetCityId = msg.targetCityId
  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 gatherInfo = myUnionData.gatherInfo
  972. if msg.opType == 1 then --集结
  973. -- 集结冷却时间判断
  974. local now = os.time()
  975. if gatherInfo then
  976. local gatherTime = gatherInfo.gatherTime
  977. if now - gatherTime < AnotherWorldBattleDefine.AB_GATHER_CD_SEC then
  978. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_6)
  979. end
  980. end
  981. -- 城池是否相邻判断
  982. local occupCityyArr = getUnionOccupyArr(myUnionId)
  983. if not isadJoin(occupCityyArr, targetCityId) then
  984. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_7)
  985. end
  986. myUnionData.gatherInfo = myUnionData.gatherInfo or {}
  987. myUnionData.gatherInfo.gatherTime = now
  988. myUnionData.gatherInfo.gatherCity = targetCityId
  989. else
  990. -- 取消集结
  991. if not gatherInfo then
  992. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_9)
  993. end
  994. if targetCityId ~= gatherInfo.gatherCity then
  995. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_9)
  996. end
  997. gatherInfo.gatherCity = 0
  998. end
  999. AnotherWorldBattleDB.UpdateUnionData(myUnionId, myUnionData)
  1000. -- 推送城池数据给客户端,刷新界面
  1001. N2C_CityDetailed_Query(msg)
  1002. -- 发给本地服, 用于在公会聊天频道生成链接
  1003. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_GATHER
  1004. msgData.playerUuid = msg.playerUuid
  1005. msgData.targetCityId = targetCityId
  1006. msgData.opType = msg.opType
  1007. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  1008. InnerMsg.sendMsg(fd, msgData)
  1009. end
  1010. -- 查询据点是否可以被挑战
  1011. function N2C_Try_Challengde_Point(msg)
  1012. local playerUuid = msg.playerUuid
  1013. local myUnionId = msg.myUnionId
  1014. local targetCityId = msg.targetCityId
  1015. local targetPointIdx = msg.targetPointIdx
  1016. local state = isCanChallengePoint(targetCityId, msg.targetPointIdx, msg.myUnionId, playerUuid)
  1017. if state ~= 1 then
  1018. return
  1019. end
  1020. local occupyPointNum = calcPlayerOccupyPointNum(msg.playerUuid)
  1021. if occupyPointNum >= AnotherWorldBattleDefine.AB_PLAYER_OCCUPY_POINT_MAX_NUM then
  1022. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_10)
  1023. end
  1024. local groupId = getMyUnionGourpId(myUnionId)
  1025. local cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
  1026. local targetPointData = cityData.pointArr[targetPointIdx]
  1027. local pointOccupyInfo = {targetCityId = targetCityId, targetPointIdx = targetPointIdx}
  1028. if targetPointData.unionId then
  1029. local occupyUnionData = AnotherWorldBattleDB.GetUnionData(targetPointData.unionId)
  1030. pointOccupyInfo.occupySrvId = occupyUnionData.serverId
  1031. pointOccupyInfo.occupyPlayerUuid = targetPointData.playerUuid
  1032. end
  1033. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  1034. if myUnionData.gatherInfo and myUnionData.gatherInfo.gatherCity == targetCityId then
  1035. pointOccupyInfo.isGather = 1
  1036. end
  1037. -- 检查据点是否有人挑战
  1038. local now = os.time()
  1039. local pointBattleTime = targetPointData.battleTime
  1040. if pointBattleTime and now - pointBattleTime < AnotherWorldBattleDefine.AB_POINT_BATTLE_TIME then
  1041. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_11)
  1042. end
  1043. -- 更新据点被挑战时间
  1044. targetPointData.battleTime = now
  1045. AnotherWorldBattleDB.UpdateCityData(groupId, targetCityId, cityData)
  1046. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
  1047. msgData.playerUuid = playerUuid
  1048. msgData.targetCityId = targetCityId
  1049. msgData.targetPointIdx = targetPointIdx
  1050. msgData.pointInfo = pointOccupyInfo
  1051. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  1052. InnerMsg.sendMsg(fd, msgData)
  1053. end
  1054. -- 玩家挑战据点胜利
  1055. local function challenge_Win(msg)
  1056. local playerUuid = msg.playerUuid
  1057. local myUnionId = msg.myUnionId
  1058. local targetCityId = msg.targetCityId
  1059. local targetPointIdx = msg.targetPointIdx
  1060. local playerShowInfo = msg.playerShowInfo
  1061. if not isRunning() then
  1062. return
  1063. end
  1064. local groupId = getMyUnionGourpId(myUnionId)
  1065. if not groupId then
  1066. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  1067. end
  1068. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  1069. if not myUnionData then
  1070. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  1071. end
  1072. local cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
  1073. local pointData = cityData.pointArr[targetPointIdx]
  1074. local now = os.time()
  1075. local cityNum, pointNum = 0, 1
  1076. local pointWeight = AnotherWorldBattleConfig.city[targetCityId].pointWeight
  1077. -- 如果城池之前被占领了, 则删除占领城池的公会Id
  1078. if cityData.occupyUnion then
  1079. cityData.occupyUnion = nil
  1080. end
  1081. -- 防守方是真实玩家
  1082. if pointData.unionId and pointData.playerUuid then
  1083. -- 更新防守方公会数据
  1084. local defUnionData = AnotherWorldBattleDB.GetUnionData(pointData.unionId)
  1085. local defOccupCityList = defUnionData.occupCityList
  1086. local defTargerCityData = defOccupCityList[targetCityId]
  1087. -- 更新防守方公会对该据点的占领状态和最后占领时间
  1088. if defTargerCityData and defTargerCityData.occupyPointList and defTargerCityData.occupyPointList[targetPointIdx] then
  1089. local defTargetPointData = defTargerCityData.occupyPointList[targetPointIdx]
  1090. if defTargetPointData then
  1091. -- 删除占领该据点的玩家uuid
  1092. defTargetPointData.playerUuid = nil
  1093. -- 更新对该据点最后占领时间段的结束时间
  1094. if defTargetPointData.occupyTimeArr then
  1095. local lastOccupyTimeTb = defTargetPointData.occupyTimeArr[#defTargetPointData.occupyTimeArr]
  1096. lastOccupyTimeTb[2] = now
  1097. end
  1098. end
  1099. end
  1100. -- 删除防守方玩家的防守阵容数据
  1101. local defPlayData = AnotherWorldBattleDB.GetPlayerData(pointData.playerUuid)
  1102. if defPlayData then
  1103. defPlayData.heroList[targetCityId][targetPointIdx] = nil
  1104. AnotherWorldBattleDB.UpdatePlayerData(pointData.playerUuid, defPlayData)
  1105. end
  1106. -- 如果防守方公会之前占领了城池, 则修改占领状态
  1107. if defTargerCityData and defTargerCityData.isOccupy then
  1108. defTargerCityData.isOccupy = false
  1109. cityNum = -1
  1110. end
  1111. -- 更新防守方公会的排行榜数据
  1112. AnotherWorldBattleDB.UpdateUnionRankList(groupId, pointData.unionId, cityNum, pointNum)
  1113. -- 更新防守方玩家的排行榜数据
  1114. AnotherWorldBattleDB.UpdatePlayerRankList(groupId, pointData.playerUuid, -pointNum, -pointWeight)
  1115. -- 通知玩家
  1116. pointLose(defUnionData.serverId, pointData.playerUuid, targetCityId, targetPointIdx)
  1117. -- 更新防守方公会数据
  1118. AnotherWorldBattleDB.UpdateUnionData(pointData.unionId, defUnionData)
  1119. end
  1120. -- 更新据点最新占领者数据
  1121. pointData.unionId = myUnionId
  1122. pointData.playerUuid = playerUuid
  1123. -- 重置据点被挑战标识
  1124. pointData.battleTime = nil
  1125. -- 更新进攻方公会数据—— 据点占有者, 最新的据点占有时间
  1126. myUnionData.occupCityList = myUnionData.occupCityList or {}
  1127. local occupCityList = myUnionData.occupCityList
  1128. occupCityList[targetCityId] = occupCityList[targetCityId] or {}
  1129. occupCityList[targetCityId].occupyPointList = occupCityList[targetCityId].occupyPointList or {}
  1130. occupCityList[targetCityId].occupyPointList[targetPointIdx] = occupCityList[targetCityId].occupyPointList[targetPointIdx] or {}
  1131. local atkPointInfo = occupCityList[targetCityId].occupyPointList[targetPointIdx]
  1132. atkPointInfo.playerUuid = playerUuid
  1133. atkPointInfo.occupyTimeArr = atkPointInfo.occupyTimeArr or {}
  1134. atkPointInfo.occupyTimeArr[#atkPointInfo.occupyTimeArr+1] = { now }
  1135. --更新进攻者的展示数据
  1136. local atkPlayerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
  1137. atkPlayerData = atkPlayerData or {}
  1138. atkPlayerData.name = playerShowInfo.name
  1139. atkPlayerData.lv = playerShowInfo.lv
  1140. atkPlayerData.head = playerShowInfo.head
  1141. atkPlayerData.headFrame = playerShowInfo.headFrame
  1142. atkPlayerData.power = playerShowInfo.power
  1143. atkPlayerData.unionId = myUnionId
  1144. -- 更新挑战次数
  1145. atkPlayerData.challengeTimes = (atkPlayerData.challengeTimes or AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_INIT_TIMES) - 1
  1146. if not atkPlayerData.lastTime or atkPlayerData.lastTime == 0 then
  1147. atkPlayerData.lastTime = os.time()
  1148. end
  1149. -- 增加防守阵容数据
  1150. atkPlayerData.heroList = atkPlayerData.heroList or {}
  1151. atkPlayerData.heroList[targetCityId] = atkPlayerData.heroList[targetCityId] or {}
  1152. atkPlayerData.heroList[targetCityId][targetPointIdx] = playerShowInfo.heroArr
  1153. cityNum = 0
  1154. -- 进攻方完全占领城池了
  1155. if isCompleteOccupy(cityData, myUnionId) then
  1156. -- 更新城池的占领公会
  1157. cityData.occupyUnion = myUnionId
  1158. -- 更新进攻方公会对该城池的占领状态
  1159. occupCityList[targetCityId].isOccupy = true
  1160. -- 如果占领的是发起集结的城池, 那么取消集结
  1161. if myUnionData.gatherInfo and myUnionData.gatherInfo.gatherCity == targetCityId then
  1162. myUnionData.gatherInfo.gatherCity = 0
  1163. end
  1164. cityNum = 1
  1165. end
  1166. -- 更新进攻方公会数据
  1167. AnotherWorldBattleDB.UpdateUnionData(myUnionId, myUnionData)
  1168. -- 更新进攻方玩家数据
  1169. AnotherWorldBattleDB.UpdatePlayerData(playerUuid, atkPlayerData)
  1170. -- 更新进攻方公会的排行榜数据
  1171. AnotherWorldBattleDB.UpdateUnionRankList(groupId, myUnionId, cityNum, pointNum)
  1172. -- 更新进攻方玩家的排行榜数据
  1173. AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerUuid, pointNum, pointWeight, playerShowInfo.power)
  1174. -- 更新城池数据
  1175. AnotherWorldBattleDB.UpdateCityData(groupId, targetCityId, cityData)
  1176. end
  1177. -- 玩家挑战据点失败
  1178. local function challenge_Fail(msg)
  1179. local playerUuid = msg.playerUuid
  1180. local myUnionId = msg.myUnionId
  1181. local targetCityId = msg.targetCityId
  1182. local targetPointIdx = msg.targetPointIdx
  1183. local groupId = getMyUnionGourpId(myUnionId)
  1184. if not groupId then
  1185. return
  1186. end
  1187. -- 据点挑战结束
  1188. local cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
  1189. if cityData and cityData.pointArr[targetPointIdx] then
  1190. local targetPointData = cityData.pointArr[targetPointIdx]
  1191. targetPointData.battleTime = nil
  1192. AnotherWorldBattleDB.UpdateCityData(groupId, targetCityId, cityData)
  1193. end
  1194. local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
  1195. playerData = playerData or {}
  1196. playerData.name = playerData.name
  1197. playerData.lv = playerData.lv
  1198. playerData.power = playerData.power
  1199. playerData.unionId = myUnionId
  1200. playerData.challengeTimes = (playerData.challengeTimes or AnotherWorldBattleDefine.AB_PLAYER_CHALLENGE_INIT_TIMES) - 1
  1201. if not playerData.lastTime or playerData.lastTime == 0 then
  1202. playerData.lastTime = os.time()
  1203. end
  1204. AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
  1205. -- 加入个人排行榜
  1206. AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerUuid, 0, 0, playerData.power)
  1207. end
  1208. --挑战据点结束的处理函数
  1209. function N2C_Point_Challenge_End_Handle(msg)
  1210. if msg.challengeRes == CombatDefine.RESULT_WIN then
  1211. challenge_Win(msg)
  1212. else
  1213. challenge_Fail(msg)
  1214. end
  1215. end
  1216. -- 玩家数据更新
  1217. function N2C_Update_Player_Data(msg)
  1218. if not isRunning() then
  1219. return
  1220. end
  1221. local playerUuid = msg.playerUuid
  1222. local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
  1223. if not playerData then
  1224. return
  1225. end
  1226. local groupId = getMyUnionGourpId(playerData.unionId)
  1227. if not groupId then
  1228. return
  1229. end
  1230. local isUpdate = false
  1231. for k,v in pairs(msg.updateData) do
  1232. if k == "power" or k == "name" then
  1233. isUpdate = true
  1234. end
  1235. playerData[k] = v
  1236. end
  1237. AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
  1238. -- 如果是战力/名字更新, 更新玩家排行榜
  1239. if isUpdate then
  1240. AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerUuid, 0, 0, playerData.power)
  1241. end
  1242. end
  1243. -- 公会数据更新
  1244. function N2C_Update_Union_Data(msg)
  1245. if not isRunning() then
  1246. return
  1247. end
  1248. local myUnionId = msg.myUnionId
  1249. local unionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  1250. if not unionData then
  1251. return
  1252. end
  1253. local groupId = getMyUnionGourpId(myUnionId)
  1254. if not groupId then
  1255. return
  1256. end
  1257. local isUpdate = false
  1258. for k,v in pairs(msg.updateData) do
  1259. if k == "power" or k == "name" then
  1260. isUpdate = true
  1261. end
  1262. unionData[k] = v
  1263. end
  1264. AnotherWorldBattleDB.UpdateUnionData(myUnionId, unionData)
  1265. -- 如果是战力更新, 更新公会排行榜
  1266. if isUpdate then
  1267. AnotherWorldBattleDB.UpdateUnionRankList(groupId, myUnionId, 0, 0, unionData.power)
  1268. end
  1269. end
  1270. -- 更新玩家据点防守阵容数据
  1271. function N2C_Update_Point_Lineup(msg)
  1272. if not isRunning() then
  1273. return
  1274. end
  1275. local playerUuid = msg.playerUuid
  1276. local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
  1277. if not playerData or not playerData.heroList then
  1278. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
  1279. end
  1280. local groupId = getMyUnionGourpId(playerData.unionId)
  1281. if not groupId then
  1282. return
  1283. end
  1284. local targetCityId, targetPointIdx = msg.targetCityId, msg.targetPointIdx
  1285. local heroList = playerData.heroList
  1286. if not heroList[targetCityId] or not heroList[targetCityId][targetPointIdx] then
  1287. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
  1288. end
  1289. heroList[targetCityId][targetPointIdx] = msg.heroArr
  1290. AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
  1291. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_UPDATE_POINT_LINEIP
  1292. msgData.playerUuid = playerUuid
  1293. msgData.targetCityId = targetCityId
  1294. msgData.targetPointIdx = targetPointIdx
  1295. msgData.formation = msg.formation
  1296. msgData.heroList = msg.heroList
  1297. msgData.helpList = msg.helpList
  1298. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  1299. InnerMsg.sendMsg(fd, msgData)
  1300. end
  1301. -- 更新玩家英雄数据
  1302. function N2C_Update_HeroData(msg)
  1303. if not isRunning() then
  1304. return
  1305. end
  1306. local playerUuid = msg.playerUuid
  1307. local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
  1308. if not playerData then
  1309. return
  1310. end
  1311. local heroList = playerData.heroList
  1312. if not heroList then
  1313. return
  1314. end
  1315. local targetCityId, targetPointIdx = msg.targetCityId, msg.targetPointIdx
  1316. if not heroList[targetCityId] or not heroList[targetCityId][targetPointIdx] then
  1317. return
  1318. end
  1319. local isUpdate = false
  1320. local newHeroData = msg.heroData
  1321. local heroArr = heroList[targetCityId][targetPointIdx]
  1322. for _, heroData in ipairs(heroArr) do
  1323. if heroData.heroUuid == newHeroData.heroUuid then
  1324. for k, v in pairs(newHeroData) do
  1325. heroData[k] = v
  1326. end
  1327. isUpdate = true
  1328. break
  1329. end
  1330. end
  1331. if isUpdate then
  1332. AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
  1333. end
  1334. end
  1335. -- 放弃据点
  1336. function N2C_Leave_Point(msg)
  1337. local playerUuid = msg.playerUuid
  1338. local myUnionId = msg.myUnionId
  1339. local targetCityId = msg.targetCityId
  1340. local targetPointIdx = msg.targetPointIdx
  1341. if not isRunning() then
  1342. return
  1343. end
  1344. local groupId = getMyUnionGourpId(myUnionId)
  1345. local cityData = AnotherWorldBattleDB.GetCityData(groupId, targetCityId)
  1346. local targetPointData = cityData.pointArr[targetPointIdx]
  1347. if not targetPointData.unionId or targetPointData.unionId ~= myUnionId or targetPointData.playerUuid ~= playerUuid then
  1348. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
  1349. end
  1350. local playerData = AnotherWorldBattleDB.GetPlayerData(playerUuid)
  1351. if not playerData then
  1352. return
  1353. end
  1354. local heroList = playerData.heroList
  1355. if not heroList or not heroList[targetCityId] or not heroList[targetCityId][targetPointIdx] then
  1356. return
  1357. end
  1358. local defUnionData = AnotherWorldBattleDB.GetUnionData(targetPointData.unionId)
  1359. if not defUnionData then
  1360. return
  1361. end
  1362. local defOccupCityList = defUnionData.occupCityList
  1363. if not defOccupCityList then
  1364. return
  1365. end
  1366. local defTargerCityData = defOccupCityList[targetCityId]
  1367. if not defTargerCityData or not defTargerCityData.occupyPointList or not defTargerCityData.occupyPointList[targetPointIdx] then
  1368. return
  1369. end
  1370. local cityNum, pointNum = 0, -1
  1371. -- 更新城池数据, 如果城池之前被本公会占领了, 则删除
  1372. if cityData.occupyUnion and cityData.occupyUnion == myUnionId then
  1373. cityData.occupyUnion = nil
  1374. end
  1375. -- 更新据点数据, 删除据点的 unionId, playerUuid
  1376. targetPointData.unionId = nil
  1377. targetPointData.playerUuid = nil
  1378. -- 更新公会数据, 删除公会数据中占领该据点的玩家uuid
  1379. local defTargetPointData = defTargerCityData.occupyPointList[targetPointIdx]
  1380. defTargetPointData.playerUuid = nil
  1381. -- 更新公会数据, 更新该据点最后占领时间段的结束时间
  1382. if defTargetPointData.occupyTimeArr then
  1383. local lastOccupyTimeTb = defTargetPointData.occupyTimeArr[#defTargetPointData.occupyTimeArr]
  1384. lastOccupyTimeTb[2] = now
  1385. end
  1386. -- 更新公会数据, 如果本公会之前占领了城池, 则修改占领状态
  1387. if defTargerCityData and defTargerCityData.isOccupy then
  1388. defTargerCityData.isOccupy = false
  1389. cityNum = -1
  1390. end
  1391. -- 更新玩家数据, 删除玩家数据中该据点的防守数据
  1392. heroList[targetCityId][targetPointIdx] = nil
  1393. if not next(heroList[targetCityId]) then
  1394. heroList[targetCityId] = nil
  1395. end
  1396. -- 更新公会数据
  1397. AnotherWorldBattleDB.UpdateUnionData(myUnionId, defUnionData)
  1398. -- 更新玩家数据
  1399. AnotherWorldBattleDB.UpdatePlayerData(playerUuid, playerData)
  1400. -- 更新公会的排行榜数据
  1401. AnotherWorldBattleDB.UpdateUnionRankList(groupId, myUnionId, cityNum, pointNum)
  1402. -- 更新玩家的排行榜数据
  1403. local pointWeight = AnotherWorldBattleConfig.city[targetCityId].pointWeight
  1404. AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerUuid, pointNum, -pointWeight)
  1405. -- 更新城池数据
  1406. AnotherWorldBattleDB.UpdateCityData(groupId, targetCityId, cityData)
  1407. -- 通知普通服, 放弃据点成功
  1408. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_LEAVE_POINT
  1409. msgData.playerUuid = playerUuid
  1410. msgData.targetCityId = targetCityId
  1411. msgData.targetPointIdx = targetPointIdx
  1412. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  1413. InnerMsg.sendMsg(fd, msgData)
  1414. N2C_AllCity_Query(msg)
  1415. end