274 lines
9.7 KiB
Lua
274 lines
9.7 KiB
Lua
------------------------------------------------
|
|
-- 作者: 王圣
|
|
-- 日期: 2021-03-19
|
|
-- 文件: TaskBehaviorManager.lua
|
|
-- 模块: TaskBehaviorManager
|
|
-- 描述: 任务行为管理
|
|
------------------------------------------------
|
|
-- 引用
|
|
local L_Talk = require "Logic.TaskSystem.Behavior.TalkCharactor"
|
|
local L_PlaneCopy = require "Logic.TaskSystem.Behavior.ArrivePosEx"
|
|
local L_OpenUI = require "Logic.TaskSystem.Behavior.TaskOpenUI"
|
|
local L_PlaneCopyAnim = require "Logic.TaskSystem.Behavior.ArriveToAnim"
|
|
local L_PassCopy = require "Logic.TaskSystem.Behavior.PassCopy"
|
|
local L_Container = require "Logic.TaskSystem.Container.TaskBehaviorContainer"
|
|
local L_Collect = require "Logic.TaskSystem.Behavior.BCollection"
|
|
|
|
local TaskBehaviorManager = {
|
|
IsPause = false,
|
|
Container = nil
|
|
}
|
|
function TaskBehaviorManager:New()
|
|
local _m = Utils.DeepCopy(self)
|
|
_m.Container = L_Container:New()
|
|
return _m
|
|
end
|
|
|
|
function TaskBehaviorManager:IniItialization()
|
|
end
|
|
|
|
function TaskBehaviorManager:UnIniItialization()
|
|
self.Container:Clear()
|
|
end
|
|
|
|
-- 创建行为
|
|
function TaskBehaviorManager:Create(type, id)
|
|
local _behavior = nil;
|
|
if type == TaskBeHaviorType.Talk then
|
|
_behavior = self:CreateTalk(type, id)
|
|
elseif type == TaskBeHaviorType.Kill then
|
|
_behavior = self:CreateKill(type, id)
|
|
elseif type == TaskBeHaviorType.Collection then
|
|
_behavior = self:CreateCollection(type, id)
|
|
elseif type == TaskBeHaviorType.CopyKillForUI or type == TaskBeHaviorType.OpenUI then
|
|
_behavior = self:CreateOpenUI(type, id)
|
|
elseif type == TaskBeHaviorType.PassCopy then
|
|
_behavior = self:CreatePassCopy(type, id)
|
|
elseif type == TaskBeHaviorType.Level then
|
|
_behavior = self:CreateLimitLv(type, id)
|
|
elseif type == TaskBeHaviorType.CopyKill then
|
|
_behavior = self:CreateCopyKill(type, id)
|
|
elseif type == TaskBeHaviorType.FindCharactor then
|
|
_behavior = self:CreateFindCharactor(type, id)
|
|
elseif type == TaskBeHaviorType.SubMit then
|
|
_behavior = self:CreateSubMitItem(type, id)
|
|
elseif type == TaskBeHaviorType.ArrivePos then
|
|
_behavior = self:CreateArrivePos(type, id)
|
|
elseif type == TaskBeHaviorType.OpenUIToSubMit or type == TaskBeHaviorType.AddFriends then
|
|
_behavior = self:CreateOpenUISbmit(type, id)
|
|
elseif type == TaskBeHaviorType.MountFlyUp then
|
|
_behavior = self:CreateTaskMountFlyUp(type, id)
|
|
elseif type == TaskBeHaviorType.CollectItem or type == TaskBeHaviorType.CollectRealItem then
|
|
_behavior = self:CreateCollectItem(type, id)
|
|
elseif type == TaskBeHaviorType.ArrivePosEx then
|
|
_behavior = self:CreateArrivePosEx(type, id)
|
|
elseif type == TaskBeHaviorType.ArriveToAnim then
|
|
_behavior = self:CreateArriveToAnim(type, id)
|
|
end
|
|
return _behavior
|
|
end
|
|
-- 对话行为
|
|
function TaskBehaviorManager:CreateTalk(type, id)
|
|
local _behavior = L_Talk:New(type, id)
|
|
return _behavior
|
|
end
|
|
-- 杀怪(杀玩家)行为
|
|
function TaskBehaviorManager:CreateKill(type, id)
|
|
-- local _behavior = L_PlaneCopy:New(type, id)
|
|
-- return _behavior
|
|
end
|
|
-- 采集行为
|
|
function TaskBehaviorManager:CreateCollection(type, id)
|
|
local _behavior = L_Collect:New(type, id)
|
|
return _behavior
|
|
end
|
|
-- 打开UI行为
|
|
function TaskBehaviorManager:CreateOpenUI(type, id)
|
|
local _behavior = L_OpenUI:New(type, id)
|
|
return _behavior
|
|
end
|
|
-- 传送进入副本行为
|
|
function TaskBehaviorManager:CreatePassCopy(type, id)
|
|
local _behavior = L_PassCopy:New(type, id)
|
|
return _behavior
|
|
end
|
|
-- 达到等级行为
|
|
function TaskBehaviorManager:CreateLimitLv()
|
|
-- LimitLevel behavior = new LimitLevel();
|
|
-- return behavior;
|
|
end
|
|
|
|
function TaskBehaviorManager:CreateCopyKill()
|
|
-- CopyKill behavior = new CopyKill();
|
|
-- return behavior;
|
|
end
|
|
-- 寻人
|
|
function TaskBehaviorManager:CreateFindCharactor()
|
|
-- FindCharactor behavior = new FindCharactor();
|
|
-- return behavior;
|
|
end
|
|
-- 提交道具
|
|
function TaskBehaviorManager:CreateSubMitItem()
|
|
-- SubMitItem behavior = new SubMitItem();
|
|
-- return behavior;
|
|
end
|
|
-- 到达某个位置
|
|
function TaskBehaviorManager:CreateArrivePos()
|
|
-- ArrivePos behavior = new ArrivePos();
|
|
-- return behavior;
|
|
end
|
|
-- 打开UI完成任务
|
|
function TaskBehaviorManager:CreateOpenUISbmit()
|
|
-- TaskOpenUISubmit behavior = new TaskOpenUISubmit();
|
|
-- return behavior;
|
|
end
|
|
-- 起飞飞行坐骑
|
|
function TaskBehaviorManager:CreateTaskMountFlyUp()
|
|
-- TaskMountFltUp behaivor = new TaskMountFltUp();
|
|
-- return behaivor;
|
|
end
|
|
-- 收集道具
|
|
function TaskBehaviorManager:CreateCollectItem()
|
|
-- CollectItem behaivor = new CollectItem();
|
|
-- return behaivor;
|
|
end
|
|
-- 到达指定位置(不转圈)
|
|
function TaskBehaviorManager:CreateArrivePosEx(type, id)
|
|
local _behavior = L_PlaneCopy:New(type, id)
|
|
return _behavior
|
|
end
|
|
-- 到达指定地点进入位面然后播放特定动作
|
|
function TaskBehaviorManager:CreateArriveToAnim(type, id)
|
|
local _behavior = L_PlaneCopyAnim:New(type, id)
|
|
return _behavior
|
|
end
|
|
|
|
-- 添加行为
|
|
function TaskBehaviorManager:Add(taskId, behavior)
|
|
-- Debug.LogError("yy TaskBehaviorManager:Add "..tostring(taskId))
|
|
-- Debug.LogTable(behaivor)
|
|
self.Container:Add(taskId, behavior)
|
|
end
|
|
-- 获取某个任务的行为
|
|
function TaskBehaviorManager:GetBehavior(taskId)
|
|
local _ret = self.Container:Find(taskId)
|
|
return _ret;
|
|
end
|
|
-- 删除某个任务行为
|
|
function TaskBehaviorManager:RmoveBehavior(taskId)
|
|
self.Container:Remove(taskId)
|
|
end
|
|
function TaskBehaviorManager:GetBehaviorCount()
|
|
return self.Container:Count()
|
|
end
|
|
-- 是否完成行为
|
|
function TaskBehaviorManager:IsEndBehavior(taskId)
|
|
local _ret = false;
|
|
local _behavior = self:GetBehavior(taskId);
|
|
if _behavior ~= nil then
|
|
_ret = _behavior.TaskTarget:IsReach(_behavior.Type);
|
|
end
|
|
return _ret;
|
|
end
|
|
-- 去完成某个行为
|
|
function TaskBehaviorManager:DoBehavior(taskId, isClick, isClickByForm)
|
|
-- 如果暂停直接返回
|
|
if self.IsPause then
|
|
return;
|
|
end
|
|
local _behavior = self:GetBehavior(taskId);
|
|
Debug.LogTable(_behavior)
|
|
local _task = GameCenter.LuaTaskManager:GetTask(taskId);
|
|
if _task == nil then
|
|
return;
|
|
end
|
|
-- 判断是否有战力限制
|
|
local _limitPower = _task:GetLimitPower();
|
|
if _limitPower > 0 and not _task:GetIgnoLimit() then
|
|
-- 有战力限制
|
|
if GameCenter.GameSceneSystem:GetLocalPlayerFightPower() >= _limitPower then
|
|
self:OnDoBehavior(_behavior, _task, isClick, isClickByForm);
|
|
else
|
|
-- 弹出提示
|
|
GameCenter.MsgPromptSystem:ShowMsgBox(DataConfig.DataMessageString.Get("Task_Score_Limit"),
|
|
DataConfig.DataMessageString.Get("Task_TiShi_1"), DataConfig.DataMessageString.Get("Task_TiShi_2"),
|
|
function(x)
|
|
if x == MsgBoxResultCode.Button1 then
|
|
self:OnDoBehavior(_behavior, _task, isClick, isClickByForm);
|
|
_task:SetIgnoLimit(true)
|
|
elseif x == MsgBoxResultCode.Button2 then
|
|
-- 打开变强界面
|
|
GameCenter.MainFunctionSystem:DoFunctionCallBack(FunctionStartIdCode.BianQiang);
|
|
end
|
|
end);
|
|
end
|
|
else
|
|
self:OnDoBehavior(_behavior, _task, isClick, isClickByForm);
|
|
end
|
|
end
|
|
|
|
function TaskBehaviorManager:OnDoBehavior(behavior, task, isClick, isClickByForm)
|
|
if behavior ~= nil then
|
|
if behavior.Type ~= TaskBeHaviorType.CopyKill and behavior.Type ~= TaskBeHaviorType.CopyKillForUI and
|
|
task.Data.Type ~= TaskType.ZhanChang and isClick then
|
|
if GameCenter.MapLogicSystem.MapCfg.Type == UnityUtils.GetObjct2Int(MapTypeDef.Copy) then
|
|
GameCenter.MsgPromptSystem:ShowPrompt(DataConfig.DataMessageString.Get("EXIT_COPY_FOR_GOON_TASK"))
|
|
return;
|
|
end
|
|
end
|
|
if task ~= nil then
|
|
if isClick and task.IsShowGuide then
|
|
task.IsShowGuide = false;
|
|
end
|
|
if isClickByForm then
|
|
if GameCenter.MapLogicSystem.MapCfg ~= nil and GameCenter.MapLogicSystem.MapCfg.Type == UnityUtils.GetObjct2Int(MapTypeDef.Copy) then
|
|
-- 如果在副本里面 弹出消息确认框是否退出副本继续任务
|
|
GameCenter.MsgPromptSystem:ShowMsgBox(DataConfig.DataMessageString.Get("TASK_TISHI_1"),
|
|
function(x)
|
|
if x == MsgBoxResultCode.Button2 then
|
|
-- 调用离开副本接口
|
|
GameCenter.LuaTaskManager.CurSelectTaskID = task.Data.Id;
|
|
GameCenter.LuaTaskManager.IsAutoTaskForTransPort = true;
|
|
GameCenter.MapLogicSystem:DoLeaveMap()
|
|
return;
|
|
end
|
|
end);
|
|
end
|
|
end
|
|
GameCenter.LuaTaskManager.CurSelectTaskID = task.Data.Id;
|
|
behavior:DoBehavior(isClick);
|
|
end
|
|
end
|
|
end
|
|
|
|
-- 更新行为
|
|
function TaskBehaviorManager:UpdateBehavior(behavior, target)
|
|
if behavior ~= nil then
|
|
behavior:UpdateBehavior(target)
|
|
end
|
|
|
|
end
|
|
|
|
function TaskBehaviorManager:SetBehaviorTag(id, count, talkId, x, y, itemID, type, behavior)
|
|
if behavior ~= nil then
|
|
behavior:SetTarget(id, count, talkId, x, y, itemID, type);
|
|
end
|
|
end
|
|
|
|
-- 获取某个任务id对应任务的行为
|
|
function TaskBehaviorManager:GetTaskBehaviorType(taskId)
|
|
local _ret = TaskBeHaviorType.Default
|
|
local _behavior = self:GetBehavior(taskId);
|
|
if _behavior ~= nil then
|
|
_ret = _behavior.Type;
|
|
end
|
|
return _ret;
|
|
end
|
|
|
|
-- 心跳
|
|
function TaskBehaviorManager:OnUpdate(dt)
|
|
self.Container:OnUpdate(dt);
|
|
end
|
|
|
|
return TaskBehaviorManager
|