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)