| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- -- 活动 - 七日累充
- ActTotalRecharge = {}
- ActTotalRecharge.__index = ActTotalRecharge
- local function _rechargeType()
- return "1003"
- end
- local function _playerDbKey()
- return "T$act_recharge_days_total_data"
- end
- -- 获取活动奖励
- local function _get_reward_items(id)
- local reward = ConfigDataManager.getTableValue("cfg_Activity_firstRecharge", "reward", "id", id)
- jprint("七日累充活动奖励", id, reward)
- local tmp = string.toIntIntMap(reward, "#", "|")
- if table.notNullOrEmpty(tmp) then
- local list = {}
- for k, v in pairs(tmp) do
- table.insert(list, {id = k, count = v})
- end
- return list
- end
- return {}
- end
- function ActTotalRecharge.getData(actor)
- local var = getplaydef(actor, _playerDbKey())
- local data = setmetatable(var or {}, ActTotalRecharge)
- -- 累计充值
- if not data.count then
- data.count = 0
- end
- -- 已领取奖励id
- if not data.rewardList then
- data.rewardList = {}
- end
- -- 结束时间
- local currTime = getbaseinfo("nowsec")
- if not data.endTime or data.endTime <= currTime then
- ActTotalRecharge.onEnd(actor)
- local weekSecs = 3600 * 24 * 7
- local openTimeSec = math.ceil(getbaseinfo(actor, "serveropentime") / 1000)
- jprint("openTimeSec:", openTimeSec)
- local weeks = math.floor((currTime - openTimeSec) / weekSecs)
- data.endTime = openTimeSec + (weeks + 1) * weekSecs
- data.count = 0
- data.rewardList = {}
- setplaydef(actor, _playerDbKey(), data)
- end
- return data
- end
- -- 活动结束
- function ActTotalRecharge.onEnd(actor)
- -- 未领取奖励,邮件发放
- local var = getplaydef(actor, _playerDbKey())
- local data = setmetatable(var or {}, ActTotalRecharge)
- if data.count and data.count > 0 then
- jprint("ActTotalRecharge.onEnd count:", data.count)
- local playerCareer = tonumber(getbaseinfo(actor, "getbasecareer"))
- local mapItems = {}
- local confs = ConfigDataManager.getList("cfg_Activity_daysTotalRecharge")
- for i = 1, #confs do
- jprint("ActTotalRecharge.onEnd count:", data.count)
- jprint("ActTotalRecharge.onEnd id:", confs[i].id)
- jprint("ActTotalRecharge.onEnd recharge:", confs[i].recharge)
- jprint("ActTotalRecharge.onEnd reward:", confs[i].reward)
- if confs[i].recharge and confs[i].id then
- if
- data.count >= tonumber(confs[i].recharge) and
- not (data.rewardList and table.contains(data.rewardList, confs[i].id))
- then
- local tmp = string.toIntIntMap4Career(playerCareer, confs[i].reward, "#", "|")
- if table.notNullOrEmpty(tmp) then
- for k, v in pairs(tmp) do
- if not mapItems[k] then
- mapItems[k] = v
- else
- mapItems[k] = mapItems[k] + v
- end
- end
- end
- end
- end
- end
- if table.notNullOrEmpty(mapItems) then
- -- 发放补充奖励邮件
- sendconfigmailbyrid(actor, getbaseinfo(actor, "rid"), MailConfig.ACT_DAYS_RECHARGES, mapItems, "")
- end
- end
- end
- function ActTotalRecharge:saveData(actor)
- setplaydef(actor, _playerDbKey(), self)
- end
- ---充值回调触发事件
- function ActTotalRecharge.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
- jprint("更新[七日累充活动]数据 amount:", amount)
- local data = ActTotalRecharge.getData(actor)
- data.count = data.count + amount
- setplaydef(actor, _playerDbKey(), data)
- jprint("更新[七日累充活动]数据 count:", data.count)
- -- 前端同步累充金额
- ActTotalRecharge.sendModuleInfo(actor)
- end
- function ActTotalRecharge.gainReward(actor, reqParameter)
- local id = reqParameter["id"]
- local recharge = ConfigDataManager.getTableValue("cfg_Activity_daysTotalRecharge", "recharge", "id", id)
- if recharge == nil then
- tipinfo(actor, "无此档位")
- return
- end
- local data = ActTotalRecharge.getData(actor)
- -- 未充值
- if data.count < tonumber(recharge) then
- tipinfo(actor, "未达标")
- return
- end
- -- 已领取
- if data.rewardList and table.contains(data.rewardList, id) then
- tipinfo(actor, "已领取")
- return
- end
- -- 发放奖励
- local reward = ConfigDataManager.getTableValue("cfg_Activity_daysTotalRecharge", "reward", "id", id)
- local playerCareer = tonumber(getbaseinfo(actor, "getbasecareer"))
- local tmp = string.toIntIntMap4Career(playerCareer, reward, "#", "|")
- if table.notNullOrEmpty(tmp) then
- --奖励进入背包
- Bag.sendRewards(actor, tmp, "七日累充活动奖励")
- end
- -- 改变状态
- table.insert(data.rewardList, id)
- setplaydef(actor, _playerDbKey(), data)
- -- jprint("领奖豪礼数据",data)
- ActTotalRecharge.sendModuleInfo(actor)
- end
- -- 获取活动信息
- function ActTotalRecharge.getInfo(actor, msgData)
- ActTotalRecharge.sendModuleInfo(actor)
- end
- -- 推送活动模块数据
- function ActTotalRecharge.sendModuleInfo(actor, isStartShow)
- local data = ActTotalRecharge.getData(actor)
- jprint("ActTotalRecharge sendModuleInfo count:", data.count)
- sendluamsg(
- actor,
- LuaMessageIdToClient.RES_ACT_DAYS_RECHARGE_INFO,
- {
- count = data.count,
- rewardList = data.rewardList,
- endTime = data.endTime
- }
- )
- end
- function ActTotalRecharge.login(actor)
- ActTotalRecharge.sendModuleInfo(actor)
- end
- --TODO 一定要放到文件最后
- EventListerTable.registerType("七日累充活动", _rechargeType(), _playerDbKey())
- --注册充值事件
- RechargeEventListerTable:eventLister("0", "七日累充活动", ActTotalRecharge.rechargeEvent)
|