123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- DailyDiamondGift = {}
- DailyDiamondGift.__index = DailyDiamondGift
- local this = {}
- --- 每日钻石礼包类型
- local function _rechargeType()
- return "15"
- end
- local function _playerDbKey()
- return "J$daily_diamond_gift_pack"
- end
- function DailyDiamondGift.get(actor)
- local obj = getplaydef(actor, _playerDbKey())
- return setmetatable(obj or {}, DailyDiamondGift)
- end
- function DailyDiamondGift:save(actor)
- setplaydef(actor, _playerDbKey(), self);
- end
- function DailyDiamondGift:setRecordIndex(rechargeId, index)
- if not self.dailyGiftInfo then
- self.dailyGiftInfo = {}
- end
- self.dailyGiftInfo[rechargeId] = index
- end
- function DailyDiamondGift:getRecordIndex(rechargeId)
- if not self.dailyGiftInfo then
- self.dailyGiftInfo = {}
- end
- return self.dailyGiftInfo[rechargeId] or 0
- end
- ---充值事件触发
- function DailyDiamondGift.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
- DailyDiamondGift.print(actor, "购买每日钻石礼包", cfg_recharge, "购买数量", count, ext, outRewards)
- if ext == "" then
- ext = {}
- end
- local dailyGiftId = cfg_recharge.parameter
- local rechargeType = cfg_recharge.type
- local giftCfg = ConfigDataManager.getById("cfg_diamondgiftbag", dailyGiftId)
- gameDebug.assertTrue(table.notNullOrEmpty(giftCfg), "没有配置每日钻石礼包", dailyGiftId)
- if not ConditionManager.Check(actor, giftCfg.conditionid) then
- tipinfo(actor, "购买条件不满足")
- return
- end
- local purchase = giftCfg.purchase
- local dailyDiamondGift = DailyDiamondGift.get(actor)
- if string.isNullOrEmpty(purchase) then
- local cfgs = ConfigDataManager.getTable("cfg_diamondgiftbag", "purchase", dailyGiftId)
- if not cfgs then
- tipinfo(actor, "一键购买配置错误")
- end
- -- 判断是否购买过单个礼包
- for _, cfg in pairs(cfgs) do
- if tonumber(cfg.price) == 0 then
- goto continue
- end
- local c = CountManager.getCount(actor, cfg["limited"])
- local buyCount = c.count
- if buyCount > 0 then
- tipinfo(actor, "购买过单个礼包")
- return
- end
- :: continue ::
- end
- gameDebug.assertTrue(table.notNullOrEmpty(cfgs), "没有一键购买每日钻石礼包配置", dailyGiftId)
- DailyDiamondGift.print("读取的配置", cfgs)
- -- 购买一键礼包
- for i = 1, #cfgs do
- local cfg = cfgs[i]
- if tonumber(cfg.price) == 0 then
- goto continue
- end
- local limited = cfg["limited"]
- local total = tonumber(ConfigDataManager.getTableValue("Count_count", "total", "id", limited))
- local index = ext[tonumber(cfg.id)] or 0
- for j = 1, total do
- DailyDiamondGift.print(actor, "购买一键礼包", cfg.id, "购买次数", j, "i", i, "ext", ext, "ext[e]", index)
- this.mergeItem(outRewards, cfg, index)
- end
- local recId = ConfigDataManager.getTableValue("cfg_recharge", "id", "parameter", cfg.id, "type", rechargeType)
- if index ~= 0 then
- dailyDiamondGift:setRecordIndex(recId, index)
- end
- CountManager.count(actor, limited, total)
- :: continue ::
- end
- else
- -- 购买单个礼包
- local index = ext[tonumber(giftCfg.id)] or 0
- this.mergeItem(outRewards, giftCfg, index)
- if index ~= 0 then
- dailyDiamondGift:setRecordIndex(cfg_recharge.id, index)
- end
- end
- dailyDiamondGift:save(actor)
- -- 发送界面信息数据
- dailyDiamondGift.queryData(actor, { type = rechargeType, action = "panel" })
- dailyDiamondGift.print(actor, "购买每日钻石礼包成功", cfg_recharge, "购买数量", count, ext, outRewards)
- end
- --- 请求充值档位信息
- ---@param msgData table 请求参数
- function DailyDiamondGift.reqRechargeAction(actor, rechargeType, action, reqParameter)
- if action == "panel" then
- DailyDiamondGift.queryData(actor, reqParameter)
- end
- end
- --- 每日钻石礼包信息
- function DailyDiamondGift.queryData(actor, reqParameter)
- DailyDiamondGift.print(actor, "请求每日钻石礼包信息", reqParameter)
- local rechargeType = reqParameter["type"]
- local dailyDiamondGifts = ConfigDataManager.getList("cfg_diamondgiftbag")
- gameDebug.assertTrue(table.notNullOrEmpty(dailyDiamondGifts), "没有配置充值档位")
- local resData = {}
- local group = 0
- local countInfo = {}
- local dailyDiamondGift = DailyDiamondGift.get(actor)
- DailyDiamondGift.print("配置表数据", dailyDiamondGifts)
- for _, cfg in pairs(dailyDiamondGifts) do
- if ConditionManager.Check(actor, cfg.conditionid) then
- local id = cfg.id
- local rechargeId = ConfigDataManager.getTableValue("cfg_recharge", "id", "parameter", id, "type", rechargeType)
- local index = dailyDiamondGift:getRecordIndex(rechargeId)
- countInfo[rechargeId] = index
- group = cfg.packagetype
- end
- end
- resData['group'] = group
- resData['countInfo'] = countInfo
- Recharge.resAction(actor, rechargeType, reqParameter.action, resData)
- end
- function this.mergeItem(outRewards, cfg, index)
- string.putIntIntMap(outRewards, cfg['rewards'], "#", "|")
- local optionalReward = cfg['optionalreward']
- if not string.isNullOrEmpty(optionalReward) then
- local strShuXian = string.split(optionalReward, "|")
- local strJinHao = strShuXian[index]
- DailyDiamondGift.print("合并奖励", cfg, "分隔好的", strShuXian, "根据索引选的", strJinHao, "索引", index)
- local str = string.split(strJinHao, "#")
- local itemCfgId = tonumber(str[1])
- local oldCount = outRewards[itemCfgId] or 0
- outRewards[itemCfgId] = oldCount + tonumber(str[2])
- end
- end
- --- 登录处理
- function DailyDiamondGift.login(play)
- DailyDiamondGift.queryData(play, { type = _rechargeType(), action = "panel" })
- end
- --- 零点处理
- function DailyDiamondGift.zero(play)
- DailyDiamondGift.queryData(play, { type = _rechargeType(), action = "panel" })
- end
- --- 打印日志
- local isPrintLog = false
- function DailyDiamondGift.print(...)
- if isPrintLog then
- return
- end
- gameDebug.print(...)
- end
- function dailydiamondgifttest(actor, id, type)
- gameDebug.print(actor, "请求每日钻石礼包", id)
- local tab
- if tonumber(type == 1) then
- tab = { [1] = 1 }
- else
- tab = { [1] = 1, [2] = 1, [3] = 1, [4] = 1 }
- end
- Recharge.request(actor, { rechargeId = id, count = 1, extraParams = tab })
- end
- EventListerTable.registerType("每日钻石礼包", _rechargeType(), _playerDbKey())
- -- 凌晨刷新事件
- ZeroEventListerTable:eventLister("0", "每日钻石礼包", DailyDiamondGift.zero)
- -- 注册登录事件
- LoginEventListerTable:eventLister("0", "每日钻石礼包", DailyDiamondGift.login)
- -- 注册充值回调事件
- RechargeEventListerTable:eventLister(_rechargeType(), "每日钻石礼包", DailyDiamondGift.rechargeEvent)
- -- 注册请求消息监听
- RechargeMessageEventListerTable:eventLister(_rechargeType(), "每日钻石礼包", DailyDiamondGift.reqRechargeAction)
|