AnotherWorldBattleDB.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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 _, _ in pairs(v.occupyPointList or {}) do
  342. occupyPointNum = occupyPointNum + 1
  343. end
  344. end
  345. return occupyCityNum, occupyPointNum, power
  346. end
  347. for _, unionId in ipairs(unionIdArr) do
  348. local unionData = AnotherWorldBattleData.unionList[unionId]
  349. if unionData then
  350. local occupyCityNum, occupyPointNum, power = getUnionRankVal(unionData)
  351. unionRank.updateGuild(unionId, unionData.name, occupyCityNum, occupyPointNum, power)
  352. end
  353. end
  354. end
  355. -- 生成个人排行榜
  356. local function genGroupPlayerRankList(playerRank, unionIdArr, playerListData)
  357. local function insertPlayerRank(unionId)
  358. if not playerListData then
  359. return
  360. end
  361. for playerUuid, playerInfo in pairs(playerListData) do
  362. if playerInfo.unionId == unionId then
  363. local pointNum, pointAllWeight = 0, 0
  364. for cityId, pointList in pairs(playerInfo.heroList or {}) do
  365. for _, _ in pairs(pointList) do
  366. pointNum = pointNum + 1
  367. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  368. pointAllWeight = pointAllWeight + (cityCfg and cityCfg.pointWeight or 0)
  369. end
  370. end
  371. playerRank.updatePlayer(playerUuid, playerInfo.name, playerInfo.power, pointNum, pointAllWeight)
  372. end
  373. end
  374. end
  375. for _, unionId in ipairs(unionIdArr) do
  376. insertPlayerRank(unionId)
  377. end
  378. end
  379. -- 生成 "公会-公会所属分组Id" 映射表
  380. local function genUnion2GroupList(groupId, unionIdArr)
  381. for _, unionId in ipairs(unionIdArr) do
  382. Union_2_Group[unionId] = groupId
  383. end
  384. end
  385. -- 生成 "serverId - 公会Array" 映射表
  386. local function genServer2UnionArr(unionRank)
  387. local rankList = unionRank.getRankList()
  388. for _, rankInfo in ipairs(rankList) do
  389. local unionId = rankInfo.guildId
  390. local unionInfo = AnotherWorldBattleData.unionList[unionId]
  391. if unionInfo then
  392. local serverId = unionInfo.serverId
  393. Server_2_UnionArr[serverId] = Server_2_UnionArr[serverId] or {}
  394. Server_2_UnionArr[serverId][#Server_2_UnionArr[serverId]+1] = unionId
  395. end
  396. end
  397. end
  398. -- 生成各组的缓存数据
  399. local function genGroupCache()
  400. if not AnotherWorldBattleData.groupArray then
  401. return
  402. end
  403. local playerListData = AnotherWorldBattleData.playerList
  404. for groupId, unionIdArr in ipairs(AnotherWorldBattleData.groupArray) do
  405. -- 城池
  406. Group_2_CityList[groupId] = {}
  407. genCityList(Group_2_CityList[groupId], unionIdArr)
  408. -- 公会排行榜
  409. Group_2_UnionRankList[groupId] = createGuildRank()
  410. genGroupUnionRankList(Group_2_UnionRankList[groupId], unionIdArr)
  411. -- "serverId -- unionIdArray" 映射表
  412. genServer2UnionArr(Group_2_UnionRankList[groupId])
  413. -- 个人排行榜
  414. Group_2_PlayerRankList[groupId] = createPlayerRank()
  415. genGroupPlayerRankList(Group_2_PlayerRankList[groupId], unionIdArr, playerListData)
  416. -- "公会-公会所属分组" 映射表
  417. genUnion2GroupList(groupId, unionIdArr)
  418. end
  419. end
  420. function initAfterStart()
  421. if _G.is_middle ~= true then return end
  422. loadData()
  423. genGroupCache()
  424. end
  425. -- 重置数据
  426. function ResetData()
  427. Group_2_CityList = {}
  428. Group_2_UnionRankList = {}
  429. Group_2_PlayerRankList = {}
  430. Union_2_Group = {}
  431. Server_2_UnionArr = {}
  432. AnotherWorldBattleData.lastRoundStartTime = os.time()
  433. -- AnotherWorldBattleData.stage = AnotherWorldBattleDefine.AB_STATE_JOIN
  434. AnotherWorldBattleData.joinUnionArr = nil
  435. AnotherWorldBattleData.groupArray = nil
  436. AnotherWorldBattleData.unionList = nil
  437. AnotherWorldBattleData.playerList = nil
  438. dbUpdate._id = AnotherWorldBattleData._id
  439. LuaMongo.update(DB.db_anotherWorldBattle, dbUpdate, AnotherWorldBattleData)
  440. end
  441. -- 获取公会所在分组的Id
  442. function GetUnionGroupId(unionId)
  443. return Union_2_Group[unionId]
  444. end
  445. -- 当自己公会没有参赛时, 获取本服第一个公会所在分组Id
  446. function GetGroupIdByServerId(serverId)
  447. local unionArr = Server_2_UnionArr[serverId]
  448. if unionArr and unionArr[1] then
  449. local unionId = unionArr[1]
  450. return GetUnionGroupId(unionId)
  451. end
  452. end
  453. -- 获取活动当前阶段
  454. function GetStage()
  455. return AnotherWorldBattleData.stage
  456. end
  457. -- 更新活动当前阶段
  458. function UpdateStage(newStage)
  459. AnotherWorldBattleData.stage = newStage
  460. updateValue("stage", newStage)
  461. if newStage == AnotherWorldBattleDefine.AB_STATE_BATTLE then
  462. genGroupCache()
  463. end
  464. end
  465. -- 获取活动上一轮的开始时间
  466. function GetLastRoundStartTime()
  467. return AnotherWorldBattleData.lastRoundStartTime
  468. end
  469. function UpdateLastRoundStartTime(newTime)
  470. AnotherWorldBattleData.lastRoundStartTime = newTime
  471. updateValue("lastRoundStartTime", newTime)
  472. end
  473. -- 获取参赛公会列表
  474. function GetJoinUnionArr()
  475. return AnotherWorldBattleData.joinUnionArr
  476. end
  477. -- 更新参赛公会列表
  478. function UpdateJoinUnionArr(newJoinUnionArr)
  479. AnotherWorldBattleData.joinUnionArr = newJoinUnionArr
  480. updateValue("joinUnionArr", newJoinUnionArr)
  481. end
  482. -- 获取分组列表
  483. function GetGroupArray()
  484. return AnotherWorldBattleData.groupArray
  485. end
  486. -- 更新分组列表
  487. function UpdateGroupArray(newGroupArray)
  488. AnotherWorldBattleData.groupArray = newGroupArray
  489. updateValue("groupArray", newGroupArray)
  490. end
  491. -- 获取公会名字
  492. function GetUnionName(unionId)
  493. return AnotherWorldBattleData.unionList and AnotherWorldBattleData.unionList[unionId].name or ""
  494. end
  495. -- 获取某个公会数据
  496. function GetUnionData(unionId)
  497. return AnotherWorldBattleData.unionList and AnotherWorldBattleData.unionList[unionId]
  498. end
  499. -- 更新某个公会数据
  500. function UpdateUnionData(unionId, newUnionData)
  501. if not AnotherWorldBattleData.unionList then
  502. AnotherWorldBattleData.unionList = {}
  503. -- updateValue("unionList", AnotherWorldBattleData.unionList)
  504. end
  505. AnotherWorldBattleData.unionList[unionId] = newUnionData
  506. updateValue("unionList"..".".. unionId, newUnionData)
  507. end
  508. -- 获取公会列表
  509. function GetUnionList()
  510. return AnotherWorldBattleData.unionList
  511. end
  512. -- 获取玩家名字
  513. function GetPlayerName(playerUuid)
  514. local playerListData = AnotherWorldBattleData.playerList
  515. if playerListData and playerListData[playerUuid] then
  516. return playerListData[playerUuid].name or ""
  517. end
  518. return ""
  519. end
  520. -- 获取玩家数据
  521. function GetPlayerData(playerUuid)
  522. return AnotherWorldBattleData.playerList and AnotherWorldBattleData.playerList[playerUuid]
  523. end
  524. -- 更新玩家数据
  525. function UpdatePlayerData(playerUuid, newPlayerData)
  526. if not AnotherWorldBattleData.playerList then
  527. AnotherWorldBattleData.playerList = {}
  528. -- updateValue("playerList", AnotherWorldBattleData.playerList)
  529. end
  530. AnotherWorldBattleData.playerList[playerUuid] = newPlayerData
  531. updateValue("playerList".. "." .. playerUuid, newPlayerData)
  532. end
  533. -- 获取公会列表
  534. function GetPlayerList()
  535. return AnotherWorldBattleData.playerList
  536. end
  537. -- 获取城池数据
  538. function GetCityData(groupId, cityId)
  539. if Group_2_CityList[groupId] then
  540. return Group_2_CityList[groupId][cityId]
  541. end
  542. end
  543. -- 更新城池数据
  544. function UpdateCityData(groupId, cityId, newCityData)
  545. if Group_2_CityList[groupId] then
  546. Group_2_CityList[groupId][cityId] = newCityData
  547. end
  548. end
  549. -- 获取所有城池数据
  550. function GetCityListByGroupId(groupId)
  551. return Group_2_CityList[groupId]
  552. end
  553. -- 更新所有城池数据
  554. function UpdateCityList(groupId, newCityList)
  555. Group_2_CityList[groupId] = newCityList
  556. end
  557. -- 获取公会排行数据
  558. function GetUnionRankList(groupId)
  559. local unionRank = Group_2_UnionRankList[groupId]
  560. if unionRank then
  561. return unionRank.getRankList()
  562. end
  563. end
  564. -- 更新公会的排行榜数据, cityVal, pointVal为变化的值
  565. function UpdateUnionRankList(groupId, unionId, cityVal, pointVal, newPower)
  566. local unionRank = Group_2_UnionRankList[groupId]
  567. if unionRank then
  568. local unionRankInfo = unionRank.getGuildDetail(unionId)
  569. unionRankInfo.occupyCityNum = unionRankInfo.occupyCityNum + cityVal
  570. unionRankInfo.occupyPointNum = unionRankInfo.occupyPointNum + pointVal
  571. if newPower then
  572. unionRankInfo.power = newPower
  573. end
  574. unionRank.updateGuild(unionId, unionRankInfo.name, unionRankInfo.occupyCityNum, unionRankInfo.occupyPointNum, unionRankInfo.power)
  575. end
  576. end
  577. -- 生成玩家用于排名的数据
  578. local function genPlayerRankVal(playerUuid)
  579. local playerListData = AnotherWorldBattleData.playerList
  580. local name, power, pointNum, pointAllWeight = "", 0, 0, 0
  581. if playerListData and playerListData[playerUuid] then
  582. power = playerListData[playerUuid].power or 0
  583. name = playerListData[playerUuid].name or ""
  584. for cityId, pointList in pairs(playerListData[playerUuid].heroList or {}) do
  585. for _, _ in pairs(pointList) do
  586. pointNum = pointNum + 1
  587. local cityCfg = AnotherWorldBattleConfig.city[cityId]
  588. pointAllWeight = pointAllWeight + (cityCfg and cityCfg.pointWeight or 0)
  589. end
  590. end
  591. end
  592. return name, power, pointNum, pointAllWeight
  593. end
  594. -- 获取玩家排行数据
  595. function GetPlayerRankList(groupId)
  596. local playerRank = Group_2_PlayerRankList[groupId]
  597. if playerRank then
  598. return playerRank.getRankList()
  599. end
  600. end
  601. -- 更新玩家排行数据, pointVal, pointWeightVal为变化的值
  602. function UpdatePlayerRankList(groupId, playerUuid, pointVal, pointWeightVal, newPower)
  603. local playerRank = Group_2_PlayerRankList[groupId]
  604. if playerRank then
  605. local playerRankData = playerRank.getPlayerDetail(playerUuid)
  606. if not playerRankData then
  607. playerRankData = {}
  608. local name, power, pointNum, pointAllWeight = genPlayerRankVal(playerUuid)
  609. playerRankData.name = name
  610. playerRankData.power = power
  611. playerRankData.pointNum = pointNum
  612. playerRankData.pointAllWeight = pointAllWeight
  613. else
  614. playerRankData.pointNum = playerRankData.pointNum + pointVal
  615. playerRankData.pointAllWeight = playerRankData.pointAllWeight + pointWeightVal
  616. if newPower then
  617. playerRankData.power = newPower
  618. end
  619. end
  620. playerRank.updatePlayer(playerUuid, playerRankData.name, playerRankData.power, playerRankData.pointNum, playerRankData.pointAllWeight)
  621. end
  622. end