OpenServerRank.lua 5.2 KB

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