Files
Main/Assets/GameAssets/Resources/Lua/Logic/TaskSystem/Manager/LuaTaskManager.lua
2025-01-25 04:38:09 +08:00

1509 lines
47 KiB
Lua
Raw 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.

------------------------------------------------
-- 作者: 王圣
-- 日期: 2021-03-19
-- 文件: LuaTaskManager.lua
-- 模块: LuaTaskManager
-- 描述: lua任务管理
------------------------------------------------
-- 引用
local L_MainTask = require "Logic.TaskSystem.Instance.MainTask"
local L_DailyTask = require "Logic.TaskSystem.Instance.DailyTask"
local L_GuildTask = require "Logic.TaskSystem.Instance.GuildTask"
local L_BranchTask = require "Logic.TaskSystem.Instance.BranchTask"
local L_TransferTask = require "Logic.TaskSystem.Instance.TransferTask"
local L_TaskLock = require "Logic.TaskSystem.Manager.TaskLock"
local L_TaskTarget = require "Logic.TaskSystem.Data.TaskTarget"
local L_TaskContainer = require "Logic.TaskSystem.Container.TaskContainer"
local L_BehaviorManager = require "Logic.TaskSystem.Manager.TaskBehaviorManager"
local L_CSNpcTaskState = CS.Thousandto.Code.Logic.NpcTaskState
local LuaTaskManager = {
CurSelectTaskID = 0, -- 当前选中的任务id
TransferTaskStep = 0, -- 转职任务完成的环数
BattleTaskStep = 0, -- 战场任务完成次数
BattleTaskAllStep = 10, -- 战场任务总次数
BattleTaskFreeCount = 0, -- 战场任务免费刷新次数
HuSongLeftCount = 0, -- 护送任务剩余次数
SelectDailyTaskId = 0, -- 外部选中的日常周长任务ID
WaiteFormId = 0, -- 等待关闭的窗体ID
BattleTaskFreshTime = 0, -- 战场任务刷新时间
SyncTime = 0,
IsAutoMainTask = false, -- 是否开始自动主线任务
IsAutoGuildTask = false, -- 是否开始自动公会任务
IsAutoDailyTask = false, -- 是否开始自动首席任务
IsAutoTransferTask = false, -- 是否开始自动转职任务
IsAutoBranchExTask = false, -- 是否开始自动支线环任务
IsAutoTaskForTransPort = false, -- 切地图后判断是否开始执行任务
IsAutoAccessTaskForTrans = false, -- 切地图接取任务
IsShowGuide = false, -- 是否显示引导
IsClickAccessHuSongTask = false, -- 是否手动领取护送任务
IsWiptOutClick = false, -- 是否点击扫荡
IsStopAllTask = false, -- 是否停止所有正在执行的任务
IsLocalUserTeleport = false, -- 是使用了小飞鞋在当前地图传送 否则是跨地图使用小飞鞋
TaskContainer = nil, -- 任务容器
OverTaskIdList = nil,
OldParam = nil,
CurSelectDailyTask = nil, -- 当前选中的日常task
TaskBeHaviorManager = nil,
FlyItemId = 0, -- 小飞鞋道具id
FlyVip = 0, -- 小飞鞋免费使用权限
-- 仙盟任务
XmRefreashCount = 0, -- 仙盟任务可刷新次数
XmReciveCount = 0, -- 仙盟任务可接取次数
LockList = List:New(),
IsSuspend = false,
MaxXmTaskCount = 5,
DailyBoxState = nil,
}
function LuaTaskManager:InitiactiveExitPlaneCopy(o, sender)
-- 玩家主动点击退出位面副本
self.IsStopAllTask = true;
PlayerBT.ChangeState(PlayerBDState.Default);
end
function LuaTaskManager:WaitCloseForm(o, sender)
local _id = o;
if _id == self.WaiteFormId then
self.IsAutoMainTask = true;
self.WaiteFormId = 0;
-- 继续执行主线任务
GameCenter.TaskController:Run(self:GetMainTaskId());
end
end
-- 日常活动刷新后回调
function LuaTaskManager:OnDailyRefresh(o, sender)
if self.TaskContainer ~= nil then
self.TaskContainer:UpdateAllTaskTargetDes()
end
end
function LuaTaskManager:OnCoinChange(o, sender)
local _type = o;
if _type == ItemTypeCode.ActivePoint then
if self.TaskContainer ~= nil then
self.TaskContainer:UpdateAllTaskTargetDes();
end
end
end
-- 战斗力改变
function LuaTaskManager:OnFightPowerChange(o, sender)
if self.TaskContainer ~= nil then
self.TaskContainer:UpdateFightPowerLimitTask();
end
end
function LuaTaskManager:IniItialization()
self.TaskContainer = L_TaskContainer:New();
self.TaskBeHaviorManager = L_BehaviorManager:New();
self.TaskBeHaviorManager:IniItialization();
self.OverTaskIdList = List:New();
-- 初始化小飞鞋道具id
local _gCfg = DataConfig.DataGlobal[GlobalName.FlyShoeID];
if _gCfg ~= nil then
self.FlyItemId = tonumber(_gCfg.Params);
end
-- 初始化小飞鞋使用权限
DataConfig.DataVip:ForeachCanBreak(function(k, v)
local _strList = Utils.SplitNumber(v.VipPowerId, '_');
if _strList ~= nil then
for i = 1, #_strList do
local _id = tonumber(_strList[i]);
if _id == 1 then
self.FlyVip = v.VipLevel;
return true
end
end
end
end)
_gCfg = nil
-- 仙盟任务最大领取数量
_gCfg = DataConfig.DataGlobal[GlobalName.GuildTaskMax];
if _gCfg ~= nil then
local _arr = Utils.SplitStr(_gCfg.Params, ';')
local _single = Utils.SplitNumber(_arr[#_arr], '_') -- .Split('_');
if #_single >= 2 then
self.MaxXmTaskCount = _single[2];
end
end
GameCenter.TimerEventSystem:AddTimeStampDayEvent(5, 10,
true, nil, function(id, remainTime, param)
if GameCenter.LuaTaskManager.DailyBoxState ~= nil then
GameCenter.LuaTaskManager.DailyBoxState[10] = false
GameCenter.LuaTaskManager.DailyBoxState[20] = false
end
end)
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_INITIATIVE_EXIT_PLANECOPY, self.InitiactiveExitPlaneCopy,
self);
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_FORM_ID_CLOSE_AFTER, self.WaitCloseForm, self);
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_REFRESH_DAILYPANEL, self.OnDailyRefresh, self);
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_REFRESH_ACTIVITYLIST, self.OnDailyRefresh, self);
GameCenter.RegFixEventHandle(LogicEventDefine.EVENT_COIN_CHANGE_UPDATE, self.OnCoinChange, self);
GameCenter.RegFixEventHandle(LogicEventDefine.EID_EVENT_FIGHT_POWER_CHANGED, self.OnFightPowerChange, self);
end
function LuaTaskManager:UnInitialization()
if self.TaskContainer ~= nil then
self.TaskContainer:Clear()
end
if self.TaskBeHaviorManager ~= nil then
self.TaskBeHaviorManager:UnIniItialization()
end
self.DailyBoxState = nil
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_INITIATIVE_EXIT_PLANECOPY, self.InitiactiveExitPlaneCopy,
self);
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_FORM_ID_CLOSE_AFTER, self.WaitCloseForm, self);
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_REFRESH_DAILYPANEL, self.OnDailyRefresh, self);
GameCenter.UnRegFixEventHandle(LogicEventDefine.EID_EVENT_REFRESH_ACTIVITYLIST, self.OnDailyRefresh, self);
GameCenter.UnRegFixEventHandle(LogicEventDefine.EVENT_COIN_CHANGE_UPDATE, self.OnCoinChange, self);
end
-- 主线
function LuaTaskManager:CreateMainTask(info)
local _task = L_MainTask:New(info)
return _task
end
-- 日常
function LuaTaskManager:CreateDailyTask(infos)
local _list = List:New()
if infos ~= nil then
for i = 1, #infos do
local _task = L_DailyTask:New(infos[i], infos[i].isReceive)
_list:Add(_task)
end
end
return _list
end
-- 帮会
function LuaTaskManager:CreateGuildTask(infos)
local _list = List:New()
if infos ~= nil then
for i = 1, #infos do
local _task = L_GuildTask:New(infos[i], infos[i].isReceive)
_list:Add(_task)
end
end
return _list
end
-- 支线
function LuaTaskManager:CreateBranchTask(infos)
if infos ~= nil then
for i = 1, #infos do
local _task = L_BranchTask:New(infos[i])
end
end
end
-- 转职
function LuaTaskManager:CreateTransferTask(infos)
if infos ~= nil then
for i = 1, #infos do
local _task = L_TransferTask:New(infos[1], infos[1].isReceive)
end
end
end
-- 添加已完成任务
function LuaTaskManager:PushOverId(id)
self.OverTaskIdList:Add(id);
end
-- 接取任务
function LuaTaskManager:AccessTask(taskId)
GameCenter.TaskManagerMsg:ReqAccessTask(taskId);
end
-- 自动寻路前往接取任务
function LuaTaskManager:AutoAccessTask(taskId)
self.IsAutoAccessTaskForTrans = false;
self.CurSelectTaskID = taskId;
local _task = self.TaskContainer:FindTakByID(taskId);
if _task ~= nil then
if _task.Data.IsAccess then
Debug.LogError("任务容器数据存储错误,该任务已经被接取");
return;
end
-- 调用Npc寻路接口
local _lp = GameCenter.GameSceneSystem:GetLocalPlayer();
if _lp == nil then
return;
end
if _task.Data.MapID ~= GameCenter.MapLogicSystem.MapCfg.MapId then
-- 传送
if _task.Data.Type ~= TaskType.Guild then
_lp:Action_CrossMapTran(task.Data.MapID);
end
self.IsAutoAccessTaskForTrans = true; -- 懒得改名字就 意思就是代表就是是否开始执行任务 不要在意Main
else
local _npcId = _task:GetAccessNpcId(taskId);
PlayerBT.Task:TaskTalkToNpc(_npcId, _task.Data.Id);
end
end
end
-- 提交任务
function LuaTaskManager:SubMitTaskNoParam()
self:AddLock(self.CurSelectTaskID);
local _subMitId = self.CurSelectTaskID;
local _task = self.TaskContainer:FindTakByID(_subMitId);
if _task ~= nil then
local _modelId = 0
local _behavior = self:GetBehavior(_task.Data.Id);
if _behavior ~= nil then
_modelId = _behavior.TaskTarget.TagId;
end
local _data = {
Id = _task.Data.Id,
Type = _task.Data.Type,
TagId = _modelId,
SubType = _task.Data.SubType,
RewardPer = 0
}
GameCenter.TaskManagerMsg:ReqTaskFinish(_data)
end
end
function LuaTaskManager:SubMitTask(id)
local _task = self:GetTask(id);
if _task ~= nil then
local _modelId = 0
local _behavior = self:GetBehavior(_task.Data.Id);
if _behavior ~= nil then
_modelId = _behavior.TaskTarget.TagId;
end
local _data = {
Id = _task.Data.Id,
Type = _task.Data.Type,
TagId = _modelId,
SubType = nil,
RewardPer = 1
}
GameCenter.TaskManagerMsg:ReqTaskFinish(_data)
end
end
-- 在UI上提交日常任务
function LuaTaskManager:SubMitDailyTaskForUI(task, rewardPer)
if task ~= nil then
local _modelId = 0
local _behavior = self:GetBehavior(task.Data.Id);
if _behavior ~= nil then
_modelId = _behavior.TaskTarget.TagId;
end
local _data = {
Id = task.Data.Id,
Type = task.Data.Type,
TagId = _modelId,
SubType = nil,
RewardPer = rewardPer
}
GameCenter.TaskManagerMsg:ReqTaskFinish(_data)
end
end
-- 完成任务
function LuaTaskManager:CompeletTask(msg)
-- 检测是否有需要展示的道具
local _task = self.TaskContainer:FindTakByID(msg.modelId);
if _task ~= nil then
if _task.Data.Type == TaskType.Main then
if _task.Data.Cfg.Type == TaskBeHaviorType.OpenUI then
-- 暂停主线任务等待操作UI关闭
if _task.Data.Cfg.CloseNpcPanel ~= 0 then
self.IsAutoMainTask = false;
self.WaiteFormId = _task.Data.Cfg.CloseNpcPanel * 10;
end
end
end
end
-- 移除任务
self:RemoveTaskEx(_task);
GameCenter.PushFixEvent(UIEventDefine.UINpcTalkForm_CLOSE)
GameCenter.PushFixEvent(LogicEventDefine.EID_EVENT_TASKCHANG)
end
-- 放弃任务
function LuaTaskManager:GiveUpTask(id, type)
local _data = {
Id = id,
Type = type
};
GameCenter.TaskManagerMsg:GiveUpTask(_data)
end
-- 请求刷新仙盟任务
function LuaTaskManager:ReqRefreashXmTask(useGold)
GameCenter.TaskManagerMsg:ReqRefreashXmTask(useGold)
end
-- 主线任务变更
function LuaTaskManager:UpdateMainTask(msg, task)
if msg == nil then
return
end
if task == nil then
return
end
-- 更新主线任务数据
local _taskTarget = L_TaskTarget:New();
-- 更新行为
local _behavior = self.TaskBeHaviorManager:GetBehavior(task.Data.Id)
if _behavior ~= nil then
if _behavior.Type == TaskBeHaviorType.CollectItem then
GameCenter.PushFixEvent(UIEventDefine.UIMSGTIPS_SHOWINFO,
L_ItemBase.CreateItemBase(msg.mainTask.useItems.model));
end
_taskTarget.TagId = msg.mainTask.useItems.model;
_taskTarget.Count = msg.mainTask.useItems.num;
self.TaskBeHaviorManager:UpdateBehavior(_behavior, _taskTarget);
if _behavior.Type ~= TaskBeHaviorType.Level and _behavior.Type ~= TaskBeHaviorType.OpenUI then
self.TaskBeHaviorManager:OnDoBehavior(_behavior, task, false, false);
end
-- 主线嵌套其他循环任务的时候 当主线满足提交条件后强制执行主线
if _behavior.Type == TaskBeHaviorType.OpenUI then
if msg.mainTask.useItems.num >= msg.mainTask.useItems.needNum then
self.TaskBeHaviorManager:OnDoBehavior(_behavior, task, false, false);
end
end
task:UpdateTask(_behavior);
end
end
-- 更新日常任务
function LuaTaskManager:UpdateDailyTask(msg, task)
if msg == nil then
return
end
if task == nil then
return
end
local _taskTarget = L_TaskTarget:New();
task.Data.StarNum = msg.dailyTask.star;
task.Data.IsFull = msg.dailyTask.isfull;
task.Data.IsAccess = msg.dailyTask.isReceive;
task.Data.IsOneKey = msg.dailyTask.oneKeyState;
task.Data.CurStep = msg.dailyTask.count;
if task.Data.IsFull then
if task.Data.Cfg ~= nil then
task.Data.RewardList:Clear();
task.Data:SetAwardData(task.Data.Cfg.Rewards5);
end
end
local _behavior = self.TaskBeHaviorManager:GetBehavior(task.Data.Id);
if _behavior ~= nil then
_taskTarget.TagId = msg.dailyTask.useItems.model;
_taskTarget.Count = msg.dailyTask.useItems.num;
self.TaskBeHaviorManager:UpdateBehavior(_behavior, _taskTarget);
if _behavior.Type == TaskBeHaviorType.Collection then
-- 如果是采集
self.TaskBeHaviorManager:OnDoBehavior(_behavior, task, false, false);
end
task:UpdateTask(_behavior);
end
end
-- 更新帮会任务
function LuaTaskManager:UpdateGuildTask(msg, task)
if msg == nil then
return
end
if task == nil then
return
end
local _taskTarget = L_TaskTarget:New();
task.Data.IsAccess = msg.questsTask.isReceive;
task.Data.Count = msg.questsTask.count;
local _behavior = self.TaskBeHaviorManager:GetBehavior(task.Data.Id);
if _behavior ~= nil then
_taskTarget.TagId = msg.questsTask.monsters.model;
_taskTarget.Count = msg.questsTask.monsters.num;
self.TaskBeHaviorManager:UpdateBehavior(_behavior, _taskTarget);
if _behavior.Type == TaskBeHaviorType.Collection then
-- 如果是采集
self.TaskBeHaviorManager:OnDoBehavior(_behavior, task, false, false);
end
task:UpdateTask(_behavior);
end
end
-- 更新帮会任务
function LuaTaskManager:UpdateXmGuildTask(info, task)
if info == nil then
return
end
if task == nil then
return
end
local _taskTarget = L_TaskTarget:New();
task.Data.IsAccess = info.isReceive;
task.Data.Count = info.count;
local _behavior = self.TaskBeHaviorManager:GetBehavior(task.Data.Id);
if _behavior ~= nil then
_taskTarget.TagId = info.monsters.model;
_taskTarget.Count = info.monsters.num;
self.TaskBeHaviorManager:UpdateBehavior(_behavior, _taskTarget);
if _behavior.Type == TaskBeHaviorType.Collection then
-- 如果是采集
self.TaskBeHaviorManager:OnDoBehavior(_behavior, task, false, false);
end
-- GameCenter.TaskBeHaviorManager.DoBehavior(behavior, task, false);
task:UpdateTask(_behavior);
end
end
-- 更新转职任务
function LuaTaskManager:UpdateTransferTask(msg, task)
if msg == nil then
return
end
if task == nil then
return
end
local _taskTarget = L_TaskTarget:New();
-- 更新行为
local _behavior = self.TaskBeHaviorManager:GetBehavior(task.Data.Id);
if _behavior ~= nil then
_taskTarget.TagId = msg.genderTask.target.model;
_taskTarget.Count = msg.genderTask.target.num;
self.TaskBeHaviorManager:UpdateBehavior(_behavior, _taskTarget);
self.TaskBeHaviorManager:OnDoBehavior(_behavior, task, false, false);
task:UpdateTask(_behavior);
end
end
-- 更新支线任务
function LuaTaskManager:UpdateBranchTask(msg, task)
if msg == nil then
return
end
if task == nil then
return
end
local _taskTarget = L_TaskTarget:New();
local _behavior = self.TaskBeHaviorManager:GetBehavior(task.Data.Id);
if _behavior ~= nil then
_taskTarget.TagId = msg.branchTask.monsters.model;
_taskTarget.Count = msg.branchTask.monsters.num;
self.TaskBeHaviorManager:UpdateBehavior(_behavior, _taskTarget);
task:UpdateTask(_behavior);
end
end
-- 更新指引任务
function LuaTaskManager:UpdatePrompteTask(msg, task)
end
-- 更新战场任务
function LuaTaskManager:UpdateBattleTask(info, task)
end
-- 更新新支线任务
function LuaTaskManager:UpdateBranchTaskEx(msg, task)
end
-- 更新护送任务
function LuaTaskManager:UpdateHuSongTask(result, task)
end
-- 添加任务
function LuaTaskManager:AddTask(task)
if self.TaskContainer ~= nil then
self.TaskContainer:Add(task.Data.Type, task);
end
end
-- 添加任务
function LuaTaskManager:AddTaskByType(type, task)
if self.TaskContainer ~= nil then
self.TaskContainer:Add(type, task)
end
end
function LuaTaskManager:RemoveTask(taskId)
local _task = self.TaskContainer:FindTakByID(taskId);
if _task ~= nil then
if _task.Data.Type == TaskType.Main then
if not self.IsAutoMainTask then
self.IsAutoMainTask = true;
end
self:PushOverId(taskID);
elseif _task.Data.Type == TaskType.Guild then
if not self.IsAutoGuildTask then
self.IsAutoGuildTask = true;
end
elseif _task.Data.Type == TaskType.Daily then
if not self.IsAutoDailyTask then
self.IsAutoDailyTask = true;
end
elseif _task.Data.Type == TaskType.ZhuanZhi then
if not self.IsAutoTransferTask then
self.IsAutoTransferTask = true;
end
elseif _task.Data.Type == TaskType.NewBranch then
if not self.IsAutoBranchExTask then
self.IsAutoBranchExTask = true;
end
end
end
self.TaskContainer:Remove(taskId);
self.TaskBeHaviorManager:RmoveBehavior(taskId);
self.CurSelectTaskID = 0;
end
function LuaTaskManager:RemoveTaskEx(task)
if task ~= nil then
if task.Data.Type == TaskType.Main then
if not self.IsAutoMainTask and self.WaiteFormId == 0 then
self.IsAutoMainTask = true;
end
self:PushOverId(task.Data.Id);
elseif task.Data.Type == TaskType.Guild then
if not self.IsAutoGuildTask then
self.IsAutoGuildTask = true;
end
elseif task.Data.Type == TaskType.Daily then
if not self.IsAutoDailyTask then
self.IsAutoDailyTask = true;
end
elseif (task.Data.Type == TaskType.ZhuanZhi) then
if (not self.IsAutoTransferTask) then
self.IsAutoTransferTask = true;
end
elseif task.Data.Type == TaskType.NewBranch then
if (not self.IsAutoBranchExTask) then
self.IsAutoBranchExTask = true;
end
end
self.TaskContainer:Remove(task.Data.Id)
self.TaskBeHaviorManager:RmoveBehavior(task.Data.Id)
self.CurSelectTaskID = 0;
end
end
function LuaTaskManager:ClearTask()
if self.TaskContainer ~= nil then
self.TaskContainer:Clear()
end
if (self.TaskBeHaviorManager.TaskBehaviorContainer ~= nil) then
self.TaskBeHaviorManager.TaskBehaviorContainer:Clear()
end
end
-- 移除指定id的未接取任务
function LuaTaskManager:RemoveTaskInNotRecieve(taskId)
self.TaskContainer:RemoveEx(TaskType.Not_Recieve, taskId)
end
-- 获取任务
function LuaTaskManager:GetTask(taskId)
return self.TaskContainer:FindTakByID(taskId);
end
-- 获取前一条主线任务的ID
function LuaTaskManager:GetPreMainTaskId(taskId)
local _ret = 0
local _cfg = DataConfig.DataTask[taskId]
if (_cfg ~= nil) then
_ret = _cfg.PreTaskId;
end
return _ret;
end
-- 返回玩家是否有接取了该任务
function LuaTaskManager:IsHaveTask(taskId)
local _ret = false
local _task = self.TaskContainer:FindTakByID(taskId);
if _task == nil then
_ret = false;
else
if not _task.Data.IsAccess then
_ret = false;
end
end
return _ret;
end
-- 获取任务名字
function LuaTaskManager:GetTaskName(taskId)
local _task = self:GetTask(taskId)
return self:GetTaskNameEx(_task)
end
-- 获取任务名字
function LuaTaskManager:GetTaskNameEx(task)
local _ret = ""
if task ~= nil then
_ret = task.Data.Name;
local _cfg = task.Data.Cfg
if task.Data.Type == TaskType.Daily then
if _cfg ~= nil then
_ret = UIUtils.CSFormat("{0} ({1}/{2})", _cfg.TaskName, task.Data.CurStep, task.Data.AllStep)
end
elseif task.Data.Type == TaskType.Guild then
if _cfg ~= nil then
if task.Data.Count > task.Data.AllStep then
_ret = UIUtils.CSFormat("{0})", _cfg.TaskName);
else
_ret = UIUtils.CSFormat("{0} ({1}/{2})", _cfg.TaskName, task.Data.Count, task.Data.AllStep)
end
end
end
end
return _ret
end
-- 执行任务
function LuaTaskManager:StarTask(taskId, isClick, isClickByForm)
if isClick == nil then
isClick = false
end
if isClickByForm == nil then
isClickByForm = false
end
self.IsSuspend = false;
if taskId == -1 then
return;
end
local _task = self:GetTask(taskId);
-- Debug.LogTable(_task)
if _task == nil then
return;
end
if _task.Data.Type == TaskType.Main then
if self:IsMainTaskOver(_task.Data.Id) then
return;
end
end
if self:IsLockContain(taskId) then
return;
end
self.TaskBeHaviorManager:DoBehavior(taskId, isClick, isClickByForm)
end
-- 执行日常任务
function LuaTaskManager:StartDailyTask(subType, isClick, isClickByForm)
local _task = self:GetDailyTask();
if _task ~= nil then
self:StarTask(_task.Data.Id, isClick, isClickByForm)
end
end
-- 传送后是否执行任务
function LuaTaskManager:StartTransPortTask()
local _ret = false;
if self.IsAutoTaskForTransPort then
self.IsAutoTaskForTransPort = false;
self.IsLocalUserTeleport = false;
local _behavior = self.TaskBeHaviorManager.Container:Find(self.CurSelectTaskID);
if _behavior ~= nil then
if _behavior.Type == TaskBeHaviorType.OpenUI then
local _isTalkToNpc = _behavior:IsTalkToNpc();
if _isTalkToNpc then
_behavior:DoBehavior();
end
else
_behavior:DoBehavior();
end
end
_ret = true;
end
return _ret;
end
-- 设置循环任务完成次数
function LuaTaskManager:SetLoopTaskStep(type, step)
if type == TaskType.ZhuanZhi then
self.TransferTaskStep = step;
end
end
-- 是否可以提交任务
function LuaTaskManager:CanSubmitTask(taskID)
return self.TaskBeHaviorManager:IsEndBehavior(taskID)
end
-- 是否可以提交任务
function LuaTaskManager:CanSubmitTaskEx(task)
local _ret = false
if task == nil then
_ret = false;
else
if task.Data.IsAccess == true then
_ret = self.TaskBeHaviorManager:IsEndBehavior(task.Data.Id)
end
end
return _ret;
end
-- 指定id的主线任务是否完成
function LuaTaskManager:IsMainTaskOver(taskId)
local _ret = false
for i = 1, #self.OverTaskIdList do
if self.OverTaskIdList[i] == taskId then
_ret = true
break
end
end
return _ret;
end
-- 是否在未接取任务容器中
function LuaTaskManager:IsInNotRecieveContainer(taskId)
local _ret = false
local _task = self.TaskContainer:FindByTypeAndID(TaskType.Not_Recieve, taskId)
if _task == nil then
_ret = false
else
_ret = true
end
return _ret
end
-- 获取当前主线任务
function LuaTaskManager:GetMainTask()
local _ret = nil
local _list = self.TaskContainer:FindTaskByType(TaskType.Main);
if _list ~= nil then
if #_list > 0 then
if #_list > 1 then
Debug.LogError("主线任务有多条 error");
else
local _task = _list[1]
if _task.Data.Type == TaskType.Main then
_ret = _task
end
end
end
end
return _ret;
end
function LuaTaskManager:GetMainTaskId()
local _ret = -1
local _list = self.TaskContainer:FindTaskByType(TaskType.Main);
if _list ~= nil then
if #_list > 0 then
if (#_list > 1) then
Debug.LogError("主线任务有多条 error");
else
local _task = _list[1];
_ret = _task ~= nil and _task.Data.Id or -1;
end
end
end
return _ret;
end
-- 获取第一个日常任务
function LuaTaskManager:GetDailyTask()
local _ret = nil
local _list = self.TaskContainer:FindTaskByType(TaskType.Daily);
if _list ~= nil and #_list > 0 then
_ret = _list[1]
end
if _list == nil then
--查找是否有未接取的日常任务
local _notReciveList = self.TaskContainer:FindTaskByType(TaskType.Not_Recieve);
if _notReciveList ~= nil then
for i = 1, #_notReciveList do
local _task = _notReciveList[i]
if _task ~= nil then
if _task.Data.Type == TaskType.Daily then
_ret = _task
break
end
end
end
end
end
return _ret
end
-- 获取第一个日常任务
function LuaTaskManager:GetNotReciveDailyTask()
local _ret = nil
local _notReciveList = self.TaskContainer:FindTaskByType(TaskType.Not_Recieve);
if _notReciveList ~= nil then
for i = 1, #_notReciveList do
local _task = _notReciveList[i]
if _task ~= nil then
if _task.Data.Type == TaskType.Daily then
_ret = _task
break
end
end
end
end
return _ret
end
-- 获取日常任务(包含未接取的日常任务)
function LuaTaskManager:GetDailyTasks()
local _list = List:New()
local _reciveList = self.TaskContainer:FindTaskByType(TaskType.Daily);
local _notReciveList = self.TaskContainer:FindTaskByType(TaskType.Not_Recieve);
if _reciveList ~= nil then
for i = 1, #_reciveList do
_list:Add(_reciveList[i])
end
end
if _notReciveList ~= nil then
for i = 1, #_notReciveList do
local _task = _notReciveList[i]
if _task.Data.Type == TaskType.Daily then
_list:Add(_task);
end
end
end
if #_list == 0 then
return nil
end
return _list;
end
-- 获取第一个帮会任务
function LuaTaskManager:GetGuildTask()
local _ret = nil
local _list = self.TaskContainer:FindTaskByType(TaskType.Guild);
if _list ~= nil and #_list ~= 0 then
_ret = _list[1]
end
return _ret
end
-- 获取帮会任务列表
function LuaTaskManager:GetGuildTasks()
local _list = List:New()
local _reciveList = self.TaskContainer:FindTaskByType(TaskType.Guild);
local _notReciveList = self.TaskContainer:FindTaskByType(TaskType.Not_Recieve);
if _reciveList ~= nil then
for i = 1, #_reciveList do
if _reciveList[i].Data.SubType ~= 2 then
_list.Add(reciveList[i])
end
end
end
if _notReciveList ~= nil then
for i = 1, #_notReciveList do
local _task = _notReciveList[i]
if _task.Data.Type == TaskType.Guild then
if _task.Data.SubType ~= 2 then
_list.Add(_task)
end
end
end
end
if #_list == 0 then
return nil
end
return _list
end
-- 获取所有的工会任务
function LuaTaskManager:GetAllGuildTasks()
local _list = List:New()
local _reciveList = self.TaskContainer:FindTaskByType(TaskType.Guild)
local _notReciveList = self.TaskContainer:FindTaskByType(TaskType.Not_Recieve)
if _reciveList ~= nil then
for i = 1, #_reciveList do
_list:Add(_reciveList[i]);
end
end
if _notReciveList ~= nil then
for i = 1, #_notReciveList do
local _task = _notReciveList[i]
if _task.Data.Type == TaskType.Guild then
_list:Add(_task)
end
end
end
if #_list == 0 then
return nil
end
return _list
end
-- 获取所有仙盟任务
function LuaTaskManager:GetXmTasks()
local _retList = List:New()
local _list = self:GetAllGuildTasks();
if _list ~= nil then
for i = 1, #_list do
local _task = _list[i];
if _task.Data.SubType == 2 then
_retList:Add(_task)
end
end
end
return _retList;
end
-- 获取当前已经接取的仙盟任务
function LuaTaskManager:GetAccessXmTask()
local _list = self:GetGuildTasks()
if _list ~= nil then
for i = 1, #_list do
local _task = _list[i];
if _task.Data.SubType == 2 and _task.Data.IsAccess then
return _task
end
end
end
return nil
end
-- 清除未接取的仙盟任务
function LuaTaskManager:ClearXmTasks()
local _list = self:GetAllGuildTasks()
if _list ~= nil then
for i = 1, #_list do
local _task = _list[i];
if _task.Data.SubType == 2 and not _task.Data.IsAccess then
-- 删除随机未接取的仙盟任务
self.TaskContainer:Remove(_task.Data.Id);
self.TaskBeHaviorManager:RmoveBehavior(_task.Data.Id)
end
end
end
end
-- 获取支线任务
function LuaTaskManager:GetBranchTask()
local _ret = nil
local _list = self.TaskContainer:FindTaskByType(TaskType.Branch);
if _list ~= nil and #_list > 0 then
_ret = _list[1]
end
return _ret
end
function LuaTaskManager:GetCopyBranchTask()
local _ret = nil
local _list = self.TaskContainer:FindTaskByType(TaskType.Branch)
if _list ~= nil and #_list > 0 then
for i = 1, #_list do
local _task = _list[i]
local _cloneMapId = _task.Data.Cfg.CopymapShow
if _cloneMapId ~= 0 then
_ret = _task
end
end
end
return _ret
end
-- 获取转职任务
function LuaTaskManager:GetTransferTask()
local _ret = nil
local _list = self.TaskContainer:FindTaskByType(TaskType.ZhuanZhi);
if _list ~= nil and #_list > 0 then
_ret = _list[1]
end
return _ret;
end
-- 采集物id是否在任务中
function LuaTaskManager:IsCollectionIdInTask(id)
local _list = self.TaskContainer:FindByBehaviorType(TaskBeHaviorType.Collection);
if _list ~= nil then
for i = 1, #_list do
local _behavior = self.TaskBeHaviorManager.Container:Find(_list[i].Data.Id);
if _behavior ~= nil then
if _behavior.TaskTarget.TagId == id then
return true;
end
end
end
end
return false;
end
function LuaTaskManager:AddLock(taskId)
if not self:IsLockContain(taskId) then
local _lockData = L_TaskLock:New()
_lockData.Id = taskId;
_lockData.Tick = _lockData.Time;
self.LockList.Add(_lockData);
end
end
function LuaTaskManager:IsLockContain(taskId)
for i = 1, #self.LockList do
local _data = self.LockList[i];
if _data.id == taskId then
return true
end
end
return false;
end
function LuaTaskManager:UpdateLockData(dt)
for i = 1, #self.LockList do
local _data = self.LockList[i]
if _data.Tick > 0 then
_data.Tick = _data.Tick - dt
else
_data.Tick = 0;
-- 移除
self.LockList:RemoveAt(i)
end
end
end
-- 创建任务行为
function LuaTaskManager:CreateBehavior(type)
return self.TaskBeHaviorManager:Create(type)
end
-- 获取任务行为
function LuaTaskManager:GetBehavior(id)
return self.TaskBeHaviorManager:GetBehavior(id)
end
-- 添加任务行为
function LuaTaskManager:AddBehavior(id, behavior)
self.TaskBeHaviorManager:Add(id, behavior)
end
-- 设置任务行为目标
function LuaTaskManager:SetBehaviorTag(id, count, talkId, x, y, itemID, type, behavior)
self.TaskBeHaviorManager:SetBehaviorTag(id, count, talkId, x, y, itemID, type, behavior);
end
-- 获取任务行为type
function LuaTaskManager:GetBehaviorType(id)
return self.TaskBeHaviorManager:GetTaskBehaviorType(id)
end
-- 是否暂停任务行为
function LuaTaskManager:GetIsPauseBehavior()
return self.TaskBeHaviorManager.IsPause
end
function LuaTaskManager:SetIsPauseBehavior(b)
self.TaskBeHaviorManager.IsPause = b;
end
-- 对应任务id的行为是否结束
function LuaTaskManager:IsEndBehavior(id)
return self.TaskBeHaviorManager:IsEndBehavior(id);
end
-- 获取任务对应id的ui上面任务行为描述
function LuaTaskManager:GetUIDescript(id)
local _uiDes = ""
local _behavior = self.TaskBeHaviorManager.Container:Find(id)
if _behavior ~= nil then
_uiDes = _behavior.UiDes
end
return _uiDes
end
-- 获取任务对话
function LuaTaskManager:GetTaskTalk(task)
local _ret = nil
local _talk = nil
local _talkId = nil
local _modelId = nil
local _talkCfg = nil
local _behavior = self.TaskBeHaviorManager:GetBehavior(task.Data.Id);
if _behavior ~= nil and _behavior.Type == TaskBeHaviorType.FindCharactor then
if _behavior.TaskTarget.Count < _behavior.TaskTarget.TCount then
-- 如果找人任务对话没有完成
_talkId = _behavior.TaskTarget.TalkId
local _cfg = DataConfig.DataTaskTalk[_talkId]
if _cfg == nil then
_talk = nil
_modelId = -1
else
_talkCfg = DataConfig.DataTaskTalk[_talkId]
if _talkCfg ~= nil then
_talk = _talkCfg.Content
end
_modelId = _cfg.Model
end
end
end
if task.Data.Type == TaskType.Main then
local _cfg = DataConfig.DataTask[task.Data.Id]
if _cfg ~= nil then
_talkId = _cfg.TaskTalkEnd
_talkCfg = DataConfig.DataTaskTalk[_talkId]
if _talkCfg == nil then
_talk = nil;
_modelId = -1;
else
_talk = _talkCfg.Content;
_modelId = _talkCfg.Model;
end
end
elseif task.Data.Type == TaskType.Daily then
if task.Data.IsAccess then
if self:CanSubmitTask(task.Data.Id) then
local _cfg = DataConfig.DataTaskDaily[task.Data.Id]
if _cfg ~= nil then
_talkId = _cfg.TaskTalkOver
end
elseif task.Data.Behavior == TaskBeHaviorType.PassCopy then
local _cfg = DataConfig.DataTaskDaily[task.Data.Id]
if _cfg ~= nil then
_talkId = _cfg.TaskTalkStart
end
else
_talk = nil
end
else
local _taskCfg = DataConfig.DataTaskDaily[task.Data.Id]
if _taskCfg ~= nil then
_talkId = _taskCfg.TaskTalkStart
end
end
_talkCfg = DataConfig.DataTaskTalk[_talkId];
if _talkCfg == nil then
_talk = nil
_modelId = -1
else
_talk = _talkCfg.Content;
_modelId = _talkCfg.Model;
end
elseif task.Data.Type == TaskType.Guild then
local _taskCfg = DataConfig.DataTaskConquer[task.Data.Id]
if task.Data.IsAccess then
if _taskCfg ~= nil then
_talkId = _taskCfg.TaskTalkOver
end
else
if _taskCfg ~= nil then
_talkId = _taskCfg.TaskTalkStart
end
end
_talkCfg = DataConfig.DataTaskTalk[_talkId]
if _talkCfg == nil then
_talk = nil
_modelId = -1
else
_talk = _talkCfg.Content;
_modelId = _talkCfg.Model;
end
elseif task.Data.Type == TaskType.ZhuanZhi then
local _taskCfg = DataConfig.DataTaskGender[task.Data.Id]
if _taskCfg ~= nil then
if task.Data.IsAccess then
if self:CanSubmitTask(task.Data.Id) then
if _taskCfg ~= nil then
_talkId = _taskCfg.TaskTalkEnd;
end
else
_talk = nil
end
else
_talkId = _taskCfg.TaskTalkStart
end
end
_talkCfg = DataConfig.DataTaskTalk[_talkId]
if _talkCfg == nil then
_talk = nil
_modelId = -1;
else
_talk = _talkCfg.Content;
_modelId = _talkCfg.Model;
end
end
_ret = {
Talk = _talk,
TalkId = _talkId,
ModelId = _modelId
}
return _ret;
end
-- 是否是任务最后一段对话
function LuaTaskManager:IsEndDialogue(talkId)
local _ret = false
local _cfg = DataConfig.DataTaskTalk[talkId]
if _cfg ~= nil then
_ret = _cfg.Nextid == 0 and true or false
end
return _ret
end
function LuaTaskManager:HaveNpcTask(npcId)
local _ret = false
local _task = self:GetNpcTask(npcId)
if _task ~= nil and _task.Data.Type ~= TaskType.Daily then
_ret = true
end
return _ret
end
-- 获取NPC身上的任务 (只返回已经完成的(主线任务优先)任务和未接取的任务(完成的任务优先级大于未接取任务的优先级))
function LuaTaskManager:GetNpcTask(npcID)
local _overTask = nil
-- 已经接取过的任务
self.TaskContainer.Container:ForeachCanBreak(function(k, v)
for i = 1, #v do
if k == TaskType.Not_Recieve then
-- 没有被接取的任务
-- 没被接取的任务
if _overTask == nil then
if self.CurSelectTaskID == 0 then
if v[i].Data.AccessNpcID == npcID then
_overTask = v[i]
end
else
-- 指定执行某任务
if v[i].Data.Id == self.CurSelectTaskID then
local _accessNpcId = v[i]:GetAccessNpcId(v[i].Data.Id)
if accessNpcId == npcID then
_overTask = v[i]
end
break
end
end
end
else
-- 已经被接取的任务
local _behavior = self.TaskBeHaviorManager:GetBehavior(v[i].Data.Id);
if _behavior ~= nil then
-- 已经接取的任务
-- 任务完成
if self.CurSelectTaskID == 0 then
-- 没有指定执行任务
if _behavior.TaskTarget:IsReach(_behavior.Type) then
if _overTask == nil then
if v[i].Data.SubmitNpcID == npcID then
_overTask = v[i]
break
end
else
if v[i].Data.Type < _overTask.Data.Type and v[i].Data.SubmitNpcID == npcID then
_overTask = v[i]
break
end
end
end
if v[i].Data.Type == TaskType.Daily and v[i].Data.Behavior == TaskBeHaviorType.PassCopy then
if v[i] ~= nil then
if v[i].Cfg.NpcId == npcID then
_overTask = v[i]
end
end
end
else
-- 指定执行某任务
if v[i].Data.Id == self.CurSelectTaskID then
if v[i].Data.Type == TaskType.Daily and v[i].Data.Behavior == TaskBeHaviorType.PassCopy then
if v[i].Cfg.NpcId == npcID then
_overTask = v[i]
return _overTask
end
end
if v[i].Data.SubmitNpcID == npcID then
_overTask = v[i]
return _overTask
end
else
if v[i].Data.SubmitNpcID == npcID then
_overTask = v[i]
end
end
end
end
end
end
end)
return _overTask;
end
function LuaTaskManager:GetXmCopyTaskByNpc(npcId)
local _ret = nil
local _list = self:GetXmTasks();
if _list ~= nil then
for i = 1, #_list do
local _task = _list[i];
local _bType = self:GetBehaviorType(_task.Data.Id)
if _bType == TaskBeHaviorType.PassCopy and _task.Data.IsAccess then
if _task.Data.Cfg.OverNpc == npcId then
_ret = _task
break
end
end
end
end
return _ret
end
-- 获取NPC身上任务状态
function LuaTaskManager:GetNpcTaskState(npcID)
local _task = self:GetNpcTask(npcID)
if _task ~= nil then
local _behavior = self.TaskBeHaviorManager:GetBehavior(_task.Data.Id);
if _behavior == nil then
return L_CSNpcTaskState.Default;
else
if _task.Data.IsAccess then
-- 可以提交
if self:CanSubmitTask(_task.Data.Id) then
return L_CSNpcTaskState.Submit;
end
return L_CSNpcTaskState.Default;
else
-- 未接取
return L_CSNpcTaskState.Can_Access;
end
end
end
return L_CSNpcTaskState.Default;
end
function LuaTaskManager:GetWaterWaveParam()
local _param = nil
local _behavior = self.TaskBeHaviorManager:GetBehavior(self.CurSelectTaskID)
if _behavior ~= nil and _behavior.Type == TaskBeHaviorType.ArrivePosEx then
self.OldParam = _behavior.Param
return self.OldParam
else
_param = self.OldParam;
return _param
end
end
function LuaTaskManager:EnterPlaneCopy()
end
function LuaTaskManager:LeavePlaneCopy()
if self.IsStopAllTask then
self.IsAutoTaskForTransPort = false
self.IsStopAllTask = false
else
-- 确保退出位面的时候主动执行任务
self.IsAutoTaskForTransPort = true
end
end
function LuaTaskManager:IsSyncPos(isEnter, frontMapId, curMapId)
local _task = self:GetTask(self.CurSelectTaskID)
if _task == nil or _task.Data.MapID ~= curMapId then
-- 进入的不是任务位面
return false;
else
return self:GetTaskSyncId(isEnter, _task) == 1;
end
end
function LuaTaskManager:GetTaskSyncId(isEnter, task)
local _syncId = 0
local _taskId = -1
if isEnter then
_taskId = self.CurSelectTaskID
else
local _preTaskId = -1;
if task.Data.Type == TaskType.Main then
_preTaskId = self:GetPreMainTaskId(self.CurSelectTaskID);
_taskId = _preTaskId;
end
end
if _taskId > 0 then
if task.Data.Type == TaskType.Main then
local _cfg = DataConfig.DataTask[taskId]
if _cfg ~= nil then
_syncId = _cfg.IsSyncPos
end
else
_syncId = 0;
end
else
_syncId = 0;
end
return _syncId;
end
function LuaTaskManager:IsTalkToNpcTask(taskId)
local _ret = false
if self:GetBehaviorType(taskId) == TaskBeHaviorType.Talk then
_ret = true
end
return _ret
end
function LuaTaskManager:ReqTaskChange(taskId)
local _task = self:GetTask(taskId)
if _task ~= nil then
GameCenter.TaskManagerMsg:ReqChangeTaskState(_task.Data.Type, _task.Data.Id)
end
end
function LuaTaskManager:GetTaskIconId(taskId)
local _ret = 0
local _task = self:GetTask(taskId)
if _task ~= nil then
_ret = _task.Data.IconId
end
end
--获取主线任务描述
function LuaTaskManager:GetMainTaskDes()
local _ret = ""
local _id = self:GetMainTaskId()
local _behavior = self:GetBehavior(_id)
if _behavior ~= nil then
_ret = _behavior.Des
end
return _ret
end
--获取主线任务类型
function LuaTaskManager:GetMainTaskType()
local _ret = 0
local _id = self:GetMainTaskId()
_ret = self:GetBehaviorType(_id)
return _ret
end
function LuaTaskManager:GetDailyTaskRewardState(count)
local _ret = false
if self.DailyBoxState ~= nil then
_ret = self.DailyBoxState[count]
else
end
return _ret
end
function LuaTaskManager:AllDailyTaskRewared()
local _ret = false
local _b1 = GameCenter.LuaTaskManager:GetDailyTaskRewardState(10)
local _b2 = GameCenter.LuaTaskManager:GetDailyTaskRewardState(20)
_ret = _b1 and _b2
return _ret
end
function LuaTaskManager:Update(dt)
-- behavior心跳
if self.TaskBeHaviorManager ~= nil then
self.TaskBeHaviorManager:OnUpdate(dt)
end
if self.IsAutoTaskForTransPort then
if self.IsLocalUserTeleport then
GameCenter.TaskController:ResumeForTransPort()
end
end
self:UpdateLockData(dt)
end
return LuaTaskManager