----- ----- Created by zhouzhipeng. ----- DateTime: 2024/11/6 14:50 ----- Desc:炎狼兽礼包 ----- SingleGift = {} SingleGift.__index = SingleGift local this = {} --- 类型 local function _rechargeType() return "5" end local function _playerDbKey() return "T$single_gift_data" end function SingleGift.get(actor) local obj = getplaydef(actor, _playerDbKey()) return setmetatable(obj or {}, SingleGift) end function SingleGift:save(actor) setplaydef(actor, _playerDbKey(), self) end function SingleGift:getSingGiftInfo() if not self.singleGiftInfo then self.singleGiftInfo = {} end return self.singleGiftInfo end function SingleGift:getEndTimeById(cfgId) local singleGiftInfo = self:getSingGiftInfo() return singleGiftInfo[cfgId] or 0 end function SingleGift:setSingGiftCfgId(cfgId, endTime) local singleGiftInfo = self:getSingGiftInfo() singleGiftInfo[cfgId] = endTime end function SingleGift.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards) SingleGift.print(actor, "充值炎狼兽礼包", cfg_recharge, "购买数量", count, ext, outRewards) --local rechargeRecord = RechargeRecord.get(actor) --local buyCount = rechargeRecord:stallTotalCount(tonumber(cfg_recharge.id)) --if buyCount > 1 then -- tipinfo(actor, "该礼包已购买过") -- return --end local id = cfg_recharge.parameter local singleGiftCfg = ConfigDataManager.getById("cfg_recharge_singleItem", id) string.putIntIntMap(outRewards, singleGiftCfg['item'], "#", "|") end --- 请求充值档位信息 ---@param msgData table 请求参数 function SingleGift.reqRechargeAction(actor, rechargeType, action, reqParameter) if action == "panel" then SingleGift.queryData(actor, reqParameter) elseif action == "reward" then SingleGift.gainReward(actor, reqParameter) end end function SingleGift.queryData(actor, reqParameter) SingleGift.print(actor, "请求单次礼包信息", reqParameter) local nowMillis = getbaseinfo(actor, "now") local singleGiftData = SingleGift.get(actor) local singleGiftInfo = singleGiftData:getSingGiftInfo() local resData = {} local cfgIds = {} for cfgId, endTime in pairs(singleGiftInfo) do if nowMillis < endTime then local recId = ConfigDataManager.getTableValue("cfg_recharge", "id", "parameter", cfgId, "type", _rechargeType()) resData['rechargeId'] = recId resData['endTime'] = endTime table.insert(cfgIds, cfgId) end end if #cfgIds > 1 then jprint("单礼包,同时满足配置数据大于1条", cfgIds) end Recharge.resAction(actor, reqParameter.type, reqParameter.action, resData) end function SingleGift.gainReward(actor, reqParameter) end -- 登录处理 function SingleGift.login(actor) SingleGift.queryData(actor, { type = _rechargeType(), action = "panel" }) end --- 0点触发和升级都需要 function SingleGift.triggerSingleGift(actor, level) local singleGiftData = SingleGift.get(actor) local singleGiftCfgs = ConfigDataManager.getList("cfg_recharge_singleItem") if table.isNullOrEmpty(singleGiftCfgs) then jprint("炎狼兽礼包配置为空") return end local nowMillis = getbaseinfo(actor, "now") local isUpdate = false for _, cfg in pairs(singleGiftCfgs) do local cfgId = tonumber(cfg.id) local endTime = singleGiftData:getEndTimeById(cfgId) if endTime ~= 0 then goto continue end SingleGift.print("校验条件", cfg, "条件内容", cfg.condition) if not ConditionManager.Check(actor, cfg.condition) then SingleGift.print("校验条件 条件不满足", cfg, "条件内容", cfg.condition) goto continue end SingleGift.print("校验条件 条件满足", cfg, "条件内容", cfg.condition) local time = nowMillis + tonumber(cfg.time) singleGiftData:setSingGiftCfgId(cfgId, time) isUpdate = true SingleGift.print("设置配置与开启时间", cfgId, "时间", time) :: continue :: end if isUpdate then singleGiftData:save(actor) SingleGift.queryData(actor, { type = _rechargeType(), action = "panel" }) end end function singlegifttest(actor, type, id) gameDebug.print(actor, "炎狼兽礼包", id) --SingleGift.triggerSingleGift(actor) local singleGiftData = SingleGift.get(actor) local singleGiftInfo = singleGiftData:getSingGiftInfo() Recharge.request(actor, { rechargeId = id, count = 1, extraParams = {} }) SingleGift.print("炎狼兽gm测试内容", singleGiftInfo) end --- 打印日志 local isPrintLog = true function SingleGift.print(...) if isPrintLog then return end gameDebug.print(...) end EventListerTable.registerType("单个礼包", _rechargeType(), _playerDbKey()) -- 注册登录事件 LoginEventListerTable:eventLister("0", "单个礼包", SingleGift.login) -- 注册等级提升事件 LevelUpEventListerTable:eventLister("0", "单个礼包", SingleGift.triggerSingleGift) --注册凌晨刷新事件 ZeroEventListerTable:eventLister("0", "单个礼包", SingleGift.triggerSingleGift) -- 注册充值回调事件 RechargeEventListerTable:eventLister(_rechargeType(), "单个礼包", SingleGift.rechargeEvent) -- 注册商业化请求消息监听 RechargeMessageEventListerTable:eventLister(_rechargeType(), "单个礼包", SingleGift.reqRechargeAction)