| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- local RemoteProxy = requireProxy("remote/RemoteProxy")
- local NPCProxy = class("NPCProxy", RemoteProxy)
- NPCProxy.NAME = global.ProxyTable.NPC
- -- NPC打开出售修理
- NPCProxy.EVENT_TYPE = {
- SELL = 1,
- REPAIRE = 2,
- DOSOMETHING = 3,
- NEWTYPE = 4,
- }
- function NPCProxy:ctor()
- NPCProxy.super.ctor(self)
- self._currClickNPCID = nil --当前点击的npc id, 跨服之后服务端发送的Useid是本地的, 导致找不到npc, 只好本地记录一下
- self._currentBackground = nil
- self._currentNPCTalkData = nil
- self._timerWidgets = {}
- self._isClickCD = false
- end
- function NPCProxy:CheckNpcTalkLayerClose(npcTypeIndex)
- if self:GetCurrentNPCIndex() == npcTypeIndex then
- self:Cleanup()
- end
- end
- function NPCProxy:GetCurrentNPCTalkData()
- return self._currentNPCTalkData
- end
- function NPCProxy:GetCurrentNPCID()
- if not self._currentNPCTalkData then
- return nil
- end
- return self._currentNPCTalkData.npcID
- end
- function NPCProxy:GetCurrentNPCIndex()
- if not self._currentNPCTalkData then
- return nil
- end
- return self._currentNPCTalkData.index
- end
- function NPCProxy:GetCurrentClickNPCID()
- return self._currClickNPCID
- end
- function NPCProxy:SetCurrentNPCTalkData(data)
- self._currentNPCTalkData = data
- end
- function NPCProxy:GetCurrentBackground()
- return self._currentBackground
- end
- function NPCProxy:SetCurrentBackground(data)
- self._currentBackground = data
- end
- function NPCProxy:ResetCurrentBackground()
- self._currentBackground = nil
- end
- function NPCProxy:Cleanup()
- self._currClickNPCID = nil
- self:ResetCurrentBackground()
- global.Facade:sendNotification(global.NoticeTable.SUIITEMBOXPutoutAll)
- global.Facade:sendNotification(global.NoticeTable.Layer_NPC_Talk_Close)
- end
- function NPCProxy:ExecuteWithCommonInput(jsonData)
- local sendData = {
- UserID = jsonData.UserID,
- Act = jsonData.Act,
- commonInput = jsonData.commonInput,
- inputID = jsonData.inputID,
- }
- self:ExecuteWithJsonData(sendData)
- end
- function NPCProxy:ExecuteWithJsonData(jsonData)
- local currNpcData = self:GetCurrentNPCTalkData()
- if currNpcData and currNpcData.index then
- jsonData.index = currNpcData.index
- end
- if jsonData.newIndex then
- jsonData.index = jsonData.newIndex
- end
- dump(jsonData)
- NPCEXECUTE_CLOCK = os.clock()
- SendTableToServer(global.MsgType.MSG_CS_NPC_TASK_CLICK, jsonData)
- end
- function NPCProxy:RequestNpcStoreItemList(data)
- local sendData = {
- UserID = self._currentNPCTalkData.npcID,
- Name = data.Name,
- }
- SendTableToServer(global.MsgType.MSG_CS_NPC_STORE_ITEM_LIST, sendData)
- end
- function NPCProxy:RequestNpcStoreBuy(data)
- local sendData = {
- UserID = self._currentNPCTalkData.npcID,
- Name = data.Name,
- MakeIndex = data.MakeIndex or 0
- }
- SendTableToServer(global.MsgType.MSG_CS_NPC_STORE_BUY, sendData)
- end
- function NPCProxy:RequestNpcMakeDrug(data)
- local sendData = {
- userid = self._currentNPCTalkData.npcID,
- name = data.name,
- }
- SendTableToServer(global.MsgType.MSG_CS_NPC_MAKE_DRUG, sendData)
- end
- local function handle_MSG_SC_NPC_TALK(msg)
- if NPCEXECUTE_CLOCK then
- print("NPC TALK RESP cost", os.clock() - NPCEXECUTE_CLOCK)
- end
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return -1
- end
- if not jsonData or not jsonData.sMsg then
- return
- end
- -- dump(jsonData)
- local npcProxy = global.Facade:retrieveProxy(global.ProxyTable.NPC)
- local nData = {}
- nData.content = jsonData.sMsg
- nData.npcName = jsonData.Name
- nData.npcID = jsonData.UserID
- nData.index = jsonData.index
- -- Timer:id:remaining:content:x:y:anchor:colorID
- -- Timer:1:7200:秘境倒计时:%s:10:10:0:255
- -- Timer:1:0:秘境倒计时:%s
- if nData.content == "CloseNpcLayer" then
- global.Facade:sendNotification(global.NoticeTable.Layer_NPC_Talk_Close)
- return
- end
- if string.find(nData.content, "<JumpTo:.->") then
- local find_info = { string.find(nData.content, "<JumpTo:(.-)>") }
- if find_info[1] and find_info[2] then
- local slices = string.split(find_info[3], ":")
- local jumpID = tonumber(slices[1])
- local close = (tonumber(slices[2]) == nil or tonumber(slices[2]) == 0)
- -- close npc talk
- if close then
- global.Facade:sendNotification(global.NoticeTable.Layer_NPC_Talk_Close)
- end
- JUMPTO(jumpID)
- end
- else
- npcProxy:SetCurrentNPCTalkData(nData)
- global.Facade:sendNotification(global.NoticeTable.Layer_NPC_Talk_Open)
- -- 同步至 SL框架
- SLBridge:onLUAEvent(LUA_EVENT_NPC_TALK, {id = jsonData.UserID, index = jsonData.index, name = jsonData.Name})
- end
- end
- local function handle_MSG_SC_NPC_TALK_BACKGROUND(msg)
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return -1
- end
- dump(jsonData)
- local npcProxy = global.Facade:retrieveProxy(global.ProxyTable.NPC)
- npcProxy:SetCurrentBackground(jsonData)
- end
- local function handle_MSG_SC_NPC_TALK_CLOSE(msg)
- print("local function handle_MSG_SC_NPC_TALK_CLOSE(msg) 644")
- local npcProxy = global.Facade:retrieveProxy(global.ProxyTable.NPC)
- npcProxy:Cleanup()
- end
- local function handle_MSG_SC_NPC_STORE_OPEN(msg)
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return -1
- end
- global.Facade:sendNotification(global.NoticeTable.Layer_NPC_Store_Open, jsonData)
- end
- local function handle_MSG_SC_NPC_STORE_ITEM_LIST(msg)
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return -1
- end
- local itemList = {}
- for _, v in ipairs(jsonData) do
- local data = ChangeItemServersSendDatas(v)
- table.insert(itemList, data)
- end
- global.Facade:sendNotification(global.NoticeTable.Layer_NPC_Store_Open, {Items = itemList})
- end
- local function handle_MSG_SC_NPC_STORE_BUY_RESULT_FAIL(msg)
- local head = msg:GetHeader()
- if not head then
- return
- end
- if head.recog then
- local str = GET_STRING(90160009)
- if head.recog == 2 then
- str = GET_STRING(90160007)
- elseif head.recog == 3 then
- str = GET_STRING(90160008)
- elseif head.recog == 1 then
- str = GET_STRING(90160006)
- end
- local data = {}
- data.str = str
- data.btnDesc = { GET_STRING(1002) }
- global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
- end
- end
- local function handle_MSG_SC_NPC_STORE_BUY_RESULT_SUCCESS(msg)
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return -1
- end
- dump(jsonData)
- local MakeIndex = jsonData.MakeIndex
- if MakeIndex and MakeIndex ~= 0 then
- global.Facade:sendNotification(global.NoticeTable.Layer_NPC_Store_Item_Remove, MakeIndex)
- end
- end
- local function handle_MSG_SC_NPC_MAKE_DRUG_LIST(msg)
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return -1
- end
- global.Facade:sendNotification(global.NoticeTable.Layer_NPC_Make_Drug_Open, jsonData)
- end
- local function handle_MSG_SC_NPC_MAKE_DRUG_SUCCESS(msg)
- local head = msg:GetHeader()
- if not head then
- return
- end
- local data = {}
- data.str = GET_STRING(90160001)
- data.btnDesc = { GET_STRING(1002) }
- global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
- end
- local function handle_MSG_SC_NPC_MAKE_DRUG_FAILED(msg)
- local head = msg:GetHeader()
- if not head then
- return
- end
- if head.recog then
- local tips = true
- local data = {}
- data.btnDesc = { GET_STRING(1002) }
- if head.recog == 1 then
- data.str = GET_STRING(90160002)
- elseif head.recog == 2 then
- data.str = GET_STRING(90160003)
- elseif head.recog == 3 then
- data.str = GET_STRING(90160004)
- elseif head.recog == 4 then
- data.str = GET_STRING(90160005)
- else
- tips = false
- end
- if tips then
- global.Facade:sendNotification(global.NoticeTable.Layer_CommonTips_Open, data)
- end
- end
- end
- function NPCProxy:handle_MSG_SC_PROGRESS_BAR(msg)
- global.Facade:sendNotification(global.NoticeTable.Layer_ProgressBar_Close)
- local jsonData = ParseRawMsgToJson(msg)
- if not jsonData then
- return nil
- end
- global.Facade:sendNotification(global.NoticeTable.Layer_ProgressBar_Open, jsonData)
- end
- function NPCProxy:RequestTalk(npcID)
- print("talk to NPC", npcID)
- NPCEXECUTE_CLOCK = os.clock()
- self:ResetCurrentBackground()
- local npc = global.npcManager:FindOneNpcInCurrViewFieldById(npcID)
- if npc then
- self._currClickNPCID = npcID
- local typeIndex = npc:GetTypeIndex()
- local sendData = {
- UserID = npcID,
- index = typeIndex,
- }
- SendTableToServer(global.MsgType.MSG_CS_NPC_CLICK, sendData)
- dump(sendData)
- global.Facade:sendNotification(global.NoticeTable.Audio_Play, { type = global.MMO.SND_TYPE_NPC_TALK, index = typeIndex })
- -- SL
- local talkData =
- {
- UserID = npcID,
- index = typeIndex,
- name = npc:GetName()
- }
- SLBridge:onLUAEvent(LUA_EVENT_TALKTONPC, talkData)
- end
- end
- function NPCProxy:CheckTalk(npcID, isAuto)
- -- 摆摊
- if false == CheckCanDoSomething() then
- return nil
- end
- -- NPC点击间隔,只有手动生效
- if not isAuto then
- if self._isClickCD then
- return nil
- end
- local mapProxy = global.Facade:retrieveProxy(global.ProxyTable.Map)
- local clickInterval = mapProxy:GetClickNpcSpeed() * 0.001
- if clickInterval and clickInterval > 0 then
- self._isClickCD = true
- PerformWithDelayGlobal(function()
- self._isClickCD = false
- end, clickInterval)
- end
- end
- -- 现在点击即可打开NPC
- local npc = global.npcManager:FindOneNpcInCurrViewFieldById(npcID)
- if npc then
- self:RequestTalk(npcID)
- end
- end
- function NPCProxy:RequestNotifyTalkOpen(talkLayerID)
- if not talkLayerID or "" == talkLayerID then
- return nil
- end
- print("---------------RequestNotifyTalkOpen", talkLayerID)
- SendTableToServer(global.MsgType.MSG_CS_NPC_TALK_OPEN_NOTIFY, {layerid = talkLayerID})
- end
- function NPCProxy:RequestNotifyTalkClose(talkLayerID)
- if not talkLayerID or "" == talkLayerID then
- return nil
- end
- print("---------------RequestNotifyTalkClose", talkLayerID)
- SendTableToServer(global.MsgType.MSG_CS_NPC_TALK_CLOSE_NOTIFY, {layerid = talkLayerID})
- end
- function NPCProxy:RegisterMsgHandler()
- NPCProxy.super.RegisterMsgHandler(self)
- local msgType = global.MsgType
- -- NPC 对话数据(以及任务)
- LuaRegisterMsgHandler(msgType.MSG_SC_NPC_TALK, handle_MSG_SC_NPC_TALK)
- -- NPC 对话框背景数据
- LuaRegisterMsgHandler(msgType.MSG_SC_NPC_TALK_BACKGROUND, handle_MSG_SC_NPC_TALK_BACKGROUND)
- -- NPC 关闭NPC面板
- LuaRegisterMsgHandler(msgType.MSG_SC_NPC_TALK_CLOSE, handle_MSG_SC_NPC_TALK_CLOSE)
- -- 打开NPC商店
- LuaRegisterMsgHandler(msgType.MSG_SC_NPC_STORE_OPEN, handle_MSG_SC_NPC_STORE_OPEN)
- -- NPC商店道具列表返回
- LuaRegisterMsgHandler(msgType.MSG_SC_NPC_STORE_ITEM_LIST, handle_MSG_SC_NPC_STORE_ITEM_LIST)
- -- NPC商店购买失败返回
- LuaRegisterMsgHandler(msgType.MSG_SC_NPC_STORE_BUY_RESULT_FAIL, handle_MSG_SC_NPC_STORE_BUY_RESULT_FAIL)
- -- NPC商店购买成功返回
- LuaRegisterMsgHandler(msgType.MSG_SC_NPC_STORE_BUY_RESULT_SUCCESS, handle_MSG_SC_NPC_STORE_BUY_RESULT_SUCCESS)
- -- 打开NPC 炼药
- LuaRegisterMsgHandler(msgType.MSG_SC_NPC_MAKE_DRUG_LIST, handle_MSG_SC_NPC_MAKE_DRUG_LIST)
- -- NPC 炼药成功
- LuaRegisterMsgHandler(msgType.MSG_SC_NPC_MAKE_DRUG_SUCCESS, handle_MSG_SC_NPC_MAKE_DRUG_SUCCESS)
- -- NPC 炼药失败
- LuaRegisterMsgHandler(msgType.MSG_SC_NPC_MAKE_DRUG_FAILED, handle_MSG_SC_NPC_MAKE_DRUG_FAILED)
- -- NPC 进度条
- LuaRegisterMsgHandler(msgType.MSG_SC_PROGRESS_BAR, handler(self, self.handle_MSG_SC_PROGRESS_BAR))
- end
- return NPCProxy
|