HomeServer/Server/AllServer/GameServer/Activity/ActivitySeekTreasure.lua
2024-11-20 15:41:37 +08:00

1047 lines
35 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local skynet = require "skynet"
local oo = require "Class"
local log = require "Log"
local pb = require "pb"
local dataType = require "DataType"
local errorInfo = require "ErrorInfo"
local activity = require "Activity"
local json =require "json"
local dataType = require "DataType"
local taskListEvent = require "TaskListEvent"
local ActivitySeekTreasure = oo.class()
ActivitySeekTreasure.ActivityType = dataType.ActivityType_SeekTreasure
--构造函数
function ActivitySeekTreasure:Init()
end
-- 每次登录需要进行修改的数据
function ActivitySeekTreasure:LoginInitData(player)
--判断模块是否开启
if not player:IsUnlockSystem( dataType.UnlockSystem_ActivitySeekTreasure ) then
log.debug("限时寻味之旅模块未开启")
return
end
--活动结束
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
if cfgSeekTreasure == nil then
log.debug("限时寻味之旅活动已结束")
return
end
--获取开启的活动
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
local seekTreasure = player.gameData.SeekTreasureMap[activityId]
--是否跨天补发免费参与次数
if os.date("%Y-%m-%d",seekTreasure.LoginDate) ~= os.date("%Y-%m-%d",skynet.GetTime()) then
seekTreasure.conParticipationNum = 1
seekTreasure.ADSkipCount =cfgSeekTreasure.adSkipPunish
seekTreasure.LoginDate = skynet.GetTime()
seekTreasure.isTodayParticipation = false --今日是否参与
seekTreasure.haveSeekTreasureTasks = {} --已刷新过的任务列表
seekTreasure.seekTreasureTasks = {} --任务列表
end
-- 处理红点
skynet.server.msgTips:Reset(player, 113)
skynet.server.msgTips:Reset(player, 114)
log.debug("限时寻味之旅活动进行中")
end
--初始玩家数据,返回活动信息,
function ActivitySeekTreasure:CheckDataAndGetActivity(player)
--默认空活动
local cfgSeekTreasure = nil
if player==nil then
log.debug("限时寻味之旅CheckDataAndGetActivity player is nil")
return cfgSeekTreasure
end
--判断等级是否开启
if not player:IsUnlockSystem( dataType.UnlockSystem_ActivitySeekTreasure) then
log.debug("限时寻味之旅等级不足")
return cfgSeekTreasure
end
--获取开启的活动
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
--没有开启的活动
if activityId == 0 then
log.debug("限时寻味之旅未开启-未获取到有效的活动1")
return cfgSeekTreasure
end
--初始化
if player.gameData.SeekTreasureMap==nil then
player.gameData.SeekTreasureMap={}
log.debug("player.gameData.SeekTreasureMap={}")
end
--获取活动配置
cfgSeekTreasure=self:GetSeekTreasureConfig(player,activityId)
--未获取到有效的活动
if cfgSeekTreasure == nil then
log.debug("限时寻味之旅未开启-未获取到有效的活动2")
return cfgSeekTreasure
end
--如果玩家已经存在活动不需要检查
if player.gameData.SeekTreasureMap[activityId] then
local seekTreasure = player.gameData.SeekTreasureMap[activityId]
--是否跨天补发免费参与次数
if os.date("%Y-%m-%d",seekTreasure.LoginDate) ~= os.date("%Y-%m-%d",skynet.GetTime()) then
seekTreasure.conParticipationNum = 1
seekTreasure.ADSkipCount =cfgSeekTreasure.adSkipPunish
seekTreasure.isTodayParticipation = false --今日是否参与
seekTreasure.haveSeekTreasureTasks = {} --已刷新过的任务列表
seekTreasure.seekTreasureTasks = {} --任务列表
end
player.gameData.SeekTreasureMap[activityId].LoginDate = skynet.GetTime() --更新登录时间 补发奖励用
--删除过期活动,减少数据产生
local removeKeyList = {}
for exceedActivityId, _ in pairs(player.gameData.SeekTreasureMap) do
if exceedActivityId ~= activityId then
table.insert(removeKeyList, exceedActivityId)
end
end
if next(removeKeyList) then
for _, removeKey in ipairs(removeKeyList) do
player.gameData.SeekTreasureMap[removeKey]=nil
end
end
return cfgSeekTreasure
end
self:InitStage(player,activityId)
return cfgSeekTreasure
end
--初始化关卡
function ActivitySeekTreasure:InitStage(player,activityId)
--获取活动配置
local cfgSeekTreasure=self:GetSeekTreasureConfig(player,activityId)
--未获取到有效的活动
if cfgSeekTreasure == nil then
log.debug("限时寻味之旅未开启-未获取到有效的活动2")
return cfgSeekTreasure
end
--存在活动初始化玩家数据
local playerActivityTreasure = {}
playerActivityTreasure.activityId = cfgSeekTreasure.activityId
playerActivityTreasure.haveSeekTreasureTasks = {} --已刷新过的任务列表
playerActivityTreasure.seekTreasureTasks = {} --任务列表
playerActivityTreasure.conParticipationNum = 1 --可参与次数
playerActivityTreasure.isFinish = false --是否完成挑战
playerActivityTreasure.isTodayParticipation = false --今日是否参与
--获取最小关卡
local minStage = 1
for index, value in ipairs(cfgSeekTreasure.allLevelId) do
if index ==1 then
minStage = value
break
end
end
playerActivityTreasure.curStage = minStage --当前阶段
--获取最小关卡
local minLevelId = 1
local minLevelIdList = {}
local cfgSeekTreasureLevels=self:GetStageConfigList(player,cfgSeekTreasure.activityId,minStage)
local levelOrder = 1
for index, cfgSeekTreasureLevel in ipairs(cfgSeekTreasureLevels) do
if levelOrder >= cfgSeekTreasureLevel.levelOrder then
table.insert(minLevelIdList,cfgSeekTreasureLevel.levelOrder)
end
end
if #minLevelIdList > 0 then
table.sort(minLevelIdList)
minLevelId = minLevelIdList[1]
end
playerActivityTreasure.curLevel = minLevelId --当前阶段
playerActivityTreasure.curStageState = 0 --当前关卡状态,0:未开启,1:未选择2惩罚中
playerActivityTreasure.curStageRewardId = 0 --当前关卡奖励id,0:惩罚奖励非0:奖励id
playerActivityTreasure.lastIsSkipPunish = false --上一次是否跳过惩罚
playerActivityTreasure.ADSkipCount =cfgSeekTreasure.adSkipPunish--广告跳过次数
playerActivityTreasure.stageRewardList = {} --奖励列表
playerActivityTreasure.LoginDate = skynet.GetTime() --登录天数
--更新缓存
player.gameData.SeekTreasureMap[activityId] = playerActivityTreasure
end
--重置当前阶段
function ActivitySeekTreasure:ResetStage(player,activityId)
--获取活动配置
local cfgSeekTreasure=self:GetSeekTreasureConfig(player,activityId)
--未获取到有效的活动
if cfgSeekTreasure == nil then
log.debug("限时寻味之旅未开启-未获取到有效的活动2")
return cfgSeekTreasure
end
--存在活动初始化玩家数据
local playerActivityTreasure = player.gameData.SeekTreasureMap[activityId]
--获取最小关卡
local minLevelId = 1
local minLevelIdList = {}
local cfgSeekTreasureLevels=self:GetStageConfigList(player,cfgSeekTreasure.activityId,playerActivityTreasure.curStage )
local levelOrder = 1
for index, cfgSeekTreasureLevel in ipairs(cfgSeekTreasureLevels) do
if levelOrder >= cfgSeekTreasureLevel.levelOrder then
table.insert(minLevelIdList,cfgSeekTreasureLevel.levelOrder)
end
end
if #minLevelIdList > 0 then
table.sort(minLevelIdList)
minLevelId = minLevelIdList[1]
end
playerActivityTreasure.curLevel = minLevelId --当前阶段
playerActivityTreasure.curStageState = 0 --当前关卡状态,0:未开启,1:未选择2惩罚中
playerActivityTreasure.curStageRewardId = 0 --当前关卡奖励id,0:惩罚奖励非0:奖励id
playerActivityTreasure.stageRewardList = {} --奖励列表
playerActivityTreasure.LoginDate = skynet.GetTime() --登录天数
skynet.server.msgTips:ReduceAll(player,114)
--更新缓存
player.gameData.SeekTreasureMap[activityId] = playerActivityTreasure
end
--获取阶段信息
function ActivitySeekTreasure:GetStageConfigList(player,activityId,level)
local cfgSeekTreasureLevel = {}
--获取该活动的默认初始关卡
local cfgSeekTreasureLevels=skynet.server.gameConfig:GetPlayerAllCfg(player, "SeekTreasureLevel")
if cfgSeekTreasureLevels==nil then
log.debug("cfgSeekTreasureLevels is nil")
return cfgSeekTreasureLevel
end
for _, value in pairs(cfgSeekTreasureLevels) do
if value.activityId==activityId and value.level == level then
table.insert(cfgSeekTreasureLevel,value)
end
end
return cfgSeekTreasureLevel
end
--是否可以挑战
function ActivitySeekTreasure:IsConParticipationNum(player)
--不存在开启的活动
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
--活动未开启
if cfgSeekTreasure == nil then
log.debug("限时寻味之旅未开启-未获取到有效的活动 IsConParticipationNum")
return false
end
--获取开启的活动
local activityId,_,_, _ = activity:GetActivityInfo(player, self.ActivityType)
return player.gameData.SeekTreasureMap[activityId].conParticipationNum > 0
end
--是否完成挑战
function ActivitySeekTreasure:IsEnd(player)
--不存在开启的活动
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
--活动未开启
if cfgSeekTreasure == nil then
log.debug("限时寻味之旅未开启-未获取到有效的活动 IsEnd")
return false
end
--获取开启的活动
local activityId,_,_, _ = activity:GetActivityInfo(player, self.ActivityType)
return player.gameData.SeekTreasureMap[activityId].curStageState ~= 0
end
--获取配置信息
function ActivitySeekTreasure:GetSeekTreasureConfig(player,activityId)
local cfgSeekTreasure=nil
--获取该活动的默认初始关卡
local cfgSeekTreasures=skynet.server.gameConfig:GetPlayerAllCfg(player, "SeekTreasure")
if cfgSeekTreasures==nil then
log.debug("cfgSeekTreasures is nil")
return cfgSeekTreasure
end
for index, value in pairs(cfgSeekTreasures) do
if value.id==activityId then
cfgSeekTreasure=value
break
end
end
return cfgSeekTreasure
end
--初始化下一关卡
function ActivitySeekTreasure:InitNextLevel(player,seekTreasure,activityId)
local cfgSeekTreasure = self:GetSeekTreasureConfig(player,activityId)
if cfgSeekTreasure == nil then
log.error("关卡配置不存在")
return false
end
--下一个关卡id
local nextLevelId = 0
local cfgSeekTreasureLevels=self:GetStageConfigList(player,activityId,seekTreasure.curStage)
local nextLevelIdList={}
for _, value in ipairs(cfgSeekTreasureLevels) do
if value.levelOrder > seekTreasure.curLevel then
table.insert(nextLevelIdList,value.levelOrder)
end
end
--找到当前阶段还有下一个节点
if #nextLevelIdList > 0 then
table.sort(nextLevelIdList)
nextLevelId= nextLevelIdList[1]
seekTreasure.curLevel=nextLevelId
seekTreasure.curStageRewardId = 0 --当前关卡奖励id,0:惩罚奖励非0:奖励id
--seekTreasure.lastIsSkipPunish = false --上一次是否跳过惩罚
return true
end
--大奖是否添加成功
local isAddReward = false
--是否是最后一关-添加大奖
for index, value in ipairs(cfgSeekTreasure.allLevelId) do
if value == seekTreasure.curStage then
table.insert(seekTreasure.stageRewardList,{rewardId = cfgSeekTreasure.levelFinalReward[index],count = 1})
isAddReward=true
break
end
end
--添加无限阶段大奖
if not isAddReward then
table.insert(seekTreasure.stageRewardList,{rewardId = cfgSeekTreasure.infiniteReward,count = 1})
end
seekTreasure.curStageRewardId = 0 --当前关卡奖励id,0:惩罚奖励非0:奖励id
--seekTreasure.lastIsSkipPunish = false --上一次是否跳过惩罚
seekTreasure.isFinish = true --设置成挑战完成
return false
end
--初始化下一阶段
function ActivitySeekTreasure:InitNextStage(player,seekTreasure,activityId)
local cfgSeekTreasure = self:GetSeekTreasureConfig(player,activityId)
if cfgSeekTreasure == nil then
log.error("关卡配置不存在")
return false
end
--下一个阶段,默认是当前
local nextStageId = seekTreasure.curStage
--未找到下一个节点,获取下一个阶段或者 循环当前
for index, value in ipairs(cfgSeekTreasure.allLevelId) do
if value == nextStageId then
nextStageId=cfgSeekTreasure.allLevelId[index+1]
break
end
end
--普通轮次不存在 进入循环轮次
if nextStageId == nil or nextStageId == seekTreasure.curStagethen then
nextStageId=cfgSeekTreasure.infiniteLevelId
end
--获取最小关卡
local minLevelId = 1
local minLevelIdList = {}
local cfgSeekTreasureLevels=self:GetStageConfigList(player,activityId,nextStageId)
local levelOrder = 1
for _, cfgSeekTreasureLevel in ipairs(cfgSeekTreasureLevels) do
if levelOrder >= cfgSeekTreasureLevel.levelOrder then
table.insert(minLevelIdList,cfgSeekTreasureLevel.levelOrder)
end
end
if #minLevelIdList > 0 then
table.sort(minLevelIdList)
minLevelId = minLevelIdList[1]
end
seekTreasure.curStage=nextStageId
seekTreasure.curLevel=minLevelId
seekTreasure.curStageState = 0 --当前关卡状态,0:未开启,1:未选择2惩罚中
seekTreasure.curStageRewardId = 0 --当前关卡奖励id,0:惩罚奖励非0:奖励id
seekTreasure.lastIsSkipPunish = false --上一次是否跳过惩罚
skynet.server.msgTips:ReduceAll(player,114)
end
--获取关卡配置
function ActivitySeekTreasure:GetSeekTreasureLevelConfig(player,level,levelOrder)
local cfgSeekTreasureLevel =nil
--获取该活动的默认初始关卡
local cfgSeekTreasureLevels=skynet.server.gameConfig:GetPlayerAllCfg(player, "SeekTreasureLevel")
if cfgSeekTreasureLevels==nil then
log.debug("cfgSeekTreasureLevels is nil")
return cfgSeekTreasureLevel
end
for _, value in pairs(cfgSeekTreasureLevels) do
if value.level==level and value.levelOrder == levelOrder then
cfgSeekTreasureLevel=value
end
end
return cfgSeekTreasureLevel
end
--开启关卡信息
function ActivitySeekTreasure:OpenStage(player,seekTreasure,activityId,level,levelOrder)
--获取活动配置
local cfgSeekTreasure=self:GetSeekTreasureConfig(player,activityId)
--未获取到有效的活动
if cfgSeekTreasure == nil then
log.debug("限时寻味之旅未开启-未获取到有效的活动 OpenStage",level,levelOrder)
return false
end
local seekTreasureLevel = self:GetSeekTreasureLevelConfig(player,level,levelOrder)
if seekTreasureLevel == nil then
log.debug("限时寻味之旅未开启-未获取到有效的活动2 OpenStage",level,levelOrder)
return false
end
--循环列表
local readmodeList = {}
for _, value in ipairs(seekTreasureLevel.levelReward) do
table.insert(readmodeList,value)
end
--是否跳过惩罚关卡
if seekTreasure.lastIsSkipPunish and seekTreasureLevel.punishReplaceReward > 0 then
table.insert(readmodeList,seekTreasureLevel.punishReplaceReward)
end
--是否需要执行惩罚关卡随机
if seekTreasureLevel.welfareLevel ~= 1 and #readmodeList < 4 then
--随机惩罚
local randomValue = math.random(1,100)
if tonumber(randomValue) <= tonumber(seekTreasureLevel.punishPossibility*100) then
seekTreasure.curStageRewardId = 0 --惩罚奖励
seekTreasure.curStageState = 1--未选择
skynet.server.msgTips:Add(player,114)
return true
end
end
local index = math.random(1,#readmodeList)
seekTreasure.curStageRewardId=readmodeList[index]--奖励id
--设置成未选择
seekTreasure.curStageState = 1
seekTreasure.lastIsSkipPunish = false
skynet.server.msgTips:Add(player,114)
return true
end
--刷新任务列表
function ActivitySeekTreasure:RefreshTaskList(player,activityId)
--获取任务配置
local cfgSeekTreasureTasks=skynet.server.gameConfig:GetPlayerAllCfg(player, "SeekTreasureTask")
--存在配置
if cfgSeekTreasureTasks == nil or not next(cfgSeekTreasureTasks) then
log.debug("限时寻味之旅未开启-未获取到有效的任务配置")
return false
end
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
local seekTreasure = player.gameData.SeekTreasureMap[activityId]
if seekTreasure ==nil
or seekTreasure.conParticipationNum > 0
or next(seekTreasure.seekTreasureTasks) then
log.debug("限时寻味之旅未开启-不满足刷新任务条件")
return false
end
--清空
seekTreasure.seekTreasureTasks={}
local cfgJigsawPuzzleTaskList = {}
for _, cfgJigsawPuzzleTask in ipairs(cfgSeekTreasureTasks) do
if cfgJigsawPuzzleTask.seekTreasureId == activityId then
table.insert(cfgJigsawPuzzleTaskList,cfgJigsawPuzzleTask)
end
end
--可用的任务
local haveSeekTreasureTaskIds = {}
for _, cfgSeekTreasureTask in ipairs(cfgJigsawPuzzleTaskList) do
for _, taskId in ipairs(seekTreasure.haveSeekTreasureTasks) do
if cfgSeekTreasureTask.id == taskId then--已经随机过了
goto continue
end
end
--添加到可用任务
table.insert(haveSeekTreasureTaskIds,cfgSeekTreasureTask.id)
::continue::
end
--不存在就设置成全部
if not next(haveSeekTreasureTaskIds) then
for _, cfgSeekTreasureTask in ipairs(cfgJigsawPuzzleTaskList) do
--添加到可用任务
table.insert(haveSeekTreasureTaskIds,cfgSeekTreasureTask.id)
end
seekTreasure.haveSeekTreasureTasks={}
end
--循环刷新
for i = 1, cfgSeekTreasure.taskNum, 1 do
--不存在就设置成全部
if not next(haveSeekTreasureTaskIds) then
seekTreasure.haveSeekTreasureTasks={}
for _, cfgSeekTreasureTask in ipairs(cfgJigsawPuzzleTaskList) do
for key, _ in pairs(seekTreasure.seekTreasureTasks) do
if cfgSeekTreasureTask.id==key then
table.insert( seekTreasure.haveSeekTreasureTasks,key)
goto continue
end
end
--添加到可用任务
table.insert(haveSeekTreasureTaskIds,cfgSeekTreasureTask.id)
::continue::
end
end
local index = math.random(1,#haveSeekTreasureTaskIds)
local id =haveSeekTreasureTaskIds[index]
seekTreasure.seekTreasureTasks[id]={ id = id , value = 0 ,status=0}
table.insert(seekTreasure.haveSeekTreasureTasks,haveSeekTreasureTaskIds[index])
--移除可用任务
table.remove(haveSeekTreasureTaskIds,index)
end
return true
end
--任务格式转换
function ActivitySeekTreasure:GetSeekTreasureTaskInfo(taskList)
local taskListInfo={}
if taskList==nil or not next(taskList) then
return taskListInfo
end
for _, value in pairs(taskList) do
table.insert(taskListInfo,{id=value.id,progress=value.value,status=value.status})
end
return taskListInfo
end
--获取限时寻味之旅信息
function ActivitySeekTreasure:Show( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivitySeekTreasureShow", c2sData.data ))
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivitySeekTreasureShow")
local data = {}
--检查并且获取活动信息
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
if cfgSeekTreasure == nil then
s2cData.code = errorInfo.ErrorCode.ActivityClosed
return
end
--获取开启的活动
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
local seekTreasure = player.gameData.SeekTreasureMap[activityId]
--刷新任务
self:RefreshTaskList(player, activityId)
data.conParticipationNum=seekTreasure.conParticipationNum
data.curStage=seekTreasure.curStage
data.curLevel=seekTreasure.curLevel
data.curStageState=seekTreasure.curStageState
data.curStageRewardId=seekTreasure.curStageRewardId
data.taskList= self:GetSeekTreasureTaskInfo(seekTreasure.seekTreasureTasks)
data.stageRewardList=seekTreasure.stageRewardList
data.isFinish=seekTreasure.isFinish
data.adSkipCount=seekTreasure.ADSkipCount
--返回信息
s2cData.data = assert(pb.encode("S2SActivitySeekTreasureShow", data))
end
--开始寻味之旅
function ActivitySeekTreasure:Start( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivitySeekTreasureStart", c2sData.data ))
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivitySeekTreasureStart")
local data = {}
--检查并且获取活动信息
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
if cfgSeekTreasure == nil then
s2cData.code = errorInfo.ErrorCode.ActivityClosed
return
end
--获取开启的活动
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
--是否有参与次数
local seekTreasure = player.gameData.SeekTreasureMap[activityId]
if seekTreasure.conParticipationNum <= 0 then
log.debug("限时寻味之旅 参与次数不足")
s2cData.code = errorInfo.ErrorCode.NotEnoughParticipateTimes
return
end
--开启关卡信息
if self:OpenStage(player,seekTreasure,activityId,seekTreasure.curStage,seekTreasure.curLevel) then
--扣除参与次数
seekTreasure.conParticipationNum = 0
skynet.server.msgTips:ReduceAll(player,113)
seekTreasure.isTodayParticipation = true --今日是否参与
end
--挑战红点
--skynet.server.msgTips:ReduceAll(player, 120)
data.conParticipationNum=seekTreasure.conParticipationNum
data.curStage=seekTreasure.curStage
data.curLevel=seekTreasure.curLevel
data.curStageState=seekTreasure.curStageState
data.curRewardId=seekTreasure.curStageRewardId
data.stageRewardList=seekTreasure.stageRewardList
data.adSkipPunish=seekTreasure.adSkipPunish
--返回信息
s2cData.data = assert(pb.encode("S2SActivitySeekTreasureStart", data))
end
--打开宝物
function ActivitySeekTreasure:Open( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivitySeekTreasureOpen", c2sData.data ))
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivitySeekTreasureOpen")
local data = {}
--检查并且获取活动信息
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
if cfgSeekTreasure == nil then
log.debug("限时寻味之旅 活动未开启")
s2cData.code = errorInfo.ErrorCode.ActivityClosed
return
end
--获取开启的活动
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
--玩家参与信息
local seekTreasure = player.gameData.SeekTreasureMap[activityId]
--状态是否正确
if seekTreasure.curStageState ~= 1 then
log.debug("限时寻味之旅 状态错误")
s2cData.code = errorInfo.ErrorCode.NotOpenLevel
return
end
data.curRewardId= seekTreasure.curStageRewardId
if seekTreasure.curStageRewardId == 0 then
seekTreasure.curStageState = 2
data.nextCurStage=0
data.nextCurLevel=0
data.nextCurRewardId=0
data.isFinish=false
else
local isUpdate= false
for index, value in ipairs(seekTreasure.stageRewardList) do
if value.rewardId == seekTreasure.curStageRewardId then
seekTreasure.stageRewardList[index]={rewardId = seekTreasure.curStageRewardId,count = value.count+1}
isUpdate=true
break
end
end
if not isUpdate then
table.insert(seekTreasure.stageRewardList,{rewardId = seekTreasure.curStageRewardId,count = 1})
end
if self:InitNextLevel(player,seekTreasure,activityId) then --初始化下一关卡
--开启关卡信息
self:OpenStage(player,seekTreasure,activityId,seekTreasure.curStage,seekTreasure.curLevel)
end
data.nextCurStage=seekTreasure.curStage
data.nextCurLevel=seekTreasure.curLevel
data.nextCurRewardId=seekTreasure.curStageRewardId
data.isFinish=seekTreasure.isFinish
end
data.stageRewardList= seekTreasure.stageRewardList
--返回信息
s2cData.data = assert(pb.encode("S2SActivitySeekTreasureOpen", data))
end
--领取奖励并且退出
function ActivitySeekTreasure:GetReward( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivitySeekTreasureGetReward", c2sData.data ))
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivitySeekTreasureGetReward")
local data = {}
data.rewardIdList={}
--检查并且获取活动信息
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
if cfgSeekTreasure == nil then
s2cData.code = errorInfo.ErrorCode.ActivityClosed
return
end
--获取开启的活动
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
--玩家参与信息
local seekTreasure = player.gameData.SeekTreasureMap[activityId]
if #seekTreasure.stageRewardList > 0 and seekTreasure.curStageState ~= 2 then
for _, reward in ipairs(seekTreasure.stageRewardList) do
--发奖
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_127")
player:GiveReward(reward.rewardId ,eventId,reward.count)
--添加到返回数据中
table.insert(data.rewardIdList,reward.rewardId)
end
end
--重置关卡信息
self:ResetStage(player,activityId)
--返回信息
s2cData.data = assert(pb.encode("S2SActivitySeekTreasureGetReward", data))
end
--跳过惩罚
function ActivitySeekTreasure:SkipPunish( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivitySeekTreasureSkipPunish", c2sData.data ))
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivitySeekTreasureSkipPunish")
local punishType = c2sData.data.punishType
local data = {}
--检查并且获取活动信息
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
if cfgSeekTreasure == nil then
s2cData.code = errorInfo.ErrorCode.ActivityClosed
return
end
--获取开启的活动
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
--玩家参与信息
local seekTreasure = player.gameData.SeekTreasureMap[activityId]
--当前是否处于惩罚中
if seekTreasure.curStageState ~= 2 then
s2cData.code = errorInfo.ErrorCode.NotInPunish
return
end
if punishType ==1 then--广告
if seekTreasure.ADSkipCount <=0 then
log.debug("限时寻味之旅 广告次数不足")
s2cData.code = errorInfo.ErrorCode.NotOpenLevel
return
end
seekTreasure.ADSkipCount=seekTreasure.ADSkipCount-1
else
local cfgSeekTreasureLevel=self:GetSeekTreasureLevelConfig(player,seekTreasure.curStage,seekTreasure.curLevel)
if cfgSeekTreasureLevel == nil then
log.debug("限时寻味之旅 配置错误")
s2cData.code = errorInfo.ErrorCode.NotOpenLevel
return
end
local type = cfgSeekTreasureLevel.skipPunishCost[1]
local count = cfgSeekTreasureLevel.skipPunishCost[2]
-- 跳过惩罚消耗
-- [货币类型,数量]
-- 1=金币
-- 2=三叶币
-- 3=蜗壳币
local goodsTypeId =0
if type == 1 then
if player.gameData.coin < count then
log.debug("限时寻味之旅 跳过惩罚消耗不足")
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
return
end
goodsTypeId =dataType.GoodsType_Coin
elseif type ==2 then
if player.gameData.clovers < count then
log.debug("限时寻味之旅 跳过惩罚消耗不足")
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
return
end
goodsTypeId =dataType.GoodsType_Clovers
elseif type ==3 then
if player.gameData.volute < count then
log.debug("限时寻味之旅 跳过惩罚消耗不足")
s2cData.code = errorInfo.ErrorCode.VoluteNotEnough
return
end
goodsTypeId =dataType.GoodsType_Volute
else
log.debug("限时寻味之旅 跳过惩罚未知类型")
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
return
end
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_128" )
--扣除消耗
player:MoneyChange(goodsTypeId, -count ,eventId)
end
--重新选择
local seekTreasureLevel = self:GetSeekTreasureLevelConfig(player,seekTreasure.curStage,seekTreasure.curLevel)
if seekTreasureLevel == nil then
log.debug("限时寻味之旅未开启-未获取到有效的活动2")
return false
end
local index = math.random(1,#seekTreasureLevel.levelReward)
seekTreasure.curStageRewardId=seekTreasureLevel.levelReward[index]--奖励id
--设置成未选择
seekTreasure.curStageState = 1
seekTreasure.lastIsSkipPunish=true
--返回客户端信息
data.curRewardId=seekTreasure.curStageRewardId
data.curStage=seekTreasure.curStage
data.curLevel=seekTreasure.curLevel
data.curStageState=seekTreasure.curStageState
data.stageRewardList=seekTreasure.stageRewardList
data.adSkipPunish=seekTreasure.ADSkipCount
--返回信息
s2cData.data = assert(pb.encode("S2SActivitySeekTreasureSkipPunish", data))
end
--领取结算奖励
function ActivitySeekTreasure:GetSettleReward( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SActivitySeekTreasureGetSettleReward", c2sData.data ))
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ActivitySeekTreasureGetSettleReward")
local data = {}
--检查并且获取活动信息
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
if cfgSeekTreasure == nil then
s2cData.code = errorInfo.ErrorCode.ActivityClosed
return
end
--检查并且获取活动信息
local cfgSeekTreasure=self:CheckDataAndGetActivity(player)
if cfgSeekTreasure == nil then
s2cData.code = errorInfo.ErrorCode.ActivityClosed
return
end
--获取开启的活动
local activityId, _, _, _ = activity:GetActivityInfo(player, self.ActivityType)
--玩家参与信息
local seekTreasure = player.gameData.SeekTreasureMap[activityId]
if #seekTreasure.stageRewardList >0 then
for _, reward in ipairs(seekTreasure.stageRewardList) do
--发奖
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_128")
player:GiveReward(reward.rewardId ,eventId,reward.count)
end
end
--初始化下一个阶段
self:InitNextStage(player,seekTreasure,activityId)
seekTreasure.curStageState = 0--设置成未开始
seekTreasure.isFinish = false --设置成未完成
seekTreasure.stageRewardList = {} --奖励列表
seekTreasure.seekTreasureTasks = {} --任务清除列表
skynet.server.msgTips:ReduceAll(player,114)
--返回信息
s2cData.data = assert(pb.encode("S2SActivitySeekTreasureGetSettleReward", data))
end
-- 定义一个回调函数
local function onEventFired(player , taskId , count)
--判断模块是否开启
if not player:IsUnlockSystem(dataType.UnlockSystem_ActivitySeekTreasure) then
return
end
--活动结束
local cfgSeekTreasure=ActivitySeekTreasure:CheckDataAndGetActivity(player)
if cfgSeekTreasure == nil then
return
end
--获取开启的活动
local activityId, _, _, _ = activity:GetActivityInfo(player, ActivitySeekTreasure.ActivityType)
--刷新任务
ActivitySeekTreasure:RefreshTaskList(player, activityId)
--是否需要执行任务
if not next(player.gameData.SeekTreasureMap[activityId].seekTreasureTasks) then
log.debug("任务触发,玩家任务列表为空")
return
end
--获取功能任务配置
local cfgSeekTreasureTasks = skynet.server.gameConfig:GetPlayerAllCfg(player,"SeekTreasureTask")
--存在配置
if cfgSeekTreasureTasks == nil or not next(cfgSeekTreasureTasks) then
log.debug("寻味之旅 配置为空")
return
end
local cfgSeekTreasureTaskList = {}
for _, cfgSeekTreasureTask in ipairs(cfgSeekTreasureTasks) do
if cfgSeekTreasureTask.seekTreasureId == activityId then
table.insert(cfgSeekTreasureTaskList,cfgSeekTreasureTask)
end
end
--触发完成任务
local finishIds = taskListEvent:Condition(player , taskId , count , player.gameData.SeekTreasureMap[activityId].seekTreasureTasks , cfgSeekTreasureTaskList)
local isAllTaskFinish = true
--是否完成所有任务
for _, value in pairs(player.gameData.SeekTreasureMap[activityId].seekTreasureTasks) do
if value.status ~= dataType.TaskStatus_Finish then
isAllTaskFinish =false
break
end
end
--是否完成所有任务
if isAllTaskFinish then
player.gameData.SeekTreasureMap[activityId].seekTreasureTasks={}
player.gameData.SeekTreasureMap[activityId].conParticipationNum = 1
skynet.server.msgTips:Add(player,113)
end
end
--改变测试数据
function ActivitySeekTreasure:ChangeTask(player,taskId,count)
onEventFired(player,taskId,count)
end
-- 注册事件处理函数
taskListEvent:Register(onEventFired,"寻味之旅")
skynet.server.activitySeekTreasure = ActivitySeekTreasure
return ActivitySeekTreasure