--- --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by 無心道(15388152619). --- DateTime: 2024/10/29 13:50 --- Recharge = {} local this = {} ---相当于前端请求用代金卷充值 function Recharge.request(actor, msgData) local rechargeId = msgData["rechargeId"] local count = tonumber(msgData["count"] or 1) gameDebug.assertTrue(1 <= count and count < 9999, "购买数量异常:", count) local cfg_recharge = ConfigDataManager.getById("cfg_recharge", rechargeId) gameDebug.assertNil(cfg_recharge, "充值表找不到配置:", rechargeId) local cfgAmount = string.tonumber(cfg_recharge.amount) local costMap = {} local amount = 0; local costSource if cfgAmount > 0 then --查找代币的道具id local replaceItemId = ConfigDataManager.getTableValue( "cfg_item", "id", "type", ItemType.DRUG, "subType", ItemSubType.REPLACEMONEY ) gameDebug.assertNil(replaceItemId, "道具表代币配置查找失败:", "type", ItemType.DRUG, "subType", ItemSubType.REPLACEMONEY) amount = math.floor(cfgAmount * count) costMap[replaceItemId] = amount local name = ConfigDataManager.getTableValue("cfg_item", "name", "id", replaceItemId) costSource = "购买道具[".. name .."]消耗" else --扣除消耗道具 无需设置价格,消耗其他道具,价格就是0 local costStr = cfg_recharge["item"] if not string.isNullOrEmpty(costStr) then string.putIntIntMap(costMap, costStr, "#", "|") local itemNames for itemid, c in pairs(costMap) do local name = ConfigDataManager.getTableValue("cfg_item", "name", "id", itemid) itemNames = name .. "|" end itemNames = string.sub(itemNames, 1, -2) costSource = string.format("购买道具[%s]消耗", itemNames) end end if table.notNullOrEmpty(costMap) then local checkResult = Bag.checkCostMapBind(actor, costMap) if not checkResult then --背包道具不足 noticeTip.noticeinfo(actor, StringIdConst.TEXT346) return end Bag.costMapBind(actor, costMap, costSource) end local ext = msgData["extraParams"] or ""; this.OnRecharge0(actor, cfg_recharge, count, amount, ext) end function Recharge.OnRecharge(actor, rechargeData) info(actor, "收到充值请求", "actor", actor, "充值事件", rechargeData) local rechargeId = tonumber(rechargeData["goodsid"]) local count = tonumber(rechargeData["count"] or 1); gameDebug.assertTrue(1 <= count and count < 9999, "购买数量异常:", rechargeData) local amount = tonumber(rechargeData["amount"]); local cfg_recharge = ConfigDataManager.getById("cfg_recharge", rechargeId) gameDebug.assertNil(cfg_recharge, "充值表找不到配置:", rechargeId) local cfg_amount = tonumber(cfg_recharge["amount"] or 0) --if rechargeData["platformId"] == "11" then --暂时需求是所有渠道都要验证金额 gameDebug.assertTrue(cfg_amount * count == amount, "充值金额异常", rechargeData) --end local ext = rechargeData["extraParams"] or ""; this.OnRecharge0(actor, cfg_recharge, count, amount, ext) end function this.OnRecharge0(actor, cfg_recharge, count, amount, ext) local nowScc = getbaseinfo("nowsec") if count < 1 then return end -- 充值次数限制 if not Recharge.checkCount(actor, cfg_recharge, count) then return end local rechargeRecord = RechargeRecord.get(actor) --充值记录 rechargeRecord:addRecord(actor, cfg_recharge["id"], amount, count, nowScc) --保存数据 rechargeRecord:save(actor) --充值数据更新通知客户端 RechargeRecord.sendMsg(actor) -- 充值次数计数 CountManager.count(actor, cfg_recharge["countkey"], count) local reward_item = {} --触发充值类型事件监听 RechargeEventListerTable:triggerEvent(cfg_recharge["type"], actor, cfg_recharge, count, amount, ext, reward_item) --触发默认事件监听 RechargeEventListerTable:triggerEvent("0", actor, cfg_recharge, count, amount, ext, reward_item) local tmp = string.toIntIntMap(cfg_recharge.gain, "#", "|") for i = 1, count do table.mergeTable(reward_item, tmp) end if table.notNullOrEmpty(reward_item) then info("充值", actor, cfg_recharge["id"], cfg_recharge["name"], "奖励", reward_item) --奖励进入背包 Bag.sendRewards(actor, reward_item, "充值奖励") end end function Recharge.checkCount(actor, cfg_recharge, count) if cfg_recharge["countkey"] == "" then return true else local c = CountManager.getCount(actor, cfg_recharge["countkey"]) if c and c:canAdd(count) then return true end end info(actor, "玩家", actor, "充值次数已上限", "rechargeId", cfg_recharge["id"], "countKey", cfg_recharge["countkey"], "充值次数", count) return false end ---用于商业化相关的请求处理,统一的消息分发 function Recharge.requestAction(actor, msgData) local rechargeType = msgData["type"] local action = msgData["action"] RechargeMessageEventListerTable:triggerEvent(rechargeType, actor, rechargeType, action, msgData) end ---统一回复消息 function Recharge.resAction(actor, rechargeType, action, resData) local resMsg = {} resMsg.type = rechargeType resMsg.action = action resMsg.data = resData EventListerTable.print(actor, "商业化统一回复消息", resMsg) sendluamsg(actor, LuaMessageIdToClient.RES_RECHARGE_ACTION, resMsg) end