OpenServerRank.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. local Msg = require("core.Msg")
  2. local Util = require("common.Util")
  3. local Lang = require("common.Lang")
  4. local OpenServerRankDB = require("present.OpenServerRankDB")
  5. local Broadcast = require("broadcast.Broadcast")
  6. local OpenAct = require("present.OpenAct")
  7. local YunYingLogic = require("yunying.YunYingLogic")
  8. local DrawCardLogic = require("drawCard.DrawCardLogic")
  9. local Log = require("common.Log")
  10. --[[
  11. 开服排名活动 充值排名、招募排名
  12. local:
  13. getOpenActParam() -- 通过排名类型获得开服活动参数
  14. getDayLeftTime() -- 获得当天剩余时间秒
  15. getActLeftTime() -- 得到活动需要用到的时间秒
  16. public:
  17. isActive() -- 激活状态
  18. isBaseOpen() -- 开启活动基本条件
  19. isOpen() -- 活动开启
  20. getLeftTime() -- 得到活动剩余时间
  21. query() -- 发送活动信息
  22. onCharge() -- 充值回调
  23. onDrawCard() -- 招募回调
  24. onHuangjingTower() -- 爬塔回调
  25. onZeroAll() -- 零点处理回调
  26. --]]
  27. local function OpenServerRank_WriteLog(human, sztext)
  28. if human then
  29. sztext = sztext.." _id = "..human.db._id.." name = "..human.db.name
  30. end
  31. Log.write(Log.LOGID_OSS_COMMON, sztext)
  32. end
  33. local function getOpenActParam(rankType)
  34. if rankType == OpenServerRankDB.RANK_TYPE_DAY_TOPUP or
  35. rankType == OpenServerRankDB.RANK_TYPE_TOTAL_TOPUP then return OpenAct.OPEN_ACT_TOPUP_RANK end
  36. if rankType == OpenServerRankDB.RANK_TYPE_DAY_DRAW_CARD or
  37. rankType == OpenServerRankDB.RANK_TYPE_TOTAL_DRAW_CARD then return OpenAct.OPEN_ACT_DRAW_CARD_RANK end
  38. if rankType == OpenServerRankDB.RANK_TYPE_TOTAL_TOWER then return OpenAct.OPEN_ACT_TOWER_RANK end
  39. end
  40. local function getDayLeftTime()
  41. local now = os.time()
  42. local endTime = Util.getDayStartTime(now) + 86400
  43. return endTime - now
  44. end
  45. local function getActLeftTime(rankType)
  46. if rankType == OpenServerRankDB.RANK_TYPE_DAY_TOPUP or
  47. rankType == OpenServerRankDB.RANK_TYPE_DAY_DRAW_CARD then
  48. return getDayLeftTime()
  49. end
  50. if rankType == OpenServerRankDB.RANK_TYPE_TOTAL_TOPUP or
  51. rankType == OpenServerRankDB.RANK_TYPE_TOTAL_DRAW_CARD or
  52. rankType == OpenServerRankDB.RANK_TYPE_TOTAL_TOWER then
  53. local openActParam = getOpenActParam(rankType)
  54. local _,leftTime = OpenAct.getOpenActTime(openActParam)
  55. return leftTime
  56. end
  57. return 0
  58. end
  59. function isActive(human, YYInfo, funcConfig)
  60. return not isOpen(human, YYInfo, funcConfig)
  61. end
  62. function isBaseOpen(human, YYInfo, funcConfig, noSend)
  63. if human.db.lv < funcConfig.openLv then
  64. if not noSend then
  65. local str = Util.format(Lang.ROLE_LEV_ERROR, funcConfig.openLv)
  66. return Broadcast.sendErr(human, str)
  67. end
  68. end
  69. local flag = OpenAct.getOpenActTime(funcConfig.param)
  70. if not flag then return end
  71. return true
  72. end
  73. function isOpen(human, YYInfo, funcConfig)
  74. if isBaseOpen(human, YYInfo, funcConfig, true) then return true end
  75. end
  76. function getLeftTime(human, YYInfo, funcConfig)
  77. local _,leftTime = OpenAct.getOpenActTime(funcConfig.param)
  78. return leftTime
  79. end
  80. function query(human, rankType)
  81. local actLeftTime = getActLeftTime(rankType)
  82. local maxSendRank = OpenServerRankDB.getMaxSendRank(rankType)
  83. local msgRet = Msg.gc.GC_OPEN_SERVER_RANK_QUERY
  84. msgRet.type = rankType
  85. msgRet.leftTime = actLeftTime
  86. OpenServerRankDB.wrapOwnerData(rankType, msgRet.ownerData, human.db._id)
  87. for rank = 1,maxSendRank do
  88. OpenServerRankDB.wrapOpenServerRankList(rankType, msgRet.list[rank], rank)
  89. end
  90. msgRet.list[0] = maxSendRank
  91. Msg.send(msgRet, human.fd)
  92. end
  93. function rewardQuery(human, rankType)
  94. OpenServerRankDB.rewardQuery(human, rankType)
  95. end
  96. function onCharge(human, price, funcID, buyID)
  97. local funcConfig = YunYingLogic.getFuncConfig(funcID)
  98. if not funcConfig then return end
  99. if not isOpen(human, nil, funcConfig) then return end
  100. if funcConfig.param == OpenAct.OPEN_ACT_TOPUP_RANK then
  101. OpenServerRankDB.onValueAdd(human, OpenServerRankDB.RANK_TYPE_DAY_TOPUP, price)
  102. OpenServerRankDB.onValueAdd(human, OpenServerRankDB.RANK_TYPE_TOTAL_TOPUP, price)
  103. OpenServerRank_WriteLog(human, "[OpenServerRankDB_onCharge] 玩家充值进行上榜操作 price = "..price.."buyID = "..buyID)
  104. end
  105. end
  106. function onDrawCard(human, funcID, value, drawType)
  107. local funcConfig = YunYingLogic.getFuncConfig(funcID)
  108. if not funcConfig then return end
  109. if not isOpen(human, nil, funcConfig) then return end
  110. if funcConfig.param == OpenAct.OPEN_ACT_DRAW_CARD_RANK then
  111. if drawType == DrawCardLogic.DRAWCARD_ID2 or
  112. drawType == DrawCardLogic.DRAWCARD_ID5 or
  113. drawType == DrawCardLogic.DRAWCARD_ID6 then
  114. OpenServerRankDB.onValueAdd(human, OpenServerRankDB.RANK_TYPE_DAY_DRAW_CARD, value)
  115. OpenServerRankDB.onValueAdd(human, OpenServerRankDB.RANK_TYPE_TOTAL_DRAW_CARD, value)
  116. OpenServerRank_WriteLog(human, "[OpenServerRankDB_onDrawCard] 玩家抽卡进行上榜操作 value = "..value.."drawType = "..drawType)
  117. end
  118. end
  119. end
  120. function onHuangjingTower(human,funcID, parameter)
  121. local funcConfig = YunYingLogic.getFuncConfig(funcID)
  122. if not funcConfig then return end
  123. if not isOpen(human, nil, funcConfig) then return end
  124. if funcConfig.param == OpenAct.OPEN_ACT_TOWER_RANK then
  125. local towerLv = human.db.tower and human.db.tower.lv or 0
  126. OpenServerRankDB.onValueSet(human, OpenServerRankDB.RANK_TYPE_TOTAL_TOWER, towerLv)
  127. OpenServerRank_WriteLog(human, "[OpenServerRankDB_onHuangjingTower] 玩家进行上榜操作 towerLv = "..towerLv)
  128. end
  129. end
  130. function onZeroAll(funcID)
  131. OpenServerRank_WriteLog(nil, "[OpenServerRank_onZeroAll] 整点进行发奖励操作 funcID = "..funcID)
  132. OpenServerRankDB.onRewardSend(funcID)
  133. end