123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- FirstRecharge = {}
- local FirstRechargeConst = {
- RECHARGE_STAGE = "T$RechargeStage",
- RECHARGE_RECORD = "T$RechargeRecord",
- }
- -- 玩家充值
- function FirstRecharge.Recharge(actor, msg)
- local money = msg.money -- 本次充值金额
- local tables = ConfigDataManager.getList("cfg_first_recharge")
- if not tables or next(tables) == nil then
- error("首充配置表不存在")
- end
- local preTotalMoney = FirstRecharge.GetTotalMoney(actor,false)
- local totalMoney = preTotalMoney + money
- local num = tonumber(0)
- local tableIds = {}
- for _, cfg in ipairs(tables) do
- local amount = tonumber(cfg.amount)
- local id = tonumber(cfg.id)
- if amount >= num and amount <= totalMoney then
- num = amount
- end
- table.insert(tableIds, id)
- end
- if num == 0 then
- -- 没有达到首充条件
- FirstRecharge.RecordHistory(actor, money)
- return
- end
- local cfg = ConfigDataManager.getTable("cfg_first_recharge", "amount", num)[1]
- local tableId = tonumber(cfg.id)
- local runDay = tonumber(cfg.runday)
- local severOpenDays = getbaseinfo(actor, "serveropendays")
- if runDay > severOpenDays then
- error("开服天数不足")
- return
- end
- -- 过滤掉发过的和达不到的,发奖励
- local stage = FirstRecharge.GetRechargeStage(actor, false)
- stage = tonumber(stage)
- for _, id in ipairs(tableIds) do
- if id > stage and id <= tableId then
- -- 发放奖励
- local reward = ConfigDataManager.getTableValue("cfg_first_recharge", "reward", "id", id)
- if reward and reward ~= "" then
- local rewardStrList = string.splitByAll(reward, "|")
- for _, value in ipairs(rewardStrList) do
- local parts = string.splitByAll(value, "#")
- local itemId = parts[1]
- local count = parts[2]
- additemtobag(actor, tonumber(itemId), tonumber(count))
- end
- end
- end
- end
- if stage == 0 then
- -- todo之前没有充值过,首充武器奖励,item要提前生成,如何放置?
- end
- FirstRecharge.RecordStage(actor, tableId)
- FirstRecharge.RecordHistory(actor, money)
- sendluamsg(actor, 00000, { tableId })
- end
- -- 记录充值阶段
- function FirstRecharge.RecordStage(actor, tableId)
- local stage = getplaydef(actor, FirstRechargeConst.RECHARGE_STAGE) or 0
- if tonumber(stage) < tableId then
- setplaydef(actor, FirstRechargeConst.RECHARGE_STAGE, tableId)
- end
- end
- -- 记录充值金额记录
- function FirstRecharge.RecordHistory(actor, money)
- local records = getplaydef(actor, FirstRechargeConst.RECHARGE_RECORD) or {}
- local tamp = getbaseinfo(actor, "now")
- records[tamp] = money
- setplaydef(actor, FirstRechargeConst.RECHARGE_RECORD, records)
- end
- -- 获取总充值金额
- function FirstRecharge.GetTotalMoney(actor, isClient)
- local record = getplaydef(actor, FirstRechargeConst.RECHARGE_RECORD) or {}
- if next(record) ~= nil then
- local total = 0
- for tamp, money in pairs(record) do
- total = total + money
- end
- if isClient then
- sendluamsg(actor, 00000, { total })
- else
- return total
- end
- end
- if isClient then
- sendluamsg(actor, 00000, { 0 })
- else
- return 0
- end
- end
- -- 获取最高充值档次
- function FirstRecharge.GetRechargeStage(actor, isClient)
- local maxRecord = getplaydef(actor, FirstRechargeConst.RECHARGE_STAGE)
- if not maxRecord then
- if isClient then
- sendluamsg(actor, 00000, { 0 })
- else
- return 0
- end
- end
- if isClient then
- sendluamsg(actor, 00000, { maxRecord })
- else
- return maxRecord
- end
- end
- -- =================测试===================
- function testrecharge(actor, money)
- local msg = {
- money = money
- }
- FirstRecharge.Recharge(actor, msg)
- end
- function clearracharge(actor)
- setplaydef(actor, FirstRechargeConst.RECHARGE_STAGE, 0)
- setplaydef(actor, FirstRechargeConst.RECHARGE_RECORD, {})
- end
|