AnotherWorldBattleDB.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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. local rankMax = AnotherWorldBattleDefine.AB_RANK_MAX_NUM
  225. for i = rankMax + 1, #rank do
  226. rank[i] = nil
  227. end
  228. dirty = false
  229. end
  230. local function getRankList()
  231. -- 确保排行已更新
  232. sortIfNeeded()
  233. -- 构建返回列表
  234. local ret = {}
  235. for i = 1, #rank do
  236. local g = rank[i]
  237. ret[i] = {
  238. rank = i, guildId = g.id, name = g.name,
  239. occupyCityNum = g.occupyCityNum,
  240. occupyPointNum = g.occupyPointNum,
  241. power = g.power
  242. }
  243. end
  244. return ret
  245. end
  246. local function getGuildDetail(id)
  247. return guilds[id]
  248. end
  249. return {
  250. updateGuild = updateGuild,
  251. getRankList = getRankList,
  252. getGuildDetail = getGuildDetail
  253. }
  254. end
  255. -- 玩家排行榜
  256. -- 当前每个公会最多25人,8个公会为一组,最多200人
  257. local function createPlayerRank()
  258. local players = {} -- id -> rec(永久存在,不删)
  259. local rank = {} -- 已排序的前RANK_MAX名,复用
  260. local tmp = {} -- 临时排序数组,预分配
  261. local dirty = true -- 脏标记:true表示rank需要重新计算
  262. local function cmp(a, b)
  263. if a.pointNum ~= b.pointNum then return a.pointNum > b.pointNum end
  264. if a.pointAllWeight ~= b.pointAllWeight then return a.pointAllWeight > b.pointAllWeight end
  265. return a.power > b.power
  266. end
  267. -- 预分配tmp容量,避免运行时动态扩容
  268. for i = 1, 500 do tmp[i] = nil end
  269. local function updatePlayer(id, name, power, pNum, pWeight)
  270. -- 更新或创建玩家记录
  271. local rec = players[id]
  272. if not rec then
  273. rec = { id = id, name = name or "", power = power or 0,
  274. pointNum = pNum or 0, pointAllWeight = pWeight or 0 }
  275. players[id] = rec
  276. else
  277. -- 原地更新,保持table引用不变
  278. rec.power = power
  279. if pNum ~= nil then rec.pointNum = pNum end
  280. if pWeight ~= nil then rec.pointAllWeight = pWeight end
  281. if name then rec.name = name end
  282. end
  283. -- 标记rank缓存失效
  284. dirty = true
  285. end
  286. -- 内部函数:按需重新排序
  287. local function sortIfNeeded()
  288. if not dirty then return end
  289. -- 收集所有玩家记录到tmp(仅复制引用)
  290. local n = 0
  291. for _, v in pairs(players) do
  292. n = n + 1
  293. tmp[n] = v
  294. end
  295. -- 排序
  296. if n > 1 then
  297. table.sort(tmp, cmp)
  298. end
  299. -- 将前RANK_MAX名复制到rank(复用数组)
  300. local rankMax = AnotherWorldBattleDefine.AB_RANK_MAX_NUM
  301. local oldRankLen = #rank
  302. for i = 1, rankMax do
  303. rank[i] = tmp[i] -- 若i>n,则赋值为nil,自动缩小rank长度
  304. end
  305. -- 清除rank数组尾部残留的旧数据
  306. for i = rankMax + 1, oldRankLen do
  307. rank[i] = nil
  308. end
  309. dirty = false
  310. end
  311. local function getRankList()
  312. -- 确保排行已更新
  313. sortIfNeeded()
  314. -- 构建返回列表
  315. local ret = {}
  316. for i = 1, #rank do
  317. local p = rank[i]
  318. ret[i] = { rank = i, playerId = p.id, name = p.name, power = p.power,
  319. pointNum = p.pointNum, pointAllWeight = p.pointAllWeight }
  320. end
  321. return ret
  322. end
  323. local function getPlayerDetail(id)
  324. return players[id]
  325. end
  326. return {
  327. updatePlayer = updatePlayer,
  328. getRankList = getRankList,
  329. getPlayerDetail = getPlayerDetail,
  330. }
  331. end
  332. -- 生成公会排行榜
  333. local function genGroupUnionRankList(unionRank, unionIdArr)
  334. local function getUnionRankVal(union)
  335. local occupyCityNum, occupyPointNum, power = 0, 0, 0
  336. power = union.power or 0
  337. for _, v in pairs(union.occupCityList or {}) do
  338. if v.isOccupy then
  339. occupyCityNum = occupyCityNum + 1
  340. end
  341. for _, pointInfo in pairs(v.occupyPointList or {}) do
  342. if pointInfo and pointInfo.playerUuid then
  343. occupyPointNum = occupyPointNum + 1
  344. end
  345. end
  346. end
  347. return occupyCityNum, occupyPointNum, power
  348. end
  349. for _, unionId in ipairs(unionIdArr) do
  350. local unionData = AnotherWorldBattleData.unionList[unionId]
  351. if unionData then
  352. local occupyCityNum, occupyPointNum, power = getUnionRankVal(unionData)
  353. unionRank.updateGuild(unionId, unionData.name, occupyCityNum, occupyPointNum, power)
  354. end
  355. end
  356. end
  357. -- 生成个人排行榜
  358. local function genGroupPlayerRankList(playerRank, unionIdArr, playerListData)
  359. local function insertPlayerRank(unionId)
  360. if not playerListData then
  361. return
  362. end
  363. for playerUuid, playerInfo in pairs(playerListData) do
  364. if playerInfo.unionId == unionId then
  365. local pointNum, pointAllWeight = 0, 0
  366. for cityId, pointList in pairs(playerInfo.heroList or {}) do
  367. for _, _ in pairs(pointList) do
  368. pointNum = pointNum + 1
  369. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  370. pointAllWeight = pointAllWeight + (cityCfg and cityCfg.pointWeight or 0)
  371. end
  372. end
  373. playerRank.updatePlayer(playerUuid, playerInfo.name, playerInfo.power, pointNum, pointAllWeight)
  374. end
  375. end
  376. end
  377. for _, unionId in ipairs(unionIdArr) do
  378. insertPlayerRank(unionId)
  379. end
  380. end
  381. -- 生成 "公会-公会所属分组Id" 映射表
  382. local function genUnion2GroupList(groupId, unionIdArr)
  383. for _, unionId in ipairs(unionIdArr) do
  384. Union_2_Group[unionId] = groupId
  385. end
  386. end
  387. -- 生成 "serverId - 公会Array" 映射表
  388. local function genServer2UnionArr(unionRank)
  389. local rankList = unionRank.getRankList()
  390. for _, rankInfo in ipairs(rankList) do
  391. local unionId = rankInfo.guildId
  392. local unionInfo = AnotherWorldBattleData.unionList[unionId]
  393. if unionInfo then
  394. local serverId = unionInfo.serverId
  395. Server_2_UnionArr[serverId] = Server_2_UnionArr[serverId] or {}
  396. Server_2_UnionArr[serverId][#Server_2_UnionArr[serverId]+1] = unionId
  397. end
  398. end
  399. end
  400. -- 生成各组的缓存数据
  401. local function genGroupCache()
  402. if not AnotherWorldBattleData.groupArray then
  403. return
  404. end
  405. local playerListData = AnotherWorldBattleData.playerList
  406. for groupId, unionIdArr in ipairs(AnotherWorldBattleData.groupArray) do
  407. -- 城池
  408. Group_2_CityList[groupId] = {}
  409. genCityList(Group_2_CityList[groupId], unionIdArr)
  410. -- 公会排行榜
  411. Group_2_UnionRankList[groupId] = createGuildRank()
  412. genGroupUnionRankList(Group_2_UnionRankList[groupId], unionIdArr)
  413. -- "serverId -- unionIdArray" 映射表
  414. genServer2UnionArr(Group_2_UnionRankList[groupId])
  415. -- 个人排行榜
  416. Group_2_PlayerRankList[groupId] = createPlayerRank()
  417. genGroupPlayerRankList(Group_2_PlayerRankList[groupId], unionIdArr, playerListData)
  418. -- "公会-公会所属分组" 映射表
  419. genUnion2GroupList(groupId, unionIdArr)
  420. end
  421. end
  422. function initAfterStart()
  423. if _G.is_middle ~= true then return end
  424. loadData()
  425. genGroupCache()
  426. end
  427. -- 重置数据
  428. function ResetData()
  429. Group_2_CityList = {}
  430. Group_2_UnionRankList = {}
  431. Group_2_PlayerRankList = {}
  432. Union_2_Group = {}
  433. Server_2_UnionArr = {}
  434. AnotherWorldBattleData.lastRoundStartTime = os.time()
  435. -- AnotherWorldBattleData.stage = AnotherWorldBattleDefine.AB_STATE_JOIN
  436. AnotherWorldBattleData.joinUnionArr = nil
  437. AnotherWorldBattleData.groupArray = nil
  438. AnotherWorldBattleData.unionList = nil
  439. AnotherWorldBattleData.playerList = nil
  440. dbUpdate._id = AnotherWorldBattleData._id
  441. LuaMongo.update(DB.db_anotherWorldBattle, dbUpdate, AnotherWorldBattleData)
  442. end
  443. -- 获取公会所在分组的Id
  444. function GetUnionGroupId(unionId)
  445. return Union_2_Group[unionId]
  446. end
  447. -- 当自己公会没有参赛时, 获取本服第一个公会所在分组Id
  448. function GetGroupIdByServerId(serverId)
  449. local unionArr = Server_2_UnionArr[serverId]
  450. if unionArr and unionArr[1] then
  451. local unionId = unionArr[1]
  452. return GetUnionGroupId(unionId)
  453. end
  454. end
  455. -- 获取活动当前阶段
  456. function GetStage()
  457. return AnotherWorldBattleData.stage
  458. end
  459. -- 更新活动当前阶段
  460. function UpdateStage(newStage)
  461. AnotherWorldBattleData.stage = newStage
  462. updateValue("stage", newStage)
  463. if newStage == AnotherWorldBattleDefine.AB_STATE_BATTLE then
  464. genGroupCache()
  465. end
  466. end
  467. -- 获取活动上一轮的开始时间
  468. function GetLastRoundStartTime()
  469. return AnotherWorldBattleData.lastRoundStartTime
  470. end
  471. function UpdateLastRoundStartTime(newTime)
  472. AnotherWorldBattleData.lastRoundStartTime = newTime
  473. updateValue("lastRoundStartTime", newTime)
  474. end
  475. -- 获取参赛公会列表
  476. function GetJoinUnionArr()
  477. return AnotherWorldBattleData.joinUnionArr
  478. end
  479. -- 更新参赛公会列表
  480. function UpdateJoinUnionArr(newJoinUnionArr)
  481. AnotherWorldBattleData.joinUnionArr = newJoinUnionArr
  482. updateValue("joinUnionArr", newJoinUnionArr)
  483. end
  484. -- 获取分组列表
  485. function GetGroupArray()
  486. return AnotherWorldBattleData.groupArray
  487. end
  488. -- 更新分组列表
  489. function UpdateGroupArray(newGroupArray)
  490. AnotherWorldBattleData.groupArray = newGroupArray
  491. updateValue("groupArray", newGroupArray)
  492. end
  493. -- 获取公会名字
  494. function GetUnionName(unionId)
  495. return AnotherWorldBattleData.unionList and AnotherWorldBattleData.unionList[unionId].name or ""
  496. end
  497. -- 获取某个公会数据
  498. function GetUnionData(unionId)
  499. return AnotherWorldBattleData.unionList and AnotherWorldBattleData.unionList[unionId]
  500. end
  501. -- 更新某个公会数据
  502. function UpdateUnionData(unionId, newUnionData)
  503. if not AnotherWorldBattleData.unionList then
  504. AnotherWorldBattleData.unionList = {}
  505. -- updateValue("unionList", AnotherWorldBattleData.unionList)
  506. end
  507. AnotherWorldBattleData.unionList[unionId] = newUnionData
  508. updateValue("unionList"..".".. unionId, newUnionData)
  509. end
  510. -- 获取公会列表
  511. function GetUnionList()
  512. return AnotherWorldBattleData.unionList
  513. end
  514. -- 获取玩家名字
  515. function GetPlayerName(playerUuid)
  516. local playerListData = AnotherWorldBattleData.playerList
  517. if playerListData and playerListData[playerUuid] then
  518. return playerListData[playerUuid].name or ""
  519. end
  520. return ""
  521. end
  522. -- 获取玩家数据
  523. function GetPlayerData(playerUuid)
  524. return AnotherWorldBattleData.playerList and AnotherWorldBattleData.playerList[playerUuid]
  525. end
  526. -- 更新玩家数据
  527. function UpdatePlayerData(playerUuid, newPlayerData)
  528. if not AnotherWorldBattleData.playerList then
  529. AnotherWorldBattleData.playerList = {}
  530. -- updateValue("playerList", AnotherWorldBattleData.playerList)
  531. end
  532. AnotherWorldBattleData.playerList[playerUuid] = newPlayerData
  533. updateValue("playerList".. "." .. playerUuid, newPlayerData)
  534. end
  535. -- 获取公会列表
  536. function GetPlayerList()
  537. return AnotherWorldBattleData.playerList
  538. end
  539. -- 获取城池数据
  540. function GetCityData(groupId, cityId)
  541. if Group_2_CityList[groupId] then
  542. return Group_2_CityList[groupId][cityId]
  543. end
  544. end
  545. -- 更新城池数据
  546. function UpdateCityData(groupId, cityId, newCityData)
  547. if Group_2_CityList[groupId] then
  548. Group_2_CityList[groupId][cityId] = newCityData
  549. end
  550. end
  551. -- 获取所有城池数据
  552. function GetCityListByGroupId(groupId)
  553. return Group_2_CityList[groupId]
  554. end
  555. -- 更新所有城池数据
  556. function UpdateCityList(groupId, newCityList)
  557. Group_2_CityList[groupId] = newCityList
  558. end
  559. -- 获取公会排行数据
  560. function GetUnionRankList(groupId)
  561. local unionRank = Group_2_UnionRankList[groupId]
  562. if unionRank then
  563. return unionRank.getRankList()
  564. end
  565. end
  566. -- 更新公会的排行榜数据, cityVal, pointVal为变化的值
  567. function UpdateUnionRankList(groupId, unionId, cityVal, pointVal, newPower)
  568. local unionRank = Group_2_UnionRankList[groupId]
  569. if unionRank then
  570. local unionRankInfo = unionRank.getGuildDetail(unionId)
  571. unionRankInfo.occupyCityNum = unionRankInfo.occupyCityNum + cityVal
  572. unionRankInfo.occupyPointNum = unionRankInfo.occupyPointNum + pointVal
  573. if newPower then
  574. unionRankInfo.power = newPower
  575. end
  576. unionRank.updateGuild(unionId, unionRankInfo.name, unionRankInfo.occupyCityNum, unionRankInfo.occupyPointNum, unionRankInfo.power)
  577. end
  578. end
  579. -- 生成玩家用于排名的数据
  580. local function genPlayerRankVal(playerUuid)
  581. local playerListData = AnotherWorldBattleData.playerList
  582. local name, power, pointNum, pointAllWeight = "", 0, 0, 0
  583. if playerListData and playerListData[playerUuid] then
  584. power = playerListData[playerUuid].power or 0
  585. name = playerListData[playerUuid].name or ""
  586. for cityId, pointList in pairs(playerListData[playerUuid].heroList or {}) do
  587. for _, _ in pairs(pointList) do
  588. pointNum = pointNum + 1
  589. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  590. pointAllWeight = pointAllWeight + (cityCfg and cityCfg.pointWeight or 0)
  591. end
  592. end
  593. end
  594. return name, power, pointNum, pointAllWeight
  595. end
  596. -- 获取玩家排行数据
  597. function GetPlayerRankList(groupId)
  598. local playerRank = Group_2_PlayerRankList[groupId]
  599. if playerRank then
  600. return playerRank.getRankList()
  601. end
  602. end
  603. -- 更新玩家排行数据, pointVal, pointWeightVal为变化的值
  604. function UpdatePlayerRankList(groupId, playerUuid, pointVal, pointWeightVal, newPower)
  605. local playerRank = Group_2_PlayerRankList[groupId]
  606. if playerRank then
  607. local playerRankData = playerRank.getPlayerDetail(playerUuid)
  608. if not playerRankData then
  609. playerRankData = {}
  610. local name, power, pointNum, pointAllWeight = genPlayerRankVal(playerUuid)
  611. playerRankData.name = name
  612. playerRankData.power = power
  613. playerRankData.pointNum = pointNum
  614. playerRankData.pointAllWeight = pointAllWeight
  615. else
  616. playerRankData.pointNum = playerRankData.pointNum + pointVal
  617. playerRankData.pointAllWeight = playerRankData.pointAllWeight + pointWeightVal
  618. if newPower then
  619. playerRankData.power = newPower
  620. end
  621. end
  622. playerRank.updatePlayer(playerUuid, playerRankData.name, playerRankData.power, playerRankData.pointNum, playerRankData.pointAllWeight)
  623. end
  624. end