BillboardLogic.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. local BillboardExcel = require("excel.billboard")
  2. local UnionExcel = require("excel.union")
  3. local Msg = require("core.Msg")
  4. local BillboardDefine = require("billboard.BillboardDefine")
  5. local BillboardDB = require("billboard.BillboardDB")
  6. local BRoleLogic = require("billboard.BRoleLogic")
  7. local BillboardAim = require("billboard.BillboardAim")
  8. local BattleLogic = require("battle.BattleLogic")
  9. local RoleLogic = require("role.RoleLogic")
  10. local UnionDBLogic = require("union.UnionDBLogic")
  11. local CombatDefine = require("combat.CombatDefine")
  12. local UnionExcel = require("excel.union")
  13. function fontBoardUnionNet(net, union)
  14. local lv = math.min(union.lv, #UnionExcel.union)
  15. local config = UnionExcel.union[lv]
  16. net.unionUuid = union._id
  17. net.name = union.name
  18. net.lv = union.lv
  19. net.maxCnt = config.maxCnt
  20. net.curCnt = union.curCnt
  21. net.zhandouli = union.zhandouli
  22. net.bannerID = union.bannerID
  23. end
  24. local function fontValuesShow(human, net, boardType, rankData)
  25. if boardType == BillboardDefine.TYPE_BATTLE then
  26. local battleID = rankData and rankData.value1 or 0
  27. local battleName, mapName = BattleLogic.getBattleName(human, battleID)
  28. net.value1 = mapName .. battleName
  29. net.value2 = ""
  30. else
  31. net.value1 = tostring(rankData and rankData.value1 or "")
  32. net.value2 = tostring(rankData and rankData.value2 or "")
  33. end
  34. end
  35. local function getBoardUuidByType(boardType, human)
  36. if boardType == BillboardDefine.TYPE_UNION then
  37. return human.db.unionUuid
  38. else
  39. return human.db._id
  40. end
  41. end
  42. local function getZhanliTypeByType(boardType)
  43. if boardType == BillboardDefine.TYPE_LIANYU then
  44. return CombatDefine.COMBAT_TYPE1
  45. end
  46. end
  47. function fontBoardNet(human, net, boardType, rank, rankData, uuid)
  48. net.rank = rank or 0
  49. net.unionData[0] = 0
  50. if boardType == BillboardDefine.TYPE_UNION then
  51. local union = UnionDBLogic.getUnion(rankData.uuid)
  52. local presidentUuid = uuid
  53. if union then
  54. net.unionData[0] = 1
  55. fontBoardUnionNet(net.unionData[1], union)
  56. presidentUuid = union.presidentUuid
  57. end
  58. RoleLogic.getRoleBaseByUuid(presidentUuid, net.roleBase)
  59. else
  60. if rankData and rankData.roleBase then
  61. RoleLogic.makeRoleBase(rankData.roleBase, net.roleBase)
  62. else
  63. local roleUuid = rankData and rankData.uuid or uuid
  64. RoleLogic.getRoleBaseByUuid(roleUuid, net.roleBase, getZhanliTypeByType(boardType))
  65. end
  66. end
  67. fontValuesShow(human, net, boardType, rankData)
  68. end
  69. -- 封装总览结构体
  70. function fontMainNet(net, boardType, config, human)
  71. net.boardType = boardType
  72. net.boardName = config.boardName
  73. net.topData[0] = 0
  74. local rank = 1
  75. local rankData = BillboardDB.getRankData(boardType, rank)
  76. if rankData then
  77. net.topData[0] = 1
  78. fontBoardNet(human, net.topData[1], boardType, rank, rankData)
  79. end
  80. net.hasAim = BillboardAim.getAimIDsByType(boardType) and 1 or 0
  81. net.hasAimRed = BillboardAim.isAimRed(human, boardType) and 1 or 0
  82. end
  83. -- 发送排行榜总览列表
  84. function sendMainList(human)
  85. local msgRet = Msg.gc.GC_BILLBOARD_MAINLIST
  86. msgRet.list[0] = 0
  87. for boardType, config in ipairs(BillboardExcel.board) do
  88. if config.isShow == 1 then
  89. msgRet.list[0] = msgRet.list[0] + 1
  90. local net = msgRet.list[msgRet.list[0]]
  91. fontMainNet(net, boardType, config, human)
  92. end
  93. end
  94. --Msg.trace(msgRet)
  95. Msg.send(msgRet, human.fd)
  96. end
  97. -- 发送排行榜
  98. function sendQuery(human, boardType)
  99. local board = BillboardDB.getBoard(boardType)
  100. if not board then return end
  101. local msgRet = Msg.gc.GC_BILLBOARD_QUERY
  102. msgRet.boardType = boardType
  103. msgRet.list[0] = math.min(#msgRet.list, #board.rank2data)
  104. for i = 1, msgRet.list[0] do
  105. local rankData = board.rank2data[i]
  106. fontBoardNet(human, msgRet.list[i], boardType, i, rankData)
  107. end
  108. local boardUuid = getBoardUuidByType(boardType, human)
  109. local myRank = BillboardDB.getRank(boardType, boardUuid)
  110. local myRankData = myRank and board.rank2data[myRank]
  111. if myRankData == nil then
  112. local value1, value2 = BRoleLogic.getValues(boardType, human.db)
  113. if value1 then
  114. myRankData = BRoleLogic.getCacheData(boardType, human.db, value1, value2)
  115. end
  116. end
  117. fontBoardNet(human, msgRet.ownData, boardType, myRank, myRankData, human.db._id)
  118. --Msg.trace(msgRet)
  119. Msg.send(msgRet, human.fd)
  120. end
  121. -- 清掉 每日重置的排行榜
  122. function onZero()
  123. for type in pairs(BillboardDefine.DAY_RESET) do
  124. BillboardDB.initBoard(type)
  125. end
  126. end
  127. function isDot(human)
  128. for boardType, config in ipairs(BillboardExcel.board) do
  129. if config.isShow == 1 then
  130. if BillboardAim.isAimRed(human, boardType) then
  131. return true
  132. end
  133. end
  134. end
  135. return false
  136. end