------------------------------------------------ -- 作者: 杨全福 -- 日期: 2021-03-05 -- 文件: NpcTalkSystem.lua -- 模块: NpcTalkSystem -- 描述: NPC对话系统 ------------------------------------------------ local L_DefaultClipName = "idle" local NpcTalkSystem = { --当前任务对话ID (默认对话 _talkId = -1) TalkId = -1, --对话NPC ModelId = -1, PreModelId = -1, --是否可提交任务 CanSubmit = false, --是否可以接取任务 CanAccess = false, Npc = nil, NpcCfgID = 0, Task = nil, ClipName = "", NextClipName = "", --当前播放动状态 CurPlayState = NpcTalkAnimPlayState.Default, } --是否还有后续对话 function NpcTalkSystem:IsEnd() if self.TalkId == -1 then return true end return GameCenter.LuaTaskManager:IsEndDialogue(self.TalkId) end --打开NPC对话 function NpcTalkSystem:OpenNpcTalk(npc, taskID, isTaskOpenUI, openUIParam) if taskID == nil then taskID = 0 end if isTaskOpenUI == nil then isTaskOpenUI = false end if npc == nil then return end local _npcCfgId = npc.PropMoudle.CfgID local _npcCfg = DataConfig.DataNpc[_npcCfgId] if _npcCfg == nil then return end self.Npc = npc self.NpcCfgID = _npcCfgId self.ClipName = L_DefaultClipName self.NextClipName = L_DefaultClipName self.ModelId = -1 if isTaskOpenUI then if _npcCfg.BindFunctionID > 0 then --检查引导 if not GameCenter.GuideSystem:Check(GuideTriggerType.ChickOpenUITask, taskID) then --当前NPC如果绑定了功能,打开一个功能 if openUIParam ~= nil then GameCenter.MainFunctionSystem:DoFunctionCallBack(_npcCfg.BindFunctionID, openUIParam) else GameCenter.MainFunctionSystem:DoFunctionCallBack(_npcCfg.BindFunctionID, _npcCfg.BindFunctionParams) end end end else if _npcCfg.IsReqNPC == 1 then GameCenter.Netword.Send("MSG_Npc.ReqClickNpc", {id = npc.ID}) return end local _talkText = nil self.TalkId = -1 self.CanSubmit = false self.CanAccess = false GameCenter.LuaTaskManager.CurSelectTaskID = taskID self.Task = GameCenter.LuaTaskManager:GetNpcTask(_npcCfgId) if self.Task == nil then if _npcCfg.BindFunctionID > 0 then --当前NPC如果绑定了功能,打开一个功能 GameCenter.MainFunctionSystem:DoFunctionCallBack(_npcCfg.BindFunctionID, _npcCfg.BindFunctionParams) elseif _npcCfg.FuncType > 0 then --如果NPC的功能类型大于0,则打开一个窗体 GameCenter.PushFixEvent(UIEventDefine.UINpcFunctionForm_OPEN, _npcCfgId) else --任务没有被接取(或者没有达成接取任务的目标)默认对话 local _lp = GameCenter.GameSceneSystem:GetLocalPlayer() if _lp ~= nil then local _occ = _lp.IntOcc if _occ == _npcCfg.Professional then _talkText = _npcCfg.ProfessionalDialog else _talkText = _npcCfg.Dialog end end self.ModelId = _npcCfgId GameCenter.PushFixEvent(UIEventDefine.UINpcTalkForm_OPEN, _talkText) end else --拥有任务 GameCenter.LuaTaskManager.CurSelectTaskID = self.Task.Data.Id --Talk = _talk, TalkId = _talkId, ModelId = _modelId local _talkData = GameCenter.LuaTaskManager:GetTaskTalk(self.Task, self.TalkId, self.ModelId) if _talkData ~= nil then _talkText = _talkData.Talk self.TalkId = _talkData.TalkId self.ModelId = _talkData.ModelId end local _talkCfg = DataConfig.DataTaskTalk[self.TalkId] if _talkCfg ~= nil then if _talkCfg.ShowName == 1 then local _lp = GameCenter.GameSceneSystem:GetLocalPlayer() if _lp ~= nil then _talkText = UIUtils.CSFormat(_talkText, _lp.Name) end end end if self.Task.Data.IsAccess then self.CanSubmit = GameCenter.LuaTaskManager:CanSubmitTaskEx(self.Task) else self.CanAccess = true end if _talkCfg ~= nil then GameCenter.PushFixEvent(UIEventDefine.UINpcTalkForm_OPEN, _talkText) self.ClipName = _talkCfg.Animation end self.NextClipName = self.ClipName end end --NPC转向 local _lp = GameCenter.GameSceneSystem:GetLocalPlayer() if _lp ~= nil then npc:LookAtPosition(_lp.Position2d) end end --设置下一条对话 function NpcTalkSystem:GetNextTalk() self.ClipName = self.NextClipName local _cfg = DataConfig.DataTaskTalk[self.TalkId] if _cfg ~= nil then if _cfg.Nextid ~= 0 then self.TalkId = _cfg.Nextid _cfg = DataConfig.DataTaskTalk[self.TalkId] if _cfg ~= nil then local _talkText = _cfg.Content self.PreModelId = self.ModelId self.ModelId = _cfg.Model if _cfg.ShowName == 1 then local _lp = GameCenter.GameSceneSystem:GetLocalPlayer() if _lp ~= nil then _talkText = UIUtils.CSFormat(_talkText, _lp.Name) end end self.NextClipName = _cfg.Animation return _talkText end end end return nil end function NpcTalkSystem:GetCurSpeechName() local _ret = "" local _cfg = DataConfig.DataTaskTalk[self.TalkId] if _cfg ~= nil then return _cfg.Speech end return _ret end function NpcTalkSystem:Reset() self.ModelId = -1 end --切换播放状态 function NpcTalkSystem:ChangePlayState(state) self.CurPlayState = state end --是否可以强制播放下一动作片段 function NpcTalkSystem:IsCanPlayNextAnim() if self.ClipName ~= L_DefaultClipName then return false else return true end end --是否播放默认动作片段 function NpcTalkSystem:IsPlayDefaultAnim() return self.NextClipName == L_DefaultClipName end return NpcTalkSystem