| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- BenefitActivity = {}
- local this = {}
- ---福利大厅数据
- local PLAYER_BENEFIT_INFO = "T$player_benefit_info"
- local GLOBAL_BENEFIT_INFO = "R$global_benefit_info"
- ---福利大厅常量
- this.ActivityType = {
- ---无
- NONE = 0,
- ---在线奖励
- ONLINE = 1,
- ---登录奖励
- LOGIN = 2,
- ---等级奖励
- LEVELUP = 3,
- ---累充奖励
- TOTAL_RECHARGE = 4,
- }
- function BenefitActivity.IsDataKey(varName)
- if string.equalsIgnoreCase(varName,PLAYER_BENEFIT_INFO) then
- return true
- else
- return false
- end
- end
- ---获取福利大厅数据
- function this.GetBenefitData(actor, type)
- local globalBenefitInfo = getplaydef(actor, PLAYER_BENEFIT_INFO)
- if globalBenefitInfo == nil then
- globalBenefitInfo = {}
- end
- if type == this.ActivityType.NONE then
- return globalBenefitInfo
- end
- -- 如果type不为NONE则返回对应数据
- if globalBenefitInfo[type] == nil then
- globalBenefitInfo[type] = {}
- end
- return globalBenefitInfo[type]
- end
- ---保存福利大厅数据
- function this.SaveBenefitData(actor, type, globalBenefitInfo)
- local golbalBenefitAllInfo = this.GetBenefitData(actor, this.ActivityType.NONE)
- golbalBenefitAllInfo[type] = globalBenefitInfo
- setplaydef(actor, PLAYER_BENEFIT_INFO, golbalBenefitAllInfo)
- end
- ---获取福利大厅数据
- function this.GetGlobalBenefitData(type)
- local globalBenefitInfo = getsysvar(GLOBAL_BENEFIT_INFO)
- if globalBenefitInfo == nil then
- globalBenefitInfo = {}
- end
- if type == this.ActivityType.NONE then
- return globalBenefitInfo
- end
- -- 如果type不为NONE则返回对应数据
- if globalBenefitInfo[type] == nil then
- globalBenefitInfo[type] = {}
- end
- return globalBenefitInfo[type]
- end
- ---保存福利大厅数据
- function this.SaveGlobalBenefitData(type, globalBenefitInfo)
- local golbalBenefitAllInfo = this.GetGlobalBenefitData(this.ActivityType.NONE)
- golbalBenefitAllInfo[type] = globalBenefitInfo
- setsysvar(GLOBAL_BENEFIT_INFO, golbalBenefitAllInfo)
- end
- -- 记录在线奖励登录时间和登录奖励
- function BenefitActivity.login(actor)
- -- 记录在线奖励此次登录时间,如果上次登录时间跨天,则清空在线时长
- -- local online_data = this.GetBenefitData(actor, this.ActivityType.ONLINE)
- -- if online_data == nil then
- -- online_data = {}
- -- end
- -- if online_data.reward_list == nil then
- -- online_data.reward_list = {}
- -- end
- -- online_data.last_login_time = getbaseinfo(actor, "logintime")
- -- if online_data.last_reward_time == nil or now - online_data.last_reward_time > 86400000 then
- -- online_data.last_reward_time = 0
- -- else
- -- end
- -- this.SaveBenefitData(actor, this.ActivityType.ONLINE, online_data)
- -- 登录数据验证,登录奖励记录领奖时间列表,超过7天的数据清零
- local now = getbaseinfo("nowsec")
- local login_data = this.GetBenefitData(actor, this.ActivityType.LOGIN)
- if login_data == nil then
- login_data = {}
- end
- if login_data.reward_list == nil then
- login_data.reward_list = {}
- end
- for i, data in pairs(login_data.reward_list) do
- if now - tonumber(data) >= 86400 * 7 then
- login_data.reward_list[i] = nil
- end
- end
- this.SaveBenefitData(actor, this.ActivityType.LOGIN, login_data)
- end
- -- 记录在线奖励在线时间
- function BenefitActivity.logout(actor)
- end
- -- 记录在线奖励在线时间
- function BenefitActivity.midNightUpdate(actor)
- end
- ---构建活动数据回包
- function BenefitActivity.SendActivityInfo(actor, msgData)
- this.SendActivityInfo(actor, msgData)
- end
- -- 获取开服天数
- function this:GetLoginDays(actor)
- -- 获取当前开服天数
- local opendays = getbaseinfo(actor, "serveropendays")
- return (opendays - 1) % 7 + 1
- end
- ---构建活动数据回包
- function this.SendActivityInfo(actor, msgData)
- -- this.SaveBenefitData(actor, this.ActivityType.LEVELUP, {})
- local globalBenefitInfo = this.GetBenefitData(actor, this.ActivityType.NONE)
- -- 整合升级数据
- if globalBenefitInfo[this.ActivityType.LEVELUP] == nil then
- globalBenefitInfo[this.ActivityType.LEVELUP] = { record = {} }
- end
- -- 判断领取数量是否已满
- local recordData = this.GetGlobalBenefitData(this.ActivityType.LEVELUP)
- local configTable = ConfigDataManager.getList("cfg_benefit_activity")
- for i = 1, #configTable do
- ---@type cfg_benefit_activity_column
- local tmpConfig = configTable[i]
- if tonumber(tmpConfig.maingroup) == this.ActivityType.LEVELUP then
- local subtype = tonumber(tmpConfig.subtype)
- if globalBenefitInfo[this.ActivityType.LEVELUP].record[subtype] == nil then
- globalBenefitInfo[this.ActivityType.LEVELUP].record[subtype] = {}
- end
- if recordData[subtype] == nil then
- recordData[subtype] = {}
- end
- globalBenefitInfo[this.ActivityType.LEVELUP].record[subtype].sub_type = subtype
- globalBenefitInfo[this.ActivityType.LEVELUP].record[subtype].reward_num = #recordData[subtype]
- end
- end
- sendluamsg(actor, LuaMessageIdToClient.RES_ACTIVITY_BENEFIT_INFO, globalBenefitInfo)
- end
- ---领取奖励
- function BenefitActivity.ReceiveReward(actor, msgData)
- this.ReceiveAward(actor, msgData)
- end
- ---领取奖励
- function this.ReceiveAward(actor, msgData)
- -- jprint("玩家请求领取福利大厅奖励",actor,msgData)
- local activityType = tonumber(msgData["activityType"])
- local activitySubType = tonumber(msgData["activitySubType"])
- local activityData = this.GetBenefitData(actor, activityType)
- ---@type cfg_benefit_activity_column[]
- local config = nil
- local configTable = ConfigDataManager.getList("cfg_benefit_activity")
- for i = 1, #configTable do
- ---@type cfg_benefit_activity_column
- local tmpConfig = configTable[i]
- if tonumber(tmpConfig.maingroup) == activityType then
- if tonumber(tmpConfig.subtype) == activitySubType then
- config = tmpConfig
- end
- end
- end
- if activityData.record == nil then
- activityData.record = {}
- end
- if config == nil then
- tipinfo(actor,"配置可领取数量不足")
- return
- elseif activityType == this.ActivityType.ONLINE then
- return
- elseif activityType == this.ActivityType.LOGIN then
- -- 获取当前开服天数
- local opendays = getbaseinfo(actor, "serveropendays")
- local curDays = (opendays - 1) % 7 + 1
- if activitySubType ~= curDays then
- tipinfo(actor,"不是当前天数")
- return
- end
- local now = getbaseinfo("now")
- -- 判断是否已领取过
- for _, recordData in pairs(activityData.record) do
- if TimeUtil.isSameDay4Millis(now, recordData.time) then
- tipinfo(actor,"您已领取过该活动奖励")
- -- 发送活动数据刷新显示
- this.SendActivityInfo(actor)
- return
- end
- end
- elseif activityType == this.ActivityType.LEVELUP then
- local level = getplayermaininfo(actor).level
- if level < tonumber(config.conditionparam) then
- tipinfo(actor, "条件不满足")
- return
- end
- -- 判断是否已领取过
- for _, recordData in pairs(activityData.record) do
- if activitySubType == tonumber(recordData.type) then
- tipinfo(actor,"您已领取过该活动奖励")
- -- 发送活动数据刷新显示
- this.SendActivityInfo(actor)
- return
- end
- end
- -- 判断领取数量是否已满
- local recordData = this.GetGlobalBenefitData(activityType)
- if recordData[activitySubType] == nil then
- recordData[activitySubType] = {}
- end
- if #recordData[activitySubType] >= tonumber(config.numparam) then
- tipinfo(actor,"领取数量已达上限")
- return
- end
- elseif activityType == this.ActivityType.TOTAL_RECHARGE then
- local totalChargeNum = RechargeRecord.getTotalMoney(actor)
- if totalChargeNum < tonumber(config.conditionparam) then
- tipinfo(actor, "条件不满足")
- return
- end
- -- 判断是否已领取过
- for _, recordData in pairs(activityData.record) do
- if activitySubType == tonumber(recordData.type) then
- tipinfo(actor,"您已领取过该活动奖励")
- -- 发送活动数据刷新显示
- this.SendActivityInfo(actor)
- return
- end
- end
- else
- tipinfo(actor, "活动不存在")
- return
- end
- -- 发送对应活动奖励
- if this.SendReward(actor, config) then
- -- 保存个人数据
- local recordData = {}
- if activityType == this.ActivityType.LOGIN then
- local now = getbaseinfo("now")
- recordData = {time = now}
- else
- recordData = {type = activitySubType}
- end
- if table.count(recordData) > 0 then
- activityData.record[activitySubType] = recordData
- this.SaveBenefitData(actor, activityType, activityData)
- end
- -- 保存全局数据
- if activityType == this.ActivityType.LEVELUP then
- local recordData = this.GetGlobalBenefitData(activityType)
- if recordData[activitySubType] == nil then
- recordData[activitySubType] = {}
- end
- table.insert(recordData[activitySubType], {rid = getbaseinfo(actor, "rid")})
- this.SaveGlobalBenefitData(activityType, recordData)
- end
- this.SendActivityInfo(actor)
- end
- end
- -- 发送奖励
- function this.SendReward(actor, config)
- if config == nil then
- print("[BenefitActivity.SendReward] configReward is nil")
- return false
- end
- local rewardsMap = string.toIntIntMap(config.reward, "#", "|")
- Bag.sendRewards(actor, rewardsMap, "福利大厅")
- print("Benefit.Activity.SendReward send reward success")
- return true
- end
|