--- 每日馈赠,每日礼包 --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by 無心道(15388152619). --- DateTime: 2024/11/11 10:44 DailyGiveaway = {} DailyGiveaway.__index = DailyGiveaway local this = {} local function __rechargeType() return "13" end local function __playerDbKey() return "T$daily_giveaway_data" end function DailyGiveaway.get(actor) local obj = getplaydef(actor, __playerDbKey()) return setmetatable(obj or {}, DailyGiveaway) end function DailyGiveaway:save(actor) setplaydef(actor, __playerDbKey(), self); end ---设置标记下一组 function DailyGiveaway:nextGroup(actor) local group = tonumber(self["group"] or 0) + 1 if table.isNullOrEmpty(ConfigDataManager.getTable("cfg_everydaygift_recharge", "round", group)) then if table.notEmpty(ConfigDataManager.getTable("cfg_everydaygift_recharge", "round", 1)) then --策划说需要循环,如果没有下一组直接切换到第一组 group = 1; else --说明没有找到下一组 return end end self["group"] = group; self["buyTime"] = 0 --更新最好一次购买时间 self["buyDay"] = 0 --记录购买天数 self["rewards"] = {}; self:save(actor) info(actor, "玩家", actor, "每日馈赠切换到下一组:", group) end ---购买分组 function DailyGiveaway:getGroup() return self["group"] or 1; end ---购买时间 function DailyGiveaway:getBuyTime() return self["buyTime"] or 0; end ---购买天数 function DailyGiveaway:getBuyDay() return self["buyDay"] or 0; end ---已经领取过的奖励 function DailyGiveaway:getRewards() if self["rewards"] == nil then self["rewards"] = {} end return self["rewards"]; end ---免费礼包领取时间 function DailyGiveaway:getDayFreeGift() return self["dayFreeGift"] or 0; end ---免费礼包领取时间 function DailyGiveaway:setDayFreeGift(nowSec) self["dayFreeGift"] = nowSec; end ---更新购买时间 function DailyGiveaway:buy(nowSec) self["buyTime"] = nowSec --更新最后一次购买时间 self["buyDay"] = tonumber(self["buyDay"] or 0) + 1 --记录购买天数 end ---充值事件触发 function this.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards) local data = DailyGiveaway.get(actor) if not this.checkOpen(data, actor) then return end local parameter = cfg_recharge["parameter"] local nowSec = getbaseinfo("nowsec") local cfg_recharge_type = cfg_recharge["type"] if cfg_recharge_type == __rechargeType() and data:getGroup() == tonumber(parameter) then -- todo 判断充值类型 发送礼包奖励 end local cfgList = ConfigDataManager.getTable("cfg_everydaygift_recharge", "round", data:getGroup()) if table.isNullOrEmpty(cfgList) then return end local cfgOne = cfgList[2]--取第二条数据,因为第一条是免费礼包 --每天充值的金额 local dailyTotalMoney = RechargeRecord.getDailyTotalMoney(actor) if dailyTotalMoney < tonumber(cfgOne["needcost"]) then return --累充金额不满足条件 end if TimeUtil.isSameDay(data:getBuyTime(), nowSec) then return --是同一天说明已经处理过了 end data:buy(nowSec) data:save(actor) this.sendPanel(actor) info(actor, "每日馈赠购买记录", actor, "购买分组:", data:getGroup(), "购买天数:", data:getBuyDay()) end function this.reqAction(actor, type, action, reqParameter) if action == "panel" then this.sendPanel(actor) elseif action == "reward" then this.reward(actor, reqParameter) end end function this.reward(actor, reqParameter) local data = DailyGiveaway.get(actor) if not this.checkOpen(data, actor) then return end local id = tonumber(reqParameter["id"]) local nowSec = getbaseinfo("nowsec") local buyDay = data:getBuyDay() local rewards = data:getRewards() local cfg = ConfigDataManager.getById("cfg_everydaygift_recharge", id) gameDebug.assertNil(cfg, "配置不存在", id) local group = data:getGroup() if tonumber(cfg["round"]) ~= group then tipinfo(actor, "当前分组未开放领取") return end if buyDay < tonumber(cfg["sort"]) then tipinfo(actor, "不满足条件") return end if cfg["sort"] == "0" then if TimeUtil.isSameDay(data:getDayFreeGift(), nowSec) then tipinfo(actor, "免费礼包已经领取") return end data:setDayFreeGift(nowSec) else local checkRewards = table.contains(rewards, id) if checkRewards then tipinfo(actor, "已经领取过该奖励") return end table.insert(rewards, id) end info(actor, "玩家", actor, "每日馈赠", group, "领取奖励:", id) --存储数据 data:save(actor) -- 发送奖励 Bag.sendRewards4CareerString(actor, cfg["gift"], "每日馈赠") this.checkNext(data, actor) this.sendPanel(actor) end function this.sendPanel(actor) local data = DailyGiveaway.get(actor) if not this.checkOpen(data, actor) then return end local nowSec = getbaseinfo("nowsec") local resInfo = { group = data:getGroup(), --分组 第几轮 buyDay = data:getBuyDay(), --本轮购买天数 rewards = data:getRewards(), --已经领取过的奖励ID todayBuy = TimeUtil.isSameDay(data:getBuyTime(), nowSec), --今日是否购买 dayFreeGift = TimeUtil.isSameDay(data:getDayFreeGift(), nowSec), --今日免费礼包是否已经领取 } Recharge.resAction(actor, __rechargeType(), "panel", resInfo) end function this.checkNext(data, actor) if not this.checkOpen(data, actor) then return end local cfgList = ConfigDataManager.getTable("cfg_everydaygift_recharge", "round", data:getGroup()) local cfgCount = table.count(cfgList) - 1 -- 扣除一个免费礼包 local nowSec = getbaseinfo("nowsec") local buyDay = DailyGiveaway.getBuyDay(data) if buyDay >= cfgCount and TimeUtil.isSameDay(DailyGiveaway.getBuyTime(data), nowSec) == false then --购买天数满足条件,且不是同一天 DailyGiveaway.nextGroup(data, actor) end end ---登录监听事件 function this.onLogin(actor) local data = DailyGiveaway.get(actor) if not this.checkOpen(data, actor) then return end if data["group"] == nil then data:nextGroup(actor) end local nowSec = getbaseinfo("nowsec") local buyDay = data:getBuyDay() if buyDay > 0 then --购买的第二天上线检查前一天的奖励是否领取,没有领取的话,自动发邮件 local rewards = data:getRewards() --职业 local career = getbaseinfo(actor, "getbasecareer") for i = 1, buyDay do if i < buyDay or (not TimeUtil.isSameDay(data:getBuyTime(), nowSec)) then local cfg = ConfigDataManager.getTableFirst("cfg_everydaygift_recharge", "round", data:getGroup(), "sort", i) if cfg then local intId = tonumber(cfg["id"]) if not table.contains(rewards, intId) then table.insert(rewards, intId) data:save(actor) local sendReward = string.toIntIntMap4Career(career, cfg["gift"], "#", "|") info(actor, "每日馈赠昨日未领取奖励发送邮件", actor, data:getGroup(), intId, sendReward) sendconfigmailbyrid(actor, actor:toString(), tonumber(cfg["mail"]), sendReward, "") end end end end this.checkNext(data, actor) end this.sendPanel(actor) end function this.checkOpen(data, actor) local inshowCondition = ConfigDataManager.getTableValue("sub_mainRecharge", "inshowCondition", "id", 6) if not ConditionManager.Check(actor, inshowCondition) then return false end local cfgList = ConfigDataManager.getTable("cfg_everydaygift_recharge", "round", data:getGroup()) if table.isEmpty(cfgList) then return false end return true end EventListerTable.registerType("每日馈赠", __rechargeType(), __playerDbKey()) --注册登录事件 LoginEventListerTable:eventLister("0", "每日馈赠", this.onLogin) --注册凌晨刷新事件 ZeroEventListerTable:eventLister("0", "每日馈赠", this.onLogin) --充值回调,不关心类型 RechargeEventListerTable:eventLister("0", "每日馈赠", this.rechargeEvent) --请求事件 RechargeMessageEventListerTable:eventLister(__rechargeType(), "每日馈赠", this.reqAction)