123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- -- 活动排行
- local logger = require "logger"
- local stringify = require "stringify"
- local asset = require "model.asset"
- local util = require "util"
- local activitytimemod
- local act_rankinglist
- local module_fun = require "model.module_fun"
- local skynet = require "skynet"
- local adventure
- local embattle
- local REQUEST = {}
- local CMD = {}
- local MODULE = {}
- local THIS = {}
- local function func_ret(fname, character, args)
- if not args.id then
- return {errno = 1} -- 参数异常
- end
- local state = activitytimemod.get_state(character, args.id)
- if state == STATE_CLOSE then
- return {errno = STD_ERR.COMMON_ACT_NOT_OPEN} -- 活动未开启
- end
- local f = THIS[fname]
- if not f then
- logger.error("func_ret not fname:%s !!!", fname)
- return {errno = STD_ERR.COMMON_SYS_ERR}
- end
- local errno, ret = f(character, args)
- if errno ~= 0 then
- return {errno = errno}
- end
- ret = ret or {}
- ret.errno = 0
- return ret
- end
- local function get_conf(character, module_id)
- return activitytimemod.get_conf(character, module_id)
- end
- local function get_info(character, module_id)
- return activitytimemod.get_info(character, module_id)
- end
- local function can_upload(character, module_id)
- act_rankinglist = act_rankinglist or skynet.localname(".rankinglist")
- local state = activitytimemod.get_state(character, module_id)
- if state == STATE_OPEN then
- -- 检查是否再上传时间内
- local conf = get_conf(character, module_id)
- if not conf then
- return
- end
- if conf.parameter3[1] > 0 then
- local info = get_info(character, module_id)
- if info and os.time() + conf.parameter3[1]*HOUR_SEC < info.endtime then
- return true
- end
- end
- end
- return false
- end
- function MODULE.list_request_interests() return REQUEST end
- function MODULE.list_command_interests() return CMD end
- -- TODO: 解析/升级模块数据 在这里把数据初始化好
- function MODULE.parse(character)
- end
- function MODULE.open(character, ainfo)
- THIS.syn(character, ainfo.activity_type)
- end
- function MODULE.close(character, ainfo)
- end
- function MODULE.continue_open(character, ainfo)
- end
- function THIS.upload(character, module_id, num, num2, temp)
- local info = get_info(character, module_id)
- if not info then
- return
- end
- local data = temp or {}
- data.num = num
- data.num2 = num2 or os.time()
- data.role = module_fun.simple_role(character)
- skynet.call(act_rankinglist, "lua", "upload", info.sid, data)
- end
- function THIS.syn(character, module_id)
- if module_id == MODULE_ID_SIMPLE_BATTLE_RANK then
- adventure = adventure or require "model.adventure"
- local data = adventure.get_simple_pass_data(character)
- if data.id > 0 then
- THIS.upload(character, MODULE_ID_SIMPLE_BATTLE_RANK, data.id, data.tm)
- end
- end
- if module_id == MODULE_ID_ELITE_BATTLE_RANK then
- adventure = adventure or require "model.adventure"
- local data = adventure.get_elite_pass_data(character)
- if data.id > 0 then
- THIS.upload(character, MODULE_ID_ELITE_BATTLE_RANK, data.id, data.tm)
- end
- end
- if module_id == MODULE_ID_POWER_RANK then
- embattle = embattle or require "model.embattle"
- local power = embattle.battle_power(character)
- if power > 0 then
- THIS.upload(character, MODULE_ID_POWER_RANK, power, 0)
- end
- end
- if module_id == MODULE_ID_HERO_RANK then
- embattle = embattle or require "model.embattle"
- local power, info = embattle.max_power_hero(character)
- if power > 0 then
- THIS.upload(character, MODULE_ID_POWER_RANK, power, 0, {
- id = info.id,
- lv = info.lv
- })
- end
- end
- end
- -- TODO: 侦听事件
- function MODULE.monitor(character)
- character.monitor("simple_battle_pass", function(_, id)
- local sign = can_upload(character, MODULE_ID_SIMPLE_BATTLE_RANK)
- if sign then
- THIS.upload(character, MODULE_ID_SIMPLE_BATTLE_RANK, id)
- end
- end)
- character.monitor("elite_battle_pass", function(_, id)
- local sign = can_upload(character, MODULE_ID_ELITE_BATTLE_RANK)
- if sign then
- THIS.upload(character, MODULE_ID_ELITE_BATTLE_RANK, id)
- end
- end)
- character.monitor("power_update", function(_, power)
- local sign = can_upload(character, MODULE_ID_POWER_RANK)
- if sign then
- THIS.upload(character, MODULE_ID_POWER_RANK, power, 0)
- end
- end)
- -- character.monitor("syn_act_rank", function(_, id)
- -- THIS.syn(character,id)
- -- end)
- character.monitor("timer.minute", function(_, tm)
- local sign = can_upload(character, MODULE_ID_HERO_RANK)
- if sign then
- THIS.syn(character,MODULE_ID_HERO_RANK)
- end
- end)
- end
- -- TODO: 类似泰利的 prepare 接口
- function MODULE.launch(character)
- activitytimemod = require "model.activitytimemod"
- act_rankinglist = skynet.localname(".act_rankinglist")
- end
- -- TODO: 与客户端同步数据
- function MODULE.ready(character)
- adventure = adventure or require "model.adventure"
- local data = adventure.get_elite_pass_data(character)
- if data.id > 0 then
- THIS.upload(character, MODULE_ID_ELITE_BATTLE_RANK, data.id, data.tm)
- end
- end
- -- TODO: 玩家下线时的处理
- function MODULE.saybye(character)
- end
- function MODULE.get_red_point(character)
- return
- end
- function THIS.act_rank_data(character, args)
- local model_id = args.id
- if not model_id then
- return 1 -- 参数异常
- end
- local conf = get_conf(character, model_id)
- if not conf then
- return 2 -- 系统异常
- end
- local list = skynet.call(act_rankinglist, "lua", "get_ranking", conf.ID)
- local ret = {
- errno = 0,
- list = {},
- }
- for k, v in ipairs(list) do
- if k <= 100 then
- ret.list[k] = v
- ret.list[k].num2 = nil
- ret.list[k].ranking = k
- else
- break
- end
- end
- return 0, ret
- end
- function REQUEST.act_rank_data(character, args)
- return func_ret("act_rank_data", character, args)
- end
- function CMD.syn_act_rank(character, id)
- local sign = can_upload(character, id)
- if sign then
- THIS.syn(character,id)
- end
- end
- return MODULE
|