AbsIceDragonRank.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. local Lang = require("common.Lang")
  2. local Msg = require("core.Msg")
  3. local ObjHuman = require("core.ObjHuman")
  4. local Util = require("common.Util")
  5. local Grid = require("bag.Grid")
  6. local Timer = require("core.Timer")
  7. local BagLogic = require("bag.BagLogic")
  8. local Broadcast = require("broadcast.Broadcast")
  9. local BRoleLogic = require("billboard.BRoleLogic")
  10. local BillboardDB = require("billboard.BillboardDB")
  11. local BillboardDefine = require("billboard.BillboardDefine")
  12. local RoleLogic = require("role.RoleLogic")
  13. local CommonDB = require("common.CommonDB")
  14. local YunYingLogic = require("yunying.YunYingLogic")
  15. local AbsActExcel = require("excel.absAct")
  16. local MailExcel = require("excel.mail")
  17. local MailManager = require("mail.MailManager")
  18. local MailDefine = require("mail.MailIdDefine")
  19. local RoleDBLogic = require("role.RoleDBLogic")
  20. local AbsActLogic = require("absAct.AbsActLogic")
  21. function getEndTime()
  22. local now = os.time()
  23. local endTime = Util.getDayStartTime(now + 24 * 60 * 60)
  24. return endTime - now
  25. end
  26. function query(human)
  27. local msgRet = Msg.gc.GC_ABS_ICE_DRAGON_RANK_QUERY
  28. local board = BillboardDB.getBoard(BillboardDefine.TYPE_DRAGON)
  29. msgRet.list[0] = 1
  30. local msgNet = msgRet.list[1]
  31. msgNet.funcRankType = 3
  32. msgNet.leftTime = getEndTime()
  33. msgNet.list[0] = 10
  34. for i = 1, 10 do
  35. local net = msgNet.list[i]
  36. net.rank = i
  37. net.rankNeedValue= 0
  38. if board and board.rank2data[i] then
  39. local rankData = board.rank2data[i]
  40. net.uid = rankData.roleBase and rankData.roleBase.uuid or rankData.uuid
  41. net.rankValue = rankData and rankData.value1 or 0
  42. if rankData and rankData.roleBase then
  43. net.uid = net.uid or ""
  44. net.name = rankData.roleBase.name
  45. net.head = rankData.roleBase.head
  46. net.headFrame = rankData.roleBase.headFrame
  47. net.lv = rankData.roleBase.lv
  48. else
  49. local userDB = RoleDBLogic.getDb(rankData.uuid)
  50. net.uid = rankData.uuid
  51. net.name = userDB.name
  52. net.head = userDB.head
  53. net.rankValue = rankData.value1
  54. net.headFrame = userDB.headFrame
  55. net.lv = userDB.lv
  56. end
  57. else
  58. net.uid = "-1"
  59. net.name = ""
  60. net.head = -1
  61. net.rankValue = 0
  62. net.headFrame = -1
  63. net.lv = -1
  64. end
  65. local id = getRewardByRank(i)
  66. local conf = AbsActExcel.IceRank[id]
  67. for j, h in ipairs(conf.totalRewards) do
  68. Grid.makeItem(net.items[j], h[1], h[2])
  69. end
  70. net.items[0] = #conf.totalRewards
  71. end
  72. -- 获取排行区间 奖励 给予前端处理 放到各个名词后面 显示排名奖励
  73. --[[
  74. for k, v in ipairs(AbsActExcel.IceRank) do
  75. local net = msgRet.rankItem[k]
  76. net.minRank = v.minRank
  77. net.maxRank = v.maxRank
  78. net.rankNeedValue = 0
  79. for j, h in ipairs(v.reward) do
  80. Grid.makeItem(net.items[j], h[1], h[2])
  81. end
  82. net.items[0] = #v.reward
  83. end
  84. msgRet.rankItem[0] = #AbsActExcel.IceRank
  85. ]]
  86. local myRank = BillboardDB.getRank(BillboardDefine.TYPE_DRAGON, human.db._id)
  87. if myRank then
  88. local rankData = BillboardDB.getRankData(BillboardDefine.TYPE_DRAGON, myRank)
  89. if rankData then
  90. local net = msgNet.onwerData
  91. net.rank = myRank
  92. net.rankValue = rankData and rankData.value1 or 0
  93. net.items[0] = 0
  94. end
  95. else
  96. local net = msgNet.onwerData
  97. net.rank = -1
  98. net.rankValue = rankData and rankData.value1 or 0
  99. net.items[0] = 0
  100. end
  101. -- Msg.trace(msgRet)
  102. Msg.send(msgRet, human.fd)
  103. end
  104. function queryReward(human)
  105. local msgRet = Msg.gc.GC_ABS_REACH_RANK_REWARD_QUERY
  106. msgRet.actId = 0
  107. msgRet.funcRankType = 3
  108. for k , conf in ipairs(AbsActExcel.IceRank) do
  109. local net = msgRet.list[k]
  110. net.minRank = conf.roleMin
  111. net.maxRank = conf.roleMax
  112. net.rankNeedValue = 0
  113. for j, h in ipairs(conf.totalRewards) do
  114. Grid.makeItem(net.items[j], h[1], h[2])
  115. end
  116. net.items[0] = #conf.totalRewards
  117. end
  118. msgRet.list[0] = #AbsActExcel.IceRank
  119. Msg.send(msgRet, human.fd)
  120. end
  121. function getRewardByRank(rank)
  122. for k , conf in ipairs(AbsActExcel.IceRank) do
  123. if conf.roleMin <= rank and conf.roleMax >= rank then
  124. return k
  125. end
  126. end
  127. end
  128. function onZero(funcID)
  129. local absConfig = AbsActExcel.absActivity[funcID]
  130. if not absConfig then return end
  131. local funcConfig = YunYingLogic.getFuncConfig(funcID)
  132. if not funcConfig then return end
  133. if not AbsActLogic.isStarted(human, funcID) then
  134. local diffDay = Util.diffDay(absConfig.realEndTime)
  135. if diffDay ~= 1 then
  136. return
  137. end
  138. end
  139. local board = BillboardDB.getBoard(BillboardDefine.TYPE_DRAGON)
  140. if board then
  141. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_HEFU_ICE_RANK]
  142. local title = mailConfig.title
  143. local senderName = mailConfig.senderName
  144. local sendList = {}
  145. local len = 0
  146. for rank = 1, #board.rank2data do
  147. local rankData = board.rank2data[rank]
  148. if rankData then
  149. local uuid
  150. if rankData and rankData.roleBase then
  151. uuid = rankData.roleBase.uuid
  152. end
  153. if not uuid then
  154. uuid = rankData and rankData.uuid or ""
  155. end
  156. if uuid then
  157. len = len + 1
  158. sendList[len] = {}
  159. sendList[len].uuid = uuid
  160. sendList[len].rank = rank
  161. end
  162. end
  163. end
  164. if len > 0 then
  165. Timer.addLater(25, iceDragonRankSend, sendList, 0 )
  166. end
  167. end
  168. end
  169. function iceDragonRankSend(sendList, len)
  170. if len >= #sendList then return end
  171. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_HEFU_ICE_RANK]
  172. local title = mailConfig.title
  173. local senderName = mailConfig.senderName
  174. local thisLen = 0
  175. for i = len + 1 , #sendList do
  176. local uuid = sendList[i].uuid
  177. local rank = sendList[i].rank
  178. local id = getRewardByRank(rank)
  179. local conf = AbsActExcel.IceRank[id]
  180. local content = Util.format(mailConfig.content, rank)
  181. MailManager.add(MailManager.SYSTEM, uuid, title, content, conf.totalRewards, senderName)
  182. thisLen = thisLen + 1
  183. if thisLen >= 10 then
  184. break
  185. end
  186. end
  187. local nextLen = len + thisLen
  188. if nextLen < #sendList and #sendList > 0 then
  189. Timer.addLater(2, iceDragonRankSend, sendList, nextLen)
  190. end
  191. end