act_rank.lua 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. -- 活动排行
  2. local logger = require "logger"
  3. local stringify = require "stringify"
  4. local asset = require "model.asset"
  5. local util = require "util"
  6. local activitytimemod
  7. local act_rankinglist
  8. local module_fun = require "model.module_fun"
  9. local skynet = require "skynet"
  10. local adventure
  11. local embattle
  12. local REQUEST = {}
  13. local CMD = {}
  14. local MODULE = {}
  15. local THIS = {}
  16. local function func_ret(fname, character, args)
  17. if not args.id then
  18. return {errno = 1} -- 参数异常
  19. end
  20. local state = activitytimemod.get_state(character, args.id)
  21. if state == STATE_CLOSE then
  22. return {errno = STD_ERR.COMMON_ACT_NOT_OPEN} -- 活动未开启
  23. end
  24. local f = THIS[fname]
  25. if not f then
  26. logger.error("func_ret not fname:%s !!!", fname)
  27. return {errno = STD_ERR.COMMON_SYS_ERR}
  28. end
  29. local errno, ret = f(character, args)
  30. if errno ~= 0 then
  31. return {errno = errno}
  32. end
  33. ret = ret or {}
  34. ret.errno = 0
  35. return ret
  36. end
  37. local function get_conf(character, module_id)
  38. return activitytimemod.get_conf(character, module_id)
  39. end
  40. local function get_info(character, module_id)
  41. return activitytimemod.get_info(character, module_id)
  42. end
  43. local function can_upload(character, module_id)
  44. act_rankinglist = act_rankinglist or skynet.localname(".rankinglist")
  45. local state = activitytimemod.get_state(character, module_id)
  46. if state == STATE_OPEN then
  47. -- 检查是否再上传时间内
  48. local conf = get_conf(character, module_id)
  49. if not conf then
  50. return
  51. end
  52. if conf.parameter3[1] > 0 then
  53. local info = get_info(character, module_id)
  54. if info and os.time() + conf.parameter3[1]*HOUR_SEC < info.endtime then
  55. return true
  56. end
  57. end
  58. end
  59. return false
  60. end
  61. function MODULE.list_request_interests() return REQUEST end
  62. function MODULE.list_command_interests() return CMD end
  63. -- TODO: 解析/升级模块数据 在这里把数据初始化好
  64. function MODULE.parse(character)
  65. end
  66. function MODULE.open(character, ainfo)
  67. THIS.syn(character, ainfo.activity_type)
  68. end
  69. function MODULE.close(character, ainfo)
  70. end
  71. function MODULE.continue_open(character, ainfo)
  72. end
  73. function THIS.upload(character, module_id, num, num2, temp)
  74. local info = get_info(character, module_id)
  75. if not info then
  76. return
  77. end
  78. local data = temp or {}
  79. data.num = num
  80. data.num2 = num2 or os.time()
  81. data.role = module_fun.simple_role(character)
  82. skynet.call(act_rankinglist, "lua", "upload", info.sid, data)
  83. end
  84. function THIS.syn(character, module_id)
  85. if module_id == MODULE_ID_SIMPLE_BATTLE_RANK then
  86. adventure = adventure or require "model.adventure"
  87. local data = adventure.get_simple_pass_data(character)
  88. if data.id > 0 then
  89. THIS.upload(character, MODULE_ID_SIMPLE_BATTLE_RANK, data.id, data.tm)
  90. end
  91. end
  92. if module_id == MODULE_ID_ELITE_BATTLE_RANK then
  93. adventure = adventure or require "model.adventure"
  94. local data = adventure.get_elite_pass_data(character)
  95. if data.id > 0 then
  96. THIS.upload(character, MODULE_ID_ELITE_BATTLE_RANK, data.id, data.tm)
  97. end
  98. end
  99. if module_id == MODULE_ID_POWER_RANK then
  100. embattle = embattle or require "model.embattle"
  101. local power = embattle.battle_power(character)
  102. if power > 0 then
  103. THIS.upload(character, MODULE_ID_POWER_RANK, power, 0)
  104. end
  105. end
  106. if module_id == MODULE_ID_HERO_RANK then
  107. embattle = embattle or require "model.embattle"
  108. local power, info = embattle.max_power_hero(character)
  109. if power > 0 then
  110. THIS.upload(character, MODULE_ID_POWER_RANK, power, 0, {
  111. id = info.id,
  112. lv = info.lv
  113. })
  114. end
  115. end
  116. end
  117. -- TODO: 侦听事件
  118. function MODULE.monitor(character)
  119. character.monitor("simple_battle_pass", function(_, id)
  120. local sign = can_upload(character, MODULE_ID_SIMPLE_BATTLE_RANK)
  121. if sign then
  122. THIS.upload(character, MODULE_ID_SIMPLE_BATTLE_RANK, id)
  123. end
  124. end)
  125. character.monitor("elite_battle_pass", function(_, id)
  126. local sign = can_upload(character, MODULE_ID_ELITE_BATTLE_RANK)
  127. if sign then
  128. THIS.upload(character, MODULE_ID_ELITE_BATTLE_RANK, id)
  129. end
  130. end)
  131. character.monitor("power_update", function(_, power)
  132. local sign = can_upload(character, MODULE_ID_POWER_RANK)
  133. if sign then
  134. THIS.upload(character, MODULE_ID_POWER_RANK, power, 0)
  135. end
  136. end)
  137. -- character.monitor("syn_act_rank", function(_, id)
  138. -- THIS.syn(character,id)
  139. -- end)
  140. character.monitor("timer.minute", function(_, tm)
  141. local sign = can_upload(character, MODULE_ID_HERO_RANK)
  142. if sign then
  143. THIS.syn(character,MODULE_ID_HERO_RANK)
  144. end
  145. end)
  146. end
  147. -- TODO: 类似泰利的 prepare 接口
  148. function MODULE.launch(character)
  149. activitytimemod = require "model.activitytimemod"
  150. act_rankinglist = skynet.localname(".act_rankinglist")
  151. end
  152. -- TODO: 与客户端同步数据
  153. function MODULE.ready(character)
  154. adventure = adventure or require "model.adventure"
  155. local data = adventure.get_elite_pass_data(character)
  156. if data.id > 0 then
  157. THIS.upload(character, MODULE_ID_ELITE_BATTLE_RANK, data.id, data.tm)
  158. end
  159. end
  160. -- TODO: 玩家下线时的处理
  161. function MODULE.saybye(character)
  162. end
  163. function MODULE.get_red_point(character)
  164. return
  165. end
  166. function THIS.act_rank_data(character, args)
  167. local model_id = args.id
  168. if not model_id then
  169. return 1 -- 参数异常
  170. end
  171. local conf = get_conf(character, model_id)
  172. if not conf then
  173. return 2 -- 系统异常
  174. end
  175. local list = skynet.call(act_rankinglist, "lua", "get_ranking", conf.ID)
  176. local ret = {
  177. errno = 0,
  178. list = {},
  179. }
  180. for k, v in ipairs(list) do
  181. if k <= 100 then
  182. ret.list[k] = v
  183. ret.list[k].num2 = nil
  184. ret.list[k].ranking = k
  185. else
  186. break
  187. end
  188. end
  189. return 0, ret
  190. end
  191. function REQUEST.act_rank_data(character, args)
  192. return func_ret("act_rank_data", character, args)
  193. end
  194. function CMD.syn_act_rank(character, id)
  195. local sign = can_upload(character, id)
  196. if sign then
  197. THIS.syn(character,id)
  198. end
  199. end
  200. return MODULE