123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- MonthGiftPack = {}
- MonthGiftPack.__index = MonthGiftPack
- local this = {}
- this.type = {
- once = "1",
- batch = "2",
- }
- local function _rechargeType()
- return "14"
- end
- local function _zeroType()
- return "0"
- end
- local function _playerDbKey()
- return PlayerDefKey.monthGift.MONTH_GIFT_KEY
- end
- local function _dailyDbKey()
- return PlayerDefKey.monthGift.MONTH_GIFT_DAILY_KEY
- end
- function MonthGiftPack.getMonth(actor)
- local data = getplaydef(actor, _playerDbKey())
- return setmetatable(data or {}, MonthGiftPack)
- end
- function MonthGiftPack:saveMonth(actor)
- setplaydef(actor, _playerDbKey(), self)
- end
- function MonthGiftPack:addMonthRecord(gift_id)
- local month = self.month_data or {}
- month[gift_id] = getbaseinfo("now")
- self.month_data = month
- end
- function MonthGiftPack.getDaily(actor)
- local data = getplaydef(actor, _dailyDbKey())
- return setmetatable(data or {}, MonthGiftPack)
- end
- function MonthGiftPack:saveDaily(actor)
- setplaydef(actor, _dailyDbKey(), self)
- end
- function MonthGiftPack:addDailyRecord(gift_id)
- local daily = self.daily_data or {}
- table.insert(daily, gift_id)
- self.daily_data = daily
- end
- -- ------------------------------------------------------------- --
- function MonthGiftPack.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
- this.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
- end
- function MonthGiftPack.reqRechargeAction(actor, _, action, reqParameter)
- if action == "panel" then
- this.sendPanelData(actor, reqParameter)
- elseif action == "reward" then
- this.gainReward(actor, reqParameter)
- end
- end
- function MonthGiftPack.loginEvent(actor)
- this.sendPanelData(actor, this.buildParameter())
- end
- function MonthGiftPack.midnightEvent(actor)
- --this.sendPanelData(actor, this.buildParameter())
- intervalcalldelay(actor, 10000, 1000, 1, "delayflushmonthgiftpackpanel", this.buildParameter())
- end
- -- ------------------------------------------------------------- --
- function delayflushmonthgiftpackpanel(actor, reqParameter)
- this.sendPanelData(actor, reqParameter)
- end
- function this.sendPanelData(actor, reqParameter)
- local month_gift = MonthGiftPack.getMonth(actor)
- local daily_gift = MonthGiftPack.getDaily(actor)
- this.debug("---- month_gift ----", month_gift)
- local resData = {}
- local list = ConfigDataManager.getList("cfg_monthlypack")
- gameDebug.assertTrue(table.notEmpty(list), "没有配置月卡礼包")
- for _, config in pairs(list) do
- local count_key = ConfigDataManager.getTableValue(
- "cfg_recharge", "countkey", "type", _rechargeType(), "parameter", config.id)
- local count_data = CountManager.getCount(actor, count_key)
- if count_data and count_data.count < 1 then
- if table.notEmpty(month_gift.month_data) then
- month_gift.month_data[config.id] = nil
- month_gift:saveMonth(actor)
- end
- if table.notEmpty(daily_gift.daily_data) then
- table.removeByValue(daily_gift.daily_data, config.id)
- daily_gift:saveDaily(actor)
- end
- end
- :: continue ::
- end
- resData.month_data = month_gift.month_data
- resData.daily_data = daily_gift.daily_data
- Recharge.resAction(actor, _rechargeType(), reqParameter.action, resData)
- this.debug("--- 请求月卡礼包面板信息", reqParameter, resData)
- end
- function this.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
- this.debug("--- 购买月卡礼包 ---", cfg_recharge, count, amount, ext, outRewards)
- local gift_id = cfg_recharge.parameter
- local config = ConfigDataManager.getById("cfg_monthlypack", gift_id)
- gameDebug.assertTrue(table.notEmpty(config), "没有配置月卡礼包", gift_id)
- local is_pass = ConditionManager.Check(actor, config.condition)
- if not is_pass then
- tipinfo(actor, "月卡礼包购买条件不满足")
- return
- end
- local month_gift = MonthGiftPack.getMonth(actor)
- if config.monthlytype == this.type.once then
- this.rechargeOnce(actor, month_gift, config)
- else
- this.rechargeBatch(actor, month_gift, config)
- end
- this.jprint("--- 月卡礼包购买完成 ---")
- this.sendPanelData(actor, this.buildParameter())
- end
- function this.rechargeOnce(actor, month_gift, config)
- month_gift:addMonthRecord(config.id)
- month_gift:saveMonth(actor)
- local rewards = {}
- local reward_str = config.onerewards
- this.addItem2Bag(actor, rewards, reward_str)
- this.debug("--- 发放月卡返利礼包奖励 ---", reward_str, rewards)
- this.sendRewardPanel(actor, rewards, GameTips.Type.month_gift, config.id)
- end
- function this.rechargeBatch(actor, month_gift, config)
- if table.notEmpty(month_gift.month_data) then
- for k, _ in pairs(month_gift.month_data) do
- local cfg = ConfigDataManager.getById("cfg_monthlypack", k)
- if table.notEmpty(cfg) and cfg ~= config.id then
- tipinfo(actor, "您已经购买过其他礼包,无法批量购买")
- return
- end
- end
- end
- local cfg_list = ConfigDataManager.getTable("cfg_monthlypack", "monthlytype", this.type.once)
- gameDebug.assertTrue(table.notEmpty(config), "没有配置单次购买月卡礼包")
- local rewards = {}
- for _, cfg in pairs(cfg_list) do
- month_gift:addMonthRecord(cfg.id)
- local count_key = ConfigDataManager.getTableValue(
- "cfg_recharge", "countkey", "type", _rechargeType(), "parameter", cfg.id)
- CountManager.count(actor, count_key, 1)
- local reward_str = cfg.onerewards
- if not string.isNullOrEmpty(reward_str) then
- string.putIntIntMap(rewards, reward_str, "#", "|")
- end
- end
- month_gift:addMonthRecord(config.id)
- month_gift:saveMonth(actor)
- if table.notEmpty(rewards) then
- additemmaptobag(actor, rewards,0, 9999, '月卡礼包')
- this.sendRewardPanel(actor, rewards, GameTips.Type.month_gift, config.id)
- end
- end
- function this.gainReward(actor, reqParameter)
- local recharge_id = reqParameter["id"]
- this.jprint("-- 请求领取月卡每日礼包 --", recharge_id)
- local config = ConfigDataManager.getById("cfg_recharge", recharge_id)
- gameDebug.assertTrue(table.notEmpty(config), "没有配置充值档位", recharge_id)
- local gift_id = config.parameter
- local month_gift = MonthGiftPack.getMonth(actor)
- this.debug("---- month_gift ----", month_gift)
- local month_ids = month_gift.month_data or {}
- if not month_ids[gift_id] then
- this.debug("没有购买月卡礼包", config.countkey)
- return
- end
- local daily_gift = MonthGiftPack.getDaily(actor)
- local daily_ids = daily_gift.daily_data or {}
- if table.contains(daily_ids, gift_id) then
- this.debug("已经领取过月卡今日礼包", config.countkey)
- return
- end
- local gift_config = ConfigDataManager.getById("cfg_monthlypack", gift_id)
- gameDebug.assertTrue(table.notEmpty(gift_config), "没有配置礼包档位", gift_id)
- local rewards = {}
- local reward_str = gift_config.rewards
- this.addItem2Bag(actor, rewards, reward_str)
- this.sendRewardPanel(actor, rewards)
- this.debug("--- 发放月卡每日礼包奖励 ---", reward_str, rewards)
- daily_gift:addDailyRecord(gift_id)
- daily_gift:saveDaily(actor)
- this.sendPanelData(actor, this.buildParameter())
- this.jprint("--- 已领取月卡每日礼包 ---")
- end
- function this.buildParameter()
- return { type = _rechargeType(), action = "panel" }
- end
- function this.addItem2Bag(actor, rewards, reward_str)
- if not string.isNullOrEmpty(reward_str) then
- rewards = string.putIntIntMap(rewards, reward_str, "#", "|")
- additemmaptobag(actor, rewards, 0, 9999, '月卡礼包')
- end
- end
- function this.sendRewardPanel(actor, rewards, type, param)
- GameTips.sendGetRewardMsgWithParam(actor, rewards, type, param)
- end
- -- ------------------------------------------------------------- --
- this.log_open = true
- function this.debug(...)
- if not this.log_open then
- return
- end
- gameDebug.print(...)
- end
- function this.jprint(...)
- if not this.log_open then
- return
- end
- jprint(...)
- end
- -- ------------------------------------------------------------- --
- -- 礼包通用事件注册
- EventListerTable.registerType("月卡礼包", _rechargeType(), _playerDbKey())
- RechargeEventListerTable:eventLister(_rechargeType(), "月卡礼包", MonthGiftPack.rechargeEvent)
- RechargeMessageEventListerTable:eventLister(_rechargeType(), "月卡礼包", MonthGiftPack.reqRechargeAction)
- -- 系统事件注册
- LoginEventListerTable:eventLister(_zeroType(), "月卡礼包", MonthGiftPack.loginEvent)
- ZeroEventListerTable:eventLister(_zeroType(), "月卡礼包", MonthGiftPack.midnightEvent)
|