123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- --- 投资基金
- --- Generated by EmmyLua(https://github.com/EmmyLua)
- --- Created by 無心道(15388152619).
- --- DateTime: 2024/11/11 10:44
- InvestmentFunds = {}
- InvestmentFunds.__index = InvestmentFunds
- local this = {}
- local function __rechargeType()
- return "10"
- end
- local function __playerDbKey()
- return "T$investment_funds_data"
- end
- function InvestmentFunds.get(actor)
- local obj = getplaydef(actor, __playerDbKey())
- return setmetatable(obj or {}, InvestmentFunds)
- end
- function InvestmentFunds:save(actor)
- setplaydef(actor, __playerDbKey(), self);
- end
- ---购买分组
- function InvestmentFunds:getGroup()
- return self["group"] or 1;
- end
- ---购买时间
- function InvestmentFunds:getBuyTime()
- return self["buyTime"] or 0;
- end
- ---购买天数,尚未购买是0
- function InvestmentFunds:getBuyDay(nowSec)
- local buyTime = self:getBuyTime()
- if buyTime == 0 then
- return 0
- end
- return TimeUtil.diffDays(buyTime, nowSec) + 1
- end
- ---购买时间
- function InvestmentFunds:getRewards()
- return self["rewards"] or {};
- end
- function InvestmentFunds:buy(nowSec)
- self["buyTime"] = nowSec --购买时间
- self["rewards"] = { } --购买时间
- end
- ---设置标记下一组
- function this.nextGroup(self, actor)
- local group = tonumber(self["group"] or 0) + 1
- local cfgList = ConfigDataManager.getTable("cfg_investmentfunds", "groupid", group)
- if table.isNullOrEmpty(cfgList) then
- --说明没有找到下一组
- return
- end
- self["group"] = group;
- self["buyTime"] = 0 --更新最好一次购买时间
- self["rewards"] = {};
- self:save(actor)
- info(actor, "玩家", actor, "投资基金切换到下一组:", group)
- end
- ---充值事件触发
- function this.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
- local data = InvestmentFunds.get(actor)
- local var = cfg_recharge["type"]
- if var ~= __rechargeType() then
- --类型不一致不处理
- print("类型不一致不处理", var)
- return
- end
- local parameter = cfg_recharge["parameter"]
- local group = data:getGroup()
- if group ~= tonumber(parameter) then
- info(actor, "玩家", actor, "数据错误,无法购买", group)
- return
- end
- local parameter = cfg_recharge["parameter"]
- local nowSec = getbaseinfo("nowsec")
- gameDebug.assertTrue(data:getBuyTime() == 0, "投资基金已经购买过了", parameter)
- data:buy(nowSec)
- data:save(actor)
- info(actor, "玩家", actor, "购买投资基金", group)
- this.sendPanel(actor)
- end
- function this.reqAction(actor, type, action, reqParameter)
- if action == "panel" then
- this.sendPanel(actor)
- elseif action == "reward" then
- this.reward(actor, reqParameter)
- elseif action == "buy" then
- end
- end
- function this.reward(actor, reqParameter)
- local data = InvestmentFunds.get(actor)
- local group = data:getGroup()
- local nowSec = getbaseinfo("nowsec")
- local id = reqParameter["id"]
- local cfg = ConfigDataManager.getById("cfg_investmentfunds", id)
- gameDebug.assertNil(cfg, "cfg_investmentfunds 数据错误", id)
- gameDebug.assertTrue(ConditionManager.Check(actor, cfg["conditionid"]), "条件未达成")
- local cfgGroup = cfg["groupid"]
- if tonumber(cfgGroup) ~= group then
- tipinfo(actor, "数据错误,无法领取")
- return
- end
- local buyDay = data:getBuyDay(nowSec)
- local cfgDay = tonumber(cfg["day"])
- if cfgDay > buyDay then
- tipinfo(actor, "基金还未到领取时间")
- return
- end
- local rewards = data:getRewards()
- local checkRewards = table.contains(rewards, id)
- if checkRewards then
- tipinfo(actor, "已经领取过该奖励")
- return
- end
- table.insert(rewards, id)
- data:save(actor)
- info(actor, "玩家", actor, "投资基金", group, "领取奖励:", id)
- --发放奖励到背包
- Bag.sendRewards4String(actor, cfg["rewards"], "投资基金")
- Recharge.resAction(actor, __rechargeType(), "reward", { id = id })
- if this.checkNext(data, actor) then
- this.sendPanel(actor)
- end
- end
- function this.sendPanel(actor)
- local nowSec = getbaseinfo("nowsec")
- local data = InvestmentFunds.get(actor)
- local group = data:getGroup()
- local cfgList = ConfigDataManager.getTable("cfg_investmentfunds", "groupid", group)
- if table.isEmpty(cfgList) then
- print(actor, "投资基金没有配置数据", group)
- return
- end
- local cfgCount = table.count(cfgList)
- local _buyDay = data:getBuyDay(nowSec)
- local resInfo = {
- group = group,
- buyDay = _buyDay > cfgCount and cfgCount or _buyDay, --这个时间跟客户端的小红点有关系
- rewards = data:getRewards()
- }
- Recharge.resAction(actor, __rechargeType(), "panel", resInfo)
- end
- function this.checkNext(self, actor)
- local group = InvestmentFunds.getGroup(self)
- local nowSec = getbaseinfo("nowsec")
- local cfgList = ConfigDataManager.getTable("cfg_investmentfunds", "groupid", group)
- local cfgCount = table.count(cfgList)
- local buyDay = InvestmentFunds.getBuyDay(self, nowSec)
- if buyDay <= cfgCount then
- --根据领奖数量,判断是否可以领取下一组
- return
- end
- local rewards = self:getRewards()
- if cfgCount <= table.count(rewards) then
- this.nextGroup(self, actor)
- return true
- end
- return false
- end
- ---登录监听事件
- function this.onLogin(actor)
- local data = InvestmentFunds.get(actor)
- if data["group"] == nil then
- this.nextGroup(data, actor)
- end
- this.checkNext(data, actor)
- this.sendPanel(actor)
- end
- EventListerTable.registerType("投资基金", __rechargeType(), __playerDbKey())
- --注册登录事件
- LoginEventListerTable:eventLister("0", "投资基金", this.onLogin)
- --注册凌晨刷新事件
- ZeroEventListerTable:eventLister("0", "投资基金", this.onLogin)
- --充值回调,不关心类型
- RechargeEventListerTable:eventLister(__rechargeType(), "投资基金", this.rechargeEvent)
- --请求事件
- RechargeMessageEventListerTable:eventLister(__rechargeType(), "投资基金", this.reqAction)
|