AnotherWorldBattleDB.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. -- 异界之战(DB)
  2. local LuaMongo = _G.lua_mongo
  3. local DB = require("common.DB")
  4. local AnotherWorldBattleDefine = require("anotherWorldBattle.AnotherWorldBattleDefine")
  5. local AnotherWorldBattleConfig = require("excel.anotherWorldBattle")
  6. local dbUpdate = {_id=nil}
  7. local dbUpdateField = {}
  8. -- db
  9. AnotherWorldBattleData = {
  10. -- lastRoundStartTime = 0, -- 上一轮活动开启时间
  11. -- stage = 1, -- 当前阶段
  12. -- joinUnionArr = {
  13. -- { unionId = "", serverId = 123, power = 9999},
  14. -- },
  15. -- groupArray = {
  16. -- [1] = {unionId1, unionId2, unionId3, unionId4, unionId5, unionId6, unionId7, unionId8},
  17. -- [2] = {unionId9, unionId10,...},
  18. -- },
  19. -- unionList = {
  20. -- [unionId1] = {
  21. -- serverId = 123, -- 公会所在服务器Id
  22. -- power = 9999,
  23. -- name = "111",
  24. -- baseCityId = 123, -- 出生城池
  25. -- baseCityStartTime = nil, -- 出生城的开始占领时间
  26. -- occupCityList = { -- 城池列表(包括曾占领过, 当前成功占领, 当前只占领过一个或多个据点)
  27. -- [cityId1] = {
  28. -- isOccupy = false, --当前是否占领
  29. -- occupyPointList = { --占领本城池中的据点列表
  30. -- [pointId1] = { playerUuid = "", occupyTimeArr = { {startTime1, endTime1}, {startTime2, endTime2}}, },
  31. -- },
  32. -- },
  33. -- },
  34. -- gatherInfo = { --集结信息
  35. -- gatherTime = 0,
  36. -- gatherCity = 123,
  37. -- },
  38. -- },
  39. -- },
  40. -- playerList = {
  41. -- [playerUuid] = {
  42. -- name = "",
  43. -- lv = 200,
  44. -- head = 1234,
  45. -- headFrame = 1234,
  46. -- power = 999,
  47. -- challengeTimes = 10,
  48. -- lastTime = nil, -- 上一次更新的时间戳
  49. -- unionId = "",
  50. -- heroList = {
  51. -- [cityId] = {
  52. -- [pointIdx] = {
  53. -- {
  54. -- heroUuid = "sdgjdjdj",
  55. -- heroStar = 111,
  56. -- heroLevel = 111,
  57. -- heroCamp = 1,
  58. -- heroBody = 111,
  59. -- heroIcon = 111,
  60. -- heroPower = 11111,
  61. -- heroId = 111,
  62. -- heroQuality = 1,
  63. -- },
  64. -- },
  65. -- },
  66. -- }
  67. -- },
  68. -- }
  69. }
  70. -- 所有分组的城池信息, 启动服务器后生成, 用于快速获取城池信息
  71. Group_2_CityList = {
  72. -- [groupId] = {
  73. -- [cityId] = {
  74. -- occupyUnion = { -- 占领公会信息, 没有公会占领时为nil
  75. -- serverId = 124,
  76. -- unionId = "123",
  77. -- },
  78. -- pointArr = { -- 城池中所有据点信息, 没人占领时, unionId, playerUuid为nil
  79. -- {unionId = nil, playerUuid = nil, },
  80. -- {unionId = nil, playerUuid = nil, },
  81. -- }
  82. -- },
  83. -- },
  84. }
  85. -- 所有分组的公会排行榜, 启动服务器后生成
  86. Group_2_UnionRankList = {}
  87. -- 所有分组的玩家排行榜, 启动服务器后生成
  88. Group_2_PlayerRankList = {}
  89. -- 区服Id - 公会列表 映射表
  90. Server_2_UnionArr = {
  91. -- [serverId] = {unionId1, unionId2},
  92. }
  93. -- 公会 - 所属分组 映射表
  94. Union_2_Group = {
  95. -- [unionId] = groupId,
  96. }
  97. local function initData()
  98. AnotherWorldBattleData.lastRoundStartTime = 0
  99. AnotherWorldBattleData.stage = AnotherWorldBattleDefine.AB_STATE_END
  100. LuaMongo.insert(DB.db_anotherWorldBattle, AnotherWorldBattleData)
  101. end
  102. local function loadData()
  103. LuaMongo.find(DB.db_anotherWorldBattle)
  104. local data = {}
  105. if LuaMongo.next(data) then
  106. AnotherWorldBattleData = data
  107. else
  108. initData()
  109. end
  110. end
  111. -- 修改db单个字段
  112. local function updateValue(key, value)
  113. if not key then return end
  114. if value then
  115. dbUpdateField["$set"] = {[key]=value}
  116. dbUpdateField["$unset"] = nil
  117. else
  118. dbUpdateField["$set"] = nil
  119. dbUpdateField["$unset"] = {[key]=1}
  120. end
  121. dbUpdate._id = AnotherWorldBattleData._id
  122. LuaMongo.update(DB.db_anotherWorldBattle, dbUpdate, dbUpdateField)
  123. end
  124. -- 生成城池数据
  125. local function genCityList(net, unionIdArr)
  126. local function getUnionByCityId(targetCityId)
  127. for _, unionId in ipairs(unionIdArr) do
  128. local unionInfo = AnotherWorldBattleData.unionList[unionId]
  129. -- 其他城池
  130. if unionInfo and unionInfo.occupCityList then
  131. for occupyCityId, occupyCityinfo in pairs(unionInfo.occupCityList) do
  132. if occupyCityId == targetCityId and occupyCityinfo.isOccupy then
  133. return unionId
  134. end
  135. end
  136. end
  137. -- 出生城池
  138. if unionInfo and unionInfo.baseCityId == targetCityId then
  139. return unionId
  140. end
  141. end
  142. return nil
  143. end
  144. local function getPointOccupyPlayer(targetCityId, targetPointIdx)
  145. for _, unionId in ipairs(unionIdArr) do
  146. local unionInfo = AnotherWorldBattleData.unionList[unionId]
  147. if unionInfo and unionInfo.occupCityList and unionInfo.occupCityList[targetCityId] then
  148. local pointList = unionInfo.occupCityList[targetCityId].occupyPointList
  149. if pointList and pointList[targetPointIdx] and pointList[targetPointIdx].playerUuid then
  150. return unionId, pointList[targetPointIdx].playerUuid
  151. end
  152. end
  153. end
  154. return nil, nil
  155. end
  156. for cityId, cityCfg in ipairs(AnotherWorldBattleConfig.city) do
  157. local cityEntry = { pointArr = {} }
  158. net[cityId] = cityEntry
  159. local unionId = getUnionByCityId(cityId)
  160. if unionId then
  161. cityEntry.occupyUnion = unionId
  162. end
  163. local pointArr = cityEntry.pointArr
  164. for i=1, AnotherWorldBattleDefine.AB_POINT_MAX_NUM do
  165. local unionId1, playerUuid = getPointOccupyPlayer(cityId, i)
  166. if unionId1 and playerUuid then
  167. pointArr[i] = {
  168. unionId = unionId1,
  169. playerUuid = playerUuid
  170. }
  171. else
  172. pointArr[i] = {}
  173. end
  174. end
  175. end
  176. end
  177. -- 工会排行榜
  178. -- 目前最多8条
  179. local function createGuildRank()
  180. local guilds = {} -- id -> guildRec(永久表,不删)
  181. local rank = {} -- 1..#guilds 复用数组
  182. local dirty = true -- 脏标记:true表示rank需要重新计算
  183. local function cmp(a, b)
  184. if a.occupyCityNum ~= b.occupyCityNum then
  185. return a.occupyCityNum > b.occupyCityNum
  186. end
  187. if a.occupyPointNum ~= b.occupyPointNum then
  188. return a.occupyPointNum > b.occupyPointNum
  189. end
  190. return a.power > b.power
  191. end
  192. local function updateGuild(id, name, occupyCityNum, occupyPointNum, power)
  193. local g = guilds[id]
  194. if not g then
  195. g = { id = id, name = name or "",
  196. occupyCityNum = occupyCityNum or 0,
  197. occupyPointNum = occupyPointNum or 0,
  198. power = power or 0 }
  199. guilds[id] = g
  200. else
  201. -- 原地更新,保持table引用
  202. g.occupyCityNum = occupyCityNum or g.occupyCityNum
  203. g.occupyPointNum = occupyPointNum or g.occupyPointNum
  204. g.power = power or g.power
  205. if name then g.name = name end
  206. end
  207. -- 标记rank缓存失效(数据量小,但统一设计模式)
  208. dirty = true
  209. end
  210. -- 内部函数:按需重新排序
  211. local function sortIfNeeded()
  212. if not dirty then return end
  213. -- 全量收集到rank(复用数组)
  214. local n = 0
  215. for _, v in pairs(guilds) do
  216. n = n + 1
  217. rank[n] = v
  218. end
  219. -- 排序
  220. if n > 1 then
  221. table.sort(rank, cmp)
  222. end
  223. -- 清除尾部残留数据
  224. for i = n + 1, #rank do
  225. rank[i] = nil
  226. end
  227. dirty = false
  228. end
  229. local function getRankList()
  230. -- 确保排行已更新
  231. sortIfNeeded()
  232. -- 构建返回列表
  233. local ret = {}
  234. for i = 1, #rank do
  235. local g = rank[i]
  236. ret[i] = {
  237. rank = i, guildId = g.id, name = g.name,
  238. occupyCityNum = g.occupyCityNum,
  239. occupyPointNum = g.occupyPointNum,
  240. power = g.power
  241. }
  242. end
  243. return ret
  244. end
  245. local function getGuildDetail(id)
  246. return guilds[id]
  247. end
  248. return {
  249. updateGuild = updateGuild,
  250. getRankList = getRankList,
  251. getGuildDetail = getGuildDetail
  252. }
  253. end
  254. -- 玩家排行榜
  255. -- 当前每个公会最多25人,8个公会为一组,最多200人
  256. local function createPlayerRank()
  257. local players = {} -- id -> rec(永久存在,不删)
  258. local rank = {} -- 已排序的前RANK_MAX名,复用
  259. local tmp = {} -- 临时排序数组,预分配
  260. local dirty = true -- 脏标记:true表示rank需要重新计算
  261. local function cmp(a, b)
  262. if a.pointNum ~= b.pointNum then return a.pointNum > b.pointNum end
  263. if a.pointAllWeight ~= b.pointAllWeight then return a.pointAllWeight > b.pointAllWeight end
  264. return a.power > b.power
  265. end
  266. -- 预分配tmp容量,避免运行时动态扩容
  267. for i = 1, 500 do tmp[i] = nil end
  268. local function updatePlayer(id, name, power, pNum, pWeight)
  269. -- 更新或创建玩家记录
  270. local rec = players[id]
  271. if not rec then
  272. rec = { id = id, name = name or "", power = power,
  273. pointNum = pNum or 0, pointAllWeight = pWeight or 0 }
  274. players[id] = rec
  275. else
  276. -- 原地更新,保持table引用不变
  277. rec.power = power
  278. if pNum ~= nil then rec.pointNum = pNum end
  279. if pWeight ~= nil then rec.pointAllWeight = pWeight end
  280. if name then rec.name = name end
  281. end
  282. -- 标记rank缓存失效
  283. dirty = true
  284. end
  285. -- 内部函数:按需重新排序
  286. local function sortIfNeeded()
  287. if not dirty then return end
  288. -- 收集所有玩家记录到tmp(仅复制引用)
  289. local n = 0
  290. for _, v in pairs(players) do
  291. n = n + 1
  292. tmp[n] = v
  293. end
  294. -- 排序
  295. if n > 1 then
  296. table.sort(tmp, cmp)
  297. end
  298. -- 将前RANK_MAX名复制到rank(复用数组)
  299. local rankMax = AnotherWorldBattleDefine.AB_RANK_MAX_NUM
  300. local oldRankLen = #rank
  301. for i = 1, rankMax do
  302. rank[i] = tmp[i] -- 若i>n,则赋值为nil,自动缩小rank长度
  303. end
  304. -- 清除rank数组尾部残留的旧数据
  305. for i = rankMax + 1, oldRankLen do
  306. rank[i] = nil
  307. end
  308. dirty = false
  309. end
  310. local function getRankList()
  311. -- 确保排行已更新
  312. sortIfNeeded()
  313. -- 构建返回列表
  314. local ret = {}
  315. for i = 1, #rank do
  316. local p = rank[i]
  317. ret[i] = { rank = i, playerId = p.id, name = p.name, power = p.power,
  318. pointNum = p.pointNum, pointAllWeight = p.pointAllWeight }
  319. end
  320. return ret
  321. end
  322. local function getPlayerDetail(id)
  323. return players[id]
  324. end
  325. return {
  326. updatePlayer = updatePlayer,
  327. getRankList = getRankList,
  328. getPlayerDetail = getPlayerDetail,
  329. }
  330. end
  331. -- 生成公会排行榜
  332. local function genGroupUnionRankList(unionRank, unionIdArr)
  333. local function getUnionRankVal(union)
  334. local occupyCityNum, occupyPointNum, power = 0, 0, 0
  335. power = union.power or 0
  336. for _, v in pairs(union.occupCityList or {}) do
  337. if v.isOccupy then
  338. occupyCityNum = occupyCityNum + 1
  339. end
  340. for _, _ in pairs(v.occupyPointList or {}) do
  341. occupyPointNum = occupyPointNum + 1
  342. end
  343. end
  344. return occupyCityNum, occupyPointNum, power
  345. end
  346. for _, unionId in ipairs(unionIdArr) do
  347. local unionData = AnotherWorldBattleData.unionList[unionId]
  348. if unionData then
  349. local occupyCityNum, occupyPointNum, power = getUnionRankVal(unionData)
  350. unionRank.updateGuild(unionId, unionData.name, occupyCityNum, occupyPointNum, power)
  351. end
  352. end
  353. end
  354. -- 生成个人排行榜
  355. local function genGroupPlayerRankList(playerRank, unionIdArr, playerListData)
  356. local function insertPlayerRank(unionId)
  357. if not playerListData then
  358. return
  359. end
  360. for playerUuid, playerInfo in pairs(playerListData) do
  361. if playerInfo.unionId == unionId then
  362. local pointNum, pointAllWeight = 0, 0
  363. for cityId, pointList in pairs(playerInfo.heroList or {}) do
  364. for _, _ in pairs(pointList) do
  365. pointNum = pointNum + 1
  366. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  367. pointAllWeight = pointAllWeight + (cityCfg and cityCfg.pointWeight or 0)
  368. end
  369. end
  370. playerRank.updatePlayer(playerUuid, playerInfo.name, playerInfo.power, pointNum, pointAllWeight)
  371. end
  372. end
  373. end
  374. for _, unionId in ipairs(unionIdArr) do
  375. insertPlayerRank(unionId)
  376. end
  377. end
  378. -- 生成 "公会-公会所属分组Id" 映射表
  379. local function genUnion2GroupList(groupId, unionIdArr)
  380. for _, unionId in ipairs(unionIdArr) do
  381. Union_2_Group[unionId] = groupId
  382. end
  383. end
  384. -- 生成 "serverId - 公会Array" 映射表
  385. local function genServer2UnionArr(unionRank)
  386. local rankList = unionRank.getRankList()
  387. for _, rankInfo in ipairs(rankList) do
  388. local unionId = rankInfo.guildId
  389. local unionInfo = AnotherWorldBattleData.unionList[unionId]
  390. if unionInfo then
  391. local serverId = unionInfo.serverId
  392. Server_2_UnionArr[serverId] = Server_2_UnionArr[serverId] or {}
  393. Server_2_UnionArr[serverId][#Server_2_UnionArr[serverId]+1] = unionId
  394. end
  395. end
  396. end
  397. -- 生成各组的缓存数据
  398. local function genGroupCache()
  399. if not AnotherWorldBattleData.groupArray then
  400. return
  401. end
  402. local playerListData = AnotherWorldBattleData.playerList
  403. for groupId, unionIdArr in ipairs(AnotherWorldBattleData.groupArray) do
  404. -- 城池
  405. Group_2_CityList[groupId] = {}
  406. genCityList(Group_2_CityList[groupId], unionIdArr)
  407. -- 公会排行榜
  408. Group_2_UnionRankList[groupId] = createGuildRank()
  409. genGroupUnionRankList(Group_2_UnionRankList[groupId], unionIdArr)
  410. -- "serverId -- unionIdArray" 映射表
  411. genServer2UnionArr(Group_2_UnionRankList[groupId])
  412. -- 个人排行榜
  413. Group_2_PlayerRankList[groupId] = createPlayerRank()
  414. genGroupPlayerRankList(Group_2_PlayerRankList[groupId], unionIdArr, playerListData)
  415. -- "公会-公会所属分组" 映射表
  416. genUnion2GroupList(groupId, unionIdArr)
  417. end
  418. end
  419. function initAfterStart()
  420. if _G.is_middle ~= true then return end
  421. loadData()
  422. genGroupCache()
  423. end
  424. -- 重置数据
  425. function ResetData()
  426. Group_2_CityList = {}
  427. Group_2_UnionRankList = {}
  428. Group_2_PlayerRankList = {}
  429. Union_2_Group = {}
  430. Server_2_UnionArr = {}
  431. AnotherWorldBattleData.lastRoundStartTime = os.time()
  432. -- AnotherWorldBattleData.stage = AnotherWorldBattleDefine.AB_STATE_JOIN
  433. AnotherWorldBattleData.joinUnionArr = nil
  434. AnotherWorldBattleData.groupArray = nil
  435. AnotherWorldBattleData.unionList = nil
  436. AnotherWorldBattleData.playerList = nil
  437. dbUpdate._id = AnotherWorldBattleData._id
  438. LuaMongo.update(DB.db_anotherWorldBattle, dbUpdate, AnotherWorldBattleData)
  439. end
  440. -- 获取公会所在分组的Id
  441. function GetUnionGroupId(unionId)
  442. return Union_2_Group[unionId]
  443. end
  444. -- 当自己公会没有参赛时, 获取本服第一个公会所在分组Id
  445. function GetGroupIdByServerId(serverId)
  446. local unionArr = Server_2_UnionArr[serverId]
  447. if unionArr and unionArr[1] then
  448. local unionId = unionArr[1]
  449. return GetUnionGroupId(unionId)
  450. end
  451. end
  452. -- 获取活动当前阶段
  453. function GetStage()
  454. return AnotherWorldBattleData.stage
  455. end
  456. -- 更新活动当前阶段
  457. function UpdateStage(newStage)
  458. AnotherWorldBattleData.stage = newStage
  459. updateValue("stage", newStage)
  460. if newStage == AnotherWorldBattleDefine.AB_STATE_BATTLE then
  461. genGroupCache()
  462. end
  463. end
  464. -- 获取活动上一轮的开始时间
  465. function GetLastRoundStartTime()
  466. return AnotherWorldBattleData.lastRoundStartTime
  467. end
  468. function UpdateLastRoundStartTime(newTime)
  469. AnotherWorldBattleData.lastRoundStartTime = newTime
  470. updateValue("lastRoundStartTime", newTime)
  471. end
  472. -- 获取参赛公会列表
  473. function GetJoinUnionArr()
  474. return AnotherWorldBattleData.joinUnionArr
  475. end
  476. -- 更新参赛公会列表
  477. function UpdateJoinUnionArr(newJoinUnionArr)
  478. AnotherWorldBattleData.joinUnionArr = newJoinUnionArr
  479. updateValue("joinUnionArr", newJoinUnionArr)
  480. end
  481. -- 获取分组列表
  482. function GetGroupArray()
  483. return AnotherWorldBattleData.groupArray
  484. end
  485. -- 更新分组列表
  486. function UpdateGroupArray(newGroupArray)
  487. AnotherWorldBattleData.groupArray = newGroupArray
  488. updateValue("groupArray", newGroupArray)
  489. end
  490. -- 获取公会名字
  491. function GetUnionName(unionId)
  492. return AnotherWorldBattleData.unionList and AnotherWorldBattleData.unionList[unionId].name or ""
  493. end
  494. -- 获取某个公会数据
  495. function GetUnionData(unionId)
  496. return AnotherWorldBattleData.unionList and AnotherWorldBattleData.unionList[unionId]
  497. end
  498. -- 更新某个公会数据
  499. function UpdateUnionData(unionId, newUnionData)
  500. if not AnotherWorldBattleData.unionList then
  501. AnotherWorldBattleData.unionList = {}
  502. -- updateValue("unionList", AnotherWorldBattleData.unionList)
  503. end
  504. AnotherWorldBattleData.unionList[unionId] = newUnionData
  505. updateValue("unionList"..".".. unionId, newUnionData)
  506. end
  507. -- 获取公会列表
  508. function GetUnionList()
  509. return AnotherWorldBattleData.unionList
  510. end
  511. -- 获取玩家名字
  512. function GetPlayerName(playerUuid)
  513. local playerListData = AnotherWorldBattleData.playerList
  514. if playerListData and playerListData[playerUuid] then
  515. return playerListData[playerUuid].name or ""
  516. end
  517. return ""
  518. end
  519. -- 获取玩家数据
  520. function GetPlayerData(playerUuid)
  521. return AnotherWorldBattleData.playerList and AnotherWorldBattleData.playerList[playerUuid]
  522. end
  523. -- 更新玩家数据
  524. function UpdatePlayerData(playerUuid, newPlayerData)
  525. if not AnotherWorldBattleData.playerList then
  526. AnotherWorldBattleData.playerList = {}
  527. -- updateValue("playerList", AnotherWorldBattleData.playerList)
  528. end
  529. AnotherWorldBattleData.playerList[playerUuid] = newPlayerData
  530. updateValue("playerList".. "." .. playerUuid, newPlayerData)
  531. end
  532. -- 获取公会列表
  533. function GetPlayerList()
  534. return AnotherWorldBattleData.playerList
  535. end
  536. -- 获取城池数据
  537. function GetCityData(groupId, cityId)
  538. if Group_2_CityList[groupId] then
  539. return Group_2_CityList[groupId][cityId]
  540. end
  541. end
  542. -- 更新城池数据
  543. function UpdateCityData(groupId, cityId, newCityData)
  544. if Group_2_CityList[groupId] then
  545. Group_2_CityList[groupId][cityId] = newCityData
  546. end
  547. end
  548. -- 获取所有城池数据
  549. function GetCityListByGroupId(groupId)
  550. return Group_2_CityList[groupId]
  551. end
  552. -- 更新所有城池数据
  553. function UpdateCityList(groupId, newCityList)
  554. Group_2_CityList[groupId] = newCityList
  555. end
  556. -- 获取公会排行数据
  557. function GetUnionRankList(groupId)
  558. local unionRank = Group_2_UnionRankList[groupId]
  559. if unionRank then
  560. return unionRank.getRankList()
  561. end
  562. end
  563. -- 更新公会的排行榜数据, cityVal, pointVal为变化的值
  564. function UpdateUnionRankList(groupId, unionId, cityVal, pointVal, newPower)
  565. local unionRank = Group_2_UnionRankList[groupId]
  566. if unionRank then
  567. local unionRankInfo = unionRank.getGuildDetail(unionId)
  568. unionRankInfo.occupyCityNum = unionRankInfo.occupyCityNum + cityVal
  569. unionRankInfo.occupyPointNum = unionRankInfo.occupyPointNum + pointVal
  570. if newPower then
  571. unionRankInfo.power = newPower
  572. end
  573. unionRank.updateGuild(unionId, unionRankInfo.name, unionRankInfo.occupyCityNum, unionRankInfo.occupyPointNum, unionRankInfo.power)
  574. end
  575. end
  576. -- 生成玩家用于排名的数据
  577. local function genPlayerRankVal(playerUuid)
  578. local playerListData = AnotherWorldBattleData.playerList
  579. local name, power, pointNum, pointAllWeight = "", 0, 0, 0
  580. if playerListData and playerListData[playerUuid] then
  581. power = playerListData[playerUuid].power or 0
  582. name = playerListData[playerUuid].name or ""
  583. for cityId, pointList in pairs(playerListData[playerUuid].heroList or {}) do
  584. for _, _ in pairs(pointList) do
  585. pointNum = pointNum + 1
  586. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  587. pointAllWeight = pointAllWeight + (cityCfg and cityCfg.pointWeight or 0)
  588. end
  589. end
  590. end
  591. return name, power, pointNum, pointAllWeight
  592. end
  593. -- 获取玩家排行数据
  594. function GetPlayerRankList(groupId)
  595. local playerRank = Group_2_PlayerRankList[groupId]
  596. if playerRank then
  597. return playerRank.getRankList()
  598. end
  599. end
  600. -- 更新玩家排行数据, pointVal, pointWeightVal为变化的值
  601. function UpdatePlayerRankList(groupId, playerUuid, pointVal, pointWeightVal, newPower)
  602. local playerRank = Group_2_PlayerRankList[groupId]
  603. if playerRank then
  604. local playerRankData = playerRank.getPlayerDetail(playerUuid)
  605. if not playerRankData then
  606. playerRankData = {}
  607. local name, power, pointNum, pointAllWeight = genPlayerRankVal(playerUuid)
  608. playerRankData.name = name
  609. playerRankData.power = power
  610. playerRankData.pointNum = pointNum
  611. playerRankData.pointAllWeight = pointAllWeight
  612. else
  613. playerRankData.pointNum = playerRankData.pointNum + pointVal
  614. playerRankData.pointAllWeight = playerRankData.pointAllWeight + pointWeightVal
  615. if newPower then
  616. playerRankData.power = newPower
  617. end
  618. end
  619. playerRank.updatePlayer(playerUuid, playerRankData.name, playerRankData.power, playerRankData.pointNum, playerRankData.pointAllWeight)
  620. end
  621. end