123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- --获取限时活动时间
- local skynet = require "skynet"
- local logger = require "logger"
- local stringify = require "stringify"
- local schema = require "model.schema"
- local asset = require "model.asset"
- local common_fun = require "model.common_fun"
- local REQUEST = {}
- local CMD = {}
- local activitytime = {}
- local activity = skynet.localname(".activitytime")
- local activitylist = {
- }
- local _M = schema.new('activitytimemod', {
- activity_token = { --所有活动的token
- --[[
- [activity_type] = {
- state = STATE_CLOSE,
- activity_type = 活动类型,
- sid = 活动sid,
- opentime = 活动开启时间,
- endtime = 活动结束时间,
- activity_type = 活动开启类型,
- switch = 1 活动临时开关
- }
- ]]
- },
- })
- local THIS = {}
- local function func_ret(fname, character, args)
- 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
- function activitytime.list_request_interests() return REQUEST end
- function activitytime.list_command_interests() return CMD end
- function activitytime.parse(character) _M.load(character) end
- -- TODO: 处理活动状态切换
- --[[
- activity_data_time: 开启活动数据
- ]]
- local function jqui_activity(character, activity_data_time)
- local d = _M.assert_get(character)
- local player_activ = d.activity_token
- local save_token = false
- -- 通知活动更新
- local function open_update(key, vey)
- local ok, info_add = xpcall(activitytime.open, debug.traceback, character, key, vey)
- if ok then
- player_activ[key] = info_add
- save_token = true
- logger.test("activitytimemod open_update. atype:%s ok:%s, info_add:%s",key,ok, stringify(info_add))
- else
- logger.test("activitytimemod open_update err. atype:%s ok:%s, info_add:%s",key,ok, info_add)
- end
- return ok
- end
- -- 活动继开 不清除玩家老的数据
- local function continue_open_update(key, vey)
- local ok, info_add = xpcall(activitytime.continue_open, debug.traceback, character,key,vey)
- if ok then
- player_activ[key] = info_add
- save_token = true
- logger.test("activitytimemod continue_open_update atype:%s ok:%s, info_add:%s",key,ok, stringify(info_add))
- else
- logger.test("activitytimemod continue_open_update err atype:%s ok:%s, info_add:%s",key,ok, info_add)
- end
- return ok
- end
- -- 活动关闭
- local function close_update(key, vey)
- local ok, str = xpcall(activitytime.close, debug.traceback,character, key, vey)
- if ok then
- player_activ[key].state = STATE_CLOSE
- save_token = true
- logger.test("activitytimemod close_update atype:%s ok:%s.",key, ok)
- else
- logger.test("activitytimemod close_update err atype:%s ok:%s, str:%s",key, ok, str)
- end
- return ok
- end
- -- 已存在活动对比
- local function compare_info(atype, ainfo, pinfo)
- local ok
- if pinfo.sid ~= ainfo.sid then -- 活动id变化
- -- 先通知关闭
- if pinfo.state == STATE_OPEN then
- ok = close_update(atype, pinfo)
- if not ok then
- return ok
- end
- end
- -- 再通知开启
- ok = open_update(atype, ainfo)
- else
- if pinfo.state == STATE_CLOSE then
- ok = continue_open_update(atype, ainfo) -- 活动续开
- else
- ok = true
- end
- end
- return ok
- end
- local err_type = {} -- 活动处理过程出现异常的活动
- -- TODO: 活动处理主流程
- for _, ainfo in pairs(activity_data_time) do
- -- 玩家数据对比 新传入活动数据
- local atype = ainfo.activity_type -- 传入活动类型
- local pinfo = player_activ[atype]
- local ok
- if not pinfo then -- 新增活动
- ok = open_update(atype,ainfo)
- else -- 老活动的处理
- -- 对比玩家数据
- ok = compare_info(atype, ainfo, pinfo)
- end
- if not ok then
- err_type[atype] = atype
- end
- end
- local del_close = {}
- -- 对比玩家数据
- for _, sinfo in pairs(d.activity_token) do
- local stype = sinfo.activity_type
- -- 玩家有得活动, 传入数据没有, 活动已经关闭
- if not activity_data_time[stype] and sinfo.state ~= STATE_CLOSE then
- logger.test(" == 关闭得活动 %s",stype)
- if close_update(stype,sinfo) then -- 通知活动关闭
- del_close[stype] = sinfo
- else
- err_type[stype] = stype
- end
- end
- end
- logger.test(" -- 玩家对比传入数据后, 已经关闭得活动 %s", stringify(del_close))
- if next(err_type or {}) then
- logger.warn(" 活动处理异常的活动: %s", stringify(err_type))
- end
- -- 是否有活动发生改变
- if save_token then
- _M.persist(character)
- end
- end
- function activitytime.launch(character)
- end
- local function project(character, finishtime_data)
- if finishtime_data and next(finishtime_data) then
- local finishtime_new = {}
- for k, v in pairs(finishtime_data) do
- local state = v.state
- if activitylist[v.activity_type] and activitylist[v.activity_type].check_over then
- if activitylist[v.activity_type].check_over(character) then
- state = STATE_OVER
- end
- end
- logger.test("activitytimemod --- 活动数据:%s,%s", k,stringify(v))
- if v.switch == 1 then -- 关闭
- local temp = {
- type = v.activity_type,
- state = state,
- opentime = v.opentime,
- endtime = v.endtime,
- name = v.name,
- sort = v.sort,
- icon = v.icon,
- }
- table.insert(finishtime_new,temp)
- end
- end
- return finishtime_new
- end
- end
- function activitytime.ready(character)
- local activity_finishtime = skynet.call(activity, "lua", "getactivitytime")
- jqui_activity(character, activity_finishtime)--将活动状态分发下去
- local finishtime = project(character, activity_finishtime)
- character.send("activity_time_list_nty",{list = finishtime})
- local d = _M.assert_get(character)
- logger.test("%s:ready, %s", "activitytime", stringify(d or {}))
- end
- function activitytime.saybye(character)
- end
- -- TODO: 规范数据处理
- local function set_activi_player(ainfo)
- return {
- state = ainfo.state,
- activity_type = ainfo.activity_type,
- sid = ainfo.sid,
- opentime = ainfo.opentime,
- endtime = ainfo.endtime,
- open_type = ainfo.open_type,
- }
- end
- -- TODO: 活动开启
- function activitytime.open(character,key,ainfo)
- activitylist[key].open(character,ainfo)
- return set_activi_player(ainfo)
- end
- -- TODO: 活动续开
- function activitytime.continue_open(character,key,ainfo)
- if activitylist[key] and activitylist[key].continue_open then
- activitylist[key].continue_open(character,ainfo)
- end
- return set_activi_player(ainfo)
- end
- function activitytime.close(character, key, pinfo)
- activitylist[key].close(character, pinfo)
- end
- function CMD.update(character,finishtime)--活动开始
- logger.test("activitytimemod 开始更新活动配置时间\n:%s",stringify(finishtime))
- jqui_activity(character, finishtime)
- character.send("activity_time_list_nty",{list = project(character, finishtime)})
- end
- function activitytime.get_conf(character, model_id)
- local d = _M.assert_get(character)
- local sid = d.activity_token[model_id] and d.activity_token[model_id].sid
- if sid then
- return asset.ActivityConfig_proto[sid]
- end
- end
- function activitytime.get_state(character, model_id)
- local d = _M.assert_get(character)
- local sid = d.activity_token[model_id] and d.activity_token[model_id].sid
- if sid then
- return d.activity_token[model_id].state
- end
- return STATE_CLOSE
- end
- function activitytime.get_info(character, model_id)
- local d = _M.assert_get(character)
- local sid = d.activity_token[model_id] and d.activity_token[model_id].sid
- return d.activity_token[model_id]
- end
- function THIS.activity_get_conf_list(character, args)
- if not args.list then
- return 1 -- 参数异常
- end
- local list = {}
- local d = _M.assert_get(character)
- for _, v in ipairs(args.list) do
- local atype = tonumber(v)
- if atype then
- local data = d.activity_token[atype]
- logger.trace("data:"..stringify(data or {}))
- if data and data.state == STATE_OPEN then
- local conf = asset.ActivityConfig_proto[data.sid]
- local temp = {
- type = atype,
- describe = conf.describe,
- parameter1 = conf.parameter1,
- parameter2 = conf.parameter2,
- parameter3 = conf.parameter3,
- }
- for _, award_id in ipairs(conf.reward)do
- if award_id <= 0 then
- break
- end
- local _, list = common_fun.get_award(award_id,"NewawardConfig_proto")
- if list then
- temp.reward_list = temp.reward_list or {}
- table.insert(temp.reward_list, {
- id = award_id,
- list = list,
- })
- end
- end
- for _, gift_id in ipairs(conf.gift) do
- if gift_id <= 0 then
- break
- end
- local gift_conf = asset.GiftConfig_proto[gift_id]
- if gift_conf then
- temp.gift_list = temp.gift_list or {}
- table.insert(temp.gift_list, {
- ID = gift_conf.ID,
- library = gift_conf.library,
- sort = gift_conf.sort,
- spendtype = gift_conf.spendtype,
- spend = gift_conf.spend,
- num = gift_conf.num,
- daylimit = gift_conf.daylimit,
- weeklimit = gift_conf.weeklimit,
- video = gift_conf.video,
- icon = gift_conf.icon,
- parameter = gift_conf.parameter,
- })
- end
- end
- table.insert(list, temp)
- end
- end
- end
- return 0, {list = list}
- end
- function REQUEST.activity_get_conf_list(character, args)
- return func_ret("activity_get_conf_list", character, args)
- end
- return activitytime
|