123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- --- 运营累充
- AccumulatedRecharge = { }
- AccumulatedRecharge.__index = AccumulatedRecharge
- local this = {}
- local function _rechargeType()
- return "17"
- end
- local function _playerDbKey()
- return "T$OPERATION_ACCUMULATED_RECHARGE"
- end
- function AccumulatedRecharge.get(actor)
- local obj = getplaydef(actor, _playerDbKey())
- return setmetatable(obj or {}, AccumulatedRecharge)
- end
- function AccumulatedRecharge:save(actor)
- setplaydef(actor, _playerDbKey(), self);
- end
- local STATISTICS_TYPE = {
- ALL = 0,
- ACTIVE = 1,
- }
- --- 请求充值档位信息
- function AccumulatedRecharge.reqRechargeAction(actor,mainGroup)
- -- 判断当前主活动是否开启了子直购活动
- local activity = {}
- local allActivityInfo = {}
- local operateActivityTable = ConfigDataManager.getList("cfg_rechargeRccrued")
- if table.isNullOrEmpty(operateActivityTable) then
- return allActivityInfo
- end
- local type = 0
- for _, config in pairs(operateActivityTable) do
- if tonumber(mainGroup) == tonumber(config.maingroup) then
- type = tonumber(config.type)
- local accumulatedId = config.id
- local itemCount = config.itemcount
- local rewardsMap = string.toIntIntMap(itemCount, "#", "|")
- local activityInfo = {
- accumulatedId = accumulatedId,
- itemInfo = rewardsMap
- }
- CountManager.getCount(actor, config.countkey)
- table.insert(allActivityInfo,activityInfo)
- end
- end
- activity["panel"] = allActivityInfo
- local money = this.totalMoney(actor,type)
- activity["money"] = money
- return activity
- end
- --- 触发充值
- function AccumulatedRecharge.rechargeEvent(actor, cfg_recharge, count, amount, ext, outRewards)
- this.debug("购买直购礼包", cfg_recharge, "购买数量", count, ext, outRewards)
- this.saveMoney(actor,amount)
- OperationalActivities.openSubActive(actor,{
- subType = ACTIVE_TYPE.TOTAL_RECHARGE
- })
- end
- function AccumulatedRecharge.reqAction(actor, rechargeType, action, reqParameter)
- if action == "reward" then
- local directGiftId = reqParameter["id"]
- local config = ConfigDataManager.getById("cfg_rechargeRccrued", directGiftId)
- local mainGroup = OperationalActivities.getCurrentMainGroup(actor)
- local cfgMainGroup = config.maingroup
- if mainGroup ~= tonumber(cfgMainGroup) then
- return
- end
- local count = CountManager.getCount(actor, config.countkey)
- local total = ConfigDataManager.getTableValue("Count_count","total","id",config.countkey)
- if count.count >= tonumber(total) then
- return
- end
- this.sendReward(actor,config)
- CountManager.count(actor, config.countkey,1)
- end
- OperationalActivities.openSubActive(actor,{
- subType = ACTIVE_TYPE.TOTAL_RECHARGE
- })
- end
- -- 保存当前充值的钱
- function this.saveMoney(actor,amount)
- local currentActive = getsysvar(actor,CURRENT_ACTIVE)
- if table.isNullOrEmpty(currentActive) then
- return
- end
- if OperationalActivities.judgeActiveClose(actor,ACTIVE_TYPE.TOTAL_RECHARGE) then
- local id = ConfigDataManager.getTableValue("cfg_OperateActivity_subActivity","id","mainGroup",currentActive.mainActive.mainGroup,"subType",ACTIVE_TYPE.TOTAL_RECHARGE)
- if string.isNullOrEmpty(id) then
- return
- end
- local numberId = tonumber(id)
- if amount ~= nil then
- local operationalActive = AccumulatedRecharge.get(actor)
- operationalActive[numberId] = tonumber(operationalActive[numberId] or 0) + amount
- operationalActive:save(actor)
- end
- end
- end
- --- 累充关闭
- function OperationalActivities.closeActive(mainGroup)
- local allRoleInfos = getallrolesummaryinfos()
- local rechargeTable = ConfigDataManager.getTable("cfg_rechargeRccrued","mainGroup",mainGroup)
- if not table.isNullOrEmpty(allRoleInfos) and not table.isNullOrEmpty(rechargeTable) then
- local specialCondition = ConfigDataManager.getTableValue("cfg_OperateActivity_subActivity","specialCondition","mainGroup",mainGroup,"subType",ACTIVE_TYPE.TOTAL_RECHARGE)
- for k, roleInfo in pairs(allRoleInfos) do
- local actor = roleInfo["actor"]
- if ConditionManager.Check(actor, specialCondition) then
- local item = {}
- local money = this.totalMoney(actor,rechargeTable[1].type)
- for k, rechargeInfo in pairs(rechargeTable) do
- local countInfo = CountManager.getCount(actor,rechargeInfo.countkey)
- if not table.isNullOrEmpty(countInfo) and countInfo.total > countInfo.count and money >= tonumber(rechargeInfo.amount) then
- local count = countInfo.total - countInfo.count
- for i = 1, count do
- string.putIntIntMap(item, rechargeInfo.reward, "#", "|")
- end
- end
- end
- if not table.isNullOrEmpty(item) then
- sendconfigmailbyrid(actor, actor:toString(), 900003, item)
- end
- end
- end
- end
- end
- -- 发送奖励
- function this.sendReward(actor,config)
- local money = this.totalMoney(actor,tonumber(config.type))
- if tonumber(config.amount) <= money and not string.isNullOrEmpty(config.reward) then
- Bag.sendRewards4String(actor, config.reward, "运营累充活动"..config.id)
- end
- end
- -- 获取当前充值多钱前
- function this.totalMoney(actor,type)
- local money = 0
- if type == STATISTICS_TYPE.ALL then
- money = RechargeRecord.getTotalMoney(actor)
- else
- local activityRecharge = AccumulatedRecharge.get(actor)
- if not table.isNullOrEmpty(activityRecharge) then
- local currentActive = getsysvar(actor, CURRENT_ACTIVE)
- if not table.isNullOrEmpty(currentActive) then
- local id = ConfigDataManager.getTableValue("cfg_OperateActivity_subActivity","id","mainGroup",currentActive.mainActive.mainGroup,"subType",ACTIVE_TYPE.TOTAL_RECHARGE)
- if not string.isNullOrEmpty(id) then
- money = activityRecharge[tonumber(id)] or 0
- end
- end
- end
- end
- return money
- end
- -- ------------------------------------------------------------- --
- this.log_open = false
- function this.debug(...)
- if not this.log_open then
- return
- end
- gameDebug.print(...)
- end
- function this.jprint(...)
- if not this.log_open then
- return
- end
- if param == nil then
- param = "error! 输出内容为空. nil"
- end
- jprint(...)
- end
- -- ------------------------------------------------------------- --
- EventListerTable.registerType("运营累充", _rechargeType(), _playerDbKey())
- RechargeEventListerTable:eventLister("0", "运营累充", AccumulatedRecharge.rechargeEvent)
- RechargeMessageEventListerTable:eventLister(_rechargeType(), "运营累充", AccumulatedRecharge.reqAction)
|