476 lines
17 KiB
Lua
476 lines
17 KiB
Lua
------------------------------------------------
|
|
-- 作者: 王圣
|
|
-- 日期: 2021-03-19
|
|
-- 文件: TaskManagerMsg.lua
|
|
-- 模块: TaskManagerMsg
|
|
-- 描述: 任务消息
|
|
------------------------------------------------
|
|
-- 引用
|
|
local TaskManagerMsg = {
|
|
SyncTime = 0,
|
|
IsReceiveTaskList = false,
|
|
}
|
|
|
|
function TaskManagerMsg:Initialize()
|
|
self.IsReceiveTaskList = false
|
|
end
|
|
|
|
function TaskManagerMsg:UnInitialize()
|
|
self.IsReceiveTaskList = false
|
|
end
|
|
|
|
-- 请求完成任务
|
|
function TaskManagerMsg:ReqTaskFinish(data)
|
|
if data == nil then
|
|
return
|
|
end
|
|
local _msgData = nil
|
|
if data.SubType ~= nil then
|
|
_msgData = {
|
|
type = data.Type,
|
|
modelId = data.TagId,
|
|
taskId = data.Id,
|
|
rewardPer = 0,
|
|
subType = data.SubType
|
|
}
|
|
else
|
|
_msgData = {
|
|
type = data.Type,
|
|
modelId = data.TagId,
|
|
taskId = data.Id,
|
|
rewardPer = 0
|
|
}
|
|
end
|
|
GameCenter.Network.Send("MSG_Task.ReqTaskFinish", _msgData)
|
|
end
|
|
|
|
-- 请求放弃任务
|
|
function TaskManagerMsg:GiveUpTask(data)
|
|
if data == nil then
|
|
return
|
|
end
|
|
GameCenter.Network.Send("MSG_Task.ReqGiveUpTask", {taskId = data.Id, type = data.Type, modelId = 0})
|
|
end
|
|
|
|
-- 请求刷新仙盟任务
|
|
function TaskManagerMsg:ReqRefreashXmTask(gold)
|
|
GameCenter.Network.Send("MSG_Task.ReqRefreshGuildTaskPool", {
|
|
useGold = gold
|
|
})
|
|
end
|
|
|
|
-- 请求接取任务
|
|
function TaskManagerMsg:ReqAccessTask(id)
|
|
local _task = GameCenter.LuaTaskManager:GetTask(id)
|
|
GameCenter.Network.Send("MSG_Task.ReqReceiveTask", {
|
|
taskId = id,
|
|
type = _task.Data.Type,
|
|
subType = _task.Data.SubType
|
|
})
|
|
end
|
|
|
|
-- 升星
|
|
function TaskManagerMsg:ReqDailyUpStar(id)
|
|
GameCenter.Network.Send("MSG_Task.ReqDailyUpStar", {
|
|
modelId = id
|
|
})
|
|
end
|
|
|
|
-- 一键完成当前任务
|
|
function TaskManagerMsg:ReqOneKeyOverTask(task)
|
|
if task ~= nil then
|
|
GameCenter.Network.Send("MSG_Task.ReqOneKeyOverTask", {
|
|
type = task.Data.Type,
|
|
taskModelId = task.Data.Id,
|
|
subType = task.Data.SubType
|
|
})
|
|
end
|
|
end
|
|
|
|
-- 一键完成所有任务
|
|
function TaskManagerMsg:ReqQuickFinish(type1, type2)
|
|
GameCenter.Network.Send("MSG_Task.ReqQuickFinish", {
|
|
type = type1,
|
|
subType = type2
|
|
})
|
|
end
|
|
|
|
-- 请求任务是否完成
|
|
function TaskManagerMsg:ReqCheckTaskIsFinish(ty, id)
|
|
GameCenter.Network.Send("MSG_Task.ReqCheckTaskIsFinish", {
|
|
type = ty,
|
|
taskId = id
|
|
})
|
|
end
|
|
|
|
-- 请求刷新任务
|
|
function TaskManagerMsg:ReqRefreshTask(ty)
|
|
GameCenter.Network.Send("MSG_Task.ReqRefreshTask", {
|
|
type = ty
|
|
})
|
|
end
|
|
|
|
-- 请求任务状态变更
|
|
function TaskManagerMsg:ReqChangeTaskState(ty, id)
|
|
GameCenter.Network.Send("MSG_Task.ReqChangeTaskState", {
|
|
type = ty,
|
|
modelId = id
|
|
})
|
|
end
|
|
|
|
-- 服务器消息返回
|
|
function TaskManagerMsg:OnAcceptTask(id)
|
|
-- 引导检测
|
|
GameCenter.GuideSystem:Check(GuideTriggerType.TaskAccept, id)
|
|
end
|
|
|
|
--请求领取日常任务奖励
|
|
function TaskManagerMsg:ReqDailyTaskCountReward(num)
|
|
GameCenter.Network.Send("MSG_Task.ReqDailyTaskCountReward", {
|
|
count = num
|
|
})
|
|
end
|
|
|
|
-- / <summary>
|
|
-- / 任务数据
|
|
-- / </summary>
|
|
-- / <param name="result"></param>
|
|
function TaskManagerMsg:GS2U_ResTaskList(result)
|
|
GameCenter.LuaTaskManager:ClearTask()
|
|
-- 日常
|
|
if result.dailyTask ~= nil and #result.dailyTask > 0 then
|
|
GameCenter.LuaTaskManager:CreateDailyTask(result.dailyTask)
|
|
end
|
|
-- 支线
|
|
if result.branchTask ~= nil and #result.branchTask > 0 then
|
|
GameCenter.LuaTaskManager:CreateBranchTask(result.branchTask)
|
|
end
|
|
-- 帮会
|
|
if result.conquerTask ~= nil and #result.conquerTask > 0 then
|
|
GameCenter.LuaTaskManager:CreateGuildTask(result.conquerTask)
|
|
end
|
|
-- 转职
|
|
if result.genderTask ~= nil and #result.genderTask > 0 then
|
|
GameCenter.LuaTaskManager:CreateTransferTask(result.genderTask)
|
|
end
|
|
-- 战场任务
|
|
if result.battleFieldTask ~= nil and #result.battleFieldTask > 0 then
|
|
GameCenter.LuaTaskManager:CreateBattleTask(result.battleFieldTask)
|
|
end
|
|
-- 新支线任务
|
|
if result.loopTask ~= nil and #result.loopTask > 0 then
|
|
GameCenter.LuaTaskManager:CreateLoopTask(result.loopTask)
|
|
end
|
|
-- 主线
|
|
if result.mainTask ~= nil then
|
|
GameCenter.LuaTaskManager:CreateMainTask(result.mainTask)
|
|
if result.mainTask.overIDs ~= nil then
|
|
for i = 1, #result.mainTask.overIDs do
|
|
GameCenter.LuaTaskManager:PushOverId(result.mainTask.overIDs[i])
|
|
end
|
|
end
|
|
end
|
|
if GameCenter.LuaTaskManager.DailyBoxState == nil then
|
|
GameCenter.LuaTaskManager.DailyBoxState = Dictionary:New()
|
|
GameCenter.LuaTaskManager.DailyBoxState:Add(10, false)
|
|
GameCenter.LuaTaskManager.DailyBoxState:Add(20, false)
|
|
end
|
|
if result.countRewardList ~= nil then
|
|
for i = 1, #result.countRewardList do
|
|
local _rewardInfo = result.countRewardList[i]
|
|
GameCenter.LuaTaskManager.DailyBoxState[_rewardInfo.count] = _rewardInfo.isReward
|
|
end
|
|
end
|
|
GameCenter.LuaTaskManager.XmReciveCount = result.guildReceiveCount
|
|
GameCenter.LuaTaskManager.XmRefreashCount = result.guildRefreshCount
|
|
GameCenter.LuaTaskManager.TransferTaskStep = result.overGenderTaskCount
|
|
GameCenter.LuaTaskManager.BattleTaskStep = result.nowBattleTaskCount
|
|
GameCenter.LuaTaskManager.BattleTaskFreeCount = result.remainFreeFreshCount
|
|
GameCenter.LuaTaskManager.HuSongLeftCount = result.remainEscortTaskCount
|
|
GameCenter.LuaTaskManager.BattleTaskFreshTime = result.autoFreshRemainTime
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKINIT)
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG)
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_CHANJEJOB_TASK_UPDATED)
|
|
self.IsReceiveTaskList = true
|
|
end
|
|
|
|
-- / <summary>
|
|
-- / 任务完成
|
|
-- / </summary>
|
|
-- / <param name="result"></param>
|
|
function TaskManagerMsg:GS2U_ResTaskFinish(result)
|
|
if not result.submitResult then
|
|
GameCenter.PushFixEvent(UIEventDefine.UINpcTalkForm_CLOSE)
|
|
return
|
|
end
|
|
if result.state == 3 then -- 任务不存在
|
|
-- 客户端直接删除该条不存在的任务
|
|
GameCenter.LuaTaskManager:RemoveTask(result.modelId)
|
|
-- 任务改变
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG)
|
|
if DataConfig.DataTaskGender[result.modelId] ~= nil then
|
|
--删除了转职任务
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_CHANJEJOB_TASK_UPDATED)
|
|
end
|
|
return
|
|
end
|
|
-- 统计任务完成
|
|
GameCenter.SDKSystem:SendEventTaskFinsh(result.modelId, result.type == TaskType.Main and "main" or "branch")
|
|
GameCenter.LuaTaskManager:SetLoopTaskStep(result.type, result.currentCount)
|
|
GameCenter.LuaTaskManager:CompeletTask(result)
|
|
if result.finshType == 1 then
|
|
-- 一键完成
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKFINISH_ONEKEY)
|
|
end
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKINIT)
|
|
-- 任务改变
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG)
|
|
-- 任务完成
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKFINISH, result.modelId)
|
|
if DataConfig.DataTaskGender[result.modelId] ~= nil then
|
|
--完成转职任务
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_CHANJEJOB_TASK_UPDATED)
|
|
end
|
|
-- 引导检测
|
|
GameCenter.GuideSystem:Check(GuideTriggerType.TaskEnd, result.modelId)
|
|
end
|
|
|
|
-- 删除任务
|
|
function TaskManagerMsg:GS2U_ResTaskDelete(result)
|
|
GameCenter.LuaTaskManager:RemoveTask(result.modelId)
|
|
GameCenter.PushFixEvent(UIEventDefine.UINpcTalkForm_CLOSE)
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG)
|
|
if DataConfig.DataTaskGender[result.modelId] ~= nil then
|
|
--删除了转职任务
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_CHANJEJOB_TASK_UPDATED)
|
|
end
|
|
end
|
|
|
|
-- / <summary>
|
|
-- / 主线任务变更
|
|
-- / </summary>
|
|
-- / <param name="result"></param>
|
|
function TaskManagerMsg:GS2U_ResMainTaskChange(result)
|
|
if not self.IsReceiveTaskList then
|
|
return
|
|
end
|
|
local _value = GameCenter.LuaTaskManager.TaskContainer.Container[TaskType.Main]
|
|
if _value ~= nil then
|
|
local _task = GameCenter.LuaTaskManager.TaskContainer:FindTakByID(result.mainTask.modelId)
|
|
if _task == nil then
|
|
-- 主线任务只有一条清除其余缓存 并且创建一条主线任务
|
|
GameCenter.LuaTaskManager.TaskContainer:Remove(TaskType.Main)
|
|
GameCenter.LuaTaskManager:CreateMainTask(result.mainTask)
|
|
self:OnAcceptTask(result.mainTask.modelId)
|
|
else
|
|
-- 更新主线任务
|
|
GameCenter.LuaTaskManager:UpdateMainTask(result, _task)
|
|
end
|
|
else
|
|
-- 没有主线任务 创建主线任务
|
|
GameCenter.LuaTaskManager:CreateMainTask(result.mainTask)
|
|
self:OnAcceptTask(result.mainTask.modelId)
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_GETNEWTASK, result.mainTask.modelId)
|
|
end
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG)
|
|
end
|
|
|
|
-- / <summary>
|
|
-- / 日常任务变更
|
|
-- / </summary>
|
|
-- / <param name="result"></param>
|
|
function TaskManagerMsg:GS2U_ResDailyTaskChang(result)
|
|
if not self.IsReceiveTaskList then
|
|
return
|
|
end
|
|
local _task = GameCenter.LuaTaskManager.TaskContainer:FindByTypeAndID(TaskType.Daily, result.dailyTask.modelId)
|
|
if _task ~= nil then
|
|
-- 更新日常任务
|
|
GameCenter.LuaTaskManager:UpdateDailyTask(result, _task)
|
|
else
|
|
-- 没有日常任务 创建日常任务
|
|
local _list = List:New()
|
|
_list:Add(result.dailyTask)
|
|
if not result.isAuto then
|
|
GameCenter.LuaTaskManager.IsAutoDailyTask = false
|
|
end
|
|
GameCenter.LuaTaskManager:CreateDailyTask(_list)
|
|
self:OnAcceptTask(result.dailyTask.modelId)
|
|
end
|
|
GameCenter.PushFixEvent(UIEventDefine.UINpcTalkForm_CLOSE)
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG, result.dailyTask)
|
|
end
|
|
|
|
-- 公会任务变更
|
|
function TaskManagerMsg:GS2U_ResGuildTaskChang(result)
|
|
if not self.IsReceiveTaskList then
|
|
return
|
|
end
|
|
if not GameCenter.LuaTaskManager.IsAutoGuildTask then
|
|
GameCenter.LuaTaskManager.IsAutoGuildTask = true
|
|
end
|
|
local _task = GameCenter.LuaTaskManager.TaskContainer:FindByTypeAndID(TaskType.Guild, result.questsTask.modelId)
|
|
if _task == nil then
|
|
if GameCenter.LuaTaskManager:IsInNotRecieveContainer(result.questsTask.modelId) then
|
|
-- 玩家主动接取该任务 把该任务移除未接取任务容器 执行该任务行为
|
|
GameCenter.LuaTaskManager:RemoveTaskInNotRecieve(result.questsTask.modelId)
|
|
end
|
|
-- 工会任务任务只有一条清除其余缓存 并且创建一条主线任务
|
|
GameCenter.LuaTaskManager.TaskContainer:Remove(TaskType.Guild)
|
|
local _list = List:New()
|
|
_list:Add(result.questsTask)
|
|
GameCenter.LuaTaskManager:CreateGuildTask(_list)
|
|
self:OnAcceptTask(result.questsTask.modelId)
|
|
else
|
|
-- 更新日常任务
|
|
GameCenter.LuaTaskManager:UpdateGuildTask(result, _task)
|
|
end
|
|
GameCenter.PushFixEvent(UIEventDefine.UINpcTalkForm_CLOSE)
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG, result.questsTask)
|
|
if result.questsTask.isReceive and not GameCenter.LuaTaskManager:CanSubmitTask(result.questsTask.modelId) then
|
|
GameCenter.PushFixEvent(UIEventDefine.UIGuildNewForm_CLOSE)
|
|
GameCenter.PushFixEvent(UIEventDefine.UIGuildTaskGetForm_Close)
|
|
GameCenter.LuaTaskManager.XmReciveCount = GameCenter.LuaTaskManager.XmReciveCount + 1
|
|
end
|
|
end
|
|
|
|
-- 仙盟任务刷新消息变更
|
|
function TaskManagerMsg:GS2U_ResGuildTaskPool(result)
|
|
if not self.IsReceiveTaskList then
|
|
return
|
|
end
|
|
if result == nil then
|
|
return
|
|
end
|
|
-- 清除之前保存的未接取的仙盟任务
|
|
GameCenter.LuaTaskManager:ClearXmTasks()
|
|
GameCenter.LuaTaskManager.XmRefreashCount = result.refreshCount
|
|
GameCenter.LuaTaskManager.XmReciveCount = result.receiveCount
|
|
if result.taskList ~= nil then
|
|
for i = 1, #result.taskList do
|
|
local _task =
|
|
GameCenter.LuaTaskManager.TaskContainer:FindByTypeAndID(TaskType.Guild, result.taskList[i].modelId)
|
|
if _task == nil then
|
|
-- 日常任务任务只有一条清除其余缓存 并且创建一条主线任务
|
|
GameCenter.LuaTaskManager.TaskContainer:Remove(TaskType.Guild)
|
|
local _list = List:New()
|
|
_list:Add(result.taskList[i])
|
|
GameCenter.LuaTaskManager:CreateGuildTask(_list)
|
|
self:OnAcceptTask(result.taskList[i].modelId)
|
|
else
|
|
GameCenter.LuaTaskManager:UpdateGuildTask(result.taskList[i], _task)
|
|
end
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG, result.taskList[i])
|
|
end
|
|
end
|
|
GameCenter.PushFixEvent(UIEventDefine.UINpcTalkForm_CLOSE)
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_GUILDTASKLIST_UPDATE)
|
|
end
|
|
|
|
-- 支线任务变更
|
|
function TaskManagerMsg:GS2U_ResBranchTaskChang(result)
|
|
if not self.IsReceiveTaskList then
|
|
return
|
|
end
|
|
local _value = GameCenter.LuaTaskManager.TaskContainer.Container[TaskType.Branch]
|
|
if _value ~= nil then
|
|
local _task = GameCenter.LuaTaskManager.TaskContainer:FindTakByID(result.branchTask.modelId)
|
|
if _task == nil then
|
|
local _list = List:New()
|
|
_list:Add(result.branchTask)
|
|
GameCenter.LuaTaskManager:CreateBranchTask(_list)
|
|
self:OnAcceptTask(result.branchTask.modelId)
|
|
else
|
|
-- 更新日常任务
|
|
GameCenter.LuaTaskManager:UpdateBranchTask(result, _task)
|
|
end
|
|
else
|
|
-- 没有日常任务 创建日常任务
|
|
local _list = List:New()
|
|
_list:Add(result.branchTask)
|
|
GameCenter.LuaTaskManager:CreateBranchTask(_list)
|
|
self:OnAcceptTask(result.branchTask.modelId)
|
|
end
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG)
|
|
end
|
|
|
|
-- 转职任务更新
|
|
function TaskManagerMsg:GS2U_ResGenderTaskChange(result)
|
|
if not self.IsReceiveTaskList then
|
|
return
|
|
end
|
|
local _isNewTask = false
|
|
local _value = GameCenter.LuaTaskManager.TaskContainer.Container[TaskType.ZhuanZhi]
|
|
if _value ~= nil then
|
|
local _task = GameCenter.LuaTaskManager.TaskContainer:FindTakByID(result.genderTask.modelId)
|
|
if _task == nil then
|
|
-- 转职任务任务只有一条清除其余缓存 并且创建一条主线任务
|
|
GameCenter.LuaTaskManager.TaskContainer:Remove(TaskType.ZhuanZhi)
|
|
local _list = List:New()
|
|
_list:Add(result.genderTask)
|
|
_isNewTask = true
|
|
GameCenter.LuaTaskManager:CreateTransferTask(_list)
|
|
self:OnAcceptTask(result.genderTask.modelId)
|
|
else
|
|
-- 更新日常任务
|
|
GameCenter.LuaTaskManager:UpdateTransferTask(result, _task)
|
|
end
|
|
else
|
|
-- 没有日常任务 创建日常任务
|
|
local _list = List:New()
|
|
_list:Add(result.genderTask)
|
|
_isNewTask = true
|
|
GameCenter.LuaTaskManager:CreateTransferTask(_list)
|
|
self:OnAcceptTask(result.genderTask.modelId)
|
|
end
|
|
GameCenter.PushFixEvent(UIEventDefine.UINpcTalkForm_CLOSE)
|
|
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG)
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_CHANJEJOB_TASK_UPDATED, _isNewTask)
|
|
end
|
|
|
|
function TaskManagerMsg:ResDailyTaskFinish(msg)
|
|
if msg == nil then
|
|
return
|
|
end
|
|
local _rewards = List:New()
|
|
if msg.rewards ~= nil then
|
|
for i = 1, #msg.rewards do
|
|
local _info = msg.rewards[i]
|
|
local _id = _info.modelId
|
|
local _num = _info.count
|
|
local _itemData = {Id = _id, Num = _num, IsBind = true}
|
|
_rewards:Add(_itemData)
|
|
end
|
|
end
|
|
local _exRewards = List:New()
|
|
if msg.extraRewards ~= nil then
|
|
for i = 1, #msg.extraRewards do
|
|
local _info = msg.extraRewards[i]
|
|
local _id = _info.modelId
|
|
local _num = _info.count
|
|
local _itemData = {Id = _id, Num = _num, IsBind = true}
|
|
_exRewards:Add(_itemData)
|
|
end
|
|
end
|
|
local _finalData = {Rewards = _rewards, ExRewards = _exRewards, Count = msg.taskCount}
|
|
GameCenter.PushFixEvent(UILuaEventDefine.UIDailyTaskFinishForm_OPEN, _finalData)
|
|
end
|
|
|
|
function TaskManagerMsg:ResDailyTaskCountReward(msg)
|
|
if msg == nil then
|
|
return
|
|
end
|
|
--DailyBoxState
|
|
if GameCenter.LuaTaskManager.DailyBoxState == nil then
|
|
GameCenter.LuaTaskManager.DailyBoxState = Dictionary:New()
|
|
GameCenter.LuaTaskManager.DailyBoxState:Add(10, false)
|
|
GameCenter.LuaTaskManager.DailyBoxState:Add(20, false)
|
|
end
|
|
if msg.countReward ~= nil then
|
|
GameCenter.LuaTaskManager.DailyBoxState[msg.countReward.count] = msg.countReward.isReward
|
|
end
|
|
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_NEWDAILYTASK_REFRESH)
|
|
end
|
|
|
|
return TaskManagerMsg
|