AnotherWorldBattleCS.lua 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  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. playerArr = {},
  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.playerArr
  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. end
  307. end
  308. end
  309. ------------------------------------C2N---------------------------------------------------
  310. local function errTips(sourceServerId, playerUuid, errCode)
  311. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_TIPS
  312. msgData.playerUuid = playerUuid
  313. msgData.errCode = errCode
  314. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  315. InnerMsg.sendMsg(fd, msgData)
  316. end
  317. -- 通知玩家,据点被别的玩家占领了
  318. local function pointLose(sourceServerId, playerUuid, loseCityId, losePointIdx)
  319. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_TIPS
  320. msgData.playerUuid = playerUuid
  321. msgData.loseCityId = loseCityId
  322. msgData.losePointIdx = losePointIdx
  323. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  324. InnerMsg.sendMsg(fd, msgData)
  325. end
  326. ------------------------------------N2C---------------------------------------------------
  327. -- 统计单个服公会报名数量
  328. local function calcSvrUnionJoinNum(serverId)
  329. local num = 0
  330. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  331. if not joinUnionArr then
  332. return num
  333. end
  334. for _, unionInfo in ipairs(joinUnionArr) do
  335. if unionInfo.serverId == serverId then
  336. num = num + 1
  337. end
  338. end
  339. return num
  340. end
  341. -- 计算多个英雄的总战力
  342. local function calcHerosPower(heroArr)
  343. local power = 0
  344. for _, v in ipairs(heroArr) do
  345. power = power + v.heroPower
  346. end
  347. return power
  348. end
  349. -- 统计公会占领不同等级的城池数量
  350. local function calcOccupyCityNum(occupCityList, cityLv)
  351. if not occupCityList then
  352. return 0
  353. end
  354. local num = 0
  355. for cityId, occupyInfo in pairs(occupCityList) do
  356. if occupyInfo.isOccupy then
  357. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  358. if cityCfg == cityLv then
  359. num = num + 1
  360. end
  361. end
  362. end
  363. return num
  364. end
  365. -- 统计公会占领的据点数量
  366. local function calcOccupyPointNum(occupCityList)
  367. if not occupCityList then
  368. return 0
  369. end
  370. local num = 0
  371. for cityId, occupyInfo in pairs(occupCityList) do
  372. for _,_ in pairs(occupyInfo.occupyPointList) do
  373. num = num + 1
  374. end
  375. end
  376. return num
  377. end
  378. -- 获取公会占领的城池列表
  379. local function getUnionOccupyArr(unionId)
  380. local union = AnotherWorldBattleDB.GetUnionData(unionId)
  381. if not union then
  382. return
  383. end
  384. local occupyCityArr = {}
  385. occupyCityArr[#occupyCityArr+1] = union.baseCityId
  386. for cityId, occupyInfo in pairs(union.occupCityList or {}) do
  387. if occupyInfo.isOccupy then
  388. occupyCityArr[#occupyCityArr+1] = cityId
  389. end
  390. end
  391. return occupyCityArr
  392. end
  393. -- 检查某个城池与公会占领的城池是否相邻
  394. local function isadJoin(cityIdArr, targetCityId)
  395. if not cityIdArr then
  396. return false
  397. end
  398. local targetCityCfg = AnotherWorldBattleConfig.city[targetCityId]
  399. if not targetCityCfg then
  400. return false
  401. end
  402. for _, cityId in ipairs(targetCityCfg.adJoinCityArr) do
  403. if table.find(cityIdArr, cityId) then
  404. return true
  405. end
  406. end
  407. return false
  408. end
  409. -- 检查某个据点是否能被玩家挑战
  410. local function isCanChallengePoint(targetCityId, targetPointIdx, myUnionId, playerUuid)
  411. -- 活动未开启
  412. if not isRunning() then
  413. return false
  414. end
  415. -- 公会没有参加活动
  416. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  417. if not groupId then
  418. return false
  419. end
  420. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  421. local tagetCityData = cityList[targetCityId]
  422. if not tagetCityData then
  423. return false
  424. end
  425. -- 城池已被本公会占领
  426. if tagetCityData.occupyUnion and tagetCityData.occupyUnion == myUnionId then
  427. return false
  428. end
  429. local targetPointData = tagetCityData.pointArr[targetPointIdx]
  430. if not targetPointData then
  431. return false
  432. end
  433. -- 据点已被本公会占领
  434. if targetPointData.unionId and targetPointData.unionId == myUnionId then
  435. return false
  436. end
  437. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  438. if not myUnionData then
  439. return false
  440. end
  441. -- 城池是否相邻
  442. local occupyCityArr = getUnionOccupyArr(myUnionId)
  443. if not isadJoin(occupyCityArr, targetCityId) then
  444. return false
  445. end
  446. -- 每个玩家最多占领据点数量是否超出
  447. local playerOccupyPonitNum = 0
  448. if myUnionData.playerList and myUnionData.playerList[playerUuid] then
  449. local heroList = myUnionData.playerList[playerUuid].heroList
  450. for cityId, pointList in pairs(heroList) do
  451. for _, _ in pairs(pointList) do
  452. playerOccupyPonitNum = playerOccupyPonitNum + 1
  453. end
  454. end
  455. end
  456. if playerOccupyPonitNum >= AnotherWorldBattleDefine.AB_PLAYER_OCCUPY_POINT_MAX_NUM then
  457. return false
  458. end
  459. return true
  460. end
  461. -- 公会是否能报名
  462. local function isCanJoin(sourceServerId, myUnionId)
  463. if not isRunning() then
  464. return 2
  465. end
  466. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  467. for _, unionData in ipairs(joinUnionArr or {}) do
  468. if unionData.unionId == myUnionId then
  469. return 1
  470. end
  471. end
  472. local num = calcSvrUnionJoinNum(sourceServerId)
  473. if num >= AnotherWorldBattleDefine.AB_SRV_UNION_MAX_NUM then
  474. return 2
  475. end
  476. return 0
  477. end
  478. -- 检查城池是否被己方公会完全占领
  479. local function isCompleteOccupy(cityData, myUnionId)
  480. for _, pointInfo in ipairs(cityData.pointArr) do
  481. if not pointInfo.unionId or pointInfo.unionId ~= myUnionId then
  482. return false
  483. end
  484. end
  485. return true
  486. end
  487. -- 查询玩家是否上榜
  488. local function getPlayerRank(playerRankList, playerUuid)
  489. for _, rankData in ipairs(playerRankList) do
  490. if rankData.playerUuid == playerUuid then
  491. return true
  492. end
  493. end
  494. return false
  495. end
  496. -- 更新公会排行榜数据
  497. local function updateUnionRanktData(unionRankList, unionId, cityNum, pointNum)
  498. for rank, rankData in ipairs(unionRankList) do
  499. if rankData.unionId == unionId then
  500. unionRankList[rank].occupyCityNum = unionRankList[rank].occupyCityNum + cityNum
  501. unionRankList[rank].occupyPointNum = unionRankList[rank].occupyPointNum + pointNum
  502. end
  503. end
  504. end
  505. -- 更新玩家排行榜数据
  506. local function updatePlayerRanktData(playerRankList, playerUuid, pointNum, pointWeight)
  507. local playerRank = 0
  508. for rank, rankData in ipairs(playerRankList) do
  509. if rankData.playerUuid == playerUuid then
  510. playerRank = rank
  511. end
  512. end
  513. if playerRank ~= 0 then
  514. playerRankList[playerRank].pointNum = playerRankList[playerRank].pointNum + pointNum
  515. playerRankList[playerRank].pointAllWeight = playerRankList[playerRank].pointAllWeight + pointWeight
  516. end
  517. end
  518. -- 查询状态
  519. function N2C_Get_State(msg)
  520. local sourceServerId = msg.sourceServerId
  521. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_GET_STATE
  522. msgData.playerUuid = msg.playerUuid
  523. local stage = AnotherWorldBattleDB.GetStage()
  524. msgData.systemState = stage
  525. msgData.joinState = 0
  526. if stage == 0 then
  527. local lastRoundStartTime = AnotherWorldBattleDB.GetLastRoundStartTime()
  528. if lastRoundStartTime == 0 then
  529. msgData.systemState = 0
  530. end
  531. end
  532. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  533. for _, unionData in ipairs(joinUnionArr or {}) do
  534. if unionData.unionId == msg.myUnionId then
  535. msgData.joinState = 1
  536. end
  537. end
  538. local num = calcSvrUnionJoinNum(sourceServerId)
  539. if num >= AnotherWorldBattleDefine.AB_SRV_UNION_MAX_NUM then
  540. msgData.joinState = 2
  541. end
  542. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  543. InnerMsg.sendMsg(fd, msgData)
  544. end
  545. -- 报名
  546. function N2C_Join(msg)
  547. local sourceServerId = msg.sourceServerId
  548. local playerUuid = msg.playerUuid
  549. local unionInfo = msg.unionInfo
  550. local state = isCanJoin(sourceServerId, unionInfo.unionId)
  551. if state == 2 then
  552. return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_1)
  553. elseif state == 1 then
  554. return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_8)
  555. end
  556. local joinUnionArr = AnotherWorldBattleDB.GetJoinUnionArr()
  557. joinUnionArr = joinUnionArr or {}
  558. joinUnionArr[#joinUnionArr+1] = {
  559. unionId = unionInfo.unionId,
  560. power = unionInfo.power,
  561. serverId = sourceServerId
  562. }
  563. AnotherWorldBattleDB.UpdateJoinUnionArr(joinUnionArr)
  564. local unionList = AnotherWorldBattleDB.GetUnionList()
  565. unionList = unionList or {}
  566. unionList[unionInfo.unionId] = {
  567. serverId = sourceServerId,
  568. power = unionInfo.power,
  569. name = unionInfo.name,
  570. }
  571. AnotherWorldBattleDB.UpdateUnionList(unionList)
  572. -- 通知报名成功
  573. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_JOIN
  574. msgData.playerUuid = playerUuid
  575. msgData.myUnionId = unionInfo.unionId
  576. local fd = MiddleManager.getFDBySvrIndex(sourceServerId)
  577. InnerMsg.sendMsg(fd, msgData)
  578. end
  579. -- 查询所有城池信息
  580. function N2C_AllCity_Query(msg)
  581. local myUnionId = msg.myUnionId
  582. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_ALLCITY_QUERY
  583. msgData.cityArr = {}
  584. msgData.playerUuid = msg.playerUuid
  585. msgData.myUnionBaseCityId = 0
  586. msgData.myOccupyCityArr = {}
  587. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  588. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  589. if not groupId then
  590. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  591. local stage = AnotherWorldBattleDB.GetStage()
  592. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  593. return InnerMsg.sendMsg(fd, msgData)
  594. end
  595. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  596. end
  597. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  598. if not cityList then
  599. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  600. end
  601. local cityArrMsg = msgData.cityArr
  602. local unionList = AnotherWorldBattleDB.GetUnionList()
  603. msgData.myUnionBaseCityId = unionList[myUnionId] and unionList[myUnionId].baseCityId or 0
  604. for cityId, cityInfo in ipairs(cityList) do
  605. cityArrMsg[cityId] = { occupyPointNum = 0 }
  606. if cityInfo.occupyUnion then
  607. cityArrMsg[cityId].occupyUnionName = unionList[cityInfo.occupyUnion] and unionList[cityInfo.occupyUnion].name
  608. end
  609. for _, pointInfo in ipairs(cityInfo.pointArr) do
  610. if pointInfo.unionId and pointInfo.playerUuid then
  611. cityArrMsg[cityId].occupyPointNum = cityArrMsg[cityId].occupyPointNum + 1
  612. end
  613. end
  614. end
  615. msgData.myOccupyCityArr = getUnionOccupyArr(myUnionId)
  616. InnerMsg.sendMsg(fd, msgData)
  617. end
  618. -- 查询某个城池的详细信息
  619. function N2C_CityDetailed_Query(msg)
  620. local myUnionId = msg.myUnionId
  621. local playerUuid = msg.playerUuid
  622. local targetCityId = msg.targetCityId
  623. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  624. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_CITYDETAILED_QUERY
  625. msgData.playerUuid = playerUuid
  626. msgData.targetCityId = targetCityId
  627. msgData.myUnionOccupyArr = {}
  628. msgData.pointArr = {}
  629. msgData.gatherState = 0
  630. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  631. if not groupId then
  632. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  633. local stage = AnotherWorldBattleDB.GetStage()
  634. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  635. return InnerMsg.sendMsg(fd, msgData)
  636. end
  637. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  638. end
  639. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  640. if not cityList or not cityList[targetCityId] then
  641. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  642. end
  643. local cityData = cityList[targetCityId]
  644. local myUnionOccupyArr = getUnionOccupyArr(myUnionId)
  645. msgData.myUnionOccupyArr = myUnionOccupyArr
  646. local pointArrMsg = msgData.pointArr
  647. for pointidx, occupyInfo in ipairs(cityData.pointArr) do
  648. pointArrMsg[pointidx] = {}
  649. local bl = isCanChallengePoint(targetCityId, pointidx, myUnionId, playerUuid)
  650. pointArrMsg[pointidx].isCanChallenge = bl and 1 or 0
  651. if occupyInfo.unionId and occupyInfo.playerUuid then
  652. local occupyUnionData = AnotherWorldBattleDB.GetUnionData(occupyInfo.unionId)
  653. if occupyUnionData then
  654. pointArrMsg[pointidx].occupyUnionName = occupyUnionData.name
  655. pointArrMsg[pointidx].occupyPlayerName = occupyUnionData.playerList[occupyInfo.playerUuid].name
  656. pointArrMsg[pointidx].power = 0
  657. local heroList = occupyUnionData.playerList[occupyInfo.playerUuid].heroList
  658. if heroList and heroList[targetCityId] and heroList[targetCityId][pointidx] then
  659. pointArrMsg[pointidx].power = calcHerosPower(heroList[targetCityId][pointidx])
  660. end
  661. end
  662. end
  663. end
  664. local isOk = isRunning()
  665. if isOk then
  666. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  667. local occupyCityArr = getUnionOccupyArr(myUnionId)
  668. isOk = isadJoin(occupyCityArr, targetCityId)
  669. if isOk then
  670. if not cityData.occupyUnion or cityData.occupyUnion ~= myUnionId then
  671. if not myUnionData.gatherInfo then
  672. msgData.gatherState = 1
  673. else
  674. if myUnionData.gatherInfo.gatherCity == targetCityId then
  675. msgData.gatherState = 2
  676. else
  677. local now = os.time()
  678. if now - myUnionData.gatherInfo.gatherTime >= AnotherWorldBattleDefine.AB_GATHER_CD_SEC then
  679. msgData.gatherState = 1
  680. end
  681. end
  682. end
  683. end
  684. end
  685. end
  686. InnerMsg.sendMsg(fd, msgData)
  687. end
  688. -- 查询某个据点信息
  689. function N2C_PointDetailed_Query(msg)
  690. local myUnionId = msg.myUnionId
  691. local targetCityId = msg.targetCityId
  692. local targetPointIdx = msg.targetPointIdx
  693. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  694. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINTDETAILED_QUERY
  695. msgData.playerUuid = msg.playerUuid
  696. msgData.targetCityId = targetCityId
  697. msgData.targetPointIdx = targetPointIdx
  698. msgData.pointInfo = {}
  699. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  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, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  707. end
  708. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  709. if not cityList or not cityList[targetCityId] then
  710. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  711. end
  712. local cityData = cityList[targetCityId]
  713. local pointData = cityData.pointArr[targetPointIdx]
  714. if not pointData then
  715. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  716. end
  717. local pointInfoMsg = msgData.pointInfo
  718. if pointData.unionId and pointData.playerUuid then
  719. local union = AnotherWorldBattleDB.GetUnionData(pointData.unionId)
  720. if not union then
  721. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  722. end
  723. local playerData = union.playerList and union.playerList[pointData.playerUuid]
  724. if not playerData then
  725. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  726. end
  727. pointInfoMsg.name = playerData.name
  728. pointInfoMsg.head = playerData.head
  729. pointInfoMsg.headFrame = playerData.headFrame
  730. pointInfoMsg.defLv = playerData.lv
  731. local targetHeroArr = playerData.heroList[targetCityId][targetPointIdx]
  732. if not targetHeroArr then
  733. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  734. end
  735. pointInfoMsg.power = calcHerosPower(targetHeroArr)
  736. pointInfoMsg.heroArr = {}
  737. for i, heroInfo in ipairs(targetHeroArr) do
  738. pointInfoMsg.heroArr[i] = {
  739. heroBody = heroInfo.heroBody,
  740. heroStar = heroInfo.heroStar,
  741. heroLv = heroInfo.heroLevel,
  742. heroCamp = heroInfo.heroCamp,
  743. heroIcon = heroInfo.heroIcon,
  744. }
  745. end
  746. end
  747. local isCanChallenge = isCanChallengePoint(targetCityId, targetPointIdx, myUnionId, msg.playerUuid)
  748. pointInfoMsg.isCanChallenge = isCanChallenge and 1 or 0
  749. InnerMsg.sendMsg(fd, msgData)
  750. end
  751. -- 查询公会出生点信息
  752. function N2C_BaseCity_Query(msg)
  753. local myUnionId = msg.myUnionId
  754. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  755. if not groupId then
  756. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  757. end
  758. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_BASECITY_QUERY
  759. msgData.playerUuid = msg.playerUuid
  760. local union = AnotherWorldBattleDB.GetUnionData(myUnionId)
  761. if not union then
  762. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  763. end
  764. local baseCityInfo = {}
  765. msgData.baseCityInfo = baseCityInfo
  766. baseCityInfo.cityId = union.baseCityId
  767. baseCityInfo.occupyPointNum = calcOccupyPointNum(union.occupCityList)
  768. baseCityInfo.myUnionOccupyArr = getUnionOccupyArr(myUnionId)
  769. baseCityInfo.occupyCityLv2Num = calcOccupyCityNum(union.occupCityList, 2)
  770. baseCityInfo.occupyCityLv3Num = calcOccupyCityNum(union.occupCityList, 3)
  771. baseCityInfo.occupyCityLv4Num = calcOccupyCityNum(union.occupCityList, 4)
  772. baseCityInfo.occupyCityLv5Num = calcOccupyCityNum(union.occupCityList, 5)
  773. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  774. InnerMsg.sendMsg(fd, msgData)
  775. end
  776. -- 查询玩家占领的所有据点信息
  777. function N2C_PlayerOccupyPoint_Query(msg)
  778. local myUnionId = msg.myUnionId
  779. local playerUuid = msg.playerUuid
  780. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  781. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_PLAYEROCCUPYPOINT_QUERY
  782. msgData.playerUuid = playerUuid
  783. msgData.occupyPointArr = {}
  784. local union = AnotherWorldBattleDB.GetUnionData(myUnionId)
  785. if not union then
  786. -- 报名阶段, 或者活动开未开启过处于默认的结束状态
  787. local stage = AnotherWorldBattleDB.GetStage()
  788. if stage == AnotherWorldBattleDefine.AB_STATE_JOIN or stage == AnotherWorldBattleDefine.AB_STATE_END then
  789. return InnerMsg.sendMsg(fd, msgData)
  790. end
  791. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  792. end
  793. local playerList = union.playerList
  794. if not playerList[playerUuid] then
  795. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_5)
  796. end
  797. local heroList = playerList[playerUuid].heroList
  798. if not heroList then
  799. return errTips(msg.sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_4)
  800. end
  801. local occupyPointArrMsg = msgData.occupyPointArr
  802. for cityId, pointList in pairs(heroList) do
  803. for pointIdx, heroInfoArr in pairs(pointList) do
  804. occupyPointArrMsg[#occupyPointArrMsg+1] = {
  805. cityId = cityId,
  806. pointIdx = pointIdx,
  807. power = calcHerosPower(heroInfoArr),
  808. heroArr = {},
  809. }
  810. local TargetHeroArr = occupyPointArrMsg[#occupyPointArrMsg].heroArr
  811. for _, heroInfo in ipairs(heroInfoArr) do
  812. TargetHeroArr[#TargetHeroArr+1] = {
  813. heroBody = heroInfo.heroBody,
  814. heroStar = heroInfo.heroStar,
  815. heroLv = heroInfo.heroLevel,
  816. heroCamp = heroInfo.heroCamp,
  817. heroIcon = heroInfo.heroIcon,
  818. }
  819. end
  820. end
  821. end
  822. InnerMsg.sendMsg(fd, msgData)
  823. end
  824. -- 查询公会排行榜
  825. function N2C_UnionRank_Query(msg)
  826. local myUnionId = msg.myUnionId
  827. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  828. if not groupId then
  829. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  830. end
  831. local unionRankList = AnotherWorldBattleDB.GetUnionRankList(groupId)
  832. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_UNIONRANK_QUERY
  833. msgData.playerUuid = msg.playerUuid
  834. msgData.myUnionRank = 0
  835. msgData.unionRankArr = {}
  836. for rank, randkData in ipairs(unionRankList) do
  837. if rank > AnotherWorldBattleDefine.AB_RANK_MAX_NUM then
  838. break
  839. end
  840. local unionName = AnotherWorldBattleDB.GetUnionName(randkData.unionId)
  841. msgData.unionRankArr[rank] = {
  842. name = unionName,
  843. power = randkData.power,
  844. cityNum = randkData.occupyCityNum,
  845. pointNum = randkData.occupyPointNum,
  846. }
  847. if randkData.unionId == myUnionId then
  848. msgData.myUnionRank = rank
  849. end
  850. end
  851. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  852. InnerMsg.sendMsg(fd, msgData)
  853. end
  854. -- 查询玩家排行榜
  855. function N2C_PlayerRank_Query(msg)
  856. local myUnionId = msg.myUnionId
  857. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  858. if not groupId then
  859. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  860. end
  861. local playerRankList = AnotherWorldBattleDB.GetPlayerRankList(groupId)
  862. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_PLAYERRANK_QUERY
  863. msgData.playerUuid = msg.playerUuid
  864. msgData.myRank = 0
  865. msgData.playerRankArr = {}
  866. for rank, randkData in ipairs(playerRankList) do
  867. if rank > AnotherWorldBattleDefine.AB_RANK_MAX_NUM then
  868. break
  869. end
  870. local playerName = AnotherWorldBattleDB.GetPlayerName(randkData.unionId, randkData.playerUuid)
  871. msgData.unionRankArr[rank] = {
  872. name = playerName,
  873. power = randkData.power,
  874. pointNum = randkData.occupyPointNum,
  875. pointWeight = randkData.pointAllWeight,
  876. }
  877. if randkData.playerUuid == msg.playerUuid then
  878. msgData.myRank = rank
  879. end
  880. end
  881. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  882. InnerMsg.sendMsg(fd, msgData)
  883. end
  884. -- 集结
  885. function N2C_Gather(msg)
  886. local sourceServerId = msg.sourceServerId
  887. local playerUuid = msg.playerUuid
  888. local myUnionId = msg.myUnionId
  889. if not isRunning() then
  890. return errTips(sourceServerId, playerUuid, AnotherWorldBattleDefine.ERR_CODE_1)
  891. end
  892. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  893. if not groupId then
  894. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  895. end
  896. local targetCityId = msg.targetCityId
  897. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  898. if not myUnionData then
  899. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  900. end
  901. local now = os.time()
  902. if myUnionData.gatherInfo then
  903. local gatherTime = myUnionData.gatherInfo.gatherTime
  904. if now - gatherTime < AnotherWorldBattleDefine.AB_GATHER_CD_SEC then
  905. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_6)
  906. end
  907. end
  908. local occupCityyArr = getUnionOccupyArr(myUnionId)
  909. if not isadJoin(occupCityyArr, targetCityId) then
  910. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_7)
  911. end
  912. myUnionData.gatherInfo = myUnionData.gatherInfo or {}
  913. myUnionData.gatherInfo.gatherTime = now
  914. myUnionData.gatherInfo.gatherCity = targetCityId
  915. AnotherWorldBattleDB.UpdateUnionData(myUnionId, myUnionData)
  916. N2C_CityDetailed_Query(msg)
  917. end
  918. -- 查询据点是否可以被挑战
  919. function N2C_Try_Challengde_Point(msg)
  920. local playerUuid = msg.playerUuid
  921. local myUnionId = msg.myUnionId
  922. local targetCityId = msg.targetCityId
  923. local targetPointIdx = msg.targetPointIdx
  924. local isCanChallenge = isCanChallengePoint(targetCityId, msg.targetPointIdx, msg.myUnionId, playerUuid)
  925. if not isCanChallenge then
  926. return
  927. end
  928. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  929. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  930. local targetPointData = cityList[targetCityId].pointArr[targetPointIdx]
  931. local pointOccupyInfo = {targetCityId = targetCityId, targetPointIdx = targetPointIdx}
  932. if targetPointData.unionId then
  933. local occupyUnionData = AnotherWorldBattleDB.GetUnionData(targetPointData.unionId)
  934. pointOccupyInfo.occupySrvId = occupyUnionData.serverId
  935. pointOccupyInfo.occupyPlayerUuid = targetPointData.playerUuid
  936. end
  937. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  938. if myUnionData.gatherInfo and myUnionData.gatherInfo.gatherCity == targetCityId then
  939. pointOccupyInfo.isGather = 1
  940. end
  941. local msgData = InnerMsg.wl.WL_ANOTHERWORLDBATTLE_POINT_ISCAN_CHALLENGE
  942. msgData.playerUuid = playerUuid
  943. msgData.targetCityId = targetCityId
  944. msgData.targetPointIdx = targetPointIdx
  945. msgData.pointInfo = pointOccupyInfo
  946. local fd = MiddleManager.getFDBySvrIndex(msg.sourceServerId)
  947. InnerMsg.sendMsg(fd, msgData)
  948. end
  949. -- 玩家挑战据点胜利
  950. function N2C_Point_Challenge_Win(msg)
  951. local playerUuid = msg.playerUuid
  952. local myUnionId = msg.myUnionId
  953. local targetCityId = msg.targetCityId
  954. local targetPointIdx = msg.targetPointIdx
  955. local playerShowInfo = msg.playerShowInfo
  956. if not isRunning() then
  957. return
  958. end
  959. local groupId = AnotherWorldBattleDB.GetUnionGroupId(myUnionId)
  960. if not groupId then
  961. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  962. end
  963. local myUnionData = AnotherWorldBattleDB.GetUnionData(myUnionId)
  964. if not myUnionData then
  965. return errTips(msg.sourceServerId, msg.playerUuid, AnotherWorldBattleDefine.ERR_CODE_3)
  966. end
  967. local cityList = AnotherWorldBattleDB.GetCityListByGroupId(groupId)
  968. local cityData = cityList[targetCityId]
  969. local pointData = cityData.pointArr[targetPointIdx]
  970. local unionRankList = AnotherWorldBattleDB.GetUnionRankList(groupId)
  971. local playerRankList = AnotherWorldBattleDB.GetPlayerRankList(groupId)
  972. local pointWeight = AnotherWorldBattleConfig.city[targetCityId].pointWeight
  973. --防守方是真实玩家
  974. if pointData.unionId and pointData.playerUuid then
  975. -- 更新防守方公会数据
  976. local defUnionData = AnotherWorldBattleDB.GetUnionData(pointData.unionId)
  977. local defOccupCityList = defUnionData.occupCityList
  978. local cityNum, pointNum = 0, -1
  979. -- 防守方之前占领了城池
  980. if defOccupCityList[targetCityId].isOccupy then
  981. -- 修改防守方的占领状态
  982. defOccupCityList[targetCityId].isOccupy = false
  983. -- 更新防守方的最后占领时间
  984. local defOccupyTimeArr = defOccupCityList[targetCityId].occupyTimeArr
  985. defOccupyTimeArr[#defOccupyTimeArr][2] = os.time()
  986. -- 更新防守方的该据点的占领者数据
  987. local defOccupyPointList = defOccupCityList[targetCityId].occupyPointList
  988. defOccupyPointList[targetCityId] = nil
  989. -- 删除防守方玩家的防守阵容数据
  990. local defPlayData = defUnionData.playerList[pointData.playerUuid]
  991. defPlayData.heroList[targetCityId][targetPointIdx] = nil
  992. cityNum = -1
  993. end
  994. -- 更新排行榜数据
  995. updateUnionRanktData(unionRankList, pointData.unionId, cityNum, pointNum)
  996. updatePlayerRanktData(playerRankList, pointData.playerUuid, pointNum, -pointWeight)
  997. -- 通知玩家
  998. pointLose(defUnionData.serverId, pointData.playerUuid, targetCityId, targetPointIdx)
  999. -- 更新防守方公会数据
  1000. AnotherWorldBattleDB.UpdateUnionData(pointData.unionId, defUnionData)
  1001. end
  1002. -- 更新据点占领数据
  1003. pointData.unionId = myUnionId
  1004. pointData.playerUuid = playerUuid
  1005. -- 更新进攻方公会数据——据点占有者
  1006. myUnionData.occupCityList = myUnionData.occupCityList or {}
  1007. local occupCityList = myUnionData.occupCityList
  1008. occupCityList[targetCityId] = occupCityList[targetCityId] or {}
  1009. occupCityList[targetCityId].occupyPointList = occupCityList[targetCityId].occupyPointList or {}
  1010. occupCityList[targetCityId].occupyPointList[targetPointIdx] = playerUuid
  1011. --更新进攻者的展示数据
  1012. myUnionData.playerList = myUnionData.playerList or {}
  1013. myUnionData.playerList[playerUuid] = myUnionData.playerList[playerUuid] or {}
  1014. local playerData = myUnionData.playerList[playerUuid]
  1015. playerData.name = playerShowInfo.name
  1016. playerData.lv = playerShowInfo.lv
  1017. playerData.head = playerShowInfo.head
  1018. playerData.headFrame = playerShowInfo.headFrame
  1019. playerData.power = playerShowInfo.power
  1020. playerData.heroList = playerData.heroList or {}
  1021. playerData.heroList[targetCityId] = playerData.heroList[targetCityId] or {}
  1022. playerData.heroList[targetCityId][targetPointIdx] = playerShowInfo.heroArr
  1023. -- 更新公会排行榜数据: 进攻方公会占领据点数量+1
  1024. updateUnionRanktData(unionRankList, myUnionId, 0, 1)
  1025. local bl = getPlayerRank(playerRankList, playerUuid)
  1026. if not bl then -- 如果玩家是第一次挑战据点, 则把玩家加入到玩家排行榜中
  1027. playerRankList[#playerRankList+1] = {
  1028. unionId = myUnionId,
  1029. playerUuid = playerUuid,
  1030. pointNum = 1,
  1031. pointAllWeight = pointWeight,
  1032. power = playerData.power
  1033. }
  1034. else
  1035. updatePlayerRanktData(playerRankList, playerUuid, 1, pointWeight)
  1036. end
  1037. -- 进攻方完全占领城池了
  1038. if isCompleteOccupy(cityData, myUnionId) then
  1039. -- 更新城池的占领公会
  1040. cityData.occupyUnion = myUnionId
  1041. -- 更新进攻方公会对该城池的占领状态
  1042. occupCityList[targetCityId].isOccupy = true
  1043. -- 增加进攻方公会对该城池的占领开始时间戳
  1044. local now = os.time()
  1045. occupCityList[targetCityId].occupyTimeArr = occupCityList[targetCityId].occupyTimeArr or {}
  1046. local occupyTimeArr = occupCityList[targetCityId].occupyTimeArr
  1047. occupyTimeArr[#occupyTimeArr+1] = { now }
  1048. -- 更新公会排行榜数据
  1049. updateUnionRanktData(unionRankList, myUnionId, 1, 0)
  1050. end
  1051. -- 更新进攻方公会数据
  1052. AnotherWorldBattleDB.UpdateUnionData(myUnionId, myUnionData)
  1053. -- 更新城池数据
  1054. AnotherWorldBattleDB.UpdateCityList(groupId, cityList)
  1055. -- 更新公会/个人排行榜
  1056. AnotherWorldBattleDB.UpdateUnionRankList(groupId, unionRankList)
  1057. AnotherWorldBattleDB.UpdatePlayerRankList(groupId, playerRankList)
  1058. end